filter factory in working shape, see example in test_filer_factory.cpp
[metaproxy-moved-to-github.git] / src / test_filter_factory.cpp
1 /* $Id: test_filter_factory.cpp,v 1.3 2005-10-29 22:23:36 marc Exp $
2    Copyright (c) 2005, Index Data.
3
4 %LICENSE%
5
6 */
7
8
9 #include <iostream>
10 #include <stdexcept>
11
12 #include "config.hpp"
13 #include "filter.hpp"
14 #include "filter_factory.hpp"
15
16
17 #define BOOST_AUTO_TEST_MAIN
18 #include <boost/test/auto_unit_test.hpp>
19
20 using namespace boost::unit_test;
21
22 class XFilter: public yp2::filter::Base {
23 public:
24     void process(yp2::Package & package) const {};
25      const std::string type() const{
26         return "XFilter";
27     };
28 };
29
30
31 yp2::filter::Base* xfilter_creator(){
32     return new XFilter;
33 }
34
35 class YFilter: public yp2::filter::Base {
36 public:
37     void process(yp2::Package & package) const {};
38     const std::string type() const{
39         return "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         XFilter xf;
57         YFilter yf;
58
59         const std::string xfid = xf.type();
60         const std::string yfid = yf.type();
61         
62         //std::cout << "Xfilter name: " << xfid << std::endl;
63         //std::cout << "Yfilter name: " << yfid << std::endl;
64
65         BOOST_CHECK_EQUAL(ffactory.add_creator(xfid, xfilter_creator),
66                           true);
67         BOOST_CHECK_EQUAL(ffactory.drop_creator(xfid),
68                           true);
69         BOOST_CHECK_EQUAL(ffactory.add_creator(xfid, xfilter_creator),
70                           true);
71         BOOST_CHECK_EQUAL(ffactory.add_creator(yfid, yfilter_creator),
72                           true);
73         
74         yp2::filter::Base* xfilter = ffactory.create(xfid);
75         yp2::filter::Base* yfilter = ffactory.create(yfid);
76
77         BOOST_CHECK_EQUAL(xf.type(), xfilter->type());
78         BOOST_CHECK_EQUAL(yf.type(), yfilter->type());
79
80         //std::cout << "Xfilter pointer name:  " << xfilter->type() << std::endl;
81         //std::cout << "Yfilter pointer name:  " << yfilter->type() << std::endl;
82         
83
84         }
85     catch ( ... ) {
86         throw;
87         BOOST_CHECK (false);
88     }
89         
90     std::exit(0);
91 }
92
93
94
95
96
97             // get function - right val in assignment
98             //std::string name() const {
99                 //return m_name;
100             //  return "Base";
101             //}
102             
103             // set function - left val in assignment
104             //std::string & name() {
105             //    return m_name;
106             //}
107             
108             // set function - can be chained
109             //Base & name(const std::string & name){
110             //  m_name = name;
111             //  return *this;
112             //}
113             
114
115 /*
116  * Local variables:
117  * c-basic-offset: 4
118  * indent-tabs-mode: nil
119  * c-file-style: "stroustrup"
120  * End:
121  * vim: shiftwidth=4 tabstop=8 expandtab
122  */