--- old/java/awt/event/MouseEvent/ClickDuringKeypress/ClickDuringKeypress.java 2014-12-02 15:06:16.000000000 +0300 +++ /dev/null 2014-11-28 15:59:11.188941000 +0300 @@ -1,165 +0,0 @@ -/* - @test 1.2 98/08/05 - @bug 4515763 - @summary Tests that clicking mouse and pressing keys generates correct amount of click-counts - @author andrei.dmitriev: area=awt.mouse - @run main ClickDuringKeypress -*/ - -// Note there is no @ in front of test above. This is so that the -// harness will not mistake this file as a test file. It should -// only see the html file as a test file. (the harness runs all -// valid test files, so it would run this test twice if this file -// were valid as well as the html file.) -// Also, note the area= after Your Name in the author tag. Here, you -// should put which functional area the test falls in. See the -// AWT-core home page -> test areas and/or -> AWT team for a list of -// areas. -// Note also the 'ClickDuringKeypress.html' in the run tag. This should -// be changed to the name of the test. - - -/** - * ClickDuringKeypress.java - * - * summary: - */ - -import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; -import sun.awt.SunToolkit; - -//Automated tests should run as applet tests if possible because they -// get their environments cleaned up, including AWT threads, any -// test created threads, and any system resources used by the test -// such as file descriptors. (This is normally not a problem as -// main tests usually run in a separate VM, however on some platforms -// such as the Mac, separate VMs are not possible and non-applet -// tests will cause problems). Also, you don't have to worry about -// synchronisation stuff in Applet tests they way you do in main -// tests... - - -public class ClickDuringKeypress implements MouseListener - { - //Declare things used in the test, like buttons and labels here - final static int CLICKCOUNT = 10; - final static int DOUBLE_CLICK_AUTO_DELAY = 10; - volatile int lastClickCount = 0; - volatile boolean clicked = false; - volatile boolean ready = false; - - Frame frame; - Robot robot; - - public void init() - { - //Create instructions for the user here, as well as set up - // the environment -- set the layout manager, add buttons, - // etc. - - frame = new Frame("ClickDuringKeypress"); - frame.addMouseListener(this); - frame.addWindowListener(new WindowAdapter() { - public void windowActivated(WindowEvent e) { - synchronized(ClickDuringKeypress.this) { - ready = true; - ClickDuringKeypress.this.notifyAll(); - } - } - }); - frame.setBounds(0, 0, 400, 400); - - start(); - - }//End init() - - public void start () - { - try { - robot = new Robot(); - } catch (AWTException e) { - System.out.println("Could not create Robot."); - throw new RuntimeException("Couldn't create Robot. Test fails"); - } - - robot.mouseMove(200, 200); - frame.show(); - - synchronized(this) { - try { - if (!ready) { - wait(10000); - } - } catch (InterruptedException ex) { - } - if (!ready) { - System.out.println("Not Activated. Test fails"); - throw new RuntimeException("Not Activated. Test fails"); - } - } - - doTest(); - - //What would normally go into main() will probably go here. - //Use System.out.println for diagnostic messages that you want - //to read after the test is done. - //Use Sysout.println for messages you want the tester to read. - - }// start() - - // Mouse should be over the Frame by this point - private void doTest() { - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); - robot.setAutoDelay(2000); - robot.keyPress(KeyEvent.VK_B); - robot.mousePress(InputEvent.BUTTON1_MASK); - robot.delay(10); - robot.mouseRelease(InputEvent.BUTTON1_MASK); - // Should trigger mouseClicked - robot.keyRelease(KeyEvent.VK_B); - robot.delay(1000); - - robot.setAutoDelay(DOUBLE_CLICK_AUTO_DELAY); - for (int i = 0; i < CLICKCOUNT / 2; i++) { - robot.mousePress(InputEvent.BUTTON1_MASK); - robot.delay(10); - robot.mouseRelease(InputEvent.BUTTON1_MASK); - robot.keyPress(KeyEvent.VK_B); - robot.delay(10); - robot.keyRelease(KeyEvent.VK_B); - robot.mousePress(InputEvent.BUTTON1_MASK); - robot.delay(10); - robot.mouseRelease(InputEvent.BUTTON1_MASK); - } - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); - // check results - robot.delay(200); - if (!clicked) { - System.out.println("No MOUSE_CLICKED events received. Test fails."); - throw new RuntimeException("No MOUSE_CLICKED events received. Test fails."); - } - if (lastClickCount != CLICKCOUNT) { - System.out.println("Actual click count: " + lastClickCount + " does not match expected click count: " + CLICKCOUNT + ". Test fails"); - throw new RuntimeException("Actual click count: " + lastClickCount + " does not match expected click count: " + CLICKCOUNT + ". Test fails"); - - } - // else test passes. - } - - public void mouseEntered(MouseEvent e) {} - public void mouseExited(MouseEvent e) {} - public void mousePressed(MouseEvent e) {} - public void mouseReleased(MouseEvent e) {} - public void mouseClicked(MouseEvent e) { - System.out.println(e.toString()); - clicked = true; - lastClickCount = e.getClickCount(); - } - - public static void main(String[] args) { - new ClickDuringKeypress().init(); - } - - }// class ClickDuringKeypress