1 /********************************************************************
3 * Copyright (c) 1997-2016, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /********************************************************************************
10 * Modification History:
12 * Madhu Katragadda Creation
13 *********************************************************************************/
14 /*C API TEST FOR BREAKITERATOR */
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.
21 #include "unicode/utypes.h"
23 #if !UCONFIG_NO_BREAK_ITERATION
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"
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));}}
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__);}}
42 #if !UCONFIG_NO_FILE_IO
43 static void TestBreakIteratorSafeClone(void);
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);
54 void addBrkIterAPITest(TestNode
** root
);
56 void addBrkIterAPITest(TestNode
** root
)
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");
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");
72 #define CLONETEST_ITERATOR_COUNT 2
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.
80 typedef struct StringStruct
{
81 struct StringStruct
*link
;
86 static UChar
* toUChar(const char *src
, void **freeHook
) {
87 /* Structure of the memory that we allocate on the heap */
91 UChar stackBuf
[2000 + sizeof(void *)/sizeof(UChar
)];
95 UErrorCode status
= U_ZERO_ERROR
;
100 cnv
= ucnv_open(NULL
, &status
);
101 if(U_FAILURE(status
) || cnv
== NULL
) {
105 numUChars
= ucnv_toUChars(cnv
,
111 destSize
= (numUChars
+1) * sizeof(UChar
) + sizeof(struct StringStruct
);
112 dest
= (StringStruct
*)malloc(destSize
);
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
);
124 ucnv_reset(cnv
); /* be good citizens */
130 dest
->link
= (StringStruct
*)(*freeHook
);
135 static void freeToUCharStrings(void **hook
) {
136 StringStruct
*s
= *(StringStruct
**)hook
;
138 StringStruct
*next
= s
->link
;
145 #if !UCONFIG_NO_FILE_IO
146 static void TestBreakIteratorCAPI()
148 UErrorCode status
= U_ZERO_ERROR
;
149 UBreakIterator
*word
, *sentence
, *line
, *character
, *b
, *bogus
;
150 int32_t start
,pos
,end
,to
;
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
160 u_uastrcpy(text
, "He's from Africa. ""Mr. Livingston, I presume?"" Yeah");
164 log_verbose("\nTesting BreakIterator open functions\n");
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");
171 } else if(U_FAILURE(status
)){
172 log_err_status(status
, "FAIL: Error in ubrk_open() for word breakiterator: %s\n", myErrorName(status
));
175 log_verbose("PASS: Successfully opened word breakiterator\n");
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
));
184 log_verbose("PASS: Successfully opened sentence breakiterator\n");
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
));
193 log_verbose("PASS: Successfully opened line breakiterator\n");
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
));
202 log_verbose("PASS: Successfully opened character breakiterator\n");
204 /*trying to open an illegal iterator*/
205 bogus
= ubrk_open((UBreakIteratorType
)5, "en_US", text
, u_strlen(text
), &status
);
207 log_err("FAIL: expected NULL from opening an invalid break iterator.\n");
209 if(U_SUCCESS(status
)){
210 log_err("FAIL: Error in ubrk_open() for BOGUS breakiterator. Expected U_ILLEGAL_ARGUMENT_ERROR\n");
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
));
220 /* ======= Test ubrk_countAvialable() and ubrk_getAvialable() */
222 log_verbose("\nTesting ubrk_countAvailable() and ubrk_getAvailable()\n");
223 count
=ubrk_countAvailable();
224 /* use something sensible w/o hardcoding the count */
226 log_err("FAIL: Error in ubrk_countAvialable() returned %d\n", count
);
229 log_verbose("PASS: ubrk_countAvialable() successful returned %d\n", count
);
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");
237 log_verbose("A locale %s for which breakiterator is applicable\n",ubrk_getAvailable(i
));
240 /*========Test ubrk_first(), ubrk_last()...... and other functions*/
242 log_verbose("\nTesting the functions for word\n");
243 start
= ubrk_first(word
);
245 log_err("error ubrk_start(word) did not return 0\n");
246 log_verbose("first (word = %d\n", (int32_t)start
);
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);
253 log_err("error ubrl_following(word,4) did not return 6\n");
254 log_verbose("next (word = %d\n", (int32_t)pos
);
257 log_err("error ubrk_last(word) did not return 49\n");
258 log_verbose("last (word = %d\n", (int32_t)end
);
260 pos
=ubrk_previous(word
);
261 log_verbose("%d %d\n", end
, pos
);
263 pos
=ubrk_previous(word
);
264 log_verbose("%d \n", pos
);
266 if (ubrk_isBoundary(word
, 2) != FALSE
) {
267 log_err("error ubrk_isBoundary(word, 2) did not return FALSE\n");
269 pos
=ubrk_current(word
);
271 log_err("error ubrk_current() != 4 after ubrk_isBoundary(word, 2)\n");
273 if (ubrk_isBoundary(word
, 4) != TRUE
) {
274 log_err("error ubrk_isBoundary(word, 4) did not return TRUE\n");
279 log_verbose("\nTesting the functions for character\n");
280 ubrk_first(character
);
281 pos
= ubrk_following(character
, 5);
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);
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);
291 log_err("error ubrk_preceding(character,22) did not return 21\n");
292 log_verbose("preceding(character,22) = %d\n", (int32_t)pos
);
295 log_verbose("\nTesting the functions for line\n");
296 pos
=ubrk_first(line
);
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);
302 log_err("error ubrk_following(line) did not return 22\n");
303 log_verbose("following (line) = %d\n", (int32_t)pos
);
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
);
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");
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
));
333 /* Test setText and setUText */
335 UChar s1
[] = {0x41, 0x42, 0x20, 0};
336 UChar s2
[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0};
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
);
350 ut
= utext_openUChars(ut
, s2
, -1, &status
);
351 ubrk_setUText(bb
, ut
, &status
);
352 TEST_ASSERT_SUCCESS(status
);
361 ubrk_close(sentence
);
363 ubrk_close(character
);
366 static void TestBreakIteratorSafeClone(void)
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
;
373 UBreakIterator
* someIterators
[CLONETEST_ITERATOR_COUNT
];
374 UBreakIterator
* someClonedIterators
[CLONETEST_ITERATOR_COUNT
];
376 UBreakIterator
* brk
;
377 UErrorCode status
= U_ZERO_ERROR
;
381 /*Testing ubrk_safeClone */
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
387 u_uastrcpy(text
, "He's from Africa. ""Mr. Livingston, I presume?"" Yeah");
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
));
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
));
402 /* test each type of iterator */
403 for (i
= 0; i
< CLONETEST_ITERATOR_COUNT
; i
++)
406 /* Check the various error & informational states */
408 /* Null status - just returns NULL */
409 if (NULL
!= ubrk_safeClone(someIterators
[i
], buffer
[i
], &bufferSize
, NULL
))
411 log_err("FAIL: Cloned Iterator failed to deal correctly with null status\n");
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
)
417 log_err("FAIL: Cloned Iterator failed to deal correctly with incoming error status\n");
419 status
= U_ZERO_ERROR
;
421 /* Null buffer size pointer is ok */
422 if (NULL
== (brk
= ubrk_safeClone(someIterators
[i
], buffer
[i
], NULL
, &status
)) || U_FAILURE(status
))
424 log_err("FAIL: Cloned Iterator failed to deal correctly with null bufferSize pointer\n");
427 status
= U_ZERO_ERROR
;
429 /* buffer size pointer is 0 - fill in pbufferSize with a size */
431 if (NULL
!= ubrk_safeClone(someIterators
[i
], buffer
[i
], &bufferSize
, &status
) ||
432 U_FAILURE(status
) || bufferSize
<= 0)
434 log_err("FAIL: Cloned Iterator failed a sizing request ('preflighting')\n");
436 /* Verify our define is large enough */
437 if (U_BRK_SAFECLONE_BUFFERSIZE
< bufferSize
)
439 log_err("FAIL: Pre-calculated buffer size is too small - %d but needed %d\n", U_BRK_SAFECLONE_BUFFERSIZE
, bufferSize
);
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
))
444 log_err("FAIL: Iterator can't be cloned with run-time size\n");
448 /* size one byte too small - should allocate & let us know */
449 if (bufferSize
> 1) {
452 if (NULL
== (brk
= ubrk_safeClone(someIterators
[i
], NULL
, &bufferSize
, &status
)) || status
!= U_SAFECLONE_ALLOCATED_WARNING
)
454 log_err("FAIL: Cloned Iterator failed to deal correctly with too-small buffer size\n");
458 status
= U_ZERO_ERROR
;
459 bufferSize
= U_BRK_SAFECLONE_BUFFERSIZE
;
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
)
464 log_err("FAIL: Cloned Iterator failed to deal correctly with null buffer pointer\n");
468 status
= U_ZERO_ERROR
;
470 /* Mis-aligned buffer pointer. */
472 char stackBuf
[U_BRK_SAFECLONE_BUFFERSIZE
+sizeof(void *)];
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");
478 if (status
== U_SAFECLONE_ALLOCATED_WARNING
) {
479 log_verbose("Cloned Iterator allocated when using a mis-aligned buffer.\n");
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
)
489 log_err("FAIL: Cloned Iterator failed to deal correctly with null Iterator pointer\n");
491 status
= U_ZERO_ERROR
;
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
);
497 start
= ubrk_first(someClonedIterators
[i
]);
499 log_err("error ubrk_start(clone) did not return 0\n");
500 pos
=ubrk_next(someClonedIterators
[i
]);
502 log_err("error ubrk_next(clone) did not return 4\n");
504 ubrk_close(someClonedIterators
[i
]);
505 ubrk_close(someIterators
[i
]);
512 // Open a break iterator from char * rules. Take care of conversion
513 // of the rules and error checking.
515 static UBreakIterator
* testOpenRules(char *rules
) {
516 UErrorCode status
= U_ZERO_ERROR
;
517 UChar
*ruleSourceU
= NULL
;
518 void *strCleanUp
= NULL
;
519 UParseError parseErr
;
522 ruleSourceU
= toUChar(rules
, &strCleanUp
);
524 bi
= ubrk_openRules(ruleSourceU
, -1, /* The rules */
525 NULL
, -1, /* The text to be iterated over. */
528 if (U_FAILURE(status
)) {
529 log_data_err("FAIL: ubrk_openRules: ICU Error \"%s\" (Are you missing data?)\n", u_errorName(status
));
532 freeToUCharStrings(&strCleanUp
);
538 * TestBreakIteratorRules - Verify that a break iterator can be created from
539 * a set of source rules.
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.
546 char rules
[] = "abc/def{666};\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};
554 void *freeHook
= NULL
;
555 UErrorCode status
= U_ZERO_ERROR
;
559 UBreakIterator
*bi
= testOpenRules(rules
);
560 if (bi
== NULL
) {return;}
561 uData
= toUChar(data
, &freeHook
);
562 ubrk_setText(bi
, uData
, -1, &status
);
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
);
570 if (pos
!= i
&& breaks
[i
] == '*') {
571 log_err("FAIL: expected break at position %d not found.\n", 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
);
587 freeToUCharStrings(&freeHook
);
591 static void TestBreakIteratorRuleError() {
593 * TestBreakIteratorRuleError - Try to create a BI from rules with syntax errors,
594 * check that the error is reported correctly.
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";
600 void *freeHook
= NULL
;
601 UErrorCode status
= U_ZERO_ERROR
;
602 UParseError parseErr
;
605 uRules
= toUChar(rules
, &freeHook
);
606 bi
= ubrk_openRules(uRules
, -1, /* The rules */
607 NULL
, -1, /* The text to be iterated over. */
609 if (U_SUCCESS(status
)) {
610 log_err("FAIL: construction of break iterator succeeded when it should have failed.\n");
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
);
618 freeToUCharStrings(&freeHook
);
623 * TestsBreakIteratorStatusVals() Test the ubrk_getRuleStatusVec() funciton
625 static void TestBreakIteratorStatusVec() {
626 #define RULE_STRING_LENGTH 200
627 UChar rules
[RULE_STRING_LENGTH
];
629 #define TEST_STRING_LENGTH 25
630 UChar testString
[TEST_STRING_LENGTH
];
631 UBreakIterator
*bi
= NULL
;
635 UErrorCode status
= U_ZERO_ERROR
;
637 u_uastrncpy(rules
, "[A-N]{100}; \n"
642 "!.*;\n", RULE_STRING_LENGTH
);
643 u_uastrncpy(testString
, "ABC", TEST_STRING_LENGTH
);
646 bi
= ubrk_openRules(rules
, -1, testString
, -1, NULL
, &status
);
647 TEST_ASSERT_SUCCESS(status
);
648 TEST_ASSERT(bi
!= NULL
);
650 /* The TEST_ASSERT above should change too... */
653 TEST_ASSERT(pos
== 1);
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);
663 numVals
= ubrk_getRuleStatusVec(bi
, vals
, 0, &status
);
664 TEST_ASSERT(status
== U_BUFFER_OVERFLOW_ERROR
);
665 TEST_ASSERT(numVals
== 2);
673 * static void TestBreakIteratorUText(void);
675 * Test that ubrk_setUText() is present and works for a simple case.
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 */
681 UErrorCode status
= U_ZERO_ERROR
;
682 UBreakIterator
*bi
= NULL
;
686 UText
*ut
= utext_openUTF8(NULL
, UTF8Str
, -1, &status
);
687 TEST_ASSERT_SUCCESS(status
);
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
));
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
));
701 pos
= ubrk_first(bi
);
702 TEST_ASSERT(pos
== 0);
705 TEST_ASSERT(pos
== 4);
708 TEST_ASSERT(pos
== 5);
711 TEST_ASSERT(pos
== 10);
714 TEST_ASSERT(pos
== UBRK_DONE
);
720 * static void TestBreakIteratorTailoring(void);
722 * Test break iterator tailorings from CLDR data.
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 };
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 };
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 };
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 };
769 UBreakIteratorType type
;
771 const int32_t * offsFwd
;
772 const int32_t * offsRev
;
776 static const RBBITailoringTest tailoringTests
[] = {
777 { "en", UBRK_CHARACTER
, thTest
, thTestOffs_thFwd
, thTestOffs_thRev
, UPRV_LENGTHOF(thTestOffs_thFwd
) },
778 { "en_US_POSIX", UBRK_CHARACTER
, thTest
, thTestOffs_thFwd
, thTestOffs_thRev
, UPRV_LENGTHOF(thTestOffs_thFwd
) },
779 { "en", UBRK_LINE
, heTest
, heTestOffs_heFwd
, heTestOffs_heRev
, UPRV_LENGTHOF(heTestOffs_heFwd
) },
780 { "he", UBRK_LINE
, heTest
, heTestOffs_heFwd
, heTestOffs_heRev
, UPRV_LENGTHOF(heTestOffs_heFwd
) },
781 { "en", UBRK_LINE
, fiTest
, fiTestOffs_enFwd
, fiTestOffs_enRev
, UPRV_LENGTHOF(fiTestOffs_enFwd
) },
782 { "fi", UBRK_LINE
, fiTest
, fiTestOffs_fiFwd
, fiTestOffs_fiRev
, UPRV_LENGTHOF(fiTestOffs_fiFwd
) },
783 { "km", UBRK_WORD
, kmTest
, kmTestOffs_kmFwd
, kmTestOffs_kmRev
, UPRV_LENGTHOF(kmTestOffs_kmFwd
) },
784 { NULL
, 0, NULL
, NULL
, NULL
, 0 },
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
;
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
);
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
);
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
]);
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
);
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
);
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
]);
830 ubrk_close(ubrkiter
);
832 log_err_status(status
, "FAIL: locale %s, break type %d, ubrk_open status: %s\n", testPtr
->locale
, testPtr
->type
, u_errorName(status
));
838 static void TestBreakIteratorRefresh(void) {
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.
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
;
850 UText ut1
= UTEXT_INITIALIZER
;
851 UText ut2
= UTEXT_INITIALIZER
;
853 bi
= ubrk_open(UBRK_LINE
, "en_US", NULL
, 0, &status
);
854 TEST_ASSERT_SUCCESS(status
);
855 if (U_FAILURE(status
)) {
859 utext_openUChars(&ut1
, testStr
, -1, &status
);
860 TEST_ASSERT_SUCCESS(status
);
861 ubrk_setUText(bi
, &ut1
, &status
);
862 TEST_ASSERT_SUCCESS(status
);
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
));
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
);
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
);
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
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.
900 static UChar japaneseText
[] = {0x30A2, 0x30EC, 0x30EB, 0x30AE, 0x30FC, 0x6027, 0x7D50, 0x819C, 0x708E};
901 int32_t boundaries
[10] = {0};
902 UBreakIterator
*bi
= NULL
;
905 int32_t totalBreaks
= 0;
906 UErrorCode status
= U_ZERO_ERROR
;
909 bi
= ubrk_open(UBRK_WORD
, "en_US", japaneseText
, UPRV_LENGTHOF(japaneseText
), &status
);
910 TEST_ASSERT_SUCCESS(status
);
914 for (brk
=ubrk_first(bi
); brk
!= UBRK_DONE
; brk
=ubrk_next(bi
)) {
915 boundaries
[brkIdx
] = brk
;
916 if (++brkIdx
>= UPRV_LENGTHOF(boundaries
) - 1) {
920 if (brkIdx
<= 2 || brkIdx
>= UPRV_LENGTHOF(boundaries
)) {
921 log_err("%s:%d too few or many breaks found.\n", __FILE__
, __LINE__
);
923 totalBreaks
= brkIdx
;
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
);
930 if (++brkIdx
>= UPRV_LENGTHOF(boundaries
) - 1) {
931 log_err("%s:%d Too many breaks.\n", __FILE__
, __LINE__
);
935 if (totalBreaks
!= brkIdx
) {
936 log_err("%s:%d Number of breaks differ between first and second iteration.\n", __FILE__
, __LINE__
);
943 * expOffset is the set of expected offsets, ending with '-1'.
944 * "Expected expOffset -1" means "expected the end of the offsets"
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, 46, 70, -1 }; /* With suppressions */
949 static const int32_t testSentFwdOffsetsEn
[] = { 4, 22, 26, 46, 70, -1 }; /* Without suppressions */
950 static const int32_t testSentSuppRevOffsetsEn
[] = { 46, 22, 0, -1 }; /* With suppressions */
951 static const int32_t testSentRevOffsetsEn
[] = { 46, 26, 22, 4, 0, -1 }; /* Without suppressions */
953 static const char testSentenceSuppressionsDe
[] = "Wenn ich schon h\\u00F6re zu Guttenberg kommt evtl. zur\\u00FCck.";
954 // "Wenn ich schon höre zu Guttenberg kommt evtl. zurück."
955 static const int32_t testSentSuppFwdOffsetsDe
[] = { 53, -1 }; /* With suppressions */
956 static const int32_t testSentFwdOffsetsDe
[] = { 53, -1 }; /* Without suppressions; no break in evtl. zur due to casing */
957 static const int32_t testSentSuppRevOffsetsDe
[] = { 0, -1 }; /* With suppressions */
958 static const int32_t testSentRevOffsetsDe
[] = { 0, -1 }; /* Without suppressions */
960 static const char testSentenceSuppressionsEs
[] = "Te esperamos todos los miercoles en Bravo 416, Col. El Pueblo a las 7 PM.";
961 static const int32_t testSentSuppFwdOffsetsEs
[] = { 73, -1 }; /* With suppressions */
962 static const int32_t testSentFwdOffsetsEs
[] = { 52, 73, -1 }; /* Without suppressions */
963 static const int32_t testSentSuppRevOffsetsEs
[] = { 0, -1 }; /* With suppressions */
964 static const int32_t testSentRevOffsetsEs
[] = { 52, 0, -1 }; /* Without suppressions */
966 static const char testSentenceSuppressionsE1
[] = "Add or detract. The world will little note.";
967 static const char testSentenceSuppressionsE1u
[] = "ADD OR DETRACT. THE WORLD WILL LITTLE NOTE.";
968 static const int32_t testSentFwdOffsetsE1
[] = { 16, 43, -1 }; /* Suppressions and case should make no difference */
969 static const int32_t testSentRevOffsetsE1
[] = { 16, 0, -1 }; /* Suppressions and case should make no difference */
971 static const char testSentenceSuppressionsE2
[] = "Coming up, the sprints at NCAA. Are you watching?";
972 static const char testSentenceSuppressionsE2u
[] = "COMING UP, THE SPRINTS AT NCAA. ARE YOU WATCHING?";
973 static const int32_t testSentFwdOffsetsE2
[] = { 32, 49, -1 }; /* Suppressions and case should make no difference */
974 static const int32_t testSentRevOffsetsE2
[] = { 32, 0, -1 }; /* Suppressions and case should make no difference */
976 static const char testSentenceSuppressionsFr
[] = "Tr\\u00E8s bonne prise de parole de M. Junod, municipal \\u00E0 la culture de Lausanne.";
977 // "Très bonne prise de parole de M. Junod, municipal à la culture de Lausanne."
978 static const int32_t testSentFwdOffsetsFr
[] = { 33, 75, -1 }; /* Without suppressions */
979 static const int32_t testSentSuppFwdOffsetsFr
[] = { 75, -1 }; /* With suppressions */
980 static const int32_t testSentRevOffsetsFr
[] = { 33, 0, -1 }; /* Without suppressions */
981 static const int32_t testSentSuppRevOffsetsFr
[] = { 0, -1 }; /* With suppressions */
983 static const char testSentenceSuppressionsE3
[] = "G8 countries e.g. U.K., Japan. Sanctions i.e. restrictions. Test E. Xx G. Xx I. Xx.";
984 static const char testSentenceSuppressionsE3u
[] = "G8 COUNTRIES E.G. U.K., JAPAN. SANCTIONS I.E. RESTRICTIONS. TEST E. XX G. XX I. XX.";
985 static const int32_t testSentSuppFwdOffsetsE3
[] = { 31, 60, 83, -1 }; /* With suppressions */
986 static const int32_t testSentSuppRevOffsetsE3
[] = { 60, 31, 0, -1 }; /* With suppressions */
987 static const int32_t testSentFwdOffsetsE3
[] = { 18, 31, 60, 68, 74, 80, 83, -1 }; /* Without suppressions */
988 static const int32_t testSentRevOffsetsE3
[] = { 80, 74, 68, 60, 31, 18, 0, -1 }; /* Without suppressions */
989 static const int32_t testSentFwdOffsetsE3u
[] = { 18, 31, 46, 60, 68, 74, 80, 83, -1 }; /* Without suppressions */
990 static const int32_t testSentRevOffsetsE3u
[] = { 80, 74, 68, 60, 46, 31, 18, 0, -1 }; /* Without suppressions */
992 enum { kTextULenMax
= 128, kTextBLenMax
= 192 };
997 const int32_t * expFwdOffsets
;
998 const int32_t * expRevOffsets
;
999 } TestBISuppressionsItem
;
1001 static const TestBISuppressionsItem testBISuppressionsItems
[] = {
1002 { "en@ss=standard", testSentenceSuppressionsEn
, testSentSuppFwdOffsetsEn
, testSentSuppRevOffsetsEn
},
1003 { "en", testSentenceSuppressionsEn
, testSentFwdOffsetsEn
, testSentRevOffsetsEn
},
1004 { "fr@ss=standard", testSentenceSuppressionsEn
, testSentFwdOffsetsEn
, testSentRevOffsetsEn
},
1005 { "af@ss=standard", testSentenceSuppressionsEn
, testSentSuppFwdOffsetsEn
, testSentSuppRevOffsetsEn
}, /* no brkiter data => en suppressions? */
1006 { "zh@ss=standard", testSentenceSuppressionsEn
, testSentFwdOffsetsEn
, testSentRevOffsetsEn
}, /* brkiter data, no suppressions data => no suppressions */
1007 { "zh_Hant@ss=standard", testSentenceSuppressionsEn
, testSentFwdOffsetsEn
, testSentRevOffsetsEn
}, /* brkiter data, no suppressions data => no suppressions */
1008 { "fi@ss=standard", testSentenceSuppressionsEn
, testSentFwdOffsetsEn
, testSentRevOffsetsEn
}, /* brkiter data, no suppressions data => no suppressions */
1009 { "ja@ss=standard", testSentenceSuppressionsEn
, testSentFwdOffsetsEn
, testSentRevOffsetsEn
}, /* brkiter data, no suppressions data => no suppressions */
1010 { "de@ss=standard", testSentenceSuppressionsDe
, testSentSuppFwdOffsetsDe
, testSentSuppRevOffsetsDe
},
1011 { "de", testSentenceSuppressionsDe
, testSentFwdOffsetsDe
, testSentRevOffsetsDe
},
1012 { "es@ss=standard", testSentenceSuppressionsEs
, testSentSuppFwdOffsetsEs
, testSentSuppRevOffsetsEs
},
1013 { "es", testSentenceSuppressionsEs
, testSentFwdOffsetsEs
, testSentRevOffsetsEs
},
1014 { "en", testSentenceSuppressionsE1
, testSentFwdOffsetsE1
, testSentRevOffsetsE1
},
1015 { "en@ss=standard", testSentenceSuppressionsE1
, testSentFwdOffsetsE1
, testSentRevOffsetsE1
},
1016 { "en", testSentenceSuppressionsE1u
, testSentFwdOffsetsE1
, testSentRevOffsetsE1
},
1017 { "en@ss=standard", testSentenceSuppressionsE1u
, testSentFwdOffsetsE1
, testSentRevOffsetsE1
},
1018 { "en", testSentenceSuppressionsE2
, testSentFwdOffsetsE2
, testSentRevOffsetsE2
},
1019 { "en@ss=standard", testSentenceSuppressionsE2
, testSentFwdOffsetsE2
, testSentRevOffsetsE2
},
1020 { "en", testSentenceSuppressionsE2u
, testSentFwdOffsetsE2
, testSentRevOffsetsE2
},
1021 { "en@ss=standard", testSentenceSuppressionsE2u
, testSentFwdOffsetsE2
, testSentRevOffsetsE2
},
1022 { "fr", testSentenceSuppressionsFr
, testSentFwdOffsetsFr
, testSentRevOffsetsFr
},
1023 { "fr@ss=standard", testSentenceSuppressionsFr
, testSentSuppFwdOffsetsFr
, testSentSuppRevOffsetsFr
},
1024 { "en@ss=standard", testSentenceSuppressionsE3
, testSentSuppFwdOffsetsE3
, testSentSuppRevOffsetsE3
},
1025 { "en", testSentenceSuppressionsE3
, testSentFwdOffsetsE3
, testSentRevOffsetsE3
},
1026 { "en@ss=standard", testSentenceSuppressionsE3u
, testSentSuppFwdOffsetsE3
, testSentSuppRevOffsetsE3
},
1027 { "en", testSentenceSuppressionsE3u
, testSentFwdOffsetsE3u
, testSentRevOffsetsE3u
},
1028 { NULL
, NULL
, NULL
}
1031 static void TestBreakIteratorSuppressions(void) {
1032 const TestBISuppressionsItem
* itemPtr
;
1034 for (itemPtr
= testBISuppressionsItems
; itemPtr
->locale
!= NULL
; itemPtr
++) {
1035 UChar textU
[kTextULenMax
+ 1];
1036 char textB
[kTextBLenMax
];
1037 int32_t textULen
= u_unescape(itemPtr
->text
, textU
, kTextULenMax
);
1038 textU
[kTextULenMax
] = 0; // ensure zero termination
1039 UErrorCode status
= U_ZERO_ERROR
;
1040 UBreakIterator
*bi
= ubrk_open(UBRK_SENTENCE
, itemPtr
->locale
, textU
, textULen
, &status
);
1041 log_verbose("#%d: %s\n", (itemPtr
-testBISuppressionsItems
), itemPtr
->locale
);
1042 if (U_SUCCESS(status
)) {
1043 int32_t offset
, start
;
1044 const int32_t * expOffsetPtr
;
1045 const int32_t * expOffsetStart
;
1046 u_austrcpy(textB
, textU
);
1048 expOffsetStart
= expOffsetPtr
= itemPtr
->expFwdOffsets
;
1050 for (; (offset
= ubrk_next(bi
)) != UBRK_DONE
&& *expOffsetPtr
>= 0; expOffsetPtr
++) {
1051 if (offset
!= *expOffsetPtr
) {
1052 log_err("FAIL: ubrk_next loc \"%s\", expected %d, got %d, text \"%s\"\n",
1053 itemPtr
->locale
, *expOffsetPtr
, offset
, textB
);
1056 if (offset
!= UBRK_DONE
|| *expOffsetPtr
>= 0) {
1057 log_err("FAIL: ubrk_next loc \"%s\", expected UBRK_DONE & expOffset -1, got %d and %d, text \"%s\"\n",
1058 itemPtr
->locale
, offset
, *expOffsetPtr
, textB
);
1061 expOffsetStart
= expOffsetPtr
= itemPtr
->expFwdOffsets
;
1062 start
= ubrk_first(bi
) + 1;
1063 for (; (offset
= ubrk_following(bi
, start
)) != UBRK_DONE
&& *expOffsetPtr
>= 0; expOffsetPtr
++) {
1064 if (offset
!= *expOffsetPtr
) {
1065 log_err("FAIL: ubrk_following(%d) loc \"%s\", expected %d, got %d, text \"%s\"\n",
1066 start
, itemPtr
->locale
, *expOffsetPtr
, offset
, textB
);
1068 start
= *expOffsetPtr
+ 1;
1070 if (offset
!= UBRK_DONE
|| *expOffsetPtr
>= 0) {
1071 log_err("FAIL: ubrk_following(%d) loc \"%s\", expected UBRK_DONE & expOffset -1, got %d and %d, text \"%s\"\n",
1072 start
, itemPtr
->locale
, offset
, *expOffsetPtr
, textB
);
1075 expOffsetStart
= expOffsetPtr
= itemPtr
->expRevOffsets
;
1076 offset
= ubrk_last(bi
);
1077 log_verbose("___ @%d ubrk_last\n", offset
);
1079 log_err("FAIL: ubrk_last loc \"%s\" unexpected %d\n", itemPtr
->locale
, offset
);
1081 for (; (offset
= ubrk_previous(bi
)) != UBRK_DONE
&& *expOffsetPtr
>= 0; expOffsetPtr
++) {
1082 if (offset
!= *expOffsetPtr
) {
1083 log_err("FAIL: ubrk_previous loc \"%s\", expected %d, got %d, text \"%s\"\n",
1084 itemPtr
->locale
, *expOffsetPtr
, offset
, textB
);
1086 log_verbose("[%d] @%d ubrk_previous()\n", (expOffsetPtr
- expOffsetStart
), offset
);
1089 if (offset
!= UBRK_DONE
|| *expOffsetPtr
>= 0) {
1090 log_err("FAIL: ubrk_previous loc \"%s\", expected UBRK_DONE & expOffset[%d] -1, got %d and %d, text \"%s\"\n",
1091 itemPtr
->locale
, expOffsetPtr
- expOffsetStart
, offset
, *expOffsetPtr
, textB
);
1094 expOffsetStart
= expOffsetPtr
= itemPtr
->expRevOffsets
;
1095 start
= ubrk_last(bi
) - 1;
1096 for (; (offset
= ubrk_preceding(bi
, start
)) != UBRK_DONE
&& *expOffsetPtr
>= 0; expOffsetPtr
++) {
1097 if (offset
!= *expOffsetPtr
) {
1098 log_err("FAIL: ubrk_preceding(%d) loc \"%s\", expected %d, got %d, text \"%s\"\n",
1099 start
, itemPtr
->locale
, *expOffsetPtr
, offset
, textB
);
1101 start
= *expOffsetPtr
- 1;
1103 if (start
>=0 && (offset
!= UBRK_DONE
|| *expOffsetPtr
>= 0)) {
1104 log_err("FAIL: ubrk_preceding loc(%d) \"%s\", expected UBRK_DONE & expOffset -1, got %d and %d, text \"%s\"\n",
1105 start
, itemPtr
->locale
, offset
, *expOffsetPtr
, textB
);
1110 log_data_err("FAIL: ubrk_open(UBRK_SENTENCE, \"%s\", ...) status %s (Are you missing data?)\n",
1111 itemPtr
->locale
, u_errorName(status
));
1117 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */