author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 40679 | jdk/test/java/text/Bidi/Bug7051769.java@5378433ac23f |
permissions | -rw-r--r-- |
10090 | 1 |
/* |
40679
5378433ac23f
8164859: Fix module dependences in java/text tests
shurailine
parents:
25385
diff
changeset
|
2 |
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. |
10090 | 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 |
|
25385
2c53e38b77aa
8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents:
10090
diff
changeset
|
26 |
* @bug 7051769 8038092 |
10090 | 27 |
* @summary verify that Bidi.toString() returns the corect result. |
25385
2c53e38b77aa
8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents:
10090
diff
changeset
|
28 |
* The second run is intended to test lazy SharedSectets init for 8038092 |
40679
5378433ac23f
8164859: Fix module dependences in java/text tests
shurailine
parents:
25385
diff
changeset
|
29 |
* @modules java.desktop |
25385
2c53e38b77aa
8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents:
10090
diff
changeset
|
30 |
* @run main Bug7051769 |
2c53e38b77aa
8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents:
10090
diff
changeset
|
31 |
* @run main/othervm -DpreloadBidi=true Bug7051769 |
10090 | 32 |
*/ |
33 |
import java.awt.font.*; |
|
34 |
import java.text.*; |
|
35 |
import java.util.*; |
|
36 |
||
37 |
public class Bug7051769 { |
|
38 |
||
25385
2c53e38b77aa
8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents:
10090
diff
changeset
|
39 |
static { |
2c53e38b77aa
8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents:
10090
diff
changeset
|
40 |
if (System.getProperty("preloadBidi", "").equals("true")) { |
2c53e38b77aa
8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents:
10090
diff
changeset
|
41 |
// Make sure the SharedSecret is lazily initialized correctly |
2c53e38b77aa
8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents:
10090
diff
changeset
|
42 |
try { |
2c53e38b77aa
8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents:
10090
diff
changeset
|
43 |
Class.forName("sun.text.bidi.BidiBase"); |
2c53e38b77aa
8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents:
10090
diff
changeset
|
44 |
System.out.println("BidiBase class has been pre-loaded."); |
2c53e38b77aa
8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents:
10090
diff
changeset
|
45 |
} catch (ClassNotFoundException e) { |
2c53e38b77aa
8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents:
10090
diff
changeset
|
46 |
System.out.println("BidiBase class could not be pre-loaded."); |
2c53e38b77aa
8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents:
10090
diff
changeset
|
47 |
} |
2c53e38b77aa
8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents:
10090
diff
changeset
|
48 |
} |
2c53e38b77aa
8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents:
10090
diff
changeset
|
49 |
} |
2c53e38b77aa
8038092: Re-examine Bidi reflective dependency on java.awt.font
naoto
parents:
10090
diff
changeset
|
50 |
|
10090 | 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 |
} |