Bug 1316437 - Convert TestSTLWrappers to a gtest. r=bsmedberg
authorEric Rahm <erahm@mozilla.com>
Thu, 10 Nov 2016 13:04:06 -0800
changeset 352134 ce03bdac8155517a5fe17def6efb1cc6bdc9900d
parent 352133 58fb3bb7a39765788927a8e8dfa184f2a3f73479
child 352135 f424e29dc77ed2790f3ab6e05940a31c4a85316a
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)
reviewersbsmedberg
bugs1316437
milestone52.0a1
Bug 1316437 - Convert TestSTLWrappers to a gtest. r=bsmedberg MozReview-Commit-ID: HRmnWvxyNP
xpcom/tests/TestSTLWrappers.cpp
xpcom/tests/gtest/TestSTLWrappers.cpp
xpcom/tests/gtest/moz.build
xpcom/tests/moz.build
rename from xpcom/tests/TestSTLWrappers.cpp
rename to xpcom/tests/gtest/TestSTLWrappers.cpp
--- a/xpcom/tests/TestSTLWrappers.cpp
+++ b/xpcom/tests/gtest/TestSTLWrappers.cpp
@@ -5,41 +5,74 @@
 #  error "failed to wrap <algorithm>"
 #endif
 
 #include <vector>
 #ifndef mozilla_vector_h
 #  error "failed to wrap <vector>"
 #endif
 
+#ifdef MOZ_CRASHREPORTER
+#include "nsCOMPtr.h"
+#include "nsICrashReporter.h"
+#include "nsServiceManagerUtils.h"
+#endif
+
 // gcc errors out if we |try ... catch| with -fno-exceptions, but we
 // can still test on windows
 #ifdef _MSC_VER
    // C4530 will be generated whenever try...catch is used without
    // enabling exceptions. We know we don't enbale exceptions.
 #  pragma warning( disable : 4530 )
 #  define TRY       try
 #  define CATCH(e)  catch (e)
 #else
 #  define TRY
 #  define CATCH(e)  if (0)
 #endif
 
-int main() {
+
+#if defined(XP_UNIX)
+extern unsigned int _gdb_sleep_duration;
+#endif
+
+void ShouldAbort()
+{
+#if defined(XP_UNIX)
+    _gdb_sleep_duration = 0;
+#endif
+
+#ifdef MOZ_CRASHREPORTER
+    nsCOMPtr<nsICrashReporter> crashreporter =
+        do_GetService("@mozilla.org/toolkit/crash-reporter;1");
+    if (crashreporter) {
+      crashreporter->SetEnabled(false);
+    }
+#endif
+
     std::vector<int> v;
     int rv = 1;
 
     TRY {
       // v.at(1) on empty v should abort; NOT throw an exception
 
       // (Do some arithmetic with result of v.at() to avoid
       // compiler warnings for unused variable/result.)
       rv += v.at(1) ? 1 : 2;
     } CATCH(const std::out_of_range&) {
       fputs("TEST-FAIL | TestSTLWrappers.cpp | caught an exception?\n",
             stderr);
-      return 1;
+      return;
     }
 
     fputs("TEST-FAIL | TestSTLWrappers.cpp | didn't abort()?\n",
           stderr);
-    return rv;
+    return;
 }
+
+#ifdef XP_WIN
+TEST(STLWrapper, DISABLED_ShouldAbortDeathTest)
+#else
+TEST(STLWrapper, ShouldAbortDeathTest)
+#endif
+{
+  ASSERT_DEATH(ShouldAbort(), "terminate called after throwing an instance of 'std::out_of_range'|vector::_M_range_check");
+}
--- a/xpcom/tests/gtest/moz.build
+++ b/xpcom/tests/gtest/moz.build
@@ -51,16 +51,21 @@ UNIFIED_SOURCES += [
 if CONFIG['MOZ_DEBUG'] and CONFIG['OS_ARCH'] not in ('WINNT') and CONFIG['OS_TARGET'] != 'Android':
     # FIXME bug 523392: TestDeadlockDetector doesn't like Windows
     # Bug 1054249: Doesn't work on Android
     UNIFIED_SOURCES += [
         'TestDeadlockDetector.cpp',
         'TestDeadlockDetectorScalability.cpp',
     ]
 
+if CONFIG['WRAP_STL_INCLUDES'] and not CONFIG['CLANG_CL']:
+    UNIFIED_SOURCES += [
+        'TestSTLWrappers.cpp',
+    ]
+
 # Compile TestAllocReplacement separately so Windows headers don't pollute
 # the global namespace for other files.
 SOURCES += [
     'TestAllocReplacement.cpp',
     'TestCOMPtr.cpp', # Redefines IFoo and IBar
     'TestHashtables.cpp', # Redefines IFoo
     'TestNsRefPtr.cpp', # Redefines Foo
 ]
--- a/xpcom/tests/moz.build
+++ b/xpcom/tests/moz.build
@@ -22,21 +22,16 @@ EXPORTS.testing += [
 SimplePrograms([
     'TestArguments',
     'TestBlockingProcess',
     'TestPRIntN',
     'TestQuickReturn',
     'TestUnicodeArguments',
 ])
 
-if CONFIG['WRAP_STL_INCLUDES'] and not CONFIG['CLANG_CL']:
-    GeckoSimplePrograms([
-        'TestSTLWrappers',
-    ])
-
 XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
 
 # FIXME: bug 577500 TestStaticAtoms fails when run in dist/bin
 #CPP_UNIT_TESTS += [
 #    'TestStaticAtoms',
 #]
 
 if CONFIG['COMPILE_ENVIRONMENT']: