1 /********************************************************************
3 * Copyright (c) 1997-2009, 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"
17 #include "../cintltst/calldata.h"
20 CollationDummyTest::CollationDummyTest()
23 /*UErrorCode status = U_ZERO_ERROR;
24 UnicodeString rules(TRUE, DEFAULTRULEARRAY, sizeof(DEFAULTRULEARRAY)/sizeof(DEFAULTRULEARRAY[0]));
25 UnicodeString newRules("& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ");
27 myCollation = new RuleBasedCollator(rules, status);
30 UErrorCode status
= U_ZERO_ERROR
;
31 UnicodeString
ruleset("& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ");
32 if (myCollation
!= NULL
)
36 myCollation
= new RuleBasedCollator(ruleset
, status
);
37 if(U_FAILURE(status
)){
38 errcheckln(status
, "ERROR: in creation of rule based collator from ruleset - %s", u_errorName(status
));
44 CollationDummyTest::~CollationDummyTest()
49 const Collator::EComparisonResult
CollationDummyTest::results
[] = {
51 Collator::LESS
, /*Collator::GREATER,*/
59 Collator::LESS
, /* 10 */
67 /* test primary > 17 */
70 Collator::EQUAL
, /* 20 */
77 /* test secondary > 26 */
82 Collator::EQUAL
, /* 30 */
85 Collator::EQUAL
, /* 34 */
92 void CollationDummyTest::TestTertiary(/* char* par */)
95 myCollation
->setStrength(Collator::TERTIARY
);
96 for (i
= 0; i
< 17 ; i
++)
98 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
]);
101 void CollationDummyTest::TestPrimary(/* char* par */)
103 /* problem in strcollinc for unfinshed contractions */
104 UErrorCode status
= U_ZERO_ERROR
;
106 myCollation
->setAttribute(UCOL_NORMALIZATION_MODE
, UCOL_ON
, status
);
107 myCollation
->setStrength(Collator::PRIMARY
);
109 if (U_FAILURE(status
))
111 errln("Failure in setting attribute for normalization mode\n");
114 for (int i
= 17; i
< 26 ; i
++)
116 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
]);
120 void CollationDummyTest::TestSecondary(/* char* par */)
123 myCollation
->setStrength(Collator::SECONDARY
);
124 for (i
= 26; i
< 34; i
++)
126 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
]);
130 void CollationDummyTest::TestExtra(/* char* par */)
133 myCollation
->setStrength(Collator::TERTIARY
);
134 for (i
= 0; i
< COUNT_TEST_CASES
-1; i
++)
136 for (j
= i
+ 1; j
< COUNT_TEST_CASES
; j
+= 1)
138 doTest(myCollation
, testCases
[i
], testCases
[j
], Collator::LESS
);
143 void CollationDummyTest::TestIdentical()
146 myCollation
->setStrength(Collator::IDENTICAL
);
147 for (i
= 34; i
<37; i
++)
149 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
]);
153 void CollationDummyTest::TestJB581(void)
155 UErrorCode status
= U_ZERO_ERROR
;
157 UnicodeString
source("THISISATEST.");
158 UnicodeString
target("Thisisatest.");
160 Collator
*coll
= Collator::createInstance("en_US", status
);
161 if (U_FAILURE(status
)){
162 errln("ERROR: Failed to create the collator for : en_US\n");
166 Collator::EComparisonResult result
= coll
->compare(source
, target
);
167 /* result is 1, secondary differences only for ignorable space characters*/
170 errln("Comparing two strings with only secondary differences in C failed.\n");
172 /* To compare them with just primary differences */
173 coll
->setStrength(Collator::PRIMARY
);
174 result
= coll
->compare(source
, target
);
178 errln("Comparing two strings with no differences in C failed.\n");
180 /* Now, do the same comparison with keys */
181 CollationKey sourceKeyOut
,
183 coll
->getCollationKey(source
, sourceKeyOut
, status
);
184 coll
->getCollationKey(target
, targetKeyOut
, status
);
185 result
= sourceKeyOut
.compareTo(targetKeyOut
);
188 errln("Comparing two strings with sort keys in C failed.\n");
193 void CollationDummyTest::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* /*par*/ )
195 if (exec
) logln("TestSuite CollationDummyTest: ");
198 case 0: name
= "TestPrimary"; if (exec
) TestPrimary(/* par */); break;
199 case 1: name
= "TestSecondary"; if (exec
) TestSecondary(/* par */); break;
200 case 2: name
= "TestTertiary"; if (exec
) TestTertiary(/* par */); break;
201 case 3: name
= "TestExtra"; if (exec
) TestExtra(/* par */); break;
202 case 4: name
= "TestIdentical"; if (exec
) TestIdentical(/* par */); break;
203 case 5: name
= "TestJB581"; if (exec
) TestJB581(/* par */); break;
204 default: name
= ""; break;
207 dataerrln("Collator couldn't be instantiated!");
212 #endif /* #if !UCONFIG_NO_COLLATION */