Skip to content

Commit a7d2077

Browse files
author
Tejesh R
committed
8340366: Open source several AWT Dialog tests - Batch 3
Reviewed-by: prr, dnguyen
1 parent 2d8fcc4 commit a7d2077

6 files changed

+656
-0
lines changed

test/jdk/ProblemList.txt

+2
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,8 @@ java/awt/KeyboardFocusmanager/ConsumeNextMnemonicKeyTypedTest/ConsumeNextMnemoni
473473

474474
java/awt/Window/GetScreenLocation/GetScreenLocationTest.java 8225787 linux-x64
475475
java/awt/Dialog/MakeWindowAlwaysOnTop/MakeWindowAlwaysOnTop.java 8266243 macosx-aarch64
476+
java/awt/Dialog/FileDialogUserFilterTest.java 8001142 generic-all
477+
476478
java/awt/dnd/BadSerializationTest/BadSerializationTest.java 8277817 linux-x64,windows-x64
477479
java/awt/dnd/DragSourceMotionListenerTest.java 8225131 windows-all
478480
java/awt/dnd/RejectDragTest.java 7124259 macosx-all
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright (c) 1998, 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.Button;
26+
import java.awt.Component;
27+
import java.awt.Dialog;
28+
import java.awt.Event;
29+
import java.awt.Frame;
30+
import java.awt.Panel;
31+
import java.awt.Window;
32+
import java.util.List;
33+
34+
/*
35+
* @test
36+
* @bug 4058370
37+
* @summary Test to verify Modality of Dialog
38+
* @library /java/awt/regtesthelpers
39+
* @build PassFailJFrame
40+
* @run main/manual DialogModalityTest
41+
*/
42+
43+
public class DialogModalityTest {
44+
public static void main(String[] args) throws Exception {
45+
String INSTRUCTIONS = """
46+
1. When the test is running, there will be a Frame, a Modal Dialog
47+
and a Window that is Modal Dialog's parent.
48+
2. Verify that it is impossible to bring up the menu in Frame before
49+
closing the Modal Dialog.
50+
""";
51+
PassFailJFrame.builder()
52+
.title("Test Instructions")
53+
.instructions(INSTRUCTIONS)
54+
.rows((int) INSTRUCTIONS.lines().count() + 2)
55+
.columns(35)
56+
.testUI(initialize())
57+
.build()
58+
.awaitAndCheck();
59+
}
60+
61+
public static List<Window> initialize() {
62+
Frame f = new Frame("Parent Frame");
63+
DialogTest dlg = new DialogTest(f, "Modal Dialog");
64+
f.add(new Button("push me"));
65+
f.setSize(200, 200);
66+
f.setLocation(210, 1);
67+
dlg.setBounds(210, 203, 200, 200);
68+
return List.of(f, dlg);
69+
}
70+
}
71+
72+
class DialogTest extends Dialog {
73+
Button closeButton;
74+
Frame parent;
75+
76+
public DialogTest(Frame parent, String title) {
77+
this(parent, title, true);
78+
}
79+
80+
public DialogTest(Frame parent, String title, boolean modal) {
81+
super(parent, title, modal);
82+
this.parent = parent;
83+
setLayout(new BorderLayout());
84+
Panel buttonPanel = new Panel();
85+
closeButton = new Button("Close");
86+
buttonPanel.add(closeButton);
87+
add("Center", buttonPanel);
88+
pack();
89+
}
90+
91+
public boolean action(Event e, Object arg) {
92+
if (e.target == closeButton) {
93+
Dialog dialog = null;
94+
Component c = (Component) e.target;
95+
96+
while (c != null && !(c instanceof Dialog)) {
97+
c = c.getParent();
98+
}
99+
100+
if (c != null) {
101+
dialog = (Dialog) c;
102+
}
103+
104+
if (dialog == null) {
105+
return false;
106+
}
107+
108+
dialog.setVisible(false);
109+
dialog.dispose();
110+
return true;
111+
}
112+
return false;
113+
}
114+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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.Button;
25+
import java.awt.Dialog;
26+
import java.awt.Frame;
27+
import java.awt.GridLayout;
28+
29+
/*
30+
* @test
31+
* @bug 4172302
32+
* @summary Test to make sure non-resizable Dialogs can be resized with the
33+
* setSize() method.
34+
* @library /java/awt/regtesthelpers
35+
* @build PassFailJFrame
36+
* @run main/manual DialogResizeTest2
37+
*/
38+
39+
public class DialogResizeTest2 {
40+
public static void main(String[] args) throws Exception {
41+
String INSTRUCTIONS = """
42+
This tests the programmatic resizability of non-resizable Dialogs
43+
Even when a Dialog is set to be non-resizable, it should be
44+
programmatically resizable using the setSize() method.
45+
46+
1. Initially the Dialog will be resizable. Try using the \\"Smaller\\"
47+
and \\"Larger\\" buttons to verify that the Dialog resizes correctly
48+
2. Then, click the \\"Toggle\\" button to make the Dialog non-resizable
49+
3. Again, verify that clicking the \\"Larger\\" and \\"Smaller\\" buttons
50+
causes the Dialog to get larger and smaller. If the Dialog does
51+
not change size, or does not re-layout correctly, the test FAILS
52+
""";
53+
PassFailJFrame.builder()
54+
.title("Test Instructions")
55+
.instructions(INSTRUCTIONS)
56+
.rows((int) INSTRUCTIONS.lines().count() + 2)
57+
.columns(35)
58+
.testUI(initialize())
59+
.logArea(8)
60+
.build()
61+
.awaitAndCheck();
62+
}
63+
64+
public static Frame initialize() {
65+
Frame frame = new Frame("Parent Frame");
66+
frame.add(new Button("Button"));
67+
frame.setSize(100, 100);
68+
new dlg(frame).setVisible(true);
69+
return frame;
70+
}
71+
72+
static class dlg extends Dialog {
73+
public dlg(Frame f_) {
74+
super(f_, "Dialog", false);
75+
setSize(200, 200);
76+
Button bLarger = new Button("Larger");
77+
bLarger.addActionListener(e -> setSize(400, 400));
78+
Button bSmaller = new Button("Smaller");
79+
bSmaller.addActionListener(e -> setSize(200, 100));
80+
Button bCheck = new Button("Resizable?");
81+
bCheck.addActionListener(e -> {
82+
if (isResizable()) {
83+
PassFailJFrame.log("Dialog is resizable");
84+
} else {
85+
PassFailJFrame.log("Dialog is not resizable");
86+
}
87+
});
88+
Button bToggle = new Button("Toggle");
89+
bToggle.addActionListener(e -> {
90+
if (isResizable()) {
91+
setResizable(false);
92+
PassFailJFrame.log("Dialog is now not resizable");
93+
} else {
94+
setResizable(true);
95+
PassFailJFrame.log("Dialog is now resizable");
96+
}
97+
});
98+
setLayout(new GridLayout(1, 4));
99+
add(bSmaller);
100+
add(bLarger);
101+
add(bCheck);
102+
add(bToggle);
103+
}
104+
}
105+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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.Button;
25+
import java.awt.Checkbox;
26+
import java.awt.Component;
27+
import java.awt.Container;
28+
import java.awt.Event;
29+
import java.awt.FileDialog;
30+
import java.awt.Frame;
31+
import java.awt.GridBagConstraints;
32+
import java.awt.GridBagLayout;
33+
import java.awt.Label;
34+
import java.awt.Panel;
35+
import java.awt.TextField;
36+
import java.io.File;
37+
import java.io.FilenameFilter;
38+
39+
/*
40+
* @test
41+
* @bug 4293697 4416433 4417139 4409600
42+
* @summary Test to verify that user filter always gets called on changing the
43+
* directory in FileDialog
44+
* @library /java/awt/regtesthelpers
45+
* @build PassFailJFrame
46+
* @run main/manual FileDialogUserFilterTest
47+
*/
48+
49+
public class FileDialogUserFilterTest {
50+
public static void main(String[] args) throws Exception {
51+
String INSTRUCTIONS = """
52+
1. Enter a mask into the <filter> field, a directory into
53+
the <directory> field (or leave the default values).
54+
2. Then click the <Load> button, file dialog will appear.
55+
Output of the user filter will be shown in the output
56+
area. Enter several different directories to the file dialog
57+
via double-clicking on the directory list. The output
58+
area should show some filtering output on each directory
59+
change. If any output was only given on dialog startup,
60+
the test is FAILED.
61+
3. Look at the list of files accepted by the filter.
62+
If some files do not match the filter,
63+
the test is FAILED.
64+
4. Open dialog with an empty filter.
65+
Enter some directories with a lot of files (like /usr/bin).
66+
If dialog crashes the test is FAILED.
67+
Enter the directory that contain files and other directories.
68+
If the directories are shown in the files box along with files
69+
then the test is FAILED.
70+
5. Click in checkbox 'do not use filter', make it checked.
71+
Open dialog, enter the directory with some files.
72+
If no files is shown in the File list box (while you are sure
73+
there are some files there) the test is FAILED
74+
Otherwise it is PASSED."
75+
""";
76+
77+
PassFailJFrame.builder()
78+
.title("Test Instructions")
79+
.instructions(INSTRUCTIONS)
80+
.rows((int) INSTRUCTIONS.lines().count() + 2)
81+
.columns(35)
82+
.testUI(new DialogFilterTest())
83+
.build()
84+
.awaitAndCheck();
85+
}
86+
}
87+
88+
class DialogFilterTest extends Frame implements FilenameFilter {
89+
FileDialog fd;
90+
static TextField tfDirectory = new TextField();
91+
static TextField tfFile = new TextField();
92+
static TextField tfFilter = new TextField();
93+
static Checkbox useFilterCheck = new Checkbox("do not use filter");
94+
95+
public DialogFilterTest() {
96+
setTitle("File Dialog User Filter test");
97+
add("North", new Button("Load"));
98+
Panel p = new Panel();
99+
p.setLayout(new GridBagLayout());
100+
addRow(p, new Label("directory:", Label.RIGHT), tfDirectory);
101+
addRow(p, new Label("file:", Label.RIGHT), tfFile);
102+
addRow(p, new Label("filter:", Label.RIGHT), tfFilter);
103+
addRow(p, new Label(""), useFilterCheck);
104+
tfFilter.setText(".java");
105+
tfDirectory.setText(".");
106+
add("Center", p);
107+
setSize(300, 200);
108+
}
109+
110+
static void addRow(Container cont, Component c1, Component c2) {
111+
GridBagLayout gbl = (GridBagLayout) cont.getLayout();
112+
GridBagConstraints c = new GridBagConstraints();
113+
c.fill = GridBagConstraints.BOTH;
114+
cont.add(c1);
115+
gbl.setConstraints(c1, c);
116+
117+
c.gridwidth = GridBagConstraints.REMAINDER;
118+
c.weightx = 1.0;
119+
cont.add(c2);
120+
gbl.setConstraints(c2, c);
121+
}
122+
123+
public boolean accept(File dir, String name) {
124+
System.out.println("File " + dir + " String " + name);
125+
if (fd.getMode() == FileDialog.LOAD) {
126+
return name.lastIndexOf(tfFilter.getText()) > 0;
127+
}
128+
return true;
129+
}
130+
131+
public boolean action(Event evt, Object what) {
132+
boolean load = "Load".equals(what);
133+
134+
if (load || "Save".equals(what)) {
135+
fd = new FileDialog(new Frame(), null,
136+
load ? FileDialog.LOAD : FileDialog.SAVE);
137+
fd.setDirectory(tfDirectory.getText());
138+
fd.setFile(tfFile.getText());
139+
if (!useFilterCheck.getState()) {
140+
fd.setFilenameFilter(this);
141+
}
142+
fd.setVisible(true);
143+
tfDirectory.setText(fd.getDirectory());
144+
tfFile.setText(fd.getFile());
145+
146+
return true;
147+
}
148+
return false;
149+
}
150+
}

0 commit comments

Comments
 (0)