]>
Commit | Line | Data |
---|---|---|
1 | /******************************************************************** | |
2 | * COPYRIGHT: | |
3 | * Copyright (c) 1997-2016, International Business Machines Corporation and | |
4 | * others. All Rights Reserved. | |
5 | ********************************************************************/ | |
6 | ||
7 | /*********************************************************************** | |
8 | * Modification history | |
9 | * Date Name Description | |
10 | * 02/14/2001 synwee Added attributes in TestTertiary and | |
11 | * TestSecondary | |
12 | ***********************************************************************/ | |
13 | ||
14 | #include "unicode/utypes.h" | |
15 | ||
16 | #if !UCONFIG_NO_COLLATION | |
17 | ||
18 | #include "unicode/coll.h" | |
19 | #include "unicode/tblcoll.h" | |
20 | #include "unicode/unistr.h" | |
21 | #include "unicode/sortkey.h" | |
22 | #include "cmemory.h" | |
23 | #include "frcoll.h" | |
24 | ||
25 | #include "sfwdchit.h" | |
26 | ||
27 | CollationFrenchTest::CollationFrenchTest() | |
28 | : myCollation(0) | |
29 | { | |
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: */ | |
35 | delete myCollation; | |
36 | myCollation = NULL; | |
37 | } | |
38 | } | |
39 | ||
40 | CollationFrenchTest::~CollationFrenchTest() | |
41 | { | |
42 | delete myCollation; | |
43 | } | |
44 | ||
45 | const UChar CollationFrenchTest::testSourceCases[][CollationFrenchTest::MAX_TOKEN_LEN] = | |
46 | { | |
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}, | |
55 | {0x01f1, 0x0000}, | |
56 | {0xfb00, 0x0000}, | |
57 | {0x01fa, 0x0000}, | |
58 | {0x0101, 0x0000} | |
59 | }; | |
60 | ||
61 | const UChar CollationFrenchTest::testTargetCases[][CollationFrenchTest::MAX_TOKEN_LEN] = | |
62 | { | |
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}, | |
71 | {0x01ee, 0x0000}, | |
72 | {0x25ca, 0x0000}, | |
73 | {0x00e0, 0x0000}, | |
74 | {0x01df, 0x0000} | |
75 | }; | |
76 | ||
77 | const Collator::EComparisonResult CollationFrenchTest::results[] = | |
78 | { | |
79 | Collator::LESS, | |
80 | Collator::LESS, | |
81 | Collator::LESS, /*Collator::GREATER,*/ | |
82 | Collator::LESS, | |
83 | Collator::GREATER, | |
84 | Collator::GREATER, | |
85 | Collator::LESS, | |
86 | Collator::GREATER, | |
87 | Collator::LESS, /*Collator::GREATER,*/ | |
88 | Collator::GREATER, | |
89 | Collator::LESS, | |
90 | Collator::LESS | |
91 | }; | |
92 | ||
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] = | |
96 | { | |
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} | |
122 | }; | |
123 | ||
124 | const UChar CollationFrenchTest::testBugs[][CollationFrenchTest::MAX_TOKEN_LEN] = | |
125 | { | |
126 | {0x0061/*'a'*/, 0x000}, | |
127 | {0x0041/*'A'*/, 0x000}, | |
128 | {0x0065/*'e'*/, 0x000}, | |
129 | {0x0045/*'E'*/, 0x000}, | |
130 | {0x00e9, 0x000}, | |
131 | {0x00e8, 0x000}, | |
132 | {0x00ea, 0x000}, | |
133 | {0x00eb, 0x000}, | |
134 | {0x0065/*'e'*/, 0x0061/*'a'*/, 0x000}, | |
135 | {0x0078/*'x'*/, 0x000} | |
136 | }; | |
137 | ||
138 | void CollationFrenchTest::TestTertiary(/* char* par */) | |
139 | { | |
140 | int32_t i = 0; | |
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"); | |
147 | } | |
148 | else | |
149 | { | |
150 | for (i = 0; i < 12 ; i++) | |
151 | { | |
152 | doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]); | |
153 | } | |
154 | } | |
155 | } | |
156 | ||
157 | void CollationFrenchTest::TestSecondary(/* char* par */) | |
158 | { | |
159 | //test acute and grave ordering | |
160 | int32_t i = 0; | |
161 | int32_t j; | |
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"); | |
168 | else | |
169 | { | |
170 | const int32_t testAcuteSize = UPRV_LENGTHOF(testAcute); | |
171 | for (i = 0; i < testAcuteSize; i++) | |
172 | { | |
173 | for (j = 0; j < testAcuteSize; j++) | |
174 | { | |
175 | if (i < j) | |
176 | expected = Collator::LESS; | |
177 | else if (i == j) | |
178 | expected = Collator::EQUAL; | |
179 | else // (i > j) | |
180 | expected = Collator::GREATER; | |
181 | doTest(myCollation, testAcute[i], testAcute[j], expected ); | |
182 | } | |
183 | } | |
184 | } | |
185 | } | |
186 | ||
187 | void CollationFrenchTest::TestExtra(/* char* par */) | |
188 | { | |
189 | int32_t i, j; | |
190 | myCollation->setStrength(Collator::TERTIARY); | |
191 | for (i = 0; i < 9 ; i++) | |
192 | { | |
193 | for (j = i + 1; j < 10; j += 1) | |
194 | { | |
195 | doTest(myCollation, testBugs[i], testBugs[j], Collator::LESS); | |
196 | } | |
197 | } | |
198 | } | |
199 | ||
200 | void CollationFrenchTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ ) | |
201 | { | |
202 | if (exec) logln("TestSuite CollationFrenchTest: "); | |
203 | ||
204 | if((!myCollation) && exec) { | |
205 | dataerrln(__FILE__ " cannot test - failed to create collator."); | |
206 | name = "some test"; | |
207 | return; | |
208 | } | |
209 | ||
210 | switch (index) { | |
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; | |
215 | } | |
216 | } | |
217 | ||
218 | #endif /* #if !UCONFIG_NO_COLLATION */ |