From 9c1964ee1d3448a699a846c68c1d515845636c83 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 3 Nov 2017 23:07:36 +0100 Subject: [PATCH] Fix a unit test in UTF-8 build using UTF-8 strings only Avoid the optimized mb_str() available in this build returning directly a "char*" as it doesn't preserve the length of the string if it contains NULs. Use mb_str(wxMBConv) overload instead which always returns the buffer of the correct length. Arguably, this is a problem of wxString API and maybe this optimized mb_str() overload shouldn't be provided at all. OTOH the main reason for wxUSE_UTF8_LOCALE_ONLY existence is optimization, so it seems a pity to deliberately make the code less efficient when using it. --- tests/strings/unicode.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/strings/unicode.cpp b/tests/strings/unicode.cpp index 04345bf199..7fb69b4728 100644 --- a/tests/strings/unicode.cpp +++ b/tests/strings/unicode.cpp @@ -269,7 +269,7 @@ void UnicodeTestCase::ConversionWithNULs() static const size_t lenNulString = 10; wxString szTheString(L"The\0String", wxConvLibc, lenNulString); - wxCharBuffer theBuffer = szTheString.mb_str(); + wxCharBuffer theBuffer = szTheString.mb_str(wxConvLibc); CPPUNIT_ASSERT( memcmp(theBuffer.data(), "The\0String", lenNulString + 1) == 0 );