public inbox for mauve-discuss@sourceware.org
 help / color / mirror / Atom feed
* java.awt.Robot tests -- visual mauve tests revisited
@ 2004-12-30 20:34 Thomas Fitzsimmons
  2004-12-31  8:59 ` Thomas Zander
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Fitzsimmons @ 2004-12-30 20:34 UTC (permalink / raw)
  To: mauve-discuss

[-- Attachment #1: Type: text/plain, Size: 437 bytes --]

Hi,

I've attached a series of tests for java.awt.Robot.  I wrote a Robot
implementation for GNU Classpath, so we can now start adding interactive
GUI tests such as these to Mauve.  I'm wondering how best to do this.
There was a thread about this recently but I don't think we came to a
decision.  I know how I'd like GUI testing to work within libgcj's
dejagnu harness, but I'm not sure how it should work in batch_run.
Thoughts?

Tom


[-- Attachment #2: constructors.java --]
[-- Type: text/x-java, Size: 1492 bytes --]

// Tags: JDK1.3

// Copyright (C) 2004 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.

package gnu.testlet.java.awt.Robot;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.awt.Robot;
import java.awt.AWTException;

/**
 * Checks that constructors in the {@link Robot} class work 
 * correctly.
 */
public class constructors implements Testlet
{

  /**
   * Runs the test using the specified harness.
   * 
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test (TestHarness harness)
  {
    // default constructor
    try
      {
	Robot r = new Robot ();
      }
    catch (AWTException e)
      {
	harness.fail ("caught AWT exception: " + e.getMessage ());
      }

    // the test passed if we got here
    harness.check (true);
  }
}

[-- Attachment #3: createScreenCapture.java --]
[-- Type: text/x-java, Size: 2152 bytes --]

// Tags: JDK1.3

// Copyright (C) 2004 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.

package gnu.testlet.java.awt.Robot;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.AWTException;

/**
 * Checks that createScreenCapture in the {@link Robot} class can
 * produce a screenshot.
 */
public class createScreenCapture implements Testlet
{
  /**
   * Runs the test using the specified harness.
   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test (TestHarness harness)
  {
    Robot r = null;

    // construct robot
    try
      {
	r = new Robot ();
      }
    catch (AWTException e)
      {
	harness.fail ("caught AWT exception: " + e.getMessage ());
      }

    Frame f = new Frame ();
    Panel p = new Panel ();

    p.setBackground (new Color (255, 0, 0));

    f.add (p);

    f.setSize (500, 500);
    f.setLocation (0, 0);
    f.show ();

    r.delay (1000);

    BufferedImage screenshot = r.createScreenCapture (new Rectangle (50, 50, 100, 100));

    // check that captured image is completely red
    boolean passed = true;

    for (int i = 0; i < 100; i++)
      {
	for (int j = 0; j < 100; j++)
	  {
	    Color c = new Color (screenshot.getRGB (i, j));

	    if (c.getRed () != 255 || c.getGreen () != 0 || c.getBlue () != 0)
	      passed = false;
	  }
      }

    harness.check (passed);
  }
}

[-- Attachment #4: getPixelColor.java --]
[-- Type: text/x-java, Size: 1889 bytes --]

// Tags: JDK1.3

// Copyright (C) 2004 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.

package gnu.testlet.java.awt.Robot;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.awt.*;
import java.awt.event.*;
import java.awt.AWTException;

/**
 * Checks that getPixelColor in the {@link Robot} class can read a
 * pixel's color value from the screen.
 */
public class getPixelColor implements Testlet
{
  /**
   * Runs the test using the specified harness.
   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test (TestHarness harness)
  {
    Robot r = null;

    // construct robot
    try
      {
	r = new Robot ();
      }
    catch (AWTException e)
      {
	harness.fail ("caught AWT exception: " + e.getMessage ());
      }

    Frame f = new Frame ();
    Panel p = new Panel ();

    p.setBackground (new Color (255, 0, 0));

    f.add (p);

    f.setSize (100, 100);
    f.setLocation (250, 250);
    f.show ();

    r.delay (100);

    Color c = r.getPixelColor (300, 300);

    r.delay (100);

    // check that pixel is red
    harness.check (c.getRed () == 255
		   && c.getGreen () == 0
		   && c.getBlue () == 0);
  }
}

[-- Attachment #5: keyPress.java --]
[-- Type: text/x-java, Size: 2364 bytes --]

// Tags: JDK1.3

// Copyright (C) 2004 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.

package gnu.testlet.java.awt.Robot;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.awt.*;
import java.awt.event.*;
import java.awt.AWTException;

/**
 * Checks that keyPress in the {@link Robot} class generates a
 * keyPressed event in a {@link TextField}.
 */
public class keyPress implements Testlet 
{
  char pressChar = '\0';
  char releaseChar = '\0';
  int pressCount = 0;
  int releaseCount = 0;

  /**
   * Runs the test using the specified harness.
   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test (TestHarness harness)
  {
    Robot r = null;

    // construct robot
    try
      {
	r = new Robot ();
      }
    catch (AWTException e)
      {
	harness.fail ("caught AWT exception: " + e.getMessage ());
      }

    Frame f = new Frame ();
    TextField tf = new TextField ();

    tf.addKeyListener (new KeyAdapter ()
      {
	public void keyPressed (KeyEvent event)
	{
	  pressChar = event.getKeyChar ();
	  pressCount++;
	}

	public void keyReleased (KeyEvent event)
	{
	  releaseChar = event.getKeyChar ();
	  releaseCount++;
	}
      });

    f.add (tf);

    f.setSize (100, 100);
    f.setLocation (250, 250);
    f.show ();

    r.setAutoDelay (100);

    // give focus to text field
    r.mouseMove (300, 300);
    r.mousePress (InputEvent.BUTTON1_MASK);
    r.mouseRelease (InputEvent.BUTTON1_MASK);

    // type 'a'
    r.keyPress (KeyEvent.VK_A);
    r.keyRelease (KeyEvent.VK_A);

    r.delay (2000);

    harness.check (pressChar == 'a');
    harness.check (pressCount == 1);
  }
}

[-- Attachment #6: keyRelease.java --]
[-- Type: text/x-java, Size: 2224 bytes --]

// Tags: JDK1.3

// Copyright (C) 2004 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.

package gnu.testlet.java.awt.Robot;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.awt.*;
import java.awt.event.*;
import java.awt.AWTException;

/**
 * Checks that keyRelease in the {@link Robot} class generates a
 * keyReleased event in a {@link TextField}.
 */
public class keyRelease implements Testlet 
{
  char releaseChar = '\0';
  int releaseCount = 0;

  /**
   * Runs the test using the specified harness.
   *
   * @param harness the test harness (<code>null</code> not permitted).
   */
  public void test (TestHarness harness)
  {
    Robot r = null;

    // construct robot
    try
      {
	r = new Robot ();
      }
    catch (AWTException e)
      {
	harness.fail ("caught AWT exception: " + e.getMessage ());
      }

    Frame f = new Frame ();
    TextField tf = new TextField ();

    tf.addKeyListener (new KeyAdapter ()
      {
	public void keyReleased (KeyEvent event)
	{
	  releaseChar = event.getKeyChar ();
	  releaseCount++;
	}
      });

    f.add (tf);

    f.setSize (100, 100);
    f.setLocation (250, 250);
    f.show ();

    r.setAutoDelay (100);

    // give focus to text field
    r.mouseMove (300, 300);
    r.mousePress (InputEvent.BUTTON1_MASK);
    r.mouseRelease (InputEvent.BUTTON1_MASK);

    // type 'a'
    r.keyPress (KeyEvent.VK_A);
    r.keyRelease (KeyEvent.VK_A);

    r.delay (2000);

    harness.check (releaseChar == 'a');
    harness.check (releaseCount == 1);
  }
}

[-- Attachment #7: mouseMove.java --]
[-- Type: text/x-java, Size: 2107 bytes --]

// Tags: JDK1.3

// Copyright (C) 2004 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.

package gnu.testlet.java.awt.Robot;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.awt.*;
import java.awt.event.*;
import java.awt.AWTException;

/**
 * Checks that mouseMove in the {@link Robot} class moves the mouse
 * pointer.
 */
public class mouseMove implements Testlet
{
  int mouseX = 0;
  int mouseY = 0;

  /**
   * Runs the test using the specified harness.
   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test (TestHarness harness)
  {
    Robot r = null;

    // construct robot
    try
      {
	r = new Robot ();
      }
    catch (AWTException e)
      {
	harness.fail ("caught AWT exception: " + e.getMessage ());
      }

    Frame f = new Frame ();
    Button b = new Button ("test");

    b.addMouseListener (new MouseAdapter ()
      {
	public void mouseClicked (MouseEvent event)
	{
	  mouseX = event.getX ();
	  mouseY = event.getY ();
	}
      });

    f.add (b);

    f.setSize (100, 100);
    f.setLocation (250, 250);
    f.show ();

    r.setAutoDelay (100);

    // click the button
    r.mouseMove (300, 300);
    r.mousePress (InputEvent.BUTTON1_MASK);
    r.mouseRelease (InputEvent.BUTTON1_MASK);

    r.delay (100);

    Insets i = f.getInsets ();

    harness.check (mouseX + i.left == 50 && mouseY + i.top == 50);
  }
}

[-- Attachment #8: mousePress.java --]
[-- Type: text/x-java, Size: 2038 bytes --]

// Tags: JDK1.3

// Copyright (C) 2004 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.

package gnu.testlet.java.awt.Robot;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.awt.*;
import java.awt.event.*;
import java.awt.AWTException;

/**
 * Checks that mousePress in the {@link Robot} class generates a
 * mousePressed event on a {@link Button}.
 */
public class mousePress implements Testlet
{
  int mousePressCount = 0;

  /**
   * Runs the test using the specified harness.
   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test (TestHarness harness)
  {
    Robot r = null;

    // construct robot
    try
      {
	r = new Robot ();
      }
    catch (AWTException e)
      {
	harness.fail ("caught AWT exception: " + e.getMessage ());
      }

    Frame f = new Frame ();
    Button b = new Button ("test");

    b.addMouseListener (new MouseAdapter ()
      {
	public void mousePressed (MouseEvent event)
	{
	  mousePressCount++;
	}
      });

    f.add (b);

    f.setSize (100, 100);
    f.setLocation (250, 250);
    f.show ();

    r.setAutoDelay (100);

    // click the button
    r.mouseMove (300, 300);
    r.mousePress (InputEvent.BUTTON1_MASK);
    r.mouseRelease (InputEvent.BUTTON1_MASK);

    r.delay (100);

    harness.check (mousePressCount == 1);
  }
}

[-- Attachment #9: mouseRelease.java --]
[-- Type: text/x-java, Size: 2050 bytes --]

// Tags: JDK1.3

// Copyright (C) 2004 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.

package gnu.testlet.java.awt.Robot;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.awt.*;
import java.awt.event.*;
import java.awt.AWTException;

/**
 * Checks that mouseRelease in the {@link Robot} class generates a
 * mouseReleased event on a {@link Button}.
 */
public class mouseRelease implements Testlet
{
  int mouseReleaseCount = 0;

  /**
   * Runs the test using the specified harness.
   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test (TestHarness harness)
  {
    Robot r = null;

    // construct robot
    try
      {
	r = new Robot ();
      }
    catch (AWTException e)
      {
	harness.fail ("caught AWT exception: " + e.getMessage ());
      }

    Frame f = new Frame ();
    Button b = new Button ("test");

    b.addMouseListener (new MouseAdapter ()
      {
	public void mouseReleased (MouseEvent event)
	{
	  mouseReleaseCount++;
	}
      });

    f.add (b);

    f.setSize (100, 100);
    f.setLocation (250, 250);
    f.show ();

    r.setAutoDelay (100);

    // click the button
    r.mouseMove (300, 300);
    r.mousePress (InputEvent.BUTTON1_MASK);
    r.mouseRelease (InputEvent.BUTTON1_MASK);

    r.delay (100);

    harness.check (mouseReleaseCount == 1);
  }
}

[-- Attachment #10: mouseWheel.java --]
[-- Type: text/x-java, Size: 2354 bytes --]

// Tags: JDK1.4

// Copyright (C) 2004 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.

package gnu.testlet.java.awt.Robot;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.awt.*;
import java.awt.event.*;
import java.awt.AWTException;

/**
 * Checks that mouseWheel in the {@link Robot} class generates a
 * {@link MouseWheelEvent} on a {@link Button}.
 */
public class mouseWheel implements Testlet
{
  int mouseWheelUpCount = 0;
  int mouseWheelDownCount = 0;

  /**
   * Runs the test using the specified harness.
   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test (TestHarness harness)
  {
    Robot r = null;

    // construct robot
    try
      {
	r = new Robot ();
      }
    catch (AWTException e)
      {
	harness.fail ("caught AWT exception: " + e.getMessage ());
      }

    Frame f = new Frame ();
    Button b = new Button ("test");

    b.addMouseWheelListener (new MouseWheelListener ()
      {
	public void mouseWheelMoved (MouseWheelEvent event)
	{
	  int wheelRotation = event.getWheelRotation ();
	  if (wheelRotation < 0)
	    mouseWheelUpCount += wheelRotation;
	  else
	    mouseWheelDownCount += wheelRotation;
	}
      });

    f.add (b);

    f.setSize (100, 100);
    f.setLocation (250, 250);
    f.show ();

    r.setAutoDelay (100);

    // scroll the mouse wheel up and down
    r.mouseMove (300, 300);
    r.mouseWheel (-4);
    r.mouseWheel (5);
    r.mouseWheel (-1);
    r.mouseWheel (3);
    r.mouseWheel (2);
    r.mouseWheel (-3);

    r.delay (100);

    harness.check (mouseWheelUpCount == -8);
    harness.check (mouseWheelDownCount == 10);
  }
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: java.awt.Robot tests -- visual mauve tests revisited
  2004-12-30 20:34 java.awt.Robot tests -- visual mauve tests revisited Thomas Fitzsimmons
@ 2004-12-31  8:59 ` Thomas Zander
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Zander @ 2004-12-31  8:59 UTC (permalink / raw)
  To: mauve-discuss

[-- Attachment #1: Type: text/plain, Size: 894 bytes --]

On Thursday 30 December 2004 21:34, Thomas Fitzsimmons wrote:
> There was a thread about this recently but I don't think we came to a
> decision.

The discussion was continued on IRC (#classpath), and here is what I 
remember.
We wanted to add at least 2 features to the mauve test-runner.
a) a keyword for all tests that need a DISPLAY
b) a way to 'redirect' graphics output away from the users screen.  There is 
a standard technology for that, I don't remember its name.  A virtual 
buffer.

With that in place you have to either explicitly enable GUI tests; or they 
would automatically detect and use the virtual framebuffer.

With Robot a screenCapture can be made and then we need a 'simple' framework 
to have various visual check()  methods on Image objects.  Things like 
'exact match' / 'tint match' / 'size match' should prove quite usefull.

-- 
Thomas Zander

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-12-31  8:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-30 20:34 java.awt.Robot tests -- visual mauve tests revisited Thomas Fitzsimmons
2004-12-31  8:59 ` Thomas Zander

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).