diff options
author | Sven Gothel <[email protected]> | 2023-01-17 23:39:04 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-01-17 23:39:04 +0100 |
commit | 509d8a01a2655fa2a1d1e3cdf4b357bd7294fb3e (patch) | |
tree | 340288b8e8c569809b62da9a9d55178312b0a737 /src/test/com/jogamp/opengl | |
parent | c33ea9f33dd0f074464ee119e0c631b091fdeb1a (diff) |
Test*NewtEventModifiers*: Ensure SWT is initialized before AWT
Diffstat (limited to 'src/test/com/jogamp/opengl')
5 files changed, 66 insertions, 25 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java b/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java index 3be7a96dc..51ffe314a 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java @@ -178,6 +178,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { } } + @Override public synchronized void mousePressed( final com.jogamp.newt.event.MouseEvent event ) { _eventCount.incrementAndGet(); if( _debug ) { @@ -186,6 +187,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { _checkModifiers( event ) ; } + @Override public synchronized void mouseReleased( final com.jogamp.newt.event.MouseEvent event ) { _eventCount.incrementAndGet(); if( _debug ) { @@ -194,6 +196,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { _checkModifiers( event ) ; } + @Override public synchronized void mouseDragged( final com.jogamp.newt.event.MouseEvent event ) { _eventCount.incrementAndGet(); if( _debug ) { @@ -206,6 +209,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { // IGNORED // + @Override public synchronized void mouseMoved( final com.jogamp.newt.event.MouseEvent event ) { // Ignored, since mouse MOVE doesn't hold mouse button, we look for DRAGGED! // _eventCount++; @@ -215,6 +219,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { // _checkModifiers( event ) ; } + @Override public synchronized void mouseClicked( final com.jogamp.newt.event.MouseEvent event ) { // Ignored, since we look for PRESS/RELEASE only! // _eventCount++; @@ -224,6 +229,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { // _checkModifiers( event ) ; } + @Override public synchronized void mouseWheelMoved( final com.jogamp.newt.event.MouseEvent event ) { // _eventCount++; if( _debug ) { @@ -232,6 +238,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { // _checkModifiers( event ) ; } + @Override public synchronized void mouseEntered( final com.jogamp.newt.event.MouseEvent event ) { // _eventCount++; if( _debug ) { @@ -240,6 +247,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { // _checkModifiers( event ) ; } + @Override public synchronized void mouseExited( final com.jogamp.newt.event.MouseEvent event ) { // _eventCount++; if( _debug ) { @@ -274,7 +282,11 @@ public abstract class BaseNewtEventModifiers extends UITestCase { return m; } - @BeforeClass + /** + * Must be called from subclass `@BeforeClass` code, + * allowing it to perform its specific initialization first. + * @throws Exception + */ public static void baseBeforeClass() throws Exception { // Who know how many buttons the AWT will say exist on given platform. @@ -390,6 +402,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { @Test(timeout=180000) // TO 3 min public void test01SingleButtonPressAndRelease() throws Exception { execOffThreadWithOnThreadEventDispatch(new Runnable() { + @Override public void run() { try { _doSingleButtonPressAndRelease( 0, 0 ); @@ -400,6 +413,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { @Test(timeout=180000) // TO 3 min public void test02SingleButtonPressAndReleaseWithShift() throws Exception { execOffThreadWithOnThreadEventDispatch(new Runnable() { + @Override public void run() { try { _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_SHIFT, java.awt.event.InputEvent.SHIFT_DOWN_MASK ) ; @@ -410,6 +424,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { @Test(timeout=180000) // TO 3 min public void test03SingleButtonPressAndReleaseWithCtrl() throws Exception { execOffThreadWithOnThreadEventDispatch(new Runnable() { + @Override public void run() { try { _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_CONTROL, java.awt.event.InputEvent.CTRL_DOWN_MASK ) ; @@ -463,6 +478,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { @Test(timeout=180000) // TO 3 min public void test10HoldOneButtonAndPressAnother() throws Exception { execOffThreadWithOnThreadEventDispatch(new Runnable() { + @Override public void run() { try { _doHoldOneButtonAndPressAnother( 0, 0 ) ; @@ -473,6 +489,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { @Test(timeout=180000) // TO 3 min public void test20PressAllButtonsInSequence() throws Exception { execOffThreadWithOnThreadEventDispatch(new Runnable() { + @Override public void run() { try { _doPressAllButtonsInSequence( 0, 0 ) ; @@ -483,6 +500,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { @Test(timeout=180000) // TO 3 min public void test30SingleButtonClickAndDrag() throws Exception { execOffThreadWithOnThreadEventDispatch(new Runnable() { + @Override public void run() { try { _doSingleButtonClickAndDrag( 0, 0 ) ; diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersAWTCanvas.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersAWTCanvas.java index 8f58ec7d9..10f352f89 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersAWTCanvas.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersAWTCanvas.java @@ -40,6 +40,7 @@ import org.junit.BeforeClass ; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; +import com.jogamp.nativewindow.swt.SWTAccessor; import com.jogamp.newt.event.awt.AWTMouseAdapter ; import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2; import com.jogamp.opengl.test.junit.util.AWTRobotUtil; @@ -58,6 +59,7 @@ public class TestNewtEventModifiersAWTCanvas extends BaseNewtEventModifiers { @BeforeClass public static void beforeClass() throws Exception { + BaseNewtEventModifiers.baseBeforeClass(); final GLCanvas canvas = new GLCanvas() ; canvas.addGLEventListener( new RedSquareES2() ) ; @@ -67,6 +69,7 @@ public class TestNewtEventModifiersAWTCanvas extends BaseNewtEventModifiers { _testFrame.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE ) ; SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { _testFrame.getContentPane().add( canvas ) ; _testFrame.setBounds( TEST_FRAME_X, TEST_FRAME_Y, TEST_FRAME_WIDTH, TEST_FRAME_HEIGHT ) ; @@ -87,6 +90,7 @@ public class TestNewtEventModifiersAWTCanvas extends BaseNewtEventModifiers { @AfterClass public static void afterClass() throws Exception { SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { if( null != _testFrame ) { _testFrame.dispose() ; diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNEWTWindowAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNEWTWindowAWT.java index 7b45e590b..473199e25 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNEWTWindowAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNEWTWindowAWT.java @@ -54,6 +54,8 @@ public class TestNewtEventModifiersNEWTWindowAWT extends BaseNewtEventModifiers @BeforeClass public static void beforeClass() throws Exception { + BaseNewtEventModifiers.baseBeforeClass(); + _glWindow = GLWindow.create( new GLCapabilities( GLProfile.getGL2ES2() ) ); _glWindow.setTitle("Event Modifier Test GLWindow"); _glWindow.addGLEventListener( new RedSquareES2() ) ; diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasAWT.java index 0fb34a062..88367a77b 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasAWT.java @@ -63,8 +63,10 @@ public class TestNewtEventModifiersNewtCanvasAWT extends BaseNewtEventModifiers @BeforeClass public static void beforeClass() throws Exception { + BaseNewtEventModifiers.baseBeforeClass(); SwingUtilities.invokeAndWait( new Runnable() { + @Override public void run() { _testFrame = new JFrame( "Event Modifier Test NewtCanvasAWT" ) ; @@ -101,6 +103,7 @@ public class TestNewtEventModifiersNewtCanvasAWT extends BaseNewtEventModifiers @AfterClass public static void afterClass() throws Exception { SwingUtilities.invokeAndWait( new Runnable() { + @Override public void run() { if( null != _testFrame ) { _testFrame.dispose() ; diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasSWTAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasSWTAWT.java index 0d83108d4..1714b1ae9 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasSWTAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasSWTAWT.java @@ -66,20 +66,25 @@ public class TestNewtEventModifiersNewtCanvasSWTAWT extends BaseNewtEventModifie protected static void eventDispatchImpl() { final int maxEvents = 10; - try { - Thread.sleep(100); - } catch (final InterruptedException e) { } final boolean[] res = { false }; int i=0; do { SWTAccessor.invokeOnSWTThread(_display, true, new Runnable() { - public void run() { - if( !_display.isDisposed() ) { - res[0] = _display.readAndDispatch(); - } else { - res[0] = false; - } - } } ); + @Override + public void run() { + if( !_display.isDisposed() ) { + if( !_display.readAndDispatch() ) { + res[0] = false; + try { + Thread.sleep(100); + } catch (final InterruptedException e) { } + } else { + res[0] = true; + } + } else { + res[0] = false; + } + }}); i++; } while( i<maxEvents && res[0] ); } @@ -94,17 +99,22 @@ public class TestNewtEventModifiersNewtCanvasSWTAWT extends BaseNewtEventModifie @BeforeClass public static void beforeClass() throws Exception { + SWTAccessor.initSingleton(); + BaseNewtEventModifiers.baseBeforeClass(); + // FIXME: Hangs .. w/ Java7 .. every now and then! + // FIXME: Implementation must still be overhauled setTestSupported(false); - /*** - SWTAccessor.invoke(true, new Runnable() { + SWTAccessor.invokeOnOSTKThread(true, new Runnable() { + @Override public void run() { _display = new Display(); }}); Assert.assertNotNull( _display ); - SWTAccessor.invoke(_display, true, new Runnable() { + SWTAccessor.invokeOnSWTThread(_display, true, new Runnable() { + @Override public void run() { _shell = new Shell( _display ); Assert.assertNotNull( _shell ); @@ -116,18 +126,19 @@ public class TestNewtEventModifiersNewtCanvasSWTAWT extends BaseNewtEventModifie }}); { - GLCapabilities caps = new GLCapabilities( GLProfile.get( GLProfile.GL2ES2 ) ) ; + final GLCapabilities caps = new GLCapabilities( GLProfile.get( GLProfile.GL2ES2 ) ) ; _glWindow = GLWindow.create( caps ) ; _glWindow.addGLEventListener( new RedSquareES2() ) ; NewtCanvasSWT.create( _composite, SWT.NO_BACKGROUND, _glWindow ) ; } - SWTAccessor.invoke(_display, true, new Runnable() { - public void run() { - _shell.setBounds( TEST_FRAME_X, TEST_FRAME_Y, TEST_FRAME_WIDTH, TEST_FRAME_HEIGHT ) ; - _shell.open(); - } + SWTAccessor.invokeOnSWTThread(_display, true, new Runnable() { + @Override + public void run() { + _shell.setBounds( TEST_FRAME_X, TEST_FRAME_Y, TEST_FRAME_WIDTH, TEST_FRAME_HEIGHT ) ; + _shell.open(); + } }); // no AWT idling, may deadlock on OSX! @@ -141,18 +152,17 @@ public class TestNewtEventModifiersNewtCanvasSWTAWT extends BaseNewtEventModifie eventDispatchImpl(); _glWindow.addMouseListener( _testMouseListener ) ; - */ } //////////////////////////////////////////////////////////////////////////// @AfterClass public static void afterClass() throws Exception { - /** _glWindow.destroy() ; try { - SWTAccessor.invoke(_display, true, new Runnable() { + SWTAccessor.invokeOnSWTThread(_display, true, new Runnable() { + @Override public void run() { if( null != _composite ) { _composite.dispose(); @@ -160,15 +170,19 @@ public class TestNewtEventModifiersNewtCanvasSWTAWT extends BaseNewtEventModifie if( null != _shell ) { _shell.dispose(); } + }}); + SWTAccessor.invokeOnOSTKThread(true, new Runnable() { + @Override + public void run() { if( null != _display && !_display.isDisposed()) { _display.dispose(); } }}); } - catch( Throwable throwable ) { + catch( final Throwable throwable ) { throwable.printStackTrace(); Assume.assumeNoException( throwable ); - } */ + } } //////////////////////////////////////////////////////////////////////////// |