summaryrefslogtreecommitdiffstats
path: root/xpcom/tests
diff options
context:
space:
mode:
Diffstat (limited to 'xpcom/tests')
-rw-r--r--xpcom/tests/gtest/TestAutoOwningEventTarget.cpp120
-rw-r--r--xpcom/tests/gtest/TestThreadUtils.cpp327
-rw-r--r--xpcom/tests/gtest/moz.build7
3 files changed, 188 insertions, 266 deletions
diff --git a/xpcom/tests/gtest/TestAutoOwningEventTarget.cpp b/xpcom/tests/gtest/TestAutoOwningEventTarget.cpp
new file mode 100644
index 0000000000..2bd34ecfee
--- /dev/null
+++ b/xpcom/tests/gtest/TestAutoOwningEventTarget.cpp
@@ -0,0 +1,120 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+// vim:cindent:ts=4:et:sw=4:
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "nsCOMPtr.h"
+#include "nsISupportsImpl.h"
+#include "nsNetCID.h"
+#include "nsServiceManagerUtils.h"
+#include "nsThreadUtils.h"
+#include "gtest/gtest.h"
+#include "mozilla/SyncRunnable.h"
+#include "mozilla/TaskQueue.h"
+#include "mozilla/gtest/MozAssertions.h"
+
+namespace TestAutoOwningEventTarget {
+
+using namespace mozilla;
+
+#ifdef MOZ_THREAD_SAFETY_OWNERSHIP_CHECKS_SUPPORTED
+
+namespace {
+
+static MozExternalRefCountType GetRefCount(nsISupports* aSupports) {
+ aSupports->AddRef();
+ return aSupports->Release();
+}
+
+void CheckAutoOwningEventTarget(
+ nsISerialEventTarget* aSerialEventTarget,
+ const nsAutoOwningEventTarget& aAutoOwningEventTarget,
+ const bool aIsCurrent) {
+ ASSERT_TRUE(aSerialEventTarget);
+
+ ASSERT_EQ(aAutoOwningEventTarget.IsCurrentThread(), aIsCurrent);
+
+ {
+ const auto refCountBefore = GetRefCount(aSerialEventTarget);
+
+ {
+ nsAutoOwningEventTarget copyConstructedEventTarget(
+ aAutoOwningEventTarget);
+ ASSERT_EQ(copyConstructedEventTarget.IsCurrentThread(), aIsCurrent);
+ }
+
+ const auto refCountAfter = GetRefCount(aSerialEventTarget);
+
+ ASSERT_GE(refCountAfter, refCountBefore);
+ ASSERT_EQ(refCountAfter - refCountBefore, 0u);
+ }
+
+ {
+ const auto refCountBefore = GetRefCount(aSerialEventTarget);
+
+ {
+ nsAutoOwningEventTarget copyAssignedEventTarget;
+ ASSERT_TRUE(copyAssignedEventTarget.IsCurrentThread());
+
+ copyAssignedEventTarget = aAutoOwningEventTarget;
+ ASSERT_EQ(copyAssignedEventTarget.IsCurrentThread(), aIsCurrent);
+ }
+
+ const auto refCountAfter = GetRefCount(aSerialEventTarget);
+
+ ASSERT_GE(refCountAfter, refCountBefore);
+ ASSERT_EQ(refCountAfter - refCountBefore, 0u);
+ }
+}
+
+} // namespace
+
+TEST(TestAutoOwningEventTarget, Simple)
+{
+ {
+ nsAutoOwningEventTarget autoOwningEventTarget;
+
+ ASSERT_NO_FATAL_FAILURE(CheckAutoOwningEventTarget(
+ GetCurrentSerialEventTarget(), autoOwningEventTarget,
+ /* aIsCurrent */ true));
+ }
+}
+
+TEST(TestAutoOwningEventTarget, TaskQueue)
+{
+ nsresult rv;
+ nsCOMPtr<nsIEventTarget> threadPool =
+ do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID, &rv);
+ ASSERT_NS_SUCCEEDED(rv);
+
+ auto taskQueue = TaskQueue::Create(threadPool.forget(), "TestTaskQueue",
+ /* aSupportsTailDispatch */ false);
+
+ nsAutoOwningEventTarget autoOwningEventTarget;
+
+ // XXX This call can't be wrapped with ASSERT_NS_SUCCEEDED directly because
+ // base-toolchains builds fail with: error: duplicate label
+ // 'gtest_label_testnofatal_111'
+ rv = SyncRunnable::DispatchToThread(
+ taskQueue,
+ NS_NewRunnableFunction(
+ "TestRunnable", [taskQueue, &autoOwningEventTarget] {
+ {
+ ASSERT_NO_FATAL_FAILURE(CheckAutoOwningEventTarget(
+ taskQueue, autoOwningEventTarget, /* aIsCurrent */ false));
+ }
+
+ {
+ nsAutoOwningEventTarget autoOwningEventTarget;
+
+ ASSERT_NO_FATAL_FAILURE(CheckAutoOwningEventTarget(
+ taskQueue, autoOwningEventTarget, /* aIsCurrent */ true));
+ }
+ }));
+ ASSERT_NS_SUCCEEDED(rv);
+}
+
+#endif
+
+} // namespace TestAutoOwningEventTarget
diff --git a/xpcom/tests/gtest/TestThreadUtils.cpp b/xpcom/tests/gtest/TestThreadUtils.cpp
index 2b9ff97192..96b1342885 100644
--- a/xpcom/tests/gtest/TestThreadUtils.cpp
+++ b/xpcom/tests/gtest/TestThreadUtils.cpp
@@ -885,122 +885,88 @@ TEST(ThreadUtils, IdleTaskRunner)
TEST(ThreadUtils, TypeTraits)
{
- static_assert(!mozilla::IsRefcountedSmartPointer<int>::value,
- "IsRefcountedSmartPointer<int> should be false");
- static_assert(mozilla::IsRefcountedSmartPointer<RefPtr<int>>::value,
- "IsRefcountedSmartPointer<RefPtr<...>> should be true");
- static_assert(mozilla::IsRefcountedSmartPointer<const RefPtr<int>>::value,
- "IsRefcountedSmartPointer<const RefPtr<...>> should be true");
- static_assert(
- mozilla::IsRefcountedSmartPointer<volatile RefPtr<int>>::value,
- "IsRefcountedSmartPointer<volatile RefPtr<...>> should be true");
- static_assert(
- mozilla::IsRefcountedSmartPointer<const volatile RefPtr<int>>::value,
- "IsRefcountedSmartPointer<const volatile RefPtr<...>> should be true");
- static_assert(mozilla::IsRefcountedSmartPointer<nsCOMPtr<int>>::value,
- "IsRefcountedSmartPointer<nsCOMPtr<...>> should be true");
- static_assert(mozilla::IsRefcountedSmartPointer<const nsCOMPtr<int>>::value,
- "IsRefcountedSmartPointer<const nsCOMPtr<...>> should be true");
- static_assert(
- mozilla::IsRefcountedSmartPointer<volatile nsCOMPtr<int>>::value,
- "IsRefcountedSmartPointer<volatile nsCOMPtr<...>> should be true");
- static_assert(
- mozilla::IsRefcountedSmartPointer<const volatile nsCOMPtr<int>>::value,
- "IsRefcountedSmartPointer<const volatile nsCOMPtr<...>> should be true");
-
- static_assert(std::is_same_v<int, mozilla::RemoveSmartPointer<int>::Type>,
- "RemoveSmartPointer<int>::Type should be int");
- static_assert(std::is_same_v<int*, mozilla::RemoveSmartPointer<int*>::Type>,
- "RemoveSmartPointer<int*>::Type should be int*");
- static_assert(
- std::is_same_v<UniquePtr<int>,
- mozilla::RemoveSmartPointer<UniquePtr<int>>::Type>,
- "RemoveSmartPointer<UniquePtr<int>>::Type should be UniquePtr<int>");
- static_assert(
- std::is_same_v<int, mozilla::RemoveSmartPointer<RefPtr<int>>::Type>,
- "RemoveSmartPointer<RefPtr<int>>::Type should be int");
- static_assert(
- std::is_same_v<int, mozilla::RemoveSmartPointer<const RefPtr<int>>::Type>,
- "RemoveSmartPointer<const RefPtr<int>>::Type should be int");
+ static_assert(std::is_same_v<int, mozilla::RemoveSmartPointer<int>>,
+ "RemoveSmartPointer<int> should be int");
+ static_assert(std::is_same_v<int*, mozilla::RemoveSmartPointer<int*>>,
+ "RemoveSmartPointer<int*> should be int*");
+ static_assert(std::is_same_v<UniquePtr<int>,
+ mozilla::RemoveSmartPointer<UniquePtr<int>>>,
+ "RemoveSmartPointer<UniquePtr<int>> should be UniquePtr<int>");
+ static_assert(std::is_same_v<int, mozilla::RemoveSmartPointer<RefPtr<int>>>,
+ "RemoveSmartPointer<RefPtr<int>> should be int");
+ static_assert(
+ std::is_same_v<int, mozilla::RemoveSmartPointer<const RefPtr<int>>>,
+ "RemoveSmartPointer<const RefPtr<int>> should be int");
+ static_assert(
+ std::is_same_v<int, mozilla::RemoveSmartPointer<volatile RefPtr<int>>>,
+ "RemoveSmartPointer<volatile RefPtr<int>> should be int");
static_assert(
std::is_same_v<int,
- mozilla::RemoveSmartPointer<volatile RefPtr<int>>::Type>,
- "RemoveSmartPointer<volatile RefPtr<int>>::Type should be int");
- static_assert(
- std::is_same_v<
- int, mozilla::RemoveSmartPointer<const volatile RefPtr<int>>::Type>,
- "RemoveSmartPointer<const volatile RefPtr<int>>::Type should be int");
+ mozilla::RemoveSmartPointer<const volatile RefPtr<int>>>,
+ "RemoveSmartPointer<const volatile RefPtr<int>> should be int");
+ static_assert(std::is_same_v<int, mozilla::RemoveSmartPointer<nsCOMPtr<int>>>,
+ "RemoveSmartPointer<nsCOMPtr<int>> should be int");
static_assert(
- std::is_same_v<int, mozilla::RemoveSmartPointer<nsCOMPtr<int>>::Type>,
- "RemoveSmartPointer<nsCOMPtr<int>>::Type should be int");
+ std::is_same_v<int, mozilla::RemoveSmartPointer<const nsCOMPtr<int>>>,
+ "RemoveSmartPointer<const nsCOMPtr<int>> should be int");
static_assert(
- std::is_same_v<int,
- mozilla::RemoveSmartPointer<const nsCOMPtr<int>>::Type>,
- "RemoveSmartPointer<const nsCOMPtr<int>>::Type should be int");
+ std::is_same_v<int, mozilla::RemoveSmartPointer<volatile nsCOMPtr<int>>>,
+ "RemoveSmartPointer<volatile nsCOMPtr<int>> should be int");
static_assert(
std::is_same_v<int,
- mozilla::RemoveSmartPointer<volatile nsCOMPtr<int>>::Type>,
- "RemoveSmartPointer<volatile nsCOMPtr<int>>::Type should be int");
- static_assert(
- std::is_same_v<
- int, mozilla::RemoveSmartPointer<const volatile nsCOMPtr<int>>::Type>,
- "RemoveSmartPointer<const volatile nsCOMPtr<int>>::Type should be int");
+ mozilla::RemoveSmartPointer<const volatile nsCOMPtr<int>>>,
+ "RemoveSmartPointer<const volatile nsCOMPtr<int>> should be int");
- static_assert(
- std::is_same_v<int, mozilla::RemoveRawOrSmartPointer<int>::Type>,
- "RemoveRawOrSmartPointer<int>::Type should be int");
+ static_assert(std::is_same_v<int, mozilla::RemoveRawOrSmartPointer<int>>,
+ "RemoveRawOrSmartPointer<int> should be int");
static_assert(
std::is_same_v<UniquePtr<int>,
- mozilla::RemoveRawOrSmartPointer<UniquePtr<int>>::Type>,
- "RemoveRawOrSmartPointer<UniquePtr<int>>::Type should be UniquePtr<int>");
- static_assert(
- std::is_same_v<int, mozilla::RemoveRawOrSmartPointer<int*>::Type>,
- "RemoveRawOrSmartPointer<int*>::Type should be int");
+ mozilla::RemoveRawOrSmartPointer<UniquePtr<int>>>,
+ "RemoveRawOrSmartPointer<UniquePtr<int>> should be UniquePtr<int>");
+ static_assert(std::is_same_v<int, mozilla::RemoveRawOrSmartPointer<int*>>,
+ "RemoveRawOrSmartPointer<int*> should be int");
static_assert(
- std::is_same_v<const int,
- mozilla::RemoveRawOrSmartPointer<const int*>::Type>,
- "RemoveRawOrSmartPointer<const int*>::Type should be const int");
+ std::is_same_v<const int, mozilla::RemoveRawOrSmartPointer<const int*>>,
+ "RemoveRawOrSmartPointer<const int*> should be const int");
static_assert(
std::is_same_v<volatile int,
- mozilla::RemoveRawOrSmartPointer<volatile int*>::Type>,
- "RemoveRawOrSmartPointer<volatile int*>::Type should be volatile int");
+ mozilla::RemoveRawOrSmartPointer<volatile int*>>,
+ "RemoveRawOrSmartPointer<volatile int*> should be volatile int");
static_assert(
- std::is_same_v<const volatile int, mozilla::RemoveRawOrSmartPointer<
- const volatile int*>::Type>,
- "RemoveRawOrSmartPointer<const volatile int*>::Type should be const "
+ std::is_same_v<const volatile int,
+ mozilla::RemoveRawOrSmartPointer<const volatile int*>>,
+ "RemoveRawOrSmartPointer<const volatile int*> should be const "
"volatile int");
static_assert(
- std::is_same_v<int, mozilla::RemoveRawOrSmartPointer<RefPtr<int>>::Type>,
- "RemoveRawOrSmartPointer<RefPtr<int>>::Type should be int");
+ std::is_same_v<int, mozilla::RemoveRawOrSmartPointer<RefPtr<int>>>,
+ "RemoveRawOrSmartPointer<RefPtr<int>> should be int");
+ static_assert(
+ std::is_same_v<int, mozilla::RemoveRawOrSmartPointer<const RefPtr<int>>>,
+ "RemoveRawOrSmartPointer<const RefPtr<int>> should be int");
static_assert(
std::is_same_v<int,
- mozilla::RemoveRawOrSmartPointer<const RefPtr<int>>::Type>,
- "RemoveRawOrSmartPointer<const RefPtr<int>>::Type should be int");
+ mozilla::RemoveRawOrSmartPointer<volatile RefPtr<int>>>,
+ "RemoveRawOrSmartPointer<volatile RefPtr<int>> should be int");
static_assert(
std::is_same_v<
- int, mozilla::RemoveRawOrSmartPointer<volatile RefPtr<int>>::Type>,
- "RemoveRawOrSmartPointer<volatile RefPtr<int>>::Type should be int");
- static_assert(
- std::is_same_v<int, mozilla::RemoveRawOrSmartPointer<
- const volatile RefPtr<int>>::Type>,
- "RemoveRawOrSmartPointer<const volatile RefPtr<int>>::Type should be "
+ int, mozilla::RemoveRawOrSmartPointer<const volatile RefPtr<int>>>,
+ "RemoveRawOrSmartPointer<const volatile RefPtr<int>> should be "
"int");
static_assert(
+ std::is_same_v<int, mozilla::RemoveRawOrSmartPointer<nsCOMPtr<int>>>,
+ "RemoveRawOrSmartPointer<nsCOMPtr<int>> should be int");
+ static_assert(
std::is_same_v<int,
- mozilla::RemoveRawOrSmartPointer<nsCOMPtr<int>>::Type>,
- "RemoveRawOrSmartPointer<nsCOMPtr<int>>::Type should be int");
+ mozilla::RemoveRawOrSmartPointer<const nsCOMPtr<int>>>,
+ "RemoveRawOrSmartPointer<const nsCOMPtr<int>> should be int");
static_assert(
- std::is_same_v<
- int, mozilla::RemoveRawOrSmartPointer<const nsCOMPtr<int>>::Type>,
- "RemoveRawOrSmartPointer<const nsCOMPtr<int>>::Type should be int");
+ std::is_same_v<int,
+ mozilla::RemoveRawOrSmartPointer<volatile nsCOMPtr<int>>>,
+ "RemoveRawOrSmartPointer<volatile nsCOMPtr<int>> should be int");
static_assert(
std::is_same_v<
- int, mozilla::RemoveRawOrSmartPointer<volatile nsCOMPtr<int>>::Type>,
- "RemoveRawOrSmartPointer<volatile nsCOMPtr<int>>::Type should be int");
- static_assert(
- std::is_same_v<int, mozilla::RemoveRawOrSmartPointer<
- const volatile nsCOMPtr<int>>::Type>,
- "RemoveRawOrSmartPointer<const volatile nsCOMPtr<int>>::Type should be "
+ int, mozilla::RemoveRawOrSmartPointer<const volatile nsCOMPtr<int>>>,
+ "RemoveRawOrSmartPointer<const volatile nsCOMPtr<int>> should be "
"int");
}
@@ -1289,15 +1255,9 @@ TEST(ThreadUtils, main)
static_assert(!IsParameterStorageClass<int>::value,
"'int' should not be recognized as Storage Class");
static_assert(
- IsParameterStorageClass<StoreCopyPassByValue<int>>::value,
- "StoreCopyPassByValue<int> should be recognized as Storage Class");
- static_assert(
IsParameterStorageClass<StoreCopyPassByConstLRef<int>>::value,
"StoreCopyPassByConstLRef<int> should be recognized as Storage Class");
static_assert(
- IsParameterStorageClass<StoreCopyPassByLRef<int>>::value,
- "StoreCopyPassByLRef<int> should be recognized as Storage Class");
- static_assert(
IsParameterStorageClass<StoreCopyPassByRRef<int>>::value,
"StoreCopyPassByRRef<int> should be recognized as Storage Class");
static_assert(
@@ -1315,12 +1275,6 @@ TEST(ThreadUtils, main)
static_assert(
IsParameterStorageClass<StoreConstPtrPassByConstPtr<int>>::value,
"StoreConstPtrPassByConstPtr<int> should be recognized as Storage Class");
- static_assert(
- IsParameterStorageClass<StoreCopyPassByConstPtr<int>>::value,
- "StoreCopyPassByConstPtr<int> should be recognized as Storage Class");
- static_assert(
- IsParameterStorageClass<StoreCopyPassByPtr<int>>::value,
- "StoreCopyPassByPtr<int> should be recognized as Storage Class");
RefPtr<ThreadUtilsObject> rpt(new ThreadUtilsObject);
int count = 0;
@@ -1359,11 +1313,6 @@ TEST(ThreadUtils, main)
StoreCopyPassByConstLRef<int>>,
"detail::ParameterStorage<int>::Type should be "
"StoreCopyPassByConstLRef<int>");
- static_assert(std::is_same_v<
- ::detail::ParameterStorage<StoreCopyPassByValue<int>>::Type,
- StoreCopyPassByValue<int>>,
- "detail::ParameterStorage<StoreCopyPassByValue<int>>::Type "
- "should be StoreCopyPassByValue<int>");
r1 = NewRunnableMethod<int>("TestThreadUtils::ThreadUtilsObject::Test1i", rpt,
&ThreadUtilsObject::Test1i, 12);
@@ -1480,37 +1429,6 @@ TEST(ThreadUtils, main)
EXPECT_EQ(i, rpt->mA0);
}
- // Raw pointer to copy.
- static_assert(std::is_same_v<StoreCopyPassByPtr<int>::stored_type, int>,
- "StoreCopyPassByPtr<int>::stored_type should be int");
- static_assert(std::is_same_v<StoreCopyPassByPtr<int>::passed_type, int*>,
- "StoreCopyPassByPtr<int>::passed_type should be int*");
- {
- int i = 1202;
- r1 = NewRunnableMethod<StoreCopyPassByPtr<int>>(
- "TestThreadUtils::ThreadUtilsObject::Test1pi", rpt,
- &ThreadUtilsObject::Test1pi, i);
- r1->Run();
- EXPECT_EQ(count += 2, rpt->mCount);
- EXPECT_EQ(i, rpt->mA0);
- }
-
- // Raw pointer to const copy.
- static_assert(std::is_same_v<StoreCopyPassByConstPtr<int>::stored_type, int>,
- "StoreCopyPassByConstPtr<int>::stored_type should be int");
- static_assert(
- std::is_same_v<StoreCopyPassByConstPtr<int>::passed_type, const int*>,
- "StoreCopyPassByConstPtr<int>::passed_type should be const int*");
- {
- int i = 1203;
- r1 = NewRunnableMethod<StoreCopyPassByConstPtr<int>>(
- "TestThreadUtils::ThreadUtilsObject::Test1pci", rpt,
- &ThreadUtilsObject::Test1pci, i);
- r1->Run();
- EXPECT_EQ(count += 2, rpt->mCount);
- EXPECT_EQ(i, rpt->mA0);
- }
-
// nsRefPtr to pointer.
static_assert(
std::is_same_v<::detail::ParameterStorage<
@@ -1536,7 +1454,7 @@ TEST(ThreadUtils, main)
// (more nsRefPtr tests below)
// nsRefPtr for ref-countable classes that do not derive from ISupports.
- static_assert(::detail::HasRefCountMethods<ThreadUtilsRefCountedFinal>::value,
+ static_assert(::detail::HasRefCountMethods<ThreadUtilsRefCountedFinal>,
"ThreadUtilsRefCountedFinal has AddRef() and Release()");
static_assert(
std::is_same_v<
@@ -1544,7 +1462,7 @@ TEST(ThreadUtils, main)
StoreRefPtrPassByPtr<ThreadUtilsRefCountedFinal>>,
"ParameterStorage<ThreadUtilsRefCountedFinal*>::Type should be "
"StoreRefPtrPassByPtr<ThreadUtilsRefCountedFinal>");
- static_assert(::detail::HasRefCountMethods<ThreadUtilsRefCountedBase>::value,
+ static_assert(::detail::HasRefCountMethods<ThreadUtilsRefCountedBase>,
"ThreadUtilsRefCountedBase has AddRef() and Release()");
static_assert(
std::is_same_v<
@@ -1552,9 +1470,8 @@ TEST(ThreadUtils, main)
StoreRefPtrPassByPtr<ThreadUtilsRefCountedBase>>,
"ParameterStorage<ThreadUtilsRefCountedBase*>::Type should be "
"StoreRefPtrPassByPtr<ThreadUtilsRefCountedBase>");
- static_assert(
- ::detail::HasRefCountMethods<ThreadUtilsRefCountedDerived>::value,
- "ThreadUtilsRefCountedDerived has AddRef() and Release()");
+ static_assert(::detail::HasRefCountMethods<ThreadUtilsRefCountedDerived>,
+ "ThreadUtilsRefCountedDerived has AddRef() and Release()");
static_assert(
std::is_same_v<
::detail::ParameterStorage<ThreadUtilsRefCountedDerived*>::Type,
@@ -1562,7 +1479,7 @@ TEST(ThreadUtils, main)
"ParameterStorage<ThreadUtilsRefCountedDerived*>::Type should be "
"StoreRefPtrPassByPtr<ThreadUtilsRefCountedDerived>");
- static_assert(!::detail::HasRefCountMethods<ThreadUtilsNonRefCounted>::value,
+ static_assert(!::detail::HasRefCountMethods<ThreadUtilsNonRefCounted>,
"ThreadUtilsNonRefCounted doesn't have AddRef() and Release()");
static_assert(!std::is_same_v<
::detail::ParameterStorage<ThreadUtilsNonRefCounted*>::Type,
@@ -1738,126 +1655,6 @@ TEST(ThreadUtils, main)
Spy::ClearAll();
if (gDebug) {
- printf("%d - Test: Store copy from lvalue, pass by value\n", __LINE__);
- }
- { // Block around nsCOMPtr lifetime.
- nsCOMPtr<nsIRunnable> r2;
- { // Block around Spy lifetime.
- if (gDebug) {
- printf("%d - Spy s(10)\n", __LINE__);
- }
- Spy s(10);
- EXPECT_EQ(1, gConstructions);
- EXPECT_EQ(1, gAlive);
- if (gDebug) {
- printf(
- "%d - r2 = "
- "NewRunnableMethod<StoreCopyPassByValue<Spy>>(&TestByValue, s)\n",
- __LINE__);
- }
- r2 = NewRunnableMethod<StoreCopyPassByValue<Spy>>(
- "TestThreadUtils::ThreadUtilsObject::TestByValue", rpt,
- &ThreadUtilsObject::TestByValue, s);
- EXPECT_EQ(2, gAlive);
- EXPECT_LE(1, gCopyConstructions); // At least 1 copy-construction.
- Spy::ClearActions();
- if (gDebug) {
- printf("%d - End block with Spy s(10)\n", __LINE__);
- }
- }
- EXPECT_EQ(1, gDestructions);
- EXPECT_EQ(1, gAlive);
- Spy::ClearActions();
- if (gDebug) {
- printf("%d - Run()\n", __LINE__);
- }
- r2->Run();
- EXPECT_LE(1, gCopyConstructions); // Another copy-construction in call.
- EXPECT_EQ(10, rpt->mSpy.mID);
- EXPECT_LE(1, gDestructions);
- EXPECT_EQ(1, gAlive);
- Spy::ClearActions();
- if (gDebug) {
- printf("%d - End block with r\n", __LINE__);
- }
- }
- if (gDebug) {
- printf("%d - After end block with r\n", __LINE__);
- }
- EXPECT_EQ(1, gDestructions);
- EXPECT_EQ(0, gAlive);
-
- Spy::ClearAll();
- if (gDebug) {
- printf("%d - Test: Store copy from prvalue, pass by value\n", __LINE__);
- }
- {
- if (gDebug) {
- printf(
- "%d - r3 = "
- "NewRunnableMethod<StoreCopyPassByValue<Spy>>(&TestByValue, "
- "Spy(11))\n",
- __LINE__);
- }
- nsCOMPtr<nsIRunnable> r3 = NewRunnableMethod<StoreCopyPassByValue<Spy>>(
- "TestThreadUtils::ThreadUtilsObject::TestByValue", rpt,
- &ThreadUtilsObject::TestByValue, Spy(11));
- EXPECT_EQ(1, gAlive);
- EXPECT_EQ(1, gConstructions);
- EXPECT_LE(1, gMoveConstructions);
- Spy::ClearActions();
- if (gDebug) {
- printf("%d - Run()\n", __LINE__);
- }
- r3->Run();
- EXPECT_LE(1, gCopyConstructions); // Another copy-construction in call.
- EXPECT_EQ(11, rpt->mSpy.mID);
- EXPECT_LE(1, gDestructions);
- EXPECT_EQ(1, gAlive);
- Spy::ClearActions();
- if (gDebug) {
- printf("%d - End block with r\n", __LINE__);
- }
- }
- if (gDebug) {
- printf("%d - After end block with r\n", __LINE__);
- }
- EXPECT_EQ(1, gDestructions);
- EXPECT_EQ(0, gAlive);
-
- Spy::ClearAll();
- { // Store copy from xvalue, pass by value.
- nsCOMPtr<nsIRunnable> r4;
- {
- Spy s(12);
- EXPECT_EQ(1, gConstructions);
- EXPECT_EQ(1, gAlive);
- Spy::ClearActions();
- r4 = NewRunnableMethod<StoreCopyPassByValue<Spy>>(
- "TestThreadUtils::ThreadUtilsObject::TestByValue", rpt,
- &ThreadUtilsObject::TestByValue, std::move(s));
- EXPECT_LE(1, gMoveConstructions);
- EXPECT_EQ(1, gAlive);
- EXPECT_EQ(1, gZombies);
- Spy::ClearActions();
- }
- EXPECT_EQ(1, gDestructions);
- EXPECT_EQ(1, gAlive);
- EXPECT_EQ(0, gZombies);
- Spy::ClearActions();
- r4->Run();
- EXPECT_LE(1, gCopyConstructions); // Another copy-construction in call.
- EXPECT_EQ(12, rpt->mSpy.mID);
- EXPECT_LE(1, gDestructions);
- EXPECT_EQ(1, gAlive);
- Spy::ClearActions();
- }
- EXPECT_EQ(1, gDestructions);
- EXPECT_EQ(0, gAlive);
- // Won't test xvalues anymore, prvalues are enough to verify all rvalues.
-
- Spy::ClearAll();
- if (gDebug) {
printf("%d - Test: Store copy from lvalue, pass by const lvalue ref\n",
__LINE__);
}
diff --git a/xpcom/tests/gtest/moz.build b/xpcom/tests/gtest/moz.build
index 57ec43a371..6fd509d7b2 100644
--- a/xpcom/tests/gtest/moz.build
+++ b/xpcom/tests/gtest/moz.build
@@ -9,6 +9,7 @@ UNIFIED_SOURCES += [
"TestArenaAllocator.cpp",
"TestArrayAlgorithm.cpp",
"TestAtoms.cpp",
+ "TestAutoOwningEventTarget.cpp",
"TestAutoRefCnt.cpp",
"TestBase64.cpp",
"TestCallTemplates.cpp",
@@ -120,10 +121,14 @@ else:
if CONFIG["OS_TARGET"] == "Darwin":
UNIFIED_SOURCES += [
"TestAvailableMemoryWatcherMac.cpp",
- "TestMacNSURLEscaping.mm",
"TestThreads_mac.mm",
]
+if CONFIG["TARGET_OS"] == "OSX":
+ UNIFIED_SOURCES += [
+ "TestMacNSURLEscaping.mm",
+ ]
+
if CONFIG["OS_TARGET"] == "Linux":
UNIFIED_SOURCES += [
"TestAvailableMemoryWatcherLinux.cpp",