1 /* $Id: test_filter_z3950_client.cpp,v 1.3 2005-10-24 14:33:30 adam Exp $
2 Copyright (c) 2005, Index Data.
11 #include "filter_z3950_client.hpp"
14 #include "session.hpp"
15 #include "package.hpp"
17 #define BOOST_AUTO_TEST_MAIN
18 #include <boost/test/auto_unit_test.hpp>
21 #include <yaz/otherinfo.h>
22 using namespace boost::unit_test;
25 BOOST_AUTO_TEST_CASE( test_filter_z3950_client_1 )
29 yp2::filter::Z3950Client zc; // can we construct OK?
36 BOOST_AUTO_TEST_CASE( test_filter_z3950_client_2 )
40 yp2::RouterChain router;
42 yp2::filter::Z3950Client zc;
46 // Create package with Z39.50 init request in it
49 ODR odr = odr_createmem(ODR_ENCODE);
50 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
54 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_TEST_CASE( test_filter_z3950_client_3 )
82 yp2::RouterChain router;
84 yp2::filter::Z3950Client zc;
88 // Create package with Z39.50 present request in it
91 ODR odr = odr_createmem(ODR_ENCODE);
92 Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
96 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_TEST_CASE( test_filter_z3950_client_4 )
124 yp2::RouterChain router;
126 yp2::filter::Z3950Client zc;
130 // Create package with Z39.50 init request in it
133 ODR odr = odr_createmem(ODR_ENCODE);
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;
146 pack.router(router).move();
148 if (pack.session().is_closed())
150 // OK, server was not up!
154 // Inspect that we got Z39.50 init response
155 yazpp_1::GDU *gdu = &pack.response();
156 Z_GDU *z_gdu = gdu->get();
159 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
160 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
173 * indent-tabs-mode: nil
174 * c-file-style: "stroustrup"
176 * vim: shiftwidth=4 tabstop=8 expandtab