1 /* $Id: test_filter_backend_test.cpp,v 1.11 2007-05-09 21:23:09 adam Exp $
2 Copyright (c) 2005-2007, Index Data.
4 This file is part of Metaproxy.
6 Metaproxy is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with Metaproxy; see the file LICENSE. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 #include "filter_backend_test.hpp"
28 #include "filter_log.hpp"
30 #include "router_chain.hpp"
31 #include "session.hpp"
32 #include "package.hpp"
35 #include <yaz/pquery.h>
36 #include <yaz/otherinfo.h>
38 #define BOOST_AUTO_TEST_MAIN
39 #include <boost/test/auto_unit_test.hpp>
40 using namespace boost::unit_test;
42 namespace mp = metaproxy_1;
44 BOOST_AUTO_UNIT_TEST( test_filter_backend_test_1 )
48 mp::filter::BackendTest btest;
55 BOOST_AUTO_UNIT_TEST( test_filter_backend_test_2 )
59 mp::RouterChain router;
61 mp::filter::BackendTest btest;
67 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
71 pack.request() = apdu;
74 pack.router(router).move();
76 // Inspect that we got Z39.50 init Response OK.
77 yazpp_1::GDU *gdu = &pack.response();
79 BOOST_CHECK(!pack.session().is_closed());
81 Z_GDU *z_gdu = gdu->get();
84 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
85 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
93 BOOST_AUTO_UNIT_TEST( test_filter_backend_test_3 )
97 mp::RouterChain router;
99 mp::filter::BackendTest btest;
100 router.append(btest);
104 // send search request as first request.. That should fail with
105 // a close from the backend
107 Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchRequest);
109 mp::util::pqf(odr, apdu, "computer");
111 apdu->u.searchRequest->num_databaseNames = 1;
112 apdu->u.searchRequest->databaseNames = (char**)
113 odr_malloc(odr, sizeof(char *));
114 apdu->u.searchRequest->databaseNames[0] = odr_strdup(odr, "Default");
118 pack.request() = apdu;
121 pack.router(router).move();
123 // Inspect that we got Z39.50 close
124 yazpp_1::GDU *gdu = &pack.response();
126 BOOST_CHECK(pack.session().is_closed());
128 Z_GDU *z_gdu = gdu->get();
131 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
132 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_close);
140 BOOST_AUTO_UNIT_TEST( test_filter_backend_test_4 )
144 mp::RouterChain router;
146 mp::filter::BackendTest btest;
147 router.append(btest);
151 // send present request as first request.. That should fail with
152 // a close from the backend
154 Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
158 pack.request() = apdu;
161 pack.router(router).move();
163 // Inspect that we got Z39.50 close
164 yazpp_1::GDU *gdu = &pack.response();
166 BOOST_CHECK(pack.session().is_closed());
168 Z_GDU *z_gdu = gdu->get();
171 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
172 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_close);
184 * indent-tabs-mode: nil
185 * c-file-style: "stroustrup"
187 * vim: shiftwidth=4 tabstop=8 expandtab