Skip to content

Commit

Permalink
8306372: Open source AWT CardLayout and Checkbox tests
Browse files Browse the repository at this point in the history
Reviewed-by: serb, honkar
  • Loading branch information
prrace committed Apr 19, 2023
1 parent d03128d commit 781d6d7
Show file tree
Hide file tree
Showing 6 changed files with 364 additions and 0 deletions.
69 changes: 69 additions & 0 deletions test/jdk/java/awt/CardLayout/CardsOrderTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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 4689398
@summary Inserting items in a Container with CardLayout does not work since Merlin
*/

import java.awt.CardLayout;
import java.awt.Component;
import java.awt.Container;

public class CardsOrderTest {

public static void main(String[] args) throws Exception {

CardLayout layout = new CardLayout();
Container cont = new Container();
Component comp1 = new Component() {};
Component comp2 = new Component() {};
Component comp3 = new Component() {};
cont.setLayout(layout);
cont.add(comp1, "1", 0);
cont.add(comp2, "2", 0);
cont.add(comp3, "3", 0);

// Testing visibility "state" - not actually if its visible on screen
// since this test does not require a UI.
System.out.println("comp1.isVisible() = " + comp1.isVisible());
System.out.println("comp2.isVisible() = " + comp2.isVisible());
System.out.println("comp3.isVisible() = " + comp3.isVisible());

if (!comp1.isVisible() || comp2.isVisible() || comp3.isVisible()) {
throw new RuntimeException("first added component must be visible");
}

System.out.println("CardLayout.next()");
layout.next(cont);

System.out.println("comp1.isVisible() = " + comp1.isVisible());
System.out.println("comp2.isVisible() = " + comp2.isVisible());
System.out.println("comp3.isVisible() = " + comp3.isVisible());

if (!comp3.isVisible() ||comp1.isVisible() || comp2.isVisible()) {
throw new RuntimeException("the wrong component is visible after CardLayout.next() (must be comp3)");
}
}
}
59 changes: 59 additions & 0 deletions test/jdk/java/awt/CardLayout/ObedienceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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 4690266
@summary REGRESSION: Wizard Page does not move to the next page
*/

import java.awt.CardLayout;
import java.awt.Component;
import java.awt.Container;

public class ObedienceTest {

public static void main(String[] args) {
Container cont = new Container();
Component comp1 = new Component() {};
Component comp2 = new Component() {};
CardLayout layout = new CardLayout();
cont.setLayout(layout);
cont.add(comp1, "first");
cont.add(comp2, "second");

if (!comp1.isVisible()) {
throw new RuntimeException("first component must be visible");
}

comp1.setVisible(false);
comp2.setVisible(true);
layout.layoutContainer(cont);

if (!comp2.isVisible() || comp1.isVisible()) {
System.out.println("comp1.isVisible() = " + comp1.isVisible());
System.out.println("comp2.isVisible() = " + comp2.isVisible());
throw new RuntimeException("manually shown component must be visible after layoutContainer()");
}
}
}
56 changes: 56 additions & 0 deletions test/jdk/java/awt/Checkbox/CheckboxCrashTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2000, 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 4378378
@summary Tests that checkbox.setLabel(null) doesn't crash the VM.
@key headful
*/

import java.awt.Checkbox;
import java.awt.EventQueue;
import java.awt.Frame;

public class CheckboxCrashTest {

static Frame f;

public static void main(String[] args) throws Exception {
try {
EventQueue.invokeAndWait(() -> runTest());
Thread.sleep(1000);
} finally {
f.dispose();
}
}

static void runTest() {
f = new Frame("CheckboxCrashTest");
Checkbox cb = new Checkbox();
f.add(cb);
f.pack();
cb.setLabel(null);
f.setVisible(true);
}
}
59 changes: 59 additions & 0 deletions test/jdk/java/awt/Checkbox/MultiCheckedCheckboxGroupTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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 4136496
@key headful
@summary Checkbox.setCheckboxGroup(CheckboxGroup) works wrong on some Checkbox states
*/

import java.awt.Checkbox;
import java.awt.CheckboxGroup;

