Bug 1126301 - Move TestUTF.cpp to gtest and enable it; r=froydnj
☠☠ backed out by 00afd1e64aa0 ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 27 Jan 2015 12:38:44 -0500
changeset 226022 c61a87a20888ebf068761c1d2ce3d461b589cb5f
parent 226021 186127d710767bf094464a151d5f88b3157992f5
child 226023 e3d924b6797f92a37db62429065de7cd5347fda6
push id54736
push usereakhgari@mozilla.com
push dateTue, 27 Jan 2015 17:39:37 +0000
treeherdermozilla-inbound@c61a87a20888 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1126301
milestone38.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 1126301 - Move TestUTF.cpp to gtest and enable it; r=froydnj
xpcom/tests/TestUTF.cpp
xpcom/tests/gtest/TestUTF.cpp
xpcom/tests/gtest/moz.build
xpcom/tests/moz.build
rename from xpcom/tests/TestUTF.cpp
rename to xpcom/tests/gtest/TestUTF.cpp
--- a/xpcom/tests/TestUTF.cpp
+++ b/xpcom/tests/gtest/TestUTF.cpp
@@ -8,182 +8,116 @@
 #include <stdlib.h>
 #include "nsString.h"
 #include "nsStringBuffer.h"
 #include "nsReadableUtils.h"
 #include "UTFStrings.h"
 #include "nsUnicharUtils.h"
 #include "mozilla/HashFunctions.h"
 
+#include "gtest/gtest.h"
+
 using namespace mozilla;
 
 namespace TestUTF {
 
-bool
-test_valid()
+TEST(UTF, Valid)
 {
   for (unsigned int i = 0; i < ArrayLength(ValidStrings); ++i) {
     nsDependentCString str8(ValidStrings[i].m8);
     nsDependentString str16(ValidStrings[i].m16);
 
-    if (!NS_ConvertUTF16toUTF8(str16).Equals(str8))
-      return false;
+    EXPECT_TRUE(NS_ConvertUTF16toUTF8(str16).Equals(str8));
 
-    if (!NS_ConvertUTF8toUTF16(str8).Equals(str16))
-      return false;
+    EXPECT_TRUE(NS_ConvertUTF8toUTF16(str8).Equals(str16));
 
     nsCString tmp8("string ");
     AppendUTF16toUTF8(str16, tmp8);
-    if (!tmp8.Equals(NS_LITERAL_CSTRING("string ") + str8))
-      return false;
+    EXPECT_TRUE(tmp8.Equals(NS_LITERAL_CSTRING("string ") + str8));
 
     nsString tmp16(NS_LITERAL_STRING("string "));
     AppendUTF8toUTF16(str8, tmp16);
-    if (!tmp16.Equals(NS_LITERAL_STRING("string ") + str16))
-      return false;
+    EXPECT_TRUE(tmp16.Equals(NS_LITERAL_STRING("string ") + str16));
 
-    if (CompareUTF8toUTF16(str8, str16) != 0)
-      return false;
+    EXPECT_EQ(CompareUTF8toUTF16(str8, str16), 0);
   }
-  
-  return true;
 }
 
-bool
-test_invalid16()
+TEST(UTF, Invalid16)
 {
   for (unsigned int i = 0; i < ArrayLength(Invalid16Strings); ++i) {
     nsDependentString str16(Invalid16Strings[i].m16);
     nsDependentCString str8(Invalid16Strings[i].m8);
 
-    if (!NS_ConvertUTF16toUTF8(str16).Equals(str8))
-      return false;
+    EXPECT_TRUE(NS_ConvertUTF16toUTF8(str16).Equals(str8));
 
     nsCString tmp8("string ");
     AppendUTF16toUTF8(str16, tmp8);
-    if (!tmp8.Equals(NS_LITERAL_CSTRING("string ") + str8))
-      return false;
+    EXPECT_TRUE(tmp8.Equals(NS_LITERAL_CSTRING("string ") + str8));
 
-    if (CompareUTF8toUTF16(str8, str16) != 0)
-      return false;
+    EXPECT_EQ(CompareUTF8toUTF16(str8, str16), 0);
   }
-  
-  return true;
 }
 
-bool
-test_invalid8()
+TEST(UTF, Invalid8)
 {
   for (unsigned int i = 0; i < ArrayLength(Invalid8Strings); ++i) {
     nsDependentString str16(Invalid8Strings[i].m16);
     nsDependentCString str8(Invalid8Strings[i].m8);
 
-    if (!NS_ConvertUTF8toUTF16(str8).Equals(str16))
-      return false;
+    EXPECT_TRUE(NS_ConvertUTF8toUTF16(str8).Equals(str16));
 
     nsString tmp16(NS_LITERAL_STRING("string "));
     AppendUTF8toUTF16(str8, tmp16);
-    if (!tmp16.Equals(NS_LITERAL_STRING("string ") + str16))
-      return false;
+    EXPECT_TRUE(tmp16.Equals(NS_LITERAL_STRING("string ") + str16));
 
-    if (CompareUTF8toUTF16(str8, str16) != 0)
-      return false;
+    EXPECT_EQ(CompareUTF8toUTF16(str8, str16), 0);
   }
-  
-  return true;
 }
 
-bool
-test_malformed8()
+TEST(UTF, Malformed8)
 {
 // Don't run this test in debug builds as that intentionally asserts.
 #ifndef DEBUG
   for (unsigned int i = 0; i < ArrayLength(Malformed8Strings); ++i) {
     nsDependentCString str8(Malformed8Strings[i]);
 
-    if (!NS_ConvertUTF8toUTF16(str8).IsEmpty())
-      return false;
+    EXPECT_TRUE(NS_ConvertUTF8toUTF16(str8).IsEmpty());
 
     nsString tmp16(NS_LITERAL_STRING("string"));
     AppendUTF8toUTF16(str8, tmp16);
-    if (!tmp16.EqualsLiteral("string"))
-      return false;
+    EXPECT_TRUE(tmp16.EqualsLiteral("string"));
 
-    if (CompareUTF8toUTF16(str8, EmptyString()) == 0)
-      return false;
+    EXPECT_NE(CompareUTF8toUTF16(str8, EmptyString()), 0);
   }
 #endif
-  
-  return true;
 }
 
-bool
-test_hashas16()
+TEST(UTF, Hash16)
 {
   for (unsigned int i = 0; i < ArrayLength(ValidStrings); ++i) {
     nsDependentCString str8(ValidStrings[i].m8);
     bool err;
-    if (HashString(ValidStrings[i].m16) !=
-        HashUTF8AsUTF16(str8.get(), str8.Length(), &err) ||
-        err)
-      return false;
+    EXPECT_EQ(HashString(ValidStrings[i].m16),
+              HashUTF8AsUTF16(str8.get(), str8.Length(), &err));
+    EXPECT_FALSE(err);
   }
 
   for (unsigned int i = 0; i < ArrayLength(Invalid8Strings); ++i) {
     nsDependentCString str8(Invalid8Strings[i].m8);
     bool err;
-    if (HashString(Invalid8Strings[i].m16) !=
-        HashUTF8AsUTF16(str8.get(), str8.Length(), &err) ||
-        err)
-      return false;
+    EXPECT_EQ(HashString(Invalid8Strings[i].m16),
+              HashUTF8AsUTF16(str8.get(), str8.Length(), &err));
+    EXPECT_FALSE(err);
   }
 
 // Don't run this test in debug builds as that intentionally asserts.
 #ifndef DEBUG
   for (unsigned int i = 0; i < ArrayLength(Malformed8Strings); ++i) {
     nsDependentCString str8(Malformed8Strings[i]);
     bool err;
-    if (HashUTF8AsUTF16(str8.get(), str8.Length(), &err) != 0 ||
-        !err)
-      return false;
+    EXPECT_EQ(HashUTF8AsUTF16(str8.get(), str8.Length(), &err), 0);
+    EXPECT_FALSE(err);
   }
 #endif
-
-  return true;
 }
 
-typedef bool (*TestFunc)();
-
-static const struct Test
-  {
-    const char* name;
-    TestFunc    func;
-  }
-tests[] =
-  {
-    { "test_valid", test_valid },
-    { "test_invalid16", test_invalid16 },
-    { "test_invalid8", test_invalid8 },
-    { "test_malformed8", test_malformed8 },
-    { "test_hashas16", test_hashas16 },
-    { nullptr, nullptr }
-  };
-
 }
