using namespace std;
using namespace libt2n;
-// this is an evil hack to get access to real_write, don't ever do this in an app!!!
-class real_write_connection: public socket_server_connection
-{
- public:
- void real_write(const std::string& data)
- { socket_write(data); }
-};
-
-class test_helloFixture : public KillChildOnShutdownFixture
-{
-protected:
- 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 send_raw_socket(string hello_string, socket_server* ss, int conn_id)
- {
- socket_server_connection *ssc=dynamic_cast<socket_server_connection*>(ss->get_connection(conn_id));
-
- // this is an evil hack to get access to real_write, don't ever do this in an app!!!
- real_write_connection *rwc=(real_write_connection*)ssc;
- rwc->real_write(hello_string);
- }
-
-public:
- test_helloFixture()
- {
- }
-
- ~test_helloFixture()
- {
- }
-};
-BOOST_FIXTURE_TEST_SUITE(test_hello, test_helloFixture)
+BOOST_FIXTURE_TEST_SUITE(test_hello, KillChildOnShutdownFixture)
BOOST_AUTO_TEST_CASE(HelloOk)
{
using namespace std;
using namespace libt2n;
-// this is an evil hack to get access to real_write, don't ever do this in an app!!!
-class real_write_connection: public socket_server_connection
-{
- public:
- void real_write(const std::string& data)
- { socket_write(data); }
-};
-
-class test_reconnectFixture : public KillChildOnShutdownFixture
-{
-protected:
- void send_raw_socket(string hello_string, socket_server* ss, int conn_id)
- {
- socket_server_connection *ssc=dynamic_cast<socket_server_connection*>(ss->get_connection(conn_id));
-
- // this is an evil hack to get access to real_write, don't ever do this in an app!!!
- real_write_connection *rwc=(real_write_connection*)ssc;
- rwc->real_write(hello_string);
- }
-
-public:
- test_reconnectFixture()
- {
- }
-
- ~test_reconnectFixture()
- {
- }
-};
-
-BOOST_FIXTURE_TEST_SUITE(test_reconnect, test_reconnectFixture)
+BOOST_FIXTURE_TEST_SUITE(test_reconnect, KillChildOnShutdownFixture)
BOOST_AUTO_TEST_CASE(simple_reconnect)
{
#include <sys/types.h>
#include <signal.h>
+#include <socket_server.hxx>
+#include <string>
+
class KillChildOnShutdownFixture
{
protected:
pid_t child_pid;
+ // this is an evil hack to get access to real_write, don't ever do this in an app!!!
+ class real_write_connection: public libt2n::socket_server_connection
+ {
+ public:
+ void real_write(const std::string& data)
+ { socket_write(data); }
+ };
+
+ //
+ // common functions used by some tests
+ //
+ void send_hello(std::string hello_string, libt2n::socket_server* ss, int conn_id)
+ {
+ libt2n::server_connection *sc=ss->get_connection(conn_id);
+ sc->write(hello_string);
+ }
+
+ void send_raw_socket(std::string hello_string, libt2n::socket_server* ss, int conn_id)
+ {
+ libt2n::socket_server_connection *ssc=dynamic_cast<libt2n::socket_server_connection*>(ss->get_connection(conn_id));
+
+ // this is an evil hack to get access to real_write, don't ever do this in an app!!!
+ real_write_connection *rwc=(real_write_connection*)ssc;
+ rwc->real_write(hello_string);
+ }
+
public:
KillChildOnShutdownFixture()
: child_pid(0)
BOOST_CLASS_EXPORT(testfunc2_cmd)
BOOST_CLASS_EXPORT(testfunc2_res)
-// this is an evil hack to get access to real_write, don't ever do this in an app!!!
-class real_write_connection: public socket_server_connection
-{
- public:
- void real_write(const std::string& data)
- { socket_write(data); }
-};
-
-// this is an evil hack to get access to real_write, don't ever do this in an app!!!
-class real_write_client_connection: public socket_client_connection
-{
- public:
- void real_write(const std::string& data)
- { socket_write(data); }
-};
-
-
class test_timeoutFixture : public KillChildOnShutdownFixture
{
protected:
typedef uint32_t packet_size_indicator;
- void send_hello(string hello_string, socket_server* ss, unsigned int conn_id)
+ // this is an evil hack to get access to real_write, don't ever do this in an app!!!
+ class real_write_client_connection: public socket_client_connection
{
- server_connection *sc=ss->get_connection(conn_id);
- sc->write(hello_string);
- }
+ public:
+ void real_write(const std::string& data)
+ { socket_write(data); }
+ };
void send_slow_raw_socket(string data, socket_server* ss, unsigned int conn_id)
{
usleep(200000);
}
}
-
-public:
- test_timeoutFixture()
- {
- }
-
- ~test_timeoutFixture()
- {
- }
};
BOOST_FIXTURE_TEST_SUITE(test_timeout, test_timeoutFixture)
BOOST_CHECK_EQUAL(2,cnt);
}
-BOOST_AUTO_TEST_SUITE_END()
-
-
-
-class test_wrapper_noserverFixture : public KillChildOnShutdownFixture
-{
-protected:
- void send_hello(string hello_string, socket_server* ss, int conn_id)
- {
- server_connection *sc=ss->get_connection(conn_id);
- sc->write(hello_string);
- }
-public:
- test_wrapper_noserverFixture()
- {
- }
-
- ~test_wrapper_noserverFixture()
- {
- }
-};
+BOOST_AUTO_TEST_SUITE_END()
-BOOST_FIXTURE_TEST_SUITE(test_wrapper_noserver, test_wrapper_noserverFixture)
+BOOST_FIXTURE_TEST_SUITE(test_wrapper_noserver, KillChildOnShutdownFixture)
BOOST_AUTO_TEST_CASE(ignore_noserver)
{