X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/a01113dcd0f39d5da295ef82785beff9ed86fe38..340931cb2e044a2141d11567dd0f782524e32994:/icuSources/test/cintltst/cstrtest.c?ds=sidebyside diff --git a/icuSources/test/cintltst/cstrtest.c b/icuSources/test/cintltst/cstrtest.c index 3903a523..cfc3a3df 100644 --- a/icuSources/test/cintltst/cstrtest.c +++ b/icuSources/test/cintltst/cstrtest.c @@ -27,11 +27,17 @@ void addCStringTest(TestNode** root); static void TestInvariant(void); static void TestCompareInvEbcdicAsAscii(void); +static void TestLocaleAtSign(void); +static void TestNoInvariantAtSign(void); +static void TestInvCharToAscii(void); void addCStringTest(TestNode** root) { - addTest(root, &TestAPI, "tsutil/cstrtest/TestAPI"); - addTest(root, &TestInvariant, "tsutil/cstrtest/TestInvariant"); + addTest(root, &TestAPI, "tsutil/cstrtest/TestAPI"); + addTest(root, &TestInvariant, "tsutil/cstrtest/TestInvariant"); addTest(root, &TestCompareInvEbcdicAsAscii, "tsutil/cstrtest/TestCompareInvEbcdicAsAscii"); + addTest(root, &TestLocaleAtSign, "tsutil/cstrtest/TestLocaleAtSign"); + addTest(root, &TestNoInvariantAtSign, "tsutil/cstrtest/TestNoInvariantAtSign"); + addTest(root, &TestInvCharToAscii, "tsutil/cstrtest/TestInvCharToAscii"); } static void TestAPI(void) @@ -117,10 +123,10 @@ static void TestAPI(void) log_err("FAIL: uprv_stricmp() where the second string is null failed. Expected: 1, returned %d\n", intValue); } if((intValue=uprv_stricmp(NULL, NULL)) != 0){ - log_err("FAIL: uprv_stricmp(NULL, NULL) failed. Expected: 0, returned %d\n", intValue);; + log_err("FAIL: uprv_stricmp(NULL, NULL) failed. Expected: 0, returned %d\n", intValue); } if((intValue=uprv_stricmp("", "")) != 0){ - log_err("FAIL: uprv_stricmp(\"\", \"\") failed. Expected: 0, returned %d\n", intValue);; + log_err("FAIL: uprv_stricmp(\"\", \"\") failed. Expected: 0, returned %d\n", intValue); } if((intValue=uprv_stricmp("", "abc")) != -1){ log_err("FAIL: uprv_stricmp(\"\", \"abc\") failed. Expected: -1, returned %d\n", intValue); @@ -146,10 +152,10 @@ static void TestAPI(void) log_err("FAIL: uprv_strnicmp() where the second string is null failed. Expected: 1, returned %d\n", intValue); } if((intValue=uprv_strnicmp(NULL, NULL, 10)) != 0){ - log_err("FAIL: uprv_strnicmp(NULL, NULL, 10) failed. Expected: 0, returned %d\n", intValue);; + log_err("FAIL: uprv_strnicmp(NULL, NULL, 10) failed. Expected: 0, returned %d\n", intValue); } if((intValue=uprv_strnicmp("", "", 10)) != 0){ - log_err("FAIL: uprv_strnicmp(\"\", \"\") failed. Expected: 0, returned %d\n", intValue);; + log_err("FAIL: uprv_strnicmp(\"\", \"\") failed. Expected: 0, returned %d\n", intValue); } if((intValue=uprv_strnicmp("", "abc", 10)) != -1){ log_err("FAIL: uprv_stricmp(\"\", \"abc\", 10) failed. Expected: -1, returned %d\n", intValue); @@ -271,7 +277,7 @@ TestInvariant() { log_err("uprv_isInvariantString(\"\\0\") failed\n"); } - for(i=0; i<(sizeof(variantChars)-1); ++i) { + for(i=0; i<(int32_t)(sizeof(variantChars)-1); ++i) { if(uprv_isInvariantString(variantChars+i, 1)) { log_err("uprv_isInvariantString(variantChars[%d]) failed\n", i); } @@ -339,3 +345,53 @@ TestCompareInvEbcdicAsAscii() { } } } + +// See U_CHARSET_FAMILY in unicode/platform.h. +static const char *nativeInvChars = + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789 \"%&'()*+,-./:;<=>?_"; +static const UChar *asciiInvChars = + u"ABCDEFGHIJKLMNOPQRSTUVWXYZ" + u"abcdefghijklmnopqrstuvwxyz" + u"0123456789 \"%&'()*+,-./:;<=>?_"; + +static void +TestLocaleAtSign() { + static const char *invLocale = "de-Latn_DE@PHONEBOOK"; + for (int32_t i = 0;; ++i) { + char ic = invLocale[i]; + if (ic == 0) { break; } + UBool expected = i == 10; + UBool actual = uprv_isAtSign(ic); + if (actual != expected) { + log_err("uprv_isAtSign('%c')=%d is wrong\n", ic, (int)actual); + } + } +} + +// The at sign is not an invariant character. +static void +TestNoInvariantAtSign() { + for (int32_t i = 0;; ++i) { + char ic = nativeInvChars[i]; + UBool actual = uprv_isAtSign(ic); + if (actual) { + log_err("uprv_isAtSign(invariant '%c')=TRUE is wrong\n", ic); + } + if (ic == 0) { break; } + } +} + +static void +TestInvCharToAscii() { + for (int32_t i = 0;; ++i) { + char ic = nativeInvChars[i]; + uint8_t ac = asciiInvChars[i]; + uint8_t actual = uprv_invCharToAscii(ic); + if (actual != ac) { + log_err("uprv_invCharToAscii('%c') did not convert to ASCII 0x%02x\n", ic, (int)ac); + } + if (ic == 0) { break; } + } +}