summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/common/DebugAssertFailed.cpp7
-rw-r--r--lib/common/DebugPrintf.cpp7
-rw-r--r--lib/common/FileStream.cpp4
-rw-r--r--lib/common/Test.h112
4 files changed, 125 insertions, 5 deletions
diff --git a/lib/common/DebugAssertFailed.cpp b/lib/common/DebugAssertFailed.cpp
index 2acf4602..0c5dc548 100644
--- a/lib/common/DebugAssertFailed.cpp
+++ b/lib/common/DebugAssertFailed.cpp
@@ -12,7 +12,12 @@
#include "Box.h"
#include <stdio.h>
-#include <syslog.h>
+
+#ifdef WIN32
+ #include "emu.h"
+#else
+ #include <syslog.h>
+#endif
#include "MemLeakFindOn.h"
diff --git a/lib/common/DebugPrintf.cpp b/lib/common/DebugPrintf.cpp
index d07604b7..8d75f458 100644
--- a/lib/common/DebugPrintf.cpp
+++ b/lib/common/DebugPrintf.cpp
@@ -13,7 +13,12 @@
#include <stdio.h>
#include <stdarg.h>
-#include <syslog.h>
+
+#ifdef WIN32
+ #include "emu.h"
+#else
+ #include <syslog.h>
+#endif
#include "MemLeakFindOn.h"
diff --git a/lib/common/FileStream.cpp b/lib/common/FileStream.cpp
index 9f5460bb..917dc9c9 100644
--- a/lib/common/FileStream.cpp
+++ b/lib/common/FileStream.cpp
@@ -197,11 +197,9 @@ void FileStream::Write(const void *pBuffer, int NBytes)
if ( (res == 0) || (numBytesWritten != NBytes))
{
- DWORD err = GetLastError();
+ // DWORD err = GetLastError();
THROW_EXCEPTION(CommonException, OSFileWriteError)
}
-
-
#else
if(::write(mOSFileHandle, pBuffer, NBytes) != NBytes)
{
diff --git a/lib/common/Test.h b/lib/common/Test.h
index bd69cd5a..472f6342 100644
--- a/lib/common/Test.h
+++ b/lib/common/Test.h
@@ -108,6 +108,116 @@ inline int LaunchServer(const char *CommandLine, const char *pidFile)
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 @@ inline bool KillServer(int pid)
return !ServerIsAlive(pid);
}
+#endif // WIN32
+
inline void TestRemoteProcessMemLeaks(const char *filename)
{
#ifdef BOX_MEMORY_LEAK_TESTING