X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Ftest_router_flexml.cpp;h=5bed848af57eb7fe2e1ed36d686ff172f24f38e4;hb=0e4bd2f722c9cf0a83e7e4ef3d936c60c9419add;hp=000ee0b44ffaa823d8dc95270e0cbb475e708e41;hpb=111438f9a883ac784b4ce743a7e83fb8a5b3ff4d;p=metaproxy-moved-to-github.git diff --git a/src/test_router_flexml.cpp b/src/test_router_flexml.cpp index 000ee0b..5bed848 100644 --- a/src/test_router_flexml.cpp +++ b/src/test_router_flexml.cpp @@ -1,4 +1,4 @@ -/* $Id: test_router_flexml.cpp,v 1.7 2005-12-08 22:32:58 adam Exp $ +/* $Id: test_router_flexml.cpp,v 1.12 2006-01-05 16:39:37 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -10,18 +10,27 @@ #include "filter.hpp" #include "router_flexml.hpp" +#include "factory_static.hpp" #define BOOST_AUTO_TEST_MAIN #include using namespace boost::unit_test; +static int tfilter_ref = 0; class TFilter: public yp2::filter::Base { public: void process(yp2::Package & package) const {}; + TFilter() { tfilter_ref++; }; + ~TFilter() { tfilter_ref--; }; }; - +static yp2::filter::Base* filter_creator() +{ + return new TFilter; +} + +// Pass well-formed XML and valid configuration to it (implicit NS) BOOST_AUTO_UNIT_TEST( test_router_flexml_1 ) { try @@ -30,50 +39,76 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_1 ) "\n" " \n" " \n" - " \n" + " \n" " 210\n" " \n" - " \n" - " mylog.log\n" + " \n" + " mylog1.log\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " mylog2.log\n" " \n" " \n" " \n" " \n" " \n" - " \n" + " \n" + " \n" + " \n" + " \n" + " \n" " \n" " \n" "\n"; - yp2::RouterFleXML rflexml(xmlconf); + + yp2::FactoryStatic factory; + factory.add_creator("tfilter", filter_creator); + yp2::RouterFleXML rflexml(xmlconf, factory); + BOOST_CHECK_EQUAL(tfilter_ref, 2); + } + catch ( std::runtime_error &e) { + std::cout << "std::runtime error: " << e.what() << "\n"; + BOOST_CHECK (false); } catch ( ... ) { BOOST_CHECK (false); } + BOOST_CHECK_EQUAL(tfilter_ref, 0); } +// Pass non-wellformed XML BOOST_AUTO_UNIT_TEST( test_router_flexml_2 ) { - bool got_xml_error = false; + bool got_error_as_expected = false; try { std::string xmlconf_invalid = "\n" "\n" " \n" " \n" - " \n" + " \n" " 210\n"; - yp2::RouterFleXML rflexml(xmlconf_invalid); + yp2::FactoryFilter factory; + yp2::RouterFleXML rflexml(xmlconf_invalid, factory); } catch ( yp2::RouterFleXML::XMLError &e) { - got_xml_error = true; + std::cout << "XMLError: " << e.what() << "\n"; + got_error_as_expected = true; + } + catch ( std::runtime_error &e) { + std::cout << "std::runtime error: " << e.what() << "\n"; } catch ( ... ) { ; } - BOOST_CHECK(got_xml_error); + BOOST_CHECK(got_error_as_expected); } +// Pass well-formed XML with explicit NS BOOST_AUTO_UNIT_TEST( test_router_flexml_3 ) { try @@ -82,7 +117,7 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_3 ) "\n" " \n" " \n" - " \n" + " \n" " 210\n" " \n" " \n" @@ -97,13 +132,53 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_3 ) " \n" "\n"; - yp2::RouterFleXML rflexml(xmlconf); + yp2::FactoryStatic factory; + yp2::RouterFleXML rflexml(xmlconf, factory); + } + catch ( std::runtime_error &e) { + std::cout << "std::runtime error: " << e.what() << "\n"; + BOOST_CHECK (false); } catch ( ... ) { BOOST_CHECK (false); } } +// Pass well-formed XML but bad filter type +BOOST_AUTO_UNIT_TEST( test_router_flexml_4 ) +{ + bool got_error_as_expected = false; + try + { + std::string xmlconf = "\n" + "\n" + " \n" + " \n" + " \n" + " 210\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n"; + + yp2::FactoryStatic factory; + factory.add_creator("tfilter", filter_creator); + yp2::RouterFleXML rflexml(xmlconf, factory); + } + catch ( yp2::FactoryFilter::NotFound &e) { + std::cout << "yp2::FactoryFilter::NotFound: " << e.what() << "\n"; + got_error_as_expected = true; + } + catch ( std::runtime_error &e) { + std::cout << "std::runtime error: " << e.what() << "\n"; + } + BOOST_CHECK(got_error_as_expected); +} + /* * Local variables: