1 /* 2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 7051769 27 * @summary verify that Bidi.toString() returns the corect result. 28 */ 29 import java.awt.font.*; 30 import java.text.*; 31 import java.util.*; 32 33 public class Bug7051769 { 34 35 private static boolean err = false; 36 37 public static void main(String[] args) { 38 testNumericShaping(); 39 40 if (err) { 41 throw new RuntimeException("Failed"); 42 } else { 43 System.out.println("Passed."); 44 } 45 } 46 47 private static void testNumericShaping() { 48 Map attrNS = new HashMap(); 49 attrNS.put(TextAttribute.NUMERIC_SHAPING, 50 NumericShaper.getContextualShaper(NumericShaper.ARABIC)); 51 attrNS.put(TextAttribute.RUN_DIRECTION, 52 TextAttribute.RUN_DIRECTION_RTL); 53 54 String text = "\u0623\u0643\u062a\u0648\u0628\u0631 10"; 55 String expected = "sun.text.bidi.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]]"; 56 57 AttributedString as = new AttributedString(text, attrNS); 58 AttributedCharacterIterator itr = as.getIterator(); 59 itr.last(); 60 itr.next(); 61 Bidi bidi = new Bidi(itr); 62 String got = bidi.toString(); 63 64 if (!got.equals(expected)) { 65 err = true; 66 System.err.println("Wrong toString() output: " + 67 "\n\tExpected=" + expected + 68 "\n\tGot=" + got); 69 } 70 } 71 72 }