8340193: Open source several AWT Dialog tests - Batch 1
Reviewed-by: psadhukhan
This commit is contained in:
parent
6e0138450a
commit
2d8fcc4271
test/jdk/java/awt/Dialog
91
test/jdk/java/awt/Dialog/DialogIconTest/DialogIconTest.java
Normal file
91
test/jdk/java/awt/Dialog/DialogIconTest/DialogIconTest.java
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Image;
|
||||
import java.awt.Label;
|
||||
import java.awt.MediaTracker;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.Window;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4779641
|
||||
* @summary Test to verify that Non-resizable dialogs should not show icons
|
||||
* @requires (os.family == "windows")
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual DialogIconTest
|
||||
*/
|
||||
|
||||
public class DialogIconTest {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
1. This is a Windows-only test of Dialog icons
|
||||
2. You can see a frame with a swing icon and two dialogs that it
|
||||
owns. The resizable dialog should have the same icon as the
|
||||
frame. The non-resizable dialog should have no icon at all
|
||||
3. Press PASS if this is true, press FAIL otherwise
|
||||
""";
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.rows((int) INSTRUCTIONS.lines().count() + 2)
|
||||
.columns(35)
|
||||
.testUI(initialize())
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static List<Window> initialize() {
|
||||
Frame f = new Frame("Parent frame");
|
||||
f.setBounds(50, 50, 200, 200);
|
||||
|
||||
Dialog dr = new Dialog(f, "Resizable Dialog");
|
||||
dr.setLocation(100, 100);
|
||||
dr.add(new Label("Should inherit icon from parent"));
|
||||
dr.pack();
|
||||
|
||||
Dialog dn = new Dialog(f, "NON Resizable Dialog");
|
||||
dn.setLocation(150, 150);
|
||||
dn.add(new Label("Should have no icon"));
|
||||
dn.pack();
|
||||
dn.setResizable(false);
|
||||
|
||||
String fileName = System.getProperty("test.src") +
|
||||
System.getProperty("file.separator") + "swing.small.gif";
|
||||
|
||||
Image icon = Toolkit.getDefaultToolkit().createImage(fileName);
|
||||
MediaTracker tracker = new MediaTracker(f);
|
||||
tracker.addImage(icon, 0);
|
||||
try {
|
||||
tracker.waitForAll();
|
||||
} catch (InterruptedException ie) {
|
||||
throw new RuntimeException("MediaTracker addImage Interrupted!");
|
||||
}
|
||||
f.setIconImage(icon);
|
||||
return List.of(f, dn, dr);
|
||||
}
|
||||
}
|
BIN
test/jdk/java/awt/Dialog/DialogIconTest/swing.small.gif
Normal file
BIN
test/jdk/java/awt/Dialog/DialogIconTest/swing.small.gif
Normal file
Binary file not shown.
After ![]() (image error) Size: 1.1 KiB |
118
test/jdk/java/awt/Dialog/DialogResizeTest.java
Normal file
118
test/jdk/java/awt/Dialog/DialogResizeTest.java
Normal file
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.awt.Checkbox;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Panel;
|
||||
import java.awt.TextArea;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.lang.Exception;
|
||||
import java.lang.String;
|
||||
import java.lang.System;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4115213
|
||||
* @summary Test to verify Checks that with resizable set to false,
|
||||
* dialog can not be resized
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual DialogResizeTest
|
||||
*/
|
||||
|
||||
public class DialogResizeTest {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
1. When this test is run a dialog will display (setResizable Test)
|
||||
Click on the checkbox to change the dialog resizable state
|
||||
2. For both dialog resizable states (resizable, non-resizable) try to
|
||||
change the size of the dialog. When isResizable is true the dialog
|
||||
is resizable. When isResizable is false the dialog is non-resizable
|
||||
3. If this is the behavior that you observe, the test has passed, Press
|
||||
the Pass button. Otherwise the test has failed, Press the Fail button
|
||||
""";
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.rows((int) INSTRUCTIONS.lines().count() + 2)
|
||||
.columns(40)
|
||||
.testUI(initialize())
|
||||
.logArea(8)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static Dialog initialize() {
|
||||
Frame f = new Frame("Owner Frame");
|
||||
MyDialog ld = new MyDialog(f);
|
||||
ld.setBounds(100, 100, 400, 150);
|
||||
ld.setResizable(false);
|
||||
System.out.println("isResizable is set to: " + ld.isResizable());
|
||||
return ld;
|
||||
}
|
||||
}
|
||||
|
||||
class MyDialog extends Dialog implements ItemListener {
|
||||
String sText = "Tests java.awt.Dialog.setResizable method";
|
||||
TextArea ta = new TextArea(sText, 2, 40, TextArea.SCROLLBARS_NONE);
|
||||
|
||||
public MyDialog(Frame f) {
|
||||
|
||||
super(f, "setResizable test", false);
|
||||
|
||||
Panel cbPanel = new Panel();
|
||||
cbPanel.setLayout(new FlowLayout());
|
||||
|
||||
Panel taPanel = new Panel();
|
||||
taPanel.setLayout(new FlowLayout());
|
||||
taPanel.add(ta);
|
||||
|
||||
Checkbox cb = new Checkbox("Check this box to change the dialog's " +
|
||||
"resizable state", null, isResizable());
|
||||
cb.setState(false);
|
||||
cb.addItemListener(this);
|
||||
cbPanel.add(cb);
|
||||
|
||||
add("North", taPanel);
|
||||
add("South", cbPanel);
|
||||
pack();
|
||||
}
|
||||
|
||||
public void itemStateChanged(ItemEvent evt) {
|
||||
setResizable(evt.getStateChange() == ItemEvent.SELECTED);
|
||||
|
||||
boolean bResizeState = isResizable();
|
||||
PassFailJFrame.log("isResizable is set to: " + bResizeState);
|
||||
|
||||
if (isResizable()) {
|
||||
ta.setText("dialog is resizable (isResizable = " + bResizeState + ")");
|
||||
} else {
|
||||
ta.setText("dialog is NOT resizable (isResizable = " + bResizeState + ")");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,258 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.awt.Button;
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Image;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Robot;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4035189
|
||||
* @summary Test to verify that PIT File Dialog icon not matching with
|
||||
* the new java icon (frame Icon) - PIT build
|
||||
* @requires (os.family == "windows")
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual FileDialogIconTest
|
||||
*/
|
||||
|
||||
public class FileDialogIconTest {
|
||||
public static Frame frame;
|
||||
public static Image image;
|
||||
public static List<Image> images;
|
||||
static String fileBase;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
1. Select the Image for a Dialog and Frame using either
|
||||
Load/Save/Just Dialog.
|
||||
2. Set the Icon Image/s to Frame and Dialog. Verify that the
|
||||
Icon is set for the respective Frame and Dialog.
|
||||
If selected Icon is set to Frame and Dialog press PASS
|
||||
else FAIL.
|
||||
""";
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.rows((int) INSTRUCTIONS.lines().count() + 2)
|
||||
.columns(35)
|
||||
.testUI(initialize())
|
||||
.logArea(8)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static void setImagesToFD(java.util.List<Image> listIcon) {
|
||||
FileDialogIconTest.images = listIcon;
|
||||
}
|
||||
|
||||
public static void setImagesToFrame(java.util.List<Image> listIcon) {
|
||||
frame.setIconImages(listIcon);
|
||||
}
|
||||
|
||||
public static void setImageToFD(Image img) {
|
||||
FileDialogIconTest.image = img;
|
||||
}
|
||||
|
||||
public static void setImageToFrame(Image img) {
|
||||
frame.setIconImage(img);
|
||||
}
|
||||
|
||||
public static Frame initialize() {
|
||||
frame = new Frame("FileDialogIconTest");
|
||||
Button setImageButton1 = new Button("setIconImageToFrame");
|
||||
Button setImageButton2 = new Button("setIconImageToDialog");
|
||||
Button setImageButton3 = new Button("setIconImagesToFrame");
|
||||
Button setImageButton4 = new Button("setIconImagesToDialog");
|
||||
Button setImageButton5 = new Button("setIconBufferedImagesToDialog");
|
||||
Button setImageButton6 = new Button("setIconBufferedImagesToFrame");
|
||||
|
||||
if (System.getProperty("test.src") == null) {
|
||||
fileBase = "";
|
||||
} else {
|
||||
fileBase = System.getProperty("test.src") + System.getProperty("file.separator");
|
||||
}
|
||||
|
||||
final String fileName = fileBase + "loading-msg.gif";
|
||||
|
||||
setImageButton1.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
try {
|
||||
Image image = Toolkit.getDefaultToolkit().getImage(fileName);
|
||||
setImageToFrame(image);
|
||||
PassFailJFrame.log("Loaded image . setting to frame");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setImageButton2.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
try {
|
||||
Image image = Toolkit.getDefaultToolkit().getImage(fileName);
|
||||
setImageToFD(image);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setImageButton3.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
try {
|
||||
Image image;
|
||||
java.util.List<Image> list = new java.util.ArrayList();
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
String fileName = fileBase + "T" + i + ".gif";
|
||||
image = Toolkit.getDefaultToolkit().getImage(fileName);
|
||||
PassFailJFrame.log("Loaded image " + fileName + ". setting to the list for frame");
|
||||
list.add(image);
|
||||
}
|
||||
setImagesToFrame(list);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
setImageButton4.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
try {
|
||||
Image image;
|
||||
List<Image> list = new ArrayList<>();
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
String fileName = fileBase + "T" + i + ".gif";
|
||||
image = Toolkit.getDefaultToolkit().getImage(fileName);
|
||||
PassFailJFrame.log("Loaded image " + fileName + ". setting to the list for dialog");
|
||||
list.add(image);
|
||||
}
|
||||
setImagesToFD(list);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
setImageButton5.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
List<BufferedImage> list = new ArrayList<>();
|
||||
try {
|
||||
Robot robot = new Robot();
|
||||
Rectangle rectangle;
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
rectangle = new Rectangle(i * 10, i * 10, i * 10 + 40, i * 10 + 40);
|
||||
java.awt.image.BufferedImage image = robot.createScreenCapture(rectangle);
|
||||
robot.delay(100);
|
||||
list.add(image);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
PassFailJFrame.log("Captured images and set to the list for dialog");
|
||||
}
|
||||
});
|
||||
|
||||
setImageButton6.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
List<BufferedImage> list = new ArrayList<>();
|
||||
try {
|
||||
Robot robot = new Robot();
|
||||
Rectangle rectangle;
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
rectangle = new Rectangle(i * 10, i * 10, i * 10 + 40, i * 10 + 40);
|
||||
java.awt.image.BufferedImage image = robot.createScreenCapture(rectangle);
|
||||
robot.delay(100);
|
||||
list.add(image);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
PassFailJFrame.log("Captured images and set to the list for frame");
|
||||
}
|
||||
});
|
||||
|
||||
Button buttonLoad = new Button("Load Dialog");
|
||||
Button buttonSave = new Button("Save Dialog");
|
||||
Button buttonSimple = new Button("Just Dialog");
|
||||
buttonLoad.addActionListener(new MyActionListener(FileDialog.LOAD, "LOAD"));
|
||||
buttonSave.addActionListener(new MyActionListener(FileDialog.SAVE, "SAVE"));
|
||||
buttonSimple.addActionListener(new MyActionListener(-1, ""));
|
||||
|
||||
frame.setSize(400, 400);
|
||||
frame.setLayout(new FlowLayout());
|
||||
frame.add(buttonLoad);
|
||||
frame.add(buttonSave);
|
||||
frame.add(buttonSimple);
|
||||
frame.add(setImageButton1);
|
||||
frame.add(setImageButton2);
|
||||
frame.add(setImageButton3);
|
||||
frame.add(setImageButton4);
|
||||
frame.pack();
|
||||
return frame;
|
||||
}
|
||||
}
|
||||
|
||||
class MyActionListener implements ActionListener {
|
||||
int id;
|
||||
String name;
|
||||
|
||||
public MyActionListener(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent ae) {
|
||||
try {
|
||||
FileDialog filedialog;
|
||||
if (id == -1 && Objects.equals(name, "")) {
|
||||
filedialog = new FileDialog(FileDialogIconTest.frame);
|
||||
} else {
|
||||
filedialog = new FileDialog(FileDialogIconTest.frame, name, id);
|
||||
}
|
||||
if (FileDialogIconTest.image != null) {
|
||||
filedialog.setIconImage(FileDialogIconTest.image);
|
||||
}
|
||||
|
||||
if (FileDialogIconTest.images != null) {
|
||||
filedialog.setIconImages(FileDialogIconTest.images);
|
||||
}
|
||||
filedialog.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
BIN
test/jdk/java/awt/Dialog/FileDialogIconTest/T1.gif
Normal file
BIN
test/jdk/java/awt/Dialog/FileDialogIconTest/T1.gif
Normal file
Binary file not shown.
After ![]() (image error) Size: 2.5 KiB |
BIN
test/jdk/java/awt/Dialog/FileDialogIconTest/T2.gif
Normal file
BIN
test/jdk/java/awt/Dialog/FileDialogIconTest/T2.gif
Normal file
Binary file not shown.
After ![]() (image error) Size: 2.6 KiB |
BIN
test/jdk/java/awt/Dialog/FileDialogIconTest/T3.gif
Normal file
BIN
test/jdk/java/awt/Dialog/FileDialogIconTest/T3.gif
Normal file
Binary file not shown.
After ![]() (image error) Size: 2.5 KiB |
BIN
test/jdk/java/awt/Dialog/FileDialogIconTest/T4.gif
Normal file
BIN
test/jdk/java/awt/Dialog/FileDialogIconTest/T4.gif
Normal file
Binary file not shown.
After ![]() (image error) Size: 2.7 KiB |
BIN
test/jdk/java/awt/Dialog/FileDialogIconTest/loading-msg.gif
Normal file
BIN
test/jdk/java/awt/Dialog/FileDialogIconTest/loading-msg.gif
Normal file
Binary file not shown.
After ![]() (image error) Size: 1.5 KiB |
72
test/jdk/java/awt/Dialog/FileDialogWrongNameCrash.java
Normal file
72
test/jdk/java/awt/Dialog/FileDialogWrongNameCrash.java
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.awt.Button;
|
||||
import java.awt.Frame;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4779118
|
||||
* @summary Tests that FileDialog with wrong initial file name
|
||||
* doesn't crash when Open button is pressed.
|
||||
* @requires (os.family == "windows")
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual FileDialogWrongNameCrash
|
||||
*/
|
||||
|
||||
public class FileDialogWrongNameCrash {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
(This is Windows only test)
|
||||
1. You should see a frame 'Frame' with button 'Load'. Press button.",
|
||||
2. You should see 'Load file' dialog, select any file and press 'Open'",
|
||||
(not 'Cancel'!!!). If Java doesn't crash - press PASS, else FAIL
|
||||
""";
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.rows((int) INSTRUCTIONS.lines().count() + 2)
|
||||
.columns(35)
|
||||
.testUI(initialize())
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
private static Frame initialize() {
|
||||
Frame frame = new Frame("File Dialog Wrong Name Crash Test");
|
||||
Button fileButton = new Button("Load");
|
||||
fileButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent e) {
|
||||
final java.awt.FileDialog selector =
|
||||
new java.awt.FileDialog(frame);
|
||||
selector.setFile("Z:\\O2 XDA\\LogiTest\\\\Testcase.xml");
|
||||
selector.setVisible(true);
|
||||
}
|
||||
});
|
||||
frame.add(fileButton);
|
||||
frame.setSize(100, 60);
|
||||
return frame;
|
||||
}
|
||||
}
|
129
test/jdk/java/awt/Dialog/GetLocationTest_1.java
Normal file
129
test/jdk/java/awt/Dialog/GetLocationTest_1.java
Normal file
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4168481
|
||||
* @summary Test to verify Dialog getLocation() regression on Solaris
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual GetLocationTest_1
|
||||
*/
|
||||
|
||||
public class GetLocationTest_1 {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
1. Click in in the blue square and the yellow window should come
|
||||
up with the top left by the cursor
|
||||
2. If you see this correct behavior press PASS. If you see that
|
||||
the yellow window location is offset by some inset, press FAIL
|
||||
""";
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.rows((int) INSTRUCTIONS.lines().count() + 2)
|
||||
.columns(35)
|
||||
.testUI(initialize())
|
||||
.logArea(8)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static Dialog initialize() {
|
||||
Frame f = new Frame("Owner Frame");
|
||||
ColorComponent blue = new ColorComponent();
|
||||
blue.setBackground(Color.blue);
|
||||
blue.setSize(50, 50);
|
||||
|
||||
final Dialog dialog = new Dialog(f, "GetLocation test");
|
||||
dialog.setLocation(300, 300);
|
||||
System.out.println("Dialog location = " + dialog.getLocation());
|
||||
blue.setLocation(50, 50);
|
||||
dialog.setLayout(null);
|
||||
dialog.add(blue);
|
||||
dialog.setSize(200, 200);
|
||||
|
||||
final ColorWindow w = new ColorWindow(f);
|
||||
w.setSize(50, 50);
|
||||
w.setBackground(Color.yellow);
|
||||
|
||||
blue.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
PassFailJFrame.log("Dialog location = " + dialog.getLocation());
|
||||
Point p = e.getPoint();
|
||||
Component c = e.getComponent();
|
||||
PassFailJFrame.log("Position = " + p);
|
||||
convertPointToScreen(p, c);
|
||||
PassFailJFrame.log("Converted to = " + p);
|
||||
w.setLocation(p.x, p.y);
|
||||
w.setVisible(true);
|
||||
}
|
||||
});
|
||||
return dialog;
|
||||
}
|
||||
|
||||
static class ColorComponent extends Component {
|
||||
public void paint(Graphics g) {
|
||||
g.setColor(getBackground());
|
||||
Rectangle bounds = getBounds();
|
||||
g.fillRect(0, 0, bounds.width, bounds.height);
|
||||
}
|
||||
}
|
||||
|
||||
static class ColorWindow extends Window {
|
||||
ColorWindow(Frame f) {
|
||||
super(f);
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
g.setColor(getBackground());
|
||||
Rectangle bounds = getBounds();
|
||||
g.fillRect(0, 0, bounds.width, bounds.height);
|
||||
}
|
||||
}
|
||||
|
||||
public static void convertPointToScreen(Point p, Component c) {
|
||||
do {
|
||||
Point b = c.getLocation();
|
||||
PassFailJFrame.log("Adding " + b + " for " + c);
|
||||
p.x += b.x;
|
||||
p.y += b.y;
|
||||
|
||||
if (c instanceof java.awt.Window) {
|
||||
break;
|
||||
}
|
||||
c = c.getParent();
|
||||
} while (c != null);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user