1 /* $Id: test_router_flexml.cpp,v 1.11 2006-01-04 14:30:51 adam Exp $
2 Copyright (c) 2005, Index Data.
12 #include "router_flexml.hpp"
13 #include "factory_static.hpp"
15 #define BOOST_AUTO_TEST_MAIN
16 #include <boost/test/auto_unit_test.hpp>
18 using namespace boost::unit_test;
20 static bool tfilter_destroyed = false;
21 class TFilter: public yp2::filter::Base {
23 void process(yp2::Package & package) const {};
24 ~TFilter() { tfilter_destroyed = true; };
27 static yp2::filter::Base* filter_creator()
32 BOOST_AUTO_UNIT_TEST( test_router_flexml_1 )
36 std::string xmlconf = "<?xml version=\"1.0\"?>\n"
37 "<yp2 xmlns=\"http://indexdata.dk/yp2/config/1\">\n"
38 " <start route=\"start\"/>\n"
40 " <filter id=\"front_default\" type=\"frontend_net\">\n"
43 " <filter id=\"log_cout1\" type=\"log\">\n"
44 " <logfile>mylog1.log</logfile>\n"
46 " <filter id=\"tfilter_id\" type=\"tfilter\">\n"
49 " <filter id=\"log_cout2\" type=\"log\">\n"
50 " <logfile>mylog2.log</logfile>\n"
54 " <route id=\"start\">\n"
55 " <filter refid=\"front_default\"/>\n"
56 " <filter refid=\"log_cout\"/>\n"
61 yp2::FactoryStatic factory;
62 factory.add_creator("tfilter", filter_creator);
63 yp2::RouterFleXML rflexml(xmlconf, factory);
65 catch ( std::runtime_error &e) {
66 std::cout << "std::runtime error: " << e.what() << "\n";
72 BOOST_CHECK(tfilter_destroyed == true);
75 BOOST_AUTO_UNIT_TEST( test_router_flexml_2 )
77 bool got_xml_error = false;
80 std::string xmlconf_invalid = "<?xml version=\"1.0\"?>\n"
81 "<y:yp2 xmlns:y=\"http://indexdata.dk/yp2/config/1\">\n"
82 " <start route=\"start\"/>\n"
84 " <filter id=\"front_default\" type=\"frontend_net\">\n"
85 " <port>210</port>\n";
87 yp2::FactoryFilter factory;
88 yp2::RouterFleXML rflexml(xmlconf_invalid, factory);
90 catch ( yp2::RouterFleXML::XMLError &e) {
93 catch ( std::runtime_error &e) {
94 std::cout << "std::runtime error: " << e.what() << "\n";
100 BOOST_CHECK(got_xml_error);
103 BOOST_AUTO_UNIT_TEST( test_router_flexml_3 )
107 std::string xmlconf = "<?xml version=\"1.0\"?>\n"
108 "<y:yp2 xmlns:y=\"http://indexdata.dk/yp2/config/1\">\n"
109 " <y:start route=\"start\"/>\n"
111 " <y:filter id=\"front_default\" type=\"frontend_net\">\n"
112 " <port>210</port>\n"
114 " <y:filter id=\"log_cout\" type=\"log\">\n"
115 " <logfile>mylog.log</logfile>\n"
119 " <y:route id=\"start\">\n"
120 " <y:filter refid=\"front_default\"/>\n"
121 " <y:filter refid=\"log_cout\"/>\n"
126 yp2::FactoryStatic factory;
127 yp2::RouterFleXML rflexml(xmlconf, factory);
129 catch ( std::runtime_error &e) {
130 std::cout << "std::runtime error: " << e.what() << "\n";
142 * indent-tabs-mode: nil
143 * c-file-style: "stroustrup"
145 * vim: shiftwidth=4 tabstop=8 expandtab