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