Fix wxTextInputStream for some inputs starting with nulls
This commit is contained in:
@@ -324,6 +324,46 @@ TEST_CASE("wxTextInputStream::GetChar", "[text][input][stream][char]")
|
||||
REQUIRE( tis.GetChar() == 0x00 );
|
||||
CHECK( tis.GetInputStream().Eof() );
|
||||
}
|
||||
|
||||
// Two null bytes that look like the start of UTF-32BE BOM,
|
||||
// followed by 4 byte UTF-8 sequence.
|
||||
// Needs wxConvAuto to not switch to fallback on <6 bytes.
|
||||
SECTION("UTF8-with-nulls")
|
||||
{
|
||||
const wxUint8 buf[] = { 0x00, 0x00, 0xf0, 0x90, 0x8c, 0x98 };
|
||||
wxMemoryInputStream mis(buf, sizeof(buf));
|
||||
wxTextInputStream tis(mis);
|
||||
|
||||
wxCharTypeBuffer<wxChar> e = wxString::FromUTF8((char*)buf, sizeof(buf))
|
||||
.tchar_str<wxChar>();
|
||||
for ( size_t i = 0; i < e.length(); ++i )
|
||||
{
|
||||
INFO("i = " << i);
|
||||
REQUIRE( tis.GetChar() == e[i] );
|
||||
}
|
||||
REQUIRE( tis.GetChar() == 0x00 );
|
||||
CHECK( tis.GetInputStream().Eof() );
|
||||
}
|
||||
|
||||
// Two null bytes that look like the start of UTF-32BE BOM,
|
||||
// then 3 bytes that look like the start of UTF-8 sequence.
|
||||
// Needs 6 character output buffer in GetChar().
|
||||
SECTION("almost-UTF8-with-nulls")
|
||||
{
|
||||
const wxUint8 buf[] = { 0x00, 0x00, 0xf0, 0x90, 0x8c, 0xe0 };
|
||||
wxMemoryInputStream mis(buf, sizeof(buf));
|
||||
wxTextInputStream tis(mis);
|
||||
|
||||
wxCharTypeBuffer<wxChar> e = wxString((char*)buf, wxCSConv(wxFONTENCODING_ISO8859_1),
|
||||
sizeof(buf)).tchar_str<wxChar>();
|
||||
for ( size_t i = 0; i < e.length(); ++i )
|
||||
{
|
||||
INFO("i = " << i);
|
||||
REQUIRE( tis.GetChar() == e[i] );
|
||||
}
|
||||
REQUIRE( tis.GetChar() == 0x00 );
|
||||
CHECK( tis.GetInputStream().Eof() );
|
||||
}
|
||||
}
|
||||
|
||||
#endif // wxUSE_UNICODE
|
||||
|
Reference in New Issue
Block a user