67
|
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 |
t2.printStackTrace();
|
|
157 |
assertTrue(t2.toString(), false);
|
|
158 |
}
|
|
159 |
}
|
|
160 |
|
|
161 |
private void normalTests()
|
|
162 |
{
|
|
163 |
// Set the com.nokia.coreui property to point valid class.
|
|
164 |
System.out.println("normalTests");
|
|
165 |
try
|
|
166 |
{
|
|
167 |
JvmInternal.setSystemProperty("com.nokia.coreui", "coreuitest");
|
|
168 |
boolean res = CoreUi.connectToUi();
|
|
169 |
assertTrue("Fail1, got: "+ res, res);
|
|
170 |
|
|
171 |
// Set a null value to UID and check that an exception is thrown.
|
|
172 |
try
|
|
173 |
{
|
|
174 |
CoreUi.createUi(null, false);
|
|
175 |
assertTrue("No exception.", false);
|
|
176 |
}
|
|
177 |
catch (NullPointerException ne)
|
|
178 |
{
|
|
179 |
}
|
|
180 |
|
|
181 |
Uid uid = Uid.createUid("[12345678]");
|
|
182 |
CoreUi.createUi(uid, true);
|
|
183 |
CoreUiImpl.createUiImplCheck(uid, true);
|
|
184 |
CoreUi.createUi(uid, false);
|
|
185 |
CoreUiImpl.createUiImplCheck(uid, false);
|
|
186 |
|
|
187 |
CoreUi.shutdownRequest();
|
|
188 |
|
|
189 |
CoreUi.foregroundRequest();
|
|
190 |
|
|
191 |
res = CoreUi.isUiInForeground();
|
|
192 |
assertTrue("Fail2, got: "+ res, res);
|
|
193 |
|
|
194 |
CoreUi.hideApplication(true);
|
|
195 |
CoreUiImpl.hideApplicationImplCheck(true);
|
|
196 |
CoreUi.hideApplication(false);
|
|
197 |
CoreUiImpl.hideApplicationImplCheck(false);
|
|
198 |
|
|
199 |
CoreUiImpl.checkCounters(new int[] {1,2,1,1,1,2});
|
|
200 |
}
|
|
201 |
catch (Throwable t)
|
|
202 |
{
|
|
203 |
t.printStackTrace();
|
|
204 |
assertTrue(t.toString(), false);
|
|
205 |
}
|
|
206 |
|
|
207 |
}
|
|
208 |
|
|
209 |
}
|
|
210 |
|
|
211 |
|
|
212 |
|