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