Bug 551153 - ###!!! ASSERTION: Not a UTF-8 string when running TestUTF and TestAtoms; (Bv1) Make it fully explicit that Malformed8Strings[] is not to be used in debug builds.
authorSerge Gautherie <sgautherie.bz@free.fr>
Wed, 10 Mar 2010 21:03:23 +0100
changeset 39219 1912459c016b9cc451648d4207004391bb95c6dc
parent 39218 b9424d98afb442ea176b7a16a316987fc9ddc765
child 39220 ba67224d0e8d14779717b985fef62e388af5507d
push idunknown
push userunknown
push dateunknown
bugs551153
milestone1.9.3a3pre
Bug 551153 - ###!!! ASSERTION: Not a UTF-8 string when running TestUTF and TestAtoms; (Bv1) Make it fully explicit that Malformed8Strings[] is not to be used in debug builds. r=jonas.
xpcom/tests/TestAtoms.cpp
xpcom/tests/TestUTF.cpp
xpcom/tests/UTFStrings.h
--- a/xpcom/tests/TestAtoms.cpp
+++ b/xpcom/tests/TestAtoms.cpp
@@ -142,20 +142,20 @@ test_invalid()
           !atom16->Equals(nsDependentString(Invalid8Strings[i].m16)))
         return PR_FALSE;
     }
     
     if (count != NS_GetNumberOfAtoms())
       return PR_FALSE;
   }
 
+// Don't run this test in debug builds as that intentionally asserts.
+#ifndef DEBUG
   nsCOMPtr<nsIAtom> emptyAtom = do_GetAtom("");
 
-#ifndef DEBUG
-    // Don't run these tests in debug builds as that intentionally asserts
   for (unsigned int i = 0; i < NS_ARRAY_LENGTH(Malformed8Strings); ++i) {
     nsrefcnt count = NS_GetNumberOfAtoms();
 
     nsCOMPtr<nsIAtom> atom8 = do_GetAtom(Malformed8Strings[i]);
     if (atom8 != emptyAtom ||
         count != NS_GetNumberOfAtoms())
       return PR_FALSE;
   }
--- a/xpcom/tests/TestUTF.cpp
+++ b/xpcom/tests/TestUTF.cpp
@@ -117,30 +117,33 @@ test_invalid8()
   }
   
   return PR_TRUE;
 }
 
 PRBool
 test_malformed8()
 {
+// Don't run this test in debug builds as that intentionally asserts.
+#ifndef DEBUG
   for (unsigned int i = 0; i < NS_ARRAY_LENGTH(Malformed8Strings); ++i) {
     nsDependentCString str8(Malformed8Strings[i]);
 
     if (!NS_ConvertUTF8toUTF16(str8).IsEmpty())
       return PR_FALSE;
 
     nsString tmp16(NS_LITERAL_STRING("string"));
     AppendUTF8toUTF16(str8, tmp16);
     if (!tmp16.Equals(NS_LITERAL_STRING("string")))
       return PR_FALSE;
 
     if (CompareUTF8toUTF16(str8, EmptyString()) == 0)
       return PR_FALSE;
   }
+#endif
   
   return PR_TRUE;
 }
 
 PRBool
 test_hashas16()
 {
   for (unsigned int i = 0; i < NS_ARRAY_LENGTH(ValidStrings); ++i) {
@@ -156,43 +159,43 @@ test_hashas16()
     nsDependentCString str8(Invalid8Strings[i].m8);
     PRBool err;
     if (nsCRT::HashCode(Invalid8Strings[i].m16) !=
         nsCRT::HashCodeAsUTF16(str8.get(), str8.Length(), &err) ||
         err)
       return PR_FALSE;
   }
 
+// Don't run this test in debug builds as that intentionally asserts.
+#ifndef DEBUG
   for (unsigned int i = 0; i < NS_ARRAY_LENGTH(Malformed8Strings); ++i) {
     nsDependentCString str8(Malformed8Strings[i]);
     PRBool err;
     if (nsCRT::HashCodeAsUTF16(str8.get(), str8.Length(), &err) != 0 ||
         !err)
       return PR_FALSE;
   }
+#endif
 
   return PR_TRUE;
 }
 
 typedef PRBool (*TestFunc)();
 
 static const struct Test
   {
     const char* name;
     TestFunc    func;
   }
 tests[] =
   {
     { "test_valid", test_valid },
     { "test_invalid16", test_invalid16 },
     { "test_invalid8", test_invalid8 },
-#ifndef DEBUG
-    // Don't run this test in debug builds as that intentionally asserts
     { "test_malformed8", test_malformed8 },
-#endif
     { "test_hashas16", test_hashas16 },
     { nsnull, nsnull }
   };
 
 }
 
 using namespace TestUTF;
 
--- a/xpcom/tests/UTFStrings.h
+++ b/xpcom/tests/UTFStrings.h
@@ -108,16 +108,18 @@ static const UTFStringsStringPair Invali
     { { 0xFFFD, 'x', 0xFFFD },
       { 0xF8, 0x80, 0x80, 0x80, 0x80, 'x', 0xF8, 0x88, 0x80, 0x80, 0x80 } },
     { { 0xFFFD, 0xFFFD },
       { 0xFB, 0xBF, 0xBF, 0xBF, 0xBF, 0xFC, 0xA0, 0x80, 0x80, 0x80, 0x80 } },
     { { 0xFFFD, 0xFFFD },
       { 0xFC, 0x80, 0x80, 0x80, 0x80, 0x80, 0xFD, 0xBF, 0xBF, 0xBF, 0xBF, 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 },
@@ -130,10 +132,11 @@ static const char Malformed8Strings[][16
     { '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' },
   };
+#endif
 
 #endif