1 /* This file is part of Metaproxy.
2 Copyright (C) 2005-2011 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
23 #include <metaproxy/util.hpp>
24 #include "filter_frontend_net.hpp"
26 #include "router_chain.hpp"
27 #include <metaproxy/package.hpp>
29 #define BOOST_AUTO_TEST_MAIN
30 #define BOOST_TEST_DYN_LINK
31 #include <boost/test/auto_unit_test.hpp>
33 using namespace boost::unit_test;
34 namespace mp = metaproxy_1;
36 class FilterInit: public mp::filter::Base {
38 void process(mp::Package & package) const {
40 if (package.session().is_closed())
42 // std::cout << "Got Close.\n";
45 Z_GDU *gdu = package.request().get();
46 if (gdu && gdu->which == Z_GDU_Z3950)
48 // std::cout << "Got PDU. Sending init response\n";
50 Z_APDU *apdu = odr.create_initResponse(gdu->u.z3950, 0, 0);
51 package.response() = apdu;
53 return package.move();
58 BOOST_AUTO_TEST_CASE( test_filter_frontend_net_1 )
63 mp::filter::FrontendNet nf;
66 catch (std::runtime_error &e) {
67 std::cerr << "std::runtime error: " << e.what() << std::endl;
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);
109 catch (std::runtime_error &e) {
110 std::cerr << "std::runtime error: " << e.what() << std::endl;
118 BOOST_AUTO_TEST_CASE( test_filter_frontend_net_3 )
123 mp::RouterChain router;
125 // put in frontend first
126 mp::filter::FrontendNet filter_front;
128 std::vector <std::string> ports;
129 ports.insert(ports.begin(), "unix:socket");
130 filter_front.set_ports(ports);
131 filter_front.set_listen_duration(1); // listen a short time only
132 router.append(filter_front);
135 FilterInit filter_init;
136 router.append(filter_init);
140 pack.router(router).move();
144 catch (std::runtime_error &e) {
145 std::cerr << "std::runtime error: " << e.what() << std::endl;
156 * c-file-style: "Stroustrup"
157 * indent-tabs-mode: nil
159 * vim: shiftwidth=4 tabstop=8 expandtab