superflous member int m_data removed from Package class
[metaproxy-moved-to-github.git] / src / test_filter_factory.cpp
1 /* $Id: test_filter_factory.cpp,v 1.14 2006-09-14 19:53:57 marc Exp $
2    Copyright (c) 2005-2006, Index Data.
3
4    See the LICENSE file for details
5 */
6
7 #include <iostream>
8 #include <stdexcept>
9
10 #include "config.hpp"
11 #include "filter.hpp"
12 #include "package.hpp"
13 #include "factory_filter.hpp"
14
15
16 #define BOOST_AUTO_TEST_MAIN
17 #include <boost/test/auto_unit_test.hpp>
18
19 using namespace boost::unit_test;
20 namespace mp = metaproxy_1;
21
22 // XFilter
23 class XFilter: public mp::filter::Base {
24 public:
25     void process(mp::Package & package) const;
26 };
27
28 void XFilter::process(mp::Package & package) const
29 {
30     //package.data() = 1;
31 }
32
33 static mp::filter::Base* xfilter_creator(){
34     return new XFilter;
35 }
36
37 // YFilter ...
38 class YFilter: public mp::filter::Base {
39 public:
40     void process(mp::Package & package) const;
41 };
42
43 void YFilter::process(mp::Package & package) const
44 {
45     //package.data() = 2;
46 }
47
48 static mp::filter::Base* yfilter_creator(){
49     return new YFilter;
50 }
51
52 BOOST_AUTO_UNIT_TEST( test_filter_factory_1 )
53 {
54     try {
55         
56         mp::FactoryFilter  ffactory;
57         
58         XFilter xf;
59         YFilter yf;
60
61         const std::string xfid = "XFilter";
62         const std::string yfid = "YFilter";
63         
64         BOOST_CHECK(ffactory.add_creator(xfid, xfilter_creator));
65         BOOST_CHECK(ffactory.drop_creator(xfid));
66         BOOST_CHECK(ffactory.add_creator(xfid, xfilter_creator));
67         BOOST_CHECK(ffactory.add_creator(yfid, yfilter_creator));
68         
69         mp::filter::Base* xfilter = 0;
70         xfilter = ffactory.create(xfid);
71         mp::filter::Base* yfilter = 0;
72         yfilter = ffactory.create(yfid);
73
74         BOOST_CHECK(0 != xfilter);
75         BOOST_CHECK(0 != yfilter);
76
77         mp::Package pack;
78         xfilter->process(pack);
79         //BOOST_CHECK_EQUAL(pack.data(), 1);
80
81         yfilter->process(pack);
82         //BOOST_CHECK_EQUAL(pack.data(), 2);
83     }
84     catch ( ... ) {
85         throw;
86         BOOST_CHECK (false);
87     }
88 }
89
90 #if HAVE_DL_SUPPORT
91 #if HAVE_DLFCN_H
92 BOOST_AUTO_UNIT_TEST( test_filter_factory_2 )
93 {
94     try {        
95         mp::FactoryFilter  ffactory;
96         
97         const std::string id = "dl";
98         
99         // first load
100         BOOST_CHECK(ffactory.add_creator_dl(id, ".libs"));
101
102         // test double load
103         BOOST_CHECK(ffactory.add_creator_dl(id, ".libs"));
104                 
105         mp::filter::Base* filter = 0;
106         filter = ffactory.create(id);
107
108         BOOST_CHECK(0 != filter);
109
110         mp::Package pack;
111         filter->process(pack);
112         //BOOST_CHECK_EQUAL(pack.data(), 42); // magic from filter_dl ..
113     }
114     catch ( ... ) {
115         throw;
116         BOOST_CHECK (false);
117     }
118 }
119 #endif
120 #endif
121
122 /*
123  * Local variables:
124  * c-basic-offset: 4
125  * indent-tabs-mode: nil
126  * c-file-style: "stroustrup"
127  * End:
128  * vim: shiftwidth=4 tabstop=8 expandtab
129  */