diff options
3 files changed, 33 insertions, 14 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java index a9d38d98c..a7a822647 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java @@ -45,6 +45,7 @@ import java.io.IOException; import com.jogamp.opengl.test.junit.util.UITestCase; import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.util.NewtTestUtil; import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; @FixMethodOrder(MethodSorters.NAME_ASCENDING) @@ -110,8 +111,7 @@ public class TestDisplayLifecycle01NEWT extends UITestCase { Assert.assertNotNull(window.getScreen()); Assert.assertEquals(false,window.isNativeValid()); Assert.assertEquals(false,window.isVisible()); - Assert.assertEquals(xy_pos,window.getX()); - Assert.assertEquals(xy_pos,window.getY()); + Assert.assertTrue(NewtTestUtil.hasPositionMax2xInsetsOr64Pix(window, xy_pos, xy_pos)); // lazy native creation sequence: Display, Screen and Window Assert.assertEquals(0, window.getTotalFPSFrames()); @@ -126,8 +126,7 @@ public class TestDisplayLifecycle01NEWT extends UITestCase { Assert.assertEquals(true,screen.isNativeValid()); Assert.assertEquals(true,window.isNativeValid()); Assert.assertEquals(true,window.isVisible()); - Assert.assertEquals(xy_pos,window.getX()); - Assert.assertEquals(xy_pos,window.getY()); + Assert.assertTrue(NewtTestUtil.hasPositionMax2xInsetsOr64Pix(window, xy_pos, xy_pos)); System.err.println("Frames for setVisible(true) 1: "+window.getTotalFPSFrames()); Assert.assertTrue(0 < window.getTotalFPSFrames()); @@ -141,8 +140,7 @@ public class TestDisplayLifecycle01NEWT extends UITestCase { window.setVisible(false); Assert.assertEquals(true,window.isNativeValid()); Assert.assertEquals(false,window.isVisible()); - Assert.assertEquals(xy_pos,window.getX()); - Assert.assertEquals(xy_pos,window.getY()); + Assert.assertTrue(NewtTestUtil.hasPositionMax2xInsetsOr64Pix(window, xy_pos, xy_pos)); // just make the Window visible again window.resetFPSCounter(); @@ -150,8 +148,7 @@ public class TestDisplayLifecycle01NEWT extends UITestCase { window.setVisible(true); Assert.assertEquals(true,window.isNativeValid()); Assert.assertEquals(true,window.isVisible()); - Assert.assertEquals(xy_pos,window.getX()); - Assert.assertEquals(xy_pos,window.getY()); + Assert.assertTrue(NewtTestUtil.hasPositionMax2xInsetsOr64Pix(window, xy_pos, xy_pos)); System.err.println("Frames for setVisible(true) 1: "+window.getTotalFPSFrames()); Assert.assertTrue(0 < window.getTotalFPSFrames()); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle02NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle02NEWT.java index 97a56ab2a..1ba8686e7 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle02NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle02NEWT.java @@ -100,8 +100,7 @@ public class TestDisplayLifecycle02NEWT extends UITestCase { Assert.assertEquals(false,screen.isNativeValid()); Assert.assertEquals(false,window.isNativeValid()); Assert.assertEquals(false,window.isVisible()); - Assert.assertEquals(xy_pos,window.getX()); - Assert.assertEquals(xy_pos,window.getY()); + Assert.assertTrue(NewtTestUtil.hasPositionMax2xInsetsOr64Pix(window, xy_pos, xy_pos)); // lazy native creation sequence: Display, Screen and Window Assert.assertEquals(0, window.getTotalFPSFrames()); @@ -117,8 +116,7 @@ public class TestDisplayLifecycle02NEWT extends UITestCase { Assert.assertEquals(true,screen.isNativeValid()); Assert.assertEquals(true,window.isNativeValid()); Assert.assertEquals(true,window.isVisible()); - Assert.assertEquals(xy_pos,window.getX()); - Assert.assertEquals(xy_pos,window.getY()); + Assert.assertTrue(NewtTestUtil.hasPositionMax2xInsetsOr64Pix(window, xy_pos, xy_pos)); System.err.println("Frames for setVisible(true) 1: "+window.getTotalFPSFrames()); Assert.assertTrue(0 < window.getTotalFPSFrames()); @@ -142,8 +140,7 @@ public class TestDisplayLifecycle02NEWT extends UITestCase { window.setVisible(true); Assert.assertEquals(true,window.isNativeValid()); Assert.assertEquals(true,window.isVisible()); - Assert.assertEquals(xy_pos,window.getX()); - Assert.assertEquals(xy_pos,window.getY()); + Assert.assertTrue(NewtTestUtil.hasPositionMax2xInsetsOr64Pix(window, xy_pos, xy_pos)); System.err.println("Frames for setVisible(true) 1: "+window.getTotalFPSFrames()); Assert.assertTrue(0 < window.getTotalFPSFrames()); diff --git a/src/test/com/jogamp/opengl/test/junit/util/NewtTestUtil.java b/src/test/com/jogamp/opengl/test/junit/util/NewtTestUtil.java index 295690f8a..9ee63dcf8 100644 --- a/src/test/com/jogamp/opengl/test/junit/util/NewtTestUtil.java +++ b/src/test/com/jogamp/opengl/test/junit/util/NewtTestUtil.java @@ -31,6 +31,7 @@ package com.jogamp.opengl.test.junit.util; import java.util.concurrent.atomic.AtomicInteger; +import com.jogamp.nativewindow.util.InsetsImmutable; import com.jogamp.newt.Screen; import com.jogamp.newt.Window; import com.jogamp.newt.event.WindowEvent; @@ -200,6 +201,30 @@ public class NewtTestUtil extends TestUtil { WindowImplAccess.windowDestroyNotify(win); return waitUntilClosed(willClose, closingListener, waitAction); } + + /** + * Validates whether the window position is on the given position within tolerances. + * <p> + * Since WM may not obey our positional request exactly, we allow a tolerance of 2 times insets[left/top], or 64 pixels, whichever is greater. + * </p> + */ + public static boolean hasPositionMax2xInsetsOr64Pix(final Window win, final int shouldX, final int shouldY) { + final int maxDX, maxDY; + { + final InsetsImmutable insets = win.getInsets(); + maxDX = Math.max(64, insets.getLeftWidth() * 2); + maxDY = Math.max(64, insets.getTopHeight() * 2); + } + return hasPosition(win, shouldX, shouldY, maxDX, maxDY); + } + /** + * Validates whether the window position is on the given position within the given tolerances. + */ + public static boolean hasPosition(final Window win, final int shouldX, final int shouldY, final int maxDX, final int maxDY) { + final boolean ok = Math.abs(shouldX - win.getX()) <= maxDX && + Math.abs(shouldY - win.getY()) <= maxDY ; + return ok; + } } |