1 /* $Id: test_filter_z3950_client.cpp,v 1.13 2007-05-09 21:23:09 adam Exp $
2 Copyright (c) 2005-2007, Index Data.
4 This file is part of Metaproxy.
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
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
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
26 #include "filter_z3950_client.hpp"
29 #include "router_chain.hpp"
30 #include "session.hpp"
31 #include "package.hpp"
33 #define BOOST_AUTO_TEST_MAIN
34 #include <boost/test/auto_unit_test.hpp>
37 #include <yaz/otherinfo.h>
38 #include <yaz/oid_db.h>
40 using namespace boost::unit_test;
41 namespace mp = metaproxy_1;
43 BOOST_AUTO_UNIT_TEST( test_filter_z3950_client_1 )
47 mp::filter::Z3950Client zc; // can we construct OK?
54 BOOST_AUTO_UNIT_TEST( test_filter_z3950_client_2 )
58 mp::RouterChain router;
60 mp::filter::Z3950Client zc;
64 // Create package with Z39.50 init request in it
68 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
72 pack.request() = apdu;
75 pack.router(router).move();
77 // Inspect that we got Z39.50 init Response - a Z39.50 session MUST
78 // specify a virtual host
79 yazpp_1::GDU *gdu = &pack.response();
81 BOOST_CHECK(pack.session().is_closed());
83 Z_GDU *z_gdu = gdu->get();
86 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
87 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
95 BOOST_AUTO_UNIT_TEST( test_filter_z3950_client_3 )
99 mp::RouterChain router;
101 mp::filter::Z3950Client zc;
105 // Create package with Z39.50 present request in it
109 Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
113 pack.request() = apdu;
116 pack.router(router).move();
118 // Inspect that we got Z39.50 close - a Z39.50 session must start
120 yazpp_1::GDU *gdu = &pack.response();
122 BOOST_CHECK(pack.session().is_closed());
124 Z_GDU *z_gdu = gdu->get();
127 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
128 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_close);
136 BOOST_AUTO_UNIT_TEST( test_filter_z3950_client_4 )
140 mp::RouterChain router;
142 mp::filter::Z3950Client zc;
146 // Create package with Z39.50 init request in it
150 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
152 const char *vhost = "localhost:9999";
155 yaz_oi_set_string_oid(&apdu->u.initRequest->otherInfo,
156 odr, yaz_oid_userinfo_proxy, 1, vhost);
160 pack.request() = apdu;
163 pack.router(router).move();
165 if (pack.session().is_closed())
167 // OK, server was not up!
171 // Inspect that we got Z39.50 init response
172 yazpp_1::GDU *gdu = &pack.response();
173 Z_GDU *z_gdu = gdu->get();
176 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
177 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
190 * indent-tabs-mode: nil
191 * c-file-style: "stroustrup"
193 * vim: shiftwidth=4 tabstop=8 expandtab