From 6edde99f98ee91db06731be9395377ed91aba215 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 23 Oct 2011 22:40:00 +0200 Subject: Tests: AWT EDT: invokeLater(..) -> invokeAndWait(..) for a more predictable workflow --- .../opengl/test/junit/newt/TestCloseNewtAWT.java | 4 +- .../test/junit/newt/TestEventSourceNotAWTBug.java | 7 +- .../junit/newt/TestWindowClosingProtocol01AWT.java | 8 +- .../newt/TestWindowClosingProtocol03NewtAWT.java | 4 +- .../junit/newt/parenting/TestParenting01aAWT.java | 101 ++++++++++++++------- .../junit/newt/parenting/TestParenting01bAWT.java | 17 ++-- .../junit/newt/parenting/TestParenting01cAWT.java | 35 ++++--- .../newt/parenting/TestParenting01cSwingAWT.java | 6 +- .../junit/newt/parenting/TestParenting02AWT.java | 5 +- .../junit/newt/parenting/TestParenting03AWT.java | 5 +- 10 files changed, 120 insertions(+), 72 deletions(-) (limited to 'src') diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java index 69f9da052..adc885191 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java @@ -97,7 +97,7 @@ public class TestCloseNewtAWT extends UITestCase { newtWindow = GLWindow.create(new GLCapabilities(GLProfile.getDefault())); newtCanvas = new MyCanvas(newtWindow); - SwingUtilities.invokeLater(new Runnable() { + SwingUtilities.invokeAndWait(new Runnable() { public void run() { frame = new JFrame("NEWT Close Test"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); @@ -107,7 +107,7 @@ public class TestCloseNewtAWT extends UITestCase { frame.setVisible(true); } }); - Thread.sleep(1000); + Thread.sleep(500); Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, true)); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestEventSourceNotAWTBug.java b/src/test/com/jogamp/opengl/test/junit/newt/TestEventSourceNotAWTBug.java index e6f3f0ac9..7956e22e6 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestEventSourceNotAWTBug.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestEventSourceNotAWTBug.java @@ -32,6 +32,7 @@ import org.junit.BeforeClass; import org.junit.Test; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; @@ -54,7 +55,7 @@ public class TestEventSourceNotAWTBug extends UITestCase { } @Test - public void testEventSourceNotNewtBug() throws InterruptedException { + public void testEventSourceNotNewtBug() throws InterruptedException, InvocationTargetException { JFrame jf = new JFrame(); jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); @@ -69,7 +70,7 @@ public class TestEventSourceNotAWTBug extends UITestCase { final JFrame f_jf = jf; - SwingUtilities.invokeLater(new Runnable() { + SwingUtilities.invokeAndWait(new Runnable() { public void run() { f_jf.setSize(800, 600); f_jf.setVisible(true); @@ -78,7 +79,7 @@ public class TestEventSourceNotAWTBug extends UITestCase { Thread.sleep(500); - SwingUtilities.invokeLater(new Runnable() { + SwingUtilities.invokeAndWait(new Runnable() { public void run() { f_jf.dispose(); } diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol01AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol01AWT.java index 710681779..be824c2c4 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol01AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol01AWT.java @@ -57,7 +57,7 @@ public class TestWindowClosingProtocol01AWT extends UITestCase { GLCapabilities caps = new GLCapabilities(glp); final GLCanvas glCanvas = new GLCanvas(caps); glCanvas.addGLEventListener(new GearsES2()); - SwingUtilities.invokeLater(new Runnable() { + SwingUtilities.invokeAndWait(new Runnable() { public void run() { frame.add(glCanvas); frame.pack(); @@ -94,7 +94,7 @@ public class TestWindowClosingProtocol01AWT extends UITestCase { Assert.assertEquals(true, frame.isVisible()); Assert.assertEquals(false, glCanvas.isRealized()); - SwingUtilities.invokeLater(new Runnable() { + SwingUtilities.invokeAndWait(new Runnable() { public void run() { frame.dispose(); } }); @@ -112,7 +112,7 @@ public class TestWindowClosingProtocol01AWT extends UITestCase { frame.pack(); frame.setSize(512, 512); frame.validate(); - SwingUtilities.invokeLater(new Runnable() { + SwingUtilities.invokeAndWait(new Runnable() { public void run() { frame.setVisible(true); } }); @@ -132,7 +132,7 @@ public class TestWindowClosingProtocol01AWT extends UITestCase { Assert.assertEquals(true, glCanvas.isValid()); Assert.assertEquals(true, glCanvas.isDisplayable()); - SwingUtilities.invokeLater(new Runnable() { + SwingUtilities.invokeAndWait(new Runnable() { public void run() { frame.setVisible(true); } }); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol03NewtAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol03NewtAWT.java index c14c461f7..19b2bbbf6 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol03NewtAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol03NewtAWT.java @@ -62,7 +62,7 @@ public class TestWindowClosingProtocol03NewtAWT extends UITestCase { final NewtCanvasAWT newtCanvas = new NewtCanvasAWT(glWindow); - SwingUtilities.invokeLater(new Runnable() { + SwingUtilities.invokeAndWait(new Runnable() { public void run() { frame.getContentPane().add(newtCanvas); frame.pack(); @@ -94,7 +94,7 @@ public class TestWindowClosingProtocol03NewtAWT extends UITestCase { Assert.assertEquals(true, windowClosingListener.isWindowClosing()); windowClosingListener.reset(); - SwingUtilities.invokeLater(new Runnable() { + SwingUtilities.invokeAndWait(new Runnable() { public void run() { frame.setVisible(true); } }); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aAWT.java index e1a9cd51c..674cf4a06 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aAWT.java @@ -45,6 +45,7 @@ import com.jogamp.newt.opengl.*; import com.jogamp.newt.awt.NewtCanvasAWT; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import com.jogamp.opengl.test.junit.util.*; import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2; @@ -64,8 +65,8 @@ public class TestParenting01aAWT extends UITestCase { } @Test - public void testWindowParenting01CreateVisibleDestroy1() throws InterruptedException { - GLWindow glWindow1 = GLWindow.create(glCaps); + public void testWindowParenting01CreateVisibleDestroy1() throws InterruptedException, InvocationTargetException { + final GLWindow glWindow1 = GLWindow.create(glCaps); Assert.assertNotNull(glWindow1); Assert.assertEquals(false, glWindow1.isVisible()); Assert.assertEquals(false, glWindow1.isNativeValid()); @@ -75,7 +76,7 @@ public class TestParenting01aAWT extends UITestCase { setDemoFields(demo1, glWindow1, false); glWindow1.addGLEventListener(demo1); - NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); + final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); Assert.assertNotNull(newtCanvasAWT); Assert.assertEquals(false, glWindow1.isVisible()); Assert.assertEquals(false, glWindow1.isNativeValid()); @@ -88,7 +89,7 @@ public class TestParenting01aAWT extends UITestCase { frame1.add(new Button("East"), BorderLayout.EAST); frame1.add(new Button("West"), BorderLayout.WEST); - Container container1 = new Container(); + final Container container1 = new Container(); container1.setLayout(new BorderLayout()); container1.add(new Button("north"), BorderLayout.NORTH); container1.add(new Button("south"), BorderLayout.SOUTH); @@ -100,33 +101,48 @@ public class TestParenting01aAWT extends UITestCase { frame1.setSize(width, height); // visible test - SwingUtilities.invokeLater(new Runnable() { + SwingUtilities.invokeAndWait(new Runnable() { public void run() { frame1.setVisible(true); } }); Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); - Animator animator1 = new Animator(glWindow1); + final Animator animator1 = new Animator(glWindow1); animator1.setUpdateFPSFrames(1, null); animator1.start(); + Assert.assertTrue(AWTRobotUtil.waitForRealized(glWindow1, true)); + Assert.assertTrue(AWTRobotUtil.waitForVisible(glWindow1, true)); + while(animator1.isAnimating() && animator1.getTotalFPSDuration()