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