1 /* $Id: test_filter_z3950_client.cpp,v 1.8 2006-03-16 10:40:59 adam Exp $
2 Copyright (c) 2005-2006, Index Data.
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>
24 using namespace boost::unit_test;
25 namespace mp = metaproxy_1;
27 BOOST_AUTO_UNIT_TEST( test_filter_z3950_client_1 )
31 mp::filter::Z3950Client zc; // can we construct OK?
38 BOOST_AUTO_UNIT_TEST( test_filter_z3950_client_2 )
42 mp::RouterChain router;
44 mp::filter::Z3950Client zc;
48 // Create package with Z39.50 init request in it
52 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
56 pack.request() = apdu;
59 pack.router(router).move();
61 // Inspect that we got Z39.50 init Response - a Z39.50 session MUST
62 // specify a virtual host
63 yazpp_1::GDU *gdu = &pack.response();
65 BOOST_CHECK(pack.session().is_closed());
67 Z_GDU *z_gdu = gdu->get();
70 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
71 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
79 BOOST_AUTO_UNIT_TEST( test_filter_z3950_client_3 )
83 mp::RouterChain router;
85 mp::filter::Z3950Client zc;
89 // Create package with Z39.50 present request in it
93 Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
97 pack.request() = apdu;
100 pack.router(router).move();
102 // Inspect that we got Z39.50 close - a Z39.50 session must start
104 yazpp_1::GDU *gdu = &pack.response();
106 BOOST_CHECK(pack.session().is_closed());
108 Z_GDU *z_gdu = gdu->get();
111 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
112 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_close);
120 BOOST_AUTO_UNIT_TEST( test_filter_z3950_client_4 )
124 mp::RouterChain router;
126 mp::filter::Z3950Client zc;
130 // Create package with Z39.50 init request in it
134 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
136 const char *vhost = "localhost:9999";
138 yaz_oi_set_string_oidval(&apdu->u.initRequest->otherInfo,
139 odr, VAL_PROXY, 1, vhost);
142 pack.request() = apdu;
145 pack.router(router).move();
147 if (pack.session().is_closed())
149 // OK, server was not up!
153 // Inspect that we got Z39.50 init response
154 yazpp_1::GDU *gdu = &pack.response();
155 Z_GDU *z_gdu = gdu->get();
158 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
159 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
172 * indent-tabs-mode: nil
173 * c-file-style: "stroustrup"
175 * vim: shiftwidth=4 tabstop=8 expandtab