This is the mail archive of the mauve-patches@sourceware.org mailing list for the Mauve project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: New Lightweight tests


I added new tests for Lightweight Containers.

2006-02-21  Lillian Angel  <langel@redhat.com>

        * gnu/testlet/TestHarness.java
        (checkColor): New method used to compare colors.
        (checkRectangleOuterColors): New method used to compare the
        colors of a rectangle's corners to the colors of the pixels
        surrounding the corners.
        (checkRectangleCornerColors): New method used to compare
        the colors of the pixels at the corners of a rectangle, to
        a given color.
        * gnu/testlet/java/awt/Container/LightweightContainer.java:
        New Test.
        * gnu/testlet/java/awt/Frame/size1.java
        (checkColor): Removed.
        (test): Changed to use new methods in TestHarness.

Index: gnu/testlet/TestHarness.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/TestHarness.java,v
retrieving revision 1.20
diff -u -r1.20 TestHarness.java
--- gnu/testlet/TestHarness.java	8 Nov 2005 21:49:38 -0000	1.20
+++ gnu/testlet/TestHarness.java	21 Feb 2006 23:48:02 -0000
@@ -21,11 +21,14 @@
 
 package gnu.testlet;
 
+import java.awt.AWTException;
+import java.awt.Color;
+import java.awt.Rectangle;
+import java.awt.Robot;
+
 import java.io.File;
 import java.io.Reader;
 import java.io.InputStream;
