870N/A/*
870N/A @test %I% %E%
870N/A @bug 6315717
870N/A @summary verifies that sun.awt.enableExtraMouseButtons is working
870N/A @author Andrei Dmitriev : area=awt.mouse
870N/A @run main/othervm -Dsun.awt.enableExtraMouseButtons=true ToolkitPropertyTest_Enable
870N/A */
870N/A
870N/Aimport java.awt.*;
870N/Aimport java.awt.event.*;
870N/A
870N/A// Testcase 1: set to TRUE (via jtreg option)
870N/A// Testcase 2: set to TRUE and check that extra events are coming
870N/A// check that standard events are coming
870N/A
870N/Apublic class ToolkitPropertyTest_Enable extends Frame {
870N/A static boolean propValue;
870N/A static Robot robot;
870N/A static int [] buttonsPressed;
870N/A static int [] buttonsReleased;
870N/A static int [] buttonsClicked;
870N/A
870N/A public static void main(String []s){
870N/A propValue = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons"));
870N/A buttonsPressed = new int [MouseInfo.getNumberOfButtons()];
870N/A buttonsReleased = new int [MouseInfo.getNumberOfButtons()];
870N/A buttonsClicked = new int [MouseInfo.getNumberOfButtons()];
870N/A
870N/A ToolkitPropertyTest_Enable frame = new ToolkitPropertyTest_Enable();
870N/A frame.setSize(300, 300);
870N/A frame.setVisible(true);
870N/A
870N/A MouseAdapter ma1 = new MouseAdapter() {
870N/A public void mousePressed(MouseEvent e) {
870N/A buttonsPressed[e.getButton() - 1] += 1;
870N/A System.out.println("PRESSED "+e);
870N/A }
870N/A public void mouseReleased(MouseEvent e) {
870N/A buttonsReleased[e.getButton() - 1] += 1;
870N/A System.out.println("RELEASED "+e);
870N/A }
870N/A public void mouseClicked(MouseEvent e) {
870N/A buttonsClicked[e.getButton() - 1] += 1;
870N/A System.out.println("CLICKED "+e);
870N/A }
870N/A };
870N/A // frame.addMouseListener(ma1);
870N/A
870N/A try {
870N/A robot = new Robot();
870N/A robot.delay(1000);
870N/A robot.mouseMove(frame.getLocationOnScreen().x + frame.getWidth()/2, frame.getLocationOnScreen().y + frame.getHeight()/2);
870N/A
870N/A System.out.println("Property = " + propValue);
870N/A testCase0();
870N/A
870N/A testCase1();
870N/A System.out.println("Number Of Buttons = "+ MouseInfo.getNumberOfButtons());
870N/A
870N/A boolean lessThenFourButtons = (MouseInfo.getNumberOfButtons() <= 3);
870N/A if ( !lessThenFourButtons ) {
870N/A frame.addMouseListener(ma1);
870N/A testCase2();
870N/A // testCase3();
870N/A // testCase4();
870N/A frame.removeMouseListener(ma1);
870N/A }
870N/A } catch (Exception e){
870N/A e.printStackTrace();
870N/A throw new RuntimeException(e);
870N/A }
870N/A
870N/A }
870N/A
870N/A public static void testCase0(){
870N/A if (!propValue){
870N/A throw new RuntimeException("TEST FAILED (0) : System property sun.awt.enableExtraMouseButtons = " + propValue);
870N/A }
870N/A }
870N/A
870N/A public static void testCase1(){
870N/A if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled() == false){
870N/A throw new RuntimeException("TEST FAILED (1) : setting to TRUE. enabled = " + Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled());
870N/A }
870N/A }
870N/A
870N/A public static void testCase2(){
870N/A emptyArrays();
870N/A //we can't post a message from an unexistent button
870N/A int [] buttonMasks = new int[MouseInfo.getNumberOfButtons()]; // = InputEvent.getButtonDownMasks();
870N/A for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
870N/A buttonMasks[i] = InputEvent.getMaskForButton(i+1);
2773N/A System.out.println("TEST: buttonMasks["+ i +"] = " + buttonMasks[i]);
870N/A }
870N/A
870N/A for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
870N/A System.out.println("button to press = " +(i+1) + " : value passed to robot = " +buttonMasks[i]);
870N/A robot.mousePress(buttonMasks[i]);
870N/A robot.delay(70);
870N/A robot.mouseRelease(buttonMasks[i]);
870N/A robot.delay(200);
870N/A }
870N/A robot.delay(1000);
870N/A
870N/A for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
870N/A if (buttonsPressed[i] != 1 || buttonsReleased[i] != 1 || buttonsClicked[i] !=1 ) {
870N/A throw new RuntimeException("TESTCASE 2 FAILED : button " + (i+1) + " wasn't single pressed|released|clicked : "+ buttonsPressed[i] +" : "+ buttonsReleased[i] +" : "+ buttonsClicked[i]);
870N/A }
870N/A }
870N/A }
870N/A
870N/A public static void emptyArrays(){
870N/A for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
870N/A buttonsPressed[i] = 0;
870N/A buttonsReleased[i] = 0;
870N/A buttonsClicked[i] = 0;
870N/A }
870N/A }
870N/A
870N/A}