Bug 1313482 - Convert XPCOM test TestTextFormatter to a gtest. r=froydnj
authorEric Rahm <erahm@mozilla.com>
Fri, 04 Nov 2016 16:24:42 -0700
changeset 321228 c1809c625dcaf04a27de1256b82abd55b7ed2640
parent 321227 2f27c76cb23119d2924dd8ccd8fe827ec9de06ed
child 321229 d0f06f2fdba053344e07fbd5b4e55af117077dd4
push id30920
push userphilringnalda@gmail.com
push dateSat, 05 Nov 2016 20:41:02 +0000
treeherdermozilla-central@c44c01dfd264 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1313482
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1313482 - Convert XPCOM test TestTextFormatter to a gtest. r=froydnj MozReview-Commit-ID: FQ5K3jvqb7c
testing/cppunittest.ini
xpcom/tests/TestTextFormatter.cpp
xpcom/tests/gtest/TestTextFormatter.cpp
xpcom/tests/gtest/moz.build
xpcom/tests/moz.build
--- a/testing/cppunittest.ini
+++ b/testing/cppunittest.ini
@@ -65,17 +65,16 @@ skip-if = os == 'android' # Bug 1147630
 [TestStartupCache]
 skip-if = os == 'b2g' || os == 'android'  # Bug 929655
 support-files = TestStartupCacheTelemetry.js TestStartupCacheTelemetry.manifest
 [TestSyncRunnable]
 [TestTimers]
 [TestTXMgr]
 skip-if = os == 'b2g'  #Bug 919595
 [TestTemplateLib]
-[TestTextFormatter]
 [TestThreadUtils]
 [TestTuple]
 [TestTypeTraits]
 [TestTypedEnum]
 [TestUDPSocket]
 [TestUniquePtr]
 [TestVariant]
 [TestVector]
rename from xpcom/tests/TestTextFormatter.cpp
rename to xpcom/tests/gtest/TestTextFormatter.cpp
--- a/xpcom/tests/TestTextFormatter.cpp
+++ b/xpcom/tests/gtest/TestTextFormatter.cpp
@@ -1,40 +1,34 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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 <nsTextFormatter.h>
-#include <nsStringGlue.h>
-#include <stdio.h>
+#include "nsTextFormatter.h"
+#include "nsString.h"
+#include "gtest/gtest.h"
 
-int main() 
-{  
-  int test_ok = true;
-
+TEST(TextFormatter, Tests)
+{
   nsAutoString fmt(NS_LITERAL_STRING("%3$s %4$S %1$d %2$d %2$d %3$s"));
-  char utf8[] = "Hello"; 
-  char16_t ucs2[]={'W', 'o', 'r', 'l', 'd', 0x4e00, 0xAc00, 0xFF45, 0x0103, 0x00}; 
-  int d=3; 
+  char utf8[] = "Hello";
+  char16_t ucs2[]={'W', 'o', 'r', 'l', 'd', 0x4e00, 0xAc00, 0xFF45, 0x0103, 0x00};
+  int d=3;
 
-  char16_t buf[256]; 
-  nsTextFormatter::snprintf(buf, 256, fmt.get(), d, 333, utf8, ucs2); 
-  nsAutoString out(buf); 
-  if(strcmp("Hello World", NS_LossyConvertUTF16toASCII(out).get()))
-    test_ok = false;
+  char16_t buf[256];
+  nsTextFormatter::snprintf(buf, 256, fmt.get(), d, 333, utf8, ucs2);
+  nsAutoString out(buf);
+  ASSERT_STREQ("Hello World", NS_LossyConvertUTF16toASCII(out).get());
 
-  const char16_t *uout = out.get(); 
+  const char16_t *uout = out.get();
   const char16_t expected[] = {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20,
                                 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x4E00,
                                 0xAC00, 0xFF45, 0x0103, 0x20, 0x33,
                                 0x20, 0x33, 0x33, 0x33, 0x20, 0x33,
                                 0x33, 0x33, 0x20, 0x48, 0x65, 0x6C,
                                 0x6C, 0x6F};
-  for(uint32_t i=0;i<out.Length();i++) {
-    if(uout[i] != expected[i]) {
-      test_ok = false;
-      break;
-    }
+
+  for (uint32_t i=0; i<out.Length(); i++) {
+    ASSERT_EQ(uout[i], expected[i]);
   }
-  printf(test_ok? "nsTextFormatter: OK\n": "nsTextFormatter: FAIL\n");
 }
 
--- a/xpcom/tests/gtest/moz.build
+++ b/xpcom/tests/gtest/moz.build
@@ -28,16 +28,17 @@ UNIFIED_SOURCES += [
     'TestSnappyStreams.cpp',
     'TestStateWatching.cpp',
     'TestStorageStream.cpp',
     'TestStrings.cpp',
     'TestStringStream.cpp',
     'TestSynchronization.cpp',
     'TestTArray.cpp',
     'TestTArray2.cpp',
+    'TestTextFormatter.cpp',
     'TestThreadPool.cpp',
     'TestThreads.cpp',
     'TestTimeStamp.cpp',
     'TestTokenizer.cpp',
     'TestUTF.cpp',
     'TestXPIDLString.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([
-    'TestTextFormatter',
     'TestThreadUtils',
     'TestTimers'
 ])
 
 if CONFIG['MOZ_MEMORY']:
     GeckoCppUnitTests([
         'TestJemalloc',
     ])