author | alanb |
Thu, 01 Dec 2016 08:57:53 +0000 | |
changeset 42338 | a60f280f803c |
parent 40128 | e635645d2a8a |
permissions | -rw-r--r-- |
17689
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
1 |
/* |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
2 |
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
4 |
* |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
8 |
* |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
13 |
* accompanied this code). |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
14 |
* |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
18 |
* |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
21 |
* questions. |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
22 |
*/ |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
23 |
|
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
24 |
/* |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
25 |
* @test |
40128
e635645d2a8a
8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents:
28071
diff
changeset
|
26 |
* @key headful |
17689
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
27 |
* @bug 8014863 |
20126 | 28 |
* @bug 8024395 |
17689
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
29 |
* @summary Tests the calculation of the line breaks when a text is inserted |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
30 |
* @author Dmitry Markov |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40128
diff
changeset
|
31 |
* @modules java.desktop/javax.swing.text:open |
17689
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
32 |
* @library ../../../regtesthelpers |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
33 |
* @build Util |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
34 |
* @run main bug8014863 |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
35 |
*/ |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
36 |
|
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
37 |
import javax.swing.*; |
20126 | 38 |
import javax.swing.text.GlyphView; |
39 |
import javax.swing.text.View; |
|
17689
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
40 |
import javax.swing.text.html.HTMLEditorKit; |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
41 |
import java.awt.*; |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
42 |
import java.awt.event.KeyEvent; |
20126 | 43 |
import java.lang.reflect.Field; |
44 |
import java.util.ArrayList; |
|
45 |
import java.util.Arrays; |
|
17689
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
46 |
|
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
47 |
public class bug8014863 { |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
48 |
|
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
49 |
private static JEditorPane editorPane; |
20126 | 50 |
private static JFrame frame; |
17689
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
51 |
private static Robot robot; |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
52 |
|
20126 | 53 |
private static String text1 = "<p>one two qqqq <em>this is a test sentence</em> qqqq <em>pp</em> qqqq <em>pp</em> " + |
54 |
"qqqq <em>pp</em> qqqq <em>pp</em> qqqq <em>pp</em> qqqq <em>pp</em> qqqq <em>pp</em> qqqq <em>pp</em> qqqq</p>"; |
|
55 |
private static String text2 = "<p>qqqq <em>this is a test sentence</em> qqqq <em>pp</em> qqqq <em>pp</em> " + |
|
56 |
"qqqq <em>pp</em> qqqq <em>pp</em> qqqq <em>pp</em> qqqq <em>pp</em> qqqq <em>pp</em> qqqq <em>pp</em> qqqq</p>"; |
|
57 |
||
58 |
private static ArrayList<GlyphView> glyphViews; |
|
59 |
||
17689
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
60 |
public static void main(String[] args) throws Exception { |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
61 |
robot = new Robot(); |
20126 | 62 |
robot.setAutoDelay(50); |
63 |
glyphViews = new ArrayList<GlyphView>(); |
|
17689
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
64 |
|
20126 | 65 |
createAndShowGUI(text1); |
66 |
||
28071
3acb75b8df45
8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
20126
diff
changeset
|
67 |
robot.waitForIdle(); |
20126 | 68 |
|
69 |
SwingUtilities.invokeAndWait(new Runnable() { |
|
70 |
public void run() { |
|
71 |
retrieveGlyphViews(editorPane.getUI().getRootView(editorPane)); |
|
72 |
} |
|
73 |
}); |
|
74 |
GlyphView [] arr1 = glyphViews.toArray(new GlyphView[glyphViews.size()]); |
|
75 |
||
76 |
frame.dispose(); |
|
77 |
glyphViews.clear(); |
|
78 |
||
79 |
createAndShowGUI(text2); |
|
17689
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
80 |
|
28071
3acb75b8df45
8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
20126
diff
changeset
|
81 |
robot.waitForIdle(); |
17689
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
82 |
|
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
83 |
Util.hitKeys(robot, KeyEvent.VK_HOME); |
28071
3acb75b8df45
8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
20126
diff
changeset
|
84 |
robot.waitForIdle(); |
17689
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
85 |
|
20126 | 86 |
Util.hitKeys(robot, KeyEvent.VK_O); |
17689
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
87 |
Util.hitKeys(robot, KeyEvent.VK_N); |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
88 |
Util.hitKeys(robot, KeyEvent.VK_E); |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
89 |
Util.hitKeys(robot, KeyEvent.VK_SPACE); |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
90 |
Util.hitKeys(robot, KeyEvent.VK_T); |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
91 |
Util.hitKeys(robot, KeyEvent.VK_W); |
20126 | 92 |
Util.hitKeys(robot, KeyEvent.VK_O); |
93 |
Util.hitKeys(robot, KeyEvent.VK_SPACE); |
|
17689
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
94 |
|
28071
3acb75b8df45
8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
20126
diff
changeset
|
95 |
robot.waitForIdle(); |
17689
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
96 |
|
20126 | 97 |
SwingUtilities.invokeAndWait(new Runnable() { |
98 |
public void run() { |
|
99 |
retrieveGlyphViews(editorPane.getUI().getRootView(editorPane)); |
|
100 |
} |
|
101 |
}); |
|
102 |
GlyphView [] arr2 = glyphViews.toArray(new GlyphView[glyphViews.size()]); |
|
103 |
||
104 |
if (arr1.length != arr2.length) { |
|
105 |
throw new RuntimeException("Test Failed!"); |
|
106 |
} |
|
107 |
||
108 |
for (int i=0; i<arr1.length; i++) { |
|
109 |
GlyphView v1 = arr1[i]; |
|
110 |
GlyphView v2 = arr2[i]; |
|
111 |
Field field = GlyphView.class.getDeclaredField("breakSpots"); |
|
112 |
field.setAccessible(true); |
|
113 |
int[] breakSpots1 = (int[])field.get(v1); |
|
114 |
int[] breakSpots2 = (int[])field.get(v2); |
|
115 |
if (!Arrays.equals(breakSpots1,breakSpots2)) { |
|
116 |
throw new RuntimeException("Test Failed!"); |
|
117 |
} |
|
118 |
} |
|
119 |
||
120 |
frame.dispose(); |
|
121 |
} |
|
122 |
||
123 |
private static void retrieveGlyphViews(View root) { |
|
124 |
for (int i=0; i<= root.getViewCount()-1; i++) { |
|
125 |
View view = root.getView(i); |
|
126 |
if (view instanceof GlyphView && view.isVisible()) { |
|
127 |
if (!glyphViews.contains(view)) { |
|
128 |
glyphViews.add((GlyphView)view); |
|
129 |
} |
|
130 |
} else { |
|
131 |
retrieveGlyphViews(view); |
|
132 |
} |
|
17689
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
133 |
} |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
134 |
} |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
135 |
|
20126 | 136 |
private static void createAndShowGUI(String text) throws Exception { |
17689
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
137 |
SwingUtilities.invokeAndWait(new Runnable() { |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
138 |
public void run() { |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
139 |
try { |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
140 |
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
141 |
} catch (Exception ex) { |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
142 |
throw new RuntimeException(ex); |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
143 |
} |
20126 | 144 |
frame = new JFrame(); |
17689
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
145 |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
146 |
|
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
147 |
editorPane = new JEditorPane(); |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
148 |
HTMLEditorKit editorKit = new HTMLEditorKit(); |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
149 |
editorPane.setEditorKit(editorKit); |
20126 | 150 |
editorPane.setText(text); |
17689
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
151 |
editorPane.setCaretPosition(1); |
20126 | 152 |
|
17689
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
153 |
frame.add(editorPane); |
20126 | 154 |
frame.setSize(200, 200); |
17689
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
155 |
frame.setVisible(true); |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
156 |
} |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
157 |
}); |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
158 |
} |
c6db20805a87
8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents:
diff
changeset
|
159 |
} |