javauis/lcdui_qt/tsrc/uitestsrc/t_uirobot/alert/AlertUITest.java
changeset 23 98ccebc37403
parent 21 2a9601315dfc
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description: 
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 package t_uirobot.alert;
    17 package t_uirobot.alert;
    18 
    18 
    19 import j2meunit.framework.*;
    19 import j2meunit.framework.*;
    34  * <li> UI-robot based tests to test Alert's functionality. <br>
    34  * <li> UI-robot based tests to test Alert's functionality. <br>
    35  * <br>
    35  * <br>
    36  *
    36  *
    37  * @created  2008-07-01
    37  * @created  2008-07-01
    38  */
    38  */
    39 public class AlertUITest extends UITestBase {
    39 public class AlertUITest extends UITestBase
       
    40 {
    40 
    41 
    41     private static final int SETCURRENT_TIMEOUT = 6000;
    42     private static final int SETCURRENT_TIMEOUT = 6000;
    42     private static final int TEXBOX_LENGTH = 100;
    43     private static final int TEXBOX_LENGTH = 100;
    43 
    44 
    44     private static String shortString = "Lorem ipsum";
    45     private static String shortString = "Lorem ipsum";
    45 
    46 
    46     private static String longString = "Lorem ipsum dolor sit amet, "
    47     private static String longString = "Lorem ipsum dolor sit amet, "
    47         + "consectetuer adipiscing elit. Cras turpis ligula, "
    48                                        + "consectetuer adipiscing elit. Cras turpis ligula, "
    48         + "condimentum nec, rhoncus quis, molestie in, arcu. "
    49                                        + "condimentum nec, rhoncus quis, molestie in, arcu. "
    49         + "Curabitur id lacus. Quisque dictum nulla id odio. "
    50                                        + "Curabitur id lacus. Quisque dictum nulla id odio. "
    50         + "Nullam nec urna. Cras ac lacus nec lacus iaculis aliquet."
    51                                        + "Nullam nec urna. Cras ac lacus nec lacus iaculis aliquet."
    51         + " Integer ut eros. Proin laoreet justo et augue. "
    52                                        + " Integer ut eros. Proin laoreet justo et augue. "
    52         + "Praesent dui. Proin vel leo a eros auctor convallis. "
    53                                        + "Praesent dui. Proin vel leo a eros auctor convallis. "
    53         + "Aenean urna nunc, sagittis vel, pellentesque a, "
    54                                        + "Aenean urna nunc, sagittis vel, pellentesque a, "
    54         + "luctus a, metus. Phasellus posuere lacus nec augue."
    55                                        + "luctus a, metus. Phasellus posuere lacus nec augue."
    55         + "Nullam nec urna. Cras ac lacus nec lacus iaculis aliquet."
    56                                        + "Nullam nec urna. Cras ac lacus nec lacus iaculis aliquet."
    56         + " Integer ut eros. Proin laoreet justo et augue. "
    57                                        + " Integer ut eros. Proin laoreet justo et augue. "
    57         + "Praesent dui. Proin vel leo a eros auctor convallis. "
    58                                        + "Praesent dui. Proin vel leo a eros auctor convallis. "
    58         + "Aenean urna nunc, sagittis vel, pellentesque a, "
    59                                        + "Aenean urna nunc, sagittis vel, pellentesque a, "
    59         + "luctus a, metus. Phasellus posuere lacus nec augue.";
    60                                        + "luctus a, metus. Phasellus posuere lacus nec augue.";
    60 
    61 
    61     private TextBox textBox;
    62     private TextBox textBox;
    62     private Command exitCmd;
    63     private Command exitCmd;
    63 
    64 
    64     /**
    65     /**
    65      * Constructor.
    66      * Constructor.
    66      */
    67      */
    67     public AlertUITest() {
    68     public AlertUITest()
    68     	super();
    69     {
       
    70         super();
    69     }
    71     }
    70 
    72 
    71     /**
    73     /**
    72      * Constructor.
    74      * Constructor.
    73      *
    75      *
    74      * @param sTestName Test name.
    76      * @param sTestName Test name.
    75      * @param rTestMethod Test method.
    77      * @param rTestMethod Test method.
    76      */
    78      */
    77     public AlertUITest(String sTestName, TestMethod rTestMethod) {
    79     public AlertUITest(String sTestName, TestMethod rTestMethod)
       
    80     {
    78         super(sTestName, rTestMethod);
    81         super(sTestName, rTestMethod);
    79     }
    82     }
    80 
    83 
    81     /**
    84     /**
    82      * Any pre-test setup can be done here
    85      * Any pre-test setup can be done here
    83      */
    86      */
    84     protected void setUp() throws Exception {
    87     protected void setUp() throws Exception
    85     	super.setUp();
    88     {
       
    89         super.setUp();
    86         exitCmd = new Command("exit", "exit", Command.EXIT, 0);
    90         exitCmd = new Command("exit", "exit", Command.EXIT, 0);
    87         textBox = new TextBox("textBox", "", TEXBOX_LENGTH, TextField.ANY);
    91         textBox = new TextBox("textBox", "", TEXBOX_LENGTH, TextField.ANY);
    88         textBox.addCommand(exitCmd);
    92         textBox.addCommand(exitCmd);
    89     }
    93     }
    90 
    94 
    92      * Creates the test suite. You need to add a new aSuite.addTest entry for
    96      * Creates the test suite. You need to add a new aSuite.addTest entry for
    93      * any new test methods, otherwise they won't be run.
    97      * any new test methods, otherwise they won't be run.
    94      *
    98      *
    95      * @return New testsuite.
    99      * @return New testsuite.
    96      */
   100      */
    97     public Test suite() {
   101     public Test suite()
       
   102     {
    98         TestSuite aSuite = new TestSuite();
   103         TestSuite aSuite = new TestSuite();
    99 
   104 
   100         aSuite.addTest(new AlertUITest("testShowTimedAlert", new TestMethod() {
   105         aSuite.addTest(new AlertUITest("testShowTimedAlert", new TestMethod()
   101             public void run(TestCase tc) {
   106         {
       
   107             public void run(TestCase tc)
       
   108             {
   102                 ((AlertUITest) tc).testShowTimedAlert();
   109                 ((AlertUITest) tc).testShowTimedAlert();
   103             }
   110             }
   104         }));
   111         }));
   105 
   112 
   106         aSuite.addTest(new AlertUITest("testCustomListener", new TestMethod() {
   113         aSuite.addTest(new AlertUITest("testCustomListener", new TestMethod()
   107             public void run(TestCase tc) {
   114         {
       
   115             public void run(TestCase tc)
       
   116             {
   108                 ((AlertUITest) tc).testCustomListener();
   117                 ((AlertUITest) tc).testCustomListener();
   109             }
   118             }
   110         }));
   119         }));
   111 
   120 
   112         aSuite.addTest(new AlertUITest("testCustomListenerCustomCommand",
   121         aSuite.addTest(new AlertUITest("testCustomListenerCustomCommand",
   113                 new TestMethod() {
   122                                        new TestMethod()
   114                     public void run(TestCase tc) {
   123         {
   115                         ((AlertUITest) tc).testCustomListenerCustomCommand();
   124             public void run(TestCase tc)
   116                     }
   125             {
   117                 }));
   126                 ((AlertUITest) tc).testCustomListenerCustomCommand();
       
   127             }
       
   128         }));
   118 
   129 
   119         aSuite.addTest(new AlertUITest("testKeypressOnCustomCommands",
   130         aSuite.addTest(new AlertUITest("testKeypressOnCustomCommands",
   120                 new TestMethod() {
   131                                        new TestMethod()
   121                     public void run(TestCase tc) {
   132         {
   122                         ((AlertUITest) tc).testKeypressOnCustomCommands();
   133             public void run(TestCase tc)
   123                     }
   134             {
   124                 }));
   135                 ((AlertUITest) tc).testKeypressOnCustomCommands();
       
   136             }
       
   137         }));
   125 
   138 
   126         aSuite.addTest(new AlertUITest("testLongTextScrolling",
   139         aSuite.addTest(new AlertUITest("testLongTextScrolling",
   127                 new TestMethod() {
   140                                        new TestMethod()
   128                     public void run(TestCase tc) {
   141         {
   129                         ((AlertUITest) tc).testLongTextScrolling();
   142             public void run(TestCase tc)
   130                     }
   143             {
   131                 }));
   144                 ((AlertUITest) tc).testLongTextScrolling();
       
   145             }
       
   146         }));
   132 
   147 
   133         aSuite.addTest(new AlertUITest("testImageAndTextCombinations",
   148         aSuite.addTest(new AlertUITest("testImageAndTextCombinations",
   134                 new TestMethod() {
   149                                        new TestMethod()
   135                     public void run(TestCase tc) {
   150         {
   136                         ((AlertUITest) tc).testImageAndTextCombinations();
   151             public void run(TestCase tc)
   137                     }
   152             {
   138                 }));
   153                 ((AlertUITest) tc).testImageAndTextCombinations();
       
   154             }
       
   155         }));
   139 
   156 
   140         return aSuite;
   157         return aSuite;
   141     }
   158     }
   142 
   159 
   143     /**
   160     /**
   144      * Tests showing a timed alert with default values.
   161      * Tests showing a timed alert with default values.
   145      */
   162      */
   146     public void testShowTimedAlert() {
   163     public void testShowTimedAlert()
       
   164     {
   147         setCurrent(textBox);
   165         setCurrent(textBox);
   148 
   166 
   149         Alert alert = new Alert("timedAlert");
   167         Alert alert = new Alert("timedAlert");
   150         int timeout = alert.getTimeout();
   168         int timeout = alert.getTimeout();
   151         assertTrue("Alert should be timed", timeout != Alert.FOREVER);
   169         assertTrue("Alert should be timed", timeout != Alert.FOREVER);
   167 
   185 
   168         // Default listener should dismisses the Alert
   186         // Default listener should dismisses the Alert
   169         setCurrent(alert);
   187         setCurrent(alert);
   170         block(timeout + CHANGE_DISPLAYABLE_DELAY);
   188         block(timeout + CHANGE_DISPLAYABLE_DELAY);
   171         assertEquals("Textbox should be current",
   189         assertEquals("Textbox should be current",
   172                 textBox, display.getCurrent());
   190                      textBox, display.getCurrent());
   173     }
   191     }
   174 
   192 
   175     /**
   193     /**
   176      * Tests showing a timed alert with custom command listener.
   194      * Tests showing a timed alert with custom command listener.
   177      */
   195      */
   178     public void testCustomListener() {
   196     public void testCustomListener()
   179     	setCurrent(textBox);
   197     {
       
   198         setCurrent(textBox);
   180 
   199 
   181         Alert alert = new Alert("customListenerAlert");
   200         Alert alert = new Alert("customListenerAlert");
   182         assertTrue("Alert should be timed",
   201         assertTrue("Alert should be timed",
   183                 alert.getTimeout() != Alert.FOREVER);
   202                    alert.getTimeout() != Alert.FOREVER);
   184         alert.setCommandListener(this);
   203         alert.setCommandListener(this);
   185         setCurrent(alert);
   204         setCurrent(alert);
   186         // wait for max 10sec to get command listener callback
   205         // wait for max 10sec to get command listener callback
   187         assertTrue("Textbox isShown() should be false", !textBox.isShown());
   206         assertTrue("Textbox isShown() should be false", !textBox.isShown());
   188         assertCmdListener("", Alert.DISMISS_COMMAND, alert);
   207         assertCmdListener("", Alert.DISMISS_COMMAND, alert);
   190 
   209 
   191     /**
   210     /**
   192      * Tests showing a timed alert with custom command listener and custom
   211      * Tests showing a timed alert with custom command listener and custom
   193      * command.
   212      * command.
   194      */
   213      */
   195     public void testCustomListenerCustomCommand() {
   214     public void testCustomListenerCustomCommand()
   196     	setCurrent(textBox);
   215     {
       
   216         setCurrent(textBox);
   197 
   217 
   198         Alert alert = new Alert("customCmdAlert");
   218         Alert alert = new Alert("customCmdAlert");
   199         assertTrue("Alert should be timed",
   219         assertTrue("Alert should be timed",
   200                 alert.getTimeout() != Alert.FOREVER);
   220                    alert.getTimeout() != Alert.FOREVER);
   201         alert.setCommandListener(this);
   221         alert.setCommandListener(this);
   202         Command testCmd = new Command("test", "test", Command.ITEM, 0);
   222         Command testCmd = new Command("test", "test", Command.ITEM, 0);
   203         alert.addCommand(testCmd);
   223         alert.addCommand(testCmd);
   204         setCurrent(alert);
   224         setCurrent(alert);
   205         // wait for max 10sec to get command listener callback
   225         // wait for max 10sec to get command listener callback
   208     }
   228     }
   209 
   229 
   210     /**
   230     /**
   211      * Tests pressing keys on Alert's custom commands.
   231      * Tests pressing keys on Alert's custom commands.
   212      */
   232      */
   213     public void testKeypressOnCustomCommands() {
   233     public void testKeypressOnCustomCommands()
   214     	setCurrent(textBox);
   234     {
       
   235         setCurrent(textBox);
   215 
   236 
   216         Alert alert = new Alert("keypressAlert");
   237         Alert alert = new Alert("keypressAlert");
   217         assertTrue("Alert should be timed",
   238         assertTrue("Alert should be timed",
   218                 alert.getTimeout() != Alert.FOREVER);
   239                    alert.getTimeout() != Alert.FOREVER);
   219         alert.setCommandListener(this);
   240         alert.setCommandListener(this);
   220         Command testCmd1 = new Command("Cmd1", "Command 1", Command.SCREEN, 0);
   241         Command testCmd1 = new Command("Cmd1", "Command 1", Command.SCREEN, 0);
   221         Command testCmd2 = new Command("Cmd2", "Command 2", Command.SCREEN, 1);
   242         Command testCmd2 = new Command("Cmd2", "Command 2", Command.SCREEN, 1);
   222         alert.addCommand(testCmd1);
   243         alert.addCommand(testCmd1);
   223         alert.addCommand(testCmd2);
   244         alert.addCommand(testCmd2);
   224         assertTrue("Alert should be modal",
   245         assertTrue("Alert should be modal",
   225                 alert.getTimeout() == Alert.FOREVER);
   246                    alert.getTimeout() == Alert.FOREVER);
   226 
   247 
   227         setCurrent(alert);
   248         setCurrent(alert);
   228         key(Key.CBA1, 0);
   249         key(Key.CBA1, 0);
   229         key(Key.Select);
   250         key(Key.Select);
   230         assertCmdListener("", testCmd1, alert);
   251         assertCmdListener("", testCmd1, alert);
   238     }
   259     }
   239 
   260 
   240     /**
   261     /**
   241      * Tests scrolling a long text.
   262      * Tests scrolling a long text.
   242      */
   263      */
   243     public void testLongTextScrolling() {
   264     public void testLongTextScrolling()
   244     	setCurrent(textBox);
   265     {
       
   266         setCurrent(textBox);
   245 
   267 
   246         Alert alert = new Alert("scrollingAlert");
   268         Alert alert = new Alert("scrollingAlert");
   247         alert.setString(longString);
   269         alert.setString(longString);
   248         alert.setCommandListener(this);
   270         alert.setCommandListener(this);
   249         assertTrue("Alert should be modal",
   271         assertTrue("Alert should be modal",
   250                 alert.getTimeout() == Alert.FOREVER);
   272                    alert.getTimeout() == Alert.FOREVER);
   251 
   273 
   252         setCurrent(alert);
   274         setCurrent(alert);
   253         for (int i = 0; i < 10; i++) {
   275         for(int i = 0; i < 10; i++)
       
   276         {
   254             key((i < 5 ? Key.DownArrow : Key.UpArrow));
   277             key((i < 5 ? Key.DownArrow : Key.UpArrow));
   255         }
   278         }
   256 
   279 
   257         key(Key.CBA1);
   280         key(Key.CBA1);
   258         assertCmdListener("", Alert.DISMISS_COMMAND, alert);
   281         assertCmdListener("", Alert.DISMISS_COMMAND, alert);
   259     }
   282     }
   260 
   283 
   261     /**
   284     /**
   262      * Tests different text and image setting combinations.
   285      * Tests different text and image setting combinations.
   263      */
   286      */
   264     public void testImageAndTextCombinations() {
   287     public void testImageAndTextCombinations()
   265     	setCurrent(textBox);
   288     {
       
   289         setCurrent(textBox);
   266 
   290 
   267         Image smallImg = null;
   291         Image smallImg = null;
   268         Image largeImg = null;
   292         Image largeImg = null;
   269         try {
   293         try
       
   294         {
   270             smallImg = Image.createImage("100x100.png");
   295             smallImg = Image.createImage("100x100.png");
   271         }
   296         }
   272         catch (IOException e) {
   297         catch(IOException e)
       
   298         {
   273             fail("Cannot load image 100x100.png");
   299             fail("Cannot load image 100x100.png");
   274         }
   300         }
   275         try {
   301         try
       
   302         {
   276             largeImg = Image.createImage("200x200.png");
   303             largeImg = Image.createImage("200x200.png");
   277         }
   304         }
   278         catch (IOException e) {
   305         catch(IOException e)
       
   306         {
   279             fail("Cannot load image 200x200.png");
   307             fail("Cannot load image 200x200.png");
   280         }
   308         }
   281 
   309 
   282         Alert alert = new Alert("varyingAlert");
   310         Alert alert = new Alert("varyingAlert");
   283         alert.setTimeout(Alert.FOREVER);
   311         alert.setTimeout(Alert.FOREVER);
   284         alert.setCommandListener(this);
   312         alert.setCommandListener(this);
   285         assertTrue("Alert should be modal",
   313         assertTrue("Alert should be modal",
   286                 alert.getTimeout() == Alert.FOREVER);
   314                    alert.getTimeout() == Alert.FOREVER);
   287 
   315 
   288         setCurrent(alert);
   316         setCurrent(alert);
   289         for (int textIndex = 0; textIndex < 3; textIndex++) {
   317         for(int textIndex = 0; textIndex < 3; textIndex++)
   290             switch (textIndex) {
   318         {
       
   319             switch(textIndex)
       
   320             {
       
   321             case 0:
       
   322                 alert.setString(null);
       
   323                 break;
       
   324             case 1:
       
   325                 alert.setString(shortString);
       
   326                 break;
       
   327             case 2:
       
   328                 alert.setString(longString);
       
   329                 break;
       
   330             default:
       
   331                 break;
       
   332             }
       
   333             for(int imgIndex = 0; imgIndex < 3; imgIndex++)
       
   334             {
       
   335                 switch(imgIndex)
       
   336                 {
   291                 case 0:
   337                 case 0:
   292                     alert.setString(null);
   338                     alert.setImage(null);
   293                     break;
   339                     break;
   294                 case 1:
   340                 case 1:
   295                     alert.setString(shortString);
   341                     alert.setImage(smallImg);
   296                     break;
   342                     break;
   297                 case 2:
   343                 case 2:
   298                     alert.setString(longString);
   344                     alert.setImage(largeImg);
   299                     break;
   345                     break;
   300                 default:
   346                 default:
   301                     break;
   347                     break;
   302             }
       
   303             for (int imgIndex = 0; imgIndex < 3; imgIndex++) {
       
   304                 switch (imgIndex) {
       
   305                     case 0:
       
   306                         alert.setImage(null);
       
   307                         break;
       
   308                     case 1:
       
   309                         alert.setImage(smallImg);
       
   310                         break;
       
   311                     case 2:
       
   312                         alert.setImage(largeImg);
       
   313                         break;
       
   314                     default:
       
   315                         break;
       
   316                 }
   348                 }
   317                 block(CHANGE_DISPLAYABLE_DELAY); // 0.3 sec
   349                 block(CHANGE_DISPLAYABLE_DELAY); // 0.3 sec
   318             }
   350             }
   319         }
   351         }
   320         block(1000); // 1sec
   352         block(1000); // 1sec