< prev index next >

jdk/test/java/awt/font/NumericShaper/ShapingTest.java

Print this page


   1 /*
   2  * Copyright (c) 2010, 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
  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 
  44         if (err) {
  45             throw new RuntimeException("shape() returned unexpected value.");
  46         }
  47     }
  48 
  49     private static void test6842557() {
  50         NumericShaper ns_old = getContextualShaper(ARABIC | TAMIL | ETHIOPIC,
  51                                    EUROPEAN);
  52         NumericShaper ns_new = getContextualShaper(EnumSet.of(
  53                                    Range.ARABIC, Range.TAMIL, Range.ETHIOPIC),
  54                                    Range.EUROPEAN);
  55 
  56         String[][] data = {
  57            // Arabic "October 10"
  58           {"\u0623\u0643\u062a\u0648\u0628\u0631 10",
  59            "\u0623\u0643\u062a\u0648\u0628\u0631 \u0661\u0660"},
  60 
  61            // Tamil "Year 2009"
  62           {"\u0b86\u0ba3\u0bcd\u0b9f\u0bc1 2009",


 121         given = "\u1a20 012";
 122         expected = "\u1a20 \u1a90\u1a91\u1a92"; // Tham digits are prioritized.
 123         checkResult("Range.TAI_THAM_HORA, Range.TAI_THAM_THAM", ns, given, expected);
 124 
 125         ns = getContextualShaper(EnumSet.of(Range.JAVANESE));
 126         given = "\ua984 012";
 127         expected = "\ua984 \ua9d0\ua9d1\ua9d2";
 128         checkResult("Range.JAVANESE", ns, given, expected);
 129 
 130         ns = getContextualShaper(EnumSet.of(Range.TAI_THAM_THAM));
 131         given = "\u1a20 012";
 132         expected = "\u1a20 \u1a90\u1a91\u1a92";
 133         checkResult("Range.TAI_THAM_THAM", ns, given, expected);
 134 
 135         ns = getContextualShaper(EnumSet.of(Range.MEETEI_MAYEK));
 136         given = "\uabc0 012";
 137         expected = "\uabc0 \uabf0\uabf1\uabf2";
 138         checkResult("Range.MEETEI_MAYEK", ns, given, expected);
 139     }
 140 












 141     private static void checkResult(String ranges, NumericShaper ns,
 142                                     String given, String expected) {
 143         char[] text = given.toCharArray();
 144         ns.shape(text, 0, text.length);
 145         String got = new String(text);
 146 
 147         if (!expected.equals(got)) {
 148             err = true;
 149             System.err.println("Error with range(s) <" + ranges + ">.");
 150             System.err.println("  text     = " + given);
 151             System.err.println("  got      = " + got);
 152             System.err.println("  expected = " + expected);
 153         } else {
 154             System.out.println("OK with range(s) <" + ranges + ">.");
 155             System.out.println("  text     = " + given);
 156             System.out.println("  got      = " + got);
 157             System.out.println("  expected = " + expected);
 158         }
 159     }
 160 
   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",


 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 
< prev index next >