From 5e39c31345a902156cbc18cbf2e4a77ba5056b78 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Fri, 13 Feb 2015 00:13:43 -0800 Subject: [PATCH] Add test for conversion of invalid characters to a replacement --- Sources/Tests/CoreTests/test_plString.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Sources/Tests/CoreTests/test_plString.cpp b/Sources/Tests/CoreTests/test_plString.cpp index ff1fa312..efc1103d 100644 --- a/Sources/Tests/CoreTests/test_plString.cpp +++ b/Sources/Tests/CoreTests/test_plString.cpp @@ -119,6 +119,25 @@ TEST(PlStringTest, ConvertWchar) EXPECT_STREQ(wtext, to_wchar.GetData()); } +TEST(PlStringTest, ConvertInvalid) +{ + // The following should encode replacement characters for invalid chars + const plUniChar unicode_replacement[] = { 0xfffd, 0 }; + + const plUniChar char_too_big[] = { 0xffffff, 0 }; + plUnicodeBuffer too_big = plString::FromUtf32(char_too_big).GetUnicodeArray(); + EXPECT_EQ(0, T_strcmp(unicode_replacement, too_big.GetData())); + + // TODO: Invalid surrogate pairs can encode to 0xfffd, but it's handled + // by an assert right now. + + // ISO-8859-1 doesn't have \ufffd, so it uses '?' instead + const plUniChar high_char[] = { 0x1ff, 0 }; + const char latin1_replacement[] = "?"; + plStringBuffer non_latin1 = plString::FromUtf32(high_char).ToIso8859_1(); + EXPECT_STREQ(latin1_replacement, non_latin1.GetData()); +} + TEST(PlStringTest,FindChar) { plString input = plString("abCdcBAeab");