Skip to content

Commit b103c1f

Browse files
committed
8340077: Open source few Checkbox tests - Set2
Backport-of: 6f459aff453679ee89fd80bb325737d76288e4d2
1 parent 388dbeb commit b103c1f

File tree

5 files changed

+404
-0
lines changed

5 files changed

+404
-0
lines changed

test/jdk/ProblemList.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,4 +820,7 @@ java/awt/Focus/FrameMinimizeTest/FrameMinimizeTest.java 8016266 linux-x64
820820
java/awt/Frame/SizeMinimizedTest.java 8305915 linux-x64
821821
java/awt/PopupMenu/PopupHangTest.java 8340022 windows-all
822822
java/awt/Focus/InactiveFocusRace.java 8023263 linux-all
823+
java/awt/Checkbox/CheckboxBoxSizeTest.java 8340870 windows-all
824+
java/awt/Checkbox/CheckboxIndicatorSizeTest.java 8340870 windows-all
825+
java/awt/Checkbox/CheckboxNullLabelTest.java 8340870 windows-all
823826
java/awt/dnd/WinMoveFileToShellTest.java 8341665 windows-all
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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.Checkbox;
25+
import java.awt.FlowLayout;
26+
import java.awt.Frame;
27+
import java.awt.Panel;
28+
29+
/*
30+
* @test
31+
* @bug 4410522
32+
* @requires (os.family == "windows")
33+
* @summary The box size of the Checkbox control should be the same as
34+
* in Windows native applications.
35+
* @library /java/awt/regtesthelpers
36+
* @build PassFailJFrame
37+
* @run main/manual CheckboxBoxSizeTest
38+
*/
39+
40+
public class CheckboxBoxSizeTest {
41+
private static final String INSTRUCTIONS = """
42+
This test must be run at UI Scale of 100% AND
43+
150% or greater.
44+
Compare the size of box to any of native apps on Windows
45+
(Eg. Font Dialog Settings on Word).
46+
They should be the same.
47+
48+
If the sizes are same Press PASS, else Press FAIL.
49+
""";
50+
51+
public static void main(String[] args) throws Exception {
52+
PassFailJFrame.builder()
53+
.title("CheckboxBoxSizeTest Instructions")
54+
.instructions(INSTRUCTIONS)
55+
.rows((int) INSTRUCTIONS.lines().count() + 2)
56+
.columns(35)
57+
.testUI(CheckboxBoxSizeTest::createTestUI)
58+
.build()
59+
.awaitAndCheck();
60+
}
61+
62+
private static Frame createTestUI() {
63+
Frame frame = new Frame("CheckboxBoxSizeTest");
64+
Panel panel = new Panel(new FlowLayout());
65+
Checkbox checkbox = new Checkbox("Compare the box size");
66+
panel.add(checkbox);
67+
frame.add(panel);
68+
frame.pack();
69+
return frame;
70+
}
71+
}
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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.Checkbox;
25+
import java.awt.CheckboxGroup;
26+
import java.awt.Color;
27+
import java.awt.Font;
28+
import java.awt.Frame;
29+
import java.awt.GridLayout;
30+
import java.awt.Label;
31+
import java.awt.Menu;
32+
import java.awt.MenuBar;
33+
import java.awt.MenuItem;
34+
import java.awt.Panel;
35+
import java.awt.event.ActionEvent;
36+
import java.awt.event.ActionListener;
37+
38+
/*
39+
* @test
40+
* @bug 4090493
41+
* @summary Test for Checkbox indicator size
42+
* @library /java/awt/regtesthelpers
43+
* @build PassFailJFrame
44+
* @run main/manual CheckboxIndicatorSizeTest
45+
*/
46+
47+
public class CheckboxIndicatorSizeTest implements ActionListener {
48+
private static final String INSTRUCTIONS = """
49+
Indicator size of Checkbox depends
50+
on the platform font used to render the label.
51+
52+
In the frame you can see a group of checkboxes
53+
and radio buttons.
54+
Verify that all checkboxes and radio buttons have
55+
indicators of the same size and proportional to
56+
the uiScale and/or font-size.
57+
58+
Use menu to change the font size and the indicators
59+
should scale proportionally.
60+
61+
If there is a bug, the checkbox/radiobutton with
62+
dingbats label will have a smaller indicator.
63+
64+
Press PASS if the above conditions are true else Press FAIL.
65+
""";
66+
private static Frame frame;
67+
private static Panel testPanel;
68+
69+
public static void main(String[] args) throws Exception {
70+
71+
CheckboxIndicatorSizeTest obj = new CheckboxIndicatorSizeTest();
72+
PassFailJFrame.builder()
73+
.title("Test Instructions")
74+
.instructions(INSTRUCTIONS)
75+
.rows((int) INSTRUCTIONS.lines().count() + 3)
76+
.columns(60)
77+
.testUI(obj::createAndShowUI)
78+
.build()
79+
.awaitAndCheck();
80+
}
81+
82+
private Frame createAndShowUI() {
83+
frame = new Frame("CheckboxIndicatorSizeTest");
84+
85+
testPanel = new Panel(new GridLayout(0, 1));
86+
testPanel.setFont(new Font("Dialog", Font.PLAIN, 12));
87+
frame.add(testPanel);
88+
89+
MenuBar menuBar = new MenuBar();
90+
Menu fontSizeMenu = new Menu("FontSize");
91+
92+
MenuItem size10 = new MenuItem("10");
93+
size10.addActionListener(this);
94+
fontSizeMenu.add(size10);
95+
96+
MenuItem size12 = new MenuItem("12");
97+
size12.addActionListener(this);
98+
fontSizeMenu.add(size12);
99+
100+
MenuItem size14 = new MenuItem("14");
101+
size14.addActionListener(this);
102+
fontSizeMenu.add(size14);
103+
104+
MenuItem size18 = new MenuItem("18");
105+
size18.addActionListener(this);
106+
fontSizeMenu.add(size18);
107+
108+
MenuItem size24 = new MenuItem("24");
109+
size24.addActionListener(this);
110+
fontSizeMenu.add(size24);
111+
112+
MenuItem size36 = new MenuItem("36");
113+
size36.addActionListener(this);
114+
fontSizeMenu.add(size36);
115+
116+
menuBar.add(fontSizeMenu);
117+
frame.setMenuBar(menuBar);
118+
119+
Checkbox cbEnglishOnly
120+
= new Checkbox("Toggle", true);
121+
Checkbox cbDingbatsOnly
122+
= new Checkbox("\u274a\u274b\u274c\u274d", true);
123+
Checkbox cbEnglishDingbats
124+
= new Checkbox("Toggle \u274a\u274d", true);
125+
Checkbox cbDingbatsEnglish
126+
= new Checkbox("\u274a\u274d toggle", true);
127+
128+
CheckboxGroup radioGroup = new CheckboxGroup();
129+
Checkbox rbEnglishOnly
130+
= new Checkbox("Radio", true, radioGroup);
131+
Checkbox rbDingbatsOnly
132+
= new Checkbox("\u274a\u274b\u274c\u274d", false, radioGroup);
133+
Checkbox rbEnglishDingbats
134+
= new Checkbox("Radio \u274a\u274d", false, radioGroup);
135+
Checkbox rbDingbatsEnglish
136+
= new Checkbox("\u274a\u274d radio", false, radioGroup);
137+
138+
Label cbLabel = new Label("Checkboxes");
139+
cbLabel.setBackground(Color.YELLOW);
140+
testPanel.add(cbLabel);
141+
testPanel.add(cbEnglishOnly);
142+
testPanel.add(cbDingbatsOnly);
143+
testPanel.add(cbEnglishDingbats);
144+
testPanel.add(cbDingbatsEnglish);
145+
146+
Label rbLabel = new Label("Radio buttons");
147+
rbLabel.setBackground(Color.YELLOW);
148+
testPanel.add(rbLabel);
149+
testPanel.add(rbEnglishOnly);
150+
testPanel.add(rbDingbatsOnly);
151+
testPanel.add(rbEnglishDingbats);
152+
testPanel.add(rbDingbatsEnglish);
153+
154+
frame.pack();
155+
return frame;
156+
}
157+
158+
@Override
159+
public void actionPerformed(ActionEvent e) {
160+
String sizeStr = e.getActionCommand();
161+
int size = Integer.parseInt(sizeStr);
162+
Font oldFont = testPanel.getFont();
163+
Font newFont = new Font(oldFont.getName(), oldFont.getStyle(), size);
164+
testPanel.setFont(newFont);
165+
frame.pack();
166+
frame.setVisible(true);
167+
}
168+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright (c) 2012, 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.CheckboxGroup;
27+
import java.awt.Color;
28+
import java.awt.Font;
29+
import java.awt.Frame;
30+
import java.awt.Panel;
31+
32+
/*
33+
* @test
34+
* @bug 4383735
35+
* @summary Checkbox buttons are too small with java 1.3 and 1.4
36+
* @library /java/awt/regtesthelpers
37+
* @build PassFailJFrame
38+
* @run main/manual CheckboxNullLabelTest
39+
*/
40+
41+
public class CheckboxNullLabelTest {
42+
private static final String INSTRUCTIONS = """
43+
Please look at the frame titled 'CheckboxNullLabelTest'.
44+
Check if all the check boxes in each group
45+
(of 3 check boxes) have the same size.
46+
47+
If the size of labeled check box is NOT the same as
48+
the size of non-labeled Press FAIL otherwise Press PASS.
49+
""";
50+
51+
public static void main(String[] args) throws Exception {
52+
PassFailJFrame.builder()
53+
.title("Test Instructions")
54+
.instructions(INSTRUCTIONS)
55+
.rows((int) INSTRUCTIONS.lines().count() + 1)
56+
.columns(35)
57+
.testUI(CheckboxNullLabelTest::createAndShowUI)
58+
.build()
59+
.awaitAndCheck();
60+
}
61+
62+
private static Frame createAndShowUI() {
63+
Frame f = new Frame("CheckboxNullLabelTest");
64+
f.setLayout(new BorderLayout());
65+
f.add(new CheckboxTest(Color.gray, new Font(null, 0, 12)), "North");
66+
f.add(new CheckboxTest(Color.green, new Font(null, 0, 18)), "South");
67+
f.add(new CheckboxTest(Color.red, new Font(null, 0, 24)), "East");
68+
f.add(new CheckboxTest(Color.white, new Font(null, 0, 30)), "West");
69+
f.add(new CheckboxTest(f.getBackground(), new Font(null, 0, 36)), "Center");
70+
f.setSize(600, 450);
71+
return f;
72+
}
73+
74+
private static class CheckboxTest extends Panel {
75+
Checkbox cb1, cb2, cb3;
76+
77+
CheckboxTest(Color background, Font font) {
78+
setBackground(background);
79+
CheckboxGroup cbg = new CheckboxGroup();
80+
81+
cb1 = new Checkbox(null, cbg, true);
82+
cb1.setFont(font);
83+
84+
cb2 = new Checkbox("", cbg, true);
85+
cb2.setFont(font);
86+
87+
cb3 = new Checkbox("Label", cbg, false);
88+
cb3.setFont(font);
89+
90+
add(cb1);
91+
add(cb2);
92+
add(cb3);
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)