javauis/lcdui_qt/tsrc/src/com/nokia/openlcdui/mt/gauge/GaugeTest.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.gauge;
       
    18 
       
    19 import junit.framework.*;
       
    20 
       
    21 import javax.microedition.lcdui.*;
       
    22 import com.nokia.openlcdui.mt.SWTTestCase;
       
    23 
       
    24 /**
       
    25  * TEST CASE SPECIFICATION <br>
       
    26  * <br>
       
    27  * Short description of the module test:
       
    28  * <li>Collection of tests to test Gauge's API functionality. <br>
       
    29  * <br>
       
    30  */
       
    31 public class GaugeTest extends SWTTestCase {
       
    32 
       
    33     private static String label = "Label";
       
    34 
       
    35     private static final int POSITIVE_INT = 100;
       
    36     private static final int NEGATIVE_INT = -100;
       
    37 
       
    38     /**
       
    39      * Constructor.
       
    40      */
       
    41     public GaugeTest() {
       
    42     }
       
    43 
       
    44     /**
       
    45      * Constructor.
       
    46      *
       
    47      * @param sTestName Test name.
       
    48      * @param rTestMethod Test method.
       
    49      */
       
    50     public GaugeTest(String sTestName) {
       
    51         super(sTestName);
       
    52     }
       
    53 
       
    54     /**
       
    55      * Any pre-test setup can be done here
       
    56      */
       
    57     protected void setUp() throws Exception {
       
    58     }
       
    59 
       
    60     /**
       
    61      * To create the test suite. You need to add a new aSuite.addTest entry for
       
    62      * any new test methods.
       
    63      *
       
    64      * @return New testsuite.
       
    65      */
       
    66     public static Test suite() {
       
    67 		TestSuite suite = new TestSuite();
       
    68 
       
    69 	    java.util.Vector methodNames;
       
    70 	    java.util.Enumeration e;
       
    71 
       
    72 	    // Add widget tests
       
    73 	    methodNames = GaugeTest.methodNames();
       
    74 	    e = methodNames.elements();
       
    75 	    while (e.hasMoreElements()) {
       
    76 	        suite.addTest(new GaugeTest((String)e.nextElement()));
       
    77 	    }
       
    78 
       
    79 		return suite;
       
    80 	}
       
    81     
       
    82     public static java.util.Vector methodNames() {
       
    83         java.util.Vector methodNames = new java.util.Vector();
       
    84         methodNames.addElement("testAccessors");
       
    85         return methodNames;
       
    86     }
       
    87     
       
    88     protected void runTest() throws Throwable {
       
    89         if (getName().equals("testAccessors")) testAccessors();
       
    90         else super.runTest();
       
    91     }
       
    92     /**
       
    93      * Tests the gauge accessor methods.
       
    94      */
       
    95     public void testAccessors() {
       
    96         Gauge gauge = new Gauge(null, false, POSITIVE_INT, 0);
       
    97 
       
    98         assertTrue("Should be noninteractive", !gauge.isInteractive());
       
    99         assertEquals("Maxvalues don't match", POSITIVE_INT,
       
   100                 gauge.getMaxValue());
       
   101         assertEquals("Labels don't match", null, gauge.getLabel());
       
   102 
       
   103         gauge.setLabel(label);
       
   104         assertEquals("Labels don't match", label, gauge.getLabel());
       
   105 
       
   106         gauge.setValue(NEGATIVE_INT);
       
   107         assertEquals("Values mismatch", 0, gauge.getValue());
       
   108 
       
   109         gauge.setValue(POSITIVE_INT * 2);
       
   110         assertEquals("Values mismatch", POSITIVE_INT, gauge.getValue());
       
   111 
       
   112         gauge.setValue(0);
       
   113         try {
       
   114             gauge.setMaxValue(NEGATIVE_INT);
       
   115             fail("1. IllegalArgumentException expected");
       
   116         }
       
   117         catch (IllegalArgumentException iae) {
       
   118         }
       
   119 
       
   120         gauge.setMaxValue(Gauge.INDEFINITE);
       
   121 
       
   122         try {
       
   123             gauge.setValue(NEGATIVE_INT);
       
   124             fail("2. IllegalArgumentException expected");
       
   125         }
       
   126         catch (IllegalArgumentException iae) {
       
   127         }
       
   128 
       
   129         try {
       
   130             gauge.setValue(Gauge.CONTINUOUS_IDLE);
       
   131             gauge.setValue(Gauge.INCREMENTAL_IDLE);
       
   132             gauge.setValue(Gauge.CONTINUOUS_RUNNING);
       
   133             gauge.setValue(Gauge.INCREMENTAL_UPDATING);
       
   134         }
       
   135         catch (IllegalArgumentException iae) {
       
   136             fail("3. IllegalArgumentException thrown " + iae.getMessage());
       
   137         }
       
   138 
       
   139         try {
       
   140             gauge.setValue(POSITIVE_INT);
       
   141             fail("4. IllegalArgumentException expected");
       
   142         }
       
   143         catch (IllegalArgumentException iae) {
       
   144         }
       
   145 
       
   146         // Test minimum bounds, non-interactive:
       
   147         gauge.setLabel(null);
       
   148         assertTrue("Minimum height was zero or negative, case 1.",
       
   149                 gauge.getMinimumHeight() > 0);
       
   150         //print("non-interactive minimum height: "
       
   151         //        + gauge.getMinimumHeight());
       
   152         assertTrue("Minimum width was zero or negative, case 1.",
       
   153                 gauge.getMinimumWidth() > 0);
       
   154         //print("non-interactive minimum width: "
       
   155         //        + gauge.getMinimumWidth());
       
   156 
       
   157         // Minimum bounds, interactive:
       
   158         Gauge gauge2 = new Gauge(null, true, POSITIVE_INT, 0);
       
   159         assertTrue("Minimum height was zero or negative, case 2.",
       
   160                 gauge2.getMinimumHeight() > 0);
       
   161         //print("interactive minimum height: "
       
   162         //        + gauge2.getMinimumHeight());
       
   163         assertTrue("Minimum width was zero or negative, case 2.",
       
   164                 gauge2.getMinimumWidth() > 0);
       
   165         //print("interactive minimum width: "
       
   166         //        + gauge2.getMinimumWidth());
       
   167 
       
   168         // Minimum bounds, non-interactive with label:
       
   169         Gauge gauge3 = new Gauge("label", false, POSITIVE_INT, 0);
       
   170         assertTrue("Minimum height was zero or negative, case 3.",
       
   171                 gauge3.getMinimumHeight() > 0);
       
   172         //print("labeled non-interactive minimum height: "
       
   173         //        + gauge3.getMinimumHeight());
       
   174         assertTrue("Minimum width was zero or negative, case 3.",
       
   175                 gauge3.getMinimumWidth() > 0);
       
   176         //print("labeled non-interactive minimum width: "
       
   177         //        + gauge3.getMinimumWidth());
       
   178 
       
   179         // Minimum bounds, interactive with label:
       
   180         Gauge gauge4 = new Gauge("label", true, POSITIVE_INT, 0);
       
   181         assertTrue("Minimum height was zero or negative, case 4.",
       
   182                 gauge4.getMinimumHeight() > 0);
       
   183         //print("labeled interactive minimum height: "
       
   184         //        + gauge4.getMinimumHeight());
       
   185         assertTrue("Minimum width was zero or negative, case 4.",
       
   186                 gauge4.getMinimumWidth() > 0);
       
   187         //print("labeled interactive minimum width: "
       
   188         //        + gauge4.getMinimumWidth());
       
   189     }
       
   190 }