|
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; |
|
18 |
|
19 import java.util.Vector; |
|
20 |
|
21 import com.nokia.mj.impl.installer.utils.InstallerMain; |
|
22 |
|
23 import junit.framework.Test; |
|
24 import junit.framework.TestCase; |
|
25 import junit.framework.TestSuite; |
|
26 import junit.framework.TestResult; |
|
27 import junit.framework.TestFailure; |
|
28 import junit.textui.ResultPrinter; |
|
29 |
|
30 |
|
31 |
|
32 /** |
|
33 * A simple main application for conveniently executing all of the eSWT tests |
|
34 * with text JUnit UI runner. |
|
35 */ |
|
36 public class AllTests extends TestSuite implements InstallerMain |
|
37 { |
|
38 |
|
39 static boolean runningMain = false; |
|
40 static boolean resultPrinter = true; |
|
41 static Vector disabledTests = SWTTestCase.getDisabledTests(); |
|
42 |
|
43 boolean started; |
|
44 |
|
45 boolean enableUIRobotTests = false; |
|
46 |
|
47 public void installerMain(String[] args) |
|
48 { |
|
49 if(!started) |
|
50 { |
|
51 started = true; |
|
52 |
|
53 Thread uiThread = new Thread(new Runnable() |
|
54 { |
|
55 public void run() |
|
56 { |
|
57 runMainUI(); |
|
58 } |
|
59 }); |
|
60 |
|
61 uiThread.start(); |
|
62 try |
|
63 { |
|
64 uiThread.join(); |
|
65 } |
|
66 catch(InterruptedException e) |
|
67 { |
|
68 e.printStackTrace(); |
|
69 } |
|
70 } |
|
71 } |
|
72 |
|
73 public static void runMainUI() |
|
74 { |
|
75 resultPrinter = false; |
|
76 java.io.PrintStream stream = null; |
|
77 final com.nokia.mj.impl.utils.OmjTestRunner runner; |
|
78 try |
|
79 { |
|
80 Test suite = suite(); |
|
81 runner = new com.nokia.mj.impl.utils.OmjTestRunner(suite); |
|
82 |
|
83 class eSWTPrinter extends ResultPrinter |
|
84 { |
|
85 public eSWTPrinter() |
|
86 { |
|
87 super(System.out); |
|
88 } |
|
89 public void startTest(Test test) |
|
90 { |
|
91 System.out.println(test.toString()); |
|
92 } |
|
93 //public void addFailure(Test t, junit.framework.AssertionFailedError e) {} |
|
94 //public void addError(Test t, Throwable e) {} |
|
95 public void endTest(Test test) |
|
96 { |
|
97 runner.endTest(test); |
|
98 super.endTest(test); |
|
99 } |
|
100 public void printDefect(TestFailure testfailure, int i) |
|
101 { |
|
102 printDefectHeader(testfailure, i); |
|
103 super.printDefect(testfailure, i); |
|
104 } |
|
105 //protected void printErrors(TestResult result) {} |
|
106 }; |
|
107 runner.setPrinter(new eSWTPrinter()); |
|
108 TestResult result = runner.doRun(suite); |
|
109 |
|
110 /* Test results will be written to: |
|
111 * - fileconn.dir.photos\results (c:\data\images\results) on S60, |
|
112 * - JAVA_BIN_ROOT/results on Linux |
|
113 */ |
|
114 runner.writeResultFile(result); |
|
115 |
|
116 } |
|
117 catch(Exception e) |
|
118 { |
|
119 e.printStackTrace(System.out); |
|
120 |
|
121 } |
|
122 finally |
|
123 { |
|
124 if(stream != null) stream.close(); |
|
125 } |
|
126 } |
|
127 |
|
128 public static void main(String[] args) |
|
129 { |
|
130 runningMain = true; |
|
131 |
|
132 Thread uiThread = new Thread(new Runnable() |
|
133 { |
|
134 public void run() |
|
135 { |
|
136 runMainUI(); |
|
137 } |
|
138 }); |
|
139 |
|
140 uiThread.start(); |
|
141 try |
|
142 { |
|
143 uiThread.join(); |
|
144 } |
|
145 catch(InterruptedException e) |
|
146 { |
|
147 e.printStackTrace(); |
|
148 } |
|
149 |
|
150 // Exit forcefully when running outside of MIDP environment, this causes |
|
151 // also OpenLCDUI thread to close. |
|
152 System.exit(0); |
|
153 } |
|
154 |
|
155 public static junit.framework.Test suite() |
|
156 { |
|
157 return new AllTests(); |
|
158 } |
|
159 |
|
160 public void init() |
|
161 { |
|
162 |
|
163 } |
|
164 |
|
165 public AllTests() |
|
166 { |
|
167 init(); |
|
168 |
|
169 addTest(com.nokia.openlcdui.mt.alert.AlertTest.suite()); |
|
170 addTest(com.nokia.openlcdui.mt.canvas.CanvasTest.suite()); |
|
171 addTest(com.nokia.openlcdui.mt.choicegroup.ChoiceGroupTest.suite()); |
|
172 addTest(com.nokia.openlcdui.mt.command.CommandTest.suite()); |
|
173 addTest(com.nokia.openlcdui.mt.command.ItemCommandTest.suite()); |
|
174 addTest(com.nokia.openlcdui.mt.datefield.DateFieldTest.suite()); |
|
175 addTest(com.nokia.openlcdui.mt.display.DisplayTest.suite()); |
|
176 addTest(com.nokia.openlcdui.mt.displayable.DisplayableTest.suite()); |
|
177 addTest(com.nokia.openlcdui.mt.font.FontTest.suite()); |
|
178 addTest(com.nokia.openlcdui.mt.form.FormTest.suite()); |
|
179 addTest(com.nokia.openlcdui.mt.fullcanvas.FullCanvasTest.suite()); |
|
180 addTest(com.nokia.openlcdui.mt.game.CollisionDetectionTest.suite()); |
|
181 addTest(com.nokia.openlcdui.mt.game.GameCanvasTest.suite()); |
|
182 addTest(com.nokia.openlcdui.mt.game.LayerManagerTest.suite()); |
|
183 addTest(com.nokia.openlcdui.mt.game.LayerTest.suite()); |
|
184 addTest(com.nokia.openlcdui.mt.game.SpriteTest.suite()); |
|
185 addTest(com.nokia.openlcdui.mt.game.TiledLayerTest.suite()); |
|
186 addTest(com.nokia.openlcdui.mt.gauge.GaugeTest.suite()); |
|
187 addTest(com.nokia.openlcdui.mt.graphics.DirectGraphicsTest.suite()); |
|
188 addTest(com.nokia.openlcdui.mt.graphics.GraphicsTest.suite()); |
|
189 addTest(com.nokia.openlcdui.mt.graphics.CommandBufferingTest.suite()); |
|
190 addTest(com.nokia.openlcdui.mt.image.ImageTest.suite()); |
|
191 addTest(com.nokia.openlcdui.mt.imageitem.ImageItemTest.suite()); |
|
192 addTest(com.nokia.openlcdui.mt.item.ItemTest.suite()); |
|
193 addTest(com.nokia.openlcdui.mt.list.ListTest.suite()); |
|
194 addTest(com.nokia.openlcdui.mt.spacer.SpacerTest.suite()); |
|
195 addTest(com.nokia.openlcdui.mt.stringitem.StringItemTest.suite()); |
|
196 addTest(com.nokia.openlcdui.mt.textbox.TextBoxTest.suite()); |
|
197 addTest(com.nokia.openlcdui.mt.textfield.TextFieldTest.suite()); |
|
198 addTest(com.nokia.openlcdui.mt.ticker.TickerTest.suite()); |
|
199 addTest(com.nokia.openlcdui.mt.devicecontrol.DeviceControlTest.suite()); |
|
200 if(enableUIRobotTests) |
|
201 { |
|
202 addTest(com.nokia.openlcdui.mt_uirobot.alert.AlertUITest.suite()); |
|
203 addTest(com.nokia.openlcdui.mt_uirobot.choicegroup.ChoiceGroupCommandTest.suite()); |
|
204 addTest(com.nokia.openlcdui.mt_uirobot.choicegroup.ChoiceGroupPopupTest.suite()); |
|
205 addTest(com.nokia.openlcdui.mt_uirobot.command.DynamicUpdateTest.suite()); |
|
206 addTest(com.nokia.openlcdui.mt_uirobot.command.ItemCommandUIRobotTest.suite()); |
|
207 addTest(com.nokia.openlcdui.mt_uirobot.customitem.CustomItemTest.suite()); |
|
208 addTest(com.nokia.openlcdui.mt_uirobot.datefield.DateFieldUIRobotTest.suite()); |
|
209 addTest(com.nokia.openlcdui.mt_uirobot.display.FlashAndVibrateTest.suite()); |
|
210 addTest(com.nokia.openlcdui.mt_uirobot.display.SetCurrentItemTest.suite()); |
|
211 addTest(com.nokia.openlcdui.mt_uirobot.displayable.AddCommandTest.suite()); |
|
212 addTest(com.nokia.openlcdui.mt_uirobot.displayable.SendBackgroundTest.suite()); |
|
213 addTest(com.nokia.openlcdui.mt_uirobot.displayable.SizeChangedTest.suite()); |
|
214 addTest(com.nokia.openlcdui.mt_uirobot.form.FormItemTest.suite()); |
|
215 addTest(com.nokia.openlcdui.mt_uirobot.gauge.GaugeCommandsTest.suite()); |
|
216 addTest(com.nokia.openlcdui.mt_uirobot.imageitem.ImageItemHyperLinkTest.suite()); |
|
217 addTest(com.nokia.openlcdui.mt_uirobot.item.ItemUITest.suite()); |
|
218 addTest(com.nokia.openlcdui.mt_uirobot.list.ListUITest.suite()); |
|
219 addTest(com.nokia.openlcdui.mt_uirobot.spacer.SpacerTest.suite()); |
|
220 addTest(com.nokia.openlcdui.mt_uirobot.stringitem.HyperLinkTest.suite()); |
|
221 addTest(com.nokia.openlcdui.mt_uirobot.stringitem.StringItemUIRobotTest.suite()); |
|
222 addTest(com.nokia.openlcdui.mt_uirobot.textbox.TestUITextBox.suite()); |
|
223 addTest(com.nokia.openlcdui.mt_uirobot.textbox.TextBoxInputModeUITest.suite()); |
|
224 addTest(com.nokia.openlcdui.mt_uirobot.textfield.FormChangeFocusCheckTest.suite()); |
|
225 addTest(com.nokia.openlcdui.mt_uirobot.textfield.TextFieldCommandTest.suite()); |
|
226 addTest(com.nokia.openlcdui.mt_uirobot.textfield.TextFieldSetInitialInputModeTest.suite()); |
|
227 } |
|
228 |
|
229 |
|
230 // If tests are executed by some runner as a suite then it won't clean up the UI |
|
231 // before it let's the thread to terminate. This is executed as the last test |
|
232 // to clean up in the UI thread before it exits. |
|
233 /*if(!runningMain) { |
|
234 addTest(new TestCase() { |
|
235 protected void runTest() throws Throwable { |
|
236 Display display = Display.getCurrent(); |
|
237 if(display != null) display.dispose(); |
|
238 } |
|
239 public String getName() { |
|
240 return "CleanUpQtBeforeGUIThreadExits"; |
|
241 } |
|
242 }); |
|
243 }*/ |
|
244 // If some tests were disabled then generate a warning about them. |
|
245 if(disabledTests != null) |
|
246 { |
|
247 addTest(new TestCase() |
|
248 { |
|
249 protected void runTest() throws Throwable |
|
250 { |
|
251 if(!disabledTests.isEmpty()) |
|
252 { |
|
253 String list = new String(); |
|
254 list += "Warning: There are " + disabledTests.size() + " disabled tests that were marked as passing: \r\n"; |
|
255 for(int i = 0; i < disabledTests.size(); ++i) |
|
256 { |
|
257 list += disabledTests.elementAt(i); |
|
258 list += "\r\n"; |
|
259 } |
|
260 throw new Exception(list); |
|
261 } |
|
262 } |
|
263 public String getName() |
|
264 { |
|
265 return "DisabledTestsCheck"; |
|
266 } |
|
267 }); |
|
268 } |
|
269 } |
|
270 } |
|
271 |