In tests use BOOST_AUTO_UNIT_TEST instead of BOOST_AUTO_TEST_CASE
[metaproxy-moved-to-github.git] / src / test_filter_factory.cpp
1 /* $Id: test_filter_factory.cpp,v 1.6 2005-12-02 12:21:07 adam 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 };
26
27
28 yp2::filter::Base* xfilter_creator(){
29     return new XFilter;
30 }
31
32 class YFilter: public yp2::filter::Base {
33 public:
34     void process(yp2::Package & package) const {};
35 };
36
37 yp2::filter::Base* yfilter_creator(){
38     return new YFilter;
39 }
40
41
42 BOOST_AUTO_UNIT_TEST( test_filter_factory_1 )
43 {
44     try {
45         
46         yp2::FilterFactory  ffactory;
47         
48         XFilter xf;
49         YFilter yf;
50
51         const std::string xfid = "XFilter";
52         const std::string yfid = "YFilter";
53         
54         //std::cout << "Xfilter name: " << xfid << std::endl;
55         //std::cout << "Yfilter name: " << yfid << std::endl;
56
57         BOOST_CHECK_EQUAL(ffactory.add_creator(xfid, xfilter_creator),
58                           true);
59         BOOST_CHECK_EQUAL(ffactory.drop_creator(xfid),
60                           true);
61         BOOST_CHECK_EQUAL(ffactory.add_creator(xfid, xfilter_creator),
62                           true);
63         BOOST_CHECK_EQUAL(ffactory.add_creator(yfid, yfilter_creator),
64                           true);
65         
66         yp2::filter::Base* xfilter = 0;
67         xfilter = ffactory.create(xfid);
68         yp2::filter::Base* yfilter = 0;
69         yfilter = ffactory.create(yfid);
70
71         //BOOST_CHECK_EQUAL(sizeof(xf), sizeof(*xfilter));
72         //BOOST_CHECK_EQUAL(sizeof(yf), sizeof(*yfilter));
73
74         BOOST_CHECK(0 != xfilter);
75         BOOST_CHECK(0 != yfilter);
76     }
77     catch ( ... ) {
78         throw;
79         BOOST_CHECK (false);
80     }
81         
82     std::exit(0);
83 }
84
85 // get function - right val in assignment
86 //std::string name() const {
87 //return m_name;
88 //  return "Base";
89 //}
90
91 // set function - left val in assignment
92 //std::string & name() {
93 //    return m_name;
94 //}
95
96 // set function - can be chained
97 //Base & name(const std::string & name){
98 //  m_name = name;
99 //  return *this;
100 //}
101
102
103 /*
104  * Local variables:
105  * c-basic-offset: 4
106  * indent-tabs-mode: nil
107  * c-file-style: "stroustrup"
108  * End:
109  * vim: shiftwidth=4 tabstop=8 expandtab
110  */