7152982: [TEST_BUG][macosx] Extremely unstable mouse modifiers test
authorpchelko
Fri, 29 Nov 2013 11:08:52 +0400
changeset 21932 1588ae1fa2f9
parent 21798 f4ab67a9cd68
child 21933 d314dba9821a
7152982: [TEST_BUG][macosx] Extremely unstable mouse modifiers test Reviewed-by: anthony, serb
jdk/test/java/awt/Mouse/MouseModifiersUnitTest/MouseModifiersUnitTest_Extra.java
--- a/jdk/test/java/awt/Mouse/MouseModifiersUnitTest/MouseModifiersUnitTest_Extra.java	Wed Nov 27 20:45:10 2013 +0400
+++ b/jdk/test/java/awt/Mouse/MouseModifiersUnitTest/MouseModifiersUnitTest_Extra.java	Fri Nov 29 11:08:52 2013 +0400
@@ -29,6 +29,8 @@
   @run main MouseModifiersUnitTest_Extra
  */
 
+import sun.awt.OSInfo;
+
 import java.awt.*;
 import java.awt.event.*;
 import java.util.Arrays;
@@ -61,6 +63,17 @@
     static int [] modifiersExStandardCTRL;
     static int [] modifiersExStandardALT;
 
+    private final static String SHIFT_MODIFIER = OSInfo.getOSType().equals(OSInfo.OSType.MACOSX) ?
+                                                "\u21e7" : "Shift";
+
+    private final static String ALT_MODIFIER = OSInfo.getOSType().equals(OSInfo.OSType.MACOSX) ?
+                                                "\u2325" : "Alt";
+
+
+    private final static String CTRL_MODIFIER = OSInfo.getOSType().equals(OSInfo.OSType.MACOSX) ?
+                                                "\u2303" : "Ctrl";
+
+
     // BUTTON1, 2, 3 press-release.
     final static int  modifiersStandard = 0; //InputEvent.BUTTON_DOWN_MASK;
 
@@ -77,7 +90,8 @@
 
         if (modifiersEx != curStandardExModifiers[index]){
 //            System.out.println(">>>>>>>>>>>>>>> Pressed. modifiersEx "+modifiersEx +" : "+!= curStandardExModifiers");
-            MessageLogger.reportError("Test failed :  Pressed. modifiersEx != curStandardExModifiers. Got: " + modifiersEx + " , Expected: " + curStandardExModifiers[index]);
+            MessageLogger.reportError("Test failed :  Pressed. modifiersEx != curStandardExModifiers. Got: "
+                    + modifiersEx + " , Expected: " + curStandardExModifiers[index]);
         }
 
      //check event.paramString() output
@@ -88,51 +102,54 @@
         checkExtModifiersOnPress(testModifier, paramStringElements, button);
     }
 