-
-using namespace TestUTF;
-
-int main(int argc, char **argv)
-  {
-    int count = 1;
-    if (argc > 1)
-      count = atoi(argv[1]);
-
-    while (count--)
-      {
-        for (const Test* t = tests; t->name != nullptr; ++t)
-          {
-            printf("%25s : %s\n", t->name, t->func() ? "SUCCESS" : "FAILURE <--");
-          }
-      }
-    
-    return 0;
-  }
--- a/xpcom/tests/gtest/moz.build
+++ b/xpcom/tests/gtest/moz.build
@@ -12,13 +12,14 @@ UNIFIED_SOURCES += [
     'TestPipes.cpp',
     'TestPriorityQueue.cpp',
     'TestSnappyStreams.cpp',
     'TestStorageStream.cpp',
     'TestStrings.cpp',
     'TestSynchronization.cpp',
     'TestThreadPool.cpp',
     'TestTimeStamp.cpp',
+    'TestUTF.cpp',
 ]
 
 FINAL_LIBRARY = 'xul-gtest'
 
 FAIL_ON_WARNINGS = True
--- a/xpcom/tests/moz.build
+++ b/xpcom/tests/moz.build
@@ -77,17 +77,16 @@ if CONFIG['MOZ_MEMORY']:
     GeckoCppUnitTests([
         'TestJemalloc',
     ])
 
 # XXX Make these tests work in libxul builds.
 #CPP_UNIT_TESTS += [
 #    'TestThreads',
 #    'TestXPIDLString',
-#    'TestUTF',
 #]
 
 # FIXME: bug 577500 TestStaticAtoms fails when run in dist/bin
 #CPP_UNIT_TESTS += [
 #    'TestStaticAtoms',
 #]
 
 if CONFIG['MOZ_DEBUG'] and CONFIG['OS_ARCH'] not in ('WINNT'):