aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/com
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2019-04-10 00:35:59 +0200
committerSven Gothel <[email protected]>2019-04-10 00:35:59 +0200
commit35e3789ba401e94cb4778971470eb90d5c383f79 (patch)
tree8dfe6acc935e8d1a13a96d16093dc3d149cad609 /src/test/com
parentb865c4bcd1a89632ea49b7be56ac230a5aa2da63 (diff)
Bug 1362: Final general lifecycle fixes of unit tests
SWT unit tests must wait while issuing 'display.readAndDispatch()' so essential event dispatching won't get blocked. Previous AWTRobotUtil cleanup and these patches ensure proper lifecycle checks.
Diffstat (limited to 'src/test/com')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2SWT3.java58
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasSWT.java25
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/swt/TestGearsES2SWT.java17
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/swt/TestBug672NewtCanvasSWTSashForm.java15
4 files changed, 79 insertions, 36 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2SWT3.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2SWT3.java
index 248551118..4e2457181 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2SWT3.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2SWT3.java
@@ -39,6 +39,7 @@ import com.jogamp.opengl.util.Animator;
import com.jogamp.opengl.swt.GLCanvas;
import com.jogamp.opengl.test.junit.util.GLTestUtil;
import com.jogamp.opengl.test.junit.util.MiscUtils;
+import com.jogamp.opengl.test.junit.util.NewtTestUtil;
import com.jogamp.opengl.test.junit.util.UITestCase;
import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
@@ -200,17 +201,27 @@ public class TestSharedContextVBOES2SWT3 extends UITestCase {
shell2.open(); // shall wait until f1 is ready
shell3.open(); // shall wait until f1 is ready
} } );
+ final long t0 = System.currentTimeMillis();
animator.start(); // kicks off GLContext .. and hence gears of f2 + f3 completion
- Thread.sleep(1000/60*10); // wait ~10 frames giving a chance to create (blocking until master share is valid)
-
- Assert.assertTrue(GLTestUtil.waitForContextCreated(c1, true));
+ final Runnable waitAction = new Runnable() {
+ public void run() {
+ if( !display.readAndDispatch() ) {
+ try {
+ Thread.sleep(10);
+ } catch (final InterruptedException e) { }
+ }
+ } };
+ Assert.assertEquals(true, GLTestUtil.waitForRealized(c1, true, waitAction));
+ Assert.assertEquals(true, GLTestUtil.waitForContextCreated(c1, true, waitAction));
Assert.assertTrue("Gears1 not initialized", g1.waitForInit(true));
- Assert.assertTrue(GLTestUtil.waitForContextCreated(c2, true));
+ Assert.assertEquals(true, GLTestUtil.waitForRealized(c2, true, waitAction));
+ Assert.assertEquals(true, GLTestUtil.waitForContextCreated(c2, true, waitAction));
Assert.assertTrue("Gears2 not initialized", g2.waitForInit(true));
- Assert.assertTrue(GLTestUtil.waitForContextCreated(c3, true));
+ Assert.assertEquals(true, GLTestUtil.waitForRealized(c3, true, waitAction));
+ Assert.assertEquals(true, GLTestUtil.waitForContextCreated(c3, true, waitAction));
Assert.assertTrue("Gears3 not initialized", g3.waitForInit(true));
final GLContext ctx1 = c1.getContext();
@@ -236,11 +247,10 @@ public class TestSharedContextVBOES2SWT3 extends UITestCase {
Assert.assertTrue("Gears2 is not shared", g2.usesSharedGears());
Assert.assertTrue("Gears3 is not shared", g3.usesSharedGears());
- try {
- Thread.sleep(duration);
- } catch(final Exception e) {
- e.printStackTrace();
+ while(animator.isAnimating() && System.currentTimeMillis()-t0<duration) {
+ waitAction.run();
}
+
// Stopped animator allows native windowing system 'repaint' event
// to trigger GLAD 'display'
animator.stop();
@@ -266,10 +276,16 @@ public class TestSharedContextVBOES2SWT3 extends UITestCase {
} } );
a1.start();
-
- Thread.sleep(1000/60*10); // wait ~10 frames giving a chance to create (blocking until master share is valid)
-
- Assert.assertTrue(GLTestUtil.waitForContextCreated(c1, true));
+ final Runnable waitAction = new Runnable() {
+ public void run() {
+ if( !display.readAndDispatch() ) {
+ try {
+ Thread.sleep(10);
+ } catch (final InterruptedException e) { }
+ }
+ } };
+ Assert.assertEquals(true, GLTestUtil.waitForRealized(c1, true, waitAction));
+ Assert.assertEquals(true, GLTestUtil.waitForContextCreated(c1, true, waitAction));
Assert.assertTrue("Gears1 not initialized", g1.waitForInit(true));
final Animator a2 = new Animator();
@@ -284,8 +300,6 @@ public class TestSharedContextVBOES2SWT3 extends UITestCase {
} } );
a2.start();
- Thread.sleep(200); // wait a while ..
-
final Animator a3 = new Animator();
final GearsES2 g3 = new GearsES2(0);
g3.setSharedGears(g1);
@@ -298,12 +312,16 @@ public class TestSharedContextVBOES2SWT3 extends UITestCase {
} } );
a3.start();
- Assert.assertTrue(GLTestUtil.waitForContextCreated(c2, true));
+ Assert.assertEquals(true, GLTestUtil.waitForRealized(c2, true, waitAction));
+ Assert.assertEquals(true, GLTestUtil.waitForContextCreated(c2, true, waitAction));
Assert.assertTrue("Gears2 not initialized", g2.waitForInit(true));
- Assert.assertTrue(GLTestUtil.waitForContextCreated(c3, true));
+ Assert.assertEquals(true, GLTestUtil.waitForRealized(c3, true, waitAction));
+ Assert.assertEquals(true, GLTestUtil.waitForContextCreated(c3, true, waitAction));
Assert.assertTrue("Gears3 not initialized", g3.waitForInit(true));
+ final long t0 = System.currentTimeMillis();
+
final GLContext ctx1 = c1.getContext();
final GLContext ctx2 = c2.getContext();
final GLContext ctx3 = c3.getContext();
@@ -327,10 +345,8 @@ public class TestSharedContextVBOES2SWT3 extends UITestCase {
Assert.assertTrue("Gears2 is not shared", g2.usesSharedGears());
Assert.assertTrue("Gears3 is not shared", g3.usesSharedGears());
- try {
- Thread.sleep(duration);
- } catch(final Exception e) {
- e.printStackTrace();
+ while(System.currentTimeMillis()-t0<duration) {
+ waitAction.run();
}
// Stopped animator allows native windowing system 'repaint' event
// to trigger GLAD 'display'
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasSWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasSWT.java
index ee72e1e6f..7eb57c436 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasSWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasSWT.java
@@ -41,7 +41,9 @@ import com.jogamp.newt.event.WindowAdapter;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.newt.swt.NewtCanvasSWT;
import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
+import com.jogamp.opengl.test.junit.util.GLTestUtil;
import com.jogamp.opengl.test.junit.util.MiscUtils;
+import com.jogamp.opengl.test.junit.util.NewtTestUtil;
import com.jogamp.opengl.test.junit.util.UITestCase;
import com.jogamp.opengl.test.junit.util.QuitAdapter;
import com.jogamp.opengl.util.Animator;
@@ -217,16 +219,24 @@ public class TestGearsES2NewtCanvasSWT extends UITestCase {
animator.setUpdateFPSFrames(60, showFPS ? System.err : null);
+ final Runnable waitAction = new Runnable() {
+ public void run() {
+ if( !display.readAndDispatch() ) {
+ try {
+ Thread.sleep(10);
+ } catch (final InterruptedException e) { }
+ }
+ } };
+ Assert.assertEquals(true, NewtTestUtil.waitForVisible(glWindow, true, waitAction));
+ Assert.assertEquals(true, GLTestUtil.waitForRealized(glWindow, true, waitAction));
+
System.err.println("NW chosen: "+glWindow.getDelegatedWindow().getChosenCapabilities());
System.err.println("GL chosen: "+glWindow.getChosenCapabilities());
System.err.println("window pos/siz: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", "+glWindow.getInsets());
if( null != rwsize ) {
for(int i=0; i<50; i++) { // 500 ms dispatched delay
- if( !display.readAndDispatch() ) {
- // blocks on linux .. display.sleep();
- Thread.sleep(10);
- }
+ waitAction.run();
}
display.syncExec( new Runnable() {
public void run() {
@@ -237,10 +247,7 @@ public class TestGearsES2NewtCanvasSWT extends UITestCase {
}
while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
- if( !display.readAndDispatch() ) {
- // blocks on linux .. display.sleep();
- Thread.sleep(10);
- }
+ waitAction.run();
}
Assert.assertEquals(exclusiveContext ? animator.getThread() : null, glWindow.getExclusiveContextThread());
@@ -251,7 +258,7 @@ public class TestGearsES2NewtCanvasSWT extends UITestCase {
canvas1.dispose();
glWindow.destroy();
- Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glWindow, false));
+ Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glWindow, false, null));
}
@Test
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/swt/TestGearsES2SWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/swt/TestGearsES2SWT.java
index c05444b02..f76081754 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/swt/TestGearsES2SWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/swt/TestGearsES2SWT.java
@@ -33,7 +33,9 @@ import java.lang.reflect.InvocationTargetException;
import com.jogamp.nativewindow.swt.SWTAccessor;
import com.jogamp.opengl.swt.GLCanvas;
+import com.jogamp.opengl.test.junit.util.GLTestUtil;
import com.jogamp.opengl.test.junit.util.MiscUtils;
+import com.jogamp.opengl.test.junit.util.NewtTestUtil;
import com.jogamp.opengl.test.junit.util.UITestCase;
import com.jogamp.opengl.util.Animator;
import com.jogamp.opengl.util.AnimatorBase;
@@ -171,11 +173,18 @@ public class TestGearsES2SWT extends UITestCase {
animator.setUpdateFPSFrames(60, showFPS ? System.err : null);
+ final Runnable waitAction = new Runnable() {
+ public void run() {
+ if( !display.readAndDispatch() ) {
+ try {
+ Thread.sleep(10);
+ } catch (final InterruptedException e) { }
+ }
+ } };
+ Assert.assertEquals(true, GLTestUtil.waitForRealized(canvas, true, waitAction));
+
while(animator.isAnimating() && !canvas.isRealized() && animator.getTotalFPSDuration()<duration) {
- if( !display.readAndDispatch() ) {
- // blocks on linux .. display.sleep();
- Thread.sleep(10);
- }
+ waitAction.run();
}
System.err.println("NW chosen: "+canvas.getDelegatedDrawable().getChosenGLCapabilities());
System.err.println("GL chosen: "+canvas.getChosenGLCapabilities());
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestBug672NewtCanvasSWTSashForm.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestBug672NewtCanvasSWTSashForm.java
index da33392e3..89df0b1fa 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestBug672NewtCanvasSWTSashForm.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestBug672NewtCanvasSWTSashForm.java
@@ -40,7 +40,9 @@ import com.jogamp.newt.event.WindowAdapter;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.newt.swt.NewtCanvasSWT;
import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
+import com.jogamp.opengl.test.junit.util.GLTestUtil;
import com.jogamp.opengl.test.junit.util.MiscUtils;
+import com.jogamp.opengl.test.junit.util.NewtTestUtil;
import com.jogamp.opengl.test.junit.util.UITestCase;
import com.jogamp.opengl.test.junit.util.QuitAdapter;
import com.jogamp.opengl.util.Animator;
@@ -228,7 +230,16 @@ public class TestBug672NewtCanvasSWTSashForm extends UITestCase {
shell.open();
}
});
- Assert.assertTrue("GLWindow didn't become visible natively!", AWTRobotUtil.waitForRealized(glWindow, true, awtRobotWaitAction));
+ final Runnable waitAction = new Runnable() {
+ public void run() {
+ if( !display.readAndDispatch() ) {
+ try {
+ Thread.sleep(10);
+ } catch (final InterruptedException e) { }
+ }
+ } };
+ Assert.assertEquals(true, NewtTestUtil.waitForVisible(glWindow, true, waitAction));
+ Assert.assertEquals(true, GLTestUtil.waitForRealized(glWindow, true, waitAction));
Assert.assertNotNull( canvas1.getNativeWindow() );
System.err.println("NW chosen: "+glWindow.getDelegatedWindow().getChosenCapabilities());
@@ -272,7 +283,7 @@ public class TestBug672NewtCanvasSWTSashForm extends UITestCase {
canvas1.dispose();
glWindow.destroy();
- Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glWindow, false, null));
+ Assert.assertEquals(true, NewtTestUtil.waitForRealized(glWindow, false, waitAction));
}
@Test