|
1 /* |
|
2 * Copyright (c) 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 * have any questions. |
|
22 */ |
|
23 |
|
24 /* |
|
25 * @test |
|
26 * @bug 6842557 |
|
27 * @summary confirm that shaping works as expected. (Mainly for new characters which were added in Unicode 5) |
|
28 * used where appropriate. |
|
29 */ |
|
30 |
|
31 import java.awt.font.NumericShaper; |
|
32 import java.util.EnumSet; |
|
33 import static java.awt.font.NumericShaper.*; |
|
34 |
|
35 public class ShapingTest { |
|
36 public static void main(String[] args) { |
|
37 NumericShaper ns_old = getContextualShaper(ARABIC | TAMIL | ETHIOPIC, |
|
38 EUROPEAN); |
|
39 NumericShaper ns_new = getContextualShaper(EnumSet.of( |
|
40 Range.ARABIC, Range.TAMIL, Range.ETHIOPIC), |
|
41 Range.EUROPEAN); |
|
42 |
|
43 boolean err = false; |
|
44 |
|
45 String[][] data = { |
|
46 // Arabic "October 10" |
|
47 {"\u0623\u0643\u062a\u0648\u0628\u0631 10", |
|
48 "\u0623\u0643\u062a\u0648\u0628\u0631 \u0661\u0660"}, |
|
49 |
|
50 // Tamil "Year 2009" |
|
51 {"\u0b86\u0ba3\u0bcd\u0b9f\u0bc1 2009", |
|
52 "\u0b86\u0ba3\u0bcd\u0b9f\u0bc1 \u0be8\u0be6\u0be6\u0bef"}, |
|
53 // "\u0be800\u0bef is returned by pre-JDK7 because Tamil zero was not |
|
54 // included in Unicode 4.0.0. |
|
55 |
|
56 // Ethiopic "Syllable<HA> 2009" |
|
57 {"\u1200 2009", |
|
58 "\u1200 \u136a00\u1371"}, |
|
59 // Ethiopic zero doesn't exist even in Unicode 5.1.0. |
|
60 }; |
|
61 |
|
62 for (int i = 0; i < data.length; i++) { |
|
63 String expected = data[i][1]; |
|
64 |
|
65 char[] text = data[i][0].toCharArray(); |
|
66 ns_old.shape(text, 0, text.length); |
|
67 String got = new String(text); |
|
68 |
|
69 if (!expected.equals(got)) { |
|
70 err = true; |
|
71 System.err.println("Error with traditional range."); |
|
72 System.err.println(" text = " + data[i][0]); |
|
73 System.err.println(" got = " + got); |
|
74 System.err.println(" expected = " + expected); |
|
75 } else { |
|
76 System.err.println("OK with traditional range."); |
|
77 System.err.println(" text = " + data[i][0]); |
|
78 System.err.println(" got = " + got); |
|
79 System.err.println(" expected = " + expected); |
|
80 } |
|
81 |
|
82 text = data[i][0].toCharArray(); |
|
83 ns_new.shape(text, 0, text.length); |
|
84 got = new String(text); |
|
85 |
|
86 if (!expected.equals(got)) { |
|
87 err = true; |
|
88 System.err.println("Error with new Enum range."); |
|
89 System.err.println(" text = " + data[i][0]); |
|
90 System.err.println(" got = " + got); |
|
91 System.err.println(" expected = " + expected); |
|
92 } else { |
|
93 System.err.println("OK with new Enum range."); |
|
94 System.err.println(" text = " + data[i][0]); |
|
95 System.err.println(" got = " + got); |
|
96 System.err.println(" expected = " + expected); |
|
97 } |
|
98 } |
|
99 |
|
100 if (err) { |
|
101 throw new RuntimeException("shape() returned unexpected value."); |
|
102 } |
|
103 } |
|
104 |
|
105 } |