|
1 /* |
|
2 * Copyright (c) 2007 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 |
|
26 * @bug 6665028 |
|
27 * @summary verify that the memory corruption doesn't happen. Note |
|
28 * that this test case fails without the fix in some different ways, |
|
29 * including timeout, due to the memory corruption. |
|
30 * @build Bug6665028 |
|
31 * @run main/othervm/timeout=60 -Xmx16m Bug6665028 |
|
32 */ |
|
33 |
|
34 import java.awt.font.TextAttribute; |
|
35 import java.text.AttributedString; |
|
36 import java.text.Bidi; |
|
37 |
|
38 // test1() and test2() were derived from BidiEmbeddingTest. |
|
39 public class Bug6665028 { |
|
40 |
|
41 private static boolean runrun = true; |
|
42 |
|
43 private static class Test extends Thread { |
|
44 public void run() { |
|
45 while (runrun) { |
|
46 test1(); |
|
47 test2(); |
|
48 } |
|
49 } |
|
50 } |
|
51 |
|
52 public static void main(String[] args) { |
|
53 Test[] tests = new Test[4]; |
|
54 for (int i = 0; i < tests.length; i++) { |
|
55 Test t = new Test(); |
|
56 tests[i] = t; |
|
57 t.start(); |
|
58 } |
|
59 |
|
60 try { |
|
61 Thread.sleep(45000); |
|
62 } catch (InterruptedException e) { |
|
63 } |
|
64 |
|
65 runrun = false; |
|
66 |
|
67 for (int i = 0; i < tests.length; i++) { |
|
68 try { |
|
69 tests[i].join(); |
|
70 } catch (InterruptedException e) { |
|
71 } |
|
72 } |
|
73 } |
|
74 |
|
75 static String target; |
|
76 static { |
|
77 String s = "A Bidi object provides information on the bidirectional reordering of the text used to create it. This is required, for example, to properly display Arabic or Hebrew text. "; |
|
78 StringBuilder sb = new StringBuilder(); |
|
79 for (int i = 0; i < 1000; i++) { |
|
80 sb.append(s); |
|
81 } |
|
82 target = sb.toString(); |
|
83 } |
|
84 |
|
85 static void test1() { |
|
86 String str = "If this text is >" + target + "< the test passed."; |
|
87 int start = str.indexOf(target); |
|
88 int limit = start + target.length(); |
|
89 |
|
90 AttributedString astr = new AttributedString(str); |
|
91 astr.addAttribute(TextAttribute.BIDI_EMBEDDING, |
|
92 new Integer(-1), |
|
93 start, |
|
94 limit); |
|
95 |
|
96 Bidi bidi = new Bidi(astr.getIterator()); |
|
97 |
|
98 byte[] embs = new byte[str.length() + 3]; |
|
99 for (int i = start + 1; i < limit + 1; ++i) { |
|
100 embs[i] = -1; |
|
101 } |
|
102 |
|
103 Bidi bidi2 = new Bidi(str.toCharArray(), 0, embs, 1, str.length(), Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT); |
|
104 if (bidi.getRunCount() != 3 || bidi2.getRunCount() != 3) { |
|
105 throw new Error("Bidi run count incorrect"); |
|
106 } |
|
107 } |
|
108 |
|
109 static void test2() { |
|
110 String str = "If this text is >" + target + "< the test passed."; |
|
111 int length = str.length(); |
|
112 int start = str.indexOf(target); |
|
113 int limit = start + target.length(); |
|
114 |
|
115 AttributedString astr = new AttributedString(str); |
|
116 astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL); |
|
117 |
|
118 astr.addAttribute(TextAttribute.BIDI_EMBEDDING, |
|
119 new Integer(-3), |
|
120 start, |
|
121 limit); |
|
122 |
|
123 Bidi bidi = new Bidi(astr.getIterator()); |
|
124 |
|
125 if (bidi.getRunCount() != 6) { // runs of spaces and angles at embedding bound,s and final period, each get level 1 |
|
126 throw new Error("Bidi embedding processing failed"); |
|
127 } |
|
128 } |
|
129 } |