1 /********************************************************************
3 * Copyright (c) 1997-2010, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
7 /***********************************************************************
9 * Date Name Description
10 * 02/14/2001 synwee Added attributes in TestTertiary and
12 ***********************************************************************/
14 #include "unicode/utypes.h"
16 #if !UCONFIG_NO_COLLATION
18 #include "unicode/coll.h"
19 #include "unicode/tblcoll.h"
20 #include "unicode/unistr.h"
21 #include "unicode/sortkey.h"
26 CollationFrenchTest::CollationFrenchTest()
29 UErrorCode status
= U_ZERO_ERROR
;
30 myCollation
= Collator::createInstance(Locale::getCanadaFrench(), status
);
31 if(!myCollation
|| U_FAILURE(status
)) {
32 errcheckln(status
, __FILE__
"failed to create! err " + UnicodeString(u_errorName(status
)));
33 /* if it wasn't already: */
39 CollationFrenchTest::~CollationFrenchTest()
44 const UChar
CollationFrenchTest::testSourceCases
[][CollationFrenchTest::MAX_TOKEN_LEN
] =
46 {0x0061/*'a'*/, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},
47 {0x0043/*'C'*/, 0x004f/*'O'*/, 0x0054/*'T'*/, 0x0045/*'E'*/, 0x0000},
48 {0x0063/*'c'*/, 0x006f/*'o'*/, 0x002d/*'-'*/, 0x006f/*'o'*/, 0x0070/*'p'*/, 0x0000},
49 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0000},
50 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/, 0x0000},
51 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/, 0x0000},
52 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/, 0x0000},
53 {0x0048/*'H'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'o'*/, 0x0000},
60 const UChar
CollationFrenchTest::testTargetCases
[][CollationFrenchTest::MAX_TOKEN_LEN
] =
62 {0x0041/*'A'*/, 0x0042/*'B'*/, 0x0043/*'C'*/, 0x0000},
63 {0x0063/*'c'*/, 0x00f4, 0x0074/*'t'*/, 0x0065/*'e'*/, 0x0000},
64 {0x0043/*'C'*/, 0x004f/*'O'*/, 0x004f/*'O'*/, 0x0050/*'P'*/, 0x0000},
65 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x00E9, 0x0000},
66 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x00E9, 0x0000},
67 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0000},
68 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/, 0x0000},
69 {0x0068/*'h'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x004f/*'O'*/, 0x0000},
76 const Collator::EComparisonResult
CollationFrenchTest::results
[] =
80 Collator::LESS
, /*Collator::GREATER,*/
86 Collator::LESS
, /*Collator::GREATER,*/
92 // 0x0300 is grave, 0x0301 is acute
93 // the order of elements in this array must be different than the order in CollationEnglishTest
94 const UChar
CollationFrenchTest::testAcute
[][CollationFrenchTest::MAX_TOKEN_LEN
] =
96 /*00*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0000},
97 /*01*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0000},
98 /*02*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0000},
99 /*03*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0000},
100 /*04*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0000},
101 /*05*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0301, 0x0000},
102 /*06*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0000},
103 /*07*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0000},
104 /*08*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0000},
105 /*09*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0000},
106 /*0a*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
107 /*0b*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
108 /*0c*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
109 /*0d*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
110 /*0e*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
111 /*0f*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0300, 0x0000},
112 /*10*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0000},
113 /*11*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0000},
114 /*12*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0000},
115 /*13*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0000},
116 /*14*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000},
117 /*15*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000},
118 /*16*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000},
119 /*17*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000},
120 /*18*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000}
123 const UChar
CollationFrenchTest::testBugs
[][CollationFrenchTest::MAX_TOKEN_LEN
] =
125 {0x0061/*'a'*/, 0x000},
126 {0x0041/*'A'*/, 0x000},
127 {0x0065/*'e'*/, 0x000},
128 {0x0045/*'E'*/, 0x000},
133 {0x0065/*'e'*/, 0x0061/*'a'*/, 0x000},
134 {0x0078/*'x'*/, 0x000}
137 void CollationFrenchTest::TestTertiary(/* char* par */)
140 UErrorCode status
= U_ZERO_ERROR
;
141 myCollation
->setStrength(Collator::TERTIARY
);
142 myCollation
->setAttribute(UCOL_FRENCH_COLLATION
, UCOL_ON
, status
);
143 myCollation
->setAttribute(UCOL_ALTERNATE_HANDLING
, UCOL_SHIFTED
, status
);
144 if (U_FAILURE(status
)) {
145 errln("Error setting attribute in French collator");
149 for (i
= 0; i
< 12 ; i
++)
151 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
]);
156 void CollationFrenchTest::TestSecondary(/* char* par */)
158 //test acute and grave ordering
161 Collator::EComparisonResult expected
;
162 UErrorCode status
= U_ZERO_ERROR
;
163 //myCollation->setAttribute(UCOL_FRENCH_COLLATION, UCOL_ON, status);
164 myCollation
->setStrength(Collator::SECONDARY
);
165 if (U_FAILURE(status
))
166 errln("Error setting attribute in French collator");
169 const int32_t testAcuteSize
= (int32_t)(sizeof(testAcute
) / sizeof(testAcute
[0]));
170 for (i
= 0; i
< testAcuteSize
; i
++)
172 for (j
= 0; j
< testAcuteSize
; j
++)
175 expected
= Collator::LESS
;
177 expected
= Collator::EQUAL
;
179 expected
= Collator::GREATER
;
180 doTest(myCollation
, testAcute
[i
], testAcute
[j
], expected
);
186 void CollationFrenchTest::TestExtra(/* char* par */)
189 myCollation
->setStrength(Collator::TERTIARY
);
190 for (i
= 0; i
< 9 ; i
++)
192 for (j
= i
+ 1; j
< 10; j
+= 1)
194 doTest(myCollation
, testBugs
[i
], testBugs
[j
], Collator::LESS
);
199 void CollationFrenchTest::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* /*par*/ )
201 if (exec
) logln("TestSuite CollationFrenchTest: ");
203 if((!myCollation
) && exec
) {
204 dataerrln(__FILE__
" cannot test - failed to create collator.");
210 case 0: name
= "TestSecondary"; if (exec
) TestSecondary(/* par */); break;
211 case 1: name
= "TestTertiary"; if (exec
) TestTertiary(/* par */); break;
212 case 2: name
= "TestExtra"; if (exec
) TestExtra(/* par */); break;
213 default: name
= ""; break;
217 #endif /* #if !UCONFIG_NO_COLLATION */