1 /* $Id: test_filter_backend_test.cpp,v 1.12 2007-11-02 17:47:41 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 #define BOOST_TEST_DYN_LINK
40 #include <boost/test/auto_unit_test.hpp>
41 using namespace boost::unit_test;
43 namespace mp = metaproxy_1;
45 BOOST_AUTO_TEST_CASE( test_filter_backend_test_1 )
49 mp::filter::BackendTest btest;
56 BOOST_AUTO_TEST_CASE( test_filter_backend_test_2 )
60 mp::RouterChain router;
62 mp::filter::BackendTest btest;
68 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
72 pack.request() = apdu;
75 pack.router(router).move();
77 // Inspect that we got Z39.50 init Response OK.
78 yazpp_1::GDU *gdu = &pack.response();
80 BOOST_CHECK(!pack.session().is_closed());
82 Z_GDU *z_gdu = gdu->get();
85 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
86 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
94 BOOST_AUTO_TEST_CASE( test_filter_backend_test_3 )
98 mp::RouterChain router;
100 mp::filter::BackendTest btest;
101 router.append(btest);
105 // send search request as first request.. That should fail with
106 // a close from the backend
108 Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchRequest);
110 mp::util::pqf(odr, apdu, "computer");
112 apdu->u.searchRequest->num_databaseNames = 1;
113 apdu->u.searchRequest->databaseNames = (char**)
114 odr_malloc(odr, sizeof(char *));
115 apdu->u.searchRequest->databaseNames[0] = odr_strdup(odr, "Default");
119 pack.request() = apdu;
122 pack.router(router).move();
124 // Inspect that we got Z39.50 close
125 yazpp_1::GDU *gdu = &pack.response();
127 BOOST_CHECK(pack.session().is_closed());
129 Z_GDU *z_gdu = gdu->get();
132 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
133 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_close);
141 BOOST_AUTO_TEST_CASE( test_filter_backend_test_4 )
145 mp::RouterChain router;
147 mp::filter::BackendTest btest;
148 router.append(btest);
152 // send present request as first request.. That should fail with
153 // a close from the backend
155 Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
159 pack.request() = apdu;
162 pack.router(router).move();
164 // Inspect that we got Z39.50 close
165 yazpp_1::GDU *gdu = &pack.response();
167 BOOST_CHECK(pack.session().is_closed());
169 Z_GDU *z_gdu = gdu->get();
172 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
173 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_close);
185 * indent-tabs-mode: nil
186 * c-file-style: "stroustrup"
188 * vim: shiftwidth=4 tabstop=8 expandtab