Index: gnu/testlet/TestHarness.java =================================================================== RCS file: /cvs/mauve/mauve/gnu/testlet/TestHarness.java,v retrieving revision 1.22 diff -u -r1.22 TestHarness.java --- gnu/testlet/TestHarness.java 22 Feb 2006 15:55:06 -0000 1.22 +++ gnu/testlet/TestHarness.java 22 Feb 2006 17:41:57 -0000 @@ -190,113 +190,6 @@ check (false); } - /** - * Compares two colors. - * - * @param a - - * Color to compare. - * @param b - - * Color to compare. - * @param match - - * true if colors should be equivalent. - */ - public void checkColor(Color a, Color b, boolean match) - { - if (match) - check(a.getRed() == b.getRed() && a.getGreen() == b.getGreen() - && a.getBlue() == b.getBlue()); - else - check(!(a.getRed() == b.getRed() && a.getGreen() == b.getGreen() - && a.getBlue() == b.getBlue())); - } - - /** - * This method checks that the pixels outside of the rectange, at all corners, - * match (or don't match) a given color. - * - * @param r - - * the Robot to use to get the pixel color at a location. - * @param rect - - * the Rectangle to check - * @param comp - - * the Color to compare the pixel colors to. - * @param match - - * true if the pixel outside the rectangle corner should be - * equivalent to comp. - */ - public void checkRectangleOuterColors(Robot r, Rectangle rect, Color comp, - boolean match) - { - Color c; - - // top-left-left - c = r.getPixelColor(rect.x - 1, rect.y); - checkColor(c, comp, match); - - // top-left-top - r.getPixelColor(rect.x, rect.y - 1); - checkColor(c, comp, match); - - // top-right-right - r.getPixelColor((rect.x + rect.width - 1) + 1, rect.y); - checkColor(c, comp, match); - - // top-right-top - r.getPixelColor((rect.x + rect.width - 1), rect.y - 1); - checkColor(c, comp, match); - - // bottom-left-left - r.getPixelColor(rect.x - 1, (rect.y + rect.height - 1)); - checkColor(c, comp, match); - - // bottom-left-bottom - r.getPixelColor(rect.x, (rect.y + rect.height - 1) + 1); - checkColor(c, comp, match); - - // bottom-right-right - r.getPixelColor((rect.x + rect.width - 1) + 1, (rect.y + rect.height - 1)); - checkColor(c, comp, match); - - // bottom-right-bottom - r.getPixelColor((rect.x + rect.width - 1), (rect.y + rect.height - 1) + 1); - checkColor(c, comp, match); - } - - /** - * This method checks the pixel colors of a Rectangle's corners. - * - * @param r - - * the Robot to use to get the pixel colors. - * @param rect - - * the Rectangle to check. - * @param comp - - * the Color to compare. - * @param match - - * true if the corner pixel color of the rectangle should be - * equivalent to comp. - */ - public void checkRectangleCornerColors(Robot r, Rectangle rect, Color comp, - boolean match) - { - Color c; - - // top-left - c = r.getPixelColor(rect.x, rect.y); - checkColor(c, comp, match); - - // top-right - c = r.getPixelColor(rect.x + rect.width - 1, rect.y); - checkColor(c, comp, match); - - // bottom-left - c = r.getPixelColor(rect.x, rect.y + rect.height - 1); - checkColor(c, comp, match); - - // bottom-right - c = r.getPixelColor(rect.x + rect.width - 1, rect.y + rect.height - 1); - checkColor(c, comp, match); - } - // Given a resource name, return a Reader on it. Resource names are // just like file names. They are relative to the top level Mauve // directory, but '#' characters are used in place of directory Index: gnu/testlet/java/awt/LocationTests.java =================================================================== RCS file: gnu/testlet/java/awt/LocationTests.java diff -N gnu/testlet/java/awt/LocationTests.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/awt/LocationTests.java 22 Feb 2006 17:41:57 -0000 @@ -0,0 +1,147 @@ +/* LocationTests.java -- + Copyright (C) 2006 Red Hat +This file is part of Mauve. + +Mauve is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +Mauve is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Mauve; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +*/ + +// Tags: JDK 1.4 + +package gnu.testlet.java.awt; + +import java.awt.Color; +import java.awt.Rectangle; +import java.awt.Robot; + +import gnu.testlet.TestHarness; + +/** + * This class tests the location of a rectangle on the screen + * using the colors of the rectangle and a given color. + * + * @author langel (langel at redhat dot com) + */ +public class LocationTests +{ + + /** + * Compares two colors. + * + * @param a - + * Color to compare. + * @param b - + * Color to compare. + * @param match - + * true if colors should be equivalent. + */ + public static void checkColor(TestHarness h, Color a, Color b, boolean match) + { + if (match) + h.check(a.getRed() == b.getRed() && a.getGreen() == b.getGreen() + && a.getBlue() == b.getBlue()); + else + h.check(!(a.getRed() == b.getRed() && a.getGreen() == b.getGreen() + && a.getBlue() == b.getBlue())); + } + + /** + * This method checks that the pixels outside of the rectange, at all corners, + * match (or don't match) a given color. + * + * @param r - + * the Robot to use to get the pixel color at a location. + * @param rect - + * the Rectangle to check + * @param comp - + * the Color to compare the pixel colors to. + * @param match - + * true if the pixel outside the rectangle corner should be + * equivalent to comp. + */ + public static void checkRectangleOuterColors(TestHarness h, Robot r, Rectangle rect, Color comp, + boolean match) + { + Color c; + + // top-left-left + c = r.getPixelColor(rect.x - 1, rect.y); + checkColor(h, c, comp, match); + + // top-left-top + r.getPixelColor(rect.x, rect.y - 1); + checkColor(h, c, comp, match); + + // top-right-right + r.getPixelColor((rect.x + rect.width - 1) + 1, rect.y); + checkColor(h, c, comp, match); + + // top-right-top + r.getPixelColor((rect.x + rect.width - 1), rect.y - 1); + checkColor(h, c, comp, match); + + // bottom-left-left + r.getPixelColor(rect.x - 1, (rect.y + rect.height - 1)); + checkColor(h, c, comp, match); + + // bottom-left-bottom + r.getPixelColor(rect.x, (rect.y + rect.height - 1) + 1); + checkColor(h, c, comp, match); + + // bottom-right-right + r.getPixelColor((rect.x + rect.width - 1) + 1, (rect.y + rect.height - 1)); + checkColor(h, c, comp, match); + + // bottom-right-bottom + r.getPixelColor((rect.x + rect.width - 1), (rect.y + rect.height - 1) + 1); + checkColor(h, c, comp, match); + } + + /** + * This method checks the pixel colors of a Rectangle's corners. + * + * @param r - + * the Robot to use to get the pixel colors. + * @param rect - + * the Rectangle to check. + * @param comp - + * the Color to compare. + * @param match - + * true if the corner pixel color of the rectangle should be + * equivalent to comp. + */ + public static void checkRectangleCornerColors(TestHarness h, Robot r, Rectangle rect, Color comp, + boolean match) + { + Color c; + + // top-left + c = r.getPixelColor(rect.x, rect.y); + checkColor(h, c, comp, match); + + // top-right + c = r.getPixelColor(rect.x + rect.width - 1, rect.y); + checkColor(h, c, comp, match); + + // bottom-left + c = r.getPixelColor(rect.x, rect.y + rect.height - 1); + checkColor(h, c, comp, match); + + // bottom-right + c = r.getPixelColor(rect.x + rect.width - 1, rect.y + rect.height - 1); + checkColor(h, c, comp, match); + } +} Index: gnu/testlet/java/awt/Container/LightweightContainer.java =================================================================== RCS file: /cvs/mauve/mauve/gnu/testlet/java/awt/Container/LightweightContainer.java,v retrieving revision 1.3 diff -u -r1.3 LightweightContainer.java --- gnu/testlet/java/awt/Container/LightweightContainer.java 22 Feb 2006 15:55:06 -0000 1.3 +++ gnu/testlet/java/awt/Container/LightweightContainer.java 22 Feb 2006 17:41:57 -0000 @@ -25,6 +25,7 @@ import gnu.testlet.TestHarness; import gnu.testlet.Testlet; +import gnu.testlet.java.awt.LocationTests; import java.awt.*; @@ -34,6 +35,7 @@ public void test (TestHarness harness) { testLoc(harness); + testLoc2(harness); testWindow(harness); } @@ -61,9 +63,10 @@ bounds.y = loc.y + i.top; // bounds of blue rectangle inside red rectangle Rectangle bounds2 = new Rectangle(bounds.x + 1, bounds.y + 1, bounds.width - 2, bounds.height - 2); - harness.checkRectangleOuterColors(r, bounds2, Color.red, true); - harness.checkRectangleCornerColors(r, bounds2, Color.red, false); + LocationTests.checkRectangleOuterColors(harness, r, bounds2, Color.red, true); + LocationTests.checkRectangleCornerColors(harness, r, bounds2, Color.red, false); + // There is a delay so the tester can see the result. r.delay(3000); } @@ -115,18 +118,74 @@ fgHW_x = p.x + i.left + fgHW_x + fgLW_x; fgHW_y = p.y + i.top + fgHW_y + fgLW_y; Rectangle b = new Rectangle(fgHW_x, fgHW_y, fgHW_w, fgHW_h); - harness.checkRectangleOuterColors(r, b, bgHW_c, true); + LocationTests.checkRectangleOuterColors(harness, r, b, bgHW_c, true); // check the fgHW's corner pixels. - harness.checkRectangleCornerColors(r, b, fgHW_c, true); - harness.checkRectangleCornerColors(r, b, bgHW_c, false); + LocationTests.checkRectangleCornerColors(harness, r, b, fgHW_c, true); + LocationTests.checkRectangleCornerColors(harness, r, b, bgHW_c, false); // check the two pixels adjacent to each corner of the fgLW p = f.getLocationOnScreen(); fgLW_x = p.x + i.left + fgLW_x; fgLW_y = p.y + i.top + fgLW_y; - harness.checkRectangleOuterColors(r, new Rectangle(fgLW_x, fgLW_y, fgLW_w, fgLW_h), bgHW_c, true); + LocationTests.checkRectangleOuterColors(harness, r, new Rectangle(fgLW_x, fgLW_y, fgLW_w, fgLW_h), bgHW_c, true); + + // There is a delay so the tester can see the result. + r.delay(3000); + } + + // Tests the location of a Lightweight Container next to + // a heavyweight panel, both in a frame. + public void testLoc2(TestHarness harness) + { + Robot r = harness.createRobot(); + Frame f = new Frame(); + f.setLayout(new BorderLayout()); + Panel HW = new Panel(); + HW.setLayout (new BorderLayout()); + HW.add (new testPanel(Color.green), BorderLayout.CENTER); + f.add(HW, BorderLayout.CENTER); + + testContainer LW = new testContainer(); + GridBagLayout gridbag = new GridBagLayout(); + GridBagConstraints c = new GridBagConstraints(); + LW.setLayout(gridbag); + Button b1 = new Button("Button1"); + Button b2 = new Button("Button2"); + Button b3 = new Button("Button3"); + Label l = new Label("Label"); + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 0.0; c.weighty = 0.0; + c.insets = new Insets(4, 4, 1, 1); + c.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints(b1, c); + LW.add(b1); + c.gridwidth = 1; + gridbag.setConstraints(l, c); + LW.add(l); + gridbag.setConstraints(b2, c); + LW.add(b2); + gridbag.setConstraints(b3, c); + LW.add(b3); + f.add(LW, BorderLayout.EAST); + + // Wait for delay to avoid race conditions + r.waitForIdle(); + r.delay(300); + + f.setSize(500, 500); + f.show(); + + Rectangle bounds = LW.getBounds(); + Point loc = f.getLocationOnScreen(); + Insets i = f.getInsets(); + bounds.x = loc.x + i.left + HW.getWidth(); + bounds.y = loc.y + i.top; + LocationTests.checkRectangleOuterColors(harness, r, bounds, Color.red, false); + LocationTests.checkRectangleOuterColors(harness, r, bounds, Color.blue, false); + + // There is a delay so the tester can see the result. r.delay(3000); } Index: gnu/testlet/java/awt/Frame/size1.java =================================================================== RCS file: /cvs/mauve/mauve/gnu/testlet/java/awt/Frame/size1.java,v retrieving revision 1.3 diff -u -r1.3 size1.java --- gnu/testlet/java/awt/Frame/size1.java 22 Feb 2006 15:55:06 -0000 1.3 +++ gnu/testlet/java/awt/Frame/size1.java 22 Feb 2006 17:41:57 -0000 @@ -23,6 +23,7 @@ import gnu.testlet.TestHarness; import gnu.testlet.Testlet; +import gnu.testlet.java.awt.LocationTests; import java.awt.*; @@ -91,11 +92,12 @@ // check the two pixels adjacent to each corner of the foreground // frame. - harness.checkRectangleOuterColors(r, bounds, nonWMColor, true); + LocationTests.checkRectangleOuterColors(harness, r, bounds, nonWMColor, true); // check the frame's corner pixels. - harness.checkRectangleCornerColors(r, bounds, nonWMColor, false); - + LocationTests.checkRectangleCornerColors(harness, r, bounds, nonWMColor, false); + + // There is a delay so the tester can see the result. r.delay (3000); } }