1/* GENERATED SOURCE. DO NOT MODIFY. */ 2// © 2016 and later: Unicode, Inc. and others. 3// License & terms of use: http://www.unicode.org/copyright.html#License 4/* 5 ******************************************************************************* 6 * Copyright (C) 2002-2014, International Business Machines Corporation and 7 * others. All Rights Reserved. 8 ******************************************************************************* 9 */ 10 11/** 12 * Port From: ICU4C v2.1 : Collate/LotusCollationKoreanTest 13 * Source File: $ICU4CRoot/source/test/intltest/lcukocol.cpp 14 **/ 15 16package android.icu.dev.test.collator; 17 18import java.util.Locale; 19 20import org.junit.Before; 21import org.junit.Test; 22 23import android.icu.dev.test.TestFmwk; 24import android.icu.text.CollationKey; 25import android.icu.text.Collator; 26 27public class LotusCollationKoreanTest extends TestFmwk{ 28 private static char[][] testSourceCases = { 29 {0xac00} 30 }; 31 32 private static char[][] testTargetCases = { 33 {0xac01} 34 }; 35 36 private static int[] results = { 37 -1 38 }; 39 40 private Collator myCollation; 41 42 public LotusCollationKoreanTest() { 43 } 44 45 @Before 46 public void init()throws Exception { 47 myCollation = Collator.getInstance(Locale.KOREAN); 48 myCollation.setDecomposition(Collator.CANONICAL_DECOMPOSITION); 49 } 50 51 // performs test with strength TERIARY 52 @Test 53 public void TestTertiary() { 54 int i = 0; 55 myCollation.setStrength(Collator.TERTIARY); 56 for (i = 0; i < 1; i++) { 57 doTest(testSourceCases[i], testTargetCases[i], results[i]); 58 } 59 } 60 61 // main test routine, tests rules specific to "Korean" locale 62 private void doTest( char[] source, char[] target, int result) { 63 String s = new String(source); 64 String t = new String(target); 65 int compareResult = myCollation.compare(s, t); 66 CollationKey sortKey1, sortKey2; 67 sortKey1 = myCollation.getCollationKey(s); 68 sortKey2 = myCollation.getCollationKey(t); 69 int keyResult = sortKey1.compareTo(sortKey2); 70 reportCResult( s, t, sortKey1, sortKey2, compareResult, keyResult, compareResult, result ); 71 } 72 73 private void reportCResult( String source, String target, CollationKey sourceKey, CollationKey targetKey, 74 int compareResult, int keyResult, int incResult, int expectedResult ){ 75 if (expectedResult < -1 || expectedResult > 1) { 76 errln("***** invalid call to reportCResult ****"); 77 return; 78 } 79 80 boolean ok1 = (compareResult == expectedResult); 81 boolean ok2 = (keyResult == expectedResult); 82 boolean ok3 = (incResult == expectedResult); 83 84 if (ok1 && ok2 && ok3 && !isVerbose()) { 85 return; 86 } else { 87 String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\""; 88 String msg2 = "\", \""; 89 String msg3 = "\") returned "; 90 String msg4 = "; expected "; 91 92 String sExpect = new String(""); 93 String sResult = new String(""); 94 sResult = CollationTest.appendCompareResult(compareResult, sResult); 95 sExpect = CollationTest.appendCompareResult(expectedResult, sExpect); 96 if (ok1) { 97 logln(msg1 + source + msg2 + target + msg3 + sResult); 98 } else { 99 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect); 100 } 101 102 msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\""; 103 msg2 = "\").compareTo(key(\""; 104 msg3 = "\")) returned "; 105 sResult = CollationTest.appendCompareResult(keyResult, sResult); 106 if (ok2) { 107 logln(msg1 + source + msg2 + target + msg3 + sResult); 108 } else { 109 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect); 110 msg1 = " "; 111 msg2 = " vs. "; 112 errln(msg1 + CollationTest.prettify(sourceKey) + msg2 + CollationTest.prettify(targetKey)); 113 } 114 115 msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\""; 116 msg2 = "\", \""; 117 msg3 = "\") returned "; 118 119 sResult = CollationTest.appendCompareResult(incResult, sResult); 120 121 if (ok3) { 122 logln(msg1 + source + msg2 + target + msg3 + sResult); 123 } else { 124 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect); 125 } 126 } 127 } 128} 129