Bug 1316191 - Convert XPCOM test TestRacingServiceManager to a gtest. r=bsmedberg
authorEric Rahm <erahm@mozilla.com>
Thu, 10 Nov 2016 12:58:09 -0800
changeset 348776 b0fe1e24154d3533cc3f64d226106c446ee4694e
parent 348775 b10dbdd46d12c4f0d98a6e4c6a6a64adab8dfe22
child 348777 375bb353c101e51e74388cc4cce22164928563f5
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs1316191
milestone52.0a1
Bug 1316191 - Convert XPCOM test TestRacingServiceManager to a gtest. r=bsmedberg MozReview-Commit-ID: QppJYYZrtT
xpcom/tests/TestRacingServiceManager.cpp
xpcom/tests/gtest/TestRacingServiceManager.cpp
xpcom/tests/gtest/moz.build
xpcom/tests/moz.build
rename from xpcom/tests/TestRacingServiceManager.cpp
rename to xpcom/tests/gtest/TestRacingServiceManager.cpp
--- a/xpcom/tests/TestRacingServiceManager.cpp
+++ b/xpcom/tests/gtest/TestRacingServiceManager.cpp
@@ -1,30 +1,31 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 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 "TestHarness.h"
-
 #include "nsIFactory.h"
 #include "mozilla/Module.h"
 #include "nsXULAppAPI.h"
 #include "nsIThread.h"
 #include "nsIComponentRegistrar.h"
 
 #include "nsAutoPtr.h"
 #include "nsThreadUtils.h"
 #include "nsXPCOMCIDInternal.h"
 #include "pratom.h"
 #include "prmon.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
 
 #include "mozilla/ReentrantMonitor.h"
+
+#include "gtest/gtest.h"
+
 using namespace mozilla;
 
 /* f93f6bdc-88af-42d7-9d64-1b43c649a3e5 */ 
 #define FACTORY_CID1                                 \
 {                                                    \
   0xf93f6bdc,                                        \
   0x88af,                                            \
   0x42d7,                                            \
@@ -40,16 +41,18 @@ NS_DEFINE_CID(kFactoryCID1, FACTORY_CID1
   0x49f0,                                            \
   { 0x80, 0x48, 0xe8, 0x19, 0xf8, 0x1d, 0x15, 0xe2 } \
 }
 NS_DEFINE_CID(kFactoryCID2, FACTORY_CID2);
 
 #define FACTORY_CONTRACTID                           \
   "TestRacingThreadManager/factory;1"
 
+namespace TestRacingServiceManager
+{
 int32_t gComponent1Count = 0;
 int32_t gComponent2Count = 0;
 
 ReentrantMonitor* gReentrantMonitor = nullptr;
 
 bool gCreateInstanceCalled = false;
 bool gMainThreadWaiting = false;
 
@@ -122,17 +125,17 @@ class Component2 final : public nsISuppo
   ~Component2() {}
 
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
 
   Component2() {
     // This is the real test - make sure that only one instance is ever created.
     int32_t count = PR_AtomicIncrement(&gComponent2Count);
-    MOZ_RELEASE_ASSERT(count == 1, "Too many components created!");
+    EXPECT_EQ(count, int32_t(1)) << "Too many components created!";
   }
 };
 
 NS_IMPL_ADDREF(Component2)
 NS_IMPL_RELEASE(Component2)
 
 NS_INTERFACE_MAP_BEGIN(Component2)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
@@ -200,17 +203,17 @@ TestRunnable::Run()
   nsCOMPtr<nsISupports> component;
 
   if (!mFirstRunnableDone) {
     component = do_GetService(kFactoryCID1, &rv);
   }
   else {
     component = do_GetService(FACTORY_CONTRACTID, &rv);
   }
-  MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv), "GetService failed!");
+  EXPECT_TRUE(NS_SUCCEEDED(rv)) << "GetService failed!";
 
   return NS_OK;
 }
 
 static Factory* gFactory;
 
 static already_AddRefed<nsIFactory>
 CreateFactory(const mozilla::Module& module, const mozilla::Module::CIDEntry& entry)
