Skip to content

Commit

Permalink
8306714: Open source few Swing event and AbstractAction tests
Browse files Browse the repository at this point in the history
Reviewed-by: serb, prr
  • Loading branch information
prsadhuk committed Apr 25, 2023
1 parent 8063aa2 commit 31a73b0
Show file tree
Hide file tree
Showing 6 changed files with 329 additions and 0 deletions.
82 changes: 82 additions & 0 deletions test/jdk/javax/swing/Action/bug4186951.java
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";
}

}
47 changes: 47 additions & 0 deletions test/jdk/javax/swing/Action/bug4211425.java
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
}
}
}
49 changes: 49 additions & 0 deletions test/jdk/javax/swing/Action/bug4211454.java
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);
}
}
}
59 changes: 59 additions & 0 deletions test/jdk/javax/swing/Action/bug4244034.java
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");
}
}
}
48 changes: 48 additions & 0 deletions test/jdk/javax/swing/event/bug4143690.java
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)...");
}
}
}
}
44 changes: 44 additions & 0 deletions test/jdk/javax/swing/event/bug4160240.java
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...");
}
}
}

3 comments on commit 31a73b0

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rudometov
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 31a73b0 May 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rudometov the backport was successfully created on the branch Rudometov-backport-31a73b0d in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 31a73b0d from the openjdk/jdk repository.

The commit being backported was authored by Prasanta Sadhukhan on 25 Apr 2023 and was reviewed by Sergey Bylokhov and Phil Race.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev.git Rudometov-backport-31a73b0d:Rudometov-backport-31a73b0d
$ git checkout Rudometov-backport-31a73b0d
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev.git Rudometov-backport-31a73b0d

Please sign in to comment.