OLD | NEW |
1 /* | 1 /* |
2 ******************************************************************************* | 2 ******************************************************************************* |
3 * | 3 * |
4 * Copyright (C) 2002-2014, International Business Machines | 4 * Copyright (C) 2002-2015, International Business Machines |
5 * Corporation and others. All Rights Reserved. | 5 * Corporation and others. All Rights Reserved. |
6 * | 6 * |
7 ******************************************************************************* | 7 ******************************************************************************* |
8 * file name: cstrcase.c | 8 * file name: cstrcase.c |
9 * encoding: US-ASCII | 9 * encoding: US-ASCII |
10 * tab size: 8 (not used) | 10 * tab size: 8 (not used) |
11 * indentation:4 | 11 * indentation:4 |
12 * | 12 * |
13 * created on: 2002feb21 | 13 * created on: 2002feb21 |
14 * created by: Markus W. Scherer | 14 * created by: Markus W. Scherer |
15 * | 15 * |
16 * Test file for string casing C API functions. | 16 * Test file for string casing C API functions. |
17 */ | 17 */ |
18 | 18 |
19 #include <string.h> | 19 #include <string.h> |
20 #include "unicode/utypes.h" | 20 #include "unicode/utypes.h" |
21 #include "unicode/uchar.h" | 21 #include "unicode/uchar.h" |
22 #include "unicode/ustring.h" | 22 #include "unicode/ustring.h" |
23 #include "unicode/uloc.h" | 23 #include "unicode/uloc.h" |
24 #include "unicode/ubrk.h" | 24 #include "unicode/ubrk.h" |
25 #include "unicode/ucasemap.h" | 25 #include "unicode/ucasemap.h" |
26 #include "cmemory.h" | 26 #include "cmemory.h" |
27 #include "cintltst.h" | 27 #include "cintltst.h" |
| 28 #include "ustr_imp.h" |
28 | 29 |
29 /* test string case mapping functions --------------------------------------- */ | 30 /* test string case mapping functions --------------------------------------- */ |
30 | 31 |
31 static void | 32 static void |
32 TestCaseLower(void) { | 33 TestCaseLower(void) { |
33 static const UChar | 34 static const UChar |
34 | 35 |
35 beforeLower[]= { 0x61, 0x42, 0x49, 0x3a3, 0xdf, 0x3a3, 0x2f, 0xd93f, 0xdfff
}, | 36 beforeLower[]= { 0x61, 0x42, 0x49, 0x3a3, 0xdf, 0x3a3, 0x2f, 0xd93f, 0xdfff
}, |
36 lowerRoot[]= { 0x61, 0x62, 0x69, 0x3c3, 0xdf, 0x3c2, 0x2f, 0xd93f, 0xdfff
}, | 37 lowerRoot[]= { 0x61, 0x62, 0x69, 0x3c3, 0xdf, 0x3c2, 0x2f, 0xd93f, 0xdfff
}, |
37 lowerTurkish[]={ 0x61, 0x62, 0x131, 0x3c3, 0xdf, 0x3c2, 0x2f, 0xd93f, 0xdfff
}; | 38 lowerTurkish[]={ 0x61, 0x62, 0x131, 0x3c3, 0xdf, 0x3c2, 0x2f, 0xd93f, 0xdfff
}; |
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 ) { | 983 ) { |
983 log_err("ucasemap_utf8ToTitle(sentence break iterator, no lowercasin
g)=%ld failed - %s\n", (long)length, u_errorName(errorCode)); | 984 log_err("ucasemap_utf8ToTitle(sentence break iterator, no lowercasin
g)=%ld failed - %s\n", (long)length, u_errorName(errorCode)); |
984 } | 985 } |
985 } | 986 } |
986 | 987 |
987 ucasemap_close(csm); | 988 ucasemap_close(csm); |
988 } | 989 } |
989 | 990 |
990 #endif | 991 #endif |
991 | 992 |
| 993 /* Test case for internal API u_caseInsensitivePrefixMatch */ |
| 994 static void |
| 995 TestUCaseInsensitivePrefixMatch(void) { |
| 996 struct { |
| 997 const char *s1; |
| 998 const char *s2; |
| 999 int32_t r1; |
| 1000 int32_t r2; |
| 1001 } testCases[] = { |
| 1002 {"ABC", "ab", 2, 2}, |
| 1003 {"ABCD", "abcx", 3, 3}, |
| 1004 {"ABC", "xyz", 0, 0}, |
| 1005 /* U+00DF LATIN SMALL LETTER SHARP S */ |
| 1006 {"A\\u00dfBC", "Ass", 2, 3}, |
| 1007 {"Fust", "Fu\\u00dfball", 2, 2}, |
| 1008 {"\\u00dfsA", "s\\u00dfB", 2, 2}, |
| 1009 {"\\u00dfs", "s\\u00df", 2, 2}, |
| 1010 /* U+0130 LATIN CAPITAL LETTER I WITH DOT ABOVE */ |
| 1011 {"XYZ\\u0130i\\u0307xxx", "xyzi\\u0307\\u0130yyy", 6, 6}, |
| 1012 {0, 0, 0, 0} |
| 1013 }; |
| 1014 int32_t i; |
| 1015 |
| 1016 for (i = 0; testCases[i].s1 != 0; i++) { |
| 1017 UErrorCode sts = U_ZERO_ERROR; |
| 1018 UChar u1[64], u2[64]; |
| 1019 int32_t matchLen1, matchLen2; |
| 1020 |
| 1021 u_unescape(testCases[i].s1, u1, 64); |
| 1022 u_unescape(testCases[i].s2, u2, 64); |
| 1023 |
| 1024 u_caseInsensitivePrefixMatch(u1, -1, u2, -1, 0, &matchLen1, &matchLen2,
&sts); |
| 1025 if (U_FAILURE(sts)) { |
| 1026 log_err("error: %s, s1=%s, s2=%s", u_errorName(sts), testCases[i].s1
, testCases[i].s2); |
| 1027 } else if (matchLen1 != testCases[i].r1 || matchLen2 != testCases[i].r2)
{ |
| 1028 log_err("s1=%s, s2=%2 / match len1=%d, len2=%d / expected len1=%d, l
en2=%d", |
| 1029 testCases[i].s1, testCases[i].s2, |
| 1030 matchLen1, matchLen2, |
| 1031 testCases[i].r1, testCases[i].r2); |
| 1032 } |
| 1033 } |
| 1034 } |
| 1035 |
992 void addCaseTest(TestNode** root); | 1036 void addCaseTest(TestNode** root); |
993 | 1037 |
994 void addCaseTest(TestNode** root) { | 1038 void addCaseTest(TestNode** root) { |
995 /* cstrcase.c functions, declared in cucdtst.h */ | 1039 /* cstrcase.c functions, declared in cucdtst.h */ |
996 addTest(root, &TestCaseLower, "tsutil/cstrcase/TestCaseLower"); | 1040 addTest(root, &TestCaseLower, "tsutil/cstrcase/TestCaseLower"); |
997 addTest(root, &TestCaseUpper, "tsutil/cstrcase/TestCaseUpper"); | 1041 addTest(root, &TestCaseUpper, "tsutil/cstrcase/TestCaseUpper"); |
998 #if !UCONFIG_NO_BREAK_ITERATION && !UCONFIG_NO_FILE_IO | 1042 #if !UCONFIG_NO_BREAK_ITERATION && !UCONFIG_NO_FILE_IO |
999 addTest(root, &TestCaseTitle, "tsutil/cstrcase/TestCaseTitle"); | 1043 addTest(root, &TestCaseTitle, "tsutil/cstrcase/TestCaseTitle"); |
1000 addTest(root, &TestCaseDutchTitle, "tsutil/cstrcase/TestCaseDutchTitle"); | 1044 addTest(root, &TestCaseDutchTitle, "tsutil/cstrcase/TestCaseDutchTitle"); |
1001 #endif | 1045 #endif |
1002 addTest(root, &TestCaseFolding, "tsutil/cstrcase/TestCaseFolding"); | 1046 addTest(root, &TestCaseFolding, "tsutil/cstrcase/TestCaseFolding"); |
1003 addTest(root, &TestCaseCompare, "tsutil/cstrcase/TestCaseCompare"); | 1047 addTest(root, &TestCaseCompare, "tsutil/cstrcase/TestCaseCompare"); |
1004 addTest(root, &TestUCaseMap, "tsutil/cstrcase/TestUCaseMap"); | 1048 addTest(root, &TestUCaseMap, "tsutil/cstrcase/TestUCaseMap"); |
1005 #if !UCONFIG_NO_BREAK_ITERATION && !UCONFIG_NO_FILE_IO | 1049 #if !UCONFIG_NO_BREAK_ITERATION && !UCONFIG_NO_FILE_IO |
1006 addTest(root, &TestUCaseMapToTitle, "tsutil/cstrcase/TestUCaseMapToTitle"); | 1050 addTest(root, &TestUCaseMapToTitle, "tsutil/cstrcase/TestUCaseMapToTitle"); |
1007 #endif | 1051 #endif |
| 1052 addTest(root, &TestUCaseInsensitivePrefixMatch, "tsutil/cstrcase/TestUCaseIn
sensitivePrefixMatch"); |
1008 } | 1053 } |
OLD | NEW |