The configure method takes test_only flag so we can avoid
[metaproxy-moved-to-github.git] / src / test_filter_frontend_net.cpp
1 /* $Id: test_filter_frontend_net.cpp,v 1.20 2008-02-20 15:07:53 adam Exp $
2    Copyright (c) 2005-2007, Index Data.
3
4 This file is part of Metaproxy.
5
6 Metaproxy is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Metaproxy; see the file LICENSE.  If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.
20  */
21 /* $Id: test_filter_frontend_net.cpp,v 1.20 2008-02-20 15:07:53 adam Exp $
22    Copyright (c) 2005-2007, Index Data.
23
24    See the LICENSE file for details
25  */
26
27 #include "config.hpp"
28 #include <iostream>
29 #include <stdexcept>
30
31 #include "util.hpp"
32 #include "filter_frontend_net.hpp"
33
34 #include "router_chain.hpp"
35 #include "session.hpp"
36 #include "package.hpp"
37
38 #define BOOST_AUTO_TEST_MAIN
39 #define BOOST_TEST_DYN_LINK
40 #include <boost/test/auto_unit_test.hpp>
41
42 using namespace boost::unit_test;
43 namespace mp = metaproxy_1;
44
45 class FilterInit: public mp::filter::Base {
46 public:
47     void process(mp::Package & package) const {
48         
49         if (package.session().is_closed())
50         {
51             // std::cout << "Got Close.\n";
52         }
53        
54         Z_GDU *gdu = package.request().get();
55         if (gdu)
56         {
57             // std::cout << "Got PDU. Sending init response\n";
58             mp::odr odr;
59             Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse);
60             
61             apdu->u.initResponse->implementationName = "YP2/YAZ";
62             
63             package.response() = apdu;
64         }
65         return package.move();
66     };
67 };
68
69
70 BOOST_AUTO_TEST_CASE( test_filter_frontend_net_1 )
71 {
72     try 
73     {
74         {
75             mp::filter::FrontendNet nf;
76         }
77     }
78     catch ( ... ) {
79         BOOST_CHECK (false);
80     }
81 }
82
83 BOOST_AUTO_TEST_CASE( test_filter_frontend_net_2 )
84 {
85     try 
86     {
87         {
88             mp::RouterChain router;
89
90             FilterInit tf;
91
92             router.append(tf);
93
94             // Create package with Z39.50 init request in it
95             mp::Package pack;
96
97             mp::odr odr;
98             Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
99             
100             pack.request() = apdu;
101             // Done creating query. 
102
103             // Put it in router
104             pack.router(router).move(); 
105
106             // Inspect that we got Z39.50 init response
107             yazpp_1::GDU *gdu = &pack.response();
108
109             Z_GDU *z_gdu = gdu->get();
110             BOOST_CHECK(z_gdu);
111             if (z_gdu) {
112                 BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
113                 BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
114             }
115         }
116     }
117     catch ( ... ) {
118         BOOST_CHECK (false);
119     }
120 }
121
122 BOOST_AUTO_TEST_CASE( test_filter_frontend_net_3 )
123 {
124     try 
125     {
126         {
127             mp::RouterChain router;
128
129             // put in frontend first
130             mp::filter::FrontendNet filter_front;
131
132             std::vector <std::string> ports;
133             ports.insert(ports.begin(), "unix:socket");
134             filter_front.set_ports(ports);
135             filter_front.set_listen_duration(1);  // listen a short time only
136             router.append(filter_front);
137
138             // put in a backend
139             FilterInit filter_init;
140             router.append(filter_init);
141
142             mp::Package pack;
143             
144             pack.router(router).move(); 
145         }
146         BOOST_CHECK(true);
147     }
148     catch ( ... ) {
149         BOOST_CHECK (false);
150     }
151 }
152
153 /*
154  * Local variables:
155  * c-basic-offset: 4
156  * indent-tabs-mode: nil
157  * c-file-style: "stroustrup"
158  * End:
159  * vim: shiftwidth=4 tabstop=8 expandtab
160  */