-    public static void checkExtModifiersOnReleaseClick(int testModifier, HashMap h, int button){
+    public static void checkExtModifiersOnReleaseClick(int testModifier, HashMap<String, String> h, int button){
         String ethalon = "";
         switch (testModifier){
             case SHIFT:{
-                ethalon = "Shift";
+                ethalon = SHIFT_MODIFIER;
                 break;
             }
             case ALT:{
-                ethalon = "Alt";
+                ethalon = ALT_MODIFIER;
                 break;
             }
             case CTRL:{
-                ethalon = "Ctrl";
+                ethalon = CTRL_MODIFIER;
                 break;
             }
         }
-        //
+
         if (h.get("extModifiers") == null){
             h.put("extModifiers", "");
         }
+
         if (!ethalon.equals(h.get("extModifiers"))) {
-            MessageLogger.reportError("Test failed :  Released/Clicked. extModifiers = " +h.get("extModifiers")+" instead of : "+ethalon);
+            MessageLogger.reportError("Test failed :  Released/Clicked. extModifiers = "
+                    + h.get("extModifiers") + " instead of : " + ethalon);
         }
     }
 
-    public static void checkExtModifiersOnPress(int testModifier, HashMap h, int button){
+    public static void checkExtModifiersOnPress(int testModifier, HashMap<String, String> h, int button){
         String ethalon = "";
         switch (testModifier){
             case SHIFT:{
-                ethalon = "Shift+";
+                ethalon = SHIFT_MODIFIER + "+";
                 break;
             }
             case ALT:{
-                ethalon = "Alt+";
+                ethalon = ALT_MODIFIER + "+";
                 break;
             }
             case CTRL:{
-                ethalon = "Ctrl+";
+                ethalon = CTRL_MODIFIER + "+";
                 break;
             }
         }
         ethalon = ethalon + "Button" +button;
 
         if (!h.get("extModifiers").equals(ethalon)) {
-            MessageLogger.reportError("Test failed :  Pressed. extModifiers = " +h.get("extModifiers")+" instead of : "+ethalon);
+            MessageLogger.reportError("Test failed :  Pressed. extModifiers = " +h.get("extModifiers")+" instead of : "
+                    + ethalon);
         }
     }
 
@@ -152,7 +169,7 @@
         }
     }
     public static HashMap<String, String> tokenizeParamString(String param){
-        HashMap <String, String> params = new HashMap<String, String>();
+        HashMap <String, String> params = new HashMap<>();
         StringTokenizer st = new StringTokenizer(param, ",=");
         while (st.hasMoreTokens()){
             String tmp = st.nextToken();
@@ -167,7 +184,7 @@
     }
 
     public static Vector<String> tokenizeModifiers(String modifierList){
-        Vector<String> modifiers = new Vector<String>();
+        Vector<String> modifiers = new Vector<>();
         StringTokenizer st = new StringTokenizer(modifierList, "+");
         while (st.hasMoreTokens()){
             String tmp = st.nextToken();
@@ -189,7 +206,8 @@
         }
 
         if (modifiersEx != curStandardExModifiers[index]){
-            MessageLogger.reportError("Test failed :  Released. modifiersEx != curStandardExModifiers. Got: " + modifiersEx + " , Expected: " + curStandardExModifiers[index]);
+            MessageLogger.reportError("Test failed :  Released. modifiersEx != curStandardExModifiers. Got: "
+                    + modifiersEx + " , Expected: " + curStandardExModifiers[index]);
         }
 
      //check event.paramString() output
@@ -212,7 +230,8 @@
         }
 
         if (modifiersEx != curStandardExModifiers[index]){
-            MessageLogger.reportError("Test failed :  Clicked. modifiersEx != curStandardExModifiers. Got: " + modifiersEx + " , Expected: " + curStandardExModifiers[index]);
+            MessageLogger.reportError("Test failed :  Clicked. modifiersEx != curStandardExModifiers. Got: "
+                    + modifiersEx + " , Expected: " + curStandardExModifiers[index]);
         }
 
      //check event.paramString() output
@@ -243,22 +262,10 @@
     static Robot robot;
     public void init() {
         this.setLayout(new BorderLayout());
-
-        String[] instructions =
-        {
-            "This test should be used with the mouse having more then three buttons.",
-            "Currently, " + MouseInfo.getNumberOfButtons() +" buttons are available.",
-            "If there are less then three buttons, press PASS.",
-            "1. Press each extra mouse button.",
-            "2. For each mouse event its modifiers and ExModifiers will be printed.",
-            "3. Verify that they are correct.",
-            "4. Press Pass or Fail accordingly."
-        };
-//        Sysout.createDialogWithInstructions( instructions );
-
-//        addMouseListener(adapterTest1);
         try {
             robot  = new Robot();
+            robot.setAutoDelay(100);
+            robot.setAutoWaitForIdle(true);
         } catch (Exception e) {
             MessageLogger.reportError("Test failed. "+e);
         }
@@ -297,9 +304,8 @@
         robot.delay(1000);
         robot.mouseMove(getLocationOnScreen().x + getWidth()/2, getLocationOnScreen().y + getHeight()/2);
         for (int i = 3; i< mouseButtonDownMasks.length; i++){
-            System.out.println("testNONE() => " +mouseButtonDownMasks[i] );
+            System.out.println("testNONE() => " + mouseButtonDownMasks[i]);
             robot.mousePress(mouseButtonDownMasks[i]);
-            robot.delay(100);
             robot.mouseRelease(mouseButtonDownMasks[i]);
         }
         robot.delay(1000);
@@ -312,9 +318,8 @@
         robot.mouseMove(getLocationOnScreen().x + getWidth()/2, getLocationOnScreen().y + getHeight()/2);
         for (int i = 3; i< mouseButtonDownMasks.length; i++){
             robot.keyPress(KeyEvent.VK_SHIFT);
-            System.out.println("testSHIFT() => " +mouseButtonDownMasks[i] );
+            System.out.println("testSHIFT() => " + mouseButtonDownMasks[i]);
             robot.mousePress(mouseButtonDownMasks[i]);
-            robot.delay(100);
             robot.mouseRelease(mouseButtonDownMasks[i]);
             robot.keyRelease(KeyEvent.VK_SHIFT);
         }
@@ -328,9 +333,8 @@
         robot.mouseMove(getLocationOnScreen().x + getWidth()/2, getLocationOnScreen().y + getHeight()/2);
         for (int i = 3; i< mouseButtonDownMasks.length; i++){
             robot.keyPress(KeyEvent.VK_CONTROL);
-            System.out.println("testCTRL() => " +mouseButtonDownMasks[i] );
+            System.out.println("testCTRL() => " + mouseButtonDownMasks[i]);
             robot.mousePress(mouseButtonDownMasks[i]);
-            robot.delay(100);
             robot.mouseRelease(mouseButtonDownMasks[i]);
             robot.keyRelease(KeyEvent.VK_CONTROL);
         }
@@ -344,9 +348,8 @@
         robot.mouseMove(getLocationOnScreen().x + getWidth()/2, getLocationOnScreen().y + getHeight()/2);
         for (int i = 3; i< mouseButtonDownMasks.length; i++){
             robot.keyPress(KeyEvent.VK_ALT);
-            System.out.println("testALT() => " +mouseButtonDownMasks[i] );
+            System.out.println("testALT() => " + mouseButtonDownMasks[i]);
             robot.mousePress(mouseButtonDownMasks[i]);
-            robot.delay(100);
             robot.mouseRelease(mouseButtonDownMasks[i]);
             robot.keyRelease(KeyEvent.VK_ALT);
         }