4396N/A/*
4396N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4396N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4396N/A *
4396N/A * This code is free software; you can redistribute it and/or modify it
4396N/A * under the terms of the GNU General Public License version 2 only, as
4396N/A * published by the Free Software Foundation.
4396N/A *
4396N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4396N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4396N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4396N/A * version 2 for more details (a copy is included in the LICENSE file that
4396N/A * accompanied this code).
4396N/A *
4396N/A * You should have received a copy of the GNU General Public License version
4396N/A * 2 along with this work; if not, write to the Free Software Foundation,
4396N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4396N/A *
4396N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4396N/A * or visit www.oracle.com if you need additional information or have any
4396N/A * questions.
4396N/A */
4396N/A
4396N/A/*
4396N/A * @test
4396N/A * @bug 7042148
4396N/A * @summary verify that Bidi.baseIsLeftToRight() returns the correct value even if an incorrect position is set in the given AttributedCharacterIterator.
4396N/A */
4396N/Aimport java.awt.font.*;
4396N/Aimport java.text.*;
4396N/Aimport java.util.*;
4396N/A
4396N/Apublic class Bug7042148 {
4396N/A
4396N/A private static boolean err = false;
4396N/A
4396N/A public static void main(String[] args) {
4396N/A testDirection();
4396N/A
4396N/A if (err) {
4396N/A throw new RuntimeException("Failed");
4396N/A } else {
4396N/A System.out.println("Passed.");
4396N/A }
4396N/A }
4396N/A
4396N/A private static void testDirection() {
4396N/A Map attrLTR = new HashMap();
4396N/A attrLTR.put(TextAttribute.RUN_DIRECTION,
4396N/A TextAttribute.RUN_DIRECTION_LTR);
4396N/A Map attrRTL = new HashMap();
4396N/A attrRTL.put(TextAttribute.RUN_DIRECTION,
4396N/A TextAttribute.RUN_DIRECTION_RTL);
4396N/A
4396N/A String str1 = "A\u05e0";
4396N/A String str2 = "\u05e0B";
4396N/A
4396N/A test(str1, attrLTR, Bidi.DIRECTION_LEFT_TO_RIGHT);
4396N/A test(str1, attrRTL, Bidi.DIRECTION_RIGHT_TO_LEFT);
4396N/A test(str2, attrLTR, Bidi.DIRECTION_LEFT_TO_RIGHT);
4396N/A test(str2, attrRTL, Bidi.DIRECTION_RIGHT_TO_LEFT);
4396N/A }
4396N/A
4396N/A private static void test(String text, Map attr, int dirFlag) {
4396N/A boolean expected = (dirFlag == Bidi.DIRECTION_LEFT_TO_RIGHT);
4396N/A
4396N/A Bidi bidi = new Bidi(text, dirFlag);
4396N/A boolean got = bidi.baseIsLeftToRight();
4396N/A if (got != expected) {
4396N/A err = true;
4396N/A System.err.println("wrong Bidi(String, int).baseIsLeftToRight() value: " +
4396N/A "\n\ttext=" + text +
4396N/A "\n\tExpected=" + expected +
4396N/A "\n\tGot=" + got);
4396N/A }
4396N/A
4396N/A AttributedString as = new AttributedString(text, attr);
4396N/A AttributedCharacterIterator itr = as.getIterator();
4396N/A itr.last();
4396N/A itr.next();
4396N/A bidi = new Bidi(itr);
4396N/A got = bidi.baseIsLeftToRight();
4396N/A if (got != expected) {
4396N/A err = true;
4396N/A System.err.println("Wrong Bidi(AttributedCharacterIterator).baseIsLeftToRight() value: " +
4396N/A "\n\ttext=" + text +
4396N/A "\n\tExpected=" + expected +
4396N/A "\n\tGot=" + got);
4396N/A }
4396N/A }
4396N/A
4396N/A}