Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/text/Bidi/Bug7042148.java
38813 views
/*1* Copyright (c) 2011, 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*/28import java.awt.font.*;29import java.text.*;30import java.util.*;3132public class Bug7042148 {3334private static boolean err = false;3536public static void main(String[] args) {37testDirection();3839if (err) {40throw new RuntimeException("Failed");41} else {42System.out.println("Passed.");43}44}4546private static void testDirection() {47Map attrLTR = new HashMap();48attrLTR.put(TextAttribute.RUN_DIRECTION,49TextAttribute.RUN_DIRECTION_LTR);50Map attrRTL = new HashMap();51attrRTL.put(TextAttribute.RUN_DIRECTION,52TextAttribute.RUN_DIRECTION_RTL);5354String str1 = "A\u05e0";55String str2 = "\u05e0B";5657test(str1, attrLTR, Bidi.DIRECTION_LEFT_TO_RIGHT);58test(str1, attrRTL, Bidi.DIRECTION_RIGHT_TO_LEFT);59test(str2, attrLTR, Bidi.DIRECTION_LEFT_TO_RIGHT);60test(str2, attrRTL, Bidi.DIRECTION_RIGHT_TO_LEFT);61}6263private static void test(String text, Map attr, int dirFlag) {64boolean expected = (dirFlag == Bidi.DIRECTION_LEFT_TO_RIGHT);6566Bidi bidi = new Bidi(text, dirFlag);67boolean got = bidi.baseIsLeftToRight();68if (got != expected) {69err = true;70System.err.println("wrong Bidi(String, int).baseIsLeftToRight() value: " +71"\n\ttext=" + text +72"\n\tExpected=" + expected +73"\n\tGot=" + got);74}7576AttributedString as = new AttributedString(text, attr);77AttributedCharacterIterator itr = as.getIterator();78itr.last();79itr.next();80bidi = new Bidi(itr);81got = bidi.baseIsLeftToRight();82if (got != expected) {83err = true;84System.err.println("Wrong Bidi(AttributedCharacterIterator).baseIsLeftToRight() value: " +85"\n\ttext=" + text +86"\n\tExpected=" + expected +87"\n\tGot=" + got);88}89}9091}929394