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.util.concurrent.CountDownLatch;
29 import java.util.concurrent.TimeUnit;
30 import java.util.concurrent.atomic.AtomicBoolean;
31 import javafx.application.Platform;
32 import javafx.scene.Group;
33 import javafx.scene.Scene;
34 import javafx.scene.paint.Color;
35 import javafx.stage.Stage;
36 import junit.framework.AssertionFailedError;
37 import util.Util;
38
39 import static org.junit.Assert.*;
40 import static util.Util.TIMEOUT;
41
42 /**
43 * Test program for Platform finishListener
44 * Each of the tests must be run in a separate JVM which is why each
45 * is in its own subclass.
46 */
47 public class ListenerTestCommon {
48
49 // Short delay in milliseconds
50 private static final int DELAY = 10;
51
52 // Sleep time showing/hiding window in milliseconds
53 private static final int SLEEP_TIME = 1000;
54
55 // Used to launch the platform before running any test
56 private final CountDownLatch launchLatch = new CountDownLatch(1);
57
58 // Used to determine when the toolkit is shutdown
59 private CountDownLatch exitLatch;
60
72 EXCEPTION,
73 ERROR
74 }
75
76 private void setup() {
77 // Start the FX Platform
78 new Thread(() -> PlatformImpl.startup(() -> {
79 assertTrue(Platform.isFxApplicationThread());
80 launchLatch.countDown();
81 })).start();
82
83 try {
84 if (!launchLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)) {
85 throw new AssertionFailedError("Timeout waiting for Platform to start");
86 }
87 } catch (InterruptedException ex) {
88 AssertionFailedError err = new AssertionFailedError("Unexpected exception");
89 err.initCause(ex);
90 throw err;
91 }
92 exitLatch = PlatformImpl.test_getPlatformExitLatch();
93 assertEquals(1, exitLatch.getCount());
94 assertEquals(0, launchLatch.getCount());
95 assertEquals(1, exitLatch.getCount());
96 assertNull(listener);
97
98 listener = new PlatformImpl.FinishListener() {
99 public void idle(boolean flag) {
100 implicitExit.set(flag);
101 idleNotification.countDown();
102 }
103 public void exitCalled() {
104 exitNotification.countDown();
105 }
106 };
107 PlatformImpl.addListener(listener);
108 }
109
110 private Stage makeStage() {
111 Stage stg = new Stage();
112 stg.setTitle("Primary stage");
|
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.PlatformImpl;
29 import com.sun.javafx.application.PlatformImplShim;
30 import java.util.concurrent.CountDownLatch;
31 import java.util.concurrent.TimeUnit;
32 import java.util.concurrent.atomic.AtomicBoolean;
33 import javafx.application.Platform;
34 import javafx.scene.Group;
35 import javafx.scene.Scene;
36 import javafx.scene.paint.Color;
37 import javafx.stage.Stage;
38 import junit.framework.AssertionFailedError;
39 import test.util.Util;
40
41 import static org.junit.Assert.*;
42 import static test.util.Util.TIMEOUT;
43
44 /**
45 * Test program for Platform finishListener
46 * Each of the tests must be run in a separate JVM which is why each
47 * is in its own subclass.
48 */
49 public class ListenerTestCommon {
50
51 // Short delay in milliseconds
52 private static final int DELAY = 10;
53
54 // Sleep time showing/hiding window in milliseconds
55 private static final int SLEEP_TIME = 1000;
56
57 // Used to launch the platform before running any test
58 private final CountDownLatch launchLatch = new CountDownLatch(1);
59
60 // Used to determine when the toolkit is shutdown
61 private CountDownLatch exitLatch;
62
74 EXCEPTION,
75 ERROR
76 }
77
78 private void setup() {
79 // Start the FX Platform
80 new Thread(() -> PlatformImpl.startup(() -> {
81 assertTrue(Platform.isFxApplicationThread());
82 launchLatch.countDown();
83 })).start();
84
85 try {
86 if (!launchLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)) {
87 throw new AssertionFailedError("Timeout waiting for Platform to start");
88 }
89 } catch (InterruptedException ex) {
90 AssertionFailedError err = new AssertionFailedError("Unexpected exception");
91 err.initCause(ex);
92 throw err;
93 }
94 exitLatch = PlatformImplShim.test_getPlatformExitLatch();
95 assertEquals(1, exitLatch.getCount());
96 assertEquals(0, launchLatch.getCount());
97 assertEquals(1, exitLatch.getCount());
98 assertNull(listener);
99
100 listener = new PlatformImpl.FinishListener() {
101 public void idle(boolean flag) {
102 implicitExit.set(flag);
103 idleNotification.countDown();
104 }
105 public void exitCalled() {
106 exitNotification.countDown();
107 }
108 };
109 PlatformImpl.addListener(listener);
110 }
111
112 private Stage makeStage() {
113 Stage stg = new Stage();
114 stg.setTitle("Primary stage");
|