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