From f74e98c9471cd08573ac656a39eeaf09bdf4b24e Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 12 Oct 2011 02:57:26 +0200 Subject: NEWT Parenting Tests: Run all AWT modification call's on AWT EDT as the spec demands; Add missing frame.validate() after change. This is esential for OSX, but may also cause an undefined state on other platforms. --- .../junit/newt/parenting/TestParenting01aAWT.java | 132 ++++++++++--- .../junit/newt/parenting/TestParenting01bAWT.java | 30 ++- .../junit/newt/parenting/TestParenting01cAWT.java | 76 ++++++-- .../newt/parenting/TestParenting01cSwingAWT.java | 31 ++- .../junit/newt/parenting/TestParenting02AWT.java | 1 + .../junit/newt/parenting/TestParenting03AWT.java | 90 +++++---- .../junit/newt/parenting/TestParenting03bAWT.java | 207 --------------------- .../parenting/TestTranslucentParentingAWT.java | 202 ++++++++++++++++++++ 8 files changed, 461 insertions(+), 308 deletions(-) delete mode 100644 src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03bAWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/parenting/TestTranslucentParentingAWT.java (limited to 'src/test/com/jogamp/opengl') 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 2da3188e2..e1a9cd51c 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 @@ -38,6 +38,7 @@ import java.awt.Container; import java.awt.Frame; import javax.media.opengl.*; +import javax.swing.SwingUtilities; import com.jogamp.opengl.util.Animator; import com.jogamp.newt.opengl.*; @@ -80,7 +81,7 @@ public class TestParenting01aAWT extends UITestCase { Assert.assertEquals(false, glWindow1.isNativeValid()); Assert.assertNull(glWindow1.getParent()); - Frame frame1 = new Frame("AWT Parent Frame"); + final Frame frame1 = new Frame("AWT Parent Frame"); frame1.setLayout(new BorderLayout()); frame1.add(new Button("North"), BorderLayout.NORTH); frame1.add(new Button("South"), BorderLayout.SOUTH); @@ -99,7 +100,11 @@ public class TestParenting01aAWT extends UITestCase { frame1.setSize(width, height); // visible test - frame1.setVisible(true); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame1.setVisible(true); + } + }); Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); Animator animator1 = new Animator(glWindow1); @@ -139,20 +144,29 @@ 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()); Assert.assertNull(glWindow1.getParent()); - Frame frame = new Frame("AWT Parent Frame"); + final Frame frame = new Frame("AWT Parent Frame"); Assert.assertNotNull(frame); frame.setSize(width, height); // visible test - frame.setVisible(true); - - frame.add(newtCanvasAWT); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame.setVisible(true); + } + }); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame.add(newtCanvasAWT); + frame.validate(); + } + }); Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); Animator animator1 = new Animator(glWindow1); @@ -175,16 +189,25 @@ public class TestParenting01aAWT extends UITestCase { setDemoFields(demo1, glWindow1, false); glWindow1.addGLEventListener(demo1); - NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); + final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); - Frame frame = new Frame("AWT Parent Frame"); + final Frame frame = new Frame("AWT Parent Frame"); Assert.assertNotNull(frame); frame.setSize(width, height); // visible test - frame.setVisible(true); - - frame.add(newtCanvasAWT); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame.setVisible(true); + } + }); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame.add(newtCanvasAWT); + frame.validate(); + } + }); Animator animator1 = new Animator(glWindow1); animator1.setUpdateFPSFrames(1, null); @@ -208,14 +231,24 @@ public class TestParenting01aAWT extends UITestCase { setDemoFields(demo1, glWindow1, false); glWindow1.addGLEventListener(demo1); - NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); + final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); - Frame frame = new Frame("AWT Parent Frame"); + final Frame frame = new Frame("AWT Parent Frame"); frame.setSize(width, height); frame.setLocation(640, 480); - frame.setVisible(true); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame.setVisible(true); + } + }); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame.add(newtCanvasAWT); + frame.validate(); + } + }); - frame.add(newtCanvasAWT); Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); Animator animator1 = new Animator(glWindow1); @@ -254,9 +287,9 @@ public class TestParenting01aAWT extends UITestCase { setDemoFields(demo1, glWindow1, false); glWindow1.addGLEventListener(demo1); - NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); + final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); - Frame frame = new Frame("AWT Parent Frame"); + final Frame frame = new Frame("AWT Parent Frame"); frame.setLayout(new BorderLayout()); frame.add(new Button("North"), BorderLayout.NORTH); frame.add(new Button("South"), BorderLayout.SOUTH); @@ -264,9 +297,20 @@ public class TestParenting01aAWT extends UITestCase { frame.add(new Button("West"), BorderLayout.WEST); frame.setSize(width, height); frame.setLocation(640, 480); - frame.setVisible(true); - - frame.add(newtCanvasAWT, BorderLayout.CENTER); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame.setVisible(true); + } + }); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame.add(newtCanvasAWT, BorderLayout.CENTER); + frame.validate(); + } + }); + Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); Animator animator1 = new Animator(glWindow1); @@ -306,9 +350,9 @@ public class TestParenting01aAWT extends UITestCase { setDemoFields(demo1, glWindow1, false); glWindow1.addGLEventListener(demo1); - NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); + final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); - Frame frame1 = new Frame("AWT Parent Frame"); + final Frame frame1 = new Frame("AWT Parent Frame"); frame1.setLayout(new BorderLayout()); frame1.add(new Button("North"), BorderLayout.NORTH); frame1.add(new Button("South"), BorderLayout.SOUTH); @@ -316,9 +360,13 @@ public class TestParenting01aAWT extends UITestCase { frame1.add(new Button("West"), BorderLayout.WEST); frame1.setSize(width, height); frame1.setLocation(0, 0); - frame1.setVisible(true); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame1.setVisible(true); + } + }); - Frame frame2 = new Frame("AWT Parent Frame"); + final Frame frame2 = new Frame("AWT Parent Frame"); frame2.setLayout(new BorderLayout()); frame2.add(new Button("North"), BorderLayout.NORTH); frame2.add(new Button("South"), BorderLayout.SOUTH); @@ -326,9 +374,19 @@ public class TestParenting01aAWT extends UITestCase { frame2.add(new Button("West"), BorderLayout.WEST); frame2.setSize(width, height); frame2.setLocation(640, 480); - frame2.setVisible(true); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame2.setVisible(true); + } + }); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame1.add(newtCanvasAWT, BorderLayout.CENTER); + frame1.validate(); + } + }); - frame1.add(newtCanvasAWT, BorderLayout.CENTER); Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); Animator animator1 = new Animator(glWindow1); @@ -340,12 +398,24 @@ public class TestParenting01aAWT extends UITestCase { Thread.sleep(durationPerTest); switch(state) { case 0: - frame1.remove(newtCanvasAWT); - frame2.add(newtCanvasAWT, BorderLayout.CENTER); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame1.remove(newtCanvasAWT); + frame2.add(newtCanvasAWT, BorderLayout.CENTER); + frame1.validate(); + frame2.validate(); + } + }); break; case 1: - frame2.remove(newtCanvasAWT); - frame1.add(newtCanvasAWT, BorderLayout.CENTER); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame2.remove(newtCanvasAWT); + frame1.add(newtCanvasAWT, BorderLayout.CENTER); + frame2.validate(); + frame1.validate(); + } + }); break; } state++; diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01bAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01bAWT.java index fb93ad92f..0a0486558 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01bAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01bAWT.java @@ -46,6 +46,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,16 +65,16 @@ public class TestParenting01bAWT extends UITestCase { } @Test - public void testWindowParenting05ReparentAWTWinHopFrame2FrameFPS25Animator() throws InterruptedException { + public void testWindowParenting05ReparentAWTWinHopFrame2FrameFPS25Animator() throws InterruptedException, InvocationTargetException { testWindowParenting05ReparentAWTWinHopFrame2FrameImpl(25); } @Test - public void testWindowParenting05ReparentAWTWinHopFrame2FrameStdAnimator() throws InterruptedException { + public void testWindowParenting05ReparentAWTWinHopFrame2FrameStdAnimator() throws InterruptedException, InvocationTargetException { testWindowParenting05ReparentAWTWinHopFrame2FrameImpl(0); } - public void testWindowParenting05ReparentAWTWinHopFrame2FrameImpl(int fps) throws InterruptedException { + public void testWindowParenting05ReparentAWTWinHopFrame2FrameImpl(int fps) throws InterruptedException, InvocationTargetException { GLWindow glWindow1 = GLWindow.create(glCaps); glWindow1.setUndecorated(true); GLEventListener demo1 = new RedSquareES2(); @@ -81,7 +82,7 @@ public class TestParenting01bAWT extends UITestCase { glWindow1.addGLEventListener(demo1); final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); - + final Frame frame1 = new Frame("AWT Parent Frame"); frame1.setLayout(new BorderLayout()); frame1.add(new Button("North"), BorderLayout.NORTH); @@ -90,7 +91,11 @@ public class TestParenting01bAWT extends UITestCase { frame1.add(new Button("West"), BorderLayout.WEST); frame1.setSize(width, height); frame1.setLocation(0, 0); - frame1.setVisible(true); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame1.setVisible(true); + } + }); final Frame frame2 = new Frame("AWT Parent Frame"); frame2.setLayout(new BorderLayout()); @@ -100,9 +105,18 @@ public class TestParenting01bAWT extends UITestCase { frame2.add(new Button("West"), BorderLayout.WEST); frame2.setSize(width, height); frame2.setLocation(640, 480); - frame2.setVisible(true); - - frame1.add(newtCanvasAWT, BorderLayout.CENTER); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame2.setVisible(true); + } + }); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame1.add(newtCanvasAWT, BorderLayout.CENTER); + frame1.validate(); + } + }); Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); GLAnimatorControl animator1; diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cAWT.java index 4477c3f8e..fa88415e4 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cAWT.java @@ -38,6 +38,7 @@ import java.awt.Container; import java.awt.Frame; import javax.media.opengl.*; +import javax.swing.SwingUtilities; import com.jogamp.newt.*; import com.jogamp.newt.opengl.*; @@ -74,13 +75,13 @@ public class TestParenting01cAWT 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()); Assert.assertNull(glWindow1.getParent()); - Frame frame1 = new Frame("AWT Parent Frame"); + final Frame frame1 = new Frame("AWT Parent Frame"); frame1.setLayout(new BorderLayout()); frame1.add(new Button("North"), BorderLayout.NORTH); frame1.add(new Button("South"), BorderLayout.SOUTH); @@ -99,20 +100,36 @@ public class TestParenting01cAWT extends UITestCase { frame1.setSize(width, height); // visible test - frame1.setVisible(true); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame1.setVisible(true); + } + }); Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); for(i=0; i*100