1 /*
2 * Copyright (c) 2011, 2016, 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 8038092
27 * @summary verify that Bidi.toString() returns the corect result.
28 * The second run is intended to test lazy SharedSectets init for 8038092
29 * @modules java.desktop
30 * @run main Bug7051769
31 * @run main/othervm -DpreloadBidi=true Bug7051769
32 */
33 import java.awt.font.*;
34 import java.text.*;
35 import java.util.*;
36
37 public class Bug7051769 {
38
39 static {
40 if (System.getProperty("preloadBidi", "").equals("true")) {
41 // Make sure the SharedSecret is lazily initialized correctly
42 try {
43 Class.forName("sun.text.bidi.BidiBase");
44 System.out.println("BidiBase class has been pre-loaded.");
45 } catch (ClassNotFoundException e) {
46 System.out.println("BidiBase class could not be pre-loaded.");
47 }
48 }
49 }
50
51 private static boolean err = false;
52
53 public static void main(String[] args) {
54 testNumericShaping();
55
56 if (err) {
57 throw new RuntimeException("Failed");
58 } else {
59 System.out.println("Passed.");
60 }
61 }
62
63 private static void testNumericShaping() {
64 Map attrNS = new HashMap();
65 attrNS.put(TextAttribute.NUMERIC_SHAPING,
66 NumericShaper.getContextualShaper(NumericShaper.ARABIC));
67 attrNS.put(TextAttribute.RUN_DIRECTION,
68 TextAttribute.RUN_DIRECTION_RTL);
69
70 String text = "\u0623\u0643\u062a\u0648\u0628\u0631 10";
71 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]]";
72
73 AttributedString as = new AttributedString(text, attrNS);
74 AttributedCharacterIterator itr = as.getIterator();
75 itr.last();
76 itr.next();
77 Bidi bidi = new Bidi(itr);
78 String got = bidi.toString();
79
80 if (!got.equals(expected)) {
81 err = true;
82 System.err.println("Wrong toString() output: " +
83 "\n\tExpected=" + expected +
84 "\n\tGot=" + got);
85 }
86 }
87
88 }
|
1 /*
2 * Copyright (c) 2011, 2020, 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 8038092 8174270
27 * @summary verify that Bidi.toString() returns the corect result.
28 * The second run is intended to test lazy SharedSectets init for 8038092
29 * @modules java.desktop
30 * @run main Bug7051769
31 * @run main/othervm -DpreloadBidi=true Bug7051769
32 */
33 import java.awt.font.*;
34 import java.text.*;
35 import java.util.*;
36
37 public class Bug7051769 {
38
39 static {
40 if (System.getProperty("preloadBidi", "").equals("true")) {
41 // Make sure the SharedSecret is lazily initialized correctly
42 try {
43 Class.forName("jdk.internal.icu.text.BidiBase");
44 System.out.println("BidiBase class has been pre-loaded.");
45 } catch (ClassNotFoundException e) {
46 System.out.println("BidiBase class could not be pre-loaded.");
47 }
48 }
49 }
50
51 private static boolean err = false;
52
53 public static void main(String[] args) {
54 testNumericShaping();
55
56 if (err) {
57 throw new RuntimeException("Failed");
58 } else {
59 System.out.println("Passed.");
60 }
61 }
62
63 private static void testNumericShaping() {
64 Map attrNS = new HashMap();
65 attrNS.put(TextAttribute.NUMERIC_SHAPING,
66 NumericShaper.getContextualShaper(NumericShaper.ARABIC));
67 attrNS.put(TextAttribute.RUN_DIRECTION,
68 TextAttribute.RUN_DIRECTION_RTL);
69
70 String text = "\u0623\u0643\u062a\u0648\u0628\u0631 10";
71 String 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]]";
72
73 AttributedString as = new AttributedString(text, attrNS);
74 AttributedCharacterIterator itr = as.getIterator();
75 itr.last();
76 itr.next();
77 Bidi bidi = new Bidi(itr);
78 String got = bidi.toString();
79
80 if (!got.equals(expected)) {
81 err = true;
82 System.err.println("Wrong toString() output: " +
83 "\n\tExpected=" + expected +
84 "\n\tGot=" + got);
85 }
86 }
87
88 }
|