[Box Backup-dev] COMMIT r216 - in box/chris/win32/merge/07-win32-fixes: . infrastructure lib/common lib/win32 test/common

boxbackup-dev@fluffy.co.uk boxbackup-dev@fluffy.co.uk
Mon, 12 Dec 2005 21:47:04 +0000 (GMT)


Author: chris
Date: 2005-12-12 21:46:48 +0000 (Mon, 12 Dec 2005)
New Revision: 216

Modified:
   box/chris/win32/merge/07-win32-fixes/infrastructure/buildenv-testmain-template.cpp
   box/chris/win32/merge/07-win32-fixes/infrastructure/makebuildenv.pl
   box/chris/win32/merge/07-win32-fixes/lib/common/DebugAssertFailed.cpp
   box/chris/win32/merge/07-win32-fixes/lib/common/DebugPrintf.cpp
   box/chris/win32/merge/07-win32-fixes/lib/common/FileStream.cpp
   box/chris/win32/merge/07-win32-fixes/lib/common/Test.h
   box/chris/win32/merge/07-win32-fixes/lib/win32/WinNamedPipeStream.cpp
   box/chris/win32/merge/07-win32-fixes/modules.txt
   box/chris/win32/merge/07-win32-fixes/test/common/testcommon.cpp
Log:
* modules.txt
* test/common/testcommon.cpp
* infrastructure/makebuildenv.pl
* infrastructure/buildenv-testmain-template.cpp
* lib/win32/WinNamedPipeStream.cpp
* lib/common/DebugAssertFailed.cpp
* lib/common/Test.h
* lib/common/FileStream.cpp
* lib/common/DebugPrintf.cpp
- Made test/common work on Win32


Modified: box/chris/win32/merge/07-win32-fixes/infrastructure/buildenv-testmain-template.cpp
===================================================================
--- box/chris/win32/merge/07-win32-fixes/infrastructure/buildenv-testmain-template.cpp	2005-12-12 21:10:51 UTC (rev 215)
+++ box/chris/win32/merge/07-win32-fixes/infrastructure/buildenv-testmain-template.cpp	2005-12-12 21:46:48 UTC (rev 216)
@@ -20,11 +20,16 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include <stdlib.h>
-#include <syslog.h>
 #include <stdarg.h>
 #include <fcntl.h>
 #include <errno.h>
 
+#ifdef WIN32
+	#include "emu.h"
+#else
+	#include <syslog.h>
+#endif
+
 #include "MemLeakFindOn.h"
 
 int test(int argc, const char *argv[]);
@@ -39,6 +44,14 @@
 
 int filedes_open_at_beginning = -1;
 
+#ifdef WIN32
+
+// any way to check for open file descriptors on Win32?
+inline int count_filedes() { return 0; }
+inline bool checkfilesleftopen() { return false; }
+
+#else // !WIN32
+
 int count_filedes()
 {
 	int c = 0;
@@ -71,6 +84,8 @@
 	return filedes_open_at_beginning != count_filedes();
 }
 
+#endif
+
 int main(int argc, const char *argv[])
 {
 	// Start memory leak testing

Modified: box/chris/win32/merge/07-win32-fixes/infrastructure/makebuildenv.pl
===================================================================
--- box/chris/win32/merge/07-win32-fixes/infrastructure/makebuildenv.pl	2005-12-12 21:10:51 UTC (rev 215)
+++ box/chris/win32/merge/07-win32-fixes/infrastructure/makebuildenv.pl	2005-12-12 21:46:48 UTC (rev 216)
@@ -408,9 +408,9 @@
 		}
 		
 		writetestfile("$mod/_t", 
-			'./test${platform_exe_ext} $1 $2 $3 $4 $5', $mod);
+			'./test' . $platform_exe_ext . '$1 $2 $3 $4 $5', $mod);
 		writetestfile("$mod/_t-gdb", 
-			'gdb ./test${platform_exe_ext}', $mod);
+			'gdb ./test ' . $platform_exe_ext, $mod);
 		
 	}
 	

Modified: box/chris/win32/merge/07-win32-fixes/lib/common/DebugAssertFailed.cpp
===================================================================
--- box/chris/win32/merge/07-win32-fixes/lib/common/DebugAssertFailed.cpp	2005-12-12 21:10:51 UTC (rev 215)
+++ box/chris/win32/merge/07-win32-fixes/lib/common/DebugAssertFailed.cpp	2005-12-12 21:46:48 UTC (rev 216)
@@ -12,8 +12,13 @@
 #include "Box.h"
 
 #include <stdio.h>
