added test case for yp2::filter::Log, added time stamping inside log filter, added...
[metaproxy-moved-to-github.git] / src / test_filter_log.cpp
1 /* $Id: test_filter_log.cpp,v 1.1 2005-10-19 22:45:59 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 "filter_log.hpp"
12
13 #include "router.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             ODR odr = odr_createmem(ODR_ENCODE);
36             Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse);
37             
38             apdu->u.initResponse->implementationName = "YP2/YAZ";
39             
40             package.response() = apdu;
41             odr_destroy(odr);
42         }
43         return package.move();
44     };
45 };
46
47
48 BOOST_AUTO_TEST_CASE( test_filter_log_1 )
49 {
50     try 
51     {
52         {
53             yp2::filter::Log lf;
54         }
55     }
56     catch ( ... ) {
57         BOOST_CHECK (false);
58     }
59 }
60
61 BOOST_AUTO_TEST_CASE( test_filter_log_2 )
62 {
63     try 
64     {
65         {
66             yp2::RouterChain router;
67
68             yp2::filter::Log lf;
69             FilterBounceInit bf;
70
71             router.rule(lf);
72             router.rule(bf);
73
74             // Create package with Z39.50 init request in it
75             yp2::Package pack;
76
77             ODR odr = odr_createmem(ODR_ENCODE);
78             Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
79             
80             pack.request() = apdu;
81             odr_destroy(odr);
82             // Done creating query. 
83
84             // Put it in router
85             pack.router(router).move(); 
86
87             // Inspect that we got Z39.50 init response
88             yazpp_1::GDU *gdu = &pack.response();
89
90             Z_GDU *z_gdu = gdu->get();
91             BOOST_CHECK(z_gdu);
92             if (z_gdu) {
93                 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
94                 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
95             }
96         }
97     }
98     catch ( ... ) {
99         BOOST_CHECK (false);
100     }
101 }
102
103 /*
104  * Local variables:
105  * c-basic-offset: 4
106  * indent-tabs-mode: nil
107  * c-file-style: "stroustrup"
108  * End:
109  * vim: shiftwidth=4 tabstop=8 expandtab
110  */