From: Shane Carr Date: Fri, 22 Dec 2017 23:44:35 +0000 (+0000) Subject: ICU-13516 Defining behavior when an invalid code point is passed to foldCase. X-Git-Tag: release-61-rc~154 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=85d3cf4f2fc8a0dd2d6ef342a3938b279b2df702;p=icu ICU-13516 Defining behavior when an invalid code point is passed to foldCase. X-SVN-Rev: 40748 --- diff --git a/icu4c/source/test/intltest/ucdtest.cpp b/icu4c/source/test/intltest/ucdtest.cpp index 489d6cdf275..e5c5989b9fc 100644 --- a/icu4c/source/test/intltest/ucdtest.cpp +++ b/icu4c/source/test/intltest/ucdtest.cpp @@ -63,6 +63,7 @@ void UnicodeTest::runIndexedTest( int32_t index, UBool exec, const char* &name, TESTCASE_AUTO(TestBidiPairedBracketType); TESTCASE_AUTO(TestEmojiProperties); TESTCASE_AUTO(TestDefaultScriptExtensions); + TESTCASE_AUTO(TestInvalidCodePointFolding); TESTCASE_AUTO_END; } @@ -546,3 +547,21 @@ void UnicodeTest::TestDefaultScriptExtensions() { uscript_getScriptExtensions(0x3012, scx, UPRV_LENGTHOF(scx), errorCode)); assertEquals("U+3012 num scx[0]", USCRIPT_COMMON, scx[0]); } + +void UnicodeTest::TestInvalidCodePointFolding(void) { + // Test behavior when an invalid code point is passed to u_foldCase + static const UChar32 invalidCodePoints[] = { + 0xD800, // lead surrogate + 0xDFFF, // trail surrogate + 0xFDD0, // noncharacter + 0xFFFF, // noncharacter + 0x110000, // out of range + -1 // negative + }; + for (auto cp : invalidCodePoints) { + assertEquals("Invalid code points should be echoed back", + cp, u_foldCase(cp, U_FOLD_CASE_DEFAULT)); + assertEquals("Invalid code points should be echoed back", + cp, u_foldCase(cp, U_FOLD_CASE_EXCLUDE_SPECIAL_I)); + } +} diff --git a/icu4c/source/test/intltest/ucdtest.h b/icu4c/source/test/intltest/ucdtest.h index 82ffb0e8dcc..8a7ae3f4ecf 100644 --- a/icu4c/source/test/intltest/ucdtest.h +++ b/icu4c/source/test/intltest/ucdtest.h @@ -42,6 +42,7 @@ public: void TestBidiPairedBracketType(); void TestEmojiProperties(); void TestDefaultScriptExtensions(); + void TestInvalidCodePointFolding(); private: diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/UCharacterCaseTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/UCharacterCaseTest.java index 09e4e2ef6c3..f54fbec2cce 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/UCharacterCaseTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/UCharacterCaseTest.java @@ -192,6 +192,28 @@ public final class UCharacterCaseTest extends TestFmwk } } + @Test + public void TestInvalidCodePointFolding() { + int[] invalidCodePoints = { + 0xD800, // lead surrogate + 0xDFFF, // trail surrogate + 0xFDD0, // noncharacter + 0xFFFF, // noncharacter + 0x110000, // out of range + -1 // negative + }; + for (int cp : invalidCodePoints) { + assertEquals("Invalid code points should be echoed back", + cp, UCharacter.foldCase(cp, true)); + assertEquals("Invalid code points should be echoed back", + cp, UCharacter.foldCase(cp, false)); + assertEquals("Invalid code points should be echoed back", + cp, UCharacter.foldCase(cp, UCharacter.FOLD_CASE_DEFAULT)); + assertEquals("Invalid code points should be echoed back", + cp, UCharacter.foldCase(cp, UCharacter.FOLD_CASE_EXCLUDE_SPECIAL_I)); + } + } + /** * Testing the strings case mapping methods */