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/CollationGermanTest
\r
10 * Source File: $ICU4CRoot/source/test/intltest/decoll.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 CollationGermanTest extends TestFmwk{
\r
20 public static void main(String[] args) throws Exception{
\r
21 new CollationGermanTest().run(args);
\r
24 private static char[][] testSourceCases = {
\r
25 {0x47, 0x72, 0x00F6, 0x00DF, 0x65},
\r
27 {0x54, 0x00F6, 0x6e, 0x65},
\r
28 {0x54, 0x00F6, 0x6e, 0x65},
\r
29 {0x54, 0x00F6, 0x6e, 0x65},
\r
30 {0x61, 0x0308, 0x62, 0x63},
\r
31 {0x00E4, 0x62, 0x63},
\r
32 {0x00E4, 0x62, 0x63},
\r
33 {0x53, 0x74, 0x72, 0x61, 0x00DF, 0x65},
\r
35 {0x00E4, 0x62, 0x63},
\r
36 {0x53, 0x74, 0x72, 0x61, 0x00DF, 0x65}
\r
39 private static char[][] testTargetCases = {
\r
40 {0x47, 0x72, 0x6f, 0x73, 0x73, 0x69, 0x73, 0x74},
\r
41 {0x61, 0x0308, 0x62, 0x63},
\r
44 {0x54, 0x6f, 0x66, 0x75},
\r
45 {0x41, 0x0308, 0x62, 0x63},
\r
46 {0x61, 0x0308, 0x62, 0x63},
\r
47 {0x61, 0x65, 0x62, 0x63},
\r
48 {0x53, 0x74, 0x72, 0x61, 0x73, 0x73, 0x65},
\r
50 {0x61, 0x65, 0x62, 0x63},
\r
51 {0x53, 0x74, 0x72, 0x61, 0x73, 0x73, 0x65}
\r
54 private static int results[][] =
\r
71 private Collator myCollation = null;
\r
73 public CollationGermanTest() {
\r
76 protected void init() throws Exception{
\r
77 myCollation = Collator.getInstance(Locale.GERMAN);
\r
78 if(myCollation == null) {
\r
79 errln("ERROR: in creation of collator of GERMAN locale");
\r
82 // perform test with strength TERTIARY
\r
83 public void TestTertiary(){
\r
84 if(myCollation == null ) {
\r
85 errln("decoll: cannot start test, collator is null\n");
\r
90 myCollation.setStrength(Collator.TERTIARY);
\r
91 myCollation.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
\r
92 for (i = 0; i < 12 ; i++)
\r
94 doTest(testSourceCases[i], testTargetCases[i], results[i][1]);
\r
98 // perform test with strength SECONDARY
\r
99 //This method in icu4c has no implementation.
\r
100 public void TestSecondary(){
\r
103 // perform test with strength PRIMARY
\r
104 public void TestPrimary(){
\r
105 if(myCollation == null ) {
\r
106 errln("decoll: cannot start test, collator is null\n");
\r
110 myCollation.setStrength(Collator.PRIMARY);
\r
111 myCollation.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
\r
112 for (i = 0; i < 12 ; i++)
\r
114 doTest(testSourceCases[i], testTargetCases[i], results[i][0]);
\r
119 //main test routine, tests rules specific to germa locale
\r
120 private void doTest(char[] source, char[] target, int result){
\r
121 String s = new String(source);
\r
122 String t = new String(target);
\r
123 int compareResult = myCollation.compare(s, t);
\r
124 CollationKey sortKey1, sortKey2;
\r
125 sortKey1 = myCollation.getCollationKey(s);
\r
126 sortKey2 = myCollation.getCollationKey(t);
\r
127 int keyResult = sortKey1.compareTo(sortKey2);
\r
128 reportCResult(s, t, sortKey1, sortKey2, compareResult, keyResult, compareResult, result);
\r
132 private void reportCResult( String source, String target, CollationKey sourceKey, CollationKey targetKey,
\r
133 int compareResult, int keyResult, int incResult, int expectedResult ){
\r
134 if (expectedResult < -1 || expectedResult > 1)
\r
136 errln("***** invalid call to reportCResult ****");
\r
140 boolean ok1 = (compareResult == expectedResult);
\r
141 boolean ok2 = (keyResult == expectedResult);
\r
142 boolean ok3 = (incResult == expectedResult);
\r
144 if (ok1 && ok2 && ok3 && !isVerbose()){
\r
147 String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\"";
\r
148 String msg2 = "\", \"";
\r
149 String msg3 = "\") returned ";
\r
150 String msg4 = "; expected ";
\r
152 String sExpect = new String("");
\r
153 String sResult = new String("");
\r
154 sResult = appendCompareResult(compareResult, sResult);
\r
155 sExpect = appendCompareResult(expectedResult, sExpect);
\r
157 logln(msg1 + source + msg2 + target + msg3 + sResult);
\r
159 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
\r
162 msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\"";
\r
163 msg2 = "\").compareTo(key(\"";
\r
164 msg3 = "\")) returned ";
\r
165 sResult = appendCompareResult(keyResult, sResult);
\r
167 logln(msg1 + source + msg2 + target + msg3 + sResult);
\r
169 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
\r
172 errln(msg1 + prettify(sourceKey) + msg2 + prettify(targetKey));
\r
175 msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\"";
\r
177 msg3 = "\") returned ";
\r
179 sResult = appendCompareResult(incResult, sResult);
\r
182 logln(msg1 + source + msg2 + target + msg3 + sResult);
\r
184 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
\r
189 private String appendCompareResult(int result, String target){
\r
190 if (result == -1) //LESS
\r
194 else if (result == 0) //EQUAL
\r
198 else if (result == 1) //GREATER
\r
200 target += "GREATER";
\r
206 target += huh + result;
\r
211 String prettify(CollationKey sourceKey) {
\r
213 byte[] bytes= sourceKey.toByteArray();
\r
214 String target = "[";
\r
216 for (i = 0; i < bytes.length; i++) {
\r
217 target += Integer.toHexString(bytes[i]);
\r