X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Ftest_router_flexml.cpp;h=b1b79a13124a1fa8e82cce0f45753a9f203fd74a;hb=357884a3c428262e37911c9429dc122fb0243bcd;hp=5cefd7a4b637627563f28dcbbf6e4ff9a919d2fb;hpb=14d0e634d5061208301502d813d488d1e82f190b;p=metaproxy-moved-to-github.git diff --git a/src/test_router_flexml.cpp b/src/test_router_flexml.cpp index 5cefd7a..b1b79a1 100644 --- a/src/test_router_flexml.cpp +++ b/src/test_router_flexml.cpp @@ -1,4 +1,4 @@ -/* $Id: test_router_flexml.cpp,v 1.11 2006-01-04 14:30:51 adam Exp $ +/* $Id: test_router_flexml.cpp,v 1.15 2006-01-11 14:58:28 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -17,11 +17,12 @@ using namespace boost::unit_test; -static bool tfilter_destroyed = false; +static int tfilter_ref = 0; class TFilter: public yp2::filter::Base { public: void process(yp2::Package & package) const {}; - ~TFilter() { tfilter_destroyed = true; }; + TFilter() { tfilter_ref++; }; + ~TFilter() { tfilter_ref--; }; }; static yp2::filter::Base* filter_creator() @@ -29,6 +30,7 @@ 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 @@ -38,22 +40,24 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_1 ) " \n" " \n" " \n" - " 210\n" + " @:210\n" " \n" " \n" - " mylog1.log\n" - " \n" - " \n" - " \n" + " my msg\n" " \n" + " \n" " \n" - " mylog2.log\n" + " other\n" " \n" " \n" " \n" " \n" " \n" - " \n" + " \n" + " \n" + " \n" + " \n" + " \n" " \n" " \n" "\n"; @@ -61,6 +65,7 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_1 ) 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"; @@ -69,12 +74,13 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_1 ) catch ( ... ) { BOOST_CHECK (false); } - BOOST_CHECK(tfilter_destroyed == true); + 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" @@ -82,24 +88,25 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_2 ) " \n" " \n" " \n" - " 210\n"; + " @:210\n"; yp2::FactoryFilter factory; yp2::RouterFleXML rflexml(xmlconf_invalid, factory); } - catch ( yp2::RouterFleXML::XMLError &e) { - got_xml_error = true; + catch ( yp2::XMLError &e) { + std::cout << "XMLError: " << e.what() << "\n"; + got_error_as_expected = true; } catch ( std::runtime_error &e) { std::cout << "std::runtime error: " << e.what() << "\n"; - BOOST_CHECK (false); } 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 @@ -109,10 +116,10 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_3 ) " \n" " \n" " \n" - " 210\n" + " @:210\n" " \n" " \n" - " mylog.log\n" + " my msg\n" " \n" " \n" " \n" @@ -135,6 +142,41 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_3 ) } } +// 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: