]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/cintltst/cfrtst.c
ICU-3.13.tar.gz
[apple/icu.git] / icuSources / test / cintltst / cfrtst.c
1 /********************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 1997-2001, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /********************************************************************************
7 *
8 * File CFRTST.C
9 *
10 * Modification History:
11 * Name Description
12 * Madhu Katragadda Ported for C API
13 *********************************************************************************/
14 /**
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.
19 */
20
21 #include <stdlib.h>
22
23 #include "unicode/utypes.h"
24
25 #if !UCONFIG_NO_COLLATION
26
27 #include "unicode/ucol.h"
28 #include "unicode/uloc.h"
29 #include "cintltst.h"
30 #include "ccolltst.h"
31 #include "callcoll.h"
32 #include "cfrtst.h"
33 #include "unicode/ustring.h"
34 #include "string.h"
35
36 static UCollator *myCollation;
37 const static UChar testSourceCases[][MAX_TOKEN_LEN] =
38 {
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},
47 {0x01f1, 0x0000},
48 {0xfb00, 0x0000},
49 {0x01fa, 0x0000},
50 {0x0101, 0x0000}
51 };
52
53 const static UChar testTargetCases[][MAX_TOKEN_LEN] =
54 {
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},
63 {0x01ee, 0x0000},
64 {0x25ca, 0x0000},
65 {0x00e0, 0x0000},
66 {0x01df, 0x0000}
67 };
68
69 const static UCollationResult results[] =
70 {
71 UCOL_LESS,
72 UCOL_LESS,
73 UCOL_LESS, /*UCOL_GREATER,*/
74 UCOL_LESS,
75 UCOL_GREATER,
76 UCOL_GREATER,
77 UCOL_LESS,
78 UCOL_GREATER,
79 UCOL_LESS, /*UCOL_GREATER,*/
80 UCOL_GREATER,
81 UCOL_LESS,
82 UCOL_LESS
83 };
84
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] =
88 {
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}
114 };
115
116 const static UChar testBugs[][MAX_TOKEN_LEN] =
117 {
118 {0x0061/*'a'*/, 0x000},
119 {0x0041/*'A'*/, 0x000},
120 {0x0065/*'e'*/, 0x000},
121 {0x0045/*'E'*/, 0x000},
122 {0x00e9, 0x000},
123 {0x00e8, 0x000},
124 {0x00ea, 0x000},
125 {0x00eb, 0x000},
126 {0x0065/*'e'*/, 0x0061/*'a'*/, 0x000},
127 {0x0078/*'x'*/, 0x000}
128 };
129
130
131
132
133 void addFrenchCollTest(TestNode** root)
134 {
135
136
137 addTest(root, &TestSecondary, "tscoll/cfrtst/TestSecondary");
138 addTest(root, &TestTertiary, "tscoll/cfrtst/TestTertiary");
139 addTest(root, &TestExtra, "tscoll/cfrtst/TestExtra");
140
141
142 }
143
144
145 static void TestTertiary( )
146 {
147
148 int32_t i;
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));
153 return;
154 }
155
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));
159 return;
160 }
161 log_verbose("Testing French Collation with Tertiary strength\n");
162 ucol_setStrength(myCollation, UCOL_QUATERNARY);
163 for (i = 0; i < 12 ; i++)
164 {
165 doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
166 }
167 ucol_close(myCollation);
168 }
169
170 static void TestSecondary()
171 {
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));
178 return;
179 }
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));
183 return;
184 }
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++)
189 {
190 for (j = 0; j < testAcuteSize; j++)
191 {
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 );
196 }
197 }
198 ucol_close(myCollation);
199 }
200
201 static void TestExtra()
202 {
203 int32_t i, j;
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));
208 return;
209 }
210 log_verbose("Testing French Collation extra with secondary strength\n");
211 ucol_setStrength(myCollation, UCOL_TERTIARY);
212 for (i = 0; i < 9 ; i++)
213 {
214 for (j = i + 1; j < 10; j += 1)
215 {
216 doTest(myCollation, testBugs[i], testBugs[j], UCOL_LESS);
217 }
218 }
219 ucol_close(myCollation);
220 }
221
222 #endif /* #if !UCONFIG_NO_COLLATION */