Windows: use Boost 1.59, msvc 14.0
[metaproxy-moved-to-github.git] / src / test_filter_factory.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 <iostream>
20 #include <stdexcept>
21
22 #include "config.hpp"
23 #include <metaproxy/filter.hpp>
24 #include <metaproxy/package.hpp>
25 #include "factory_filter.hpp"
26
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 // XFilter
36 class XFilter: public mp::filter::Base {
37 public:
38     void process(mp::Package & package) const;
39     void configure(const xmlNode* ptr, bool test_only, const char *path) {};
40 };
41
42 void XFilter::process(mp::Package & package) const
43 {
44     //package.data() = 1;
45 }
46
47 static mp::filter::Base* xfilter_creator(){
48     return new XFilter;
49 }
50
51 // YFilter ...
52 class YFilter: public mp::filter::Base {
53 public:
54     void process(mp::Package & package) const;
55     void configure(const xmlNode* ptr, bool test_only, const char *path) {};
56 };
57
58 void YFilter::process(mp::Package & package) const
59 {
60     //package.data() = 2;
61 }
62
63 static mp::filter::Base* yfilter_creator(){
64     return new YFilter;
65 }
66
67 BOOST_AUTO_TEST_CASE( test_filter_factory_1 )
68 {
69     try {
70
71         mp::FactoryFilter  ffactory;
72
73         XFilter xf;
74         YFilter yf;
75
76         const std::string xfid = "XFilter";
77         const std::string yfid = "YFilter";
78
79         BOOST_CHECK(ffactory.add_creator(xfid, xfilter_creator));
80         BOOST_CHECK(ffactory.drop_creator(xfid));
81         BOOST_CHECK(ffactory.add_creator(xfid, xfilter_creator));
82         BOOST_CHECK(ffactory.add_creator(yfid, yfilter_creator));
83
84         mp::filter::Base* xfilter = 0;
85         xfilter = ffactory.create(xfid);
86         mp::filter::Base* yfilter = 0;
87         yfilter = ffactory.create(yfid);
88
89         BOOST_CHECK(0 != xfilter);
90         BOOST_CHECK(0 != yfilter);
91
92         mp::Package pack;
93         xfilter->process(pack);
94         //BOOST_CHECK_EQUAL(pack.data(), 1);
95
96         yfilter->process(pack);
97         //BOOST_CHECK_EQUAL(pack.data(), 2);
98     }
99     catch ( ... ) {
100         throw;
101         BOOST_CHECK (false);
102     }
103 }
104
105 #if HAVE_DL_SUPPORT
106 #if HAVE_DLFCN_H
107 BOOST_AUTO_TEST_CASE( test_filter_factory_2 )
108 {
109     try {
110         mp::FactoryFilter  ffactory;
111
112         const std::string id = "dl";
113
114         // first load
115         BOOST_CHECK(ffactory.add_creator_dl(id, ".libs"));
116
117         // test double load
118         BOOST_CHECK(ffactory.add_creator_dl(id, ".libs"));
119
120         mp::filter::Base* filter = 0;
121         filter = ffactory.create(id);
122
123         BOOST_CHECK(0 != filter);
124
125         mp::Package pack;
126         filter->process(pack);
127         //BOOST_CHECK_EQUAL(pack.data(), 42); // magic from filter_dl ..
128     }
129     catch ( ... ) {
130         throw;
131         BOOST_CHECK (false);
132     }
133 }
134 #endif
135 #endif
136
137 /*
138  * Local variables:
139  * c-basic-offset: 4
140  * c-file-style: "Stroustrup"
141  * indent-tabs-mode: nil
142  * End:
143  * vim: shiftwidth=4 tabstop=8 expandtab
144  */
145