1 /* This file is part of Metaproxy.
2 Copyright (C) 2005-2009 Index Data
4 Metaproxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "filter_z3950_client.hpp"
26 #include "router_chain.hpp"
27 #include "session.hpp"
28 #include "package.hpp"
30 #define BOOST_AUTO_TEST_MAIN
31 #define BOOST_TEST_DYN_LINK
32 #include <boost/test/auto_unit_test.hpp>
35 #include <yaz/otherinfo.h>
36 #include <yaz/oid_db.h>
38 using namespace boost::unit_test;
39 namespace mp = metaproxy_1;
41 BOOST_AUTO_TEST_CASE( test_filter_z3950_client_1 )
45 mp::filter::Z3950Client zc; // can we construct OK?
52 BOOST_AUTO_TEST_CASE( test_filter_z3950_client_2 )
56 mp::RouterChain router;
58 mp::filter::Z3950Client zc;
62 // Create package with Z39.50 init request in it
66 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
70 pack.request() = apdu;
73 pack.router(router).move();
75 // Inspect that we got Z39.50 init Response - a Z39.50 session MUST
76 // specify a virtual host
77 yazpp_1::GDU *gdu = &pack.response();
79 BOOST_CHECK(pack.session().is_closed());
81 Z_GDU *z_gdu = gdu->get();
84 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
85 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
93 BOOST_AUTO_TEST_CASE( test_filter_z3950_client_3 )
97 mp::RouterChain router;
99 mp::filter::Z3950Client zc;
103 // Create package with Z39.50 present request in it
107 Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
111 pack.request() = apdu;
114 pack.router(router).move();
116 // Inspect that we got Z39.50 close - a Z39.50 session must start
118 yazpp_1::GDU *gdu = &pack.response();
120 BOOST_CHECK(pack.session().is_closed());
122 Z_GDU *z_gdu = gdu->get();
125 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
126 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_close);
134 BOOST_AUTO_TEST_CASE( test_filter_z3950_client_4 )
138 mp::RouterChain router;
140 mp::filter::Z3950Client zc;
144 // Create package with Z39.50 init request in it
148 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
150 const char *vhost = "localhost:9999";
153 yaz_oi_set_string_oid(&apdu->u.initRequest->otherInfo,
154 odr, yaz_oid_userinfo_proxy, 1, vhost);
158 pack.request() = apdu;
161 pack.router(router).move();
163 if (pack.session().is_closed())
165 // OK, server was not up!
169 // Inspect that we got Z39.50 init response
170 yazpp_1::GDU *gdu = &pack.response();
171 Z_GDU *z_gdu = gdu->get();
174 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
175 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
188 * c-file-style: "Stroustrup"
189 * indent-tabs-mode: nil
191 * vim: shiftwidth=4 tabstop=8 expandtab