Bug 1534878 - xpcom: Re-enable NonASCII16 UTF-16 string tests. r=hsivonen
authorChris Peterson <cpeterson@mozilla.com>
Sun, 24 Feb 2019 21:45:15 -0800
changeset 464365 710481a0ddfa6826b5d06e93d683547f4da97402
parent 464364 25fbad7b3214444a3b07a52880faa61e399309a9
child 464366 ecf117f6a9b78d9c0f918107b0ea9dc9d9d3dd1e
push id35714
push userapavel@mozilla.com
push dateSat, 16 Mar 2019 09:47:26 +0000
treeherdermozilla-central@124ee436c421 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsivonen
bugs1534878, 1402247
milestone67.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 1534878 - xpcom: Re-enable NonASCII16 UTF-16 string tests. r=hsivonen The NonASCII16 test function was removed in bug 1402247 but the NonASCII16_helper() function was not: https://hg.mozilla.org/mozilla-central/rev/4ef0f163fdeb xpcom/tests/gtest/TestUTF.cpp:119:6 [-Wmissing-prototypes] no previous prototype for function 'NonASCII16_helper' Differential Revision: https://phabricator.services.mozilla.com/D23267
xpcom/tests/gtest/TestUTF.cpp
--- a/xpcom/tests/gtest/TestUTF.cpp
+++ b/xpcom/tests/gtest/TestUTF.cpp
@@ -111,17 +111,17 @@ TEST(UTF, Hash16) {
     EXPECT_TRUE(err);
   }
 }
 
 /**
  * This tests the handling of a non-ascii character at various locations in a
  * UTF-16 string that is being converted to UTF-8.
  */
-void NonASCII16_helper(const size_t aStrSize) {
+static void NonASCII16_helper(const size_t aStrSize) {
   const size_t kTestSize = aStrSize;
   const size_t kMaxASCII = 0x80;
   const char16_t kUTF16Char = 0xC9;
   const char kUTF8Surrogates[] = {char(0xC3), char(0x89)};
 
   // Generate a string containing only ASCII characters.
   nsString asciiString;
   asciiString.SetLength(kTestSize);
@@ -149,29 +149,38 @@ void NonASCII16_helper(const size_t aStr
     EXPECT_EQ(dest.Length(), unicodeString.Length() + 1);
 
     // Build up the expected UTF-8 string.
     nsCString expected;
 
     // First add the leading ASCII chars.
     expected.Append(asciiCString.BeginReading(), i);
 
-    // Now append the UTF-8 surrogate pair we expect the UTF-16 unicode char to
+    // Now append the UTF-8 pair we expect the UTF-16 unicode char to
     // be converted to.
     for (auto& c : kUTF8Surrogates) {
       expected.Append(c);
     }
 
     // And finish with the trailing ASCII chars.
     expected.Append(asciiCString.BeginReading() + i + 1, kTestSize - i - 1);
 
     EXPECT_STREQ(dest.BeginReading(), expected.BeginReading());
   }
 }
 
+TEST(UTF, NonASCII16) {
+  // Test with various string sizes to catch any special casing.
+  NonASCII16_helper(1);
+  NonASCII16_helper(8);
+  NonASCII16_helper(16);
+  NonASCII16_helper(32);
+  NonASCII16_helper(512);
+}
+
 TEST(UTF, UTF8CharEnumerator) {
   const char* p =
       "\x61\xC0\xC2\xC2\x80\xE0\x80\x80\xE0\xA0\x80\xE1\x80\x80\xED\xBF\xBF\xED"
       "\x9F\xBF\xEE\x80\x80\xEE\x80\xFF\xF0\x90\x80\x80\xF0\x80\x80\x80\xF1\x80"
       "\x80\x80\xF4\x8F\xBF\xF4\x8F\xBF\xBF\xF4\xBF\xBF\xBF";
   const char* end = p + 49;
   EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0x0061U);
   EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);