|
1 // Copyright (c) 2008-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 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 |
|
22 #include "susutilserver.h" |
|
23 #include "tsus_step_utilserver.h" |
|
24 |
|
25 #include "tsus_ssmsuscli.h" |
|
26 #include "tsus_startserver.h" |
|
27 |
|
28 #include "tsus_goodsup.h" |
|
29 |
|
30 |
|
31 _LIT(KFileNameMissing, "missing.bin"); |
|
32 _LIT(KFileNameBadSup, "tsus_badsup.dll"); |
|
33 _LIT(KFileNameGoodSup, "tsus_goodsup.dll"); |
|
34 |
|
35 const TUid KIdentityMissing = {123}; |
|
36 const TUid KIdentityBadSup = {0x1028359A}; |
|
37 const TUid KIdentityGoodSup = {0x10283598}; |
|
38 |
|
39 |
|
40 CSusUtilServerTest::~CSusUtilServerTest() |
|
41 { |
|
42 } |
|
43 |
|
44 CSusUtilServerTest::CSusUtilServerTest() |
|
45 { |
|
46 SetTestStepName(KTSusUtilServerStep); |
|
47 } |
|
48 |
|
49 /** */ |
|
50 TVerdict CSusUtilServerTest::doTestStepPreambleL() |
|
51 { |
|
52 return CTestStep::doTestStepPreambleL(); |
|
53 } |
|
54 |
|
55 /** */ |
|
56 TVerdict CSusUtilServerTest::doTestStepL() |
|
57 { |
|
58 INFO_PRINTF1(_L("CSusUtilServerTest tests started....")); |
|
59 |
|
60 __UHEAP_MARK; |
|
61 doTestForMemoryLeaksL(); //UT server |
|
62 doTestForMemoryLeaksDuringHeapFailureL(); //UT server |
|
63 doTestProcessCriticalL(); //UT server |
|
64 doTestUnconnected(); //UT RSession |
|
65 doTestPositiveConnectCloseL(); //IT RSession+CSession |
|
66 doTestNegativeConnectCloseL(); //IT RSession+CSession |
|
67 doTestLoadSupL(); //IT all classes used by utility server |
|
68 __UHEAP_MARKEND; |
|
69 |
|
70 INFO_PRINTF1(_L("....CSusUtilServerTest tests completed!")); |
|
71 return TestStepResult(); |
|
72 } |
|
73 |
|
74 /** */ |
|
75 TVerdict CSusUtilServerTest::doTestStepPostambleL() |
|
76 { |
|
77 return CTestStep::doTestStepPostambleL(); |
|
78 } |
|
79 |
|
80 /** |
|
81 Old Test CaseID APPFWK-SUS-0002 |
|
82 New Test CaseID DEVSRVS-SSMA-SUS-0002 |
|
83 */ |
|
84 |
|
85 void CSusUtilServerTest::doTestForMemoryLeaksL() |
|
86 { |
|
87 INFO_PRINTF1(_L("Checking for memoryleaks in SusUtilServer destructor")); |
|
88 |
|
89 CActiveScheduler* sched = new(ELeave) CActiveScheduler; |
|
90 CleanupStack::PushL (sched ); |
|
91 CActiveScheduler::Install (sched ); |
|
92 |
|
93 __UHEAP_MARK; |
|
94 RProcess process; |
|
95 CSusUtilServer* server = CSusUtilServer::NewLC(KTestServerName, process.SecureId()); |
|
96 CleanupStack::PopAndDestroy(server); |
|
97 __UHEAP_MARKEND; |
|
98 |
|
99 CleanupStack::PopAndDestroy(sched); |
|
100 } |
|
101 |
|
102 void CSusUtilServerTest::doTestForMemoryLeaksDuringHeapFailureL( ) |
|
103 { |
|
104 INFO_PRINTF1(_L("Checking for memoryleaks during heap failure")); |
|
105 |
|
106 CActiveScheduler* sched = new(ELeave) CActiveScheduler; |
|
107 CleanupStack::PushL (sched ); |
|
108 CActiveScheduler::Install (sched ); |
|
109 |
|
110 // CSusUtilServer::NewLC |
|
111 INFO_PRINTF1(_L(" CSusUtilServer construction under OOM")); |
|
112 RProcess process; |
|
113 CSusUtilServer* server=NULL; |
|
114 TInt failRate = 1; |
|
115 for (;;failRate++) |
|
116 { |
|
117 __UHEAP_RESET; |
|
118 __UHEAP_SETFAIL(RHeap::EDeterministic,failRate); |
|
119 __UHEAP_MARK; |
|
120 |
|
121 TRAPD(ret, |
|
122 { |
|
123 server = CSusUtilServer::NewLC(KTestServerName, process.SecureId()); |
|
124 CleanupStack::Pop(server); |
|
125 }) |
|
126 |
|
127 |
|
128 TEST((ret==KErrNone || ret==KErrNoMemory)); |
|
129 if (ret!=KErrNone) |
|
130 { |
|
131 __UHEAP_MARKEND; |
|
132 TEST(server==NULL); |
|
133 } |
|
134 else |
|
135 { |
|
136 TEST(server!=NULL); |
|
137 delete server; |
|
138 server = NULL; |
|
139 __UHEAP_MARKEND; |
|
140 break; |
|
141 } |
|
142 } |
|
143 __UHEAP_RESET; |
|
144 INFO_PRINTF2(_L(" #allocs for c'tion: %d."),failRate-1); |
|
145 |
|
146 CleanupStack::PopAndDestroy(sched); |
|
147 } |
|
148 |
|
149 void CSusUtilServerTest::doTestProcessCriticalL() |
|
150 { |
|
151 INFO_PRINTF1(_L("Checking that UtilServer set its thread to critical")); |
|
152 |
|
153 __UHEAP_MARK; |
|
154 User::TCritical before = User::Critical(); |
|
155 TESTL(before == User::ENotCritical); |
|
156 |
|
157 CActiveScheduler* sched = new(ELeave) CActiveScheduler; |
|
158 CleanupStack::PushL (sched ); |
|
159 CActiveScheduler::Install (sched ); |
|
160 RProcess process; |
|
161 CSusUtilServer* server = CSusUtilServer::NewLC(KTestServerName, process.SecureId()); |
|
162 |
|
163 User::TCritical critical = User::Critical(); |
|
164 TEST(critical == User::ESystemCritical); |
|
165 |
|
166 CleanupStack::PopAndDestroy(server); |
|
167 CleanupStack::PopAndDestroy(sched); |
|
168 |
|
169 User::TCritical after = User::Critical(); |
|
170 TESTL(after == User::ENotCritical); |
|
171 __UHEAP_MARKEND; |
|
172 } |
|
173 |
|
174 /** |
|
175 Old Test CaseID APPFWK-SUS-0003 |
|
176 New Test CaseID DEVSRVS-SSMA-SUS-0002 |
|
177 */ |
|
178 |
|
179 void CSusUtilServerTest::doTestUnconnected() |
|
180 { |
|
181 INFO_PRINTF1(_L("Testing errormessages returned from an unconnected session")); |
|
182 |
|
183 RSsmSusCliTest client; |
|
184 |
|
185 const TInt connect = client.Connect(KTestServerName); |
|
186 TESTE(KErrNotFound == connect, connect); |
|
187 |
|
188 client.Close(); //should not cause a Panic or any other problem |
|
189 |
|
190 TSsmSupInfo supinfo; |
|
191 const TInt syncReq = client.RequestLoadSup(supinfo); |
|
192 TESTE(KErrDisconnected == syncReq, syncReq); |
|
193 |
|
194 TRequestStatus status; |
|
195 TPckgC<TSsmSupInfo> ptr(supinfo); |
|
196 client.RequestLoadSup(ptr, status); |
|
197 User::WaitForRequest(status); |
|
198 const TInt asyncReq = status.Int(); |
|
199 TESTE(KErrDisconnected == asyncReq, asyncReq); |
|
200 |
|
201 client.RequestLoadSupCancel(); //should not cause a Panic or any other problem |
|
202 |
|
203 const TInt unload = client.RequestUnLoadSup(supinfo); |
|
204 TESTE(KErrDisconnected == unload, unload); |
|
205 } |
|
206 |
|
207 /** |
|
208 Old Test CaseID APPFWK-SUS-0006 |
|
209 New Test CaseID DEVSRVS-SSMA-SUS-0002 |
|
210 */ |
|
211 |
|
212 |
|
213 void CSusUtilServerTest::doTestPositiveConnectCloseL() |
|
214 { |
|
215 INFO_PRINTF1(_L("Testing a valid connection attempt of RSsmSusCli")); |
|
216 |
|
217 __UHEAP_MARK; |
|
218 RProcess process; |
|
219 const TUint32 sid = process.SecureId(); |
|
220 RThread thread; |
|
221 CleanupClosePushL(thread); |
|
222 TESTL(KErrNone == StartServer(thread, sid)); |
|
223 |
|
224 //Test the RSession |
|
225 RSsmSusCliTest session; |
|
226 TInt err = session.Connect(KTestServerName); |
|
227 TESTE(KErrNone == err, err); |
|
228 |
|
229 //Test a second connect |
|
230 err = session.Connect(KTestServerName); |
|
231 TESTE(KErrAlreadyExists == err, err); |
|
232 |
|
233 session.Close(); |
|
234 |
|
235 thread.Kill(KErrNone); |
|
236 CleanupStack::PopAndDestroy(&thread); |
|
237 __UHEAP_MARKEND; |
|
238 } |
|
239 |
|
240 |
|
241 /** |
|
242 Old Test CaseID APPFWK-SUS-0007 |
|
243 New Test CaseID DEVSRVS-SSMA-SUS-0002 |
|
244 */ |
|
245 |
|
246 void CSusUtilServerTest::doTestNegativeConnectCloseL() |
|
247 { |
|
248 INFO_PRINTF1(_L("Testing the SID-check in CSusUtilSession")); |
|
249 |
|
250 __UHEAP_MARK; |
|
251 const TUint32 wrongSecureId = 1; |
|
252 RThread thread; |
|
253 CleanupClosePushL(thread); |
|
254 TESTL(KErrNone == StartServer(thread, wrongSecureId)); |
|
255 |
|
256 //Test the RSession |
|
257 RSsmSusCliTest session; |
|
258 |
|
259 // As the server is started with a wrong secure id, no requests would be serviced by the server. |
|
260 // Hence no need to set the heap mark on server. |
|
261 TInt err = session.Connect(KTestServerName, EFalse); |
|
262 TESTE(KErrNone == err, err); |
|
263 err = session.SendAnyrequest(); |
|
264 TESTE(KErrPermissionDenied == err, err); |
|
265 |
|
266 // As the server cannot service any request, no need to check the memory heap on server. |
|
267 session.Close(EFalse); |
|
268 |
|
269 thread.Kill(KErrNone); |
|
270 CleanupStack::PopAndDestroy(&thread); |
|
271 __UHEAP_MARKEND; |
|
272 } |
|
273 |
|
274 /** |
|
275 Old Test CaseID APPFWK-SUS-0005 |
|
276 New Test CaseID DEVSRVS-SSMA-SUS-0002 |
|
277 */ |
|
278 |
|
279 void CSusUtilServerTest::doTestLoadSupL() |
|
280 { |
|
281 __UHEAP_MARK; |
|
282 |
|
283 RProcess process; |
|
284 const TUint32 sid = process.SecureId(); |
|
285 RThread thread; |
|
286 CleanupClosePushL(thread); |
|
287 TESTL(KErrNone == StartServer(thread, sid)); |
|
288 |
|
289 //Connect the RSession |
|
290 RSsmSusCliTest session; |
|
291 CleanupClosePushL(session); |
|
292 TInt err = session.Connect(KTestServerName); |
|
293 TESTE(KErrNone == err, err); |
|
294 |
|
295 TestLoadMissing(session); |
|
296 TestLoadWrongType(session); |
|
297 TestLoadWrongIdentity(session); |
|
298 TestLoadOkL(session); |
|
299 TestLoadDuplicate(session); |
|
300 TestUnloadSup(session); |
|
301 |
|
302 //Cleanup |
|
303 CleanupStack::PopAndDestroy(&session); |
|
304 //Kill test-server |
|
305 thread.Kill(KErrNone); |
|
306 CleanupStack::PopAndDestroy(&thread); |
|
307 |
|
308 __UHEAP_MARKEND; |
|
309 } |
|
310 |
|
311 void CSusUtilServerTest::TestLoadMissing(RSsmSusCli& aSession) |
|
312 { |
|
313 INFO_PRINTF1(_L("Try Load missing SUP")); |
|
314 |
|
315 TSsmSupInfo info(KFileNameMissing, 1, KIdentityMissing); |
|
316 TInt result = aSession.RequestLoadSup(info); |
|
317 TESTE(KErrNotFound==result, result); |
|
318 } |
|
319 |
|
320 void CSusUtilServerTest::TestLoadWrongType(RSsmSusCli& aSession) |
|
321 { |
|
322 INFO_PRINTF1(_L("Try Load a SUP with incorrect type UID2")); |
|
323 |
|
324 TSsmSupInfo info(KFileNameBadSup); |
|
325 TInt result = aSession.RequestLoadSup(info); |
|
326 TESTE(KErrNotSupported==result, result); |
|
327 } |
|
328 |
|
329 void CSusUtilServerTest::TestLoadWrongIdentity(RSsmSusCli& aSession) |
|
330 { |
|
331 INFO_PRINTF1(_L("Try Load a SUP with wrong Identity UID3")); |
|
332 |
|
333 TSsmSupInfo info(KFileNameGoodSup, 1, KIdentityBadSup); |
|
334 TInt result = aSession.RequestLoadSup(info); |
|
335 TESTE(KErrBadName==result, result); |
|
336 } |
|
337 |
|
338 void CSusUtilServerTest::TestLoadOkL(RSsmSusCli& aSession) |
|
339 { |
|
340 INFO_PRINTF1(_L("Load a valid and working SUP. Ensure that its RunL gets called.")); |
|
341 |
|
342 RSemaphore sem; |
|
343 sem.CreateGlobal(KTestGoodSupSemaphore, 0); |
|
344 CleanupClosePushL(sem); |
|
345 |
|
346 //Issue a LoadSup request |
|
347 TRequestStatus status; |
|
348 TSsmSupInfo info(KFileNameGoodSup, 1, KIdentityGoodSup); |
|
349 TPckgC<TSsmSupInfo>* infoBuf = new (ELeave) TPckgC<TSsmSupInfo>(info); |
|
350 CleanupStack::PushL(infoBuf); |
|
351 aSession.RequestLoadSup(*infoBuf, status); |
|
352 |
|
353 //Wait until GoodSup signal our semaphore from its RunL (or give up after 5 seconds) |
|
354 const TInt timeout = 5000000; |
|
355 const TInt result = sem.Wait(timeout); |
|
356 TESTE(KErrNone == result, result); // a timeout would cause the result to be KErrTimedOut |
|
357 |
|
358 //The request to load the sup should already have been completed before the semaphore was signaled |
|
359 TESTE(status==KErrNone, status.Int()); |
|
360 CleanupStack::PopAndDestroy(infoBuf); |
|
361 CleanupStack::PopAndDestroy(&sem); |
|
362 } //lint !e429 Suppress Custodial pointer 'infoBuf' has not been freed or returned |
|
363 |
|
364 void CSusUtilServerTest::TestLoadDuplicate(RSsmSusCli& aSession) |
|
365 { |
|
366 INFO_PRINTF1(_L("Test that a second request to load the same Sup will fail with KErrAlreadyExists.")); |
|
367 TSsmSupInfo info(KFileNameGoodSup, 1, KIdentityGoodSup); |
|
368 TInt result = aSession.RequestLoadSup(info); |
|
369 TESTE(KErrAlreadyExists==result, result); |
|
370 } |
|
371 |
|
372 void CSusUtilServerTest::TestUnloadSup(RSsmSusCli& aSession) |
|
373 { |
|
374 INFO_PRINTF1(_L("Unload Sup")); |
|
375 TSsmSupInfo info(KFileNameGoodSup, 1, KIdentityGoodSup); |
|
376 TInt result = aSession.RequestUnLoadSup(info); |
|
377 TESTE(KErrNone==result, result); |
|
378 |
|
379 INFO_PRINTF1(_L("Test error-message for a subsequent unload-request")); |
|
380 result = aSession.RequestUnLoadSup(info); |
|
381 TESTE(KErrNotFound==result, result); |
|
382 } |
|
383 |