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