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/CollationTurkishTest
\r
10 * Source File: $ICU4CRoot/source/test/intltest/trcoll.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 CollationTurkishTest extends TestFmwk{
\r
20 public static void main(String[] args) throws Exception{
\r
21 new CollationTurkishTest().run(args);
\r
24 private static char[][] testSourceCases = {
\r
26 {0x76, 0x00E4, 0x74},
\r
28 {0x00FC, 0x6f, 0x69, 0x64},
\r
29 {0x68, 0x011E, 0x61, 0x6c, 0x74},
\r
30 {0x73, 0x74, 0x72, 0x65, 0x73, 0x015E},
\r
31 {0x76, 0x6f, 0x0131, 0x64},
\r
32 {0x69, 0x64, 0x65, 0x61},
\r
33 {0x00FC, 0x6f, 0x69, 0x64},
\r
34 {0x76, 0x6f, 0x0131, 0x64},
\r
35 {0x69, 0x64, 0x65, 0x61}
\r
38 private static char[][] testTargetCases = {
\r
41 {0x00D6, 0x61, 0x79},
\r
42 {0x76, 0x6f, 0x69, 0x64},
\r
43 {0x68, 0x61, 0x6c, 0x74},
\r
44 {0x015E, 0x74, 0x72, 0x65, 0x015E, 0x73},
\r
45 {0x76, 0x6f, 0x69, 0x64},
\r
46 {0x49, 0x64, 0x65, 0x61},
\r
47 {0x76, 0x6f, 0x69, 0x64},
\r
48 {0x76, 0x6f, 0x69, 0x64},
\r
49 {0x49, 0x64, 0x65, 0x61}
\r
52 private static int[] results = {
\r
67 private Collator myCollation = null;
\r
69 public CollationTurkishTest() {
\r
72 protected void init()throws Exception{
\r
73 myCollation = Collator.getInstance(new Locale("tr", ""));
\r
76 public void TestTertiary() {
\r
78 myCollation.setStrength(Collator.TERTIARY);
\r
79 for (i = 0; i < 8 ; i++) {
\r
80 doTest(testSourceCases[i], testTargetCases[i], results[i]);
\r
84 public void TestPrimary() {
\r
86 myCollation.setStrength(Collator.PRIMARY);
\r
87 for (i = 8; i < 11; i++) {
\r
88 doTest(testSourceCases[i], testTargetCases[i], results[i]);
\r
93 // main test routine, tests rules specific to turkish locale
\r
94 private void doTest(char[] source, char[] target, int result) {
\r
95 String s = new String(source);
\r
96 String t = new String(target);
\r
97 int compareResult = myCollation.compare(s, t);
\r
98 CollationKey sortKey1, sortKey2;
\r
99 sortKey1 = myCollation.getCollationKey(s);
\r
100 sortKey2 = myCollation.getCollationKey(t);
\r
101 int keyResult = sortKey1.compareTo(sortKey2);
\r
102 reportCResult(s, t, sortKey1, sortKey2, compareResult, keyResult, compareResult, result);
\r
106 private void reportCResult( String source, String target, CollationKey sourceKey, CollationKey targetKey,
\r
107 int compareResult, int keyResult, int incResult, int expectedResult ) {
\r
108 if (expectedResult < -1 || expectedResult > 1) {
\r
109 errln("***** invalid call to reportCResult ****");
\r
113 boolean ok1 = (compareResult == expectedResult);
\r
114 boolean ok2 = (keyResult == expectedResult);
\r
115 boolean ok3 = (incResult == expectedResult);
\r
117 if (ok1 && ok2 && ok3 && !isVerbose()) {
\r
120 String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\"";
\r
121 String msg2 = "\", \"";
\r
122 String msg3 = "\") returned ";
\r
123 String msg4 = "; expected ";
\r
125 String sExpect = new String("");
\r
126 String sResult = new String("");
\r
127 sResult = appendCompareResult(compareResult, sResult);
\r
128 sExpect = appendCompareResult(expectedResult, sExpect);
\r
130 logln(msg1 + source + msg2 + target + msg3 + sResult);
\r
132 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
\r
135 msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\"";
\r
136 msg2 = "\").compareTo(key(\"";
\r
137 msg3 = "\")) returned ";
\r
138 sResult = appendCompareResult(keyResult, sResult);
\r
140 logln(msg1 + source + msg2 + target + msg3 + sResult);
\r
142 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
\r
145 errln(msg1 + prettify(sourceKey) + msg2 + prettify(targetKey));
\r
148 msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\"";
\r
150 msg3 = "\") returned ";
\r
152 sResult = appendCompareResult(incResult, sResult);
\r
155 logln(msg1 + source + msg2 + target + msg3 + sResult);
\r
157 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
\r
162 private String appendCompareResult(int result, String target) {
\r
163 if (result == -1) {
\r
165 } else if (result == 0) {
\r
167 } else if (result == 1) {
\r
168 target += "GREATER";
\r
171 target += huh + result;
\r
176 String prettify(CollationKey sourceKey) {
\r
178 byte[] bytes= sourceKey.toByteArray();
\r
179 String target = "[";
\r
181 for (i = 0; i < bytes.length; i++) {
\r
182 target += Integer.toHexString(bytes[i]);
\r