Bug 1125559 - Move TestThreadPool.cpp to gtest and enable it; r=froydnj

--HG--
rename : xpcom/tests/TestThreadPool.cpp => xpcom/tests/gtest/TestThreadPool.cpp
extra : amend_source : 08b95083290e67062ebaecff820ff627f87b35a2
This commit is contained in:
Ehsan Akhgari 2015-01-26 17:10:09 -05:00
Родитель e6a83f6014
Коммит 87ec49dc6f
3 изменённых файлов: 16 добавлений и 18 удалений

Просмотреть файл

@ -12,13 +12,15 @@
#include "nsComponentManagerUtils.h"
#include "nsCOMPtr.h"
#include "nsIRunnable.h"
#include "mozilla/Atomics.h"
#include "gtest/gtest.h"
class Task : public nsIRunnable
class Task MOZ_FINAL : public nsIRunnable
{
public:
NS_DECL_THREADSAFE_ISUPPORTS
Task(int i) : mIndex(i) {}
explicit Task(int i) : mIndex(i) {}
NS_IMETHOD Run()
{
@ -26,37 +28,33 @@ public:
int r = (int) ((float) rand() * 200 / RAND_MAX);
PR_Sleep(PR_MillisecondsToInterval(r));
printf("###(%d) exiting from thread: %p\n", mIndex, (void *) PR_GetCurrentThread());
++sCount;
return NS_OK;
}
static mozilla::Atomic<int> sCount;
private:
~Task() {}
int mIndex;
};
NS_IMPL_ISUPPORTS(Task, nsIRunnable)
static nsresult
RunTests()
mozilla::Atomic<int> Task::sCount;
TEST(ThreadPool, Main)
{
nsCOMPtr<nsIThreadPool> pool = do_CreateInstance(NS_THREADPOOL_CONTRACTID);
NS_ENSURE_STATE(pool);
EXPECT_TRUE(pool);
for (int i = 0; i < 100; ++i) {
nsCOMPtr<nsIRunnable> task = new Task(i);
NS_ENSURE_TRUE(task, NS_ERROR_OUT_OF_MEMORY);
EXPECT_TRUE(task);
pool->Dispatch(task, NS_DISPATCH_NORMAL);
}
pool->Shutdown();
return NS_OK;
}
int
main(int argc, char **argv)
{
if (NS_FAILED(NS_InitXPCOM2(nullptr, nullptr, nullptr)))
return -1;
RunTests();
NS_ShutdownXPCOM(nullptr);
return 0;
EXPECT_EQ(Task::sCount, 100);
}

Просмотреть файл

@ -14,6 +14,7 @@ UNIFIED_SOURCES += [
'TestStorageStream.cpp',
'TestStrings.cpp',
'TestSynchronization.cpp',
'TestThreadPool.cpp',
'TestTimeStamp.cpp',
]

Просмотреть файл

@ -80,7 +80,6 @@ if CONFIG['MOZ_MEMORY']:
# XXX Make these tests work in libxul builds.
#CPP_UNIT_TESTS += [
# 'TestThreadPool',
# 'TestThreads',
# 'TestXPIDLString',
# 'TestUTF',