Include config.hpp in all .cpp files
[metaproxy-moved-to-github.git] / src / test_filter2.cpp
1
2
3 #include "config.hpp"
4 #include "filter.hpp"
5 #include "router.hpp"
6 #include "package.hpp"
7
8 #include <iostream>
9
10 #define BOOST_AUTO_TEST_MAIN
11 #include <boost/test/auto_unit_test.hpp>
12
13 using namespace boost::unit_test;
14
15
16 class FilterConstant: public yp2::Filter {
17 public:
18     yp2::Package & process(yp2::Package & package) const {
19         package.data() = 1234;
20         return package.move();
21     };
22 };
23
24
25 class FilterDouble: public yp2::Filter {
26 public:
27     yp2::Package & process(yp2::Package & package) const {
28         package.data() = package.data() * 2;
29         return package.move();
30     };
31 };
32     
33     
34 BOOST_AUTO_TEST_CASE( testfilter2 ) 
35 {
36     try {
37         FilterConstant fc;
38         fc.name() = "FilterConstant";
39         FilterDouble fd;
40         fd.name() = "FilterDouble";
41
42         {
43             yp2::RouterChain router1;
44             
45             // test filter set/get/exception
46             router1.rule(fc);
47             
48             router1.rule(fd);
49             
50             yp2::Package pack_in;
51             
52             yp2::Package pack_out;
53             
54             pack_out = pack_in.router(router1).move(); 
55             
56             BOOST_CHECK (pack_out.data() == 2468);
57             
58         }
59         
60         {
61             
62             yp2::RouterChain router2;
63             
64             router2.rule(fd);
65             router2.rule(fc);
66             
67             yp2::Package pack_in;
68             
69             yp2::Package pack_out;
70             
71             pack_out = pack_in.router(router2).move();
72      
73             BOOST_CHECK (pack_out.data() == 1234);
74             
75         }
76
77     }
78     catch (std::exception &e) {
79         std::cout << e.what() << "\n";
80         BOOST_CHECK (false);
81     }
82     catch ( ...) {
83         BOOST_CHECK (false);
84     }
85
86 }
87
88 /*
89  * Local variables:
90  * c-basic-offset: 4
91  * indent-tabs-mode: nil
92  * End:
93  * vim: shiftwidth=4 tabstop=8 expandtab
94  */