|
1 // Copyright (c) 2005-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 the License "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Performs Tests on Backup server.\n |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @internalComponent - Internal Symbian test code |
|
23 */ |
|
24 |
|
25 #include <s32file.h> |
|
26 #include <e32base.h> |
|
27 #include <f32file.h> |
|
28 #include <e32test.h> |
|
29 #include <babackup.h> |
|
30 #include <e32std.h> |
|
31 #include <e32math.h> |
|
32 #include "T_BackupStep.h" |
|
33 |
|
34 |
|
35 |
|
36 CTestActive::CTestActive() |
|
37 : CActive(EPriorityIdle*2) |
|
38 { |
|
39 CActiveScheduler::Add(this); |
|
40 } |
|
41 |
|
42 CTestActive::~CTestActive() |
|
43 { |
|
44 Cancel(); |
|
45 } |
|
46 |
|
47 void CTestActive::DoCancel() |
|
48 { |
|
49 TRequestStatus* s=&iStatus; |
|
50 User::RequestComplete(s, KErrNone); |
|
51 } |
|
52 |
|
53 void CTestActive::StartL() |
|
54 { |
|
55 iReport = NULL; |
|
56 SetActive(); |
|
57 } |
|
58 |
|
59 |
|
60 /** |
|
61 Auxiliary Fn for Test Case ID T-BackupStep-testGetsCallbackOnBackupStartL, |
|
62 T-BackupStep-testGetsCallbackOnBackupEndL, |
|
63 T-BackupStep-testGetsCallbackOnBackupStartInSecondWrapperL, |
|
64 T-BackupStep-testGetsCallbackOnBackupWrapperKillL, and |
|
65 T-BackupStep-testGetsCallbackOnBackupWrapperKillOtherL |
|
66 |
|
67 This function is used to set the event request to the AO and |
|
68 to set that AO active.\n |
|
69 |
|
70 */ |
|
71 void CTestActive::StartL(TRequestStatus& aRequestStatus) |
|
72 { |
|
73 iReport = &aRequestStatus; |
|
74 SetActive(); |
|
75 } |
|
76 |
|
77 void CTestActive::RunL() |
|
78 { |
|
79 CActiveScheduler::Stop(); |
|
80 } |
|
81 |
|
82 // Class to test the n-th recieved event from the backup server is the same as the event |
|
83 // the object is initialised with |
|
84 CTestBackupOperationObserver::CTestBackupOperationObserver(const TBackupOperationAttributes& aEvent, CTestExecuteLogger& aLogger) : CTestActive(), iEvent(aEvent), iCount(1) |
|
85 { |
|
86 iLogger=aLogger; |
|
87 } |
|
88 CTestBackupOperationObserver::CTestBackupOperationObserver(const TBackupOperationAttributes& aEvent, TInt aCount, CTestExecuteLogger& aLogger) : CTestActive(), iEvent(aEvent), iCount(aCount) |
|
89 { |
|
90 iLogger=aLogger; |
|
91 } |
|
92 |
|
93 |
|
94 /** |
|
95 Auxiliary Fn for Test Case ID T-BackupStep-testGetsCallbackOnBackupStartL, |
|
96 T-BackupStep-testGetsCallbackOnBackupEndL, |
|
97 T-BackupStep-testGetsCallbackOnBackupStartInSecondWrapperL, |
|
98 T-BackupStep-testGetsCallbackOnBackupWrapperKillL, and |
|
99 T-BackupStep-testGetsCallbackOnBackupWrapperKillOtherL |
|
100 |
|
101 This function is overridden from MBackupOperationObserver and is called |
|
102 when a backup or restore operation either starts or ends. The function is used |
|
103 to receive signals that tell what backup operation completed.\n |
|
104 |
|
105 */ |
|
106 void CTestBackupOperationObserver::HandleBackupOperationEventL(const TBackupOperationAttributes& aBackupOperationAttributes) |
|
107 { |
|
108 const TInt KOneOfOurEvents = 12321; |
|
109 if(iCount!=KOneOfOurEvents) |
|
110 { |
|
111 INFO_PRINTF2(_L("Got event #%d from backup server; ignoring this one\n"), iCount+1); |
|
112 } |
|
113 else |
|
114 { |
|
115 iCount=0; |
|
116 if(iReport) |
|
117 { |
|
118 User::RequestComplete(iReport, aBackupOperationAttributes.iOperation); |
|
119 INFO_PRINTF1(_L("Got event from backup server; Completing...\n")); |
|
120 } |
|
121 else |
|
122 { |
|
123 INFO_PRINTF1(_L("Got event from backup server; iReport not set...testing...\n")); |
|
124 } |
|
125 } |
|
126 } |
|
127 |
|
128 void CTestBackupOperationObserver::SetReadyToGo() |
|
129 { |
|
130 const TInt KOneOfOurEvents = 12321; |
|
131 iCount=KOneOfOurEvents; |
|
132 } |
|
133 |
|
134 |
|
135 /** |
|
136 Auxiliary Fn for all test cases |
|
137 |
|
138 This function creates an Active Object (AO).Sets the AO to |
|
139 be active. Starts the active scheduler to complete any pending requests |
|
140 and flushes all requests from the scheduler list.\n |
|
141 |
|
142 */ |
|
143 void CT_BackupStep::FlushSchedulerQueueL() |
|
144 { |
|
145 CTestActive* active = new(ELeave) CTestActive(); |
|
146 CleanupStack::PushL(active); |
|
147 RTimer timer; |
|
148 timer.CreateLocal(); |
|
149 timer.After(active->iStatus,500000); |
|
150 active->StartL(); |
|
151 CActiveScheduler::Start(); |
|
152 CleanupStack::PopAndDestroy(1);//active |
|
153 } |
|
154 |
|
155 |
|
156 /** |
|
157 @SYMTestCaseID T-BackupStep-testGetsCallbackOnBackupStartL |
|
158 |
|
159 @SYMPREQ |
|
160 |
|
161 @SYMTestCaseDesc Test whether backup server signals the test backup observer |
|
162 on backup start operation. |
|
163 |
|
164 @SYMTestPriority High |
|
165 |
|
166 @SYMTestStatus Implemented |
|
167 |
|
168 @SYMTestActions The test creates an object of test observer to observe for |
|
169 start backup event and registers the specified observer to be notified |
|
170 when a backup operation starts by calling RegisterBackupOperationObserverL(). |
|
171 Set attributes to indicate start of backup operation. Flush the scheduler |
|
172 of all pending requests. Set start backup event to the AO. Notify the |
|
173 server of backup operation using NotifyBackupOperationL(). |
|
174 Start the active scheduler to receive signal for start event from backup |
|
175 server.\n |
|
176 API Calls:\n |
|
177 CBaBackupSessionWrapper::RegisterBackupOperationObserverL(MBackupOperationObserver& aBackupOperationObserver)\n |
|
178 CBaBackupSessionWrapper::NotifyBackupOperationL(const TBackupOperationAttributes& aBackupOperationAttributes)\n |
|
179 CBaBackupSessionWrapper::DeRegisterBackupOperationObserver(MBackupOperationObserver& aBackupOperationObserver)\n |
|
180 |
|
181 @SYMTestExpectedResults The test should complete with Backup server signaling the observer |
|
182 when the Backup operation starts.\n |
|
183 |
|
184 */ |
|
185 void CT_BackupStep::testGetsCallbackOnBackupStartL() |
|
186 { |
|
187 const TBackupOperationAttributes gEventStart(MBackupObserver::EReleaseLockNoAccess, MBackupOperationObserver::EStart); |
|
188 CTestBackupOperationObserver* backupObserver = new(ELeave) CTestBackupOperationObserver(gEventStart, Logger()); |
|
189 CleanupStack::PushL(backupObserver); |
|
190 gWrapper->RegisterBackupOperationObserverL(*backupObserver); |
|
191 FlushSchedulerQueueL(); |
|
192 |
|
193 backupObserver->StartL(backupObserver->iStatus); |
|
194 gWrapper->NotifyBackupOperationL(gEventStart); |
|
195 backupObserver->SetReadyToGo(); |
|
196 CActiveScheduler::Start(); |
|
197 TEST(backupObserver->iStatus == gEventStart.iOperation); |
|
198 |
|
199 gWrapper->DeRegisterBackupOperationObserver(*backupObserver); |
|
200 CleanupStack::PopAndDestroy();//backupObserver; |
|
201 } |
|
202 |
|
203 |
|
204 /** |
|
205 @SYMTestCaseID T-BackupStep-testGetsCallbackOnBackupEndL |
|
206 |
|
207 @SYMPREQ |
|
208 |
|
209 @SYMTestCaseDesc Test whether backup server signals the test backupobserver on |
|
210 backup end operation. |
|
211 |
|
212 @SYMTestPriority High |
|
213 |
|
214 @SYMTestStatus Implemented |
|
215 |
|
216 @SYMTestActions The test creates an object of test observer to observe for end |
|
217 of backup event and registers the specified observer to be notified when a |
|
218 backup operation ends by calling RegisterBackupOperationObserverL().Set |
|
219 attributes to indicate start and end of backup operation. Flush the scheduler |
|
220 from all pending requests. Set start backup event to the AO. Notify the |
|
221 server of a start backup operation using NotifyBackupOperationL(). |
|
222 Start the active scheduler to receive signal for start event from backup |
|
223 server. Now set end of backup event to the AO. Notify server of an end |
|
224 backup operation using NotifyBackupOperationL(). Start the active |
|
225 scheduler to receive signal for end of backup event from backup server.\n |
|
226 API Calls:\n |
|
227 CBaBackupSessionWrapper::RegisterBackupOperationObserverL(MBackupOperationObserver& aBackupOperationObserver)\n |
|
228 CBaBackupSessionWrapper::NotifyBackupOperationL(const TBackupOperationAttributes& aBackupOperationAttributes)\n |
|
229 CBaBackupSessionWrapper::DeRegisterBackupOperationObserver(MBackupOperationObserver& aBackupOperationObserver)\n |
|
230 |
|
231 @SYMTestExpectedResults The test should complete with Backup server signaling the observer |
|
232 when the Backup operation ends. |
|
233 |
|
234 */ |
|
235 void CT_BackupStep::testGetsCallbackOnBackupEndL() |
|
236 { |
|
237 const TBackupOperationAttributes gEventStart(MBackupObserver::EReleaseLockNoAccess, MBackupOperationObserver::EStart); |
|
238 const TBackupOperationAttributes gEventEnd(MBackupObserver::ETakeLock, MBackupOperationObserver::EEnd); |
|
239 CTestBackupOperationObserver* backupObserver = new(ELeave) CTestBackupOperationObserver(gEventEnd, Logger()); |
|
240 CleanupStack::PushL(backupObserver); |
|
241 gWrapper->RegisterBackupOperationObserverL(*backupObserver); |
|
242 FlushSchedulerQueueL(); |
|
243 |
|
244 backupObserver->StartL(backupObserver->iStatus); |
|
245 gWrapper->NotifyBackupOperationL(gEventStart); |
|
246 backupObserver->SetReadyToGo(); |
|
247 CActiveScheduler::Start(); |
|
248 TEST(backupObserver->iStatus == gEventStart.iOperation); |
|
249 |
|
250 backupObserver->StartL(backupObserver->iStatus); |
|
251 gWrapper->NotifyBackupOperationL(gEventEnd); |
|
252 backupObserver->SetReadyToGo(); |
|
253 CActiveScheduler::Start(); |
|
254 TEST(backupObserver->iStatus == gEventEnd.iOperation); |
|
255 |
|
256 gWrapper->DeRegisterBackupOperationObserver(*backupObserver); |
|
257 CleanupStack::PopAndDestroy();//backupObserver; |
|
258 } |
|
259 |
|
260 |
|
261 /** |
|
262 @SYMTestCaseID T-BackupStep-testGetsCallbackOnBackupStartInSecondWrapperL |
|
263 |
|
264 @SYMPREQ |
|
265 |
|
266 @SYMTestCaseDesc Test whether signal for start backup operation can be |
|
267 received by a second observer that is not associated |
|
268 with the wrapper object that issued the request for start |
|
269 of backup. |
|
270 |
|
271 @SYMTestPriority High |
|
272 |
|
273 @SYMTestStatus Implemented |
|
274 |
|
275 @SYMTestActions The test creates two test observers and two wrappers to the |
|
276 backup server. Set attributes to indicate start of backup operation. |
|
277 Register & associate each observer with each session wrappers that needs |
|
278 to be notified of backup start operation, issued by the respective wrappers |
|
279 by calling RegisterBackupOperationObserverL(). Using the first wrapper, |
|
280 notify the server to start backup. Verify that second observer receives |
|
281 the notification for start of server.\n |
|
282 API Calls:\n |
|
283 CBaBackupSessionWrapper::NewL()\n |
|
284 CBaBackupSessionWrapper::RegisterBackupOperationObserverL(MBackupOperationObserver& aBackupOperationObserver)\n |
|
285 CBaBackupSessionWrapper::NotifyBackupOperationL(const TBackupOperationAttributes& aBackupOperationAttributes)\n |
|
286 CBaBackupSessionWrapper::DeRegisterBackupOperationObserver(MBackupOperationObserver& aBackupOperationObserver)\n |
|
287 |
|
288 @SYMTestExpectedResults The test should confirm that second observer receives |
|
289 the signal for backup start operation issued by the first wrapper object. |
|
290 |
|
291 */ |
|
292 void CT_BackupStep::testGetsCallbackOnBackupStartInSecondWrapperL() |
|
293 { |
|
294 const TBackupOperationAttributes gEventStart(MBackupObserver::EReleaseLockNoAccess, MBackupOperationObserver::EStart); |
|
295 CTestBackupOperationObserver* backupObserver = new(ELeave) CTestBackupOperationObserver(gEventStart, Logger()); |
|
296 CleanupStack::PushL(backupObserver); |
|
297 gWrapper->RegisterBackupOperationObserverL(*backupObserver); |
|
298 FlushSchedulerQueueL(); |
|
299 |
|
300 CBaBackupSessionWrapper* secondWrapper=CBaBackupSessionWrapper::NewL(); |
|
301 CleanupStack::PushL(secondWrapper); |
|
302 |
|
303 CTestBackupOperationObserver* backupObserver2 = new(ELeave) CTestBackupOperationObserver(gEventStart, Logger()); |
|
304 CleanupStack::PushL(backupObserver2); |
|
305 secondWrapper->RegisterBackupOperationObserverL(*backupObserver2); |
|
306 FlushSchedulerQueueL(); |
|
307 |
|
308 backupObserver2->StartL(backupObserver2->iStatus); |
|
309 gWrapper->NotifyBackupOperationL(gEventStart); |
|
310 backupObserver2->SetReadyToGo(); |
|
311 CActiveScheduler::Start(); |
|
312 TEST(backupObserver2->iStatus == gEventStart.iOperation); |
|
313 |
|
314 gWrapper->DeRegisterBackupOperationObserver(*backupObserver); |
|
315 secondWrapper->DeRegisterBackupOperationObserver(*backupObserver2); |
|
316 CleanupStack::PopAndDestroy(3);//backupObserver, backupObserver2, secondWrapper |
|
317 } |
|
318 |
|
319 |
|
320 /** |
|
321 @SYMTestCaseID T-BackupStep-testGetsCallbackOnBackupWrapperKillL |
|
322 |
|
323 @SYMPREQ |
|
324 |
|
325 @SYMTestCaseDesc Test if MBackupOperationObserver::EAbort event is received |
|
326 when wrapper to the backup server is destroyed immediately |
|
327 after backup start operation is requested. |
|
328 |
|
329 @SYMTestPriority High |
|
330 |
|
331 @SYMTestStatus Implemented |
|
332 |
|
333 @SYMTestActions Create a test backup observer. Register the observer to receive |
|
334 event from server. Create a second wrapper to the backup server. Use the |
|
335 second wrapper to notify the server to start backup. After receiving signal |
|
336 for start of backup, destroy the second wrapper. Observe event received |
|
337 from the server.\n |
|
338 API Calls:\n |
|
339 CBaBackupSessionWrapper::NewL()\n |
|
340 CBaBackupSessionWrapper::RegisterBackupOperationObserverL(MBackupOperationObserver& aBackupOperationObserver)\n |
|
341 CBaBackupSessionWrapper::NotifyBackupOperationL(const TBackupOperationAttributes& aBackupOperationAttributes)\n |
|
342 CBaBackupSessionWrapper::DeRegisterBackupOperationObserver(MBackupOperationObserver& aBackupOperationObserver)\n |
|
343 |
|
344 @SYMTestExpectedResults Test confirms that event MBackupOperationObserver::EAbort |
|
345 is received. |
|
346 |
|
347 */ |
|
348 void CT_BackupStep::testGetsCallbackOnBackupWrapperKillL() |
|
349 { |
|
350 const TBackupOperationAttributes gEventStart(MBackupObserver::EReleaseLockNoAccess, MBackupOperationObserver::EStart); |
|
351 const TBackupOperationAttributes gEventEnd(MBackupObserver::ETakeLock, MBackupOperationObserver::EEnd); |
|
352 const TBackupOperationAttributes gEventAbort(MBackupObserver::ETakeLock, MBackupOperationObserver::EAbort); |
|
353 CTestBackupOperationObserver* backupObserver = new(ELeave) CTestBackupOperationObserver(gEventEnd, Logger()); |
|
354 CleanupStack::PushL(backupObserver); |
|
355 gWrapper->RegisterBackupOperationObserverL(*backupObserver); |
|
356 FlushSchedulerQueueL(); |
|
357 |
|
358 CBaBackupSessionWrapper* secondWrapper=CBaBackupSessionWrapper::NewL(); |
|
359 CleanupStack::PushL(secondWrapper); |
|
360 |
|
361 backupObserver->StartL(backupObserver->iStatus); |
|
362 secondWrapper->NotifyBackupOperationL(gEventStart); |
|
363 backupObserver->SetReadyToGo(); |
|
364 CActiveScheduler::Start(); |
|
365 TEST(backupObserver->iStatus == gEventStart.iOperation); |
|
366 |
|
367 backupObserver->StartL(backupObserver->iStatus); |
|
368 CleanupStack::PopAndDestroy();//secondWrapper |
|
369 backupObserver->SetReadyToGo(); |
|
370 CActiveScheduler::Start(); |
|
371 TEST(backupObserver->iStatus == gEventAbort.iOperation); |
|
372 |
|
373 gWrapper->DeRegisterBackupOperationObserver(*backupObserver); |
|
374 CleanupStack::PopAndDestroy(1);//backupObserver |
|
375 } |
|
376 |
|
377 |
|
378 /** |
|
379 @SYMTestCaseID T-BackupStep-testGetsCallbackOnBackupWrapperKillOtherL |
|
380 |
|
381 @SYMPREQ |
|
382 |
|
383 @SYMTestCaseDesc Test that the backup is not terminated after a backup start event, |
|
384 which is followed by destruction of any wrapper other than the wrapper |
|
385 which requested the backup start event. |
|
386 |
|
387 @SYMTestPriority High |
|
388 |
|
389 @SYMTestStatus Implemented |
|
390 |
|
391 @SYMTestActions Create a test observer. Register the observer with the server. |
|
392 Create second and third wrappers to the backup server besides the global |
|
393 wrapper. Use the second observer to start backup. Observe that the event for |
|
394 start of backup is received. Destroy the third wrapper created. Observe |
|
395 event received from the server. Notify the server to observe for event |
|
396 MBackupOperationObserver::ENone.Observe the event received. Notify the server |
|
397 to stop backup. Observe the event received. Destroy the second observer. |
|
398 Note that this destruction causes an abort event.\n |
|
399 API Calls:\n |
|
400 CBaBackupSessionWrapper::NewL()\n |
|
401 CBaBackupSessionWrapper::RegisterBackupOperationObserverL(MBackupOperationObserver& aBackupOperationObserver)\n |
|
402 CBaBackupSessionWrapper::NotifyBackupOperationL(const TBackupOperationAttributes& aBackupOperationAttributes)\n |
|
403 CBaBackupSessionWrapper::DeRegisterBackupOperationObserver(MBackupOperationObserver& aBackupOperationObserver)\n |
|
404 |
|
405 @SYMTestExpectedResults Test confirms that backup will not be terminated by |
|
406 destruction of wrapper object that did not initiate the back up process, |
|
407 after the backup operation has started. |
|
408 |
|
409 */ |
|
410 void CT_BackupStep::testGetsCallbackOnBackupWrapperKillOtherL() |
|
411 { |
|
412 const TBackupOperationAttributes gEventStart(MBackupObserver::EReleaseLockNoAccess, MBackupOperationObserver::EStart); |
|
413 const TBackupOperationAttributes gEventEnd(MBackupObserver::ETakeLock, MBackupOperationObserver::EEnd); |
|
414 const TBackupOperationAttributes gEventNone(MBackupObserver::ETakeLock, MBackupOperationObserver::ENone); |
|
415 |
|
416 CTestBackupOperationObserver* backupObserver = new(ELeave) CTestBackupOperationObserver(gEventEnd, Logger()); |
|
417 CleanupStack::PushL(backupObserver); |
|
418 gWrapper->RegisterBackupOperationObserverL(*backupObserver); |
|
419 FlushSchedulerQueueL(); |
|
420 |
|
421 CBaBackupSessionWrapper* secondWrapper=CBaBackupSessionWrapper::NewL(); |
|
422 CleanupStack::PushL(secondWrapper); // This one starts the backup |
|
423 |
|
424 CBaBackupSessionWrapper* thirdWrapper=CBaBackupSessionWrapper::NewL(); |
|
425 CleanupStack::PushL(thirdWrapper); // This one gets destroyed |
|
426 FlushSchedulerQueueL(); |
|
427 |
|
428 backupObserver->StartL(backupObserver->iStatus); |
|
429 secondWrapper->NotifyBackupOperationL(gEventStart);; |
|
430 backupObserver->SetReadyToGo(); |
|
431 CActiveScheduler::Start(); |
|
432 TEST(backupObserver->iStatus == gEventStart.iOperation); |
|
433 |
|
434 backupObserver->StartL(backupObserver->iStatus); |
|
435 CleanupStack::PopAndDestroy(thirdWrapper);//thirdWrapper |
|
436 TEST(backupObserver->iStatus == gEventStart.iOperation); // |
|
437 secondWrapper->NotifyBackupOperationL(gEventNone); |
|
438 backupObserver->SetReadyToGo(); |
|
439 CActiveScheduler::Start(); |
|
440 TEST(backupObserver->iStatus == gEventNone.iOperation); |
|
441 |
|
442 backupObserver->StartL(backupObserver->iStatus); |
|
443 secondWrapper->NotifyBackupOperationL(gEventEnd); |
|
444 backupObserver->SetReadyToGo(); |
|
445 CActiveScheduler::Start(); |
|
446 TEST(backupObserver->iStatus == gEventEnd.iOperation); |
|
447 |
|
448 backupObserver->StartL(backupObserver->iStatus); |
|
449 CleanupStack::PopAndDestroy(secondWrapper);//secondWrapper |
|
450 TEST(backupObserver->iStatus == gEventEnd.iOperation); |
|
451 CleanupStack::PopAndDestroy();//backupObserver |
|
452 gWrapper->DeRegisterBackupOperationObserver(*backupObserver); |
|
453 } |
|
454 |
|
455 |
|
456 CThreadLaunchCounter::CThreadLaunchCounter() : CActive(0) |
|
457 { |
|
458 CActiveScheduler::Add(this); |
|
459 gCount = 0; |
|
460 } |
|
461 |
|
462 CThreadLaunchCounter::~CThreadLaunchCounter() |
|
463 { |
|
464 if(IsActive()) |
|
465 Cancel(); |
|
466 } |
|
467 |
|
468 void CThreadLaunchCounter::Start() |
|
469 { |
|
470 iStatus=KRequestPending; |
|
471 gCount++; |
|
472 SetActive(); |
|
473 } |
|
474 |
|
475 void CThreadLaunchCounter::RunL() |
|
476 { |
|
477 if(--gCount==0) |
|
478 CActiveScheduler::Stop(); |
|
479 delete this; |
|
480 } |
|
481 |
|
482 |
|
483 /** |
|
484 @SYMTestCaseID T-BackupStep-testMultipleClientsL |
|
485 |
|
486 @SYMPREQ |
|
487 |
|
488 @SYMTestCaseDesc Test multiple clients accessing the Backup server. |
|
489 |
|
490 @SYMTestPriority High |
|
491 |
|
492 @SYMTestStatus Implemented |
|
493 |
|
494 @SYMTestActions The test creates multiple threads to make multiple clients |
|
495 access the backup server simultaneously. Each of the threads execute the |
|
496 thread function BackupMultipleTestThreadEntry() to create a wrapper object |
|
497 to the backup server so that a backup operation can be carried out. |
|
498 The test thus emulates a multiple client scenario.\n |
|
499 API Calls:\n |
|
500 RThread::Create(const TDesC& aName, TThreadFunction aFunction, TInt aStackSize, RAllocator* aHeap, TAny* aPtr, TOwnerType aType=EOwnerProcess)\n |
|
501 RThread::Resume() const\n |
|
502 RThread::Logon(TRequestStatus& aStatus) const\n |
|
503 RThread::Close()\n |
|
504 |
|
505 @SYMTestExpectedResults The test completes creating multiple threads and tests |
|
506 multi-client interaction with the backup server. |
|
507 |
|
508 */ |
|
509 void CT_BackupStep::testMultipleClientsL() |
|
510 { |
|
511 const TInt KNumMultipleThreads=1; |
|
512 _LIT(KMultiThreadBaseName,"Multithread"); |
|
513 const TInt KBackupServerStackSize =0x3000; // 16k |
|
514 CBackupTestThreadParams Params; |
|
515 Params.Step = this; |
|
516 for(TInt i=0;i<KNumMultipleThreads;i++) |
|
517 { |
|
518 CThreadLaunchCounter* threadCounter = new(ELeave) CThreadLaunchCounter; |
|
519 CleanupStack::PushL(threadCounter); |
|
520 RThread thread; |
|
521 TBuf<0x100> name(KMultiThreadBaseName); |
|
522 name.AppendNum(i); |
|
523 TInt64 theSeed = 12312312; |
|
524 Params.seed=Math::Rand(theSeed); |
|
525 User::LeaveIfError(thread.Create(name, BackupMultipleTestThreadEntry, KBackupServerStackSize, NULL, &Params)); |
|
526 thread.Resume(); |
|
527 thread.Logon(threadCounter->iStatus); |
|
528 threadCounter->Start(); |
|
529 thread.Close(); |
|
530 } |
|
531 User::After(2000000); |
|
532 CActiveScheduler::Start();//runs until all the CThreadLaunchCounter are completed |
|
533 User::After(2000000); |
|
534 CleanupStack::Pop(KNumMultipleThreads); |
|
535 } |
|
536 |
|
537 |
|
538 |
|
539 TRequestStatus CT_BackupStep::testExtraRestartLockedOutL() |
|
540 // |
|
541 // Tests that we are only able to restart the apps once - no extra threads around! |
|
542 // |
|
543 { |
|
544 //vm |
|
545 const TBackupOperationAttributes gEventStart(MBackupObserver::EReleaseLockNoAccess, MBackupOperationObserver::EStart); |
|
546 gWrapper->NotifyBackupOperationL(gEventStart); |
|
547 //vm |
|
548 _LIT(KAppRestarterThreadName,"AppRestarterThread"); |
|
549 TRequestStatus status; |
|
550 gWrapper->CloseAll(MBackupObserver::EReleaseLockNoAccess, status); |
|
551 User::WaitForRequest(status); |
|
552 ///vm |
|
553 if(status != KErrNone) |
|
554 { |
|
555 return status; |
|
556 } |
|
557 |
|
558 const TBackupOperationAttributes gEventEnd(MBackupObserver::ETakeLock, MBackupOperationObserver::EEnd); |
|
559 gWrapper->NotifyBackupOperationL(gEventEnd); |
|
560 //// |
|
561 |
|
562 gWrapper->RestartAll(); |
|
563 gWrapper->RestartAll(); |
|
564 gWrapper->RestartAll(); |
|
565 gWrapper->RestartAll(); |
|
566 |
|
567 TInt err; |
|
568 err=KErrNone; |
|
569 TFullName name; |
|
570 TFindThread find(KAppRestarterThreadName); |
|
571 err=find.Next(name); |
|
572 if(err==KErrNotFound) |
|
573 { |
|
574 INFO_PRINTF1(_L("Error in test code timing - need to try again\n")); |
|
575 |
|
576 return status; |
|
577 } |
|
578 gWrapper->RestartAll(); |
|
579 gWrapper->RestartAll(); |
|
580 |
|
581 RThread thread; |
|
582 err=thread.Open(name); |
|
583 TInt ignoreId = thread.Id(); |
|
584 if(err==KErrNotFound) |
|
585 { |
|
586 INFO_PRINTF1(_L("Error in test code timing - need to try again\n")); |
|
587 return status; |
|
588 } |
|
589 thread.Logon(status); |
|
590 User::WaitForRequest(status); |
|
591 thread.Close(); |
|
592 |
|
593 TFindThread find1(KAppRestarterThreadName); |
|
594 while( (err=find1.Next(name)) != KErrNotFound) |
|
595 { |
|
596 RThread thread; |
|
597 if(thread.Open(name)==KErrNone) |
|
598 { |
|
599 TInt id=thread.Id(); |
|
600 TEST(id == ignoreId); |
|
601 thread.Close(); |
|
602 } |
|
603 } |
|
604 return status; |
|
605 } |
|
606 |
|
607 |
|
608 /** |
|
609 @SYMTestCaseID T-BackupStep-testRestartAppsL |
|
610 |
|
611 @SYMPREQ |
|
612 |
|
613 @SYMTestCaseDesc Test whether CBaBackupSessionWrapper::RestartAll() unlocks |
|
614 file locks (MBackupObserver::ETakeLock flag) for the |
|
615 registered files locked by CloseAll(). |
|
616 |
|
617 @SYMTestPriority High |
|
618 |
|
619 @SYMTestStatus Implemented |
|
620 |
|
621 @SYMTestActions Call TFindThread::Next() continuously to find all threads and |
|
622 append id of each of these threads to a list. |
|
623 Call CBaBackupSessionWrapper::CloseAll() to close all non-system |
|
624 applications and call all observers to release or stop writing to the |
|
625 registered files. Call CBaBackupSessionWrapper::RestartAll(). |
|
626 Call TFindThread::Next() continuously to find all threads. Compare the id |
|
627 of each thread to the id stored in the list to find a match.\n |
|
628 API Calls:\n |
|
629 CBaBackupSessionWrapper::RestartAll()\n |
|
630 CBaBackupSessionWrapper::CloseAll(MBackupObserver::TFileLockFlags aFlags, TRequestStatus& aStatus)\n |
|
631 |
|
632 @SYMTestExpectedResults Test that CBaBackupSessionWrapper::RestartAll() take |
|
633 back file locks (MBackupObserver::ETakeLock flag) for the registered files |
|
634 locked by CloseAll(). |
|
635 |
|
636 */ |
|
637 void CT_BackupStep::testRestartAppsL() |
|
638 { |
|
639 //vm |
|
640 const TBackupOperationAttributes gEventStart(MBackupObserver::EReleaseLockNoAccess, MBackupOperationObserver::EStart); |
|
641 gWrapper->NotifyBackupOperationL(gEventStart); |
|
642 //vm |
|
643 |
|
644 TFindThread find; |
|
645 INFO_PRINTF1(_L("\nRestartApps.......")); |
|
646 TFullName name; |
|
647 RArray<TInt> idArray; |
|
648 CleanupClosePushL(idArray); |
|
649 while(find.Next(name)!=KErrNotFound) |
|
650 { |
|
651 INFO_PRINTF1(_L("\nAppending thread id.......")); |
|
652 RThread thread; |
|
653 thread.Open(name); |
|
654 TInt id=thread.Id(); |
|
655 idArray.Append(id); |
|
656 thread.Close(); |
|
657 INFO_PRINTF1(_L("\nCompleted.")); |
|
658 } |
|
659 |
|
660 INFO_PRINTF1(_L("\nGWrapper: Close all.......")); |
|
661 TRequestStatus status; |
|
662 gWrapper->CloseAll(MBackupObserver::EReleaseLockNoAccess, status); |
|
663 |
|
664 User::WaitForRequest(status); |
|
665 |
|
666 INFO_PRINTF1(_L("\nWait.")); |
|
667 User::After(1000000); |
|
668 |
|
669 ///vm |
|
670 const TBackupOperationAttributes gEventEnd(MBackupObserver::ETakeLock, MBackupOperationObserver::EEnd); |
|
671 gWrapper->NotifyBackupOperationL(gEventEnd); |
|
672 |
|
673 //// |
|
674 |
|
675 INFO_PRINTF1(_L("\nGWrapper: Restart all.......")); |
|
676 gWrapper->RestartAll(); |
|
677 INFO_PRINTF1(_L("\nGWrapper: Restart all.....Completed")); |
|
678 INFO_PRINTF1(_L("\nGWrapper: Close all.......Completed.")); |
|
679 |
|
680 TFindThread find2; |
|
681 |
|
682 while(find2.Next(name)!=KErrNotFound) |
|
683 { |
|
684 // Create a thread in the calling process |
|
685 INFO_PRINTF1(_L("\nGet Thread ID.......")); |
|
686 RThread thread; |
|
687 thread.Open(name); |
|
688 TInt id=thread.Id(); |
|
689 thread.Close(); |
|
690 INFO_PRINTF1(_L("\nGet Thread ID......Completed.")); |
|
691 |
|
692 INFO_PRINTF1(_L("\nFind process ID in idArray")); |
|
693 if(idArray.Find(id)==KErrNone) |
|
694 { |
|
695 TInt temp =0; |
|
696 TEST(temp==0); // no instance of this thread is found |
|
697 } |
|
698 INFO_PRINTF1(_L("\nFind process ID in idArray.....Completed.")); |
|
699 } |
|
700 CleanupStack::PopAndDestroy(&idArray); //idArray |
|
701 |
|
702 |
|
703 INFO_PRINTF1(_L("\nRestartApps completed.")); |
|
704 } |
|
705 |
|
706 |
|
707 |
|
708 /** |
|
709 Auxiliary Fn for all Test Cases. |
|
710 |
|
711 The method initiates all the tests to be performed. |
|
712 |
|
713 */ |
|
714 void CT_BackupStep::doTestsL() |
|
715 { |
|
716 const TBackupOperationAttributes gEventEnd(MBackupObserver::ETakeLock, MBackupOperationObserver::EEnd); |
|
717 TRAPD(err,gWrapper=CBaBackupSessionWrapper::NewL()); |
|
718 if(err!=KErrNone) |
|
719 { |
|
720 INFO_PRINTF1(_L("Couldn't open session wrapper\n")); |
|
721 User::Leave(err); |
|
722 } |
|
723 INFO_PRINTF1(_L("Backup session test 1\n")); |
|
724 TRAP(err,gWrapper->NotifyBackupOperationL(gEventEnd)); |
|
725 if(err!=KErrNone) |
|
726 { |
|
727 INFO_PRINTF1(_L("Couldn't notify backup operation\n")); |
|
728 User::Leave(err); |
|
729 } |
|
730 |
|
731 FlushSchedulerQueueL(); |
|
732 testGetsCallbackOnBackupStartL(); |
|
733 |
|
734 gWrapper->NotifyBackupOperationL(gEventEnd); |
|
735 FlushSchedulerQueueL(); |
|
736 INFO_PRINTF1(_L("Backup session test 2\n")); |
|
737 testGetsCallbackOnBackupEndL(); |
|
738 |
|
739 gWrapper->NotifyBackupOperationL(gEventEnd); |
|
740 FlushSchedulerQueueL(); |
|
741 INFO_PRINTF1(_L("Backup session test 3\n")); |
|
742 testGetsCallbackOnBackupStartInSecondWrapperL(); |
|
743 |
|
744 gWrapper->NotifyBackupOperationL(gEventEnd); |
|
745 FlushSchedulerQueueL(); |
|
746 INFO_PRINTF1(_L("Backup session test 4\n")); |
|
747 testGetsCallbackOnBackupWrapperKillL(); |
|
748 |
|
749 gWrapper->NotifyBackupOperationL(gEventEnd); |
|
750 FlushSchedulerQueueL(); |
|
751 INFO_PRINTF1(_L("Backup session test 5\n")); |
|
752 testGetsCallbackOnBackupWrapperKillOtherL(); |
|
753 |
|
754 gWrapper->NotifyBackupOperationL(gEventEnd); |
|
755 FlushSchedulerQueueL(); |
|
756 INFO_PRINTF1(_L("Backup session test 6\n")); |
|
757 /*TRequestStatus status = testExtraRestartLockedOutL(); |
|
758 |
|
759 if(status=KErrNone) |
|
760 { |
|
761 gWrapper->NotifyBackupOperationL(gEventEnd); |
|
762 FlushSchedulerQueueL(); |
|
763 INFO_PRINTF1(_L("Backup session test 7\n")); |
|
764 testRestartAppsL(); |
|
765 |
|
766 gWrapper->NotifyBackupOperationL(gEventEnd); |
|
767 INFO_PRINTF1(_L("Backup session test 8\n")); |
|
768 testMultipleClientsL(); |
|
769 }*/ |
|
770 delete gWrapper; |
|
771 |
|
772 } |
|
773 |
|
774 |
|
775 /** |
|
776 Auxiliary Fn for Test Case ID T-BackupStep-testMultipleClientsL |
|
777 |
|
778 Entry point for the thread used to test multiple simultaneous wrapper |
|
779 sessions with the backup server. This method calls |
|
780 DoBackupMultipleTestThreadEntryL() method to perform this task.\n |
|
781 |
|
782 */ |
|
783 GLDEF_C TInt CT_BackupStep::BackupMultipleTestThreadEntry(TAny* aPtr) |
|
784 { |
|
785 CActiveScheduler* scheduler=new CActiveScheduler; |
|
786 if (!scheduler) |
|
787 return KErrNoMemory; |
|
788 CTrapCleanup* trapCleanup=CTrapCleanup::New(); |
|
789 if (!trapCleanup) |
|
790 { |
|
791 delete scheduler; |
|
792 return KErrNoMemory; |
|
793 } |
|
794 CActiveScheduler::Install(scheduler); |
|
795 |
|
796 CBackupTestThreadParams& threadParams = *(CBackupTestThreadParams*)aPtr; |
|
797 TRAPD(err,threadParams.Step->DoBackupMultipleTestThreadEntryL(/*aPtr*/)); |
|
798 |
|
799 delete CActiveScheduler::Current(); |
|
800 delete trapCleanup; |
|
801 return err; |
|
802 } |
|
803 |
|
804 |
|
805 /** |
|
806 Auxiliary Fn for Test Case ID T-BackupStep-testMultipleClientsL |
|
807 |
|
808 The method is called by the thread function BackupMultipleTestThreadEntry() |
|
809 to create a wrapper session to perform some backup operation.\n |
|
810 |
|
811 */ |
|
812 TInt CT_BackupStep::DoBackupMultipleTestThreadEntryL(/*TAny* aSeed*/) |
|
813 { |
|
814 const TBackupOperationAttributes gEventEnd(MBackupObserver::ETakeLock, MBackupOperationObserver::EEnd); |
|
815 CBaBackupSessionWrapper* wrapper=CBaBackupSessionWrapper::NewL(); |
|
816 CleanupStack::PushL(wrapper); |
|
817 |
|
818 CTestBackupOperationObserver* backupObserver = new(ELeave) CTestBackupOperationObserver(gEventEnd, Logger()); |
|
819 CleanupStack::PushL(backupObserver); |
|
820 wrapper->RegisterBackupOperationObserverL(*backupObserver); |
|
821 FlushSchedulerQueueL(); |
|
822 wrapper->NotifyBackupOperationL(gEventEnd); |
|
823 |
|
824 wrapper->DeRegisterBackupOperationObserver(*backupObserver); |
|
825 CleanupStack::PopAndDestroy(2);//backupObserver, wrapper |
|
826 return KErrNone; |
|
827 } |
|
828 |
|
829 |
|
830 /** |
|
831 Auxiliary Fn for entire Test Step |
|
832 |
|
833 This method creates and installs an active scheduler for tests. |
|
834 |
|
835 */ |
|
836 void CT_BackupStep::SetupSchedulerL() |
|
837 { |
|
838 testScheduler = new (ELeave) CActiveScheduler; |
|
839 CleanupStack::PushL( testScheduler ); |
|
840 CActiveScheduler::Install( testScheduler ); |
|
841 } |
|
842 |
|
843 /** |
|
844 Auxiliary Fn for entire Test Step |
|
845 |
|
846 This method removes the active scheduler from the cleanup stack and |
|
847 destroys it on completion of the tests. |
|
848 |
|
849 */ |
|
850 void CT_BackupStep::CloseScheduler() |
|
851 { |
|
852 CleanupStack::PopAndDestroy(); // Scheduler |
|
853 testScheduler = NULL; |
|
854 } |
|
855 |
|
856 //********************************** |
|
857 // Global |
|
858 //********************************** |
|
859 |
|
860 |
|
861 void CT_BackupStep::doMainL() |
|
862 { |
|
863 SetupSchedulerL(); |
|
864 doTestsL(); |
|
865 CloseScheduler(); |
|
866 } |
|
867 |
|
868 |
|
869 CT_BackupStep::~CT_BackupStep() |
|
870 /** |
|
871 Destructor |
|
872 */ |
|
873 { |
|
874 } |
|
875 |
|
876 CT_BackupStep::CT_BackupStep() |
|
877 /** |
|
878 Constructor |
|
879 */ |
|
880 { |
|
881 // Call base class method to set up the human readable name for logging |
|
882 SetTestStepName(KT_BackupStep); |
|
883 } |
|
884 |
|
885 TVerdict CT_BackupStep::doTestStepPreambleL() |
|
886 /** |
|
887 @return - TVerdict code |
|
888 Override of base class virtual |
|
889 */ |
|
890 { |
|
891 return TestStepResult(); |
|
892 } |
|
893 |
|
894 TVerdict CT_BackupStep::doTestStepPostambleL() |
|
895 /** |
|
896 @return - TVerdict code |
|
897 Override of base class virtual |
|
898 */ |
|
899 { |
|
900 return TestStepResult(); |
|
901 } |
|
902 |
|
903 |
|
904 TVerdict CT_BackupStep::doTestStepL() |
|
905 /** |
|
906 @return - TVerdict code |
|
907 Override of base class virtual |
|
908 */ |
|
909 { |
|
910 INFO_PRINTF1(_L("Testing Apparc...T_Backup")); |
|
911 // |
|
912 __UHEAP_MARK; |
|
913 TRAPD(ret,doMainL()); |
|
914 TEST(ret==KErrNone); |
|
915 __UHEAP_MARKEND; |
|
916 |
|
917 INFO_PRINTF1(_L("Test completed!")); |
|
918 return TestStepResult(); |
|
919 } |