1 /* This file is part of Metaproxy.
2 Copyright (C) 2005-2008 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
24 #include "filter_backend_test.hpp"
25 #include "filter_log.hpp"
27 #include "router_chain.hpp"
28 #include "session.hpp"
29 #include "package.hpp"
32 #include <yaz/pquery.h>
33 #include <yaz/otherinfo.h>
35 #define BOOST_AUTO_TEST_MAIN
36 #define BOOST_TEST_DYN_LINK
37 #include <boost/test/auto_unit_test.hpp>
38 using namespace boost::unit_test;
40 namespace mp = metaproxy_1;
42 BOOST_AUTO_TEST_CASE( test_filter_backend_test_1 )
46 mp::filter::BackendTest btest;
53 BOOST_AUTO_TEST_CASE( test_filter_backend_test_2 )
57 mp::RouterChain router;
59 mp::filter::BackendTest btest;
65 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
69 pack.request() = apdu;
72 pack.router(router).move();
74 // Inspect that we got Z39.50 init Response OK.
75 yazpp_1::GDU *gdu = &pack.response();
77 BOOST_CHECK(!pack.session().is_closed());
79 Z_GDU *z_gdu = gdu->get();
82 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
83 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
91 BOOST_AUTO_TEST_CASE( test_filter_backend_test_3 )
95 mp::RouterChain router;
97 mp::filter::BackendTest btest;
102 // send search request as first request.. That should fail with
103 // a close from the backend
105 Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchRequest);
107 mp::util::pqf(odr, apdu, "computer");
109 apdu->u.searchRequest->num_databaseNames = 1;
110 apdu->u.searchRequest->databaseNames = (char**)
111 odr_malloc(odr, sizeof(char *));
112 apdu->u.searchRequest->databaseNames[0] = odr_strdup(odr, "Default");
116 pack.request() = apdu;
119 pack.router(router).move();
121 // Inspect that we got Z39.50 close
122 yazpp_1::GDU *gdu = &pack.response();
124 BOOST_CHECK(pack.session().is_closed());
126 Z_GDU *z_gdu = gdu->get();
129 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
130 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_close);
138 BOOST_AUTO_TEST_CASE( test_filter_backend_test_4 )
142 mp::RouterChain router;
144 mp::filter::BackendTest btest;
145 router.append(btest);
149 // send present request as first request.. That should fail with
150 // a close from the backend
152 Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
156 pack.request() = apdu;
159 pack.router(router).move();
161 // Inspect that we got Z39.50 close
162 yazpp_1::GDU *gdu = &pack.response();
164 BOOST_CHECK(pack.session().is_closed());
166 Z_GDU *z_gdu = gdu->get();
169 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
170 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_close);
182 * indent-tabs-mode: nil
183 * c-file-style: "stroustrup"
185 * vim: shiftwidth=4 tabstop=8 expandtab