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.
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 #define BOOST_TEST_DYN_LINK
35 #include <boost/test/auto_unit_test.hpp>
38 #include <yaz/otherinfo.h>
39 #include <yaz/oid_db.h>
41 using namespace boost::unit_test;
42 namespace mp = metaproxy_1;
44 BOOST_AUTO_TEST_CASE( test_filter_z3950_client_1 )
48 mp::filter::Z3950Client zc; // can we construct OK?
55 BOOST_AUTO_TEST_CASE( test_filter_z3950_client_2 )
59 mp::RouterChain router;
61 mp::filter::Z3950Client zc;
65 // Create package with Z39.50 init request in it
69 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
73 pack.request() = apdu;
76 pack.router(router).move();
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();
82 BOOST_CHECK(pack.session().is_closed());
84 Z_GDU *z_gdu = gdu->get();
87 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
88 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
96 BOOST_AUTO_TEST_CASE( test_filter_z3950_client_3 )
100 mp::RouterChain router;
102 mp::filter::Z3950Client zc;
106 // Create package with Z39.50 present request in it
110 Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
114 pack.request() = apdu;
117 pack.router(router).move();
119 // Inspect that we got Z39.50 close - a Z39.50 session must start
121 yazpp_1::GDU *gdu = &pack.response();
123 BOOST_CHECK(pack.session().is_closed());
125 Z_GDU *z_gdu = gdu->get();
128 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
129 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_close);
137 BOOST_AUTO_TEST_CASE( test_filter_z3950_client_4 )
141 mp::RouterChain router;
143 mp::filter::Z3950Client zc;
147 // Create package with Z39.50 init request in it
151 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
153 const char *vhost = "localhost:9999";
156 yaz_oi_set_string_oid(&apdu->u.initRequest->otherInfo,
157 odr, yaz_oid_userinfo_proxy, 1, vhost);
161 pack.request() = apdu;
164 pack.router(router).move();
166 if (pack.session().is_closed())
168 // OK, server was not up!
172 // Inspect that we got Z39.50 init response
173 yazpp_1::GDU *gdu = &pack.response();
174 Z_GDU *z_gdu = gdu->get();
177 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
178 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
191 * indent-tabs-mode: nil
192 * c-file-style: "stroustrup"
194 * vim: shiftwidth=4 tabstop=8 expandtab