Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/text/resources/Collator/Bug6755060.java
38855 views
/*1* Copyright (c) 2011, 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* @summary updating collation tables for thai to make it consistent with CLDR 1.927*/2829import java.text.*;30import java.util.*;3132public class Bug6755060 {3334/********************************************************35*********************************************************/36public static void main (String[] args) {3738Locale reservedLocale = Locale.getDefault();3940try{4142int errors=0;4344Locale loc = new Locale ("th", "TH"); // Thai4546Locale.setDefault (loc);47Collator col = Collator.getInstance ();4849/*50* The original data "data" are the data to be sorted provided by the submitter of the CR.51* It's in correct order in accord with thai collation in CLDR 1.9. If we use old Java without this fix,52* the output order will be incorrect. Correct order will be turned into incorrect order.5354* If fix is there, "data" after sorting will be unchanged, same as "sortedData". If fix is lost (regression),55* "data" after sorting will be changed, not as "sortedData".(not correct anymore)5657* The submitter of the CR also gives a expected "sortedData" in the CR, but it's in accord with collation in CLDR 1.4.58* His data to be sorted are actually well sorted in accord with CLDR 1.9.59*/6061String[] 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"};6263String[] 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"};6465Arrays.sort (data, col);6667System.out.println ("Using " + loc.getDisplayName());68for (int i = 0; i < data.length; i++) {69System.out.println(data[i] + " : " + sortedData[i]);70if (sortedData[i].compareTo(data[i]) != 0) {71errors++;72}73}//end for7475if (errors > 0){76StringBuffer expected = new StringBuffer(), actual = new StringBuffer();77expected.append(sortedData[0]);78actual.append(data[0]);7980for (int i=1; i<data.length; i++) {81expected.append(",");82expected.append(sortedData[i]);8384actual.append(",");85actual.append(data[i]);86}8788String errmsg = "Error is found in collation testing in Thai\n" + "exepected order is: " + expected.toString() + "\n" + "actual order is: " + actual.toString() + "\n";8990throw new RuntimeException(errmsg);91}92}finally{93// restore the reserved locale94Locale.setDefault(reservedLocale);95}9697}//end main9899}//end class CollatorTest100101102