Add GDU in Package class. Use classes Origin and Session
[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::Session session;
51             yp2::Origin origin;
52             yp2::Package pack_in(session, origin);
53             
54             yp2::Package pack_out = pack_in.router(router1).move(); 
55             
56             BOOST_CHECK (pack_out.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_in(session, origin);
69          
70             yp2::Package pack_out(session, origin);
71
72             pack_out = pack_in.router(router2).move();
73      
74             BOOST_CHECK (pack_out.data() == 1234);
75             
76         }
77
78     }
79     catch (std::exception &e) {
80         std::cout << e.what() << "\n";
81         BOOST_CHECK (false);
82     }
83     catch ( ...) {
84         BOOST_CHECK (false);
85     }
86
87 }
88
89 /*
90  * Local variables:
91  * c-basic-offset: 4
92  * indent-tabs-mode: nil
93  * End:
94  * vim: shiftwidth=4 tabstop=8 expandtab
95  */