Windows: use Boost 1.59, msvc 14.0
[metaproxy-moved-to-github.git] / src / test_filter_log.cpp
1 /* This file is part of Metaproxy.
2    Copyright (C) Index Data
3
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
7 version.
8
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
12 for more details.
13
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
17 */
18
19 #include "config.hpp"
20 #include <iostream>
21 #include <stdexcept>
22
23 #include "filter_log.hpp"
24 #include <metaproxy/util.hpp>
25 #include <metaproxy/router_chain.hpp>
26 #include <metaproxy/package.hpp>
27
28 #define BOOST_AUTO_TEST_MAIN
29 #define BOOST_TEST_DYN_LINK
30 #include <boost/test/auto_unit_test.hpp>
31
32 using namespace boost::unit_test;
33 namespace mp = metaproxy_1;
34
35 class FilterBounceInit: public mp::filter::Base {
36 public:
37     void process(mp::Package & package) const {
38
39         if (package.session().is_closed())
40         {
41             // std::cout << "Got Close.\n";
42         }
43
44         Z_GDU *gdu = package.request().get();
45         if (gdu && gdu->which == Z_GDU_Z3950)
46         {
47             // std::cout << "Got PDU. Sending init response\n";
48             mp::odr odr;
49             Z_APDU *apdu = odr.create_initResponse(gdu->u.z3950, 0, 0);
50             package.response() = apdu;
51         }
52         return package.move();
53     };
54     void configure(const xmlNode* ptr, bool test_only, const char *path) {};
55 };
56
57
58 BOOST_AUTO_TEST_CASE( test_filter_log_1 )
59 {
60     try
61     {
62         mp::filter::Log lf;
63     }
64     catch ( ... ) {
65         BOOST_CHECK (false);
66     }
67 }
68
69 BOOST_AUTO_TEST_CASE( test_filter_log_2 )
70 {
71     try
72     {
73         mp::RouterChain router;
74
75         mp::filter::Log lf;
76         FilterBounceInit bf;
77
78         router.append(lf);
79         router.append(bf);
80
81         // Create package with Z39.50 init request in it
82         mp::Package pack;
83
84         mp::odr odr;
85         Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
86
87         pack.request() = apdu;
88         // Done creating query.
89
90         // Put it in router
91         pack.router(router).move();
92
93         // Inspect that we got Z39.50 init response
94         yazpp_1::GDU *gdu = &pack.response();
95
96         Z_GDU *z_gdu = gdu->get();
97         BOOST_CHECK(z_gdu);
98         if (z_gdu) {
99             BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
100             BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
101         }
102     }
103     catch ( ... ) {
104         BOOST_CHECK (false);
105     }
106 }
107
108 /*
109  * Local variables:
110  * c-basic-offset: 4
111  * c-file-style: "Stroustrup"
112  * indent-tabs-mode: nil
113  * End:
114  * vim: shiftwidth=4 tabstop=8 expandtab
115  */
116