1/*
2 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 * @test
26 * @bug 6755060
27 * @modules jdk.localedata
28 * @summary updating collation tables for thai to make it consistent with CLDR 1.9
29 */
30
31import java.text.Collator;
32import java.util.Arrays;
33import java.util.Locale;
34
35public class Bug6755060 {
36
37  /********************************************************
38  *********************************************************/
39  public static void main (String[] args) {
40
41    Locale reservedLocale = Locale.getDefault();
42
43    try{
44
45        int errors=0;
46
47        Locale loc = new Locale ("th", "TH");   // Thai
48
49        Locale.setDefault (loc);
50        Collator col = Collator.getInstance ();
51
52        /*
53        * The original data "data" are the data to be sorted provided by the submitter of the CR.
54        * It's in correct order in accord with thai collation in CLDR 1.9. If we use old Java without this fix,
55        * the output order will be incorrect. Correct order will be turned into incorrect order.
56
57        * If fix is there, "data" after sorting will be unchanged, same as "sortedData". If fix is lost (regression),
58        * "data" after sorting will be changed, not as "sortedData".(not correct anymore)
59
60        * The submitter of the CR also gives a expected "sortedData" in the CR, but it's in accord with collation in CLDR 1.4.
61        * His data to be sorted are actually well sorted in accord with CLDR 1.9.
62        */
63
64        String[] 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"};
65
66        String[] 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"};
67
68        Arrays.sort (data, col);
69
70        System.out.println ("Using " + loc.getDisplayName());
71        for (int i = 0;  i < data.length;  i++) {
72            System.out.println(data[i] + "  :  " + sortedData[i]);
73            if (sortedData[i].compareTo(data[i]) != 0) {
74                errors++;
75            }
76        }//end for
77
78        if (errors > 0){
79            StringBuffer expected = new StringBuffer(), actual = new StringBuffer();
80            expected.append(sortedData[0]);
81            actual.append(data[0]);
82
83                for (int i=1; i<data.length; i++) {
84                    expected.append(",");
85                    expected.append(sortedData[i]);
86
87                    actual.append(",");
88                    actual.append(data[i]);
89                }
90
91            String errmsg = "Error is found in collation testing in Thai\n" + "exepected order is: " + expected.toString() + "\n" + "actual order is: " + actual.toString() + "\n";
92
93            throw new RuntimeException(errmsg);
94        }
95    }finally{
96        // restore the reserved locale
97        Locale.setDefault(reservedLocale);
98    }
99
100  }//end main
101
102}//end class CollatorTest
103