1 /* $Id: test_filter_z3950_client.cpp,v 1.7 2005-12-02 12:21:07 adam Exp $
2 Copyright (c) 2005, 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>
23 using namespace boost::unit_test;
26 BOOST_AUTO_UNIT_TEST( test_filter_z3950_client_1 )
30 yp2::filter::Z3950Client zc; // can we construct OK?
37 BOOST_AUTO_UNIT_TEST( test_filter_z3950_client_2 )
41 yp2::RouterChain router;
43 yp2::filter::Z3950Client zc;
47 // Create package with Z39.50 init request in it
51 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
55 pack.request() = apdu;
58 pack.router(router).move();
60 // Inspect that we got Z39.50 init Response - a Z39.50 session MUST
61 // specify a virtual host
62 yazpp_1::GDU *gdu = &pack.response();
64 BOOST_CHECK(pack.session().is_closed());
66 Z_GDU *z_gdu = gdu->get();
69 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
70 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
78 BOOST_AUTO_UNIT_TEST( test_filter_z3950_client_3 )
82 yp2::RouterChain router;
84 yp2::filter::Z3950Client zc;
88 // Create package with Z39.50 present request in it
92 Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
96 pack.request() = apdu;
99 pack.router(router).move();
101 // Inspect that we got Z39.50 close - a Z39.50 session must start
103 yazpp_1::GDU *gdu = &pack.response();
105 BOOST_CHECK(pack.session().is_closed());
107 Z_GDU *z_gdu = gdu->get();
110 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
111 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_close);
119 BOOST_AUTO_UNIT_TEST( test_filter_z3950_client_4 )
123 yp2::RouterChain router;
125 yp2::filter::Z3950Client zc;
129 // Create package with Z39.50 init request in it
133 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
135 const char *vhost = "localhost:9999";
137 yaz_oi_set_string_oidval(&apdu->u.initRequest->otherInfo,
138 odr, VAL_PROXY, 1, vhost);
141 pack.request() = apdu;
144 pack.router(router).move();
146 if (pack.session().is_closed())
148 // OK, server was not up!
152 // Inspect that we got Z39.50 init response
153 yazpp_1::GDU *gdu = &pack.response();
154 Z_GDU *z_gdu = gdu->get();
157 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
158 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
171 * indent-tabs-mode: nil
172 * c-file-style: "stroustrup"
174 * vim: shiftwidth=4 tabstop=8 expandtab