Skip to content

Commit 781d6d7

Browse files
committed
8306372: Open source AWT CardLayout and Checkbox tests
Reviewed-by: serb, honkar
1 parent d03128d commit 781d6d7

File tree

6 files changed

+364
-0
lines changed

6 files changed

+364
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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 4689398
27+
@summary Inserting items in a Container with CardLayout does not work since Merlin
28+
*/
29+
30+
import java.awt.CardLayout;
31+
import java.awt.Component;
32+
import java.awt.Container;
33+
34+
public class CardsOrderTest {
35+
36+
public static void main(String[] args) throws Exception {
37+
38+
CardLayout layout = new CardLayout();
39+
Container cont = new Container();
40+
Component comp1 = new Component() {};
41+
Component comp2 = new Component() {};
42+
Component comp3 = new Component() {};
43+
cont.setLayout(layout);
44+
cont.add(comp1, "1", 0);
45+
cont.add(comp2, "2", 0);
46+
cont.add(comp3, "3", 0);
47+
48+
// Testing visibility "state" - not actually if its visible on screen
49+
// since this test does not require a UI.
50+
System.out.println("comp1.isVisible() = " + comp1.isVisible());
51+
System.out.println("comp2.isVisible() = " + comp2.isVisible());
52+
System.out.println("comp3.isVisible() = " + comp3.isVisible());
53+
54+
if (!comp1.isVisible() || comp2.isVisible() || comp3.isVisible()) {
55+
throw new RuntimeException("first added component must be visible");
56+
}
57+
58+
System.out.println("CardLayout.next()");
59+
layout.next(cont);
60+
61+
System.out.println("comp1.isVisible() = " + comp1.isVisible());
62+
System.out.println("comp2.isVisible() = " + comp2.isVisible());
63+
System.out.println("comp3.isVisible() = " + comp3.isVisible());
64+
65+
if (!comp3.isVisible() ||comp1.isVisible() || comp2.isVisible()) {
66+
throw new RuntimeException("the wrong component is visible after CardLayout.next() (must be comp3)");
67+
}
68+
}
69+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 4690266
27+
@summary REGRESSION: Wizard Page does not move to the next page
28+
*/
29+
30+
import java.awt.CardLayout;
31+
import java.awt.Component;
32+
import java.awt.Container;
33+
34+
public class ObedienceTest {
35+
36+
public static void main(String[] args) {
37+
Container cont = new Container();
38+
Component comp1 = new Component() {};
39+
Component comp2 = new Component() {};
40+
CardLayout layout = new CardLayout();
41+
cont.setLayout(layout);
42+
cont.add(comp1, "first");
43+
cont.add(comp2, "second");
44+
45+
if (!comp1.isVisible()) {
46+
throw new RuntimeException("first component must be visible");
47+
}
48+
49+
comp1.setVisible(false);
50+
comp2.setVisible(true);
51+
layout.layoutContainer(cont);
52+
53+
if (!comp2.isVisible() || comp1.isVisible()) {
54+
System.out.println("comp1.isVisible() = " + comp1.isVisible());
55+
System.out.println("comp2.isVisible() = " + comp2.isVisible());
56+
throw new RuntimeException("manually shown component must be visible after layoutContainer()");
57+
}
58+
}
59+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2000, 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 4378378
27+
@summary Tests that checkbox.setLabel(null) doesn't crash the VM.
28+
@key headful
29+
*/
30+
31+
import java.awt.Checkbox;
32+
import java.awt.EventQueue;
33+
import java.awt.Frame;
34+
35+
public class CheckboxCrashTest {
36+
37+
static Frame f;
38+
39+
public static void main(String[] args) throws Exception {
40+
try {
41+
EventQueue.invokeAndWait(() -> runTest());
42+
Thread.sleep(1000);
43+
} finally {
44+
f.dispose();
45+
}
46+
}
47+
48+
static void runTest() {
49+
f = new Frame("CheckboxCrashTest");
50+
Checkbox cb = new Checkbox();
51+
f.add(cb);
52+
f.pack();
53+
cb.setLabel(null);
54+
f.setVisible(true);
55+
}
56+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 4136496
27+
@key headful
28+
@summary Checkbox.setCheckboxGroup(CheckboxGroup) works wrong on some Checkbox states
29+
*/
30+
31+
import java.awt.Checkbox;
32+
import java.awt.CheckboxGroup;
33+
34+
public class MultiCheckedCheckboxGroupTest {
35+
36+
public static void main(String[] args) throws Exception {
37+
38+
CheckboxGroup gr = new CheckboxGroup();
39+
Checkbox chb1 = new Checkbox("Box 1", true, gr);
40+
Checkbox chb2 = new Checkbox("Box 2", true, null);
41+
42+
chb2.setCheckboxGroup(gr);
43+
44+
System.out.println("chb1="+chb1);
45+
System.out.println("chb2="+chb2);
46+
System.out.println("gr.getSelectedCheckbox="+gr.getSelectedCheckbox());
47+
48+
if(chb1.getState()
49+
&& !chb2.getState()
50+
&& chb1.getCheckboxGroup() == gr
51+
&& chb2.getCheckboxGroup() == gr
52+
&& gr.getSelectedCheckbox() == chb1) {
53+
System.out.println("PASSED");
54+
} else {
55+
System.out.println("FAILED");
56+
throw new RuntimeException("Test FAILED");
57+
}
58+
}
59+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 4114268
27+
@key headful
28+
@summary Checkbox.setCheckboxGroup(null) alters selection for CB's previous CBGroup
29+
*/
30+
31+
import java.awt.Checkbox;
32+
import java.awt.CheckboxGroup;
33+
34+
public class NullCheckboxGroupTest {
35+
36+
37+
public static void main(String[] args) {
38+
CheckboxGroup cbg = new CheckboxGroup();
39+
Checkbox chbox1 = new Checkbox("First", cbg, true);
40+
Checkbox chbox2 = new Checkbox("Second", cbg, false);
41+
42+
chbox2.setCheckboxGroup(null);
43+
44+
System.out.println("chbox1="+chbox1);
45+
System.out.println("chbox2="+chbox2);
46+
System.out.println("cbg="+cbg);
47+
48+
if (cbg.getSelectedCheckbox() != chbox1) {
49+
System.out.println("FAILED");
50+
throw new RuntimeException("Test FAILED");
51+
} else {
52+
System.out.println("PASSED");
53+
}
54+
}
55+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 4726853
27+
@key headful
28+
@summary Checkbox is changing it's state after removing from CheckboxGroup
29+
*/
30+
31+
import java.awt.Checkbox;
32+
import java.awt.CheckboxGroup;
33+
34+
public class SetCheckboxGroupNull {
35+
36+
public static void main(String[] args) {
37+
boolean passed = true;
38+
39+
// 1 step
40+
{
41+
CheckboxGroup g = new CheckboxGroup();
42+
Checkbox cb1 = new Checkbox("Label", true, g);
43+
System.out.println("1. (should be true) "+cb1.getState());
44+
passed = passed && (cb1.getState() == true);
45+
cb1.setCheckboxGroup(null);
46+
System.out.println("2. (should be true) "+cb1.getState());
47+
passed = passed && (cb1.getState() == true);
48+
}
49+
50+
// 2 step
51+
{
52+
CheckboxGroup g = new CheckboxGroup();
53+
Checkbox cb1 = new Checkbox("CB1", true, g);
54+
System.out.println("3. (should be true) " + cb1.getState());
55+
passed = passed && (cb1.getState() == true);
56+
g.setSelectedCheckbox(null);
57+
System.out.println("4. (should be false) " + cb1.getState());
58+
passed = passed && (cb1.getState() == false);
59+
}
60+
61+
if (!passed) {
62+
throw new RuntimeException("SetCheckboxGroupNull FAILED");
63+
}
64+
System.out.println("SetCheckboxGroupNull PASSED");
65+
}
66+
}

0 commit comments

Comments
 (0)