X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=test%2Fwrapper.cpp;h=8a7c16d548bbee5efc4e49c06046954e52243c2e;hp=c820531afd9a912469bdd81e922badbb78757d3c;hb=b592218402bfa779c024da2f32c4c782d52eaf88;hpb=fb3345ada7ea94225b78994fd50e3de693a2a3d5 diff --git a/test/wrapper.cpp b/test/wrapper.cpp index c820531..8a7c16d 100644 --- a/test/wrapper.cpp +++ b/test/wrapper.cpp @@ -236,10 +236,6 @@ class test_wrapper : public TestFixture CPPUNIT_TEST(ignore_server_disconnect); CPPUNIT_TEST(ignore_handler_reconnects); -// TODO: missing tests: -// ignore: init, no server, ignore -// ignore: init, no server, ignore, server ok, connect? - CPPUNIT_TEST_SUITE_END(); public: @@ -421,8 +417,6 @@ class test_wrapper : public TestFixture CPPUNIT_ASSERT_EQUAL(2,cnt); } - - }; CPPUNIT_TEST_SUITE_REGISTRATION(test_wrapper); @@ -434,6 +428,7 @@ class test_wrapper_noserver : public TestFixture CPPUNIT_TEST(ignore_noserver); CPPUNIT_TEST(ignore_finds_lateserver); + CPPUNIT_TEST(ignore_wrongserver); CPPUNIT_TEST_SUITE_END(); @@ -442,10 +437,19 @@ class test_wrapper_noserver : public TestFixture pid_t child_pid; void setUp() - { } + { + child_pid=0; + } void tearDown() - { } + { + // make sure the server-child is dead before the next test runs + if (child_pid != 0) + { + kill(child_pid,SIGKILL); + sleep(1); + } + } void ignore_noserver() { @@ -472,7 +476,6 @@ class test_wrapper_noserver : public TestFixture t2n_exec(&cmd_group_x_client::serverfunc)(1); // launch a server - close_server=false; kill_server=false; @@ -516,10 +519,62 @@ class test_wrapper_noserver : public TestFixture int i=t2n_exec(&cmd_group_x_client::serverfunc)(1); CPPUNIT_ASSERT_EQUAL(2,i); + } - // make sure the server-child is dead before the next test runs - kill(child_pid,SIGKILL); - sleep(1); + void send_hello(string hello_string, socket_server* ss, int conn_id) + { + server_connection *sc=ss->get_connection(conn_id); + sc->write(hello_string); + } + + void ignore_wrongserver() + { + wraptype::set_connection(auto_ptr + (new ReconnectIgnoreFailureSocketWrapper("./socket"))); + + // launch a server + + switch(child_pid=fork()) + { + case -1: + { + CPPUNIT_FAIL("fork error"); + break; + } + case 0: + // child + { + socket_server ss("./socket"); + + // server sends garbage + + ostringstream hello; + hello << "XYZ 123"; + + ss.add_callback(new_connection,bind(&test_wrapper_noserver::send_hello, boost::ref(*this), hello.str(),&ss, _1)); + + // max 10 sec + for (int i=0; i < 10; i++) + ss.fill_buffer(1000000); + // don't call atexit and stuff + _exit(0); + } + + default: + // parent + { + // wait till server is up + sleep(1); + } + } + + // there is no valid server + + int i=t2n_exec(&cmd_group_x_client::serverfunc)(1); + + // result is constructed with default constructor on error-and-ignore -> i=0 + + CPPUNIT_ASSERT_EQUAL(0,i); }