1 /********************************************************************
3 * Copyright (c) 1997-2008, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /*****************************************************************************
10 * Modification History:
12 * Madhu Katragadda Ported for C API
13 ******************************************************************************
14 *//* C API TEST For COLLATOR */
16 #include "unicode/utypes.h"
18 #if !UCONFIG_NO_COLLATION
23 #include "unicode/uloc.h"
24 #include "unicode/ustring.h"
25 #include "unicode/ures.h"
26 #include "unicode/ucoleitr.h"
32 static void TestAttribute(void);
33 static void TestDefault(void);
34 int TestBufferSize(); /* defined in "colutil.c" */
39 /* next two function is modified from "i18n/ucol.cpp" to avoid include "ucol_imp.h" */
40 static void uprv_appendByteToHexString(char *dst
, uint8_t val
) {
41 uint32_t len
= (uint32_t)strlen(dst
);
42 sprintf(dst
+len
, "%02X", val
);
45 static char* U_EXPORT2
ucol_sortKeyToString(const UCollator
*coll
, const uint8_t *sortkey
, char *buffer
, uint32_t *len
) {
46 int32_t strength
= UCOL_PRIMARY
;
47 uint32_t res_size
= 0;
48 UBool doneCase
= FALSE
;
50 char *current
= buffer
;
51 const uint8_t *currentSk
= sortkey
;
53 UErrorCode error_code
= U_ZERO_ERROR
;
57 while(strength
<= UCOL_QUATERNARY
&& strength
<= ucol_getAttribute(coll
,UCOL_STRENGTH
, &error_code
)) {
58 if(U_FAILURE(error_code
)) {
59 log_err("ucol_getAttribute returned error: %s\n", u_errorName(error_code
));
61 if(strength
> UCOL_PRIMARY
) {
62 strcat(current
, " . ");
64 while(*currentSk
!= 0x01 && *currentSk
!= 0x00) { /* print a level */
65 uprv_appendByteToHexString(current
, *currentSk
++);
68 if(ucol_getAttribute(coll
,UCOL_CASE_LEVEL
, &error_code
) == UCOL_ON
&& strength
== UCOL_SECONDARY
&& doneCase
== FALSE
) {
70 } else if(ucol_getAttribute(coll
,UCOL_CASE_LEVEL
, &error_code
) == UCOL_OFF
|| doneCase
== TRUE
|| strength
!= UCOL_SECONDARY
) {
73 if(U_FAILURE(error_code
)) {
74 log_err("ucol_getAttribute returned error: %s\n", u_errorName(error_code
));
76 uprv_appendByteToHexString(current
, *currentSk
++); /* This should print '01' */
77 if(strength
== UCOL_QUATERNARY
&& ucol_getAttribute(coll
,UCOL_ALTERNATE_HANDLING
, &error_code
) == UCOL_NON_IGNORABLE
) {
82 if(ucol_getAttribute(coll
,UCOL_STRENGTH
, &error_code
) == UCOL_IDENTICAL
) {
83 strcat(current
, " . ");
84 while(*currentSk
!= 0) {
85 uprv_appendByteToHexString(current
, *currentSk
++);
89 uprv_appendByteToHexString(current
, *currentSk
++);
91 if(U_FAILURE(error_code
)) {
92 log_err("ucol_getAttribute returned error: %s\n", u_errorName(error_code
));
102 /* end of avoid include "ucol_imp.h" */
105 void addCollAPITest(TestNode
** root
)
107 /* WEIVTODO: return tests here */
108 addTest(root
, &TestProperty
, "tscoll/capitst/TestProperty");
109 addTest(root
, &TestRuleBasedColl
, "tscoll/capitst/TestRuleBasedColl");
110 addTest(root
, &TestCompare
, "tscoll/capitst/TestCompare");
111 addTest(root
, &TestSortKey
, "tscoll/capitst/TestSortKey");
112 addTest(root
, &TestHashCode
, "tscoll/capitst/TestHashCode");
113 addTest(root
, &TestElemIter
, "tscoll/capitst/TestElemIter");
114 addTest(root
, &TestGetAll
, "tscoll/capitst/TestGetAll");
115 /*addTest(root, &TestGetDefaultRules, "tscoll/capitst/TestGetDefaultRules");*/
116 addTest(root
, &TestDecomposition
, "tscoll/capitst/TestDecomposition");
117 addTest(root
, &TestSafeClone
, "tscoll/capitst/TestSafeClone");
118 addTest(root
, &TestCloneBinary
, "tscoll/capitst/TestCloneBinary");
119 addTest(root
, &TestGetSetAttr
, "tscoll/capitst/TestGetSetAttr");
120 addTest(root
, &TestBounds
, "tscoll/capitst/TestBounds");
121 addTest(root
, &TestGetLocale
, "tscoll/capitst/TestGetLocale");
122 addTest(root
, &TestSortKeyBufferOverrun
, "tscoll/capitst/TestSortKeyBufferOverrun");
123 addTest(root
, &TestAttribute
, "tscoll/capitst/TestAttribute");
124 addTest(root
, &TestGetTailoredSet
, "tscoll/capitst/TestGetTailoredSet");
125 addTest(root
, &TestMergeSortKeys
, "tscoll/capitst/TestMergeSortKeys");
126 addTest(root
, &TestShortString
, "tscoll/capitst/TestShortString");
127 addTest(root
, &TestGetContractionsAndUnsafes
, "tscoll/capitst/TestGetContractionsAndUnsafes");
128 addTest(root
, &TestOpenBinary
, "tscoll/capitst/TestOpenBinary");
129 addTest(root
, &TestDefault
, "tscoll/capitst/TestDefault");
132 void TestGetSetAttr(void) {
133 UErrorCode status
= U_ZERO_ERROR
;
134 UCollator
*coll
= ucol_open(NULL
, &status
);
137 UColAttributeValue val
[5];
139 UColAttributeValue nonValue
;
141 {UCOL_FRENCH_COLLATION
, {UCOL_ON
, UCOL_OFF
}, 2, UCOL_SHIFTED
},
142 {UCOL_ALTERNATE_HANDLING
, {UCOL_NON_IGNORABLE
, UCOL_SHIFTED
}, 2, UCOL_OFF
},/* attribute for handling variable elements*/
143 {UCOL_CASE_FIRST
, {UCOL_OFF
, UCOL_LOWER_FIRST
, UCOL_UPPER_FIRST
}, 3, UCOL_SHIFTED
},/* who goes first, lower case or uppercase */
144 {UCOL_CASE_LEVEL
, {UCOL_ON
, UCOL_OFF
}, 2, UCOL_SHIFTED
},/* do we have an extra case level */
145 {UCOL_NORMALIZATION_MODE
, {UCOL_ON
, UCOL_OFF
}, 2, UCOL_SHIFTED
},/* attribute for normalization */
146 {UCOL_DECOMPOSITION_MODE
, {UCOL_ON
, UCOL_OFF
}, 2, UCOL_SHIFTED
},
147 {UCOL_STRENGTH
, {UCOL_PRIMARY
, UCOL_SECONDARY
, UCOL_TERTIARY
, UCOL_QUATERNARY
, UCOL_IDENTICAL
}, 5, UCOL_SHIFTED
},/* attribute for strength */
148 {UCOL_HIRAGANA_QUATERNARY_MODE
, {UCOL_ON
, UCOL_OFF
}, 2, UCOL_SHIFTED
},/* when turned on, this attribute */
150 UColAttribute currAttr
;
151 UColAttributeValue value
;
152 uint32_t i
= 0, j
= 0;
154 for(i
= 0; i
<sizeof(attrs
)/sizeof(attrs
[0]); i
++) {
155 currAttr
= attrs
[i
].att
;
156 ucol_setAttribute(coll
, currAttr
, UCOL_DEFAULT
, &status
);
157 if(U_FAILURE(status
)) {
158 log_err("ucol_setAttribute with the default value returned error: %s\n", u_errorName(status
));
161 value
= ucol_getAttribute(coll
, currAttr
, &status
);
162 if(U_FAILURE(status
)) {
163 log_err("ucol_getAttribute returned error: %s\n", u_errorName(status
));
166 for(j
= 0; j
<attrs
[i
].valueSize
; j
++) {
167 ucol_setAttribute(coll
, currAttr
, attrs
[i
].val
[j
], &status
);
168 if(U_FAILURE(status
)) {
169 log_err("ucol_setAttribute with the value %i returned error: %s\n", attrs
[i
].val
[j
], u_errorName(status
));
173 status
= U_ZERO_ERROR
;
174 ucol_setAttribute(coll
, currAttr
, attrs
[i
].nonValue
, &status
);
175 if(U_SUCCESS(status
)) {
176 log_err("ucol_setAttribute with the bad value didn't return an error\n");
179 status
= U_ZERO_ERROR
;
181 ucol_setAttribute(coll
, currAttr
, value
, &status
);
182 if(U_FAILURE(status
)) {
183 log_err("ucol_setAttribute with the default valuereturned error: %s\n", u_errorName(status
));
188 status
= U_ZERO_ERROR
;
189 value
= ucol_getAttribute(coll
, UCOL_ATTRIBUTE_COUNT
, &status
);
190 if(U_SUCCESS(status
)) {
191 log_err("ucol_getAttribute for UCOL_ATTRIBUTE_COUNT didn't return an error\n");
193 status
= U_ZERO_ERROR
;
194 ucol_setAttribute(coll
, UCOL_ATTRIBUTE_COUNT
, UCOL_DEFAULT
, &status
);
195 if(U_SUCCESS(status
)) {
196 log_err("ucol_setAttribute for UCOL_ATTRIBUTE_COUNT didn't return an error\n");
198 status
= U_ZERO_ERROR
;
203 static void doAssert(int condition
, const char *message
)
206 log_err("ERROR : %s\n", message
);
211 /* We don't have default rules, at least not in the previous sense */
212 void TestGetDefaultRules(){
214 UErrorCode status
=U_ZERO_ERROR
;
215 UCollator
*coll
=NULL
;
216 int32_t len1
= 0, len2
=0;
217 uint8_t *binColData
= NULL
;
219 UResourceBundle
*res
= NULL
;
220 UResourceBundle
*binColl
= NULL
;
221 uint8_t *binResult
= NULL
;
224 const UChar
* defaultRulesArray
=ucol_getDefaultRulesArray(&size
);
225 log_verbose("Test the function ucol_getDefaultRulesArray()\n");
227 coll
= ucol_openRules(defaultRulesArray
, size
, UCOL_ON
, UCOL_PRIMARY
, &status
);
228 if(U_SUCCESS(status
) && coll
!=NULL
) {
229 binColData
= (uint8_t*)ucol_cloneRuleData(coll
, &len1
, &status
);
235 res
=ures_open(NULL
, "root", &status
);
236 if(U_FAILURE(status
)){
237 log_err("ERROR: Failed to get resource for \"root Locale\" with %s", myErrorName(status
));
240 binColl
=ures_getByKey(res
, "%%Collation", binColl
, &status
);
241 if(U_SUCCESS(status
)){
242 binResult
=(uint8_t*)ures_getBinary(binColl
, &len2
, &status
);
243 if(U_FAILURE(status
)){
244 log_err("ERROR: ures_getBinary() failed\n");
247 log_err("ERROR: ures_getByKey(locale(default), %%Collation) failed");
252 log_err("Error: ucol_getDefaultRulesArray() failed to return the correct length.\n");
254 if(memcmp(binColData
, binResult
, len1
) != 0){
255 log_err("Error: ucol_getDefaultRulesArray() failed\n");
266 /* Collator Properties
267 ucol_open, ucol_strcoll, getStrength/setStrength
268 getDecomposition/setDecomposition, getDisplayName*/
271 UCollator
*col
, *ruled
;
273 int32_t len
= 0, i
= 0;
274 UChar
*source
, *target
;
276 UErrorCode status
= U_ZERO_ERROR
;
278 All the collations have the same version in an ICU
280 ICU 2.0 currVersionArray = {0x18, 0xC0, 0x02, 0x02};
281 ICU 2.1 currVersionArray = {0x19, 0x00, 0x03, 0x03};
282 ICU 2.2 currVersionArray = {0x21, 0x40, 0x04, 0x04};
283 ICU 2.4 currVersionArray = {0x21, 0x40, 0x04, 0x04};
284 ICU 2.6 currVersionArray = {0x21, 0x40, 0x03, 0x03};
285 ICU 2.8 currVersionArray = {0x29, 0x80, 0x00, 0x04};
286 ICU 3.4 currVersionArray = {0x31, 0xC0, 0x00, 0x04};
288 UVersionInfo currVersionArray
= {0x31, 0xC0, 0x00, 0x05};
289 /* ICU 3.4 had UCA 4.1 */
290 /*UVersionInfo currUCAVersionArray = {4, 1, 0, 0};*/
291 UVersionInfo currUCAVersionArray
= {5, 1, 0, 0};
292 UVersionInfo versionArray
= {0, 0, 0, 0};
293 UVersionInfo versionUCAArray
= {0, 0, 0, 0};
295 log_verbose("The property tests begin : \n");
296 log_verbose("Test ucol_strcoll : \n");
297 col
= ucol_open("en_US", &status
);
298 if (U_FAILURE(status
)) {
299 log_err("Default Collator creation failed.: %s\n", myErrorName(status
));
303 ucol_getVersion(col
, versionArray
);
304 for (i
=0; i
<4; ++i
) {
305 if (versionArray
[i
] != currVersionArray
[i
]) {
306 log_err("Testing ucol_getVersion() - unexpected result: %hu.%hu.%hu.%hu\n",
307 versionArray
[0], versionArray
[1], versionArray
[2], versionArray
[3]);
312 ucol_getUCAVersion(col
, versionUCAArray
);
313 for (i
=0; i
<4; ++i
) {
314 if (versionUCAArray
[i
] != currUCAVersionArray
[i
]) {
315 log_err("Testing ucol_getUCAVersion() - unexpected result: %hu.%hu.%hu.%hu\n",
316 versionUCAArray
[0], versionUCAArray
[1], versionUCAArray
[2], versionUCAArray
[3]);
321 source
=(UChar
*)malloc(sizeof(UChar
) * 12);
322 target
=(UChar
*)malloc(sizeof(UChar
) * 12);
325 u_uastrcpy(source
, "ab");
326 u_uastrcpy(target
, "abc");
328 doAssert((ucol_strcoll(col
, source
, u_strlen(source
), target
, u_strlen(target
)) == UCOL_LESS
), "ab < abc comparison failed");
330 u_uastrcpy(source
, "ab");
331 u_uastrcpy(target
, "AB");
333 doAssert((ucol_strcoll(col
, source
, u_strlen(source
), target
, u_strlen(target
)) == UCOL_LESS
), "ab < AB comparison failed");
334 /* u_uastrcpy(source, "black-bird");
335 u_uastrcpy(target, "blackbird"); */
336 u_uastrcpy(target
, "black-bird");
337 u_uastrcpy(source
, "blackbird");
339 doAssert((ucol_strcoll(col
, source
, u_strlen(source
), target
, u_strlen(target
)) == UCOL_GREATER
),
340 "black-bird > blackbird comparison failed");
341 u_uastrcpy(source
, "black bird");
342 u_uastrcpy(target
, "black-bird");
343 doAssert((ucol_strcoll(col
, source
, u_strlen(source
), target
, u_strlen(target
)) == UCOL_LESS
),
344 "black bird < black-bird comparison failed");
345 u_uastrcpy(source
, "Hello");
346 u_uastrcpy(target
, "hello");
348 doAssert((ucol_strcoll(col
, source
, u_strlen(source
), target
, u_strlen(target
)) == UCOL_GREATER
),
349 "Hello > hello comparison failed");
352 log_verbose("Test ucol_strcoll ends.\n");
354 log_verbose("testing ucol_getStrength() method ...\n");
355 doAssert( (ucol_getStrength(col
) == UCOL_TERTIARY
), "collation object has the wrong strength");
356 doAssert( (ucol_getStrength(col
) != UCOL_PRIMARY
), "collation object's strength is primary difference");
358 log_verbose("testing ucol_setStrength() method ...\n");
359 ucol_setStrength(col
, UCOL_SECONDARY
);
360 doAssert( (ucol_getStrength(col
) != UCOL_TERTIARY
), "collation object's strength is secondary difference");
361 doAssert( (ucol_getStrength(col
) != UCOL_PRIMARY
), "collation object's strength is primary difference");
362 doAssert( (ucol_getStrength(col
) == UCOL_SECONDARY
), "collation object has the wrong strength");
365 log_verbose("Get display name for the default collation in German : \n");
367 len
=ucol_getDisplayName("en_US", "de_DE", NULL
, 0, &status
);
368 if(status
==U_BUFFER_OVERFLOW_ERROR
){
370 disName
=(UChar
*)malloc(sizeof(UChar
) * (len
+1));
371 ucol_getDisplayName("en_US", "de_DE", disName
, len
+1, &status
);
372 log_verbose("the display name for default collation in german: %s\n", austrdup(disName
) );
375 if(U_FAILURE(status
)){
376 log_err("ERROR: in getDisplayName: %s\n", myErrorName(status
));
379 log_verbose("Default collation getDisplayName ended.\n");
381 ruled
= ucol_open("da_DK", &status
);
382 log_verbose("ucol_getRules() testing ...\n");
383 ucol_getRules(ruled
, &tempLength
);
384 doAssert( tempLength
!= 0, "getRules() result incorrect" );
385 log_verbose("getRules tests end.\n");
387 UChar
*buffer
= (UChar
*)malloc(200000*sizeof(UChar
));
388 int32_t bufLen
= 200000;
390 log_verbose("ucol_getRulesEx() testing ...\n");
391 tempLength
= ucol_getRulesEx(col
,UCOL_TAILORING_ONLY
,buffer
,bufLen
);
392 doAssert( tempLength
== 0x0a, "getRulesEx() result incorrect" );
393 log_verbose("getRules tests end.\n");
395 log_verbose("ucol_getRulesEx() testing ...\n");
396 tempLength
=ucol_getRulesEx(col
,UCOL_FULL_RULES
,buffer
,bufLen
);
397 doAssert( tempLength
!= 0, "getRulesEx() result incorrect" );
398 log_verbose("getRules tests end.\n");
404 log_verbose("open an collator for french locale");
405 col
= ucol_open("fr_FR", &status
);
406 if (U_FAILURE(status
)) {
407 log_err("ERROR: Creating French collation failed.: %s\n", myErrorName(status
));
410 ucol_setStrength(col
, UCOL_PRIMARY
);
411 log_verbose("testing ucol_getStrength() method again ...\n");
412 doAssert( (ucol_getStrength(col
) != UCOL_TERTIARY
), "collation object has the wrong strength");
413 doAssert( (ucol_getStrength(col
) == UCOL_PRIMARY
), "collation object's strength is not primary difference");
415 log_verbose("testing French ucol_setStrength() method ...\n");
416 ucol_setStrength(col
, UCOL_TERTIARY
);
417 doAssert( (ucol_getStrength(col
) == UCOL_TERTIARY
), "collation object's strength is not tertiary difference");
418 doAssert( (ucol_getStrength(col
) != UCOL_PRIMARY
), "collation object's strength is primary difference");
419 doAssert( (ucol_getStrength(col
) != UCOL_SECONDARY
), "collation object's strength is secondary difference");
422 log_verbose("Get display name for the french collation in english : \n");
423 len
=ucol_getDisplayName("fr_FR", "en_US", NULL
, 0, &status
);
424 if(status
==U_BUFFER_OVERFLOW_ERROR
){
426 disName
=(UChar
*)malloc(sizeof(UChar
) * (len
+1));
427 ucol_getDisplayName("fr_FR", "en_US", disName
, len
+1, &status
);
428 log_verbose("the display name for french collation in english: %s\n", austrdup(disName
) );
431 if(U_FAILURE(status
)){
432 log_err("ERROR: in getDisplayName: %s\n", myErrorName(status
));
435 log_verbose("Default collation getDisplayName ended.\n");
439 /* Test RuleBasedCollator and getRules*/
440 void TestRuleBasedColl()
442 UCollator
*col1
, *col2
, *col3
, *col4
;
443 UCollationElements
*iter1
, *iter2
;
448 const UChar
*rule1
, *rule2
, *rule3
, *rule4
;
450 UErrorCode status
= U_ZERO_ERROR
;
451 u_uastrcpy(ruleset1
, "&9 < a, A < b, B < c, C; ch, cH, Ch, CH < d, D, e, E");
452 u_uastrcpy(ruleset2
, "&9 < a, A < b, B < c, C < d, D, e, E");
455 col1
= ucol_openRules(ruleset1
, u_strlen(ruleset1
), UCOL_DEFAULT
, UCOL_DEFAULT_STRENGTH
, NULL
,&status
);
456 if (U_FAILURE(status
)) {
457 log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status
));
461 log_verbose("PASS: RuleBased Collator creation passed\n");
463 status
= U_ZERO_ERROR
;
464 col2
= ucol_openRules(ruleset2
, u_strlen(ruleset2
), UCOL_DEFAULT
, UCOL_DEFAULT_STRENGTH
, NULL
, &status
);
465 if (U_FAILURE(status
)) {
466 log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status
));
470 log_verbose("PASS: RuleBased Collator creation passed\n");
473 status
= U_ZERO_ERROR
;
474 col3
= ucol_open(NULL
, &status
);
475 if (U_FAILURE(status
)) {
476 log_err("Default Collator creation failed.: %s\n", myErrorName(status
));
480 log_verbose("PASS: Default Collator creation passed\n");
482 rule1
= ucol_getRules(col1
, &tempLength
);
483 rule2
= ucol_getRules(col2
, &tempLength
);
484 rule3
= ucol_getRules(col3
, &tempLength
);
486 doAssert((u_strcmp(rule1
, rule2
) != 0), "Default collator getRules failed");
487 doAssert((u_strcmp(rule2
, rule3
) != 0), "Default collator getRules failed");
488 doAssert((u_strcmp(rule1
, rule3
) != 0), "Default collator getRules failed");
490 col4
=ucol_openRules(rule2
, u_strlen(rule2
), UCOL_DEFAULT
, UCOL_DEFAULT_STRENGTH
, NULL
, &status
);
491 if (U_FAILURE(status
)) {
492 log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status
));
495 rule4
= ucol_getRules(col4
, &tempLength
);
496 doAssert((u_strcmp(rule2
, rule4
) == 0), "Default collator getRules failed");
503 /* tests that modifier ! is always ignored */
504 u_uastrcpy(ruleset1
, "!&a<b");
508 col1
= ucol_openRules(ruleset1
, u_strlen(ruleset1
), UCOL_DEFAULT
, UCOL_DEFAULT_STRENGTH
, NULL
, &status
);
509 if (U_FAILURE(status
)) {
510 log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status
));
513 col2
= ucol_open("en_US", &status
);
514 if (U_FAILURE(status
)) {
515 log_err("en_US Collator creation failed.: %s\n", myErrorName(status
));
518 iter1
= ucol_openElements(col1
, teststr
, 3, &status
);
519 iter2
= ucol_openElements(col2
, teststr
, 3, &status
);
520 if(U_FAILURE(status
)) {
521 log_err("ERROR: CollationElement iterator creation failed.: %s\n", myErrorName(status
));
525 /* testing with en since thai has its own tailoring */
526 uint32_t ce
= ucol_next(iter1
, &status
);
527 uint32_t ce2
= ucol_next(iter2
, &status
);
528 if(U_FAILURE(status
)) {
529 log_err("ERROR: CollationElement iterator creation failed.: %s\n", myErrorName(status
));
533 log_err("! modifier test failed");
535 if (ce
== UCOL_NULLORDER
) {
539 ucol_closeElements(iter1
);
540 ucol_closeElements(iter2
);
543 /* test that we can start a rule without a & or < */
544 u_uastrcpy(ruleset1
, "< z < a");
545 col1
= ucol_openRules(ruleset1
, u_strlen(ruleset1
), UCOL_DEFAULT
, UCOL_DEFAULT_STRENGTH
, NULL
, &status
);
546 if (U_FAILURE(status
)) {
547 log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status
));
550 u_uastrcpy(teststr
, "z");
551 u_uastrcpy(teststr2
, "a");
552 if (ucol_greaterOrEqual(col1
, teststr
, 1, teststr2
, 1)) {
553 log_err("Rule \"z < a\" fails");
560 UErrorCode status
= U_ZERO_ERROR
;
565 log_verbose("The compare tests begin : \n");
567 col
= ucol_open("en_US", &status
);
568 if(U_FAILURE(status
)) {
569 log_err("ucal_open() collation creation failed.: %s\n", myErrorName(status
));
572 test1
=(UChar
*)malloc(sizeof(UChar
) * 6);
573 test2
=(UChar
*)malloc(sizeof(UChar
) * 6);
574 u_uastrcpy(test1
, "Abcda");
575 u_uastrcpy(test2
, "abcda");
577 log_verbose("Use tertiary comparison level testing ....\n");
579 doAssert( (!ucol_equal(col
, test1
, u_strlen(test1
), test2
, u_strlen(test2
))), "Result should be \"Abcda\" != \"abcda\" ");
580 doAssert( (ucol_greater(col
, test1
, u_strlen(test1
), test2
, u_strlen(test2
))), "Result should be \"Abcda\" >>> \"abcda\" ");
581 doAssert( (ucol_greaterOrEqual(col
, test1
, u_strlen(test1
), test2
, u_strlen(test2
))), "Result should be \"Abcda\" >>> \"abcda\"");
583 ucol_setStrength(col
, UCOL_SECONDARY
);
584 log_verbose("Use secondary comparison level testing ....\n");
586 doAssert( (ucol_equal(col
, test1
, u_strlen(test1
), test2
, u_strlen(test2
) )), "Result should be \"Abcda\" == \"abcda\"");
587 doAssert( (!ucol_greater(col
, test1
, u_strlen(test1
), test2
, u_strlen(test2
))), "Result should be \"Abcda\" == \"abcda\"");
588 doAssert( (ucol_greaterOrEqual(col
, test1
, u_strlen(test1
), test2
, u_strlen(test2
) )), "Result should be \"Abcda\" == \"abcda\"");
590 ucol_setStrength(col
, UCOL_PRIMARY
);
591 log_verbose("Use primary comparison level testing ....\n");
593 doAssert( (ucol_equal(col
, test1
, u_strlen(test1
), test2
, u_strlen(test2
))), "Result should be \"Abcda\" == \"abcda\"");
594 doAssert( (!ucol_greater(col
, test1
, u_strlen(test1
), test2
, u_strlen(test2
))), "Result should be \"Abcda\" == \"abcda\"");
595 doAssert( (ucol_greaterOrEqual(col
, test1
, u_strlen(test1
), test2
, u_strlen(test2
))), "Result should be \"Abcda\" == \"abcda\"");
598 log_verbose("The compare tests end.\n");
605 ---------------------------------------------
606 tests decomposition setting
608 void TestDecomposition() {
609 UErrorCode status
= U_ZERO_ERROR
;
610 UCollator
*en_US
, *el_GR
, *vi_VN
;
611 en_US
= ucol_open("en_US", &status
);
612 el_GR
= ucol_open("el_GR", &status
);
613 vi_VN
= ucol_open("vi_VN", &status
);
615 if (U_FAILURE(status
)) {
616 log_err("ERROR: collation creation failed.: %s\n", myErrorName(status
));
620 if (ucol_getAttribute(vi_VN
, UCOL_NORMALIZATION_MODE
, &status
) != UCOL_ON
||
623 log_err("ERROR: vi_VN collation did not have cannonical decomposition for normalization!\n");
626 status
= U_ZERO_ERROR
;
627 if (ucol_getAttribute(el_GR
, UCOL_NORMALIZATION_MODE
, &status
) != UCOL_ON
||
630 log_err("ERROR: el_GR collation did not have cannonical decomposition for normalization!\n");
633 status
= U_ZERO_ERROR
;
634 if (ucol_getAttribute(en_US
, UCOL_NORMALIZATION_MODE
, &status
) != UCOL_OFF
||
637 log_err("ERROR: en_US collation had cannonical decomposition for normalization!\n");
645 #define CLONETEST_COLLATOR_COUNT 4
647 void TestSafeClone() {
650 static const UChar umlautUStr
[] = {0x00DC, 0};
651 static const UChar oeStr
[] = {0x0055, 0x0045, 0};
652 UCollator
* someCollators
[CLONETEST_COLLATOR_COUNT
];
653 UCollator
* someClonedCollators
[CLONETEST_COLLATOR_COUNT
];
655 UErrorCode err
= U_ZERO_ERROR
;
656 int8_t index
= 6; /* Leave this here to test buffer alingment in memory*/
657 uint8_t buffer
[CLONETEST_COLLATOR_COUNT
] [U_COL_SAFECLONE_BUFFERSIZE
];
658 int32_t bufferSize
= U_COL_SAFECLONE_BUFFERSIZE
;
659 const char sampleRuleChars
[] = "&Z < CH";
660 UChar sampleRule
[sizeof(sampleRuleChars
)];
662 if (TestBufferSize()) {
663 log_err("U_COL_SAFECLONE_BUFFERSIZE should be larger than sizeof(UCollator)\n");
667 u_uastrcpy(test1
, "abCda");
668 u_uastrcpy(test2
, "abcda");
669 u_uastrcpy(sampleRule
, sampleRuleChars
);
671 /* one default collator & two complex ones */
672 someCollators
[0] = ucol_open("en_US", &err
);
673 someCollators
[1] = ucol_open("ko", &err
);
674 someCollators
[2] = ucol_open("ja_JP", &err
);
675 someCollators
[3] = ucol_openRules(sampleRule
, -1, UCOL_ON
, UCOL_TERTIARY
, NULL
, &err
);
677 for (index
= 0; index
< CLONETEST_COLLATOR_COUNT
; index
++) {
678 ucol_close(someCollators
[index
]);
680 log_data_err("Couldn't open one or more collators\n");
684 /* Check the various error & informational states: */
686 /* Null status - just returns NULL */
687 if (0 != ucol_safeClone(someCollators
[0], buffer
[0], &bufferSize
, 0))
689 log_err("FAIL: Cloned Collator failed to deal correctly with null status\n");
691 /* error status - should return 0 & keep error the same */
692 err
= U_MEMORY_ALLOCATION_ERROR
;
693 if (0 != ucol_safeClone(someCollators
[0], buffer
[0], &bufferSize
, &err
) || err
!= U_MEMORY_ALLOCATION_ERROR
)
695 log_err("FAIL: Cloned Collator failed to deal correctly with incoming error status\n");
699 /* Null buffer size pointer - just returns NULL & set error to U_ILLEGAL_ARGUMENT_ERROR*/
700 if (0 != ucol_safeClone(someCollators
[0], buffer
[0], 0, &err
) || err
!= U_ILLEGAL_ARGUMENT_ERROR
)
702 log_err("FAIL: Cloned Collator failed to deal correctly with null bufferSize pointer\n");
706 /* buffer size pointer is 0 - fill in pbufferSize with a size */
708 if (0 != ucol_safeClone(someCollators
[0], buffer
[0], &bufferSize
, &err
) || U_FAILURE(err
) || bufferSize
<= 0)
710 log_err("FAIL: Cloned Collator failed a sizing request ('preflighting')\n");
712 /* Verify our define is large enough */
713 if (U_COL_SAFECLONE_BUFFERSIZE
< bufferSize
)
715 log_err("FAIL: Pre-calculated buffer size is too small\n");
717 /* Verify we can use this run-time calculated size */
718 if (0 == (col
= ucol_safeClone(someCollators
[0], buffer
[0], &bufferSize
, &err
)) || U_FAILURE(err
))
720 log_err("FAIL: Collator can't be cloned with run-time size\n");
722 if (col
) ucol_close(col
);
723 /* size one byte too small - should allocate & let us know */
725 if (0 == (col
= ucol_safeClone(someCollators
[0], 0, &bufferSize
, &err
)) || err
!= U_SAFECLONE_ALLOCATED_WARNING
)
727 log_err("FAIL: Cloned Collator failed to deal correctly with too-small buffer size\n");
729 if (col
) ucol_close(col
);
731 bufferSize
= U_COL_SAFECLONE_BUFFERSIZE
;
734 /* Null buffer pointer - return Collator & set error to U_SAFECLONE_ALLOCATED_ERROR */
735 if (0 == (col
= ucol_safeClone(someCollators
[0], 0, &bufferSize
, &err
)) || err
!= U_SAFECLONE_ALLOCATED_WARNING
)
737 log_err("FAIL: Cloned Collator failed to deal correctly with null buffer pointer\n");
739 if (col
) ucol_close(col
);
742 /* Null Collator - return NULL & set U_ILLEGAL_ARGUMENT_ERROR */
743 if (0 != ucol_safeClone(0, buffer
[0], &bufferSize
, &err
) || err
!= U_ILLEGAL_ARGUMENT_ERROR
)
745 log_err("FAIL: Cloned Collator failed to deal correctly with null Collator pointer\n");
750 /* Test that a cloned collator doesn't accidentally use UCA. */
751 col
=ucol_open("de@collation=phonebook", &err
);
752 bufferSize
= U_COL_SAFECLONE_BUFFERSIZE
;
753 someClonedCollators
[0] = ucol_safeClone(col
, buffer
[0], &bufferSize
, &err
);
754 doAssert( (ucol_greater(col
, umlautUStr
, u_strlen(umlautUStr
), oeStr
, u_strlen(oeStr
))), "Original German phonebook collation sorts differently than expected");
755 doAssert( (ucol_greater(someClonedCollators
[0], umlautUStr
, u_strlen(umlautUStr
), oeStr
, u_strlen(oeStr
))), "Cloned German phonebook collation sorts differently than expected");
756 if (!ucol_equals(someClonedCollators
[0], col
)) {
757 log_err("FAIL: Cloned German phonebook collator is not equal to original.\n");
760 ucol_close(someClonedCollators
[0]);
764 /* change orig & clone & make sure they are independent */
766 for (index
= 0; index
< CLONETEST_COLLATOR_COUNT
; index
++)
768 ucol_setStrength(someCollators
[index
], UCOL_IDENTICAL
);
771 ucol_close(ucol_safeClone(someCollators
[index
], buffer
[index
], &bufferSize
, &err
));
772 if (err
!= U_SAFECLONE_ALLOCATED_WARNING
) {
773 log_err("FAIL: collator number %d was not allocated.\n", index
);
774 log_err("FAIL: status of Collator[%d] is %d (hex: %x).\n", index
, err
, err
);
777 bufferSize
= U_COL_SAFECLONE_BUFFERSIZE
;
779 someClonedCollators
[index
] = ucol_safeClone(someCollators
[index
], buffer
[index
], &bufferSize
, &err
);
780 if (someClonedCollators
[index
] == NULL
781 || someClonedCollators
[index
] < (UCollator
*)buffer
[index
]
782 || someClonedCollators
[index
] > (UCollator
*)(buffer
[index
]+(U_COL_SAFECLONE_BUFFERSIZE
-1)))
784 log_err("FAIL: Cloned collator didn't use provided buffer.\n");
787 if (!ucol_equals(someClonedCollators
[index
], someCollators
[index
])) {
788 log_err("FAIL: Cloned collator is not equal to original at index = %d.\n", index
);
791 /* Check the usability */
792 ucol_setStrength(someCollators
[index
], UCOL_PRIMARY
);
793 ucol_setAttribute(someCollators
[index
], UCOL_CASE_LEVEL
, UCOL_OFF
, &err
);
795 doAssert( (ucol_equal(someCollators
[index
], test1
, u_strlen(test1
), test2
, u_strlen(test2
))), "Result should be \"abcda\" == \"abCda\"");
797 /* Close the original to make sure that the clone is usable. */
798 ucol_close(someCollators
[index
]);
800 ucol_setStrength(someClonedCollators
[index
], UCOL_TERTIARY
);
801 ucol_setAttribute(someClonedCollators
[index
], UCOL_CASE_LEVEL
, UCOL_OFF
, &err
);
802 doAssert( (ucol_greater(someClonedCollators
[index
], test1
, u_strlen(test1
), test2
, u_strlen(test2
))), "Result should be \"abCda\" >>> \"abcda\" ");
804 ucol_close(someClonedCollators
[index
]);
808 void TestCloneBinary(){
809 UErrorCode err
= U_ZERO_ERROR
;
810 UCollator
* col
= ucol_open("en_US", &err
);
815 if (U_FAILURE(err
)) {
816 log_data_err("Couldn't open collator. Error: %s\n", u_errorName(err
));
820 size
= ucol_cloneBinary(col
, NULL
, 0, &err
);
821 if(size
==0 || err
!=U_BUFFER_OVERFLOW_ERROR
) {
822 log_err("ucol_cloneBinary - couldn't check size. Error: %s\n", u_errorName(err
));
827 buffer
= (uint8_t *) malloc(size
);
828 ucol_cloneBinary(col
, buffer
, size
, &err
);
830 log_err("ucol_cloneBinary - couldn't clone.. Error: %s\n", u_errorName(err
));
835 /* how to check binary result ? */
837 c
= ucol_openBinary(buffer
, size
, col
, &err
);
839 log_err("ucol_openBinary failed. Error: %s\n", u_errorName(err
));
841 UChar t
[] = {0x41, 0x42, 0x43, 0}; /* ABC */
844 l1
= ucol_getSortKey(col
, t
, -1, NULL
,0);
845 l2
= ucol_getSortKey(c
, t
, -1, NULL
,0);
846 k1
= (uint8_t *) malloc(sizeof(uint8_t) * l1
);
847 k2
= (uint8_t *) malloc(sizeof(uint8_t) * l2
);
848 ucol_getSortKey(col
, t
, -1, k1
, l1
);
849 ucol_getSortKey(col
, t
, -1, k2
, l2
);
850 if (strcmp((char *)k1
,(char *)k2
) != 0){
851 log_err("ucol_openBinary - new collator should equal to old one\n");
861 ----------------------------------------------------------------------------
862 ctor -- Tests the getSortKey
866 uint8_t *sortk1
= NULL
, *sortk2
= NULL
, *sortk3
= NULL
, *sortkEmpty
= NULL
;
867 uint8_t sortk2_compat
[] = {
868 /* 3.9 key, from UCA 5.1 */
869 0x2c, 0x2e, 0x30, 0x32, 0x2c, 0x01,
870 0x09, 0x01, 0x09, 0x01, 0x2b, 0x01,
871 0x92, 0x93, 0x94, 0x95, 0x92, 0x0
873 /* 3.6 key, from UCA 5.0 */
875 0x29, 0x2b, 0x2d, 0x2f, 0x29, 0x01,
876 0x09, 0x01, 0x09, 0x01, 0x28, 0x01,
877 0x92, 0x93, 0x94, 0x95, 0x92, 0x00
879 /* 3.4 key, from UCA 4.1 */
880 /* 0x28, 0x2a, 0x2c, 0x2e, 0x28, 0x01, 0x09, 0x01, 0x09, 0x01, 0x27, 0x01, 0x92, 0x93, 0x94, 0x95, 0x92, 0x00 */
882 /* 0x26, 0x28, 0x2A, 0x2C, 0x26, 0x01, 0x09, 0x01, 0x09, 0x01, 0x25, 0x01, 0x92, 0x93, 0x94, 0x95, 0x92, 0x00 */
884 /*0x1D, 0x1F, 0x21, 0x23, 0x1D, 0x01, 0x09, 0x01, 0x09, 0x01, 0x1C, 0x01, 0x92, 0x93, 0x94, 0x95, 0x92, 0x00*/
886 /*0x19, 0x1B, 0x1D, 0x1F, 0x19, 0x01, 0x09, 0x01, 0x09, 0x01, 0x18, 0x01, 0x92, 0x93, 0x94, 0x95, 0x92, 0x00*/
888 /*0x19, 0x1B, 0x1D, 0x1F, 0x19, 0x01, 0x0A, 0x01, 0x0A, 0x01, 0x92, 0x93, 0x94, 0x95, 0x92, 0x00*/
889 /*this is a 1.8 sortkey */
890 /*0x17, 0x19, 0x1B, 0x1D, 0x17, 0x01, 0x08, 0x01, 0x08, 0x00*/
891 /*this is a 1.7 sortkey */
892 /*0x02, 0x54, 0x02, 0x55, 0x02, 0x56, 0x02, 0x57, 0x02, 0x54, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00*/
893 /* this is a 1.6 sortkey */
894 /*0x00, 0x53, 0x00, 0x54, 0x00, 0x55, 0x00, 0x56, 0x00, 0x53, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00*/
897 int32_t sortklen
, osortklen
;
898 uint32_t toStringLen
=0;
900 UChar
*test1
, *test2
, *test3
;
901 UErrorCode status
= U_ZERO_ERROR
;
902 char toStringBuffer
[256], *resultP
;
905 uint8_t s1
[] = { 0x9f, 0x00 };
906 uint8_t s2
[] = { 0x61, 0x00 };
909 strcmpResult
= strcmp((const char *)s1
, (const char *)s2
);
910 log_verbose("strcmp(0x9f..., 0x61...) = %d\n", strcmpResult
);
912 if(strcmpResult
<= 0) {
913 log_err("ERR: expected strcmp(\"9f 00\", \"61 00\") to be >=0 (GREATER).. got %d. Calling strcmp() for sortkeys may not work! \n",
918 log_verbose("testing SortKey begins...\n");
919 /* this is supposed to open default date format, but later on it treats it like it is "en_US"
920 - very bad if you try to run the tests on machine where default locale is NOT "en_US" */
921 /* col = ucol_open(NULL, &status); */
922 col
= ucol_open("en_US", &status
);
923 if (U_FAILURE(status
)) {
924 log_err("ERROR: Default collation creation failed.: %s\n", myErrorName(status
));
929 if(ucol_getStrength(col
) != UCOL_DEFAULT_STRENGTH
)
931 log_err("ERROR: default collation did not have UCOL_DEFAULT_STRENGTH !\n");
933 /* Need to use identical strength */
934 ucol_setAttribute(col
, UCOL_STRENGTH
, UCOL_IDENTICAL
, &status
);
936 test1
=(UChar
*)malloc(sizeof(UChar
) * 6);
937 test2
=(UChar
*)malloc(sizeof(UChar
) * 6);
938 test3
=(UChar
*)malloc(sizeof(UChar
) * 6);
940 memset(test1
,0xFE, sizeof(UChar
)*6);
941 memset(test2
,0xFE, sizeof(UChar
)*6);
942 memset(test3
,0xFE, sizeof(UChar
)*6);
945 u_uastrcpy(test1
, "Abcda");
946 u_uastrcpy(test2
, "abcda");
947 u_uastrcpy(test3
, "abcda");
949 log_verbose("Use tertiary comparison level testing ....\n");
951 sortklen
=ucol_getSortKey(col
, test1
, u_strlen(test1
), NULL
, 0);
952 sortk1
=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen
+1));
953 memset(sortk1
,0xFE, sortklen
);
954 ucol_getSortKey(col
, test1
, u_strlen(test1
), sortk1
, sortklen
+1);
956 sortklen
=ucol_getSortKey(col
, test2
, u_strlen(test2
), NULL
, 0);
957 sortk2
=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen
+1));
958 memset(sortk2
,0xFE, sortklen
);
959 ucol_getSortKey(col
, test2
, u_strlen(test2
), sortk2
, sortklen
+1);
961 osortklen
= sortklen
;
962 sortklen
=ucol_getSortKey(col
, test2
, u_strlen(test3
), NULL
, 0);
963 sortk3
=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen
+1));
964 memset(sortk3
,0xFE, sortklen
);
965 ucol_getSortKey(col
, test2
, u_strlen(test2
), sortk3
, sortklen
+1);
967 doAssert( (sortklen
== osortklen
), "Sortkey length should be the same (abcda, abcda)");
969 doAssert( (memcmp(sortk1
, sortk2
, sortklen
) > 0), "Result should be \"Abcda\" > \"abcda\"");
970 doAssert( (memcmp(sortk2
, sortk1
, sortklen
) < 0), "Result should be \"abcda\" < \"Abcda\"");
971 doAssert( (memcmp(sortk2
, sortk3
, sortklen
) == 0), "Result should be \"abcda\" == \"abcda\"");
973 doAssert( (memcmp(sortk2
, sortk2_compat
, sortklen
) == 0), "Binary format for 'abcda' sortkey different!");
975 resultP
= ucol_sortKeyToString(col
, sortk2_compat
, toStringBuffer
, &toStringLen
);
976 doAssert( (resultP
!= 0), "sortKeyToString failed!");
978 #if 1 /* verobse log of sortkeys */
984 strcpy(junk2
, "abcda[2] ");
985 strcpy(junk3
, " abcda[3] ");
987 for(i
=0;i
<sortklen
;i
++)
989 sprintf(junk2
+strlen(junk2
), "%02X ",(int)( 0xFF & sortk2
[i
]));
990 sprintf(junk3
+strlen(junk3
), "%02X ",(int)( 0xFF & sortk3
[i
]));
993 log_verbose("%s\n", junk2
);
994 log_verbose("%s\n", junk3
);
1002 log_verbose("Use secondary comparision level testing ...\n");
1003 ucol_setStrength(col
, UCOL_SECONDARY
);
1004 sortklen
=ucol_getSortKey(col
, test1
, u_strlen(test1
), NULL
, 0);
1005 sortk1
=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen
+1));
1006 ucol_getSortKey(col
, test1
, u_strlen(test1
), sortk1
, sortklen
+1);
1007 sortklen
=ucol_getSortKey(col
, test2
, u_strlen(test2
), NULL
, 0);
1008 sortk2
=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen
+1));
1009 ucol_getSortKey(col
, test2
, u_strlen(test2
), sortk2
, sortklen
+1);
1011 doAssert( !(memcmp(sortk1
, sortk2
, sortklen
) > 0), "Result should be \"Abcda\" == \"abcda\"");
1012 doAssert( !(memcmp(sortk2
, sortk1
, sortklen
) < 0), "Result should be \"abcda\" == \"Abcda\"");
1013 doAssert( (memcmp(sortk1
, sortk2
, sortklen
) == 0), "Result should be \"abcda\" == \"abcda\"");
1015 log_verbose("getting sortkey for an empty string\n");
1016 ucol_setAttribute(col
, UCOL_STRENGTH
, UCOL_TERTIARY
, &status
);
1017 sortklen
= ucol_getSortKey(col
, test1
, 0, NULL
, 0);
1018 sortkEmpty
= (uint8_t*)malloc(sizeof(uint8_t) * sortklen
+1);
1019 sortklen
= ucol_getSortKey(col
, test1
, 0, sortkEmpty
, sortklen
+1);
1020 if(sortklen
!= 3 || sortkEmpty
[0] != 1 || sortkEmpty
[0] != 1 || sortkEmpty
[2] != 0) {
1021 log_err("Empty string generated wrong sortkey!\n");
1025 log_verbose("testing passing invalid string\n");
1026 sortklen
= ucol_getSortKey(col
, NULL
, 0, NULL
, 0);
1028 log_err("Invalid string didn't return sortkey size of 0\n");
1032 log_verbose("testing sortkey ends...\n");
1043 uint8_t *sortk1
, *sortk2
, *sortk3
;
1044 int32_t sortk1len
, sortk2len
, sortk3len
;
1046 UChar
*test1
, *test2
, *test3
;
1047 UErrorCode status
= U_ZERO_ERROR
;
1048 log_verbose("testing getHashCode begins...\n");
1049 col
= ucol_open("en_US", &status
);
1050 if (U_FAILURE(status
)) {
1051 log_err("ERROR: Default collation creation failed.: %s\n", myErrorName(status
));
1054 test1
=(UChar
*)malloc(sizeof(UChar
) * 6);
1055 test2
=(UChar
*)malloc(sizeof(UChar
) * 6);
1056 test3
=(UChar
*)malloc(sizeof(UChar
) * 6);
1057 u_uastrcpy(test1
, "Abcda");
1058 u_uastrcpy(test2
, "abcda");
1059 u_uastrcpy(test3
, "abcda");
1061 log_verbose("Use tertiary comparison level testing ....\n");
1062 sortk1len
=ucol_getSortKey(col
, test1
, u_strlen(test1
), NULL
, 0);
1063 sortk1
=(uint8_t*)malloc(sizeof(uint8_t) * (sortk1len
+1));
1064 ucol_getSortKey(col
, test1
, u_strlen(test1
), sortk1
, sortk1len
+1);
1065 sortk2len
=ucol_getSortKey(col
, test2
, u_strlen(test2
), NULL
, 0);
1066 sortk2
=(uint8_t*)malloc(sizeof(uint8_t) * (sortk2len
+1));
1067 ucol_getSortKey(col
, test2
, u_strlen(test2
), sortk2
, sortk2len
+1);
1068 sortk3len
=ucol_getSortKey(col
, test2
, u_strlen(test3
), NULL
, 0);
1069 sortk3
=(uint8_t*)malloc(sizeof(uint8_t) * (sortk3len
+1));
1070 ucol_getSortKey(col
, test2
, u_strlen(test2
), sortk3
, sortk3len
+1);
1073 log_verbose("ucol_hashCode() testing ...\n");
1075 doAssert( ucol_keyHashCode(sortk1
, sortk1len
) != ucol_keyHashCode(sortk2
, sortk2len
), "Hash test1 result incorrect" );
1076 doAssert( !(ucol_keyHashCode(sortk1
, sortk1len
) == ucol_keyHashCode(sortk2
, sortk2len
)), "Hash test2 result incorrect" );
1077 doAssert( ucol_keyHashCode(sortk2
, sortk2len
) == ucol_keyHashCode(sortk3
, sortk3len
), "Hash result not equal" );
1079 log_verbose("hashCode tests end.\n");
1091 *----------------------------------------------------------------------------
1092 * Tests the UCollatorElements API.
1098 int32_t order1
, order2
, order3
;
1099 UChar
*testString1
, *testString2
;
1101 UCollationElements
*iterator1
, *iterator2
, *iterator3
;
1102 UErrorCode status
= U_ZERO_ERROR
;
1103 log_verbose("testing UCollatorElements begins...\n");
1104 col
= ucol_open("en_US", &status
);
1105 ucol_setAttribute(col
, UCOL_NORMALIZATION_MODE
, UCOL_OFF
, &status
);
1106 if (U_FAILURE(status
)) {
1107 log_err("ERROR: Default collation creation failed.: %s\n", myErrorName(status
));
1111 testString1
=(UChar
*)malloc(sizeof(UChar
) * 150);
1112 testString2
=(UChar
*)malloc(sizeof(UChar
) * 150);
1113 u_uastrcpy(testString1
, "XFILE What subset of all possible test cases has the highest probability of detecting the most errors?");
1114 u_uastrcpy(testString2
, "Xf_ile What subset of all possible test cases has the lowest probability of detecting the least errors?");
1116 log_verbose("Constructors and comparison testing....\n");
1118 iterator1
= ucol_openElements(col
, testString1
, u_strlen(testString1
), &status
);
1119 if(U_FAILURE(status
)) {
1120 log_err("ERROR: Default collationElement iterator creation failed.: %s\n", myErrorName(status
));
1124 else{ log_verbose("PASS: Default collationElement iterator1 creation passed\n");}
1126 iterator2
= ucol_openElements(col
, testString1
, u_strlen(testString1
), &status
);
1127 if(U_FAILURE(status
)) {
1128 log_err("ERROR: Default collationElement iterator creation failed.: %s\n", myErrorName(status
));
1132 else{ log_verbose("PASS: Default collationElement iterator2 creation passed\n");}
1134 iterator3
= ucol_openElements(col
, testString2
, u_strlen(testString2
), &status
);
1135 if(U_FAILURE(status
)) {
1136 log_err("ERROR: Default collationElement iterator creation failed.: %s\n", myErrorName(status
));
1140 else{ log_verbose("PASS: Default collationElement iterator3 creation passed\n");}
1142 offset
=ucol_getOffset(iterator1
);
1143 ucol_setOffset(iterator1
, 6, &status
);
1144 if (U_FAILURE(status
)) {
1145 log_err("Error in setOffset for UCollatorElements iterator.: %s\n", myErrorName(status
));
1148 if(ucol_getOffset(iterator1
)==6)
1149 log_verbose("setOffset and getOffset working fine\n");
1151 log_err("error in set and get Offset got %d instead of 6\n", ucol_getOffset(iterator1
));
1154 ucol_setOffset(iterator1
, 0, &status
);
1155 order1
= ucol_next(iterator1
, &status
);
1156 if (U_FAILURE(status
)) {
1157 log_err("Somehow ran out of memory stepping through the iterator1.: %s\n", myErrorName(status
));
1160 order2
=ucol_getOffset(iterator2
);
1161 doAssert((order1
!= order2
), "The first iterator advance failed");
1162 order2
= ucol_next(iterator2
, &status
);
1163 if (U_FAILURE(status
)) {
1164 log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status
));
1167 order3
= ucol_next(iterator3
, &status
);
1168 if (U_FAILURE(status
)) {
1169 log_err("Somehow ran out of memory stepping through the iterator3.: %s\n", myErrorName(status
));
1173 doAssert((order1
== order2
), "The second iterator advance failed should be the same as first one");
1175 doAssert( (ucol_primaryOrder(order1
) == ucol_primaryOrder(order3
)), "The primary orders should be identical");
1176 doAssert( (ucol_secondaryOrder(order1
) == ucol_secondaryOrder(order3
)), "The secondary orders should be identical");
1177 doAssert( (ucol_tertiaryOrder(order1
) == ucol_tertiaryOrder(order3
)), "The tertiary orders should be identical");
1179 order1
=ucol_next(iterator1
, &status
);
1180 if (U_FAILURE(status
)) {
1181 log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status
));
1184 order3
=ucol_next(iterator3
, &status
);
1185 if (U_FAILURE(status
)) {
1186 log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status
));
1189 doAssert( (ucol_primaryOrder(order1
) == ucol_primaryOrder(order3
)), "The primary orders should be identical");
1190 doAssert( (ucol_tertiaryOrder(order1
) != ucol_tertiaryOrder(order3
)), "The tertiary orders should be different");
1192 order1
=ucol_next(iterator1
, &status
);
1193 if (U_FAILURE(status
)) {
1194 log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status
));
1197 order3
=ucol_next(iterator3
, &status
);
1198 if (U_FAILURE(status
)) {
1199 log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status
));
1202 /* this here, my friends, is either pure lunacy or something so obsolete that even it's mother
1203 * doesn't care about it. Essentialy, this test complains if secondary values for 'I' and '_'
1204 * are the same. According to the UCA, this is not true. Therefore, remove the test.
1205 * Besides, if primary strengths for two code points are different, it doesn't matter one bit
1206 * what is the relation between secondary or any other strengths.
1207 * killed by weiv 06/11/2002.
1210 doAssert( ((order1 & UCOL_SECONDARYMASK) != (order3 & UCOL_SECONDARYMASK)), "The secondary orders should be different");
1212 doAssert( (order1
!= UCOL_NULLORDER
), "Unexpected end of iterator reached");
1216 ucol_closeElements(iterator1
);
1217 ucol_closeElements(iterator2
);
1218 ucol_closeElements(iterator3
);
1221 log_verbose("testing CollationElementIterator ends...\n");
1224 void TestGetLocale() {
1225 UErrorCode status
= U_ZERO_ERROR
;
1226 const char *rules
= "&a<x<y<z";
1227 UChar rlz
[256] = {0};
1228 uint32_t rlzLen
= u_unescape(rules
, rlz
, 256);
1230 UCollator
*coll
= NULL
;
1231 const char *locale
= NULL
;
1235 /* Now that the collation tree is separate, actual==valid at all times. [alan] */
1236 static const struct {
1237 const char* requestedLocale
;
1238 const char* validLocale
;
1239 const char* actualLocale
;
1241 { "sr_RS", "sr_Cyrl_RS", "ru" },
1242 { "sh_YU", "sr_Latn_RS", "hr" }, /* this used to be sh, but now sh collation aliases hr */
1243 { "en_BE_FOO", "en_BE", "en_BE" },
1244 { "fr_FR_NONEXISTANT", "fr_FR", "fr" }
1247 /* test opening collators for different locales */
1248 for(i
= 0; i
<sizeof(testStruct
)/sizeof(testStruct
[0]); i
++) {
1249 status
= U_ZERO_ERROR
;
1250 coll
= ucol_open(testStruct
[i
].requestedLocale
, &status
);
1251 if(U_FAILURE(status
)) {
1252 log_err("Failed to open collator for %s with %s\n", testStruct
[i
].requestedLocale
, u_errorName(status
));
1256 locale
= ucol_getLocale(coll
, ULOC_REQUESTED_LOCALE
, &status
);
1257 if(strcmp(locale
, testStruct
[i
].requestedLocale
) != 0) {
1258 log_err("[Coll %s]: Error in requested locale, expected %s, got %s\n", testStruct
[i
].requestedLocale
, testStruct
[i
].requestedLocale
, locale
);
1260 locale
= ucol_getLocale(coll
, ULOC_VALID_LOCALE
, &status
);
1261 if(strcmp(locale
, testStruct
[i
].validLocale
) != 0) {
1262 log_err("[Coll %s]: Error in valid locale, expected %s, got %s\n", testStruct
[i
].requestedLocale
, testStruct
[i
].validLocale
, locale
);
1264 locale
= ucol_getLocale(coll
, ULOC_ACTUAL_LOCALE
, &status
);
1265 if(strcmp(locale
, testStruct
[i
].actualLocale
) != 0) {
1266 log_err("[Coll %s]: Error in actual locale, expected %s, got %s\n", testStruct
[i
].requestedLocale
, testStruct
[i
].actualLocale
, locale
);
1271 /* completely non-existant locale for collator should get a default collator */
1273 UCollator
*defaultColl
= ucol_open(NULL
, &status
);
1274 coll
= ucol_open("blahaha", &status
);
1275 if(U_SUCCESS(status
)) {
1276 if(strcmp(ucol_getLocale(coll
, ULOC_REQUESTED_LOCALE
, &status
), "blahaha")) {
1277 log_err("Nonexisting locale didn't preserve the requested locale\n");
1279 if(strcmp(ucol_getLocale(coll
, ULOC_VALID_LOCALE
, &status
),
1280 ucol_getLocale(defaultColl
, ULOC_VALID_LOCALE
, &status
))) {
1281 log_err("Valid locale for nonexisting locale locale collator differs "
1282 "from valid locale for default collator\n");
1284 if(strcmp(ucol_getLocale(coll
, ULOC_ACTUAL_LOCALE
, &status
),
1285 ucol_getLocale(defaultColl
, ULOC_ACTUAL_LOCALE
, &status
))) {
1286 log_err("Actual locale for nonexisting locale locale collator differs "
1287 "from actual locale for default collator\n");
1290 ucol_close(defaultColl
);
1292 log_data_err("Couldn't open collators\n");
1298 /* collator instantiated from rules should have all three locales NULL */
1299 coll
= ucol_openRules(rlz
, rlzLen
, UCOL_DEFAULT
, UCOL_DEFAULT
, NULL
, &status
);
1300 locale
= ucol_getLocale(coll
, ULOC_REQUESTED_LOCALE
, &status
);
1301 if(locale
!= NULL
) {
1302 log_err("For collator instantiated from rules, requested locale returned %s instead of NULL\n", locale
);
1304 locale
= ucol_getLocale(coll
, ULOC_VALID_LOCALE
, &status
);
1305 if(locale
!= NULL
) {
1306 log_err("For collator instantiated from rules, valid locale returned %s instead of NULL\n", locale
);
1308 locale
= ucol_getLocale(coll
, ULOC_ACTUAL_LOCALE
, &status
);
1309 if(locale
!= NULL
) {
1310 log_err("For collator instantiated from rules, actual locale returned %s instead of NULL\n", locale
);
1320 count
=ucol_countAvailable();
1321 /* use something sensible w/o hardcoding the count */
1323 log_err("Error in countAvailable(), it returned %d\n", count
);
1326 log_verbose("PASS: countAvailable() successful, it returned %d\n", count
);
1328 for(i
=0;i
<count
;i
++)
1329 log_verbose("%s\n", ucol_getAvailable(i
));
1336 const char *original
;
1340 static int compare_teststruct(const void *string1
, const void *string2
) {
1341 return(strcmp((const char *)((struct teststruct
*)string1
)->key
, (const char *)((struct teststruct
*)string2
)->key
));
1345 UErrorCode status
= U_ZERO_ERROR
;
1347 UCollator
*coll
= ucol_open("sh", &status
);
1349 uint8_t sortkey
[512], lower
[512], upper
[512];
1352 static const char * const test
[] = {
1356 "j\\u00F6hn sm\\u00EFth",
1357 "J\\u00F6hn Sm\\u00EFth",
1358 "J\\u00D6HN SM\\u00CFTH",
1363 struct teststruct tests
[] = {
1364 {"\\u010CAKI MIHALJ" } ,
1365 {"\\u010CAKI MIHALJ" } ,
1366 {"\\u010CAKI PIRO\\u0160KA" },
1367 {"\\u010CABAI ANDRIJA" } ,
1368 {"\\u010CABAI LAJO\\u0160" } ,
1369 {"\\u010CABAI MARIJA" } ,
1370 {"\\u010CABAI STEVAN" } ,
1371 {"\\u010CABAI STEVAN" } ,
1372 {"\\u010CABARKAPA BRANKO" } ,
1373 {"\\u010CABARKAPA MILENKO" } ,
1374 {"\\u010CABARKAPA MIROSLAV" } ,
1375 {"\\u010CABARKAPA SIMO" } ,
1376 {"\\u010CABARKAPA STANKO" } ,
1377 {"\\u010CABARKAPA TAMARA" } ,
1378 {"\\u010CABARKAPA TOMA\\u0160" } ,
1379 {"\\u010CABDARI\\u0106 NIKOLA" } ,
1380 {"\\u010CABDARI\\u0106 ZORICA" } ,
1381 {"\\u010CABI NANDOR" } ,
1382 {"\\u010CABOVI\\u0106 MILAN" } ,
1383 {"\\u010CABRADI AGNEZIJA" } ,
1384 {"\\u010CABRADI IVAN" } ,
1385 {"\\u010CABRADI JELENA" } ,
1386 {"\\u010CABRADI LJUBICA" } ,
1387 {"\\u010CABRADI STEVAN" } ,
1388 {"\\u010CABRDA MARTIN" } ,
1389 {"\\u010CABRILO BOGDAN" } ,
1390 {"\\u010CABRILO BRANISLAV" } ,
1391 {"\\u010CABRILO LAZAR" } ,
1392 {"\\u010CABRILO LJUBICA" } ,
1393 {"\\u010CABRILO SPASOJA" } ,
1394 {"\\u010CADE\\u0160 ZDENKA" } ,
1395 {"\\u010CADESKI BLAGOJE" } ,
1396 {"\\u010CADOVSKI VLADIMIR" } ,
1397 {"\\u010CAGLJEVI\\u0106 TOMA" } ,
1398 {"\\u010CAGOROVI\\u0106 VLADIMIR" } ,
1399 {"\\u010CAJA VANKA" } ,
1400 {"\\u010CAJI\\u0106 BOGOLJUB" } ,
1401 {"\\u010CAJI\\u0106 BORISLAV" } ,
1402 {"\\u010CAJI\\u0106 RADOSLAV" } ,
1403 {"\\u010CAK\\u0160IRAN MILADIN" } ,
1404 {"\\u010CAKAN EUGEN" } ,
1405 {"\\u010CAKAN EVGENIJE" } ,
1406 {"\\u010CAKAN IVAN" } ,
1407 {"\\u010CAKAN JULIJAN" } ,
1408 {"\\u010CAKAN MIHAJLO" } ,
1409 {"\\u010CAKAN STEVAN" } ,
1410 {"\\u010CAKAN VLADIMIR" } ,
1411 {"\\u010CAKAN VLADIMIR" } ,
1412 {"\\u010CAKAN VLADIMIR" } ,
1413 {"\\u010CAKARA ANA" } ,
1414 {"\\u010CAKAREVI\\u0106 MOMIR" } ,
1415 {"\\u010CAKAREVI\\u0106 NEDELJKO" } ,
1416 {"\\u010CAKI \\u0160ANDOR" } ,
1417 {"\\u010CAKI AMALIJA" } ,
1418 {"\\u010CAKI ANDRA\\u0160" } ,
1419 {"\\u010CAKI LADISLAV" } ,
1420 {"\\u010CAKI LAJO\\u0160" } ,
1421 {"\\u010CAKI LASLO" } ,
1426 int32_t i
= 0, j
= 0, k
= 0, buffSize
= 0, skSize
= 0, lowerSize
= 0, upperSize
= 0;
1427 int32_t arraySize
= sizeof(tests
)/sizeof(tests
[0]);
1429 if(U_SUCCESS(status
) && coll
) {
1430 for(i
= 0; i
<arraySize
; i
++) {
1431 buffSize
= u_unescape(tests
[i
].original
, buffer
, 512);
1432 skSize
= ucol_getSortKey(coll
, buffer
, buffSize
, tests
[i
].key
, 512);
1435 qsort(tests
, arraySize
, sizeof(struct teststruct
), compare_teststruct
);
1437 for(i
= 0; i
< arraySize
-1; i
++) {
1438 for(j
= i
+1; j
< arraySize
; j
++) {
1439 lowerSize
= ucol_getBound(tests
[i
].key
, -1, UCOL_BOUND_LOWER
, 1, lower
, 512, &status
);
1440 upperSize
= ucol_getBound(tests
[j
].key
, -1, UCOL_BOUND_UPPER
, 1, upper
, 512, &status
);
1441 for(k
= i
; k
<= j
; k
++) {
1442 if(strcmp((const char *)lower
, (const char *)tests
[k
].key
) > 0) {
1443 log_err("Problem with lower! j = %i (%s vs %s)\n", k
, tests
[k
].original
, tests
[i
].original
);
1445 if(strcmp((const char *)upper
, (const char *)tests
[k
].key
) <= 0) {
1446 log_err("Problem with upper! j = %i (%s vs %s)\n", k
, tests
[k
].original
, tests
[j
].original
);
1454 for(i
= 0; i
< 1000; i
++) {
1455 lowerRND
= (rand()/(RAND_MAX
/arraySize
));
1456 upperRND
= lowerRND
+ (rand()/(RAND_MAX
/(arraySize
-lowerRND
)));
1458 lowerSize
= ucol_getBound(tests
[lowerRND
].key
, -1, UCOL_BOUND_LOWER
, 1, lower
, 512, &status
);
1459 upperSize
= ucol_getBound(tests
[upperRND
].key
, -1, UCOL_BOUND_UPPER_LONG
, 1, upper
, 512, &status
);
1461 for(j
= lowerRND
; j
<=upperRND
; j
++) {
1462 if(strcmp(lower
, tests
[j
].key
) > 0) {
1463 log_err("Problem with lower! j = %i (%s vs %s)\n", j
, tests
[j
].original
, tests
[lowerRND
].original
);
1465 if(strcmp(upper
, tests
[j
].key
) <= 0) {
1466 log_err("Problem with upper! j = %i (%s vs %s)\n", j
, tests
[j
].original
, tests
[upperRND
].original
);
1476 for(i
= 0; i
<sizeof(test
)/sizeof(test
[0]); i
++) {
1477 buffSize
= u_unescape(test
[i
], buffer
, 512);
1478 skSize
= ucol_getSortKey(coll
, buffer
, buffSize
, sortkey
, 512);
1479 lowerSize
= ucol_getBound(sortkey
, skSize
, UCOL_BOUND_LOWER
, 1, lower
, 512, &status
);
1480 upperSize
= ucol_getBound(sortkey
, skSize
, UCOL_BOUND_UPPER_LONG
, 1, upper
, 512, &status
);
1481 for(j
= i
+1; j
<sizeof(test
)/sizeof(test
[0]); j
++) {
1482 buffSize
= u_unescape(test
[j
], buffer
, 512);
1483 skSize
= ucol_getSortKey(coll
, buffer
, buffSize
, sortkey
, 512);
1484 if(strcmp((const char *)lower
, (const char *)sortkey
) > 0) {
1485 log_err("Problem with lower! i = %i, j = %i (%s vs %s)\n", i
, j
, test
[i
], test
[j
]);
1487 if(strcmp((const char *)upper
, (const char *)sortkey
) <= 0) {
1488 log_err("Problem with upper! i = %i, j = %i (%s vs %s)\n", i
, j
, test
[i
], test
[j
]);
1494 log_data_err("Couldn't open collator\n");
1499 static void doOverrunTest(UCollator
*coll
, const UChar
*uString
, int32_t strLen
) {
1500 int32_t skLen
= 0, skLen2
= 0;
1501 uint8_t sortKey
[256];
1503 uint8_t filler
= 0xFF;
1505 skLen
= ucol_getSortKey(coll
, uString
, strLen
, NULL
, 0);
1507 for(i
= 0; i
< skLen
; i
++) {
1508 memset(sortKey
, filler
, 256);
1509 skLen2
= ucol_getSortKey(coll
, uString
, strLen
, sortKey
, i
);
1510 if(skLen
!= skLen2
) {
1511 log_err("For buffer size %i, got different sortkey length. Expected %i got %i\n", i
, skLen
, skLen2
);
1513 for(j
= i
; j
< 256; j
++) {
1514 if(sortKey
[j
] != filler
) {
1515 log_err("Something run over index %i\n", j
);
1522 /* j1865 reports that if a shorter buffer is passed to
1523 * to get sort key, a buffer overrun happens in some
1524 * cases. This test tries to check this.
1526 void TestSortKeyBufferOverrun(void) {
1527 UErrorCode status
= U_ZERO_ERROR
;
1528 const char* cString
= "A very Merry liTTle-lamB..";
1531 UCollator
*coll
= ucol_open("root", &status
);
1532 strLen
= u_unescape(cString
, uString
, 256);
1534 if(U_SUCCESS(status
)) {
1535 log_verbose("testing non ignorable\n");
1536 ucol_setAttribute(coll
, UCOL_ALTERNATE_HANDLING
, UCOL_NON_IGNORABLE
, &status
);
1537 doOverrunTest(coll
, uString
, strLen
);
1539 log_verbose("testing shifted\n");
1540 ucol_setAttribute(coll
, UCOL_ALTERNATE_HANDLING
, UCOL_SHIFTED
, &status
);
1541 doOverrunTest(coll
, uString
, strLen
);
1543 log_verbose("testing shifted quaternary\n");
1544 ucol_setAttribute(coll
, UCOL_STRENGTH
, UCOL_QUATERNARY
, &status
);
1545 doOverrunTest(coll
, uString
, strLen
);
1547 log_verbose("testing with french secondaries\n");
1548 ucol_setAttribute(coll
, UCOL_FRENCH_COLLATION
, UCOL_ON
, &status
);
1549 ucol_setAttribute(coll
, UCOL_STRENGTH
, UCOL_TERTIARY
, &status
);
1550 ucol_setAttribute(coll
, UCOL_ALTERNATE_HANDLING
, UCOL_NON_IGNORABLE
, &status
);
1551 doOverrunTest(coll
, uString
, strLen
);
1557 static void TestAttribute()
1559 UErrorCode error
= U_ZERO_ERROR
;
1560 UCollator
*coll
= ucol_open(NULL
, &error
);
1562 if (U_FAILURE(error
)) {
1563 log_err("Creation of default collator failed");
1567 ucol_setAttribute(coll
, UCOL_FRENCH_COLLATION
, UCOL_OFF
, &error
);
1568 if (ucol_getAttribute(coll
, UCOL_FRENCH_COLLATION
, &error
) != UCOL_OFF
||
1570 log_err("Setting and retrieving of the french collation failed");
1573 ucol_setAttribute(coll
, UCOL_FRENCH_COLLATION
, UCOL_ON
, &error
);
1574 if (ucol_getAttribute(coll
, UCOL_FRENCH_COLLATION
, &error
) != UCOL_ON
||
1576 log_err("Setting and retrieving of the french collation failed");
1579 ucol_setAttribute(coll
, UCOL_ALTERNATE_HANDLING
, UCOL_SHIFTED
, &error
);
1580 if (ucol_getAttribute(coll
, UCOL_ALTERNATE_HANDLING
, &error
) != UCOL_SHIFTED
||
1582 log_err("Setting and retrieving of the alternate handling failed");
1585 ucol_setAttribute(coll
, UCOL_ALTERNATE_HANDLING
, UCOL_NON_IGNORABLE
, &error
);
1586 if (ucol_getAttribute(coll
, UCOL_ALTERNATE_HANDLING
, &error
) != UCOL_NON_IGNORABLE
||
1588 log_err("Setting and retrieving of the alternate handling failed");
1591 ucol_setAttribute(coll
, UCOL_CASE_FIRST
, UCOL_LOWER_FIRST
, &error
);
1592 if (ucol_getAttribute(coll
, UCOL_CASE_FIRST
, &error
) != UCOL_LOWER_FIRST
||
1594 log_err("Setting and retrieving of the case first attribute failed");
1597 ucol_setAttribute(coll
, UCOL_CASE_FIRST
, UCOL_UPPER_FIRST
, &error
);
1598 if (ucol_getAttribute(coll
, UCOL_CASE_FIRST
, &error
) != UCOL_UPPER_FIRST
||
1600 log_err("Setting and retrieving of the case first attribute failed");
1603 ucol_setAttribute(coll
, UCOL_CASE_LEVEL
, UCOL_ON
, &error
);
1604 if (ucol_getAttribute(coll
, UCOL_CASE_LEVEL
, &error
) != UCOL_ON
||
1606 log_err("Setting and retrieving of the case level attribute failed");
1609 ucol_setAttribute(coll
, UCOL_CASE_LEVEL
, UCOL_OFF
, &error
);
1610 if (ucol_getAttribute(coll
, UCOL_CASE_LEVEL
, &error
) != UCOL_OFF
||
1612 log_err("Setting and retrieving of the case level attribute failed");
1615 ucol_setAttribute(coll
, UCOL_NORMALIZATION_MODE
, UCOL_ON
, &error
);
1616 if (ucol_getAttribute(coll
, UCOL_NORMALIZATION_MODE
, &error
) != UCOL_ON
||
1618 log_err("Setting and retrieving of the normalization on/off attribute failed");
1621 ucol_setAttribute(coll
, UCOL_NORMALIZATION_MODE
, UCOL_OFF
, &error
);
1622 if (ucol_getAttribute(coll
, UCOL_NORMALIZATION_MODE
, &error
) != UCOL_OFF
||
1624 log_err("Setting and retrieving of the normalization on/off attribute failed");
1627 ucol_setAttribute(coll
, UCOL_STRENGTH
, UCOL_PRIMARY
, &error
);
1628 if (ucol_getAttribute(coll
, UCOL_STRENGTH
, &error
) != UCOL_PRIMARY
||
1630 log_err("Setting and retrieving of the collation strength failed");
1633 ucol_setAttribute(coll
, UCOL_STRENGTH
, UCOL_SECONDARY
, &error
);
1634 if (ucol_getAttribute(coll
, UCOL_STRENGTH
, &error
) != UCOL_SECONDARY
||
1636 log_err("Setting and retrieving of the collation strength failed");
1639 ucol_setAttribute(coll
, UCOL_STRENGTH
, UCOL_TERTIARY
, &error
);
1640 if (ucol_getAttribute(coll
, UCOL_STRENGTH
, &error
) != UCOL_TERTIARY
||
1642 log_err("Setting and retrieving of the collation strength failed");
1645 ucol_setAttribute(coll
, UCOL_STRENGTH
, UCOL_QUATERNARY
, &error
);
1646 if (ucol_getAttribute(coll
, UCOL_STRENGTH
, &error
) != UCOL_QUATERNARY
||
1648 log_err("Setting and retrieving of the collation strength failed");
1651 ucol_setAttribute(coll
, UCOL_STRENGTH
, UCOL_IDENTICAL
, &error
);
1652 if (ucol_getAttribute(coll
, UCOL_STRENGTH
, &error
) != UCOL_IDENTICAL
||
1654 log_err("Setting and retrieving of the collation strength failed");
1660 void TestGetTailoredSet() {
1663 const char *tests
[20];
1666 { "&a < \\u212b", { "\\u212b", "A\\u030a", "\\u00c5" }, 3},
1667 { "& S < \\u0161 <<< \\u0160", { "\\u0161", "s\\u030C", "\\u0160", "S\\u030C" }, 4}
1670 int32_t i
= 0, j
= 0;
1671 UErrorCode status
= U_ZERO_ERROR
;
1674 UCollator
*coll
= NULL
;
1676 int32_t buffLen
= 0;
1679 for(i
= 0; i
< sizeof(setTest
)/sizeof(setTest
[0]); i
++) {
1680 buffLen
= u_unescape(setTest
[i
].rules
, buff
, 1024);
1681 coll
= ucol_openRules(buff
, buffLen
, UCOL_DEFAULT
, UCOL_DEFAULT
, &pError
, &status
);
1682 if(U_SUCCESS(status
)) {
1683 set
= ucol_getTailoredSet(coll
, &status
);
1684 if(uset_size(set
) != setTest
[i
].testsize
) {
1685 log_err("Tailored set size different (%d) than expected (%d)\n", uset_size(set
), setTest
[i
].testsize
);
1687 for(j
= 0; j
< setTest
[i
].testsize
; j
++) {
1688 buffLen
= u_unescape(setTest
[i
].tests
[j
], buff
, 1024);
1689 if(!uset_containsString(set
, buff
, buffLen
)) {
1690 log_err("Tailored set doesn't contain %s... It should\n", setTest
[i
].tests
[j
]);
1695 log_err("Couldn't open collator with rules %s\n", setTest
[i
].rules
);
1701 static int tMemCmp(const uint8_t *first
, const uint8_t *second
) {
1702 int32_t firstLen
= (int32_t)strlen((const char *)first
);
1703 int32_t secondLen
= (int32_t)strlen((const char *)second
);
1704 return memcmp(first
, second
, uprv_min(firstLen
, secondLen
));
1706 static const char * strengthsC
[] = {
1714 void TestMergeSortKeys(void) {
1715 UErrorCode status
= U_ZERO_ERROR
;
1716 UCollator
*coll
= ucol_open("en", &status
);
1717 if(U_SUCCESS(status
)) {
1719 const char* cases
[] = {
1724 uint32_t casesSize
= sizeof(cases
)/sizeof(cases
[0]);
1725 const char* prefix
= "foo";
1726 const char* suffix
= "egg";
1727 char outBuff1
[256], outBuff2
[256];
1729 uint8_t **sortkeys
= (uint8_t **)malloc(casesSize
*sizeof(uint8_t *));
1730 uint8_t **mergedPrefixkeys
= (uint8_t **)malloc(casesSize
*sizeof(uint8_t *));
1731 uint8_t **mergedSuffixkeys
= (uint8_t **)malloc(casesSize
*sizeof(uint8_t *));
1732 uint32_t *sortKeysLen
= (uint32_t *)malloc(casesSize
*sizeof(uint32_t));
1733 uint8_t prefixKey
[256], suffixKey
[256];
1734 uint32_t prefixKeyLen
= 0, suffixKeyLen
= 0, i
= 0;
1736 uint32_t unescapedLen
= 0, l1
= 0, l2
= 0;
1737 UColAttributeValue strength
;
1739 log_verbose("ucol_mergeSortkeys test\n");
1740 log_verbose("Testing order of the test cases\n");
1741 genericLocaleStarter("en", cases
, casesSize
);
1743 for(i
= 0; i
<casesSize
; i
++) {
1744 sortkeys
[i
] = (uint8_t *)malloc(256*sizeof(uint8_t));
1745 mergedPrefixkeys
[i
] = (uint8_t *)malloc(256*sizeof(uint8_t));
1746 mergedSuffixkeys
[i
] = (uint8_t *)malloc(256*sizeof(uint8_t));
1749 unescapedLen
= u_unescape(prefix
, buffer
, 256);
1750 prefixKeyLen
= ucol_getSortKey(coll
, buffer
, unescapedLen
, prefixKey
, 256);
1752 unescapedLen
= u_unescape(suffix
, buffer
, 256);
1753 suffixKeyLen
= ucol_getSortKey(coll
, buffer
, unescapedLen
, suffixKey
, 256);
1755 log_verbose("Massaging data with prefixes and different strengths\n");
1756 strength
= UCOL_PRIMARY
;
1757 while(strength
<= UCOL_IDENTICAL
) {
1758 log_verbose("Strength %s\n", strengthsC
[strength
<=UCOL_QUATERNARY
?strength
:4]);
1759 ucol_setAttribute(coll
, UCOL_STRENGTH
, strength
, &status
);
1760 for(i
= 0; i
<casesSize
; i
++) {
1761 unescapedLen
= u_unescape(cases
[i
], buffer
, 256);
1762 sortKeysLen
[i
] = ucol_getSortKey(coll
, buffer
, unescapedLen
, sortkeys
[i
], 256);
1763 ucol_mergeSortkeys(prefixKey
, prefixKeyLen
, sortkeys
[i
], sortKeysLen
[i
], mergedPrefixkeys
[i
], 256);
1764 ucol_mergeSortkeys(sortkeys
[i
], sortKeysLen
[i
], suffixKey
, suffixKeyLen
, mergedSuffixkeys
[i
], 256);
1766 if(tMemCmp(mergedPrefixkeys
[i
-1], mergedPrefixkeys
[i
]) >= 0) {
1767 log_err("Error while comparing prefixed keys @ strength %s:\n", strengthsC
[strength
<=UCOL_QUATERNARY
?strength
:4]);
1769 ucol_sortKeyToString(coll
, mergedPrefixkeys
[i
-1], outBuff1
, &l1
),
1770 ucol_sortKeyToString(coll
, mergedPrefixkeys
[i
], outBuff2
, &l2
));
1772 if(tMemCmp(mergedSuffixkeys
[i
-1], mergedSuffixkeys
[i
]) >= 0) {
1773 log_err("Error while comparing suffixed keys @ strength %s:\n", strengthsC
[strength
<=UCOL_QUATERNARY
?strength
:4]);
1775 ucol_sortKeyToString(coll
, mergedSuffixkeys
[i
-1], outBuff1
, &l1
),
1776 ucol_sortKeyToString(coll
, mergedSuffixkeys
[i
], outBuff2
, &l2
));
1780 if(strength
== UCOL_QUATERNARY
) {
1781 strength
= UCOL_IDENTICAL
;
1788 uint8_t smallBuf
[3];
1789 uint32_t reqLen
= 0;
1790 log_verbose("testing buffer overflow\n");
1791 reqLen
= ucol_mergeSortkeys(prefixKey
, prefixKeyLen
, suffixKey
, suffixKeyLen
, smallBuf
, 3);
1792 if(reqLen
!= (prefixKeyLen
+suffixKeyLen
-1)) {
1793 log_err("Wrong preflight size for merged sortkey\n");
1799 uint8_t emptyKey
[20], abcKey
[50], mergedKey
[100];
1800 int32_t emptyKeyLen
= 0, abcKeyLen
= 0, mergedKeyLen
= 0;
1802 log_verbose("testing merging with sortkeys generated for empty strings\n");
1803 emptyKeyLen
= ucol_getSortKey(coll
, &empty
, 0, emptyKey
, 20);
1804 unescapedLen
= u_unescape(cases
[0], buffer
, 256);
1805 abcKeyLen
= ucol_getSortKey(coll
, buffer
, unescapedLen
, abcKey
, 50);
1806 mergedKeyLen
= ucol_mergeSortkeys(emptyKey
, emptyKeyLen
, abcKey
, abcKeyLen
, mergedKey
, 100);
1807 if(mergedKey
[0] != 2) {
1808 log_err("Empty sortkey didn't produce a level separator\n");
1810 /* try with zeros */
1811 mergedKeyLen
= ucol_mergeSortkeys(emptyKey
, 0, abcKey
, abcKeyLen
, mergedKey
, 100);
1812 if(mergedKeyLen
!= 0 || mergedKey
[0] != 0) {
1813 log_err("Empty key didn't produce null mergedKey\n");
1815 mergedKeyLen
= ucol_mergeSortkeys(abcKey
, abcKeyLen
, emptyKey
, 0, mergedKey
, 100);
1816 if(mergedKeyLen
!= 0 || mergedKey
[0] != 0) {
1817 log_err("Empty key didn't produce null mergedKey\n");
1822 for(i
= 0; i
<casesSize
; i
++) {
1824 free(mergedPrefixkeys
[i
]);
1825 free(mergedSuffixkeys
[i
]);
1828 free(mergedPrefixkeys
);
1829 free(mergedSuffixkeys
);
1832 /* need to finish this up */
1834 log_data_err("Couldn't open collator");
1837 static void TestShortString(void)
1841 const char *expectedOutput
;
1843 UErrorCode expectedStatus
;
1844 int32_t expectedOffset
;
1845 uint32_t expectedIdentifier
;
1847 {"LDE_RDE_KPHONEBOOK_T0041_ZLATN","B2C00_KPHONEBOOK_LDE", "de@collation=phonebook", U_USING_FALLBACK_WARNING
, 0, 0 },
1848 {"LEN_RUS_NO_AS_S4","AS_LEN_NO_S4", NULL
, U_USING_FALLBACK_WARNING
, 0, 0 },
1849 {"LDE_VPHONEBOOK_EO_SI","EO_KPHONEBOOK_LDE_SI", "de@collation=phonebook", U_ZERO_ERROR
, 0, 0 },
1850 {"LDE_Kphonebook","KPHONEBOOK_LDE", "de@collation=phonebook", U_ZERO_ERROR
, 0, 0 },
1851 {"Xqde_DE@collation=phonebookq_S3_EX","KPHONEBOOK_LDE", "de@collation=phonebook", U_USING_FALLBACK_WARNING
, 0, 0 },
1852 {"LFR_FO", "LFR", NULL
, U_ZERO_ERROR
, 0, 0 },
1853 {"SO_LX_AS", "", NULL
, U_ILLEGAL_ARGUMENT_ERROR
, 8, 0 },
1854 {"S3_ASS_MMM", "", NULL
, U_ILLEGAL_ARGUMENT_ERROR
, 5, 0 }
1858 UCollator
*coll
= NULL
, *fromNormalized
= NULL
;
1859 UParseError parseError
;
1860 UErrorCode status
= U_ZERO_ERROR
;
1861 char fromShortBuffer
[256], normalizedBuffer
[256], fromNormalizedBuffer
[256];
1862 const char* locale
= NULL
;
1865 for(i
= 0; i
< sizeof(testCases
)/sizeof(testCases
[0]); i
++) {
1866 status
= U_ZERO_ERROR
;
1867 if(testCases
[i
].locale
) {
1868 locale
= testCases
[i
].locale
;
1873 coll
= ucol_openFromShortString(testCases
[i
].input
, FALSE
, &parseError
, &status
);
1874 if(status
!= testCases
[i
].expectedStatus
) {
1875 log_err("Got status '%s' that is different from expected '%s' for '%s'\n",
1876 u_errorName(status
), u_errorName(testCases
[i
].expectedStatus
), testCases
[i
].input
);
1879 if(U_SUCCESS(status
)) {
1880 ucol_getShortDefinitionString(coll
, locale
, fromShortBuffer
, 256, &status
);
1882 if(strcmp(fromShortBuffer
, testCases
[i
].expectedOutput
)) {
1883 log_err("Got short string '%s' from the collator. Expected '%s' for input '%s'\n",
1884 fromShortBuffer
, testCases
[i
].expectedOutput
, testCases
[i
].input
);
1887 ucol_normalizeShortDefinitionString(testCases
[i
].input
, normalizedBuffer
, 256, &parseError
, &status
);
1888 fromNormalized
= ucol_openFromShortString(normalizedBuffer
, FALSE
, &parseError
, &status
);
1889 ucol_getShortDefinitionString(fromNormalized
, locale
, fromNormalizedBuffer
, 256, &status
);
1891 if(strcmp(fromShortBuffer
, fromNormalizedBuffer
)) {
1892 log_err("Strings obtained from collators instantiated by short string ('%s') and from normalized string ('%s') differ\n",
1893 fromShortBuffer
, fromNormalizedBuffer
);
1897 if(!ucol_equals(coll
, fromNormalized
)) {
1898 log_err("Collator from short string ('%s') differs from one obtained through a normalized version ('%s')\n",
1899 testCases
[i
].input
, normalizedBuffer
);
1902 ucol_close(fromNormalized
);
1906 if(parseError
.offset
!= testCases
[i
].expectedOffset
) {
1907 log_err("Got parse error offset %i, but expected %i instead for '%s'\n",
1908 parseError
.offset
, testCases
[i
].expectedOffset
, testCases
[i
].input
);
1916 doSetsTest(const char *locale
, const USet
*ref
, USet
*set
, const char* inSet
, const char* outSet
, UErrorCode
*status
) {
1921 bufLen
= u_unescape(inSet
, buffer
, 512);
1922 uset_applyPattern(set
, buffer
, bufLen
, 0, status
);
1923 if(U_FAILURE(*status
)) {
1924 log_err("%s: Failure setting pattern %s\n", locale
, u_errorName(*status
));
1927 if(!uset_containsAll(ref
, set
)) {
1928 log_err("%s: Some stuff from %s is not present in the set\n", locale
, inSet
);
1932 bufLen
= u_unescape(outSet
, buffer
, 512);
1933 uset_applyPattern(set
, buffer
, bufLen
, 0, status
);
1934 if(U_FAILURE(*status
)) {
1935 log_err("%s: Failure setting pattern %s\n", locale
, u_errorName(*status
));
1938 if(!uset_containsNone(ref
, set
)) {
1939 log_err("%s: Some stuff from %s is present in the set\n", locale
, outSet
);
1947 TestGetContractionsAndUnsafes(void)
1951 const char* inConts
;
1952 const char* outConts
;
1955 const char* unsafeCodeUnits
;
1956 const char* safeCodeUnits
;
1959 "[{\\u0474\\u030F}{\\u0475\\u030F}{\\u04D8\\u0308}{\\u04D9\\u0308}{\\u04E8\\u0308}{\\u04E9\\u0308}]",
1960 "[{\\u0430\\u0306}{\\u0410\\u0306}{\\u0430\\u0308}{\\u0410\\u0306}{\\u0433\\u0301}{\\u0413\\u0301}]",
1963 "[\\u0474\\u0475\\u04d8\\u04d9\\u04e8\\u04e9]",
1964 "[aAbB\\u0430\\u0410\\u0433\\u0413]"
1967 "[{\\u0474\\u030F}{\\u0475\\u030F}{\\u04D8\\u0308}{\\u04D9\\u0308}{\\u04E8\\u0308}{\\u04E9\\u0308}"
1968 "{\\u0430\\u0306}{\\u0410\\u0306}{\\u0430\\u0308}{\\u0410\\u0306}{\\u0433\\u0301}{\\u0413\\u0301}]",
1972 "[\\u0474\\u0475\\u04D8\\u04D9\\u04E8\\u04E9\\u0430\\u0410\\u0433\\u0413]",
1976 "[{C\\u0301}{C\\u030C}{C\\u0341}{DZ\\u030C}{Dz\\u030C}{D\\u017D}{D\\u017E}{lj}{nj}]",
1977 "[{\\u309d\\u3099}{\\u30fd\\u3099}]",
1984 "[{\\u3053\\u3099\\u309D}{\\u3053\\u3099\\u309D\\u3099}{\\u3053\\u3099\\u309E}{\\u3053\\u3099\\u30FC}{\\u3053\\u309D}{\\u3053\\u309D\\u3099}{\\u3053\\u309E}{\\u3053\\u30FC}{\\u30B3\\u3099\\u30FC}{\\u30B3\\u3099\\u30FD}{\\u30B3\\u3099\\u30FD\\u3099}{\\u30B3\\u3099\\u30FE}{\\u30B3\\u30FC}{\\u30B3\\u30FD}{\\u30B3\\u30FD\\u3099}{\\u30B3\\u30FE}]",
1985 "[{\\u30FD\\u3099}{\\u309D\\u3099}{\\u3053\\u3099}{\\u30B3\\u3099}{lj}{nj}]",
1996 UErrorCode status
= U_ZERO_ERROR
;
1997 UCollator
*coll
= NULL
;
1999 int32_t noConts
= 0;
2000 USet
*conts
= uset_open(0,0);
2001 USet
*exp
= uset_open(0, 0);
2002 USet
*set
= uset_open(0,0);
2003 int32_t setBufferLen
= 65536;
2004 UChar buffer
[65536];
2007 for(i
= 0; i
< sizeof(tests
)/sizeof(tests
[0]); i
++) {
2008 log_verbose("Testing locale: %s\n", tests
[i
].locale
);
2009 coll
= ucol_open(tests
[i
].locale
, &status
);
2010 ucol_getContractionsAndExpansions(coll
, conts
, exp
, TRUE
, &status
);
2011 doSetsTest(tests
[i
].locale
, conts
, set
, tests
[i
].inConts
, tests
[i
].outConts
, &status
);
2012 setLen
= uset_toPattern(conts
, buffer
, setBufferLen
, TRUE
, &status
);
2013 if(U_SUCCESS(status
)) {
2014 /*log_verbose("Contractions %i: %s\n", uset_getItemCount(conts), aescstrdup(buffer, setLen));*/
2016 log_err("error %s. %i\n", u_errorName(status
), setLen
);
2017 status
= U_ZERO_ERROR
;
2019 doSetsTest(tests
[i
].locale
, exp
, set
, tests
[i
].inExp
, tests
[i
].outExp
, &status
);
2020 setLen
= uset_toPattern(exp
, buffer
, setBufferLen
, TRUE
, &status
);
2021 if(U_SUCCESS(status
)) {
2022 /*log_verbose("Expansions %i: %s\n", uset_getItemCount(exp), aescstrdup(buffer, setLen));*/
2024 log_err("error %s. %i\n", u_errorName(status
), setLen
);
2025 status
= U_ZERO_ERROR
;
2028 noConts
= ucol_getUnsafeSet(coll
, conts
, &status
);
2029 doSetsTest(tests
[i
].locale
, conts
, set
, tests
[i
].unsafeCodeUnits
, tests
[i
].safeCodeUnits
, &status
);
2030 setLen
= uset_toPattern(conts
, buffer
, setBufferLen
, TRUE
, &status
);
2031 if(U_SUCCESS(status
)) {
2032 log_verbose("Unsafe %i: %s\n", uset_getItemCount(exp
), aescstrdup(buffer
, setLen
));
2034 log_err("error %s. %i\n", u_errorName(status
), setLen
);
2035 status
= U_ZERO_ERROR
;
2048 TestOpenBinary(void)
2050 UErrorCode status
= U_ZERO_ERROR
;
2052 char rule[] = "&h < d < c < b";
2053 char *wUCA[] = { "a", "h", "d", "c", "b", "i" };
2054 char *noUCA[] = {"d", "c", "b", "a", "h", "i" };
2056 /* we have to use Cyrillic letters because latin-1 always gets copied */
2057 const char rule
[] = "&\\u0452 < \\u0434 < \\u0433 < \\u0432"; /* &dje < d < g < v */
2058 const char *wUCA
[] = { "\\u0430", "\\u0452", "\\u0434", "\\u0433", "\\u0432", "\\u0435" }; /* a, dje, d, g, v, e */
2059 const char *noUCA
[] = {"\\u0434", "\\u0433", "\\u0432", "\\u0430", "\\u0435", "\\u0452" }; /* d, g, v, a, e, dje */
2062 int32_t uRulesLen
= u_unescape(rule
, uRules
, 256);
2064 UCollator
*coll
= ucol_openRules(uRules
, uRulesLen
, UCOL_DEFAULT
, UCOL_DEFAULT
, NULL
, &status
);
2065 UCollator
*UCA
= NULL
;
2066 UCollator
*cloneNOUCA
= NULL
, *cloneWUCA
= NULL
;
2068 uint8_t imageBuffer
[32768];
2069 uint8_t *image
= imageBuffer
;
2070 int32_t imageBufferCapacity
= 32768;
2074 if((coll
==NULL
)||(U_FAILURE(status
))) {
2075 log_data_err("could not load collators or error occured: %s\n",
2076 u_errorName(status
));
2079 UCA
= ucol_open("root", &status
);
2080 if((UCA
==NULL
)||(U_FAILURE(status
))) {
2081 log_data_err("could not load UCA collator or error occured: %s\n",
2082 u_errorName(status
));
2085 imageSize
= ucol_cloneBinary(coll
, image
, imageBufferCapacity
, &status
);
2086 if(U_FAILURE(status
)) {
2087 image
= (uint8_t *)malloc(imageSize
*sizeof(uint8_t));
2088 status
= U_ZERO_ERROR
;
2089 imageSize
= ucol_cloneBinary(coll
, imageBuffer
, imageSize
, &status
);
2093 cloneWUCA
= ucol_openBinary(image
, imageSize
, UCA
, &status
);
2094 cloneNOUCA
= ucol_openBinary(image
, imageSize
, NULL
, &status
);
2096 genericOrderingTest(coll
, wUCA
, sizeof(wUCA
)/sizeof(wUCA
[0]));
2098 genericOrderingTest(cloneWUCA
, wUCA
, sizeof(wUCA
)/sizeof(wUCA
[0]));
2099 genericOrderingTest(cloneNOUCA
, noUCA
, sizeof(noUCA
)/sizeof(noUCA
[0]));
2101 if(image
!= imageBuffer
) {
2105 ucol_close(cloneNOUCA
);
2106 ucol_close(cloneWUCA
);
2110 static void TestDefault(void) {
2111 /* Tests for code coverage. */
2112 UErrorCode status
= U_ZERO_ERROR
;
2113 UCollator
*coll
= ucol_open("es@collation=pinyin", &status
);
2114 if (status
!= U_USING_DEFAULT_WARNING
) {
2115 /* What do you mean that you know about using pinyin collation in Spanish!? This should be in the zh locale. */
2116 log_err("es@collation=pinyin should return U_USING_DEFAULT_WARNING, but returned %s\n", u_errorName(status
));
2119 if (ucol_getKeywordValues("funky", &status
) != NULL
) {
2120 log_err("Collators should not know about the funky keyword.\n");
2122 if (status
!= U_ILLEGAL_ARGUMENT_ERROR
) {
2123 log_err("funky keyword didn't fail as expected %s\n", u_errorName(status
));
2125 if (ucol_getKeywordValues("collation", &status
) != NULL
) {
2126 log_err("ucol_getKeywordValues should not work when given a bad status.\n");
2130 #endif /* #if !UCONFIG_NO_COLLATION */