Skip to content

Commit c05f8c7

Browse files
author
Alexander Zuev
committedMar 15, 2024
8316388: Opensource five Swing component related regression tests
Reviewed-by: aivanov
1 parent b8dfeaf commit c05f8c7

File tree

5 files changed

+450
-0
lines changed

5 files changed

+450
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 1999, 2024, 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+
/* @test
25+
* @bug 4132993
26+
* @summary JDesktopPane.getAllFramesInLayer(..) return iconified frame
27+
* @run main bug4132993
28+
*/
29+
30+
import javax.swing.JDesktopPane;
31+
import javax.swing.JInternalFrame;
32+
import javax.swing.JLayeredPane;
33+
34+
35+
public class bug4132993 {
36+
public static void main(String[] args) throws Exception {
37+
JDesktopPane mDesktop = new JDesktopPane();
38+
JInternalFrame jif = new JInternalFrame("My Frame");
39+
jif.setIconifiable(true);
40+
mDesktop.add(jif);
41+
jif.setIcon(true);
42+
JInternalFrame[] ji =
43+
mDesktop.getAllFramesInLayer(JLayeredPane.DEFAULT_LAYER);
44+
for (int i = 0; i < ji.length; i++) {
45+
if (jif == ji[i]) {
46+
return;
47+
}
48+
}
49+
throw new RuntimeException("JDesktopPane.getAllFramesInLayer() failed...");
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* Copyright (c) 2003, 2024, 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+
/* @test
25+
* @bug 4773378
26+
* @summary BasicDesktopPaneUI.desktopManager nulled after JDesktopPane.updateUI()
27+
* @key headful
28+
* @run main bug4773378
29+
*/
30+
31+
import java.awt.AWTException;
32+
import java.awt.BorderLayout;
33+
import java.awt.Robot;
34+
import java.awt.event.KeyEvent;
35+
import java.beans.PropertyVetoException;
36+
import java.lang.reflect.InvocationTargetException;
37+
import java.util.concurrent.CountDownLatch;
38+
import javax.swing.DefaultDesktopManager;
39+
import javax.swing.JDesktopPane;
40+
import javax.swing.JFrame;
41+
import javax.swing.JInternalFrame;
42+
import javax.swing.SwingUtilities;
43+
import javax.swing.event.InternalFrameAdapter;
44+
import javax.swing.event.InternalFrameEvent;
45+
46+
public class bug4773378 {
47+
JFrame frame;
48+
49+
JDesktopPane desktop;
50+
DefaultDesktopManager desktopManager;
51+
JInternalFrame jif;
52+
53+
Robot robot;
54+
private final CountDownLatch frameActivated = new CountDownLatch(1);
55+
public void setupGUI() {
56+
frame = new JFrame("bug4773378");
57+
frame.setLayout(new BorderLayout());
58+
desktop = new JDesktopPane();
59+
frame.add(desktop, BorderLayout.CENTER);
60+
61+
jif = new JInternalFrame("jif", true, false, true, true);
62+
jif.setSize(150, 100);
63+
jif.setVisible(true);
64+
desktop.add(jif);
65+
66+
jif.addInternalFrameListener(new InternalFrameAdapter() {
67+
public void internalFrameActivated(InternalFrameEvent e) {
68+
frameActivated.countDown();
69+
}
70+
});
71+
72+
desktopManager = new MyDesktopManager();
73+
desktop.setDesktopManager(desktopManager);
74+
desktop.updateUI();
75+
76+
frame.setSize(200, 200);
77+
frame.setLocationRelativeTo(null);
78+
frame.setVisible(true);
79+
jif.requestFocus();
80+
}
81+
82+
public void performTest() throws InterruptedException,
83+
InvocationTargetException, AWTException {
84+
SwingUtilities.invokeAndWait(() -> {
85+
try {
86+
jif.setSelected(true);
87+
} catch (PropertyVetoException e) {
88+
throw new RuntimeException(e);
89+
}
90+
});
91+
92+
frameActivated.await();
93+
94+
robot = new Robot();
95+
robot.keyPress(KeyEvent.VK_CONTROL);
96+
robot.keyPress(KeyEvent.VK_F6);
97+
robot.keyRelease(KeyEvent.VK_F6);
98+
robot.keyRelease(KeyEvent.VK_CONTROL);
99+
100+
robot.waitForIdle();
101+
}
102+
103+
public void cleanupGUI() {
104+
if (frame != null) {
105+
frame.setVisible(false);
106+
frame.dispose();
107+
}
108+
}
109+
110+
private static class MyDesktopManager extends DefaultDesktopManager {
111+
}
112+
113+
public static void main(String[] args) throws InterruptedException,
114+
InvocationTargetException, AWTException {
115+
bug4773378 b = new bug4773378();
116+
SwingUtilities.invokeAndWait(b::setupGUI);
117+
b.performTest();
118+
SwingUtilities.invokeAndWait(b::cleanupGUI);
119+
}
120+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
* Copyright (c) 2000, 2024, 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+
/* @test
25+
* @bug 4325606
26+
* @summary Tests getting row start
27+
* @key headful
28+
* @run main bug4325606
29+
*/
30+
31+
import java.awt.AWTException;
32+
import java.awt.BorderLayout;
33+
import java.awt.Point;
34+
import java.awt.Robot;
35+
import java.awt.event.InputEvent;
36+
import java.awt.event.MouseAdapter;
37+
import java.awt.event.MouseEvent;
38+
import java.awt.event.WindowAdapter;
39+
import java.awt.event.WindowEvent;
40+
import java.lang.reflect.InvocationTargetException;
41+
import javax.swing.JEditorPane;
42+
import javax.swing.JFrame;
43+
import javax.swing.JScrollPane;
44+
import javax.swing.SwingUtilities;
45+
import javax.swing.text.BadLocationException;
46+
import javax.swing.text.Utilities;
47+
48+
public class bug4325606 {
49+
50+
public volatile boolean passed = true;
51+
private JFrame frame;
52+
private JEditorPane pane;
53+
54+
public void setupGUI() {
55+
frame = new JFrame("Click Bug");
56+
frame.setLayout(new BorderLayout());
57+
58+
pane = new JEditorPane();
59+
pane.addMouseListener(new ClickListener());
60+
pane.setContentType("text/html");
61+
pane.setText("<html><body>" +
62+
"<p>Here is line one</p>" +
63+
"<p>Here is line two</p>" +
64+
"</body></html>");
65+
66+
frame.add(new JScrollPane(pane), BorderLayout.CENTER);
67+
68+
frame.addWindowListener(new TestStateListener());
69+
frame.setLocation(50, 50);
70+
frame.setSize(400, 300);
71+
frame.setVisible(true);
72+
}
73+
74+
class TestStateListener extends WindowAdapter {
75+
public void windowOpened(WindowEvent ev) {
76+
Robot robo;
77+
try {
78+
robo = new Robot();
79+
} catch (AWTException e) {
80+
throw new RuntimeException("Robot could not be created", e);
81+
}
82+
robo.setAutoDelay(100);
83+
robo.delay(1000);
84+
Point p = frame.getLocationOnScreen();
85+
robo.mouseMove(p.x + 50, p.y + 50);
86+
robo.mousePress(InputEvent.BUTTON1_DOWN_MASK);
87+
robo.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
88+
robo.mousePress(InputEvent.BUTTON1_DOWN_MASK);
89+
robo.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
90+
robo.mousePress(InputEvent.BUTTON1_DOWN_MASK);
91+
robo.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
92+
}
93+
}
94+
95+
class ClickListener extends MouseAdapter {
96+
public void mouseClicked(MouseEvent event) {
97+
try {
98+
Utilities.getRowStart(pane, pane.getCaretPosition());
99+
} catch (BadLocationException blex) {
100+
throw new RuntimeException("Test failed.", blex);
101+
}
102+
}
103+
}
104+
105+
public void cleanupGUI() {
106+
if (frame != null) {
107+
frame.setVisible(false);
108+
frame.dispose();
109+
}
110+
}
111+
112+
public static void main(String[] args) throws InterruptedException,
113+
InvocationTargetException, AWTException {
114+
bug4325606 b = new bug4325606();
115+
try {
116+
Robot robot = new Robot();
117+
SwingUtilities.invokeAndWait(b::setupGUI);
118+
robot.waitForIdle();
119+
} finally {
120+
SwingUtilities.invokeAndWait(b::cleanupGUI);
121+
}
122+
}
123+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2002, 2024, 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+
/* @test
25+
* @bug 4330998
26+
* @summary JEditorPane.setText(null) throws NullPointerException.
27+
* @run main bug4330998
28+
*/
29+
30+
import javax.swing.JEditorPane;
31+
32+
public class bug4330998 {
33+
public static void main(String[] args) {
34+
JEditorPane jep = new JEditorPane();
35+
jep.setText(null);
36+
}
37+
}

0 commit comments

Comments
 (0)