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