From 8512777873461ee33d8ed913ee26bafc00a08a02 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 4 Dec 2013 07:51:30 +0100 Subject: Bug 919 - TestNewtKeyCodesAWT w/ NewtCanvasAWT Fails on Windows Due to Clogged Key-Release Event by AWT Robot Impact: Only unit test code - TestNewtKeyCodesAWT: Fix Bug 919 - Move mouse bacl/forth while waiting for events .. - Use common wait for key timeout/polling using constants in NEWTKeyUtil - InputEventCountAdapter: 'getQueued()' -> 'copyQueue()' - ensuring queue is copied while instance is locked. --- .../junit/newt/event/BaseNewtEventModifiers.java | 204 ++++++++++----------- .../newt/event/TestNewtKeyCodeModifiersAWT.java | 4 +- .../test/junit/newt/event/TestNewtKeyCodesAWT.java | 81 ++++---- .../newt/event/TestNewtKeyEventAutoRepeatAWT.java | 107 ++++++----- .../junit/newt/event/TestNewtKeyEventOrderAWT.java | 2 +- .../opengl/test/junit/util/AWTKeyAdapter.java | 6 +- .../opengl/test/junit/util/AWTMouseAdapter.java | 6 +- .../opengl/test/junit/util/AWTRobotUtil.java | 32 ++-- .../test/junit/util/InputEventCountAdapter.java | 2 +- .../opengl/test/junit/util/NEWTKeyAdapter.java | 8 +- .../jogamp/opengl/test/junit/util/NEWTKeyUtil.java | 70 +++---- .../opengl/test/junit/util/NEWTMouseAdapter.java | 6 +- 12 files changed, 266 insertions(+), 262 deletions(-) (limited to 'src/test/com/jogamp/opengl') 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 44d6a2dec..a46e21b23 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 @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,12 +20,12 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ - + package com.jogamp.opengl.test.junit.newt.event ; import java.io.PrintStream ; @@ -66,15 +66,15 @@ public abstract class BaseNewtEventModifiers extends UITestCase { protected static final int MS_ROBOT_KEY_PRESS_DELAY = 50 ; protected static final int MS_ROBOT_KEY_RELEASE_DELAY = 50 ; protected static final int MS_ROBOT_MOUSE_MOVE_DELAY = 200 ; - - protected static final int MS_ROBOT_AUTO_DELAY = 50 ; + + protected static final int MS_ROBOT_AUTO_DELAY = 50 ; protected static final int MS_ROBOT_POST_TEST_DELAY = 100; - + protected static final boolean _debug = true ; protected static PrintStream _debugPrintStream = System.err ; - + //////////////////////////////////////////////////////////////////////////// - + static { GLProfile.initSingleton() ; @@ -96,7 +96,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { public synchronized boolean modifierCheckEnabled() { return _modifierCheckEnabled ; } - + /** * Sets the modifiers the listener should expect, and clears * out any existing accumulated failures. Normally this kind @@ -108,20 +108,20 @@ public abstract class BaseNewtEventModifiers extends UITestCase { _expectedModifiers = value ; clear(); } - + public synchronized ArrayList clear() { ArrayList old = _failures; - + _eventCount = 0; // Assume we will have a failure due to no event delivery. // If an event is delivered and it's good this assumed - // failure will get cleared out. + // failure will get cleared out. _failures = new ArrayList(); _failures.add( NO_EVENT_DELIVERY ); return old; } - + public ArrayList getFailures(int waitEventCount) { int j; for(j=0; j < 20 && _eventCount < waitEventCount; j++) { // wait until events are collected @@ -132,14 +132,14 @@ public abstract class BaseNewtEventModifiers extends UITestCase { } return clear(); } - + private synchronized void _checkModifiers( com.jogamp.newt.event.MouseEvent hasEvent ) { if( _modifierCheckEnabled ) { - final MouseEvent expEvent = new MouseEvent(hasEvent.getEventType(), hasEvent.getSource(), hasEvent.getWhen(), _expectedModifiers, - hasEvent.getX(), hasEvent.getY(), hasEvent.getClickCount(), hasEvent.getButton(), + final MouseEvent expEvent = new MouseEvent(hasEvent.getEventType(), hasEvent.getSource(), hasEvent.getWhen(), _expectedModifiers, + hasEvent.getX(), hasEvent.getY(), hasEvent.getClickCount(), hasEvent.getButton(), hasEvent.getRotation(), hasEvent.getRotationScale()); - + _checkModifierMask( expEvent, hasEvent, com.jogamp.newt.event.InputEvent.SHIFT_MASK, "shift" ) ; _checkModifierMask( expEvent, hasEvent, com.jogamp.newt.event.InputEvent.CTRL_MASK, "ctrl" ) ; _checkModifierMask( expEvent, hasEvent, com.jogamp.newt.event.InputEvent.META_MASK, "meta" ) ; @@ -180,7 +180,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { _eventCount++; if( _debug ) { _debugPrintStream.println( "MousePressed "+_eventCount+": "+event); - } + } _checkModifiers( event ) ; } @@ -188,7 +188,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { _eventCount++; if( _debug ) { _debugPrintStream.println( "MouseReleased "+_eventCount+": "+event); - } + } _checkModifiers( event ) ; } @@ -196,29 +196,29 @@ public abstract class BaseNewtEventModifiers extends UITestCase { _eventCount++; if( _debug ) { _debugPrintStream.println( "MouseDragged "+_eventCount+": "+event); - } + } _checkModifiers( event ) ; } // - // IGNORED - // - - public synchronized void mouseMoved( com.jogamp.newt.event.MouseEvent event ) { + // IGNORED + // + + 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( "MouseMoved ignored: "+event); - } + } // _checkModifiers( event ) ; } - + public synchronized void mouseClicked( com.jogamp.newt.event.MouseEvent event ) { // Ignored, since we look for PRESS/RELEASE only! // _eventCount++; if( _debug ) { _debugPrintStream.println( "MouseClicked ignored: "+event); - } + } // _checkModifiers( event ) ; } @@ -226,23 +226,23 @@ public abstract class BaseNewtEventModifiers extends UITestCase { // _eventCount++; if( _debug ) { _debugPrintStream.println( "MouseWheeleMoved ignored: "+event); - } + } // _checkModifiers( event ) ; } - + public synchronized void mouseEntered( com.jogamp.newt.event.MouseEvent event ) { // _eventCount++; if( _debug ) { _debugPrintStream.println( "MouseEntered ignored: "+event); - } + } // _checkModifiers( event ) ; } - + public synchronized void mouseExited( com.jogamp.newt.event.MouseEvent event ) { // _eventCount++; if( _debug ) { _debugPrintStream.println( "MouseExited ignored: "+event); - } + } // _checkModifiers( event ) ; } @@ -261,7 +261,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { public static int getAWTButtonMask(int button) { // Java7: java.awt.event.InputEvent.getMaskForButton( n + 1 ) ; -> using InputEvent.BUTTON1_DOWN_MASK .. etc - // Java6: Only use BUTTON1_MASK, .. + // Java6: Only use BUTTON1_MASK, .. int m; switch(button) { case 1 : m = java.awt.event.InputEvent.BUTTON1_MASK; break; @@ -271,14 +271,14 @@ public abstract class BaseNewtEventModifiers extends UITestCase { } return m; } - + @BeforeClass public static void baseBeforeClass() throws Exception { // Who know how many buttons the AWT will say exist on given platform. // We'll test the smaller of what NEWT supports and what the // AWT says is available. - /** Java7: + /** Java7: if( java.awt.Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled() ) { _numButtonsToTest = java.awt.MouseInfo.getNumberOfButtons() ; } else { @@ -300,7 +300,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { _numButtonsToTest = 3 ; { - if( _numButtonsToTest > com.jogamp.newt.event.MouseEvent.BUTTON_COUNT ) { + if( _numButtonsToTest > com.jogamp.newt.event.MouseEvent.BUTTON_COUNT ) { _numButtonsToTest = com.jogamp.newt.event.MouseEvent.BUTTON_COUNT ; } @@ -309,10 +309,10 @@ public abstract class BaseNewtEventModifiers extends UITestCase { // either array. _awtButtonMasks = new int[_numButtonsToTest] ; - + for( int n = 0 ; n < _awtButtonMasks.length ; ++n ) { _awtButtonMasks[n] = getAWTButtonMask( n + 1 ); - } + } } _robot = new java.awt.Robot() ; @@ -326,23 +326,23 @@ public abstract class BaseNewtEventModifiers extends UITestCase { // to run the SWT event dispatch on the TK thread - which must be the main thread on OSX. // We spawn off the actual test-action into another thread, // while dispatching the events until the test-action is completed. - // YES: This is sort of ideal - NOT :) - - protected void eventDispatch() { + // YES: This is sort of ideal - NOT :) + + protected void eventDispatch() { try { Thread.sleep(100); - } catch (InterruptedException e) { } + } catch (InterruptedException e) { } } - + private void execOffThreadWithOnThreadEventDispatch(Runnable testAction) throws Exception { - _testMouseListener.setModifierCheckEnabled( false ) ; + _testMouseListener.setModifierCheckEnabled( false ) ; _robot.setAutoDelay( MS_ROBOT_AUTO_DELAY ) ; - { + { // Make sure all the buttons and modifier keys are released. clearKeyboadAndMouse(); } _testMouseListener.setModifierCheckEnabled( true ) ; - + Throwable throwable = null; // final Object sync = new Object(); final RunnableTask rt = new RunnableTask( testAction, null, true, System.err ); @@ -361,13 +361,13 @@ public abstract class BaseNewtEventModifiers extends UITestCase { throw new RuntimeException(throwable); } // } - } finally { + } finally { System.err.println("WAIT-till-done: DONE"); - _testMouseListener.setModifierCheckEnabled( false ) ; + _testMouseListener.setModifierCheckEnabled( false ) ; clearKeyboadAndMouse(); } } - + //////////////////////////////////////////////////////////////////////////// // The approach on all these tests is to tell the test mouse listener what @@ -390,59 +390,59 @@ public abstract class BaseNewtEventModifiers extends UITestCase { @Test(timeout=180000) // TO 3 min public void testSingleButtonPressAndRelease() throws Exception { - execOffThreadWithOnThreadEventDispatch(new Runnable() { - public void run() { - try { - _doSingleButtonPressAndRelease( 0, 0 ); - } catch (Exception e) { throw new RuntimeException(e); } + execOffThreadWithOnThreadEventDispatch(new Runnable() { + public void run() { + try { + _doSingleButtonPressAndRelease( 0, 0 ); + } catch (Exception e) { throw new RuntimeException(e); } } } ); } @Test(timeout=180000) // TO 3 min public void testSingleButtonPressAndReleaseWithShift() throws Exception { - execOffThreadWithOnThreadEventDispatch(new Runnable() { - public void run() { - try { + execOffThreadWithOnThreadEventDispatch(new Runnable() { + public void run() { + try { _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_SHIFT, java.awt.event.InputEvent.SHIFT_DOWN_MASK ) ; - } catch (Exception e) { throw new RuntimeException(e); } + } catch (Exception e) { throw new RuntimeException(e); } } } ); } @Test(timeout=180000) // TO 3 min public void testSingleButtonPressAndReleaseWithCtrl() throws Exception { - execOffThreadWithOnThreadEventDispatch(new Runnable() { - public void run() { - try { + execOffThreadWithOnThreadEventDispatch(new Runnable() { + public void run() { + try { _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_CONTROL, java.awt.event.InputEvent.CTRL_DOWN_MASK ) ; - } catch (Exception e) { throw new RuntimeException(e); } + } catch (Exception e) { throw new RuntimeException(e); } } } ); } /** * The META and ALT tests get too tied up with functions of the window system on X11, - * so it's probably best to leave them commented out. + * so it's probably best to leave them commented out. @Test(timeout=180000) // TO 3 min public void testSingleButtonPressAndReleaseWithMeta() throws Exception { - execOffThreadWithOnThreadEventDispatch(new Runnable() { - public void run() { - try { + execOffThreadWithOnThreadEventDispatch(new Runnable() { + public void run() { + try { _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_META, java.awt.event.InputEvent.META_DOWN_MASK ) ; - } catch (Exception e) { throw new RuntimeException(e); } + } catch (Exception e) { throw new RuntimeException(e); } } } ); } - + @Test(timeout=180000) // TO 3 min public void testSingleButtonPressAndReleaseWithAlt() throws Exception { - execOffThreadWithOnThreadEventDispatch(new Runnable() { - public void run() { - try { + execOffThreadWithOnThreadEventDispatch(new Runnable() { + public void run() { + try { _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_ALT, java.awt.event.InputEvent.ALT_DOWN_MASK ) ; - } catch (Exception e) { throw new RuntimeException(e); } + } catch (Exception e) { throw new RuntimeException(e); } } } ); } */ - /** + /** * FIXME - not sure yet what's up with ALT_GRAPH. It appears that this * modifier didn't make it through, so I had to disable this test else it would always fail. * @@ -450,11 +450,11 @@ public abstract class BaseNewtEventModifiers extends UITestCase { * enough to not let this modifier slip through (?). @Test public void testSingleButtonPressAndReleaseWithAltGraph() throws Exception { - execOffThreadWithOnThreadEventDispatch(new Runnable() { - public void run() { - try { + execOffThreadWithOnThreadEventDispatch(new Runnable() { + public void run() { + try { _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_ALT_GRAPH, java.awt.event.InputEvent.ALT_GRAPH_DOWN_MASK ) ; - } catch (Exception e) { throw new RuntimeException(e); } + } catch (Exception e) { throw new RuntimeException(e); } } } ); } */ @@ -463,31 +463,31 @@ public abstract class BaseNewtEventModifiers extends UITestCase { @Test(timeout=180000) // TO 3 min public void testHoldOneButtonAndPressAnother() throws Exception { - execOffThreadWithOnThreadEventDispatch(new Runnable() { - public void run() { - try { + execOffThreadWithOnThreadEventDispatch(new Runnable() { + public void run() { + try { _doHoldOneButtonAndPressAnother( 0, 0 ) ; - } catch (Exception e) { throw new RuntimeException(e); } + } catch (Exception e) { throw new RuntimeException(e); } } } ); } - + @Test(timeout=180000) // TO 3 min public void testPressAllButtonsInSequence() throws Exception { - execOffThreadWithOnThreadEventDispatch(new Runnable() { - public void run() { - try { + execOffThreadWithOnThreadEventDispatch(new Runnable() { + public void run() { + try { _doPressAllButtonsInSequence( 0, 0 ) ; - } catch (Exception e) { throw new RuntimeException(e); } + } catch (Exception e) { throw new RuntimeException(e); } } } ); } @Test(timeout=180000) // TO 3 min public void testSingleButtonClickAndDrag() throws Exception { - execOffThreadWithOnThreadEventDispatch(new Runnable() { - public void run() { - try { + execOffThreadWithOnThreadEventDispatch(new Runnable() { + public void run() { + try { _doSingleButtonClickAndDrag( 0, 0 ) ; - } catch (Exception e) { throw new RuntimeException(e); } + } catch (Exception e) { throw new RuntimeException(e); } } } ); } @@ -522,7 +522,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { private void _doHoldOneButtonAndPressAnother( final int keyCode, final int keyModifierMask ) throws Exception { if( _debug ) { _debugPrintStream.println( "\n>>>> _doHoldOneButtonAndPressAnother" ) ; } - + _doKeyPress( keyCode ) ; for (int n = 0 ; n < _numButtonsToTest ; ++n) { @@ -533,7 +533,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | awtButtonMask ) ) ; _robot.mousePress( awtButtonMask ) ; _checkFailures("mouse-press("+(n+1)+")", 1) ; - + for (int m = 0 ; m < _numButtonsToTest ; ++m) { if( n != m ) { @@ -564,12 +564,12 @@ public abstract class BaseNewtEventModifiers extends UITestCase { private void _doPressAllButtonsInSequence( final int keyCode, final int keyModifierMask ) throws Exception { if( _debug ) { _debugPrintStream.println( "\n>>>> _doPressAllButtonsInSequence" ) ; } - + _doKeyPress( keyCode ) ; { int cumulativeAwtModifiers = 0 ; - + for (int n = 0 ; n < _numButtonsToTest ; ++n) { cumulativeAwtModifiers |= _awtButtonMasks[n] ; @@ -586,7 +586,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | cumulativeAwtModifiers ) ) ; _robot.mouseRelease( _awtButtonMasks[n] ) ; _checkFailures("mouse-release("+(n+1)+")", 1) ; - + cumulativeAwtModifiers &= ~_awtButtonMasks[n] ; } } @@ -627,7 +627,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { _testMouseListener.setModifierCheckEnabled( false ) ; _robot.mouseMove( INITIAL_MOUSE_X, INITIAL_MOUSE_Y ) ; - _robot.delay(MS_ROBOT_MOUSE_MOVE_DELAY); + _robot.delay(MS_ROBOT_MOUSE_MOVE_DELAY); _testMouseListener.setModifierCheckEnabled( true ) ; } @@ -637,7 +637,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { //////////////////////////////////////////////////////////////////////////// private void _doKeyPress( int keyCode ) { - AWTRobotUtil.validateAWTEDTIsAlive(); + AWTRobotUtil.validateAWTEDTIsAlive(); if( keyCode != 0 ) { boolean modifierCheckEnabled = _testMouseListener.modifierCheckEnabled() ; _testMouseListener.setModifierCheckEnabled( false ) ; @@ -686,9 +686,9 @@ public abstract class BaseNewtEventModifiers extends UITestCase { eventDispatch(); eventDispatch(); eventDispatch(); Thread.sleep( MS_ROBOT_POST_TEST_DELAY ) ; eventDispatch(); eventDispatch(); eventDispatch(); - _testMouseListener.clear(); + _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). @@ -745,7 +745,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase { * @return * The equivalent NEWT modifiers. */ - + private int _getNewtModifiersForAwtExtendedModifiers( int awtExtendedModifiers ) { int mask = 0 ; diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodeModifiersAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodeModifiersAWT.java index 4be819261..2516fc536 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodeModifiersAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodeModifiersAWT.java @@ -186,7 +186,7 @@ public class TestNewtKeyCodeModifiersAWT extends UITestCase { 3 /* press-SI */, 3 /* release-SI */, 0 /* press-AR */, 0 /* release-AR */ ); - final List queue = keyAdapter.getQueued(); + final List queue = keyAdapter.copyQueue(); int i=0; NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, 0, keyCode, keyCharOnly); NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, 0, keyCode, keyCharOnly); @@ -226,7 +226,7 @@ public class TestNewtKeyCodeModifiersAWT extends UITestCase { 4 /* press-SI */, 4 /* release-SI */, 0 /* press-AR */, 0 /* release-AR */ ); - final List queue = keyAdapter.getQueued(); + final List queue = keyAdapter.copyQueue(); int i=0; NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, m1m, m1k, KeyEvent.NULL_CHAR); NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, m1m|m2m, m2k, KeyEvent.NULL_CHAR); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodesAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodesAWT.java index 4778b4feb..71778c611 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodesAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodesAWT.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,12 +20,12 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ - + package com.jogamp.opengl.test.junit.newt.event; import org.junit.After; @@ -60,7 +60,6 @@ import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.util.Animator; import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2; - import com.jogamp.opengl.test.junit.util.*; import com.jogamp.opengl.test.junit.util.NEWTKeyUtil.CodeSeg; @@ -85,35 +84,35 @@ public class TestNewtKeyCodesAWT extends UITestCase { @AfterClass public static void release() { } - + @Before - public void initTest() { + public void initTest() { } @After - public void releaseTest() { + public void releaseTest() { } - + @Test(timeout=180000) // TO 3 min public void test01NEWT() throws AWTException, InterruptedException, InvocationTargetException { GLWindow glWindow = GLWindow.create(glCaps); glWindow.setSize(width, height); glWindow.setVisible(true); - + testImpl(glWindow); - + glWindow.destroy(); } - + private void testNewtCanvasAWT_Impl(boolean onscreen) throws AWTException, InterruptedException, InvocationTargetException { GLWindow glWindow = GLWindow.create(glCaps); - + // Wrap the window in a canvas. final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow); if( !onscreen ) { newtCanvasAWT.setShallUseOffscreenLayer(true); } - + // Add the canvas to a frame, and make it all visible. final JFrame frame1 = new JFrame("Swing AWT Parent Frame: "+ glWindow.getTitle()); frame1.getContentPane().add(newtCanvasAWT, BorderLayout.CENTER); @@ -122,11 +121,11 @@ public class TestNewtKeyCodesAWT extends UITestCase { frame1.setSize(width, height); frame1.setVisible(true); } } ); - + Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame1, true)); - + testImpl(glWindow); - + try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -136,10 +135,10 @@ public class TestNewtKeyCodesAWT extends UITestCase { } catch( Throwable throwable ) { throwable.printStackTrace(); Assume.assumeNoException( throwable ); - } + } glWindow.destroy(); } - + @Test(timeout=180000) // TO 3 min public void test02NewtCanvasAWT_Onscreen() throws AWTException, InterruptedException, InvocationTargetException { if( JAWTUtil.isOffscreenLayerRequired() ) { @@ -148,7 +147,7 @@ public class TestNewtKeyCodesAWT extends UITestCase { } testNewtCanvasAWT_Impl(true); } - + @Test(timeout=180000) // TO 3 min public void test03NewtCanvasAWT_Offsccreen() throws AWTException, InterruptedException, InvocationTargetException { if( !JAWTUtil.isOffscreenLayerSupported() ) { @@ -157,7 +156,7 @@ public class TestNewtKeyCodesAWT extends UITestCase { } testNewtCanvasAWT_Impl(false); } - + /** Almost all keyCodes reachable w/o modifiers [shift, alt, ..] on US keyboard! */ static CodeSeg[] codeSegments = new CodeSeg[] { // new CodeSeg(KeyEvent.VK_HOME, KeyEvent.VK_PRINTSCREEN, "home, end, final, prnt"), @@ -188,16 +187,19 @@ public class TestNewtKeyCodesAWT extends UITestCase { new CodeSeg(KeyEvent.VK_LEFT, KeyEvent.VK_DOWN, "cursor arrows"), // new CodeSeg(KeyEvent.VK_WINDOWS, KeyEvent.VK_HELP, "windows, meta, hlp"), }; - - static void testKeyCodes(Robot robot, NEWTKeyAdapter keyAdapter) { + + static void testKeyCodes(Robot robot, Object obj, NEWTKeyAdapter keyAdapter) throws InterruptedException, InvocationTargetException { final List> cse = new ArrayList>(); - + + keyAdapter.setVerbose(true); // FIXME + final int[] objCenter = AWTRobotUtil.getCenterLocation(obj, false /* onTitleBarIfWindow */); + for(int i=0; i events = new ArrayList(keyAdapter.getQueued()); - cse.add(events); + AWTRobotUtil.awtRobotMouseMove(robot, objCenter[0], objCenter[1]); // Bug 919: Reset mouse position + cse.add(keyAdapter.copyQueue()); } - Assert.assertEquals("KeyCode impl. incomplete", true, NEWTKeyUtil.validateKeyCodes(codeSegments, cse, true)); + Assert.assertEquals("KeyCode impl. incomplete", true, NEWTKeyUtil.validateKeyCodes(codeSegments, cse, true)); } - + void testImpl(GLWindow glWindow) throws AWTException, InterruptedException, InvocationTargetException { final Robot robot = new Robot(); robot.setAutoWaitForIdle(true); @@ -238,20 +243,20 @@ public class TestNewtKeyCodesAWT extends UITestCase { glWindow1KA.setVerbose(false); glWindow.addKeyListener(glWindow1KA); - Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glWindow, true)); + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glWindow, true)); // Continuous animation .. Animator animator = new Animator(glWindow); animator.start(); Thread.sleep(durationPerTest); // manual testing - + AWTRobotUtil.assertRequestFocusAndWait(null, glWindow, glWindow, null, null); // programmatic AWTRobotUtil.requestFocus(robot, glWindow, false); // within unit framework, prev. tests (TestFocus02SwingAWTRobot) 'confuses' Windows keyboard input - glWindow1KA.reset(); + glWindow1KA.reset(); + + testKeyCodes(robot, glWindow, glWindow1KA); - testKeyCodes(robot, glWindow1KA); - // Remove listeners to avoid logging during dispose/destroy. glWindow.removeKeyListener(glWindow1KA); @@ -276,7 +281,7 @@ public class TestNewtKeyCodesAWT extends UITestCase { /** BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); System.err.println("Press enter to continue"); - System.err.println(stdin.readLine()); + System.err.println(stdin.readLine()); */ System.out.println("durationPerTest: "+durationPerTest); String tstname = TestNewtKeyCodesAWT.class.getName(); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyEventAutoRepeatAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyEventAutoRepeatAWT.java index 34e81c033..3ef96edc2 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyEventAutoRepeatAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyEventAutoRepeatAWT.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,12 +20,12 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ - + package com.jogamp.opengl.test.junit.newt.event; import org.junit.After; @@ -59,12 +59,11 @@ import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.util.Animator; import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2; - import com.jogamp.opengl.test.junit.util.*; /** * Testing key event order incl. auto-repeat (Bug 601) - * + * *

* Note Event order: *

    @@ -102,33 +101,33 @@ public class TestNewtKeyEventAutoRepeatAWT extends UITestCase { @AfterClass public static void release() { } - + @Before - public void initTest() { + public void initTest() { } @After - public void releaseTest() { + public void releaseTest() { } - + @Test(timeout=180000) // TO 3 min public void test01NEWT() throws AWTException, InterruptedException, InvocationTargetException { GLWindow glWindow = GLWindow.create(glCaps); glWindow.setSize(width, height); glWindow.setVisible(true); - + testImpl(glWindow); - + glWindow.destroy(); } - + @Test(timeout=180000) // TO 3 min public void test02NewtCanvasAWT() throws AWTException, InterruptedException, InvocationTargetException { GLWindow glWindow = GLWindow.create(glCaps); - + // Wrap the window in a canvas. final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow); - + // Add the canvas to a frame, and make it all visible. final JFrame frame1 = new JFrame("Swing AWT Parent Frame: "+ glWindow.getTitle()); frame1.getContentPane().add(newtCanvasAWT, BorderLayout.CENTER); @@ -137,11 +136,11 @@ public class TestNewtKeyEventAutoRepeatAWT extends UITestCase { public void run() { frame1.setVisible(true); } } ); - + Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame1, true)); - + testImpl(glWindow); - + try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -151,15 +150,15 @@ public class TestNewtKeyEventAutoRepeatAWT extends UITestCase { } catch( Throwable throwable ) { throwable.printStackTrace(); Assume.assumeNoException( throwable ); - } + } glWindow.destroy(); } - + static void testKeyEventAutoRepeat(Robot robot, NEWTKeyAdapter keyAdapter, int loops, int pressDurationMS) { System.err.println("KEY Event Auto-Repeat Test: "+loops); EventObject[][] first = new EventObject[loops][2]; EventObject[][] last = new EventObject[loops][2]; - + keyAdapter.reset(); int firstIdx = 0; for(int i=0; i keyEvents = keyAdapter.copyQueue(); + Assert.assertTrue("AR Test didn't collect enough key events: required min "+minCodeCount+", received "+(keyAdapter.getQueueSize()-firstIdx)+", "+keyEvents, keyAdapter.getQueueSize() >= minCodeCount ); - final List keyEvents = keyAdapter.getQueued(); - first[i][0] = (KeyEvent) keyEvents.get(firstIdx+0); - first[i][1] = (KeyEvent) keyEvents.get(firstIdx+1); + first[i][0] = keyEvents.get(firstIdx+0); + first[i][1] = keyEvents.get(firstIdx+1); firstIdx = keyEvents.size() - 2; - last[i][0] = (KeyEvent) keyEvents.get(firstIdx+0); - last[i][1] = (KeyEvent) keyEvents.get(firstIdx+1); + last[i][0] = keyEvents.get(firstIdx+0); + last[i][1] = keyEvents.get(firstIdx+1); System.err.println("+++ KEY Event Auto-Repeat END Input Loop: "+i); - + // add a pair of normal press/release in between auto-repeat! firstIdx = keyEvents.size(); AWTRobotUtil.waitForIdle(robot); AWTRobotUtil.keyPress(0, robot, true, java.awt.event.KeyEvent.VK_B, 10); AWTRobotUtil.keyPress(0, robot, false, java.awt.event.KeyEvent.VK_B, 250); AWTRobotUtil.waitForIdle(robot); - for(int j=0; j < 20 && keyAdapter.getQueueSize() < firstIdx+3; j++) { // wait until events are collected - robot.delay(100); + for(int j=0; j < NEWTKeyUtil.POLL_DIVIDER && keyAdapter.getQueueSize() < firstIdx+3; j++) { // wait until events are collected + robot.delay(NEWTKeyUtil.TIME_SLICE); } firstIdx = keyEvents.size(); } // dumpKeyEvents(keyEvents); - final List keyEvents = keyAdapter.getQueued(); + final List keyEvents = keyAdapter.copyQueue(); NEWTKeyUtil.validateKeyEventOrder(keyEvents); - + final boolean hasAR = 0 < keyAdapter.getKeyPressedCount(true) ; - + { final int perLoopSI = 2; // per loop: 1 non AR event and 1 for non AR 'B' final int expSI, expAR; @@ -208,48 +207,48 @@ public class TestNewtKeyEventAutoRepeatAWT extends UITestCase { expAR = ( keyEvents.size() - expSI*2 ) / 2; // auto-repeat release } else { expSI = keyEvents.size() / 2; // all released events - expAR = 0; + expAR = 0; } - - NEWTKeyUtil.validateKeyAdapterStats(keyAdapter, - expSI /* press-SI */, expSI /* release-SI */, - expAR /* press-AR */, expAR /* release-AR */ ); + + NEWTKeyUtil.validateKeyAdapterStats(keyAdapter, + expSI /* press-SI */, expSI /* release-SI */, + expAR /* press-AR */, expAR /* release-AR */ ); } - + if( !hasAR ) { System.err.println("No AUTO-REPEAT triggered by AWT Robot .. aborting test analysis"); return; } - + for(int i=0; i getQueued() { - return queue; + public synchronized List copyQueue() { + return new ArrayList(queue); } public synchronized int getQueueSize() { diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTMouseAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/AWTMouseAdapter.java index f6cbd0a04..c1bec79f5 100644 --- a/src/test/com/jogamp/opengl/test/junit/util/AWTMouseAdapter.java +++ b/src/test/com/jogamp/opengl/test/junit/util/AWTMouseAdapter.java @@ -46,7 +46,7 @@ public class AWTMouseAdapter extends java.awt.event.MouseAdapter implements Inpu reset(); } - public synchronized void setVerbose(boolean v) { verbose = false; } + public synchronized void setVerbose(boolean v) { verbose = v; } public synchronized boolean isPressed() { return pressed; @@ -60,8 +60,8 @@ public class AWTMouseAdapter extends java.awt.event.MouseAdapter implements Inpu return consumed; } - public synchronized List getQueued() { - return queue; + public synchronized List copyQueue() { + return new ArrayList(queue); } public synchronized int getQueueSize() { diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java index 657936adc..cf58ae257 100644 --- a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java +++ b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java @@ -59,9 +59,6 @@ public class AWTRobotUtil { public static final int TIME_SLICE = TIME_OUT / POLL_DIVIDER ; public static Integer AWT_CLICK_TO = null; - static Object awtEDTAliveSync = new Object(); - static volatile boolean awtEDTAliveFlag = false; - static class OurUncaughtExceptionHandler implements UncaughtExceptionHandler { @Override public void uncaughtException(Thread t, Throwable e) { @@ -82,12 +79,7 @@ public class AWTRobotUtil { } synchronized ( awtEDTAliveSync ) { awtEDTAliveFlag = false; - EventQueue.invokeLater(new Runnable() { - @Override - public void run() { - awtEDTAliveFlag = true; - } - }); + EventQueue.invokeLater(aliveRun); for (int wait=0; wait getQueued(); + public List copyQueue(); public int getQueueSize(); } diff --git a/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyAdapter.java index 5242da637..0e86afd93 100644 --- a/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyAdapter.java +++ b/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyAdapter.java @@ -51,7 +51,7 @@ public class NEWTKeyAdapter extends KeyAdapter implements KeyEventCountAdapter { reset(); } - public synchronized void setVerbose(boolean v) { verbose = false; } + public synchronized void setVerbose(boolean v) { verbose = v; } public synchronized boolean isPressed() { return pressed; @@ -73,8 +73,8 @@ public class NEWTKeyAdapter extends KeyAdapter implements KeyEventCountAdapter { return autoRepeatOnly ? keyReleasedAR: keyReleased; } - public synchronized List getQueued() { - return queue; + public synchronized List copyQueue() { + return new ArrayList(queue); } public synchronized int getQueueSize() { @@ -118,6 +118,6 @@ public class NEWTKeyAdapter extends KeyAdapter implements KeyEventCountAdapter { } } - public String toString() { return prefix+"[pressed "+pressed+", keyReleased "+keyReleased+", consumed "+consumed+"]"; } + public String toString() { return prefix+"[pressed "+pressed+", keysPressed "+keyPressed+" (AR "+keyPressedAR+"), keyReleased "+keyReleased+" (AR "+keyReleasedAR+"), consumed "+consumed+"]"; } } diff --git a/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyUtil.java b/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyUtil.java index 990930994..89bafbd8c 100644 --- a/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyUtil.java +++ b/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyUtil.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,7 +20,7 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. @@ -37,11 +37,15 @@ import com.jogamp.common.util.IntIntHashMap; import com.jogamp.newt.event.KeyEvent; public class NEWTKeyUtil { + public static final int TIME_OUT = 2000; // 2s + public static final int POLL_DIVIDER = 20; // TO/20 + public static final int TIME_SLICE = TIME_OUT / POLL_DIVIDER ; + public static class CodeSeg { public final short min; public final short max; public final String description; - + public CodeSeg(int min, int max, String description) { this.min = (short)min; this.max = (short)max; @@ -52,23 +56,23 @@ public class NEWTKeyUtil { public final short code; public final String description; public final KeyEvent event; - + public CodeEvent(short code, String description, KeyEvent event) { this.code = code; this.description = description; this.event = event; } public String toString() { - return "Code 0x"+Integer.toHexString( (int)code & 0x0000FFFF )+" != "+event+" // "+description; + return "Code 0x"+Integer.toHexString( code & 0x0000FFFF )+" != "+event+" // "+description; } } - + public static void dumpKeyEvents(List keyEvents) { for(int i=0; i> keyEventsList, boolean verbose) { final List missCodes = new ArrayList(); int totalCodeCount = 0; @@ -78,7 +82,7 @@ public class NEWTKeyUtil { totalCodeCount += codeSeg.max - codeSeg.min + 1; final List keyEvents = keyEventsList.get(i); res &= validateKeyCodes(missCodes, codeSeg, keyEvents, verbose); - } + } if(verbose) { System.err.println("*** Total KeyCode Misses "+missCodes.size()+" / "+totalCodeCount+", valid "+res); for(int i=0; i keyEvents) { - IntIntHashMap keyCode2NextEvent = new IntIntHashMap(); + IntIntHashMap keyCode2NextEvent = new IntIntHashMap(); for(int i=0; i keyEvents = keyAdapter.getQueued(); - + + final List keyEvents = keyAdapter.copyQueue(); + Assert.assertEquals("Key pressRelease count failure (ALL) w/ list sum ", expPressReleaseCountALL, pressReleaseCountALL); Assert.assertEquals("Key total count failure (ALL) w/ list size ", pressReleaseCountALL, keyEvents.size()); - } + } } diff --git a/src/test/com/jogamp/opengl/test/junit/util/NEWTMouseAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/NEWTMouseAdapter.java index 6850fcf47..22e241f71 100644 --- a/src/test/com/jogamp/opengl/test/junit/util/NEWTMouseAdapter.java +++ b/src/test/com/jogamp/opengl/test/junit/util/NEWTMouseAdapter.java @@ -49,7 +49,7 @@ public class NEWTMouseAdapter extends MouseAdapter implements InputEventCountAda reset(); } - public synchronized void setVerbose(boolean v) { verbose = false; } + public synchronized void setVerbose(boolean v) { verbose = v; } public synchronized boolean isPressed() { return pressed; @@ -63,8 +63,8 @@ public class NEWTMouseAdapter extends MouseAdapter implements InputEventCountAda return consumed; } - public synchronized List getQueued() { - return queue; + public synchronized List copyQueue() { + return new ArrayList(queue); } public synchronized int getQueueSize() { -- cgit v1.2.3