javauis/lcdui_qt/tsrc/src/com/nokia/openlcdui/mt/spacer/SpacerTest.java
changeset 21 2a9601315dfc
child 23 98ccebc37403
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 package com.nokia.openlcdui.mt.spacer;
       
    18 
       
    19 import junit.framework.*;
       
    20 import javax.microedition.lcdui.*;
       
    21 
       
    22 import junit.framework.Test;
       
    23 import junit.framework.TestSuite;
       
    24 import com.nokia.openlcdui.mt.SWTTestCase;
       
    25 
       
    26 /**
       
    27  * TEST CASE SPECIFICATION <br>
       
    28  * <br>
       
    29  * Short description of the module test:
       
    30  * <li>Collection of tests to test Spacer's API functionality.<br>
       
    31  *
       
    32  * @created 1.8.2008
       
    33  */
       
    34 public class SpacerTest extends SWTTestCase {
       
    35 
       
    36     private static final int WIDTH = 100;
       
    37     private static final int HEIGHT = 100;
       
    38 
       
    39     /**
       
    40      * Constructor.
       
    41      */
       
    42     public SpacerTest() {
       
    43     }
       
    44 
       
    45     /**
       
    46      * Constructor.
       
    47      *
       
    48      * @param sTestName name of the test
       
    49      * @param rTestMethod TestMethod used
       
    50      */
       
    51     public SpacerTest(String sTestName) {
       
    52         super(sTestName);
       
    53     }
       
    54 
       
    55     /**
       
    56      * Any pre-test setup can be done here
       
    57      */
       
    58     protected void setUp() throws Exception {
       
    59     }
       
    60 
       
    61     /**
       
    62      * To create the test suite. You need to add a new aSuite.addTest entry for
       
    63      * any new test methods.
       
    64      *
       
    65      * @return New TestSuite.
       
    66      */
       
    67     public static Test suite() {
       
    68 		TestSuite suite = new TestSuite();
       
    69 
       
    70 	    java.util.Vector methodNames;
       
    71 	    java.util.Enumeration e;
       
    72 
       
    73 	    // Add widget tests
       
    74 	    methodNames = SpacerTest.methodNames();
       
    75 	    e = methodNames.elements();
       
    76 	    while (e.hasMoreElements()) {
       
    77 	        suite.addTest(new SpacerTest((String)e.nextElement()));
       
    78 	    }
       
    79 
       
    80 		return suite;
       
    81 	}
       
    82 
       
    83     public static java.util.Vector methodNames() {
       
    84         java.util.Vector methodNames = new java.util.Vector();
       
    85         methodNames.addElement("testAccessors");
       
    86         return methodNames;
       
    87     }
       
    88     
       
    89     protected void runTest() throws Throwable {
       
    90         if (getName().equals("testAccessors")) testAccessors();
       
    91         else super.runTest();
       
    92     }
       
    93 
       
    94     /**
       
    95      * Test method.
       
    96      */
       
    97     public void testAccessors() {
       
    98         Spacer spacer;
       
    99 
       
   100         try {
       
   101             spacer = new Spacer(-1, -1);
       
   102             fail("no IllegalArgumentException is thrown when parameters are"
       
   103                     + " incorrect in constructor");
       
   104         }
       
   105         catch (IllegalArgumentException e) {
       
   106             //OK
       
   107         }
       
   108         spacer = new Spacer(WIDTH, HEIGHT);
       
   109         Command ok = new Command("Ok", "", Command.ITEM, 0);
       
   110         try {
       
   111             spacer.addCommand(ok);
       
   112             fail("no IllegalStateException is thrown when adding command");
       
   113         }
       
   114         catch (IllegalStateException e) {
       
   115             //OK
       
   116         }
       
   117         try {
       
   118             spacer.setDefaultCommand(ok);
       
   119             fail("no IllegalStateException is thrown when setting default "
       
   120                     + " command");
       
   121         }
       
   122         catch (IllegalStateException e) {
       
   123             //OK
       
   124         }
       
   125         try {
       
   126             spacer.setLabel("some label");
       
   127             fail("no IllegalStateException is thrown when setting label");
       
   128         }
       
   129         catch (IllegalStateException e) {
       
   130             //OK
       
   131         }
       
   132         try {
       
   133             spacer.setMinimumSize(-1, -1);
       
   134             fail("no IllegalArgumentException is thrown when setting minimum "
       
   135                     + "size less then 0");
       
   136         }
       
   137         catch (IllegalArgumentException e) {
       
   138             //OK
       
   139         }
       
   140     }
       
   141 }