Clover coverage report - clover
Coverage timestamp: Sat Oct 8 2005 22:54:17 EDT
file stats: LOC: 255   Methods: 24
NCLOC: 151   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Bugs.java 0% 34% 75% 39.6%
coverage coverage
 1   
 /*
 2   
  * Copyright 2004 Timothy Wall
 3   
  *
 4   
  */
 5   
 package abbot.util;
 6   
 
 7   
 import java.awt.Window;
 8   
 import java.awt.event.InputEvent;
 9   
 import java.awt.event.MouseAdapter;
 10   
 import java.awt.event.MouseEvent;
 11   
 import java.util.ArrayList;
 12   
 
 13   
 import abbot.Log;
 14   
 import abbot.Platform;
 15   
 import abbot.i18n.Strings;
 16   
 import abbot.tester.Robot;
 17   
 
 18   
 /**
 19   
  Provides extant bug characterization of the current platform.  For any bug
 20   
  encountered, there should be a static method indicating whether the bug is
 21   
  expected on the current platform, for example
 22   
  {@link #showAWTPopupMenuBlocks()}.
 23   
  See the source for <code>
 24   
  <a href=../../../../test/abbot/util/BugsTest.java>BugsTest</a></code> for the
 25   
  test implementations. 
 26   
  @author twall
 27   
 */
 28   
 public class Bugs {
 29   
     private static java.util.ArrayList bugList = null;
 30   
     private static boolean gotBug1Event = false;
 31   
 
 32  0
     private Bugs() { }
 33   
 
 34   
     /** Returns whether AWT menus have enable/disable problems. */
 35  10
     public static boolean hasMenuDisableBug() {
 36  10
         return Platform.isOSX()
 37   
             && Platform.JAVA_VERSION >= Platform.JAVA_1_4
 38   
             && Platform.JAVA_VERSION < 0x1424; // when it got fixed
 39   
     }
 40   
 
 41   
     /** Returns whether KEY_TYPED events are sent to AWT listeners. */
 42  14119
     public static boolean hasInputMethodInsteadOfKeyTyped() {
 43  14119
         return Platform.isOSX()
 44   
             && Platform.JAVA_VERSION >= Platform.JAVA_1_4
 45   
             && Platform.JAVA_VERSION < 0x1424; // when it got fixed
 46   
     }
 47   
 
 48   
     /** Returns whether windows send mouse motion events to AWT listeners. */
 49  97
     public static boolean hasMissingWindowMouseMotion() {
 50  97
         return Platform.isOSX()
 51   
             && Platform.JAVA_VERSION >= Platform.JAVA_1_4
 52   
             && Platform.JAVA_VERSION <= 0x1425; // most recent tested
 53   
     }
 54   
 
 55   
     /** Returns whether mouse buttons 2/3 are swapped when using Robot. */
 56  1
     public static boolean hasRobotButtonsSwapped() {
 57  1
         return Platform.isOSX()
 58   
             && Platform.JAVA_VERSION >= Platform.JAVA_1_4
 59   
             && Platform.JAVA_VERSION <= 0x1425; // most recent tested
 60   
     }
 61   
 
 62   
     /** Do we get multiple clicks even when the individual clicks are on
 63   
      * different frames?
 64   
      */
 65   
     // Will we get incorrectly get multiple clicks on rapid robot clicks?
 66   
     // frame1->click,frame2->click 
 67   
     // frame1->click,frame1->hide/show,frame1->click
 68  489
     public static boolean hasMultiClickFrameBug() {
 69   
         // w32 (1.3.02) will count it even if it was on a different component!
 70   
         // w32 (1.3.1_06) same
 71   
         // w32 (1.4.1_02) same (sporadic)
 72   
         // OSX (1.3.x, 1.4.1) has the same problem
 73   
         // Haven't seen it on linux
 74  489
         return Platform.isWindows() || Platform.isOSX()
 75   
             || Platform.JAVA_VERSION < Platform.JAVA_1_3;
 76   
     }
 77   
 
 78   
     /** Returns whether there may be some scenarios in which the robot does
 79   
         not function properly.
 80   
     */
 81  96
     public static boolean needsRobotVerification() {
 82  96
         return Platform.isWindows() || Platform.isOSX();
 83   
     }
 84   
 
 85   
     /** Prior to 1.4.1, hierarchy events are only sent if listeners are added
 86   
         to a given component.
 87   
      */
 88  0
     public static boolean hasHierarchyEventGenerationBug() {
 89  0
         return Platform.JAVA_VERSION < Platform.JAVA_1_4;
 90   
     }
 91   
 
 92   
     /** OSX prior to 1.4 has really crappy key input handling. */
 93  861
     public static boolean hasKeyStrokeGenerationBug() {
 94  861
         return Platform.isOSX()
 95   
             && Platform.JAVA_VERSION < Platform.JAVA_1_4;
 96   
     }
 97   
 
 98   
     /** Returnes whether there a longer delay required between robot
 99   
         generation and event queue posting for key events. */
 100  755
     public static boolean hasKeyInputDelay() {
 101  755
         return Platform.isOSX()
 102   
             && Platform.JAVA_VERSION >= Platform.JAVA_1_4
 103   
             && Platform.JAVA_VERSION <= 0x1425;
 104   
     }
 105   
 
 106   
     /** Some OSX releases wouldn't restore an iconified Frame. */
 107  4
     public static boolean hasFrameDeiconifyBug() {
 108  4
         return Platform.isOSX()
 109   
             && Platform.JAVA_VERSION > 0x1310
 110   
             && Platform.JAVA_VERSION < 0x1424;
 111   
     }
 112   
 
 113   
     /** OS X (as of 1.3.1, v10.1.5), will sometimes send a click to the wrong
 114   
         component after a mouse move.  This continues to be an issue in 1.4.1
 115   
         <p>
 116   
         Linux x86 (1.3.1) has a similar problem, although it manifests it at
 117   
         different times (need a bug test case for this one).
 118   
         <p>
 119   
         Solaris and HPUX probably share code with the linux VM implementation,
 120   
         so the bug there is probably identical.
 121   
         <p>
 122   
     */
 123   
     // FIXME add tests to determine presence of bug.
 124  723
     public static boolean hasRobotMotionBug() {
 125  723
         return Platform.isOSX()
 126   
             || (!Platform.isWindows()
 127   
                 && Platform.JAVA_VERSION < Platform.JAVA_1_4)
 128   
             || Boolean.getBoolean("abbot.robot.need_jitter");
 129   
     }
 130   
 
 131   
     /** Choice popup activates on mouse press, but locks up when the Robot
 132   
      * attempts to post a mouse release.
 133   
      */
 134  1
     public static boolean hasChoiceLockupBug() {
 135  1
         return Platform.isOSX()
 136   
             && Platform.JAVA_VERSION < Platform.JAVA_1_4;
 137   
     }
 138   
 
 139   
     /** Robot.keyPress(KeyEvent.VK_ESCAPE doesn't work. */
 140  0
     public static boolean hasEscapeGenerationBug() {
 141  0
     return Platform.isOSX()
 142   
         && Platform.JAVA_VERSION < Platform.JAVA_1_4;
 143   
     }
 144   
 
 145   
     /** Returns whether the Java event queue is suspended while an AWT popup
 146   
         is showing. */
 147  663
     public static boolean showAWTPopupMenuBlocks() {
 148  663
         return Platform.isWindows()
 149   
             && Platform.JAVA_VERSION <= Platform.JAVA_1_5;
 150   
     }
 151   
 
 152   
     /** Locking key state is reported incorrectly. */
 153  1
     public static boolean reportsIncorrectLockingKeyState() {
 154  1
         return Platform.isLinux()
 155   
             && Platform.JAVA_VERSION <= 0x1424;
 156   
     }
 157   
 
 158   
     /** Whether drag/drop requires native events. */
 159   
     // TODO: needs a test
 160  41
     public static boolean dragDropRequiresNativeEvents() {
 161  41
         return Platform.JAVA_VERSION <= 0x1425;
 162   
     }
 163   
 
 164   
     /** Returns whether a {@link java.awt.FileDialog} requires an explicit
 165   
         dismiss (ok/cancel).  Ordinarily {@link Window#dispose()} will work.
 166   
     */
 167  2
     public static boolean fileDialogRequiresDismiss() {
 168  2
         return Platform.isOSX() && Platform.JAVA_VERSION <= 0x1425
 169   
             || (Platform.isWindows()
 170   
                 && Platform.JAVA_VERSION <= Platform.JAVA_1_5);
 171   
     }
 172   
 
 173   
     /** Returns whether a {@link java.awt.FileDialog} misreports its screen
 174   
         location.
 175   
     */ 
 176  1
     public static boolean fileDialogMisreportsBounds() {
 177  1
         return (Platform.isOSX() && Platform.JAVA_VERSION <= 0x1425)
 178   
             || (Platform.isWindows()
 179   
                 && Platform.JAVA_VERSION <= Platform.JAVA_1_5);
 180   
     }
 181   
 
 182  7
     public static boolean fileDialogRequiresVisibleFrame() {
 183   
         // Subsequent FileDialogs don't show up if the frame isn't visible,
 184   
         // and a previous non-visible frame was disposed.
 185  7
         return Platform.isWindows() && Platform.JAVA_VERSION <= 0x1421;
 186   
     }
 187   
 
 188  8
     public static boolean hasTextComponentSelectionDelay() {
 189   
         // TODO: write a test for this one
 190   
         // Select TextComponent text, wait for idle, selection end not updated
 191  8
         return (Platform.isLinux() || Platform.isWindows())
 192   
             && Platform.JAVA_VERSION <= 0x1424;
 193   
     }
 194   
 
 195   
     /** Check for certain robot-related bugs that will affect Abbot
 196   
      * operation.  Returns a String for each bug detected on the current
 197   
      * system. 
 198   
      */ 
 199  0
     public static String[] bugCheck(final Window window) {
 200  0
         if (bugList == null) {
 201  0
             bugList = new java.util.ArrayList();
 202  0
             final int x = window.getWidth() / 2;
 203  0
             final int y = window.getHeight() / 2;
 204  0
             if (Platform.isWindows() && !Platform.isWindowsXP()
 205   
                 && Platform.JAVA_VERSION < Platform.JAVA_1_4) {
 206  0
                 Log.debug("Checking for w32 bugs");
 207  0
                 final int mask = InputEvent.BUTTON2_MASK;
 208  0
                 MouseAdapter ma = new MouseAdapter() {
 209  0
                     public void mouseClicked(MouseEvent e) {
 210  0
                         gotBug1Event = true;
 211   
                         // w32 acceleration settings bug
 212  0
                         if (e.getX() != x || e.getY() != y) {
 213  0
                             bugList.add(Strings.get("Bug1"));
 214   
                         }
 215   
                         // w32 mouse button mapping bug
 216  0
                         if ((e.getModifiers() & mask) != mask) {
 217  0
                             bugList.add(Strings.get("Bug2"));
 218   
                         }
 219   
                     }
 220   
                 };
 221  0
                 window.addMouseListener(ma);
 222  0
                 Robot robot = new Robot();
 223  0
                 robot.click(window, x, y, mask);
 224  0
                 robot.waitForIdle();
 225  0
                 window.toFront();
 226   
                 // Bogus acceleration may mean the event goes entirely
 227   
                 // elsewhere 
 228  0
                 if (!gotBug1Event) {
 229  0
                     bugList.add(0, Strings.get("Bug1"));
 230   
                 }
 231  0
                 window.removeMouseListener(ma);
 232   
             }
 233  0
             else if (Platform.isOSX() 
 234   
                 && Platform.JAVA_VERSION < 0x1430) {
 235  0
                 Log.debug("Checking for OSX bugs");
 236  0
                 final int mask = InputEvent.BUTTON2_MASK;
 237  0
                 MouseAdapter ma = new MouseAdapter() {
 238  0
                     public void mouseClicked(MouseEvent e) {
 239  0
                         if ((e.getModifiers() & mask) != mask) {
 240  0
                             bugList.add(Strings.get("robot.bug3"));
 241   
                         }
 242   
                     }
 243   
                 };
 244  0
                 window.addMouseListener(ma);
 245  0
                 Robot robot = new Robot();
 246  0
                 robot.click(window, x, y, mask);
 247  0
                 robot.waitForIdle();
 248  0
                 window.removeMouseListener(ma);
 249   
             }
 250   
         }
 251  0
         return (String[])bugList.toArray(new String[bugList.size()]);
 252   
     }
 253   
     
 254   
 }
 255