-#include <syslog.h>
 
+#ifdef WIN32
+	#include "emu.h"
+#else
+	#include <syslog.h>
+#endif
+
 #include "MemLeakFindOn.h"
 
 bool AssertFailuresToSyslog = false;

Modified: box/chris/win32/merge/07-win32-fixes/lib/common/DebugPrintf.cpp
===================================================================
--- box/chris/win32/merge/07-win32-fixes/lib/common/DebugPrintf.cpp	2005-12-12 21:10:51 UTC (rev 215)
+++ box/chris/win32/merge/07-win32-fixes/lib/common/DebugPrintf.cpp	2005-12-12 21:46:48 UTC (rev 216)
@@ -13,8 +13,13 @@
 
 #include <stdio.h>
 #include <stdarg.h>
-#include <syslog.h>
 
+#ifdef WIN32
+	#include "emu.h"
+#else
+	#include <syslog.h>
+#endif
+
 #include "MemLeakFindOn.h"
 
 // Use this apparently superflous printf function to avoid having to 

Modified: box/chris/win32/merge/07-win32-fixes/lib/common/FileStream.cpp
===================================================================
--- box/chris/win32/merge/07-win32-fixes/lib/common/FileStream.cpp	2005-12-12 21:10:51 UTC (rev 215)
+++ box/chris/win32/merge/07-win32-fixes/lib/common/FileStream.cpp	2005-12-12 21:46:48 UTC (rev 216)
@@ -197,11 +197,9 @@
 
 	if ( (res == 0) || (numBytesWritten != NBytes))
 	{
-		DWORD err = GetLastError();
+		// DWORD err = GetLastError();
 		THROW_EXCEPTION(CommonException, OSFileWriteError)
 	}
-
-
 #else
 	if(::write(mOSFileHandle, pBuffer, NBytes) != NBytes)
 	{

Modified: box/chris/win32/merge/07-win32-fixes/lib/common/Test.h
===================================================================
--- box/chris/win32/merge/07-win32-fixes/lib/common/Test.h	2005-12-12 21:10:51 UTC (rev 215)
+++ box/chris/win32/merge/07-win32-fixes/lib/common/Test.h	2005-12-12 21:46:48 UTC (rev 216)
@@ -108,6 +108,116 @@
 	return pid;
 }
 
+#ifdef WIN32
+
+#include "WinNamedPipeStream.h"
+#include "IOStreamGetLine.h"
+#include "BoxPortsAndFiles.h"
+
+bool SendCommands(const std::string& rCmd)
+{
+	WinNamedPipeStream connection;
+
+	try
+	{
+		connection.Connect(BOX_NAMED_PIPE_NAME);
+	}
+	catch(...)
+	{
+		printf("Failed to connect to daemon control socket.\n");
+		return false;
+	}
+
+	// For receiving data
+	IOStreamGetLine getLine(connection);
+	
+	// Wait for the configuration summary
+	std::string configSummary;
+	if(!getLine.GetLine(configSummary))
+	{
+		printf("Failed to receive configuration summary from daemon\n");
+		return false;
+	}
+
+	// Was the connection rejected by the server?
+	if(getLine.IsEOF())
+	{
+		printf("Server rejected the connection.\n");
+		return false;
+	}
+
+	// Decode it
+	int autoBackup, updateStoreInterval, minimumFileAge, maxUploadWait;
+	if(::sscanf(configSummary.c_str(), "bbackupd: %d %d %d %d", 
+			&autoBackup, &updateStoreInterval, 
+			&minimumFileAge, &maxUploadWait) != 4)
+	{
+		printf("Config summary didn't decode\n");
+		return false;
+	}
+
+	std::string cmds;
+	bool expectResponse;
+
+	if (rCmd != "")
+	{
+		cmds = rCmd;
+		cmds += "\nquit\n";
+		expectResponse = true;
+	}
+	else
+	{
+		cmds = "quit\n";
+		expectResponse = false;
+	}
+	
+	connection.Write(cmds.c_str(), cmds.size());
+	
+	// Read the response
+	std::string line;
+	bool statusOk = !expectResponse;
+
+	while (expectResponse && !getLine.IsEOF() && getLine.GetLine(line))
+	{
+		// Is this an OK or error line?
+		if (line == "ok")
+		{
+			statusOk = true;
+		}
+		else if (line == "error")
+		{
+			printf("ERROR (%s)\n", rCmd.c_str());
+			break;
+		}
+		else
+		{
+			printf("WARNING: Unexpected response to command '%s': "
+				"%s", rCmd.c_str(), line.c_str());
+		}
+	}
+	
+	return statusOk;
+}
+
+inline bool ServerIsAlive()
+{
+	return SendCommands("");
+}
+
+inline bool HUPServer(int pid)
+{
+	return SendCommands("reload");
+}
+
+inline bool KillServer(int pid)
+{
+	TEST_THAT(SendCommands("terminate"));
+	::sleep(1);
+	return !ServerIsAlive();
+}
+
+#else // !WIN32
+
 inline bool ServerIsAlive(int pid)
 {
 	if(pid == 0) return false;
@@ -129,6 +239,8 @@
 	return !ServerIsAlive(pid);
 }
 
