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
18 /* $Id: test_filter_frontend_net.cpp,v 1.20 2008-02-20 15:07:53 adam Exp $
19 Copyright (c) 2005-2007, Index Data.
21 See the LICENSE file for details
29 #include "filter_frontend_net.hpp"
31 #include "router_chain.hpp"
32 #include "session.hpp"
33 #include "package.hpp"
35 #define BOOST_AUTO_TEST_MAIN
36 #define BOOST_TEST_DYN_LINK
37 #include <boost/test/auto_unit_test.hpp>
39 using namespace boost::unit_test;
40 namespace mp = metaproxy_1;
42 class FilterInit: public mp::filter::Base {
44 void process(mp::Package & package) const {
46 if (package.session().is_closed())
48 // std::cout << "Got Close.\n";
51 Z_GDU *gdu = package.request().get();
54 // std::cout << "Got PDU. Sending init response\n";
56 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse);
58 apdu->u.initResponse->implementationName = "YP2/YAZ";
60 package.response() = apdu;
62 return package.move();
67 BOOST_AUTO_TEST_CASE( test_filter_frontend_net_1 )
72 mp::filter::FrontendNet nf;
80 BOOST_AUTO_TEST_CASE( test_filter_frontend_net_2 )
85 mp::RouterChain router;
91 // Create package with Z39.50 init request in it
95 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
97 pack.request() = apdu;
98 // Done creating query.
101 pack.router(router).move();
103 // Inspect that we got Z39.50 init response
104 yazpp_1::GDU *gdu = &pack.response();
106 Z_GDU *z_gdu = gdu->get();
109 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
110 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
119 BOOST_AUTO_TEST_CASE( test_filter_frontend_net_3 )
124 mp::RouterChain router;
126 // put in frontend first
127 mp::filter::FrontendNet filter_front;
129 std::vector <std::string> ports;
130 ports.insert(ports.begin(), "unix:socket");
131 filter_front.set_ports(ports);
132 filter_front.set_listen_duration(1); // listen a short time only
133 router.append(filter_front);
136 FilterInit filter_init;
137 router.append(filter_init);
141 pack.router(router).move();
153 * indent-tabs-mode: nil
154 * c-file-style: "stroustrup"
156 * vim: shiftwidth=4 tabstop=8 expandtab