diff options
Diffstat (limited to 'src/junit/com/jogamp/test')
3 files changed, 59 insertions, 10 deletions
diff --git a/src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWTRobot.java b/src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWTRobot.java index 97b37aec0..6ae0ee9d3 100644 --- a/src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWTRobot.java +++ b/src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWTRobot.java @@ -161,7 +161,7 @@ public class TestFocus01SwingAWTRobot extends UITestCase { Thread.sleep(100); // allow event sync System.err.println("FOCUS AWT Button request"); EventCountAdapterUtil.reset(eventCountAdapters); - Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, button, button)); + Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, button, button, buttonFA, null)); Assert.assertEquals(1, buttonFA.getCount()); Assert.assertEquals(0, glWindow1FA.getCount()); Assert.assertEquals(0, newtCanvasAWTFA.getCount()); @@ -172,10 +172,11 @@ public class TestFocus01SwingAWTRobot extends UITestCase { Thread.sleep(100); // allow event sync System.err.println("FOCUS NEWT Canvas/GLWindow request"); EventCountAdapterUtil.reset(eventCountAdapters); - Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild())); + Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild(), glWindow1FA, buttonFA)); + Assert.assertTrue(AWTRobotUtil.waitForCount(0, newtCanvasAWTFA)); Assert.assertEquals(1, glWindow1FA.getCount()); Assert.assertEquals(0, newtCanvasAWTFA.getCount()); - // Assert.assertEquals(-1, buttonFA.getCount()); // lost focus + Assert.assertEquals(-1, buttonFA.getCount()); // lost focus System.err.println("FOCUS NEWT Canvas/GLWindow sync"); Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, glWindow1, glWindow1KA)); Assert.assertEquals("AWT parent canvas received keyboard events", 0, newtCanvasAWTKA.getCount()); diff --git a/src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWTRobot.java b/src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWTRobot.java index a7602b49b..1ca5e6cd7 100644 --- a/src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWTRobot.java +++ b/src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWTRobot.java @@ -177,7 +177,7 @@ public class TestFocus02SwingAWTRobot extends UITestCase { Thread.sleep(100); // allow event sync System.err.println("FOCUS AWT Button Outer request"); EventCountAdapterUtil.reset(eventCountAdapters); - Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, buttonNorthOuter, buttonNorthOuter)); + Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, buttonNorthOuter, buttonNorthOuter, buttonNorthOuterFA, null)); Assert.assertEquals(1, buttonNorthOuterFA.getCount()); Assert.assertEquals(0, glWindow1FA.getCount()); Assert.assertEquals(0, newtCanvasAWTFA.getCount()); @@ -194,11 +194,12 @@ public class TestFocus02SwingAWTRobot extends UITestCase { Thread.sleep(100); // allow event sync System.err.println("FOCUS NEWT Canvas/GLWindow request"); EventCountAdapterUtil.reset(eventCountAdapters); - Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild())); + Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild(), glWindow1FA, buttonNorthOuterFA)); + Assert.assertTrue(AWTRobotUtil.waitForCount(0, newtCanvasAWTFA)); Assert.assertEquals(1, glWindow1FA.getCount()); Assert.assertEquals(0, newtCanvasAWTFA.getCount()); Assert.assertEquals(0, buttonNorthInnerFA.getCount()); - // Assert.assertEquals(-1, buttonNorthOuterFA.getCount()); // lost focus + Assert.assertEquals(-1, buttonNorthOuterFA.getCount()); // lost focus Assert.assertEquals(0, jFrame1FA.getCount()); System.err.println("FOCUS NEWT Canvas/GLWindow sync"); Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, glWindow1, glWindow1KA)); @@ -213,9 +214,9 @@ public class TestFocus02SwingAWTRobot extends UITestCase { Thread.sleep(100); // allow event sync System.err.println("FOCUS AWT Button request"); EventCountAdapterUtil.reset(eventCountAdapters); - Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, buttonNorthInner, buttonNorthInner)); + Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, buttonNorthInner, buttonNorthInner, buttonNorthInnerFA, glWindow1FA)); Assert.assertEquals(1, buttonNorthInnerFA.getCount()); - // Assert.assertEquals(-1, glWindow1FA.getCount()); // lost focus + Assert.assertEquals(-1, glWindow1FA.getCount()); // lost focus Assert.assertEquals(0, newtCanvasAWTFA.getCount()); Assert.assertEquals(0, buttonNorthOuterFA.getCount()); Assert.assertEquals(0, jFrame1FA.getCount()); @@ -230,10 +231,11 @@ public class TestFocus02SwingAWTRobot extends UITestCase { Thread.sleep(100); // allow event sync System.err.println("FOCUS NEWT Canvas/GLWindow request"); EventCountAdapterUtil.reset(eventCountAdapters); - Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild())); + Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild(), glWindow1FA, buttonNorthInnerFA)); + Assert.assertTrue(AWTRobotUtil.waitForCount(0, newtCanvasAWTFA)); Assert.assertEquals(1, glWindow1FA.getCount()); Assert.assertEquals(0, newtCanvasAWTFA.getCount()); - // Assert.assertEquals(-1, buttonNorthInnerFA.getCount()); // lost focus + Assert.assertEquals(-1, buttonNorthInnerFA.getCount()); // lost focus Assert.assertEquals(0, buttonNorthOuterFA.getCount()); Assert.assertEquals(0, jFrame1FA.getCount()); System.err.println("FOCUS NEWT Canvas/GLWindow sync"); diff --git a/src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java b/src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java index 48563b190..4e0d4a883 100644 --- a/src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java +++ b/src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java @@ -211,6 +211,27 @@ public class AWTRobotUtil { return wait<POLL_DIVIDER; } + /** + * + * @return True if the Window became the global focused Window within TIME_OUT + */ + public static boolean waitForFocus(Object obj, int gainT0, EventCountAdapter gain, + int lostT0, EventCountAdapter lost) throws InterruptedException { + if(!waitForFocus(obj)) { + return false; + } + int wait; + for (wait=0; wait<POLL_DIVIDER; wait++) { + int gainT1 = gain.getCount(); + int lostT1 = (null!=lost) ? lost.getCount() : -1; + if(gainT1-gainT0==1 && lostT1-lostT0==-1) { + return true; + } + Thread.sleep(TIME_OUT/POLL_DIVIDER); + } + return false; + } + public static boolean requestFocusAndWait(Robot robot, Object requestFocus, Object waitForFocus) throws AWTException, InterruptedException, InvocationTargetException { @@ -218,6 +239,17 @@ public class AWTRobotUtil { return waitForFocus(waitForFocus); } + public static boolean requestFocusAndWait(Robot robot, Object requestFocus, Object waitForFocus, + EventCountAdapter gain, EventCountAdapter lost) + throws AWTException, InterruptedException, InvocationTargetException { + + int gainT0 = gain.getCount(); + int lostT0 = (null!=lost) ? lost.getCount() : 0; + + requestFocus(robot, requestFocus); + return waitForFocus(waitForFocus, gainT0, gain, lostT0, lost); + } + /** * @param keyTypedCounter shall return the number of keys typed (press + release) * @return True if typeCount keys within TIME_OUT has been received @@ -288,5 +320,19 @@ public class AWTRobotUtil { return mouseClickCounter.getCount()-c0; } + /** + * + * @return True if the EventCountAdapter became the desired value within TIME_OUT + */ + public static boolean waitForCount(int desired, EventCountAdapter eca) throws InterruptedException { + for (int wait=0; wait<POLL_DIVIDER; wait++) { + if( eca.getCount() == desired ) { + return true; + } + Thread.sleep(TIME_OUT/POLL_DIVIDER); + } + return false; + } + } |