From: <gjo...@us...> - 2007-10-18 16:51:18
|
Revision: 2567 http://abbot.svn.sourceforge.net/abbot/?rev=2567&view=rev Author: gjohnsto Date: 2007-10-18 09:51:16 -0700 (Thu, 18 Oct 2007) Log Message: ----------- fixed timing problems added providing more failure info Modified Paths: -------------- abbot.swt/trunk/abbot.swt.test/src/abbot/swt/test/RobotTest.java Modified: abbot.swt/trunk/abbot.swt.test/src/abbot/swt/test/RobotTest.java =================================================================== --- abbot.swt/trunk/abbot.swt.test/src/abbot/swt/test/RobotTest.java 2007-10-18 01:20:50 UTC (rev 2566) +++ abbot.swt/trunk/abbot.swt.test/src/abbot/swt/test/RobotTest.java 2007-10-18 16:51:16 UTC (rev 2567) @@ -151,12 +151,13 @@ private void mouseMove(final int x, final int y) { robot.mouseMove(x, y); Wait.wait(new Condition() { + private Point location; public boolean test() { - Point location = getCursorLocation(); + location = getCursorLocation(); return location.x == x && location.y == y; } public String toString() { - return String.format("cursor location %d,%d", x, y); + return String.format("expected cursor location %d,%d, got %s", x, y, location); } }, 5000); } @@ -196,7 +197,7 @@ int x = bounds.x + bounds.width / 2; int y = bounds.y + bounds.height / 2; mouseMove(x, y); - assertSame(shell, getCursorControl()); + waitCursorControl(shell); // Check press & release of button 1. List<Event> events = clickEvents(shell, SWT.BUTTON1, 2); @@ -494,7 +495,7 @@ int x = bounds.x + bounds.width / 2; int y = bounds.y + bounds.height / 2; mouseMove(x, y); - assertSame(shell, getCursorControl()); + waitCursorControl(shell); // Just to be sure... assertSame(shell, getFocusControl()); @@ -537,6 +538,19 @@ } }); } + + private void waitCursorControl(final Control expected) { + Wait.wait(new Condition() { + private Control actual; + public boolean test() { + actual = getCursorControl(); + return actual == expected; + } + public String toString() { + return String.format("expected cursor control %s, got %s", expected, actual); + } + }, 5000); + } private Control getFocusControl() { return (Control) syncExec(new Result<Control>() { @@ -749,29 +763,62 @@ }); } } + + private static class PixelColorCondition implements Condition { + + private static final double ERROR_DIFF = 0.05 * 255.0; + private final Robot robot; + + private final Color expectedColor; + + private final int x, y; + + private Color actualColor; + + private double diff; + + public PixelColorCondition(Robot robot, Color expectedColor, int x, int y) { + this.robot = robot; + this.expectedColor = expectedColor; + this.x = x; + this.y = y; + } + + public boolean test() { + dispose(); + actualColor = robot.getPixelColor(x, y); + diff = colorDiff(expectedColor, actualColor); + return diff < ERROR_DIFF; + } + + public void dispose() { + if (actualColor != null) + actualColor.dispose(); + } + + private double colorDiff(Color color0, Color color1) { + int rr = (color0.getRed() - color1.getRed()) ^ 2; + int gg = (color0.getGreen() - color1.getGreen()) ^ 2; + int bb = (color0.getBlue() - color1.getBlue()) ^ 2; + double mm = (double) (rr + gg + bb) / 3.0; + return Math.sqrt(mm); + } + + public String toString() { + return String.format( + "pixel color %s at %d,%d, got %s (diff %f)", + expectedColor, + x, + y, + actualColor, + diff); + } + } + private void checkGetPixelColor(final Color expectedColor, final int x, final int y) { - Wait.wait(new Condition() { - public boolean test() { - Color color = robot.getPixelColor(x, y); - double diff = colorDiff(expectedColor, color); - color.dispose(); - return diff < ERROR_DIFF; - } - public String toString() { - return String.format("%s at %d,%d", expectedColor, x, y); - } - }, 5000L); + Wait.wait(new PixelColorCondition(robot, expectedColor, x, y), 5000); } - private static final double ERROR_DIFF = 0.05 * 255.0; - - private double colorDiff(Color color0, Color color1) { - int rr = (color0.getRed() - color1.getRed()) ^ 2; - int gg = (color0.getGreen() - color1.getGreen()) ^ 2; - int bb = (color0.getBlue() - color1.getBlue()) ^ 2; - double mm = (double) (rr + gg + bb) / 3.0; - return Math.sqrt(mm); - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |