Don't rely on wxMBConv::cWC2MB(NULL) returning the exact byte count
UTF-32 conversions use a useful optimization by avoiding the extra scan of the input wchar_t string in their FromWChar() and cWC2MB() implementation when they are only asked to compute the required buffer size without actually doing the conversion. However this means that for an input string containing UTF-16 surrogates (which is possible under MSW where wchar_t is 16 bits) the actual size of the output string can be smaller than that returned by FromWChar(NULL). Document that this may happen and avoid relying on the exact equality in the tests. See #17070.
This commit is contained in:
@@ -1096,15 +1096,16 @@ void MBConvTestCase::TestEncoder(
|
||||
memcpy( inputCopy.data(), wideBuffer, (wideChars*sizeof(wchar_t)) );
|
||||
inputCopy.data()[wideChars] = 0;
|
||||
|
||||
// calculate the output size
|
||||
// calculate the output size: notice that it can be greater than the real
|
||||
// size as the converter is allowed to estimate the maximal size needed
|
||||
// instead of computing it precisely
|
||||
size_t outputWritten = converter.WC2MB
|
||||
(
|
||||
0,
|
||||
(const wchar_t*)inputCopy.data(),
|
||||
0
|
||||
);
|
||||
// make sure the correct output length was calculated
|
||||
CPPUNIT_ASSERT_EQUAL( multiBytes, outputWritten );
|
||||
CPPUNIT_ASSERT( outputWritten >= multiBytes );
|
||||
|
||||
// convert the string
|
||||
size_t guardBytes = 8; // to make sure we're not overrunning the output buffer
|
||||
|
Reference in New Issue
Block a user