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/LotusCollationKoreanTest
\r
10 * Source File: $ICU4CRoot/source/test/intltest/lcukocol.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
21 public class LotusCollationKoreanTest extends TestFmwk{
\r
22 public static void main(String[] args) throws Exception{
\r
23 new LotusCollationKoreanTest().run(args);
\r
26 private static char[][] testSourceCases = {
\r
30 private static char[][] testTargetCases = {
\r
34 private static int[] results = {
\r
38 private Collator myCollation;
\r
40 public LotusCollationKoreanTest() {
\r
42 protected void init()throws Exception{
\r
43 myCollation = Collator.getInstance(Locale.KOREAN);
\r
44 myCollation.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
\r
46 // performs test with strength TERIARY
\r
47 public void TestTertiary() {
\r
49 myCollation.setStrength(Collator.TERTIARY);
\r
50 for (i = 0; i < 1; i++) {
\r
51 doTest(testSourceCases[i], testTargetCases[i], results[i]);
\r
55 // main test routine, tests rules specific to "Korean" locale
\r
56 private void doTest( char[] source, char[] target, int result) {
\r
57 String s = new String(source);
\r
58 String t = new String(target);
\r
59 int compareResult = myCollation.compare(s, t);
\r
60 CollationKey sortKey1, sortKey2;
\r
61 sortKey1 = myCollation.getCollationKey(s);
\r
62 sortKey2 = myCollation.getCollationKey(t);
\r
63 int keyResult = sortKey1.compareTo(sortKey2);
\r
64 reportCResult( s, t, sortKey1, sortKey2, compareResult, keyResult, compareResult, result );
\r
67 private void reportCResult( String source, String target, CollationKey sourceKey, CollationKey targetKey,
\r
68 int compareResult, int keyResult, int incResult, int expectedResult ){
\r
69 if (expectedResult < -1 || expectedResult > 1) {
\r
70 errln("***** invalid call to reportCResult ****");
\r
74 boolean ok1 = (compareResult == expectedResult);
\r
75 boolean ok2 = (keyResult == expectedResult);
\r
76 boolean ok3 = (incResult == expectedResult);
\r
78 if (ok1 && ok2 && ok3 && !isVerbose()) {
\r
81 String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\"";
\r
82 String msg2 = "\", \"";
\r
83 String msg3 = "\") returned ";
\r
84 String msg4 = "; expected ";
\r
86 String sExpect = new String("");
\r
87 String sResult = new String("");
\r
88 sResult = appendCompareResult(compareResult, sResult);
\r
89 sExpect = appendCompareResult(expectedResult, sExpect);
\r
91 logln(msg1 + source + msg2 + target + msg3 + sResult);
\r
93 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
\r
96 msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\"";
\r
97 msg2 = "\").compareTo(key(\"";
\r
98 msg3 = "\")) returned ";
\r
99 sResult = appendCompareResult(keyResult, sResult);
\r
101 logln(msg1 + source + msg2 + target + msg3 + sResult);
\r
103 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
\r
106 errln(msg1 + prettify(sourceKey) + msg2 + prettify(targetKey));
\r
109 msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\"";
\r
111 msg3 = "\") returned ";
\r
113 sResult = appendCompareResult(incResult, sResult);
\r
116 logln(msg1 + source + msg2 + target + msg3 + sResult);
\r
118 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
\r
123 private String appendCompareResult(int result, String target){
\r
124 if (result == -1) {
\r
126 } else if (result == 0) {
\r
128 } else if (result == 1) {
\r
129 target += "GREATER";
\r
132 target += huh + result;
\r
137 String prettify(CollationKey sourceKey) {
\r
139 byte[] bytes= sourceKey.toByteArray();
\r
140 String target = "[";
\r
142 for (i = 0; i < bytes.length; i++) {
\r
143 target += Integer.toHexString(bytes[i]);
\r