2 *******************************************************************************
\r
3 * Copyright (C) 2002-2010, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
9 * Port From: ICU4C v2.1 : Collate/CollationFrenchTest
\r
10 * Source File: $ICU4CRoot/source/test/intltest/frcoll.cpp
\r
13 package com.ibm.icu.dev.test.collator;
\r
15 import java.util.Locale;
\r
17 import com.ibm.icu.dev.test.TestFmwk;
\r
18 import com.ibm.icu.text.CollationKey;
\r
19 import com.ibm.icu.text.Collator;
\r
20 import com.ibm.icu.text.RuleBasedCollator;
\r
22 public class CollationFrenchTest extends TestFmwk{
\r
23 public static void main(String[] args) throws Exception {
\r
24 new CollationFrenchTest().run(args);
\r
27 private static char[][] testSourceCases = {
\r
28 {0x0061/*'a'*/, 0x0062/*'b'*/, 0x0063/*'c'*/},
\r
29 {0x0043/*'C'*/, 0x004f/*'O'*/, 0x0054/*'T'*/, 0x0045/*'E'*/},
\r
30 {0x0063/*'c'*/, 0x006f/*'o'*/, 0x002d/*'-'*/, 0x006f/*'o'*/, 0x0070/*'p'*/},
\r
31 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/},
\r
32 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/},
\r
33 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/},
\r
34 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/},
\r
35 {0x0048/*'H'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'o'*/},
\r
42 private static char[][] testTargetCases = {
\r
43 {0x0041/*'A'*/, 0x0042/*'B'*/, 0x0043/*'C'*/},
\r
44 {0x0063/*'c'*/, 0x00f4, 0x0074/*'t'*/, 0x0065/*'e'*/},
\r
45 {0x0043/*'C'*/, 0x004f/*'O'*/, 0x004f/*'O'*/, 0x0050/*'P'*/},
\r
46 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x00E9},
\r
47 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x00E9},
\r
48 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/},
\r
49 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/},
\r
50 {0x0068/*'h'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x004f/*'O'*/},
\r
57 private static int[] results = {
\r
60 -1, /*Collator::GREATER,*/
\r
66 -1, /*Collator::GREATER,*/
\r
72 // 0x0300 is grave, 0x0301 is acute
\r
73 // the order of elements in this array must be different than the order in CollationEnglishTest
\r
74 private static char[][] testAcute = {
\r
75 /*00*/ {0x0065/*'e'*/, 0x0065/*'e'*/},
\r
76 /*01*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/},
\r
77 /*02*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/},
\r
78 /*03*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/},
\r
79 /*04*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/},
\r
80 /*05*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0301},
\r
81 /*06*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0301},
\r
82 /*07*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0301},
\r
83 /*08*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0301},
\r
84 /*09*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0301},
\r
85 /*0a*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0300, 0x0301},
\r
86 /*0b*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0301},
\r
87 /*0c*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0301},
\r
88 /*0d*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0301},
\r
89 /*0e*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0301},
\r
90 /*0f*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0300},
\r
91 /*10*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0300},
\r
92 /*11*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0300},
\r
93 /*12*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0300},
\r
94 /*13*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0300},
\r
95 /*14*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0301, 0x0300},
\r
96 /*15*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0300},
\r
97 /*16*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0300},
\r
98 /*17*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0300},
\r
99 /*18*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0300}
\r
102 private static char[][] testBugs = {
\r
111 {0x0065/*'e'*/, 0x0061/*'a'*/},
\r
116 private Collator myCollation = null;
\r
118 public CollationFrenchTest() {
\r
121 protected void init()throws Exception{
\r
122 myCollation = Collator.getInstance(Locale.FRENCH);
\r
125 // perform tests with strength TERTIARY
\r
126 public void TestTertiary() {
\r
128 myCollation.setStrength(Collator.TERTIARY);
\r
130 for (i = 0; i < 12 ; i++) {
\r
131 doTest(testSourceCases[i], testTargetCases[i], results[i]);
\r
135 // perform tests with strength SECONDARY
\r
136 public void TestSecondary() {
\r
137 //test acute and grave ordering
\r
142 myCollation.setStrength(Collator.SECONDARY);
\r
144 for (i = 0; i < testAcute.length; i++) {
\r
145 for (j = 0; j < testAcute.length; j++) {
\r
148 } else if (i == j) {
\r
153 doTest(testAcute[i], testAcute[j], expected );
\r
158 // perform extra tests
\r
159 public void TestExtra() {
\r
161 myCollation.setStrength(Collator.TERTIARY);
\r
162 for (i = 0; i < 9 ; i++) {
\r
163 for (j = i + 1; j < 10; j += 1) {
\r
164 doTest(testBugs[i], testBugs[j], -1);
\r
169 public void TestContinuationReordering()
\r
171 String rule = "&0x2f00 << 0x2f01";
\r
173 RuleBasedCollator collator = new RuleBasedCollator(rule);
\r
174 collator.setFrenchCollation(true);
\r
176 = collator.getCollationKey("a\u0325\u2f00\u2f01b\u0325");
\r
178 = collator.getCollationKey("a\u0325\u2f01\u2f01b\u0325");
\r
179 if (key1.compareTo(key2) >= 0) {
\r
180 errln("Error comparing continuation strings");
\r
182 } catch (Exception e) {
\r
183 errln(e.toString());
\r
187 // main test routine, test rules specific to the french locale
\r
188 private void doTest(char[] source, char[] target, int result) {
\r
189 String s = new String(source);
\r
190 String t = new String(target);
\r
191 int compareResult = myCollation.compare(s, t);
\r
192 CollationKey sortKey1, sortKey2;
\r
193 sortKey1 = myCollation.getCollationKey(s);
\r
194 sortKey2 = myCollation.getCollationKey(t);
\r
195 int keyResult = sortKey1.compareTo(sortKey2);
\r
196 reportCResult(s, t, sortKey1, sortKey2, compareResult, keyResult, compareResult, result);
\r
199 private void reportCResult( String source, String target, CollationKey sourceKey, CollationKey targetKey,
\r
200 int compareResult, int keyResult, int incResult, int expectedResult ) {
\r
201 if (expectedResult < -1 || expectedResult > 1) {
\r
202 errln("***** invalid call to reportCResult ****");
\r
206 boolean ok1 = (compareResult == expectedResult);
\r
207 boolean ok2 = (keyResult == expectedResult);
\r
208 boolean ok3 = (incResult == expectedResult);
\r
210 if (ok1 && ok2 && ok3 && !isVerbose()) {
\r
213 String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\"";
\r
214 String msg2 = "\", \"";
\r
215 String msg3 = "\") returned ";
\r
216 String msg4 = "; expected ";
\r
218 String sExpect = new String("");
\r
219 String sResult = new String("");
\r
220 sResult = appendCompareResult(compareResult, sResult);
\r
221 sExpect = appendCompareResult(expectedResult, sExpect);
\r
223 logln(msg1 + source + msg2 + target + msg3 + sResult);
\r
225 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
\r
228 msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\"";
\r
229 msg2 = "\").compareTo(key(\"";
\r
230 msg3 = "\")) returned ";
\r
231 sResult = appendCompareResult(keyResult, sResult);
\r
233 logln(msg1 + source + msg2 + target + msg3 + sResult);
\r
235 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
\r
238 errln(msg1 + prettify(sourceKey) + msg2 + prettify(targetKey));
\r
241 msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\"";
\r
243 msg3 = "\") returned ";
\r
245 sResult = appendCompareResult(incResult, sResult);
\r
248 logln(msg1 + source + msg2 + target + msg3 + sResult);
\r
250 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
\r
255 private String appendCompareResult(int result, String target) {
\r
256 if (result == -1) {
\r
258 } else if (result == 0) {
\r
260 } else if (result == 1) {
\r
261 target += "GREATER";
\r
264 target += huh + result;
\r
269 String prettify(CollationKey sourceKey) {
\r
271 byte[] bytes= sourceKey.toByteArray();
\r
272 String target = "[";
\r
274 for (i = 0; i < bytes.length; i++) {
\r
275 target += Integer.toHexString(bytes[i]);
\r