1 /* This file is part of Metaproxy.
2 Copyright (C) 2005-2012 Index Data
4 Metaproxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <metaproxy/util.hpp>
24 #include "filter_backend_test.hpp"
25 #include "filter_log.hpp"
27 #include "router_chain.hpp"
28 #include <metaproxy/package.hpp>
31 #include <yaz/pquery.h>
32 #include <yaz/otherinfo.h>
34 #define BOOST_AUTO_TEST_MAIN
35 #define BOOST_TEST_DYN_LINK
36 #include <boost/test/auto_unit_test.hpp>
37 using namespace boost::unit_test;
39 namespace mp = metaproxy_1;
41 BOOST_AUTO_TEST_CASE( test_filter_backend_test_1 )
45 mp::filter::BackendTest btest;
52 BOOST_AUTO_TEST_CASE( test_filter_backend_test_2 )
56 mp::RouterChain router;
58 mp::filter::BackendTest btest;
64 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
68 pack.request() = apdu;
71 pack.router(router).move();
73 // Inspect that we got Z39.50 init Response OK.
74 yazpp_1::GDU *gdu = &pack.response();
76 BOOST_CHECK(!pack.session().is_closed());
78 Z_GDU *z_gdu = gdu->get();
81 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
82 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
90 BOOST_AUTO_TEST_CASE( test_filter_backend_test_3 )
94 mp::RouterChain router;
96 mp::filter::BackendTest btest;
101 // send search request as first request.. That should fail with
102 // a close from the backend
104 Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchRequest);
106 mp::util::pqf(odr, apdu, "computer");
108 apdu->u.searchRequest->num_databaseNames = 1;
109 apdu->u.searchRequest->databaseNames = (char**)
110 odr_malloc(odr, sizeof(char *));
111 apdu->u.searchRequest->databaseNames[0] = odr_strdup(odr, "Default");
115 pack.request() = apdu;
118 pack.router(router).move();
120 // Inspect that we got Z39.50 close
121 yazpp_1::GDU *gdu = &pack.response();
123 BOOST_CHECK(pack.session().is_closed());
125 Z_GDU *z_gdu = gdu->get();
128 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
129 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_close);
137 BOOST_AUTO_TEST_CASE( test_filter_backend_test_4 )
141 mp::RouterChain router;
143 mp::filter::BackendTest btest;
144 router.append(btest);
148 // send present request as first request.. That should fail with
149 // a close from the backend
151 Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
155 pack.request() = apdu;
158 pack.router(router).move();
160 // Inspect that we got Z39.50 close
161 yazpp_1::GDU *gdu = &pack.response();
163 BOOST_CHECK(pack.session().is_closed());
165 Z_GDU *z_gdu = gdu->get();
168 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
169 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_close);
181 * c-file-style: "Stroustrup"
182 * indent-tabs-mode: nil
184 * vim: shiftwidth=4 tabstop=8 expandtab