From a0c50530714ceb3072e258b8704cd05376d30074 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 27 Mar 2013 03:19:38 +0100 Subject: Unit Tests: Unify 'AWT Robot Key Press/Release', waitForIdle, action, delay, waitForIdle ; TestFocus0*: Wait until closed after win.destroy(). --- .../test/junit/newt/TestFocus01SwingAWTRobot.java | 1 + .../test/junit/newt/TestFocus02SwingAWTRobot.java | 1 + .../opengl/test/junit/util/AWTRobotUtil.java | 37 ++++++++++++++-------- 3 files changed, 26 insertions(+), 13 deletions(-) (limited to 'src/test/com/jogamp/opengl') diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java index a87cbe0ac..672a44154 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java @@ -208,6 +208,7 @@ public class TestFocus01SwingAWTRobot extends UITestCase { Assume.assumeNoException( throwable ); } glWindow1.destroy(); + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glWindow1, false)); } static int atoi(String a) { diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java index 978bc1c0a..5d0a0fbb5 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java @@ -262,6 +262,7 @@ public class TestFocus02SwingAWTRobot extends UITestCase { } }); glWindow1.destroy(); + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glWindow1, false)); } @Test 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 960145e78..4195711d6 100644 --- a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java +++ b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java @@ -393,6 +393,19 @@ public class AWTRobotUtil { Assert.assertTrue("Did not gain focus", hasFocus); } + private static void awtRobotKeyPress(final Robot robot, final int keyCode, final int msDelay) { + robot.waitForIdle(); + robot.keyPress(keyCode); + robot.delay(msDelay); + robot.waitForIdle(); + } + private static void awtRobotKeyRelease(final Robot robot, final int keyCode, final int msDelay) { + robot.waitForIdle(); + robot.keyRelease(keyCode); + robot.delay(msDelay); + robot.waitForIdle(); + } + public static int keyType(int i, Robot robot, int keyCode, Object obj, KeyEventCountAdapter counter) throws InterruptedException, AWTException, InvocationTargetException { @@ -404,24 +417,23 @@ public class AWTRobotUtil { for(j=0; 1 > tc && j tc; wait++) { + if(DEBUG) { System.err.println(i+":"+j+" KC1.4."+wait+": "+counter+", sleep for "+TIME_OUT+"ms"); } robot.delay(TIME_SLICE); tc = counter.getCount() - c0; } - if(DEBUG) { System.err.println(i+":"+j+" KC1.X: tc "+tc+", "+counter); } + if(DEBUG) { System.err.println(i+":"+j+" KC1.X: tc "+tc+", "+counter+" on thread "+Thread.currentThread().getName()); } } - Assert.assertEquals("Key ("+i+":"+j+") not typed one time", 1, tc); + Assert.assertEquals("Key ("+i+":"+j+") not typed one time on thread "+Thread.currentThread().getName(), 1, tc); return (int) ( System.currentTimeMillis() - t0 ) ; } @@ -429,11 +441,10 @@ public class AWTRobotUtil { public static int keyPress(int i, Robot robot, boolean press, int keyCode, int msDelay) { final long t0 = System.currentTimeMillis(); if(press) { - robot.keyPress(keyCode); + awtRobotKeyPress(robot, keyCode, msDelay); } else { - robot.keyRelease(keyCode); + awtRobotKeyRelease(robot, keyCode, msDelay); } - robot.delay(msDelay); return (int) ( System.currentTimeMillis() - t0 ) ; } -- cgit v1.2.3