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/Bug7042148.java
38813 views
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 7042148
27
* @summary verify that Bidi.baseIsLeftToRight() returns the correct value even if an incorrect position is set in the given AttributedCharacterIterator.
28
*/
29
import java.awt.font.*;
30
import java.text.*;
31
import java.util.*;
32
33
public class Bug7042148 {
34
35
private static boolean err = false;
36
37
public static void main(String[] args) {
38
testDirection();
39
40
if (err) {
41
throw new RuntimeException("Failed");
42
} else {
43
System.out.println("Passed.");
44
}
45
}
46
47
private static void testDirection() {
48
Map attrLTR = new HashMap();
49
attrLTR.put(TextAttribute.RUN_DIRECTION,
50
TextAttribute.RUN_DIRECTION_LTR);
51
Map attrRTL = new HashMap();
52
attrRTL.put(TextAttribute.RUN_DIRECTION,
53
TextAttribute.RUN_DIRECTION_RTL);
54
55
String str1 = "A\u05e0";
56
String str2 = "\u05e0B";
57
58
test(str1, attrLTR, Bidi.DIRECTION_LEFT_TO_RIGHT);
59
test(str1, attrRTL, Bidi.DIRECTION_RIGHT_TO_LEFT);
60
test(str2, attrLTR, Bidi.DIRECTION_LEFT_TO_RIGHT);
61
test(str2, attrRTL, Bidi.DIRECTION_RIGHT_TO_LEFT);
62
}
63
64
private static void test(String text, Map attr, int dirFlag) {
65
boolean expected = (dirFlag == Bidi.DIRECTION_LEFT_TO_RIGHT);
66
67
Bidi bidi = new Bidi(text, dirFlag);
68
boolean got = bidi.baseIsLeftToRight();
69
if (got != expected) {
70
err = true;
71
System.err.println("wrong Bidi(String, int).baseIsLeftToRight() value: " +
72
"\n\ttext=" + text +
73
"\n\tExpected=" + expected +
74
"\n\tGot=" + got);
75
}
76
77
AttributedString as = new AttributedString(text, attr);
78
AttributedCharacterIterator itr = as.getIterator();
79
itr.last();
80
itr.next();
81
bidi = new Bidi(itr);
82
got = bidi.baseIsLeftToRight();
83
if (got != expected) {
84
err = true;
85
System.err.println("Wrong Bidi(AttributedCharacterIterator).baseIsLeftToRight() value: " +
86
"\n\ttext=" + text +
87
"\n\tExpected=" + expected +
88
"\n\tGot=" + got);
89
}
90
}
91
92
}
93
94