From b9adfc2c67d2bc46cae887ed39a5953b1e74e96a Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 8 Oct 2010 01:56:46 +0200 Subject: Fix: JOGL GLContextLock starvation; Tighten NEWT/AWT focus unit tests Fix: JOGL GLContextLock starvation - Apply changes made in RecursiveToolkitLock (c8a9c59e4838cd43090378a7ed60544449472801), ie notifyAll() -> notify(), plus sync (flow/mem) usage. Fix: Tighten NEWT/AWT focus unit tests - AWTRobotUtil.requestFocusAndWait() waits for EventCountAdapter gain and lost focus as well. - In case of NewtCanvasAWT, additionally wait for it's lost focus --- .../test/junit/newt/TestFocus01SwingAWTRobot.java | 7 ++-- .../test/junit/newt/TestFocus02SwingAWTRobot.java | 16 ++++---- .../com/jogamp/test/junit/util/AWTRobotUtil.java | 46 ++++++++++++++++++++++ 3 files changed, 59 insertions(+), 10 deletions(-) (limited to 'src/junit') 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