java/awt/event/MouseEvent/ClickDuringKeypress/ClickDuringKeypress.java

Print this page


   1 /*























   2   @test 1.2 98/08/05
   3   @bug 4515763
   4   @summary Tests that clicking mouse and pressing keys generates correct amount of click-counts
   5   @author andrei.dmitriev: area=awt.mouse
   6   @run main ClickDuringKeypress
   7 */
   8 
   9 // Note there is no @ in front of test above.  This is so that the
  10 //  harness will not mistake this file as a test file.  It should
  11 //  only see the html file as a test file. (the harness runs all
  12 //  valid test files, so it would run this test twice if this file
  13 //  were valid as well as the html file.)
  14 // Also, note the area= after Your Name in the author tag.  Here, you
  15 //  should put which functional area the test falls in.  See the
  16 //  AWT-core home page -> test areas and/or -> AWT team  for a list of
  17 //  areas.
  18 // Note also the 'ClickDuringKeypress.html' in the run tag.  This should
  19 //  be changed to the name of the test.
  20 
  21 
  22 /**
  23  * ClickDuringKeypress.java
  24  *
  25  * summary:
  26  */
  27 
  28 import java.applet.Applet;
  29 import java.awt.*;
  30 import java.awt.event.*;
  31 import sun.awt.SunToolkit;
  32 
  33 //Automated tests should run as applet tests if possible because they
  34 // get their environments cleaned up, including AWT threads, any
  35 // test created threads, and any system resources used by the test
  36 // such as file descriptors.  (This is normally not a problem as
  37 // main tests usually run in a separate VM, however on some platforms
  38 // such as the Mac, separate VMs are not possible and non-applet
  39 // tests will cause problems).  Also, you don't have to worry about
  40 // synchronisation stuff in Applet tests they way you do in main
  41 // tests...
  42 
  43 
  44 public class ClickDuringKeypress implements MouseListener
  45  {
  46    //Declare things used in the test, like buttons and labels here
  47    final static int CLICKCOUNT = 10;
  48    final static int DOUBLE_CLICK_AUTO_DELAY = 10;
  49    volatile int lastClickCount = 0;
  50    volatile boolean clicked = false;
  51    volatile boolean ready = false;
  52 
  53    Frame frame;
  54    Robot robot;
  55 
  56    public void init()
  57     {
  58       //Create instructions for the user here, as well as set up
  59       // the environment -- set the layout manager, add buttons,
  60       // etc.
  61 
  62       frame = new Frame("ClickDuringKeypress");


  94               }
  95           } catch (InterruptedException ex) {
  96           }
  97           if (!ready) {
  98               System.out.println("Not Activated. Test fails");
  99               throw new RuntimeException("Not Activated. Test fails");
 100           }
 101       }
 102 
 103       doTest();
 104 
 105       //What would normally go into main() will probably go here.
 106       //Use System.out.println for diagnostic messages that you want
 107       //to read after the test is done.
 108       //Use Sysout.println for messages you want the tester to read.
 109 
 110     }// start()
 111 
 112     // Mouse should be over the Frame by this point
 113     private void doTest() {
 114         ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
 115       robot.setAutoDelay(2000);

 116       robot.keyPress(KeyEvent.VK_B);
 117       robot.mousePress(InputEvent.BUTTON1_MASK);
 118       robot.delay(10);
 119       robot.mouseRelease(InputEvent.BUTTON1_MASK);
 120       // Should trigger mouseClicked
 121       robot.keyRelease(KeyEvent.VK_B);
 122       robot.delay(1000);
 123 
 124       robot.setAutoDelay(DOUBLE_CLICK_AUTO_DELAY);
 125       for (int i = 0; i < CLICKCOUNT / 2; i++) {
 126         robot.mousePress(InputEvent.BUTTON1_MASK);
 127         robot.delay(10);
 128         robot.mouseRelease(InputEvent.BUTTON1_MASK);
 129         robot.keyPress(KeyEvent.VK_B);
 130         robot.delay(10);
 131         robot.keyRelease(KeyEvent.VK_B);
 132         robot.mousePress(InputEvent.BUTTON1_MASK);
 133         robot.delay(10);
 134         robot.mouseRelease(InputEvent.BUTTON1_MASK);
 135       }
 136       ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
 137       // check results
 138       robot.delay(200);
 139       if (!clicked) {
 140           System.out.println("No MOUSE_CLICKED events received.  Test fails.");
 141           throw new RuntimeException("No MOUSE_CLICKED events received.  Test fails.");
 142       }
 143       if (lastClickCount != CLICKCOUNT) {
 144           System.out.println("Actual click count: " + lastClickCount + " does not match expected click count: " + CLICKCOUNT + ".  Test fails");
 145           throw new RuntimeException("Actual click count: " + lastClickCount + " does not match expected click count: " + CLICKCOUNT + ".  Test fails");
 146 
 147       }
 148       // else test passes.
 149     }
 150 
 151     public void mouseEntered(MouseEvent e) {}
 152     public void mouseExited(MouseEvent e) {}
 153     public void mousePressed(MouseEvent e) {}
 154     public void mouseReleased(MouseEvent e) {}
 155     public void mouseClicked(MouseEvent e) {
 156         System.out.println(e.toString());
   1 /*
   2  * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25   @test 1.2 98/08/05
  26   @bug 4515763
  27   @summary Tests that clicking mouse and pressing keys generates correct amount of click-counts
  28   @author andrei.dmitriev: area=awt.mouse
  29   @run main ClickDuringKeypress
  30 */
  31 













  32 /**
  33  * ClickDuringKeypress.java
  34  *
  35  * summary:
  36  */
  37 
  38 import java.applet.Applet;
  39 import java.awt.*;
  40 import java.awt.event.*;












  41 
  42 public class ClickDuringKeypress implements MouseListener
  43  {
  44    //Declare things used in the test, like buttons and labels here
  45    final static int CLICKCOUNT = 10;
  46    final static int DOUBLE_CLICK_AUTO_DELAY = 10;
  47    volatile int lastClickCount = 0;
  48    volatile boolean clicked = false;
  49    volatile boolean ready = false;
  50 
  51    Frame frame;
  52    Robot robot;
  53 
  54    public void init()
  55     {
  56       //Create instructions for the user here, as well as set up
  57       // the environment -- set the layout manager, add buttons,
  58       // etc.
  59 
  60       frame = new Frame("ClickDuringKeypress");


  92               }
  93           } catch (InterruptedException ex) {
  94           }
  95           if (!ready) {
  96               System.out.println("Not Activated. Test fails");
  97               throw new RuntimeException("Not Activated. Test fails");
  98           }
  99       }
 100 
 101       doTest();
 102 
 103       //What would normally go into main() will probably go here.
 104       //Use System.out.println for diagnostic messages that you want
 105       //to read after the test is done.
 106       //Use Sysout.println for messages you want the tester to read.
 107 
 108     }// start()
 109 
 110     // Mouse should be over the Frame by this point
 111     private void doTest() {

 112       robot.setAutoDelay(2000);
 113       robot.waitForIdle();
 114       robot.keyPress(KeyEvent.VK_B);
 115       robot.mousePress(InputEvent.BUTTON1_MASK);
 116       robot.delay(10);
 117       robot.mouseRelease(InputEvent.BUTTON1_MASK);
 118       // Should trigger mouseClicked
 119       robot.keyRelease(KeyEvent.VK_B);
 120       robot.delay(1000);
 121 
 122       robot.setAutoDelay(DOUBLE_CLICK_AUTO_DELAY);
 123       for (int i = 0; i < CLICKCOUNT / 2; i++) {
 124         robot.mousePress(InputEvent.BUTTON1_MASK);
 125         robot.delay(10);
 126         robot.mouseRelease(InputEvent.BUTTON1_MASK);
 127         robot.keyPress(KeyEvent.VK_B);
 128         robot.delay(10);
 129         robot.keyRelease(KeyEvent.VK_B);
 130         robot.mousePress(InputEvent.BUTTON1_MASK);
 131         robot.delay(10);
 132         robot.mouseRelease(InputEvent.BUTTON1_MASK);
 133       }
 134       robot.waitForIdle();
 135       // check results
 136       robot.delay(200);
 137       if (!clicked) {
 138           System.out.println("No MOUSE_CLICKED events received.  Test fails.");
 139           throw new RuntimeException("No MOUSE_CLICKED events received.  Test fails.");
 140       }
 141       if (lastClickCount != CLICKCOUNT) {
 142           System.out.println("Actual click count: " + lastClickCount + " does not match expected click count: " + CLICKCOUNT + ".  Test fails");
 143           throw new RuntimeException("Actual click count: " + lastClickCount + " does not match expected click count: " + CLICKCOUNT + ".  Test fails");
 144 
 145       }
 146       // else test passes.
 147     }
 148 
 149     public void mouseEntered(MouseEvent e) {}
 150     public void mouseExited(MouseEvent e) {}
 151     public void mousePressed(MouseEvent e) {}
 152     public void mouseReleased(MouseEvent e) {}
 153     public void mouseClicked(MouseEvent e) {
 154         System.out.println(e.toString());