Path: blob/master/test/jdk/sun/text/resources/Collator/Bug6755060.java
41152 views
/*1* Copyright (c) 2011, 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* @test25* @bug 675506026* @modules jdk.localedata27* @summary updating collation tables for thai to make it consistent with CLDR 1.928*/2930import java.text.Collator;31import java.util.Arrays;32import java.util.Locale;3334public class Bug6755060 {3536/********************************************************37*********************************************************/38public static void main (String[] args) {3940Locale reservedLocale = Locale.getDefault();4142try{4344int errors=0;4546Locale loc = new Locale ("th", "TH"); // Thai4748Locale.setDefault (loc);49Collator col = Collator.getInstance ();5051/*52* The original data "data" are the data to be sorted provided by the submitter of the CR.53* It's in correct order in accord with thai collation in CLDR 1.9. If we use old Java without this fix,54* the output order will be incorrect. Correct order will be turned into incorrect order.5556* If fix is there, "data" after sorting will be unchanged, same as "sortedData". If fix is lost (regression),57* "data" after sorting will be changed, not as "sortedData".(not correct anymore)5859* The submitter of the CR also gives a expected "sortedData" in the CR, but it's in accord with collation in CLDR 1.4.60* His data to be sorted are actually well sorted in accord with CLDR 1.9.61*/6263String[] data = {"\u0e01", "\u0e01\u0e2f", "\u0e01\u0e46", "\u0e01\u0e4f", "\u0e01\u0e5a", "\u0e01\u0e5b", "\u0e01\u0e4e", "\u0e01\u0e4c", "\u0e01\u0e48", "\u0e01\u0e01", "\u0e01\u0e4b\u0e01", "\u0e01\u0e4d", "\u0e01\u0e30", "\u0e01\u0e31\u0e01", "\u0e01\u0e32", "\u0e01\u0e33", "\u0e01\u0e34", "\u0e01\u0e35", "\u0e01\u0e36", "\u0e01\u0e37", "\u0e01\u0e38", "\u0e01\u0e39", "\u0e40\u0e01", "\u0e40\u0e01\u0e48", "\u0e40\u0e01\u0e49", "\u0e40\u0e01\u0e4b", "\u0e41\u0e01", "\u0e42\u0e01", "\u0e43\u0e01", "\u0e44\u0e01", "\u0e01\u0e3a", "\u0e24\u0e32", "\u0e24\u0e45", "\u0e40\u0e25", "\u0e44\u0e26"};6465String[] sortedData = {"\u0e01", "\u0e01\u0e2f", "\u0e01\u0e46", "\u0e01\u0e4f", "\u0e01\u0e5a", "\u0e01\u0e5b", "\u0e01\u0e4e", "\u0e01\u0e4c", "\u0e01\u0e48", "\u0e01\u0e01", "\u0e01\u0e4b\u0e01", "\u0e01\u0e4d", "\u0e01\u0e30", "\u0e01\u0e31\u0e01", "\u0e01\u0e32", "\u0e01\u0e33", "\u0e01\u0e34", "\u0e01\u0e35", "\u0e01\u0e36", "\u0e01\u0e37", "\u0e01\u0e38", "\u0e01\u0e39", "\u0e40\u0e01", "\u0e40\u0e01\u0e48", "\u0e40\u0e01\u0e49", "\u0e40\u0e01\u0e4b", "\u0e41\u0e01", "\u0e42\u0e01", "\u0e43\u0e01", "\u0e44\u0e01", "\u0e01\u0e3a", "\u0e24\u0e32", "\u0e24\u0e45", "\u0e40\u0e25", "\u0e44\u0e26"};6667Arrays.sort (data, col);6869System.out.println ("Using " + loc.getDisplayName());70for (int i = 0; i < data.length; i++) {71System.out.println(data[i] + " : " + sortedData[i]);72if (sortedData[i].compareTo(data[i]) != 0) {73errors++;74}75}//end for7677if (errors > 0){78StringBuffer expected = new StringBuffer(), actual = new StringBuffer();79expected.append(sortedData[0]);80actual.append(data[0]);8182for (int i=1; i<data.length; i++) {83expected.append(",");84expected.append(sortedData[i]);8586actual.append(",");87actual.append(data[i]);88}8990String errmsg = "Error is found in collation testing in Thai\n" + "exepected order is: " + expected.toString() + "\n" + "actual order is: " + actual.toString() + "\n";9192throw new RuntimeException(errmsg);93}94}finally{95// restore the reserved locale96Locale.setDefault(reservedLocale);97}9899}//end main100101}//end class CollatorTest102103104