-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8306135: Clean up and open source some AWT tests #13518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
70d5b59
8306135: Clean up and open source some AWT tests
azuev-java 01c217f
Added a line separating class declaration from imports
azuev-java 8877ee0
Cosmitic change: couple of extra-long strings were reformatted to be …
azuev-java 2a04dff
Splitting couple of extra long lines to keep it more readable
azuev-java File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * Copyright (c) 2002, 2023, 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. | ||
| */ | ||
|
|
||
| /* | ||
| @test | ||
| @bug 4653170 | ||
| @summary Make sure setCursor does not produce Arithmetic Exception. | ||
| @key headful | ||
| @run main SingleColorCursorTest | ||
| */ | ||
|
|
||
| import java.awt.BorderLayout; | ||
| import java.awt.Button; | ||
| import java.awt.Cursor; | ||
| import java.awt.EventQueue; | ||
| import java.awt.Frame; | ||
| import java.awt.Panel; | ||
| import java.awt.Point; | ||
| import java.awt.Toolkit; | ||
| import java.awt.image.BufferedImage; | ||
| import java.lang.reflect.InvocationTargetException; | ||
|
|
||
| public class SingleColorCursorTest extends Panel { | ||
| public void init() { | ||
| setLayout (new BorderLayout()); | ||
| setSize (200,200); | ||
| add(new Button("JButton")); | ||
| } | ||
|
|
||
| public void start () { | ||
| Cursor singleColorCursor = Toolkit.getDefaultToolkit() | ||
| .createCustomCursor(new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_BINARY), | ||
| new Point(0,0), "Single Color Cursor"); | ||
| try { | ||
| setCursor(singleColorCursor); | ||
| } catch (ArithmeticException ae) { | ||
| throw new RuntimeException("Setting a 1x1 custom cursor causes arithmetic exception"); | ||
| } | ||
| } | ||
|
|
||
| public static void main(String[] args) throws InterruptedException, InvocationTargetException { | ||
| EventQueue.invokeAndWait(() -> { | ||
| Frame frame = new Frame("Test window"); | ||
| try { | ||
| SingleColorCursorTest test = new SingleColorCursorTest(); | ||
| test.init(); | ||
| frame.add(test); | ||
| frame.pack(); | ||
| frame.setLocationRelativeTo(null); | ||
| frame.setVisible(true); | ||
| test.start(); | ||
| frame.setVisible(false); | ||
| } finally { | ||
| frame.dispose(); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * Copyright (c) 1999, 2023, 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. | ||
| */ | ||
|
|
||
| /* | ||
| @test | ||
| @bug 4274360 | ||
| @summary Ensures that Dialogs receive COMPONENT_SHOWN events | ||
| @key headful | ||
| @run main ComponentShownEvent | ||
| */ | ||
|
|
||
| import java.awt.AWTException; | ||
| import java.awt.Dialog; | ||
| import java.awt.EventQueue; | ||
| import java.awt.Frame; | ||
| import java.awt.Robot; | ||
| import java.awt.event.ComponentAdapter; | ||
| import java.awt.event.ComponentEvent; | ||
| import java.lang.reflect.InvocationTargetException; | ||
|
|
||
| public class ComponentShownEvent { | ||
|
|
||
| volatile boolean componentShown = false; | ||
| Frame f; | ||
| Dialog d; | ||
|
|
||
| public void start() throws InterruptedException, | ||
| InvocationTargetException, AWTException { | ||
| Robot robot = new Robot(); | ||
| try { | ||
| EventQueue.invokeAndWait(() -> { | ||
| f = new Frame(); | ||
| d = new Dialog(f); | ||
|
|
||
| d.addComponentListener(new ComponentAdapter() { | ||
| public void componentShown(ComponentEvent e) { | ||
| componentShown = true; | ||
| } | ||
| }); | ||
|
|
||
| f.setSize(100, 100); | ||
| f.setLocationRelativeTo(null); | ||
| f.setVisible(true); | ||
| d.setVisible(true); | ||
| }); | ||
|
|
||
| robot.waitForIdle(); | ||
| robot.delay(1000); | ||
|
|
||
| if (!componentShown) { | ||
| throw new RuntimeException("test failed"); | ||
| } | ||
| } finally { | ||
| EventQueue.invokeAndWait(() -> { | ||
| if (d != null) { | ||
| d.setVisible(false); | ||
| d.dispose(); | ||
| } | ||
| if (f != null) { | ||
| f.setVisible(false); | ||
| f.dispose(); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| public static void main(String[] args) throws InterruptedException, | ||
| InvocationTargetException, AWTException { | ||
| ComponentShownEvent test = new ComponentShownEvent(); | ||
| test.start(); | ||
| System.out.println("test passed"); | ||
| } | ||
| } |
189 changes: 189 additions & 0 deletions
189
test/jdk/java/awt/Dialog/DialogAsParentOfFileDialog.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| /* | ||
| * Copyright (c) 2003, 2023, 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. | ||
| */ | ||
|
|
||
| /* | ||
| @test | ||
| @bug 4221123 | ||
| @summary Why Dialog can't be an owner of FileDialog? | ||
| @key headful | ||
| @run main DialogAsParentOfFileDialog | ||
| */ | ||
|
|
||
| import java.awt.Dialog; | ||
| import java.awt.EventQueue; | ||
| import java.awt.FileDialog; | ||
| import java.awt.Frame; | ||
| import java.lang.reflect.InvocationTargetException; | ||
|
|
||
| public class DialogAsParentOfFileDialog { | ||
| FileDialog fdialog; | ||
|
|
||
| public void start () { | ||
| StringBuilder errors = new StringBuilder(); | ||
| String nl = System.lineSeparator(); | ||
| Dialog dlg; | ||
| String title; | ||
| int mode; | ||
| boolean passed; | ||
|
|
||
| System.out.println("DialogAsParentOfFileDialog"); | ||
|
|
||
| /* | ||
| * public FileDialog(Dialog parent), | ||
| * checks owner and default settings. | ||
| */ | ||
| System.out.print("\ttest 01: "); | ||
| dlg = new Dialog(new Frame()); | ||
| fdialog = new FileDialog(dlg); | ||
| passed = | ||
| fdialog.getOwner() == dlg | ||
| && fdialog.isModal() | ||
| && fdialog.getTitle().equals("") | ||
| && fdialog.getMode() == FileDialog.LOAD | ||
| && fdialog.getFile() == null | ||
| && fdialog.getDirectory() == null | ||
| && fdialog.getFilenameFilter() == null; | ||
| System.out.println(passed ? "passed" : "FAILED"); | ||
| if (!passed) { | ||
| errors.append(nl); | ||
| errors.append("DialogAsParentOfFileDialog FAILED"); | ||
| } | ||
|
|
||
| /* | ||
| * public FileDialog(Dialog parent, String title), | ||
| * checks owner, title and default settings. | ||
| */ | ||
| System.out.print("\ttest 02: "); | ||
| dlg = new Dialog(new Frame()); | ||
| title = "Title"; | ||
| fdialog = new FileDialog(dlg, title); | ||
| passed = | ||
| fdialog.getOwner() == dlg | ||
| && fdialog.isModal() | ||
| && fdialog.getTitle().equals(title) | ||
| && fdialog.getMode() == FileDialog.LOAD | ||
| && fdialog.getFile() == null | ||
| && fdialog.getDirectory() == null | ||
| && fdialog.getFilenameFilter() == null; | ||
| System.out.println(passed ? "passed" : "FAILED"); | ||
| if (!passed) { | ||
| errors.append(nl); | ||
| errors.append("DialogAsParentOfFileDialog FAILED"); | ||
| } | ||
|
|
||
| /* | ||
| * public FileDialog(Dialog parent, String title), | ||
| * title: null. | ||
| * expected results: FileDialog object with a null title | ||
| */ | ||
| System.out.print("\ttest 03: "); | ||
| dlg = new Dialog(new Frame()); | ||
| title = null; | ||
| fdialog = new FileDialog(dlg, title); | ||
| passed = | ||
| fdialog.getOwner() == dlg | ||
| && (fdialog.getTitle() == null | ||
| || fdialog.getTitle().equals("")); | ||
| System.out.println(passed ? "passed" : "FAILED"); | ||
| if (!passed) { | ||
| errors.append(nl); | ||
| errors.append("DialogAsParentOfFileDialog FAILED"); | ||
| } | ||
|
|
||
| /* | ||
| * public FileDialog(Dialog parent, String title, int mode), | ||
| * checks owner, title and mode. | ||
| */ | ||
| dlg = new Dialog(new Frame()); | ||
| title = "Title"; | ||
|
|
||
| System.out.print("\ttest 04: "); | ||
| mode = FileDialog.SAVE; | ||
| fdialog = new FileDialog(dlg, title, mode); | ||
| passed = | ||
| fdialog.getOwner() == dlg | ||
| && fdialog.isModal() | ||
| && fdialog.getTitle().equals(title) | ||
| && fdialog.getMode() == mode | ||
| && fdialog.getFile() == null | ||
| && fdialog.getDirectory() == null | ||
| && fdialog.getFilenameFilter() == null; | ||
| System.out.println(passed ? "passed" : "FAILED"); | ||
| if (!passed) { | ||
| errors.append(nl); | ||
| errors.append("DialogAsParentOfFileDialog FAILED"); | ||
| } | ||
|
|
||
| System.out.print("\ttest 05: "); | ||
| mode = FileDialog.LOAD; | ||
| fdialog = new FileDialog(dlg, title, mode); | ||
| passed = | ||
| fdialog.getOwner() == dlg | ||
| && fdialog.isModal() | ||
| && fdialog.getTitle().equals(title) | ||
| && fdialog.getMode() == mode | ||
| && fdialog.getFile() == null | ||
| && fdialog.getDirectory() == null | ||
| && fdialog.getFilenameFilter() == null; | ||
| System.out.println(passed ? "passed" : "FAILED"); | ||
| if (!passed) { | ||
| errors.append(nl); | ||
| errors.append("DialogAsParentOfFileDialog FAILED"); | ||
| } | ||
|
|
||
| /* | ||
| * public FileDialog(Dialog parent, String title, int mode), | ||
| * mode: Integer.MIN_VALUE, Integer.MIN_VALUE+1, | ||
| * Integer.MAX_VALUE-1, Integer.MAX_VALUE | ||
| * expected results: IllegalArgumentException should be thrown | ||
| */ | ||
| System.out.print("\ttest 06: "); | ||
| dlg = new Dialog(new Frame()); | ||
| title = "Title"; | ||
| int[] modes = {Integer.MIN_VALUE, Integer.MIN_VALUE+1, | ||
| Integer.MAX_VALUE-1, Integer.MAX_VALUE}; | ||
| passed = true; | ||
| for (int i = 0; i < modes.length; i++) { | ||
| try { | ||
| fdialog = new FileDialog(dlg, title, modes[i]); | ||
| passed = false; | ||
| } catch (IllegalArgumentException e) {} | ||
| } | ||
| System.out.println(passed ? "passed" : "FAILED"); | ||
| if (!passed) { | ||
| errors.append(nl); | ||
| errors.append("DialogAsParentOfFileDialog FAILED"); | ||
| } | ||
|
|
||
| if (!errors.isEmpty()) { | ||
| throw new RuntimeException("Following tests failed:" + errors); | ||
| } | ||
| } | ||
|
|
||
| public static void main(String[] args) throws InterruptedException, | ||
| InvocationTargetException { | ||
| EventQueue.invokeAndWait(() -> { | ||
| new DialogAsParentOfFileDialog().start(); | ||
| }); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add empty line between class and the import statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done