This is the mail archive of the mauve-discuss@sources.redhat.com 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]

java.awt.Robot tests -- visual mauve tests revisited


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

// 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);
  }
}
// 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);
  }
}
// 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);
  }
}
// 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);
  }
}
// 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);
  }
}
// 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);
  }
}
// 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);
  }
}
// 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);
  }
}
// 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);
  }
}

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