1 /* 2 * Copyright (c) 2010, 2015, 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 6842557 6943963 6959267 8032446 27 * @summary confirm that shaping works as expected. (Mainly for new characters which were added in Unicode 5 and 6) 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 37 private static boolean err = false; 38 39 public static void main(String[] args) { 40 test6842557(); 41 test6943963(); 42 test6903266(); 43 test8032446(); 44 45 if (err) { 46 throw new RuntimeException("shape() returned unexpected value."); 47 } 48 } 49 50 private static void test6842557() { 51 NumericShaper ns_old = getContextualShaper(ARABIC | TAMIL | ETHIOPIC, 52 EUROPEAN); 53 NumericShaper ns_new = getContextualShaper(EnumSet.of( 54 Range.ARABIC, Range.TAMIL, Range.ETHIOPIC), 55 Range.EUROPEAN); 56 57 String[][] data = { 58 // Arabic "October 10" 59 {"\u0623\u0643\u062a\u0648\u0628\u0631 10", 60 "\u0623\u0643\u062a\u0648\u0628\u0631 \u0661\u0660"}, 61 62 // Tamil "Year 2009" 63 {"\u0b86\u0ba3\u0bcd\u0b9f\u0bc1 2009", 64 "\u0b86\u0ba3\u0bcd\u0b9f\u0bc1 \u0be8\u0be6\u0be6\u0bef"}, 65 // "\u0be800\u0bef is returned by pre-JDK7 because Tamil zero was not 66 // included in Unicode 4.0.0. 67 68 // Ethiopic "Syllable<HA> 2009" 69 {"\u1200 2009", 70 "\u1200 \u136a00\u1371"}, 71 // Ethiopic zero doesn't exist even in Unicode 5.1.0. 72 }; 73 74 for (int i = 0; i < data.length; i++) { 75 checkResult("ARABIC | TAMIL | ETHIOPIC", 76 ns_old, data[i][0], data[i][1]); 77 78 checkResult("Range.ARABIC, Range.TAMIL, Range.ETHIOPIC", 79 ns_new, data[i][0], data[i][1]); 80 } 81 } 82 83 private static void test6943963() { 84 // Needed to reproduce this bug. 85 NumericShaper ns_dummy = getContextualShaper(ARABIC | TAMIL | ETHIOPIC, 86 EUROPEAN); 87 char[] c = "\u1200 1".toCharArray(); 88 ns_dummy.shape(c, 0, c.length); 89 90 91 String given = "\u0627\u0628 456"; 92 String expected_ARABIC = "\u0627\u0628 \u0664\u0665\u0666"; 93 String expected_EASTERN_ARABIC = "\u0627\u0628 \u06f4\u06f5\u06f6"; 94 95 NumericShaper ns = getContextualShaper(ARABIC); 96 checkResult("ARABIC", ns, given, expected_ARABIC); 97 98 ns = getContextualShaper(EnumSet.of(Range.ARABIC)); 99 checkResult("Range.ARABIC", ns, given, expected_ARABIC); 100 101 ns = getContextualShaper(EASTERN_ARABIC); 102 checkResult("EASTERN_ARABIC", ns, given, expected_EASTERN_ARABIC); 103 104 ns = getContextualShaper(EnumSet.of(Range.EASTERN_ARABIC)); 105 checkResult("Range.EASTERN_ARABIC", ns, given, expected_EASTERN_ARABIC); 106 107 ns = getContextualShaper(ARABIC | EASTERN_ARABIC); 108 checkResult("ARABIC | EASTERN_ARABIC", ns, given, expected_EASTERN_ARABIC); 109 110 ns = getContextualShaper(EnumSet.of(Range.ARABIC, Range.EASTERN_ARABIC)); 111 checkResult("Range.ARABIC, Range.EASTERN_ARABIC", ns, given, expected_EASTERN_ARABIC); 112 } 113 114 private static void test6903266() { 115 NumericShaper ns = getContextualShaper(EnumSet.of(Range.TAI_THAM_HORA)); 116 String given = "\u1a20 012"; 117 String expected = "\u1a20 \u1a80\u1a81\u1a82"; 118 checkResult("Range.TAI_THAM_HORA", ns, given, expected); 119 120 ns = getContextualShaper(EnumSet.of(Range.TAI_THAM_HORA, 121 Range.TAI_THAM_THAM)); 122 given = "\u1a20 012"; 123 expected = "\u1a20 \u1a90\u1a91\u1a92"; // Tham digits are prioritized. 124 checkResult("Range.TAI_THAM_HORA, Range.TAI_THAM_THAM", ns, given, expected); 125 126 ns = getContextualShaper(EnumSet.of(Range.JAVANESE)); 127 given = "\ua984 012"; 128 expected = "\ua984 \ua9d0\ua9d1\ua9d2"; 129 checkResult("Range.JAVANESE", ns, given, expected); 130 131 ns = getContextualShaper(EnumSet.of(Range.TAI_THAM_THAM)); 132 given = "\u1a20 012"; 133 expected = "\u1a20 \u1a90\u1a91\u1a92"; 134 checkResult("Range.TAI_THAM_THAM", ns, given, expected); 135 136 ns = getContextualShaper(EnumSet.of(Range.MEETEI_MAYEK)); 137 given = "\uabc0 012"; 138 expected = "\uabc0 \uabf0\uabf1\uabf2"; 139 checkResult("Range.MEETEI_MAYEK", ns, given, expected); 140 } 141 142 private static void test8032446() { 143 NumericShaper ns = getContextualShaper(EnumSet.of(Range.SINHALA)); 144 String given = "\u0d85 012"; 145 String expected = "\u0d85 \u0de6\u0de7\u0de8"; 146 checkResult("Range.SINHALA", ns, given, expected); 147 148 ns = getContextualShaper(EnumSet.of(Range.MYANMAR_TAI_LAING)); 149 given = "\ua9e2 012"; 150 expected = "\ua9e2 \ua9f0\ua9f1\ua9f2"; 151 checkResult("Range.MYANMAR_TAI_LAING", ns, given, expected); 152 } 153 154 private static void checkResult(String ranges, NumericShaper ns, 155 String given, String expected) { 156 char[] text = given.toCharArray(); 157 ns.shape(text, 0, text.length); 158 String got = new String(text); 159 160 if (!expected.equals(got)) { 161 err = true; 162 System.err.println("Error with range(s) <" + ranges + ">."); 163 System.err.println(" text = " + given); 164 System.err.println(" got = " + got); 165 System.err.println(" expected = " + expected); 166 } else { 167 System.out.println("OK with range(s) <" + ranges + ">."); 168 System.out.println(" text = " + given); 169 System.out.println(" got = " + got); 170 System.out.println(" expected = " + expected); 171 } 172 } 173 174 }