git clone of logicmail with some fixes/features added
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Minor code cleanup and addition of test tree icons

git-svn-id: https://logicmail.svn.sourceforge.net/svnroot/logicmail/trunk@621 5c734088-3d25-0410-9155-b3c3832efda5

octorian 70aba48b 4a227677

+170 -86
J2MEUnit/res/icons/test_failed.png

This is a binary file and will not be displayed.

J2MEUnit/res/icons/test_initial.png

This is a binary file and will not be displayed.

J2MEUnit/res/icons/test_passed.png

This is a binary file and will not be displayed.

+116 -76
J2MEUnit/src/j2meunit/rimui/TestConsoleScreen.java
··· 1 - /* 2 - * TestConsoleScreen.java 1 + /*- 2 + * Copyright (c) 2010, Derek Konigsberg 3 + * All rights reserved. 3 4 * 4 - * Created on February 2, 2007, 10:11 PM 5 + * Redistribution and use in source and binary forms, with or without 6 + * modification, are permitted provided that the following conditions 7 + * are met: 5 8 * 6 - * To change this template, choose Tools | Template Manager 7 - * and open the template in the editor. 9 + * 1. Redistributions of source code must retain the above copyright 10 + * notice, this list of conditions and the following disclaimer. 11 + * 2. Redistributions in binary form must reproduce the above copyright 12 + * notice, this list of conditions and the following disclaimer in the 13 + * documentation and/or other materials provided with the distribution. 14 + * 3. Neither the name of the project nor the names of its 15 + * contributors may be used to endorse or promote products derived 16 + * from this software without specific prior written permission. 17 + * 18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 27 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 + * OF THE POSSIBILITY OF SUCH DAMAGE. 8 30 */ 9 31 10 32 package j2meunit.rimui; ··· 19 41 import java.util.Enumeration; 20 42 import java.util.Hashtable; 21 43 import java.util.Vector; 44 + 45 + import net.rim.device.api.system.Bitmap; 22 46 import net.rim.device.api.system.Characters; 23 47 import net.rim.device.api.ui.Field; 24 48 import net.rim.device.api.ui.Font; ··· 34 58 import net.rim.device.api.ui.container.MainScreen; 35 59 36 60 /** 37 - * 61 + * J2MEUnit Test Console Screen for the BlackBerry UI. 62 + * 38 63 * @author Derek Konigsberg 39 64 */ 40 - public class TestConsoleScreen extends MainScreen implements TreeFieldCallback, TestListener { 41 - private LabelField titleLabel; 65 + public class TestConsoleScreen extends MainScreen implements TestListener { 66 + private LabelField titleLabel; 42 67 private LabelField statusLabel; 43 68 private LabelField failureLabel; 44 69 private LabelField errorLabel; ··· 51 76 private TestResult testResults; 52 77 private Test selectedTest; 53 78 private long elapsedTime; 54 - 79 + 80 + private Bitmap testInitialBitmap = Bitmap.getBitmapResource("test_initial.png"); 81 + private Bitmap testPassedBitmap = Bitmap.getBitmapResource("test_passed.png"); 82 + private Bitmap testFailedBitmap = Bitmap.getBitmapResource("test_failed.png"); 83 + 55 84 private static class TestTreeItem { 56 85 public TestTreeItem(Test test) { 57 86 this.test = test; 58 - if(test instanceof TestCase) 87 + if(test instanceof TestCase) { 59 88 name = ((TestCase)test).getName(); 60 - else if(test instanceof TestSuite) 89 + } 90 + else if(test instanceof TestSuite) { 61 91 name = ((TestSuite)test).toString(); 62 - else 92 + } 93 + else { 63 94 name = "Test"; 95 + } 64 96 this.hasRun = false; 65 97 this.hasPassed = true; 66 98 this.id = 0; ··· 71 103 public boolean hasPassed; 72 104 public int id; 73 105 } 74 - 106 + 75 107 /** 76 108 * Creates a new instance of TestConsoleScreen 77 109 */ ··· 82 114 elapsedTime = -1; 83 115 populateTestTree(mainTestSuite, 0); 84 116 } 85 - 117 + 86 118 private void initializeFields() { 87 - Font labelFont = Font.getDefault().derive(Font.PLAIN, 12); 119 + Font labelFont = Font.getDefault().derive(Font.PLAIN, 12); 88 120 Font treeFont = Font.getDefault().derive(Font.PLAIN, 14); 89 - 90 - titleLabel = new LabelField("J2MEUnit " + j2meunit.util.Version.id()); 91 - titleLabel.setFont(labelFont); 121 + 122 + titleLabel = new LabelField("J2MEUnit " + j2meunit.util.Version.id()); 123 + titleLabel.setFont(labelFont); 92 124 statusLabel = new LabelField("Status: Idle"); 93 125 statusLabel.setFont(labelFont); 94 126 failureLabel = new LabelField("Failures: 0"); ··· 99 131 timeLabel.setFont(labelFont); 100 132 progressGauge = new GaugeField(null, 0, 100, 0, GaugeField.NO_TEXT); 101 133 progressGauge.setFont(labelFont); 102 - 103 - testTreeField = new TreeField(this, Field.FOCUSABLE); 134 + 135 + testTreeField = new TreeField(new TreeFieldCallback() { 136 + public void drawTreeItem(TreeField treeField, Graphics graphics, int node, int y, int width, int indent) { 137 + testTreeField_DrawTreeItem(treeField, graphics, node, y, width, indent); 138 + } 139 + }, Field.FOCUSABLE); 104 140 testTreeField.setEmptyString("No tests", 0); 105 141 testTreeField.setDefaultExpanded(true); 106 142 testTreeField.setIndentWidth(20); 107 143 testTreeField.setFont(treeFont); 108 144 testTreeField.setRowHeight(treeFont.getHeight() + 2); 109 - 145 + 110 146 add(titleLabel); 111 147 add(statusLabel); 112 148 add(failureLabel); ··· 116 152 add(new SeparatorField()); 117 153 add(testTreeField); 118 154 } 119 - 155 + 120 156 private void populateTestTree(TestSuite suite, int parentId) { 121 157 // Get the tests 122 158 Vector tests = new Vector(); 123 159 for(Enumeration e = suite.tests(); e.hasMoreElements(); ) { 124 160 tests.addElement(e.nextElement()); 125 161 } 126 - 162 + 127 163 // Iterate backwards so the tree is populated in the correct order 128 164 int size = tests.size(); 129 165 for(int i = size - 1; i >= 0; i--) { ··· 137 173 } 138 174 } 139 175 } 140 - 176 + 141 177 /** Standard Escape-key handler */ 142 178 public boolean keyChar(char key, int status, int time) { 143 179 boolean retval = false; 144 180 switch (key) { 145 - case Characters.ESCAPE: 146 - System.exit(1); 147 - break; 148 - default: 149 - retval = super.keyChar(key, status, time); 181 + case Characters.ESCAPE: 182 + System.exit(1); 183 + break; 184 + default: 185 + retval = super.keyChar(key, status, time); 150 186 } 151 187 return retval; 152 188 } 153 - 154 - public void drawTreeItem(TreeField treeField, Graphics graphics, int node, int y, int width, int indent) { 189 + 190 + private void testTreeField_DrawTreeItem(TreeField treeField, Graphics graphics, int node, int y, int width, int indent) { 155 191 Object cookie = testTreeField.getCookie(node); 156 - 192 + 157 193 if(cookie instanceof TestTreeItem) { 158 194 TestTreeItem item = (TestTreeItem)cookie; 159 195 int height = testTreeField.getRowHeight(); 160 - 161 - int oldColor = graphics.getColor(); 162 - 163 - if(item.hasRun) { 164 - if(item.hasPassed) 165 - graphics.setColor(0x0000FF00); // green 166 - else 167 - graphics.setColor(0x00FF0000); // red 168 - } else 169 - graphics.setColor(0x00C0C0C0); // grey 170 - 171 - graphics.fillArc(indent, y+1, height-2, height-2, 0, 360); 172 - graphics.setColor(oldColor); 196 + 197 + Bitmap iconBitmap = getItemIcon(item); 173 198 174 - graphics.drawText(item.name, indent + height, y, Graphics.ELLIPSIS, width); 199 + graphics.drawBitmap(indent, y, 16, 16, iconBitmap, 0, 0); 200 + 201 + graphics.drawText(item.name, indent + height + 2, y, Graphics.ELLIPSIS, width - height - 2); 175 202 } 176 203 } 177 - 178 - private MenuItem resultsItem = new MenuItem("View results", 100000, 10) { 204 + 205 + private Bitmap getItemIcon(TestTreeItem item) { 206 + Bitmap iconBitmap; 207 + if(item.hasRun) { 208 + if(item.hasPassed) { 209 + iconBitmap = testPassedBitmap; 210 + } 211 + else { 212 + iconBitmap = testFailedBitmap; 213 + } 214 + } 215 + else { 216 + iconBitmap = testInitialBitmap; 217 + } 218 + return iconBitmap; 219 + } 220 + 221 + private MenuItem resultsItem = new MenuItem("View results", 300100, 1010) { 179 222 public void run() { 180 223 showTestResults(); 181 224 } 182 225 }; 183 - private MenuItem runAllItem = new MenuItem("Run all", 100010, 10) { 226 + private MenuItem runAllItem = new MenuItem("Run all", 400110, 1020) { 184 227 public void run() { 185 228 runAllTests(); 186 229 } 187 230 }; 188 - private MenuItem runSelectedItem = new MenuItem("Run selected", 100020, 10) { 231 + private MenuItem runSelectedItem = new MenuItem("Run selected", 400120, 1030) { 189 232 public void run() { 190 233 runSelectedTests(); 191 234 } 192 235 }; 193 - private MenuItem exitItem = new MenuItem("Exit", 200001, 10) { 236 + private MenuItem exitItem = new MenuItem("Exit", 60000100, 9000) { 194 237 public void run() { 195 238 System.exit(0); 196 239 } ··· 201 244 if(node > 0) { 202 245 TestTreeItem item = (TestTreeItem)testTreeField.getCookie(node); 203 246 if(item.hasRun && item.test instanceof TestCase) { 204 - menu.addSeparator(); 205 247 menu.add(resultsItem); 206 248 } 207 249 } 208 - menu.addSeparator(); 209 250 menu.add(runAllItem); 210 251 menu.add(runSelectedItem); 211 - menu.addSeparator(); 212 252 menu.add(exitItem); 213 253 } 214 254 ··· 217 257 errorLabel.setText("Errors: " + testResults.errorCount()); 218 258 } 219 259 } 220 - 260 + 221 261 public synchronized void addFailure(Test test, AssertionFailedError assertionFailedError) { 222 262 synchronized(UiApplication.getEventLock()) { 223 263 failureLabel.setText("Failures: " + testResults.failureCount()); 224 264 } 225 265 } 226 - 266 + 227 267 public void endTest(Test test) { 228 268 synchronized(UiApplication.getEventLock()) { 229 269 progressGauge.setValue(progressGauge.getValue() + 1); ··· 232 272 updateTestBranch(test); 233 273 updateTestTree(); 234 274 } 235 - 275 + 236 276 public void endTestStep(Test test) { 237 277 synchronized(UiApplication.getEventLock()) { 238 278 progressGauge.setValue(progressGauge.getValue() + 1); ··· 241 281 updateTestBranch(test); 242 282 updateTestTree(); 243 283 } 244 - 284 + 245 285 public synchronized void startTest(Test test) { 246 286 TestTreeItem item = (TestTreeItem)testTreeItems.get(test.toString()); 247 287 item.hasRun = true; ··· 265 305 item = (TestTreeItem)testTreeField.getCookie(parentId); 266 306 item.hasRun = hasAllRun; 267 307 item.hasPassed = hasAllPassed; 268 - 308 + 269 309 if(testTreeField.getParent(item.id) >= 0) { 270 310 updateTestBranch(item.test); 271 311 } 272 312 } 273 - 313 + 274 314 private void updateTreeErrors() { 275 315 // Update the test data structures 276 316 TestTreeItem item; ··· 287 327 item.hasPassed = false; 288 328 } 289 329 } 290 - 330 + 291 331 private synchronized void updateTestTree() { 292 332 // Repaint the tree 293 333 UiApplication.getUiApplication().invokeAndWait(new Runnable() { ··· 305 345 TestTreeItem item = (TestTreeItem)testTreeField.getCookie(node); 306 346 if(!(item.test instanceof TestCase)) return; 307 347 TestCase testCase = (TestCase)item.test; 308 - 348 + 309 349 Enumeration e; 310 350 TestFailure testFailure = null; 311 351 TestFailure testError = null; 312 - 352 + 313 353 for(e = testResults.failures(); e.hasMoreElements(); ) { 314 354 TestFailure failure = (TestFailure)e.nextElement(); 315 355 if(failure.failedTest() == testCase) { ··· 317 357 break; 318 358 } 319 359 } 320 - 360 + 321 361 for(e = testResults.errors(); e.hasMoreElements(); ) { 322 362 TestFailure error = (TestFailure)e.nextElement(); 323 363 if(error.failedTest() == testCase) { ··· 325 365 break; 326 366 } 327 367 } 328 - 368 + 329 369 UiApplication.getUiApplication().pushModalScreen( 330 370 new TestResultsScreen(testCase, testFailure, testError)); 331 371 } 332 - 372 + 333 373 /** 334 374 * Builds a test suite from all test case classes in a string array. 335 375 * ··· 341 381 if (testCaseClasses.length < 1) { 342 382 return testSuite; 343 383 } 344 - 384 + 345 385 for (int i = 0; i < testCaseClasses.length; i++) { 346 386 try { 347 387 String className = testCaseClasses[i]; ··· 350 390 testSuite.addTest(testCase.suite()); 351 391 } catch (Throwable t) { 352 392 System.out.println("Access to TestCase " + testCaseClasses[i] + 353 - " failed: " + t.getMessage() + " - " + 354 - t.getClass().getName()); 393 + " failed: " + t.getMessage() + " - " + 394 + t.getClass().getName()); 355 395 } 356 396 } 357 - 397 + 358 398 return testSuite; 359 399 } 360 - 400 + 361 401 /** 362 402 * Run all tests in the given test suite. 363 403 * ··· 366 406 protected void doRun(Test suite) { 367 407 testResults = new TestResult(); 368 408 testResults.addListener(this); 369 - 409 + 370 410 long startTime = System.currentTimeMillis(); 371 411 372 412 // Mark the suite's tree item ··· 376 416 377 417 // Run the suite 378 418 suite.run(testResults); 379 - 419 + 380 420 long endTime = System.currentTimeMillis(); 381 421 elapsedTime = endTime - startTime; 382 422 } ··· 385 425 selectedTest = mainTestSuite; 386 426 runTests(); 387 427 } 388 - 428 + 389 429 private void runSelectedTests() { 390 430 int nodeId = testTreeField.getCurrentNode(); 391 431 if(nodeId == -1) return; ··· 398 438 progressGauge.reset(null, 0, selectedTest.countTestCases(), 0); 399 439 new Thread() { 400 440 public void run() { 401 - Thread.yield(); 441 + Thread.yield(); 402 442 try { 403 443 doRun(selectedTest); 404 444 updateResults(); ··· 409 449 } 410 450 }.start(); 411 451 } 412 - 452 + 413 453 private synchronized void updateResults() { 414 454 UiApplication.getUiApplication().invokeAndWait(new Runnable() { 415 455 public void run() {
+27 -5
J2MEUnit/src/j2meunit/rimui/TestResultsScreen.java
··· 1 - /* 2 - * TestResultsScreen.java 1 + /*- 2 + * Copyright (c) 2010, Derek Konigsberg 3 + * All rights reserved. 3 4 * 4 - * Created on February 4, 2007, 2:27 PM 5 + * Redistribution and use in source and binary forms, with or without 6 + * modification, are permitted provided that the following conditions 7 + * are met: 5 8 * 6 - * To change this template, choose Tools | Template Manager 7 - * and open the template in the editor. 9 + * 1. Redistributions of source code must retain the above copyright 10 + * notice, this list of conditions and the following disclaimer. 11 + * 2. Redistributions in binary form must reproduce the above copyright 12 + * notice, this list of conditions and the following disclaimer in the 13 + * documentation and/or other materials provided with the distribution. 14 + * 3. Neither the name of the project nor the names of its 15 + * contributors may be used to endorse or promote products derived 16 + * from this software without specific prior written permission. 17 + * 18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 27 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 + * OF THE POSSIBILITY OF SUCH DAMAGE. 8 30 */ 9 31 10 32 package j2meunit.rimui;
+27 -5
J2MEUnit/src/j2meunit/rimui/TestRunner.java
··· 1 - /* 2 - * TestRunner.java 1 + /*- 2 + * Copyright (c) 2010, Derek Konigsberg 3 + * All rights reserved. 3 4 * 4 - * Created on February 2, 2007, 10:03 PM 5 + * Redistribution and use in source and binary forms, with or without 6 + * modification, are permitted provided that the following conditions 7 + * are met: 5 8 * 6 - * To change this template, choose Tools | Template Manager 7 - * and open the template in the editor. 9 + * 1. Redistributions of source code must retain the above copyright 10 + * notice, this list of conditions and the following disclaimer. 11 + * 2. Redistributions in binary form must reproduce the above copyright 12 + * notice, this list of conditions and the following disclaimer in the 13 + * documentation and/or other materials provided with the distribution. 14 + * 3. Neither the name of the project nor the names of its 15 + * contributors may be used to endorse or promote products derived 16 + * from this software without specific prior written permission. 17 + * 18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 27 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 + * OF THE POSSIBILITY OF SUCH DAMAGE. 8 30 */ 9 31 10 32 package j2meunit.rimui;