aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java204
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodeModifiersAWT.java4
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodesAWT.java81
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyEventAutoRepeatAWT.java107
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyEventOrderAWT.java2
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/AWTKeyAdapter.java6
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/AWTMouseAdapter.java6
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java32
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/InputEventCountAdapter.java2
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/NEWTKeyAdapter.java8
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/NEWTKeyUtil.java70
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/NEWTMouseAdapter.java6
12 files changed, 266 insertions, 262 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 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<String> clear() {
ArrayList<String> 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<String>();
_failures.add( NO_EVENT_DELIVERY );
return old;
}
-
+
public ArrayList<String> 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<EventObject> queue = keyAdapter.getQueued();
+ final List<EventObject> 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<EventObject> queue = keyAdapter.getQueued();
+ final List<EventObject> 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<List<EventObject>> cse = new ArrayList<List<EventObject>>();
-
+
+ keyAdapter.setVerbose(true); // FIXME
+ final int[] objCenter = AWTRobotUtil.getCenterLocation(obj, false /* onTitleBarIfWindow */);
+
for(int i=0; i<codeSegments.length; i++) {
keyAdapter.reset();
final CodeSeg codeSeg = codeSegments[i];
// System.err.println("*** Segment "+codeSeg.description);
int eventCount = 0;
- for(short c=codeSeg.min; c<=codeSeg.max; c++) {
+ for(short c=codeSeg.min; c<=codeSeg.max; c++) {
AWTRobotUtil.waitForIdle(robot);
// System.err.println("*** KeyCode 0x"+Integer.toHexString(c));
try {
@@ -216,15 +218,18 @@ public class TestNewtKeyCodesAWT extends UITestCase {
eventCount++;
}
AWTRobotUtil.waitForIdle(robot);
- for(int j=0; j < 20 && keyAdapter.getQueueSize() < eventCount; j++) { // wait until events are collected
- robot.delay(100);
+ for(int j=0; j < NEWTKeyUtil.POLL_DIVIDER && keyAdapter.getQueueSize() < eventCount; j++) { // wait until events are collected
+ robot.delay(NEWTKeyUtil.TIME_SLICE);
+ // Bug 919 - TestNewtKeyCodesAWT w/ NewtCanvasAWT Fails on Windows Due to Clogged Key-Release Event by AWT Robot
+ final int off = 0==j%2 ? 1 : -1;
+ AWTRobotUtil.awtRobotMouseMove(robot, objCenter[0]+off, objCenter[1]);
}
- final ArrayList<EventObject> events = new ArrayList<EventObject>(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)
- *
+ *
* <p>
* Note Event order:
* <ol>
@@ -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<loops; i++) {
@@ -170,36 +169,36 @@ public class TestNewtKeyEventAutoRepeatAWT extends UITestCase {
AWTRobotUtil.waitForIdle(robot);
final int minCodeCount = firstIdx + 2;
final int desiredCodeCount = firstIdx + 4;
- for(int j=0; j < 10 && keyAdapter.getQueueSize() < desiredCodeCount; j++) { // wait until events are collected
- robot.delay(100);
+ for(int j=0; j < NEWTKeyUtil.POLL_DIVIDER && keyAdapter.getQueueSize() < desiredCodeCount; j++) { // wait until events are collected
+ robot.delay(NEWTKeyUtil.TIME_SLICE);
}
- Assert.assertTrue("AR Test didn't collect enough key events: required min "+minCodeCount+", received "+(keyAdapter.getQueueSize()-firstIdx)+", "+keyAdapter.getQueued(),
+ final List<EventObject> 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<EventObject> 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<EventObject> keyEvents = keyAdapter.getQueued();
+ final List<EventObject> 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<loops; i++) {
System.err.println("Auto-Repeat Loop "+i+" - Head:");
NEWTKeyUtil.dumpKeyEvents(Arrays.asList(first[i]));
System.err.println("Auto-Repeat Loop "+i+" - Tail:");
NEWTKeyUtil.dumpKeyEvents(Arrays.asList(last[i]));
- }
+ }
for(int i=0; i<loops; i++) {
KeyEvent e = (KeyEvent) first[i][0];
Assert.assertTrue("1st Shall be A, but is "+e, KeyEvent.VK_A == e.getKeyCode() );
Assert.assertTrue("1st Shall be PRESSED, but is "+e, KeyEvent.EVENT_KEY_PRESSED == e.getEventType() );
Assert.assertTrue("1st Shall not be AR, but is "+e, 0 == ( InputEvent.AUTOREPEAT_MASK & e.getModifiers() ) );
-
+
e = (KeyEvent) first[i][1];
Assert.assertTrue("2nd Shall be A, but is "+e, KeyEvent.VK_A == e.getKeyCode() );
Assert.assertTrue("2nd Shall be RELEASED, but is "+e, KeyEvent.EVENT_KEY_RELEASED == e.getEventType() );
Assert.assertTrue("2nd Shall be AR, but is "+e, 0 != ( InputEvent.AUTOREPEAT_MASK & e.getModifiers() ) );
-
+
e = (KeyEvent) last[i][0];
Assert.assertTrue("last-1 Shall be A, but is "+e, KeyEvent.VK_A == e.getKeyCode() );
Assert.assertTrue("last-1 Shall be PRESSED, but is "+e, KeyEvent.EVENT_KEY_PRESSED == e.getEventType() );
Assert.assertTrue("last-1 Shall be AR, but is "+e, 0 != ( InputEvent.AUTOREPEAT_MASK & e.getModifiers() ) );
-
+
e = (KeyEvent) last[i][1];
Assert.assertTrue("last-0 Shall be A, but is "+e, KeyEvent.VK_A == e.getKeyCode() );
Assert.assertTrue("last-2 Shall be RELEASED, but is "+e, KeyEvent.EVENT_KEY_RELEASED == e.getEventType() );
Assert.assertTrue("last-0 Shall not be AR, but is "+e, 0 == ( InputEvent.AUTOREPEAT_MASK & e.getModifiers() ) );
}
}
-
+
void testImpl(GLWindow glWindow) throws AWTException, InterruptedException, InvocationTargetException {
final Robot robot = new Robot();
robot.setAutoWaitForIdle(true);
@@ -261,29 +260,29 @@ public class TestNewtKeyEventAutoRepeatAWT 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();
- //
+ //
// Test the key event order w/ auto-repeat
//
final int origAutoDelay = robot.getAutoDelay();
robot.setAutoDelay(10);
try {
testKeyEventAutoRepeat(robot, glWindow1KA, 3, 1000);
- } finally {
+ } finally {
robot.setAutoDelay(origAutoDelay);
}
-
+
// Remove listeners to avoid logging during dispose/destroy.
glWindow.removeKeyListener(glWindow1KA);
@@ -308,7 +307,7 @@ public class TestNewtKeyEventAutoRepeatAWT 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 = TestNewtKeyEventAutoRepeatAWT.class.getName();
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyEventOrderAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyEventOrderAWT.java
index 23de0e91d..8cc427508 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyEventOrderAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyEventOrderAWT.java
@@ -190,7 +190,7 @@ public class TestNewtKeyEventOrderAWT extends UITestCase {
robot.delay(250);
// dumpKeyEvents(keyAdapter.getQueued());
- NEWTKeyUtil.validateKeyEventOrder(keyAdapter.getQueued());
+ NEWTKeyUtil.validateKeyEventOrder(keyAdapter.copyQueue());
final int expTotal = 6*loops; // all typed events
NEWTKeyUtil.validateKeyAdapterStats(keyAdapter,
diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTKeyAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/AWTKeyAdapter.java
index 5ae473e18..9461af5c0 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/AWTKeyAdapter.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/AWTKeyAdapter.java
@@ -47,7 +47,7 @@ public class AWTKeyAdapter extends java.awt.event.KeyAdapter implements KeyEvent
reset();
}
- public synchronized void setVerbose(boolean v) { verbose = false; }
+ public synchronized void setVerbose(boolean v) { verbose = v; }
public synchronized boolean isPressed() {
return pressed;
@@ -69,8 +69,8 @@ public class AWTKeyAdapter extends java.awt.event.KeyAdapter implements KeyEvent
return keyReleased;
}
- public synchronized List<EventObject> getQueued() {
- return queue;
+ public synchronized List<EventObject> copyQueue() {
+ return new ArrayList<EventObject>(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<EventObject> getQueued() {
- return queue;
+ public synchronized List<EventObject> copyQueue() {
+ return new ArrayList<EventObject>(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<POLL_DIVIDER && !awtEDTAliveFlag; wait++) {
try {
Thread.sleep(TIME_SLICE);
@@ -98,6 +90,10 @@ public class AWTRobotUtil {
return awtEDTAliveFlag;
}
}
+ private static Runnable aliveRun = new Runnable() { public void run() { awtEDTAliveFlag = true; } };
+ private static Object awtEDTAliveSync = new Object();
+ private static volatile boolean awtEDTAliveFlag = false;
+
/** Throws Error if {@link #isAWTEDTAlive()} returns false. */
public static void validateAWTEDTIsAlive() {
if( !isAWTEDTAlive() ) {
@@ -184,6 +180,11 @@ public class AWTRobotUtil {
return new int[] { (int)p0.getX(), (int)p0.getY() };
}
+ public static void awtRobotMouseMove(Robot robot, int x, int y) {
+ robot.mouseMove( x, y );
+ robot.delay(ROBOT_DELAY);
+ }
+
/**
* toFront, call setVisible(true) and toFront(),
* after positioning the mouse in the middle of the window via robot.
@@ -203,9 +204,8 @@ public class AWTRobotUtil {
robot.setAutoWaitForIdle(true);
}
int[] p0 = getCenterLocation(window, false);
- System.err.println("toFront: robot pos: "+p0[0]+"x"+p0[1]);
- robot.mouseMove( p0[0], p0[1] );
- robot.delay(ROBOT_DELAY);
+ System.err.println("toFront: robot pos: "+p0[0]+"/"+p0[1]);
+ awtRobotMouseMove(robot, p0[0], p0[1] );
int wait=0;
do {
@@ -247,9 +247,7 @@ public class AWTRobotUtil {
int[] p0 = getCenterLocation(obj, onTitleBarIfWindow);
System.err.println("centerMouse: robot pos: "+p0[0]+"x"+p0[1]+", onTitleBarIfWindow: "+onTitleBarIfWindow);
-
- robot.mouseMove( p0[0], p0[1] );
- robot.delay(ROBOT_DELAY);
+ awtRobotMouseMove(robot, p0[0], p0[1] );
}
public static void setMouseToClientLocation(Robot robot, Object obj, int x, int y)
@@ -261,9 +259,7 @@ public class AWTRobotUtil {
}
int[] p0 = getClientLocation(obj, x, y);
-
- robot.mouseMove( p0[0], p0[1] );
- robot.delay(ROBOT_DELAY);
+ awtRobotMouseMove(robot, p0[0], p0[1] );
}
public static int getClickTimeout(Object obj) {
diff --git a/src/test/com/jogamp/opengl/test/junit/util/InputEventCountAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/InputEventCountAdapter.java
index 1804b9cb6..a32e995d9 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/InputEventCountAdapter.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/InputEventCountAdapter.java
@@ -36,7 +36,7 @@ public interface InputEventCountAdapter extends EventCountAdapter {
int getCount();
boolean isPressed();
- public List<EventObject> getQueued();
+ public List<EventObject> 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<EventObject> getQueued() {
- return queue;
+ public synchronized List<EventObject> copyQueue() {
+ return new ArrayList<EventObject>(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<EventObject> keyEvents) {
for(int i=0; i<keyEvents.size(); i++) {
System.err.println(i+": "+keyEvents.get(i));
- }
+ }
}
-
+
public static boolean validateKeyCodes(CodeSeg[] codeSegments, List<List<EventObject>> keyEventsList, boolean verbose) {
final List<CodeEvent> missCodes = new ArrayList<CodeEvent>();
int totalCodeCount = 0;
@@ -78,7 +82,7 @@ public class NEWTKeyUtil {
totalCodeCount += codeSeg.max - codeSeg.min + 1;
final List<EventObject> 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<missCodes.size(); i++) {
@@ -104,7 +108,7 @@ public class NEWTKeyUtil {
missCodes.add(new CodeEvent(c, codeSeg.description, e));
misses++;
}
- evtIdx += 2;
+ evtIdx += 2;
}
}
final boolean res = evtIdx == keyEvents.size() && 0 == missCodes.size();
@@ -113,7 +117,7 @@ public class NEWTKeyUtil {
}
return res;
}
-
+
public static void validateKeyEvent(KeyEvent e, short eventType, int modifiers, short keyCode, char keyChar) {
if(0 <= eventType) {
Assert.assertTrue("KeyEvent type mismatch, expected 0x"+Integer.toHexString(eventType)+", has "+e, eventType == e.getEventType());
@@ -126,24 +130,24 @@ public class NEWTKeyUtil {
}
if(KeyEvent.NULL_CHAR != keyChar) {
Assert.assertTrue("KeyEvent char mismatch, expected 0x"+Integer.toHexString(keyChar)+", has "+e, keyChar == e.getKeyChar());
- }
+ }
}
-
+
public static short getNextKeyEventType(KeyEvent e) {
final int et = e.getEventType();
switch( et ) {
case KeyEvent.EVENT_KEY_PRESSED:
return KeyEvent.EVENT_KEY_RELEASED;
case KeyEvent.EVENT_KEY_RELEASED:
- return KeyEvent.EVENT_KEY_PRESSED;
+ return KeyEvent.EVENT_KEY_PRESSED;
default:
Assert.assertTrue("Invalid event "+e, false);
return 0;
}
}
-
+
public static void validateKeyEventOrder(List<EventObject> keyEvents) {
- IntIntHashMap keyCode2NextEvent = new IntIntHashMap();
+ IntIntHashMap keyCode2NextEvent = new IntIntHashMap();
for(int i=0; i<keyEvents.size(); i++) {
final KeyEvent e = (KeyEvent) keyEvents.get(i);
int eet = keyCode2NextEvent.get(e.getKeyCode());
@@ -154,9 +158,9 @@ public class NEWTKeyUtil {
Assert.assertEquals("Key event not in proper order "+i+"/"+keyEvents.size()+" - event "+e, eet, et);
eet = getNextKeyEventType(e);
keyCode2NextEvent.put(e.getKeyCode(), eet);
- }
+ }
}
-
+
/**
* @param keyAdapter
* @param expPressedCountSI number of single key press events
@@ -164,46 +168,46 @@ public class NEWTKeyUtil {
* @param expPressedCountAR number of auto-repeat key press events
* @param expReleasedCountAR number of auto-repeat key release events
*/
- public static void validateKeyAdapterStats(NEWTKeyAdapter keyAdapter,
- int expPressedCountSI, int expReleasedCountSI,
+ public static void validateKeyAdapterStats(NEWTKeyAdapter keyAdapter,
+ int expPressedCountSI, int expReleasedCountSI,
int expPressedCountAR, int expReleasedCountAR) {
final int expPressReleaseCountSI = expPressedCountSI + expReleasedCountSI;
final int expPressReleaseCountAR = expPressedCountAR + expReleasedCountAR;
final int expPressReleaseCountALL = expPressReleaseCountSI + expPressReleaseCountAR;
-
+
final int keyPressedALL = keyAdapter.getKeyPressedCount(false);
final int keyPressedAR = keyAdapter.getKeyPressedCount(true);
final int keyReleasedALL = keyAdapter.getKeyReleasedCount(false);
final int keyReleasedAR = keyAdapter.getKeyReleasedCount(true);
-
+
final int keyPressedSI = keyPressedALL-keyPressedAR;
final int keyReleasedSI = keyReleasedALL-keyReleasedAR;
-
+
final int pressReleaseCountALL = keyPressedALL + keyReleasedALL;
final int pressReleaseCountSI = keyPressedSI + keyReleasedSI;
final int pressReleaseCountAR = keyPressedAR + keyReleasedAR;
System.err.println("Expec Single Press "+expPressedCountSI +", Release "+expReleasedCountSI);
System.err.println("Expec AutoRp Press "+expPressedCountAR +", Release "+expReleasedCountAR);
-
+
System.err.println("Total Single Press "+keyPressedSI +", Release "+keyReleasedSI +", Events "+pressReleaseCountSI);
System.err.println("Total AutoRp Press "+keyPressedAR +", Release "+keyReleasedAR +", Events "+pressReleaseCountAR);
System.err.println("Total ALL Press "+keyPressedALL +", Release "+keyReleasedALL +", Events "+pressReleaseCountALL);
-
+
Assert.assertEquals("Internal Error: pressReleaseSI != pressReleaseALL - pressReleaseAR", pressReleaseCountSI, pressReleaseCountALL - pressReleaseCountAR);
-
+
Assert.assertEquals("Key press count failure (SI)", expPressedCountSI, keyPressedSI);
Assert.assertEquals("Key released count failure (SI)", expReleasedCountSI, keyReleasedSI);
Assert.assertEquals("Key press count failure (AR)", expPressedCountAR, keyPressedAR);
Assert.assertEquals("Key released count failure (AR)", expReleasedCountAR, keyReleasedAR);
-
+
Assert.assertEquals("Key pressRelease count failure (SI)", expPressReleaseCountSI, pressReleaseCountSI);
Assert.assertEquals("Key pressRelease count failure (AR)", expPressReleaseCountAR, pressReleaseCountAR);
-
- final List<EventObject> keyEvents = keyAdapter.getQueued();
-
+
+ final List<EventObject> 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<EventObject> getQueued() {
- return queue;
+ public synchronized List<EventObject> copyQueue() {
+ return new ArrayList<EventObject>(queue);
}
public synchronized int getQueueSize() {