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