aboutsummaryrefslogtreecommitdiff
path: root/test/java/awt/font
diff options
context:
space:
mode:
authorpeytoia <none@none>2009-11-12 18:59:19 +0900
committerpeytoia <none@none>2009-11-12 18:59:19 +0900
commita1192197b45914dce6b6f3cf1a6c81bca4d33209 (patch)
tree63af570bf58026cb7f6f71cffa80eed9eed2f18f /test/java/awt/font
parent6406d077d5ded7cc69de78cb00546aa91c1e7ec3 (diff)
6842557: NumericShaper needs to be updated for Unicode 5.1 support
6843181: NumericShaper is not thread-safe 6900137: Typo in API Doc for NumericShaper Reviewed-by: okutsu
Diffstat (limited to 'test/java/awt/font')
-rw-r--r--test/java/awt/font/NumericShaper/EqualsTest.java65
-rw-r--r--test/java/awt/font/NumericShaper/MTTest.java134
-rw-r--r--test/java/awt/font/NumericShaper/ShapingTest.java105
3 files changed, 304 insertions, 0 deletions
diff --git a/test/java/awt/font/NumericShaper/EqualsTest.java b/test/java/awt/font/NumericShaper/EqualsTest.java
new file mode 100644
index 000000000..b71bacf42
--- /dev/null
+++ b/test/java/awt/font/NumericShaper/EqualsTest.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6842557
+ * @summary confirm that an instance which is created with new Enum ranges is
+ * equivalent to another instance which is created with equivalent traditional
+ * ranges or the same Enum ranges.
+ */
+
+import java.awt.font.NumericShaper;
+import java.util.EnumSet;
+import static java.awt.font.NumericShaper.*;
+
+public class EqualsTest {
+ public static void main(String[] args) {
+ NumericShaper ns1 = getContextualShaper(ARABIC | TAMIL, TAMIL);
+ NumericShaper ns2 = getContextualShaper(
+ EnumSet.of(Range.ARABIC, Range.TAMIL),
+ Range.TAMIL);
+ NumericShaper ns3 = getContextualShaper(
+ EnumSet.of(Range.ARABIC, Range.TAMIL),
+ Range.TAMIL);
+ NumericShaper ns4 = getContextualShaper(
+ EnumSet.of(Range.ARABIC, Range.TAMIL),
+ Range.ARABIC);
+
+ if (!ns1.equals(ns2)) {
+ throw new RuntimeException("ns1 != ns2: ns1=" + ns1 + ", ns2=" + ns2);
+ }
+ if (!ns2.equals(ns1)) {
+ throw new RuntimeException("ns2 != ns1: ns1=" + ns1 + ", ns2=" + ns2);
+ }
+ if (!ns2.equals(ns3)) {
+ throw new RuntimeException("ns2 != ns3: ns2=" + ns2 + ", ns3=" + ns3);
+ }
+ if (ns1.equals(ns4)) {
+ throw new RuntimeException("ns1 == ns4: ns1=" + ns1 + ", ns4=" + ns4);
+ }
+ if (ns2.equals(ns4)) {
+ throw new RuntimeException("ns2 == ns4: ns2=" + ns2 + ", ns4=" + ns4);
+ }
+ }
+}
diff --git a/test/java/awt/font/NumericShaper/MTTest.java b/test/java/awt/font/NumericShaper/MTTest.java
new file mode 100644
index 000000000..e2598c3c3
--- /dev/null
+++ b/test/java/awt/font/NumericShaper/MTTest.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6843181
+ * @summary Confirm that NumericShaper is thread-safe.
+ * @run main/timeout=300/othervm MTTest
+ */
+
+import java.awt.font.NumericShaper;
+import java.util.Arrays;
+import java.util.EnumSet;
+import static java.awt.font.NumericShaper.*;
+
+public class MTTest {
+ static volatile boolean runrun = true;
+ static volatile boolean err = false;
+
+ final static String text = "-123 (English) 456.00 (Arabic) \u0641\u0642\u0643 -789 (Thai) \u0e01\u0e33 01.23";
+ static char[] t1, t2;
+ static NumericShaper ns1, ns2, ns3, ns4;
+
+ public static void main(String[] args) {
+ System.out.println(" original: " + text);
+ ns1 = getContextualShaper(EnumSet.of(Range.ARABIC), Range.ARABIC);
+ t1 = text.toCharArray();
+ ns1.shape(t1, 0, t1.length);
+ System.out.println("expected t1: " + String.valueOf(t1));
+
+ ns2 = getContextualShaper(EnumSet.of(Range.THAI), Range.THAI);
+ t2 = text.toCharArray();
+ ns2.shape(t2, 0, t2.length);
+ System.out.println("expected t2: " + String.valueOf(t2));
+
+ ns3 = getContextualShaper(ARABIC, ARABIC);
+ ns4 = getContextualShaper(THAI, THAI);
+
+ Thread th1 = new Thread(new Work(ns1, t1));
+ Thread th2 = new Thread(new Work(ns2, t2));
+ Thread th3 = new Thread(new Work(ns1, t1));
+ Thread th4 = new Thread(new Work(ns2, t2));
+ Thread th5 = new Thread(new Work(ns3, t1));
+ Thread th6 = new Thread(new Work(ns4, t2));
+ Thread th7 = new Thread(new Work(ns3, t1));
+ Thread th8 = new Thread(new Work(ns4, t2));
+
+ th1.start();
+ th2.start();
+ th3.start();
+ th4.start();
+ th5.start();
+ th6.start();
+ th7.start();
+ th8.start();
+
+ try {
+ for (int i = 0; runrun && i < 180; i++) {
+ Thread.sleep(1000); // 1 seconds
+ }
+ runrun = false;
+ th1.join();
+ th2.join();
+ th3.join();
+ th4.join();
+ th5.join();
+ th6.join();
+ th7.join();
+ th8.join();
+ }
+ catch (InterruptedException e) {
+ }
+
+ if (err) {
+ throw new RuntimeException("Thread-safe test failed.");
+ }
+ }
+
+ private static class Work implements Runnable {
+ NumericShaper ns;
+ char[] expectedText;
+
+ Work(NumericShaper ns, char[] expectedText) {
+ this.ns = ns;
+ this.expectedText = expectedText;
+
+ }
+
+ public void run() {
+ int count = 0;
+ while (runrun) {
+ char[] t = text.toCharArray();
+ try {
+ count++;
+ ns.shape(t, 0, t.length);
+ } catch (Exception e) {
+ System.err.println("Error: Unexpected exception: " + e);
+ runrun = false;
+ err = true;
+ return;
+ }
+ if (!Arrays.equals(t, expectedText)) {
+ System.err.println("Error: shape() returned unexpected value: ");
+ System.err.println("count = " + count);
+ System.err.println(" expected: " + String.valueOf(expectedText));
+ System.err.println(" got: " + String.valueOf(t));
+ runrun = false;
+ err = true;
+ return;
+ }
+ }
+ }
+ }
+}
diff --git a/test/java/awt/font/NumericShaper/ShapingTest.java b/test/java/awt/font/NumericShaper/ShapingTest.java
new file mode 100644
index 000000000..047e67f12
--- /dev/null
+++ b/test/java/awt/font/NumericShaper/ShapingTest.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6842557
+ * @summary confirm that shaping works as expected. (Mainly for new characters which were added in Unicode 5)
+ * used where appropriate.
+ */
+
+import java.awt.font.NumericShaper;
+import java.util.EnumSet;
+import static java.awt.font.NumericShaper.*;
+
+public class ShapingTest {
+ public static void main(String[] args) {
+ NumericShaper ns_old = getContextualShaper(ARABIC | TAMIL | ETHIOPIC,
+ EUROPEAN);
+ NumericShaper ns_new = getContextualShaper(EnumSet.of(
+ Range.ARABIC, Range.TAMIL, Range.ETHIOPIC),
+ Range.EUROPEAN);
+
+ boolean err = false;
+
+ String[][] data = {
+ // Arabic "October 10"
+ {"\u0623\u0643\u062a\u0648\u0628\u0631 10",
+ "\u0623\u0643\u062a\u0648\u0628\u0631 \u0661\u0660"},
+
+ // Tamil "Year 2009"
+ {"\u0b86\u0ba3\u0bcd\u0b9f\u0bc1 2009",
+ "\u0b86\u0ba3\u0bcd\u0b9f\u0bc1 \u0be8\u0be6\u0be6\u0bef"},
+ // "\u0be800\u0bef is returned by pre-JDK7 because Tamil zero was not
+ // included in Unicode 4.0.0.
+
+ // Ethiopic "Syllable<HA> 2009"
+ {"\u1200 2009",
+ "\u1200 \u136a00\u1371"},
+ // Ethiopic zero doesn't exist even in Unicode 5.1.0.
+ };
+
+ for (int i = 0; i < data.length; i++) {
+ String expected = data[i][1];
+
+ char[] text = data[i][0].toCharArray();
+ ns_old.shape(text, 0, text.length);
+ String got = new String(text);
+
+ if (!expected.equals(got)) {
+ err = true;
+ System.err.println("Error with traditional range.");
+ System.err.println(" text = " + data[i][0]);
+ System.err.println(" got = " + got);
+ System.err.println(" expected = " + expected);
+ } else {
+ System.err.println("OK with traditional range.");
+ System.err.println(" text = " + data[i][0]);
+ System.err.println(" got = " + got);
+ System.err.println(" expected = " + expected);
+ }
+
+ text = data[i][0].toCharArray();
+ ns_new.shape(text, 0, text.length);
+ got = new String(text);
+
+ if (!expected.equals(got)) {
+ err = true;
+ System.err.println("Error with new Enum range.");
+ System.err.println(" text = " + data[i][0]);
+ System.err.println(" got = " + got);
+ System.err.println(" expected = " + expected);
+ } else {
+ System.err.println("OK with new Enum range.");
+ System.err.println(" text = " + data[i][0]);
+ System.err.println(" got = " + got);
+ System.err.println(" expected = " + expected);
+ }
+ }
+
+ if (err) {
+ throw new RuntimeException("shape() returned unexpected value.");
+ }
+ }
+
+}