Skip to content

Commit

Permalink
8234149: Several regression tests do not dispose Frame at end
Browse files Browse the repository at this point in the history
Reviewed-by: serb
  • Loading branch information
prsadhuk committed Dec 2, 2019
1 parent 0ee193c commit 55f3fd9
Show file tree
Hide file tree
Showing 54 changed files with 1,852 additions and 1,614 deletions.
77 changes: 41 additions & 36 deletions test/jdk/javax/swing/AbstractButton/6711682/bug6711682.java
Expand Up @@ -43,53 +43,58 @@ public class bug6711682 {
private static JCheckBox editorCb;
private static JCheckBox rendererCb;
private static JTable table;
private static JFrame f;

public static void main(String[] args) throws Exception {
Robot robot = new Robot();
robot.setAutoDelay(50);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createAndShowGUI();
try {
Robot robot = new Robot();
robot.setAutoDelay(50);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createAndShowGUI();
}
});
robot.waitForIdle();
Point l = table.getLocationOnScreen();
int h = table.getRowHeight();
for (int i = 0; i < 3; i++) {
robot.mouseMove(l.x + 5, l.y + 5 + i * h);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
});
robot.waitForIdle();
Point l = table.getLocationOnScreen();
int h = table.getRowHeight();
for (int i = 0; i < 3; i++) {
robot.mouseMove(l.x + 5, l.y + 5 + i * h);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
// Without pressing F2 the last table's cell
// reported <code>false</code> value
// note that I can't press it inside the for loop
// because it doesn't reproduce the bug
robot.keyPress(KeyEvent.VK_F2);
robot.keyRelease(KeyEvent.VK_F2);

for (int i = 0; i < 3; i++) {
if (!Boolean.TRUE.equals(table.getValueAt(i, 0))) {
throw new RuntimeException("Row #" + i + " checkbox is not selected");
// Without pressing F2 the last table's cell
// reported <code>false</code> value
// note that I can't press it inside the for loop
// because it doesn't reproduce the bug
robot.keyPress(KeyEvent.VK_F2);
robot.keyRelease(KeyEvent.VK_F2);

for (int i = 0; i < 3; i++) {
if (!Boolean.TRUE.equals(table.getValueAt(i, 0))) {
throw new RuntimeException("Row #" + i + " checkbox is not selected");
}
}
}
for (int i = 2; i >= 0; i--) {
robot.mouseMove(l.x + 5, l.y + 5 + i * h);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
robot.keyPress(KeyEvent.VK_F2);
robot.keyRelease(KeyEvent.VK_F2);
for (int i = 0; i < 3; i++) {
if (Boolean.TRUE.equals(table.getValueAt(i, 0))) {
throw new RuntimeException("Row #" + i + " checkbox is selected");
for (int i = 2; i >= 0; i--) {
robot.mouseMove(l.x + 5, l.y + 5 + i * h);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
robot.keyPress(KeyEvent.VK_F2);
robot.keyRelease(KeyEvent.VK_F2);
for (int i = 0; i < 3; i++) {
if (Boolean.TRUE.equals(table.getValueAt(i, 0))) {
throw new RuntimeException("Row #" + i + " checkbox is selected");
}
}
} finally {
if (f != null) SwingUtilities.invokeAndWait(() -> f.dispose());
}
}

private static void createAndShowGUI() {
editorCb = new JCheckBox();
rendererCb = new JCheckBox();
JFrame f = new JFrame("Table with CheckBox");
f = new JFrame("Table with CheckBox");
Container p = f.getContentPane();
p.setLayout(new BorderLayout());
table = new JTable(new Object[][]{{false}, {false}, {false}}, new Object[]{"CheckBox"});
Expand Down
11 changes: 8 additions & 3 deletions test/jdk/javax/swing/Action/8133039/bug8133039.java
Expand Up @@ -45,10 +45,15 @@ public class bug8133039 {

private static volatile int ACTION_PERFORMED_CALLS = 0;
private static volatile int ACTION_ACCEPTED_CALLS = 0;
private static JFrame frame;

public static void main(String[] args) throws Exception {
testActionNotification();
testPopupAction();
try {
testActionNotification();
testPopupAction();
} finally {
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
}
}

private static void testActionNotification() {
Expand Down Expand Up @@ -114,7 +119,7 @@ private static void testPopupAction() throws Exception {

private static void createAndShowGUI() {

JFrame frame = new JFrame();
frame = new JFrame();
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Expand Down
35 changes: 20 additions & 15 deletions test/jdk/javax/swing/JButton/4368790/bug4368790.java
Expand Up @@ -36,9 +36,10 @@

public class bug4368790 {
private static JButton b1;
private static JFrame frame;

private static void createGui() {
final JFrame frame = new JFrame();
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new FlowLayout());

Expand All @@ -53,21 +54,25 @@ private static void createGui() {
}

public static void main(String[] args) throws Exception {
Robot robot = new Robot();
robot.setAutoDelay(50);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
bug4368790.createGui();
try {
Robot robot = new Robot();
robot.setAutoDelay(50);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
bug4368790.createGui();
}
});
robot.waitForIdle();
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_SPACE);
robot.waitForIdle();
if (b1.getModel().isPressed()) {
throw new RuntimeException("The button is unexpectedly pressed");
}
});
robot.waitForIdle();
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_SPACE);
robot.waitForIdle();
if (b1.getModel().isPressed()) {
throw new RuntimeException("The button is unexpectedly pressed");
} finally {
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
}
}
}
14 changes: 10 additions & 4 deletions test/jdk/javax/swing/JButton/4796987/bug4796987.java
Expand Up @@ -24,6 +24,7 @@
/*
* @test
* @bug 4796987
* @key headful
* @requires (os.family == "windows")
* @summary XP Only: JButton.setBorderPainted() does not work with XP L&F
* @author Alexander Scherbatiy
Expand All @@ -46,12 +47,17 @@ public class bug4796987 {

private static JButton button1;
private static JButton button2;
private static JFrame frame;

public static void main(String[] args) throws Exception {
if (Platform.isWindows()
try {
if (Platform.isWindows()
&& OSVersion.current().equals(OSVersion.WINDOWS_XP)) {
UIManager.setLookAndFeel(new WindowsLookAndFeel());
testButtonBorder();
UIManager.setLookAndFeel(new WindowsLookAndFeel());
testButtonBorder();
}
} finally {
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
}
}

Expand Down Expand Up @@ -89,7 +95,7 @@ private static JButton getButton() {
}

private static void createAndShowGUI() {
JFrame frame = new JFrame("Test");
frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);

Expand Down
13 changes: 9 additions & 4 deletions test/jdk/javax/swing/JColorChooser/Test8051548.java
Expand Up @@ -56,11 +56,16 @@ public class Test8051548 {
private static JColorChooser colorChooser;
private static boolean propertyChangeListenerInvoked;
private static volatile Color color;
private static JFrame frame;

public static void main(String[] args) throws Exception {
testColorPanels();
testShowDialog(true);
testShowDialog(false);
try {
testColorPanels();
testShowDialog(true);
testShowDialog(false);
} finally {
if(frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
}
}

private static void testColorPanels() throws Exception {
Expand Down Expand Up @@ -182,7 +187,7 @@ private static boolean colorHasAlpha(){
}

private static void createAndShowGUI() {
JFrame frame = new JFrame();
frame = new JFrame();
frame.setSize(700, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
colorChooser = new JColorChooser();
Expand Down
6 changes: 4 additions & 2 deletions test/jdk/javax/swing/JComboBox/4523758/bug4523758.java
Expand Up @@ -43,7 +43,7 @@

public class bug4523758 {

private JFrame frame;
private static JFrame frame;
private JToolBar tools;
private JComboBox combo;

Expand Down Expand Up @@ -153,13 +153,15 @@ public void run() {
}
}

public static void main(String[] args) {
public static void main(String[] args) throws Exception {
try {
bug4523758 test = new bug4523758();
test.doTest();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("FAIL");
} finally {
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
}
}

Expand Down
20 changes: 12 additions & 8 deletions test/jdk/javax/swing/JComboBox/6236162/bug6236162.java
Expand Up @@ -46,14 +46,18 @@ public class bug6236162 {
private static MyComboUI comboUI;

public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createAndShowGUI();
}
});
test();
System.out.println("Test passed");
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createAndShowGUI();
}
});
test();
System.out.println("Test passed");
} finally {
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
}
}

private static void createAndShowGUI() {
Expand Down
61 changes: 33 additions & 28 deletions test/jdk/javax/swing/JComboBox/7195179/Test7195179.java
Expand Up @@ -42,43 +42,48 @@
*/

public class Test7195179 {
private static JFrame frame;
public static void main(String[] args) throws Exception {
invokeAndWait(new Runnable() {
@Override
public void run() {
Integer[] items = {null, 1, 2, 3};
JComboBox<Integer> combo = new JComboBox<>(items);
JLabel label = new JLabel("choose:");
JPanel panel = new JPanel();
GroupLayout layout = new GroupLayout(panel);
panel.setLayout(layout);
label.setLabelFor(combo);
combo.setSelectedIndex(0);
combo.setRenderer(new ListCellRenderer<Integer>() {
private final BasicComboBoxRenderer renderer = new BasicComboBoxRenderer();
try {
Integer[] items = {null, 1, 2, 3};
JComboBox<Integer> combo = new JComboBox<>(items);
JLabel label = new JLabel("choose:");
JPanel panel = new JPanel();
GroupLayout layout = new GroupLayout(panel);
panel.setLayout(layout);
label.setLabelFor(combo);
combo.setSelectedIndex(0);
combo.setRenderer(new ListCellRenderer<Integer>() {
private final BasicComboBoxRenderer renderer = new BasicComboBoxRenderer();

@Override
public Component getListCellRendererComponent(JList<? extends Integer> list, Integer value, int index, boolean isSelected, boolean cellHasFocus) {
return this.renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
});
layout.setAutoCreateContainerGaps(true);
layout.setAutoCreateGaps(true);
layout.setHorizontalGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup().addComponent(label))
.addGroup(layout.createParallelGroup().addComponent(combo)));
layout.setVerticalGroup(layout
.createSequentialGroup()
.addGroup(layout
@Override
public Component getListCellRendererComponent(JList<? extends Integer> list, Integer value, int index, boolean isSelected, boolean cellHasFocus) {
return this.renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
});
layout.setAutoCreateContainerGaps(true);
layout.setAutoCreateGaps(true);
layout.setHorizontalGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup().addComponent(label))
.addGroup(layout.createParallelGroup().addComponent(combo)));
layout.setVerticalGroup(layout
.createSequentialGroup()
.addGroup(layout
.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(label)
.addComponent(combo)));

JFrame frame = new JFrame(getClass().getSimpleName());
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
frame = new JFrame(getClass().getSimpleName());
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
} finally {
if (frame != null) frame.dispose();
}
}
});
}
Expand Down
4 changes: 3 additions & 1 deletion test/jdk/javax/swing/JComboBox/8057893/bug8057893.java
Expand Up @@ -43,13 +43,14 @@
public class bug8057893 {

private static volatile boolean isComboBoxEdited = false;
private static JFrame frame;

public static void main(String[] args) throws Exception {
Robot robot = new Robot();
robot.setAutoDelay(50);

EventQueue.invokeAndWait(() -> {
JFrame frame = new JFrame();
frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JComboBox<String> comboBox = new JComboBox<>(new String[]{"one", "two"});
comboBox.setEditable(true);
Expand All @@ -76,6 +77,7 @@ public void actionPerformed(ActionEvent e) {
robot.keyRelease(KeyEvent.VK_ENTER);
robot.waitForIdle();

if (frame != null) EventQueue.invokeAndWait(() -> frame.dispose());
if(!isComboBoxEdited){
throw new RuntimeException("ComboBoxEdited event is not fired!");
}
Expand Down

0 comments on commit 55f3fd9

Please sign in to comment.