Fixed bug #1589: tests does not compile for libboost 1.34.1.
[metaproxy-moved-to-github.git] / src / test_filter_auth_simple.cpp
1 /* $Id: test_filter_auth_simple.cpp,v 1.6 2007-11-02 17:47:41 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_auth_simple.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 #define BOOST_TEST_DYN_LINK
34 #include <boost/test/auto_unit_test.hpp>
35
36 using namespace boost::unit_test;
37 namespace mp = metaproxy_1;
38
39 class FilterBounceInit: public mp::filter::Base {
40 public:
41     void process(mp::Package & package) const {
42         
43         if (package.session().is_closed())
44         {
45             // std::cout << "Got Close.\n";
46         }
47        
48         Z_GDU *gdu = package.request().get();
49         if (gdu)
50         {
51             // std::cout << "Got PDU. Sending init response\n";
52             mp::odr odr;
53             Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse);
54             
55             apdu->u.initResponse->implementationName = "YP2/YAZ";
56             
57             package.response() = apdu;
58         }
59         package.move();
60     };
61 };
62
63
64 BOOST_AUTO_TEST_CASE( test_filter_auth_simple_1 )
65 {
66     try 
67     {
68         mp::filter::AuthSimple lf;
69     }
70     catch ( ... ) {
71         BOOST_CHECK (false);
72     }
73 }
74
75 BOOST_AUTO_TEST_CASE( test_filter_auth_simple2 )
76 {
77     try 
78     {
79         mp::RouterChain router;
80         
81         mp::filter::AuthSimple auth;
82         FilterBounceInit bounce;
83         
84         router.append(auth);
85         router.append(bounce);
86         
87         // Create package with Z39.50 init request in it
88         mp::Package pack;
89         
90         mp::odr odr;
91         Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
92         
93         pack.request() = apdu;
94         // Done creating query. 
95         
96         // Put it in router
97         pack.router(router).move(); 
98         
99         // Inspect that we got Z39.50 init response
100         yazpp_1::GDU *gdu = &pack.response();
101         
102         Z_GDU *z_gdu = gdu->get();
103         BOOST_CHECK(z_gdu);
104         if (z_gdu) {
105             BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
106             BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
107         }
108     }
109     catch ( ... ) {
110         BOOST_CHECK (false);
111     }
112 }
113
114 /*
115  * Local variables:
116  * c-basic-offset: 4
117  * indent-tabs-mode: nil
118  * c-file-style: "stroustrup"
119  * End:
120  * vim: shiftwidth=4 tabstop=8 expandtab
121  */