-/* $Id: test_filter_virt_db.cpp,v 1.18 2007-11-02 17:47:41 adam Exp $
- Copyright (c) 2005-2007, Index Data.
-
-This file is part of Metaproxy.
+/* This file is part of Metaproxy.
+ Copyright (C) Index Data
Metaproxy is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
for more details.
You should have received a copy of the GNU General Public License
-along with Metaproxy; see the file LICENSE. If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
- */
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
#include "config.hpp"
#include <iostream>
#include <stdexcept>
-#include "util.hpp"
+#include <metaproxy/util.hpp>
#include "filter_virt_db.hpp"
#include "filter_backend_test.hpp"
#include "filter_log.hpp"
-#include "router_chain.hpp"
-#include "session.hpp"
-#include "package.hpp"
+#include <metaproxy/router_chain.hpp>
+#include <metaproxy/package.hpp>
#define BOOST_AUTO_TEST_MAIN
#define BOOST_TEST_DYN_LINK
BOOST_AUTO_TEST_CASE( test_filter_virt_db_1 )
{
- try
+ try
{
mp::filter::VirtualDB vdb;
}
BOOST_AUTO_TEST_CASE( test_filter_virt_db_2 )
{
- try
+ try
{
mp::RouterChain router;
-
+
mp::filter::VirtualDB vdb;
-
+
router.append(vdb);
-
+
// Create package with Z39.50 init request in it
// Since there is not vhost given, the virt will make its
// own init response (regardless of backend)
mp::Package pack;
-
+
mp::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
-
+
BOOST_CHECK(apdu);
-
+
pack.request() = apdu;
-
+
// Put it in router
- pack.router(router).move();
-
+ pack.router(router).move();
+
// Inspect that we got Z39.50 init Response OK.
yazpp_1::GDU *gdu = &pack.response();
-
- BOOST_CHECK(!pack.session().is_closed());
-
+
+ BOOST_CHECK(!pack.session().is_closed());
+
Z_GDU *z_gdu = gdu->get();
BOOST_CHECK(z_gdu);
if (z_gdu) {
// Create package with Z39.50 init request in it
mp::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
-
+
BOOST_CHECK(apdu);
if (!apdu)
return;
-
+
pack.request() = apdu;
-
+
// Put it in router
- pack.router(router).move();
-
+ pack.router(router).move();
+
// Inspect that we got Z39.50 init response
yazpp_1::GDU *gdu = &pack.response();
-
- BOOST_CHECK(!pack.session().is_closed());
-
+
+ BOOST_CHECK(!pack.session().is_closed());
+
Z_GDU *z_gdu = gdu->get();
BOOST_CHECK(z_gdu);
if (!z_gdu)
BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
}
-
+
static void search(mp::Package &pack, mp::Router &router,
const std::string &query, const char *db,
const char *setname)
{
// Create package with Z39.50 search request in it
-
+
mp::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchRequest);
mp::util::pqf(odr, apdu, query);
apdu->u.searchRequest->resultSetName = odr_strdup(odr, setname);
-
+
apdu->u.searchRequest->num_databaseNames = 1;
apdu->u.searchRequest->databaseNames = (char**)
odr_malloc(odr, sizeof(char *));
apdu->u.searchRequest->databaseNames[0] = odr_strdup(odr, db);
-
+
BOOST_CHECK(apdu);
if (!apdu)
return;
-
+
pack.request() = apdu;
-
+
Z_GDU *gdu_test = pack.request().get();
BOOST_CHECK(gdu_test);
-
+
// Put it in router
- pack.router(router).move();
-
+ pack.router(router).move();
+
// Inspect that we got Z39.50 search response
yazpp_1::GDU *gdu = &pack.response();
-
- BOOST_CHECK(!pack.session().is_closed());
-
+
+ BOOST_CHECK(!pack.session().is_closed());
+
Z_GDU *z_gdu = gdu->get();
BOOST_CHECK(z_gdu);
if (!z_gdu)
const char *setname)
{
// Create package with Z39.50 present request in it
-
+
mp::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
-
+
apdu->u.presentRequest->resultSetId = odr_strdup(odr, setname);
*apdu->u.presentRequest->resultSetStartPoint = start;
*apdu->u.presentRequest->numberOfRecordsRequested = number;
BOOST_CHECK(apdu);
if (!apdu)
return;
-
+
pack.request() = apdu;
-
+
Z_GDU *gdu_test = pack.request().get();
BOOST_CHECK(gdu_test);
-
+
// Put it in router
- pack.router(router).move();
-
+ pack.router(router).move();
+
// Inspect that we got Z39.50 present response
yazpp_1::GDU *gdu = &pack.response();
-
- BOOST_CHECK(!pack.session().is_closed());
-
+
+ BOOST_CHECK(!pack.session().is_closed());
+
Z_GDU *z_gdu = gdu->get();
BOOST_CHECK(z_gdu);
if (!z_gdu)
BOOST_AUTO_TEST_CASE( test_filter_virt_db_3 )
{
- try
+ try
{
mp::RouterChain router;
#if 0
router.append(filter_log1);
#endif
-
- mp::filter::VirtualDB vdb;
+
+ mp::filter::VirtualDB vdb;
router.append(vdb);
vdb.add_map_db2target("Default", "localhost:210", "");
mp::filter::Log filter_log2("BACK");
mp::Session session1;
mp::Origin origin1;
-
+
{
mp::Package pack(session1, origin1);
init(pack, router);
/*
* Local variables:
* c-basic-offset: 4
+ * c-file-style: "Stroustrup"
* indent-tabs-mode: nil
- * c-file-style: "stroustrup"
* End:
* vim: shiftwidth=4 tabstop=8 expandtab
*/
+