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