Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: source/test/cintltst/capitst.c

Issue 845603002: Update ICU to 54.1 step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: remove unusued directories Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/test/cintltst/callcoll.c ('k') | source/test/cintltst/cbiditst.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /******************************************************************** 1 /********************************************************************
2 * Copyright (c) 1997-2013, International Business Machines 2 * Copyright (c) 1997-2014, International Business Machines
3 * Corporation and others. All Rights Reserved. 3 * Corporation and others. All Rights Reserved.
4 ********************************************************************/ 4 ********************************************************************/
5 /***************************************************************************** 5 /*****************************************************************************
6 * 6 *
7 * File CAPITEST.C 7 * File CAPITEST.C
8 * 8 *
9 * Modification History: 9 * Modification History:
10 * Name Description 10 * Name Description
11 * Madhu Katragadda Ported for C API 11 * Madhu Katragadda Ported for C API
12 * Brian Rower Added TestOpenVsOpenRules 12 * Brian Rower Added TestOpenVsOpenRules
(...skipping 11 matching lines...) Expand all
24 #include "unicode/ulocdata.h" 24 #include "unicode/ulocdata.h"
25 #include "unicode/ustring.h" 25 #include "unicode/ustring.h"
26 #include "unicode/ures.h" 26 #include "unicode/ures.h"
27 #include "unicode/ucoleitr.h" 27 #include "unicode/ucoleitr.h"
28 #include "cintltst.h" 28 #include "cintltst.h"
29 #include "capitst.h" 29 #include "capitst.h"
30 #include "ccolltst.h" 30 #include "ccolltst.h"
31 #include "putilimp.h" 31 #include "putilimp.h"
32 #include "cmemory.h" 32 #include "cmemory.h"
33 #include "cstring.h" 33 #include "cstring.h"
34 #include "ucol_imp.h"
34 35
35 static void TestAttribute(void); 36 static void TestAttribute(void);
36 static void TestDefault(void); 37 static void TestDefault(void);
37 static void TestDefaultKeyword(void); 38 static void TestDefaultKeyword(void);
38 static void TestBengaliSortKey(void); 39 static void TestBengaliSortKey(void);
39 40
40 41
41 static char* U_EXPORT2 ucol_sortKeyToString(const UCollator *coll, const uint8_t *sortkey, char *buffer, uint32_t len) { 42 static char* U_EXPORT2 ucol_sortKeyToString(const UCollator *coll, const uint8_t *sortkey, char *buffer, uint32_t len) {
42 uint32_t position = 0; 43 uint32_t position = 0;
43 uint8_t b; 44 uint8_t b;
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 261
261 } 262 }
262 #endif 263 #endif
263 264
264 /* Collator Properties 265 /* Collator Properties
265 ucol_open, ucol_strcoll, getStrength/setStrength 266 ucol_open, ucol_strcoll, getStrength/setStrength
266 getDecomposition/setDecomposition, getDisplayName*/ 267 getDecomposition/setDecomposition, getDisplayName*/
267 void TestProperty() 268 void TestProperty()
268 { 269 {
269 UCollator *col, *ruled; 270 UCollator *col, *ruled;
271 const UChar *rules;
270 UChar *disName; 272 UChar *disName;
271 int32_t len = 0; 273 int32_t len = 0;
272 UChar source[12], target[12]; 274 UChar source[12], target[12];
273 int32_t tempLength; 275 int32_t tempLength;
274 UErrorCode status = U_ZERO_ERROR; 276 UErrorCode status = U_ZERO_ERROR;
275 /* 277 /*
276 * Expected version of the English collator. 278 * Expected version of the English collator.
277 * Currently, the major/minor version numbers change when the builder code 279 * Currently, the major/minor version numbers change when the builder code
278 * changes, 280 * changes,
279 * number 2 is from the tailoring data version and 281 * number 2 is from the tailoring data version and
(...skipping 23 matching lines...) Expand all
303 versionArray[0], versionArray[1], versionArray[2], versionArray[3] ); 305 versionArray[0], versionArray[1], versionArray[2], versionArray[3] );
304 } else { 306 } else {
305 log_verbose("ucol_getVersion() result: %02x.%02x.%02x.%02x\n", 307 log_verbose("ucol_getVersion() result: %02x.%02x.%02x.%02x\n",
306 versionArray[0], versionArray[1], versionArray[2], versionArra y[3]); 308 versionArray[0], versionArray[1], versionArray[2], versionArra y[3]);
307 } 309 }
308 310
309 /* Assume that the UCD and UCA versions are the same, 311 /* Assume that the UCD and UCA versions are the same,
310 * rather than hardcoding (and updating each time) a particular UCA version. */ 312 * rather than hardcoding (and updating each time) a particular UCA version. */
311 u_getUnicodeVersion(versionUCDArray); 313 u_getUnicodeVersion(versionUCDArray);
312 ucol_getUCAVersion(col, versionUCAArray); 314 ucol_getUCAVersion(col, versionUCAArray);
313 if (0!=uprv_memcmp(versionUCAArray, versionUCDArray, 4) /*TODO: remove the f ollowing once UCA is up to date, ticket:9101*/ && !(versionUCDArray[0]==6 && ver sionUCDArray[1]==3)) { 315 if (0!=uprv_memcmp(versionUCAArray, versionUCDArray, 4)) {
314 log_err("Testing ucol_getUCAVersion() - unexpected result: %hu.%hu.%hu.%hu \n", 316 log_err("Testing ucol_getUCAVersion() - unexpected result: %hu.%hu.%hu.%hu \n",
315 versionUCAArray[0], versionUCAArray[1], versionUCAArray[2], versio nUCAArray[3]); 317 versionUCAArray[0], versionUCAArray[1], versionUCAArray[2], versio nUCAArray[3]);
316 } 318 }
317 319
318 u_uastrcpy(source, "ab"); 320 u_uastrcpy(source, "ab");
319 u_uastrcpy(target, "abc"); 321 u_uastrcpy(target, "abc");
320 322
321 doStrcoll(col, source, u_strlen(source), target, u_strlen(target), UCOL_LESS , "ab < abc comparison failed"); 323 doStrcoll(col, source, u_strlen(source), target, u_strlen(target), UCOL_LESS , "ab < abc comparison failed");
322 324
323 u_uastrcpy(source, "ab"); 325 u_uastrcpy(source, "ab");
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 log_verbose("the display name for default collation in german: %s\n", au strdup(disName) ); 365 log_verbose("the display name for default collation in german: %s\n", au strdup(disName) );
364 free(disName); 366 free(disName);
365 } 367 }
366 if(U_FAILURE(status)){ 368 if(U_FAILURE(status)){
367 log_err("ERROR: in getDisplayName: %s\n", myErrorName(status)); 369 log_err("ERROR: in getDisplayName: %s\n", myErrorName(status));
368 return; 370 return;
369 } 371 }
370 log_verbose("Default collation getDisplayName ended.\n"); 372 log_verbose("Default collation getDisplayName ended.\n");
371 373
372 ruled = ucol_open("da_DK", &status); 374 ruled = ucol_open("da_DK", &status);
375 if(U_FAILURE(status)) {
376 log_data_err("ucol_open(\"da_DK\") failed - %s\n", u_errorName(status));
377 ucol_close(col);
378 return;
379 }
373 log_verbose("ucol_getRules() testing ...\n"); 380 log_verbose("ucol_getRules() testing ...\n");
374 ucol_getRules(ruled, &tempLength); 381 rules = ucol_getRules(ruled, &tempLength);
375 doAssert( tempLength != 0, "getRules() result incorrect" ); 382 if(tempLength == 0) {
383 log_data_err("missing da_DK tailoring rule string\n");
384 } else {
385 UChar aa[2] = { 0x61, 0x61 };
386 doAssert(u_strFindFirst(rules, tempLength, aa, 2) != NULL,
387 "da_DK rules do not contain 'aa'");
388 }
376 log_verbose("getRules tests end.\n"); 389 log_verbose("getRules tests end.\n");
377 { 390 {
378 UChar *buffer = (UChar *)malloc(200000*sizeof(UChar)); 391 UChar *buffer = (UChar *)malloc(200000*sizeof(UChar));
379 int32_t bufLen = 200000; 392 int32_t bufLen = 200000;
380 buffer[0] = '\0'; 393 buffer[0] = '\0';
381 log_verbose("ucol_getRulesEx() testing ...\n"); 394 log_verbose("ucol_getRulesEx() testing ...\n");
382 tempLength = ucol_getRulesEx(col,UCOL_TAILORING_ONLY,buffer,bufLen ); 395 tempLength = ucol_getRulesEx(col,UCOL_TAILORING_ONLY,buffer,bufLen );
383 doAssert( tempLength == 0x00, "getRulesEx() result incorrect" ); 396 doAssert( tempLength == 0x00, "getRulesEx() result incorrect" );
384 log_verbose("getRules tests end.\n"); 397 log_verbose("getRules tests end.\n");
385 398
386 log_verbose("ucol_getRulesEx() testing ...\n"); 399 log_verbose("ucol_getRulesEx() testing ...\n");
387 tempLength=ucol_getRulesEx(col,UCOL_FULL_RULES,buffer,bufLen ); 400 tempLength=ucol_getRulesEx(col,UCOL_FULL_RULES,buffer,bufLen );
388 doAssert( tempLength != 0, "getRulesEx() result incorrect" ); 401 if(tempLength == 0) {
389 log_verbose("getRules tests end.\n"); 402 log_data_err("missing *full* rule string\n");
403 }
404 log_verbose("getRulesEx tests end.\n");
390 free(buffer); 405 free(buffer);
391 } 406 }
392 ucol_close(ruled); 407 ucol_close(ruled);
393 ucol_close(col); 408 ucol_close(col);
394 409
395 log_verbose("open an collator for french locale"); 410 log_verbose("open an collator for french locale");
396 col = ucol_open("fr_FR", &status); 411 col = ucol_open("fr_FR", &status);
397 if (U_FAILURE(status)) { 412 if (U_FAILURE(status)) {
398 log_err("ERROR: Creating French collation failed.: %s\n", myErrorName(sta tus)); 413 log_err("ERROR: Creating French collation failed.: %s\n", myErrorName(sta tus));
399 return; 414 return;
(...skipping 28 matching lines...) Expand all
428 } 443 }
429 444
430 /* Test RuleBasedCollator and getRules*/ 445 /* Test RuleBasedCollator and getRules*/
431 void TestRuleBasedColl() 446 void TestRuleBasedColl()
432 { 447 {
433 UCollator *col1, *col2, *col3, *col4; 448 UCollator *col1, *col2, *col3, *col4;
434 UCollationElements *iter1, *iter2; 449 UCollationElements *iter1, *iter2;
435 UChar ruleset1[60]; 450 UChar ruleset1[60];
436 UChar ruleset2[50]; 451 UChar ruleset2[50];
437 UChar teststr[10]; 452 UChar teststr[10];
438 UChar teststr2[10];
439 const UChar *rule1, *rule2, *rule3, *rule4; 453 const UChar *rule1, *rule2, *rule3, *rule4;
440 int32_t tempLength; 454 int32_t tempLength;
441 UErrorCode status = U_ZERO_ERROR; 455 UErrorCode status = U_ZERO_ERROR;
442 u_uastrcpy(ruleset1, "&9 < a, A < b, B < c, C; ch, cH, Ch, CH < d, D, e, E") ; 456 u_uastrcpy(ruleset1, "&9 < a, A < b, B < c, C; ch, cH, Ch, CH < d, D, e, E") ;
443 u_uastrcpy(ruleset2, "&9 < a, A < b, B < c, C < d, D, e, E"); 457 u_uastrcpy(ruleset2, "&9 < a, A < b, B < c, C < d, D, e, E");
444 458
445 459
446 col1 = ucol_openRules(ruleset1, u_strlen(ruleset1), UCOL_DEFAULT, UCOL_DEFAU LT_STRENGTH, NULL,&status); 460 col1 = ucol_openRules(ruleset1, u_strlen(ruleset1), UCOL_DEFAULT, UCOL_DEFAU LT_STRENGTH, NULL,&status);
447 if (U_FAILURE(status)) { 461 if (U_FAILURE(status)) {
448 log_err_status(status, "RuleBased Collator creation failed.: %s\n", myEr rorName(status)); 462 log_err_status(status, "RuleBased Collator creation failed.: %s\n", myEr rorName(status));
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 log_err("! modifier test failed"); 538 log_err("! modifier test failed");
525 } 539 }
526 if (ce == UCOL_NULLORDER) { 540 if (ce == UCOL_NULLORDER) {
527 break; 541 break;
528 } 542 }
529 } 543 }
530 ucol_closeElements(iter1); 544 ucol_closeElements(iter1);
531 ucol_closeElements(iter2); 545 ucol_closeElements(iter2);
532 ucol_close(col1); 546 ucol_close(col1);
533 ucol_close(col2); 547 ucol_close(col2);
534 /* test that we can start a rule without a & or < */ 548 /* CLDR 24+ requires a reset before the first relation */
535 u_uastrcpy(ruleset1, "< z < a"); 549 u_uastrcpy(ruleset1, "< z < a");
536 col1 = ucol_openRules(ruleset1, u_strlen(ruleset1), UCOL_DEFAULT, UCOL_DEFAU LT_STRENGTH, NULL, &status); 550 col1 = ucol_openRules(ruleset1, u_strlen(ruleset1), UCOL_DEFAULT, UCOL_DEFAU LT_STRENGTH, NULL, &status);
537 if (U_FAILURE(status)) { 551 if (status != U_PARSE_ERROR && status != U_INVALID_FORMAT_ERROR) {
538 log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status) ); 552 log_err("ucol_openRules(without initial reset: '< z < a') "
539 return; 553 "should fail with U_PARSE_ERROR or U_INVALID_FORMAT_ERROR but yi elded %s\n",
540 } 554 myErrorName(status));
541 u_uastrcpy(teststr, "z");
542 u_uastrcpy(teststr2, "a");
543 if (ucol_greaterOrEqual(col1, teststr, 1, teststr2, 1)) {
544 log_err("Rule \"z < a\" fails");
545 } 555 }
546 ucol_close(col1); 556 ucol_close(col1);
547 } 557 }
548 558
549 void TestCompare() 559 void TestCompare()
550 { 560 {
551 UErrorCode status = U_ZERO_ERROR; 561 UErrorCode status = U_ZERO_ERROR;
552 UCollator *col; 562 UCollator *col;
553 UChar* test1; 563 UChar* test1;
554 UChar* test2; 564 UChar* test2;
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 969
960 /* create a collator the normal API way */ 970 /* create a collator the normal API way */
961 c1 = ucol_open(curLoc, &err); 971 c1 = ucol_open(curLoc, &err);
962 if (U_FAILURE(err)) { 972 if (U_FAILURE(err)) {
963 log_err("ERROR: Normal collation creation failed with locale: %s : % s\n", curLoc, myErrorName(err)); 973 log_err("ERROR: Normal collation creation failed with locale: %s : % s\n", curLoc, myErrorName(err));
964 return; 974 return;
965 } 975 }
966 976
967 /* grab the rules */ 977 /* grab the rules */
968 rules = ucol_getRules(c1, &rulesLength); 978 rules = ucol_getRules(c1, &rulesLength);
979 if (rulesLength == 0) {
980 /* The optional tailoring rule string is either empty (boring) or mi ssing. */
981 ucol_close(c1);
982 continue;
983 }
969 984
970 /* use those rules to create a collator from rules */ 985 /* use those rules to create a collator from rules */
971 c2 = ucol_openRules(rules, rulesLength, UCOL_DEFAULT, UCOL_DEFAULT_STREN GTH, NULL, &err); 986 c2 = ucol_openRules(rules, rulesLength, UCOL_DEFAULT, UCOL_DEFAULT_STREN GTH, NULL, &err);
972 if (U_FAILURE(err)) { 987 if (U_FAILURE(err)) {
973 log_err("ERROR: Creating collator from rules failed with locale: %s : %s\n", curLoc, myErrorName(err)); 988 log_err("ERROR: Creating collator from rules failed with locale: %s : %s\n", curLoc, myErrorName(err));
974 return; 989 ucol_close(c1);
990 continue;
975 } 991 }
976 992
977 uld = ulocdata_open(curLoc, &err); 993 uld = ulocdata_open(curLoc, &err);
978 994
979 /*now that we have some collators, we get several strings */ 995 /*now that we have some collators, we get several strings */
980 996
981 for(y = 0; y < 5; y++){ 997 for(y = 0; y < 5; y++){
982 998
983 /* get a set of ALL the characters in this locale */ 999 /* get a set of ALL the characters in this locale */
984 eSet = ulocdata_getExemplarSet(uld, NULL, 0, ULOCDATA_ES_STANDARD, &err); 1000 eSet = ulocdata_getExemplarSet(uld, NULL, 0, ULOCDATA_ES_STANDARD, &err);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 ucol_setAttribute(col, UCOL_STRENGTH, UCOL_TERTIARY, &status); 1188 ucol_setAttribute(col, UCOL_STRENGTH, UCOL_TERTIARY, &status);
1173 sortklen = ucol_getSortKey(col, test1, 0, NULL, 0); 1189 sortklen = ucol_getSortKey(col, test1, 0, NULL, 0);
1174 sortkEmpty = (uint8_t*)malloc(sizeof(uint8_t) * sortklen+1); 1190 sortkEmpty = (uint8_t*)malloc(sizeof(uint8_t) * sortklen+1);
1175 sortklen = ucol_getSortKey(col, test1, 0, sortkEmpty, sortklen+1); 1191 sortklen = ucol_getSortKey(col, test1, 0, sortkEmpty, sortklen+1);
1176 if(sortklen != 3 || sortkEmpty[0] != 1 || sortkEmpty[0] != 1 || sortkEmpty[2 ] != 0) { 1192 if(sortklen != 3 || sortkEmpty[0] != 1 || sortkEmpty[0] != 1 || sortkEmpty[2 ] != 0) {
1177 log_err("Empty string generated wrong sortkey!\n"); 1193 log_err("Empty string generated wrong sortkey!\n");
1178 } 1194 }
1179 free(sortkEmpty); 1195 free(sortkEmpty);
1180 1196
1181 log_verbose("testing passing invalid string\n"); 1197 log_verbose("testing passing invalid string\n");
1182 sortklen = ucol_getSortKey(col, NULL, 0, NULL, 0); 1198 sortklen = ucol_getSortKey(col, NULL, 10, NULL, 0);
1183 if(sortklen != 0) { 1199 if(sortklen != 0) {
1184 log_err("Invalid string didn't return sortkey size of 0\n"); 1200 log_err("Invalid string didn't return sortkey size of 0\n");
1185 } 1201 }
1186 1202
1187 1203
1188 log_verbose("testing sortkey ends...\n"); 1204 log_verbose("testing sortkey ends...\n");
1189 ucol_close(col); 1205 ucol_close(col);
1190 free(test1); 1206 free(test1);
1191 free(test2); 1207 free(test2);
1192 free(test3); 1208 free(test3);
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 UErrorCode status = U_ZERO_ERROR; 1398 UErrorCode status = U_ZERO_ERROR;
1383 const char *rules = "&a<x<y<z"; 1399 const char *rules = "&a<x<y<z";
1384 UChar rlz[256] = {0}; 1400 UChar rlz[256] = {0};
1385 uint32_t rlzLen = u_unescape(rules, rlz, 256); 1401 uint32_t rlzLen = u_unescape(rules, rlz, 256);
1386 1402
1387 UCollator *coll = NULL; 1403 UCollator *coll = NULL;
1388 const char *locale = NULL; 1404 const char *locale = NULL;
1389 1405
1390 int32_t i = 0; 1406 int32_t i = 0;
1391 1407
1392 /* Now that the collation tree is separate, actual==valid at all times. [alan] */
1393 static const struct { 1408 static const struct {
1394 const char* requestedLocale; 1409 const char* requestedLocale;
1395 const char* validLocale; 1410 const char* validLocale;
1396 const char* actualLocale; 1411 const char* actualLocale;
1397 } testStruct[] = { 1412 } testStruct[] = {
1398 { "sr_RS", "sr_Cyrl_RS", "sr" }, 1413 { "sr_RS", "sr_Cyrl_RS", "sr" },
1399 { "sh_YU", "sr_Latn_RS", "sr_Latn" }, /* was sh, then aliased to hr, now sr_ Latn via import per cldrbug 5647: */ 1414 { "sh_YU", "sr_Latn_RS", "sr_Latn" }, /* was sh, then aliased to hr, now sr_ Latn via import per cldrbug 5647: */
1400 { "en_BE_FOO", "en_BE", "root" }, 1415 { "en_BE_FOO", "en", "root" },
1401 { "sv_SE_NONEXISTANT", "sv_SE", "sv" } 1416 { "sv_SE_NONEXISTANT", "sv", "sv" }
1402 }; 1417 };
1403 1418
1404 /* test opening collators for different locales */ 1419 /* test opening collators for different locales */
1405 for(i = 0; i<sizeof(testStruct)/sizeof(testStruct[0]); i++) { 1420 for(i = 0; i<sizeof(testStruct)/sizeof(testStruct[0]); i++) {
1406 status = U_ZERO_ERROR; 1421 status = U_ZERO_ERROR;
1407 coll = ucol_open(testStruct[i].requestedLocale, &status); 1422 coll = ucol_open(testStruct[i].requestedLocale, &status);
1408 if(U_FAILURE(status)) { 1423 if(U_FAILURE(status)) {
1409 log_err_status(status, "Failed to open collator for %s with %s\n", testStr uct[i].requestedLocale, u_errorName(status)); 1424 log_err_status(status, "Failed to open collator for %s with %s\n", testStr uct[i].requestedLocale, u_errorName(status));
1410 ucol_close(coll); 1425 ucol_close(coll);
1411 continue; 1426 continue;
1412 } 1427 }
1413 locale = ucol_getLocaleByType(coll, ULOC_REQUESTED_LOCALE, &status); 1428 /*
1414 if(strcmp(locale, testStruct[i].requestedLocale) != 0) { 1429 * The requested locale may be the same as the valid locale,
1430 * or may not be supported at all. See ticket #10477.
1431 */
1432 locale = ucol_getLocaleByType(coll, ULOC_REQUESTED_LOCALE, &status);
1433 if(U_SUCCESS(status) &&
1434 strcmp(locale, testStruct[i].requestedLocale) != 0 && strcmp(locale, t estStruct[i].validLocale) != 0) {
1415 log_err("[Coll %s]: Error in requested locale, expected %s, got %s\n", tes tStruct[i].requestedLocale, testStruct[i].requestedLocale, locale); 1435 log_err("[Coll %s]: Error in requested locale, expected %s, got %s\n", tes tStruct[i].requestedLocale, testStruct[i].requestedLocale, locale);
1416 } 1436 }
1437 status = U_ZERO_ERROR;
1417 locale = ucol_getLocaleByType(coll, ULOC_VALID_LOCALE, &status); 1438 locale = ucol_getLocaleByType(coll, ULOC_VALID_LOCALE, &status);
1418 if(strcmp(locale, testStruct[i].validLocale) != 0) { 1439 if(strcmp(locale, testStruct[i].validLocale) != 0) {
1419 log_err("[Coll %s]: Error in valid locale, expected %s, got %s\n", testStr uct[i].requestedLocale, testStruct[i].validLocale, locale); 1440 log_err("[Coll %s]: Error in valid locale, expected %s, got %s\n", testStr uct[i].requestedLocale, testStruct[i].validLocale, locale);
1420 } 1441 }
1421 locale = ucol_getLocaleByType(coll, ULOC_ACTUAL_LOCALE, &status); 1442 locale = ucol_getLocaleByType(coll, ULOC_ACTUAL_LOCALE, &status);
1422 if(strcmp(locale, testStruct[i].actualLocale) != 0) { 1443 if(strcmp(locale, testStruct[i].actualLocale) != 0) {
1423 log_err("[Coll %s]: Error in actual locale, expected %s, got %s\n", testSt ruct[i].requestedLocale, testStruct[i].actualLocale, locale); 1444 log_err("[Coll %s]: Error in actual locale, expected %s, got %s\n", testSt ruct[i].requestedLocale, testStruct[i].actualLocale, locale);
1424 } 1445 }
1425 ucol_close(coll); 1446 ucol_close(coll);
1426 } 1447 }
1427 1448
1428 /* completely non-existant locale for collator should get a default collator * / 1449 /* completely non-existant locale for collator should get a default collator * /
1429 { 1450 {
1430 UCollator *defaultColl = ucol_open(NULL, &status); 1451 UCollator *defaultColl = ucol_open(NULL, &status);
1431 coll = ucol_open("blahaha", &status); 1452 coll = ucol_open("blahaha", &status);
1432 if(U_SUCCESS(status)) { 1453 if(U_SUCCESS(status)) {
1454 /* See comment above about ticket #10477.
1433 if(strcmp(ucol_getLocaleByType(coll, ULOC_REQUESTED_LOCALE, &status), "bla haha")) { 1455 if(strcmp(ucol_getLocaleByType(coll, ULOC_REQUESTED_LOCALE, &status), "bla haha")) {
1434 log_err("Nonexisting locale didn't preserve the requested locale\n"); 1456 log_err("Nonexisting locale didn't preserve the requested locale\n");
1435 } 1457 } */
1436 if(strcmp(ucol_getLocaleByType(coll, ULOC_VALID_LOCALE, &status), 1458 if(strcmp(ucol_getLocaleByType(coll, ULOC_VALID_LOCALE, &status),
1437 ucol_getLocaleByType(defaultColl, ULOC_VALID_LOCALE, &status))) { 1459 ucol_getLocaleByType(defaultColl, ULOC_VALID_LOCALE, &status))) {
1438 log_err("Valid locale for nonexisting locale locale collator differs " 1460 log_err("Valid locale for nonexisting locale locale collator differs "
1439 "from valid locale for default collator\n"); 1461 "from valid locale for default collator\n");
1440 } 1462 }
1441 if(strcmp(ucol_getLocaleByType(coll, ULOC_ACTUAL_LOCALE, &status), 1463 if(strcmp(ucol_getLocaleByType(coll, ULOC_ACTUAL_LOCALE, &status),
1442 ucol_getLocaleByType(defaultColl, ULOC_ACTUAL_LOCALE, &status))) { 1464 ucol_getLocaleByType(defaultColl, ULOC_ACTUAL_LOCALE, &status))) {
1443 log_err("Actual locale for nonexisting locale locale collator differs " 1465 log_err("Actual locale for nonexisting locale locale collator differs "
1444 "from actual locale for default collator\n"); 1466 "from actual locale for default collator\n");
1445 } 1467 }
1446 ucol_close(coll); 1468 ucol_close(coll);
1447 ucol_close(defaultColl); 1469 ucol_close(defaultColl);
1448 } else { 1470 } else {
1449 log_data_err("Couldn't open collators\n"); 1471 log_data_err("Couldn't open collators\n");
1450 } 1472 }
1451 } 1473 }
1452 1474
1453 1475
1454 1476
1455 /* collator instantiated from rules should have all three locales NULL */ 1477 /* collator instantiated from rules should have all three locales NULL */
1456 coll = ucol_openRules(rlz, rlzLen, UCOL_DEFAULT, UCOL_DEFAULT, NULL, &status); 1478 coll = ucol_openRules(rlz, rlzLen, UCOL_DEFAULT, UCOL_DEFAULT, NULL, &status);
1457 locale = ucol_getLocaleByType(coll, ULOC_REQUESTED_LOCALE, &status); 1479 if (coll != NULL) {
1458 if(locale != NULL) { 1480 locale = ucol_getLocaleByType(coll, ULOC_REQUESTED_LOCALE, &status);
1459 log_err("For collator instantiated from rules, requested locale returned %s instead of NULL\n", locale); 1481 if(U_SUCCESS(status) && locale != NULL) {
1482 log_err("For collator instantiated from rules, requested locale returned % s instead of NULL\n", locale);
1483 }
1484 status = U_ZERO_ERROR;
1485 locale = ucol_getLocaleByType(coll, ULOC_VALID_LOCALE, &status);
1486 if(locale != NULL) {
1487 log_err("For collator instantiated from rules, valid locale returned %s i nstead of NULL\n", locale);
1488 }
1489 locale = ucol_getLocaleByType(coll, ULOC_ACTUAL_LOCALE, &status);
1490 if(locale != NULL) {
1491 log_err("For collator instantiated from rules, actual locale returned %s i nstead of NULL\n", locale);
1492 }
1493 ucol_close(coll);
1494 } else {
1495 log_data_err("Couldn't get collator from ucol_openRules() - %s\n", u_errorNa me(status));
1460 } 1496 }
1461 locale = ucol_getLocaleByType(coll, ULOC_VALID_LOCALE, &status);
1462 if(locale != NULL) {
1463 log_err("For collator instantiated from rules, valid locale returned %s ins tead of NULL\n", locale);
1464 }
1465 locale = ucol_getLocaleByType(coll, ULOC_ACTUAL_LOCALE, &status);
1466 if(locale != NULL) {
1467 log_err("For collator instantiated from rules, actual locale returned %s ins tead of NULL\n", locale);
1468 }
1469 ucol_close(coll);
1470
1471 } 1497 }
1472 1498
1473 1499
1474 void TestGetAll() 1500 void TestGetAll()
1475 { 1501 {
1476 int32_t i, count; 1502 int32_t i, count;
1477 count=ucol_countAvailable(); 1503 count=ucol_countAvailable();
1478 /* use something sensible w/o hardcoding the count */ 1504 /* use something sensible w/o hardcoding the count */
1479 if(count < 0){ 1505 if(count < 0){
1480 log_err("Error in countAvailable(), it returned %d\n", count); 1506 log_err("Error in countAvailable(), it returned %d\n", count);
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 1854
1829 int32_t i = 0, j = 0; 1855 int32_t i = 0, j = 0;
1830 UErrorCode status = U_ZERO_ERROR; 1856 UErrorCode status = U_ZERO_ERROR;
1831 UParseError pError; 1857 UParseError pError;
1832 1858
1833 UCollator *coll = NULL; 1859 UCollator *coll = NULL;
1834 UChar buff[1024]; 1860 UChar buff[1024];
1835 int32_t buffLen = 0; 1861 int32_t buffLen = 0;
1836 USet *set = NULL; 1862 USet *set = NULL;
1837 1863
1838 for(i = 0; i < sizeof(setTest)/sizeof(setTest[0]); i++) { 1864 for(i = 0; i < UPRV_LENGTHOF(setTest); i++) {
1839 buffLen = u_unescape(setTest[i].rules, buff, 1024); 1865 buffLen = u_unescape(setTest[i].rules, buff, 1024);
1840 coll = ucol_openRules(buff, buffLen, UCOL_DEFAULT, UCOL_DEFAULT, &pError, &s tatus); 1866 coll = ucol_openRules(buff, buffLen, UCOL_DEFAULT, UCOL_DEFAULT, &pError, &s tatus);
1841 if(U_SUCCESS(status)) { 1867 if(U_SUCCESS(status)) {
1842 set = ucol_getTailoredSet(coll, &status); 1868 set = ucol_getTailoredSet(coll, &status);
1843 if(uset_size(set) != setTest[i].testsize) { 1869 if(uset_size(set) < setTest[i].testsize) {
1844 log_err("Tailored set size different (%d) than expected (%d)\n", uset_si ze(set), setTest[i].testsize); 1870 log_err("Tailored set size smaller (%d) than expected (%d)\n", uset_size (set), setTest[i].testsize);
1845 } 1871 }
1846 for(j = 0; j < setTest[i].testsize; j++) { 1872 for(j = 0; j < setTest[i].testsize; j++) {
1847 buffLen = u_unescape(setTest[i].tests[j], buff, 1024); 1873 buffLen = u_unescape(setTest[i].tests[j], buff, 1024);
1848 if(!uset_containsString(set, buff, buffLen)) { 1874 if(!uset_containsString(set, buff, buffLen)) {
1849 log_err("Tailored set doesn't contain %s... It should\n", setTest[i].t ests[j]); 1875 log_err("Tailored set doesn't contain %s... It should\n", setTest[i].t ests[j]);
1850 } 1876 }
1851 } 1877 }
1852 uset_close(set); 1878 uset_close(set);
1853 } else { 1879 } else {
1854 log_err_status(status, "Couldn't open collator with rules %s\n", setTest[i ].rules); 1880 log_err_status(status, "Couldn't open collator with rules %s\n", setTest[i ].rules);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1997 { 2023 {
1998 struct { 2024 struct {
1999 const char *input; 2025 const char *input;
2000 const char *expectedOutput; 2026 const char *expectedOutput;
2001 const char *locale; 2027 const char *locale;
2002 UErrorCode expectedStatus; 2028 UErrorCode expectedStatus;
2003 int32_t expectedOffset; 2029 int32_t expectedOffset;
2004 uint32_t expectedIdentifier; 2030 uint32_t expectedIdentifier;
2005 } testCases[] = { 2031 } testCases[] = {
2006 /* 2032 /*
2007 * The following expectedOutput contains a collation weight (2700 from U CA 6.0) 2033 * Note: The first test case sets variableTop to the dollar sign '$'.
2008 * which is the primary weight for the T character (U+0041) in the input . 2034 * We have agreed to drop support for variableTop in ucol_getShortDefini tionString(),
2009 * When that character gets a different weight in FractionalUCA.txt, 2035 * related to ticket #10372 "deprecate collation APIs for short definiti on strings",
2010 * the expectedOutput needs to be adjusted. 2036 * and because it did not work for most spaces/punctuation/symbols,
2011 * That is, when we upgrade to a new UCA version or change collation 2037 * as documented in ticket #10386 "collation short definition strings is sues":
2012 * in such a way that the absolute weight for 'A' changes, 2038 * The old code wrote only 3 hex digits for primary weights below 0x0FFF ,
2013 * we will get a test failure here and need to adjust the test case. 2039 * which is a syntax error, and then failed to normalize the result.
2040 *
2041 * The "B2700" was removed from the expected result ("B2700_KPHONEBOOK_L DE").
2042 *
2043 * Previously, this test had to be adjusted for root collator changes be cause the
2044 * primary weight of the variable top character naturally changed
2045 * but was baked into the expected result.
2014 */ 2046 */
2015 {"LDE_RDE_KPHONEBOOK_T0041_ZLATN","B2700_KPHONEBOOK_LDE", "de@collation= phonebook", U_USING_FALLBACK_WARNING, 0, 0 }, 2047 {"LDE_RDE_KPHONEBOOK_T0024_ZLATN","KPHONEBOOK_LDE", "de@collation=phoneb ook", U_USING_FALLBACK_WARNING, 0, 0 },
2016 2048
2017 {"LEN_RUS_NO_AS_S4","AS_LROOT_NO_S4", NULL, U_USING_DEFAULT_WARNING, 0, 0 }, 2049 {"LEN_RUS_NO_AS_S4","AS_LROOT_NO_S4", NULL, U_USING_DEFAULT_WARNING, 0, 0 },
2018 {"LDE_VPHONEBOOK_EO_SI","EO_KPHONEBOOK_LDE_SI", "de@collation=phonebook" , U_ZERO_ERROR, 0, 0 }, 2050 {"LDE_VPHONEBOOK_EO_SI","EO_KPHONEBOOK_LDE_SI", "de@collation=phonebook" , U_ZERO_ERROR, 0, 0 },
2019 {"LDE_Kphonebook","KPHONEBOOK_LDE", "de@collation=phonebook", U_ZERO_ERR OR, 0, 0 }, 2051 {"LDE_Kphonebook","KPHONEBOOK_LDE", "de@collation=phonebook", U_ZERO_ERR OR, 0, 0 },
2020 {"Xqde_DE@collation=phonebookq_S3_EX","KPHONEBOOK_LDE", "de@collation=ph onebook", U_USING_FALLBACK_WARNING, 0, 0 }, 2052 {"Xqde_DE@collation=phonebookq_S3_EX","KPHONEBOOK_LDE", "de@collation=ph onebook", U_USING_FALLBACK_WARNING, 0, 0 },
2021 {"LFR_FO", "FO_LROOT", NULL, U_USING_DEFAULT_WARNING, 0, 0 }, 2053 {"LFR_FO", "FO_LROOT", NULL, U_USING_DEFAULT_WARNING, 0, 0 },
2022 {"SO_LX_AS", "", NULL, U_ILLEGAL_ARGUMENT_ERROR, 8, 0 }, 2054 {"SO_LX_AS", "", NULL, U_ILLEGAL_ARGUMENT_ERROR, 8, 0 },
2023 {"S3_ASS_MMM", "", NULL, U_ILLEGAL_ARGUMENT_ERROR, 5, 0 } 2055 {"S3_ASS_MMM", "", NULL, U_ILLEGAL_ARGUMENT_ERROR, 5, 0 }
2024 }; 2056 };
2025 2057
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2077 log_err("Got parse error offset %i, but expected %i instead for '%s'\n", 2109 log_err("Got parse error offset %i, but expected %i instead for '%s'\n",
2078 parseError.offset, testCases[i].expectedOffset, testCases[i] .input); 2110 parseError.offset, testCases[i].expectedOffset, testCases[i] .input);
2079 } 2111 }
2080 } 2112 }
2081 } 2113 }
2082 2114
2083 } 2115 }
2084 2116
2085 static void 2117 static void
2086 doSetsTest(const char *locale, const USet *ref, USet *set, const char* inSet, co nst char* outSet, UErrorCode *status) { 2118 doSetsTest(const char *locale, const USet *ref, USet *set, const char* inSet, co nst char* outSet, UErrorCode *status) {
2087 UChar buffer[512]; 2119 UChar buffer[65536];
2088 int32_t bufLen; 2120 int32_t bufLen;
2089 2121
2090 uset_clear(set); 2122 uset_clear(set);
2091 bufLen = u_unescape(inSet, buffer, 512); 2123 bufLen = u_unescape(inSet, buffer, 512);
2092 uset_applyPattern(set, buffer, bufLen, 0, status); 2124 uset_applyPattern(set, buffer, bufLen, 0, status);
2093 if(U_FAILURE(*status)) { 2125 if(U_FAILURE(*status)) {
2094 log_err("%s: Failure setting pattern %s\n", locale, u_errorName(*status) ); 2126 log_err("%s: Failure setting pattern %s\n", locale, u_errorName(*status) );
2095 } 2127 }
2096 2128
2097 if(!uset_containsAll(ref, set)) { 2129 if(!uset_containsAll(ref, set)) {
2098 log_err("%s: Some stuff from %s is not present in the set\n", locale, in Set); 2130 log_err("%s: Some stuff from %s is not present in the set\n", locale, in Set);
2131 uset_removeAll(set, ref);
2132 bufLen = uset_toPattern(set, buffer, UPRV_LENGTHOF(buffer), TRUE, status );
2133 log_info(" missing: %s\n", aescstrdup(buffer, bufLen));
2134 bufLen = uset_toPattern(ref, buffer, UPRV_LENGTHOF(buffer), TRUE, status );
2135 log_info(" total: size=%i %s\n", uset_getItemCount(ref), aescstrdup( buffer, bufLen));
2099 } 2136 }
2100 2137
2101 uset_clear(set); 2138 uset_clear(set);
2102 bufLen = u_unescape(outSet, buffer, 512); 2139 bufLen = u_unescape(outSet, buffer, 512);
2103 uset_applyPattern(set, buffer, bufLen, 0, status); 2140 uset_applyPattern(set, buffer, bufLen, 0, status);
2104 if(U_FAILURE(*status)) { 2141 if(U_FAILURE(*status)) {
2105 log_err("%s: Failure setting pattern %s\n", locale, u_errorName(*status) ); 2142 log_err("%s: Failure setting pattern %s\n", locale, u_errorName(*status) );
2106 } 2143 }
2107 2144
2108 if(!uset_containsNone(ref, set)) { 2145 if(!uset_containsNone(ref, set)) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2143 }, 2180 },
2144 { "sh", 2181 { "sh",
2145 "[{C\\u0301}{C\\u030C}{C\\u0341}{DZ\\u030C}{Dz\\u030C}{D\\u017D}{D\\ u017E}{lj}{nj}]", 2182 "[{C\\u0301}{C\\u030C}{C\\u0341}{DZ\\u030C}{Dz\\u030C}{D\\u017D}{D\\ u017E}{lj}{nj}]",
2146 "[{\\u309d\\u3099}{\\u30fd\\u3099}]", 2183 "[{\\u309d\\u3099}{\\u30fd\\u3099}]",
2147 "[\\u00e6]", 2184 "[\\u00e6]",
2148 "[a]", 2185 "[a]",
2149 "[nlcdzNLCDZ]", 2186 "[nlcdzNLCDZ]",
2150 "[jabv]" 2187 "[jabv]"
2151 }, 2188 },
2152 { "ja", 2189 { "ja",
2153 "[{\\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\\u3 099\\u30FD\\u3099}{\\u30B3\\u3099\\u30FE}{\\u30B3\\u30FC}{\\u30B3\\u30FD}{\\u30B 3\\u30FD\\u3099}{\\u30B3\\u30FE}]", 2190 /*
2191 * The "collv2" builder omits mappings if the collator maps their
2192 * character sequences to the same CEs.
2193 * For example, it omits Japanese contractions for NFD forms
2194 * of the voiced iteration mark (U+309E = U+309D + U+3099), such as
2195 * {\\u3053\\u3099\\u309D\\u3099}{\\u3053\\u309D\\u3099}
2196 * {\\u30B3\\u3099\\u30FD\\u3099}{\\u30B3\\u30FD\\u3099}.
2197 * It does add mappings for the precomposed forms.
2198 */
2199 "[{\\u3053\\u3099\\u309D}{\\u3053\\u3099\\u309E}{\\u3053\\u3099\\u30FC }"
2200 "{\\u3053\\u309D}{\\u3053\\u309E}{\\u3053\\u30FC}"
2201 "{\\u30B3\\u3099\\u30FC}{\\u30B3\\u3099\\u30FD}{\\u30B3\\u3099\\u30FE }"
2202 "{\\u30B3\\u30FC}{\\u30B3\\u30FD}{\\u30B3\\u30FE}]",
2154 "[{\\u30FD\\u3099}{\\u309D\\u3099}{\\u3053\\u3099}{\\u30B3\\u3099}{lj} {nj}]", 2203 "[{\\u30FD\\u3099}{\\u309D\\u3099}{\\u3053\\u3099}{\\u30B3\\u3099}{lj} {nj}]",
2155 "[\\u30FE\\u00e6]", 2204 "[\\u30FE\\u00e6]",
2156 "[a]", 2205 "[a]",
2157 "[\\u3099]", 2206 "[\\u3099]",
2158 "[]" 2207 "[]"
2159 } 2208 }
2160 }; 2209 };
2161 2210
2162
2163
2164
2165 UErrorCode status = U_ZERO_ERROR; 2211 UErrorCode status = U_ZERO_ERROR;
2166 UCollator *coll = NULL; 2212 UCollator *coll = NULL;
2167 int32_t i = 0; 2213 int32_t i = 0;
2168 int32_t noConts = 0; 2214 int32_t noConts = 0;
2169 USet *conts = uset_open(0,0); 2215 USet *conts = uset_open(0,0);
2170 USet *exp = uset_open(0, 0); 2216 USet *exp = uset_open(0, 0);
2171 USet *set = uset_open(0,0); 2217 USet *set = uset_open(0,0);
2172 int32_t setBufferLen = 65536; 2218 int32_t setBufferLen = 65536;
2173 UChar buffer[65536]; 2219 UChar buffer[65536];
2174 int32_t setLen = 0; 2220 int32_t setLen = 0;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2214 2260
2215 2261
2216 uset_close(conts); 2262 uset_close(conts);
2217 uset_close(exp); 2263 uset_close(exp);
2218 uset_close(set); 2264 uset_close(set);
2219 } 2265 }
2220 2266
2221 static void 2267 static void
2222 TestOpenBinary(void) 2268 TestOpenBinary(void)
2223 { 2269 {
2270 /*
2271 * ucol_openBinary() documents:
2272 * "The API also takes a base collator which usually should be UCA."
2273 * and
2274 * "Currently it cannot be NULL."
2275 *
2276 * However, the check for NULL was commented out in ICU 3.4 (r18149).
2277 * Ticket #4355 requested "Make collation work with minimal data.
2278 * Optionally without UCA, with relevant parts of UCA copied into the tailor ing table."
2279 *
2280 * The ICU team agreed with ticket #10517 "require base collator in ucol_ope nBinary() etc."
2281 * to require base!=NULL again.
2282 */
2283 #define OPEN_BINARY_ACCEPTS_NULL_BASE 0
2224 UErrorCode status = U_ZERO_ERROR; 2284 UErrorCode status = U_ZERO_ERROR;
2225 /* 2285 /*
2226 char rule[] = "&h < d < c < b"; 2286 char rule[] = "&h < d < c < b";
2227 char *wUCA[] = { "a", "h", "d", "c", "b", "i" }; 2287 char *wUCA[] = { "a", "h", "d", "c", "b", "i" };
2228 char *noUCA[] = {"d", "c", "b", "a", "h", "i" }; 2288 char *noUCA[] = {"d", "c", "b", "a", "h", "i" };
2229 */ 2289 */
2230 /* we have to use Cyrillic letters because latin-1 always gets copied */ 2290 /* we have to use Cyrillic letters because latin-1 always gets copied */
2231 const char rule[] = "&\\u0452 < \\u0434 < \\u0433 < \\u0432"; /* &dje < d < g < v */ 2291 const char rule[] = "&\\u0452 < \\u0434 < \\u0433 < \\u0432"; /* &dje < d < g < v */
2232 const char *wUCA[] = { "\\u0430", "\\u0452", "\\u0434", "\\u0433", "\\u0432" , "\\u0435" }; /* a, dje, d, g, v, e */ 2292 const char *wUCA[] = { "\\u0430", "\\u0452", "\\u0434", "\\u0433", "\\u0432" , "\\u0435" }; /* a, dje, d, g, v, e */
2293 #if OPEN_BINARY_ACCEPTS_NULL_BASE
2233 const char *noUCA[] = {"\\u0434", "\\u0433", "\\u0432", "\\u0430", "\\u0435" , "\\u0452" }; /* d, g, v, a, e, dje */ 2294 const char *noUCA[] = {"\\u0434", "\\u0433", "\\u0432", "\\u0430", "\\u0435" , "\\u0452" }; /* d, g, v, a, e, dje */
2295 #endif
2234 2296
2235 UChar uRules[256]; 2297 UChar uRules[256];
2236 int32_t uRulesLen = u_unescape(rule, uRules, 256); 2298 int32_t uRulesLen = u_unescape(rule, uRules, 256);
2237 2299
2238 UCollator *coll = ucol_openRules(uRules, uRulesLen, UCOL_DEFAULT, UCOL_DEFAU LT, NULL, &status); 2300 UCollator *coll = ucol_openRules(uRules, uRulesLen, UCOL_DEFAULT, UCOL_DEFAU LT, NULL, &status);
2239 UCollator *UCA = NULL; 2301 UCollator *UCA = NULL;
2240 UCollator *cloneNOUCA = NULL, *cloneWUCA = NULL; 2302 UCollator *cloneNOUCA = NULL, *cloneWUCA = NULL;
2241 2303
2242 uint8_t imageBuffer[32768]; 2304 uint8_t imageBuffer[32768];
2243 uint8_t *image = imageBuffer; 2305 uint8_t *image = imageBuffer;
(...skipping 15 matching lines...) Expand all
2259 imageSize = ucol_cloneBinary(coll, image, imageBufferCapacity, &status); 2321 imageSize = ucol_cloneBinary(coll, image, imageBufferCapacity, &status);
2260 if(U_FAILURE(status)) { 2322 if(U_FAILURE(status)) {
2261 image = (uint8_t *)malloc(imageSize*sizeof(uint8_t)); 2323 image = (uint8_t *)malloc(imageSize*sizeof(uint8_t));
2262 status = U_ZERO_ERROR; 2324 status = U_ZERO_ERROR;
2263 imageSize = ucol_cloneBinary(coll, imageBuffer, imageSize, &status); 2325 imageSize = ucol_cloneBinary(coll, imageBuffer, imageSize, &status);
2264 } 2326 }
2265 2327
2266 2328
2267 cloneWUCA = ucol_openBinary(image, imageSize, UCA, &status); 2329 cloneWUCA = ucol_openBinary(image, imageSize, UCA, &status);
2268 cloneNOUCA = ucol_openBinary(image, imageSize, NULL, &status); 2330 cloneNOUCA = ucol_openBinary(image, imageSize, NULL, &status);
2331 #if !OPEN_BINARY_ACCEPTS_NULL_BASE
2332 if(status != U_ILLEGAL_ARGUMENT_ERROR) {
2333 log_err("ucol_openBinary(base=NULL) unexpectedly did not fail - %s\n", u _errorName(status));
2334 }
2335 #endif
2269 2336
2270 genericOrderingTest(coll, wUCA, sizeof(wUCA)/sizeof(wUCA[0])); 2337 genericOrderingTest(coll, wUCA, sizeof(wUCA)/sizeof(wUCA[0]));
2271 2338
2272 genericOrderingTest(cloneWUCA, wUCA, sizeof(wUCA)/sizeof(wUCA[0])); 2339 genericOrderingTest(cloneWUCA, wUCA, sizeof(wUCA)/sizeof(wUCA[0]));
2340 #if OPEN_BINARY_ACCEPTS_NULL_BASE
2273 genericOrderingTest(cloneNOUCA, noUCA, sizeof(noUCA)/sizeof(noUCA[0])); 2341 genericOrderingTest(cloneNOUCA, noUCA, sizeof(noUCA)/sizeof(noUCA[0]));
2342 #endif
2274 2343
2275 if(image != imageBuffer) { 2344 if(image != imageBuffer) {
2276 free(image); 2345 free(image);
2277 } 2346 }
2278 ucol_close(coll); 2347 ucol_close(coll);
2279 ucol_close(cloneNOUCA); 2348 ucol_close(cloneNOUCA);
2280 ucol_close(cloneWUCA); 2349 ucol_close(cloneWUCA);
2281 ucol_close(UCA); 2350 ucol_close(UCA);
2282 } 2351 }
2283 2352
(...skipping 30 matching lines...) Expand all
2314 log_info("Warning: ucol_open(%s, ...) returned %s, at least it didn't cr ash.\n", loc, u_errorName(status)); 2383 log_info("Warning: ucol_open(%s, ...) returned %s, at least it didn't cr ash.\n", loc, u_errorName(status));
2315 } else if (status != U_USING_FALLBACK_WARNING) { 2384 } else if (status != U_USING_FALLBACK_WARNING) {
2316 /* Hmm, skip the following test for CLDR 1.9 data and/or ICU 4.6, no lon ger seems to apply */ 2385 /* Hmm, skip the following test for CLDR 1.9 data and/or ICU 4.6, no lon ger seems to apply */
2317 #if 0 2386 #if 0
2318 log_err("ucol_open(%s, ...) should return an error or some sort of U_USI NG_FALLBACK_WARNING, but returned %s\n", loc, u_errorName(status)); 2387 log_err("ucol_open(%s, ...) should return an error or some sort of U_USI NG_FALLBACK_WARNING, but returned %s\n", loc, u_errorName(status));
2319 #endif 2388 #endif
2320 } 2389 }
2321 ucol_close(coll); 2390 ucol_close(coll);
2322 } 2391 }
2323 2392
2393 static UBool uenum_contains(UEnumeration *e, const char *s, UErrorCode *status) {
2394 const char *t;
2395 uenum_reset(e, status);
2396 while(((t = uenum_next(e, NULL, status)) != NULL) && U_SUCCESS(*status)) {
2397 if(uprv_strcmp(s, t) == 0) {
2398 return TRUE;
2399 }
2400 }
2401 return FALSE;
2402 }
2403
2324 static void TestGetKeywordValuesForLocale(void) { 2404 static void TestGetKeywordValuesForLocale(void) {
2325 #define INCLUDE_UNIHAN_COLLATION 0
2326 #define PREFERRED_SIZE 16
2327 #define MAX_NUMBER_OF_KEYWORDS 9 2405 #define MAX_NUMBER_OF_KEYWORDS 9
2328 const char *PREFERRED[PREFERRED_SIZE][MAX_NUMBER_OF_KEYWORDS+1] = { 2406 const char *PREFERRED[][MAX_NUMBER_OF_KEYWORDS+1] = {
2329 { "und", "standard", "eor", "search", NULL, NULL, NULL, N ULL, NULL, NULL }, 2407 { "und", "standard", "eor", "search", NULL, NULL, NULL, N ULL, NULL, NULL },
2330 { "en_US", "standard", "eor", "search", NULL, NULL, NULL, N ULL, NULL, NULL }, 2408 { "en_US", "standard", "eor", "search", NULL, NULL, NULL, N ULL, NULL, NULL },
2331 { "en_029", "standard", "eor", "search", NULL, NULL, NULL, N ULL, NULL, NULL }, 2409 { "en_029", "standard", "eor", "search", NULL, NULL, NULL, N ULL, NULL, NULL },
2332 { "de_DE", "standard", "phonebook", "search", "eor", NULL, NULL, NULL, NULL, NULL }, 2410 { "de_DE", "standard", "phonebook", "search", "eor", NULL, NULL, NULL, NULL, NULL },
2333 { "de_Latn_DE", "standard", "phonebook", "search", "eor", NULL, NULL, NULL, NULL, NULL }, 2411 { "de_Latn_DE", "standard", "phonebook", "search", "eor", NULL, NULL, NULL, NULL, NULL },
2334 #if INCLUDE_UNIHAN_COLLATION 2412 { "zh", "pinyin", "stroke", "eor", "search", "standard", NULL },
2335 { "zh", "pinyin", "big5han", "gb2312han", "stroke", "uni han", "zhuyin", "eor", "search", "standard" }, 2413 { "zh_Hans", "pinyin", "stroke", "eor", "search", "standard", NULL },
2336 { "zh_Hans", "pinyin", "big5han", "gb2312han", "stroke", "uni han", "zhuyin", "eor", "search", "standard" }, 2414 { "zh_CN", "pinyin", "stroke", "eor", "search", "standard", NULL },
2337 { "zh_CN", "pinyin", "big5han", "gb2312han", "stroke", "uni han", "zhuyin", "eor", "search", "standard" }, 2415 { "zh_Hant", "stroke", "pinyin", "eor", "search", "standard", NULL },
2338 { "zh_Hant", "stroke", "big5han", "gb2312han", "pinyin", "uni han", "zhuyin", "eor", "search", "standard" }, 2416 { "zh_TW", "stroke", "pinyin", "eor", "search", "standard", NULL },
2339 { "zh_TW", "stroke", "big5han", "gb2312han", "pinyin", "uni han", "zhuyin", "eor", "search", "standard" }, 2417 { "zh__PINYIN", "pinyin", "stroke", "eor", "search", "standard", NULL },
2340 { "zh__PINYIN", "pinyin", "big5han", "gb2312han", "stroke", "uni han", "zhuyin", "eor", "search", "standard" },
2341 #else
2342 { "zh", "pinyin", "big5han", "gb2312han", "stroke", "zhu yin", "eor", "search", "standard", NULL },
2343 { "zh_Hans", "pinyin", "big5han", "gb2312han", "stroke", "zhu yin", "eor", "search", "standard", NULL },
2344 { "zh_CN", "pinyin", "big5han", "gb2312han", "stroke", "zhu yin", "eor", "search", "standard", NULL },
2345 { "zh_Hant", "stroke", "big5han", "gb2312han", "pinyin", "zhu yin", "eor", "search", "standard", NULL },
2346 { "zh_TW", "stroke", "big5han", "gb2312han", "pinyin", "zhu yin", "eor", "search", "standard", NULL },
2347 { "zh__PINYIN", "pinyin", "big5han", "gb2312han", "stroke", "zhu yin", "eor", "search", "standard", NULL },
2348 #endif
2349 { "es_ES", "standard", "search", "traditional", "eor", NULL , NULL, NULL, NULL, NULL }, 2418 { "es_ES", "standard", "search", "traditional", "eor", NULL , NULL, NULL, NULL, NULL },
2350 { "es__TRADITIONAL","traditional", "search", "standard", "eor", NULL , NULL, NULL, NULL, NULL }, 2419 { "es__TRADITIONAL","traditional", "search", "standard", "eor", NULL , NULL, NULL, NULL, NULL },
2351 { "und@collation=phonebook", "standard", "eor", "search", NULL, N ULL, NULL, NULL, NULL, NULL }, 2420 { "und@collation=phonebook", "standard", "eor", "search", NULL, N ULL, NULL, NULL, NULL, NULL },
2352 { "de_DE@collation=big5han", "standard", "phonebook", "search", " eor", NULL, NULL, NULL, NULL, NULL }, 2421 { "de_DE@collation=pinyin", "standard", "phonebook", "search", " eor", NULL, NULL, NULL, NULL, NULL },
2353 { "zzz@collation=xxx", "standard", "eor", "search", NULL, N ULL, NULL, NULL, NULL, NULL } 2422 { "zzz@collation=xxx", "standard", "eor", "search", NULL, N ULL, NULL, NULL, NULL, NULL }
2354 }; 2423 };
2355 #if INCLUDE_UNIHAN_COLLATION
2356 const int32_t expectedLength[PREFERRED_SIZE] = { 3, 3, 3, 4, 4, 9, 9, 9, 9, 9, 9, 4, 4, 3, 4, 3 };
2357 #else
2358 const int32_t expectedLength[PREFERRED_SIZE] = { 3, 3, 3, 4, 4, 8, 8, 8, 8, 8, 8, 4, 4, 3, 4, 3 };
2359 #endif
2360 2424
2361 UErrorCode status = U_ZERO_ERROR; 2425 UErrorCode status = U_ZERO_ERROR;
2362 UEnumeration *keywordValues = NULL; 2426 UEnumeration *keywordValues = NULL;
2363 int32_t i, n, size, valueLength; 2427 int32_t i, n, size, valueLength;
2364 const char *locale = NULL, *value = NULL; 2428 const char *locale = NULL, *value = NULL;
2365 UBool errorOccurred = FALSE; 2429 UBool errorOccurred = FALSE;
2366 2430
2367 for (i = 0; i < PREFERRED_SIZE; i++) { 2431 for (i = 0; i < UPRV_LENGTHOF(PREFERRED) && !errorOccurred; i++) {
2368 locale = PREFERRED[i][0]; 2432 locale = PREFERRED[i][0];
2369 value = NULL; 2433 value = NULL;
2370 valueLength = 0; 2434 valueLength = 0;
2371 size = 0; 2435 size = 0;
2372 2436
2373 keywordValues = ucol_getKeywordValuesForLocale("collation", locale, TRUE , &status); 2437 keywordValues = ucol_getKeywordValuesForLocale("collation", locale, TRUE , &status);
2374 if (keywordValues == NULL || U_FAILURE(status)) { 2438 if (keywordValues == NULL || U_FAILURE(status)) {
2375 log_err_status(status, "Error getting keyword values: %s\n", u_error Name(status)); 2439 log_err_status(status, "Error getting keyword values: %s\n", u_error Name(status));
2376 break; 2440 break;
2377 } 2441 }
2378 size = uenum_count(keywordValues, &status); 2442 size = uenum_count(keywordValues, &status);
2379 2443
2380 if (size == expectedLength[i]) { 2444 for (n = 0; (value = PREFERRED[i][n+1]) != NULL; n++) {
2381 for (n = 0; n < expectedLength[i]; n++) { 2445 if (!uenum_contains(keywordValues, value, &status)) {
2382 if ((value = uenum_next(keywordValues, &valueLength, &status)) ! = NULL && U_SUCCESS(status)) { 2446 if (U_SUCCESS(status)) {
2383 if (uprv_strcmp(value, PREFERRED[i][n+1]) != 0) { 2447 log_err("Keyword value \"%s\" missing for locale: %s\n", val ue, locale);
2384 log_err("Keyword values differ: Got [%s] Expected [%s] f or locale: %s\n", value, PREFERRED[i][n+1], locale);
2385 errorOccurred = TRUE;
2386 break;
2387 }
2388
2389 } else { 2448 } else {
2390 log_err("While getting keyword value from locale: %s got thi s error: %s\n", locale, u_errorName(status)); 2449 log_err("While getting keyword value from locale: %s got thi s error: %s\n", locale, u_errorName(status));
2391 errorOccurred = TRUE; 2450 errorOccurred = TRUE;
2392 break; 2451 break;
2393 } 2452 }
2394 } 2453 }
2395 if (errorOccurred) {
2396 break;
2397 }
2398 } else {
2399 log_err("Number of keywords (%d) does not match expected size (%d) f or locale: %s\n", size, expectedLength[i], locale);
2400 break;
2401 } 2454 }
2402 uenum_close(keywordValues); 2455 uenum_close(keywordValues);
2403 keywordValues = NULL; 2456 keywordValues = NULL;
2404 } 2457 }
2405 if (keywordValues != NULL) { 2458 uenum_close(keywordValues);
2406 uenum_close(keywordValues);
2407 }
2408 } 2459 }
2409 2460
2410 static void TestStrcollNull(void) { 2461 static void TestStrcollNull(void) {
2411 UErrorCode status = U_ZERO_ERROR; 2462 UErrorCode status = U_ZERO_ERROR;
2412 UCollator *coll; 2463 UCollator *coll;
2413 2464
2414 const UChar u16asc[] = {0x0049, 0x0042, 0x004D, 0}; 2465 const UChar u16asc[] = {0x0049, 0x0042, 0x004D, 0};
2415 const int32_t u16ascLen = 3; 2466 const int32_t u16ascLen = 3;
2416 2467
2417 const UChar u16han[] = {0x5c71, 0x5ddd, 0}; 2468 const UChar u16han[] = {0x5c71, 0x5ddd, 0};
2418 const int32_t u16hanLen = 2; 2469 const int32_t u16hanLen = 2;
2419 2470
2420 const char u8asc[] = {0x49, 0x42, 0x4D, 0}; 2471 const char *u8asc = "\x49\x42\x4D";
2421 const int32_t u8ascLen = 3; 2472 const int32_t u8ascLen = 3;
2422 2473
2423 const char u8han[] = {0xE5, 0xB1, 0xB1, 0xE5, 0xB7, 0x9D, 0}; 2474 const char *u8han = "\xE5\xB1\xB1\xE5\xB7\x9D";
2424 const int32_t u8hanLen = 6; 2475 const int32_t u8hanLen = 6;
2425 2476
2426 coll = ucol_open(NULL, &status); 2477 coll = ucol_open(NULL, &status);
2427 if (U_FAILURE(status)) { 2478 if (U_FAILURE(status)) {
2428 log_err_status(status, "Default Collator creation failed.: %s\n", myErro rName(status)); 2479 log_err_status(status, "Default Collator creation failed.: %s\n", myErro rName(status));
2429 return; 2480 return;
2430 } 2481 }
2431 2482
2432 /* UChar API */ 2483 /* UChar API */
2433 if (ucol_strcoll(coll, NULL, 0, NULL, 0) != 0) { 2484 if (ucol_strcoll(coll, NULL, 0, NULL, 0) != 0) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
2503 } 2554 }
2504 status = U_ZERO_ERROR; 2555 status = U_ZERO_ERROR;
2505 if (ucol_strcollUTF8(coll, NULL, 0, u8han, u8hanLen, &status) >= 0 || U_FAIL URE(status)) { 2556 if (ucol_strcollUTF8(coll, NULL, 0, u8han, u8hanLen, &status) >= 0 || U_FAIL URE(status)) {
2506 log_err("ERROR : ucol_strcollUTF8 NULL/0 and u8han/u8hanLen"); 2557 log_err("ERROR : ucol_strcollUTF8 NULL/0 and u8han/u8hanLen");
2507 } 2558 }
2508 2559
2509 ucol_close(coll); 2560 ucol_close(coll);
2510 } 2561 }
2511 2562
2512 #endif /* #if !UCONFIG_NO_COLLATION */ 2563 #endif /* #if !UCONFIG_NO_COLLATION */
OLDNEW
« no previous file with comments | « source/test/cintltst/callcoll.c ('k') | source/test/cintltst/cbiditst.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698