Implemented FilterFrontendNet which is a network server based on
[metaproxy-moved-to-github.git] / src / test_filter_frontend_net.cpp
1
2 #include "config.hpp"
3 #include <iostream>
4 #include <stdexcept>
5
6 #include "router.hpp"
7 #include "session.hpp"
8 #include "package.hpp"
9 #include "filter_frontend_net.hpp"
10
11 #define BOOST_AUTO_TEST_MAIN
12 #include <boost/test/auto_unit_test.hpp>
13
14 using namespace boost::unit_test;
15
16 class FilterInit: public yp2::Filter {
17 public:
18     yp2::Package & process(yp2::Package & package) const {
19         ODR odr = odr_createmem(ODR_ENCODE);
20         Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse);
21
22         apdu->u.initResponse->implementationName = "YP2/YAZ";
23
24         package.response() = apdu;
25         odr_destroy(odr);
26         return package.move();
27     };
28 };
29
30
31 BOOST_AUTO_TEST_CASE( test_filter_frontend_net_1 )
32 {
33     try 
34     {
35         {
36             yp2::FilterFrontendNet nf;
37         }
38         BOOST_CHECK(true);
39     }
40     catch ( ... ) {
41         BOOST_CHECK (false);
42     }
43 }
44
45 BOOST_AUTO_TEST_CASE( test_filter_frontend_net_2 )
46 {
47     try 
48     {
49         {
50             yp2::RouterChain router;
51
52             FilterInit tf;
53
54             router.rule(tf);
55
56             yp2::Session session;
57             yp2::Origin origin;
58             yp2::Package pack_in(session, origin);
59             
60             pack_in.router(router).move(); 
61
62             yazpp_1::GDU *gdu = &pack_in.response();
63
64             BOOST_CHECK_EQUAL(gdu->get()->which, Z_GDU_Z3950);
65             BOOST_CHECK_EQUAL(gdu->get()->u.z3950->which, Z_APDU_initResponse);
66         }
67         BOOST_CHECK(true);
68     }
69     catch ( ... ) {
70         BOOST_CHECK (false);
71     }
72 }
73
74 BOOST_AUTO_TEST_CASE( test_filter_frontend_net_3 )
75 {
76     try 
77     {
78         {
79             yp2::RouterChain router;
80
81             yp2::FilterFrontendNet filter_front;
82             filter_front.listen_address() = "unix:socket";
83             filter_front.listen_duration() = 2;  // listen a short time only
84             router.rule(filter_front);
85
86             FilterInit filter_init;
87             router.rule(filter_init);
88
89             yp2::Session session;
90             yp2::Origin origin;
91             yp2::Package pack_in(session, origin);
92             
93             pack_in.router(router).move(); 
94         }
95         BOOST_CHECK(true);
96     }
97     catch ( ... ) {
98         BOOST_CHECK (false);
99     }
100 }
101
102 /*
103  * Local variables:
104  * c-basic-offset: 4
105  * indent-tabs-mode: nil
106  * End:
107  * vim: shiftwidth=4 tabstop=8 expandtab
108  */