javauis/lcdui_qt/tsrc/uitestsrc/t_uirobot/displayable/SendBackgroundTest.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.displayable;
    17 package t_uirobot.displayable;
    18 
    18 
    19 import j2meunit.framework.*;
    19 import j2meunit.framework.*;
    31  * <li> UI-robot based tests to test Displayable's isShow when MIDlet or
    31  * <li> UI-robot based tests to test Displayable's isShow when MIDlet or
    32  * displayable is sent to background. <br>
    32  * displayable is sent to background. <br>
    33  * <br>
    33  * <br>
    34  * Created: 2008-05-07
    34  * Created: 2008-05-07
    35  */
    35  */
    36 public class SendBackgroundTest extends UITestBase {
    36 public class SendBackgroundTest extends UITestBase
       
    37 {
    37 
    38 
    38     private static final int MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX = 100;
    39     private static final int MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX = 100;
    39     private static final int SEND_BACKGROUND_DELAY = 300;
    40     private static final int SEND_BACKGROUND_DELAY = 300;
    40     private static final int SEND_FOREGROUND_DELAY = 300;
    41     private static final int SEND_FOREGROUND_DELAY = 300;
    41 
    42 
    42     /**
    43     /**
    43      * Constructor.
    44      * Constructor.
    44      */
    45      */
    45     public SendBackgroundTest() {
    46     public SendBackgroundTest()
    46     	super();
    47     {
       
    48         super();
    47     }
    49     }
    48 
    50 
    49     /**
    51     /**
    50      * Constructor.
    52      * Constructor.
    51      *
    53      *
    52      * @param sTestName Test name.
    54      * @param sTestName Test name.
    53      * @param rTestMethod Test method.
    55      * @param rTestMethod Test method.
    54      */
    56      */
    55     public SendBackgroundTest(String sTestName, TestMethod rTestMethod) {
    57     public SendBackgroundTest(String sTestName, TestMethod rTestMethod)
       
    58     {
    56         super(sTestName, rTestMethod);
    59         super(sTestName, rTestMethod);
    57     }
    60     }
    58 
    61 
    59     /**
    62     /**
    60      * Creates the test suite. You need to add a new aSuite.addTest antry for
    63      * Creates the test suite. You need to add a new aSuite.addTest antry for
    61      * any new test methods, otherwise they won't be run.
    64      * any new test methods, otherwise they won't be run.
    62      *
    65      *
    63      * @return New testsuite.
    66      * @return New testsuite.
    64      */
    67      */
    65     public Test suite() {
    68     public Test suite()
       
    69     {
    66         TestSuite aSuite = new TestSuite();
    70         TestSuite aSuite = new TestSuite();
    67 
    71 
    68         aSuite.addTest(new SendBackgroundTest("testIsShownWhenBackground",
    72         aSuite.addTest(new SendBackgroundTest("testIsShownWhenBackground",
    69                 new TestMethod() {
    73                                               new TestMethod()
    70                     public void run(TestCase tc) {
    74         {
    71                         ((SendBackgroundTest) tc).testIsShownWhenBackground();
    75             public void run(TestCase tc)
    72                     }
    76             {
    73                 }));
    77                 ((SendBackgroundTest) tc).testIsShownWhenBackground();
       
    78             }
       
    79         }));
    74 
    80 
    75         aSuite.addTest(new SendBackgroundTest("testIsShownWhenNotCurrent",
    81         aSuite.addTest(new SendBackgroundTest("testIsShownWhenNotCurrent",
    76                 new TestMethod() {
    82                                               new TestMethod()
    77                     public void run(TestCase tc) {
    83         {
    78                         ((SendBackgroundTest) tc).testIsShownWhenNotCurrent();
    84             public void run(TestCase tc)
    79                     }
    85             {
    80                 }));
    86                 ((SendBackgroundTest) tc).testIsShownWhenNotCurrent();
       
    87             }
       
    88         }));
    81 
    89 
    82         aSuite.addTest(new SendBackgroundTest("testGetHeightAndWidth",
    90         aSuite.addTest(new SendBackgroundTest("testGetHeightAndWidth",
    83                 new TestMethod() {
    91                                               new TestMethod()
    84                     public void run(TestCase tc) {
    92         {
    85                         ((SendBackgroundTest) tc).testGetHeightAndWidth();
    93             public void run(TestCase tc)
    86                     }
    94             {
    87                 }));
    95                 ((SendBackgroundTest) tc).testGetHeightAndWidth();
       
    96             }
       
    97         }));
    88 
    98 
    89         return aSuite;
    99         return aSuite;
    90     }
   100     }
    91 
   101 
    92     /**
   102     /**
    93      * Test that isShown()-method returns false when displayable is in
   103      * Test that isShown()-method returns false when displayable is in
    94      * background.
   104      * background.
    95      */
   105      */
    96     public void testIsShownWhenBackground() {
   106     public void testIsShownWhenBackground()
       
   107     {
    97         boolean testPassed = true;
   108         boolean testPassed = true;
    98         String testMsg = "";
   109         String testMsg = "";
    99 
   110 
   100         TextBox textBox = new TextBox("title", "content",
   111         TextBox textBox = new TextBox("title", "content",
   101                 MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX, 0);
   112                                       MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX, 0);
   102 
   113 
   103         setCurrent(textBox);
   114         setCurrent(textBox);
   104 
   115 
   105         // Send MIDlet to background and verify that isShown()
   116         // Send MIDlet to background and verify that isShown()
   106         // returns false:
   117         // returns false:
   107         key(Key.Applications, SEND_BACKGROUND_DELAY);
   118         key(Key.Applications, SEND_BACKGROUND_DELAY);
   108 
   119 
   109         if (textBox.isShown()) {
   120         if(textBox.isShown())
       
   121         {
   110             testPassed = false;
   122             testPassed = false;
   111             testMsg = "isShown() returned true when MIDlet was in background.";
   123             testMsg = "isShown() returned true when MIDlet was in background.";
   112         }
   124         }
   113 
   125 
   114         // Move MIDlet back to foreground and verify isShown()
   126         // Move MIDlet back to foreground and verify isShown()
   116         key(Key.CBA1, 0);
   128         key(Key.CBA1, 0);
   117         key(Key.UpArrow, 0);
   129         key(Key.UpArrow, 0);
   118         key(Key.Select, 0);
   130         key(Key.Select, 0);
   119         key(Key.Select, SEND_FOREGROUND_DELAY);
   131         key(Key.Select, SEND_FOREGROUND_DELAY);
   120 
   132 
   121         if (!textBox.isShown()) {
   133         if(!textBox.isShown())
       
   134         {
   122             testPassed = false;
   135             testPassed = false;
   123             testMsg = "isShown() returned false when MIDlet was in foreground.";
   136             testMsg = "isShown() returned false when MIDlet was in foreground.";
   124         }
   137         }
   125 
   138 
   126         assertTrue(getName() + " failed, " + testMsg, testPassed);
   139         assertTrue(getName() + " failed, " + testMsg, testPassed);
   128 
   141 
   129     /**
   142     /**
   130      * Tests that isShown() returns false if displayable is first set current
   143      * Tests that isShown() returns false if displayable is first set current
   131      * and then another displayable is set current.
   144      * and then another displayable is set current.
   132      */
   145      */
   133     public void testIsShownWhenNotCurrent() {
   146     public void testIsShownWhenNotCurrent()
       
   147     {
   134         boolean testPassed = true;
   148         boolean testPassed = true;
   135         String testMsg = "";
   149         String testMsg = "";
   136 
   150 
   137         TextBox textBox = new TextBox("title", "content",
   151         TextBox textBox = new TextBox("title", "content",
   138                 MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX, 0);
   152                                       MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX, 0);
   139         TextBox textBox2 = new TextBox("title2", "content2",
   153         TextBox textBox2 = new TextBox("title2", "content2",
   140                 MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX, 0);
   154                                        MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX, 0);
   141 
   155 
   142         // First set displayable current and make sure it's shown:
   156         // First set displayable current and make sure it's shown:
   143         setCurrent(textBox);
   157         setCurrent(textBox);
   144         if (!textBox.isShown()) {
   158         if(!textBox.isShown())
       
   159         {
   145             testPassed = false;
   160             testPassed = false;
   146             testMsg = "isShown() returned false when displayable current.";
   161             testMsg = "isShown() returned false when displayable current.";
   147         }
   162         }
   148 
   163 
   149         // Then set another displayable current and make sure the first
   164         // Then set another displayable current and make sure the first
   150         // one isn't shown:
   165         // one isn't shown:
   151         setCurrent(textBox2);
   166         setCurrent(textBox2);
   152 
   167 
   153         if (textBox.isShown()) {
   168         if(textBox.isShown())
       
   169         {
   154             testPassed = false;
   170             testPassed = false;
   155             testMsg = "isShown() returned true when displayable isn't current.";
   171             testMsg = "isShown() returned true when displayable isn't current.";
   156         }
   172         }
   157 
   173 
   158         // Now move first displayable back to current and make sure
   174         // Now move first displayable back to current and make sure
   159         // it knows it's shown:
   175         // it knows it's shown:
   160         setCurrent(textBox);
   176         setCurrent(textBox);
   161         if (!textBox.isShown()) {
   177         if(!textBox.isShown())
       
   178         {
   162             testPassed = false;
   179             testPassed = false;
   163             testMsg = "isShown() returned false when displayable set "
   180             testMsg = "isShown() returned false when displayable set "
   164                     + " back to current.";
   181                       + " back to current.";
   165         }
   182         }
   166 
   183 
   167         assertTrue(getName() + " failed, " + testMsg, testPassed);
   184         assertTrue(getName() + " failed, " + testMsg, testPassed);
   168     }
   185     }
   169 
   186 
   170     /**
   187     /**
   171      * Tests the functionality of getWidth() and getHeight()-methods when
   188      * Tests the functionality of getWidth() and getHeight()-methods when
   172      * displayable not current and when MIDlet is sent to background.
   189      * displayable not current and when MIDlet is sent to background.
   173      */
   190      */
   174     public void testGetHeightAndWidth() {
   191     public void testGetHeightAndWidth()
       
   192     {
   175         boolean testPassed = true;
   193         boolean testPassed = true;
   176         String testMsg = "";
   194         String testMsg = "";
   177         int width = 0;
   195         int width = 0;
   178         int height = 0;
   196         int height = 0;
   179 
   197 
   180         TextBox textBox = new TextBox("title", "content",
   198         TextBox textBox = new TextBox("title", "content",
   181                 MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX, 0);
   199                                       MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX, 0);
   182         TextBox textBox2 = new TextBox("title2", "content2",
   200         TextBox textBox2 = new TextBox("title2", "content2",
   183                 MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX, 0);
   201                                        MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX, 0);
   184 
   202 
   185         // Get initial values:
   203         // Get initial values:
   186         width = textBox.getWidth();
   204         width = textBox.getWidth();
   187         height = textBox.getHeight();
   205         height = textBox.getHeight();
   188 
   206 
   189         // Set displayable to current and make sure the dimension isn't changed:
   207         // Set displayable to current and make sure the dimension isn't changed:
   190         setCurrent(textBox);
   208         setCurrent(textBox);
   191 
   209 
   192         if ((textBox.getWidth() != width) || (textBox.getHeight() != height)) {
   210         if((textBox.getWidth() != width) || (textBox.getHeight() != height))
       
   211         {
   193             testPassed = false;
   212             testPassed = false;
   194             testMsg = "dimension changed after displayable set current:"
   213             testMsg = "dimension changed after displayable set current:"
   195                     + " original w: " + width + " original h:" + height
   214                       + " original w: " + width + " original h:" + height
   196                     + " new w: " + textBox.getWidth() + " new h: "
   215                       + " new w: " + textBox.getWidth() + " new h: "
   197                     + textBox.getHeight();
   216                       + textBox.getHeight();
   198         }
   217         }
   199 
   218 
   200         // Send MIDlet to background and verify that dimension remains same:
   219         // Send MIDlet to background and verify that dimension remains same:
   201         key(Key.Applications, SEND_BACKGROUND_DELAY);
   220         key(Key.Applications, SEND_BACKGROUND_DELAY);
   202 
   221 
   203         if ((textBox.getWidth() != width) || (textBox.getHeight() != height)) {
   222         if((textBox.getWidth() != width) || (textBox.getHeight() != height))
       
   223         {
   204             testPassed = false;
   224             testPassed = false;
   205             testMsg = "dimension changed after MIDlet sent to background:"
   225             testMsg = "dimension changed after MIDlet sent to background:"
   206                     + " original w: " + width + " original h:" + height
   226                       + " original w: " + width + " original h:" + height
   207                     + " new w: " + textBox.getWidth() + " new h: "
   227                       + " new w: " + textBox.getWidth() + " new h: "
   208                     + textBox.getHeight();
   228                       + textBox.getHeight();
   209         }
   229         }
   210 
   230 
   211         // Move MIDlet back to foreground:
   231         // Move MIDlet back to foreground:
   212         key(Key.CBA1, 0);
   232         key(Key.CBA1, 0);
   213         key(Key.UpArrow, 0);
   233         key(Key.UpArrow, 0);
   216 
   236 
   217         // Switch to second displayable and make sure the dimension
   237         // Switch to second displayable and make sure the dimension
   218         // of first displayable remains same:
   238         // of first displayable remains same:
   219         setCurrent(textBox2);
   239         setCurrent(textBox2);
   220 
   240 
   221         if ((textBox.getWidth() != width) || (textBox.getHeight() != height)) {
   241         if((textBox.getWidth() != width) || (textBox.getHeight() != height))
       
   242         {
   222             testPassed = false;
   243             testPassed = false;
   223             testMsg = "dimension changed after other displayable set current:"
   244             testMsg = "dimension changed after other displayable set current:"
   224                     + " original w: " + width + " original h:" + height
   245                       + " original w: " + width + " original h:" + height
   225                     + " new w: " + textBox.getWidth() + " new h: "
   246                       + " new w: " + textBox.getWidth() + " new h: "
   226                     + textBox.getHeight();
   247                       + textBox.getHeight();
   227         }
   248         }
   228 
   249 
   229         assertTrue(getName() + " failed, " + testMsg, testPassed);
   250         assertTrue(getName() + " failed, " + testMsg, testPassed);
   230     }
   251     }
   231 
   252