Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/text/Collator/JapaneseTest.java
47066 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/1125* @bug 4176141 465581926* @summary Regression tests for Japanese Collation27*/2829import java.text.*;30import java.util.*;3132public class JapaneseTest {3334// NOTE:35// Golden data in this test case is locale data dependent and36// may need to be changed if the Japanese locale collation rules37// are changed.3839/*40* | NO_DECOMP(default) | CANONICAL_DECOMP | FULL_DECOMP41* -------------------+--------------------+------------------+-------------42* PRIMARY | s1 < s2 (-1) | s1 < s2 (-1) | s1 < s2 (-1)43* SECONDARY | s1 < s2 (-1) | s1 < s2 (-1) | s1 < s2 (-1)44* TERTIARY(default) | S1 < s2 (-1) | s1 < s2 (-1) | s1 < s2 (-1)45*/46static final int[][] results1 = {47{ -1, -1, -1},48{ -1, -1, -1},49{ -1, -1, -1},50};51static final String[][] compData1 = {52/*53* Data to verify '<' relationship in LocaleElements_ja.java54*/55{"\u3084", "\u30E6",56"Hiragana \"YA\"(0x3084) <---> Katakana \"YU\"(0x30E6)"},57{"\u30E6", "\u3088",58"Katakana \"YU\"(0x30E6) <---> Hiragana \"YO\"(0x3088)"},59{"\u00B1", "\u2260",60"Plus-Minus Sign(0x00B1) <---> Not Equal To(0x2260)"},61{"\u3011", "\u2260",62"Right Black Lenticular Bracket(0x3011) <---> Not Equal To(0x2260)"},63{"\u2260", "\u2103",64"Not Equal To(0x2260) <---> Degree Celsius(0x2103)"},65{"\u2260", "\u2606",66"Not Equal To(0x2260) <---> White Star(0x2606)"},67{"\u30FD", "\u309E",68"Katakana Iteration Mark(0x30FD) <---> Hiragana Voiced Iteration Mark(0x309E)"},69{"\u3059\u309D", "\u3059\u309E",70"Hiragana \"SU\"(0x3059)Hiragana Iteration Mark(0x309D) <---> Hiragana \"SU\"(0x3059)Hiragana Voiced Iteration Mark(0x309E)"},71{"\u821E", "\u798F",72"CJK Unified Ideograph(0x821E) <---> CJK Unified Ideograph(0x798F)"},7374/*75* Data to verify normalization76*/77{"\u2260", "\u225F",78"Not Equal To(0x2260) <---> Questioned Equal To(0x225F)"},79{"\u226E", "\u2260",80"Not Less-than(0x226E) <---> Not Equal To(0x2260)"},81{"\u226E", "\u226D",82"Not Less-than(0x226E) <---> Not Equivalent To(0x226D)"},83};8485/*86* | NO_DECOMP(default) | CANONICAL_DECOMP | FULL_DECOMP87* -------------------+--------------------+------------------+-------------88* PRIMARY | s1 = s2 (0) | s1 = s2 (0) | s1 = s2 (0)89* SECONDARY | s1 < s2 (-1) | s1 < s2 (-1) | s1 < s2 (-1)90* TERTIARY(default) | S1 < s2 (-1) | s1 < s2 (-1) | s1 < s2 (-1)91*/92static final int[][] results2 = {93{ 0, 0, 0},94{ -1, -1, -1},95{ -1, -1, -1},96};97static final String[][] compData2 = {98/*99* Data to verify ';' relationship in LocaleElements_ja.java100*/101{"\u3099", "\u309A",102"Combining Katakana-Hiragana Voiced Sound Mark(0x3099) <---> Combining Katakana-Hiragana Semi-voiced Sound Mark(0x309A)"},103{"\u3053\u3046\u3068\u3046", "\u3053\u3046\u3068\u3099\u3046",104"Hiragana \"KOUTOU\"(0x3053 0x3046 0x3068 0x3046) <---> Hiragana \"KOUTO\"(0x3053 0x3046 0x3068)Combining Katakana-Hiragana Voiced Sound Mark(0X3099)\"U\"(0x3046)"},105{"\u3053\u3046\u3068\u3046", "\u3053\u3046\u3069\u3046",106"Hiragana \"KOUTOU\"(0x3053 0x3046 0x3068 0x3046) <---> Hiragana \"KOUDOU\"(0x3053 0x3046 0x3069 0x3046)"},107{"\u3053\u3046\u3069\u3046", "\u3054\u3046\u3068\u3046",108"Hiragana \"KOUTOU\"(0x3053 0x3046 0x3069 0x3046) <---> Hiragana \"GOUTOU\"(0x3054 0x3046 0x3068 0x3046)"},109{"\u3054\u3046\u3068\u3046", "\u3054\u3046\u3069\u3046",110"Hiragana \"GOUTOU\"(0x3054 0x3046 0x3068 0x3046) <---> Hiragana \"GOUDOU\"(0x3054 0x3046 0x3069 0x3046)"},111};112113/*114* | NO_DECOMP(default) | CANONICAL_DECOMP | FULL_DECOMP115* -------------------+--------------------+------------------+-------------116* PRIMARY | s1 = s2 (0) | s1 = s2 (0) | s1 = s2 (0)117* SECONDARY | s1 = s2 (0) | s1 = s2 (0) | s1 = s2 (0)118* TERTIARY(default) | S1 < s2 (-1) | s1 < s2 (-1) | s1 < s2 (-1)119*/120static final int[][] results3 = {121{ 0, 0, 0},122{ 0, 0, 0},123{ -1, -1, -1},124};125static final String[][] compData3 = {126/*127* Data to verify ',' relationship in LocaleElements_ja.java128*/129{"\u3042", "\u3041",130"Hiragana \"A\"(0x3042) <---> Hiragana \"a\"(0x3041)"},131{"\u3041", "\u30A2",132"Hiragana \"a\"(0x3041) <---> Katakana \"A\"(0x30A2)"},133{"\u30A2", "\u30A1",134"Katakana \"A\"(0x30A2) <---> Katakana \"a\"(0x30A1)"},135{"\u3094", "\u30F4",136"Hiragana \"VU\"(0x3094) <---> Katakana \"VU\"(0x30F4)"},137{"\u3094", "\u30A6\u3099",138"Hiragana \"VU\"(0x3094) <---> Katakana \"U\"(0x30A6)Combining Katakana-Hiragana Voiced Sound Mark(0x3099)"},139{"\u3046\u3099", "\u30F4",140"Hiragana \"U\"(0x3046)Combining Katakana-Hiragana Voiced Sound Mark(0x3099) <---> Katakana \"VU\"(0x30F4)"},141{"\u3046\u3099", "\u30A6\u3099",142"Hiragana \"U\"(0x3046)Combining Katakana-Hiragana Voiced Sound Mark(0x3099) <---> Katakana \"U\"(0x30A6)Combining Katakana-Hiragana Voiced Sound Mark(0x3099)"},143{"\u30AB\u30A2", "\u30AB\u30FC",144"Katakana \"KAA\"(0x30AB 0x30A2) <---> Katakana \"KA-\"(0x30AB 0x30FC)"},145{"\u30CB\u30A1\u30A2", "\u30CB\u30A1\u30FC",146"Katakana \"NyaA\"(0x30CB 0x30A1 0x30A2) <---> Katakana \"Nya-\"(0x30CB 0x30A1 0x30FC)"},147{"\u30B3\u30AA\u30D2\u30A4", "\u30B3\u30FC\u30D2\u30FC",148"Katakana \"KOOHII\"(0x30B3 0x30AA 0x30D2 0x30A4) <---> Katakana \"KO-HI-\"(0x30B3 0x30FC 0x30D2 0x30FC)"},149{"\u308A\u3088\u3046", "\u308A\u3087\u3046",150"Hiragana \"RIYOU\"(0x308A 0x3088 0x3046) <---> Hiragana \"Ryou\"(0x308A 0x3087 0x3046)"},151{"\u3081\u3064\u304D", "\u3081\u3063\u304D",152"Hiragana \"METSUKI\"(0x3081 0x3064 0x304D) <---> Hiragana \"MEKKI\"(0x3081 0x3063 0x304D)"},153{"\u3075\u3042\u3093", "\u30D5\u30A1\u30F3",154"Hiragana \"FUAN\"(0x3075 0x3042 0x3093) <---> Katakana \"FUaN\"(0x30D5 0x30A1 0x30F3)"},155{"\u3075\u3041\u3093", "\u30D5\u30A2\u30F3",156"Hiragana \"FUaN\"(0x3075 0x3041 0x3093) <---> Katakana \"FUAN\"(0x30D5 0x30A2 0x30F3)"},157{"\u30D5\u30A2\u30F3", "\u30D5\u30A1\u30F3",158"Katakana \"FUAN\"(0x30D5 0x30A2 0x30F3) <---> Katakana \"FUaN\"(0x30D5 0x30A1 0x30F3)"},159};160161/*162* | NO_DECOMP(default) | CANONICAL_DECOMP | FULL_DECOMP163* -------------------+--------------------+------------------+-------------164* PRIMARY | s1 = s2 (0) | s1 = s2 (0) | s1 = s2 (0)165* SECONDARY | s1 = s2 (0) | s1 = s2 (0) | s1 = s2 (0)166* TERTIARY(default) | S1 = s2 (0) | s1 = s2 (0) | s1 = s2 (0)167*/168static final int[][] results4 = {169{ 0, 0, 0},170{ 0, 0, 0},171{ 0, 0, 0},172};173static final String[][] compData4 = {174/*175* Data to verify Japanese normalization176*/177{"\u309E", "\u309D\u3099",178"Hiragana Voiced Iteration Mark(0x309E) <---> Hiragana Iteration Mark(0x309D)Combining Katakana-Hiragana Voiced Sound Mark(0x3099)"},179{"\u30FE", "\u30FD\u3099",180"Katakana Voiced Iteration Mark(0x30FE) <---> Katakana iteration mark(0x30FD)Combining Katakana-Hiragana Voiced Sound Mark(0x3099)"},181{"\u306F\u3099", "\u3070",182"Hiragana \"HA\"(0x306F)Combining Katakana-Hiragana Voiced Sound Mark(0x3099) <---> Hiragana \"BA\"(0x3070)"},183{"\u306F\u309A", "\u3071",184"Hiragana \"HA\"(0x306F)Combining Katakana-Hiragana Semi-voiced Sound Mark(0x309A) <---> Hiragana \"PA\"(0x3071)"},185{"\u30EF\u3099", "\u30F7",186"Katakana \"WA\"(0x306F)Combining Katakana-Hiragana Voiced Sound Mark(0x3099) <---> Katakana \"VA\"(0x30F7)"},187{"\u30F0\u3099", "\u30F8",188"Katakana \"WI\"(0x30F0)Combining Katakana-Hiragana Voiced Sound Mark(0x3099) <---> Katakana \"VI\"(0x30F8)"},189{"\u30F1\u3099", "\u30F9",190"Katakana \"WE\"(0x30F1)Combining Katakana-Hiragana Voiced Sound Mark(0x3099) <---> Katakana \"VE\"(0x30F9)"},191{"\u30F2\u3099", "\u30FA",192"Katakana \"WO\"(0x30F2)Combining Katakana-Hiragana Voiced Sound Mark(0x3099) <---> Katakana \"VO\"(0x30FA)"},193{"\u3046\u3099", "\u3094",194"Hiragana \"U\"(0x3046)Combining Katakana-Hiragana Voiced Sound Mark(0x3099) <---> Hiragana \"VU\"(0x3094)"},195{"\u30A6\u3099", "\u30F4",196"Katakana \"U\"(0x30A6)Combining Katakana-Hiragana Voiced Sound Mark(0x3099) <---> Katakana \"VU\"(0x30F4)"},197198// verify normalization199{"\u2260", "\u003D\u0338",200"Not Equal To(0x2260) <---> Equal(0x003D)Combining Long Solidus Overlay(0x0338)"},201{"\u2262", "\u2261\u0338",202"Not Identical To(0x2262) <---> Identical To(0x2261)Combining Long Solidus Overlay(0x0338)"},203{"\u226E", "\u003C\u0338",204"Not Less-than(0x226E) <---> Less-than Sign(0x003C)Combining Long Solidus Overlay(0x0338)"},205206// Verify a character which has been added since Unicode 2.1.X.207{"\u798F", "\uFA1B",208"CJK Unified Ideograph \"FUKU\"(0x798F) <---> CJK Compatibility Ideograph \"FUKU\"(0xFA1B)"},209};210211/*212* | NO_DECOMP(default) | CANONICAL_DECOMP | FULL_DECOMP213* -------------------+--------------------+------------------+-------------214* PRIMARY | s1 > s2 (1) | s1 = s2 (0) | s1 = s2 (0)215* SECONDARY | s1 > s2 (1) | s1 = s2 (0) | s1 = s2 (0)216* TERTIARY(default) | S1 > s2 (1) | s1 = s2 (0) | s1 = s2 (0)217*/218static final int[][] results5 = {219{ 1, 0, 0},220{ 1, 0, 0},221{ 1, 0, 0},222};223static final String[][] compData5 = {224/*225* Data to verify normalization226*/227{"\u226D", "\u224D\u0338",228"Not Equivalent To(0x226D) <---> Equivalent To(0x224D)Combining Long Solidus Overlay(0x0338)"},229};230231static final int[][] results6 = {232{ 1, -1, -1},233{ 1, -1, -1},234{ 1, -1, -1},235};236static final String[][] compData6 = {237/*238* Data to verify normalization239*/240{"\u226D", "\u226C",241"Not Equivalent To(0x226D) <---> Between(0x226C)"},242{"\u226D", "\u225F",243"Not Equivalent To(0x226D) <---> Questioned Equal To(0x225F)"},244};245246247/*248* The following data isn't used at the moment because iteration marks249* aren't supported now.250*/251static final String[][] compData0 = {252{"\u307F\u307F", "\u307F\u309D",253"Hiragana \"MIMI\"(0x307F 0x307F) <---> Hiragana \"MI\"(0x307F)Hiragana Iteration Mark(0x309D)"},254{"\u3044\u3059\u305A", "\u3044\u3059\u309E",255"Hiragana \"ISUZU\"(0x3044 0x3059 0x305A) <---> Hiragana \"ISU\"(0x3044 0x3059)Hiragana Voiced Iteration Mark(0x309E)"},256{"\u30DF\u30DF", "\u30DF\u30FD",257"Katakana \"MIMI\"(0x30DF 0x30DF) <---> Katakana \"MI\"(0x30DF)Katakana Iteration Mark(0x30FD)"},258{"\u30A4\u30B9\u30BA", "\u30A4\u30B9\u30FE",259"Katakana \"ISUZU\"(0x30A4 0x30B9 0x30BA) <---> Katakana \"ISU\"(0x30A4 0x30B9)Katakana Voiced Iteration Mark(0x30FE)"},260};261262263static final String[] decomp_name = {264"NO_DECOMP", "CANONICAL_DECOMP", "FULL_DECOMP"265};266267static final String[] strength_name = {268"PRIMARY", "SECONDARY", "TERTIARY"269};270271272Collator col = Collator.getInstance(Locale.JAPAN);273int result = 0;274275public static void main(String[] args) throws Exception {276new JapaneseTest().run();277}278279public void run() {280// Use all available localse on the initial testing....281// Locale[] locales = Locale.getAvailableLocales();282Locale[] locales = { Locale.getDefault() };283284for (int l = 0; l < locales.length; l++) {285Locale.setDefault(locales[l]);286287for (int decomp = 0; decomp < 3; decomp++) {// See decomp_name.288col.setDecomposition(decomp);289290for (int strength = 0; strength < 3; strength++) {// See strength_name.291// System.err.println("\n" + locales[l] + ": " + strength_name[strength] + " --- " + decomp_name[decomp]);292293col.setStrength(strength);294doCompare(compData1, results1[strength][decomp], strength, decomp);295doCompare(compData2, results2[strength][decomp], strength, decomp);296doCompare(compData3, results3[strength][decomp], strength, decomp);297doCompare(compData4, results4[strength][decomp], strength, decomp);298doCompare(compData5, results5[strength][decomp], strength, decomp);299doCompare(compData6, results6[strength][decomp], strength, decomp);300}301}302}303304/* Check result */305if (result !=0) {306throw new RuntimeException("Unexpected results on Japanese collation.");307}308}309310void doCompare(String[][] s, int expectedValue, int strength, int decomp) {311int value;312for (int i=0; i < s.length; i++) {313if ((value = col.compare(s[i][0], s[i][1])) != expectedValue) {314result++;315System.err.println(strength_name[strength] +316": compare() returned unexpected value.(" +317value + ") on " + decomp_name[decomp] +318" Expected(" + expectedValue +319") for " + s[i][2]);320}321}322}323}324325326