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 : 9d779a219338a8cbf854af28070ddc5559d28d2b
extra : histedit_source : 59dd08d1722b1fe621f3d5070b64d791012fa026%2C5231f875b1e958f393079ac9258a2d3812a1feb1
This commit is contained in:
Ehsan Akhgari 2015-01-26 20:49:22 -05:00
Родитель e484daf16b
Коммит 1ff610e6bd
3 изменённых файлов: 17 добавлений и 19 удалений

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

@ -12,51 +12,49 @@
#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()
NS_IMETHOD Run() MOZ_OVERRIDE
{
printf("###(%d) running from thread: %p\n", mIndex, (void *) PR_GetCurrentThread());
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',
]
FINAL_LIBRARY = 'xul-gtest'

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

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