@@ -235,66 +238,63 @@ static const mozilla::Module::ContractID
 };
 
 static const mozilla::Module kLocalModule = {
     mozilla::Module::kVersion,
     kLocalCIDs,
     kLocalContracts
 };
 
-int main(int argc, char** argv)
+TEST(RacingServiceManager, Test)
 {
   nsresult rv;
   XRE_AddStaticComponent(&kLocalModule);
 
-  ScopedXPCOM xpcom("RacingServiceManager");
-  NS_ENSURE_FALSE(xpcom.failed(), 1);
-
   AutoCreateAndDestroyReentrantMonitor mon1(&gReentrantMonitor);
 
   RefPtr<TestRunnable> runnable = new TestRunnable();
-  NS_ENSURE_TRUE(runnable, 1);
+  ASSERT_TRUE(runnable);
 
   // Run the classID test
   nsCOMPtr<nsIThread> newThread;
   rv = NS_NewThread(getter_AddRefs(newThread), runnable);
-  NS_ENSURE_SUCCESS(rv, 1);
+  ASSERT_TRUE(NS_SUCCEEDED(rv));
 
   {
     ReentrantMonitorAutoEnter mon2(*gReentrantMonitor);
 
     gMainThreadWaiting = true;
     mon2.Notify();
 
     while (!gCreateInstanceCalled) {
       mon2.Wait();
     }
   }
 
   nsCOMPtr<nsISupports> component(do_GetService(kFactoryCID1, &rv));
-  NS_ENSURE_SUCCESS(rv, 1);
+  ASSERT_TRUE(NS_SUCCEEDED(rv));
 
   // Reset for the contractID test
   gMainThreadWaiting = gCreateInstanceCalled = false;
   gFactory->mFirstComponentCreated = runnable->mFirstRunnableDone = true;
   component = nullptr;
 
   rv = newThread->Dispatch(runnable, NS_DISPATCH_NORMAL);
-  NS_ENSURE_SUCCESS(rv, 1);
+  ASSERT_TRUE(NS_SUCCEEDED(rv));
 
   {
     ReentrantMonitorAutoEnter mon3(*gReentrantMonitor);
 
     gMainThreadWaiting = true;
     mon3.Notify();
 
     while (!gCreateInstanceCalled) {
       mon3.Wait();
     }
   }
 
   component = do_GetService(FACTORY_CONTRACTID, &rv);
-  NS_ENSURE_SUCCESS(rv, 1);
+  ASSERT_TRUE(NS_SUCCEEDED(rv));
 
   NS_RELEASE(gFactory);
+}
 
-  return 0;
-}
+} // namespace TestRacingServiceManager
--- a/xpcom/tests/gtest/moz.build
+++ b/xpcom/tests/gtest/moz.build
@@ -20,16 +20,17 @@ UNIFIED_SOURCES += [
     'TestFile.cpp',
     'TestID.cpp',
     'TestNSPRLogModulesParser.cpp',
     'TestObserverArray.cpp',
     'TestObserverService.cpp',
     'TestPipes.cpp',
     'TestPLDHash.cpp',
     'TestPriorityQueue.cpp',
+    'TestRacingServiceManager.cpp',
     'TestSlicedInputStream.cpp',
     'TestSnappyStreams.cpp',
     'TestStateWatching.cpp',
     'TestStorageStream.cpp',
     'TestStrings.cpp',
     'TestStringStream.cpp',
     'TestSynchronization.cpp',
     'TestTArray.cpp',
--- a/xpcom/tests/moz.build
+++ b/xpcom/tests/moz.build
@@ -23,17 +23,16 @@ SimplePrograms([
     'TestArguments',
     'TestBlockingProcess',
     'TestPRIntN',
     'TestQuickReturn',
 ])
 
 GeckoSimplePrograms([
     'TestINIParser',
-    'TestRacingServiceManager',
     'TestRegistrationOrder',
     'TestUnicodeArguments',
 ])
 
 if CONFIG['OS_TARGET'] == 'WINNT':
     GeckoSimplePrograms([
         'TestBase64',
     ])