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/CollationFinnishTest 13 * Source File: $ICU4CRoot/source/test/intltest/ficoll.cpp 14 **/ 15 16 package android.icu.dev.test.collator; 17 18 import org.junit.Before; 19 import org.junit.Test; 20 import org.junit.runner.RunWith; 21 import org.junit.runners.JUnit4; 22 23 import android.icu.dev.test.TestFmwk; 24 import android.icu.text.CollationKey; 25 import android.icu.text.Collator; 26 import android.icu.util.ULocale; 27 import android.icu.testsharding.MainTestShard; 28 29 @MainTestShard 30 @RunWith(JUnit4.class) 31 public class CollationFinnishTest extends TestFmwk { 32 private static char[][] testSourceCases = { 33 {0x77, 0x61, 0x74}, 34 {0x76, 0x61, 0x74}, 35 {0x61, 0x00FC, 0x62, 0x65, 0x63, 0x6b}, 36 {0x4c, 0x00E5, 0x76, 0x69}, 37 {0x77, 0x61, 0x74} 38 }; 39 40 private static char[][] testTargetCases = { 41 {0x76, 0x61, 0x74}, 42 {0x77, 0x61, 0x79}, 43 {0x61, 0x78, 0x62, 0x65, 0x63, 0x6b}, 44 {0x4c, 0x00E4, 0x77, 0x65}, 45 {0x76, 0x61, 0x74} 46 }; 47 48 private static int[] results = { 49 1, 50 -1, 51 1, 52 -1, 53 // test primary > 4 54 1, // v < w per cldrbug 6615 55 }; 56 57 private Collator myCollation = null; 58 59 public CollationFinnishTest() { 60 } 61 62 @Before 63 public void init()throws Exception{ 64 myCollation = Collator.getInstance(new ULocale("fi_FI@collation=standard")); 65 } 66 67 68 // perform tests with strength PRIMARY 69 @Test 70 public void TestPrimary() { 71 int i = 0; 72 myCollation.setStrength(Collator.PRIMARY); 73 for(i = 4; i < 5; i++) { 74 doTest(testSourceCases[i], testTargetCases[i], results[i]); 75 } 76 } 77 78 // perform test with strength TERTIARY 79 @Test 80 public void TestTertiary() { 81 int i = 0; 82 myCollation.setStrength(Collator.TERTIARY); 83 for(i = 0; i < 4; i++ ) { 84 doTest(testSourceCases[i], testTargetCases[i], results[i]); 85 } 86 } 87 88 // main test routine, tests rules specific to the finish locale 89 private void doTest(char[] source, char[] target, int result) { 90 String s = new String(source); 91 String t = new String(target); 92 int compareResult = myCollation.compare(s, t); 93 CollationKey sortKey1, sortKey2; 94 sortKey1 = myCollation.getCollationKey(s); 95 sortKey2 = myCollation.getCollationKey(t); 96 int keyResult = sortKey1.compareTo(sortKey2); 97 reportCResult(s, t, sortKey1, sortKey2, compareResult, keyResult, compareResult, result); 98 } 99 100 private void reportCResult( String source, String target, CollationKey sourceKey, CollationKey targetKey, 101 int compareResult, int keyResult, int incResult, int expectedResult ) { 102 if (expectedResult < -1 || expectedResult > 1) { 103 errln("***** invalid call to reportCResult ****"); 104 return; 105 } 106 107 boolean ok1 = (compareResult == expectedResult); 108 boolean ok2 = (keyResult == expectedResult); 109 boolean ok3 = (incResult == expectedResult); 110 111 if (ok1 && ok2 && ok3 && !isVerbose()) { 112 return; 113 } else { 114 String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\""; 115 String msg2 = "\", \""; 116 String msg3 = "\") returned "; 117 String msg4 = "; expected "; 118 119 String sExpect = new String(""); 120 String sResult = new String(""); 121 sResult = CollationTest.appendCompareResult(compareResult, sResult); 122 sExpect = CollationTest.appendCompareResult(expectedResult, sExpect); 123 if (ok1) { 124 logln(msg1 + source + msg2 + target + msg3 + sResult); 125 } else { 126 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect); 127 } 128 129 msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\""; 130 msg2 = "\").compareTo(key(\""; 131 msg3 = "\")) returned "; 132 sResult = CollationTest.appendCompareResult(keyResult, sResult); 133 if (ok2) { 134 logln(msg1 + source + msg2 + target + msg3 + sResult); 135 } else { 136 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect); 137 msg1 = " "; 138 msg2 = " vs. "; 139 errln(msg1 + CollationTest.prettify(sourceKey) + msg2 + CollationTest.prettify(targetKey)); 140 } 141 142 msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\""; 143 msg2 = "\", \""; 144 msg3 = "\") returned "; 145 146 sResult = CollationTest.appendCompareResult(incResult, sResult); 147 148 if (ok3) { 149 logln(msg1 + source + msg2 + target + msg3 + sResult); 150 } else { 151 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect); 152 } 153 } 154 } 155 } 156