diff options
author | Sven Gothel <[email protected]> | 2011-09-16 07:26:34 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-09-16 07:26:34 +0200 |
commit | 4e3f2e5bf35c05e0c7ccf4995bcb4dbdf23f18cd (patch) | |
tree | 39b7ce8bdbc23bee01d694d7a1c28d1462f484ec /src/test | |
parent | 3b402dad37065c17e657aa276b838739755ef477 (diff) |
Fix AWT Test Cases: Use AWT-EDT for modifying visible frame and call validate() afterwards
Diffstat (limited to 'src/test')
3 files changed, 84 insertions, 58 deletions
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 da556b3c6..fb93ad92f 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 @@ -37,11 +37,11 @@ import java.awt.BorderLayout; import java.awt.Frame; import javax.media.opengl.*; +import javax.swing.SwingUtilities; import com.jogamp.opengl.util.Animator; import com.jogamp.opengl.util.FPSAnimator; import com.jogamp.newt.*; -import com.jogamp.newt.event.*; import com.jogamp.newt.opengl.*; import com.jogamp.newt.awt.NewtCanvasAWT; @@ -80,9 +80,9 @@ public class TestParenting01bAWT 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); @@ -92,7 +92,7 @@ public class TestParenting01bAWT extends UITestCase { frame1.setLocation(0, 0); 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); @@ -118,12 +118,24 @@ public class TestParenting01bAWT 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; } } diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java index 8ee91ddfb..478e00007 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java @@ -101,13 +101,13 @@ public class TestParenting01cSwingAWT extends UITestCase { disturbanceThread.start(); - 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()); - 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); @@ -115,7 +115,7 @@ public class TestParenting01cSwingAWT extends UITestCase { container1.add(new Button("west"), BorderLayout.WEST); container1.add(newtCanvasAWT, BorderLayout.CENTER); - JPanel jPanel1 = new JPanel(); + final JPanel jPanel1 = new JPanel(); jPanel1.setLayout(new BorderLayout()); jPanel1.add(new Button("north"), BorderLayout.NORTH); jPanel1.add(new Button("south"), BorderLayout.SOUTH); @@ -123,7 +123,7 @@ public class TestParenting01cSwingAWT extends UITestCase { jPanel1.add(new Button("west"), BorderLayout.WEST); jPanel1.add(container1, BorderLayout.CENTER); - JFrame jFrame1 = new JFrame("Swing Parent JFrame"); + final JFrame jFrame1 = new JFrame("Swing Parent JFrame"); // jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jFrame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event! jFrame1.setContentPane(jPanel1); @@ -131,10 +131,6 @@ public class TestParenting01cSwingAWT extends UITestCase { System.out.println("Demos: 1 - Visible"); jFrame1.setVisible(true); // from here on, we need to run modifications on EDT - final JFrame _jFrame1 = jFrame1; - final JPanel _jPanel1 = jPanel1; - final Container _container1 = container1; - // visible test Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); @@ -148,28 +144,29 @@ public class TestParenting01cSwingAWT extends UITestCase { SwingUtilities.invokeAndWait(new Runnable() { public void run() { System.out.println("Demos: 3 - !Visible"); - _jFrame1.setVisible(false); + jFrame1.setVisible(false); } }); Assert.assertEquals(true, glWindow1.isNativeValid()); SwingUtilities.invokeAndWait(new Runnable() { public void run() { System.out.println("Demos: 4 - Visible"); - _jFrame1.setVisible(true); + jFrame1.setVisible(true); } }); Assert.assertEquals(true, glWindow1.isNativeValid()); SwingUtilities.invokeAndWait(new Runnable() { public void run() { System.out.println("Demos: 5 - X Container"); - _jPanel1.remove(_container1); + jPanel1.remove(container1); + jFrame1.validate(); } }); // Assert.assertNull(glWindow1.getParent()); Assert.assertEquals(true, glWindow1.isNativeValid()); SwingUtilities.invokeAndWait(new Runnable() { public void run() { - _jFrame1.dispose(); + jFrame1.dispose(); } }); Assert.assertEquals(true, glWindow1.isNativeValid()); @@ -211,13 +208,13 @@ public class TestParenting01cSwingAWT extends UITestCase { }); disturbanceThread.start(); - 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()); - 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); @@ -225,7 +222,7 @@ public class TestParenting01cSwingAWT extends UITestCase { container1.add(new Button("west"), BorderLayout.WEST); container1.add(newtCanvasAWT, BorderLayout.CENTER); - JPanel jPanel1 = new JPanel(); + final JPanel jPanel1 = new JPanel(); jPanel1.setLayout(new BorderLayout()); jPanel1.add(new Button("north"), BorderLayout.NORTH); jPanel1.add(new Button("south"), BorderLayout.SOUTH); @@ -233,7 +230,7 @@ public class TestParenting01cSwingAWT extends UITestCase { jPanel1.add(new Button("west"), BorderLayout.WEST); jPanel1.add(container1, BorderLayout.CENTER); - JFrame jFrame1 = new JFrame("Swing Parent JFrame"); + final JFrame jFrame1 = new JFrame("Swing Parent JFrame"); // jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jFrame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event! jFrame1.setContentPane(jPanel1); @@ -241,14 +238,14 @@ public class TestParenting01cSwingAWT extends UITestCase { jFrame1.setSize(width, height); jFrame1.setVisible(true); // from here on, we need to run modifications on EDT - JPanel jPanel2 = new JPanel(); + final JPanel jPanel2 = new JPanel(); jPanel2.setLayout(new BorderLayout()); jPanel2.add(new Button("north"), BorderLayout.NORTH); jPanel2.add(new Button("south"), BorderLayout.SOUTH); jPanel2.add(new Button("east"), BorderLayout.EAST); jPanel2.add(new Button("west"), BorderLayout.WEST); - JFrame jFrame2 = new JFrame("Swing Parent JFrame"); + final JFrame jFrame2 = new JFrame("Swing Parent JFrame"); // jFrame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jFrame2.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event! jFrame2.setContentPane(jPanel2); @@ -256,12 +253,6 @@ public class TestParenting01cSwingAWT extends UITestCase { jFrame2.setSize(width, height); jFrame2.setVisible(true); // from here on, we need to run modifications on EDT - final NewtCanvasAWT _newtCanvasAWT = newtCanvasAWT; - final JFrame _jFrame1 = jFrame1; - final Container _container1 = container1; - final JFrame _jFrame2 = jFrame2; - final JPanel _jPanel2 = jPanel2; - // visible test Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); @@ -272,15 +263,19 @@ public class TestParenting01cSwingAWT extends UITestCase { case 0: SwingUtilities.invokeAndWait(new Runnable() { public void run() { - _container1.remove(_newtCanvasAWT); - _jPanel2.add(_newtCanvasAWT, BorderLayout.CENTER); + container1.remove(newtCanvasAWT); + jPanel2.add(newtCanvasAWT, BorderLayout.CENTER); + jFrame1.validate(); + jFrame2.validate(); } }); break; case 1: SwingUtilities.invokeAndWait(new Runnable() { public void run() { - _jPanel2.remove(_newtCanvasAWT); - _container1.add(_newtCanvasAWT, BorderLayout.CENTER); + jPanel2.remove(newtCanvasAWT); + container1.add(newtCanvasAWT, BorderLayout.CENTER); + jFrame1.validate(); + jFrame2.validate(); } }); break; } @@ -292,15 +287,15 @@ public class TestParenting01cSwingAWT extends UITestCase { SwingUtilities.invokeAndWait(new Runnable() { public void run() { - _jFrame1.setVisible(false); - _jFrame2.setVisible(false); + jFrame1.setVisible(false); + jFrame2.setVisible(false); } }); Assert.assertEquals(true, glWindow1.isNativeValid()); SwingUtilities.invokeAndWait(new Runnable() { public void run() { - _jFrame1.dispose(); - _jFrame2.dispose(); + jFrame1.dispose(); + jFrame2.dispose(); } }); Assert.assertEquals(true, glWindow1.isNativeValid()); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02AWT.java index 6257436e8..3ce1f5079 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02AWT.java @@ -44,6 +44,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.GearsES2; @@ -61,46 +62,46 @@ public class TestParenting02AWT extends UITestCase { } @Test - public void testWindowParenting01NewtChildOnAWTParentLayouted() throws InterruptedException { + public void testWindowParenting01NewtChildOnAWTParentLayouted() throws InterruptedException, InvocationTargetException { runNewtChildOnAWTParent(true, false); } @Test - public void testWindowParenting02NewtChildOnAWTParentLayoutedDef() throws InterruptedException { + public void testWindowParenting02NewtChildOnAWTParentLayoutedDef() throws InterruptedException, InvocationTargetException { runNewtChildOnAWTParent(true, true); } @Test - public void testWindowParenting03NewtChildOnAWTParentDirect() throws InterruptedException { + public void testWindowParenting03NewtChildOnAWTParentDirect() throws InterruptedException, InvocationTargetException { runNewtChildOnAWTParent(false, false); } @Test - public void testWindowParenting04NewtChildOnAWTParentDirectDef() throws InterruptedException { + public void testWindowParenting04NewtChildOnAWTParentDirectDef() throws InterruptedException, InvocationTargetException { runNewtChildOnAWTParent(false, true); } - public void runNewtChildOnAWTParent(boolean useLayout, boolean deferredPeer) throws InterruptedException { + public void runNewtChildOnAWTParent(final boolean useLayout, final boolean deferredPeer) throws InterruptedException, InvocationTargetException { NEWTEventFiFo eventFifo = new NEWTEventFiFo(); // setup NEWT GLWindow .. - GLWindow glWindow = GLWindow.create(new GLCapabilities(null)); + final GLWindow glWindow = GLWindow.create(new GLCapabilities(null)); Assert.assertNotNull(glWindow); glWindow.setTitle("NEWT - CHILD"); glWindow.addKeyListener(new TraceKeyAdapter(new KeyAction(eventFifo))); glWindow.addWindowListener(new TraceWindowAdapter(new WindowAction(eventFifo))); - GLEventListener demo = new GearsES2(); + final GLEventListener demo = new GearsES2(); setDemoFields(demo, glWindow, false); glWindow.addGLEventListener(demo); // attach NEWT GLWindow to AWT Canvas - NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow); + final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow); Assert.assertNotNull(newtCanvasAWT); Assert.assertEquals(false, glWindow.isVisible()); Assert.assertEquals(false, glWindow.isNativeValid()); Assert.assertNull(glWindow.getParent()); - Frame frame = new Frame("AWT Parent Frame"); + final Frame frame = new Frame("AWT Parent Frame"); Assert.assertNotNull(frame); if(useLayout) { frame.setLayout(new BorderLayout()); @@ -119,15 +120,22 @@ public class TestParenting02AWT extends UITestCase { frame.setSize(width, height); - frame.setVisible(true); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.setVisible(true); + }}); // X11: true, Windows: false - Assert.assertEquals(true, glWindow.isVisible()); if(deferredPeer) { - if(useLayout) { - frame.add(newtCanvasAWT, BorderLayout.CENTER); - } else { - frame.add(newtCanvasAWT); - } + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + if(useLayout) { + frame.add(newtCanvasAWT, BorderLayout.CENTER); + } else { + frame.add(newtCanvasAWT); + } + frame.validate(); + }}); } // Since it is not defined when AWT's addNotify call happen @@ -149,7 +157,11 @@ public class TestParenting02AWT extends UITestCase { if(useLayout) { // test some fancy re-layout .. - frame.remove(newtCanvasAWT); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.remove(newtCanvasAWT); + frame.validate(); + }}); Assert.assertEquals(false, glWindow.isVisible()); Assert.assertEquals(true, glWindow.isNativeValid()); Assert.assertNull(glWindow.getParent()); @@ -159,7 +171,11 @@ public class TestParenting02AWT extends UITestCase { Thread.sleep(waitReparent); // should recreate properly .. - frame.add(newtCanvasAWT, BorderLayout.CENTER); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.add(newtCanvasAWT, BorderLayout.CENTER); + frame.validate(); + }}); glWindow.display(); Assert.assertEquals(true, glWindow.isVisible()); Assert.assertEquals(true, glWindow.isNativeValid()); @@ -202,7 +218,10 @@ public class TestParenting02AWT extends UITestCase { glWindow.destroy(); if(useLayout) { - frame.remove(newtCanvasAWT); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.remove(newtCanvasAWT); + }}); } frame.dispose(); } |