1 /********************************************************************
3 * Copyright (c) 1997-2016, 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"
27 CollationFrenchTest::CollationFrenchTest()
30 UErrorCode status
= U_ZERO_ERROR
;
31 myCollation
= Collator::createInstance(Locale::getCanadaFrench(), status
);
32 if(!myCollation
|| U_FAILURE(status
)) {
33 errcheckln(status
, __FILE__
"failed to create! err " + UnicodeString(u_errorName(status
)));
34 /* if it wasn't already: */
40 CollationFrenchTest::~CollationFrenchTest()
45 const UChar
CollationFrenchTest::testSourceCases
[][CollationFrenchTest::MAX_TOKEN_LEN
] =
47 {0x0061/*'a'*/, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},
48 {0x0043/*'C'*/, 0x004f/*'O'*/, 0x0054/*'T'*/, 0x0045/*'E'*/, 0x0000},
49 {0x0063/*'c'*/, 0x006f/*'o'*/, 0x002d/*'-'*/, 0x006f/*'o'*/, 0x0070/*'p'*/, 0x0000},
50 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0000},
51 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/, 0x0000},
52 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/, 0x0000},
53 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/, 0x0000},
54 {0x0048/*'H'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'o'*/, 0x0000},
61 const UChar
CollationFrenchTest::testTargetCases
[][CollationFrenchTest::MAX_TOKEN_LEN
] =
63 {0x0041/*'A'*/, 0x0042/*'B'*/, 0x0043/*'C'*/, 0x0000},
64 {0x0063/*'c'*/, 0x00f4, 0x0074/*'t'*/, 0x0065/*'e'*/, 0x0000},
65 {0x0043/*'C'*/, 0x004f/*'O'*/, 0x004f/*'O'*/, 0x0050/*'P'*/, 0x0000},
66 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x00E9, 0x0000},
67 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x00E9, 0x0000},
68 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0000},
69 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/, 0x0000},
70 {0x0068/*'h'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x004f/*'O'*/, 0x0000},
77 const Collator::EComparisonResult
CollationFrenchTest::results
[] =
81 Collator::LESS
, /*Collator::GREATER,*/
87 Collator::LESS
, /*Collator::GREATER,*/
93 // 0x0300 is grave, 0x0301 is acute
94 // the order of elements in this array must be different than the order in CollationEnglishTest
95 const UChar
CollationFrenchTest::testAcute
[][CollationFrenchTest::MAX_TOKEN_LEN
] =
97 /*00*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0000},
98 /*01*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0000},
99 /*02*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0000},
100 /*03*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0000},
101 /*04*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0000},
102 /*05*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0301, 0x0000},
103 /*06*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0000},
104 /*07*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0000},
105 /*08*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0000},
106 /*09*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0000},
107 /*0a*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
108 /*0b*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
109 /*0c*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
110 /*0d*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
111 /*0e*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
112 /*0f*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0300, 0x0000},
113 /*10*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0000},
114 /*11*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0000},
115 /*12*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0000},
116 /*13*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0000},
117 /*14*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000},
118 /*15*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000},
119 /*16*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000},
120 /*17*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000},
121 /*18*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000}
124 const UChar
CollationFrenchTest::testBugs
[][CollationFrenchTest::MAX_TOKEN_LEN
] =
126 {0x0061/*'a'*/, 0x000},
127 {0x0041/*'A'*/, 0x000},
128 {0x0065/*'e'*/, 0x000},
129 {0x0045/*'E'*/, 0x000},
134 {0x0065/*'e'*/, 0x0061/*'a'*/, 0x000},
135 {0x0078/*'x'*/, 0x000}
138 void CollationFrenchTest::TestTertiary(/* char* par */)
141 UErrorCode status
= U_ZERO_ERROR
;
142 myCollation
->setStrength(Collator::TERTIARY
);
143 myCollation
->setAttribute(UCOL_FRENCH_COLLATION
, UCOL_ON
, status
);
144 myCollation
->setAttribute(UCOL_ALTERNATE_HANDLING
, UCOL_SHIFTED
, status
);
145 if (U_FAILURE(status
)) {
146 errln("Error setting attribute in French collator");
150 for (i
= 0; i
< 12 ; i
++)
152 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
]);
157 void CollationFrenchTest::TestSecondary(/* char* par */)
159 //test acute and grave ordering
162 Collator::EComparisonResult expected
;
163 UErrorCode status
= U_ZERO_ERROR
;
164 //myCollation->setAttribute(UCOL_FRENCH_COLLATION, UCOL_ON, status);
165 myCollation
->setStrength(Collator::SECONDARY
);
166 if (U_FAILURE(status
))
167 errln("Error setting attribute in French collator");
170 const int32_t testAcuteSize
= UPRV_LENGTHOF(testAcute
);
171 for (i
= 0; i
< testAcuteSize
; i
++)
173 for (j
= 0; j
< testAcuteSize
; j
++)
176 expected
= Collator::LESS
;
178 expected
= Collator::EQUAL
;
180 expected
= Collator::GREATER
;
181 doTest(myCollation
, testAcute
[i
], testAcute
[j
], expected
);
187 void CollationFrenchTest::TestExtra(/* char* par */)
190 myCollation
->setStrength(Collator::TERTIARY
);
191 for (i
= 0; i
< 9 ; i
++)
193 for (j
= i
+ 1; j
< 10; j
+= 1)
195 doTest(myCollation
, testBugs
[i
], testBugs
[j
], Collator::LESS
);
200 void CollationFrenchTest::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* /*par*/ )
202 if (exec
) logln("TestSuite CollationFrenchTest: ");
204 if((!myCollation
) && exec
) {
205 dataerrln(__FILE__
" cannot test - failed to create collator.");
211 case 0: name
= "TestSecondary"; if (exec
) TestSecondary(/* par */); break;
212 case 1: name
= "TestTertiary"; if (exec
) TestTertiary(/* par */); break;
213 case 2: name
= "TestExtra"; if (exec
) TestExtra(/* par */); break;
214 default: name
= ""; break;
218 #endif /* #if !UCONFIG_NO_COLLATION */