< prev index next >

test/jdk/javax/swing/DefaultButtonModel/DefaultButtonModelCrashTest.java

Print this page
rev 48027 : 8191678: [TESTBUG] Add keyword headful in java/awt and javax tests.
Summary: Also fix some NPE thrown if run headless.


   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 /*

  24  * @test
  25  * @bug 8182577
  26  * @summary  Verifies if moving focus via custom ButtonModel causes crash

  27  * @run main DefaultButtonModelCrashTest
  28  */

  29 import java.awt.BorderLayout;
  30 import java.awt.Container;
  31 import java.awt.Point;
  32 import java.awt.Robot;
  33 import java.awt.event.KeyEvent;
  34 import javax.swing.ButtonModel;
  35 import javax.swing.DefaultButtonModel;
  36 import javax.swing.JCheckBox;
  37 import javax.swing.JComponent;
  38 import javax.swing.JFrame;
  39 import javax.swing.JPanel;
  40 import javax.swing.JTextField;
  41 import javax.swing.SwingUtilities;
  42 
  43 public class DefaultButtonModelCrashTest {
  44     private JFrame frame = null;
  45     private JPanel panel;
  46     private volatile Point p = null;
  47 
  48     public static void main(String[] args) throws Exception {
  49         new DefaultButtonModelCrashTest();
  50     }
  51 
  52     public DefaultButtonModelCrashTest() throws Exception {
  53         try {
  54             Robot robot = new Robot();
  55             robot.setAutoDelay(200);
  56             SwingUtilities.invokeAndWait(() -> go());
  57             robot.waitForIdle();
  58             robot.keyPress(KeyEvent.VK_TAB);
  59             robot.keyRelease(KeyEvent.VK_TAB);
  60             robot.delay(100);
  61             robot.keyPress(KeyEvent.VK_TAB);
  62             robot.keyRelease(KeyEvent.VK_TAB);
  63         } finally {
  64             SwingUtilities.invokeAndWait(()->frame  .dispose());
  65         }
  66     }
  67 
  68     private void go() {
  69 
  70         frame = new JFrame();
  71         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  72         Container contentPane = frame.getContentPane();
  73         ButtonModel model = new DefaultButtonModel();
  74 
  75         JCheckBox check = new JCheckBox("a bit broken");
  76         check.setModel(model);
  77         panel = new JPanel(new BorderLayout());
  78         panel.add(new JTextField("Press Tab (twice?)"), BorderLayout.NORTH);
  79         panel.add(check);
  80         contentPane.add(panel);
  81         frame.setLocationRelativeTo(null);
  82         frame.pack();
  83         frame.setVisible(true);
  84     }


   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @bug 8182577
  27  * @summary  Verifies if moving focus via custom ButtonModel causes crash
  28  * @key headful
  29  * @run main DefaultButtonModelCrashTest
  30  */
  31 
  32 import java.awt.BorderLayout;
  33 import java.awt.Container;
  34 import java.awt.Point;
  35 import java.awt.Robot;
  36 import java.awt.event.KeyEvent;
  37 import javax.swing.ButtonModel;
  38 import javax.swing.DefaultButtonModel;
  39 import javax.swing.JCheckBox;
  40 import javax.swing.JComponent;
  41 import javax.swing.JFrame;
  42 import javax.swing.JPanel;
  43 import javax.swing.JTextField;
  44 import javax.swing.SwingUtilities;
  45 
  46 public class DefaultButtonModelCrashTest {
  47     private JFrame frame = null;
  48     private JPanel panel;
  49     private volatile Point p = null;
  50 
  51     public static void main(String[] args) throws Exception {
  52         new DefaultButtonModelCrashTest();
  53     }
  54 
  55     public DefaultButtonModelCrashTest() throws Exception {
  56         try {
  57             Robot robot = new Robot();
  58             robot.setAutoDelay(200);
  59             SwingUtilities.invokeAndWait(() -> go());
  60             robot.waitForIdle();
  61             robot.keyPress(KeyEvent.VK_TAB);
  62             robot.keyRelease(KeyEvent.VK_TAB);
  63             robot.delay(100);
  64             robot.keyPress(KeyEvent.VK_TAB);
  65             robot.keyRelease(KeyEvent.VK_TAB);
  66         } finally {
  67             if (frame != null) { SwingUtilities.invokeAndWait(()->frame.dispose()); }
  68         }
  69     }
  70 
  71     private void go() {
  72 
  73         frame = new JFrame();
  74         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  75         Container contentPane = frame.getContentPane();
  76         ButtonModel model = new DefaultButtonModel();
  77 
  78         JCheckBox check = new JCheckBox("a bit broken");
  79         check.setModel(model);
  80         panel = new JPanel(new BorderLayout());
  81         panel.add(new JTextField("Press Tab (twice?)"), BorderLayout.NORTH);
  82         panel.add(check);
  83         contentPane.add(panel);
  84         frame.setLocationRelativeTo(null);
  85         frame.pack();
  86         frame.setVisible(true);
  87     }
< prev index next >