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:
CPPUNIT_ASSERT_EQUAL(2,cnt);
}
-
-
};
CPPUNIT_TEST_SUITE_REGISTRATION(test_wrapper);
CPPUNIT_TEST(ignore_noserver);
CPPUNIT_TEST(ignore_finds_lateserver);
+ CPPUNIT_TEST(ignore_wrongserver);
CPPUNIT_TEST_SUITE_END();
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()
{
t2n_exec(&cmd_group_x_client::serverfunc)(1);
// launch a server
-
close_server=false;
kill_server=false;
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<ConnectionWrapper>
+ (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);
}