1 /*
2  * Copyright (c) 2009, 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 5047314
27  * @summary verify that compare() and getCollationKey() don't go into an infinite loop for unfinished Thai/Lao text.
28  * @run main/timeout=60 Bug5047314
29  */
30 package test.java.text.Collator;
31 
32 import java.text.Collator;
33 import java.util.Locale;
34 
35 public class Bug5047314 {
36 
37     private static Collator colLao = Collator.getInstance(new Locale("lo"));
38     private static Collator colThai = Collator.getInstance(new Locale("th"));
39 
40     private static String[] textLao = {
41         "\u0ec0", "\u0ec1", "\u0ec2", "\u0ec3", "\u0ec4"
42     };
43     private static String[] textThai = {
44         "\u0e40", "\u0e41", "\u0e42", "\u0e43", "\u0e44"
45     };
46 
main(String[] args)47     public static void main(String[] args) {
48         testLao1();
49         testLao2();
50         testThai1();
51         testThai2();
52     }
53 
testLao1()54     private static void testLao1() {
55         System.out.print("Test(Lao 1) .... ");
56         for (int i = 0; i < textLao.length; i++) {
57             colLao.compare(textLao[i], textLao[i]);
58         }
59         System.out.println("Passed.");
60     }
61 
testLao2()62     private static void testLao2() {
63         System.out.print("Test(Lao 2) .... ");
64         for (int i = 0; i < textLao.length; i++) {
65             colLao.compare(textLao[i], textLao[i]);
66         }
67         System.out.println("Passed.");
68     }
69 
testThai1()70     private static void testThai1() {
71         System.out.print("Test(Thai 1) .... ");
72         for (int i = 0; i < textThai.length; i++) {
73             colThai.compare(textThai[i], textThai[i]);
74         }
75         System.out.println("Passed.");
76     }
77 
testThai2()78     private static void testThai2() {
79         System.out.print("Test(Thai 2) .... ");
80         for (int i = 0; i < textThai.length; i++) {
81             colThai.getCollationKey(textThai[i]);
82         }
83         System.out.println("Passed.");
84     }
85 
86 }
87