From cf2ebbf3e584e7f7a15c323633a495b119ece37e Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 1 May 2011 06:40:46 +0200 Subject: UI Tests/Robot: Attempt to stabilize UI tests (focus/input) Focus: Always programmatic, clear global focus state upfront Key/Mouse Input: Retry w/ optional focus request if lost .. Dropped redundant robot delays, ie between keypress/release. --- make/build-test.xml | 1 + make/scripts/tests.sh | 6 +- .../test/junit/newt/TestFocus01SwingAWTRobot.java | 26 +- .../test/junit/newt/TestFocus02SwingAWTRobot.java | 110 +++++---- .../opengl/test/junit/util/AWTRobotUtil.java | 265 +++++++++++++-------- 5 files changed, 245 insertions(+), 163 deletions(-) diff --git a/make/build-test.xml b/make/build-test.xml index 18b131594..9dfc526c9 100644 --- a/make/build-test.xml +++ b/make/build-test.xml @@ -45,6 +45,7 @@ + diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index 03c27c103..37194f602 100755 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -72,7 +72,7 @@ function jrun() { #D_ARGS="-Djogl.debug.GraphicsConfiguration" #D_ARGS="-Djogl.debug.GLCanvas -Djogl.debug.GraphicsConfiguration" #D_ARGS="-Djogl.debug.GLCanvas" - D_ARGS="-Djogl.debug.DebugGL -Djogl.debug.GLDebugMessageHandler" + #D_ARGS="-Djogl.debug.DebugGL -Djogl.debug.GLDebugMessageHandler" #D_ARGS="-Djogl.debug.DebugGL -Djogl.debug.TraceGL" #D_ARGS="-Djogl.debug.GLDebugMessageHandler -Dnewt.debug.Window -Dnewt.debug.Display -Dnewt.debug.EDT" #D_ARGS="-Djogl.debug.GLDebugMessageHandler" @@ -172,7 +172,7 @@ function testawtmt() { #testawt com.jogamp.opengl.test.junit.jogl.newt.TestSwingAWTRobotUsageBeforeJOGLInitBug411 #testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.newt.TestGearsNewtAWTWrapper #testawt com.jogamp.opengl.test.junit.newt.TestEventSourceNotAWTBug -#testawt com.jogamp.opengl.test.junit.newt.TestFocus01SwingAWTRobot +testawt com.jogamp.opengl.test.junit.newt.TestFocus01SwingAWTRobot #testawt com.jogamp.opengl.test.junit.newt.TestFocus02SwingAWTRobot #testawt com.jogamp.opengl.test.junit.newt.TestListenerCom01AWT #testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01aAWT @@ -207,7 +207,7 @@ function testawtmt() { # #testnoawt com.jogamp.opengl.test.junit.jogl.glsl.TestTransformFeedbackVaryingsBug407NEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.glsl.TestGLSLSimple01NEWT $* -testnoawt com.jogamp.opengl.test.junit.jogl.glsl.TestGLSLShaderState01NEWT $* +#testnoawt com.jogamp.opengl.test.junit.jogl.glsl.TestGLSLShaderState01NEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.glsl.TestGLSLShaderState02NEWT $* #testnoawt com.jogamp.opengl.test.junit.graph.TestRegionRendererNEWT01 $* 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 8be7d1c85..79196bd4c 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java @@ -119,6 +119,8 @@ public class TestFocus01SwingAWTRobot extends UITestCase { // Add the canvas to a frame, and make it all visible. JFrame frame1 = new JFrame("Swing AWT Parent Frame: " + glWindow1.getTitle()); + AWTFocusAdapter frame1FA = new AWTFocusAdapter("frame1"); + frame1.addFocusListener(frame1FA); frame1.getContentPane().add(newtCanvasAWT, BorderLayout.CENTER); Button button = new Button("Click me .."); AWTFocusAdapter buttonFA = new AWTFocusAdapter("Button"); @@ -141,29 +143,31 @@ public class TestFocus01SwingAWTRobot extends UITestCase { // Continuous animation .. Animator animator = new Animator(glWindow1); animator.start(); + AWTRobotUtil.assertRequestFocusAndWait(robot, frame1, frame1, frame1FA, null); // Button Focus Thread.sleep(100); // allow event sync + System.err.println("FOCUS AWT Button request"); EventCountAdapterUtil.reset(eventCountAdapters); - Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, button, button, buttonFA, null)); - Assert.assertEquals(1, buttonFA.getCount()); - Assert.assertEquals(0, glWindow1FA.getCount()); - Assert.assertEquals(0, newtCanvasAWTFA.getCount()); + AWTRobotUtil.assertRequestFocusAndWait(robot, button, button, buttonFA, null); + Assert.assertEquals(true, buttonFA.hasFocus()); + Assert.assertEquals(false, glWindow1FA.hasFocus()); + Assert.assertEquals(false, newtCanvasAWTFA.hasFocus()); System.err.println("FOCUS AWT Button sync"); - Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, button, buttonKA)); + AWTRobotUtil.assertKeyType(robot, java.awt.event.KeyEvent.VK_A, 2, button, buttonKA); // Request the AWT focus, which should automatically provide the NEWT window with focus. 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(), 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 + AWTRobotUtil.assertRequestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild(), glWindow1FA, buttonFA); + Assert.assertTrue(AWTRobotUtil.waitForFocusCount(false, newtCanvasAWTFA)); + Assert.assertEquals(true, glWindow1FA.hasFocus()); + Assert.assertEquals(false, newtCanvasAWTFA.hasFocus()); + Assert.assertEquals(false, buttonFA.hasFocus()); System.err.println("FOCUS NEWT Canvas/GLWindow sync"); - Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, glWindow1, glWindow1KA)); + AWTRobotUtil.assertKeyType(robot, java.awt.event.KeyEvent.VK_A, 2, glWindow1, glWindow1KA); Assert.assertEquals("AWT parent canvas received keyboard events", 0, newtCanvasAWTKA.getCount()); // Remove listeners to avoid logging during dispose/destroy. 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 996ce9ca8..47d986fcb 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java @@ -172,82 +172,82 @@ public class TestFocus02SwingAWTRobot extends UITestCase { // Continuous animation .. Animator animator1 = new Animator(glWindow1); animator1.start(); + AWTRobotUtil.assertRequestFocusAndWait(robot, jFrame1, jFrame1, jFrame1FA, null); // Button Outer Focus Thread.sleep(100); // allow event sync System.err.println("FOCUS AWT Button Outer request"); EventCountAdapterUtil.reset(eventCountAdapters); - Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, buttonNorthOuter, buttonNorthOuter, buttonNorthOuterFA, null)); - Assert.assertEquals(1, buttonNorthOuterFA.getCount()); - Assert.assertEquals(0, glWindow1FA.getCount()); - Assert.assertEquals(0, newtCanvasAWTFA.getCount()); - Assert.assertEquals(0, buttonNorthInnerFA.getCount()); - Assert.assertEquals(0, jFrame1FA.getCount()); + AWTRobotUtil.assertRequestFocusAndWait(robot, buttonNorthOuter, buttonNorthOuter, buttonNorthOuterFA, null); + Assert.assertEquals(true, buttonNorthOuterFA.hasFocus()); + Assert.assertEquals(false, glWindow1FA.hasFocus()); + Assert.assertEquals(false, newtCanvasAWTFA.hasFocus()); + Assert.assertEquals(false, buttonNorthInnerFA.hasFocus()); + Assert.assertEquals(false, jFrame1FA.hasFocus()); System.err.println("FOCUS AWT Button Outer sync"); - Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, buttonNorthOuter, buttonNorthOuterKA)); - Assert.assertEquals(1, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1, - buttonNorthOuter, buttonNorthOuterMA)); - Assert.assertEquals(3, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 2, - buttonNorthOuter, buttonNorthOuterMA)); + AWTRobotUtil.assertKeyType(robot, java.awt.event.KeyEvent.VK_A, 2, buttonNorthOuter, buttonNorthOuterKA); + AWTRobotUtil.assertMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1, + buttonNorthOuter, buttonNorthOuterMA); + AWTRobotUtil.assertMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 2, + buttonNorthOuter, buttonNorthOuterMA); // NEWT Focus 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(), 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(0, jFrame1FA.getCount()); + AWTRobotUtil.assertRequestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild(), glWindow1FA, buttonNorthOuterFA); + Assert.assertTrue(AWTRobotUtil.waitForFocusCount(false, newtCanvasAWTFA)); + Assert.assertEquals(true, glWindow1FA.hasFocus()); + Assert.assertEquals(false, newtCanvasAWTFA.hasFocus()); + Assert.assertEquals(false, buttonNorthInnerFA.hasFocus()); + Assert.assertEquals(false, buttonNorthOuterFA.hasFocus()); + Assert.assertEquals(false, jFrame1FA.hasFocus()); System.err.println("FOCUS NEWT Canvas/GLWindow sync"); - Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, glWindow1, glWindow1KA)); + AWTRobotUtil.assertKeyType(robot, java.awt.event.KeyEvent.VK_A, 2, glWindow1, glWindow1KA); Assert.assertEquals("AWT parent canvas received keyboard events", 0, newtCanvasAWTKA.getCount()); - Assert.assertEquals(1, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1, - glWindow1, glWindow1MA)); - Assert.assertEquals(3, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 2, - glWindow1, glWindow1MA)); + AWTRobotUtil.assertMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1, + glWindow1, glWindow1MA); + AWTRobotUtil.assertMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 2, + glWindow1, glWindow1MA); Assert.assertEquals("AWT parent canvas received mouse events", 0, newtCanvasAWTMA.getCount()); // Button Inner Focus Thread.sleep(100); // allow event sync System.err.println("FOCUS AWT Button request"); EventCountAdapterUtil.reset(eventCountAdapters); - Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, buttonNorthInner, buttonNorthInner, buttonNorthInnerFA, glWindow1FA)); - Assert.assertEquals(1, buttonNorthInnerFA.getCount()); - Assert.assertEquals(-1, glWindow1FA.getCount()); // lost focus - Assert.assertEquals(0, newtCanvasAWTFA.getCount()); - Assert.assertEquals(0, buttonNorthOuterFA.getCount()); - Assert.assertEquals(0, jFrame1FA.getCount()); + AWTRobotUtil.assertRequestFocusAndWait(robot, buttonNorthInner, buttonNorthInner, buttonNorthInnerFA, glWindow1FA); + Assert.assertEquals(true, buttonNorthInnerFA.hasFocus()); + Assert.assertEquals(false, glWindow1FA.hasFocus()); + Assert.assertEquals(false, newtCanvasAWTFA.hasFocus()); + Assert.assertEquals(false, buttonNorthOuterFA.hasFocus()); + Assert.assertEquals(false, jFrame1FA.hasFocus()); System.err.println("FOCUS AWT Button sync"); - Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, buttonNorthInner, buttonNorthInnerKA)); - Assert.assertEquals(1, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1, - buttonNorthInner, buttonNorthInnerMA)); - Assert.assertEquals(3, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 2, - buttonNorthInner, buttonNorthInnerMA)); + AWTRobotUtil.assertKeyType(robot, java.awt.event.KeyEvent.VK_A, 2, buttonNorthInner, buttonNorthInnerKA); + AWTRobotUtil.assertMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1, + buttonNorthInner, buttonNorthInnerMA); + AWTRobotUtil.assertMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 2, + buttonNorthInner, buttonNorthInnerMA); // NEWT Focus 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(), 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(0, buttonNorthOuterFA.getCount()); - Assert.assertEquals(0, jFrame1FA.getCount()); + AWTRobotUtil.assertRequestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild(), glWindow1FA, buttonNorthInnerFA); + Assert.assertTrue(AWTRobotUtil.waitForFocusCount(false, newtCanvasAWTFA)); + Assert.assertEquals(true, glWindow1FA.hasFocus()); + Assert.assertEquals(false, newtCanvasAWTFA.hasFocus()); + Assert.assertEquals(false, buttonNorthInnerFA.hasFocus()); + Assert.assertEquals(false, buttonNorthOuterFA.hasFocus()); + Assert.assertEquals(false, jFrame1FA.hasFocus()); System.err.println("FOCUS NEWT Canvas/GLWindow sync"); - Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, glWindow1, glWindow1KA)); + AWTRobotUtil.assertKeyType(robot, java.awt.event.KeyEvent.VK_A, 2, glWindow1, glWindow1KA); Assert.assertEquals("AWT parent canvas received keyboard events", 0, newtCanvasAWTKA.getCount()); - Assert.assertEquals(1, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1, - glWindow1, glWindow1MA)); - Assert.assertEquals(3, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 2, - glWindow1, glWindow1MA)); + AWTRobotUtil.assertMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1, + glWindow1, glWindow1MA); + AWTRobotUtil.assertMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 2, + glWindow1, glWindow1MA); Assert.assertEquals("AWT parent canvas received mouse events", 0, newtCanvasAWTMA.getCount()); - animator1.stop(); Assert.assertEquals(false, animator1.isAnimating()); @@ -284,7 +284,9 @@ public class TestFocus02SwingAWTRobot extends UITestCase { return i; } - public static void main(String args[]) throws IOException { + public static void main(String args[]) + throws IOException, AWTException, InterruptedException, InvocationTargetException + { for(int i=0; i tc && j tc; wait++) { + robot.delay(TIME_SLICE); + tc = counter.getCount() - c0; + } + if(DEBUG) { System.err.println(i+":"+j+" KC1.X: tc "+tc+", "+counter); } + } + Assert.assertEquals("Key ("+i+":"+j+") not typed one time", 1, tc); + return (int) ( System.currentTimeMillis() - t0 ) ; } - + /** - * @param keyTypedCounter shall return the number of keys typed (press + release) - * @return True if typeCount keys within TIME_OUT has been received + * @param keyCode TODO + * @param counter shall return the number of keys typed (press + release) */ - public static int testKeyType(Robot robot, int typeCount, Object obj, EventCountAdapter keyTypedCounter) + public static void assertKeyType(Robot robot, int keyCode, int typeCount, + Object obj, InputEventCountAdapter counter) throws AWTException, InterruptedException, InvocationTargetException { - Component comp = null; - com.jogamp.newt.Window win = null; if(null == robot) { robot = new Robot(); @@ -258,30 +296,59 @@ public class AWTRobotUtil { centerMouse(robot, obj); - int c0 = keyTypedCounter.getCount(); + Assert.assertEquals("Key already pressed", false, counter.isPressed()); + + if(DEBUG) { + System.err.println("**************************************"); + System.err.println("KC0: "+counter); + } + + final int c0 = counter.getCount(); for(int i=0; i tc && j tc; wait++) { + robot.delay(TIME_SLICE); + tc = counter.getCount() - c0; + } + if(DEBUG) { System.err.println(i+":"+j+" MC1.X: tc "+tc+", "+counter); } + } + Assert.assertEquals("Mouse ("+i+":"+j+") not clicked one time", 1, tc); + return (int) ( System.currentTimeMillis() - t0 ) ; + } + /** * @param mouseButton ie InputEvent.BUTTON1_MASK * @param clickCount ie 1, or 2 - * @return True if the desired clickCount within TIME_OUT has been received */ - public static int testMouseClick(Robot robot, int mouseButton, int clickCount, - Object obj, EventCountAdapter mouseClickCounter) + public static void assertMouseClick(Robot robot, int mouseButton, int clickCount, + Object obj, InputEventCountAdapter counter) throws AWTException, InterruptedException, InvocationTargetException { if(null == robot) { @@ -293,35 +360,35 @@ public class AWTRobotUtil { centerMouse(robot, obj); - robot.delay(2*clickTO); - - int c0 = mouseClickCounter.getCount(); - + Assert.assertEquals("Mouse already pressed", false, counter.isPressed()); + + if(DEBUG) { + System.err.println("**************************************"); + System.err.println("MC0: "+counter); + } + + final int c0 = counter.getCount(); + for(int i=0; i drawable.setRealized(true); if(wait=POLL_DIVIDER) { // for some reason GLCanvas hasn't been painted yet, force it! System.err.println("XXX: FORCE REPAINT PRE - canvas: "+glcanvas); glcanvas.repaint(); for (wait=0; wait