added test UTF-16 string with embedded NUL NUL which makes the current code fail
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 2 Apr 2006 14:01:18 +0000 (14:01 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 2 Apr 2006 14:01:18 +0000 (14:01 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38520 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

tests/strings/unicode.cpp

index 064ae7568628af697bd25c30afb010fec96dcef2..42e92cfa26bb4ef02c1c59a9fbb4d753fd3b7dd0 100644 (file)
@@ -152,7 +152,7 @@ void UnicodeTestCase::ConversionWithNULs()
         CPPUNIT_ASSERT_EQUAL( lenNulString, szTheString2.length() );
         CPPUNIT_ASSERT( wxTmemcmp(szTheString2.c_str(), L"The\0String",
                         lenNulString + 1) == 0 );
-#else
+#else // !wxUSE_UNICODE
         wxString szTheString(wxT("TheString"));
         szTheString.insert(3, 1, '\0');
         wxWCharBuffer theBuffer = szTheString.wc_str(wxConvLibc);
@@ -164,7 +164,7 @@ void UnicodeTestCase::ConversionWithNULs()
         wxWCharBuffer theLocalBuffer = szLocalTheString.wc_str(wxConvLocal);
 
         CPPUNIT_ASSERT( memcmp(theLocalBuffer.data(), L"The\0String", 11 * sizeof(wchar_t)) == 0 );
-#endif
+#endif // wxUSE_UNICODE/!wxUSE_UNICODE
 }
 
 void
@@ -266,6 +266,13 @@ void UnicodeTestCase::ConversionUTF16()
         const StringConversionData& d = utf16data[n];
         DoTestConversion(d.str, d.wcs, conv);
     }
+
+    // special case: this string has consecutive NULs inside it which don't
+    // terminate the string, this exposed a bug in our conversion code which
+    // got confused in this case
+    size_t len;
+    wxWCharBuffer wbuf(conv.cMB2WC("\x01\0\0B\0C" /* A macron BC */, 6, &len));
+    CPPUNIT_ASSERT_EQUAL( 3u, len );
 }
 
 #endif // wxUSE_WCHAR_T