Skip to content

Commit be9cc73

Browse files
author
Alexander Zuev
committed
8315871: Opensource five more Swing regression tests
Reviewed-by: dnguyen, prr
1 parent b65f4f7 commit be9cc73

File tree

5 files changed

+355
-0
lines changed

5 files changed

+355
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright (c) 2003, 2023, 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 4817630
27+
* @summary AncestorEvent ancestorAdded thrown at JFrame creation, not at show()
28+
* @key headful
29+
* @run main bug4817630
30+
*/
31+
32+
import java.lang.reflect.InvocationTargetException;
33+
import javax.swing.JFrame;
34+
import javax.swing.JLabel;
35+
import javax.swing.SwingUtilities;
36+
import javax.swing.event.AncestorEvent;
37+
import javax.swing.event.AncestorListener;
38+
39+
public class bug4817630 {
40+
41+
JFrame fr;
42+
43+
volatile boolean ancestorAdded = false;
44+
volatile boolean passed = true;
45+
46+
public void init() {
47+
fr = new JFrame("bug4817630");
48+
JLabel label = new JLabel("Label");
49+
50+
label.addAncestorListener(new AncestorListener() {
51+
public void ancestorAdded(AncestorEvent e) {
52+
if (!fr.isVisible()) {
53+
setPassed(false);
54+
}
55+
synchronized (bug4817630.this) {
56+
ancestorAdded = true;
57+
bug4817630.this.notifyAll();
58+
}
59+
}
60+
public void ancestorRemoved(AncestorEvent e) {
61+
}
62+
public void ancestorMoved(AncestorEvent e) {
63+
}
64+
});
65+
66+
fr.setLocationRelativeTo(null);
67+
fr.getContentPane().add(label);
68+
fr.pack();
69+
fr.setVisible(true);
70+
}
71+
72+
public void start() {
73+
try {
74+
synchronized (bug4817630.this) {
75+
while (!ancestorAdded) {
76+
bug4817630.this.wait();
77+
}
78+
}
79+
} catch(Exception e) {
80+
throw new RuntimeException("Test failed because of "
81+
+ e.getLocalizedMessage());
82+
}
83+
}
84+
85+
public void destroy() {
86+
if (fr != null) {
87+
fr.setVisible(false);
88+
fr.dispose();
89+
}
90+
if (!isPassed()) {
91+
throw new RuntimeException("ancestorAdded() method shouldn't be "
92+
+ "called before the frame is shown.");
93+
}
94+
}
95+
96+
synchronized void setPassed(boolean passed) {
97+
this.passed = passed;
98+
}
99+
100+
synchronized boolean isPassed() {
101+
return passed;
102+
}
103+
104+
public static void main(String[] args) throws InterruptedException,
105+
InvocationTargetException {
106+
bug4817630 test = new bug4817630();
107+
try {
108+
SwingUtilities.invokeAndWait(test::init);
109+
test.start();
110+
} finally {
111+
SwingUtilities.invokeAndWait(test::destroy);
112+
}
113+
}
114+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (c) 1999, 2023, 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 4191948
27+
* @summary BoxLayout doesn't ignore invisible components
28+
* @key headful
29+
* @run main bug4191948
30+
*/
31+
32+
import java.awt.BorderLayout;
33+
import java.lang.reflect.InvocationTargetException;
34+
import javax.swing.BoxLayout;
35+
import javax.swing.JButton;
36+
import javax.swing.JFrame;
37+
import javax.swing.JPanel;
38+
import javax.swing.SwingUtilities;
39+
40+
public class bug4191948 {
41+
JFrame frame;
42+
JPanel p;
43+
JButton foo1;
44+
JButton foo2;
45+
JButton foo3;
46+
47+
public void init() {
48+
frame = new JFrame("bug4191948");
49+
p = new JPanel();
50+
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
51+
foo1 = (JButton)p.add(new JButton("Foo1"));
52+
foo2 = (JButton)p.add(new JButton("Foo2"));
53+
foo3 = (JButton)p.add(new JButton("Foo3"));
54+
55+
foo2.setVisible(false);
56+
frame.setLocationRelativeTo(null);
57+
frame.setLayout(new BorderLayout());
58+
frame.add(p, BorderLayout.CENTER);
59+
frame.pack();
60+
frame.setVisible(true);
61+
}
62+
63+
public void start() {
64+
try {
65+
int totalWidth = p.getPreferredSize().width;
66+
int foo1Width = foo1.getPreferredSize().width;
67+
int foo2Width = foo2.getPreferredSize().width;
68+
int foo3Width = foo3.getPreferredSize().width;
69+
if (totalWidth >= (foo1Width + foo2Width + foo3Width)) {
70+
throw new RuntimeException("Panel is too wide");
71+
}
72+
} finally {
73+
if (frame != null) {
74+
frame.setVisible(false);
75+
frame.dispose();
76+
}
77+
}
78+
}
79+
80+
public static void main(String[] args) throws InterruptedException,
81+
InvocationTargetException {
82+
bug4191948 test = new bug4191948();
83+
SwingUtilities.invokeAndWait(test::init);
84+
SwingUtilities.invokeAndWait(test::start);
85+
}
86+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (c) 1999, 2023, 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 4248723
27+
* @summary Tests that ComponentInputMap doesn't throw NPE when deserializing
28+
* @run main bug4248723
29+
*/
30+
31+
import java.awt.event.InputEvent;
32+
import java.awt.event.KeyEvent;
33+
import java.io.ByteArrayInputStream;
34+
import java.io.ByteArrayOutputStream;
35+
import java.io.IOException;
36+
import java.io.ObjectInputStream;
37+
import java.io.ObjectOutputStream;
38+
import javax.swing.ComponentInputMap;
39+
import javax.swing.JButton;
40+
import javax.swing.KeyStroke;
41+
42+
public class bug4248723 {
43+
public static Object serializeAndDeserialize(Object toWrite)
44+
throws ClassNotFoundException, IOException {
45+
ByteArrayOutputStream ostream = new ByteArrayOutputStream();
46+
ObjectOutputStream p = new ObjectOutputStream(ostream);
47+
p.writeObject(toWrite);
48+
p.flush();
49+
byte[] data = ostream.toByteArray();
50+
ostream.close();
51+
52+
ByteArrayInputStream istream = new ByteArrayInputStream(data);
53+
ObjectInputStream q = new ObjectInputStream(istream);
54+
Object retValue = q.readObject();
55+
istream.close();
56+
return retValue;
57+
}
58+
59+
public static void main(String[] argv) {
60+
ComponentInputMap cim = new ComponentInputMap(new JButton());
61+
cim.put(KeyStroke.getKeyStroke(
62+
KeyEvent.VK_B, InputEvent.CTRL_DOWN_MASK), "A");
63+
try {
64+
cim = (ComponentInputMap)serializeAndDeserialize(cim);
65+
} catch (ClassNotFoundException|IOException ignore) {
66+
// Should not cause test to fail so silently ignore these
67+
}
68+
}
69+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2002, 2023, 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 4297953
27+
* @summary Tests that DefaultBoundedRangeModel doesn't zero out the
28+
* extent value when maximum changes
29+
* @run main bug4297953
30+
*/
31+
32+
import javax.swing.JScrollBar;
33+
34+
public class bug4297953 {
35+
public static void main(String[] args) {
36+
JScrollBar sb = new JScrollBar(JScrollBar.HORIZONTAL, 90, 10, 0, 100);
37+
sb.setMaximum(80);
38+
if (sb.getVisibleAmount() != 10) {
39+
throw new RuntimeException("Failed: extent is " + sb.getVisibleAmount());
40+
}
41+
}
42+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 1999, 2023, 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 4097723
27+
* @summary Tests that method DefaultButtonModel.getGroup() exists
28+
* @run main bug4097723
29+
*/
30+
31+
import javax.swing.ButtonGroup;
32+
import javax.swing.DefaultButtonModel;
33+
34+
public class bug4097723 {
35+
public static void main(String[] argv) {
36+
DefaultButtonModel dbm = new DefaultButtonModel();
37+
ButtonGroup group = new ButtonGroup();
38+
dbm.setGroup(group);
39+
ButtonGroup g = dbm.getGroup();
40+
if (g != group) {
41+
throw new RuntimeException("Failure: getGroup() returned wrong thing");
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)