|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 //This test will be able to do what it is planned to do only if the shutdown client and server |
|
17 //components are built with SYSLIBS_TEST macro defined. |
|
18 #include <e32test.h> //RTest |
|
19 #include <e32svr.h> //RDebug |
|
20 #include <savenotf.h> //RSaveSession, MSaveObserver, CSaveNotifier |
|
21 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
22 #include <shutdownsrv.h> //CServShutdownServer |
|
23 #else //SYMBIAN_ENABLE_SPLIT_HEADERS |
|
24 #include "shutdownsess.h" //CServShutdownServer |
|
25 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS |
|
26 |
|
27 |
|
28 static RTest TheTest(_L("t_pwroffevents")); |
|
29 |
|
30 // |
|
31 // |
|
32 //Test macroses and functions |
|
33 static void Check(TInt aValue, TInt aLine) |
|
34 { |
|
35 if(!aValue) |
|
36 { |
|
37 TheTest(EFalse, aLine); |
|
38 } |
|
39 } |
|
40 static void Check(TInt aValue, TInt aExpected, TInt aLine) |
|
41 { |
|
42 if(aValue != aExpected) |
|
43 { |
|
44 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
|
45 TheTest(EFalse, aLine); |
|
46 } |
|
47 } |
|
48 #define TEST(arg) ::Check((arg), __LINE__) |
|
49 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) |
|
50 |
|
51 // |
|
52 //Test classes & objects |
|
53 |
|
54 // Stub Power API implementation |
|
55 static TPowerState iCurrentState = EPwLimit; |
|
56 static TPowerState iTargetState = EPwLimit; |
|
57 |
|
58 // Sets the target state for the current test |
|
59 void SetTargetState(TPowerState aState) |
|
60 { |
|
61 iTargetState = aState; |
|
62 } |
|
63 |
|
64 TInt Power::EnableWakeupEvents(TPowerState aState) |
|
65 { |
|
66 iCurrentState = aState; |
|
67 return KErrNone; |
|
68 } |
|
69 |
|
70 void Power::RequestWakeupEventNotification(TRequestStatus& aStatus) |
|
71 { |
|
72 TRequestStatus* ptrStatus = &aStatus; |
|
73 User::RequestComplete(ptrStatus, KErrNone); |
|
74 } |
|
75 |
|
76 TInt Power::PowerDown() |
|
77 { |
|
78 TEST2(iCurrentState, iTargetState); |
|
79 return KErrNone; |
|
80 } |
|
81 |
|
82 // Type definition for pointer to member function. |
|
83 typedef void (*ClassFuncPtrL) (void); |
|
84 /** |
|
85 Wrapper function to call all OOM test functions |
|
86 @param testFuncL pointer to OOM test function |
|
87 @param aTestDesc test function name |
|
88 */ |
|
89 LOCAL_C void DoOOMTestL(ClassFuncPtrL testFuncL, const TDesC& aTestDesc) |
|
90 { |
|
91 TheTest.Next(aTestDesc); |
|
92 |
|
93 TInt err=KErrNone; |
|
94 TInt tryCount = 0; |
|
95 do |
|
96 { |
|
97 __UHEAP_MARK; |
|
98 |
|
99 |
|
100 TInt startProcessHandleCount; |
|
101 TInt startThreadHandleCount; |
|
102 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); |
|
103 |
|
104 __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount); |
|
105 |
|
106 TRAP(err, (*testFuncL)()); |
|
107 |
|
108 __UHEAP_SETFAIL(RHeap::ENone, 0); |
|
109 |
|
110 if (err!=KErrNoMemory) |
|
111 TEST2(err, KErrNone); |
|
112 |
|
113 // check that no handles have leaked |
|
114 TInt endProcessHandleCount; |
|
115 TInt endThreadHandleCount; |
|
116 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); |
|
117 |
|
118 TEST2(startProcessHandleCount, endProcessHandleCount); |
|
119 TEST2(startThreadHandleCount, endThreadHandleCount); |
|
120 |
|
121 __UHEAP_MARKEND; |
|
122 } while(err == KErrNoMemory); |
|
123 |
|
124 TEST2(err, KErrNone); |
|
125 TheTest.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount); |
|
126 } |
|
127 |
|
128 /** |
|
129 @SYMTestCaseID SYSLIB-PWRLCLI-UT-3687 |
|
130 @SYMTestCaseDesc Device Standby (default) Test |
|
131 @SYMPREQ PREQ1089 |
|
132 @SYMREQ REQ6883 |
|
133 @SYMTestStatus Implemented |
|
134 @SYMTestPriority Critical |
|
135 @SYMTestPurpose To ensure that the existing default behaviour of going to standby if no power state is passed to HandleShutdownEventL() is maintained. |
|
136 @SYMTestActions Call two parameter version of HandleShutdownEventL() with aPowerOff = ETrue. |
|
137 @SYMTestExpectedResults When Power::PowerDown() is called, the target power state should be EPwStandby. |
|
138 */ |
|
139 void StandbyTestL() |
|
140 { |
|
141 SetTargetState(EPwStandby); |
|
142 |
|
143 CServShutdownServer* serv = CServShutdownServer::NewL(); |
|
144 |
|
145 serv->HandleShutdownEventL(MSaveObserver::ESaveAll,ETrue); |
|
146 |
|
147 delete serv; |
|
148 |
|
149 SetTargetState(EPwLimit); // To reset the target state |
|
150 } |
|
151 |
|
152 /** |
|
153 @SYMTestCaseID SYSLIB-PWRLCLI-UT-3688 |
|
154 @SYMTestCaseDesc Device Standby with Parameter Test |
|
155 @SYMPREQ PREQ1089 |
|
156 @SYMREQ REQ6883 |
|
157 @SYMTestStatus Implemented |
|
158 @SYMTestPriority Critical |
|
159 @SYMTestPurpose To ensure that the device goes into standby mode by passing the standby power state to HandleShutdownEventL(). |
|
160 @SYMTestActions Call three parameter version of HandleShutdownEventL() with aPowerOff = ETrue and aEvent = EPwStandby. |
|
161 @SYMTestExpectedResults When Power::PowerDown() is called, the target power state should be EPwStandby. |
|
162 */ |
|
163 void StandbyWithParameterTestL() |
|
164 { |
|
165 SetTargetState(EPwStandby); |
|
166 |
|
167 CServShutdownServer* serv = CServShutdownServer::NewL(); |
|
168 |
|
169 serv->HandleShutdownEventL(MSaveObserver::ESaveAll,ETrue,EPwStandby); |
|
170 |
|
171 delete serv; |
|
172 |
|
173 SetTargetState(EPwLimit); // To reset the target state |
|
174 } |
|
175 |
|
176 /** |
|
177 @SYMTestCaseID SYSLIB-PWRLCLI-UT-3689 |
|
178 @SYMTestCaseDesc Device Power-off Test |
|
179 @SYMPREQ PREQ1089 |
|
180 @SYMREQ REQ6883 |
|
181 @SYMTestStatus Implemented |
|
182 @SYMTestPriority Critical |
|
183 @SYMTestPurpose To ensure that the device goes into power-off mode by passing the power off power state to HandleShutdownEventL(). |
|
184 @SYMTestActions Call three parameter version of HandleShutdownEventL() with aPowerOff = ETrue and aEvent = EPwOff. |
|
185 @SYMTestExpectedResults When Power::PowerDown() is called, the target power state should be EPwOff. |
|
186 */ |
|
187 void PowerOffTestL() |
|
188 { |
|
189 SetTargetState(EPwOff); |
|
190 |
|
191 CServShutdownServer* serv = CServShutdownServer::NewL(); |
|
192 |
|
193 serv->HandleShutdownEventL(MSaveObserver::ESaveAll,ETrue,EPwOff); |
|
194 |
|
195 delete serv; |
|
196 |
|
197 SetTargetState(EPwLimit); // To reset the target state |
|
198 } |
|
199 |
|
200 /** |
|
201 @SYMTestCaseID SYSLIB-PWRLCLI-UT-3690 |
|
202 @SYMTestCaseDesc Device Restart Test |
|
203 @SYMPREQ PREQ1089 |
|
204 @SYMREQ REQ6883 |
|
205 @SYMTestStatus Implemented |
|
206 @SYMTestPriority Critical |
|
207 @SYMTestPurpose To ensure that the device goes into restart mode by passing the restart power state to HandleShutdownEventL(). |
|
208 @SYMTestActions Call three parameter version of HandleShutdownEventL() with aPowerOff = ETrue and aEvent = EPwRestart. |
|
209 @SYMTestExpectedResults When Power::PowerDown() is called, the target power state should be EPwRestart. |
|
210 */ |
|
211 void RestartTestL() |
|
212 { |
|
213 SetTargetState(EPwRestart); |
|
214 |
|
215 CServShutdownServer* serv = CServShutdownServer::NewL(); |
|
216 |
|
217 serv->HandleShutdownEventL(MSaveObserver::ESaveAll,ETrue,EPwRestart); |
|
218 |
|
219 delete serv; |
|
220 |
|
221 SetTargetState(EPwLimit); // To reset the target state |
|
222 } |
|
223 |
|
224 /** |
|
225 @SYMTestCaseID SYSLIB-PWRLCLI-UT-3691 |
|
226 @SYMTestCaseDesc Invalid Value Test |
|
227 @SYMPREQ PREQ1089 |
|
228 @SYMREQ REQ6883 |
|
229 @SYMTestStatus Implemented |
|
230 @SYMTestPriority Critical |
|
231 @SYMTestPurpose To ensure that invalid values do not cause the system to change power state. |
|
232 @SYMTestActions Call HandleShutdownEventL() with aPowerOff = ETrue and EPwActive, EPwLimit as power state values. |
|
233 @SYMTestExpectedResults Function should panic with KErrNotSupported. |
|
234 */ |
|
235 void InvalidValueTestL() |
|
236 { |
|
237 CServShutdownServer* serv = CServShutdownServer::NewL(); |
|
238 |
|
239 TRAPD(err, serv->HandleShutdownEventL(MSaveObserver::ESaveAll,ETrue,EPwActive)); |
|
240 TEST2(err, KErrNotSupported); |
|
241 |
|
242 TRAPD(err2, serv->HandleShutdownEventL(MSaveObserver::ESaveAll,ETrue,EPwLimit)); |
|
243 TEST2(err2, KErrNotSupported); |
|
244 |
|
245 delete serv; |
|
246 |
|
247 SetTargetState(EPwLimit); // To reset the target state |
|
248 } |
|
249 |
|
250 /** |
|
251 @SYMTestCaseID SYSLIB-PWRLCLI-UT-3692 |
|
252 @SYMTestCaseDesc Out of memory Test |
|
253 @SYMPREQ PREQ1089 |
|
254 @SYMTestStatus Implemented |
|
255 @SYMTestPriority Critical |
|
256 @SYMTestPurpose To ensure that any OOM failure in the new code path is handled gracefully. |
|
257 @SYMTestActions SYSLIB-PWRLCLI-UT-1000 to SYSLIB-PWRLCLI-UT-1005 will be run under standard RTest OOM Harness. |
|
258 @SYMTestExpectedResults The existing tests should succeed when executed under OOM conditions. |
|
259 */ |
|
260 void OOMTestL() |
|
261 { |
|
262 DoOOMTestL(&StandbyTestL,_L("OOM Device Standby (default) Test")); |
|
263 DoOOMTestL(&StandbyWithParameterTestL,_L("OOM Device Standby with Parameter Test")); |
|
264 DoOOMTestL(&PowerOffTestL,_L("OOM Device Power-off Test")); |
|
265 DoOOMTestL(&RestartTestL,_L("OOM Device Restart Test")); |
|
266 DoOOMTestL(&InvalidValueTestL,_L("OOM Invalid Value Test")); |
|
267 } |
|
268 |
|
269 // |
|
270 // |
|
271 //Tests |
|
272 |
|
273 static void DoRunL() |
|
274 { |
|
275 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-PWRLCLI-UT-3687 Device Standby (default) Test ")); |
|
276 ::StandbyTestL(); |
|
277 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-PWRLCLI-UT-3688 Device Standby with Parameter Test ")); |
|
278 ::StandbyWithParameterTestL(); |
|
279 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-PWRLCLI-UT-3689 Device Power-off Test ")); |
|
280 ::PowerOffTestL(); |
|
281 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-PWRLCLI-UT-3690 Device Restart Test ")); |
|
282 ::RestartTestL(); |
|
283 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-PWRLCLI-UT-3691 Invalid Value Test ")); |
|
284 ::InvalidValueTestL(); |
|
285 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-PWRLCLI-UT-3692 Out of memory Test ")); |
|
286 ::OOMTestL(); |
|
287 } |
|
288 |
|
289 TInt E32Main() |
|
290 { |
|
291 __UHEAP_MARK; |
|
292 CTrapCleanup* tc = CTrapCleanup::New(); |
|
293 TEST(tc != NULL); |
|
294 |
|
295 TheTest.Start(_L("Power shutdown tests")); |
|
296 |
|
297 TRAPD(err, ::DoRunL()); |
|
298 TEST2(err, KErrNone); |
|
299 |
|
300 TheTest.End(); |
|
301 TheTest.Close(); |
|
302 |
|
303 delete tc; |
|
304 |
|
305 __UHEAP_MARKEND; |
|
306 |
|
307 User::Heap().Check(); |
|
308 return KErrNone; |
|
309 } |