From: Vadim Zeitlin Date: Sun, 2 Apr 2006 14:01:18 +0000 (+0000) Subject: added test UTF-16 string with embedded NUL NUL which makes the current code fail X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/2877b82808cab53b3cfb2484bbaaa8a7a3da54af added test UTF-16 string with embedded NUL NUL which makes the current code fail git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38520 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/tests/strings/unicode.cpp b/tests/strings/unicode.cpp index 064ae75686..42e92cfa26 100644 --- a/tests/strings/unicode.cpp +++ b/tests/strings/unicode.cpp @@ -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