Bug 1313477 - Convert XPCOM test TestObserverArray to a gtest. r=froydnj
authorEric Rahm <erahm@mozilla.com>
Fri, 04 Nov 2016 16:23:38 -0700
changeset 351266 b64e935b6316c2ebae0566d0577f0996d9729fc5
parent 351265 ce050e1aab2f73e214566fdb9bd00e2d45aff281
child 351267 9559827d07d0f7ddfbf38eec42140c4b6f26195e
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1313477
milestone52.0a1
Bug 1313477 - Convert XPCOM test TestObserverArray to a gtest. r=froydnj This is a very straightforward conversion of TestObserverArray. The tests were not split out as they are all dependent on each other. The test macro was left as well as converting it to a proper function would require a fair amount of modification to the tests. MozReview-Commit-ID: Bz9aWbAwBS
testing/cppunittest.ini
xpcom/tests/TestObserverArray.cpp
xpcom/tests/gtest/TestObserverArray.cpp
xpcom/tests/gtest/moz.build
xpcom/tests/moz.build
--- a/testing/cppunittest.ini
+++ b/testing/cppunittest.ini
@@ -42,17 +42,16 @@ skip-if = os != 'win'
 [TestMacroArgs]
 [TestMacroForEach]
 [TestMathAlgorithms]
 [TestMaybe]
 [TestNativeXMLHttpRequest]
 skip-if = os == 'b2g' || os == 'android'  #Bug 919642
 [TestNtPathToDosPath]
 skip-if = os != 'win'
-[TestObserverArray]
 [TestObserverService]
 [TestPLDHash]
 skip-if = os == 'b2g'  #Bug 1038197
 [TestPair]
 [TestPlainTextSerializer]
 skip-if = os == 'b2g' || os == 'android'  #Bug 919599
 [TestPoisonArea]
 skip-if = os == 'android' # Bug 1147630
rename from xpcom/tests/TestObserverArray.cpp
rename to xpcom/tests/gtest/TestObserverArray.cpp
--- a/xpcom/tests/TestObserverArray.cpp
+++ b/xpcom/tests/gtest/TestObserverArray.cpp
@@ -1,55 +1,38 @@
 /* -*- 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 "TestHarness.h"
 #include "nsTObserverArray.h"
+#include "gtest/gtest.h"
 
 using namespace mozilla;
 
 typedef nsTObserverArray<int> IntArray;
 
 #define DO_TEST(_type, _exp, _code)                                   \
   do {                                                                \
     ++testNum;                                                        \
     count = 0;                                                        \
     IntArray::_type iter(arr);                                        \
     while (iter.HasMore() && count != ArrayLength(_exp)) {            \
       _code                                                           \
       int next = iter.GetNext();                                      \
       int expected = _exp[count++];                                   \
-      if (next != expected) {                                         \
-        fail("During test %d at position %d got %d expected %d\n",    \
-             testNum, count-1, next, expected);                       \
-        rv = 1;                                                       \
-      }                                                               \
+      ASSERT_EQ(next, expected) << "During test " << testNum << " at position " << count - 1;  \
     }                                                                 \
-    if (iter.HasMore()) {                                             \
-      fail("During test %d, iterator ran over", testNum);             \
-      rv = 1;                                                         \
-    }                                                                 \
-    if (count != ArrayLength(_exp)) {                             \
-      fail("During test %d, iterator finished too early", testNum);   \
-      rv = 1;                                                         \
-    }                                                                 \
+    ASSERT_FALSE(iter.HasMore()) << "During test " << testNum << ", iterator ran over"; \
+    ASSERT_EQ(count, ArrayLength(_exp)) << "During test " << testNum << ", iterator finished too early"; \
   } while (0)
 
-int main(int argc, char **argv)
+TEST(ObserverArray, Tests)
 {
-  ScopedXPCOM xpcom("nsTObserverArrayTests");
-  if (xpcom.failed()) {
-    return 1;
-  }
-
-  int rv = 0;
-
   IntArray arr;
   arr.AppendElement(3);
   arr.AppendElement(4);
 
   size_t count;
   int testNum = 0;
 
   // Basic sanity
@@ -176,10 +159,9 @@ int main(int argc, char **argv)
 
   /**
    * Note: _code is executed before the call to GetNext(), it can therefore not
    * test the case of prepending when the BackwardIterator already returned the
    * first element.
    * In that case BackwardIterator does not traverse the newly prepended Element
    */
 
-  return rv;
 }
--- a/xpcom/tests/gtest/moz.build
+++ b/xpcom/tests/gtest/moz.build
@@ -14,16 +14,17 @@ UNIFIED_SOURCES += [
     'TestCOMPtrEq.cpp',
     'TestCRT.cpp',
     'TestEncoding.cpp',
     'TestEscapeURL.cpp',
     'TestExpirationTracker.cpp',
     'TestFile.cpp',
     'TestID.cpp',
     'TestNSPRLogModulesParser.cpp',
+    'TestObserverArray.cpp',
     'TestPipes.cpp',
     'TestPLDHash.cpp',
     'TestPriorityQueue.cpp',
     'TestSlicedInputStream.cpp',
     'TestSnappyStreams.cpp',
     'TestStateWatching.cpp',
     'TestStorageStream.cpp',
     'TestStrings.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([
-    'TestObserverArray',
     'TestObserverService',
     'TestStringAPI',
     'TestTArray',
     'TestTextFormatter',
     'TestThreadUtils',
     'TestTimers'
 ])