javauis/runtimeui_qt/tsrc.s60/javasrc/com/nokia/mj/impl/rt/ui/qt/RuntimeUiQtTests.java
changeset 21 2a9601315dfc
child 47 f40128debb5d
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2008 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 
       
    18 
       
    19 package com.nokia.mj.impl.rt.ui.qt;
       
    20 
       
    21 import com.nokia.mj.impl.installer.utils.InstallerMain;
       
    22 import com.nokia.mj.impl.utils.exception.ExceptionBase;
       
    23 import com.nokia.mj.impl.rt.ui.qt.RuntimeUiQt;
       
    24 import com.nokia.mj.impl.rt.ui.RuntimeUi;
       
    25 import com.nokia.mj.impl.rt.ui.ConfirmData;
       
    26 
       
    27 import j2meunit.framework.Test;
       
    28 import j2meunit.framework.TestCase;
       
    29 import j2meunit.framework.TestMethod;
       
    30 import j2meunit.framework.TestSuite;
       
    31 
       
    32 /**
       
    33  * RuntimeUiQt unit tests.
       
    34  */
       
    35 public class RuntimeUiQtTests extends TestCase implements InstallerMain
       
    36 {
       
    37 
       
    38     // Begin j2meunit test framework setup
       
    39     public void installerMain(String[] args)
       
    40     {
       
    41         TestSuite suite = new TestSuite(this.getClass().getName());
       
    42 
       
    43         suite.addTest(new RuntimeUiQtTests("testQt", new TestMethod()
       
    44         {
       
    45             public void run(TestCase tc)
       
    46             {
       
    47                 ((RuntimeUiQtTests)tc).testQt();
       
    48             }
       
    49         }));
       
    50 
       
    51         com.nokia.mj.impl.utils.OmjTestRunner.run(suite);
       
    52     }
       
    53 
       
    54     public RuntimeUiQtTests()
       
    55     {
       
    56     }
       
    57 
       
    58     public RuntimeUiQtTests(String aTestName, TestMethod aTestMethod)
       
    59     {
       
    60         super(aTestName, aTestMethod);
       
    61     }
       
    62 
       
    63     public void assertFalse(String aMsg, boolean aCondition)
       
    64     {
       
    65         assertTrue(aMsg, !aCondition);
       
    66     }
       
    67 
       
    68     // End j2meunit test framework setup
       
    69 
       
    70     protected void setUp()
       
    71     {
       
    72     }
       
    73 
       
    74     protected void tearDown()
       
    75     {
       
    76     }
       
    77 
       
    78     private void testQt()
       
    79     {
       
    80         doTest(new RuntimeUiQt());
       
    81     }
       
    82 
       
    83     private void doTest(RuntimeUi runtimeUi)
       
    84     {
       
    85         System.out.println("+doTest()");
       
    86         // error message with details -> make sure both are available to the user
       
    87         ExceptionBase exc = new ExceptionBase(
       
    88             new ShortErrorMessage(),
       
    89             ShortErrorMessage.MSG_WITH_DETAILS_ID,
       
    90             null, /* no params for short msg */
       
    91             new DetailedErrorMessage(),
       
    92             DetailedErrorMessage.MSG_ID,
       
    93             null /* no params for detailed msg */);
       
    94 
       
    95 
       
    96         runtimeUi.error("MyApplication", exc);
       
    97 
       
    98         // error message with short description only
       
    99         exc = new ExceptionBase(
       
   100             new ShortErrorMessage(),
       
   101             ShortErrorMessage.MSG_WITHOUT_DETAILS_ID,
       
   102             null, /* no params for short msg */
       
   103             null,
       
   104             0,
       
   105             null /* no params for detailed msg */);
       
   106         System.out.println("3");
       
   107 
       
   108         runtimeUi.error("MyApplication", exc);
       
   109 
       
   110         // Test no crash happen.
       
   111         runtimeUi.error("NullException", null);
       
   112 
       
   113 
       
   114         boolean answerAvailable = false;
       
   115 
       
   116         // Test confirm
       
   117         ConfirmData confirmData = new ConfirmData("Confirm dialog. Select Allow", new String[] {"answerOpt1", "answerOpt2", "answerOption3"}, 1);
       
   118         answerAvailable = runtimeUi.confirm("MyFavouriteAplication", confirmData);
       
   119         assertTrue(answerAvailable && confirmData.getAnswer() == 1);
       
   120 
       
   121         confirmData = new ConfirmData("Confirm dialog. Select Deny", new String[] {"answerOpt1", "answerOpt2", "answerOption3"}, 1);
       
   122         answerAvailable = runtimeUi.confirm("MyFavouriteAplication", confirmData);
       
   123         assertTrue(answerAvailable && confirmData.getAnswer() == 0);
       
   124 
       
   125         confirmData = new ConfirmData("Null Answer options", null /*Not Supported*/, 1);
       
   126         answerAvailable = runtimeUi.confirm("Null answer options", confirmData);
       
   127         assertTrue(answerAvailable);
       
   128 
       
   129         ConfirmData nullConf = null;
       
   130         runtimeUi.confirm("Null Application", nullConf);
       
   131 
       
   132         runtimeUi.destroy();
       
   133         System.out.println("-doTest()");
       
   134     }
       
   135 }