Path: blob/master/test/jdk/java/text/Bidi/Bug7051769.java
41152 views
/*1* Copyright (c) 2011, 2020, 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 7051769 8038092 817427026* @summary verify that Bidi.toString() returns the corect result.27* The second run is intended to test lazy SharedSectets init for 803809228* @modules java.desktop29* @run main Bug705176930* @run main/othervm -DpreloadBidi=true Bug705176931*/32import java.awt.font.*;33import java.text.*;34import java.util.*;3536public class Bug7051769 {3738static {39if (System.getProperty("preloadBidi", "").equals("true")) {40// Make sure the SharedSecret is lazily initialized correctly41try {42Class.forName("jdk.internal.icu.text.BidiBase");43System.out.println("BidiBase class has been pre-loaded.");44} catch (ClassNotFoundException e) {45System.out.println("BidiBase class could not be pre-loaded.");46}47}48}4950private static boolean err = false;5152public static void main(String[] args) {53testNumericShaping();5455if (err) {56throw new RuntimeException("Failed");57} else {58System.out.println("Passed.");59}60}6162private static void testNumericShaping() {63Map attrNS = new HashMap();64attrNS.put(TextAttribute.NUMERIC_SHAPING,65NumericShaper.getContextualShaper(NumericShaper.ARABIC));66attrNS.put(TextAttribute.RUN_DIRECTION,67TextAttribute.RUN_DIRECTION_RTL);6869String text = "\u0623\u0643\u062a\u0648\u0628\u0631 10";70String expected = "jdk.internal.icu.text.BidiBase[dir: 2 baselevel: 1 length: 9 runs: [1 1 1 1 1 1 1 2 2] text: [0x623 0x643 0x62a 0x648 0x628 0x631 0x20 0x661 0x660]]";7172AttributedString as = new AttributedString(text, attrNS);73AttributedCharacterIterator itr = as.getIterator();74itr.last();75itr.next();76Bidi bidi = new Bidi(itr);77String got = bidi.toString();7879if (!got.equals(expected)) {80err = true;81System.err.println("Wrong toString() output: " +82"\n\tExpected=" + expected +83"\n\tGot=" + got);84}85}8687}888990