Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/text/Collator/KoreanTest.java
47182 views
/*1* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test 1.1 02/09/1225* @bug 4176141 465581926* @summary Regression tests for Korean Collation27*/2829import java.text.*;30import java.util.*;3132public class KoreanTest {3334// NOTE:35// Golden data in this test case is locale data dependent and36// may need to be changed if the Korean locale collation rules37// are changed.3839// And, CollationDecomp has been set to 0(NO_DECOMPOSITION) in40// LocaleElements_ko.java.41// This is very important to consider what is correct behavior in42// Korean Collator. Sometimes different from other locales.4344/*45* TERTIARY(default): s1 < s2, SECONDARY: s1 < s2, PRIMARY: s1 < s246*/47static final String[][] compData1 = {48/*49* Data to verify '<' relationship in LocaleElements_ja.java50*/51{"\uACE0\uC591\uC774", "\u732B",52"Hangul \"Cat\"(0xACE0 0xC591 0xC774) <---> Chinese Kanji \"Cat\"(0x732B)"},53{"\u30FB", "\u2025",54"Katakana middle dot(0x30FB) <---> Two dot leader(0x2025)"},5556{"\u00B1", "\u2260",57"Plus-Minus Sign(0x00B1) <---> Not Equal To(0x2260)"},58{"\u3011", "\u2260",59"Right Black Lenticular Bracket(0x3011) <---> Not Equal To(0x2260)"},60{"\u2260", "\u2103",61"Not Equal To(0x2260) <---> Degree Celsius(0x2103)"},62{"\u2260", "\u2606",63"Not Equal To(0x2260) <---> White Star(0x2606)"},6465// Unlike other locales' Collator, compare() returns -1 because of66// NO_DECOMPOSITION.67/* above "assumption" is no longer true, now we do normalize ("decomposition")68for the pattern in ko locale, but exclude those hangul syllables, so the69test case below need to be excluded from tiger/1.570{"\u003D\u0338", "\u2260",71"Equal(0x003D)Combining Long Solidus Overlay(0x0338) <---> Not Equal To(0x2260)"},72*/73};7475/*76* TERTIARY(default): s1 = s2, SECONDARY: s1 = s2, PRIMARY: s1 = s277*/78static final String[][] compData2 = {79// Verify a character which has been added since Unicode 2.1.X.80{"\u798F", "\uFA1B",81"CJK Unified Ideograph \"FUKU\"(0x798F) <---> CJK Compatibility Ideograph \"FUKU\"(0xFA1B)"},8283};8485Collator col = Collator.getInstance(Locale.KOREA);86int result = 0;8788public static void main(String[] args) throws Exception {89new KoreanTest().run();90}9192public void run() {93//94// Test for TERTIARY(default)95//96doCompare(compData1);97doEquals(compData2);9899//100// Test for SECONDARY101//102col.setStrength(Collator.SECONDARY);103doCompare(compData1);104doEquals(compData2);105106//107// Test for PRIMARY108//109col.setStrength(Collator.PRIMARY);110doCompare(compData1);111doEquals(compData2);112113if (result !=0) {114throw new RuntimeException("Unexpected results on Korean collation.");115}116}117118/* compare() should return -1 for each combination. */119void doCompare(String[][] s) {120int value;121for (int i=0; i < s.length; i++) {122if ((value = col.compare(s[i][0], s[i][1])) > -1) {123result++;124System.err.println("TERTIARY: The first string should be less than the second string: " +125s[i][2] + " compare() returned " + value + ".");126}127}128}129130/* equals() should return true for each combination. */131void doEquals(String[][] s) {132for (int i=0; i < s.length; i++) {133if (!col.equals(s[i][0], s[i][1])) {134result++;135System.err.println("TERTIARY: The first string should be equals to the second string: " +136s[i][2] + " compare() returned " +137col.compare(s[i][0], s[i][1] + "."));138}139}140}141}142143144