2 *******************************************************************************
\r
3 * Copyright (C) 2002-2005, 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 com.ibm.icu.dev.test.*;
\r
16 import com.ibm.icu.text.*;
\r
17 import java.util.Locale;
\r
19 public class CollationFrenchTest extends TestFmwk{
\r
20 public static void main(String[] args) throws Exception {
\r
21 new CollationFrenchTest().run(args);
\r
24 private static char[][] testSourceCases = {
\r
25 {0x0061/*'a'*/, 0x0062/*'b'*/, 0x0063/*'c'*/},
\r
26 {0x0043/*'C'*/, 0x004f/*'O'*/, 0x0054/*'T'*/, 0x0045/*'E'*/},
\r
27 {0x0063/*'c'*/, 0x006f/*'o'*/, 0x002d/*'-'*/, 0x006f/*'o'*/, 0x0070/*'p'*/},
\r
28 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/},
\r
29 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/},
\r
30 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/},
\r
31 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/},
\r
32 {0x0048/*'H'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'o'*/},
\r
39 private static char[][] testTargetCases = {
\r
40 {0x0041/*'A'*/, 0x0042/*'B'*/, 0x0043/*'C'*/},
\r
41 {0x0063/*'c'*/, 0x00f4, 0x0074/*'t'*/, 0x0065/*'e'*/},
\r
42 {0x0043/*'C'*/, 0x004f/*'O'*/, 0x004f/*'O'*/, 0x0050/*'P'*/},
\r
43 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x00E9},
\r
44 {0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x00E9},
\r
45 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/},
\r
46 {0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/},
\r
47 {0x0068/*'h'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x004f/*'O'*/},
\r
54 private static int[] results = {
\r
57 -1, /*Collator::GREATER,*/
\r
63 -1, /*Collator::GREATER,*/
\r
69 // 0x0300 is grave, 0x0301 is acute
\r
70 // the order of elements in this array must be different than the order in CollationEnglishTest
\r
71 private static char[][] testAcute = {
\r
72 /*00*/ {0x0065/*'e'*/, 0x0065/*'e'*/},
\r
73 /*01*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/},
\r
74 /*02*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/},
\r
75 /*03*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/},
\r
76 /*04*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/},
\r
77 /*05*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0301},
\r
78 /*06*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0301},
\r
79 /*07*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0301},
\r
80 /*08*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0301},
\r
81 /*09*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0301},
\r
82 /*0a*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0300, 0x0301},
\r
83 /*0b*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0301},
\r
84 /*0c*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0301},
\r
85 /*0d*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0301},
\r
86 /*0e*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0301},
\r
87 /*0f*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0300},
\r
88 /*10*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0300},
\r
89 /*11*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0300},
\r
90 /*12*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0300},
\r
91 /*13*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0300},
\r
92 /*14*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0301, 0x0300},
\r
93 /*15*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0300},
\r
94 /*16*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0300},
\r
95 /*17*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0300},
\r
96 /*18*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0300}
\r
99 private static char[][] testBugs = {
\r
108 {0x0065/*'e'*/, 0x0061/*'a'*/},
\r
113 private Collator myCollation = null;
\r
115 public CollationFrenchTest() {
\r
118 protected void init()throws Exception{
\r
119 myCollation = Collator.getInstance(Locale.FRENCH);
\r
122 // perform tests with strength TERTIARY
\r
123 public void TestTertiary() {
\r
125 myCollation.setStrength(Collator.TERTIARY);
\r
127 for (i = 0; i < 12 ; i++) {
\r
128 doTest(testSourceCases[i], testTargetCases[i], results[i]);
\r
132 // perform tests with strength SECONDARY
\r
133 public void TestSecondary() {
\r
134 //test acute and grave ordering
\r
139 myCollation.setStrength(Collator.SECONDARY);
\r
141 for (i = 0; i < testAcute.length; i++) {
\r
142 for (j = 0; j < testAcute.length; j++) {
\r
145 } else if (i == j) {
\r
150 doTest(testAcute[i], testAcute[j], expected );
\r
155 // perform extra tests
\r
156 public void TestExtra() {
\r
158 myCollation.setStrength(Collator.TERTIARY);
\r
159 for (i = 0; i < 9 ; i++) {
\r
160 for (j = i + 1; j < 10; j += 1) {
\r
161 doTest(testBugs[i], testBugs[j], -1);
\r
166 public void TestContinuationReordering()
\r
168 String rule = "&0x2f00 << 0x2f01";
\r
170 RuleBasedCollator collator = new RuleBasedCollator(rule);
\r
171 collator.setFrenchCollation(true);
\r
173 = collator.getCollationKey("a\u0325\u2f00\u2f01b\u0325");
\r
175 = collator.getCollationKey("a\u0325\u2f01\u2f01b\u0325");
\r
176 if (key1.compareTo(key2) >= 0) {
\r
177 errln("Error comparing continuation strings");
\r
179 } catch (Exception e) {
\r
180 errln(e.toString());
\r
184 // main test routine, test rules specific to the french locale
\r
185 private void doTest(char[] source, char[] target, int result) {
\r
186 String s = new String(source);
\r
187 String t = new String(target);
\r
188 int compareResult = myCollation.compare(s, t);
\r
189 CollationKey sortKey1, sortKey2;
\r
190 sortKey1 = myCollation.getCollationKey(s);
\r
191 sortKey2 = myCollation.getCollationKey(t);
\r
192 int keyResult = sortKey1.compareTo(sortKey2);
\r
193 reportCResult(s, t, sortKey1, sortKey2, compareResult, keyResult, compareResult, result);
\r
196 private void reportCResult( String source, String target, CollationKey sourceKey, CollationKey targetKey,
\r
197 int compareResult, int keyResult, int incResult, int expectedResult ) {
\r
198 if (expectedResult < -1 || expectedResult > 1) {
\r
199 errln("***** invalid call to reportCResult ****");
\r
203 boolean ok1 = (compareResult == expectedResult);
\r
204 boolean ok2 = (keyResult == expectedResult);
\r
205 boolean ok3 = (incResult == expectedResult);
\r
207 if (ok1 && ok2 && ok3 && !isVerbose()) {
\r
210 String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\"";
\r
211 String msg2 = "\", \"";
\r
212 String msg3 = "\") returned ";
\r
213 String msg4 = "; expected ";
\r
215 String sExpect = new String("");
\r
216 String sResult = new String("");
\r
217 sResult = appendCompareResult(compareResult, sResult);
\r
218 sExpect = appendCompareResult(expectedResult, sExpect);
\r
220 logln(msg1 + source + msg2 + target + msg3 + sResult);
\r
222 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
\r
225 msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\"";
\r
226 msg2 = "\").compareTo(key(\"";
\r
227 msg3 = "\")) returned ";
\r
228 sResult = appendCompareResult(keyResult, sResult);
\r
230 logln(msg1 + source + msg2 + target + msg3 + sResult);
\r
232 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
\r
235 errln(msg1 + prettify(sourceKey) + msg2 + prettify(targetKey));
\r
238 msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\"";
\r
240 msg3 = "\") returned ";
\r
242 sResult = appendCompareResult(incResult, sResult);
\r
245 logln(msg1 + source + msg2 + target + msg3 + sResult);
\r
247 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
\r
252 private String appendCompareResult(int result, String target) {
\r
253 if (result == -1) {
\r
255 } else if (result == 0) {
\r
257 } else if (result == 1) {
\r
258 target += "GREATER";
\r
261 target += huh + result;
\r
266 String prettify(CollationKey sourceKey) {
\r
268 byte[] bytes= sourceKey.toByteArray();
\r
269 String target = "[";
\r
271 for (i = 0; i < bytes.length; i++) {
\r
272 target += Integer.toHexString(bytes[i]);
\r