Simplified process interface. Private sub class Worker.
[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     void process(yp2::Package & package) const {
19         package.data() = 1234;
20         package.move();
21     };
22 };
23
24
25 class FilterDouble: public yp2::Filter {
26 public:
27     void process(yp2::Package & package) const {
28         package.data() = package.data() * 2;
29         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::Session session;
51             yp2::Origin origin;
52             yp2::Package pack(session, origin);
53             
54             pack.router(router1).move(); 
55             
56             BOOST_CHECK (pack.data() == 2468);
57             
58         }
59         
60         {
61             yp2::RouterChain router2;
62             
63             router2.rule(fd);
64             router2.rule(fc);
65             
66             yp2::Session session;
67             yp2::Origin origin;
68             yp2::Package pack(session, origin);
69          
70             pack.router(router2).move();
71      
72             BOOST_CHECK (pack.data() == 1234);
73             
74         }
75
76     }
77     catch (std::exception &e) {
78         std::cout << e.what() << "\n";
79         BOOST_CHECK (false);
80     }
81     catch ( ...) {
82         BOOST_CHECK (false);
83     }
84
85 }
86
87 /*
88  * Local variables:
89  * c-basic-offset: 4
90  * indent-tabs-mode: nil
91  * End:
92  * vim: shiftwidth=4 tabstop=8 expandtab
93  */