Rename from yp2 to metaproxy. The namespace for all definitions
[metaproxy-moved-to-github.git] / src / test_filter_multi.cpp
1 /* $Id: test_filter_multi.cpp,v 1.2 2006-03-16 10:40:59 adam Exp $
2    Copyright (c) 2005-2006, Index Data.
3
4 %LICENSE%
5  */
6
7 #include "config.hpp"
8 #include <iostream>
9 #include <stdexcept>
10
11 #include "filter_multi.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 namespace mp = metaproxy_1;
22
23 class FilterBounceInit: public mp::filter::Base {
24 public:
25     void process(mp::Package & package) const {
26         
27         if (package.session().is_closed())
28         {
29             // std::cout << "Got Close.\n";
30         }
31        
32         Z_GDU *gdu = package.request().get();
33         if (gdu)
34         {
35             // std::cout << "Got PDU. Sending init response\n";
36             mp::odr odr;
37             Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse);
38             
39             apdu->u.initResponse->implementationName = "YP2/YAZ";
40             
41             package.response() = apdu;
42         }
43         package.move();
44     };
45 };
46
47
48 BOOST_AUTO_UNIT_TEST( test_filter_multi_1 )
49 {
50     try 
51     {
52         mp::filter::Multi lf;
53     }
54     catch ( ... ) {
55         BOOST_CHECK (false);
56     }
57 }
58
59 BOOST_AUTO_UNIT_TEST( test_filter_multi_2 )
60 {
61     try 
62     {
63         mp::RouterChain router;
64         
65         mp::filter::Multi multi;
66         FilterBounceInit bounce;
67         
68         router.append(multi);
69         router.append(bounce);
70         
71         // Create package with Z39.50 init request in it
72         mp::Package pack;
73         
74         mp::odr odr;
75         Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
76         
77         pack.request() = apdu;
78         // Done creating query. 
79         
80         // Put it in router
81         pack.router(router).move(); 
82         
83         // Inspect that we got Z39.50 init response
84         yazpp_1::GDU *gdu = &pack.response();
85         
86         Z_GDU *z_gdu = gdu->get();
87         BOOST_CHECK(z_gdu);
88         if (z_gdu) {
89             BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
90             BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
91         }
92     }
93     catch ( ... ) {
94         BOOST_CHECK (false);
95     }
96 }
97
98 /*
99  * Local variables:
100  * c-basic-offset: 4
101  * indent-tabs-mode: nil
102  * c-file-style: "stroustrup"
103  * End:
104  * vim: shiftwidth=4 tabstop=8 expandtab
105  */