diff options
author | Sven Gothel <[email protected]> | 2012-12-24 20:17:52 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-12-24 20:17:52 +0100 |
commit | b478cf3ead567fcc79fd8b75cade17efe0af3127 (patch) | |
tree | 75162205a9d1dc7a6cec52239edd7fdc6433d8f0 /src/test | |
parent | 17fde6c517b4ccf91b07c7e86974019bcbfee642 (diff) |
WT-NEWT Modifier mapping and test: part-4 (Fix unit tests): BaseNewtEventModifiers ignore more events (clicked, wheel, entered, exited); Fix TestNewtEventModifiersNewtCanvasSWT SWT-Display thread.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java | 58 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasSWT.java | 134 |
2 files changed, 117 insertions, 75 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 b4ece6c46..85a5f24cb 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 @@ -174,14 +174,6 @@ public abstract class BaseNewtEventModifiers extends UITestCase { } } - public synchronized void mouseClicked( com.jogamp.newt.event.MouseEvent event ) { - _eventCount++; - if( _debug ) { - _debugPrintStream.println( "MouseClicked "+_eventCount+": "+event); - } - _checkModifiers( event ) ; - } - public synchronized void mousePressed( com.jogamp.newt.event.MouseEvent event ) { _eventCount++; if( _debug ) { @@ -198,46 +190,60 @@ public abstract class BaseNewtEventModifiers extends UITestCase { _checkModifiers( event ) ; } - public synchronized void mouseEntered( com.jogamp.newt.event.MouseEvent event ) { + public synchronized void mouseDragged( com.jogamp.newt.event.MouseEvent event ) { _eventCount++; if( _debug ) { - _debugPrintStream.println( "MouseEntered "+_eventCount+": "+event); + _debugPrintStream.println( "MouseDragged "+_eventCount+": "+event); } _checkModifiers( event ) ; } + + // + // IGNORED + // - public synchronized void mouseExited( com.jogamp.newt.event.MouseEvent event ) { - _eventCount++; + public synchronized void mouseMoved( com.jogamp.newt.event.MouseEvent event ) { + // Ignored, since mouse MOVE doesn't hold mouse button, we look for DRAGGED! + // _eventCount++; if( _debug ) { - _debugPrintStream.println( "MouseExited "+_eventCount+": "+event); + _debugPrintStream.println( "MouseMoved ignored: "+event); } - _checkModifiers( event ) ; + // _checkModifiers( event ) ; } - - public synchronized void mouseDragged( com.jogamp.newt.event.MouseEvent event ) { - _eventCount++; + + public synchronized void mouseClicked( com.jogamp.newt.event.MouseEvent event ) { + // Ignored, since we look for PRESS/RELEASE only! + // _eventCount++; if( _debug ) { - _debugPrintStream.println( "MouseDragged "+_eventCount+": "+event); + _debugPrintStream.println( "MouseClicked ignored: "+event); } - _checkModifiers( event ) ; + // _checkModifiers( event ) ; } - public synchronized void mouseMoved( com.jogamp.newt.event.MouseEvent event ) { - // Ignored, since mouse MOVE doesn't hold mouse button, we look for DRAGGED! + public synchronized void mouseWheelMoved( com.jogamp.newt.event.MouseEvent event ) { // _eventCount++; if( _debug ) { - _debugPrintStream.println( "MouseMoved ignored: "+event); + _debugPrintStream.println( "MouseWheeleMoved ignored: "+event); } // _checkModifiers( event ) ; } - public synchronized void mouseWheelMoved( com.jogamp.newt.event.MouseEvent event ) { - _eventCount++; + public synchronized void mouseEntered( com.jogamp.newt.event.MouseEvent event ) { + // _eventCount++; if( _debug ) { - _debugPrintStream.println( "MouseWheeleMoved "+_eventCount+": "+event); + _debugPrintStream.println( "MouseEntered ignored: "+event); } - _checkModifiers( event ) ; + // _checkModifiers( event ) ; } + + public synchronized void mouseExited( com.jogamp.newt.event.MouseEvent event ) { + // _eventCount++; + if( _debug ) { + _debugPrintStream.println( "MouseExited ignored: "+event); + } + // _checkModifiers( event ) ; + } + } //////////////////////////////////////////////////////////////////////////// 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 ec01ed9d3..83b7ded7a 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 @@ -30,6 +30,7 @@ package com.jogamp.opengl.test.junit.newt.event; import org.eclipse.swt.SWT ; import org.eclipse.swt.layout.FillLayout ; +import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display ; import org.eclipse.swt.widgets.Shell ; @@ -38,8 +39,10 @@ import javax.media.opengl.GLProfile ; import org.junit.AfterClass ; import org.junit.Assert; +import org.junit.Assume; import org.junit.BeforeClass ; +import com.jogamp.nativewindow.swt.SWTAccessor; import com.jogamp.newt.opengl.GLWindow ; import com.jogamp.newt.swt.NewtCanvasSWT ; import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2; @@ -52,7 +55,9 @@ import com.jogamp.opengl.test.junit.util.AWTRobotUtil; public class TestNewtEventModifiersNewtCanvasSWT extends BaseNewtEventModifiers { - private static Shell _testShell ; + private static Display _display = null; + private static Shell _shell = null; + private static Composite _composite = null; private static GLWindow _glWindow ; private static DisplayThread _displayThread ; @@ -60,28 +65,48 @@ public class TestNewtEventModifiersNewtCanvasSWT extends BaseNewtEventModifiers private static class DisplayThread extends Thread { - private Display _display ; - + public volatile boolean shallStop = false; + public volatile boolean isInit = false; + public DisplayThread() { super( "SWT Display Thread" ) ; } - public Display getDisplay() { - return _display ; - } - public void run() { - - _display = new Display() ; - - while( isInterrupted() == false ) { + + synchronized(this) { + SWTAccessor.invoke(true, new Runnable() { + public void run() { + _display = new Display(); + Assert.assertNotNull( _display ); + }}); + + isInit = true; + this.notifyAll(); + } + + while( !_display.isDisposed() && !shallStop && isInterrupted() == false ) { if( !_display.readAndDispatch() ) { - _display.sleep() ; + try { + Thread.sleep(10); + } catch (InterruptedException e) { } + } + } + + synchronized(this) { + try { + if(!_display.isDisposed()) { + SWTAccessor.invoke(true, new Runnable() { + public void run() { + _display.dispose(); + }}); + } + } finally { + isInit = false; + this.notifyAll(); } } - - _display.dispose() ; } } @@ -91,34 +116,39 @@ public class TestNewtEventModifiersNewtCanvasSWT extends BaseNewtEventModifiers public static void beforeClass() throws Exception { _displayThread = new DisplayThread() ; - _displayThread.start() ; - - // Wait for the display thread's runnable to get set. - - while( _displayThread.getDisplay() == null ) { - try { Thread.sleep( 10 ) ; } catch( InterruptedException e ) {} + synchronized(_displayThread) { + _displayThread.start() ; + while(!_displayThread.isInit) { + _displayThread.wait(); + } } + + _display.syncExec(new Runnable() { + public void run() { + _shell = new Shell( _display ); + Assert.assertNotNull( _shell ); + _shell.setText( "Event Modifier Test NewtCanvasSWT" ) ; + _shell.setLayout( new FillLayout() ); + _composite = new Composite( _shell, SWT.NONE ); + _composite.setLayout( new FillLayout() ); + Assert.assertNotNull( _composite ); + }}); - _displayThread.getDisplay().syncExec( new Runnable() { - public void run() { - - _testShell = new Shell( _displayThread.getDisplay() ) ; - _testShell.setText( "Event Modifier Test NewtCanvasSWT" ) ; - _testShell.setLayout( new FillLayout() ) ; - - { - GLCapabilities caps = new GLCapabilities( GLProfile.get( GLProfile.GL2ES2 ) ) ; - _glWindow = GLWindow.create( caps ) ; - - NewtCanvasSWT.create( _testShell, SWT.NO_BACKGROUND, _glWindow ) ; - - _glWindow.addGLEventListener( new RedSquareES2() ) ; - } + { + GLCapabilities caps = new GLCapabilities( GLProfile.get( GLProfile.GL2ES2 ) ) ; + _glWindow = GLWindow.create( caps ) ; + _glWindow.addGLEventListener( new RedSquareES2() ) ; - _testShell.setBounds( TEST_FRAME_X, TEST_FRAME_Y, TEST_FRAME_WIDTH, TEST_FRAME_HEIGHT ) ; - _testShell.open() ; - } - } ) ; + NewtCanvasSWT.create( _composite, SWT.NO_BACKGROUND, _glWindow ) ; + } + + _display.syncExec( new Runnable() { + public void run() { + _shell.setBounds( TEST_FRAME_X, TEST_FRAME_Y, TEST_FRAME_WIDTH, TEST_FRAME_HEIGHT ) ; + _shell.open(); + } + }); + AWTRobotUtil.assertRequestFocusAndWait(null, _glWindow, _glWindow, null, null); // programmatic Assert.assertNotNull(_robot); AWTRobotUtil.requestFocus(_robot, _glWindow, false); // within unit framework, prev. tests (TestFocus02SwingAWTRobot) 'confuses' Windows keyboard input @@ -134,17 +164,23 @@ public class TestNewtEventModifiersNewtCanvasSWT extends BaseNewtEventModifiers _glWindow.destroy() ; - _displayThread.getDisplay().syncExec( new Runnable() { - public void run() { - _testShell.dispose() ; - } - } ) ; - - _displayThread.interrupt() ; - try { - _displayThread.join() ; - } catch( InterruptedException e ) { + _display.syncExec(new Runnable() { + public void run() { + _composite.dispose(); + _shell.dispose(); + }}); + + synchronized(_displayThread) { + _displayThread.shallStop = true; + while( _displayThread.isInit && _displayThread.isAlive() ) { + _displayThread.wait(); + } + } + } + catch( Throwable throwable ) { + throwable.printStackTrace(); + Assume.assumeNoException( throwable ); } } |