GPL v2.
[metaproxy-moved-to-github.git] / src / test_filter_log.cpp
1 /* $Id: test_filter_log.cpp,v 1.12 2007-05-09 21:23:09 adam Exp $
2    Copyright (c) 2005-2007, Index Data.
3
4 This file is part of Metaproxy.
5
6 Metaproxy is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Metaproxy; see the file LICENSE.  If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.
20  */
21
22 #include "config.hpp"
23 #include <iostream>
24 #include <stdexcept>
25
26 #include "filter_log.hpp"
27 #include "util.hpp"
28 #include "router_chain.hpp"
29 #include "session.hpp"
30 #include "package.hpp"
31
32 #define BOOST_AUTO_TEST_MAIN
33 #include <boost/test/auto_unit_test.hpp>
34
35 using namespace boost::unit_test;
36 namespace mp = metaproxy_1;
37
38 class FilterBounceInit: public mp::filter::Base {
39 public:
40     void process(mp::Package & package) const {
41         
42         if (package.session().is_closed())
43         {
44             // std::cout << "Got Close.\n";
45         }
46        
47         Z_GDU *gdu = package.request().get();
48         if (gdu)
49         {
50             // std::cout << "Got PDU. Sending init response\n";
51             mp::odr odr;
52             Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse);
53             
54             apdu->u.initResponse->implementationName = "YP2/YAZ";
55             
56             package.response() = apdu;
57         }
58         return package.move();
59     };
60 };
61
62
63 BOOST_AUTO_UNIT_TEST( test_filter_log_1 )
64 {
65     try 
66     {
67         mp::filter::Log lf;
68     }
69     catch ( ... ) {
70         BOOST_CHECK (false);
71     }
72 }
73
74 BOOST_AUTO_UNIT_TEST( test_filter_log_2 )
75 {
76     try 
77     {
78         mp::RouterChain router;
79         
80         mp::filter::Log lf;
81         FilterBounceInit bf;
82         
83         router.append(lf);
84         router.append(bf);
85         
86         // Create package with Z39.50 init request in it
87         mp::Package pack;
88         
89         mp::odr odr;
90         Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
91         
92         pack.request() = apdu;
93         // Done creating query. 
94         
95         // Put it in router
96         pack.router(router).move(); 
97         
98         // Inspect that we got Z39.50 init response
99         yazpp_1::GDU *gdu = &pack.response();
100         
101         Z_GDU *z_gdu = gdu->get();
102         BOOST_CHECK(z_gdu);
103         if (z_gdu) {
104             BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
105             BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
106         }
107     }
108     catch ( ... ) {
109         BOOST_CHECK (false);
110     }
111 }
112
113 /*
114  * Local variables:
115  * c-basic-offset: 4
116  * indent-tabs-mode: nil
117  * c-file-style: "stroustrup"
118  * End:
119  * vim: shiftwidth=4 tabstop=8 expandtab
120  */