+#endif // WIN32
+
 inline void TestRemoteProcessMemLeaks(const char *filename)
 {
 #ifdef BOX_MEMORY_LEAK_TESTING


Property changes on: box/chris/win32/merge/07-win32-fixes/lib/win32/WinNamedPipeStream.cpp
___________________________________________________________________
Name: svn:executable
   - *

Modified: box/chris/win32/merge/07-win32-fixes/modules.txt
===================================================================
--- box/chris/win32/merge/07-win32-fixes/modules.txt	2005-12-12 21:10:51 UTC (rev 215)
+++ box/chris/win32/merge/07-win32-fixes/modules.txt	2005-12-12 21:46:48 UTC (rev 216)
@@ -18,8 +18,8 @@
 lib/server
 lib/win32		lib/server
 lib/compress
-test/common
-test/crypto			lib/crypto
+test/common		lib/win32
+test/crypto		lib/crypto
 test/compress		lib/compress
 test/basicserver	lib/server
 

Modified: box/chris/win32/merge/07-win32-fixes/test/common/testcommon.cpp
===================================================================
--- box/chris/win32/merge/07-win32-fixes/test/common/testcommon.cpp	2005-12-12 21:10:51 UTC (rev 215)
+++ box/chris/win32/merge/07-win32-fixes/test/common/testcommon.cpp	2005-12-12 21:46:48 UTC (rev 216)
@@ -182,7 +182,8 @@
 
 	// First, test the FdGetLine class -- rather important this works!
 	{
-		FileHandleGuard<O_RDONLY> file("testfiles/fdgetlinetest.txt");
+		FileHandleGuard<O_RDONLY> file("testfiles"
+			DIRECTORY_SEPARATOR "fdgetlinetest.txt");
 		FdGetLine getline(file);
 		
   		int l = 0;
@@ -199,8 +200,10 @@
 	}
 	// and again without pre-processing
 	{
-		FileHandleGuard<O_RDONLY> file("testfiles/fdgetlinetest.txt");
-		FILE *file2 = fopen("testfiles/fdgetlinetest.txt", "r");
+		FileHandleGuard<O_RDONLY> file("testfiles"
+			DIRECTORY_SEPARATOR "fdgetlinetest.txt");
+		FILE *file2 = fopen("testfiles" DIRECTORY_SEPARATOR 
+			"fdgetlinetest.txt", "r");
 		TEST_THAT_ABORTONFAIL(file2 != 0);
 		FdGetLine getline(file);
 		char ll[512];
@@ -228,7 +231,8 @@
 	
 	// Then the IOStream version of get line, seeing as we're here...
 	{
-		FileStream file("testfiles/fdgetlinetest.txt", O_RDONLY);
+		FileStream file("testfiles" DIRECTORY_SEPARATOR 
+			"fdgetlinetest.txt", O_RDONLY);
 		IOStreamGetLine getline(file);
 		
   		int l = 0;
@@ -248,10 +252,12 @@
 	}
 	// and again without pre-processing
 	{
-		FileStream file("testfiles/fdgetlinetest.txt", O_RDONLY);
+		FileStream file("testfiles" DIRECTORY_SEPARATOR 
+			"fdgetlinetest.txt", O_RDONLY);
 		IOStreamGetLine getline(file);
 
-		FILE *file2 = fopen("testfiles/fdgetlinetest.txt", "r");
+		FILE *file2 = fopen("testfiles" DIRECTORY_SEPARATOR 
+			"fdgetlinetest.txt", "r");
 		TEST_THAT_ABORTONFAIL(file2 != 0);
 		char ll[512];
 		
@@ -282,13 +288,20 @@
 	// Doesn't exist
 	{
 		std::string errMsg;
-		TEST_CHECK_THROWS(std::auto_ptr<Configuration> pconfig(Configuration::LoadAndVerify("testfiles/DOESNTEXIST", &verify, errMsg)), CommonException, OSFileOpenError);
+		TEST_CHECK_THROWS(std::auto_ptr<Configuration> pconfig(
+			Configuration::LoadAndVerify(
+				"testfiles" DIRECTORY_SEPARATOR "DOESNTEXIST", 
+				&verify, errMsg)), 
+			CommonException, OSFileOpenError);
 	}
 
 	// Basic configuration test
 	{
 		std::string errMsg;
-		std::auto_ptr<Configuration> pconfig(Configuration::LoadAndVerify("testfiles/config1.txt", &verify, errMsg));
+		std::auto_ptr<Configuration> pconfig(
+			Configuration::LoadAndVerify(
+				"testfiles" DIRECTORY_SEPARATOR "config1.txt", 
+				&verify, errMsg));
 		if(!errMsg.empty())
 		{
 			printf("UNEXPECTED error msg is:\n------\n%s------\n", errMsg.c_str());
@@ -333,22 +346,38 @@
 
 	static const char *file[] =
 	{
-		"testfiles/config2.txt", // Value missing from root
-		"testfiles/config3.txt", // Unexpected {
-		"testfiles/config4.txt", // Missing }
-		"testfiles/config5.txt", // { expected, but wasn't there
-		"testfiles/config6.txt", // Duplicate key
-		"testfiles/config7.txt", // Invalid key (no name)
-		"testfiles/config8.txt", // Not all sub blocks terminated
-		"testfiles/config9.txt", // Not valid integer
-		"testfiles/config9b.txt", // Not valid integer
-		"testfiles/config9c.txt", // Not valid integer
-		"testfiles/config9d.txt", // Not valid integer
-		"testfiles/config10.txt", // Missing key (in subblock)
-		"testfiles/config11.txt", // Unknown key
-		"testfiles/config12.txt", // Missing block
-		"testfiles/config13.txt", // Subconfig (wildcarded) should exist, but missing (ie nothing present)
-		"testfiles/config16.txt", // bad boolean value
+		"testfiles" DIRECTORY_SEPARATOR "config2.txt", 
+			// Value missing from root
+		"testfiles" DIRECTORY_SEPARATOR "config3.txt", 
+			// Unexpected {
+		"testfiles" DIRECTORY_SEPARATOR "config4.txt", 
+			// Missing }
+		"testfiles" DIRECTORY_SEPARATOR "config5.txt", 
+			// { expected, but wasn't there
+		"testfiles" DIRECTORY_SEPARATOR "config6.txt", 
+			// Duplicate key
+		"testfiles" DIRECTORY_SEPARATOR "config7.txt", 
+			// Invalid key (no name)
+		"testfiles" DIRECTORY_SEPARATOR "config8.txt", 
+			// Not all sub blocks terminated
+		"testfiles" DIRECTORY_SEPARATOR "config9.txt", 
+			// Not valid integer
+		"testfiles" DIRECTORY_SEPARATOR "config9b.txt", 
+			// Not valid integer
+		"testfiles" DIRECTORY_SEPARATOR "config9c.txt", 
+			// Not valid integer
+		"testfiles" DIRECTORY_SEPARATOR "config9d.txt", 
+			// Not valid integer
+		"testfiles" DIRECTORY_SEPARATOR "config10.txt", 
+			// Missing key (in subblock)
+		"testfiles" DIRECTORY_SEPARATOR "config11.txt", 
+			// Unknown key
+		"testfiles" DIRECTORY_SEPARATOR "config12.txt", 
+			// Missing block
+		"testfiles" DIRECTORY_SEPARATOR "config13.txt", 
+			// Subconfig (wildcarded) should exist, but missing (ie nothing present)
+		"testfiles" DIRECTORY_SEPARATOR "config16.txt", 
+			// bad boolean value
 		0
 	};
 
@@ -365,7 +394,10 @@
 	// (single value in a multivalue already checked)
 	{
 		std::string errMsg;
-		std::auto_ptr<Configuration> pconfig(Configuration::LoadAndVerify("testfiles/config14.txt", &verify, errMsg));
+		std::auto_ptr<Configuration> pconfig(
+			Configuration::LoadAndVerify(
+				"testfiles" DIRECTORY_SEPARATOR "config14.txt",
+			&verify, errMsg));
 		TEST_THAT(pconfig.get() != 0);
 		TEST_THAT(errMsg.empty());
 		TEST_THAT(pconfig->KeyExists("MultiValue"));
@@ -379,7 +411,10 @@
 	// Check boolean values	
 	{
 		std::string errMsg;
-		std::auto_ptr<Configuration> pconfig(Configuration::LoadAndVerify("testfiles/config15.txt", &verify, errMsg));
+		std::auto_ptr<Configuration> pconfig(
+			Configuration::LoadAndVerify(
+				"testfiles" DIRECTORY_SEPARATOR "config15.txt",
+			&verify, errMsg));
 		TEST_THAT(pconfig.get() != 0);
 		TEST_THAT(errMsg.empty());
 		TEST_THAT(pconfig->GetKeyValueBool("BoolTrue1") == true);
@@ -392,32 +427,50 @@
 	{
 		NamedLock lock1;
 		// Try and get a lock on a name in a directory which doesn't exist
-		TEST_CHECK_THROWS(lock1.TryAndGetLock("testfiles/non-exist/lock"), CommonException, OSFileError);
+		TEST_CHECK_THROWS(lock1.TryAndGetLock(
+				"testfiles" 
+				DIRECTORY_SEPARATOR "non-exist"
+				DIRECTORY_SEPARATOR "lock"), 
+			CommonException, OSFileError);
+
 		// And a more resonable request
-		TEST_THAT(lock1.TryAndGetLock("testfiles/lock1") == true);
+		TEST_THAT(lock1.TryAndGetLock(
+			"testfiles" DIRECTORY_SEPARATOR "lock1") == true);
+
 		// Try to lock something using the same lock
-		TEST_CHECK_THROWS(lock1.TryAndGetLock("testfiles/non-exist/lock2"), CommonException, NamedLockAlreadyLockingSomething);		
+		TEST_CHECK_THROWS(
+			lock1.TryAndGetLock(
+				"testfiles" 
+				DIRECTORY_SEPARATOR "non-exist"
+				DIRECTORY_SEPARATOR "lock2"), 
+			CommonException, NamedLockAlreadyLockingSomething);		
 #if defined(HAVE_FLOCK) || HAVE_DECL_O_EXLOCK
 		// And again on that name
 		NamedLock lock2;
-		TEST_THAT(lock2.TryAndGetLock("testfiles/lock1") == false);
+		TEST_THAT(lock2.TryAndGetLock(
+			"testfiles" DIRECTORY_SEPARATOR "lock1") == false);
 #endif
 	}
 	{
 		// Check that it unlocked when it went out of scope
 		NamedLock lock3;
-		TEST_THAT(lock3.TryAndGetLock("testfiles/lock1") == true);
+		TEST_THAT(lock3.TryAndGetLock(
+			"testfiles" DIRECTORY_SEPARATOR "lock1") == true);
 	}
 	{
 		// And unlocking works
 		NamedLock lock4;
-		TEST_CHECK_THROWS(lock4.ReleaseLock(), CommonException, NamedLockNotHeld);		
-		TEST_THAT(lock4.TryAndGetLock("testfiles/lock4") == true);
+		TEST_CHECK_THROWS(lock4.ReleaseLock(), CommonException, 
+			NamedLockNotHeld);
+		TEST_THAT(lock4.TryAndGetLock(
+			"testfiles" DIRECTORY_SEPARATOR "lock4") == true);
 		lock4.ReleaseLock();
 		NamedLock lock5;
-		TEST_THAT(lock5.TryAndGetLock("testfiles/lock4") == true);
+		TEST_THAT(lock5.TryAndGetLock(
+			"testfiles" DIRECTORY_SEPARATOR "lock4") == true);
 		// And can reuse it
-		TEST_THAT(lock4.TryAndGetLock("testfiles/lock5") == true);
+		TEST_THAT(lock4.TryAndGetLock(
+			"testfiles" DIRECTORY_SEPARATOR "lock5") == true);
 	}
 
 	// Test the ReadGatherStream