public class MultiCheckedCheckboxGroupTest {

public static void main(String[] args) throws Exception {

CheckboxGroup gr = new CheckboxGroup();
Checkbox chb1 = new Checkbox("Box 1", true, gr);
Checkbox chb2 = new Checkbox("Box 2", true, null);

chb2.setCheckboxGroup(gr);

System.out.println("chb1="+chb1);
System.out.println("chb2="+chb2);
System.out.println("gr.getSelectedCheckbox="+gr.getSelectedCheckbox());

if(chb1.getState()
&& !chb2.getState()
&& chb1.getCheckboxGroup() == gr
&& chb2.getCheckboxGroup() == gr
&& gr.getSelectedCheckbox() == chb1) {
System.out.println("PASSED");
} else {
System.out.println("FAILED");
throw new RuntimeException("Test FAILED");
}
}
}
55 changes: 55 additions & 0 deletions test/jdk/java/awt/Checkbox/NullCheckboxGroupTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 4114268
@key headful
@summary Checkbox.setCheckboxGroup(null) alters selection for CB's previous CBGroup
*/

import java.awt.Checkbox;
import java.awt.CheckboxGroup;

public class NullCheckboxGroupTest {


public static void main(String[] args) {
CheckboxGroup cbg = new CheckboxGroup();
Checkbox chbox1 = new Checkbox("First", cbg, true);
Checkbox chbox2 = new Checkbox("Second", cbg, false);

chbox2.setCheckboxGroup(null);

System.out.println("chbox1="+chbox1);
System.out.println("chbox2="+chbox2);
System.out.println("cbg="+cbg);

if (cbg.getSelectedCheckbox() != chbox1) {
System.out.println("FAILED");
throw new RuntimeException("Test FAILED");
} else {
System.out.println("PASSED");
}
}
}
66 changes: 66 additions & 0 deletions test/jdk/java/awt/Checkbox/SetCheckboxGroupNull.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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 4726853
@key headful
@summary Checkbox is changing it's state after removing from CheckboxGroup
*/

import java.awt.Checkbox;
import java.awt.CheckboxGroup;

public class SetCheckboxGroupNull {

public static void main(String[] args) {
boolean passed = true;

// 1 step
{
CheckboxGroup g = new CheckboxGroup();
Checkbox cb1 = new Checkbox("Label", true, g);
System.out.println("1. (should be true) "+cb1.getState());
passed = passed && (cb1.getState() == true);
cb1.setCheckboxGroup(null);
System.out.println("2. (should be true) "+cb1.getState());
passed = passed && (cb1.getState() == true);
}

// 2 step
{
CheckboxGroup g = new CheckboxGroup();
Checkbox cb1 = new Checkbox("CB1", true, g);
System.out.println("3. (should be true) " + cb1.getState());
passed = passed && (cb1.getState() == true);
g.setSelectedCheckbox(null);
System.out.println("4. (should be false) " + cb1.getState());
passed = passed && (cb1.getState() == false);
}

if (!passed) {
throw new RuntimeException("SetCheckboxGroupNull FAILED");
}
System.out.println("SetCheckboxGroupNull PASSED");
}
}

6 comments on commit 781d6d7

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@openjdk
Copy link

@openjdk openjdk bot commented on 781d6d7 Apr 20, 2023

Choose a reason for hiding this comment

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

@JesperIRL A tag with name jdk-20+19 already exists that refers to commit 760a260f.

@JesperIRL
Copy link
Member

Choose a reason for hiding this comment

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

/tag jdk-21+19

@openjdk
Copy link

@openjdk openjdk bot commented on 781d6d7 Apr 20, 2023

Choose a reason for hiding this comment

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

@JesperIRL The tag jdk-21+19 was successfully created.

@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 781d6d7 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-781d6d79 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 781d6d79 from the openjdk/jdk repository.

The commit being backported was authored by Phil Race on 19 Apr 2023 and was reviewed by Sergey Bylokhov and Harshitha Onkar.

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-781d6d79:Rudometov-backport-781d6d79
$ git checkout Rudometov-backport-781d6d79
# 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-781d6d79

Please sign in to comment.