From d1c45eadbdcb4c0f4a761437cffa4f486825026a Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 24 Jan 2023 09:20:25 +0100 Subject: [PATCH] Simplify test_filter_frontend_net (#26) --- src/test_filter_frontend_net.cpp | 120 ++++++++++++------------------- 1 file changed, 47 insertions(+), 73 deletions(-) diff --git a/src/test_filter_frontend_net.cpp b/src/test_filter_frontend_net.cpp index 38b0bef..dacdc55 100644 --- a/src/test_filter_frontend_net.cpp +++ b/src/test_filter_frontend_net.cpp @@ -33,122 +33,96 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA using namespace boost::unit_test; namespace mp = metaproxy_1; -class FilterInit: public mp::filter::Base { +class FilterInit : public mp::filter::Base +{ public: - void process(mp::Package & package) const { + void process(mp::Package &package) const + { if (package.session().is_closed()) { - // std::cout << "Got Close.\n"; + std::cout << "Got Close.\n"; } Z_GDU *gdu = package.request().get(); if (gdu && gdu->which == Z_GDU_Z3950) { - // std::cout << "Got PDU. Sending init response\n"; + std::cout << "Got PDU. Sending init response\n"; mp::odr odr; Z_APDU *apdu = odr.create_initResponse(gdu->u.z3950, 0, 0); package.response() = apdu; } return package.move(); }; - void configure(const xmlNode* ptr, bool test_only, const char *path) {}; + void configure(const xmlNode *ptr, bool test_only, const char *path){}; }; - -BOOST_AUTO_TEST_CASE( test_filter_frontend_net_1 ) +BOOST_AUTO_TEST_CASE(test_filter_frontend_net_1) { try { - { - mp::filter::FrontendNet nf; - } - } - catch (std::runtime_error &e) { - std::cerr << "std::runtime error: " << e.what() << std::endl; + mp::filter::FrontendNet nf; + nf.configure(0, true, 0); BOOST_CHECK(false); } - catch ( ... ) { - BOOST_CHECK (false); + catch (metaproxy_1::filter::FilterException &e) + { + BOOST_CHECK_EQUAL(std::string(e.what()), "FilterException: No ports for Frontend"); } } -BOOST_AUTO_TEST_CASE( test_filter_frontend_net_2 ) +BOOST_AUTO_TEST_CASE(test_filter_frontend_net_2) { - try - { - { - mp::RouterChain router; + mp::RouterChain router; - FilterInit tf; + FilterInit tf; - router.append(tf); + router.append(tf); - // Create package with Z39.50 init request in it - mp::Package pack; + // Create package with Z39.50 init request in it + mp::Package pack; - mp::odr odr; - Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest); + mp::odr odr; + Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest); - pack.request() = apdu; - // Done creating query. + pack.request() = apdu; + // Done creating query. - // Put it in router - pack.router(router).move(); + // Put it in router + pack.router(router).move(); - // Inspect that we got Z39.50 init response - yazpp_1::GDU *gdu = &pack.response(); + // Inspect that we got Z39.50 init response + yazpp_1::GDU *gdu = &pack.response(); - Z_GDU *z_gdu = gdu->get(); - BOOST_CHECK(z_gdu); - if (z_gdu) { - BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950); - BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse); - } - } - } - catch (std::runtime_error &e) { - std::cerr << "std::runtime error: " << e.what() << std::endl; - BOOST_CHECK(false); - } - catch ( ... ) { - BOOST_CHECK (false); + Z_GDU *z_gdu = gdu->get(); + BOOST_CHECK(z_gdu); + if (z_gdu) + { + BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950); + BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse); } } -BOOST_AUTO_TEST_CASE( test_filter_frontend_net_3 ) +BOOST_AUTO_TEST_CASE(test_filter_frontend_net_3) { - try - { - { - mp::RouterChain router; + mp::RouterChain router; - // put in frontend first - mp::filter::FrontendNet filter_front; + // put in frontend first + mp::filter::FrontendNet filter_front; - std::vector ports; - ports.insert(ports.begin(), "unix:socket"); - filter_front.set_ports(ports); - filter_front.set_listen_duration(1); // listen a short time only - router.append(filter_front); + std::vector ports; + ports.insert(ports.begin(), "unix:socket"); + filter_front.set_ports(ports); + filter_front.set_listen_duration(1); // listen a short time only + router.append(filter_front); - // put in a backend - FilterInit filter_init; - router.append(filter_init); + // put in a backend + FilterInit filter_init; + router.append(filter_init); - mp::Package pack; + mp::Package pack; - pack.router(router).move(); - } - BOOST_CHECK(true); - } - catch (std::runtime_error &e) { - std::cerr << "std::runtime error: " << e.what() << std::endl; - BOOST_CHECK(false); - } - catch ( ... ) { - BOOST_CHECK (false); - } + pack.router(router).move(); } /*