1 /* $Id: test_filter_frontend_net.cpp,v 1.11 2005-10-29 22:23:36 marc Exp $
2 Copyright (c) 2005, Index Data.
11 #include "filter_frontend_net.hpp"
13 #include "router_chain.hpp"
14 #include "session.hpp"
15 #include "package.hpp"
17 #define BOOST_AUTO_TEST_MAIN
18 #include <boost/test/auto_unit_test.hpp>
20 using namespace boost::unit_test;
22 class FilterInit: public yp2::filter::Base {
24 void process(yp2::Package & package) const {
26 if (package.session().is_closed())
28 // std::cout << "Got Close.\n";
31 Z_GDU *gdu = package.request().get();
34 // std::cout << "Got PDU. Sending init response\n";
35 ODR odr = odr_createmem(ODR_ENCODE);
36 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse);
38 apdu->u.initResponse->implementationName = "YP2/YAZ";
40 package.response() = apdu;
43 return package.move();
45 const std::string type() const {
51 BOOST_AUTO_TEST_CASE( test_filter_frontend_net_1 )
56 yp2::filter::FrontendNet nf;
64 BOOST_AUTO_TEST_CASE( test_filter_frontend_net_2 )
69 yp2::RouterChain router;
75 // Create package with Z39.50 init request in it
78 ODR odr = odr_createmem(ODR_ENCODE);
79 Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
81 pack.request() = apdu;
83 // Done creating query.
86 pack.router(router).move();
88 // Inspect that we got Z39.50 init response
89 yazpp_1::GDU *gdu = &pack.response();
91 Z_GDU *z_gdu = gdu->get();
94 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
95 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
104 BOOST_AUTO_TEST_CASE( test_filter_frontend_net_3 )
109 yp2::RouterChain router;
111 // put in frontend first
112 yp2::filter::FrontendNet filter_front;
114 std::vector <std::string> ports;
115 ports.insert(ports.begin(), "unix:socket");
116 filter_front.ports() = ports;
117 filter_front.listen_duration() = 1; // listen a short time only
118 router.append(filter_front);
121 FilterInit filter_init;
122 router.append(filter_init);
126 pack.router(router).move();
138 * indent-tabs-mode: nil
139 * c-file-style: "stroustrup"
141 * vim: shiftwidth=4 tabstop=8 expandtab