Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/text/Bidi/BidiEmbeddingTest.java
38813 views
1
/*
2
* Copyright (c) 2008, 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 4396492 4396496 4778510 6850113
27
* @summary verify that the embedding values processed by the bidi code use negative values to
28
* indicate overrides, rather than using bit 7. Also tests Bidi without loading awt classes to
29
* confirm that Bidi can be used without awt. Verify that embedding level 0 is properly mapped
30
* to the base embedding level.
31
*/
32
33
import java.awt.Color;
34
import java.awt.Frame;
35
import java.awt.font.TextAttribute;
36
import java.text.AttributedString;
37
import java.text.Bidi;
38
39
public class BidiEmbeddingTest {
40
public static void main(String[] args) {
41
// to regress embedding test against old fix, call with an arg. A window will pop
42
// up causing awt lib to be loaded so the vm won't die with the unsatisfied link error.
43
if (args.length > 0) {
44
Frame f = new Frame();
45
f.setSize(300, 300);
46
f.setBackground(Color.white);
47
f.show();
48
}
49
50
test1();
51
test2();
52
}
53
54
static void test1() {
55
String target = "BACK WARDS";
56
String str = "If this text is >" + target + "< the test passed.";
57
int start = str.indexOf(target);
58
int limit = start + target.length();
59
60
System.out.println("start: " + start + " limit: " + limit);
61
62
AttributedString astr = new AttributedString(str);
63
astr.addAttribute(TextAttribute.BIDI_EMBEDDING,
64
new Integer(-1),
65
start,
66
limit);
67
68
Bidi bidi = new Bidi(astr.getIterator());
69
70
for (int i = 0; i < bidi.getRunCount(); ++i) {
71
System.out.println("run " + i +
72
" from " + bidi.getRunStart(i) +
73
" to " + bidi.getRunLimit(i) +
74
" at level " + bidi.getRunLevel(i));
75
}
76
77
System.out.println(bidi);
78
79
byte[] embs = new byte[str.length() + 3];
80
for (int i = start + 1; i < limit + 1; ++i) {
81
embs[i] = -1;
82
}
83
84
Bidi bidi2 = new Bidi(str.toCharArray(), 0, embs, 1, str.length(), Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
85
for (int i = 0; i < bidi2.getRunCount(); ++i) {
86
System.out.println("run " + i +
87
" from " + bidi2.getRunStart(i) +
88
" to " + bidi2.getRunLimit(i) +
89
" at level " + bidi2.getRunLevel(i));
90
}
91
92
System.out.println(bidi2 + "\n");
93
94
if (bidi.getRunCount() != 3 || bidi2.getRunCount() != 3) {
95
throw new Error("Bidi run count incorrect");
96
} else {
97
System.out.println("test1() passed.\n");
98
}
99
}
100
101
// make sure BIDI_EMBEDDING values of 0 are mapped to base run direction, instead of flagging an error.
102
static void test2() {
103
String target = "BACK WARDS";
104
String str = "If this text is >" + target + "< the test passed.";
105
int length = str.length();
106
int start = str.indexOf(target);
107
int limit = start + target.length();
108
109
System.out.println("start: " + start + " limit: " + limit);
110
111
AttributedString astr = new AttributedString(str);
112
astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
113
114
astr.addAttribute(TextAttribute.BIDI_EMBEDDING,
115
new Integer(-3),
116
start,
117
limit);
118
119
Bidi bidi = new Bidi(astr.getIterator());
120
121
for (int i = 0; i < bidi.getRunCount(); ++i) {
122
System.out.println("run " + i +
123
" from " + bidi.getRunStart(i) +
124
" to " + bidi.getRunLimit(i) +
125
" at level " + bidi.getRunLevel(i));
126
}
127
128
System.out.println(bidi + "\n");
129
130
if (bidi.getRunCount() != 6) { // runs of spaces and angles at embedding bound,s and final period, each get level 1
131
throw new Error("Bidi embedding processing failed");
132
} else {
133
System.out.println("test2() passed.\n");
134
}
135
}
136
}
137
138