1 /********************************************************************
3 * Copyright (c) 1997-2016, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
7 #include "unicode/utypes.h"
9 #if !UCONFIG_NO_COLLATION
11 #include "unicode/coll.h"
12 #include "unicode/tblcoll.h"
13 #include "unicode/unistr.h"
14 #include "unicode/sortkey.h"
18 #include "../cintltst/calldata.h"
21 CollationDummyTest::CollationDummyTest()
24 /*UErrorCode status = U_ZERO_ERROR;
25 UnicodeString rules(TRUE, DEFAULTRULEARRAY, UPRV_LENGTHOF(DEFAULTRULEARRAY));
26 UnicodeString newRules("& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ");
28 myCollation = new RuleBasedCollator(rules, status);
31 UErrorCode status
= U_ZERO_ERROR
;
32 UnicodeString
ruleset("& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ");
33 if (myCollation
!= NULL
)
37 myCollation
= new RuleBasedCollator(ruleset
, status
);
38 if(U_FAILURE(status
)){
39 errcheckln(status
, "ERROR: in creation of rule based collator from ruleset - %s", u_errorName(status
));
45 CollationDummyTest::~CollationDummyTest()
50 const Collator::EComparisonResult
CollationDummyTest::results
[] = {
52 Collator::LESS
, /*Collator::GREATER,*/
60 Collator::LESS
, /* 10 */
68 /* test primary > 17 */
71 Collator::EQUAL
, /* 20 */
78 /* test secondary > 26 */
83 Collator::EQUAL
, /* 30 */
86 Collator::EQUAL
, /* 34 */
93 void CollationDummyTest::TestTertiary(/* char* par */)
96 myCollation
->setStrength(Collator::TERTIARY
);
97 for (i
= 0; i
< 17 ; i
++)
99 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
]);
102 void CollationDummyTest::TestPrimary(/* char* par */)
104 /* problem in strcollinc for unfinshed contractions */
105 UErrorCode status
= U_ZERO_ERROR
;
107 myCollation
->setAttribute(UCOL_NORMALIZATION_MODE
, UCOL_ON
, status
);
108 myCollation
->setStrength(Collator::PRIMARY
);
110 if (U_FAILURE(status
))
112 errln("Failure in setting attribute for normalization mode\n");
115 for (int i
= 17; i
< 26 ; i
++)
117 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
]);
121 void CollationDummyTest::TestSecondary(/* char* par */)
124 myCollation
->setStrength(Collator::SECONDARY
);
125 for (i
= 26; i
< 34; i
++)
127 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
]);
131 void CollationDummyTest::TestExtra(/* char* par */)
134 myCollation
->setStrength(Collator::TERTIARY
);
135 for (i
= 0; i
< COUNT_TEST_CASES
-1; i
++)
137 for (j
= i
+ 1; j
< COUNT_TEST_CASES
; j
+= 1)
139 doTest(myCollation
, testCases
[i
], testCases
[j
], Collator::LESS
);
144 void CollationDummyTest::TestIdentical()
147 myCollation
->setStrength(Collator::IDENTICAL
);
148 for (i
= 34; i
<37; i
++)
150 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
]);
154 void CollationDummyTest::TestJB581(void)
156 UErrorCode status
= U_ZERO_ERROR
;
158 UnicodeString
source("THISISATEST.");
159 UnicodeString
target("Thisisatest.");
161 Collator
*coll
= Collator::createInstance("en_US", status
);
162 if (U_FAILURE(status
)){
163 errln("ERROR: Failed to create the collator for : en_US\n");
167 Collator::EComparisonResult result
= coll
->compare(source
, target
);
168 /* result is 1, secondary differences only for ignorable space characters*/
171 errln("Comparing two strings with only secondary differences in C failed.\n");
173 /* To compare them with just primary differences */
174 coll
->setStrength(Collator::PRIMARY
);
175 result
= coll
->compare(source
, target
);
179 errln("Comparing two strings with no differences in C failed.\n");
181 /* Now, do the same comparison with keys */
182 CollationKey sourceKeyOut
,
184 coll
->getCollationKey(source
, sourceKeyOut
, status
);
185 coll
->getCollationKey(target
, targetKeyOut
, status
);
186 result
= sourceKeyOut
.compareTo(targetKeyOut
);
189 errln("Comparing two strings with sort keys in C failed.\n");
194 void CollationDummyTest::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* /*par*/ )
196 if (exec
) logln("TestSuite CollationDummyTest: ");
199 case 0: name
= "TestPrimary"; if (exec
) TestPrimary(/* par */); break;
200 case 1: name
= "TestSecondary"; if (exec
) TestSecondary(/* par */); break;
201 case 2: name
= "TestTertiary"; if (exec
) TestTertiary(/* par */); break;
202 case 3: name
= "TestExtra"; if (exec
) TestExtra(/* par */); break;
203 case 4: name
= "TestIdentical"; if (exec
) TestIdentical(/* par */); break;
204 case 5: name
= "TestJB581"; if (exec
) TestJB581(/* par */); break;
205 default: name
= ""; break;
208 dataerrln("Collator couldn't be instantiated!");
213 #endif /* #if !UCONFIG_NO_COLLATION */