1 /* $Id: test_filter_z3950_client.cpp,v 1.11 2007-04-13 09:57:51 adam Exp $
2 Copyright (c) 2005-2007, Index Data.
4 See the LICENSE file for details
11 #include "filter_z3950_client.hpp"
14 #include "router_chain.hpp"
15 #include "session.hpp"
16 #include "package.hpp"
18 #define BOOST_AUTO_TEST_MAIN
19 #include <boost/test/auto_unit_test.hpp>
22 #include <yaz/otherinfo.h>
23 #include <yaz/oid_db.h>
25 using namespace boost::unit_test;
26 namespace mp = metaproxy_1;
28 BOOST_AUTO_UNIT_TEST( test_filter_z3950_client_1 )
32 mp::filter::Z3950Client zc; // can we construct OK?
39 BOOST_AUTO_UNIT_TEST( test_filter_z3950_client_2 )
43 mp::RouterChain router;
45 mp::filter::Z3950Client zc;
49 // Create package with Z39.50 init request in it
53 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
57 pack.request() = apdu;
60 pack.router(router).move();
62 // Inspect that we got Z39.50 init Response - a Z39.50 session MUST
63 // specify a virtual host
64 yazpp_1::GDU *gdu = &pack.response();
66 BOOST_CHECK(pack.session().is_closed());
68 Z_GDU *z_gdu = gdu->get();
71 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
72 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
80 BOOST_AUTO_UNIT_TEST( test_filter_z3950_client_3 )
84 mp::RouterChain router;
86 mp::filter::Z3950Client zc;
90 // Create package with Z39.50 present request in it
94 Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
98 pack.request() = apdu;
101 pack.router(router).move();
103 // Inspect that we got Z39.50 close - a Z39.50 session must start
105 yazpp_1::GDU *gdu = &pack.response();
107 BOOST_CHECK(pack.session().is_closed());
109 Z_GDU *z_gdu = gdu->get();
112 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
113 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_close);
121 BOOST_AUTO_UNIT_TEST( test_filter_z3950_client_4 )
125 mp::RouterChain router;
127 mp::filter::Z3950Client zc;
131 // Create package with Z39.50 init request in it
135 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
137 const char *vhost = "localhost:9999";
140 const int *oid_proxy = yaz_string_to_oid(yaz_oid_std(),
143 yaz_oi_set_string_oid(&apdu->u.initRequest->otherInfo,
144 odr, oid_proxy, 1, vhost);
148 pack.request() = apdu;
151 pack.router(router).move();
153 if (pack.session().is_closed())
155 // OK, server was not up!
159 // Inspect that we got Z39.50 init response
160 yazpp_1::GDU *gdu = &pack.response();
161 Z_GDU *z_gdu = gdu->get();
164 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
165 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
178 * indent-tabs-mode: nil
179 * c-file-style: "stroustrup"
181 * vim: shiftwidth=4 tabstop=8 expandtab