1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
5 * Copyright (c) 1997-2016, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ********************************************************************/
9 /***********************************************************************
10 * Modification history
11 * Date Name Description
12 * 02/14/2001 synwee Added attributes in TestTertiary and
14 ***********************************************************************/
16 #include "unicode/utypes.h"
18 #if !UCONFIG_NO_COLLATION
20 #include "unicode/coll.h"
21 #include "unicode/tblcoll.h"
22 #include "unicode/unistr.h"
23 #include "unicode/sortkey.h"
29 CollationFrenchTest::CollationFrenchTest()
32 UErrorCode status
= U_ZERO_ERROR
;
33 myCollation
= Collator::createInstance(Locale::getCanadaFrench(), status
);
34 if(!myCollation
|| U_FAILURE(status
)) {
35 errcheckln(status
, __FILE__
"failed to create! err " + UnicodeString(u_errorName(status
)));
36 /* if it wasn't already: */
42 CollationFrenchTest::~CollationFrenchTest()
47 const UChar
CollationFrenchTest::testSourceCases
[][CollationFrenchTest::MAX_TOKEN_LEN
] =
49 {0x0061/*'a'*/, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},
50 {0x0043/*'C'*/, 0x004f/*'O'*/, 0x0054/*'T'*/, 0x0045/*'E'*/, 0x0000},
51 {0x0063/*'c'*/, 0x006f/*'o'*/, 0x002d/*'-'*/, 0x006f/*'o'*/, 0x0070/*'p'*/, 0x0000},
52 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0000},
53 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/, 0x0000},
54 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/, 0x0000},
55 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/, 0x0000},
56 {0x0048/*'H'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'o'*/, 0x0000},
63 const UChar
CollationFrenchTest::testTargetCases
[][CollationFrenchTest::MAX_TOKEN_LEN
] =
65 {0x0041/*'A'*/, 0x0042/*'B'*/, 0x0043/*'C'*/, 0x0000},
66 {0x0063/*'c'*/, 0x00f4, 0x0074/*'t'*/, 0x0065/*'e'*/, 0x0000},
67 {0x0043/*'C'*/, 0x004f/*'O'*/, 0x004f/*'O'*/, 0x0050/*'P'*/, 0x0000},
68 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x00E9, 0x0000},
69 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x00E9, 0x0000},
70 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0000},
71 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/, 0x0000},
72 {0x0068/*'h'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x004f/*'O'*/, 0x0000},
79 const Collator::EComparisonResult
CollationFrenchTest::results
[] =
83 Collator::LESS
, /*Collator::GREATER,*/
89 Collator::LESS
, /*Collator::GREATER,*/
95 // 0x0300 is grave, 0x0301 is acute
96 // the order of elements in this array must be different than the order in CollationEnglishTest
97 const UChar
CollationFrenchTest::testAcute
[][CollationFrenchTest::MAX_TOKEN_LEN
] =
99 /*00*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0000},
100 /*01*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0000},
101 /*02*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0000},
102 /*03*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0000},
103 /*04*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0000},
104 /*05*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0301, 0x0000},
105 /*06*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0000},
106 /*07*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0000},
107 /*08*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0000},
108 /*09*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0000},
109 /*0a*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
110 /*0b*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
111 /*0c*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
112 /*0d*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
113 /*0e*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
114 /*0f*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0300, 0x0000},
115 /*10*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0000},
116 /*11*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0000},
117 /*12*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0000},
118 /*13*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0000},
119 /*14*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000},
120 /*15*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000},
121 /*16*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000},
122 /*17*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000},
123 /*18*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000}
126 const UChar
CollationFrenchTest::testBugs
[][CollationFrenchTest::MAX_TOKEN_LEN
] =
128 {0x0061/*'a'*/, 0x000},
129 {0x0041/*'A'*/, 0x000},
130 {0x0065/*'e'*/, 0x000},
131 {0x0045/*'E'*/, 0x000},
136 {0x0065/*'e'*/, 0x0061/*'a'*/, 0x000},
137 {0x0078/*'x'*/, 0x000}
140 void CollationFrenchTest::TestTertiary(/* char* par */)
143 UErrorCode status
= U_ZERO_ERROR
;
144 myCollation
->setStrength(Collator::TERTIARY
);
145 myCollation
->setAttribute(UCOL_FRENCH_COLLATION
, UCOL_ON
, status
);
146 myCollation
->setAttribute(UCOL_ALTERNATE_HANDLING
, UCOL_SHIFTED
, status
);
147 if (U_FAILURE(status
)) {
148 errln("Error setting attribute in French collator");
152 for (i
= 0; i
< 12 ; i
++)
154 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
]);
159 void CollationFrenchTest::TestSecondary(/* char* par */)
161 //test acute and grave ordering
164 Collator::EComparisonResult expected
;
165 UErrorCode status
= U_ZERO_ERROR
;
166 //myCollation->setAttribute(UCOL_FRENCH_COLLATION, UCOL_ON, status);
167 myCollation
->setStrength(Collator::SECONDARY
);
168 if (U_FAILURE(status
))
169 errln("Error setting attribute in French collator");
172 const int32_t testAcuteSize
= UPRV_LENGTHOF(testAcute
);
173 for (i
= 0; i
< testAcuteSize
; i
++)
175 for (j
= 0; j
< testAcuteSize
; j
++)
178 expected
= Collator::LESS
;
180 expected
= Collator::EQUAL
;
182 expected
= Collator::GREATER
;
183 doTest(myCollation
, testAcute
[i
], testAcute
[j
], expected
);
189 void CollationFrenchTest::TestExtra(/* char* par */)
192 myCollation
->setStrength(Collator::TERTIARY
);
193 for (i
= 0; i
< 9 ; i
++)
195 for (j
= i
+ 1; j
< 10; j
+= 1)
197 doTest(myCollation
, testBugs
[i
], testBugs
[j
], Collator::LESS
);
202 void CollationFrenchTest::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* /*par*/ )
204 if (exec
) logln("TestSuite CollationFrenchTest: ");
206 if((!myCollation
) && exec
) {
207 dataerrln(__FILE__
" cannot test - failed to create collator.");
213 case 0: name
= "TestSecondary"; if (exec
) TestSecondary(/* par */); break;
214 case 1: name
= "TestTertiary"; if (exec
) TestTertiary(/* par */); break;
215 case 2: name
= "TestExtra"; if (exec
) TestExtra(/* par */); break;
216 default: name
= ""; break;
220 #endif /* #if !UCONFIG_NO_COLLATION */