Improve element checking in XML config reader
[metaproxy-moved-to-github.git] / src / test_router_flexml.cpp
1 /* $Id: test_router_flexml.cpp,v 1.7 2005-12-08 22:32:58 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
14 #define BOOST_AUTO_TEST_MAIN
15 #include <boost/test/auto_unit_test.hpp>
16
17 using namespace boost::unit_test;
18
19 class TFilter: public yp2::filter::Base {
20 public:
21     void process(yp2::Package & package) const {};
22 };
23     
24
25 BOOST_AUTO_UNIT_TEST( test_router_flexml_1 )
26 {
27     try
28     {
29         std::string xmlconf = "<?xml version=\"1.0\"?>\n"
30             "<yp2 xmlns=\"http://indexdata.dk/yp2/config/1\">\n"
31             "  <start route=\"start\"/>\n"
32             "  <filters>\n"
33             "    <filter id=\"front_default\" type=\"frontend-net\">\n"
34             "      <port>210</port>\n"
35             "    </filter>\n"
36             "    <filter id=\"log_cout\" type=\"log\">\n"
37             "      <logfile>mylog.log</logfile>\n"
38             "    </filter>\n"
39             "  </filters>\n"
40             "  <routes>\n"  
41             "    <route id=\"start\">\n"
42             "      <filter refid=\"front_default\"/>\n"
43             "      <filter refid=\"log_cout\"/>\n"
44             "    </route>\n"
45             "  </routes>\n"
46             "</yp2>\n";
47         yp2::RouterFleXML rflexml(xmlconf);
48     }
49     catch ( ... ) {
50         BOOST_CHECK (false);
51     }
52 }
53
54 BOOST_AUTO_UNIT_TEST( test_router_flexml_2 )
55 {
56     bool got_xml_error = false;
57     try
58     {
59         std::string xmlconf_invalid = "<?xml version=\"1.0\"?>\n"
60             "<y:yp2 xmlns:y=\"http://indexdata.dk/yp2/config/1\">\n"
61             "  <start route=\"start\"/>\n"
62             "  <filters>\n"
63             "    <filter id=\"front_default\" type=\"frontend-net\">\n"
64             "      <port>210</port>\n";
65         
66         yp2::RouterFleXML rflexml(xmlconf_invalid);
67     }
68     catch ( yp2::RouterFleXML::XMLError &e) {
69         got_xml_error = true;
70     }
71     catch ( ... ) {
72         ;
73     }
74     BOOST_CHECK(got_xml_error);
75 }
76
77 BOOST_AUTO_UNIT_TEST( test_router_flexml_3 )
78 {
79     try
80     {
81         std::string xmlconf = "<?xml version=\"1.0\"?>\n"
82             "<y:yp2 xmlns:y=\"http://indexdata.dk/yp2/config/1\">\n"
83             "  <y:start route=\"start\"/>\n"
84             "  <y:filters>\n"
85             "    <y:filter id=\"front_default\" type=\"frontend-net\">\n"
86             "      <port>210</port>\n"
87             "    </y:filter>\n"
88             "    <y:filter id=\"log_cout\" type=\"log\">\n"
89             "      <logfile>mylog.log</logfile>\n"
90             "    </y:filter>\n"
91             "  </y:filters>\n"
92             "  <y:routes>\n"  
93             "    <y:route id=\"start\">\n"
94             "      <y:filter refid=\"front_default\"/>\n"
95             "      <y:filter refid=\"log_cout\"/>\n"
96             "    </y:route>\n"
97             "  </y:routes>\n"
98             "</y:yp2>\n";
99        
100         yp2::RouterFleXML rflexml(xmlconf);
101     }
102     catch ( ... ) {
103         BOOST_CHECK (false);
104     }
105 }
106
107
108 /*
109  * Local variables:
110  * c-basic-offset: 4
111  * indent-tabs-mode: nil
112  * c-file-style: "stroustrup"
113  * End:
114  * vim: shiftwidth=4 tabstop=8 expandtab
115  */