diff options
author | Sven Gothel <[email protected]> | 2013-02-21 14:22:10 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-02-21 14:22:10 +0100 |
commit | 405bc071d5d13e00d0561a485d31e3a7d61bf167 (patch) | |
tree | b9e83f5397fde2d810de0f2ed706ace979e1e364 /src/test/com/jogamp | |
parent | fe0a2ad6f702aee71ea06f9da19ec9fd696d4095 (diff) |
TestNewtEventModifiers*: Robostness (uhh) Unify wait-clear result code - fix SWT event dispatching.
Diffstat (limited to 'src/test/com/jogamp')
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java | 65 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasSWT.java | 53 |
2 files changed, 56 insertions, 62 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 138d30823..4dd3bb98a 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 @@ -318,11 +318,6 @@ public abstract class BaseNewtEventModifiers extends UITestCase { _testMouseListener = new TestMouseListener() ; } - @After - public void afterTest() throws Exception { - clearKeyboadAndMouse(); - } - //////////////////////////////////////////////////////////////////////////// // Following both methods are mandatory to deal with SWT's requirement // to run the SWT event dispatch on the TK thread - which must be the main thread on OSX. @@ -341,34 +336,32 @@ public abstract class BaseNewtEventModifiers extends UITestCase { _robot.setAutoDelay( MS_ROBOT_AUTO_DELAY ) ; { // Make sure all the buttons and modifier keys are released. - _releaseModifiers() ; - _escape() ; - eventDispatch(); eventDispatch(); eventDispatch(); - Thread.sleep( MS_ROBOT_POST_TEST_DELAY ) ; - eventDispatch(); eventDispatch(); eventDispatch(); - _testMouseListener.clear(); + clearKeyboadAndMouse(); } _testMouseListener.setModifierCheckEnabled( true ) ; Throwable throwable = null; - final Object sync = new Object(); - final RunnableTask rt = new RunnableTask( testAction, sync, true ); + // final Object sync = new Object(); + final RunnableTask rt = new RunnableTask( testAction, null, true ); try { - new Thread(rt, "Test-Thread").start(); - while( !rt.isExecuted() && null == throwable ) { - eventDispatch(); - } - if(null==throwable) { - throwable = rt.getThrowable(); - } - if(null!=throwable) { - throw new RuntimeException(throwable); - } + // synchronized(sync) { + new Thread(rt, "Test-Thread").start(); + int i=0; + while( !rt.isExecuted() && null == throwable ) { + System.err.println("WAIT-till-done: eventDispatch() #"+i++); + eventDispatch(); + } + if(null==throwable) { + throwable = rt.getThrowable(); + } + if(null!=throwable) { + throw new RuntimeException(throwable); + } + // } } finally { - _testMouseListener.setModifierCheckEnabled( false ) ; - eventDispatch(); eventDispatch(); eventDispatch(); - Thread.sleep( MS_ROBOT_POST_TEST_DELAY ) ; - eventDispatch(); eventDispatch(); eventDispatch(); + System.err.println("WAIT-till-done: DONE"); + _testMouseListener.setModifierCheckEnabled( false ) ; + clearKeyboadAndMouse(); } } @@ -684,20 +677,24 @@ public abstract class BaseNewtEventModifiers extends UITestCase { //////////////////////////////////////////////////////////////////////////// - public static void clearKeyboadAndMouse() throws Exception { - + public void eventDispatchedPostTestDelay() throws Exception { + eventDispatch(); eventDispatch(); eventDispatch(); + Thread.sleep( MS_ROBOT_POST_TEST_DELAY ) ; + eventDispatch(); eventDispatch(); eventDispatch(); + _testMouseListener.clear(); + } + + public void clearKeyboadAndMouse() throws Exception { // Make sure all modifiers are released, otherwise the user's // desktop can get locked up (ask me how I know this). - _releaseModifiers() ; _escape() ; - Thread.sleep( MS_ROBOT_POST_TEST_DELAY ) ; - _testMouseListener.clear(); + eventDispatchedPostTestDelay(); } //////////////////////////////////////////////////////////////////////////// - private static void _releaseModifiers() { + private void _releaseModifiers() { if (_robot != null) { @@ -722,7 +719,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { } } - private static void _escape() { + private void _escape() { if (_robot != null) { _robot.keyPress( java.awt.event.KeyEvent.VK_ESCAPE ) ; _robot.keyRelease( java.awt.event.KeyEvent.VK_ESCAPE ) ; diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasSWT.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasSWT.java index 002134216..6279b70dc 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasSWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasSWT.java @@ -62,22 +62,23 @@ public class TestNewtEventModifiersNewtCanvasSWT extends BaseNewtEventModifiers //////////////////////////////////////////////////////////////////////////// - protected static void eventDispatch2xImpl() { - eventDispatchImpl(); + protected static void eventDispatchImpl() { + final int maxEvents = 10; try { Thread.sleep(100); } catch (InterruptedException e) { } - eventDispatchImpl(); - } - - protected static void eventDispatchImpl() { - if( !_display.isDisposed() ) { - if( !_display.readAndDispatch() ) { - try { - Thread.sleep(10); - } catch (InterruptedException e) { } - } - } + final boolean[] res = { false }; + int i=0; + do { + SWTAccessor.invoke(_display, true, new Runnable() { + public void run() { + if( !_display.isDisposed() ) { + res[0] = _display.readAndDispatch(); + } else { + res[0] = false; + } + } } ); + } while( i<maxEvents && res[0] ); } @Override @@ -96,7 +97,7 @@ public class TestNewtEventModifiersNewtCanvasSWT extends BaseNewtEventModifiers }}); Assert.assertNotNull( _display ); - _display.syncExec(new Runnable() { + SWTAccessor.invoke(_display, true, new Runnable() { public void run() { _shell = new Shell( _display ); Assert.assertNotNull( _shell ); @@ -115,7 +116,7 @@ public class TestNewtEventModifiersNewtCanvasSWT extends BaseNewtEventModifiers NewtCanvasSWT.create( _composite, SWT.NO_BACKGROUND, _glWindow ) ; } - _display.syncExec( new Runnable() { + 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(); @@ -128,9 +129,9 @@ public class TestNewtEventModifiersNewtCanvasSWT extends BaseNewtEventModifiers // no waiting for results .. AWTRobotUtil.requestFocus(null, _glWindow, false); // programmatic - eventDispatch2xImpl(); + eventDispatchImpl(); AWTRobotUtil.requestFocus(_robot, _glWindow, INITIAL_MOUSE_X, INITIAL_MOUSE_Y); - eventDispatch2xImpl(); + eventDispatchImpl(); _glWindow.addMouseListener( _testMouseListener ) ; } @@ -142,18 +143,14 @@ public class TestNewtEventModifiersNewtCanvasSWT extends BaseNewtEventModifiers _glWindow.destroy() ; try { - _display.syncExec(new Runnable() { - public void run() { - _composite.dispose(); - _shell.dispose(); - }}); - - if(!_display.isDisposed()) { - SWTAccessor.invoke(true, new Runnable() { - public void run() { + SWTAccessor.invoke(_display, true, new Runnable() { + public void run() { + _composite.dispose(); + _shell.dispose(); + if(!_display.isDisposed()) { _display.dispose(); - }}); - } + } + }}); } catch( Throwable throwable ) { throwable.printStackTrace(); |