|
1 // Copyright (c) 2004-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 #include <c32comm.h> |
|
17 #include <f32file.h> |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <e32test.h> |
|
21 #include <e32svr.h> |
|
22 #include <c32root.h> |
|
23 #include <e32property.h> |
|
24 |
|
25 #include "te_cntsyncadd.h" |
|
26 #include "te_cntsyncdelete.h" |
|
27 #include "te_cntsyncedit.h" |
|
28 #include "te_cntsyncfind.h" |
|
29 #include "te_cntsyncread.h" |
|
30 #include "te_cntsyncstress.h" |
|
31 #include "te_cntsyncbase.h" |
|
32 #include "te_cntsyncsync.h" |
|
33 #include "te_cntsyncutils.h" |
|
34 #include "te_cntsyncview.h" |
|
35 |
|
36 #include <e32property.h> |
|
37 |
|
38 |
|
39 const TInt KTestStringSize=30; |
|
40 typedef TBuf<KTestStringSize> TTestString; |
|
41 |
|
42 #if defined (__WINS__) |
|
43 #define PDD_NAME _L("ECDRV") |
|
44 #define LDD_NAME _L("ECOMM") |
|
45 #else |
|
46 #define PDD_NAME _L("EUART1") |
|
47 #define LDD_NAME _L("ECOMM") |
|
48 #endif |
|
49 |
|
50 #include "te_cntsyncbase.h" |
|
51 |
|
52 |
|
53 /** |
|
54 Instruct the PhBkSync server to configure to a 'Full' state |
|
55 by using the Secure Backup interface. This will cause the |
|
56 server to reconnect to ETel and SIMTSY. |
|
57 */ |
|
58 void CCntSyncTestStep::ConfigurePhbkSyncToFullL() |
|
59 { |
|
60 // |
|
61 // Ensure that the Secure Backup system does not currently think |
|
62 // it is performing a backup or restore. |
|
63 // |
|
64 iSecureBackupEngine->SetBURModeL(TDriveList(_L8("C")), |
|
65 EBURNormal, ENoBackup); |
|
66 |
|
67 // |
|
68 // Connect to the server to ensure that the server is running and |
|
69 // responding. |
|
70 // |
|
71 RPhoneBookSession phoneBookSession; |
|
72 RPhoneBookSession::TPhonebookSyncMode dummySyncMode; |
|
73 TInt ret; |
|
74 |
|
75 ret = phoneBookSession.Connect(); |
|
76 TESTCHECKL(ret, KErrNone); |
|
77 |
|
78 ret = KErrNotReady; |
|
79 while (ret != KErrNone) |
|
80 { |
|
81 ret = phoneBookSession.GetSyncMode(dummySyncMode); |
|
82 if (ret != KErrNone) |
|
83 { |
|
84 User::After(1); |
|
85 } |
|
86 } |
|
87 |
|
88 phoneBookSession.Close(); |
|
89 } // CCntSyncTestStep::ConfigurePhbkSyncToFullL |
|
90 |
|
91 |
|
92 /** |
|
93 Instruct the PhBkSync server to unconfigure to an 'Idle' state |
|
94 by using the Secure Backup interface. This will cause the |
|
95 server to disconnect from ETel and SIMTSY. This is effectively |
|
96 the same as shutting down the server, but can be performed on |
|
97 release versions. |
|
98 */ |
|
99 void CCntSyncTestStep::ConfigurePhbkSyncToIdleL() |
|
100 { |
|
101 // |
|
102 // Connect to the server to ensure that the server is running. |
|
103 // |
|
104 RPhoneBookSession phoneBookSession; |
|
105 TInt ret; |
|
106 |
|
107 ret = phoneBookSession.Connect(); |
|
108 TESTCHECKL(ret, KErrNone); |
|
109 |
|
110 // |
|
111 // Ensure that the Secure Backup system does not currently think |
|
112 // it is performing a backup or restore. |
|
113 // |
|
114 iSecureBackupEngine->SetBURModeL(TDriveList(_L8("C")), |
|
115 EBURBackupFull, EBackupBase); |
|
116 |
|
117 // |
|
118 // Check that the server is responding. |
|
119 // |
|
120 RPhoneBookSession::TPhonebookSyncMode dummySyncMode; |
|
121 |
|
122 ret = KErrNone; |
|
123 while (ret == KErrNone) |
|
124 { |
|
125 ret = phoneBookSession.GetSyncMode(dummySyncMode); |
|
126 if (ret == KErrNone) |
|
127 { |
|
128 User::After(1); |
|
129 } |
|
130 } |
|
131 |
|
132 phoneBookSession.Close(); |
|
133 } // CCntSyncTestStep::ConfigurePhbkSyncToIdleL |
|
134 |
|
135 |
|
136 /** |
|
137 * Set the synchronisation mode as aMode |
|
138 * @param aMode RPhoneBookSession::TPhonebookSyncMode enumeration |
|
139 */ |
|
140 void CCntSyncTestStep::SetSyncModeL(RPhoneBookSession::TPhonebookSyncMode aMode) |
|
141 { |
|
142 User::LeaveIfError(iSession.SetSyncMode(aMode)); |
|
143 User::LeaveIfError(iSession.SetSyncMode(aMode, KUidIccGlobalSdnPhonebook)); |
|
144 User::LeaveIfError(iSession.SetSyncMode(aMode, KUidIccGlobalLndPhonebook)); |
|
145 User::LeaveIfError(iSession.SetSyncMode(aMode, KUidUsimAppAdnPhonebook)); |
|
146 User::LeaveIfError(iSession.SetSyncMode(aMode, KUidIccGlobalFdnPhonebook)); |
|
147 } |
|
148 |
|
149 |
|
150 /** |
|
151 * Check the synchronisation mode is the same as aMode |
|
152 * @param aMode RPhoneBookSession::TPhonebookSyncMode enumeration |
|
153 */ |
|
154 void CCntSyncTestStep::CheckSyncModeL(RPhoneBookSession::TPhonebookSyncMode aMode) |
|
155 { |
|
156 RPhoneBookSession::TPhonebookSyncMode mode; |
|
157 User::LeaveIfError(iSession.GetSyncMode(mode)); |
|
158 TESTCHECK(mode, aMode); |
|
159 User::LeaveIfError(iSession.GetSyncMode(mode, KUidIccGlobalSdnPhonebook)); |
|
160 TESTCHECK(mode, aMode); |
|
161 User::LeaveIfError(iSession.GetSyncMode(mode, KUidIccGlobalLndPhonebook)); |
|
162 TESTCHECK(mode, aMode); |
|
163 User::LeaveIfError(iSession.GetSyncMode(mode, KUidUsimAppAdnPhonebook)); |
|
164 TESTCHECK(mode, aMode); |
|
165 User::LeaveIfError(iSession.GetSyncMode(mode, KUidIccGlobalFdnPhonebook)); |
|
166 TESTCHECK(mode, aMode); |
|
167 } |
|
168 |
|
169 |
|
170 /** |
|
171 * Check the synchronisation state is aStat |
|
172 * |
|
173 * @param aState An expected sync state enumeration value. |
|
174 */ |
|
175 void CCntSyncTestStep::CheckCacheStateL(RPhoneBookSession::TSyncState aState) |
|
176 { |
|
177 RPhoneBookSession::TSyncState state; |
|
178 TInt ret; |
|
179 |
|
180 ret = iSession.GetPhoneBookCacheState(state, KUidIccGlobalAdnPhonebook); |
|
181 if (ret != KErrNone && ret != KErrNotReady) |
|
182 { |
|
183 User::Leave(ret); |
|
184 } |
|
185 TESTCHECK(state, aState); |
|
186 |
|
187 ret = iSession.GetPhoneBookCacheState(state, KUidIccGlobalSdnPhonebook); |
|
188 if (ret != KErrNone && ret != KErrNotReady) |
|
189 { |
|
190 User::Leave(ret); |
|
191 } |
|
192 TESTCHECK(state, aState); |
|
193 |
|
194 ret = iSession.GetPhoneBookCacheState(state, KUidIccGlobalLndPhonebook); |
|
195 if (ret != KErrNone && ret != KErrNotReady) |
|
196 { |
|
197 User::Leave(ret); |
|
198 } |
|
199 TESTCHECK(state, aState); |
|
200 |
|
201 ret = iSession.GetPhoneBookCacheState(state, KUidUsimAppAdnPhonebook); |
|
202 if (ret != KErrNone && ret != KErrNotReady) |
|
203 { |
|
204 User::Leave(ret); |
|
205 } |
|
206 TESTCHECK(state, aState); |
|
207 |
|
208 ret = iSession.GetPhoneBookCacheState(state, KUidIccGlobalFdnPhonebook); |
|
209 if (ret != KErrNone && ret != KErrNotReady) |
|
210 { |
|
211 User::Leave(ret); |
|
212 } |
|
213 TESTCHECK(state, aState); |
|
214 } |
|
215 |
|
216 TVerdict CCntSyncTestStep::doTestStepPreambleL() |
|
217 { |
|
218 __UHEAP_MARK; //mark for memory leaks!! |
|
219 |
|
220 iScheduler=new(ELeave) CActiveScheduler; |
|
221 CActiveScheduler::Install(iScheduler); |
|
222 |
|
223 iSecureBackupEngine = CSBEClient::NewL(); |
|
224 iSecureBackupEngine->SetBURModeL(TDriveList(_L8("C")), |
|
225 EBURNormal, ENoBackup); |
|
226 |
|
227 TInt ret = iSession.Connect(); |
|
228 TESTCHECKL(ret, KErrNone); |
|
229 |
|
230 // |
|
231 // Open the existing database or create a new one. |
|
232 // |
|
233 TRAPD(err, iDb = OpenOrCreateContactDatabaseL()); |
|
234 TESTCHECKL(err, KErrNone); |
|
235 |
|
236 return TestStepResult() ; |
|
237 } |
|
238 |
|
239 TVerdict CCntSyncTestStep::doTestStepPostambleL() |
|
240 { |
|
241 delete iDb; |
|
242 iDb=NULL; |
|
243 |
|
244 iSession.Close(); |
|
245 |
|
246 delete iSecureBackupEngine; |
|
247 iSecureBackupEngine = NULL; |
|
248 |
|
249 delete iScheduler; |
|
250 iScheduler = NULL; |
|
251 |
|
252 __UHEAP_MARKEND; |
|
253 |
|
254 return TestStepResult() ; |
|
255 } |
|
256 |
|
257 |
|
258 /** |
|
259 * Set the SIM TSY test number to run |
|
260 * |
|
261 */ |
|
262 void CCntSyncTestStep::SetSimTsyTestNumberL(TInt aTestNumber) |
|
263 { |
|
264 RProperty testNumberProperty; |
|
265 User::LeaveIfError(testNumberProperty.Attach(KUidPSSimTsyCategory, KPSSimTsyTestNumber)); |
|
266 CleanupClosePushL(testNumberProperty); |
|
267 |
|
268 TRequestStatus status; |
|
269 testNumberProperty.Subscribe(status); |
|
270 User::LeaveIfError(testNumberProperty.Set(KUidPSSimTsyCategory,KPSSimTsyTestNumber,aTestNumber)); |
|
271 User::WaitForRequest(status); |
|
272 User::LeaveIfError(status.Int()); |
|
273 TInt testNumberCheck; |
|
274 User::LeaveIfError(testNumberProperty.Get(testNumberCheck)); |
|
275 if (aTestNumber != testNumberCheck) |
|
276 { |
|
277 User::Leave(KErrNotFound); |
|
278 } |
|
279 |
|
280 CleanupStack::PopAndDestroy(&testNumberProperty); |
|
281 |
|
282 delete iDb; |
|
283 iDb=NULL; |
|
284 |
|
285 iSession.Close(); |
|
286 |
|
287 // |
|
288 // Ensure that the server resets its configuration.... |
|
289 // |
|
290 ConfigurePhbkSyncToIdleL(); |
|
291 ConfigurePhbkSyncToFullL(); |
|
292 |
|
293 iDb = OpenOrCreateContactDatabaseL(); |
|
294 |
|
295 User::LeaveIfError(iSession.Connect()); |
|
296 |
|
297 // Ensure that the test number has been set properly |
|
298 RProperty testNumberInUseProperty; |
|
299 User::LeaveIfError(testNumberInUseProperty.Attach(KUidPSSimTsyCategory, KPSSimTsyTestNumberInUse)); |
|
300 CleanupClosePushL(testNumberInUseProperty); |
|
301 |
|
302 TInt testNumberInUseCheck; |
|
303 User::LeaveIfError(testNumberInUseProperty.Get(KUidPSSimTsyCategory, KPSSimTsyTestNumberInUse,testNumberInUseCheck)); |
|
304 TESTCHECKL(aTestNumber,testNumberInUseCheck); |
|
305 |
|
306 CleanupStack::PopAndDestroy(&testNumberInUseProperty); |
|
307 |
|
308 } // CCntSyncTestStep::SetSimTsyTestNumberL |
|
309 |
|
310 |
|
311 /** |
|
312 * Publish a new value to indicate that test has finished and simtsy timer can now stop. |
|
313 * |
|
314 */ |
|
315 void CCntSyncTestStep::SignalSimTsyToReduceTimersL() |
|
316 { |
|
317 RProperty reduceTimersProperty; |
|
318 User::LeaveIfError(reduceTimersProperty.Attach(KUidPSSimTsyCategory, KPSSimTsyTimersReduceTime)); |
|
319 CleanupClosePushL(reduceTimersProperty); |
|
320 |
|
321 User::LeaveIfError(reduceTimersProperty.Set(KUidPSSimTsyCategory, KPSSimTsyTimersReduceTime, |
|
322 KReduceSimTsyTimers)); |
|
323 |
|
324 CleanupStack::PopAndDestroy(&reduceTimersProperty); |
|
325 } |
|
326 |
|
327 |
|
328 /** |
|
329 * Opens the Contacts Database, allowing for errors if the database exists |
|
330 * or is not found. The function will retry where appropriate. |
|
331 * |
|
332 * @return Pointer to opened database. |
|
333 */ |
|
334 CContactDatabase* CCntSyncTestStep::OpenOrCreateContactDatabaseL() |
|
335 { |
|
336 CContactDatabase* db = NULL; |
|
337 |
|
338 // |
|
339 // 10 attempts at opening the Contacts DB... |
|
340 // |
|
341 TInt retryCount = 10; |
|
342 |
|
343 while (retryCount > 0) |
|
344 { |
|
345 TRAPD(err, db = CContactDatabase::OpenL()); |
|
346 if (err == KErrNone) |
|
347 { |
|
348 return db; |
|
349 } |
|
350 else if (err == KErrNotFound) |
|
351 { |
|
352 TRAP(err, db = CContactDatabase::CreateL()); |
|
353 if (err == KErrNone) |
|
354 { |
|
355 return db; |
|
356 } |
|
357 } |
|
358 |
|
359 // |
|
360 // If this is the last attempt then give up... |
|
361 // |
|
362 if (retryCount == 0) |
|
363 { |
|
364 User::Leave(err); |
|
365 } |
|
366 |
|
367 // |
|
368 // Wait a short time and retry... |
|
369 // |
|
370 User::After(1000000); |
|
371 retryCount--; |
|
372 } |
|
373 |
|
374 return db; |
|
375 } // CCntSyncTestStep::OpenOrCreateContactDatabaseL |
|
376 |
|
377 |
|
378 /** Do a manual synchronisation */ |
|
379 void CCntSyncTestStep::DoSyncL() |
|
380 { |
|
381 // Global ADN Phonebook |
|
382 TRequestStatus status; |
|
383 iSession.DoSynchronisation(status); |
|
384 User::WaitForRequest(status); |
|
385 TESTCHECKL(status.Int(), KErrNone); |
|
386 |
|
387 // Global SDN Phonebook |
|
388 iSession.DoSynchronisation(status, KUidIccGlobalSdnPhonebook); |
|
389 User::WaitForRequest(status); |
|
390 TESTCHECKL(status.Int(), KErrNone); |
|
391 |
|
392 // Global LND Phonebook |
|
393 iSession.DoSynchronisation(status, KUidIccGlobalLndPhonebook); |
|
394 User::WaitForRequest(status); |
|
395 TESTCHECKL(status.Int(), KErrNone); |
|
396 |
|
397 // Usim App ADN Phonebook |
|
398 iSession.DoSynchronisation(status, KUidUsimAppAdnPhonebook); |
|
399 User::WaitForRequest(status); |
|
400 TESTCHECKL(status.Int(), KErrNone); |
|
401 |
|
402 // Global FDN Phonebook |
|
403 iSession.DoSynchronisation(status, KUidIccGlobalFdnPhonebook); |
|
404 User::WaitForRequest(status); |
|
405 TESTCHECKL(status.Int(), KErrNone); |
|
406 } |
|
407 |
|
408 /** Do a manual synchronisation, but without checking for a succeess. This mehtod can |
|
409 * be used to test DoSync failures. |
|
410 */ |
|
411 void CCntSyncTestStep::DoSyncFailL() |
|
412 { |
|
413 TRequestStatus status; |
|
414 iSession.DoSynchronisation(status, KUidIccGlobalAdnPhonebook); |
|
415 User::WaitForRequest(status); |
|
416 //If status is KErrNone then view has already been created so, sync |
|
417 //will not fail with access denied so no point in continuing with the test |
|
418 if(status.Int() == KErrNone) |
|
419 { |
|
420 User::Leave(KErrGeneral); |
|
421 } |
|
422 TESTCHECKL(status.Int(), KErrAccessDenied); |
|
423 |
|
424 // Global SDN Phonebook |
|
425 iSession.DoSynchronisation(status, KUidIccGlobalSdnPhonebook); |
|
426 User::WaitForRequest(status); |
|
427 //If status is KErrNone then view has already been created so, sync |
|
428 //will not fail with access denied so no point in continuing with the test |
|
429 if(status.Int() == KErrNone) |
|
430 { |
|
431 User::Leave(KErrGeneral); |
|
432 } |
|
433 TESTCHECKL(status.Int(), KErrAccessDenied); |
|
434 |
|
435 // Global LND Phonebook |
|
436 iSession.DoSynchronisation(status, KUidIccGlobalLndPhonebook); |
|
437 User::WaitForRequest(status); |
|
438 //If status is KErrNone then view has already been created so, sync |
|
439 //will not fail with access denied so no point in continuing with the test |
|
440 if(status.Int() == KErrNone) |
|
441 { |
|
442 User::Leave(KErrGeneral); |
|
443 } |
|
444 TESTCHECKL(status.Int(), KErrAccessDenied); |
|
445 |
|
446 // Usim App ADN Phonebook |
|
447 iSession.DoSynchronisation(status, KUidUsimAppAdnPhonebook); |
|
448 User::WaitForRequest(status); |
|
449 //If status is KErrNone then view has already been created so, sync |
|
450 //will not fail with access denied so no point in continuing with the test |
|
451 if(status.Int() == KErrNone) |
|
452 { |
|
453 User::Leave(KErrGeneral); |
|
454 } |
|
455 TESTCHECKL(status.Int(), KErrAccessDenied); |
|
456 |
|
457 // Global FDN Phonebook |
|
458 iSession.DoSynchronisation(status, KUidIccGlobalFdnPhonebook); |
|
459 User::WaitForRequest(status); |
|
460 //If status is KErrNone then view has already been created so, sync |
|
461 //will not fail with access denied so no point in continuing with the test |
|
462 if(status.Int() == KErrNone) |
|
463 { |
|
464 User::Leave(KErrGeneral); |
|
465 } |
|
466 TESTCHECKL(status.Int(), KErrAccessDenied); |
|
467 } |
|
468 |
|
469 void CCntSyncTestStep::WaitForSyncToCompleteL() |
|
470 /** |
|
471 * Wait for all phonebooks to become syncronised. The phonebooks checked are ADN, SDN, |
|
472 * LND, USIM ADN and FDN. |
|
473 */ { |
|
474 RPhoneBookSession::TSyncState iccAdnState, iccSdnState, iccLndState; |
|
475 RPhoneBookSession::TSyncState usimAdnState, iccFdnState; |
|
476 |
|
477 // |
|
478 // Initial check and setup of variables... |
|
479 // |
|
480 TInt ret; |
|
481 |
|
482 ret = iSession.GetPhoneBookCacheState(iccAdnState, KUidIccGlobalAdnPhonebook); |
|
483 if (ret != KErrNone && ret != KErrNotReady) |
|
484 { |
|
485 User::Leave(ret); |
|
486 } |
|
487 ret = iSession.GetPhoneBookCacheState(iccSdnState, KUidIccGlobalSdnPhonebook); |
|
488 if (ret != KErrNone && ret != KErrNotReady) |
|
489 { |
|
490 User::Leave(ret); |
|
491 } |
|
492 ret = iSession.GetPhoneBookCacheState(iccLndState, KUidIccGlobalLndPhonebook); |
|
493 if (ret != KErrNone && ret != KErrNotReady) |
|
494 { |
|
495 User::Leave(ret); |
|
496 } |
|
497 ret = iSession.GetPhoneBookCacheState(usimAdnState, KUidUsimAppAdnPhonebook); |
|
498 if (ret != KErrNone && ret != KErrNotReady) |
|
499 { |
|
500 User::Leave(ret); |
|
501 } |
|
502 ret = iSession.GetPhoneBookCacheState(iccFdnState, KUidIccGlobalFdnPhonebook); |
|
503 if (ret != KErrNone && ret != KErrNotReady) |
|
504 { |
|
505 User::Leave(ret); |
|
506 } |
|
507 |
|
508 // |
|
509 // Wait if needed, checking every 1 second... |
|
510 // |
|
511 while (iccAdnState != RPhoneBookSession::ECacheValid || |
|
512 iccSdnState != RPhoneBookSession::ECacheValid || |
|
513 iccLndState != RPhoneBookSession::ECacheValid || |
|
514 usimAdnState != RPhoneBookSession::ECacheValid || |
|
515 iccFdnState != RPhoneBookSession::ECacheValid) |
|
516 { |
|
517 User::After(1000000); |
|
518 ret = iSession.GetPhoneBookCacheState(iccAdnState, KUidIccGlobalAdnPhonebook); |
|
519 if (ret != KErrNone && ret != KErrNotReady) |
|
520 { |
|
521 User::Leave(ret); |
|
522 } |
|
523 ret = iSession.GetPhoneBookCacheState(iccSdnState, KUidIccGlobalSdnPhonebook); |
|
524 if (ret != KErrNone && ret != KErrNotReady) |
|
525 { |
|
526 User::Leave(ret); |
|
527 } |
|
528 ret = iSession.GetPhoneBookCacheState(iccLndState, KUidIccGlobalLndPhonebook); |
|
529 if (ret != KErrNone && ret != KErrNotReady) |
|
530 { |
|
531 User::Leave(ret); |
|
532 } |
|
533 ret = iSession.GetPhoneBookCacheState(usimAdnState, KUidUsimAppAdnPhonebook); |
|
534 if (ret != KErrNone && ret != KErrNotReady) |
|
535 { |
|
536 User::Leave(ret); |
|
537 } |
|
538 ret = iSession.GetPhoneBookCacheState(iccFdnState, KUidIccGlobalFdnPhonebook); |
|
539 if (ret != KErrNone && ret != KErrNotReady) |
|
540 { |
|
541 User::Leave(ret); |
|
542 } |
|
543 } |
|
544 } |