Path: blob/master/test/jdk/java/text/Collator/KoreanTest.java
41149 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* @modules jdk.localedata28*/2930import java.text.*;31import java.util.*;3233public class KoreanTest {3435// NOTE:36// Golden data in this test case is locale data dependent and37// may need to be changed if the Korean locale collation rules38// are changed.3940// And, CollationDecomp has been set to 0(NO_DECOMPOSITION) in41// LocaleElements_ko.java.42// This is very important to consider what is correct behavior in43// Korean Collator. Sometimes different from other locales.4445/*46* TERTIARY(default): s1 < s2, SECONDARY: s1 < s2, PRIMARY: s1 < s247*/48static final String[][] compData1 = {49/*50* Data to verify '<' relationship in LocaleElements_ja.java51*/52{"\uACE0\uC591\uC774", "\u732B",53"Hangul \"Cat\"(0xACE0 0xC591 0xC774) <---> Chinese Kanji \"Cat\"(0x732B)"},54{"\u30FB", "\u2025",55"Katakana middle dot(0x30FB) <---> Two dot leader(0x2025)"},5657{"\u00B1", "\u2260",58"Plus-Minus Sign(0x00B1) <---> Not Equal To(0x2260)"},59{"\u3011", "\u2260",60"Right Black Lenticular Bracket(0x3011) <---> Not Equal To(0x2260)"},61{"\u2260", "\u2103",62"Not Equal To(0x2260) <---> Degree Celsius(0x2103)"},63{"\u2260", "\u2606",64"Not Equal To(0x2260) <---> White Star(0x2606)"},6566// Unlike other locales' Collator, compare() returns -1 because of67// NO_DECOMPOSITION.68/* above "assumption" is no longer true, now we do normalize ("decomposition")69for the pattern in ko locale, but exclude those hangul syllables, so the70test case below need to be excluded from tiger/1.571{"\u003D\u0338", "\u2260",72"Equal(0x003D)Combining Long Solidus Overlay(0x0338) <---> Not Equal To(0x2260)"},73*/74};7576/*77* TERTIARY(default): s1 = s2, SECONDARY: s1 = s2, PRIMARY: s1 = s278*/79static final String[][] compData2 = {80// Verify a character which has been added since Unicode 2.1.X.81{"\u798F", "\uFA1B",82"CJK Unified Ideograph \"FUKU\"(0x798F) <---> CJK Compatibility Ideograph \"FUKU\"(0xFA1B)"},8384};8586Collator col = Collator.getInstance(Locale.KOREA);87int result = 0;8889public static void main(String[] args) throws Exception {90new KoreanTest().run();91}9293public void run() {94//95// Test for TERTIARY(default)96//97doCompare(compData1);98doEquals(compData2);99100//101// Test for SECONDARY102//103col.setStrength(Collator.SECONDARY);104doCompare(compData1);105doEquals(compData2);106107//108// Test for PRIMARY109//110col.setStrength(Collator.PRIMARY);111doCompare(compData1);112doEquals(compData2);113114if (result !=0) {115throw new RuntimeException("Unexpected results on Korean collation.");116}117}118119/* compare() should return -1 for each combination. */120void doCompare(String[][] s) {121int value;122for (int i=0; i < s.length; i++) {123if ((value = col.compare(s[i][0], s[i][1])) > -1) {124result++;125System.err.println("TERTIARY: The first string should be less than the second string: " +126s[i][2] + " compare() returned " + value + ".");127}128}129}130131/* equals() should return true for each combination. */132void doEquals(String[][] s) {133for (int i=0; i < s.length; i++) {134if (!col.equals(s[i][0], s[i][1])) {135result++;136System.err.println("TERTIARY: The first string should be equals to the second string: " +137s[i][2] + " compare() returned " +138col.compare(s[i][0], s[i][1] + "."));139}140}141}142}143144145