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_frontend_net.hpp"
26 #include "router_chain.hpp"
27 #include "session.hpp"
28 #include "package.hpp"
30 #define BOOST_AUTO_TEST_MAIN
31 #define BOOST_TEST_DYN_LINK
32 #include <boost/test/auto_unit_test.hpp>
34 using namespace boost::unit_test;
35 namespace mp = metaproxy_1;
37 class FilterInit: public mp::filter::Base {
39 void process(mp::Package & package) const {
41 if (package.session().is_closed())
43 // std::cout << "Got Close.\n";
46 Z_GDU *gdu = package.request().get();
49 // std::cout << "Got PDU. Sending init response\n";
51 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse);
53 apdu->u.initResponse->implementationName = "YP2/YAZ";
55 package.response() = apdu;
57 return package.move();
62 BOOST_AUTO_TEST_CASE( test_filter_frontend_net_1 )
67 mp::filter::FrontendNet nf;
75 BOOST_AUTO_TEST_CASE( test_filter_frontend_net_2 )
80 mp::RouterChain router;
86 // Create package with Z39.50 init request in it
90 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
92 pack.request() = apdu;
93 // Done creating query.
96 pack.router(router).move();
98 // Inspect that we got Z39.50 init response
99 yazpp_1::GDU *gdu = &pack.response();
101 Z_GDU *z_gdu = gdu->get();
104 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
105 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
114 BOOST_AUTO_TEST_CASE( test_filter_frontend_net_3 )
119 mp::RouterChain router;
121 // put in frontend first
122 mp::filter::FrontendNet filter_front;
124 std::vector <std::string> ports;
125 ports.insert(ports.begin(), "unix:socket");
126 filter_front.set_ports(ports);
127 filter_front.set_listen_duration(1); // listen a short time only
128 router.append(filter_front);
131 FilterInit filter_init;
132 router.append(filter_init);
136 pack.router(router).move();
148 * indent-tabs-mode: nil
149 * c-file-style: "stroustrup"
151 * vim: shiftwidth=4 tabstop=8 expandtab