javauis/eswt_qt/eswtuitestutils/javasrc/com/nokia/mj/impl/uitestutils/UITestUtils.java
changeset 35 85266cc22c7f
equal deleted inserted replaced
26:dc7c549001d5 35:85266cc22c7f
       
     1 // UITestUtils.java // // //
       
     2 
       
     3 package com.nokia.mj.impl.uitestutils;
       
     4 
       
     5 import java.lang.String;
       
     6 import org.eclipse.swt.internal.qt.OS;
       
     7 
       
     8 public class UITestUtils {
       
     9 
       
    10     private static final int RES_CHANGE_DEFAULT_DELAY = 5000;
       
    11 
       
    12     public UITestUtils() {
       
    13         // Always disable screensaver when running tests.
       
    14         S60Utils.S60DisableScreensaver(); 	
       
    15     }
       
    16 
       
    17     /** Init test and s. shot directory, make sure you use slashes to start and
       
    18     end it dir name */
       
    19     public void startTest(String screenShotDir) {
       
    20     }
       
    21 
       
    22     /** Ends the test, prints a summary, etc */
       
    23     public void endTest(boolean passed, String msg) {
       
    24     }
       
    25 
       
    26     /** Log a message */
       
    27     public void log(String msg) {
       
    28     }
       
    29 
       
    30     /** Logs one of the two messages and either PASSED or FAILED according to
       
    31     value of    passed parameter */
       
    32     public void log(boolean passed, String msgPassed, String msgFailed) {
       
    33     }
       
    34 
       
    35     /** Sends a key event to the midlet using the specified key and scan code */
       
    36     public void triggerKeyPressEvent(Key key) {
       
    37         int keycode = key.scanCode;
       
    38         int modifiers = key.modifiers;
       
    39         if(S60Utils.S60SendKeyToFocusWindow(keycode, modifiers, S60Utils.PRESS) != 0)
       
    40             throw new RuntimeException("Emulating key press failed");
       
    41         if(S60Utils.S60SendKeyToFocusWindow(keycode, modifiers, S60Utils.RELEASE) != 0)
       
    42             throw new RuntimeException("Emulating key release failed");
       
    43     }
       
    44 
       
    45     /** Sends a key down event to the application using the specified key */
       
    46     public void triggerKeyDownEvent(Key key) {
       
    47         int keycode = key.scanCode;
       
    48         int modifiers = key.modifiers;
       
    49         if(S60Utils.S60SendKeyToFocusWindow(keycode, modifiers, S60Utils.PRESS) != 0)
       
    50             throw new RuntimeException("Emulating key press failed");
       
    51     }
       
    52 
       
    53     /** Sends a key up event to the application using the specified key */
       
    54     public void triggerKeyUpEvent(Key key) {
       
    55         int keycode = key.scanCode;
       
    56         int modifiers = key.modifiers;
       
    57         if(S60Utils.S60SendKeyToFocusWindow(keycode, modifiers, S60Utils.RELEASE) != 0)
       
    58             throw new RuntimeException("Emulating key release failed");
       
    59     }
       
    60 
       
    61 
       
    62     /** Triggers key repeat events using the specified key and scan code.
       
    63         Calling this method will trigger the following events to Canvas/CustomItem:
       
    64             1. keyPressed event
       
    65             2. keyRepeated events, the number of events is indicated by count parameter
       
    66             3. keyReleased events
       
    67 
       
    68         NOTE 1: This method returns right after triggering the keyPressed event. There should be enough delay
       
    69         after calling this so that all repeat events can be handled before the test result is checked.
       
    70         The delay before triggering first repeat event is 0.6 seconds and between sequential repeat
       
    71         events 0.2 seconds.
       
    72 
       
    73         NOTE 2: For triggering media key repeat events triggerMediaKeyRepeatEvents()
       
    74         must be used.
       
    75     */
       
    76     public int triggerKeyRepeatEvents(Key key, int count) {
       
    77         return 0;
       
    78     }
       
    79 
       
    80     /** This method must be used when triggering repeat events for media keys.
       
    81         pressedTimeInMillis defines how long a key is kept pressed down.
       
    82 
       
    83         NOTE 1: This method returns right after triggering the keyDown event. There should be enough delay
       
    84          (> pressedTimeInMillis) after calling this so that all repeat events and key up can be handled before
       
    85          the test result is checked.
       
    86     */
       
    87     public int triggerMediaKeyRepeatEvents(Key key, int pressedTimeInMillis) {
       
    88         return 0;
       
    89     }
       
    90 
       
    91     /** Sends pointer down event to the midlet */
       
    92     public void triggerPointerDownEvent(int x, int y) {
       
    93         // Setting double click interval to 0 disables double clicks, making it possible
       
    94         // to click around in the test cases quickly without causing unwanted double click
       
    95         // events 
       
    96         OS.QApplication_setDoubleClickInterval(0); 	
       
    97         if(S60Utils.S60SendPointerEvent(x, y, S60Utils.BUTTON1, S60Utils.PRESS) != 0)
       
    98             throw new RuntimeException("Emulating pointer down failed");
       
    99     }
       
   100 
       
   101     /** Sends pointer up event to the midlet */
       
   102     public void triggerPointerUpEvent(int x, int y) {
       
   103         if(S60Utils.S60SendPointerEvent(x, y, S60Utils.BUTTON1, S60Utils.RELEASE) != 0)
       
   104             throw new RuntimeException("Emulating pointer up failed");
       
   105     }
       
   106 
       
   107     /** Sends pointer drag event to the midlet */
       
   108     public void triggerPointerDragEvent(int x, int y) {
       
   109         if(S60Utils.S60SendPointerMoveEvent(x, y, S60Utils.BUTTON1) != 0 ) {
       
   110             throw new RuntimeException("Emulating pointer move failed");
       
   111         }
       
   112     }
       
   113 
       
   114     /**
       
   115      * Sends a pointer event to open up a context menu. E.g. long-press, right-click
       
   116      * or such depending on the platform.
       
   117      */
       
   118     public void triggerContextPointerEvent(int x, int y) {
       
   119         if(S60Utils.S60SendPointerEvent(x, y, S60Utils.BUTTON3, S60Utils.PRESS) != 0)
       
   120             throw new RuntimeException("Emulating pointer down failed");
       
   121         if(S60Utils.S60SendPointerEvent(x, y, S60Utils.BUTTON3, S60Utils.RELEASE) != 0)
       
   122             throw new RuntimeException("Emulating pointer up failed");
       
   123     }
       
   124 
       
   125     /** Takes a screen shot and saves it into a .png file. Returns true if
       
   126     reference screen shot exists and is identical to the new screen shot*/
       
   127     public boolean getScreenShot(String screenShotName) {
       
   128         return true;
       
   129     }
       
   130 
       
   131     /** Takes a screen shot and saves it into a .png file. Returns true if
       
   132     reference screen shot exists and compared area is identical in the reference and new screen shot.
       
   133     areaToCompare and displayableType define the area that is compared. See also SpedeRunner.java.*/
       
   134     public boolean getScreenShot(String screenShotName, int areaToCompare, int displayableType) {
       
   135         return true;
       
   136     }
       
   137 
       
   138     /** Takes a screen shot and saves it into a .png file. Returns true if
       
   139     reference screen shot exists and compared area is identical in the reference and new screen shot.
       
   140     Four integer parameters define the rectangle area for screen shot comparison. */
       
   141     public boolean getScreenShot(String screenShotName, int topLeftX, int topLeftY,
       
   142                                                         int bottomRightX, int bottomRightY) {
       
   143         return true;
       
   144     }
       
   145 
       
   146     public void dispose() {
       
   147     }
       
   148 
       
   149     /** Enable or disable QWERTY input */
       
   150     public void changeQwertyInput(boolean aOn) {
       
   151     }
       
   152 
       
   153     public int switchResolution() {
       
   154         return switchResolution(1);
       
   155     }
       
   156 
       
   157     /** Change the screen resolution - works only on the emulator */
       
   158     public int switchResolution(int numTimes) {
       
   159         return 0;
       
   160     }
       
   161 
       
   162     /** Change the screen resolution - works only on the emulator */
       
   163     public int switchResolutionWithDelay(int delayMillis) {
       
   164         return 0;
       
   165     }
       
   166 
       
   167     /**
       
   168      * Get the top left and bottom right coordinates of main pane, form rect, etc.
       
   169      *
       
   170      * @param coordinates   The coordinates are returned in this array
       
   171      * @param type          Defines for which area the coordinates are fetched
       
   172      */
       
   173     public void getBoundsOf(int type, int[] coordinates) {
       
   174     }
       
   175 
       
   176     /**
       
   177      * Disable screen saver
       
   178      */
       
   179     public void disableScreenSaver() {
       
   180     }
       
   181 
       
   182     /**
       
   183      * Enable screen saver
       
   184      */
       
   185     public void enableScreenSaver() {
       
   186     }
       
   187 }