author | peytoia |
Sat, 13 Jun 2009 06:43:54 +0900 | |
changeset 2956 | 931f209e57a9 |
parent 1834 | 6eefd0d6804d |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
1834 | 1 |
/* |
2 |
* Copyright (c) 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 |
* have any questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
2956
931f209e57a9
6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents:
1834
diff
changeset
|
26 |
* @bug 4396492 4396496 4778510 6850113 |
1834 | 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 |
||
2956
931f209e57a9
6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents:
1834
diff
changeset
|
92 |
System.out.println(bidi2 + "\n"); |
1834 | 93 |
|
94 |
if (bidi.getRunCount() != 3 || bidi2.getRunCount() != 3) { |
|
95 |
throw new Error("Bidi run count incorrect"); |
|
2956
931f209e57a9
6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents:
1834
diff
changeset
|
96 |
} else { |
931f209e57a9
6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents:
1834
diff
changeset
|
97 |
System.out.println("test1() passed.\n"); |
1834 | 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 |
||
2956
931f209e57a9
6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents:
1834
diff
changeset
|
128 |
System.out.println(bidi + "\n"); |
1834 | 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"); |
|
2956
931f209e57a9
6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents:
1834
diff
changeset
|
132 |
} else { |
931f209e57a9
6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents:
1834
diff
changeset
|
133 |
System.out.println("test2() passed.\n"); |
1834 | 134 |
} |
135 |
} |
|
136 |
} |