javauis/lcdui_qt/tsrc/uitestsrc/t_uirobot/displayable/AddCommandTest.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.*;
    32  * <li> UI-robot based tests to test Displayable's Command-related
    32  * <li> UI-robot based tests to test Displayable's Command-related
    33  * functionality. <br>
    33  * functionality. <br>
    34  * <br>
    34  * <br>
    35  * Created: 2008-04-30
    35  * Created: 2008-04-30
    36  */
    36  */
    37 public class AddCommandTest extends UITestBase {
    37 public class AddCommandTest extends UITestBase
       
    38 {
    38 
    39 
    39     private static final int MAX_CHARS = 100;
    40     private static final int MAX_CHARS = 100;
    40 
    41 
    41     public AddCommandTest() {
    42     public AddCommandTest()
    42 		super();
    43     {
    43 	}
    44         super();
    44 
    45     }
    45 	public AddCommandTest(String name, TestMethod method) {
    46 
    46 		super(name, method);
    47     public AddCommandTest(String name, TestMethod method)
    47 	}
    48     {
    48 
    49         super(name, method);
    49 	/**
    50     }
       
    51 
       
    52     /**
    50     /**
    53     /**
    51      * Creates the test suite. You need to add a new aSuite.addTest antry for
    54      * Creates the test suite. You need to add a new aSuite.addTest antry for
    52      * any new test methods, otherwise they won't be run.
    55      * any new test methods, otherwise they won't be run.
    53      *
    56      *
    54      * @return New testsuite.
    57      * @return New testsuite.
    55      */
    58      */
    56     public Test suite() {
    59     public Test suite()
       
    60     {
    57         TestSuite aSuite = new TestSuite();
    61         TestSuite aSuite = new TestSuite();
    58 
    62 
    59         aSuite.addTest(new AddCommandTest("testAddCommandBeforeListener",
    63         aSuite.addTest(new AddCommandTest("testAddCommandBeforeListener",
    60                 new TestMethod() {
    64                                           new TestMethod()
    61                     public void run(TestCase tc) {
    65         {
    62                         ((AddCommandTest) tc).testAddCommandBeforeListener();
    66             public void run(TestCase tc)
    63                     }
    67             {
    64                 }));
    68                 ((AddCommandTest) tc).testAddCommandBeforeListener();
       
    69             }
       
    70         }));
    65 
    71 
    66         aSuite.addTest(new AddCommandTest("testAddCommandAfterListener",
    72         aSuite.addTest(new AddCommandTest("testAddCommandAfterListener",
    67                 new TestMethod() {
    73                                           new TestMethod()
    68                     public void run(TestCase tc) {
    74         {
    69                         ((AddCommandTest) tc).testAddCommandAfterListener();
    75             public void run(TestCase tc)
    70                     }
    76             {
    71                 }));
    77                 ((AddCommandTest) tc).testAddCommandAfterListener();
       
    78             }
       
    79         }));
    72 
    80 
    73         aSuite.addTest(new AddCommandTest("testRemoveListener",
    81         aSuite.addTest(new AddCommandTest("testRemoveListener",
    74                 new TestMethod() {
    82                                           new TestMethod()
    75                     public void run(TestCase tc) {
    83         {
    76                         ((AddCommandTest) tc).testRemoveListener();
    84             public void run(TestCase tc)
    77                     }
    85             {
    78                 }));
    86                 ((AddCommandTest) tc).testRemoveListener();
       
    87             }
       
    88         }));
    79 
    89 
    80         aSuite.addTest(new AddCommandTest("testAddToManyDisplayables",
    90         aSuite.addTest(new AddCommandTest("testAddToManyDisplayables",
    81                 new TestMethod() {
    91                                           new TestMethod()
    82                     public void run(TestCase tc) {
    92         {
    83                         ((AddCommandTest) tc).testAddToManyDisplayables();
    93             public void run(TestCase tc)
    84                     }
    94             {
    85                 }));
    95                 ((AddCommandTest) tc).testAddToManyDisplayables();
       
    96             }
       
    97         }));
    86 
    98 
    87         aSuite.addTest(new AddCommandTest("testAddCommandTwice",
    99         aSuite.addTest(new AddCommandTest("testAddCommandTwice",
    88                 new TestMethod() {
   100                                           new TestMethod()
    89                     public void run(TestCase tc) {
   101         {
    90                         ((AddCommandTest) tc).testAddCommandTwice();
   102             public void run(TestCase tc)
    91                     }
   103             {
    92                 }));
   104                 ((AddCommandTest) tc).testAddCommandTwice();
       
   105             }
       
   106         }));
    93 
   107 
    94         return aSuite;
   108         return aSuite;
    95     }
   109     }
    96 
   110 
    97     /**
   111     /**
    98      * Test command adding before CommandListener is set.
   112      * Test command adding before CommandListener is set.
    99      */
   113      */
   100     public void testAddCommandBeforeListener() {
   114     public void testAddCommandBeforeListener()
       
   115     {
   101         TextBox textBox = new TextBox("title", "content", MAX_CHARS, 0);
   116         TextBox textBox = new TextBox("title", "content", MAX_CHARS, 0);
   102         Command c1 = new Command("item1", "item1", Command.ITEM, 0);
   117         Command c1 = new Command("item1", "item1", Command.ITEM, 0);
   103 
   118 
   104         textBox.addCommand(c1);
   119         textBox.addCommand(c1);
   105         textBox.setCommandListener(this);
   120         textBox.setCommandListener(this);
   113     }
   128     }
   114 
   129 
   115     /**
   130     /**
   116      * Test command adding after CommandListener is set.
   131      * Test command adding after CommandListener is set.
   117      */
   132      */
   118     public void testAddCommandAfterListener() {
   133     public void testAddCommandAfterListener()
       
   134     {
   119         TextBox textBox = new TextBox("title", "content", MAX_CHARS, 0);
   135         TextBox textBox = new TextBox("title", "content", MAX_CHARS, 0);
   120         Command c1 = new Command("item1", "item1", Command.ITEM, 0);
   136         Command c1 = new Command("item1", "item1", Command.ITEM, 0);
   121 
   137 
   122         textBox.setCommandListener(this);
   138         textBox.setCommandListener(this);
   123         textBox.addCommand(c1);
   139         textBox.addCommand(c1);
   132 
   148 
   133     /**
   149     /**
   134      * Test that removing CommandListener will work and no commands are
   150      * Test that removing CommandListener will work and no commands are
   135      * delivered to CommandListener anymore.
   151      * delivered to CommandListener anymore.
   136      */
   152      */
   137     public void testRemoveListener() {
   153     public void testRemoveListener()
       
   154     {
   138         TextBox textBox = new TextBox("title", "content", MAX_CHARS, 0);
   155         TextBox textBox = new TextBox("title", "content", MAX_CHARS, 0);
   139         Command c1 = new Command("item1", "item1", Command.ITEM, 0);
   156         Command c1 = new Command("item1", "item1", Command.ITEM, 0);
   140 
   157 
   141         textBox.setCommandListener(this);
   158         textBox.setCommandListener(this);
   142         textBox.addCommand(c1);
   159         textBox.addCommand(c1);
   154 
   171 
   155     /**
   172     /**
   156      * In LCDUI it's possible to add same Command to many Displayables. This
   173      * In LCDUI it's possible to add same Command to many Displayables. This
   157      * test tests that events occurs correctly in such case.
   174      * test tests that events occurs correctly in such case.
   158      */
   175      */
   159     public void testAddToManyDisplayables() {
   176     public void testAddToManyDisplayables()
       
   177     {
   160         // There are two Displayables and one Command in this test:
   178         // There are two Displayables and one Command in this test:
   161         TextBox textBox = new TextBox("title", "content", MAX_CHARS, 0);
   179         TextBox textBox = new TextBox("title", "content", MAX_CHARS, 0);
   162         TextBox textBox2 = new TextBox("title2", "content2", MAX_CHARS, 0);
   180         TextBox textBox2 = new TextBox("title2", "content2", MAX_CHARS, 0);
   163         Command c1 = new Command("item1", "item1", Command.ITEM, 0);
   181         Command c1 = new Command("item1", "item1", Command.ITEM, 0);
   164 
   182 
   208 
   226 
   209     /**
   227     /**
   210      * Tests that nothing happens if command is added to the displayable which
   228      * Tests that nothing happens if command is added to the displayable which
   211      * already contains the command.
   229      * already contains the command.
   212      */
   230      */
   213     public void testAddCommandTwice() {
   231     public void testAddCommandTwice()
       
   232     {
   214         TextBox textBox = new TextBox("title", "content", MAX_CHARS, 0);
   233         TextBox textBox = new TextBox("title", "content", MAX_CHARS, 0);
   215         Command c1 = new Command("item1", "item1", Command.ITEM, 0);
   234         Command c1 = new Command("item1", "item1", Command.ITEM, 0);
   216 
   235 
   217         textBox.setCommandListener(this);
   236         textBox.setCommandListener(this);
   218         setCurrent(textBox);
   237         setCurrent(textBox);