Bug 1254373: Make TestDemon build on Windows; r?billm
MozReview-Commit-ID: GtgAVfDYhtk
--- a/ipc/ipdl/test/cxx/TestDemon.cpp
+++ b/ipc/ipdl/test/cxx/TestDemon.cpp
@@ -1,20 +1,21 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=4 ts=4 et :
*/
#include "TestDemon.h"
#include <stdlib.h>
-#include <sys/time.h>
#include "IPDLUnitTests.h" // fail etc.
#if defined(OS_POSIX)
+#include <sys/time.h>
#include <unistd.h>
#else
+#include <time.h>
#include <windows.h>
#endif
template<>
struct RunnableMethodTraits<mozilla::_ipdltest::TestDemonParent>
{
static void RetainCallee(mozilla::_ipdltest::TestDemonParent* obj) { }
static void ReleaseCallee(mozilla::_ipdltest::TestDemonParent* obj) { }
@@ -29,25 +30,29 @@ struct RunnableMethodTraits<mozilla::_ip
namespace mozilla {
namespace _ipdltest {
const int kMaxStackHeight = 4;
static LazyLogModule sLogModule("demon");
-#define DEMON_LOG(args...) MOZ_LOG(sLogModule, LogLevel::Debug, (args))
+#define DEMON_LOG(...) MOZ_LOG(sLogModule, LogLevel::Debug, (__VA_ARGS__))
static int gStackHeight = 0;
static bool gFlushStack = false;
static int
Choose(int count)
{
+#if defined(OS_POSIX)
return random() % count;
+#else
+ return rand() % count;
+#endif
}
//-----------------------------------------------------------------------------
// parent
TestDemonParent::TestDemonParent()
: mDone(false),
mIncoming(),
@@ -63,17 +68,21 @@ TestDemonParent::~TestDemonParent()
void
TestDemonParent::Main()
{
if (!getenv("MOZ_TEST_IPC_DEMON")) {
QuitParent();
return;
}
+#if defined(OS_POSIX)
srandom(time(nullptr));
+#else
+ srand(time(nullptr));
+#endif
DEMON_LOG("Start demon");
if (!SendStart())
fail("sending Start");
RunUnlimitedSequence();
}
@@ -264,17 +273,21 @@ TestDemonChild::TestDemonChild()
TestDemonChild::~TestDemonChild()
{
MOZ_COUNT_DTOR(TestDemonChild);
}
bool
TestDemonChild::RecvStart()
{
+#ifdef OS_POSIX
srandom(time(nullptr));
+#else
+ srand(time(nullptr));
+#endif
DEMON_LOG("RecvStart");
RunUnlimitedSequence();
return true;
}
#ifdef DEBUG