Make public yp2_filter_struct non-const. If not, the linker symbol
[metaproxy-moved-to-github.git] / src / test_router_flexml.cpp
1 /* $Id: test_router_flexml.cpp,v 1.9 2006-01-04 11:55:32 adam Exp $
2    Copyright (c) 2005, Index Data.
3
4 %LICENSE%
5  */
6
7 #include "config.hpp"
8 #include <iostream>
9 #include <stdexcept>
10
11 #include "filter.hpp"
12 #include "router_flexml.hpp"
13 #include "filter_factory.hpp"
14
15 #define BOOST_AUTO_TEST_MAIN
16 #include <boost/test/auto_unit_test.hpp>
17
18 using namespace boost::unit_test;
19
20 class TFilter: public yp2::filter::Base {
21 public:
22     void process(yp2::Package & package) const {};
23 };
24     
25
26 BOOST_AUTO_UNIT_TEST( test_router_flexml_1 )
27 {
28     try
29     {
30         std::string xmlconf = "<?xml version=\"1.0\"?>\n"
31             "<yp2 xmlns=\"http://indexdata.dk/yp2/config/1\">\n"
32             "  <start route=\"start\"/>\n"
33             "  <filters>\n"
34             "    <filter id=\"front_default\" type=\"frontend_net\">\n"
35             "      <port>210</port>\n"
36             "    </filter>\n"
37             "    <filter id=\"log_cout1\" type=\"log\">\n"
38             "      <logfile>mylog1.log</logfile>\n"
39             "    </filter>\n"
40             "    <filter id=\"log_cout2\" type=\"log\">\n"
41             "      <logfile>mylog2.log</logfile>\n"
42             "    </filter>\n"
43             "  </filters>\n"
44             "  <routes>\n"  
45             "    <route id=\"start\">\n"
46             "      <filter refid=\"front_default\"/>\n"
47             "      <filter refid=\"log_cout\"/>\n"
48             "    </route>\n"
49             "  </routes>\n"
50             "</yp2>\n";
51         yp2::RouterFleXML rflexml(xmlconf);
52     }
53     catch ( yp2::RouterFleXML::XMLError &e) {
54         std::cout << "XMLError: " << e.what() << "\n";
55         BOOST_CHECK (false);
56     }
57     catch ( yp2::FilterFactoryException &e) {
58         std::cout << "FilterFactoryException: " << e.what() << "\n";
59         BOOST_CHECK (false);
60     }
61     catch ( ... ) {
62         BOOST_CHECK (false);
63     }
64 }
65
66 BOOST_AUTO_UNIT_TEST( test_router_flexml_2 )
67 {
68     bool got_xml_error = false;
69     try
70     {
71         std::string xmlconf_invalid = "<?xml version=\"1.0\"?>\n"
72             "<y:yp2 xmlns:y=\"http://indexdata.dk/yp2/config/1\">\n"
73             "  <start route=\"start\"/>\n"
74             "  <filters>\n"
75             "    <filter id=\"front_default\" type=\"frontend_net\">\n"
76             "      <port>210</port>\n";
77         
78         yp2::RouterFleXML rflexml(xmlconf_invalid);
79     }
80     catch ( yp2::RouterFleXML::XMLError &e) {
81         got_xml_error = true;
82     }
83     catch ( ... ) {
84         ;
85     }
86     BOOST_CHECK(got_xml_error);
87 }
88
89 BOOST_AUTO_UNIT_TEST( test_router_flexml_3 )
90 {
91     try
92     {
93         std::string xmlconf = "<?xml version=\"1.0\"?>\n"
94             "<y:yp2 xmlns:y=\"http://indexdata.dk/yp2/config/1\">\n"
95             "  <y:start route=\"start\"/>\n"
96             "  <y:filters>\n"
97             "    <y:filter id=\"front_default\" type=\"frontend_net\">\n"
98             "      <port>210</port>\n"
99             "    </y:filter>\n"
100             "    <y:filter id=\"log_cout\" type=\"log\">\n"
101             "      <logfile>mylog.log</logfile>\n"
102             "    </y:filter>\n"
103             "  </y:filters>\n"
104             "  <y:routes>\n"  
105             "    <y:route id=\"start\">\n"
106             "      <y:filter refid=\"front_default\"/>\n"
107             "      <y:filter refid=\"log_cout\"/>\n"
108             "    </y:route>\n"
109             "  </y:routes>\n"
110             "</y:yp2>\n";
111        
112         yp2::RouterFleXML rflexml(xmlconf);
113     }
114     catch ( ... ) {
115         BOOST_CHECK (false);
116     }
117 }
118
119
120 /*
121  * Local variables:
122  * c-basic-offset: 4
123  * indent-tabs-mode: nil
124  * c-file-style: "stroustrup"
125  * End:
126  * vim: shiftwidth=4 tabstop=8 expandtab
127  */