javauis/coreui/tsrc/testcoreui/javasrc/com/nokia/mj/impl/coreuitest/CoreUiTests.java
branchRCL_3
changeset 77 7cee158cb8cd
child 72 1f0034e370aa
equal deleted inserted replaced
71:d5e927d5853b 77:7cee158cb8cd
       
     1 /*
       
     2 * Copyright (c) 2010 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.coreuitest;
       
    20 
       
    21 
       
    22 import com.nokia.mj.impl.coreui.CoreUi;
       
    23 import com.nokia.mj.impl.coreuitest.CoreUiImpl;
       
    24 import com.nokia.mj.impl.rt.support.JvmInternal;
       
    25 import com.nokia.mj.impl.utils.Uid;
       
    26 
       
    27 
       
    28 import com.nokia.mj.impl.rt.test.UnitTestSuiteCreator;
       
    29 import j2meunit.framework.Test;
       
    30 import j2meunit.framework.TestCase;
       
    31 import j2meunit.framework.TestMethod;
       
    32 import j2meunit.framework.TestSuite;
       
    33 
       
    34 /**
       
    35  * SystemProperty unit tests.
       
    36  */
       
    37 public class CoreUiTests extends TestCase implements UnitTestSuiteCreator
       
    38 {
       
    39     // Begin j2meunit test framework setup
       
    40     public TestSuite createTestSuite(String[] args)
       
    41     {
       
    42         TestSuite suite = new TestSuite(this.getClass().getName());
       
    43         String testSelector = "0000000000000000";
       
    44         if (args.length > 1 && args[1] != null)
       
    45         {
       
    46             testSelector = args[1]  + "0000000000000000";
       
    47         }
       
    48 
       
    49         if (testSelector.charAt(0) != '0')
       
    50         {
       
    51             suite.addTest(new CoreUiTests("AbNormalTests", new TestMethod()
       
    52             {
       
    53                 public void run(TestCase tc)
       
    54                 {
       
    55                     ((CoreUiTests)tc).abNormalTests();
       
    56                 }
       
    57             }));
       
    58         }
       
    59 
       
    60         if (testSelector.charAt(1) != '0')
       
    61         {
       
    62             suite.addTest(new CoreUiTests("AbNormalTests2", new TestMethod()
       
    63             {
       
    64                 public void run(TestCase tc)
       
    65                 {
       
    66                     ((CoreUiTests)tc).abNormalTests2();
       
    67                 }
       
    68             }));
       
    69         }
       
    70 
       
    71         if (testSelector.charAt(2) != '0')
       
    72         {
       
    73             suite.addTest(new CoreUiTests("NormalTests", new TestMethod()
       
    74             {
       
    75                 public void run(TestCase tc)
       
    76                 {
       
    77                     ((CoreUiTests)tc).normalTests();
       
    78                 }
       
    79             }));
       
    80         }
       
    81 
       
    82         return suite;
       
    83 
       
    84     }
       
    85 
       
    86     public CoreUiTests()
       
    87     {
       
    88     }
       
    89 
       
    90     public CoreUiTests(String aTestName, TestMethod aTestMethod)
       
    91     {
       
    92         super(aTestName, aTestMethod);
       
    93     }
       
    94 
       
    95     // End j2meunit test framework setup
       
    96 
       
    97     protected void setUp()
       
    98     {
       
    99     }
       
   100 
       
   101     protected void tearDown()
       
   102     {
       
   103     }
       
   104 
       
   105     // Test cases
       
   106 
       
   107     private void abNormalTests()
       
   108     {
       
   109         System.out.println("abNormalTests");
       
   110         // Don't set the com.nokia.coreui property yet.
       
   111         try
       
   112         {
       
   113             boolean res = CoreUi.connectToUi();
       
   114             assertTrue("Fail1, got: "+ res, res);
       
   115             CoreUi.createUi(null, false);
       
   116 
       
   117             CoreUi.createUi(null, false);
       
   118             CoreUi.shutdownRequest();
       
   119             CoreUi.foregroundRequest();
       
   120 
       
   121             res = CoreUi.isUiInForeground();
       
   122             assertTrue("Fail2, got: "+ res, res);
       
   123             CoreUi.hideApplication(false);
       
   124         }
       
   125         catch (Throwable t)
       
   126         {
       
   127             t.printStackTrace();
       
   128             assertTrue(t.toString(), false);
       
   129         }
       
   130     }
       
   131 
       
   132 
       
   133     private void abNormalTests2()
       
   134     {
       
   135         System.out.println("abNormalTests2");
       
   136         // Set the com.nokia.coreui property to point nonexisitng class.
       
   137         try
       
   138         {
       
   139             JvmInternal.setSystemProperty("com.nokia.coreui", "nonvalid");
       
   140             boolean res = CoreUi.connectToUi();
       
   141             assertTrue("No exception.", false);
       
   142         }
       
   143         catch (Error re)
       
   144         {
       
   145             int ind = re.toString().indexOf("Not able to instantiate class com.nokia.mj.impl.nonvalid.CoreUiImpl");
       
   146             boolean ok = ind >= 0;
       
   147             if (!ok)
       
   148             {
       
   149                 // Accept also java.lang.ExceptionInInitializerError.
       
   150                 ok = re.toString().equals("java.lang.ExceptionInInitializerError");
       
   151             }
       
   152             assertTrue(re.toString(),  ok);
       
   153         }
       
   154         catch (Throwable t2)
       
   155         {
       
   156             System.out.println("JOU2 "+ t2);
       
   157             t2.printStackTrace();
       
   158             assertTrue(t2.toString(), false);
       
   159         }
       
   160     }
       
   161 
       
   162     private void normalTests()
       
   163     {
       
   164         // Set the com.nokia.coreui property to point valid class.
       
   165         System.out.println("normalTests");
       
   166         try
       
   167         {
       
   168             JvmInternal.setSystemProperty("com.nokia.coreui", "coreuitest");
       
   169             boolean res = CoreUi.connectToUi();
       
   170             assertTrue("Fail1, got: "+ res, res);
       
   171 
       
   172             // Set a null value to UID and check that an exception is thrown.
       
   173             try
       
   174             {
       
   175                 CoreUi.createUi(null, false);
       
   176                 assertTrue("No exception.", false);
       
   177             }
       
   178             catch (NullPointerException ne)
       
   179             {
       
   180             }
       
   181 
       
   182             Uid uid = Uid.createUid("[12345678]");
       
   183             CoreUi.createUi(uid, true);
       
   184             CoreUiImpl.createUiImplCheck(uid, true);
       
   185             CoreUi.createUi(uid, false);
       
   186             CoreUiImpl.createUiImplCheck(uid, false);
       
   187 
       
   188             CoreUi.shutdownRequest();
       
   189 
       
   190             CoreUi.foregroundRequest();
       
   191 
       
   192             res = CoreUi.isUiInForeground();
       
   193             assertTrue("Fail2, got: "+ res, res);
       
   194 
       
   195             CoreUi.hideApplication(true);
       
   196             CoreUiImpl.hideApplicationImplCheck(true);
       
   197             CoreUi.hideApplication(false);
       
   198             CoreUiImpl.hideApplicationImplCheck(false);
       
   199 
       
   200             CoreUiImpl.checkCounters(new int[] {1,2,1,1,1,2});
       
   201         }
       
   202         catch (Throwable t)
       
   203         {
       
   204             t.printStackTrace();
       
   205             assertTrue(t.toString(), false);
       
   206         }
       
   207 
       
   208     }
       
   209 
       
   210 }
       
   211 
       
   212 
       
   213