1 /********************************************************************
3 * Copyright (c) 1997-2001, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /********************************************************************************
10 * Modification History:
12 * Madhu Katragadda Ported for C API
13 *********************************************************************************/
15 * CollationFrenchTest is a third level test class. This tests the locale
16 * specific primary, secondary and tertiary rules. For example, the ignorable
17 * character '-' in string "black-bird". The en_US locale uses the default
18 * collation rules as its sorting sequence.
23 #include "unicode/utypes.h"
25 #if !UCONFIG_NO_COLLATION
27 #include "unicode/ucol.h"
28 #include "unicode/uloc.h"
33 #include "unicode/ustring.h"
36 static UCollator
*myCollation
;
37 const static UChar testSourceCases
[][MAX_TOKEN_LEN
] =
39 {0x0061/*'a'*/, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},
40 {0x0043/*'C'*/, 0x004f/*'O'*/, 0x0054/*'T'*/, 0x0045/*'E'*/, 0x0000},
41 {0x0063/*'c'*/, 0x006f/*'o'*/, 0x002d/*'-'*/, 0x006f/*'o'*/, 0x0070/*'p'*/, 0x0000},
42 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0000},
43 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/, 0x0000},
44 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/, 0x0000},
45 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/, 0x0000},
46 {0x0048/*'H'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'o'*/, 0x0000},
53 const static UChar testTargetCases
[][MAX_TOKEN_LEN
] =
55 {0x0041/*'A'*/, 0x0042/*'B'*/, 0x0043/*'C'*/, 0x0000},
56 {0x0063/*'c'*/, 0x00f4, 0x0074/*'t'*/, 0x0065/*'e'*/, 0x0000},
57 {0x0043/*'C'*/, 0x004f/*'O'*/, 0x004f/*'O'*/, 0x0050/*'P'*/, 0x0000},
58 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x00E9, 0x0000},
59 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x00E9, 0x0000},
60 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0000},
61 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/, 0x0000},
62 {0x0068/*'h'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x004f/*'O'*/, 0x0000},
69 const static UCollationResult results
[] =
73 UCOL_LESS
, /*UCOL_GREATER,*/
79 UCOL_LESS
, /*UCOL_GREATER,*/
85 /* 0x0300 is grave, 0x0301 is acute*/
86 /* the order of elements in this array must be different than the order in CollationEnglishTest*/
87 const static UChar testAcute
[][MAX_TOKEN_LEN
] =
89 /*00*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0000},
90 /*01*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0000},
91 /*02*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0000},
92 /*03*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0000},
93 /*04*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0000},
94 /*05*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0301, 0x0000},
95 /*06*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0000},
96 /*07*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0000},
97 /*08*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0000},
98 /*09*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0000},
99 /*0a*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
100 /*0b*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
101 /*0c*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
102 /*0d*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
103 /*0e*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
104 /*0f*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0300, 0x0000},
105 /*10*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0000},
106 /*11*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0000},
107 /*12*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0000},
108 /*13*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0000},
109 /*14*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000},
110 /*15*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000},
111 /*16*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000},
112 /*17*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000},
113 /*18*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000}
116 const static UChar testBugs
[][MAX_TOKEN_LEN
] =
118 {0x0061/*'a'*/, 0x000},
119 {0x0041/*'A'*/, 0x000},
120 {0x0065/*'e'*/, 0x000},
121 {0x0045/*'E'*/, 0x000},
126 {0x0065/*'e'*/, 0x0061/*'a'*/, 0x000},
127 {0x0078/*'x'*/, 0x000}
133 void addFrenchCollTest(TestNode
** root
)
137 addTest(root
, &TestSecondary
, "tscoll/cfrtst/TestSecondary");
138 addTest(root
, &TestTertiary
, "tscoll/cfrtst/TestTertiary");
139 addTest(root
, &TestExtra
, "tscoll/cfrtst/TestExtra");
145 static void TestTertiary( )
149 UErrorCode status
= U_ZERO_ERROR
;
150 myCollation
= ucol_open("fr_FR", &status
);
151 if(U_FAILURE(status
) || !myCollation
){
152 log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status
));
156 ucol_setAttribute(myCollation
, UCOL_ALTERNATE_HANDLING
, UCOL_SHIFTED
, &status
);
157 if(U_FAILURE(status
)){
158 log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status
));
161 log_verbose("Testing French Collation with Tertiary strength\n");
162 ucol_setStrength(myCollation
, UCOL_QUATERNARY
);
163 for (i
= 0; i
< 12 ; i
++)
165 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
]);
167 ucol_close(myCollation
);
170 static void TestSecondary()
172 int32_t i
,j
, testAcuteSize
;
173 UCollationResult expected
=UCOL_EQUAL
;
174 UErrorCode status
= U_ZERO_ERROR
;
175 myCollation
= ucol_open("fr_FR", &status
);
176 if(U_FAILURE(status
)){
177 log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status
));
180 ucol_setAttribute(myCollation
, UCOL_STRENGTH
, UCOL_SECONDARY
, &status
);
181 if(U_FAILURE(status
)){
182 log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status
));
185 log_verbose("Testing French Collation with Secondary strength\n");
186 /*test acute and grave ordering (compare to french collation)*/
187 testAcuteSize
= sizeof(testAcute
) / sizeof(testAcute
[0]);
188 for (i
= 0; i
< testAcuteSize
; i
++)
190 for (j
= 0; j
< testAcuteSize
; j
++)
192 if (i
< j
) expected
= UCOL_LESS
;
193 if (i
== j
) expected
= UCOL_EQUAL
;
194 if (i
> j
) expected
= UCOL_GREATER
;
195 doTest(myCollation
, testAcute
[i
], testAcute
[j
], expected
);
198 ucol_close(myCollation
);
201 static void TestExtra()
204 UErrorCode status
= U_ZERO_ERROR
;
205 myCollation
= ucol_open("fr_FR", &status
);
206 if(U_FAILURE(status
)){
207 log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status
));
210 log_verbose("Testing French Collation extra with secondary strength\n");
211 ucol_setStrength(myCollation
, UCOL_TERTIARY
);
212 for (i
= 0; i
< 9 ; i
++)
214 for (j
= i
+ 1; j
< 10; j
+= 1)
216 doTest(myCollation
, testBugs
[i
], testBugs
[j
], UCOL_LESS
);
219 ucol_close(myCollation
);
222 #endif /* #if !UCONFIG_NO_COLLATION */