jdk/test/java/awt/event/MouseEvent/CTORRestrictions/CTORRestrictions_Disable.java
author martin
Wed, 02 Sep 2015 14:11:50 -0700
changeset 32427 c22b7e41adf3
parent 23010 6dadb192ad81
permissions -rw-r--r--
8134984: Text files should end in exactly one newline Summary: automated fixup of newlines at end-of-file via the usual perl one-liner Reviewed-by: chegar, sherman
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21596
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21596
diff changeset
     2
 * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
21596
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
     4
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
     7
 * published by the Free Software Foundation.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
     8
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    13
 * accompanied this code).
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    14
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    18
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    21
 * questions.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    22
 */
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    23
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    24
/*
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    25
  test %I% %E%
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    26
  @bug 6315717
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    27
  @summary verifies that MouseEvent could be constructed correctly for mouse extra buttons in regard to sun.awt.enableExtraMouseButtons property
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    28
  @author Andrei Dmitriev : area=awt.event
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    29
  @run main/othervm -Dsun.awt.enableExtraMouseButtons=false CTORRestrictions_Disable
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    30
 */
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    31
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    32
/*
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    33
 * verify that user can't create the MouseEvent? with button4|5|... when property "sun.awt.enableExtraMouseButtons"=false
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    34
 * verify that user can create the MouseEvent? with button1|2|3 when property "sun.awt.enableExtraMouseButtons"=false
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    35
 */
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    36
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    37
import java.awt.*;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    38
import java.awt.event.*;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    39
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    40
public class CTORRestrictions_Disable {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    41
    static Frame frame = new Frame("MouseEvent Test Frame");
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    42
    static Point mousePosition;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    43
    static Point mousePositionOnScreen;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    44
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    45
    public static void main(String []s){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    46
        Robot robot = null;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    47
        try {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    48
            robot = new Robot();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    49
        } catch (AWTException ex) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    50
            throw new RuntimeException("Test Failed", ex);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    51
        }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    52
        frame.setSize (200,200);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    53
        frame.setLocation (300, 400);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    54
        frame.setVisible(true);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    55
        robot.delay(1000);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    56
        System.out.println(Toolkit.getDefaultToolkit().getDesktopProperty("sun.awt.enableExtraMouseButtons"));
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    57
        mousePosition = new Point(100, 100);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    58
        mousePositionOnScreen = new  Point(frame.getLocationOnScreen().x + mousePosition.x,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    59
                                                 frame.getLocationOnScreen().y + mousePosition.y);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    60
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    61
        System.out.println("Stage 1");
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    62
        for (int buttonId = 1; buttonId <= MouseInfo.getNumberOfButtons(); buttonId++){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    63
           try {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    64
               postMouseEventNewCtor(buttonId);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    65
               if (buttonId > 3) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    66
                   throw new RuntimeException("Stage 1 FAILED: MouseEvent CTOR accepted the extra button " + (buttonId+1) + " instead of throwing an exception.");
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    67
               }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    68
           } catch (IllegalArgumentException e){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    69
                if (buttonId > 3) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    70
                    System.out.println("Passed: an exception caught for extra button.");
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    71
                } else {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    72
                    throw new RuntimeException("Stage 1 FAILED : exception happen on standard button.", e);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    73
                }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    74
            }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    75
        }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    76
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    77
        System.out.println("Stage 2");
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    78
        for (int buttonId = 1; buttonId <= MouseInfo.getNumberOfButtons(); buttonId++){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    79
           try {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    80
               postMouseEventOldCtor(buttonId);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    81
               if (buttonId > 3) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    82
                   throw new RuntimeException("Stage 2 FAILED: MouseEvent CTOR accepted the extra button " + (buttonId+1) + " instead of throwing an exception.");
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    83
               }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    84
           } catch (IllegalArgumentException e){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    85
                if (buttonId > 3) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    86
                    System.out.println("Passed: an exception caught for extra button.");
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    87
                } else {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    88
                    throw new RuntimeException("Stage 2 FAILED : exception happen on standard button.", e);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    89
                }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    90
            }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    91
        }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    92
        System.out.println("Test passed.");
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    93
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    94
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    95
    public static void postMouseEventNewCtor(int buttonId)    {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    96
        MouseEvent me = new MouseEvent(frame,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    97
                                       MouseEvent.MOUSE_PRESSED,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    98
                                       System.currentTimeMillis(),
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    99
                                       MouseEvent.BUTTON1_DOWN_MASK,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   100
                                       mousePosition.x, mousePosition.y,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   101
                                       mousePositionOnScreen.x,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   102
                                       mousePositionOnScreen.y,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   103
                                       1,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   104
                                       false,              //popupTrigger
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   105
                                       buttonId            //button
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   106
                                       );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   107
        frame.dispatchEvent( ( AWTEvent )me );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   108
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   109
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   110
    public static void postMouseEventOldCtor(int buttonId)    {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   111
        MouseEvent meOld = new MouseEvent(frame,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   112
                                          MouseEvent.MOUSE_PRESSED,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   113
                                          System.currentTimeMillis(),
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   114
                                          MouseEvent.BUTTON1_DOWN_MASK,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   115
                                          mousePosition.x, mousePosition.y,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   116
                                          1,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   117
                                          false,              //popupTrigger
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   118
                                          buttonId //button
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   119
                                          );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   120
        frame.dispatchEvent( ( AWTEvent )meOld );
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   121
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   122
}