Skip to content

Commit

Permalink
Simplify test_filter_frontend_net (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdickmeiss authored Jan 24, 2023
1 parent a50be1a commit d1c45ea
Showing 1 changed file with 47 additions and 73 deletions.
120 changes: 47 additions & 73 deletions src/test_filter_frontend_net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <std::string> 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<std::string> 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();
}

/*
Expand Down

0 comments on commit d1c45ea

Please sign in to comment.