first functional filter factory implementation plus test case added
[metaproxy-moved-to-github.git] / src / test_filter_factory.cpp
1 /* $Id: test_filter_factory.cpp,v 1.2 2005-10-29 17:58:14 marc Exp $
2    Copyright (c) 2005, Index Data.
3
4 %LICENSE%
5  */
6
7
8 #include <iostream>
9 #include <stdexcept>
10
11 #include "config.hpp"
12 #include "filter.hpp"
13 #include "filter_factory.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
21 class XFilter: public yp2::filter::Base {
22 public:
23     void process(yp2::Package & package) const {};
24     std::string name(){
25         return std::string("xfilter");
26         }   
27 };
28
29
30 yp2::filter::Base* xfilter_creator(){
31     return new XFilter;
32 }
33
34
35 class YFilter: public yp2::filter::Base {
36 public:
37     void process(yp2::Package & package) const {};
38     std::string name(){
39         return std::string("yfilter");
40         }   
41 };
42
43 yp2::filter::Base* yfilter_creator(){
44     return new YFilter;
45 }
46
47
48
49 //int main(int argc, char **argv)
50 BOOST_AUTO_TEST_CASE( test_filter_factory_1 )
51 {
52     try {
53         
54         yp2::filter::FilterFactory  ffactory;
55         
56         BOOST_CHECK_EQUAL(ffactory.add_creator("xfilter", xfilter_creator),
57                           true);
58         BOOST_CHECK_EQUAL(ffactory.drop_creator("xfilter"),
59                           true);
60         BOOST_CHECK_EQUAL(ffactory.add_creator("xfilter", xfilter_creator),
61                           true);
62         BOOST_CHECK_EQUAL(ffactory.add_creator("yfilter", yfilter_creator),
63                           true);
64         
65         yp2::filter::Base* xfilter = ffactory.create("xfilter");
66         yp2::filter::Base* yfilter = ffactory.create("yfilter");
67         
68         //BOOST_CHECK_EQUAL(xfilter->name(), std::string("xfilter"));
69         //BOOST_CHECK_EQUAL(yfilter->name(), std::string("yfilter"));
70         
71         }
72     catch ( ... ) {
73         BOOST_CHECK (false);
74     }
75         
76     std::exit(0);
77 }
78
79
80 /*
81  * Local variables:
82  * c-basic-offset: 4
83  * indent-tabs-mode: nil
84  * c-file-style: "stroustrup"
85  * End:
86  * vim: shiftwidth=4 tabstop=8 expandtab
87  */