Implemented yp2::odr which is a noncopyable wrapper for YAZ' ODR.
[metaproxy-moved-to-github.git] / src / test_filter_log.cpp
1 /* $Id: test_filter_log.cpp,v 1.6 2005-10-30 17:13:36 adam Exp $
2    Copyright (c) 2005, Index Data.
3
4 %LICENSE%
5  */
6
7 #include "config.hpp"
8 #include <iostream>
9 #include <stdexcept>
10
11 #include "filter_log.hpp"
12 #include "util.hpp"
13 #include "router_chain.hpp"
14 #include "session.hpp"
15 #include "package.hpp"
16
17 #define BOOST_AUTO_TEST_MAIN
18 #include <boost/test/auto_unit_test.hpp>
19
20 using namespace boost::unit_test;
21
22 class FilterBounceInit: public yp2::filter::Base {
23 public:
24     void process(yp2::Package & package) const {
25         
26         if (package.session().is_closed())
27         {
28             // std::cout << "Got Close.\n";
29         }
30        
31         Z_GDU *gdu = package.request().get();
32         if (gdu)
33         {
34             // std::cout << "Got PDU. Sending init response\n";
35             yp2::odr odr;
36             Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse);
37             
38             apdu->u.initResponse->implementationName = "YP2/YAZ";
39             
40             package.response() = apdu;
41         }
42         return package.move();
43     };
44     const std::string type() const {
45         return "FilterBounceInit";
46     };
47 };
48
49
50 BOOST_AUTO_TEST_CASE( test_filter_log_1 )
51 {
52     try 
53     {
54         yp2::filter::Log lf;
55     }
56     catch ( ... ) {
57         BOOST_CHECK (false);
58     }
59 }
60
61 BOOST_AUTO_TEST_CASE( test_filter_log_2 )
62 {
63     try 
64     {
65         yp2::RouterChain router;
66         
67         yp2::filter::Log lf;
68         FilterBounceInit bf;
69         
70         router.append(lf);
71         router.append(bf);
72         
73         // Create package with Z39.50 init request in it
74         yp2::Package pack;
75         
76         yp2::odr odr;
77         Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
78         
79         pack.request() = apdu;
80         // Done creating query. 
81         
82         // Put it in router
83         pack.router(router).move(); 
84         
85         // Inspect that we got Z39.50 init response
86         yazpp_1::GDU *gdu = &pack.response();
87         
88         Z_GDU *z_gdu = gdu->get();
89         BOOST_CHECK(z_gdu);
90         if (z_gdu) {
91             BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
92             BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
93         }
94     }
95     catch ( ... ) {
96         BOOST_CHECK (false);
97     }
98 }
99
100 /*
101  * Local variables:
102  * c-basic-offset: 4
103  * indent-tabs-mode: nil
104  * c-file-style: "stroustrup"
105  * End:
106  * vim: shiftwidth=4 tabstop=8 expandtab
107  */