-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
8306714: Open source few Swing event and AbstractAction tests
Backport-of: 31a73b0d7088d10a5ffb5541d66806a92b681ef9
- Loading branch information
Andrew Lu
committed
Apr 2, 2024
1 parent
151091c
commit 4ececad
Showing
6 changed files
with
329 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,82 @@ | ||
/* | ||
* 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 4186951 | ||
@summary Bulletproofing for AbstractAction.ArrayTable Serialization. | ||
@run main bug4186951 | ||
*/ | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.ObjectInputStream; | ||
import java.io.ObjectOutputStream; | ||
import java.io.Serializable; | ||
import java.awt.event.ActionEvent; | ||
import javax.swing.AbstractAction; | ||
import javax.swing.SwingUtilities; | ||
|
||
public class bug4186951 { | ||
public static void main(String[] args) throws Exception { | ||
AbstractAction ma = new MyAction(); | ||
MyClassSer mcs = new MyClassSer(); | ||
ma.putValue("serializable",mcs); | ||
MyClassNonSer mcn = new MyClassNonSer(); | ||
ma.putValue("non-serializable",mcn); | ||
FileOutputStream fos = new FileOutputStream("file.test"); | ||
ObjectOutputStream oos = new ObjectOutputStream(fos); | ||
oos.writeObject(ma); | ||
FileInputStream fis = new FileInputStream("file.test"); | ||
ObjectInputStream ois = new ObjectInputStream(fis); | ||
ma = (MyAction)ois.readObject(); | ||
File fil = new File("file.test"); | ||
if (fil!=null) { | ||
fil.delete(); | ||
} | ||
if (!((MyClassSer)ma.getValue("serializable")).equals(mcs)) { | ||
throw new RuntimeException("Serialisable class " + | ||
" wasn't serialized..."); | ||
} | ||
if ((MyClassNonSer)ma.getValue("non-serializable") != null) { | ||
throw new RuntimeException("Serialisation occurs for " + | ||
" non-serialisable class..."); | ||
} | ||
} | ||
|
||
static class MyAction extends AbstractAction { | ||
public void actionPerformed(ActionEvent e) {} | ||
} | ||
|
||
static class MyClassSer implements Serializable { | ||
String str = "default_string"; | ||
public boolean equals(MyClassSer s) { | ||
return str.equals(s.str); | ||
} | ||
} | ||
|
||
static class MyClassNonSer { | ||
String str = "default_string"; | ||
} | ||
|
||
} |
This file contains 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,47 @@ | ||
/* | ||
* 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 4211425 | ||
@summary Verifies ClassCastException in AbstractAction | ||
@run main bug4211425 | ||
*/ | ||
|
||
import java.awt.event.ActionEvent; | ||
import javax.swing.AbstractAction; | ||
|
||
public class bug4211425 { | ||
|
||
public static void main(String[] args) { | ||
AbstractAction at = new AbstractAction() { | ||
public void actionPerformed(ActionEvent e) { | ||
System.out.println("Action!"); | ||
} | ||
}; | ||
for (int i = 0; i < 10; i++) { | ||
at.putValue("key " + i, "name"); | ||
at.putValue("key " + i, "name"); // Adding another with same key | ||
// tickles this bug | ||
} | ||
} | ||
} |
This file contains 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,49 @@ | ||
/* | ||
* 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 4211454 | ||
@summary Verifies ClassCastException in AbstractAction | ||
@run main bug4211454 | ||
*/ | ||
|
||
import java.awt.event.ActionEvent; | ||
import javax.swing.AbstractAction; | ||
|
||
public class bug4211454 { | ||
|
||
public static void main(String[] args) { | ||
AbstractAction at = new AbstractAction() { | ||
public void actionPerformed(ActionEvent e) { | ||
System.out.println("Action!"); | ||
} | ||
}; | ||
for (int i = 0; i<9; i++) { | ||
at.putValue("key " + i, "name"); | ||
} | ||
for (int i = 9; i>3; i--) { | ||
at.putValue("key " + i, null); | ||
at.putValue("Not a key " + i, null); | ||
} | ||
} | ||
} |
This file contains 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,59 @@ | ||
/* | ||
* 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 4244034 | ||
@summary Tests that AbstractAction has method getKeys() | ||
@run main bug4244034 | ||
*/ | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.awt.event.ActionEvent; | ||
import javax.swing.Action; | ||
import javax.swing.AbstractAction; | ||
|
||
public class bug4244034 { | ||
|
||
/** Auxilliary class extending AbstractAction | ||
*/ | ||
static class NullAction extends AbstractAction { | ||
public void actionPerformed(ActionEvent e) {} | ||
} | ||
|
||
public static void main(String[] args) { | ||
AbstractAction action = new NullAction(); | ||
action.putValue(Action.SHORT_DESCRIPTION, "my short descr"); | ||
action.putValue(Action.LONG_DESCRIPTION, "my long descr"); | ||
action.putValue(Action.NAME, "my name"); | ||
|
||
Object[] keys = action.getKeys(); | ||
List keysList = Arrays.asList(keys); | ||
if (! keysList.contains(Action.SHORT_DESCRIPTION) || | ||
! keysList.contains(Action.LONG_DESCRIPTION) || | ||
! keysList.contains(Action.NAME)) { | ||
|
||
throw new Error("Failed: getKeys() works improperly"); | ||
} | ||
} | ||
} |
This file contains 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,48 @@ | ||
/* | ||
* 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 4143690 | ||
@summary Tests that TreeSelectionEvent has isAddedPath(int) method | ||
@run main bug4143690 | ||
*/ | ||
|
||
import javax.swing.event.TreeSelectionEvent; | ||
import javax.swing.tree.TreePath; | ||
|
||
public class bug4143690 { | ||
|
||
public static void main(String[] argv) throws Exception { | ||
bug4143690 test = new bug4143690(); | ||
TreePath p = new TreePath(""); | ||
TreeSelectionEvent e = new TreeSelectionEvent(test, p, true, p, p); | ||
|
||
TreePath[] paths = e.getPaths(); | ||
for(int i = 0; i < paths.length; i++) { | ||
TreePath path = paths[i]; | ||
if (e.isAddedPath(i) != true) { | ||
throw new RuntimeException("Incorrect isAddedPath(int)..."); | ||
} | ||
} | ||
} | ||
} |
This file contains 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,44 @@ | ||
/* | ||
* 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 4160240 | ||
@summary InternalFrameEvent has getInternalFrame() method. | ||
@run main bug4160240 | ||
*/ | ||
|
||
import javax.swing.JInternalFrame; | ||
import javax.swing.event.InternalFrameEvent; | ||
|
||
public class bug4160240 { | ||
|
||
public static void main(String[] argv) throws Exception { | ||
JInternalFrame jif = new JInternalFrame(); | ||
InternalFrameEvent ife = new InternalFrameEvent(jif, | ||
InternalFrameEvent.INTERNAL_FRAME_OPENED); | ||
if (ife.getInternalFrame() != jif) { | ||
throw new RuntimeException("JInternalFrame.getInternalFrame " + | ||
" doesn't work correctly..."); | ||
} | ||
} | ||
} |
4ececad
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.
Review
Issues