OLD | NEW |
1 /* | 1 /* |
2 ******************************************************************************* | 2 ******************************************************************************* |
3 * | 3 * |
4 * Copyright (C) 2002-2013, International Business Machines | 4 * Copyright (C) 2002-2014, 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 | 28 |
29 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) | |
30 | |
31 /* test string case mapping functions --------------------------------------- */ | 29 /* test string case mapping functions --------------------------------------- */ |
32 | 30 |
33 static void | 31 static void |
34 TestCaseLower(void) { | 32 TestCaseLower(void) { |
35 static const UChar | 33 static const UChar |
36 | 34 |
37 beforeLower[]= { 0x61, 0x42, 0x49, 0x3a3, 0xdf, 0x3a3, 0x2f, 0xd93f, 0xdfff
}, | 35 beforeLower[]= { 0x61, 0x42, 0x49, 0x3a3, 0xdf, 0x3a3, 0x2f, 0xd93f, 0xdfff
}, |
38 lowerRoot[]= { 0x61, 0x62, 0x69, 0x3c3, 0xdf, 0x3c2, 0x2f, 0xd93f, 0xdfff
}, | 36 lowerRoot[]= { 0x61, 0x62, 0x69, 0x3c3, 0xdf, 0x3c2, 0x2f, 0xd93f, 0xdfff
}, |
39 lowerTurkish[]={ 0x61, 0x62, 0x131, 0x3c3, 0xdf, 0x3c2, 0x2f, 0xd93f, 0xdfff
}; | 37 lowerTurkish[]={ 0x61, 0x62, 0x131, 0x3c3, 0xdf, 0x3c2, 0x2f, 0xd93f, 0xdfff
}; |
40 | 38 |
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 log_err("ucasemap_open(\"\") failed - %s\n", u_errorName(errorCode)); | 882 log_err("ucasemap_open(\"\") failed - %s\n", u_errorName(errorCode)); |
885 return; | 883 return; |
886 } | 884 } |
887 | 885 |
888 iter=ucasemap_getBreakIterator(csm); | 886 iter=ucasemap_getBreakIterator(csm); |
889 if(iter!=NULL) { | 887 if(iter!=NULL) { |
890 log_err("ucasemap_getBreakIterator() returns %p!=NULL before setting any
iterator or titlecasing\n", iter); | 888 log_err("ucasemap_getBreakIterator() returns %p!=NULL before setting any
iterator or titlecasing\n", iter); |
891 } | 889 } |
892 | 890 |
893 /* Use default UBreakIterator: Word breaks. */ | 891 /* Use default UBreakIterator: Word breaks. */ |
894 length=ucasemap_toTitle(csm, buffer, LENGTHOF(buffer), beforeTitle, LENGTHOF
(beforeTitle), &errorCode); | 892 length=ucasemap_toTitle(csm, buffer, UPRV_LENGTHOF(buffer), beforeTitle, UPR
V_LENGTHOF(beforeTitle), &errorCode); |
895 if( U_FAILURE(errorCode) || | 893 if( U_FAILURE(errorCode) || |
896 length!=LENGTHOF(titleWord) || | 894 length!=UPRV_LENGTHOF(titleWord) || |
897 0!=u_memcmp(buffer, titleWord, length) || | 895 0!=u_memcmp(buffer, titleWord, length) || |
898 buffer[length]!=0 | 896 buffer[length]!=0 |
899 ) { | 897 ) { |
900 log_err_status(errorCode, "ucasemap_toTitle(default iterator)=%ld failed
- %s\n", (long)length, u_errorName(errorCode)); | 898 log_err_status(errorCode, "ucasemap_toTitle(default iterator)=%ld failed
- %s\n", (long)length, u_errorName(errorCode)); |
901 } | 899 } |
902 if (U_SUCCESS(errorCode)) { | 900 if (U_SUCCESS(errorCode)) { |
903 iter=ucasemap_getBreakIterator(csm); | 901 iter=ucasemap_getBreakIterator(csm); |
904 if(iter==NULL) { | 902 if(iter==NULL) { |
905 log_err("ucasemap_getBreakIterator() returns NULL after titlecasing\
n"); | 903 log_err("ucasemap_getBreakIterator() returns NULL after titlecasing\
n"); |
906 } | 904 } |
907 } | 905 } |
908 | 906 |
909 /* Try U_TITLECASE_NO_BREAK_ADJUSTMENT. */ | 907 /* Try U_TITLECASE_NO_BREAK_ADJUSTMENT. */ |
910 ucasemap_setOptions(csm, U_TITLECASE_NO_BREAK_ADJUSTMENT, &errorCode); | 908 ucasemap_setOptions(csm, U_TITLECASE_NO_BREAK_ADJUSTMENT, &errorCode); |
911 if(U_FAILURE(errorCode)) { | 909 if(U_FAILURE(errorCode)) { |
912 log_err_status(errorCode, "error: ucasemap_setOptions(U_TITLECASE_NO_BRE
AK_ADJUSTMENT) failed - %s\n", u_errorName(errorCode)); | 910 log_err_status(errorCode, "error: ucasemap_setOptions(U_TITLECASE_NO_BRE
AK_ADJUSTMENT) failed - %s\n", u_errorName(errorCode)); |
913 return; | 911 return; |
914 } | 912 } |
915 | 913 |
916 length=ucasemap_toTitle(csm, buffer, LENGTHOF(buffer), beforeTitle, LENGTHOF
(beforeTitle), &errorCode); | 914 length=ucasemap_toTitle(csm, buffer, UPRV_LENGTHOF(buffer), beforeTitle, UPR
V_LENGTHOF(beforeTitle), &errorCode); |
917 if( U_FAILURE(errorCode) || | 915 if( U_FAILURE(errorCode) || |
918 length!=LENGTHOF(titleWordNoAdjust) || | 916 length!=UPRV_LENGTHOF(titleWordNoAdjust) || |
919 0!=u_memcmp(buffer, titleWordNoAdjust, length) || | 917 0!=u_memcmp(buffer, titleWordNoAdjust, length) || |
920 buffer[length]!=0 | 918 buffer[length]!=0 |
921 ) { | 919 ) { |
922 log_err("ucasemap_toTitle(default iterator, no break adjustment)=%ld fai
led - %s\n", (long)length, u_errorName(errorCode)); | 920 log_err("ucasemap_toTitle(default iterator, no break adjustment)=%ld fai
led - %s\n", (long)length, u_errorName(errorCode)); |
923 } | 921 } |
924 | 922 |
925 /* Set a sentence break iterator. */ | 923 /* Set a sentence break iterator. */ |
926 errorCode=U_ZERO_ERROR; | 924 errorCode=U_ZERO_ERROR; |
927 sentenceIter=ubrk_open(UBRK_SENTENCE, "", NULL, 0, &errorCode); | 925 sentenceIter=ubrk_open(UBRK_SENTENCE, "", NULL, 0, &errorCode); |
928 if(U_FAILURE(errorCode)) { | 926 if(U_FAILURE(errorCode)) { |
(...skipping 13 matching lines...) Expand all Loading... |
942 log_err("ucasemap_getBreakIterator() returns %p!=%p after setting the it
erator\n", iter, sentenceIter); | 940 log_err("ucasemap_getBreakIterator() returns %p!=%p after setting the it
erator\n", iter, sentenceIter); |
943 } | 941 } |
944 | 942 |
945 ucasemap_setOptions(csm, U_TITLECASE_NO_LOWERCASE, &errorCode); | 943 ucasemap_setOptions(csm, U_TITLECASE_NO_LOWERCASE, &errorCode); |
946 if(U_FAILURE(errorCode)) { | 944 if(U_FAILURE(errorCode)) { |
947 log_err("error: ucasemap_setOptions(U_TITLECASE_NO_LOWERCASE) failed - %
s\n", u_errorName(errorCode)); | 945 log_err("error: ucasemap_setOptions(U_TITLECASE_NO_LOWERCASE) failed - %
s\n", u_errorName(errorCode)); |
948 return; | 946 return; |
949 } | 947 } |
950 | 948 |
951 /* Use the sentence break iterator with the option. Preflight first. */ | 949 /* Use the sentence break iterator with the option. Preflight first. */ |
952 length=ucasemap_toTitle(csm, NULL, 0, beforeTitle, LENGTHOF(beforeTitle), &e
rrorCode); | 950 length=ucasemap_toTitle(csm, NULL, 0, beforeTitle, UPRV_LENGTHOF(beforeTitle
), &errorCode); |
953 if( errorCode!=U_BUFFER_OVERFLOW_ERROR || | 951 if( errorCode!=U_BUFFER_OVERFLOW_ERROR || |
954 length!=LENGTHOF(titleSentNoLower) | 952 length!=UPRV_LENGTHOF(titleSentNoLower) |
955 ) { | 953 ) { |
956 log_err("ucasemap_toTitle(preflight sentence break iterator, no lowercas
ing)=%ld failed - %s\n", (long)length, u_errorName(errorCode)); | 954 log_err("ucasemap_toTitle(preflight sentence break iterator, no lowercas
ing)=%ld failed - %s\n", (long)length, u_errorName(errorCode)); |
957 } | 955 } |
958 | 956 |
959 errorCode=U_ZERO_ERROR; | 957 errorCode=U_ZERO_ERROR; |
960 buffer[0]=0; | 958 buffer[0]=0; |
961 length=ucasemap_toTitle(csm, buffer, LENGTHOF(buffer), beforeTitle, LENGTHOF
(beforeTitle), &errorCode); | 959 length=ucasemap_toTitle(csm, buffer, UPRV_LENGTHOF(buffer), beforeTitle, UPR
V_LENGTHOF(beforeTitle), &errorCode); |
962 if( U_FAILURE(errorCode) || | 960 if( U_FAILURE(errorCode) || |
963 length!=LENGTHOF(titleSentNoLower) || | 961 length!=UPRV_LENGTHOF(titleSentNoLower) || |
964 0!=u_memcmp(buffer, titleSentNoLower, length) || | 962 0!=u_memcmp(buffer, titleSentNoLower, length) || |
965 buffer[length]!=0 | 963 buffer[length]!=0 |
966 ) { | 964 ) { |
967 log_err("ucasemap_toTitle(sentence break iterator, no lowercasing)=%ld f
ailed - %s\n", (long)length, u_errorName(errorCode)); | 965 log_err("ucasemap_toTitle(sentence break iterator, no lowercasing)=%ld f
ailed - %s\n", (long)length, u_errorName(errorCode)); |
968 } | 966 } |
969 | 967 |
970 /* UTF-8 C API coverage. More thorough test via C++ intltest's StringCaseTes
t::TestCasing(). */ | 968 /* UTF-8 C API coverage. More thorough test via C++ intltest's StringCaseTes
t::TestCasing(). */ |
971 { | 969 { |
972 char utf8BeforeTitle[64], utf8TitleSentNoLower[64], utf8[64]; | 970 char utf8BeforeTitle[64], utf8TitleSentNoLower[64], utf8[64]; |
973 int32_t utf8BeforeTitleLength, utf8TitleSentNoLowerLength; | 971 int32_t utf8BeforeTitleLength, utf8TitleSentNoLowerLength; |
974 | 972 |
975 errorCode=U_ZERO_ERROR; | 973 errorCode=U_ZERO_ERROR; |
976 u_strToUTF8(utf8BeforeTitle, (int32_t)sizeof(utf8BeforeTitle), &utf8Befo
reTitleLength, beforeTitle, LENGTHOF(beforeTitle), &errorCode); | 974 u_strToUTF8(utf8BeforeTitle, (int32_t)sizeof(utf8BeforeTitle), &utf8Befo
reTitleLength, beforeTitle, UPRV_LENGTHOF(beforeTitle), &errorCode); |
977 u_strToUTF8(utf8TitleSentNoLower, (int32_t)sizeof(utf8TitleSentNoLower),
&utf8TitleSentNoLowerLength, titleSentNoLower, LENGTHOF(titleSentNoLower), &err
orCode); | 975 u_strToUTF8(utf8TitleSentNoLower, (int32_t)sizeof(utf8TitleSentNoLower),
&utf8TitleSentNoLowerLength, titleSentNoLower, UPRV_LENGTHOF(titleSentNoLower),
&errorCode); |
978 | 976 |
979 length=ucasemap_utf8ToTitle(csm, utf8, (int32_t)sizeof(utf8), utf8Before
Title, utf8BeforeTitleLength, &errorCode); | 977 length=ucasemap_utf8ToTitle(csm, utf8, (int32_t)sizeof(utf8), utf8Before
Title, utf8BeforeTitleLength, &errorCode); |
980 if( U_FAILURE(errorCode) || | 978 if( U_FAILURE(errorCode) || |
981 length!=utf8TitleSentNoLowerLength || | 979 length!=utf8TitleSentNoLowerLength || |
982 0!=uprv_memcmp(utf8, utf8TitleSentNoLower, length) || | 980 0!=uprv_memcmp(utf8, utf8TitleSentNoLower, length) || |
983 utf8[length]!=0 | 981 utf8[length]!=0 |
984 ) { | 982 ) { |
985 log_err("ucasemap_utf8ToTitle(sentence break iterator, no lowercasin
g)=%ld failed - %s\n", (long)length, u_errorName(errorCode)); | 983 log_err("ucasemap_utf8ToTitle(sentence break iterator, no lowercasin
g)=%ld failed - %s\n", (long)length, u_errorName(errorCode)); |
986 } | 984 } |
987 } | 985 } |
(...skipping 13 matching lines...) Expand all Loading... |
1001 addTest(root, &TestCaseTitle, "tsutil/cstrcase/TestCaseTitle"); | 999 addTest(root, &TestCaseTitle, "tsutil/cstrcase/TestCaseTitle"); |
1002 addTest(root, &TestCaseDutchTitle, "tsutil/cstrcase/TestCaseDutchTitle"); | 1000 addTest(root, &TestCaseDutchTitle, "tsutil/cstrcase/TestCaseDutchTitle"); |
1003 #endif | 1001 #endif |
1004 addTest(root, &TestCaseFolding, "tsutil/cstrcase/TestCaseFolding"); | 1002 addTest(root, &TestCaseFolding, "tsutil/cstrcase/TestCaseFolding"); |
1005 addTest(root, &TestCaseCompare, "tsutil/cstrcase/TestCaseCompare"); | 1003 addTest(root, &TestCaseCompare, "tsutil/cstrcase/TestCaseCompare"); |
1006 addTest(root, &TestUCaseMap, "tsutil/cstrcase/TestUCaseMap"); | 1004 addTest(root, &TestUCaseMap, "tsutil/cstrcase/TestUCaseMap"); |
1007 #if !UCONFIG_NO_BREAK_ITERATION && !UCONFIG_NO_FILE_IO | 1005 #if !UCONFIG_NO_BREAK_ITERATION && !UCONFIG_NO_FILE_IO |
1008 addTest(root, &TestUCaseMapToTitle, "tsutil/cstrcase/TestUCaseMapToTitle"); | 1006 addTest(root, &TestUCaseMapToTitle, "tsutil/cstrcase/TestUCaseMapToTitle"); |
1009 #endif | 1007 #endif |
1010 } | 1008 } |
OLD | NEW |