< prev index next >

tests/system/src/test/java/test/com/sun/javafx/application/SwingExitCommon.java

Print this page
rev 9491 : 8145203: Refactor systemTests for clear separation of tests
Reviewed-by: kcr


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.application;
  27 

  28 import java.awt.BorderLayout;
  29 import javax.swing.SwingUtilities;
  30 import java.awt.Dimension;
  31 import java.lang.reflect.InvocationTargetException;
  32 import java.util.concurrent.CountDownLatch;
  33 import java.util.concurrent.TimeUnit;
  34 import javafx.application.Platform;
  35 import javafx.embed.swing.JFXPanel;
  36 import javafx.scene.Group;
  37 import javafx.scene.Scene;
  38 import javafx.scene.paint.Color;
  39 import javax.swing.JFrame;
  40 import junit.framework.AssertionFailedError;
  41 import util.Util;
  42 
  43 import static org.junit.Assert.*;
  44 import static util.Util.TIMEOUT;
  45 
  46 /**
  47  * Test program for Platform implicit exit behavior using an embedded JFXPanel.
  48  * Each of the tests must be run in a separate JVM which is why each
  49  * is in its own subclass.
  50  */
  51 public class SwingExitCommon {
  52 
  53     // Sleep time showing/hiding window in milliseconds
  54     private static final int SLEEP_TIME = 1000;
  55 
  56     // Used to launch the application before running any test
  57     private static final CountDownLatch initialized = new CountDownLatch(1);
  58 
  59     // Value of the implicit exit flag for the given test
  60     private static volatile boolean implicitExit;
  61 
  62     private JFrame frame;
  63     private JFXPanel fxPanel;
  64 


 116         });
 117 
 118         try {
 119             if (!initialized.await(TIMEOUT, TimeUnit.MILLISECONDS)) {
 120                 throw new AssertionFailedError("Timeout waiting for JFXPanel to launch and initialize");
 121             }
 122 
 123             Thread.sleep(SLEEP_TIME);
 124             try {
 125                 SwingUtilities.invokeAndWait(() -> {
 126                     frame.setVisible(false);
 127                     frame.dispose();
 128                 });
 129             }
 130             catch (InvocationTargetException ex) {
 131                 AssertionFailedError err = new AssertionFailedError("Exception while disposing JFrame");
 132                 err.initCause(ex.getCause());
 133                 throw err;
 134             }
 135 
 136             final CountDownLatch exitLatch = PlatformImpl.test_getPlatformExitLatch();
 137 
 138             if (reEnableImplicitExit) {
 139                 Thread.sleep(SLEEP_TIME);
 140                 assertEquals(1, exitLatch.getCount());
 141                 assertFalse(Platform.isImplicitExit());
 142                 Platform.setImplicitExit(true);
 143                 assertTrue(Platform.isImplicitExit());
 144             }
 145 
 146             if (!appShouldExit) {
 147                 Thread.sleep(SLEEP_TIME);
 148                 assertEquals(1, exitLatch.getCount());
 149                 Platform.exit();
 150             }
 151 
 152             if (!exitLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)) {
 153                 throw new AssertionFailedError("Timeout waiting for Platform to exit");
 154             }
 155         } catch (InterruptedException ex) {
 156             Util.throwError(testError[0]);




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package test.com.sun.javafx.application;
  27 
  28 import com.sun.javafx.application.PlatformImplShim;
  29 import java.awt.BorderLayout;
  30 import javax.swing.SwingUtilities;
  31 import java.awt.Dimension;
  32 import java.lang.reflect.InvocationTargetException;
  33 import java.util.concurrent.CountDownLatch;
  34 import java.util.concurrent.TimeUnit;
  35 import javafx.application.Platform;
  36 import javafx.embed.swing.JFXPanel;
  37 import javafx.scene.Group;
  38 import javafx.scene.Scene;
  39 import javafx.scene.paint.Color;
  40 import javax.swing.JFrame;
  41 import junit.framework.AssertionFailedError;
  42 import test.util.Util;
  43 
  44 import static org.junit.Assert.*;
  45 import static test.util.Util.TIMEOUT;
  46 
  47 /**
  48  * Test program for Platform implicit exit behavior using an embedded JFXPanel.
  49  * Each of the tests must be run in a separate JVM which is why each
  50  * is in its own subclass.
  51  */
  52 public class SwingExitCommon {
  53 
  54     // Sleep time showing/hiding window in milliseconds
  55     private static final int SLEEP_TIME = 1000;
  56 
  57     // Used to launch the application before running any test
  58     private static final CountDownLatch initialized = new CountDownLatch(1);
  59 
  60     // Value of the implicit exit flag for the given test
  61     private static volatile boolean implicitExit;
  62 
  63     private JFrame frame;
  64     private JFXPanel fxPanel;
  65 


 117         });
 118 
 119         try {
 120             if (!initialized.await(TIMEOUT, TimeUnit.MILLISECONDS)) {
 121                 throw new AssertionFailedError("Timeout waiting for JFXPanel to launch and initialize");
 122             }
 123 
 124             Thread.sleep(SLEEP_TIME);
 125             try {
 126                 SwingUtilities.invokeAndWait(() -> {
 127                     frame.setVisible(false);
 128                     frame.dispose();
 129                 });
 130             }
 131             catch (InvocationTargetException ex) {
 132                 AssertionFailedError err = new AssertionFailedError("Exception while disposing JFrame");
 133                 err.initCause(ex.getCause());
 134                 throw err;
 135             }
 136 
 137             final CountDownLatch exitLatch = PlatformImplShim.test_getPlatformExitLatch();
 138 
 139             if (reEnableImplicitExit) {
 140                 Thread.sleep(SLEEP_TIME);
 141                 assertEquals(1, exitLatch.getCount());
 142                 assertFalse(Platform.isImplicitExit());
 143                 Platform.setImplicitExit(true);
 144                 assertTrue(Platform.isImplicitExit());
 145             }
 146 
 147             if (!appShouldExit) {
 148                 Thread.sleep(SLEEP_TIME);
 149                 assertEquals(1, exitLatch.getCount());
 150                 Platform.exit();
 151             }
 152 
 153             if (!exitLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)) {
 154                 throw new AssertionFailedError("Timeout waiting for Platform to exit");
 155             }
 156         } catch (InterruptedException ex) {
 157             Util.throwError(testError[0]);


< prev index next >