1 /* $Id: test_filter_z3950_client.cpp,v 1.12 2007-04-16 21:54:52 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 yaz_oi_set_string_oid(&apdu->u.initRequest->otherInfo,
141 odr, yaz_oid_userinfo_proxy, 1, vhost);
145 pack.request() = apdu;
148 pack.router(router).move();
150 if (pack.session().is_closed())
152 // OK, server was not up!
156 // Inspect that we got Z39.50 init response
157 yazpp_1::GDU *gdu = &pack.response();
158 Z_GDU *z_gdu = gdu->get();
161 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
162 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
175 * indent-tabs-mode: nil
176 * c-file-style: "stroustrup"
178 * vim: shiftwidth=4 tabstop=8 expandtab