Bug 1126301 - Move TestUTF.cpp to gtest and enable it; r=froydnj
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 27 Jan 2015 12:38:44 -0500
changeset 226134 18b38a86c2637dc97c6c472e742e6bda916e4ec5
parent 226133 fabb44ffd5d054c43c88ac5a6d367754a63f092e
child 226135 22fb05349a10681c74da313485dac594dc1d7a82
push id28187
push usercbook@mozilla.com
push dateWed, 28 Jan 2015 13:20:48 +0000
treeherdermozilla-central@fc21937ca612 [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/UTFStrings.h
xpcom/tests/gtest/TestUTF.cpp
xpcom/tests/gtest/UTFStrings.h
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), 0u);
+    EXPECT_TRUE(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;
-  }
rename from xpcom/tests/UTFStrings.h
rename to xpcom/tests/gtest/UTFStrings.h
--- a/xpcom/tests/UTFStrings.h
+++ b/xpcom/tests/gtest/UTFStrings.h
@@ -13,98 +13,98 @@ struct UTFStringsStringPair
 
 static const UTFStringsStringPair ValidStrings[] =
   {
     { { 'a', 'b', 'c', 'd' },
       { 'a', 'b', 'c', 'd' } },
     { { '1', '2', '3', '4' },
       { '1', '2', '3', '4' } },
     { { 0x7F, 'A', 0x80, 'B', 0x101, 0x200 },
-      { 0x7F, 'A', 0xC2, 0x80, 'B', 0xC4, 0x81, 0xC8, 0x80 } },
+      { 0x7F, 'A', char(0xC2), char(0x80), 'B', char(0xC4), char(0x81), char(0xC8), char(0x80) } },
     { { 0x7FF, 0x800, 0x1000 },
-      { 0xDF, 0xBF, 0xE0, 0xA0, 0x80, 0xE1, 0x80, 0x80 } },
+      { char(0xDF), char(0xBF), char(0xE0), char(0xA0), char(0x80), char(0xE1), char(0x80), char(0x80) } },
     { { 0xD7FF, 0xE000, 0xF00F, 'A', 0xFFF0 },
-      { 0xED, 0x9F, 0xBF, 0xEE, 0x80, 0x80, 0xEF, 0x80, 0x8F, 'A', 0xEF, 0xBF, 0xB0 } },
+      { char(0xED), char(0x9F), char(0xBF), char(0xEE), char(0x80), char(0x80), char(0xEF), char(0x80), char(0x8F), 'A', char(0xEF), char(0xBF), char(0xB0) } },
     { { 0xFFF7, 0xFFFC, 0xFFFD, 0xFFFD },
-      { 0xEF, 0xBF, 0xB7, 0xEF, 0xBF, 0xBC, 0xEF, 0xBF, 0xBD, 0xEF, 0xBF, 0xBD } },
+      { char(0xEF), char(0xBF), char(0xB7), char(0xEF), char(0xBF), char(0xBC), char(0xEF), char(0xBF), char(0xBD), char(0xEF), char(0xBF), char(0xBD) } },
     { { 0xD800, 0xDC00, 0xD800, 0xDCFF },
-      { 0xF0, 0x90, 0x80, 0x80, 0xF0, 0x90, 0x83, 0xBF } },
+      { char(0xF0), char(0x90), char(0x80), char(0x80), char(0xF0), char(0x90), char(0x83), char(0xBF) } },
     { { 0xDBFF, 0xDFFF, 0xDBB7, 0xDCBA },
-      { 0xF4, 0x8F, 0xBF, 0xBF, 0xF3, 0xBD, 0xB2, 0xBA } },
+      { char(0xF4), char(0x8F), char(0xBF), char(0xBF), char(0xF3), char(0xBD), char(0xB2), char(0xBA) } },
     { { 0xFFFD, 0xFFFF },
-      { 0xEF, 0xBF, 0xBD, 0xEF, 0xBF, 0xBF } },
+      { char(0xEF), char(0xBF), char(0xBD), char(0xEF), char(0xBF), char(0xBF) } },
     { { 0xFFFD, 0xFFFE, 0xFFFF },
-      { 0xEF, 0xBF, 0xBD, 0xEF, 0xBF, 0xBE, 0xEF, 0xBF, 0xBF } },
+      { char(0xEF), char(0xBF), char(0xBD), char(0xEF), char(0xBF), char(0xBE), char(0xEF), char(0xBF), char(0xBF) } },
   };
 
 static const UTFStringsStringPair Invalid16Strings[] =
   {
     { { 'a', 'b', 0xD800 },
-      { 'a', 'b', 0xEF, 0xBF, 0xBD } },
+      { 'a', 'b', char(0xEF), char(0xBF), char(0xBD) } },
     { { 0xD8FF, 'b' },
-      { 0xEF, 0xBF, 0xBD, 'b' } },
+      { char(0xEF), char(0xBF), char(0xBD), 'b' } },
     { { 0xD821 },
-      { 0xEF, 0xBF, 0xBD } },
+      { char(0xEF), char(0xBF), char(0xBD) } },
     { { 0xDC21 },
-      { 0xEF, 0xBF, 0xBD } },
+      { char(0xEF), char(0xBF), char(0xBD) } },
     { { 0xDC00, 0xD800, 'b' },
-      { 0xEF, 0xBF, 0xBD, 0xEF, 0xBF, 0xBD, 'b' } },
+      { char(0xEF), char(0xBF), char(0xBD), char(0xEF), char(0xBF), char(0xBD), 'b' } },
     { { 'b', 0xDC00, 0xD800 },
-      { 'b', 0xEF, 0xBF, 0xBD, 0xEF, 0xBF, 0xBD } },
+      { 'b', char(0xEF), char(0xBF), char(0xBD), char(0xEF), char(0xBF), char(0xBD) } },
     { { 0xDC00, 0xD800 },
-      { 0xEF, 0xBF, 0xBD, 0xEF, 0xBF, 0xBD } },
+      { char(0xEF), char(0xBF), char(0xBD), char(0xEF), char(0xBF), char(0xBD) } },
     { { 0xDC00, 0xD800, 0xDC00, 0xD800 },
-      { 0xEF, 0xBF, 0xBD, 0xF0, 0x90, 0x80, 0x80, 0xEF, 0xBF, 0xBD } },
+      { char(0xEF), char(0xBF), char(0xBD), char(0xF0), char(0x90), char(0x80), char(0x80), char(0xEF), char(0xBF), char(0xBD) } },
     { { 0xDC00, 0xD800, 0xD800, 0xDC00 },
-      { 0xEF, 0xBF, 0xBD, 0xEF, 0xBF, 0xBD, 0xF0, 0x90, 0x80, 0x80 } },
+      { char(0xEF), char(0xBF), char(0xBD), char(0xEF), char(0xBF), char(0xBD), char(0xF0), char(0x90), char(0x80), char(0x80) } },
   };
 
 static const UTFStringsStringPair Invalid8Strings[] =
   {
     { { 'a', 0xFFFD, 'b' },
-      { 'a', 0xC0, 0x80, 'b' } },
+      { 'a', char(0xC0), char(0x80), 'b' } },
     { { 0xFFFD, 0x80 },
-      { 0xC1, 0xBF, 0xC2, 0x80 } },
+      { char(0xC1), char(0xBF), char(0xC2), char(0x80) } },
     { { 0xFFFD },
-      { 0xC1, 0xBF } },
+      { char(0xC1), char(0xBF) } },
     { { 0xFFFD, 'x', 0x0800 },
-      { 0xE0, 0x80, 0x80, 'x', 0xE0, 0xA0, 0x80 } },
+      { char(0xE0), char(0x80), char(0x80), 'x', char(0xE0), char(0xA0), char(0x80) } },
     { { 0xFFFD, 'x', 0xFFFD },
-      { 0xF0, 0x80, 0x80, 0x80, 'x', 0xF0, 0x80, 0x8F, 0x80 } },
+      { char(0xF0), char(0x80), char(0x80), char(0x80), 'x', char(0xF0), char(0x80), char(0x8F), char(0x80) } },
     { { 0xFFFD, 0xFFFD },
-      { 0xF4, 0x90, 0x80, 0x80, 0xF7, 0xBF, 0xBF, 0xBF } },
+      { char(0xF4), char(0x90), char(0x80), char(0x80), char(0xF7), char(0xBF), char(0xBF), char(0xBF) } },
     { { 0xFFFD, 'x', 0xD800, 0xDC00, 0xFFFD },
-      { 0xF0, 0x8F, 0xBF, 0xBF, 'x', 0xF0, 0x90, 0x80, 0x80, 0xF0, 0x8F, 0xBF, 0xBF } },
+      { char(0xF0), char(0x8F), char(0xBF), char(0xBF), 'x', char(0xF0), char(0x90), char(0x80), char(0x80), char(0xF0), char(0x8F), char(0xBF), char(0xBF) } },
     { { 0xFFFD, 'x', 0xFFFD },
-      { 0xF8, 0x80, 0x80, 0x80, 0x80, 'x', 0xF8, 0x88, 0x80, 0x80, 0x80 } },
+      { char(0xF8), char(0x80), char(0x80), char(0x80), char(0x80), 'x', char(0xF8), char(0x88), char(0x80), char(0x80), char(0x80) } },
     { { 0xFFFD, 0xFFFD },
-      { 0xFB, 0xBF, 0xBF, 0xBF, 0xBF, 0xFC, 0xA0, 0x80, 0x80, 0x80, 0x80 } },
+      { char(0xFB), char(0xBF), char(0xBF), char(0xBF), char(0xBF), char(0xFC), char(0xA0), char(0x80), char(0x80), char(0x80), char(0x80) } },
     { { 0xFFFD, 0xFFFD },
-      { 0xFC, 0x80, 0x80, 0x80, 0x80, 0x80, 0xFD, 0xBF, 0xBF, 0xBF, 0xBF, 0xBF } },
+      { char(0xFC), char(0x80), char(0x80), char(0x80), char(0x80), char(0x80), char(0xFD), char(0xBF), char(0xBF), char(0xBF), char(0xBF), char(0xBF) } },
   };
 
 // Don't use this array in debug builds as that intentionally asserts.
 #ifndef DEBUG
 static const char Malformed8Strings[][16] =
   {
-    { 0x80 },
-    { 'a', 0xC8, 'c' },
-    { 'a', 0xC0 },
-    { 'a', 0xE8, 'c' },
-    { 'a', 0xE8, 0x80, 'c' },
-    { 'a', 0xE8, 0x80 },
-    { 0xE8, 0x7F, 0x80 },
-    { 'a', 0xE8, 0xE8, 0x80 },
-    { 'a', 0xF4 },
-    { 'a', 0xF4, 0x80, 0x80, 'c', 'c' },
-    { 'a', 0xF4, 0x80, 'x', 0x80 },
-    { 0xF4, 0x80, 0x80, 0x80, 0x80 },
-    { 'a', 0xFA, 'c' },
-    { 'a', 0xFA, 0x80, 0x80, 0x7F, 0x80, 'c' },
-    { 'a', 0xFA, 0x80, 0x80, 0x80, 0x80, 0x80, 'c' },
-    { 'a', 0xFD },
-    { 'a', 0xFD, 0x80, 0x80, 0x80, 0x80, 'c' },
-    { 'a', 0xFD, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 },
-    { 'a', 0xFC, 0x80, 0x80, 0x40, 0x80, 0x80, 'c' },
+    { char(0x80) },
+    { 'a', char(0xC8), 'c' },
+    { 'a', char(0xC0) },
+    { 'a', char(0xE8), 'c' },
+    { 'a', char(0xE8), char(0x80), 'c' },
+    { 'a', char(0xE8), char(0x80) },
+    { char(0xE8), 0x7F, char(0x80) },
+    { 'a', char(0xE8), char(0xE8), char(0x80) },
+    { 'a', char(0xF4) },
+    { 'a', char(0xF4), char(0x80), char(0x80), 'c', 'c' },
+    { 'a', char(0xF4), char(0x80), 'x', char(0x80) },
+    { char(0xF4), char(0x80), char(0x80), char(0x80), char(0x80) },
+    { 'a', char(0xFA), 'c' },
+    { 'a', char(0xFA), char(0x80), char(0x80), 0x7F, char(0x80), 'c' },
+    { 'a', char(0xFA), char(0x80), char(0x80), char(0x80), char(0x80), char(0x80), 'c' },
+    { 'a', char(0xFD) },
+    { 'a', char(0xFD), char(0x80), char(0x80), char(0x80), char(0x80), 'c' },
+    { 'a', char(0xFD), char(0x80), char(0x80), char(0x80), char(0x80), char(0x80), char(0x80) },
+    { 'a', char(0xFC), char(0x80), char(0x80), 0x40, char(0x80), char(0x80), 'c' },
   };
 #endif
 
 #endif
--- a/xpcom/tests/gtest/moz.build
+++ b/xpcom/tests/gtest/moz.build
@@ -11,13 +11,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',
 #    'TestAtoms',
 #]
 
 # FIXME: bug 577500 TestStaticAtoms fails when run in dist/bin
 #CPP_UNIT_TESTS += [
 #    'TestStaticAtoms',
 #]