[Box Backup-commit] COMMIT r1523 - box/chris/general/test/basicserver
boxbackup-dev@fluffy.co.uk
boxbackup-dev@fluffy.co.uk
Fri, 20 Apr 2007 23:20:22 +0100
Author: chris
Date: 2007-04-20 23:20:22 +0100 (Fri, 20 Apr 2007)
New Revision: 1523
Modified:
box/chris/general/test/basicserver/testbasicserver.cpp
Log:
Remove winsock initialisation, no longer needed now that the
buildenv-testmain-template.cpp does it for us.
Use unified LaunchServer which converts paths to remove #ifdefs.
Add spaces to improve code formatting.
Indent short #ifdefs to look more like if() statements.
Modified: box/chris/general/test/basicserver/testbasicserver.cpp
===================================================================
--- box/chris/general/test/basicserver/testbasicserver.cpp 2007-04-20 22:08:07 UTC (rev 1522)
+++ box/chris/general/test/basicserver/testbasicserver.cpp 2007-04-20 22:20:22 UTC (rev 1523)
@@ -431,26 +431,13 @@
}
}
-#ifdef WIN32
- // Under win32 we must initialise the Winsock library
- // before using sockets
+ //printf("SKIPPING TESTS------------------------\n");
+ //goto protocolserver;
- WSADATA info;
- TEST_THAT(WSAStartup(0x0101, &info) != SOCKET_ERROR)
-#endif
-
-//printf("SKIPPING TESTS------------------------\n");
-//goto protocolserver;
-
// Launch a basic server
{
-#ifdef WIN32
- int pid = LaunchServer("test srv1 testfiles\\srv1.conf",
- "testfiles\\srv1.pid");
-#else
int pid = LaunchServer("./test srv1 testfiles/srv1.conf",
"testfiles/srv1.pid");
-#endif
TEST_THAT(pid != -1 && pid != 0);
if(pid > 0)
@@ -459,109 +446,123 @@
TEST_THAT(TestFileExists("testfiles"
DIRECTORY_SEPARATOR "srv1.test1"));
TEST_THAT(ServerIsAlive(pid));
+
// Move the config file over
-#ifdef WIN32
- TEST_THAT(::unlink("testfiles" DIRECTORY_SEPARATOR
- "srv1.conf") != -1);
-#endif
+ #ifdef WIN32
+ TEST_THAT(::unlink("testfiles"
+ DIRECTORY_SEPARATOR "srv1.conf") != -1);
+ #endif
+
TEST_THAT(::rename(
"testfiles" DIRECTORY_SEPARATOR "srv1b.conf",
"testfiles" DIRECTORY_SEPARATOR "srv1.conf")
!= -1);
-#ifndef WIN32
- // Get it to reread the config file
- TEST_THAT(HUPServer(pid));
- ::sleep(1);
- TEST_THAT(ServerIsAlive(pid));
- // Check that new file exists
- TEST_THAT(TestFileExists("testfiles"
- DIRECTORY_SEPARATOR "srv1.test2"));
-#endif // !WIN32
+
+ #ifndef WIN32
+ // Get it to reread the config file
+ TEST_THAT(HUPServer(pid));
+ ::sleep(1);
+ TEST_THAT(ServerIsAlive(pid));
+ // Check that new file exists
+ TEST_THAT(TestFileExists("testfiles"
+ DIRECTORY_SEPARATOR "srv1.test2"));
+ #endif // !WIN32
+
// Kill it off
TEST_THAT(KillServer(pid));
-#ifndef WIN32
- TestRemoteProcessMemLeaks("generic-daemon.memleaks");
-#endif // !WIN32
+
+ #ifndef WIN32
+ TestRemoteProcessMemLeaks(
+ "generic-daemon.memleaks");
+ #endif // !WIN32
}
}
// Launch a test forking server
{
-#ifdef WIN32
- int pid = LaunchServer("test srv2 testfiles\\srv2.conf",
- "testfiles\\srv2.pid");
-#else
int pid = LaunchServer("./test srv2 testfiles/srv2.conf",
"testfiles/srv2.pid");
-#endif
TEST_THAT(pid != -1 && pid != 0);
+
if(pid > 0)
{
// Will it restart?
TEST_THAT(ServerIsAlive(pid));
-#ifndef WIN32
- TEST_THAT(HUPServer(pid));
- ::sleep(1);
- TEST_THAT(ServerIsAlive(pid));
-#endif // !WIN32
+
+ #ifndef WIN32
+ TEST_THAT(HUPServer(pid));
+ ::sleep(1);
+ TEST_THAT(ServerIsAlive(pid));
+ #endif // !WIN32
+
// Make some connections
{
SocketStream conn1;
conn1.Open(Socket::TypeINET, "localhost", 2003);
-#ifndef WIN32
- SocketStream conn2;
- conn2.Open(Socket::TypeUNIX, "testfiles/srv2.sock");
- SocketStream conn3;
- conn3.Open(Socket::TypeINET, "localhost", 2003);
-#endif // !WIN32
+
+ #ifndef WIN32
+ SocketStream conn2;
+ conn2.Open(Socket::TypeUNIX,
+ "testfiles/srv2.sock");
+ SocketStream conn3;
+ conn3.Open(Socket::TypeINET,
+ "localhost", 2003);
+ #endif // !WIN32
+
// Quick check that reconnections fail
- TEST_CHECK_THROWS(conn1.Open(Socket::TypeUNIX, "testfiles/srv2.sock");, ServerException, SocketAlreadyOpen);
+ TEST_CHECK_THROWS(conn1.Open(Socket::TypeUNIX,
+ "testfiles/srv2.sock");,
+ ServerException, SocketAlreadyOpen);
+
// Stuff some data around
std::vector<IOStream *> conns;
conns.push_back(&conn1);
-#ifndef WIN32
- conns.push_back(&conn2);
- conns.push_back(&conn3);
-#endif // !WIN32
+
+ #ifndef WIN32
+ conns.push_back(&conn2);
+ conns.push_back(&conn3);
+ #endif // !WIN32
+
Srv2TestConversations(conns);
// Implicit close
}
-#ifndef WIN32
- // HUP again
- TEST_THAT(HUPServer(pid));
- ::sleep(1);
- TEST_THAT(ServerIsAlive(pid));
-#endif // !WIN32
+
+ #ifndef WIN32
+ // HUP again
+ TEST_THAT(HUPServer(pid));
+ ::sleep(1);
+ TEST_THAT(ServerIsAlive(pid));
+ #endif // !WIN32
+
// Kill it
TEST_THAT(KillServer(pid));
::sleep(1);
TEST_THAT(!ServerIsAlive(pid));
-#ifndef WIN32
- TestRemoteProcessMemLeaks("test-srv2.memleaks");
-#endif // !WIN32
+
+ #ifndef WIN32
+ TestRemoteProcessMemLeaks("test-srv2.memleaks");
+ #endif // !WIN32
}
}
// Launch a test SSL server
{
-#ifdef WIN32
- int pid = LaunchServer("test srv3 testfiles\\srv3.conf",
- "testfiles\\srv3.pid");
-#else
- int pid = LaunchServer("./test srv3 testfiles/srv3.conf", "testfiles/srv3.pid");
-#endif
+ int pid = LaunchServer("./test srv3 testfiles/srv3.conf",
+ "testfiles/srv3.pid");
+
TEST_THAT(pid != -1 && pid != 0);
+
if(pid > 0)
{
// Will it restart?
TEST_THAT(ServerIsAlive(pid));
-#ifndef WIN32
- TEST_THAT(HUPServer(pid));
- ::sleep(1);
- TEST_THAT(ServerIsAlive(pid));
-#endif
+ #ifndef WIN32
+ TEST_THAT(HUPServer(pid));
+ ::sleep(1);
+ TEST_THAT(ServerIsAlive(pid));
+ #endif
// Make some connections
{
@@ -577,51 +578,60 @@
SocketStreamTLS conn1;
conn1.Open(context, Socket::TypeINET, "localhost", 2003);
-#ifndef WIN32
- SocketStreamTLS conn2;
- conn2.Open(context, Socket::TypeUNIX, "testfiles/srv3.sock");
- SocketStreamTLS conn3;
- conn3.Open(context, Socket::TypeINET, "localhost", 2003);
-#endif
+ #ifndef WIN32
+ SocketStreamTLS conn2;
+ conn2.Open(context, Socket::TypeUNIX,
+ "testfiles/srv3.sock");
+ SocketStreamTLS conn3;
+ conn3.Open(context, Socket::TypeINET,
+ "localhost", 2003);
+ #endif
+
// Quick check that reconnections fail
- TEST_CHECK_THROWS(conn1.Open(context, Socket::TypeUNIX, "testfiles/srv3.sock");, ServerException, SocketAlreadyOpen);
+ TEST_CHECK_THROWS(conn1.Open(context,
+ Socket::TypeUNIX,
+ "testfiles/srv3.sock");,
+ ServerException, SocketAlreadyOpen);
+
// Stuff some data around
std::vector<IOStream *> conns;
conns.push_back(&conn1);
-#ifndef WIN32
- conns.push_back(&conn2);
- conns.push_back(&conn3);
-#endif
+
+ #ifndef WIN32
+ conns.push_back(&conn2);
+ conns.push_back(&conn3);
+ #endif
+
Srv2TestConversations(conns);
// Implicit close
}
-#ifndef WIN32
- // HUP again
- TEST_THAT(HUPServer(pid));
- ::sleep(1);
- TEST_THAT(ServerIsAlive(pid));
-#endif
+
+ #ifndef WIN32
+ // HUP again
+ TEST_THAT(HUPServer(pid));
+ ::sleep(1);
+ TEST_THAT(ServerIsAlive(pid));
+ #endif
+
// Kill it
TEST_THAT(KillServer(pid));
::sleep(1);
TEST_THAT(!ServerIsAlive(pid));
-#ifndef WIN32
- TestRemoteProcessMemLeaks("test-srv3.memleaks");
-#endif
+
+ #ifndef WIN32
+ TestRemoteProcessMemLeaks("test-srv3.memleaks");
+ #endif
}
}
//protocolserver:
// Launch a test protocol handling server
{
-#ifdef WIN32
- int pid = LaunchServer("test srv4 testfiles\\srv4.conf",
- "testfiles\\srv4.pid");
-#else
int pid = LaunchServer("./test srv4 testfiles/srv4.conf",
"testfiles/srv4.pid");
-#endif
+
TEST_THAT(pid != -1 && pid != 0);
+
if(pid > 0)
{
::sleep(1);
@@ -629,11 +639,11 @@
// Open a connection to it
SocketStream conn;
-#ifdef WIN32
- conn.Open(Socket::TypeINET, "localhost", 2003);
-#else
- conn.Open(Socket::TypeUNIX, "testfiles/srv4.sock");
-#endif
+ #ifdef WIN32
+ conn.Open(Socket::TypeINET, "localhost", 2003);
+ #else
+ conn.Open(Socket::TypeUNIX, "testfiles/srv4.sock");
+ #endif
// Create a protocol
TestProtocolClient protocol(conn);
@@ -696,9 +706,10 @@
TEST_THAT(KillServer(pid));
::sleep(1);
TEST_THAT(!ServerIsAlive(pid));
-#ifndef WIN32
- TestRemoteProcessMemLeaks("test-srv4.memleaks");
-#endif
+
+ #ifndef WIN32
+ TestRemoteProcessMemLeaks("test-srv4.memleaks");
+ #endif
}
}