2 *****************************************************************************
3 * Copyright (C) 2001-2006, International Business Machines orporation
4 * and others. All Rights Reserved.
5 ****************************************************************************/
7 #include "unicode/utypes.h"
9 #if !UCONFIG_NO_COLLATION
12 #include "../cintltst/usrchdat.c"
13 #include "unicode/stsearch.h"
14 #include "unicode/ustring.h"
15 #include "unicode/schriter.h"
19 // private definitions -----------------------------------------------------
21 #define CASE(id,test) \
26 logln((UnicodeString)""); \
28 errln(__FILE__ " cannot test - failed to create collator."); \
35 // public contructors and destructors --------------------------------------
37 StringSearchTest::StringSearchTest() :
38 m_en_wordbreaker_(NULL
), m_en_characterbreaker_(NULL
)
40 UErrorCode status
= U_ZERO_ERROR
;
42 m_en_us_
= (RuleBasedCollator
*)Collator::createInstance("en_US", status
);
43 m_fr_fr_
= (RuleBasedCollator
*)Collator::createInstance("fr_FR", status
);
44 m_de_
= (RuleBasedCollator
*)Collator::createInstance("de_DE", status
);
45 m_es_
= (RuleBasedCollator
*)Collator::createInstance("es_ES", status
);
46 if(U_FAILURE(status
)) {
55 errln("Collator creation failed with %s", u_errorName(status
));
61 rules
.setTo(((RuleBasedCollator
*)m_de_
)->getRules());
62 UChar extrarules
[128];
63 u_unescape(EXTRACOLLATIONRULE
, extrarules
, 128);
64 rules
.append(extrarules
, u_strlen(extrarules
));
67 m_de_
= new RuleBasedCollator(rules
, status
);
69 rules
.setTo(((RuleBasedCollator
*)m_es_
)->getRules());
70 rules
.append(extrarules
, u_strlen(extrarules
));
74 m_es_
= new RuleBasedCollator(rules
, status
);
76 #if !UCONFIG_NO_BREAK_ITERATION
77 m_en_wordbreaker_
= BreakIterator::createWordInstance(
78 Locale::getEnglish(), status
);
79 m_en_characterbreaker_
= BreakIterator::createCharacterInstance(
80 Locale::getEnglish(), status
);
84 StringSearchTest::~StringSearchTest()
90 #if !UCONFIG_NO_BREAK_ITERATION
91 delete m_en_wordbreaker_
;
92 delete m_en_characterbreaker_
;
96 // public methods ----------------------------------------------------------
98 void StringSearchTest::runIndexedTest(int32_t index
, UBool exec
,
99 const char* &name
, char* )
101 UBool areBroken
= FALSE
;
102 if (m_en_us_
== NULL
&& m_fr_fr_
== NULL
&& m_de_
== NULL
&&
103 m_es_
== NULL
&& m_en_wordbreaker_
== NULL
&&
104 m_en_characterbreaker_
== NULL
&& exec
) {
109 CASE(0, TestOpenClose
)
110 CASE(1, TestInitialization
)
112 CASE(3, TestNormExact
)
113 CASE(4, TestStrength
)
114 #if UCONFIG_NO_BREAK_ITERATION
116 name
= "TestBreakIterator";
119 CASE(5, TestBreakIterator
)
121 CASE(6, TestVariable
)
123 CASE(8, TestCollator
)
126 CASE(11, TestCompositeBoundaries
)
127 CASE(12, TestGetSetOffset
)
128 CASE(13, TestGetSetAttribute
)
129 CASE(14, TestGetMatch
)
130 CASE(15, TestSetMatch
)
132 CASE(17, TestSupplementary
)
133 CASE(18, TestContraction
)
134 CASE(19, TestIgnorable
)
135 CASE(20, TestCanonical
)
136 CASE(21, TestNormCanonical
)
137 CASE(22, TestStrengthCanonical
)
138 #if UCONFIG_NO_BREAK_ITERATION
140 name
= "TestBreakIteratorCanonical";
143 CASE(23, TestBreakIteratorCanonical
)
145 CASE(24, TestVariableCanonical
)
146 CASE(25, TestOverlapCanonical
)
147 CASE(26, TestCollatorCanonical
)
148 CASE(27, TestPatternCanonical
)
149 CASE(28, TestTextCanonical
)
150 CASE(29, TestCompositeBoundariesCanonical
)
151 CASE(30, TestGetSetOffsetCanonical
)
152 CASE(31, TestSupplementaryCanonical
)
153 CASE(32, TestContractionCanonical
)
154 CASE(33, TestUClassID
)
155 CASE(34, TestSubclass
)
156 CASE(35, TestCoverage
)
157 default: name
= ""; break;
161 // private methods ------------------------------------------------------
163 RuleBasedCollator
* StringSearchTest::getCollator(const char *collator
)
165 if (collator
== NULL
) {
168 if (strcmp(collator
, "fr") == 0) {
171 else if (strcmp(collator
, "de") == 0) {
174 else if (strcmp(collator
, "es") == 0) {
182 BreakIterator
* StringSearchTest::getBreakIterator(const char *breaker
)
184 #if UCONFIG_NO_BREAK_ITERATION
187 if (breaker
== NULL
) {
190 if (strcmp(breaker
, "wordbreaker") == 0) {
191 return m_en_wordbreaker_
;
194 return m_en_characterbreaker_
;
199 char * StringSearchTest::toCharString(const UnicodeString
&text
)
201 static char result
[1024];
204 int length
= text
.length();
206 for (; count
< length
; count
++) {
207 UChar ch
= text
[count
];
208 if (ch
>= 0x20 && ch
<= 0x7e) {
209 result
[index
++] = (char)ch
;
212 sprintf(result
+index
, "\\u%04x", ch
);
213 index
+= 6; /* \uxxxx */
221 Collator::ECollationStrength
StringSearchTest::getECollationStrength(
222 const UCollationStrength
&strength
) const
227 return Collator::PRIMARY
;
228 case UCOL_SECONDARY
:
229 return Collator::SECONDARY
;
231 return Collator::TERTIARY
;
233 return Collator::IDENTICAL
;
237 UBool
StringSearchTest::assertEqualWithStringSearch(StringSearch
*strsrch
,
238 const SearchData
*search
)
241 UErrorCode status
= U_ZERO_ERROR
;
242 int32_t matchindex
= search
->offset
[count
];
243 UnicodeString matchtext
;
245 if (strsrch
->getMatchedStart() != USEARCH_DONE
||
246 strsrch
->getMatchedLength() != 0) {
247 errln("Error with the initialization of match start and length");
249 // start of following matches
250 while (U_SUCCESS(status
) && matchindex
>= 0) {
251 int32_t matchlength
= search
->size
[count
];
252 strsrch
->next(status
);
253 if (matchindex
!= strsrch
->getMatchedStart() ||
254 matchlength
!= strsrch
->getMatchedLength()) {
255 char *str
= toCharString(strsrch
->getText());
256 errln("Text: %s", str
);
257 str
= toCharString(strsrch
->getPattern());
258 errln("Pattern: %s", str
);
259 errln("Error following match found at %d %d",
260 strsrch
->getMatchedStart(), strsrch
->getMatchedLength());
265 strsrch
->getMatchedText(matchtext
);
267 if (U_FAILURE(status
) ||
268 strsrch
->getText().compareBetween(matchindex
,
269 matchindex
+ matchlength
,
271 matchtext
.length())) {
272 errln("Error getting following matched text");
275 matchindex
= search
->offset
[count
];
277 strsrch
->next(status
);
278 if (strsrch
->getMatchedStart() != USEARCH_DONE
||
279 strsrch
->getMatchedLength() != 0) {
280 char *str
= toCharString(strsrch
->getText());
281 errln("Text: %s", str
);
282 str
= toCharString(strsrch
->getPattern());
283 errln("Pattern: %s", str
);
284 errln("Error following match found at %d %d",
285 strsrch
->getMatchedStart(), strsrch
->getMatchedLength());
288 // start of preceding matches
289 count
= count
== 0 ? 0 : count
- 1;
290 matchindex
= search
->offset
[count
];
291 while (U_SUCCESS(status
) && matchindex
>= 0) {
292 int32_t matchlength
= search
->size
[count
];
293 strsrch
->previous(status
);
294 if (matchindex
!= strsrch
->getMatchedStart() ||
295 matchlength
!= strsrch
->getMatchedLength()) {
296 char *str
= toCharString(strsrch
->getText());
297 errln("Text: %s", str
);
298 str
= toCharString(strsrch
->getPattern());
299 errln("Pattern: %s", str
);
300 errln("Error following match found at %d %d",
301 strsrch
->getMatchedStart(), strsrch
->getMatchedLength());
305 strsrch
->getMatchedText(matchtext
);
307 if (U_FAILURE(status
) ||
308 strsrch
->getText().compareBetween(matchindex
,
309 matchindex
+ matchlength
,
311 matchtext
.length())) {
312 errln("Error getting following matched text");
315 matchindex
= count
> 0 ? search
->offset
[count
- 1] : -1;
318 strsrch
->previous(status
);
319 if (strsrch
->getMatchedStart() != USEARCH_DONE
||
320 strsrch
->getMatchedLength() != 0) {
321 char *str
= toCharString(strsrch
->getText());
322 errln("Text: %s", str
);
323 str
= toCharString(strsrch
->getPattern());
324 errln("Pattern: %s", str
);
325 errln("Error following match found at %d %d",
326 strsrch
->getMatchedStart(), strsrch
->getMatchedLength());
332 UBool
StringSearchTest::assertEqual(const SearchData
*search
)
334 UErrorCode status
= U_ZERO_ERROR
;
336 Collator
*collator
= getCollator(search
->collator
);
337 BreakIterator
*breaker
= getBreakIterator(search
->breaker
);
338 StringSearch
*strsrch
, *strsrch2
;
341 #if UCONFIG_NO_BREAK_ITERATION
342 if(search
->breaker
) {
343 return TRUE
; /* skip test */
346 u_unescape(search
->text
, temp
, 128);
349 u_unescape(search
->pattern
, temp
, 128);
350 UnicodeString pattern
;
353 #if !UCONFIG_NO_BREAK_ITERATION
354 if (breaker
!= NULL
) {
355 breaker
->setText(text
);
358 collator
->setStrength(getECollationStrength(search
->strength
));
359 strsrch
= new StringSearch(pattern
, text
, (RuleBasedCollator
*)collator
,
361 if (U_FAILURE(status
)) {
362 errln("Error opening string search %s", u_errorName(status
));
366 if (!assertEqualWithStringSearch(strsrch
, search
)) {
367 collator
->setStrength(getECollationStrength(UCOL_TERTIARY
));
373 strsrch2
= strsrch
->clone();
374 if( strsrch2
== strsrch
|| *strsrch2
!= *strsrch
||
375 !assertEqualWithStringSearch(strsrch2
, search
)
377 errln("failure with StringSearch.clone()");
378 collator
->setStrength(getECollationStrength(UCOL_TERTIARY
));
385 collator
->setStrength(getECollationStrength(UCOL_TERTIARY
));
390 UBool
StringSearchTest::assertCanonicalEqual(const SearchData
*search
)
392 UErrorCode status
= U_ZERO_ERROR
;
393 Collator
*collator
= getCollator(search
->collator
);
394 BreakIterator
*breaker
= getBreakIterator(search
->breaker
);
395 StringSearch
*strsrch
;
398 #if UCONFIG_NO_BREAK_ITERATION
399 if(search
->breaker
) {
400 return TRUE
; /* skip test */
404 u_unescape(search
->text
, temp
, 128);
407 u_unescape(search
->pattern
, temp
, 128);
408 UnicodeString pattern
;
411 #if !UCONFIG_NO_BREAK_ITERATION
412 if (breaker
!= NULL
) {
413 breaker
->setText(text
);
416 collator
->setStrength(getECollationStrength(search
->strength
));
417 strsrch
= new StringSearch(pattern
, text
, (RuleBasedCollator
*)collator
,
419 strsrch
->setAttribute(USEARCH_CANONICAL_MATCH
, USEARCH_ON
, status
);
420 if (U_FAILURE(status
)) {
421 errln("Error opening string search %s", u_errorName(status
));
425 if (!assertEqualWithStringSearch(strsrch
, search
)) {
426 collator
->setStrength(getECollationStrength(UCOL_TERTIARY
));
430 collator
->setStrength(getECollationStrength(UCOL_TERTIARY
));
435 UBool
StringSearchTest::assertEqualWithAttribute(const SearchData
*search
,
436 USearchAttributeValue canonical
,
437 USearchAttributeValue overlap
)
439 UErrorCode status
= U_ZERO_ERROR
;
440 Collator
*collator
= getCollator(search
->collator
);
441 BreakIterator
*breaker
= getBreakIterator(search
->breaker
);
442 StringSearch
*strsrch
;
446 #if UCONFIG_NO_BREAK_ITERATION
447 if(search
->breaker
) {
448 return TRUE
; /* skip test */
452 u_unescape(search
->text
, temp
, 128);
455 u_unescape(search
->pattern
, temp
, 128);
456 UnicodeString pattern
;
459 #if !UCONFIG_NO_BREAK_ITERATION
460 if (breaker
!= NULL
) {
461 breaker
->setText(text
);
464 collator
->setStrength(getECollationStrength(search
->strength
));
465 strsrch
= new StringSearch(pattern
, text
, (RuleBasedCollator
*)collator
,
467 strsrch
->setAttribute(USEARCH_CANONICAL_MATCH
, canonical
, status
);
468 strsrch
->setAttribute(USEARCH_OVERLAP
, overlap
, status
);
470 if (U_FAILURE(status
)) {
471 errln("Error opening string search %s", u_errorName(status
));
475 if (!assertEqualWithStringSearch(strsrch
, search
)) {
476 collator
->setStrength(getECollationStrength(UCOL_TERTIARY
));
480 collator
->setStrength(getECollationStrength(UCOL_TERTIARY
));
485 void StringSearchTest::TestOpenClose()
487 UErrorCode status
= U_ZERO_ERROR
;
488 StringSearch
*result
;
489 BreakIterator
*breakiter
= m_en_wordbreaker_
;
490 UnicodeString pattern
;
492 UnicodeString
temp("a");
493 StringCharacterIterator
chariter(text
);
495 /* testing null arguments */
496 result
= new StringSearch(pattern
, text
, NULL
, NULL
, status
);
497 if (U_SUCCESS(status
)) {
498 errln("Error: NULL arguments should produce an error");
502 chariter
.setText(text
);
503 status
= U_ZERO_ERROR
;
504 result
= new StringSearch(pattern
, chariter
, NULL
, NULL
, status
);
505 if (U_SUCCESS(status
)) {
506 errln("Error: NULL arguments should produce an error");
511 status
= U_ZERO_ERROR
;
512 result
= new StringSearch(pattern
, text
, NULL
, NULL
, status
);
513 if (U_SUCCESS(status
)) {
514 errln("Error: Empty pattern should produce an error");
518 chariter
.setText(text
);
519 status
= U_ZERO_ERROR
;
520 result
= new StringSearch(pattern
, chariter
, NULL
, NULL
, status
);
521 if (U_SUCCESS(status
)) {
522 errln("Error: Empty pattern should produce an error");
527 pattern
.append(temp
);
528 status
= U_ZERO_ERROR
;
529 result
= new StringSearch(pattern
, text
, NULL
, NULL
, status
);
530 if (U_SUCCESS(status
)) {
531 errln("Error: Empty text should produce an error");
535 chariter
.setText(text
);
536 status
= U_ZERO_ERROR
;
537 result
= new StringSearch(pattern
, chariter
, NULL
, NULL
, status
);
538 if (U_SUCCESS(status
)) {
539 errln("Error: Empty text should produce an error");
544 status
= U_ZERO_ERROR
;
545 result
= new StringSearch(pattern
, text
, NULL
, NULL
, status
);
546 if (U_SUCCESS(status
)) {
547 errln("Error: NULL arguments should produce an error");
551 chariter
.setText(text
);
552 status
= U_ZERO_ERROR
;
553 result
= new StringSearch(pattern
, chariter
, NULL
, NULL
, status
);
554 if (U_SUCCESS(status
)) {
555 errln("Error: NULL arguments should produce an error");
559 status
= U_ZERO_ERROR
;
560 result
= new StringSearch(pattern
, text
, m_en_us_
, NULL
, status
);
561 if (U_FAILURE(status
)) {
562 errln("Error: NULL break iterator is valid for opening search");
566 status
= U_ZERO_ERROR
;
567 result
= new StringSearch(pattern
, chariter
, m_en_us_
, NULL
, status
);
568 if (U_FAILURE(status
)) {
569 errln("Error: NULL break iterator is valid for opening search");
573 status
= U_ZERO_ERROR
;
574 result
= new StringSearch(pattern
, text
, Locale::getEnglish(), NULL
, status
);
575 if (U_FAILURE(status
) || result
== NULL
) {
576 errln("Error: NULL break iterator is valid for opening search");
580 status
= U_ZERO_ERROR
;
581 result
= new StringSearch(pattern
, chariter
, Locale::getEnglish(), NULL
, status
);
582 if (U_FAILURE(status
)) {
583 errln("Error: NULL break iterator is valid for opening search");
587 status
= U_ZERO_ERROR
;
588 result
= new StringSearch(pattern
, text
, m_en_us_
, breakiter
, status
);
589 if (U_FAILURE(status
)) {
590 errln("Error: Break iterator is valid for opening search");
594 status
= U_ZERO_ERROR
;
595 result
= new StringSearch(pattern
, chariter
, m_en_us_
, NULL
, status
);
596 if (U_FAILURE(status
)) {
597 errln("Error: Break iterator is valid for opening search");
602 void StringSearchTest::TestInitialization()
604 UErrorCode status
= U_ZERO_ERROR
;
605 UnicodeString pattern
;
607 UnicodeString
temp("a");
608 StringSearch
*result
;
611 /* simple test on the pattern ce construction */
612 pattern
.append(temp
);
613 pattern
.append(temp
);
617 result
= new StringSearch(pattern
, text
, m_en_us_
, NULL
, status
);
618 if (U_FAILURE(status
)) {
619 errln("Error opening search %s", u_errorName(status
));
621 StringSearch
*copy
= new StringSearch(*result
);
622 if (*(copy
->getCollator()) != *(result
->getCollator()) ||
623 copy
->getBreakIterator() != result
->getBreakIterator() ||
624 copy
->getMatchedLength() != result
->getMatchedLength() ||
625 copy
->getMatchedStart() != result
->getMatchedStart() ||
626 copy
->getOffset() != result
->getOffset() ||
627 copy
->getPattern() != result
->getPattern() ||
628 copy
->getText() != result
->getText() ||
629 *(copy
) != *(result
))
631 errln("Error copying StringSearch");
635 copy
= (StringSearch
*)result
->safeClone();
636 if (*(copy
->getCollator()) != *(result
->getCollator()) ||
637 copy
->getBreakIterator() != result
->getBreakIterator() ||
638 copy
->getMatchedLength() != result
->getMatchedLength() ||
639 copy
->getMatchedStart() != result
->getMatchedStart() ||
640 copy
->getOffset() != result
->getOffset() ||
641 copy
->getPattern() != result
->getPattern() ||
642 copy
->getText() != result
->getText() ||
643 *(copy
) != *(result
)) {
644 errln("Error copying StringSearch");
648 /* testing if an extremely large pattern will fail the initialization */
649 for (count
= 0; count
< 512; count
++) {
650 pattern
.append(temp
);
652 result
= new StringSearch(pattern
, text
, m_en_us_
, NULL
, status
);
653 if (*result
!= *result
) {
654 errln("Error: string search object expected to match itself");
656 if (*result
== *copy
) {
657 errln("Error: string search objects are not expected to match");
660 if (*(copy
->getCollator()) != *(result
->getCollator()) ||
661 copy
->getBreakIterator() != result
->getBreakIterator() ||
662 copy
->getMatchedLength() != result
->getMatchedLength() ||
663 copy
->getMatchedStart() != result
->getMatchedStart() ||
664 copy
->getOffset() != result
->getOffset() ||
665 copy
->getPattern() != result
->getPattern() ||
666 copy
->getText() != result
->getText() ||
667 *(copy
) != *(result
)) {
668 errln("Error copying StringSearch");
670 if (U_FAILURE(status
)) {
671 errln("Error opening search %s", u_errorName(status
));
677 void StringSearchTest::TestBasic()
680 while (BASIC
[count
].text
!= NULL
) {
681 //printf("count %d", count);
682 if (!assertEqual(&BASIC
[count
])) {
683 errln("Error at test number %d", count
);
689 void StringSearchTest::TestNormExact()
692 UErrorCode status
= U_ZERO_ERROR
;
693 m_en_us_
->setAttribute(UCOL_NORMALIZATION_MODE
, UCOL_ON
, status
);
694 if (U_FAILURE(status
)) {
695 errln("Error setting collation normalization %s",
696 u_errorName(status
));
698 while (BASIC
[count
].text
!= NULL
) {
699 if (!assertEqual(&BASIC
[count
])) {
700 errln("Error at test number %d", count
);
705 while (NORMEXACT
[count
].text
!= NULL
) {
706 if (!assertEqual(&NORMEXACT
[count
])) {
707 errln("Error at test number %d", count
);
711 m_en_us_
->setAttribute(UCOL_NORMALIZATION_MODE
, UCOL_OFF
, status
);
713 while (NONNORMEXACT
[count
].text
!= NULL
) {
714 if (!assertEqual(&NONNORMEXACT
[count
])) {
715 errln("Error at test number %d", count
);
721 void StringSearchTest::TestStrength()
724 while (STRENGTH
[count
].text
!= NULL
) {
725 if (!assertEqual(&STRENGTH
[count
])) {
726 errln("Error at test number %d", count
);
732 #if !UCONFIG_NO_BREAK_ITERATION
734 void StringSearchTest::TestBreakIterator()
737 u_unescape(BREAKITERATOREXACT
[0].text
, temp
, 128);
739 text
.setTo(temp
, u_strlen(temp
));
740 u_unescape(BREAKITERATOREXACT
[0].pattern
, temp
, 128);
741 UnicodeString pattern
;
742 pattern
.setTo(temp
, u_strlen(temp
));
744 UErrorCode status
= U_ZERO_ERROR
;
745 StringSearch
*strsrch
= new StringSearch(pattern
, text
, m_en_us_
, NULL
,
747 if (U_FAILURE(status
)) {
748 errln("Error opening string search %s", u_errorName(status
));
751 strsrch
->setBreakIterator(NULL
, status
);
752 if (U_FAILURE(status
) || strsrch
->getBreakIterator() != NULL
) {
753 errln("Error usearch_getBreakIterator returned wrong object");
756 strsrch
->setBreakIterator(m_en_characterbreaker_
, status
);
757 if (U_FAILURE(status
) ||
758 strsrch
->getBreakIterator() != m_en_characterbreaker_
) {
759 errln("Error usearch_getBreakIterator returned wrong object");
762 strsrch
->setBreakIterator(m_en_wordbreaker_
, status
);
763 if (U_FAILURE(status
) ||
764 strsrch
->getBreakIterator() != m_en_wordbreaker_
) {
765 errln("Error usearch_getBreakIterator returned wrong object");
772 // special purposes for tests numbers 0-3
773 const SearchData
*search
= &(BREAKITERATOREXACT
[count
]);
774 RuleBasedCollator
*collator
= getCollator(search
->collator
);
775 BreakIterator
*breaker
= getBreakIterator(search
->breaker
);
776 StringSearch
*strsrch
;
778 u_unescape(search
->text
, temp
, 128);
779 text
.setTo(temp
, u_strlen(temp
));
780 u_unescape(search
->pattern
, temp
, 128);
781 pattern
.setTo(temp
, u_strlen(temp
));
782 if (breaker
!= NULL
) {
783 breaker
->setText(text
);
785 collator
->setStrength(getECollationStrength(search
->strength
));
787 strsrch
= new StringSearch(pattern
, text
, collator
, breaker
, status
);
788 if (U_FAILURE(status
) ||
789 strsrch
->getBreakIterator() != breaker
) {
790 errln("Error setting break iterator");
791 if (strsrch
!= NULL
) {
795 if (!assertEqualWithStringSearch(strsrch
, search
)) {
796 collator
->setStrength(getECollationStrength(UCOL_TERTIARY
));
799 search
= &(BREAKITERATOREXACT
[count
+ 1]);
800 breaker
= getBreakIterator(search
->breaker
);
801 if (breaker
!= NULL
) {
802 breaker
->setText(text
);
804 strsrch
->setBreakIterator(breaker
, status
);
805 if (U_FAILURE(status
) ||
806 strsrch
->getBreakIterator() != breaker
) {
807 errln("Error setting break iterator");
811 if (!assertEqualWithStringSearch(strsrch
, search
)) {
812 errln("Error at test number %d", count
);
818 while (BREAKITERATOREXACT
[count
].text
!= NULL
) {
819 if (!assertEqual(&BREAKITERATOREXACT
[count
])) {
820 errln("Error at test number %d", count
);
828 void StringSearchTest::TestVariable()
831 UErrorCode status
= U_ZERO_ERROR
;
832 m_en_us_
->setAttribute(UCOL_ALTERNATE_HANDLING
, UCOL_SHIFTED
, status
);
833 if (U_FAILURE(status
)) {
834 errln("Error setting collation alternate attribute %s",
835 u_errorName(status
));
837 while (VARIABLE
[count
].text
!= NULL
) {
838 logln("variable %d", count
);
839 if (!assertEqual(&VARIABLE
[count
])) {
840 errln("Error at test number %d", count
);
844 m_en_us_
->setAttribute(UCOL_ALTERNATE_HANDLING
, UCOL_NON_IGNORABLE
,
848 void StringSearchTest::TestOverlap()
851 while (OVERLAP
[count
].text
!= NULL
) {
852 if (!assertEqualWithAttribute(&OVERLAP
[count
], USEARCH_OFF
,
854 errln("Error at overlap test number %d", count
);
859 while (NONOVERLAP
[count
].text
!= NULL
) {
860 if (!assertEqual(&NONOVERLAP
[count
])) {
861 errln("Error at non overlap test number %d", count
);
868 const SearchData
*search
= &(OVERLAP
[count
]);
870 u_unescape(search
->text
, temp
, 128);
872 text
.setTo(temp
, u_strlen(temp
));
873 u_unescape(search
->pattern
, temp
, 128);
874 UnicodeString pattern
;
875 pattern
.setTo(temp
, u_strlen(temp
));
877 RuleBasedCollator
*collator
= getCollator(search
->collator
);
878 UErrorCode status
= U_ZERO_ERROR
;
879 StringSearch
*strsrch
= new StringSearch(pattern
, text
,
883 strsrch
->setAttribute(USEARCH_OVERLAP
, USEARCH_ON
, status
);
884 if (U_FAILURE(status
) ||
885 strsrch
->getAttribute(USEARCH_OVERLAP
) != USEARCH_ON
) {
886 errln("Error setting overlap option");
888 if (!assertEqualWithStringSearch(strsrch
, search
)) {
893 search
= &(NONOVERLAP
[count
]);
894 strsrch
->setAttribute(USEARCH_OVERLAP
, USEARCH_OFF
, status
);
895 if (U_FAILURE(status
) ||
896 strsrch
->getAttribute(USEARCH_OVERLAP
) != USEARCH_OFF
) {
897 errln("Error setting overlap option");
900 if (!assertEqualWithStringSearch(strsrch
, search
)) {
902 errln("Error at test number %d", count
);
910 void StringSearchTest::TestCollator()
912 // test collator that thinks "o" and "p" are the same thing
914 u_unescape(COLLATOR
[0].text
, temp
, 128);
916 text
.setTo(temp
, u_strlen(temp
));
917 u_unescape(COLLATOR
[0].pattern
, temp
, 128);
918 UnicodeString pattern
;
919 pattern
.setTo(temp
, u_strlen(temp
));
921 UErrorCode status
= U_ZERO_ERROR
;
922 StringSearch
*strsrch
= new StringSearch(pattern
, text
, m_en_us_
, NULL
,
924 if (U_FAILURE(status
)) {
925 errln("Error opening string search %s", u_errorName(status
));
929 if (!assertEqualWithStringSearch(strsrch
, &COLLATOR
[0])) {
934 u_unescape(TESTCOLLATORRULE
, temp
, 128);
936 rules
.setTo(temp
, u_strlen(temp
));
937 RuleBasedCollator
*tailored
= new RuleBasedCollator(rules
, status
);
938 tailored
->setStrength(getECollationStrength(COLLATOR
[1].strength
));
940 if (U_FAILURE(status
)) {
941 errln("Error opening rule based collator %s", u_errorName(status
));
943 if (tailored
!= NULL
) {
949 strsrch
->setCollator(tailored
, status
);
950 if (U_FAILURE(status
) || (*strsrch
->getCollator()) != (*tailored
)) {
951 errln("Error setting rule based collator");
953 if (tailored
!= NULL
) {
958 if (!assertEqualWithStringSearch(strsrch
, &COLLATOR
[1])) {
960 if (tailored
!= NULL
) {
966 strsrch
->setCollator(m_en_us_
, status
);
968 if (U_FAILURE(status
) || (*strsrch
->getCollator()) != (*m_en_us_
)) {
969 errln("Error setting rule based collator");
971 if (tailored
!= NULL
) {
975 if (!assertEqualWithStringSearch(strsrch
, &COLLATOR
[0])) {
976 errln("Error searching collator test");
979 if (tailored
!= NULL
) {
984 void StringSearchTest::TestPattern()
989 u_unescape(PATTERN
[0].text
, temp
, 512);
991 text
.setTo(temp
, u_strlen(temp
));
992 u_unescape(PATTERN
[0].pattern
, temp
, 512);
993 UnicodeString pattern
;
994 pattern
.setTo(temp
, u_strlen(temp
));
996 m_en_us_
->setStrength(getECollationStrength(PATTERN
[0].strength
));
997 UErrorCode status
= U_ZERO_ERROR
;
998 StringSearch
*strsrch
= new StringSearch(pattern
, text
, m_en_us_
, NULL
,
1001 if (U_FAILURE(status
)) {
1002 errln("Error opening string search %s", u_errorName(status
));
1003 m_en_us_
->setStrength(getECollationStrength(UCOL_TERTIARY
));
1004 if (strsrch
!= NULL
) {
1009 if (strsrch
->getPattern() != pattern
) {
1010 errln("Error setting pattern");
1012 if (!assertEqualWithStringSearch(strsrch
, &PATTERN
[0])) {
1013 m_en_us_
->setStrength(getECollationStrength(UCOL_TERTIARY
));
1014 if (strsrch
!= NULL
) {
1020 u_unescape(PATTERN
[1].pattern
, temp
, 512);
1021 pattern
.setTo(temp
, u_strlen(temp
));
1022 strsrch
->setPattern(pattern
, status
);
1023 if (pattern
!= strsrch
->getPattern()) {
1024 errln("Error setting pattern");
1025 m_en_us_
->setStrength(getECollationStrength(UCOL_TERTIARY
));
1026 if (strsrch
!= NULL
) {
1032 if (U_FAILURE(status
)) {
1033 errln("Error setting pattern %s", u_errorName(status
));
1035 if (!assertEqualWithStringSearch(strsrch
, &PATTERN
[1])) {
1036 m_en_us_
->setStrength(getECollationStrength(UCOL_TERTIARY
));
1037 if (strsrch
!= NULL
) {
1043 u_unescape(PATTERN
[0].pattern
, temp
, 512);
1044 pattern
.setTo(temp
, u_strlen(temp
));
1045 strsrch
->setPattern(pattern
, status
);
1046 if (pattern
!= strsrch
->getPattern()) {
1047 errln("Error setting pattern");
1048 m_en_us_
->setStrength(getECollationStrength(UCOL_TERTIARY
));
1049 if (strsrch
!= NULL
) {
1055 if (U_FAILURE(status
)) {
1056 errln("Error setting pattern %s", u_errorName(status
));
1058 if (!assertEqualWithStringSearch(strsrch
, &PATTERN
[0])) {
1059 m_en_us_
->setStrength(getECollationStrength(UCOL_TERTIARY
));
1060 if (strsrch
!= NULL
) {
1065 /* enormous pattern size to see if this crashes */
1066 for (templength
= 0; templength
!= 512; templength
++) {
1067 temp
[templength
] = 0x61;
1070 pattern
.setTo(temp
, 511);
1071 strsrch
->setPattern(pattern
, status
);
1072 if (U_FAILURE(status
)) {
1073 errln("Error setting pattern with size 512, %s", u_errorName(status
));
1075 m_en_us_
->setStrength(getECollationStrength(UCOL_TERTIARY
));
1076 if (strsrch
!= NULL
) {
1081 void StringSearchTest::TestText()
1084 u_unescape(TEXT
[0].text
, temp
, 128);
1086 text
.setTo(temp
, u_strlen(temp
));
1087 u_unescape(TEXT
[0].pattern
, temp
, 128);
1088 UnicodeString pattern
;
1089 pattern
.setTo(temp
, u_strlen(temp
));
1091 UErrorCode status
= U_ZERO_ERROR
;
1092 StringSearch
*strsrch
= new StringSearch(pattern
, text
, m_en_us_
, NULL
,
1094 if (U_FAILURE(status
)) {
1095 errln("Error opening string search %s", u_errorName(status
));
1098 if (text
!= strsrch
->getText()) {
1099 errln("Error setting text");
1101 if (!assertEqualWithStringSearch(strsrch
, &TEXT
[0])) {
1106 u_unescape(TEXT
[1].text
, temp
, 128);
1107 text
.setTo(temp
, u_strlen(temp
));
1108 strsrch
->setText(text
, status
);
1109 if (text
!= strsrch
->getText()) {
1110 errln("Error setting text");
1114 if (U_FAILURE(status
)) {
1115 errln("Error setting text %s", u_errorName(status
));
1117 if (!assertEqualWithStringSearch(strsrch
, &TEXT
[1])) {
1122 u_unescape(TEXT
[0].text
, temp
, 128);
1123 text
.setTo(temp
, u_strlen(temp
));
1124 StringCharacterIterator
chariter(text
);
1125 strsrch
->setText(chariter
, status
);
1126 if (text
!= strsrch
->getText()) {
1127 errln("Error setting text");
1131 if (U_FAILURE(status
)) {
1132 errln("Error setting pattern %s", u_errorName(status
));
1134 if (!assertEqualWithStringSearch(strsrch
, &TEXT
[0])) {
1135 errln("Error searching within set text");
1140 void StringSearchTest::TestCompositeBoundaries()
1143 while (COMPOSITEBOUNDARIES
[count
].text
!= NULL
) {
1144 logln("composite %d", count
);
1145 if (!assertEqual(&COMPOSITEBOUNDARIES
[count
])) {
1146 errln("Error at test number %d", count
);
1152 void StringSearchTest::TestGetSetOffset()
1154 UErrorCode status
= U_ZERO_ERROR
;
1155 UnicodeString
pattern("1234567890123456");
1156 UnicodeString
text("12345678901234567890123456789012");
1157 StringSearch
*strsrch
= new StringSearch(pattern
, text
, m_en_us_
,
1159 /* testing out of bounds error */
1160 strsrch
->setOffset(-1, status
);
1161 if (U_SUCCESS(status
)) {
1162 errln("Error expecting set offset error");
1164 strsrch
->setOffset(128, status
);
1165 if (U_SUCCESS(status
)) {
1166 errln("Error expecting set offset error");
1169 while (BASIC
[index
].text
!= NULL
) {
1170 UErrorCode status
= U_ZERO_ERROR
;
1171 SearchData search
= BASIC
[index
++];
1174 u_unescape(search
.text
, temp
, 128);
1175 text
.setTo(temp
, u_strlen(temp
));
1176 u_unescape(search
.pattern
, temp
, 128);
1177 pattern
.setTo(temp
, u_strlen(temp
));
1178 strsrch
->setText(text
, status
);
1179 strsrch
->setPattern(pattern
, status
);
1180 strsrch
->getCollator()->setStrength(getECollationStrength(
1185 int32_t matchindex
= search
.offset
[count
];
1186 while (U_SUCCESS(status
) && matchindex
>= 0) {
1187 int32_t matchlength
= search
.size
[count
];
1188 strsrch
->next(status
);
1189 if (matchindex
!= strsrch
->getMatchedStart() ||
1190 matchlength
!= strsrch
->getMatchedLength()) {
1191 char *str
= toCharString(strsrch
->getText());
1192 errln("Text: %s", str
);
1193 str
= toCharString(strsrch
->getPattern());
1194 errln("Pattern: %s", str
);
1195 errln("Error match found at %d %d",
1196 strsrch
->getMatchedStart(),
1197 strsrch
->getMatchedLength());
1200 matchindex
= search
.offset
[count
+ 1] == -1 ? -1 :
1201 search
.offset
[count
+ 2];
1202 if (search
.offset
[count
+ 1] != -1) {
1203 strsrch
->setOffset(search
.offset
[count
+ 1] + 1, status
);
1204 if (strsrch
->getOffset() != search
.offset
[count
+ 1] + 1) {
1205 errln("Error setting offset\n");
1212 strsrch
->next(status
);
1213 if (strsrch
->getMatchedStart() != USEARCH_DONE
) {
1214 char *str
= toCharString(strsrch
->getText());
1215 errln("Text: %s", str
);
1216 str
= toCharString(strsrch
->getPattern());
1217 errln("Pattern: %s", str
);
1218 errln("Error match found at %d %d",
1219 strsrch
->getMatchedStart(),
1220 strsrch
->getMatchedLength());
1224 strsrch
->getCollator()->setStrength(getECollationStrength(
1229 void StringSearchTest::TestGetSetAttribute()
1231 UErrorCode status
= U_ZERO_ERROR
;
1232 UnicodeString
pattern("pattern");
1233 UnicodeString
text("text");
1234 StringSearch
*strsrch
= new StringSearch(pattern
, text
, m_en_us_
, NULL
,
1236 if (U_FAILURE(status
)) {
1237 errln("Error opening search %s", u_errorName(status
));
1241 strsrch
->setAttribute(USEARCH_OVERLAP
, USEARCH_DEFAULT
, status
);
1242 if (U_FAILURE(status
) ||
1243 strsrch
->getAttribute(USEARCH_OVERLAP
) != USEARCH_OFF
) {
1244 errln("Error setting overlap to the default");
1246 strsrch
->setAttribute(USEARCH_OVERLAP
, USEARCH_ON
, status
);
1247 if (U_FAILURE(status
) ||
1248 strsrch
->getAttribute(USEARCH_OVERLAP
) != USEARCH_ON
) {
1249 errln("Error setting overlap true");
1251 strsrch
->setAttribute(USEARCH_OVERLAP
, USEARCH_OFF
, status
);
1252 if (U_FAILURE(status
) ||
1253 strsrch
->getAttribute(USEARCH_OVERLAP
) != USEARCH_OFF
) {
1254 errln("Error setting overlap false");
1256 strsrch
->setAttribute(USEARCH_OVERLAP
, USEARCH_ATTRIBUTE_VALUE_COUNT
,
1258 if (U_SUCCESS(status
)) {
1259 errln("Error setting overlap to illegal value");
1261 status
= U_ZERO_ERROR
;
1262 strsrch
->setAttribute(USEARCH_CANONICAL_MATCH
, USEARCH_DEFAULT
, status
);
1263 if (U_FAILURE(status
) ||
1264 strsrch
->getAttribute(USEARCH_CANONICAL_MATCH
) != USEARCH_OFF
) {
1265 errln("Error setting canonical match to the default");
1267 strsrch
->setAttribute(USEARCH_CANONICAL_MATCH
, USEARCH_ON
, status
);
1268 if (U_FAILURE(status
) ||
1269 strsrch
->getAttribute(USEARCH_CANONICAL_MATCH
) != USEARCH_ON
) {
1270 errln("Error setting canonical match true");
1272 strsrch
->setAttribute(USEARCH_CANONICAL_MATCH
, USEARCH_OFF
, status
);
1273 if (U_FAILURE(status
) ||
1274 strsrch
->getAttribute(USEARCH_CANONICAL_MATCH
) != USEARCH_OFF
) {
1275 errln("Error setting canonical match false");
1277 strsrch
->setAttribute(USEARCH_CANONICAL_MATCH
,
1278 USEARCH_ATTRIBUTE_VALUE_COUNT
, status
);
1279 if (U_SUCCESS(status
)) {
1280 errln("Error setting canonical match to illegal value");
1282 status
= U_ZERO_ERROR
;
1283 strsrch
->setAttribute(USEARCH_ATTRIBUTE_COUNT
, USEARCH_DEFAULT
, status
);
1284 if (U_SUCCESS(status
)) {
1285 errln("Error setting illegal attribute success");
1291 void StringSearchTest::TestGetMatch()
1294 SearchData search
= MATCH
[0];
1295 u_unescape(search
.text
, temp
, 128);
1297 text
.setTo(temp
, u_strlen(temp
));
1298 u_unescape(search
.pattern
, temp
, 128);
1299 UnicodeString pattern
;
1300 pattern
.setTo(temp
, u_strlen(temp
));
1302 UErrorCode status
= U_ZERO_ERROR
;
1303 StringSearch
*strsrch
= new StringSearch(pattern
, text
, m_en_us_
, NULL
,
1305 if (U_FAILURE(status
)) {
1306 errln("Error opening string search %s", u_errorName(status
));
1307 if (strsrch
!= NULL
) {
1314 int32_t matchindex
= search
.offset
[count
];
1315 UnicodeString matchtext
;
1316 while (U_SUCCESS(status
) && matchindex
>= 0) {
1317 int32_t matchlength
= search
.size
[count
];
1318 strsrch
->next(status
);
1319 if (matchindex
!= strsrch
->getMatchedStart() ||
1320 matchlength
!= strsrch
->getMatchedLength()) {
1321 char *str
= toCharString(strsrch
->getText());
1322 errln("Text: %s", str
);
1323 str
= toCharString(strsrch
->getPattern());
1324 errln("Pattern: %s", str
);
1325 errln("Error match found at %d %d", strsrch
->getMatchedStart(),
1326 strsrch
->getMatchedLength());
1331 status
= U_ZERO_ERROR
;
1332 strsrch
->getMatchedText(matchtext
);
1333 if (matchtext
.length() != matchlength
|| U_FAILURE(status
)){
1334 errln("Error getting match text");
1336 matchindex
= search
.offset
[count
];
1338 status
= U_ZERO_ERROR
;
1339 strsrch
->next(status
);
1340 if (strsrch
->getMatchedStart() != USEARCH_DONE
||
1341 strsrch
->getMatchedLength() != 0) {
1342 errln("Error end of match not found");
1344 status
= U_ZERO_ERROR
;
1345 strsrch
->getMatchedText(matchtext
);
1346 if (matchtext
.length() != 0) {
1347 errln("Error getting null matches");
1352 void StringSearchTest::TestSetMatch()
1355 while (MATCH
[count
].text
!= NULL
) {
1356 SearchData search
= MATCH
[count
];
1358 UErrorCode status
= U_ZERO_ERROR
;
1359 u_unescape(search
.text
, temp
, 128);
1361 text
.setTo(temp
, u_strlen(temp
));
1362 u_unescape(search
.pattern
, temp
, 128);
1363 UnicodeString pattern
;
1364 pattern
.setTo(temp
, u_strlen(temp
));
1366 StringSearch
*strsrch
= new StringSearch(pattern
, text
, m_en_us_
,
1368 if (U_FAILURE(status
)) {
1369 errln("Error opening string search %s", u_errorName(status
));
1370 if (strsrch
!= NULL
) {
1377 while (search
.offset
[size
] != -1) {
1381 if (strsrch
->first(status
) != search
.offset
[0] || U_FAILURE(status
)) {
1382 errln("Error getting first match");
1384 if (strsrch
->last(status
) != search
.offset
[size
-1] ||
1385 U_FAILURE(status
)) {
1386 errln("Error getting last match");
1390 while (index
< size
) {
1391 if (index
+ 2 < size
) {
1392 if (strsrch
->following(search
.offset
[index
+ 2] - 1, status
)
1393 != search
.offset
[index
+ 2] || U_FAILURE(status
)) {
1394 errln("Error getting following match at index %d",
1395 search
.offset
[index
+ 2] - 1);
1398 if (index
+ 1 < size
) {
1399 if (strsrch
->preceding(search
.offset
[index
+ 1] +
1400 search
.size
[index
+ 1] + 1,
1401 status
) != search
.offset
[index
+ 1] ||
1402 U_FAILURE(status
)) {
1403 errln("Error getting preceeding match at index %d",
1404 search
.offset
[index
+ 1] + 1);
1409 status
= U_ZERO_ERROR
;
1410 if (strsrch
->following(text
.length(), status
) != USEARCH_DONE
) {
1411 errln("Error expecting out of bounds match");
1413 if (strsrch
->preceding(0, status
) != USEARCH_DONE
) {
1414 errln("Error expecting out of bounds match");
1421 void StringSearchTest::TestReset()
1423 UErrorCode status
= U_ZERO_ERROR
;
1424 UnicodeString
text("fish fish");
1425 UnicodeString
pattern("s");
1426 StringSearch
*strsrch
= new StringSearch(pattern
, text
, m_en_us_
, NULL
,
1428 if (U_FAILURE(status
)) {
1429 errln("Error opening string search %s", u_errorName(status
));
1430 if (strsrch
!= NULL
) {
1435 strsrch
->setAttribute(USEARCH_OVERLAP
, USEARCH_ON
, status
);
1436 strsrch
->setAttribute(USEARCH_CANONICAL_MATCH
, USEARCH_ON
, status
);
1437 strsrch
->setOffset(9, status
);
1438 if (U_FAILURE(status
)) {
1439 errln("Error setting attributes and offsets");
1443 if (strsrch
->getAttribute(USEARCH_OVERLAP
) != USEARCH_OFF
||
1444 strsrch
->getAttribute(USEARCH_CANONICAL_MATCH
) != USEARCH_OFF
||
1445 strsrch
->getOffset() != 0 || strsrch
->getMatchedLength() != 0 ||
1446 strsrch
->getMatchedStart() != USEARCH_DONE
) {
1447 errln("Error resetting string search");
1449 strsrch
->previous(status
);
1450 if (strsrch
->getMatchedStart() != 7 ||
1451 strsrch
->getMatchedLength() != 1) {
1452 errln("Error resetting string search\n");
1458 void StringSearchTest::TestSupplementary()
1461 while (SUPPLEMENTARY
[count
].text
!= NULL
) {
1462 if (!assertEqual(&SUPPLEMENTARY
[count
])) {
1463 errln("Error at test number %d", count
);
1469 void StringSearchTest::TestContraction()
1472 UErrorCode status
= U_ZERO_ERROR
;
1474 u_unescape(CONTRACTIONRULE
, temp
, 128);
1475 UnicodeString rules
;
1476 rules
.setTo(temp
, u_strlen(temp
));
1477 RuleBasedCollator
*collator
= new RuleBasedCollator(rules
,
1478 getECollationStrength(UCOL_TERTIARY
), UCOL_ON
, status
);
1479 if (U_FAILURE(status
)) {
1480 errln("Error opening collator %s", u_errorName(status
));
1482 UnicodeString
text("text");
1483 UnicodeString
pattern("pattern");
1484 StringSearch
*strsrch
= new StringSearch(pattern
, text
, collator
, NULL
,
1486 if (U_FAILURE(status
)) {
1487 errln("Error opening string search %s", u_errorName(status
));
1491 while (CONTRACTION
[count
].text
!= NULL
) {
1492 u_unescape(CONTRACTION
[count
].text
, temp
, 128);
1493 text
.setTo(temp
, u_strlen(temp
));
1494 u_unescape(CONTRACTION
[count
].pattern
, temp
, 128);
1495 pattern
.setTo(temp
, u_strlen(temp
));
1496 strsrch
->setText(text
, status
);
1497 strsrch
->setPattern(pattern
, status
);
1498 if (!assertEqualWithStringSearch(strsrch
, &CONTRACTION
[count
])) {
1499 errln("Error at test number %d", count
);
1507 void StringSearchTest::TestIgnorable()
1510 u_unescape(IGNORABLERULE
, temp
, 128);
1511 UnicodeString rules
;
1512 rules
.setTo(temp
, u_strlen(temp
));
1513 UErrorCode status
= U_ZERO_ERROR
;
1515 RuleBasedCollator
*collator
= new RuleBasedCollator(rules
,
1516 getECollationStrength(IGNORABLE
[count
].strength
),
1518 if (U_FAILURE(status
)) {
1519 errln("Error opening collator %s", u_errorName(status
));
1522 UnicodeString
pattern("pattern");
1523 UnicodeString
text("text");
1524 StringSearch
*strsrch
= new StringSearch(pattern
, text
, collator
, NULL
,
1526 if (U_FAILURE(status
)) {
1527 errln("Error opening string search %s", u_errorName(status
));
1532 while (IGNORABLE
[count
].text
!= NULL
) {
1533 u_unescape(IGNORABLE
[count
].text
, temp
, 128);
1534 text
.setTo(temp
, u_strlen(temp
));
1535 u_unescape(IGNORABLE
[count
].pattern
, temp
, 128);
1536 pattern
.setTo(temp
, u_strlen(temp
));
1537 strsrch
->setText(text
, status
);
1538 strsrch
->setPattern(pattern
, status
);
1539 if (!assertEqualWithStringSearch(strsrch
, &IGNORABLE
[count
])) {
1540 errln("Error at test number %d", count
);
1548 void StringSearchTest::TestCanonical()
1551 while (BASICCANONICAL
[count
].text
!= NULL
) {
1552 if (!assertCanonicalEqual(&BASICCANONICAL
[count
])) {
1553 errln("Error at test number %d", count
);
1559 void StringSearchTest::TestNormCanonical()
1561 UErrorCode status
= U_ZERO_ERROR
;
1562 m_en_us_
->setAttribute(UCOL_NORMALIZATION_MODE
, UCOL_ON
, status
);
1564 while (NORMCANONICAL
[count
].text
!= NULL
) {
1565 if (!assertCanonicalEqual(&NORMCANONICAL
[count
])) {
1566 errln("Error at test number %d", count
);
1570 m_en_us_
->setAttribute(UCOL_NORMALIZATION_MODE
, UCOL_OFF
, status
);
1573 void StringSearchTest::TestStrengthCanonical()
1576 while (STRENGTHCANONICAL
[count
].text
!= NULL
) {
1577 if (!assertCanonicalEqual(&STRENGTHCANONICAL
[count
])) {
1578 errln("Error at test number %d", count
);
1584 #if !UCONFIG_NO_BREAK_ITERATION
1586 void StringSearchTest::TestBreakIteratorCanonical()
1588 UErrorCode status
= U_ZERO_ERROR
;
1592 // special purposes for tests numbers 0-3
1594 const SearchData
*search
= &(BREAKITERATORCANONICAL
[count
]);
1596 u_unescape(search
->text
, temp
, 128);
1598 text
.setTo(temp
, u_strlen(temp
));
1599 u_unescape(search
->pattern
, temp
, 128);
1600 UnicodeString pattern
;
1601 pattern
.setTo(temp
, u_strlen(temp
));
1602 RuleBasedCollator
*collator
= getCollator(search
->collator
);
1603 collator
->setStrength(getECollationStrength(search
->strength
));
1605 BreakIterator
*breaker
= getBreakIterator(search
->breaker
);
1606 StringSearch
*strsrch
= new StringSearch(pattern
, text
, collator
,
1608 if (U_FAILURE(status
)) {
1609 errln("Error creating string search data");
1612 strsrch
->setAttribute(USEARCH_CANONICAL_MATCH
, USEARCH_ON
, status
);
1613 if (U_FAILURE(status
) ||
1614 strsrch
->getBreakIterator() != breaker
) {
1615 errln("Error setting break iterator");
1619 if (!assertEqualWithStringSearch(strsrch
, search
)) {
1620 collator
->setStrength(getECollationStrength(UCOL_TERTIARY
));
1624 search
= &(BREAKITERATOREXACT
[count
+ 1]);
1625 breaker
= getBreakIterator(search
->breaker
);
1626 if (breaker
== NULL
) {
1627 errln("Error creating BreakIterator");
1630 breaker
->setText(strsrch
->getText());
1631 strsrch
->setBreakIterator(breaker
, status
);
1632 if (U_FAILURE(status
) || strsrch
->getBreakIterator() != breaker
) {
1633 errln("Error setting break iterator");
1638 strsrch
->setAttribute(USEARCH_CANONICAL_MATCH
, USEARCH_ON
, status
);
1639 if (!assertEqualWithStringSearch(strsrch
, search
)) {
1640 errln("Error at test number %d", count
);
1647 while (BREAKITERATORCANONICAL
[count
].text
!= NULL
) {
1648 if (!assertEqual(&BREAKITERATORCANONICAL
[count
])) {
1649 errln("Error at test number %d", count
);
1658 void StringSearchTest::TestVariableCanonical()
1661 UErrorCode status
= U_ZERO_ERROR
;
1662 m_en_us_
->setAttribute(UCOL_ALTERNATE_HANDLING
, UCOL_SHIFTED
, status
);
1663 if (U_FAILURE(status
)) {
1664 errln("Error setting collation alternate attribute %s",
1665 u_errorName(status
));
1667 while (VARIABLE
[count
].text
!= NULL
) {
1668 logln("variable %d", count
);
1669 if (!assertCanonicalEqual(&VARIABLE
[count
])) {
1670 errln("Error at test number %d", count
);
1674 m_en_us_
->setAttribute(UCOL_ALTERNATE_HANDLING
, UCOL_NON_IGNORABLE
,
1678 void StringSearchTest::TestOverlapCanonical()
1681 while (OVERLAPCANONICAL
[count
].text
!= NULL
) {
1682 if (!assertEqualWithAttribute(&OVERLAPCANONICAL
[count
], USEARCH_ON
,
1684 errln("Error at overlap test number %d", count
);
1689 while (NONOVERLAP
[count
].text
!= NULL
) {
1690 if (!assertCanonicalEqual(&NONOVERLAPCANONICAL
[count
])) {
1691 errln("Error at non overlap test number %d", count
);
1699 const SearchData
*search
= &(OVERLAPCANONICAL
[count
]);
1700 UErrorCode status
= U_ZERO_ERROR
;
1702 u_unescape(search
->text
, temp
, 128);
1704 text
.setTo(temp
, u_strlen(temp
));
1705 u_unescape(search
->pattern
, temp
, 128);
1706 UnicodeString pattern
;
1707 pattern
.setTo(temp
, u_strlen(temp
));
1708 RuleBasedCollator
*collator
= getCollator(search
->collator
);
1709 StringSearch
*strsrch
= new StringSearch(pattern
, text
, collator
,
1711 strsrch
->setAttribute(USEARCH_CANONICAL_MATCH
, USEARCH_ON
, status
);
1712 strsrch
->setAttribute(USEARCH_OVERLAP
, USEARCH_ON
, status
);
1713 if (U_FAILURE(status
) ||
1714 strsrch
->getAttribute(USEARCH_OVERLAP
) != USEARCH_ON
) {
1715 errln("Error setting overlap option");
1717 if (!assertEqualWithStringSearch(strsrch
, search
)) {
1721 search
= &(NONOVERLAPCANONICAL
[count
]);
1722 strsrch
->setAttribute(USEARCH_OVERLAP
, USEARCH_OFF
, status
);
1723 if (U_FAILURE(status
) ||
1724 strsrch
->getAttribute(USEARCH_OVERLAP
) != USEARCH_OFF
) {
1725 errln("Error setting overlap option");
1728 if (!assertEqualWithStringSearch(strsrch
, search
)) {
1730 errln("Error at test number %d", count
);
1738 void StringSearchTest::TestCollatorCanonical()
1740 /* test collator that thinks "o" and "p" are the same thing */
1742 u_unescape(COLLATORCANONICAL
[0].text
, temp
, 128);
1744 text
.setTo(temp
, u_strlen(temp
));
1745 u_unescape(COLLATORCANONICAL
[0].pattern
, temp
, 128);
1746 UnicodeString pattern
;
1747 pattern
.setTo(temp
, u_strlen(temp
));
1749 UErrorCode status
= U_ZERO_ERROR
;
1750 StringSearch
*strsrch
= new StringSearch(pattern
, text
, m_en_us_
,
1752 strsrch
->setAttribute(USEARCH_CANONICAL_MATCH
, USEARCH_ON
, status
);
1753 if (U_FAILURE(status
)) {
1754 errln("Error opening string search %s", u_errorName(status
));
1756 if (!assertEqualWithStringSearch(strsrch
, &COLLATORCANONICAL
[0])) {
1761 u_unescape(TESTCOLLATORRULE
, temp
, 128);
1762 UnicodeString rules
;
1763 rules
.setTo(temp
, u_strlen(temp
));
1764 RuleBasedCollator
*tailored
= new RuleBasedCollator(rules
,
1765 getECollationStrength(COLLATORCANONICAL
[1].strength
),
1768 if (U_FAILURE(status
)) {
1769 errln("Error opening rule based collator %s", u_errorName(status
));
1772 strsrch
->setCollator(tailored
, status
);
1773 if (U_FAILURE(status
) || *(strsrch
->getCollator()) != *tailored
) {
1774 errln("Error setting rule based collator");
1777 strsrch
->setAttribute(USEARCH_CANONICAL_MATCH
, USEARCH_ON
, status
);
1778 if (!assertEqualWithStringSearch(strsrch
, &COLLATORCANONICAL
[1])) {
1780 if (tailored
!= NULL
) {
1785 strsrch
->setCollator(m_en_us_
, status
);
1787 if (U_FAILURE(status
) || *(strsrch
->getCollator()) != *m_en_us_
) {
1788 errln("Error setting rule based collator");
1790 if (!assertEqualWithStringSearch(strsrch
, &COLLATORCANONICAL
[0])) {
1793 if (tailored
!= NULL
) {
1798 void StringSearchTest::TestPatternCanonical()
1803 u_unescape(PATTERNCANONICAL
[0].text
, temp
, 128);
1805 text
.setTo(temp
, u_strlen(temp
));
1806 u_unescape(PATTERNCANONICAL
[0].pattern
, temp
, 128);
1807 UnicodeString pattern
;
1808 pattern
.setTo(temp
, u_strlen(temp
));
1810 m_en_us_
->setStrength(
1811 getECollationStrength(PATTERNCANONICAL
[0].strength
));
1813 UErrorCode status
= U_ZERO_ERROR
;
1814 StringSearch
*strsrch
= new StringSearch(pattern
, text
, m_en_us_
, NULL
,
1816 strsrch
->setAttribute(USEARCH_CANONICAL_MATCH
, USEARCH_ON
, status
);
1817 if (U_FAILURE(status
)) {
1818 errln("Error opening string search %s", u_errorName(status
));
1819 goto ENDTESTPATTERN
;
1821 if (pattern
!= strsrch
->getPattern()) {
1822 errln("Error setting pattern");
1824 if (!assertEqualWithStringSearch(strsrch
, &PATTERNCANONICAL
[0])) {
1825 goto ENDTESTPATTERN
;
1828 u_unescape(PATTERNCANONICAL
[1].pattern
, temp
, 128);
1829 pattern
.setTo(temp
, u_strlen(temp
));
1830 strsrch
->setPattern(pattern
, status
);
1831 if (pattern
!= strsrch
->getPattern()) {
1832 errln("Error setting pattern");
1833 goto ENDTESTPATTERN
;
1836 strsrch
->setAttribute(USEARCH_CANONICAL_MATCH
, USEARCH_ON
, status
);
1837 if (U_FAILURE(status
)) {
1838 errln("Error setting pattern %s", u_errorName(status
));
1840 if (!assertEqualWithStringSearch(strsrch
, &PATTERNCANONICAL
[1])) {
1841 goto ENDTESTPATTERN
;
1844 u_unescape(PATTERNCANONICAL
[0].pattern
, temp
, 128);
1845 pattern
.setTo(temp
, u_strlen(temp
));
1846 strsrch
->setPattern(pattern
, status
);
1847 if (pattern
!= strsrch
->getPattern()) {
1848 errln("Error setting pattern");
1849 goto ENDTESTPATTERN
;
1852 strsrch
->setAttribute(USEARCH_CANONICAL_MATCH
, USEARCH_ON
, status
);
1853 if (U_FAILURE(status
)) {
1854 errln("Error setting pattern %s", u_errorName(status
));
1856 if (!assertEqualWithStringSearch(strsrch
, &PATTERNCANONICAL
[0])) {
1857 goto ENDTESTPATTERN
;
1860 m_en_us_
->setStrength(getECollationStrength(UCOL_TERTIARY
));
1861 if (strsrch
!= NULL
) {
1866 void StringSearchTest::TestTextCanonical()
1869 u_unescape(TEXTCANONICAL
[0].text
, temp
, 128);
1871 text
.setTo(temp
, u_strlen(temp
));
1872 u_unescape(TEXTCANONICAL
[0].pattern
, temp
, 128);
1873 UnicodeString pattern
;
1874 pattern
.setTo(temp
, u_strlen(temp
));
1876 UErrorCode status
= U_ZERO_ERROR
;
1877 StringSearch
*strsrch
= new StringSearch(pattern
, text
, m_en_us_
, NULL
,
1879 strsrch
->setAttribute(USEARCH_CANONICAL_MATCH
, USEARCH_ON
, status
);
1881 if (U_FAILURE(status
)) {
1882 errln("Error opening string search %s", u_errorName(status
));
1883 goto ENDTESTPATTERN
;
1885 if (text
!= strsrch
->getText()) {
1886 errln("Error setting text");
1888 if (!assertEqualWithStringSearch(strsrch
, &TEXTCANONICAL
[0])) {
1889 goto ENDTESTPATTERN
;
1892 u_unescape(TEXTCANONICAL
[1].text
, temp
, 128);
1893 text
.setTo(temp
, u_strlen(temp
));
1894 strsrch
->setText(text
, status
);
1895 if (text
!= strsrch
->getText()) {
1896 errln("Error setting text");
1897 goto ENDTESTPATTERN
;
1899 if (U_FAILURE(status
)) {
1900 errln("Error setting text %s", u_errorName(status
));
1902 if (!assertEqualWithStringSearch(strsrch
, &TEXTCANONICAL
[1])) {
1903 goto ENDTESTPATTERN
;
1906 u_unescape(TEXTCANONICAL
[0].text
, temp
, 128);
1907 text
.setTo(temp
, u_strlen(temp
));
1908 strsrch
->setText(text
, status
);
1909 if (text
!= strsrch
->getText()) {
1910 errln("Error setting text");
1911 goto ENDTESTPATTERN
;
1913 if (U_FAILURE(status
)) {
1914 errln("Error setting pattern %s", u_errorName(status
));
1916 if (!assertEqualWithStringSearch(strsrch
, &TEXTCANONICAL
[0])) {
1917 goto ENDTESTPATTERN
;
1920 if (strsrch
!= NULL
) {
1925 void StringSearchTest::TestCompositeBoundariesCanonical()
1928 while (COMPOSITEBOUNDARIESCANONICAL
[count
].text
!= NULL
) {
1929 logln("composite %d", count
);
1930 if (!assertCanonicalEqual(&COMPOSITEBOUNDARIESCANONICAL
[count
])) {
1931 errln("Error at test number %d", count
);
1937 void StringSearchTest::TestGetSetOffsetCanonical()
1940 UErrorCode status
= U_ZERO_ERROR
;
1941 UnicodeString
text("text");
1942 UnicodeString
pattern("pattern");
1943 StringSearch
*strsrch
= new StringSearch(pattern
, text
, m_en_us_
, NULL
,
1945 strsrch
->setAttribute(USEARCH_CANONICAL_MATCH
, USEARCH_ON
, status
);
1946 /* testing out of bounds error */
1947 strsrch
->setOffset(-1, status
);
1948 if (U_SUCCESS(status
)) {
1949 errln("Error expecting set offset error");
1951 strsrch
->setOffset(128, status
);
1952 if (U_SUCCESS(status
)) {
1953 errln("Error expecting set offset error");
1957 while (BASICCANONICAL
[index
].text
!= NULL
) {
1958 SearchData search
= BASICCANONICAL
[index
++];
1959 if (BASICCANONICAL
[index
].text
== NULL
) {
1960 /* skip the last one */
1964 u_unescape(search
.text
, temp
, 128);
1965 text
.setTo(temp
, u_strlen(temp
));
1966 u_unescape(search
.pattern
, temp
, 128);
1967 pattern
.setTo(temp
, u_strlen(temp
));
1969 UErrorCode status
= U_ZERO_ERROR
;
1970 strsrch
->setText(text
, status
);
1972 strsrch
->setPattern(pattern
, status
);
1975 int32_t matchindex
= search
.offset
[count
];
1976 while (U_SUCCESS(status
) && matchindex
>= 0) {
1977 int32_t matchlength
= search
.size
[count
];
1978 strsrch
->next(status
);
1979 if (matchindex
!= strsrch
->getMatchedStart() ||
1980 matchlength
!= strsrch
->getMatchedLength()) {
1981 char *str
= toCharString(strsrch
->getText());
1982 errln("Text: %s", str
);
1983 str
= toCharString(strsrch
->getPattern());
1984 errln("Pattern: %s", str
);
1985 errln("Error match found at %d %d",
1986 strsrch
->getMatchedStart(),
1987 strsrch
->getMatchedLength());
1990 matchindex
= search
.offset
[count
+ 1] == -1 ? -1 :
1991 search
.offset
[count
+ 2];
1992 if (search
.offset
[count
+ 1] != -1) {
1993 strsrch
->setOffset(search
.offset
[count
+ 1] + 1, status
);
1994 if (strsrch
->getOffset() != search
.offset
[count
+ 1] + 1) {
1995 errln("Error setting offset");
2002 strsrch
->next(status
);
2003 if (strsrch
->getMatchedStart() != USEARCH_DONE
) {
2004 char *str
= toCharString(strsrch
->getText());
2005 errln("Text: %s", str
);
2006 str
= toCharString(strsrch
->getPattern());
2007 errln("Pattern: %s", str
);
2008 errln("Error match found at %d %d", strsrch
->getMatchedStart(),
2009 strsrch
->getMatchedLength());
2016 void StringSearchTest::TestSupplementaryCanonical()
2019 while (SUPPLEMENTARYCANONICAL
[count
].text
!= NULL
) {
2020 if (!assertCanonicalEqual(&SUPPLEMENTARYCANONICAL
[count
])) {
2021 errln("Error at test number %d", count
);
2027 void StringSearchTest::TestContractionCanonical()
2031 u_unescape(CONTRACTIONRULE
, temp
, 128);
2032 UnicodeString rules
;
2033 rules
.setTo(temp
, u_strlen(temp
));
2035 UErrorCode status
= U_ZERO_ERROR
;
2036 RuleBasedCollator
*collator
= new RuleBasedCollator(rules
,
2037 getECollationStrength(UCOL_TERTIARY
), UCOL_ON
, status
);
2038 if (U_FAILURE(status
)) {
2039 errln("Error opening collator %s", u_errorName(status
));
2041 UnicodeString
text("text");
2042 UnicodeString
pattern("pattern");
2043 StringSearch
*strsrch
= new StringSearch(pattern
, text
, collator
, NULL
,
2045 strsrch
->setAttribute(USEARCH_CANONICAL_MATCH
, USEARCH_ON
, status
);
2046 if (U_FAILURE(status
)) {
2047 errln("Error opening string search %s", u_errorName(status
));
2051 while (CONTRACTIONCANONICAL
[count
].text
!= NULL
) {
2052 u_unescape(CONTRACTIONCANONICAL
[count
].text
, temp
, 128);
2053 text
.setTo(temp
, u_strlen(temp
));
2054 u_unescape(CONTRACTIONCANONICAL
[count
].pattern
, temp
, 128);
2055 pattern
.setTo(temp
, u_strlen(temp
));
2056 strsrch
->setText(text
, status
);
2057 strsrch
->setPattern(pattern
, status
);
2058 if (!assertEqualWithStringSearch(strsrch
,
2059 &CONTRACTIONCANONICAL
[count
])) {
2060 errln("Error at test number %d", count
);
2068 void StringSearchTest::TestUClassID()
2070 char id
= *((char *)StringSearch::getStaticClassID());
2072 errln("Static class id for StringSearch should be 0");
2074 UErrorCode status
= U_ZERO_ERROR
;
2075 UnicodeString
text("text");
2076 UnicodeString
pattern("pattern");
2077 StringSearch
*strsrch
= new StringSearch(pattern
, text
, m_en_us_
, NULL
,
2079 id
= *((char *)strsrch
->getDynamicClassID());
2081 errln("Dynamic class id for StringSearch should be 0");
2086 class TestSearch
: public SearchIterator
2089 TestSearch(const TestSearch
&obj
);
2090 TestSearch(const UnicodeString
&text
,
2091 BreakIterator
*breakiter
,
2092 const UnicodeString
&pattern
);
2095 void setOffset(int32_t position
, UErrorCode
&status
);
2096 int32_t getOffset() const;
2097 SearchIterator
* safeClone() const;
2101 * ICU "poor man's RTTI", returns a UClassID for the actual class.
2105 virtual inline UClassID
getDynamicClassID() const { return getStaticClassID(); }
2108 * ICU "poor man's RTTI", returns a UClassID for this class.
2112 static inline UClassID
getStaticClassID() { return (UClassID
)&fgClassID
; }
2114 UBool
operator!=(const TestSearch
&that
) const;
2116 UnicodeString m_pattern_
;
2119 int32_t handleNext(int32_t position
, UErrorCode
&status
);
2120 int32_t handlePrev(int32_t position
, UErrorCode
&status
);
2121 TestSearch
& operator=(const TestSearch
&that
);
2126 * The address of this static class variable serves as this class's ID
2127 * for ICU "poor man's RTTI".
2129 static const char fgClassID
;
2133 const char TestSearch::fgClassID
=0;
2135 TestSearch::TestSearch(const TestSearch
&obj
) : SearchIterator(obj
)
2137 m_offset_
= obj
.m_offset_
;
2138 m_pattern_
= obj
.m_pattern_
;
2141 TestSearch::TestSearch(const UnicodeString
&text
,
2142 BreakIterator
*breakiter
,
2143 const UnicodeString
&pattern
) : SearchIterator()
2145 m_breakiterator_
= breakiter
;
2146 m_pattern_
= pattern
;
2149 m_pattern_
= pattern
;
2152 TestSearch::~TestSearch()
2157 void TestSearch::setOffset(int32_t position
, UErrorCode
&status
)
2159 if (position
>= 0 && position
<= m_text_
.length()) {
2160 m_offset_
= position
;
2163 status
= U_INDEX_OUTOFBOUNDS_ERROR
;
2167 int32_t TestSearch::getOffset() const
2172 SearchIterator
* TestSearch::safeClone() const
2174 return new TestSearch(m_text_
, m_breakiterator_
, m_pattern_
);
2177 UBool
TestSearch::operator!=(const TestSearch
&that
) const
2179 if (SearchIterator::operator !=(that
)) {
2182 return m_offset_
!= that
.m_offset_
|| m_pattern_
!= that
.m_pattern_
;
2185 int32_t TestSearch::handleNext(int32_t start
, UErrorCode
&status
)
2187 if(U_SUCCESS(status
)) {
2188 int match
= m_text_
.indexOf(m_pattern_
, start
);
2190 m_offset_
= m_text_
.length();
2191 setMatchStart(m_offset_
);
2193 return USEARCH_DONE
;
2195 setMatchStart(match
);
2197 setMatchLength(m_pattern_
.length());
2200 return USEARCH_DONE
;
2204 int32_t TestSearch::handlePrev(int32_t start
, UErrorCode
&status
)
2206 if(U_SUCCESS(status
)) {
2207 int match
= m_text_
.lastIndexOf(m_pattern_
, 0, start
);
2210 setMatchStart(m_offset_
);
2212 return USEARCH_DONE
;
2214 setMatchStart(match
);
2216 setMatchLength(m_pattern_
.length());
2219 return USEARCH_DONE
;
2223 TestSearch
& TestSearch::operator=(const TestSearch
&that
)
2225 SearchIterator::operator=(that
);
2226 m_offset_
= that
.m_offset_
;
2227 m_pattern_
= that
.m_pattern_
;
2231 void StringSearchTest::TestSubclass()
2233 UnicodeString
text("abc abcd abc");
2234 UnicodeString
pattern("abc");
2235 TestSearch
search(text
, NULL
, pattern
);
2236 TestSearch
search2(search
);
2237 int expected
[] = {0, 4, 9};
2238 UErrorCode status
= U_ZERO_ERROR
;
2240 StringCharacterIterator
chariter(text
);
2242 search
.setText(text
, status
);
2243 if (search
.getText() != search2
.getText()) {
2244 errln("Error setting text");
2247 search
.setText(chariter
, status
);
2248 if (search
.getText() != search2
.getText()) {
2249 errln("Error setting text");
2253 // comparing constructors
2255 for (i
= 0; i
< (int)(sizeof(expected
) / sizeof(expected
[0])); i
++) {
2256 if (search
.next(status
) != expected
[i
]) {
2257 errln("Error getting next match");
2259 if (search
.getMatchedLength() != search
.m_pattern_
.length()) {
2260 errln("Error getting next match length");
2263 if (search
.next(status
) != USEARCH_DONE
) {
2264 errln("Error should have reached the end of the iteration");
2266 for (i
= sizeof(expected
) / sizeof(expected
[0]) - 1; i
>= 0; i
--) {
2267 if (search
.previous(status
) != expected
[i
]) {
2268 errln("Error getting previous match");
2270 if (search
.getMatchedLength() != search
.m_pattern_
.length()) {
2271 errln("Error getting previous match length");
2274 if (search
.previous(status
) != USEARCH_DONE
) {
2275 errln("Error should have reached the start of the iteration");
2279 class StubSearchIterator
:public SearchIterator
{
2281 StubSearchIterator(){}
2282 virtual void setOffset(int32_t , UErrorCode
&) {};
2283 virtual int32_t getOffset(void) const {return 0;};
2284 virtual SearchIterator
* safeClone(void) const {return NULL
;};
2285 virtual int32_t handleNext(int32_t , UErrorCode
&){return 0;};
2286 virtual int32_t handlePrev(int32_t , UErrorCode
&) {return 0;};
2287 virtual UClassID
getDynamicClassID() const {
2288 static char classID
= 0;
2289 return (UClassID
)&classID
;
2293 void StringSearchTest::TestCoverage(){
2294 StubSearchIterator stub1
, stub2
;
2295 UErrorCode status
= U_ZERO_ERROR
;
2297 if (stub1
!= stub2
){
2298 errln("new StubSearchIterator should be equal");
2301 stub2
.setText(UnicodeString("ABC"), status
);
2302 if (U_FAILURE(status
)) {
2303 errln("Error: SearchIterator::SetText");
2307 if (stub1
!= stub2
){
2308 errln("SearchIterator::operator = assigned object should be equal");
2312 #endif /* #if !UCONFIG_NO_COLLATION */