1 /******************************************************************** 2 * COPYRIGHT: 3 * Copyright (c) 1997-2015, International Business Machines Corporation and 4 * others. All Rights Reserved. 5 ********************************************************************/ 6 /******************************************************************************** 7 * 8 * File CBIAPTS.C 9 * 10 * Modification History: 11 * Name Description 12 * Madhu Katragadda Creation 13 *********************************************************************************/ 14 /*C API TEST FOR BREAKITERATOR */ 15 /** 16 * This is an API test. It doesn't test very many cases, and doesn't 17 * try to test the full functionality. It just calls each function in the class and 18 * verifies that it works on a basic level. 19 **/ 20 21 #include "unicode/utypes.h" 22 23 #if !UCONFIG_NO_BREAK_ITERATION 24 25 #include <stdlib.h> 26 #include <string.h> 27 #include "unicode/uloc.h" 28 #include "unicode/ubrk.h" 29 #include "unicode/ustring.h" 30 #include "unicode/ucnv.h" 31 #include "unicode/utext.h" 32 #include "cintltst.h" 33 #include "cbiapts.h" 34 #include "cmemory.h" 35 36 #define TEST_ASSERT_SUCCESS(status) {if (U_FAILURE(status)) { \ 37 log_data_err("Failure at file %s, line %d, error = %s (Are you missing data?)\n", __FILE__, __LINE__, u_errorName(status));}} 38 39 #define TEST_ASSERT(expr) {if ((expr)==FALSE) { \ 40 log_data_err("Test Failure at file %s, line %d (Are you missing data?)\n", __FILE__, __LINE__);}} 41 42 #if !UCONFIG_NO_FILE_IO 43 static void TestBreakIteratorSafeClone(void); 44 #endif 45 static void TestBreakIteratorRules(void); 46 static void TestBreakIteratorRuleError(void); 47 static void TestBreakIteratorStatusVec(void); 48 static void TestBreakIteratorUText(void); 49 static void TestBreakIteratorTailoring(void); 50 static void TestBreakIteratorRefresh(void); 51 static void TestBug11665(void); 52 static void TestBreakIteratorSuppressions(void); 53 54 void addBrkIterAPITest(TestNode** root); 55 56 void addBrkIterAPITest(TestNode** root) 57 { 58 #if !UCONFIG_NO_FILE_IO 59 addTest(root, &TestBreakIteratorCAPI, "tstxtbd/cbiapts/TestBreakIteratorCAPI"); 60 addTest(root, &TestBreakIteratorSafeClone, "tstxtbd/cbiapts/TestBreakIteratorSafeClone"); 61 addTest(root, &TestBreakIteratorUText, "tstxtbd/cbiapts/TestBreakIteratorUText"); 62 #endif 63 addTest(root, &TestBreakIteratorRules, "tstxtbd/cbiapts/TestBreakIteratorRules"); 64 addTest(root, &TestBreakIteratorRuleError, "tstxtbd/cbiapts/TestBreakIteratorRuleError"); 65 addTest(root, &TestBreakIteratorStatusVec, "tstxtbd/cbiapts/TestBreakIteratorStatusVec"); 66 addTest(root, &TestBreakIteratorTailoring, "tstxtbd/cbiapts/TestBreakIteratorTailoring"); 67 addTest(root, &TestBreakIteratorRefresh, "tstxtbd/cbiapts/TestBreakIteratorRefresh"); 68 addTest(root, &TestBug11665, "tstxtbd/cbiapts/TestBug11665"); 69 addTest(root, &TestBreakIteratorSuppressions, "tstxtbd/cbiapts/TestBreakIteratorSuppressions"); 70 } 71 72 #define CLONETEST_ITERATOR_COUNT 2 73 74 /* 75 * Utility function for converting char * to UChar * strings, to 76 * simplify the test code. Converted strings are put in heap allocated 77 * storage. A hook (probably a local in the caller's code) allows all 78 * strings converted with that hook to be freed with a single call. 79 */ 80 typedef struct StringStruct { 81 struct StringStruct *link; 82 UChar str[1]; 83 } StringStruct; 84 85 86 static UChar* toUChar(const char *src, void **freeHook) { 87 /* Structure of the memory that we allocate on the heap */ 88 89 int32_t numUChars; 90 int32_t destSize; 91 UChar stackBuf[2000 + sizeof(void *)/sizeof(UChar)]; 92 StringStruct *dest; 93 UConverter *cnv; 94 95 UErrorCode status = U_ZERO_ERROR; 96 if (src == NULL) { 97 return NULL; 98 }; 99 100 cnv = ucnv_open(NULL, &status); 101 if(U_FAILURE(status) || cnv == NULL) { 102 return NULL; 103 } 104 ucnv_reset(cnv); 105 numUChars = ucnv_toUChars(cnv, 106 stackBuf, 107 2000, 108 src, -1, 109 &status); 110 111 destSize = (numUChars+1) * sizeof(UChar) + sizeof(struct StringStruct); 112 dest = (StringStruct *)malloc(destSize); 113 if (dest != NULL) { 114 if (status == U_BUFFER_OVERFLOW_ERROR || status == U_STRING_NOT_TERMINATED_WARNING) { 115 ucnv_toUChars(cnv, dest->str, numUChars+1, src, -1, &status); 116 } else if (status == U_ZERO_ERROR) { 117 u_strcpy(dest->str, stackBuf); 118 } else { 119 free(dest); 120 dest = NULL; 121 } 122 } 123 124 ucnv_reset(cnv); /* be good citizens */ 125 ucnv_close(cnv); 126 if (dest == NULL) { 127 return NULL; 128 } 129 130 dest->link = (StringStruct*)(*freeHook); 131 *freeHook = dest; 132 return dest->str; 133 } 134 135 static void freeToUCharStrings(void **hook) { 136 StringStruct *s = *(StringStruct **)hook; 137 while (s != NULL) { 138 StringStruct *next = s->link; 139 free(s); 140 s = next; 141 } 142 } 143 144 145 #if !UCONFIG_NO_FILE_IO 146 static void TestBreakIteratorCAPI() 147 { 148 UErrorCode status = U_ZERO_ERROR; 149 UBreakIterator *word, *sentence, *line, *character, *b, *bogus; 150 int32_t start,pos,end,to; 151 int32_t i; 152 int32_t count = 0; 153 154 UChar text[50]; 155 156 /* Note: the adjacent "" are concatenating strings, not adding a \" to the 157 string, which is probably what whoever wrote this intended. Don't fix, 158 because it would throw off the hard coded break positions in the following 159 tests. */ 160 u_uastrcpy(text, "He's from Africa. ""Mr. Livingston, I presume?"" Yeah"); 161 162 163 /*test ubrk_open()*/ 164 log_verbose("\nTesting BreakIterator open functions\n"); 165 166 /* Use french for fun */ 167 word = ubrk_open(UBRK_WORD, "en_US", text, u_strlen(text), &status); 168 if(status == U_FILE_ACCESS_ERROR) { 169 log_data_err("Check your data - it doesn't seem to be around\n"); 170 return; 171 } else if(U_FAILURE(status)){ 172 log_err_status(status, "FAIL: Error in ubrk_open() for word breakiterator: %s\n", myErrorName(status)); 173 } 174 else{ 175 log_verbose("PASS: Successfully opened word breakiterator\n"); 176 } 177 178 sentence = ubrk_open(UBRK_SENTENCE, "en_US", text, u_strlen(text), &status); 179 if(U_FAILURE(status)){ 180 log_err_status(status, "FAIL: Error in ubrk_open() for sentence breakiterator: %s\n", myErrorName(status)); 181 return; 182 } 183 else{ 184 log_verbose("PASS: Successfully opened sentence breakiterator\n"); 185 } 186 187 line = ubrk_open(UBRK_LINE, "en_US", text, u_strlen(text), &status); 188 if(U_FAILURE(status)){ 189 log_err("FAIL: Error in ubrk_open() for line breakiterator: %s\n", myErrorName(status)); 190 return; 191 } 192 else{ 193 log_verbose("PASS: Successfully opened line breakiterator\n"); 194 } 195 196 character = ubrk_open(UBRK_CHARACTER, "en_US", text, u_strlen(text), &status); 197 if(U_FAILURE(status)){ 198 log_err("FAIL: Error in ubrk_open() for character breakiterator: %s\n", myErrorName(status)); 199 return; 200 } 201 else{ 202 log_verbose("PASS: Successfully opened character breakiterator\n"); 203 } 204 /*trying to open an illegal iterator*/ 205 bogus = ubrk_open((UBreakIteratorType)5, "en_US", text, u_strlen(text), &status); 206 if(bogus != NULL) { 207 log_err("FAIL: expected NULL from opening an invalid break iterator.\n"); 208 } 209 if(U_SUCCESS(status)){ 210 log_err("FAIL: Error in ubrk_open() for BOGUS breakiterator. Expected U_ILLEGAL_ARGUMENT_ERROR\n"); 211 } 212 if(U_FAILURE(status)){ 213 if(status != U_ILLEGAL_ARGUMENT_ERROR){ 214 log_err("FAIL: Error in ubrk_open() for BOGUS breakiterator. Expected U_ILLEGAL_ARGUMENT_ERROR\n Got %s\n", myErrorName(status)); 215 } 216 } 217 status=U_ZERO_ERROR; 218 219 220 /* ======= Test ubrk_countAvialable() and ubrk_getAvialable() */ 221 222 log_verbose("\nTesting ubrk_countAvailable() and ubrk_getAvailable()\n"); 223 count=ubrk_countAvailable(); 224 /* use something sensible w/o hardcoding the count */ 225 if(count < 0){ 226 log_err("FAIL: Error in ubrk_countAvialable() returned %d\n", count); 227 } 228 else{ 229 log_verbose("PASS: ubrk_countAvialable() successful returned %d\n", count); 230 } 231 for(i=0;i<count;i++) 232 { 233 log_verbose("%s\n", ubrk_getAvailable(i)); 234 if (ubrk_getAvailable(i) == 0) 235 log_err("No locale for which breakiterator is applicable\n"); 236 else 237 log_verbose("A locale %s for which breakiterator is applicable\n",ubrk_getAvailable(i)); 238 } 239 240 /*========Test ubrk_first(), ubrk_last()...... and other functions*/ 241 242 log_verbose("\nTesting the functions for word\n"); 243 start = ubrk_first(word); 244 if(start!=0) 245 log_err("error ubrk_start(word) did not return 0\n"); 246 log_verbose("first (word = %d\n", (int32_t)start); 247 pos=ubrk_next(word); 248 if(pos!=4) 249 log_err("error ubrk_next(word) did not return 4\n"); 250 log_verbose("next (word = %d\n", (int32_t)pos); 251 pos=ubrk_following(word, 4); 252 if(pos!=5) 253 log_err("error ubrl_following(word,4) did not return 6\n"); 254 log_verbose("next (word = %d\n", (int32_t)pos); 255 end=ubrk_last(word); 256 if(end!=49) 257 log_err("error ubrk_last(word) did not return 49\n"); 258 log_verbose("last (word = %d\n", (int32_t)end); 259 260 pos=ubrk_previous(word); 261 log_verbose("%d %d\n", end, pos); 262 263 pos=ubrk_previous(word); 264 log_verbose("%d \n", pos); 265 266 if (ubrk_isBoundary(word, 2) != FALSE) { 267 log_err("error ubrk_isBoundary(word, 2) did not return FALSE\n"); 268 } 269 pos=ubrk_current(word); 270 if (pos != 4) { 271 log_err("error ubrk_current() != 4 after ubrk_isBoundary(word, 2)\n"); 272 } 273 if (ubrk_isBoundary(word, 4) != TRUE) { 274 log_err("error ubrk_isBoundary(word, 4) did not return TRUE\n"); 275 } 276 277 278 279 log_verbose("\nTesting the functions for character\n"); 280 ubrk_first(character); 281 pos = ubrk_following(character, 5); 282 if(pos!=6) 283 log_err("error ubrk_following(character,5) did not return 6\n"); 284 log_verbose("Following (character,5) = %d\n", (int32_t)pos); 285 pos=ubrk_following(character, 18); 286 if(pos!=19) 287 log_err("error ubrk_following(character,18) did not return 19\n"); 288 log_verbose("Followingcharacter,18) = %d\n", (int32_t)pos); 289 pos=ubrk_preceding(character, 22); 290 if(pos!=21) 291 log_err("error ubrk_preceding(character,22) did not return 21\n"); 292 log_verbose("preceding(character,22) = %d\n", (int32_t)pos); 293 294 295 log_verbose("\nTesting the functions for line\n"); 296 pos=ubrk_first(line); 297 if(pos != 0) 298 log_err("error ubrk_first(line) returned %d, expected 0\n", (int32_t)pos); 299 pos = ubrk_next(line); 300 pos=ubrk_following(line, 18); 301 if(pos!=22) 302 log_err("error ubrk_following(line) did not return 22\n"); 303 log_verbose("following (line) = %d\n", (int32_t)pos); 304 305 306 log_verbose("\nTesting the functions for sentence\n"); 307 ubrk_first(sentence); 308 pos = ubrk_current(sentence); 309 log_verbose("Current(sentence) = %d\n", (int32_t)pos); 310 pos = ubrk_last(sentence); 311 if(pos!=49) 312 log_err("error ubrk_last for sentence did not return 49\n"); 313 log_verbose("Last (sentence) = %d\n", (int32_t)pos); 314 ubrk_first(sentence); 315 to = ubrk_following( sentence, 0 ); 316 if (to == 0) log_err("ubrk_following returned 0\n"); 317 to = ubrk_preceding( sentence, to ); 318 if (to != 0) log_err("ubrk_preceding didn't return 0\n"); 319 if (ubrk_first(sentence)!=ubrk_current(sentence)) { 320 log_err("error in ubrk_first() or ubrk_current()\n"); 321 } 322 323 324 /*---- */ 325 /*Testing ubrk_open and ubrk_close()*/ 326 log_verbose("\nTesting open and close for us locale\n"); 327 b = ubrk_open(UBRK_WORD, "fr_FR", text, u_strlen(text), &status); 328 if (U_FAILURE(status)) { 329 log_err("ubrk_open for word returned NULL: %s\n", myErrorName(status)); 330 } 331 ubrk_close(b); 332 333 /* Test setText and setUText */ 334 { 335 UChar s1[] = {0x41, 0x42, 0x20, 0}; 336 UChar s2[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0}; 337 UText *ut = NULL; 338 UBreakIterator *bb; 339 int j; 340 341 log_verbose("\nTesting ubrk_setText() and ubrk_setUText()\n"); 342 status = U_ZERO_ERROR; 343 bb = ubrk_open(UBRK_WORD, "en_US", NULL, 0, &status); 344 TEST_ASSERT_SUCCESS(status); 345 ubrk_setText(bb, s1, -1, &status); 346 TEST_ASSERT_SUCCESS(status); 347 ubrk_first(bb); 348 j = ubrk_next(bb); 349 TEST_ASSERT(j == 2); 350 ut = utext_openUChars(ut, s2, -1, &status); 351 ubrk_setUText(bb, ut, &status); 352 TEST_ASSERT_SUCCESS(status); 353 j = ubrk_next(bb); 354 TEST_ASSERT(j == 5); 355 356 ubrk_close(bb); 357 utext_close(ut); 358 } 359 360 ubrk_close(word); 361 ubrk_close(sentence); 362 ubrk_close(line); 363 ubrk_close(character); 364 } 365 366 static void TestBreakIteratorSafeClone(void) 367 { 368 UChar text[51]; /* Keep this odd to test for 64-bit memory alignment */ 369 /* NOTE: This doesn't reliably force mis-alignment of following items. */ 370 uint8_t buffer [CLONETEST_ITERATOR_COUNT] [U_BRK_SAFECLONE_BUFFERSIZE]; 371 int32_t bufferSize = U_BRK_SAFECLONE_BUFFERSIZE; 372 373 UBreakIterator * someIterators [CLONETEST_ITERATOR_COUNT]; 374 UBreakIterator * someClonedIterators [CLONETEST_ITERATOR_COUNT]; 375 376 UBreakIterator * brk; 377 UErrorCode status = U_ZERO_ERROR; 378 int32_t start,pos; 379 int32_t i; 380 381 /*Testing ubrk_safeClone */ 382 383 /* Note: the adjacent "" are concatenating strings, not adding a \" to the 384 string, which is probably what whoever wrote this intended. Don't fix, 385 because it would throw off the hard coded break positions in the following 386 tests. */ 387 u_uastrcpy(text, "He's from Africa. ""Mr. Livingston, I presume?"" Yeah"); 388 389 /* US & Thai - rule-based & dictionary based */ 390 someIterators[0] = ubrk_open(UBRK_WORD, "en_US", text, u_strlen(text), &status); 391 if(!someIterators[0] || U_FAILURE(status)) { 392 log_data_err("Couldn't open en_US word break iterator - %s\n", u_errorName(status)); 393 return; 394 } 395 396 someIterators[1] = ubrk_open(UBRK_WORD, "th_TH", text, u_strlen(text), &status); 397 if(!someIterators[1] || U_FAILURE(status)) { 398 log_data_err("Couldn't open th_TH word break iterator - %s\n", u_errorName(status)); 399 return; 400 } 401 402 /* test each type of iterator */ 403 for (i = 0; i < CLONETEST_ITERATOR_COUNT; i++) 404 { 405 406 /* Check the various error & informational states */ 407 408 /* Null status - just returns NULL */ 409 if (NULL != ubrk_safeClone(someIterators[i], buffer[i], &bufferSize, NULL)) 410 { 411 log_err("FAIL: Cloned Iterator failed to deal correctly with null status\n"); 412 } 413 /* error status - should return 0 & keep error the same */ 414 status = U_MEMORY_ALLOCATION_ERROR; 415 if (NULL != ubrk_safeClone(someIterators[i], buffer[i], &bufferSize, &status) || status != U_MEMORY_ALLOCATION_ERROR) 416 { 417 log_err("FAIL: Cloned Iterator failed to deal correctly with incoming error status\n"); 418 } 419 status = U_ZERO_ERROR; 420 421 /* Null buffer size pointer is ok */ 422 if (NULL == (brk = ubrk_safeClone(someIterators[i], buffer[i], NULL, &status)) || U_FAILURE(status)) 423 { 424 log_err("FAIL: Cloned Iterator failed to deal correctly with null bufferSize pointer\n"); 425 } 426 ubrk_close(brk); 427 status = U_ZERO_ERROR; 428 429 /* buffer size pointer is 0 - fill in pbufferSize with a size */ 430 bufferSize = 0; 431 if (NULL != ubrk_safeClone(someIterators[i], buffer[i], &bufferSize, &status) || 432 U_FAILURE(status) || bufferSize <= 0) 433 { 434 log_err("FAIL: Cloned Iterator failed a sizing request ('preflighting')\n"); 435 } 436 /* Verify our define is large enough */ 437 if (U_BRK_SAFECLONE_BUFFERSIZE < bufferSize) 438 { 439 log_err("FAIL: Pre-calculated buffer size is too small - %d but needed %d\n", U_BRK_SAFECLONE_BUFFERSIZE, bufferSize); 440 } 441 /* Verify we can use this run-time calculated size */ 442 if (NULL == (brk = ubrk_safeClone(someIterators[i], buffer[i], &bufferSize, &status)) || U_FAILURE(status)) 443 { 444 log_err("FAIL: Iterator can't be cloned with run-time size\n"); 445 } 446 if (brk) 447 ubrk_close(brk); 448 /* size one byte too small - should allocate & let us know */ 449 if (bufferSize > 1) { 450 --bufferSize; 451 } 452 if (NULL == (brk = ubrk_safeClone(someIterators[i], NULL, &bufferSize, &status)) || status != U_SAFECLONE_ALLOCATED_WARNING) 453 { 454 log_err("FAIL: Cloned Iterator failed to deal correctly with too-small buffer size\n"); 455 } 456 if (brk) 457 ubrk_close(brk); 458 status = U_ZERO_ERROR; 459 bufferSize = U_BRK_SAFECLONE_BUFFERSIZE; 460 461 /* Null buffer pointer - return Iterator & set error to U_SAFECLONE_ALLOCATED_ERROR */ 462 if (NULL == (brk = ubrk_safeClone(someIterators[i], NULL, &bufferSize, &status)) || status != U_SAFECLONE_ALLOCATED_WARNING) 463 { 464 log_err("FAIL: Cloned Iterator failed to deal correctly with null buffer pointer\n"); 465 } 466 if (brk) 467 ubrk_close(brk); 468 status = U_ZERO_ERROR; 469 470 /* Mis-aligned buffer pointer. */ 471 { 472 char stackBuf[U_BRK_SAFECLONE_BUFFERSIZE+sizeof(void *)]; 473 474 brk = ubrk_safeClone(someIterators[i], &stackBuf[1], &bufferSize, &status); 475 if (U_FAILURE(status) || brk == NULL) { 476 log_err("FAIL: Cloned Iterator failed with misaligned buffer pointer\n"); 477 } 478 if (status == U_SAFECLONE_ALLOCATED_WARNING) { 479 log_verbose("Cloned Iterator allocated when using a mis-aligned buffer.\n"); 480 } 481 if (brk) 482 ubrk_close(brk); 483 } 484 485 486 /* Null Iterator - return NULL & set U_ILLEGAL_ARGUMENT_ERROR */ 487 if (NULL != ubrk_safeClone(NULL, buffer[i], &bufferSize, &status) || status != U_ILLEGAL_ARGUMENT_ERROR) 488 { 489 log_err("FAIL: Cloned Iterator failed to deal correctly with null Iterator pointer\n"); 490 } 491 status = U_ZERO_ERROR; 492 493 /* Do these cloned Iterators work at all - make a first & next call */ 494 bufferSize = U_BRK_SAFECLONE_BUFFERSIZE; 495 someClonedIterators[i] = ubrk_safeClone(someIterators[i], buffer[i], &bufferSize, &status); 496 497 start = ubrk_first(someClonedIterators[i]); 498 if(start!=0) 499 log_err("error ubrk_start(clone) did not return 0\n"); 500 pos=ubrk_next(someClonedIterators[i]); 501 if(pos!=4) 502 log_err("error ubrk_next(clone) did not return 4\n"); 503 504 ubrk_close(someClonedIterators[i]); 505 ubrk_close(someIterators[i]); 506 } 507 } 508 #endif 509 510 511 /* 512 // Open a break iterator from char * rules. Take care of conversion 513 // of the rules and error checking. 514 */ 515 static UBreakIterator * testOpenRules(char *rules) { 516 UErrorCode status = U_ZERO_ERROR; 517 UChar *ruleSourceU = NULL; 518 void *strCleanUp = NULL; 519 UParseError parseErr; 520 UBreakIterator *bi; 521 522 ruleSourceU = toUChar(rules, &strCleanUp); 523 524 bi = ubrk_openRules(ruleSourceU, -1, /* The rules */ 525 NULL, -1, /* The text to be iterated over. */ 526 &parseErr, &status); 527 528 if (U_FAILURE(status)) { 529 log_data_err("FAIL: ubrk_openRules: ICU Error \"%s\" (Are you missing data?)\n", u_errorName(status)); 530 bi = 0; 531 }; 532 freeToUCharStrings(&strCleanUp); 533 return bi; 534 535 } 536 537 /* 538 * TestBreakIteratorRules - Verify that a break iterator can be created from 539 * a set of source rules. 540 */ 541 static void TestBreakIteratorRules() { 542 /* Rules will keep together any run of letters not including 'a', OR 543 * keep together 'abc', but only when followed by 'def', OTHERWISE 544 * just return one char at a time. 545 */ 546 char rules[] = "abc{666}/def;\n [\\p{L} - [a]]* {2}; . {1};"; 547 /* 0123456789012345678 */ 548 char data[] = "abcdex abcdefgh-def"; /* the test data string */ 549 char breaks[] = "** ** * ** *"; /* * the expected break positions */ 550 char tags[] = "01 21 6 21 2"; /* expected tag values at break positions */ 551 int32_t tagMap[] = {0, 1, 2, 3, 4, 5, 666}; 552 553 UChar *uData; 554 void *freeHook = NULL; 555 UErrorCode status = U_ZERO_ERROR; 556 int32_t pos; 557 int i; 558 559 UBreakIterator *bi = testOpenRules(rules); 560 if (bi == NULL) {return;} 561 uData = toUChar(data, &freeHook); 562 ubrk_setText(bi, uData, -1, &status); 563 564 pos = ubrk_first(bi); 565 for (i=0; i<sizeof(breaks); i++) { 566 if (pos == i && breaks[i] != '*') { 567 log_err("FAIL: unexpected break at position %d found\n", pos); 568 break; 569 } 570 if (pos != i && breaks[i] == '*') { 571 log_err("FAIL: expected break at position %d not found.\n", i); 572 break; 573 } 574 if (pos == i) { 575 int32_t tag, expectedTag; 576 tag = ubrk_getRuleStatus(bi); 577 expectedTag = tagMap[tags[i]&0xf]; 578 if (tag != expectedTag) { 579 log_err("FAIL: incorrect tag value. Position = %d; expected tag %d, got %d", 580 pos, expectedTag, tag); 581 break; 582 } 583 pos = ubrk_next(bi); 584 } 585 } 586 587 freeToUCharStrings(&freeHook); 588 ubrk_close(bi); 589 } 590 591 static void TestBreakIteratorRuleError() { 592 /* 593 * TestBreakIteratorRuleError - Try to create a BI from rules with syntax errors, 594 * check that the error is reported correctly. 595 */ 596 char rules[] = " # This is a rule comment on line 1\n" 597 "[:L:]; # this rule is OK.\n" 598 "abcdefg); # Error, mismatched parens\n"; 599 UChar *uRules; 600 void *freeHook = NULL; 601 UErrorCode status = U_ZERO_ERROR; 602 UParseError parseErr; 603 UBreakIterator *bi; 604 605 uRules = toUChar(rules, &freeHook); 606 bi = ubrk_openRules(uRules, -1, /* The rules */ 607 NULL, -1, /* The text to be iterated over. */ 608 &parseErr, &status); 609 if (U_SUCCESS(status)) { 610 log_err("FAIL: construction of break iterator succeeded when it should have failed.\n"); 611 ubrk_close(bi); 612 } else { 613 if (parseErr.line != 3 || parseErr.offset != 8) { 614 log_data_err("FAIL: incorrect error position reported. Got line %d, char %d, expected line 3, char 7 (Are you missing data?)\n", 615 parseErr.line, parseErr.offset); 616 } 617 } 618 freeToUCharStrings(&freeHook); 619 } 620 621 622 /* 623 * TestsBreakIteratorStatusVals() Test the ubrk_getRuleStatusVec() funciton 624 */ 625 static void TestBreakIteratorStatusVec() { 626 #define RULE_STRING_LENGTH 200 627 UChar rules[RULE_STRING_LENGTH]; 628 629 #define TEST_STRING_LENGTH 25 630 UChar testString[TEST_STRING_LENGTH]; 631 UBreakIterator *bi = NULL; 632 int32_t pos = 0; 633 int32_t vals[10]; 634 int32_t numVals; 635 UErrorCode status = U_ZERO_ERROR; 636 637 u_uastrncpy(rules, "[A-N]{100}; \n" 638 "[a-w]{200}; \n" 639 "[\\p{L}]{300}; \n" 640 "[\\p{N}]{400}; \n" 641 "[0-5]{500}; \n" 642 "!.*;\n", RULE_STRING_LENGTH); 643 u_uastrncpy(testString, "ABC", TEST_STRING_LENGTH); 644 645 646 bi = ubrk_openRules(rules, -1, testString, -1, NULL, &status); 647 TEST_ASSERT_SUCCESS(status); 648 TEST_ASSERT(bi != NULL); 649 650 /* The TEST_ASSERT above should change too... */ 651 if (bi != NULL) { 652 pos = ubrk_next(bi); 653 TEST_ASSERT(pos == 1); 654 655 memset(vals, -1, sizeof(vals)); 656 numVals = ubrk_getRuleStatusVec(bi, vals, 10, &status); 657 TEST_ASSERT_SUCCESS(status); 658 TEST_ASSERT(numVals == 2); 659 TEST_ASSERT(vals[0] == 100); 660 TEST_ASSERT(vals[1] == 300); 661 TEST_ASSERT(vals[2] == -1); 662 663 numVals = ubrk_getRuleStatusVec(bi, vals, 0, &status); 664 TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR); 665 TEST_ASSERT(numVals == 2); 666 } 667 668 ubrk_close(bi); 669 } 670 671 672 /* 673 * static void TestBreakIteratorUText(void); 674 * 675 * Test that ubrk_setUText() is present and works for a simple case. 676 */ 677 static void TestBreakIteratorUText(void) { 678 const char *UTF8Str = "\x41\xc3\x85\x5A\x20\x41\x52\x69\x6E\x67"; /* c3 85 is utf-8 for A with a ring on top */ 679 /* 0 1 2 34567890 */ 680 681 UErrorCode status = U_ZERO_ERROR; 682 UBreakIterator *bi = NULL; 683 int32_t pos = 0; 684 685 686 UText *ut = utext_openUTF8(NULL, UTF8Str, -1, &status); 687 TEST_ASSERT_SUCCESS(status); 688 689 bi = ubrk_open(UBRK_WORD, "en_US", NULL, 0, &status); 690 if (U_FAILURE(status)) { 691 log_err_status(status, "Failure at file %s, line %d, error = %s\n", __FILE__, __LINE__, u_errorName(status)); 692 return; 693 } 694 695 ubrk_setUText(bi, ut, &status); 696 if (U_FAILURE(status)) { 697 log_err("Failure at file %s, line %d, error = %s\n", __FILE__, __LINE__, u_errorName(status)); 698 return; 699 } 700 701 pos = ubrk_first(bi); 702 TEST_ASSERT(pos == 0); 703 704 pos = ubrk_next(bi); 705 TEST_ASSERT(pos == 4); 706 707 pos = ubrk_next(bi); 708 TEST_ASSERT(pos == 5); 709 710 pos = ubrk_next(bi); 711 TEST_ASSERT(pos == 10); 712 713 pos = ubrk_next(bi); 714 TEST_ASSERT(pos == UBRK_DONE); 715 ubrk_close(bi); 716 utext_close(ut); 717 } 718 719 /* 720 * static void TestBreakIteratorTailoring(void); 721 * 722 * Test break iterator tailorings from CLDR data. 723 */ 724 725 /* Thai/Lao grapheme break tailoring */ 726 static const UChar thTest[] = { 0x0020, 0x0E40, 0x0E01, 0x0020, 727 0x0E01, 0x0E30, 0x0020, 0x0E01, 0x0E33, 0x0020, 0 }; 728 /*in Unicode 6.1 en should behave just like th for this*/ 729 /*static const int32_t thTestOffs_enFwd[] = { 1, 3, 4, 6, 7, 9, 10 };*/ 730 static const int32_t thTestOffs_thFwd[] = { 1, 2, 3, 4, 5, 6, 7, 9, 10 }; 731 /*static const int32_t thTestOffs_enRev[] = { 9, 7, 6, 4, 3, 1, 0 };*/ 732 static const int32_t thTestOffs_thRev[] = { 9, 7, 6, 5, 4, 3, 2, 1, 0 }; 733 734 /* Hebrew line break tailoring, for cldrbug 3028 */ 735 static const UChar heTest[] = { 0x0020, 0x002D, 0x0031, 0x0032, 0x0020, 736 0x0061, 0x002D, 0x006B, 0x0020, 737 0x0061, 0x0300, 0x2010, 0x006B, 0x0020, 738 0x05DE, 0x05D4, 0x002D, 0x0069, 0x0020, 739 0x05D1, 0x05BC, 0x2010, 0x0047, 0x0020, 0 }; 740 /*in Unicode 6.1 en should behave just like he for this*/ 741 /*static const int32_t heTestOffs_enFwd[] = { 1, 5, 7, 9, 12, 14, 17, 19, 22, 24 };*/ 742 static const int32_t heTestOffs_heFwd[] = { 1, 5, 7, 9, 12, 14, 19, 24 }; 743 /*static const int32_t heTestOffs_enRev[] = { 22, 19, 17, 14, 12, 9, 7, 5, 1, 0 };*/ 744 static const int32_t heTestOffs_heRev[] = { 19, 14, 12, 9, 7, 5, 1, 0 }; 745 746 /* Finnish line break tailoring, for cldrbug 3029 */ 747 static const UChar fiTest[] = { /* 00 */ 0x0020, 0x002D, 0x0031, 0x0032, 0x0020, 748 /* 05 */ 0x0061, 0x002D, 0x006B, 0x0020, 749 /* 09 */ 0x0061, 0x0300, 0x2010, 0x006B, 0x0020, 750 /* 14 */ 0x0061, 0x0020, 0x002D, 0x006B, 0x0020, 751 /* 19 */ 0x0061, 0x0300, 0x0020, 0x2010, 0x006B, 0x0020, 0 }; 752 static const int32_t fiTestOffs_enFwd[] = { 1, 5, 7, 9, 12, 14, 16, 17, 19, 22, 23, 25 }; 753 static const int32_t fiTestOffs_fiFwd[] = { 1, 5, 7, 9, 12, 14, 16, 19, 22, 25 }; 754 static const int32_t fiTestOffs_enRev[] = { 23, 22, 19, 17, 16, 14, 12, 9, 7, 5, 1, 0 }; 755 static const int32_t fiTestOffs_fiRev[] = { 22, 19, 16, 14, 12, 9, 7, 5, 1, 0 }; 756 757 /* Khmer dictionary-based work break, for ICU ticket #8329 */ 758 static const UChar kmTest[] = { /* 00 */ 0x179F, 0x17BC, 0x1798, 0x1785, 0x17C6, 0x178E, 0x17B6, 0x1799, 0x1796, 0x17C1, 759 /* 10 */ 0x179B, 0x1794, 0x1793, 0x17D2, 0x178F, 0x17B7, 0x1785, 0x178A, 0x17BE, 0x1798, 760 /* 20 */ 0x17D2, 0x1794, 0x17B8, 0x17A2, 0x1792, 0x17B7, 0x179F, 0x17D2, 0x178B, 0x17B6, 761 /* 30 */ 0x1793, 0x17A2, 0x179A, 0x1796, 0x17D2, 0x179A, 0x17C7, 0x1782, 0x17BB, 0x178E, 762 /* 40 */ 0x178A, 0x179B, 0x17CB, 0x1796, 0x17D2, 0x179A, 0x17C7, 0x17A2, 0x1784, 0x17D2, 763 /* 50 */ 0x1782, 0 }; 764 static const int32_t kmTestOffs_kmFwd[] = { 3, /*8,*/ 11, 17, 23, 31, /*33,*/ 40, 43, 51 }; /* TODO: Investigate failure to break at offset 8 */ 765 static const int32_t kmTestOffs_kmRev[] = { 43, 40, /*33,*/ 31, 23, 17, 11, /*8,*/ 3, 0 }; 766 767 typedef struct { 768 const char * locale; 769 UBreakIteratorType type; 770 const UChar * test; 771 const int32_t * offsFwd; 772 const int32_t * offsRev; 773 int32_t numOffsets; 774 } RBBITailoringTest; 775 776 static const RBBITailoringTest tailoringTests[] = { 777 { "en", UBRK_CHARACTER, thTest, thTestOffs_thFwd, thTestOffs_thRev, sizeof(thTestOffs_thFwd)/sizeof(thTestOffs_thFwd[0]) }, 778 { "en_US_POSIX", UBRK_CHARACTER, thTest, thTestOffs_thFwd, thTestOffs_thRev, sizeof(thTestOffs_thFwd)/sizeof(thTestOffs_thFwd[0]) }, 779 { "en", UBRK_LINE, heTest, heTestOffs_heFwd, heTestOffs_heRev, sizeof(heTestOffs_heFwd)/sizeof(heTestOffs_heFwd[0]) }, 780 { "he", UBRK_LINE, heTest, heTestOffs_heFwd, heTestOffs_heRev, sizeof(heTestOffs_heFwd)/sizeof(heTestOffs_heFwd[0]) }, 781 { "en", UBRK_LINE, fiTest, fiTestOffs_enFwd, fiTestOffs_enRev, sizeof(fiTestOffs_enFwd)/sizeof(fiTestOffs_enFwd[0]) }, 782 { "fi", UBRK_LINE, fiTest, fiTestOffs_fiFwd, fiTestOffs_fiRev, sizeof(fiTestOffs_fiFwd)/sizeof(fiTestOffs_fiFwd[0]) }, 783 { "km", UBRK_WORD, kmTest, kmTestOffs_kmFwd, kmTestOffs_kmRev, sizeof(kmTestOffs_kmFwd)/sizeof(kmTestOffs_kmFwd[0]) }, 784 { NULL, 0, NULL, NULL, NULL, 0 }, 785 }; 786 787 static void TestBreakIteratorTailoring(void) { 788 const RBBITailoringTest * testPtr; 789 for (testPtr = tailoringTests; testPtr->locale != NULL; ++testPtr) { 790 UErrorCode status = U_ZERO_ERROR; 791 UBreakIterator* ubrkiter = ubrk_open(testPtr->type, testPtr->locale, testPtr->test, -1, &status); 792 if ( U_SUCCESS(status) ) { 793 int32_t offset, offsindx; 794 UBool foundError; 795 796 foundError = FALSE; 797 for (offsindx = 0; (offset = ubrk_next(ubrkiter)) != UBRK_DONE; ++offsindx) { 798 if (!foundError && offsindx >= testPtr->numOffsets) { 799 log_err("FAIL: locale %s, break type %d, ubrk_next expected UBRK_DONE, got %d\n", 800 testPtr->locale, testPtr->type, offset); 801 foundError = TRUE; 802 } else if (!foundError && offset != testPtr->offsFwd[offsindx]) { 803 log_err("FAIL: locale %s, break type %d, ubrk_next expected %d, got %d\n", 804 testPtr->locale, testPtr->type, testPtr->offsFwd[offsindx], offset); 805 foundError = TRUE; 806 } 807 } 808 if (!foundError && offsindx < testPtr->numOffsets) { 809 log_err("FAIL: locale %s, break type %d, ubrk_next expected %d, got UBRK_DONE\n", 810 testPtr->locale, testPtr->type, testPtr->offsFwd[offsindx]); 811 } 812 813 foundError = FALSE; 814 for (offsindx = 0; (offset = ubrk_previous(ubrkiter)) != UBRK_DONE; ++offsindx) { 815 if (!foundError && offsindx >= testPtr->numOffsets) { 816 log_err("FAIL: locale %s, break type %d, ubrk_previous expected UBRK_DONE, got %d\n", 817 testPtr->locale, testPtr->type, offset); 818 foundError = TRUE; 819 } else if (!foundError && offset != testPtr->offsRev[offsindx]) { 820 log_err("FAIL: locale %s, break type %d, ubrk_previous expected %d, got %d\n", 821 testPtr->locale, testPtr->type, testPtr->offsRev[offsindx], offset); 822 foundError = TRUE; 823 } 824 } 825 if (!foundError && offsindx < testPtr->numOffsets) { 826 log_err("FAIL: locale %s, break type %d, ubrk_previous expected %d, got UBRK_DONE\n", 827 testPtr->locale, testPtr->type, testPtr->offsRev[offsindx]); 828 } 829 830 ubrk_close(ubrkiter); 831 } else { 832 log_err_status(status, "FAIL: locale %s, break type %d, ubrk_open status: %s\n", testPtr->locale, testPtr->type, u_errorName(status)); 833 } 834 } 835 } 836 837 838 static void TestBreakIteratorRefresh(void) { 839 /* 840 * RefreshInput changes out the input of a Break Iterator without 841 * changing anything else in the iterator's state. Used with Java JNI, 842 * when Java moves the underlying string storage. This test 843 * runs a ubrk_next() repeatedly, moving the text in the middle of the sequence. 844 * The right set of boundaries should still be found. 845 */ 846 UChar testStr[] = {0x20, 0x41, 0x20, 0x42, 0x20, 0x43, 0x20, 0x44, 0x0}; /* = " A B C D" */ 847 UChar movedStr[] = {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0}; 848 UErrorCode status = U_ZERO_ERROR; 849 UBreakIterator *bi; 850 UText ut1 = UTEXT_INITIALIZER; 851 UText ut2 = UTEXT_INITIALIZER; 852 853 bi = ubrk_open(UBRK_LINE, "en_US", NULL, 0, &status); 854 TEST_ASSERT_SUCCESS(status); 855 if (U_FAILURE(status)) { 856 return; 857 } 858 859 utext_openUChars(&ut1, testStr, -1, &status); 860 TEST_ASSERT_SUCCESS(status); 861 ubrk_setUText(bi, &ut1, &status); 862 TEST_ASSERT_SUCCESS(status); 863 864 if (U_SUCCESS(status)) { 865 /* Line boundaries will occur before each letter in the original string */ 866 TEST_ASSERT(1 == ubrk_next(bi)); 867 TEST_ASSERT(3 == ubrk_next(bi)); 868 869 /* Move the string, kill the original string. */ 870 u_strcpy(movedStr, testStr); 871 u_memset(testStr, 0x20, u_strlen(testStr)); 872 utext_openUChars(&ut2, movedStr, -1, &status); 873 TEST_ASSERT_SUCCESS(status); 874 ubrk_refreshUText(bi, &ut2, &status); 875 TEST_ASSERT_SUCCESS(status); 876 877 /* Find the following matches, now working in the moved string. */ 878 TEST_ASSERT(5 == ubrk_next(bi)); 879 TEST_ASSERT(7 == ubrk_next(bi)); 880 TEST_ASSERT(8 == ubrk_next(bi)); 881 TEST_ASSERT(UBRK_DONE == ubrk_next(bi)); 882 TEST_ASSERT_SUCCESS(status); 883 884 utext_close(&ut1); 885 utext_close(&ut2); 886 } 887 ubrk_close(bi); 888 } 889 890 891 static void TestBug11665(void) { 892 // The problem was with the incorrect breaking of Japanese text beginning 893 // with Katakana characters when no prior Japanese or Chinese text had been 894 // encountered. 895 // 896 // Tested here in cintltst, rather than in intltest, because only cintltst 897 // tests have the ability to reset ICU, which is needed to get the bug 898 // to manifest itself. 899 900 static UChar japaneseText[] = {0x30A2, 0x30EC, 0x30EB, 0x30AE, 0x30FC, 0x6027, 0x7D50, 0x819C, 0x708E}; 901 int32_t boundaries[10] = {0}; 902 UBreakIterator *bi = NULL; 903 int32_t brk; 904 int32_t brkIdx = 0; 905 int32_t totalBreaks = 0; 906 UErrorCode status = U_ZERO_ERROR; 907 908 ctest_resetICU(); 909 bi = ubrk_open(UBRK_WORD, "en_US", japaneseText, UPRV_LENGTHOF(japaneseText), &status); 910 TEST_ASSERT_SUCCESS(status); 911 if (!bi) { 912 return; 913 } 914 for (brk=ubrk_first(bi); brk != UBRK_DONE; brk=ubrk_next(bi)) { 915 boundaries[brkIdx] = brk; 916 if (++brkIdx >= UPRV_LENGTHOF(boundaries) - 1) { 917 break; 918 } 919 } 920 if (brkIdx <= 2 || brkIdx >= UPRV_LENGTHOF(boundaries)) { 921 log_err("%s:%d too few or many breaks found.\n", __FILE__, __LINE__); 922 } else { 923 totalBreaks = brkIdx; 924 brkIdx = 0; 925 for (brk=ubrk_first(bi); brk != UBRK_DONE; brk=ubrk_next(bi)) { 926 if (brk != boundaries[brkIdx]) { 927 log_err("%s:%d Break #%d differs between first and second iteration.\n", __FILE__, __LINE__, brkIdx); 928 break; 929 } 930 if (++brkIdx >= UPRV_LENGTHOF(boundaries) - 1) { 931 log_err("%s:%d Too many breaks.\n", __FILE__, __LINE__); 932 break; 933 } 934 } 935 if (totalBreaks != brkIdx) { 936 log_err("%s:%d Number of breaks differ between first and second iteration.\n", __FILE__, __LINE__); 937 } 938 } 939 ubrk_close(bi); 940 } 941 942 /* 943 * expOffset is the set of expected offsets, ending with '-1'. 944 * "Expected expOffset -1" means "expected the end of the offsets" 945 */ 946 947 static const char testSentenceSuppressionsEn[] = "Mr. Jones comes home. Dr. Smith Ph.D. is out. In the U.S.A. it is hot."; 948 static const int32_t testSentSuppFwdOffsetsEn[] = { 22, 26, 46, 70, -1 }; /* With suppressions, currently not handling Dr. */ 949 static const int32_t testSentFwdOffsetsEn[] = { 4, 22, 26, 46, 70, -1 }; /* Without suppressions */ 950 static const int32_t testSentSuppRevOffsetsEn[] = { 46, 26, 22, 0, -1 }; /* With suppressions, currently not handling Dr. */ 951 static const int32_t testSentRevOffsetsEn[] = { 46, 26, 22, 4, 0, -1 }; /* Without suppressions */ 952 953 static const char testSentenceSuppressionsDe[] = "Wenn ich schon h\\u00F6re zu Guttenberg kommt evtl. zur\\u00FCck."; 954 static const int32_t testSentSuppFwdOffsetsDe[] = { 53, -1 }; /* With suppressions */ 955 static const int32_t testSentFwdOffsetsDe[] = { 53, -1 }; /* Without suppressions; no break in evtl. zur due to casing */ 956 static const int32_t testSentSuppRevOffsetsDe[] = { 0, -1 }; /* With suppressions */ 957 static const int32_t testSentRevOffsetsDe[] = { 0, -1 }; /* Without suppressions */ 958 959 static const char testSentenceSuppressionsEs[] = "Te esperamos todos los miercoles en Bravo 416, Col. El Pueblo a las 7 PM."; 960 static const int32_t testSentSuppFwdOffsetsEs[] = { 73, -1 }; /* With suppressions */ 961 static const int32_t testSentFwdOffsetsEs[] = { 52, 73, -1 }; /* Without suppressions */ 962 static const int32_t testSentSuppRevOffsetsEs[] = { 0, -1 }; /* With suppressions */ 963 static const int32_t testSentRevOffsetsEs[] = { 52, 0, -1 }; /* Without suppressions */ 964 965 enum { kTextULenMax = 128 }; 966 967 typedef struct { 968 const char * locale; 969 const char * text; 970 const int32_t * expFwdOffsets; 971 const int32_t * expRevOffsets; 972 } TestBISuppressionsItem; 973 974 static const TestBISuppressionsItem testBISuppressionsItems[] = { 975 { "en@ss=standard", testSentenceSuppressionsEn, testSentSuppFwdOffsetsEn, testSentSuppRevOffsetsEn }, 976 { "en", testSentenceSuppressionsEn, testSentFwdOffsetsEn, testSentRevOffsetsEn }, 977 { "fr@ss=standard", testSentenceSuppressionsEn, testSentFwdOffsetsEn, testSentRevOffsetsEn }, 978 { "af@ss=standard", testSentenceSuppressionsEn, testSentSuppFwdOffsetsEn, testSentSuppRevOffsetsEn }, /* no brkiter data => en suppressions? */ 979 { "zh@ss=standard", testSentenceSuppressionsEn, testSentFwdOffsetsEn, testSentRevOffsetsEn }, /* brkiter data, no suppressions data => no suppressions */ 980 { "zh_Hant@ss=standard", testSentenceSuppressionsEn, testSentFwdOffsetsEn, testSentRevOffsetsEn }, /* brkiter data, no suppressions data => no suppressions */ 981 { "fi@ss=standard", testSentenceSuppressionsEn, testSentFwdOffsetsEn, testSentRevOffsetsEn }, /* brkiter data, no suppressions data => no suppressions */ 982 { "ja@ss=standard", testSentenceSuppressionsEn, testSentFwdOffsetsEn, testSentRevOffsetsEn }, /* brkiter data, no suppressions data => no suppressions */ 983 { "de@ss=standard", testSentenceSuppressionsDe, testSentSuppFwdOffsetsDe, testSentSuppRevOffsetsDe }, 984 { "de", testSentenceSuppressionsDe, testSentFwdOffsetsDe, testSentRevOffsetsDe }, 985 { "es@ss=standard", testSentenceSuppressionsEs, testSentSuppFwdOffsetsEs, testSentSuppRevOffsetsEs }, 986 { "es", testSentenceSuppressionsEs, testSentFwdOffsetsEs, testSentRevOffsetsEs }, 987 { NULL, NULL, NULL } 988 }; 989 990 static void TestBreakIteratorSuppressions(void) { 991 const TestBISuppressionsItem * itemPtr; 992 993 for (itemPtr = testBISuppressionsItems; itemPtr->locale != NULL; itemPtr++) { 994 UChar textU[kTextULenMax]; 995 int32_t textULen = u_unescape(itemPtr->text, textU, kTextULenMax); 996 UErrorCode status = U_ZERO_ERROR; 997 UBreakIterator *bi = ubrk_open(UBRK_SENTENCE, itemPtr->locale, textU, textULen, &status); 998 log_verbose("#%d: %s\n", (itemPtr-testBISuppressionsItems), itemPtr->locale); 999 if (U_SUCCESS(status)) { 1000 int32_t offset, start; 1001 const int32_t * expOffsetPtr; 1002 const int32_t * expOffsetStart; 1003 1004 expOffsetStart = expOffsetPtr = itemPtr->expFwdOffsets; 1005 ubrk_first(bi); 1006 for (; (offset = ubrk_next(bi)) != UBRK_DONE && *expOffsetPtr >= 0; expOffsetPtr++) { 1007 if (offset != *expOffsetPtr) { 1008 log_err("FAIL: ubrk_next loc \"%s\", expected %d, got %d\n", itemPtr->locale, *expOffsetPtr, offset); 1009 } 1010 } 1011 if (offset != UBRK_DONE || *expOffsetPtr >= 0) { 1012 log_err("FAIL: ubrk_next loc \"%s\", expected UBRK_DONE & expOffset -1, got %d and %d\n", itemPtr->locale, offset, *expOffsetPtr); 1013 } 1014 1015 expOffsetStart = expOffsetPtr = itemPtr->expFwdOffsets; 1016 start = ubrk_first(bi) + 1; 1017 for (; (offset = ubrk_following(bi, start)) != UBRK_DONE && *expOffsetPtr >= 0; expOffsetPtr++) { 1018 if (offset != *expOffsetPtr) { 1019 log_err("FAIL: ubrk_following(%d) loc \"%s\", expected %d, got %d\n", start, itemPtr->locale, *expOffsetPtr, offset); 1020 } 1021 start = *expOffsetPtr + 1; 1022 } 1023 if (offset != UBRK_DONE || *expOffsetPtr >= 0) { 1024 log_err("FAIL: ubrk_following(%d) loc \"%s\", expected UBRK_DONE & expOffset -1, got %d and %d\n", start, itemPtr->locale, offset, *expOffsetPtr); 1025 } 1026 1027 expOffsetStart = expOffsetPtr = itemPtr->expRevOffsets; 1028 offset = ubrk_last(bi); 1029 log_verbose("___ @%d ubrk_last\n", offset); 1030 if(offset == 0) { 1031 log_err("FAIL: ubrk_last loc \"%s\" unexpected %d\n", itemPtr->locale, offset); 1032 } 1033 for (; (offset = ubrk_previous(bi)) != UBRK_DONE && *expOffsetPtr >= 0; expOffsetPtr++) { 1034 if (offset != *expOffsetPtr) { 1035 log_err("FAIL: ubrk_previous loc \"%s\", expected %d, got %d\n", itemPtr->locale, *expOffsetPtr, offset); 1036 } else { 1037 log_verbose("[%d] @%d ubrk_previous()\n", (expOffsetPtr - expOffsetStart), offset); 1038 } 1039 } 1040 if (offset != UBRK_DONE || *expOffsetPtr >= 0) { 1041 log_err("FAIL: ubrk_previous loc \"%s\", expected UBRK_DONE & expOffset[%d] -1, got %d and %d\n", itemPtr->locale, 1042 expOffsetPtr - expOffsetStart, 1043 offset, *expOffsetPtr); 1044 } 1045 1046 expOffsetStart = expOffsetPtr = itemPtr->expRevOffsets; 1047 start = ubrk_last(bi) - 1; 1048 for (; (offset = ubrk_preceding(bi, start)) != UBRK_DONE && *expOffsetPtr >= 0; expOffsetPtr++) { 1049 if (offset != *expOffsetPtr) { 1050 log_err("FAIL: ubrk_preceding(%d) loc \"%s\", expected %d, got %d\n", start, itemPtr->locale, *expOffsetPtr, offset); 1051 } 1052 start = *expOffsetPtr - 1; 1053 } 1054 if (start >=0 && (offset != UBRK_DONE || *expOffsetPtr >= 0)) { 1055 log_err("FAIL: ubrk_preceding loc(%d) \"%s\", expected UBRK_DONE & expOffset -1, got %d and %d\n", start, itemPtr->locale, offset, *expOffsetPtr); 1056 } 1057 1058 ubrk_close(bi); 1059 } else { 1060 log_data_err("FAIL: ubrk_open(UBRK_SENTENCE, \"%s\", ...) status %s (Are you missing data?)\n", itemPtr->locale, u_errorName(status)); 1061 } 1062 } 1063 } 1064 1065 1066 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */ 1067