std::string type() function taken out of all filter classes again
[metaproxy-moved-to-github.git] / src / test_filter_frontend_net.cpp
1 /* $Id: test_filter_frontend_net.cpp,v 1.13 2005-10-31 09:40:18 marc 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 "util.hpp"
12 #include "filter_frontend_net.hpp"
13
14 #include "router_chain.hpp"
15 #include "session.hpp"
16 #include "package.hpp"
17
18 #define BOOST_AUTO_TEST_MAIN
19 #include <boost/test/auto_unit_test.hpp>
20
21 using namespace boost::unit_test;
22
23 class FilterInit: public yp2::filter::Base {
24 public:
25     void process(yp2::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             yp2::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         return package.move();
44     };
45 };
46
47
48 BOOST_AUTO_TEST_CASE( test_filter_frontend_net_1 )
49 {
50     try 
51     {
52         {
53             yp2::filter::FrontendNet nf;
54         }
55     }
56     catch ( ... ) {
57         BOOST_CHECK (false);
58     }
59 }
60
61 BOOST_AUTO_TEST_CASE( test_filter_frontend_net_2 )
62 {
63     try 
64     {
65         {
66             yp2::RouterChain router;
67
68             FilterInit tf;
69
70             router.append(tf);
71
72             // Create package with Z39.50 init request in it
73             yp2::Package pack;
74
75             yp2::odr odr;
76             Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
77             
78             pack.request() = apdu;
79             // Done creating query. 
80
81             // Put it in router
82             pack.router(router).move(); 
83
84             // Inspect that we got Z39.50 init response
85             yazpp_1::GDU *gdu = &pack.response();
86
87             Z_GDU *z_gdu = gdu->get();
88             BOOST_CHECK(z_gdu);
89             if (z_gdu) {
90                 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
91                 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
92             }
93         }
94     }
95     catch ( ... ) {
96         BOOST_CHECK (false);
97     }
98 }
99
100 BOOST_AUTO_TEST_CASE( test_filter_frontend_net_3 )
101 {
102     try 
103     {
104         {
105             yp2::RouterChain router;
106
107             // put in frontend first
108             yp2::filter::FrontendNet filter_front;
109
110             std::vector <std::string> ports;
111             ports.insert(ports.begin(), "unix:socket");
112             filter_front.ports() = ports;
113             filter_front.listen_duration() = 1;  // listen a short time only
114             router.append(filter_front);
115
116             // put in a backend
117             FilterInit filter_init;
118             router.append(filter_init);
119
120             yp2::Package pack;
121             
122             pack.router(router).move(); 
123         }
124         BOOST_CHECK(true);
125     }
126     catch ( ... ) {
127         BOOST_CHECK (false);
128     }
129 }
130
131 /*
132  * Local variables:
133  * c-basic-offset: 4
134  * indent-tabs-mode: nil
135  * c-file-style: "stroustrup"
136  * End:
137  * vim: shiftwidth=4 tabstop=8 expandtab
138  */