Fixed bug #1589: tests does not compile for libboost 1.34.1.
[metaproxy-moved-to-github.git] / src / test_filter_bounce.cpp
1 /* $Id: test_filter_bounce.cpp,v 1.4 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 "filter_bounce.hpp"
24 #include "util.hpp"
25 #include "gduutil.hpp"
26 //#include "sru_util.hpp"
27 #include "router_chain.hpp"
28 #include "session.hpp"
29 #include "package.hpp"
30
31 #include <iostream>
32 #include <stdexcept>
33
34 #define BOOST_AUTO_TEST_MAIN
35 #define BOOST_TEST_DYN_LINK
36 #include <boost/test/auto_unit_test.hpp>
37
38
39
40
41 using namespace boost::unit_test;
42
43 namespace mp = metaproxy_1;
44 using namespace mp::util;
45
46 void check_bounce_z3950(mp::RouterChain &router, int request, int response)
47 {
48
49     bool print = false;
50     if (print)
51         std::cout << "check_bounce_z3950\n";
52
53     // Create package with Z39.50 init request in it
54     mp::Package pack;
55         
56     mp::odr odr;
57     Z_APDU *apdu = zget_APDU(odr, request);
58
59     pack.request() = apdu;
60
61     // Put it in router
62     pack.router(router).move(); 
63     
64     // Inspect bounced back request
65     yazpp_1::GDU *gdu_req = &pack.request();
66     yazpp_1::GDU *gdu_res = &pack.response();
67     
68     Z_GDU *z_gdu_req = gdu_req->get();
69     Z_GDU *z_gdu_res = gdu_res->get();
70
71     BOOST_CHECK(z_gdu_req);
72     if (z_gdu_req) {
73         if (print)
74             std::cout << "Z_GDU " << *(z_gdu_req) << "\n";
75         BOOST_CHECK_EQUAL(z_gdu_req->which, Z_GDU_Z3950);
76         BOOST_CHECK_EQUAL(z_gdu_req->u.z3950->which, request);
77     }
78
79     BOOST_CHECK(z_gdu_res);
80     if (z_gdu_res) {
81         if (print)
82             std::cout << "Z_GDU " << *(z_gdu_res) << "\n";
83         BOOST_CHECK_EQUAL(z_gdu_res->which, Z_GDU_Z3950);
84         BOOST_CHECK_EQUAL(z_gdu_res->u.z3950->which, response);
85     }
86 }
87
88 void check_bounce_http(mp::RouterChain &router)
89 {
90
91     bool print = false;
92     if (print)
93         std::cout << "check_bounce_http\n";
94
95     // Create package with Z39.50 init request in it
96     mp::Package pack;
97         
98     mp::odr odr;
99     Z_GDU *gdu = z_get_HTTP_Request(odr);
100     //z_get_HTTP_Request_host_path(odr, host, path);
101     pack.request() = gdu;
102
103     // Put it in router
104     pack.router(router).move(); 
105     
106     // Inspect bounced back request
107     yazpp_1::GDU *gdu_req = &pack.request();
108     yazpp_1::GDU *gdu_res = &pack.response();
109     
110     Z_GDU *z_gdu_req = gdu_req->get();
111     Z_GDU *z_gdu_res = gdu_res->get();
112
113     BOOST_CHECK(z_gdu_req);
114     if (z_gdu_req) {
115         if (print)
116             std::cout << "Z_GDU " << *(z_gdu_req) << "\n";
117         BOOST_CHECK_EQUAL(z_gdu_req->which, Z_GDU_HTTP_Request);
118     }
119
120     BOOST_CHECK(z_gdu_res);
121     if (z_gdu_res) {
122         if (print)
123             std::cout << "Z_GDU " << *(z_gdu_res) << "\n";
124         BOOST_CHECK_EQUAL(z_gdu_res->which,  Z_GDU_HTTP_Response);
125     }
126 }
127
128 BOOST_AUTO_TEST_CASE( test_filter_bounce_1 )
129 {
130     try 
131     {
132         mp::filter::Bounce f_bounce;
133     }
134     catch ( ... ) {
135         BOOST_CHECK (false);
136     }
137 }
138
139 BOOST_AUTO_TEST_CASE( test_filter_bounce_2 )
140 {
141     try 
142     {
143         mp::RouterChain router;        
144         mp::filter::Bounce f_bounce;
145         router.append(f_bounce);
146
147         check_bounce_z3950(router, 
148                            Z_APDU_initRequest, Z_APDU_close);
149         //check_bounce_z3950(router, 
150         //                   Z_APDU_searchRequest, Z_APDU_close);
151         check_bounce_z3950(router, 
152                            Z_APDU_presentRequest, Z_APDU_close);
153         check_bounce_z3950(router, 
154                            Z_APDU_deleteResultSetRequest, Z_APDU_close);
155         //check_bounce_z3950(router, 
156         //                   Z_APDU_accessControlRequest, Z_APDU_close);
157         check_bounce_z3950(router, 
158                            Z_APDU_resourceControlRequest, Z_APDU_close);
159         check_bounce_z3950(router, 
160                            Z_APDU_triggerResourceControlRequest, Z_APDU_close);
161         check_bounce_z3950(router, 
162                            Z_APDU_resourceReportRequest, Z_APDU_close);
163         //check_bounce_z3950(router, 
164         //                   Z_APDU_scanRequest, Z_APDU_close);
165         //check_bounce_z3950(router, 
166         //                   Z_APDU_sortRequest, Z_APDU_close);
167         check_bounce_z3950(router, 
168                            Z_APDU_segmentRequest, Z_APDU_close);
169         //check_bounce_z3950(router, 
170         //                   Z_APDU_extendedServicesRequest, Z_APDU_close);
171         check_bounce_z3950(router, 
172                            Z_APDU_close , Z_APDU_close);
173         //check_bounce_z3950(router, 
174         //                   Z_APDU_duplicateDetectionRequest, Z_APDU_close);
175
176
177     }
178     catch ( ... ) {
179         BOOST_CHECK (false);
180     }
181 }
182
183 BOOST_AUTO_TEST_CASE( test_filter_bounce_3 )
184 {
185     try 
186     {
187         mp::RouterChain router;        
188         mp::filter::Bounce f_bounce;
189         router.append(f_bounce);
190
191         check_bounce_http(router);
192
193     }
194     catch ( ... ) {
195         BOOST_CHECK (false);
196     }
197 }
198
199 /*
200  * Local variables:
201  * c-basic-offset: 4
202  * indent-tabs-mode: nil
203  * c-file-style: "stroustrup"
204  * End:
205  * vim: shiftwidth=4 tabstop=8 expandtab
206  */