Skip to content

Commit a9b0f9c

Browse files
author
Alexander Zvegintsev
committed
8340393: Open source closed choice tests #2
Reviewed-by: psadhukhan
1 parent 63e611c commit a9b0f9c

File tree

4 files changed

+322
-0
lines changed

4 files changed

+322
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
import java.awt.BorderLayout;
25+
import java.awt.Choice;
26+
import java.awt.Frame;
27+
import javax.swing.JComponent;
28+
import javax.swing.JPanel;
29+
import javax.swing.SwingUtilities;
30+
31+
/*
32+
* @test
33+
* @bug 4151949
34+
* @summary Verifies that Components are reshaped to their preferred size
35+
* when their Container is packed.
36+
* @library /java/awt/regtesthelpers
37+
* @build PassFailJFrame
38+
* @run main/manual CheckChoiceTest
39+
*/
40+
41+
public class CheckChoiceTest {
42+
43+
private static JComponent componentToFocus;
44+
45+
private static final String INSTRUCTIONS = """
46+
Verify that the widths of the Choice components are all the same
47+
and that none is the minimum possible size.
48+
(The Choices should be at least as wide as the Frame.)
49+
""";
50+
51+
public static void main(String[] args) throws Exception {
52+
PassFailJFrame passFailJFrame = PassFailJFrame.builder()
53+
.title("CheckChoiceTest Instructions")
54+
.instructions(INSTRUCTIONS)
55+
.rows((int) INSTRUCTIONS.lines().count() + 3)
56+
.columns(45)
57+
.testUI(CheckChoiceTest::createAndShowUI)
58+
.splitUIBottom(CheckChoiceTest::createComponentToFocus)
59+
.build();
60+
61+
// focus away from the window with choices
62+
Thread.sleep(300);
63+
SwingUtilities.invokeAndWait(() -> componentToFocus.requestFocus());
64+
65+
passFailJFrame.awaitAndCheck();
66+
}
67+
68+
private static JComponent createComponentToFocus() {
69+
componentToFocus = new JPanel();
70+
return componentToFocus;
71+
}
72+
73+
private static Frame createAndShowUI() {
74+
Frame f = new Frame("Check Choice");
75+
f.setLayout(new BorderLayout());
76+
77+
Choice choice1 = new Choice();
78+
Choice choice2 = new Choice();
79+
Choice choice3 = new Choice();
80+
81+
f.add(choice1, BorderLayout.NORTH);
82+
f.add(choice3, BorderLayout.CENTER);
83+
f.add(choice2, BorderLayout.SOUTH);
84+
f.pack();
85+
86+
choice1.add("I am Choice, yes I am : 0");
87+
choice2.add("I am the same, yes I am : 0");
88+
choice3.add("I am the same, yes I am : 0");
89+
90+
return f;
91+
}
92+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2001, 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+
import java.awt.Choice;
25+
import java.awt.Frame;
26+
import java.awt.FlowLayout;
27+
import java.awt.Window;
28+
29+
/*
30+
* @test
31+
* @bug 4288285
32+
* @summary Verifies choice works with many items
33+
* @library /java/awt/regtesthelpers
34+
* @build PassFailJFrame
35+
* @run main/manual ChoiceBigTest
36+
*/
37+
38+
public class ChoiceBigTest {
39+
private static final String INSTRUCTIONS = """
40+
Click the Choice button, press Pass if:
41+
42+
- all looks good.
43+
- if you can select the item 1000
44+
45+
Otherwise press Fail.
46+
""";
47+
48+
public static void main(String[] args) throws Exception {
49+
PassFailJFrame.builder()
50+
.title("ChoiceBigTest Instructions")
51+
.instructions(INSTRUCTIONS)
52+
.rows((int) INSTRUCTIONS.lines().count() + 3)
53+
.columns(45)
54+
.testUI(ChoiceBigTest::createAndShowUI)
55+
.build()
56+
.awaitAndCheck();
57+
}
58+
59+
private static Window createAndShowUI() {
60+
Frame frame = new Frame("Check Choice");
61+
frame.setLayout(new FlowLayout());
62+
Choice choice = new Choice();
63+
frame.setSize(400, 200);
64+
for (int i = 1; i < 1001; ++i) {
65+
choice.add("I am Choice, yes I am : " + i);
66+
}
67+
frame.add(choice);
68+
return frame;
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
import java.awt.Button;
25+
import java.awt.Choice;
26+
import java.awt.Frame;
27+
import java.awt.Panel;
28+
import java.awt.Window;
29+
30+
/*
31+
* @test
32+
* @bug 4927930
33+
* @summary Verify that the focus is set to the selected item after calling the java.awt.Choice.select() method
34+
* @library /java/awt/regtesthelpers
35+
* @build PassFailJFrame
36+
* @run main/manual ChoiceFocusTest
37+
*/
38+
39+
public class ChoiceFocusTest {
40+
41+
private static final String INSTRUCTIONS = """
42+
1. Use the mouse to select Item 5 in the Choice list.
43+
2. Click on the Choice. Item5 is now selected and highlighted. This is the correct behavior.
44+
3. Select Item 1 in the Choice list.
45+
4. Click the "choice.select(5)" button. This causes a call to Choice.select(5). Item 5 is now selected.
46+
5. Click on the Choice.
47+
6. If the cursor and focus are on item 5, the test passes. Otherwise, it fails.
48+
""";
49+
50+
public static void main(String[] args) throws Exception {
51+
PassFailJFrame.builder()
52+
.title("ChoiceFocusTest Instructions")
53+
.instructions(INSTRUCTIONS)
54+
.rows((int) INSTRUCTIONS.lines().count() + 3)
55+
.columns(50)
56+
.testUI(ChoiceFocusTest::createAndShowUI)
57+
.build()
58+
.awaitAndCheck();
59+
}
60+
61+
private static Window createAndShowUI() {
62+
Panel panel = new Panel();
63+
Choice choice = new Choice();
64+
Button button = new Button("choice.select(5);");
65+
66+
for (int i = 0; i < 10; i++) {
67+
choice.add(String.valueOf(i));
68+
}
69+
70+
button.addActionListener(e -> choice.select(5));
71+
72+
panel.add(button);
73+
panel.add(choice);
74+
75+
Frame frame = new Frame("ChoiceFocusTest");
76+
frame.add(panel);
77+
frame.pack();
78+
79+
return frame;
80+
}
81+
}
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (c) 2011, 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+
import java.awt.BorderLayout;
25+
import java.awt.Checkbox;
26+
import java.awt.Choice;
27+
import java.awt.Frame;
28+
import java.awt.Window;
29+
import java.awt.event.ItemEvent;
30+
31+
/*
32+
* @test
33+
* @bug 6476183
34+
* @summary Drop down of a Choice changed to enabled state has a disabled like appearance
35+
* @library /java/awt/regtesthelpers
36+
* @build PassFailJFrame
37+
* @run main/manual DisabledList
38+
*/
39+
40+
public class DisabledList {
41+
42+
private static final String INSTRUCTIONS = """
43+
1) Select the checkbox
44+
2) Open Choice
45+
3) Drag mouse over the scrollbar or drag out it the choice
46+
4) If choice's items become disabled press fail, otherwise pass
47+
""";
48+
49+
public static void main(String[] args) throws Exception {
50+
PassFailJFrame.builder()
51+
.title("DisabledList Instructions")
52+
.instructions(INSTRUCTIONS)
53+
.rows((int) INSTRUCTIONS.lines().count() + 3)
54+
.columns(45)
55+
.testUI(DisabledList::createAndShowUI)
56+
.logArea(4)
57+
.build()
58+
.awaitAndCheck();
59+
}
60+
61+
private static Window createAndShowUI() {
62+
Frame frame = new Frame("DisabledList");
63+
frame.setSize(200, 200);
64+
frame.validate();
65+
Checkbox checkbox = new Checkbox("checkbox");
66+
final Choice choice = new Choice();
67+
choice.setEnabled(false);
68+
for (int i = 0; i < 15; i++) {
69+
choice.addItem("Item" + i);
70+
}
71+
checkbox.addItemListener(event -> {
72+
PassFailJFrame.log("CheckBox.itemStateChanged occurred");
73+
choice.setEnabled(event.getStateChange() == ItemEvent.SELECTED);
74+
});
75+
frame.add(BorderLayout.NORTH, checkbox);
76+
frame.add(BorderLayout.CENTER, choice);
77+
return frame;
78+
}
79+
}

0 commit comments

Comments
 (0)