Bug 1313468: Convert XPCOM test TestAutoRef to a gtest. r=froydnj
authorEric Rahm <erahm@mozilla.com>
Fri, 04 Nov 2016 16:21:37 -0700
changeset 347898 825b955d94df324138255e4ee8e5a4e241171a0d
parent 347755 f092853e564086a98e14f0018ce784bb033e1d85
child 347899 2d4477c3e98f5759db56a626a521231f71b0d5e2
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)
reviewersfroydnj
bugs1313468
milestone52.0a1
Bug 1313468: Convert XPCOM test TestAutoRef to a gtest. r=froydnj MozReview-Commit-ID: GkEPSkzNeuB
testing/cppunittest.ini
xpcom/tests/TestAutoRef.cpp
xpcom/tests/gtest/TestAutoRef.cpp
xpcom/tests/gtest/TestStorageStream.cpp
xpcom/tests/gtest/moz.build
xpcom/tests/moz.build
--- a/testing/cppunittest.ini
+++ b/testing/cppunittest.ini
@@ -1,17 +1,16 @@
 [ShowSSEConfig]
 [TestAppShellSteadyState]
 [TestArray]
 [TestArrayUtils]
 [TestAtomics]
 [TestAudioBuffers]
 skip-if = os == 'b2g'  # Bug 1062937
 [TestAudioMixer]
-[TestAutoRef]
 [TestBinarySearch]
 [TestBind]
 [TestBloomFilter]
 [TestCOM]
 skip-if = os != 'win'
 [TestCOMArray]
 [TestCOMPtr]
 [TestCOMPtrEq]
rename from xpcom/tests/TestAutoRef.cpp
rename to xpcom/tests/gtest/TestAutoRef.cpp
--- a/xpcom/tests/TestAutoRef.cpp
+++ b/xpcom/tests/gtest/TestAutoRef.cpp
@@ -1,27 +1,24 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 // 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 "nsAutoRef.h"
-#include "TestHarness.h"
-
-#define TEST(aCondition, aMsg) \
-  if (!(aCondition)) { fail("TestAutoRef: "#aMsg); exit(1); }
+#include "gtest/gtest.h"
 
 struct TestObjectA {
 public:
   TestObjectA() : mRefCnt(0) {
   }
 
   ~TestObjectA() {
-    TEST(mRefCnt == 0, "mRefCnt in destructor");
+    EXPECT_EQ(mRefCnt, 0);
   }
 
 public:
   int mRefCnt;
 };
 
 template <>
 class nsAutoRefTraits<TestObjectA> : public nsPointerRefTraits<TestObjectA>
@@ -38,25 +35,22 @@ public:
 
   static void AddRef(TestObjectA *ptr) {
     ptr->mRefCnt++;
   }
 };
 
 int nsAutoRefTraits<TestObjectA>::mTotalRefsCnt = 0;
 
-int main()
+TEST(AutoRef, Assignment)
 {
   {
     nsCountedRef<TestObjectA> a(new TestObjectA());
-    TEST(a->mRefCnt == 1, "nsCountedRef instantiation with valid RawRef");
+    ASSERT_EQ(a->mRefCnt, 1);
 
     nsCountedRef<TestObjectA> b;
-    TEST(b.get() == nullptr, "nsCountedRef instantiation with invalid RawRef");
+    ASSERT_EQ(b.get(), nullptr);
 
     a.swap(b);
-    TEST(b->mRefCnt, "nsAutoRef::swap() t1");
-    TEST(a.get() == nullptr, "nsAutoRef::swap() t2");
+    ASSERT_EQ(b->mRefCnt, 1);
+    ASSERT_EQ(a.get(), nullptr);
   }
-
-  TEST(true, "All tests pass");
-  return 0;
 }
--- a/xpcom/tests/gtest/TestStorageStream.cpp
+++ b/xpcom/tests/gtest/TestStorageStream.cpp
@@ -7,16 +7,17 @@
 #include <stdlib.h>
 #include "gtest/gtest.h"
 #include "Helpers.h"
 #include "nsCOMPtr.h"
 #include "nsICloneableInputStream.h"
 #include "nsIInputStream.h"
 #include "nsIOutputStream.h"
 #include "nsIStorageStream.h"
+#include "nsTArray.h"
 
 namespace {
 
 void
 WriteData(nsIOutputStream* aOut, nsTArray<char>& aData, uint32_t aNumBytes,
           nsACString& aDataWritten)
 {
   uint32_t n;
--- a/xpcom/tests/gtest/moz.build
+++ b/xpcom/tests/gtest/moz.build
@@ -3,16 +3,17 @@
 # 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/.
 
 UNIFIED_SOURCES += [
     'Helpers.cpp',
     'TestAtoms.cpp',
     'TestAutoPtr.cpp',
+    'TestAutoRef.cpp',
     'TestCloneInputStream.cpp',
     'TestCRT.cpp',
     'TestEncoding.cpp',
     'TestEscapeURL.cpp',
     'TestExpirationTracker.cpp',
     'TestNSPRLogModulesParser.cpp',
     'TestPipes.cpp',
     'TestPLDHash.cpp',
--- a/xpcom/tests/moz.build
+++ b/xpcom/tests/moz.build
@@ -41,17 +41,16 @@ if CONFIG['OS_TARGET'] == 'WINNT':
 if CONFIG['WRAP_STL_INCLUDES'] and not CONFIG['CLANG_CL']:
     GeckoSimplePrograms([
         'TestSTLWrappers',
     ])
 
 XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
 
 GeckoCppUnitTests([
-    'TestAutoRef',
     'TestCOMArray',
     'TestCOMPtr',
     'TestCOMPtrEq',
     'TestFile',
     'TestHashtables',
     'TestID',
     'TestNsRefPtr',
     'TestObserverArray',