-import java.awt.AWTException;
-import java.awt.Robot;
 
 /**
  * This base class defines the API that test cases can report against.  This
@@ -186,7 +189,114 @@
       checkPoint (name);
       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/Container/LightweightContainer.java
===================================================================
RCS file: gnu/testlet/java/awt/Container/LightweightContainer.java
diff -N gnu/testlet/java/awt/Container/LightweightContainer.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/Container/LightweightContainer.java	21 Feb 2006 23:48:02 -0000
@@ -0,0 +1,170 @@
+/* LightweightContainer.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.Container;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.*;
+
+public class LightweightContainer implements Testlet
+{
+  
+  public void test (TestHarness harness)
+  {
+    testLoc(harness);
+    testWindow(harness);
+  }
+  
+  // Tests a Window containing a Frame and a Lightweight Container
+  public void testWindow(TestHarness harness)
+  {
+    Robot r = harness.createRobot();
+        
+    Frame f = new Frame();
+    testContainer tc = new testContainer();
+    f.setSize(500, 500);
+    tc.setBounds(0, 0, 500, 500);
+    f.add(tc);
+    f.show();
+
+    r.waitForIdle();
+    r.delay(300);
+    
+    // bounds of red rectangle (1 pixel wide border)
+    Rectangle bounds = tc.getBounds();
+    Point loc = f.getLocationOnScreen();
+    Insets i = f.getInsets();
+    bounds.x = loc.x + i.left;
+    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);
+    
+    r.delay(3000);
+  }
+  
+  // Tests the location of a Lightweight Container containing
+  // a heavyweight component, which is also in a heavyweight
+  public void testLoc(TestHarness harness)
+  {
+    Robot r = harness.createRobot();
+    Color bgHW_c = Color.red;
+    Color fgHW_c = Color.blue;
+    
+    testPanel bgHW = new testPanel(bgHW_c);
+    Container fgLW = new Container();
+    testPanel fgHW = new testPanel(fgHW_c);
+    
+    Frame f = new Frame();
+    
+    int bgHW_x = 0;
+    int bgHW_y = 0;
+    int bgHW_w = 500;
+    int bgHW_h = 500;
+    
+    int fgLW_x = 50;
+    int fgLW_y = 60;
+    int fgLW_w = 200;
+    int fgLW_h = 200;
+    
+    int fgHW_x = 70;
+    int fgHW_y = 40;
+    int fgHW_w = 100;
+    int fgHW_h = 100;
+
+    f.setSize(500, 500);
+    bgHW.setBounds(bgHW_x, bgHW_y, bgHW_w, bgHW_h);
+    fgLW.setBounds(fgLW_x, fgLW_y, fgLW_w, fgLW_h);
+    fgHW.setBounds(fgHW_x, fgHW_y, fgHW_w, fgHW_h);
+    f.add(bgHW);
+    bgHW.add(fgLW);
+    fgLW.add(fgHW);
+    f.show();
+    
+    r.waitForIdle();
+    r.delay(300);    
+    Insets i = f.getInsets();
+    
+    // check the two pixels adjacent to each corner of the fgHW
+    Point p = f.getLocationOnScreen();
+    fgHW_x = p.x + i.left + fgHW_x + fgLW_x;
+    fgHW_y = p.y + i.top + fgHW_y + fgLW_y;
+    harness.checkRectangleOuterColors(r, new Rectangle(fgHW_x, fgHW_y, fgHW_w, fgHW_h), bgHW_c, true);
+    
+    // check the fgHW's corner pixels.
+    harness.checkRectangleCornerColors(r, new Rectangle(fgHW_x, fgHW_y, fgHW_w, fgHW_h), 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);
+
+    r.delay(3000);
+  }
+  
+  class testPanel extends Panel
+  {
+    Color c;
+
+    public testPanel(Color c)
+    {
+      super(null);
+      this.c = c;
+    }
+
+    public void paint(Graphics g)
+    {
+      Rectangle bounds = new Rectangle(0,
+                                       0,
+                                       this.getSize().width,
+                                       this.getSize().height);
+      g.setColor(c);
+      g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
+    }
+  }
+  
+  class testContainer extends Container
+  {
+
+    public testContainer()
+    {
+      super();
+    }
+
+    public void paint(Graphics g)
+    {
+      Rectangle bounds = new Rectangle(0,
+                                       0,
+                                       this.getSize().width,
+                                       this.getSize().height);
+      g.setColor(Color.red);
+      g.drawRect(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1);
+      g.setColor(Color.blue);
+      g.fillRect(bounds.x + 1, bounds.y + 1, bounds.width - 2, bounds.height - 2);
+    }
+  }
+}
Index: gnu/testlet/java/awt/Frame/size1.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/awt/Frame/size1.java,v
retrieving revision 1.1
diff -u -r1.1 size1.java
--- gnu/testlet/java/awt/Frame/size1.java	21 Feb 2005 06:58:49 -0000	1.1
+++ gnu/testlet/java/awt/Frame/size1.java	21 Feb 2006 23:48:02 -0000
@@ -25,7 +25,6 @@
 import gnu.testlet.Testlet;
 
 import java.awt.*;
-import java.awt.event.*;
 
 /**
  * Check that a frame's size is set correctly when it is initially
@@ -58,18 +57,6 @@
     }
   }
 
-  public void checkColor (TestHarness harness, Color c, boolean match)
-  {
-    if (match)
-      harness.check (c.getRed () == nonWMColor.getRed ()
-		     && c.getGreen () == nonWMColor.getGreen ()
-		     && c.getBlue () == nonWMColor.getBlue ());
-    else
-      harness.check (!(c.getRed () == nonWMColor.getRed ()
-		       && c.getGreen () == nonWMColor.getGreen ()
-		       && c.getBlue () == nonWMColor.getBlue ()));
-  }
-
   public void test (TestHarness harness)
   {
     Robot r = harness.createRobot ();
@@ -99,61 +86,14 @@
     r.waitForIdle ();
     r.delay (100);
 
+    Rectangle bounds = fg.getBounds();
+    
     // check the two pixels adjacent to each corner of the foreground
     // frame.
-
-    // top-left-left
-    c = r.getPixelColor (fg_x - 1, fg_y);
-    checkColor (harness, c, true);
-
-    // top-left-top
-    c = r.getPixelColor (fg_x, fg_y - 1);
-    checkColor (harness, c, true);
-
-    // top-right-right
-    c = r.getPixelColor ((fg_x + fg_width - 1) + 1, fg_y);
-    checkColor (harness, c, true);
-
-    // top-right-top
-    c = r.getPixelColor ((fg_x + fg_width - 1), fg_y - 1);
-    checkColor (harness, c, true);
-
-    // bottom-left-left
-    c = r.getPixelColor (fg_x - 1, (fg_y + fg_height - 1));
-    checkColor (harness, c, true);
-
-    // bottom-left-bottom
-    c = r.getPixelColor (fg_x, (fg_y + fg_height - 1) + 1);
-    checkColor (harness, c, true);
-
-    // bottom-right-right
-    c = r.getPixelColor ((fg_x + fg_width - 1) + 1,
-			 (fg_y + fg_height - 1));
-    checkColor (harness, c, true);
-
-    // bottom-right-bottom
-    c = r.getPixelColor ((fg_x + fg_width - 1),
-			 (fg_y + fg_height - 1) + 1);
-    checkColor (harness, c, true);
-
+    harness.checkRectangleOuterColors(r, bounds, nonWMColor, true);
+    
     // check the frame's corner pixels.
-
-    // top-left
-    c = r.getPixelColor (fg_x, fg_y);
-    checkColor (harness, c, false);
-
-    // top-right
-    c = r.getPixelColor (fg_x + fg_width - 1, fg_y);
-    checkColor (harness, c, false);
-
-    // bottom-left
-    c = r.getPixelColor (fg_x, fg_y + fg_height - 1);
-    checkColor (harness, c, false);
-
-    // bottom-right
-    c = r.getPixelColor (fg_x + fg_width -1,
-			 fg_y + fg_height - 1);
-    checkColor (harness, c, false);
+    harness.checkRectangleCornerColors(r, bounds, nonWMColor, false);
 
     r.delay (3000);
   }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]