ShapingTest.java revision 1914
1914N/A/*
1914N/A * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved.
1914N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1914N/A *
1914N/A * This code is free software; you can redistribute it and/or modify it
1914N/A * under the terms of the GNU General Public License version 2 only, as
1914N/A * published by the Free Software Foundation.
1914N/A *
1914N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1914N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1914N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1914N/A * version 2 for more details (a copy is included in the LICENSE file that
1914N/A * accompanied this code).
1914N/A *
1914N/A * You should have received a copy of the GNU General Public License version
1914N/A * 2 along with this work; if not, write to the Free Software Foundation,
1914N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1914N/A *
1914N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
1914N/A * CA 95054 USA or visit www.sun.com if you need additional information or
1914N/A * have any questions.
1914N/A */
1914N/A
1914N/A/*
1914N/A * @test
1914N/A * @bug 6842557
1914N/A * @summary confirm that shaping works as expected. (Mainly for new characters which were added in Unicode 5)
1914N/A * used where appropriate.
1914N/A */
1914N/A
1914N/Aimport java.awt.font.NumericShaper;
1914N/Aimport java.util.EnumSet;
1914N/Aimport static java.awt.font.NumericShaper.*;
1914N/A
1914N/Apublic class ShapingTest {
1914N/A public static void main(String[] args) {
1914N/A NumericShaper ns_old = getContextualShaper(ARABIC | TAMIL | ETHIOPIC,
1914N/A EUROPEAN);
1914N/A NumericShaper ns_new = getContextualShaper(EnumSet.of(
1914N/A Range.ARABIC, Range.TAMIL, Range.ETHIOPIC),
1914N/A Range.EUROPEAN);
1914N/A
1914N/A boolean err = false;
1914N/A
1914N/A String[][] data = {
1914N/A // Arabic "October 10"
1914N/A {"\u0623\u0643\u062a\u0648\u0628\u0631 10",
1914N/A "\u0623\u0643\u062a\u0648\u0628\u0631 \u0661\u0660"},
1914N/A
1914N/A // Tamil "Year 2009"
1914N/A {"\u0b86\u0ba3\u0bcd\u0b9f\u0bc1 2009",
1914N/A "\u0b86\u0ba3\u0bcd\u0b9f\u0bc1 \u0be8\u0be6\u0be6\u0bef"},
1914N/A // "\u0be800\u0bef is returned by pre-JDK7 because Tamil zero was not
1914N/A // included in Unicode 4.0.0.
1914N/A
1914N/A // Ethiopic "Syllable<HA> 2009"
1914N/A {"\u1200 2009",
1914N/A "\u1200 \u136a00\u1371"},
1914N/A // Ethiopic zero doesn't exist even in Unicode 5.1.0.
1914N/A };
1914N/A
1914N/A for (int i = 0; i < data.length; i++) {
1914N/A String expected = data[i][1];
1914N/A
1914N/A char[] text = data[i][0].toCharArray();
1914N/A ns_old.shape(text, 0, text.length);
1914N/A String got = new String(text);
1914N/A
1914N/A if (!expected.equals(got)) {
1914N/A err = true;
1914N/A System.err.println("Error with traditional range.");
1914N/A System.err.println(" text = " + data[i][0]);
1914N/A System.err.println(" got = " + got);
1914N/A System.err.println(" expected = " + expected);
1914N/A } else {
1914N/A System.err.println("OK with traditional range.");
1914N/A System.err.println(" text = " + data[i][0]);
1914N/A System.err.println(" got = " + got);
1914N/A System.err.println(" expected = " + expected);
1914N/A }
1914N/A
1914N/A text = data[i][0].toCharArray();
1914N/A ns_new.shape(text, 0, text.length);
1914N/A got = new String(text);
1914N/A
1914N/A if (!expected.equals(got)) {
1914N/A err = true;
1914N/A System.err.println("Error with new Enum range.");
1914N/A System.err.println(" text = " + data[i][0]);
1914N/A System.err.println(" got = " + got);
1914N/A System.err.println(" expected = " + expected);
1914N/A } else {
1914N/A System.err.println("OK with new Enum range.");
1914N/A System.err.println(" text = " + data[i][0]);
1914N/A System.err.println(" got = " + got);
1914N/A System.err.println(" expected = " + expected);
1914N/A }
1914N/A }
1914N/A
1914N/A if (err) {
1914N/A throw new RuntimeException("shape() returned unexpected value.");
1914N/A }
1914N/A }
1914N/A
1914N/A}