Path: blob/master/test/jdk/java/text/Bidi/Bug7042148.java
41149 views
/*1* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 704214826* @summary verify that Bidi.baseIsLeftToRight() returns the correct value even if an incorrect position is set in the given AttributedCharacterIterator.27* @modules java.desktop28*/29import java.awt.font.*;30import java.text.*;31import java.util.*;3233public class Bug7042148 {3435private static boolean err = false;3637public static void main(String[] args) {38testDirection();3940if (err) {41throw new RuntimeException("Failed");42} else {43System.out.println("Passed.");44}45}4647private static void testDirection() {48Map attrLTR = new HashMap();49attrLTR.put(TextAttribute.RUN_DIRECTION,50TextAttribute.RUN_DIRECTION_LTR);51Map attrRTL = new HashMap();52attrRTL.put(TextAttribute.RUN_DIRECTION,53TextAttribute.RUN_DIRECTION_RTL);5455String str1 = "A\u05e0";56String str2 = "\u05e0B";5758test(str1, attrLTR, Bidi.DIRECTION_LEFT_TO_RIGHT);59test(str1, attrRTL, Bidi.DIRECTION_RIGHT_TO_LEFT);60test(str2, attrLTR, Bidi.DIRECTION_LEFT_TO_RIGHT);61test(str2, attrRTL, Bidi.DIRECTION_RIGHT_TO_LEFT);62}6364private static void test(String text, Map attr, int dirFlag) {65boolean expected = (dirFlag == Bidi.DIRECTION_LEFT_TO_RIGHT);6667Bidi bidi = new Bidi(text, dirFlag);68boolean got = bidi.baseIsLeftToRight();69if (got != expected) {70err = true;71System.err.println("wrong Bidi(String, int).baseIsLeftToRight() value: " +72"\n\ttext=" + text +73"\n\tExpected=" + expected +74"\n\tGot=" + got);75}7677AttributedString as = new AttributedString(text, attr);78AttributedCharacterIterator itr = as.getIterator();79itr.last();80itr.next();81bidi = new Bidi(itr);82got = bidi.baseIsLeftToRight();83if (got != expected) {84err = true;85System.err.println("Wrong Bidi(AttributedCharacterIterator).baseIsLeftToRight() value: " +86"\n\ttext=" + text +87"\n\tExpected=" + expected +88"\n\tGot=" + got);89}90}9192}939495