|
1 // Copyright (c) 2001-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 "TE_PhBkSyncBase.h" |
|
17 |
|
18 // all test step header files |
|
19 #include "TestOpenSteps.h" |
|
20 #include "TestConnectSteps.h" |
|
21 #include "TestDeleteContactSteps.h" |
|
22 #include "TestDoSynchronisationSteps.h" |
|
23 #include "TestGetContactFormatSteps.h" |
|
24 #include "TestGetSyncModeSteps.h" |
|
25 #include "TestOtherSteps.h" |
|
26 #include "TestSetSyncModeSteps.h" |
|
27 #include "TestValidateContactSteps.h" |
|
28 #include "TestVersionSteps.h" |
|
29 #include "TestWriteContactSteps.h" |
|
30 #include "TestReadingIniFile.h" |
|
31 |
|
32 |
|
33 |
|
34 CTestStepPhbkSync::CTestStepPhbkSync() |
|
35 { |
|
36 |
|
37 iUidIccGlobalAdnPhonebookCallByRef = KUidIccGlobalAdnPhonebook; |
|
38 iUidIccGlobalSdnPhonebookCallByRef = KUidIccGlobalSdnPhonebook; |
|
39 iUidIccGlobalLndPhonebookCallByRef = KUidIccGlobalLndPhonebook; |
|
40 iUidUsimAppAdnPhonebookCallByRef = KUidUsimAppAdnPhonebook; |
|
41 iUidIccGlobalFdnPhonebookCallByRef = KUidIccGlobalFdnPhonebook; |
|
42 |
|
43 iPhoneBook[0] = KUidIccGlobalAdnPhonebook; |
|
44 iPhoneBook[1] = KUidIccGlobalSdnPhonebook; |
|
45 iPhoneBook[2] = KUidIccGlobalLndPhonebook; |
|
46 iPhoneBook[3] = KUidUsimAppAdnPhonebook; |
|
47 iPhoneBook[4] = KUidIccGlobalFdnPhonebook; |
|
48 } |
|
49 |
|
50 |
|
51 /** |
|
52 * Deletes the PhBkSync INI file. |
|
53 */ |
|
54 void CTestStepPhbkSync::DestroyDefaultIniFileL() |
|
55 { |
|
56 // Delete contacts database and phonebook sync ini file |
|
57 RFs fs; |
|
58 User::LeaveIfError(fs.Connect()); // Connect to File server |
|
59 CleanupClosePushL(fs); |
|
60 TInt err(fs.Delete(KPhbkSyncIniFile)); // Delete PhBkSync.INI file |
|
61 if(!(err == KErrNone || err == KErrNotFound || err == KErrPathNotFound)) // Deleted successfully OR no default INI file |
|
62 User::Leave(err); |
|
63 CleanupStack::PopAndDestroy(); // fs |
|
64 } |
|
65 |
|
66 |
|
67 /** |
|
68 * Deletes the Contacts Database and the PhBkSync INI file. |
|
69 */ |
|
70 void CTestStepPhbkSync::DestroyDefaultFilesL() |
|
71 { |
|
72 // Delete contacts database and phonebook sync ini file |
|
73 RFs fs; |
|
74 User::LeaveIfError(fs.Connect()); // Connect to File server |
|
75 TInt err(fs.Delete(KPhbkSyncIniFile)); // Delete PhBkSync.INI fileNI file |
|
76 if(!(err == KErrNone || err == KErrNotFound || err == KErrPathNotFound )) // Deleted successfully OR no default INI file |
|
77 User::Leave(err); |
|
78 TRAP(err,CContactDatabase::DeleteDefaultFileL()); // Delete default ContactsDb |
|
79 if(!(err == KErrNone || err == KErrNotFound)) // Deleted successfully OR no default INI file |
|
80 User::Leave(err); |
|
81 } |
|
82 |
|
83 |
|
84 TVerdict CTestStepPhbkSync::doTestStepPreambleL() |
|
85 { |
|
86 __UHEAP_MARK; |
|
87 |
|
88 iScheduler = new(ELeave) CActiveScheduler; |
|
89 CActiveScheduler::Install(iScheduler); |
|
90 |
|
91 iSecureBackupEngine = CSBEClient::NewL(); |
|
92 |
|
93 TInt ret = iSession.Connect(); |
|
94 TESTCHECKL(ret, KErrNone); |
|
95 |
|
96 return TestStepResult(); |
|
97 } |
|
98 |
|
99 TVerdict CTestStepPhbkSync::doTestStepPostambleL() |
|
100 { |
|
101 iSession.Close(); |
|
102 |
|
103 delete iSecureBackupEngine; |
|
104 iSecureBackupEngine = NULL; |
|
105 |
|
106 delete iScheduler; |
|
107 iScheduler = NULL; |
|
108 |
|
109 __UHEAP_MARKEND; |
|
110 |
|
111 return TestStepResult(); |
|
112 } |
|
113 |
|
114 /** |
|
115 * Change the synchronisation mode for the given phone book. |
|
116 */ |
|
117 void CTestStepPhbkSync::ChangeSyncModeL(RPhoneBookSession::TPhonebookSyncMode aMode, TUid aPhonebookUid) |
|
118 { |
|
119 User::LeaveIfError(iSession.SetSyncMode(aMode, aPhonebookUid)); |
|
120 } |
|
121 |
|
122 /** |
|
123 * Check the synchronisation mode is the same as aMode for given phone book. |
|
124 */ |
|
125 void CTestStepPhbkSync::CheckSyncModeL(RPhoneBookSession::TPhonebookSyncMode aMode, TUid aPhonebookUid) |
|
126 { |
|
127 RPhoneBookSession::TPhonebookSyncMode mode; |
|
128 User::LeaveIfError(iSession.GetSyncMode(mode, aPhonebookUid)); |
|
129 TESTCHECK(mode, aMode); |
|
130 } |
|
131 |
|
132 void CTestStepPhbkSync::CheckCacheStateValidL(TUid aPhonebookUid) |
|
133 { |
|
134 RPhoneBookSession::TSyncState state; |
|
135 TInt ret; |
|
136 |
|
137 ret = iSession.GetPhoneBookCacheState(state, aPhonebookUid); |
|
138 while (ret != KErrNone || state == RPhoneBookSession::EUnsynchronised) |
|
139 { |
|
140 User::After(KOneSeconduS); // Wait until cache becomes usable |
|
141 |
|
142 ret = iSession.GetPhoneBookCacheState(state, aPhonebookUid); |
|
143 } |
|
144 |
|
145 // Cache now in valid state |
|
146 TESTCHECKL(state, RPhoneBookSession::ECacheValid); |
|
147 } |
|
148 |
|
149 void CTestStepPhbkSync::CheckCacheStateInvalidL(TUid aPhonebookUid) |
|
150 { |
|
151 User::After(3000000); // Delay is needed to prove that synchronisation has not been carried out |
|
152 RPhoneBookSession::TSyncState state; |
|
153 TInt ret; |
|
154 |
|
155 ret = iSession.GetPhoneBookCacheState(state, aPhonebookUid); |
|
156 if (ret == KErrNone) |
|
157 { |
|
158 TESTCHECKL(state, RPhoneBookSession::EUnsynchronised); |
|
159 } |
|
160 } |
|
161 |
|
162 void CTestStepPhbkSync::CheckCacheStateErrorL(TUid aPhonebookUid) |
|
163 { |
|
164 User::After(3000000); // Delay is needed to prove that synchronisation has not been carried out |
|
165 RPhoneBookSession::TSyncState state; |
|
166 TInt ret; |
|
167 |
|
168 ret = iSession.GetPhoneBookCacheState(state, aPhonebookUid); |
|
169 if (ret == KErrNone) |
|
170 { |
|
171 TESTCHECKL(state, RPhoneBookSession::EErrorDuringSync); |
|
172 } |
|
173 } |
|
174 |
|
175 void CTestStepPhbkSync::WaitForIccToBecomeLockedL() |
|
176 { |
|
177 TContactItemId validContactId; |
|
178 validContactId = GetValidUIDFromContactsDbL(KUidIccGlobalAdnPhonebook); |
|
179 TESTCHECKCONDITIONL(validContactId != KNullContactId); |
|
180 |
|
181 // Wait for ICC to become locked |
|
182 TInt result = KErrNone; |
|
183 result = iSession.ValidateContact(MContactSynchroniser::ERead, validContactId); |
|
184 while (result != KErrAccessDenied) |
|
185 { |
|
186 result = iSession.ValidateContact(MContactSynchroniser::ERead, validContactId); |
|
187 User::After(1000000); |
|
188 } |
|
189 TESTCHECKL(result, KErrAccessDenied); |
|
190 } |
|
191 |
|
192 /** |
|
193 * Convert the given phonebookUid into its corresponding EnumId used |
|
194 * used by phonebook internally. |
|
195 */ |
|
196 MyCSyncContactICCEntry::TSyncPhoneBook CTestStepPhbkSync::convertPhonebookUid2Enum(TUid aPhonebookUid) |
|
197 { |
|
198 if (aPhonebookUid == KUidIccGlobalAdnPhonebook) |
|
199 return MyCSyncContactICCEntry::EIccGlobalAdnPhonebook; |
|
200 else if (aPhonebookUid == KUidIccGlobalSdnPhonebook) |
|
201 return MyCSyncContactICCEntry::EIccGlobalSdnPhonebook; |
|
202 else if (aPhonebookUid == KUidIccGlobalLndPhonebook) |
|
203 return MyCSyncContactICCEntry::EIccGlobalLndPhonebook; |
|
204 else if (aPhonebookUid == KUidUsimAppAdnPhonebook) |
|
205 return MyCSyncContactICCEntry::EUsimAppAdnPhonebook; |
|
206 else if (aPhonebookUid == KUidIccGlobalFdnPhonebook) |
|
207 return MyCSyncContactICCEntry::EIccGlobalFdnPhonebook; |
|
208 else |
|
209 return MyCSyncContactICCEntry::EIccGlobalAdnPhonebook; |
|
210 } |
|
211 |
|
212 void CTestStepPhbkSync::DoWriteContactToICCL(MyCSyncContactICCEntry* aIccEntryInternal, |
|
213 TUid& aPhonebook, |
|
214 TRequestStatus& aStatus, |
|
215 RPhoneBookSession* aSession) |
|
216 { |
|
217 // to get the template associated with the given phonebook |
|
218 // Use the contacts model API to get the template ID rather than |
|
219 // the RPhonebookSession as this is how it is going to be done in reality |
|
220 CContactDatabase *iDb = NULL; |
|
221 TRAPD(err,iDb = CContactDatabase::OpenL()); // open existing database |
|
222 CleanupStack::PushL(iDb); |
|
223 CContactItem* iccTemplate = NULL; |
|
224 |
|
225 TESTCHECKL(err, KErrNone); |
|
226 |
|
227 if (err == KErrNone) |
|
228 { |
|
229 TContactItemId templateId = iDb->ICCTemplateIdL(aPhonebook); |
|
230 iccTemplate = iDb->ReadContactL(templateId); |
|
231 } |
|
232 CleanupStack::PopAndDestroy(); // iDb |
|
233 CleanupStack::PushL(iccTemplate); |
|
234 |
|
235 // Create an ICC (exteranl format) entry |
|
236 CContactICCEntry* iccEntryExternal; |
|
237 |
|
238 // If an overwrite is being attempted then ensure an entry with relevant UID is used |
|
239 if (aIccEntryInternal->iContactUID > 0) |
|
240 { |
|
241 TContactItemId realId(GetValidUIDFromContactsDbL(aPhonebook, EFalse)); |
|
242 iccEntryExternal = static_cast<CContactICCEntry*> (iDb->ReadContactL(realId)); |
|
243 } |
|
244 else |
|
245 { |
|
246 iccEntryExternal = CContactICCEntry::NewL(*iccTemplate); // Create an ICC entry |
|
247 } |
|
248 CleanupStack::PopAndDestroy(); // iccTemplate |
|
249 CleanupStack::PushL(iccEntryExternal); |
|
250 |
|
251 |
|
252 // Create phone number field |
|
253 if(aIccEntryInternal->iNumber.Length() != KErrNone) |
|
254 { |
|
255 TBuf<RMobilePhone::KMaxMobileTelNumberSize> number; |
|
256 |
|
257 if(aIccEntryInternal->iTON==RMobilePhone::EInternationalNumber) |
|
258 { |
|
259 // Append '+' prefix if International Number |
|
260 number.Append(KInternationalPrefix); |
|
261 } |
|
262 number.Append(aIccEntryInternal->iNumber); |
|
263 AddTextFieldToIccContactL(KStorageTypeText, |
|
264 KUidContactFieldPhoneNumber, |
|
265 KUidContactFieldVCardMapTEL, |
|
266 number, |
|
267 iccEntryExternal, |
|
268 0); // 0 means the first instance |
|
269 } |
|
270 |
|
271 // Check whether this is hidden entry and set its hidden attributes |
|
272 if(aIccEntryInternal->iIsHidden) |
|
273 { |
|
274 iccEntryExternal->SetHidden(ETrue); |
|
275 } |
|
276 |
|
277 // Additional numbers |
|
278 TInt count(aIccEntryInternal->iNumberList->Count()); |
|
279 TInt i(0); |
|
280 for(i=0; i<count; ++i) |
|
281 { |
|
282 MyCSyncContactICCEntry::TSyncAdditionalNumber additionalNum(aIccEntryInternal->iNumberList->At(i)); |
|
283 |
|
284 /***** |
|
285 // Add additional number alpha string |
|
286 TBuf<CSyncContactICCEntry::KMaxPhBkNameSize> numberString; |
|
287 numberString.Copy(additionalNum.iNumberString); |
|
288 AddTextFieldToIccContactL(KStorageTypeText, KUidContactFieldSecondName, KUidContactFieldVCardMapUnusedN, numberString, iccEntryExternal,i); |
|
289 *****/ |
|
290 // Actual number |
|
291 TBuf<RMobilePhone::KMaxMobileTelNumberSize> number; |
|
292 if(additionalNum.iTON==RMobilePhone::EInternationalNumber) |
|
293 { |
|
294 number.Append(KInternationalPrefix); // Append '+' prefix if International Number |
|
295 } |
|
296 number.Append(additionalNum.iNumber); |
|
297 AddTextFieldToIccContactL(KStorageTypeText, KUidContactFieldPhoneNumber, KUidContactFieldVCardMapTEL, number, iccEntryExternal,i+1); |
|
298 } |
|
299 |
|
300 // Create name field(s) |
|
301 count = aIccEntryInternal->iNameList->Count(); |
|
302 for(i=0; i<count; ++i) |
|
303 { |
|
304 MyCSyncContactICCEntry::TSyncEntryName nameField; |
|
305 nameField.Copy(aIccEntryInternal->iNameList->At(i)); |
|
306 // First name only is stored as Family Name |
|
307 if (i == 0) |
|
308 { |
|
309 AddTextFieldToIccContactL(KStorageTypeText, KUidContactFieldFamilyName, KUidContactFieldVCardMapUnusedN, nameField, iccEntryExternal, i); |
|
310 } |
|
311 else |
|
312 { |
|
313 AddTextFieldToIccContactL(KStorageTypeText, KUidContactFieldSecondName, KUidContactFieldVCardMapUnusedN, nameField, iccEntryExternal, i-1); |
|
314 } |
|
315 } |
|
316 |
|
317 // Create group field(s) |
|
318 count = aIccEntryInternal->iGroupList->Count(); |
|
319 for(i=0; i<count; ++i) |
|
320 { |
|
321 MyCSyncContactICCEntry::TSyncEntryName groupField; |
|
322 groupField.Copy(aIccEntryInternal->iGroupList->At(i)); |
|
323 AddTextFieldToIccContactL(KStorageTypeText, KUidContactFieldICCGroup, KUidContactFieldVCardMapUnusedN, groupField, iccEntryExternal,i); |
|
324 } |
|
325 |
|
326 // Create e-mail field(s) |
|
327 count = aIccEntryInternal->iEmailList->Count(); |
|
328 for(i=0; i<count; ++i) |
|
329 { |
|
330 MyCSyncContactICCEntry::TSyncEntryName emailField; |
|
331 emailField.Copy(aIccEntryInternal->iEmailList->At(i)); |
|
332 AddTextFieldToIccContactL(KStorageTypeText, KUidContactFieldEMail, KUidContactFieldVCardMapUnusedN, emailField, iccEntryExternal,i); |
|
333 } |
|
334 |
|
335 // Create slot number field |
|
336 if(aIccEntryInternal->iSlotNum!=KSyncIndexNotSupplied) // it is not a new entry so slot number is supplied |
|
337 { |
|
338 // Create slot number field |
|
339 HBufC* buf = HBufC::NewL(5); |
|
340 TPtr indexPtr(buf->Des()); |
|
341 indexPtr.AppendNum(aIccEntryInternal->iSlotNum); |
|
342 TPtrC indexPtrC = indexPtr.Mid(0); |
|
343 AddTextFieldToIccContactL(KStorageTypeText, KUidContactFieldICCSlot, KUidContactFieldVCardMapNotRequired, indexPtrC, iccEntryExternal,0); |
|
344 delete buf; |
|
345 } |
|
346 |
|
347 // Create phonebook type field |
|
348 TBuf<KFieldLength> buf; |
|
349 buf.FillZ(); |
|
350 buf.Zero(); |
|
351 buf.AppendNum(static_cast<TInt>(aIccEntryInternal->iPhonebook)); |
|
352 TPtrC phonebookPtrC(buf.Ptr()); |
|
353 AddTextFieldToIccContactL(KStorageTypeText, KUidContactFieldICCPhonebook, KUidContactFieldVCardMapNotRequired, phonebookPtrC, iccEntryExternal,0); |
|
354 |
|
355 // Send a Write-Contact-ICC request |
|
356 // Here you need to pass an EXTERNAL format not INTERNAL as this is what |
|
357 // the plug-in will pass to the server |
|
358 TInt iSlotNumCallByRef = aIccEntryInternal->iSlotNum; |
|
359 |
|
360 if (aSession != NULL) |
|
361 { |
|
362 aSession->WriteContact(aStatus, *iccEntryExternal, iSlotNumCallByRef, aPhonebook); |
|
363 } |
|
364 else |
|
365 { |
|
366 iSession.WriteContact(aStatus, *iccEntryExternal, iSlotNumCallByRef, aPhonebook); |
|
367 } |
|
368 User::WaitForRequest(aStatus); |
|
369 |
|
370 // if a new slot number is allocated, write it back to EXTERNAL object |
|
371 if (aIccEntryInternal->iSlotNum == KSyncIndexNotSupplied) |
|
372 { |
|
373 // a new slot should be allocated and put into "iSlotNumCallByRef". |
|
374 // In case the phonebook is full, write will faile which is why a |
|
375 // TESTCHECKCODITION(iSlotNumCallByRef != KSyncIndexNotSupplied) is not done here. |
|
376 aIccEntryInternal->iSlotNum = iSlotNumCallByRef; |
|
377 } |
|
378 |
|
379 CleanupStack::PopAndDestroy(); // iccEntryExternal |
|
380 } |
|
381 |
|
382 /** Do a manual synchronisation */ |
|
383 void CTestStepPhbkSync::DoSyncL(TUid aPhonebookUid, TInt aExpectedErr, TBool aIgnoreErr) |
|
384 { |
|
385 TRequestStatus status; |
|
386 iSession.DoSynchronisation(status, aPhonebookUid); |
|
387 User::WaitForRequest(status); |
|
388 if (!aIgnoreErr) |
|
389 { |
|
390 TESTCHECK(status.Int(), aExpectedErr); |
|
391 } |
|
392 else |
|
393 { |
|
394 // to make sure the given error code != KErrNone |
|
395 // and simply ignore the returned error message |
|
396 TESTCHECKCONDITION(status.Int()!=KErrNone); |
|
397 } |
|
398 } |
|
399 |
|
400 /** Do a manual synchronisation with cache state change notification*/ |
|
401 void CTestStepPhbkSync::DoSyncAndNotificationL(TUid aPhonebookUid, TInt aExpectedErr, |
|
402 RPhoneBookSession::TSyncState aExpectedState, |
|
403 TRequestStatus& aNotifyStatus, TBool aIgnoreErr) |
|
404 { |
|
405 TRequestStatus status; |
|
406 iSession.DoSynchronisation(status, aPhonebookUid); |
|
407 User::WaitForRequest(aNotifyStatus); |
|
408 User::WaitForRequest(status); |
|
409 |
|
410 RPhoneBookSession::TSyncState state; |
|
411 iSession.GetPhoneBookCacheState(state, aPhonebookUid); |
|
412 if (!aIgnoreErr) |
|
413 { |
|
414 TESTCHECKL(status.Int(), aExpectedErr); |
|
415 TESTCHECK(state, aExpectedState); |
|
416 } |
|
417 else |
|
418 { |
|
419 // to make sure the given error code != KErrNone |
|
420 // and simply ignore the returned error message |
|
421 TESTCHECKCONDITIONL(status.Int() != KErrNone); |
|
422 } |
|
423 } |
|
424 |
|
425 |
|
426 /** |
|
427 Instruct the PhBkSync server to configure to a 'Full' state |
|
428 by using the Secure Backup interface. This will cause the |
|
429 server to reconnect to ETel and SIMTSY. |
|
430 */ |
|
431 void CTestStepPhbkSync::ConfigurePhbkSyncToFullL() |
|
432 { |
|
433 // |
|
434 // Ensure that the Secure Backup system does not currently think |
|
435 // it is performing a backup or restore. |
|
436 // |
|
437 iSecureBackupEngine->SetBURModeL(TDriveList(_L8("C")), |
|
438 EBURNormal, ENoBackup); |
|
439 |
|
440 // |
|
441 // Connect to the server to ensure that the server is running and |
|
442 // responding. |
|
443 // |
|
444 RPhoneBookSession phoneBookSession; |
|
445 RPhoneBookSession::TPhonebookSyncMode dummySyncMode; |
|
446 TInt ret; |
|
447 |
|
448 ret = phoneBookSession.Connect(); |
|
449 TESTCHECKL(ret, KErrNone); |
|
450 |
|
451 ret = KErrNotReady; |
|
452 while (ret != KErrNone) |
|
453 { |
|
454 ret = phoneBookSession.GetSyncMode(dummySyncMode); |
|
455 if (ret != KErrNone) |
|
456 { |
|
457 User::After(1); |
|
458 } |
|
459 } |
|
460 |
|
461 phoneBookSession.Close(); |
|
462 } // CTestStepPhbkSync::ConfigurePhbkSyncToFullL |
|
463 |
|
464 |
|
465 /** |
|
466 Instruct the PhBkSync server to unconfigure to an 'Idle' state |
|
467 by using the Secure Backup interface. This will cause the |
|
468 server to disconnect from ETel and SIMTSY. This is effectively |
|
469 the same as shutting down the server, but can be performed on |
|
470 release versions. |
|
471 */ |
|
472 void CTestStepPhbkSync::ConfigurePhbkSyncToIdleL() |
|
473 { |
|
474 // |
|
475 // Connect to the server to ensure that the server is running. |
|
476 // |
|
477 RPhoneBookSession phoneBookSession; |
|
478 TInt ret; |
|
479 |
|
480 ret = phoneBookSession.Connect(); |
|
481 TESTCHECKL(ret, KErrNone); |
|
482 |
|
483 // |
|
484 // Ensure that the Secure Backup system does not currently think |
|
485 // it is performing a backup or restore. |
|
486 // |
|
487 iSecureBackupEngine->SetBURModeL(TDriveList(_L8("C")), |
|
488 EBURBackupFull, EBackupBase); |
|
489 |
|
490 // |
|
491 // Check that the server is responding. |
|
492 // |
|
493 RPhoneBookSession::TPhonebookSyncMode dummySyncMode; |
|
494 |
|
495 ret = KErrNone; |
|
496 while (ret == KErrNone) |
|
497 { |
|
498 ret = phoneBookSession.GetSyncMode(dummySyncMode); |
|
499 if (ret == KErrNone) |
|
500 { |
|
501 User::After(1); |
|
502 } |
|
503 } |
|
504 |
|
505 phoneBookSession.Close(); |
|
506 } // CTestStepPhbkSync::ConfigurePhbkSyncToIdleL |
|
507 |
|
508 |
|
509 /** |
|
510 * Set the SIM TSY test number to run |
|
511 * |
|
512 */ |
|
513 void CTestStepPhbkSync::SetSimTsyTestNumberL(TInt aTestNumber, TBool aIgnoreErr) |
|
514 { |
|
515 RProperty testNumberProperty; |
|
516 User::LeaveIfError(testNumberProperty.Attach(KUidPSSimTsyCategory, KPSSimTsyTestNumber)); |
|
517 CleanupClosePushL(testNumberProperty); |
|
518 |
|
519 TRequestStatus status; |
|
520 testNumberProperty.Subscribe(status); |
|
521 User::LeaveIfError(testNumberProperty.Set(KUidPSSimTsyCategory,KPSSimTsyTestNumber,aTestNumber)); |
|
522 User::WaitForRequest(status); |
|
523 User::LeaveIfError(status.Int()); |
|
524 TInt testNumberCheck; |
|
525 User::LeaveIfError(testNumberProperty.Get(testNumberCheck)); |
|
526 if (aTestNumber != testNumberCheck) |
|
527 { |
|
528 User::Leave(KErrNotFound); |
|
529 } |
|
530 |
|
531 CleanupStack::PopAndDestroy(&testNumberProperty); |
|
532 |
|
533 iSession.Close(); |
|
534 |
|
535 // |
|
536 // Ensure that the server resets its configuration.... |
|
537 // |
|
538 ConfigurePhbkSyncToIdleL(); |
|
539 ConfigurePhbkSyncToFullL(); |
|
540 |
|
541 TInt ret = iSession.Connect(); |
|
542 |
|
543 if (!aIgnoreErr) |
|
544 { |
|
545 User::LeaveIfError(ret); |
|
546 } |
|
547 else |
|
548 { |
|
549 TESTCHECKCONDITION(ret != KErrNone); |
|
550 } |
|
551 |
|
552 // Ensure that the test number has been set properly |
|
553 RProperty testNumberInUseProperty; |
|
554 User::LeaveIfError(testNumberInUseProperty.Attach(KUidPSSimTsyCategory, KPSSimTsyTestNumberInUse)); |
|
555 CleanupClosePushL(testNumberInUseProperty); |
|
556 |
|
557 TInt testNumberInUseCheck; |
|
558 User::LeaveIfError(testNumberInUseProperty.Get(KUidPSSimTsyCategory, KPSSimTsyTestNumberInUse,testNumberInUseCheck)); |
|
559 TESTCHECKL(aTestNumber,testNumberInUseCheck); |
|
560 |
|
561 CleanupStack::PopAndDestroy(&testNumberInUseProperty); |
|
562 } |
|
563 |
|
564 |
|
565 /** |
|
566 * Publish a new value to indicate that test has finished and simtsy timer |
|
567 * can now proceed to the next timer point. |
|
568 */ |
|
569 void CTestStepPhbkSync::SignalSimTsyToReduceTimersL() |
|
570 { |
|
571 RProperty reduceTimersProperty; |
|
572 User::LeaveIfError(reduceTimersProperty.Attach(KUidPSSimTsyCategory, KPSSimTsyTimersReduceTime)); |
|
573 CleanupClosePushL(reduceTimersProperty); |
|
574 |
|
575 User::LeaveIfError(reduceTimersProperty.Set(KUidPSSimTsyCategory, KPSSimTsyTimersReduceTime, |
|
576 KReduceSimTsyTimers)); |
|
577 |
|
578 CleanupStack::PopAndDestroy(&reduceTimersProperty); |
|
579 } // CTestStepPhbkSync::SignalSimTsyToReduceTimersL |
|
580 |
|
581 |
|
582 /** |
|
583 * To return a valid contact item id. |
|
584 */ |
|
585 TContactItemId CTestStepPhbkSync::GetValidUIDFromContactsDbL(TUid aPhonebookUid, TBool aHiddenRequired) |
|
586 { |
|
587 TContactItemId firstId(KNullContactId); |
|
588 |
|
589 CContactDatabase *iDb = NULL; |
|
590 TRAPD(err,iDb = CContactDatabase::OpenL()); // open existing database |
|
591 CleanupStack::PushL(iDb); |
|
592 if (err != KErrNone) |
|
593 { |
|
594 CleanupStack::PopAndDestroy(); // iDb |
|
595 return firstId; |
|
596 } |
|
597 |
|
598 iDb->SetDbViewContactType(KUidContactICCEntry); |
|
599 |
|
600 // to get the unique groupId for the given phonebook |
|
601 TContactItemId groupId(KNullContactId); |
|
602 User::LeaveIfError(iSession.GetPhoneBookId(groupId, |
|
603 RPhoneBookSession::ESyncGroupId, |
|
604 aPhonebookUid)); |
|
605 TESTCHECKCONDITIONL(groupId != KNullContactId); |
|
606 |
|
607 // based on the groupId, get all iterms belonging to the phonebook |
|
608 CContactGroup* group = |
|
609 static_cast<CContactGroup*>(iDb->ReadContactLC(groupId)); |
|
610 const CContactIdArray* array = group->ItemsContained(); |
|
611 TInt count(array->Count()); |
|
612 for(TInt i=0; i<count; ++i) |
|
613 { |
|
614 firstId = (*array)[i]; |
|
615 CContactICCEntry* entry = static_cast<CContactICCEntry*>(iDb->ReadContactLC(firstId)); |
|
616 if(((aHiddenRequired) && (entry->IsHidden())) || |
|
617 ((!aHiddenRequired) && (!entry->IsHidden()))) |
|
618 { |
|
619 CleanupStack::PopAndDestroy(entry); |
|
620 break; |
|
621 } |
|
622 CleanupStack::PopAndDestroy(entry); |
|
623 } |
|
624 |
|
625 CleanupStack::PopAndDestroy(group); |
|
626 CleanupStack::PopAndDestroy(); // iDb |
|
627 return firstId; |
|
628 } |
|
629 |
|
630 /** |
|
631 * To return a valid slot number. |
|
632 */ |
|
633 TInt CTestStepPhbkSync::GetValidSlotFromContactsDbL(TUid aPhonebookUid, TBool aHiddenRequired) |
|
634 { |
|
635 TInt slot(KSyncIndexNotSupplied); |
|
636 TContactItemId id = GetValidUIDFromContactsDbL(aPhonebookUid, aHiddenRequired); |
|
637 |
|
638 CContactDatabase *iDb = NULL; |
|
639 TRAPD(err,iDb = CContactDatabase::OpenL()); // open existing database |
|
640 CleanupStack::PushL(iDb); |
|
641 if (err != KErrNone) |
|
642 { |
|
643 CleanupStack::PopAndDestroy(); // iDb |
|
644 return slot; |
|
645 } |
|
646 |
|
647 iDb->SetDbViewContactType(KUidContactICCEntry); |
|
648 CContactICCEntry* entry = static_cast<CContactICCEntry*>(iDb->ReadContactLC(id)); // down cast |
|
649 |
|
650 //set of fields for this entry |
|
651 CContactItemFieldSet& fieldSet = entry->CardFields(); |
|
652 |
|
653 //get index of the icc slot field |
|
654 TInt index = fieldSet.Find(KUidContactFieldICCSlot); |
|
655 |
|
656 if(index!=KErrNotFound) |
|
657 { // index field provided |
|
658 TPtrC tempPtr(NULL,0); |
|
659 tempPtr.Set(fieldSet[index].TextStorage()->Text()); |
|
660 TLex lex(tempPtr); |
|
661 User::LeaveIfError(lex.Val(slot)); |
|
662 } |
|
663 |
|
664 CleanupStack::PopAndDestroy(2); // iDb and entry |
|
665 return slot; |
|
666 } |
|
667 |
|
668 void CTestStepPhbkSync::AddTextFieldToIccContactL(TStorageType aType, |
|
669 TFieldType aFieldType, |
|
670 TUid aMapping, |
|
671 TDesC& aField, |
|
672 CContactICCEntry* aIccEntry, |
|
673 TInt aCount) |
|
674 /** |
|
675 * Add a new text field (aField) to the CContactICCEntry supplied by aIccEntry. |
|
676 * @param aType Field Storage type |
|
677 * @param aFieldType Field type |
|
678 * @param aMapping Mapping for the field's content type |
|
679 * @param aField Field data |
|
680 * @param aIccEntry CContactICCEntry item |
|
681 * @param aCount Identifies which instance of field is to be used |
|
682 */ |
|
683 { |
|
684 CContactItemFieldSet& fieldSet = aIccEntry->CardFields(); |
|
685 TInt pos(KErrNotFound); |
|
686 for (TInt i = 0; i <= aCount; i++) |
|
687 { |
|
688 pos = fieldSet.FindNext(aFieldType, pos + 1); |
|
689 if (pos == KErrNotFound) |
|
690 break; |
|
691 } |
|
692 if (pos!=KErrNotFound) // Field already present. Note, Contacts model reads all fields |
|
693 // in template and adds them as empty fields in ICC item |
|
694 { |
|
695 CContactItemField& field=fieldSet[pos]; |
|
696 field.TextStorage()->SetTextL(aField); |
|
697 } |
|
698 else |
|
699 { |
|
700 CContactItemField* field=CContactItemField::NewLC(aType, aFieldType); |
|
701 field->SetMapping(aMapping); |
|
702 field->AddFieldTypeL(aFieldType); // Appends a field type to the field's content type |
|
703 field->TextStorage()->SetTextL(aField); |
|
704 aIccEntry->AddFieldL(*field); |
|
705 CleanupStack::Pop(); // field. No need to destroy it since contact item takes ownership of field |
|
706 } |
|
707 } |
|
708 |
|
709 |
|
710 /** |
|
711 * A utility used to initialise the entry with (short) internal format, |
|
712 * The values of iSlotNum, iContactUID and iTON are set as: |
|
713 * iSlotNum = KSyncIndexNotSupplied |
|
714 * iContactUID = KNullContactId |
|
715 * iTON = EUnknownNumber |
|
716 */ |
|
717 void CTestStepPhbkSync::InitialiseIccEntryInternalOldL(MyCSyncContactICCEntry* aIccEntryInternal) |
|
718 { |
|
719 aIccEntryInternal->iNumber.Format(KTel); |
|
720 |
|
721 // leave the slot number unspecified on purpose |
|
722 aIccEntryInternal->iSlotNum = KSyncIndexNotSupplied; |
|
723 |
|
724 aIccEntryInternal->iContactUID=KNullContactId; |
|
725 aIccEntryInternal->iTON=RMobilePhone::EUnknownNumber; |
|
726 |
|
727 // initialise the (CSyncICCEntry - TContactICCEntry) attributes |
|
728 MyCSyncContactICCEntry::TSyncEntryName tName; |
|
729 tName.Copy(KName1); |
|
730 aIccEntryInternal->iNameList->AppendL(tName); |
|
731 } |
|
732 |
|
733 |
|
734 /** |
|
735 * A utility used to initialise the entry with (long) internal format. |
|
736 * The values of iSlotNum, iContactUID and iTON are set as: |
|
737 * iSlotNum = KSyncIndexNotSupplied |
|
738 * iContactUID = KNullContactId |
|
739 * iTON = EUnknownNumber |
|
740 */ |
|
741 void CTestStepPhbkSync::InitialiseIccEntryInternalNewL(MyCSyncContactICCEntry* aIccEntryInternal) |
|
742 { |
|
743 aIccEntryInternal->iNumber.Format(KTel); |
|
744 |
|
745 // leave the slot number unspecified on purpose |
|
746 aIccEntryInternal->iSlotNum = KSyncIndexNotSupplied; |
|
747 |
|
748 aIccEntryInternal->iContactUID=KNullContactId; |
|
749 aIccEntryInternal->iTON=RMobilePhone::EUnknownNumber; |
|
750 |
|
751 // initialise the (CSyncICCEntry - TContactICCEntry) attributes |
|
752 // 1 iNameList |
|
753 MyCSyncContactICCEntry::TSyncEntryName tName; |
|
754 tName.Copy(KName1); |
|
755 aIccEntryInternal->iNameList->AppendL(tName); |
|
756 tName.Copy(KName2); |
|
757 aIccEntryInternal->iNameList->AppendL(tName); |
|
758 |
|
759 // 2. iNumberList (i.e. list of additional numbers) |
|
760 MyCSyncContactICCEntry::TSyncAdditionalNumber addNum; |
|
761 |
|
762 addNum.iNumber.Format(KAdditionalNumber1); |
|
763 // addNum.iNumberString.Copy(KAdditionalString1); |
|
764 addNum.iTON = RMobilePhone::EUnknownNumber; //KAdditionalTON1 |
|
765 |
|
766 aIccEntryInternal->iNumberList->AppendL(addNum); |
|
767 |
|
768 addNum.iNumber.Format(KAdditionalNumber2); |
|
769 // addNum.iNumberString.Copy(KAdditionalString2); |
|
770 addNum.iTON = RMobilePhone::EUnknownNumber; //KAdditionalTON2 |
|
771 |
|
772 aIccEntryInternal->iNumberList->AppendL(addNum); |
|
773 |
|
774 // 3. iGrouplist |
|
775 tName.Copy(KGroup1); |
|
776 aIccEntryInternal->iGroupList->AppendL(tName); |
|
777 tName.Copy(KGroup2); |
|
778 aIccEntryInternal->iGroupList->AppendL(tName); |
|
779 /***** |
|
780 tName.Copy(KGroup3); |
|
781 iccEntryInternal->iGroupList->AppendL(tName); |
|
782 tName.Copy(KGroup4); |
|
783 iccEntryInternal->iGroupList->AppendL(tName); |
|
784 tName.Copy(KGroup5); |
|
785 iccEntryInternal->iGroupList->AppendL(tName); |
|
786 *****/ |
|
787 |
|
788 // 4. iEmailList |
|
789 tName.Copy(KEmail1); |
|
790 aIccEntryInternal->iEmailList->AppendL(tName); |
|
791 tName.Copy(KEmail2); |
|
792 aIccEntryInternal->iEmailList->AppendL(tName); |
|
793 /***** |
|
794 tName.Copy(KEmail3); |
|
795 iccEntryInternal->iEmailList->AppendL(tName); |
|
796 tName.Copy(KEmail4); |
|
797 iccEntryInternal->iEmailList->AppendL(tName); |
|
798 tName.Copy(KEmail5); |
|
799 iccEntryInternal->iEmailList->AppendL(tName); |
|
800 *****/ |
|
801 |
|
802 // 5. iPhonebook |
|
803 // set each phonebook TUid during the loop (see below) |
|
804 |
|
805 // 6. iIsHidden |
|
806 aIccEntryInternal->iIsHidden = EFalse; |
|
807 } |
|
808 |
|
809 void CTestStepPhbkSync::InitialiseIccEntryInternalNewL(MyCSyncContactICCEntry& aIccEntryInternal) |
|
810 { |
|
811 InitialiseIccEntryInternalNewL(&aIccEntryInternal); |
|
812 } |
|
813 |
|
814 // |
|
815 // code copied from phbkinternal.cpp // |
|
816 // |
|
817 MyCSyncContactICCEntry* MyCSyncContactICCEntry::NewL() |
|
818 { |
|
819 MyCSyncContactICCEntry* ptr = new (ELeave) MyCSyncContactICCEntry(); |
|
820 CleanupStack::PushL(ptr); |
|
821 ptr->ConstructL(); |
|
822 CleanupStack::Pop(); // ptr |
|
823 return ptr; |
|
824 } |
|
825 |
|
826 MyCSyncContactICCEntry::MyCSyncContactICCEntry() : |
|
827 iSlotNum(0), |
|
828 iTON(RMobilePhone::EUnknownNumber), |
|
829 iContactUID(KNullContactId), |
|
830 iPhonebook(EIccGlobalAdnPhonebook), |
|
831 iIsHidden(EFalse), |
|
832 iGroupId(KNullContactId) |
|
833 { |
|
834 } |
|
835 |
|
836 void MyCSyncContactICCEntry::ConstructL() |
|
837 { |
|
838 iNameList = new (ELeave) CArrayFixFlat<TSyncEntryName>(KSyncArrayGranularity); |
|
839 iNumberList = new (ELeave) CArrayFixFlat<TSyncAdditionalNumber>(KSyncArrayGranularity); |
|
840 iGroupList = new (ELeave) CArrayFixFlat<TSyncEntryName>(KSyncArrayGranularity); |
|
841 iEmailList = new (ELeave) CArrayFixFlat<TSyncEntryName>(KSyncArrayGranularity); |
|
842 } |
|
843 |
|
844 MyCSyncContactICCEntry::~MyCSyncContactICCEntry() |
|
845 { |
|
846 delete iNameList; |
|
847 delete iNumberList; |
|
848 delete iGroupList; |
|
849 delete iEmailList; |
|
850 } |