Fixed bug #1589: tests does not compile for libboost 1.34.1.
[metaproxy-moved-to-github.git] / src / test_filter_backend_test.cpp
1 /* $Id: test_filter_backend_test.cpp,v 1.12 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 "util.hpp"
27 #include "filter_backend_test.hpp"
28 #include "filter_log.hpp"
29
30 #include "router_chain.hpp"
31 #include "session.hpp"
32 #include "package.hpp"
33
34 #include <yaz/zgdu.h>
35 #include <yaz/pquery.h>
36 #include <yaz/otherinfo.h>
37
38 #define BOOST_AUTO_TEST_MAIN
39 #define BOOST_TEST_DYN_LINK
40 #include <boost/test/auto_unit_test.hpp>
41 using namespace boost::unit_test;
42
43 namespace mp = metaproxy_1;
44
45 BOOST_AUTO_TEST_CASE( test_filter_backend_test_1 )
46 {
47     try 
48     {
49         mp::filter::BackendTest btest;
50     }
51     catch ( ... ) {
52         BOOST_CHECK (false);
53     }
54 }
55
56 BOOST_AUTO_TEST_CASE( test_filter_backend_test_2 )
57 {
58     try 
59     {
60         mp::RouterChain router;
61         
62         mp::filter::BackendTest btest;
63         router.append(btest);
64         
65         mp::Package pack;
66         
67         mp::odr odr;
68         Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
69         
70         BOOST_CHECK(apdu);
71         
72         pack.request() = apdu;
73         
74         // Put it in router
75         pack.router(router).move(); 
76         
77         // Inspect that we got Z39.50 init Response OK.
78         yazpp_1::GDU *gdu = &pack.response();
79         
80         BOOST_CHECK(!pack.session().is_closed()); 
81         
82         Z_GDU *z_gdu = gdu->get();
83         BOOST_CHECK(z_gdu);
84         if (z_gdu) {
85             BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
86             BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
87         }
88     }
89     catch ( ... ) {
90         BOOST_CHECK (false);
91     }
92 }
93
94 BOOST_AUTO_TEST_CASE( test_filter_backend_test_3 )
95 {
96     try 
97     {
98         mp::RouterChain router;
99         
100         mp::filter::BackendTest btest;
101         router.append(btest);
102         
103         mp::Package pack;
104         
105         // send search request as first request.. That should fail with
106         // a close from the backend
107         mp::odr odr;
108         Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchRequest);
109
110         mp::util::pqf(odr, apdu, "computer");
111         
112         apdu->u.searchRequest->num_databaseNames = 1;
113         apdu->u.searchRequest->databaseNames = (char**)
114             odr_malloc(odr, sizeof(char *));
115         apdu->u.searchRequest->databaseNames[0] = odr_strdup(odr, "Default");
116         
117         BOOST_CHECK(apdu);
118         
119         pack.request() = apdu;
120         
121         // Put it in router
122         pack.router(router).move(); 
123         
124         // Inspect that we got Z39.50 close
125         yazpp_1::GDU *gdu = &pack.response();
126         
127         BOOST_CHECK(pack.session().is_closed()); 
128         
129         Z_GDU *z_gdu = gdu->get();
130         BOOST_CHECK(z_gdu);
131         if (z_gdu) {
132             BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
133             BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_close);
134         }
135     }
136     catch ( ... ) {
137         BOOST_CHECK (false);
138     }
139 }
140
141 BOOST_AUTO_TEST_CASE( test_filter_backend_test_4 )
142 {
143     try 
144     {
145         mp::RouterChain router;
146         
147         mp::filter::BackendTest btest;
148         router.append(btest);
149         
150         mp::Package pack;
151         
152         // send present request as first request.. That should fail with
153         // a close from the backend
154         mp::odr odr;
155         Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
156
157         BOOST_CHECK(apdu);
158         
159         pack.request() = apdu;
160         
161         // Put it in router
162         pack.router(router).move(); 
163         
164         // Inspect that we got Z39.50 close
165         yazpp_1::GDU *gdu = &pack.response();
166         
167         BOOST_CHECK(pack.session().is_closed()); 
168         
169         Z_GDU *z_gdu = gdu->get();
170         BOOST_CHECK(z_gdu);
171         if (z_gdu) {
172             BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
173             BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_close);
174         }
175     }
176     catch ( ... ) {
177         BOOST_CHECK (false);
178     }
179 }
180
181
182 /*
183  * Local variables:
184  * c-basic-offset: 4
185  * indent-tabs-mode: nil
186  * c-file-style: "stroustrup"
187  * End:
188  * vim: shiftwidth=4 tabstop=8 expandtab
189  */