8306714: Open source few Swing event and AbstractAction tests
Reviewed-by: serb, prr
This commit is contained in:
parent
8063aa2e4a
commit
31a73b0d70
82
test/jdk/javax/swing/Action/bug4186951.java
Normal file
82
test/jdk/javax/swing/Action/bug4186951.java
Normal file
@ -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";
|
||||
}
|
||||
|
||||
}
|
47
test/jdk/javax/swing/Action/bug4211425.java
Normal file
47
test/jdk/javax/swing/Action/bug4211425.java
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
}
|
49
test/jdk/javax/swing/Action/bug4211454.java
Normal file
49
test/jdk/javax/swing/Action/bug4211454.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
59
test/jdk/javax/swing/Action/bug4244034.java
Normal file
59
test/jdk/javax/swing/Action/bug4244034.java
Normal file
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
48
test/jdk/javax/swing/event/bug4143690.java
Normal file
48
test/jdk/javax/swing/event/bug4143690.java
Normal file
@ -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)...");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
44
test/jdk/javax/swing/event/bug4160240.java
Normal file
44
test/jdk/javax/swing/event/bug4160240.java
Normal file
@ -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...");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user