|
1 /* |
|
2 * Copyright (c) 2002 - 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <e32svr.h> |
|
23 #include <StifParser.h> |
|
24 #include <Stiftestinterface.h> |
|
25 #include <VPbkEng.rsg> |
|
26 |
|
27 #include <MVPbkContactFieldTextData.h> |
|
28 #include <MVPbkContactStoreList.h> |
|
29 #include <MVPbkContactOperationBase.h> |
|
30 #include <MVPbkContactLink.h> |
|
31 #include <CVPbkContactLinkArray.h> |
|
32 #include <MVPbkContactGroup.h> |
|
33 #include <utf.h> |
|
34 #include <CVPbkPhoneNumberMatchStrategy.h> |
|
35 #include <CVPbkContactStoreUriArray.h> |
|
36 #include <TVPbkContactStoreUriPtr.h> |
|
37 #include "tcontacts_async.h" |
|
38 #include "singlecontact.h" |
|
39 |
|
40 // CONSTANTS |
|
41 _LIT(KError,"Error code is"); |
|
42 _LIT(KSuccess,"Successful"); |
|
43 _LIT(KNewLine,"\n"); |
|
44 _LIT(KServiceOpen,"Service handle created"); |
|
45 _LIT(KServiceClose,"Service handle deleted"); |
|
46 _LIT(KPhoneNumber,"9886431364"); |
|
47 _LIT(KGroup1,"Test1"); |
|
48 TInt KInvalidKey = -1; |
|
49 // ============================ MEMBER FUNCTIONS =============================== |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CContactsUT::Delete |
|
53 // Delete here all resources allocated and opened from test methods. |
|
54 // Called from destructor. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 void CContactsUT::Delete() |
|
58 { |
|
59 |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CContactsUT::RunMethodL |
|
64 // Run specified method. Contains also table of test mothods and their names. |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 TInt CContactsUT::RunMethodL( |
|
68 CStifItemParser& aItem ) |
|
69 { |
|
70 |
|
71 static TStifFunctionInfo const KFunctions[] = |
|
72 { |
|
73 ENTRY( "Add_contact_sapi", CContactsUT::AddContactSAPIL ), |
|
74 ENTRY( "Delete_contact_sapi", CContactsUT::DeleteContactSAPIL ), |
|
75 ENTRY( "Modify_contact_sapi", CContactsUT::ModifyContactSAPIL ), |
|
76 ENTRY( "Getlist_delete_contact", CContactsUT::GetListDeleteContactL ), |
|
77 ENTRY( "Add_getlist_contact", CContactsUT::AddContactGetListL ), |
|
78 ENTRY( "Get_group", CContactsUT::GetGroupsL ), |
|
79 ENTRY( "Get_contact", CContactsUT::GetContactsL ), |
|
80 ENTRY( "Get_database", CContactsUT::GetDatabaseL ), |
|
81 ENTRY( "Add_contact", CContactsUT::AddL ), |
|
82 ENTRY( "Add_group", CContactsUT::AddGroupL ), |
|
83 ENTRY( "Modify_contact", CContactsUT::ModifyL ), |
|
84 ENTRY( "Modify_group", CContactsUT::ModifyGroupL ), |
|
85 ENTRY( "Delete_contact", CContactsUT::DeleteContactL ), |
|
86 ENTRY( "Delete_group", CContactsUT::DeleteGroupL ), |
|
87 ENTRY( "Organise_add", CContactsUT::OrganiseAddL ), |
|
88 ENTRY( "Organise_delete", CContactsUT::OrganiseDeleteL ), |
|
89 ENTRY( "Import", CContactsUT::ImportL ), |
|
90 ENTRY( "Export", CContactsUT::ExportL ), |
|
91 ENTRY( "Get_SearchContact", CContactsUT::GetSearchContactL ), |
|
92 ENTRY( "Get_ContactAsc", CContactsUT::GetContactsAscOrderL ), |
|
93 ENTRY( "Get_ContactDsc", CContactsUT::GetContactsDscOrderL ), |
|
94 ENTRY( "Get_ContactbyId", CContactsUT::GetListConactIdL ), |
|
95 ENTRY( "AddInvalidField", CContactsUT::AddInvalidFieldL ), |
|
96 ENTRY( "AddMultiplePhoneNumbersContact", CContactsUT::AddMultiplePhoneNumbersContactL ), |
|
97 ENTRY( "DeleteSingleContact", CContactsUT::DeleteSingleContactL ), |
|
98 ENTRY( "GetListCancelTest", CContactsUT::GetListCancelL ), |
|
99 ENTRY( "GetListSrchCancelTest", CContactsUT::GetListSrchCancelL ), |
|
100 ENTRY( "ExportCancelTest", CContactsUT::ExportCancelL ), |
|
101 ENTRY( "AddCancelTest", CContactsUT::AddCancelL ), |
|
102 ENTRY( "ImportCancelTest", CContactsUT::ImportCancelL ), |
|
103 ENTRY( "DeleteCancelTest", CContactsUT::DeleteCancelL ), |
|
104 ENTRY( "OrganiseCancelTest", CContactsUT::OrganiseCancelL), |
|
105 }; |
|
106 |
|
107 const TInt count = sizeof( KFunctions ) / |
|
108 sizeof( TStifFunctionInfo ); |
|
109 |
|
110 return RunInternalL( KFunctions, count, aItem ); |
|
111 |
|
112 } |
|
113 |
|
114 |
|
115 void CContactsUT::HandleReturnValue(TOperationEvent /*aEvent*/, const TInt& aError, TInt /*aTransId*/ ) |
|
116 { |
|
117 CActiveScheduler::Stop(); |
|
118 _LIT(KFunc,"In Handle Return Value\n"); |
|
119 iLog->Log(KFunc); |
|
120 if(aError == KErrArgument) |
|
121 iErr = KErrNone; |
|
122 else |
|
123 iErr = aError; |
|
124 TBuf<5> buf; |
|
125 buf.Num(aError); |
|
126 iLog->Log(KError); |
|
127 iLog->Log(buf); |
|
128 iLog->Log(KNewLine); |
|
129 } |
|
130 |
|
131 void CContactsUT::HandleReturnIter(const TInt& aError, CContactIter* aIter, TInt /*aTransId*/ ) |
|
132 { |
|
133 CActiveScheduler::Stop(); |
|
134 _LIT(KFunc,"In Handle Return Iter\n"); |
|
135 iLog->Log(KFunc); |
|
136 iErr = aError; |
|
137 TBuf<5> buf; |
|
138 buf.Num(aError); |
|
139 iLog->Log(KError); |
|
140 iLog->Log(buf); |
|
141 iLog->Log(KNewLine); |
|
142 |
|
143 if(EGetContactDelete == iOperation ) |
|
144 { |
|
145 iOperation = ENone; |
|
146 CSingleContact* singleContact = NULL; |
|
147 HBufC8* buf = NULL; |
|
148 TInt count = 0; |
|
149 while(ETrue) |
|
150 { |
|
151 aIter->NextL(singleContact,buf); |
|
152 if(!singleContact) |
|
153 { |
|
154 break; |
|
155 } |
|
156 iBuffer = buf; |
|
157 // delete buf; |
|
158 delete singleContact; |
|
159 break; |
|
160 } |
|
161 } |
|
162 if(iOperation == EContact) |
|
163 { |
|
164 iOperation = ENone; |
|
165 iErr = KErrGeneral; |
|
166 CSingleContact* singleContact = NULL; |
|
167 HBufC8* buf = NULL; |
|
168 |
|
169 _LIT(KPhone,"Birbal"); |
|
170 _LIT8(KField,"FirstName"); |
|
171 |
|
172 while(ETrue) |
|
173 { |
|
174 __UHEAP_MARK; |
|
175 aIter->NextL(singleContact,buf); |
|
176 if(!singleContact) |
|
177 { |
|
178 break; |
|
179 } |
|
180 CleanupStack::PushL(singleContact); |
|
181 //CleanupStack::PushL(buf); |
|
182 if(!buf->Compare(*iBuffer)) |
|
183 { |
|
184 TInt count(singleContact->FieldCount()); |
|
185 CSingleContactField* field = NULL; |
|
186 while(count) |
|
187 { |
|
188 TPtrC8 fieldKey; |
|
189 TPtrC label; |
|
190 TPtrC value; |
|
191 field = singleContact->FieldAt(--count); |
|
192 field->GetFieldDataL(fieldKey,label,value); |
|
193 if(!fieldKey.Compare(KField)) |
|
194 { |
|
195 field->SetFieldParamsL(KField,KNullDesC,KPhone); |
|
196 iLog->Log(_L("Phone Contact Field modified \n")); |
|
197 __UHEAP_MARK; |
|
198 iServiceHandle->AddL(this,0,singleContact); |
|
199 iLog->Log(_L("AddL called\n")); |
|
200 iLog->Log(_L("Start Active Scheduler\n")); |
|
201 CActiveScheduler::Start(); |
|
202 __UHEAP_MARKEND; |
|
203 break; |
|
204 } |
|
205 } |
|
206 } |
|
207 |
|
208 //CleanupStack::PopAndDestroy(buf); |
|
209 delete buf; |
|
210 CleanupStack::PopAndDestroy(singleContact); |
|
211 __UHEAP_MARKEND; |
|
212 } |
|
213 } |
|
214 if(EGetContact == iOperation ) |
|
215 { |
|
216 iOperation = ENone; |
|
217 //iErr = KErrGeneral; |
|
218 _LIT8(KFirstName,"FirstName"); |
|
219 _LIT(KName,"Kats"); |
|
220 CSingleContact* singleContact = NULL; |
|
221 HBufC8* buf = NULL; |
|
222 TInt count = 0; |
|
223 while(ETrue) |
|
224 { |
|
225 aIter->NextL(singleContact,buf); |
|
226 if(!singleContact) |
|
227 { |
|
228 break; |
|
229 } |
|
230 ++count; |
|
231 TInt count(singleContact->FieldCount()); |
|
232 while(count) |
|
233 { |
|
234 CSingleContactField* field = singleContact->FieldAt(--count); |
|
235 TPtrC8 fieldKey; |
|
236 TPtrC label; |
|
237 TPtrC value; |
|
238 field->GetFieldDataL(fieldKey,label,value); |
|
239 if (fieldKey == KFirstName && value == KName) |
|
240 { |
|
241 iErr = KErrNone; |
|
242 } |
|
243 // delete field; |
|
244 } |
|
245 delete buf; |
|
246 delete singleContact; |
|
247 } |
|
248 delete buf; |
|
249 } |
|
250 if(EContactVerify == iOperation ) |
|
251 { |
|
252 iOperation = ENone; |
|
253 iErr = KErrGeneral; |
|
254 _LIT8(KFirstName,"FirstName"); |
|
255 _LIT(KName,"Tenali"); |
|
256 CSingleContact* singleContact = NULL; |
|
257 HBufC8* buf = NULL; |
|
258 aIter->NextL(singleContact,buf); |
|
259 if(buf->Compare(*iBuf)==0) |
|
260 { |
|
261 iErr = KErrNone; |
|
262 } |
|
263 } |
|
264 if(EContactId == iOperation ) |
|
265 { |
|
266 iOperation = ENone; |
|
267 //iErr = KErrGeneral; |
|
268 _LIT8(KFirstName,"FirstName"); |
|
269 _LIT(KName,"Tenali"); |
|
270 CSingleContact* singleContact = NULL; |
|
271 HBufC8* buf = NULL; |
|
272 TInt count = 0; |
|
273 |
|
274 aIter->NextL(singleContact,buf); |
|
275 iOperation = EContactVerify; |
|
276 iBuf = buf; |
|
277 iServiceHandle->GetListL(this,0,EContacts,*buf); |
|
278 CActiveScheduler::Start(); |
|
279 delete singleContact; |
|
280 } |
|
281 if(ESearchContact == iOperation ) |
|
282 { |
|
283 iOperation = ENone; |
|
284 iErr = KErrGeneral; |
|
285 _LIT8(KFirstName,"FirstName"); |
|
286 _LIT(KName,"Tenali"); |
|
287 CSingleContact* singleContact = NULL; |
|
288 HBufC8* buf = NULL; |
|
289 TInt count = 0; |
|
290 while(ETrue) |
|
291 { |
|
292 aIter->NextL(singleContact,buf); |
|
293 if(!singleContact) |
|
294 { |
|
295 break; |
|
296 } |
|
297 ++count; |
|
298 TInt count(singleContact->FieldCount()); |
|
299 while(count) |
|
300 { |
|
301 CSingleContactField* field = singleContact->FieldAt(--count); |
|
302 TPtrC8 fieldKey; |
|
303 TPtrC label; |
|
304 TPtrC value; |
|
305 field->GetFieldDataL(fieldKey,label,value); |
|
306 if (fieldKey == KFirstName && value == KName) |
|
307 { |
|
308 iErr = KErrNone; |
|
309 } |
|
310 else if (fieldKey == KFirstName) |
|
311 { |
|
312 break; |
|
313 } |
|
314 } |
|
315 delete singleContact; |
|
316 } |
|
317 } |
|
318 if(EAscContact == iOperation ) |
|
319 { |
|
320 iOperation = ENone; |
|
321 iErr = KErrGeneral; |
|
322 _LIT8(KFirstName,"FirstName"); |
|
323 _LIT(KNameT,"Tenali"); |
|
324 _LIT(KNameB,"Birbal"); |
|
325 TInt count1 = 0; |
|
326 TInt tCount = 0; |
|
327 TInt bCount = 0; |
|
328 CSingleContact* singleContact = NULL; |
|
329 HBufC8* buf = NULL; |
|
330 TInt count = 0; |
|
331 |
|
332 while(ETrue) |
|
333 { |
|
334 aIter->NextL(singleContact,buf); |
|
335 if(!singleContact) |
|
336 { |
|
337 break; |
|
338 } |
|
339 ++count; |
|
340 TInt count(singleContact->FieldCount()); |
|
341 while(count) |
|
342 { |
|
343 CSingleContactField* field = singleContact->FieldAt(--count); |
|
344 TPtrC8 fieldKey; |
|
345 TPtrC label; |
|
346 TPtrC value; |
|
347 field->GetFieldDataL(fieldKey,label,value); |
|
348 if (fieldKey == KFirstName && value == KNameT) |
|
349 { |
|
350 ++count1; |
|
351 tCount = count1; |
|
352 } |
|
353 if (fieldKey == KFirstName && value == KNameB) |
|
354 { |
|
355 ++count1; |
|
356 bCount = count1; |
|
357 } |
|
358 |
|
359 } |
|
360 delete singleContact; |
|
361 } |
|
362 |
|
363 if(bCount>0 && tCount>0 && bCount<tCount) |
|
364 { |
|
365 iErr = KErrNone; |
|
366 } |
|
367 } |
|
368 |
|
369 if(EDscContact == iOperation ) |
|
370 { |
|
371 iOperation = ENone; |
|
372 iErr = KErrGeneral; |
|
373 _LIT8(KFirstName,"FirstName"); |
|
374 _LIT(KNameT,"Tenali"); |
|
375 _LIT(KNameB,"Birbal"); |
|
376 TInt count1 = 0; |
|
377 TInt tCount = 0; |
|
378 TInt bCount = 0; |
|
379 CSingleContact* singleContact = NULL; |
|
380 HBufC8* buf = NULL; |
|
381 TInt count = 0; |
|
382 while(ETrue) |
|
383 { |
|
384 aIter->NextL(singleContact,buf); |
|
385 if(!singleContact) |
|
386 { |
|
387 break; |
|
388 } |
|
389 ++count; |
|
390 TInt count(singleContact->FieldCount()); |
|
391 while(count) |
|
392 { |
|
393 CSingleContactField* field = singleContact->FieldAt(--count); |
|
394 TPtrC8 fieldKey; |
|
395 TPtrC label; |
|
396 TPtrC value; |
|
397 field->GetFieldDataL(fieldKey,label,value); |
|
398 if (fieldKey == KFirstName && value == KNameT) |
|
399 { |
|
400 ++count1; |
|
401 tCount = count1; |
|
402 } |
|
403 if (fieldKey == KFirstName && value == KNameB) |
|
404 { |
|
405 ++count1; |
|
406 bCount = count1; |
|
407 } |
|
408 } |
|
409 delete singleContact; |
|
410 } |
|
411 if(bCount>tCount) |
|
412 { |
|
413 iErr = KErrNone; |
|
414 } |
|
415 } |
|
416 if(EGetGroup == iOperation ) |
|
417 { |
|
418 iOperation = ENone; |
|
419 iErr = KErrGeneral; |
|
420 CSingleContact* singleContact = NULL; |
|
421 HBufC8* buf = NULL; |
|
422 TInt count = 0; |
|
423 while(ETrue) |
|
424 { |
|
425 aIter->NextL(singleContact,buf); |
|
426 iBuffer = buf; |
|
427 if(!singleContact) |
|
428 { |
|
429 break; |
|
430 } |
|
431 ++count; |
|
432 TInt fields(singleContact->FieldCount()); |
|
433 while(fields) |
|
434 { |
|
435 CSingleContactField* field = singleContact->FieldAt(--fields); |
|
436 TPtrC groupId; |
|
437 RPointerArray<TDesC8> array; |
|
438 field->GetFieldDataL(groupId,array); |
|
439 |
|
440 |
|
441 if(groupId.Compare(KGroup1)==0) |
|
442 { |
|
443 iErr = KErrNone; |
|
444 break; |
|
445 } |
|
446 |
|
447 } |
|
448 |
|
449 } |
|
450 } |
|
451 delete aIter; |
|
452 } |
|
453 |
|
454 void CContactsUT::HandleRetrieveContact( MVPbkStoreContact* /*aStoreContact*/, TInt /*aTransId*/ ) |
|
455 { |
|
456 CActiveScheduler::Stop(); |
|
457 _LIT(KFunc,"In Handle Retrieve Contact\n"); |
|
458 iLog->Log(KFunc); |
|
459 } |
|
460 |
|
461 void CContactsUT::ContactOperationCompleted(TContactOpResult aResult) |
|
462 { |
|
463 CActiveScheduler::Stop(); |
|
464 _LIT(KFunc,"In ContactOperationCompleted \n"); |
|
465 iLog->Log(KFunc); |
|
466 iErr = KErrNone; |
|
467 TBuf<5> buf; |
|
468 buf.Num(aResult.iOpCode); |
|
469 iLog->Log(KSuccess); |
|
470 iLog->Log(buf); |
|
471 iLog->Log(KNewLine); |
|
472 switch(iOperation) |
|
473 {/* |
|
474 case EContact: delete iStoreContact; |
|
475 iStoreContact = NULL; |
|
476 break;*/ |
|
477 case EGroup: delete iGroup; |
|
478 iGroup = NULL; |
|
479 break; |
|
480 } |
|
481 iOperation = ENone; |
|
482 } |
|
483 void CContactsUT::ContactOperationFailed |
|
484 (TContactOp /*aOpCode*/, TInt aErrorCode, TBool /*aErrorNotified*/) |
|
485 { |
|
486 CActiveScheduler::Stop(); |
|
487 _LIT(KFunc,"In ContactOperationFailed \n"); |
|
488 iLog->Log(KFunc); |
|
489 iErr = aErrorCode; |
|
490 TBuf<5> buf; |
|
491 buf.Num(aErrorCode); |
|
492 iLog->Log(KError); |
|
493 iLog->Log(buf); |
|
494 iLog->Log(KNewLine); |
|
495 switch(iOperation) |
|
496 { |
|
497 case EContact:/* delete iStoreContact; |
|
498 iStoreContact = NULL; |
|
499 break;*/ |
|
500 case EGroup: delete iGroup; |
|
501 iGroup = NULL; |
|
502 break; |
|
503 } |
|
504 iOperation = ENone; |
|
505 } |
|
506 |
|
507 void CContactsUT::FindCompleteL( MVPbkContactLinkArray* aResults ) |
|
508 { |
|
509 CActiveScheduler::Stop(); |
|
510 _LIT(KFunc,"In FindCompleteL \n"); |
|
511 iLog->Log(KFunc); |
|
512 iErr = KErrNone; |
|
513 TInt count = aResults->Count(); |
|
514 iFindResults = aResults; |
|
515 iLog->Log(KSuccess); |
|
516 } |
|
517 void CContactsUT::FindFailed( TInt aError ) |
|
518 { |
|
519 CActiveScheduler::Stop(); |
|
520 _LIT(KFunc,"In FindFailed \n"); |
|
521 iLog->Log(KFunc); |
|
522 iErr = aError; |
|
523 TBuf<5> buf; |
|
524 buf.Num(aError); |
|
525 iLog->Log(KError); |
|
526 iLog->Log(buf); |
|
527 iLog->Log(KNewLine); |
|
528 } |
|
529 |
|
530 void CContactsUT::VPbkSingleContactOperationComplete( |
|
531 MVPbkContactOperationBase& aOperation, |
|
532 MVPbkStoreContact* aContact ) |
|
533 { |
|
534 CActiveScheduler::Stop(); |
|
535 _LIT(KFunc,"In VPbkSingleContactOperationComplete \n"); |
|
536 iLog->Log(KFunc); |
|
537 iErr = KErrNone; |
|
538 |
|
539 if(iOperation == EVCard) |
|
540 { |
|
541 iDestStream.CommitL(); |
|
542 delete iOp; |
|
543 iOp = NULL; |
|
544 iDestStream.Close(); |
|
545 delete iResult; |
|
546 iResult = NULL; |
|
547 } |
|
548 else if(iOperation == EVCardEx) |
|
549 { |
|
550 delete iOp; |
|
551 iOp = NULL; |
|
552 } |
|
553 else |
|
554 { |
|
555 delete iStoreContact; |
|
556 iStoreContact = NULL; |
|
557 iStoreContact = aContact; |
|
558 if( iOp == &aOperation ) |
|
559 { |
|
560 delete iOp; |
|
561 iOp = NULL; |
|
562 } |
|
563 } |
|
564 iOperation = ENone; |
|
565 iLog->Log(KSuccess); |
|
566 } |
|
567 |
|
568 |
|
569 void CContactsUT::VPbkSingleContactOperationFailed( |
|
570 MVPbkContactOperationBase& aOperation, |
|
571 TInt aError ) |
|
572 { |
|
573 CActiveScheduler::Stop(); |
|
574 _LIT(KFunc,"In VPbkSingleContactOperationFailed \n"); |
|
575 iLog->Log(KFunc); |
|
576 iErr = aError; |
|
577 ; |
|
578 if(iOperation == EVCard) |
|
579 { |
|
580 iDestStream.CommitL(); |
|
581 delete iOp; |
|
582 iOp = NULL; |
|
583 iDestStream.Close(); |
|
584 delete iBuffer; |
|
585 iBuffer = NULL; |
|
586 delete iResult; |
|
587 iResult = NULL; |
|
588 } |
|
589 else if(iOperation == EVCardEx) |
|
590 { |
|
591 delete iOp; |
|
592 iOp = NULL; |
|
593 } |
|
594 else |
|
595 { |
|
596 delete iStoreContact; |
|
597 iStoreContact = NULL; |
|
598 if( iOp == &aOperation ) |
|
599 { |
|
600 delete iOp; |
|
601 iOp = NULL; |
|
602 } |
|
603 } |
|
604 TBuf<5> buf; |
|
605 buf.Num(aError); |
|
606 iLog->Log(KError); |
|
607 iLog->Log(buf); |
|
608 iLog->Log(KNewLine); |
|
609 |
|
610 iOperation = ENone; |
|
611 } |
|
612 |
|
613 void CContactsUT::StepComplete( |
|
614 MVPbkContactOperationBase& /*aOperation*/, |
|
615 TInt /*aStepSize*/ ) |
|
616 { |
|
617 _LIT(KFunc,"In StepComplete \n"); |
|
618 iLog->Log(KFunc); |
|
619 iLog->Log(KSuccess); |
|
620 iLog->Log(KNewLine); |
|
621 } |
|
622 |
|
623 TBool CContactsUT::StepFailed( |
|
624 MVPbkContactOperationBase& /*aOperation*/, |
|
625 TInt /*aStepSize*/, TInt /*aError*/ ) |
|
626 { |
|
627 _LIT(KFunc,"In StepFailed \n"); |
|
628 iLog->Log(KFunc); |
|
629 return EFalse; |
|
630 } |
|
631 |
|
632 void CContactsUT::OperationComplete( |
|
633 MVPbkContactOperationBase& /*aOperation*/ ) |
|
634 { |
|
635 CActiveScheduler::Stop(); |
|
636 _LIT(KFunc,"In OperationComplete \n"); |
|
637 iLog->Log(KFunc); |
|
638 iErr = KErrNone; |
|
639 iLog->Log(KSuccess); |
|
640 iLog->Log(KNewLine); |
|
641 } |
|
642 |
|
643 |
|
644 //Delete all contacts |
|
645 void CContactsUT::DeleteAllL() |
|
646 { |
|
647 // Print to UI |
|
648 _LIT( KContactsTest, "ContactsUT" ); |
|
649 _LIT( KExample, "In DeleteAllL" ); |
|
650 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
651 // Print to log file |
|
652 iLog->Log( KExample ); |
|
653 |
|
654 iErr = KErrNone; |
|
655 |
|
656 __UHEAP_MARK; |
|
657 iOp = iContactManager->MatchPhoneNumberL( |
|
658 KPhoneNumber, KPhoneNumber().Length(), *this ); |
|
659 CActiveScheduler::Start(); |
|
660 delete iOp; |
|
661 iOp = NULL; |
|
662 |
|
663 TInt count(iFindResults->Count()); |
|
664 iContactToDelete = CVPbkContactLinkArray::NewLC(); |
|
665 while(count) |
|
666 { |
|
667 MVPbkContactLink* link = iFindResults->At(--count).CloneLC(); |
|
668 iContactToDelete->AppendL(link); |
|
669 CleanupStack::Pop(); |
|
670 } |
|
671 delete iFindResults; |
|
672 iFindResults = NULL; |
|
673 |
|
674 iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
675 CActiveScheduler::Start(); |
|
676 delete iOp; |
|
677 iOp = NULL; |
|
678 CleanupStack::PopAndDestroy(iContactToDelete); |
|
679 iContactToDelete = NULL; |
|
680 |
|
681 |
|
682 __UHEAP_MARKEND; |
|
683 } |
|
684 |
|
685 //Add 1 contact |
|
686 void CContactsUT::AddOneContactL(TDesC& aName) |
|
687 { |
|
688 // Print to UI |
|
689 _LIT( KContactsTest, "ContactsUT" ); |
|
690 _LIT( KExample, "In AddOneContactL" ); |
|
691 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
692 // Print to log file |
|
693 iLog->Log( KExample ); |
|
694 |
|
695 iErr = KErrNone; |
|
696 |
|
697 __UHEAP_MARK; |
|
698 CVPbkFieldTypeRefsList* fieldTypeRefList = CVPbkFieldTypeRefsList::NewL(); |
|
699 CleanupStack::PushL(fieldTypeRefList); |
|
700 |
|
701 fieldTypeRefList->AppendL( |
|
702 *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_FIRSTNAME ) ); |
|
703 fieldTypeRefList->AppendL( |
|
704 *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN ) ); |
|
705 |
|
706 // Create first contact |
|
707 iStoreContact = iStore->CreateNewContactLC(); |
|
708 |
|
709 // Create contact field for contact |
|
710 MVPbkStoreContactField* field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
711 // Set contact field data |
|
712 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( aName ); |
|
713 // Add the contact field to contact |
|
714 iStoreContact->AddFieldL( field ); |
|
715 CleanupStack::Pop(); // field |
|
716 |
|
717 // Create contact field for contact |
|
718 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
719 // Set contact field data |
|
720 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KPhoneNumber ); |
|
721 // Add the contact field to contact |
|
722 iStoreContact->AddFieldL( field ); |
|
723 CleanupStack::Pop(); // field |
|
724 |
|
725 // Commit the new created contact to contact store |
|
726 iStoreContact->CommitL( *this ); |
|
727 CActiveScheduler::Start(); |
|
728 CleanupStack::PopAndDestroy(); // iStoreContact |
|
729 iStoreContact = NULL; |
|
730 CleanupStack::PopAndDestroy(fieldTypeRefList); |
|
731 __UHEAP_MARKEND; |
|
732 } |
|
733 |
|
734 //Check for contact |
|
735 void CContactsUT::CheckContactsL(TInt& aCount,RPointerArray<TDesC8>& aIdArray) |
|
736 { |
|
737 // Print to UI |
|
738 _LIT( KContactsTest, "ContactsUT" ); |
|
739 _LIT( KExample, "In CheckContactsL" ); |
|
740 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
741 // Print to log file |
|
742 iLog->Log( KExample ); |
|
743 |
|
744 iErr = KErrNone; |
|
745 |
|
746 //__UHEAP_MARK; |
|
747 iOp = iContactManager->MatchPhoneNumberL( |
|
748 KPhoneNumber, KPhoneNumber().Length(), *this ); |
|
749 CActiveScheduler::Start(); |
|
750 delete iOp; |
|
751 iOp = NULL; |
|
752 |
|
753 aCount = iFindResults->Count(); |
|
754 TInt count(aCount); |
|
755 while(count) |
|
756 { |
|
757 aIdArray.AppendL((const_cast<MVPbkContactLink&>(iFindResults->At(--count))).PackLC()); |
|
758 CleanupStack::Pop(); |
|
759 } |
|
760 delete iFindResults; |
|
761 iFindResults = NULL; |
|
762 // __UHEAP_MARKENDC(aCount); |
|
763 } |
|
764 |
|
765 // ----------------------------------------------------------------------------- |
|
766 // CContactsUT::?member_function |
|
767 // ?implementation_description |
|
768 // (other items were commented in a header). |
|
769 // ----------------------------------------------------------------------------- |
|
770 // |
|
771 TInt CContactsUT::AddContactSAPIL( CStifItemParser& aItem ) |
|
772 { |
|
773 // Print to UI |
|
774 _LIT( KContactsTest, "ContactsUT" ); |
|
775 _LIT( KExample, "In AddContactSAPIL" ); |
|
776 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
777 // Print to log file |
|
778 iLog->Log( KExample ); |
|
779 |
|
780 TInt i = 0; |
|
781 TPtrC string; |
|
782 _LIT( KParam, "Param[%i]: %S" ); |
|
783 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
784 { |
|
785 TestModuleIf().Printf( i, KContactsTest, |
|
786 KParam, i, &string ); |
|
787 i++; |
|
788 } |
|
789 |
|
790 iErr = KErrNone; |
|
791 |
|
792 DeleteAllL(); |
|
793 |
|
794 /**Add contact using SAPI Core class*/ |
|
795 |
|
796 _LIT8(KFirstName,"FirstName"); |
|
797 _LIT(KName,"Sikandar"); |
|
798 _LIT8(KNumber,"MobilePhoneGen"); |
|
799 |
|
800 __UHEAP_MARK; |
|
801 //instantiate service class |
|
802 CContactService* serviceHandle = CContactService::NewL(); |
|
803 CleanupStack::PushL(serviceHandle); |
|
804 iLog->Log( KServiceOpen ); |
|
805 |
|
806 CSingleContact* singleContact = CSingleContact::NewL(); |
|
807 CleanupStack::PushL(singleContact); |
|
808 iLog->Log(_L("single Contact created\n")); |
|
809 |
|
810 CSingleContactField* nameContactField = CSingleContactField::NewL(); |
|
811 CleanupStack::PushL(nameContactField); |
|
812 iLog->Log(_L("Name Contact Field created \n")); |
|
813 |
|
814 CSingleContactField* phoneContactField = CSingleContactField::NewL(); |
|
815 CleanupStack::PushL(phoneContactField); |
|
816 iLog->Log(_L("Phone Contact Field created \n")); |
|
817 |
|
818 nameContactField->SetFieldParamsL(KFirstName,KNullDesC,KName); |
|
819 singleContact->AddFieldToContactL(nameContactField); |
|
820 iLog->Log(_L("Name Contact Field added \n")); |
|
821 |
|
822 phoneContactField->SetFieldParamsL(KNumber,KNullDesC,KPhoneNumber); |
|
823 singleContact->AddFieldToContactL(phoneContactField); |
|
824 iLog->Log(_L("Phone Contact Field added \n")); |
|
825 |
|
826 serviceHandle->AddL(this,0,singleContact); |
|
827 iLog->Log(_L("AddL called\n")); |
|
828 iLog->Log(_L("Start Active Scheduler\n")); |
|
829 CActiveScheduler::Start(); |
|
830 |
|
831 CleanupStack::Pop(phoneContactField);//singleContactField |
|
832 CleanupStack::Pop(nameContactField);//singleContactField |
|
833 CleanupStack::PopAndDestroy(singleContact);//singleContact |
|
834 CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
835 iLog->Log( KServiceClose ); |
|
836 __UHEAP_MARKEND; |
|
837 /**end */ |
|
838 |
|
839 TInt count; |
|
840 RPointerArray<TDesC8> idArray; |
|
841 CheckContactsL(count,idArray); |
|
842 if(count != 1) |
|
843 { |
|
844 iErr = KErrGeneral; |
|
845 } |
|
846 idArray.ResetAndDestroy(); |
|
847 |
|
848 DeleteAllL(); |
|
849 return iErr; |
|
850 } |
|
851 |
|
852 // ----------------------------------------------------------------------------- |
|
853 // CContactsUT::?member_function |
|
854 // ?implementation_description |
|
855 // (other items were commented in a header). |
|
856 // ----------------------------------------------------------------------------- |
|
857 // |
|
858 TInt CContactsUT::DeleteContactSAPIL( CStifItemParser& aItem ) |
|
859 { |
|
860 // Print to UI |
|
861 _LIT( KContactsTest, "ContactsUT" ); |
|
862 _LIT( KExample, "In DeleteContactSAPIL" ); |
|
863 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
864 // Print to log file |
|
865 iLog->Log( KExample ); |
|
866 |
|
867 TInt i = 0; |
|
868 TPtrC string; |
|
869 _LIT( KParam, "Param[%i]: %S" ); |
|
870 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
871 { |
|
872 TestModuleIf().Printf( i, KContactsTest, |
|
873 KParam, i, &string ); |
|
874 i++; |
|
875 } |
|
876 |
|
877 iErr = KErrNone; |
|
878 |
|
879 DeleteAllL(); |
|
880 _LIT(KName,"SpiderMan"); |
|
881 TPtrC name(KName); |
|
882 AddOneContactL(name); |
|
883 |
|
884 TInt count(0); |
|
885 RPointerArray<TDesC8> idArray; |
|
886 CleanupClosePushL(idArray); |
|
887 CheckContactsL(count,idArray); |
|
888 if(count != 1) |
|
889 { |
|
890 return KErrGeneral; |
|
891 } |
|
892 |
|
893 /**Delete using SAPI core class*/ |
|
894 |
|
895 __UHEAP_MARK; |
|
896 CContactService* serviceHandle = CContactService::NewL(); |
|
897 CleanupStack::PushL(serviceHandle); |
|
898 iLog->Log( KServiceOpen ); |
|
899 |
|
900 serviceHandle->DeleteL(this,0,idArray); |
|
901 iLog->Log(_L("DeleteL called\n")); |
|
902 iLog->Log(_L("Start Active Scheduler\n")); |
|
903 CActiveScheduler::Start(); |
|
904 |
|
905 CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
906 iLog->Log( KServiceClose ); |
|
907 __UHEAP_MARKEND; |
|
908 /**end*/ |
|
909 CleanupStack::Pop(&idArray); |
|
910 idArray.ResetAndDestroy(); |
|
911 |
|
912 RPointerArray<TDesC8> idArray1; |
|
913 CleanupClosePushL(idArray1); |
|
914 CheckContactsL(count,idArray1); |
|
915 if(count) |
|
916 { |
|
917 iErr = KErrGeneral; |
|
918 } |
|
919 CleanupStack::Pop(&idArray1); |
|
920 idArray.ResetAndDestroy(); |
|
921 return iErr; |
|
922 |
|
923 } |
|
924 |
|
925 // ----------------------------------------------------------------------------- |
|
926 // CContactsUT::?member_function |
|
927 // ?implementation_description |
|
928 // (other items were commented in a header). |
|
929 // ----------------------------------------------------------------------------- |
|
930 // |
|
931 TInt CContactsUT::ModifyContactSAPIL( CStifItemParser& aItem ) |
|
932 { |
|
933 // Print to UI |
|
934 _LIT( KContactsTest, "ContactsUT" ); |
|
935 _LIT( KExample, "In ModifyContactSAPIL" ); |
|
936 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
937 // Print to log file |
|
938 iLog->Log( KExample ); |
|
939 |
|
940 TInt i = 0; |
|
941 TPtrC string; |
|
942 _LIT( KParam, "Param[%i]: %S" ); |
|
943 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
944 { |
|
945 TestModuleIf().Printf( i, KContactsTest, |
|
946 KParam, i, &string ); |
|
947 i++; |
|
948 } |
|
949 |
|
950 iErr = KErrNone; |
|
951 |
|
952 DeleteAllL(); |
|
953 _LIT(KName,"SuperMan"); |
|
954 TPtrC name(KName); |
|
955 AddOneContactL(name); |
|
956 |
|
957 TInt count(0); |
|
958 RPointerArray<TDesC8> idArray; |
|
959 CleanupClosePushL(idArray); |
|
960 CheckContactsL(count,idArray); |
|
961 if(count != 1) |
|
962 { |
|
963 return KErrGeneral; |
|
964 } |
|
965 |
|
966 /**Get using SAPI core class*/ |
|
967 __UHEAP_MARK; |
|
968 CContactService* serviceHandle = CContactService::NewL(); |
|
969 CleanupStack::PushL(serviceHandle); |
|
970 iLog->Log( KServiceOpen ); |
|
971 |
|
972 serviceHandle->GetListL(this,0,EContacts,*idArray[0]); |
|
973 iLog->Log(_L("GetListL called\n")); |
|
974 iLog->Log(_L("Start Active Scheduler\n")); |
|
975 CActiveScheduler::Start(); |
|
976 |
|
977 if(!iSingleContact) |
|
978 { |
|
979 return KErrGeneral; |
|
980 } |
|
981 |
|
982 _LIT(KName1,"SpiderMan"); |
|
983 _LIT8(KFirstName,"FirstName"); |
|
984 CSingleContactField* field = NULL; |
|
985 TInt fieldCount(iSingleContact->FieldCount()); |
|
986 while(fieldCount) |
|
987 { |
|
988 TPtrC8 fieldKey; |
|
989 TPtrC label; |
|
990 TPtrC value; |
|
991 field = iSingleContact->FieldAt(--fieldCount); |
|
992 field->GetFieldDataL(fieldKey,label,value); |
|
993 if(!fieldKey.Compare(KFirstName) && !value.Compare(KName)) |
|
994 { |
|
995 field->SetFieldParamsL(KFirstName,KNullDesC,KName1); |
|
996 iLog->Log(_L("Phone Contact Field modified \n")); |
|
997 break; |
|
998 } |
|
999 } |
|
1000 |
|
1001 __UHEAP_MARK; |
|
1002 serviceHandle->AddL(this,0,iSingleContact); |
|
1003 iLog->Log(_L("AddL called\n")); |
|
1004 iLog->Log(_L("Start Active Scheduler\n")); |
|
1005 CActiveScheduler::Start(); |
|
1006 __UHEAP_MARKEND; |
|
1007 |
|
1008 delete iSingleContact; |
|
1009 iSingleContact = NULL; |
|
1010 |
|
1011 CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
1012 iLog->Log( KServiceClose ); |
|
1013 __UHEAP_MARKEND; |
|
1014 /**end*/ |
|
1015 |
|
1016 |
|
1017 CleanupStack::Pop(&idArray); |
|
1018 idArray.ResetAndDestroy(); |
|
1019 |
|
1020 RPointerArray<TDesC8> idArray1; |
|
1021 CleanupClosePushL(idArray1); |
|
1022 CheckContactsL(count,idArray1); |
|
1023 if(count != 1) |
|
1024 { |
|
1025 iErr = KErrGeneral; |
|
1026 } |
|
1027 CleanupStack::Pop(); |
|
1028 idArray1.ResetAndDestroy(); |
|
1029 //to implement ..checking name |
|
1030 return iErr; |
|
1031 |
|
1032 } |
|
1033 |
|
1034 // ----------------------------------------------------------------------------- |
|
1035 // CContactsUT::?member_function |
|
1036 // ?implementation_description |
|
1037 // (other items were commented in a header). |
|
1038 // ----------------------------------------------------------------------------- |
|
1039 // |
|
1040 TInt CContactsUT::ImportContactSAPIL( CStifItemParser& aItem ) |
|
1041 { |
|
1042 // Print to UI |
|
1043 _LIT( KContactsTest, "ContactsUT" ); |
|
1044 _LIT( KExample, "In ImportContactSAPIL" ); |
|
1045 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
1046 // Print to log file |
|
1047 iLog->Log( KExample ); |
|
1048 |
|
1049 TInt i = 0; |
|
1050 TPtrC string; |
|
1051 _LIT( KParam, "Param[%i]: %S" ); |
|
1052 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
1053 { |
|
1054 TestModuleIf().Printf( i, KContactsTest, |
|
1055 KParam, i, &string ); |
|
1056 i++; |
|
1057 } |
|
1058 |
|
1059 iErr = KErrNone; |
|
1060 _LIT(KFileName,"c:\\vcardim.vcf"); |
|
1061 |
|
1062 /* DeleteAllL(); |
|
1063 |
|
1064 _LIT(KName,"SuperMan"); |
|
1065 TPtrC name(KName); |
|
1066 AddOneContactL(name); |
|
1067 |
|
1068 TInt count(0); |
|
1069 RPointerArray<TDesC8> idArray; |
|
1070 CleanupClosePushL(idArray); |
|
1071 CheckContactsL(count,idArray); |
|
1072 if(count != 1) |
|
1073 { |
|
1074 return KErrGeneral; |
|
1075 } |
|
1076 |
|
1077 //__UHEAP_MARK; |
|
1078 MVPbkContactLinkArray* linkArray = iContactManager->CreateLinksLC(*idArray[0]); |
|
1079 iVCardEngine = CVPbkVCardEng::NewL( *iContactManager ); |
|
1080 // Create the buffer to store the contact |
|
1081 iBuffer = HBufC8::NewL( 1024 ); |
|
1082 TPtr8 bufferPtr( iBuffer->Des() ); |
|
1083 iDestStream.Open( bufferPtr ); |
|
1084 //export the contact from MVPbkContactLink |
|
1085 // __UHEAP_MARK; |
|
1086 iOp = iVCardEngine->ExportVCardL( iDestStream, linkArray->At(0), *this ); |
|
1087 CActiveScheduler::Start(); |
|
1088 |
|
1089 // __UHEAP_MARKEND; |
|
1090 if( !iErr ) |
|
1091 { |
|
1092 iDestStream.CommitL(); |
|
1093 } |
|
1094 |
|
1095 iDestStream.Close(); |
|
1096 if(iBuffer) |
|
1097 { |
|
1098 RFile file; |
|
1099 CleanupClosePushL(file); |
|
1100 file.Replace(iRfs,KFileName,EFileWrite); |
|
1101 file.Write(0,*iBuffer); |
|
1102 CleanupStack::PopAndDestroy(&file); |
|
1103 } |
|
1104 delete iBuffer; |
|
1105 iBuffer = NULL; |
|
1106 delete iVCardEngine; |
|
1107 iVCardEngine = NULL; |
|
1108 CleanupStack::PopAndDestroy();//linkArray |
|
1109 //__UHEAP_MARKEND; |
|
1110 |
|
1111 CleanupStack::Pop(&idArray); |
|
1112 idArray.ResetAndDestroy(); |
|
1113 DeleteAllL(); |
|
1114 */ |
|
1115 DeleteAllL(); |
|
1116 __UHEAP_MARK; |
|
1117 CContactService* serviceHandle = CContactService::NewL(); |
|
1118 CleanupStack::PushL(serviceHandle); |
|
1119 iLog->Log( KServiceOpen ); |
|
1120 |
|
1121 TFileName importFile(KFileName); |
|
1122 |
|
1123 serviceHandle->ImportVCardToStoreL(this,0,importFile); |
|
1124 iLog->Log(_L("ImportVCardToStoreL called\n")); |
|
1125 iLog->Log(_L("Start Active Scheduler\n")); |
|
1126 CActiveScheduler::Start(); |
|
1127 |
|
1128 CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
1129 iLog->Log( KServiceClose ); |
|
1130 __UHEAP_MARKEND; |
|
1131 |
|
1132 TInt count = 0; |
|
1133 RPointerArray<TDesC8> idArray; |
|
1134 CleanupClosePushL(idArray); |
|
1135 CheckContactsL(count,idArray); |
|
1136 if(count != 1) |
|
1137 { |
|
1138 return KErrGeneral; |
|
1139 } |
|
1140 CleanupStack::Pop(&idArray); |
|
1141 idArray.ResetAndDestroy(); |
|
1142 return iErr; |
|
1143 } |
|
1144 |
|
1145 // ----------------------------------------------------------------------------- |
|
1146 // CContactsUT::?member_function |
|
1147 // ?implementation_description |
|
1148 // (other items were commented in a header). |
|
1149 // ----------------------------------------------------------------------------- |
|
1150 // |
|
1151 TInt CContactsUT::ExportContactSAPIL( CStifItemParser& aItem ) |
|
1152 { |
|
1153 // Print to UI |
|
1154 _LIT( KContactsTest, "ContactsUT" ); |
|
1155 _LIT( KExample, "In ExportContactSAPIL" ); |
|
1156 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
1157 // Print to log file |
|
1158 iLog->Log( KExample ); |
|
1159 |
|
1160 TInt i = 0; |
|
1161 TPtrC string; |
|
1162 _LIT( KParam, "Param[%i]: %S" ); |
|
1163 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
1164 { |
|
1165 TestModuleIf().Printf( i, KContactsTest, |
|
1166 KParam, i, &string ); |
|
1167 i++; |
|
1168 } |
|
1169 |
|
1170 iErr = KErrNone; |
|
1171 _LIT(KFileName,"c:\\vcardim.vcf"); |
|
1172 _LIT(KFileName1,"c:\\vcardim1.vcf"); |
|
1173 |
|
1174 DeleteAllL(); |
|
1175 |
|
1176 _LIT(KName,"SuperMan"); |
|
1177 TPtrC name(KName); |
|
1178 AddOneContactL(name); |
|
1179 |
|
1180 _LIT(KName1,"SpiderMan"); |
|
1181 TPtrC name1(KName1); |
|
1182 AddOneContactL(name1); |
|
1183 |
|
1184 TInt count(0); |
|
1185 RPointerArray<TDesC8> idArray; |
|
1186 CleanupClosePushL(idArray); |
|
1187 CheckContactsL(count,idArray); |
|
1188 TInt ret = iRfs.Delete(KFileName); |
|
1189 // ret = iRfs.Delete(KFileName1); |
|
1190 /* if(count != 1) |
|
1191 { |
|
1192 return KErrGeneral; |
|
1193 }*/ |
|
1194 |
|
1195 /* __UHEAP_MARK; |
|
1196 RFile writeStream; |
|
1197 CleanupClosePushL(writeStream); |
|
1198 User::LeaveIfError(writeStream.Create(iRfs,KFileName,EFileWrite)); |
|
1199 while(count) |
|
1200 { |
|
1201 writeStream.Write(*idArray[--count]); |
|
1202 } |
|
1203 CleanupStack::PopAndDestroy(&writeStream); |
|
1204 __UHEAP_MARKEND; |
|
1205 */ |
|
1206 //iBuffer = HBufC8::NewL( 1024 ); |
|
1207 //TPtr8 bfrPtr(iBuffer->Des()); |
|
1208 // __UHEAP_MARK; |
|
1209 //RFileReadStream readStream; |
|
1210 // CleanupClosePushL(readStream); |
|
1211 // User::LeaveIfError(readStream.Open(iRfs,KFileName,EFileRead)); |
|
1212 |
|
1213 //TInt cells = User::CountAllocCells(); |
|
1214 __UHEAP_MARK; |
|
1215 RFileWriteStream destStream; |
|
1216 CleanupClosePushL(destStream); |
|
1217 User::LeaveIfError(destStream.Create(iRfs,KFileName,EFileWrite)); |
|
1218 iVCardEngine = CVPbkVCardEng::NewL( *iContactManager ); |
|
1219 while(count) |
|
1220 { |
|
1221 MVPbkContactLinkArray* linkArray = iContactManager->CreateLinksLC(*idArray[--count]); |
|
1222 const MVPbkContactLink& link = linkArray->At(0); |
|
1223 iOp = iVCardEngine->ExportVCardL( destStream, link, *this ); |
|
1224 CActiveScheduler::Start(); |
|
1225 destStream.CommitL(); |
|
1226 CleanupStack::PopAndDestroy(); |
|
1227 } |
|
1228 delete iVCardEngine; |
|
1229 iVCardEngine = NULL; |
|
1230 CleanupStack::PopAndDestroy(&destStream); |
|
1231 __UHEAP_MARKEND; |
|
1232 CleanupStack::Pop(&idArray); |
|
1233 idArray.ResetAndDestroy(); |
|
1234 |
|
1235 /* |
|
1236 //CleanupStack::PushL(linkArray); |
|
1237 cells = User::CountAllocCells(); |
|
1238 iVCardEngine = CVPbkVCardEng::NewL( *iContactManager ); |
|
1239 |
|
1240 cells = User::CountAllocCells(); |
|
1241 RDesWriteStream destStream; |
|
1242 CleanupClosePushL(destStream); |
|
1243 //User::LeaveIfError(destStream.Create(iRfs,KFileName1,EFileWrite)); |
|
1244 destStream.Open(bfrPtr); |
|
1245 TInt links = linkArray->Count(); |
|
1246 while(links) |
|
1247 { |
|
1248 const MVPbkContactLink& link = linkArray->At(--links); |
|
1249 iOp = iVCardEngine->ExportVCardL( destStream, link, *this ); |
|
1250 CActiveScheduler::Start(); |
|
1251 } |
|
1252 destStream.CommitL(); |
|
1253 CleanupStack::PopAndDestroy(&destStream); |
|
1254 |
|
1255 cells = User::CountAllocCells(); |
|
1256 delete iVCardEngine; |
|
1257 iVCardEngine = NULL; |
|
1258 cells = User::CountAllocCells(); |
|
1259 |
|
1260 CleanupStack::PopAndDestroy(); |
|
1261 cells = User::CountAllocCells(); |
|
1262 CleanupStack::PopAndDestroy(&readStream); |
|
1263 |
|
1264 // __UHEAP_MARKEND; |
|
1265 if(iBuffer) |
|
1266 { |
|
1267 RFile file; |
|
1268 CleanupClosePushL(file); |
|
1269 file.Replace(iRfs,KFileName,EFileWrite); |
|
1270 file.Write(0,*iBuffer); |
|
1271 CleanupStack::PopAndDestroy(&file); |
|
1272 } |
|
1273 delete iBuffer; |
|
1274 iBuffer = NULL; |
|
1275 CleanupStack::Pop(&idArray); |
|
1276 idArray.ResetAndDestroy(); |
|
1277 /* |
|
1278 // Create the buffer to store the contact |
|
1279 iBuffer = HBufC8::NewL( 1024 ); |
|
1280 TPtr8 bufferPtr( iBuffer->Des() ); |
|
1281 iDestStream.Open( bufferPtr ); |
|
1282 //export the contact from MVPbkContactLink |
|
1283 // __UHEAP_MARK; |
|
1284 |
|
1285 CActiveScheduler::Start(); |
|
1286 |
|
1287 // __UHEAP_MARKEND; |
|
1288 if( !iErr ) |
|
1289 { |
|
1290 iDestStream.CommitL(); |
|
1291 } |
|
1292 |
|
1293 iDestStream.Close(); |
|
1294 if(iBuffer) |
|
1295 { |
|
1296 RFile file; |
|
1297 CleanupClosePushL(file); |
|
1298 file.Replace(iRfs,KFileName,EFileWrite); |
|
1299 file.Write(0,*iBuffer); |
|
1300 CleanupStack::PopAndDestroy(&file); |
|
1301 } |
|
1302 delete iBuffer; |
|
1303 iBuffer = NULL; |
|
1304 delete iVCardEngine; |
|
1305 iVCardEngine = NULL; |
|
1306 CleanupStack::PopAndDestroy();//linkArray |
|
1307 //__UHEAP_MARKEND; |
|
1308 |
|
1309 CleanupStack::Pop(&idArray); |
|
1310 idArray.ResetAndDestroy(); |
|
1311 DeleteAllL(); |
|
1312 */ |
|
1313 /* __UHEAP_MARK; |
|
1314 CContactService* serviceHandle = CContactService::NewL(); |
|
1315 CleanupStack::PushL(serviceHandle); |
|
1316 iLog->Log( KServiceOpen ); |
|
1317 |
|
1318 TFileName exportFile(KFileName); |
|
1319 |
|
1320 serviceHandle->ExportVCardL(this,0,exportFile,idArray); |
|
1321 iLog->Log(_L("ExportVCardL called\n")); |
|
1322 iLog->Log(_L("Start Active Scheduler\n")); |
|
1323 CActiveScheduler::Start(); |
|
1324 |
|
1325 CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
1326 iLog->Log( KServiceClose ); |
|
1327 __UHEAP_MARKEND; |
|
1328 *//* |
|
1329 TInt count = 0; |
|
1330 RPointerArray<TDesC8> idArray; |
|
1331 CleanupClosePushL(idArray); |
|
1332 CheckContactsL(count,idArray); |
|
1333 if(count != 1) |
|
1334 { |
|
1335 return KErrGeneral; |
|
1336 }*/ |
|
1337 /* CleanupStack::Pop(&idArray); |
|
1338 idArray.ResetAndDestroy();*/ |
|
1339 return iErr; |
|
1340 } |
|
1341 // ----------------------------------------------------------------------------- |
|
1342 // CContactsUT::?member_function |
|
1343 // ?implementation_description |
|
1344 // (other items were commented in a header). |
|
1345 // ----------------------------------------------------------------------------- |
|
1346 // |
|
1347 TInt CContactsUT::GetListDeleteContactL( CStifItemParser& aItem ) |
|
1348 { |
|
1349 // Print to UI |
|
1350 _LIT( KContactsTest, "ContactsUT" ); |
|
1351 _LIT( KExample, "In Add" ); |
|
1352 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
1353 // Print to log file |
|
1354 iLog->Log( KExample ); |
|
1355 |
|
1356 TInt i = 0; |
|
1357 TPtrC string; |
|
1358 _LIT( KParam, "Param[%i]: %S" ); |
|
1359 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
1360 { |
|
1361 TestModuleIf().Printf( i, KContactsTest, |
|
1362 KParam, i, &string ); |
|
1363 i++; |
|
1364 } |
|
1365 |
|
1366 iErr = KErrNone; |
|
1367 |
|
1368 |
|
1369 /**Getlist using SAPI core class*/ |
|
1370 |
|
1371 //__UHEAP_MARK; |
|
1372 CContactService* serviceHandle = CContactService::NewL(); |
|
1373 CleanupStack::PushL(serviceHandle); |
|
1374 iLog->Log( KServiceOpen ); |
|
1375 |
|
1376 iOperation = EGetContactDelete; |
|
1377 serviceHandle->GetListL(this,0,EContacts); |
|
1378 iLog->Log(_L("GetListL called\n")); |
|
1379 iLog->Log(_L("Start Active Scheduler\n")); |
|
1380 CActiveScheduler::Start(); |
|
1381 |
|
1382 //iOperation = EGetContact; |
|
1383 //iServiceHandle->GetListL(this,0,EContacts,*iBuffer); |
|
1384 //CActiveScheduler::Start(); |
|
1385 /**Delete using SAPI core class*/ |
|
1386 |
|
1387 // __UHEAP_MARK; |
|
1388 RPointerArray<TDesC8> idArray; |
|
1389 CleanupClosePushL(idArray); |
|
1390 idArray.AppendL(iBuffer); |
|
1391 |
|
1392 |
|
1393 serviceHandle->DeleteL(this,0,idArray); |
|
1394 iLog->Log(_L("DeleteL called\n")); |
|
1395 iLog->Log(_L("Start Active Scheduler\n")); |
|
1396 CActiveScheduler::Start(); |
|
1397 |
|
1398 |
|
1399 CleanupStack::PopAndDestroy(&idArray);//singleContactField |
|
1400 |
|
1401 CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
1402 iLog->Log( KServiceClose ); |
|
1403 // __UHEAP_MARKEND; |
|
1404 |
|
1405 |
|
1406 |
|
1407 return iErr; |
|
1408 } |
|
1409 // ----------------------------------------------------------------------------- |
|
1410 // CContactsUT::?member_function |
|
1411 // ?implementation_description |
|
1412 // (other items were commented in a header). |
|
1413 // ----------------------------------------------------------------------------- |
|
1414 // |
|
1415 TInt CContactsUT::AddContactGetListL( CStifItemParser& aItem ) |
|
1416 { |
|
1417 // Print to UI |
|
1418 _LIT( KContactsTest, "ContactsUT" ); |
|
1419 _LIT( KExample, "In Add" ); |
|
1420 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
1421 // Print to log file |
|
1422 iLog->Log( KExample ); |
|
1423 |
|
1424 TInt i = 0; |
|
1425 TPtrC string; |
|
1426 _LIT( KParam, "Param[%i]: %S" ); |
|
1427 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
1428 { |
|
1429 TestModuleIf().Printf( i, KContactsTest, |
|
1430 KParam, i, &string ); |
|
1431 i++; |
|
1432 } |
|
1433 |
|
1434 iErr = KErrNone; |
|
1435 |
|
1436 /**Add contact using SAPI Core class*/ |
|
1437 |
|
1438 _LIT8(KFirstName,"FirstName"); |
|
1439 _LIT(KName,"Kats"); |
|
1440 _LIT8(KNumber,"MobilePhoneHome"); |
|
1441 _LIT(KPhone,"98789"); |
|
1442 |
|
1443 // __UHEAP_MARK; |
|
1444 //instantiate service class |
|
1445 CContactService* serviceHandle = CContactService::NewL(); |
|
1446 CleanupStack::PushL(serviceHandle); |
|
1447 iLog->Log( KServiceOpen ); |
|
1448 |
|
1449 CSingleContact* singleContact = CSingleContact::NewL(); |
|
1450 CleanupStack::PushL(singleContact); |
|
1451 iLog->Log(_L("single Contact created\n")); |
|
1452 |
|
1453 CSingleContactField* nameContactField = CSingleContactField::NewL(); |
|
1454 CleanupStack::PushL(nameContactField); |
|
1455 iLog->Log(_L("Name Contact Field created \n")); |
|
1456 |
|
1457 CSingleContactField* phoneContactField = CSingleContactField::NewL(); |
|
1458 CleanupStack::PushL(phoneContactField); |
|
1459 iLog->Log(_L("Phone Contact Field created \n")); |
|
1460 |
|
1461 nameContactField->SetFieldParamsL(KFirstName,KNullDesC,KName); |
|
1462 singleContact->AddFieldToContactL(nameContactField); |
|
1463 iLog->Log(_L("Name Contact Field added \n")); |
|
1464 |
|
1465 phoneContactField->SetFieldParamsL(KNumber,KNullDesC,KPhone); |
|
1466 singleContact->AddFieldToContactL(phoneContactField); |
|
1467 iLog->Log(_L("Phone Contact Field added \n")); |
|
1468 |
|
1469 serviceHandle->AddL(this,0,singleContact,KNullDesC8,KNullDesC); |
|
1470 iLog->Log(_L("AddL called\n")); |
|
1471 iLog->Log(_L("Start Active Scheduler\n")); |
|
1472 CActiveScheduler::Start(); |
|
1473 |
|
1474 CleanupStack::Pop(phoneContactField);//singleContactField |
|
1475 CleanupStack::Pop(nameContactField);//singleContactField |
|
1476 CleanupStack::PopAndDestroy(singleContact);//singleContact |
|
1477 // CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
1478 // iLog->Log( KServiceClose ); |
|
1479 // __UHEAP_MARKENDC(1); |
|
1480 /**end */ |
|
1481 |
|
1482 if(iErr) |
|
1483 { |
|
1484 return iErr; |
|
1485 } |
|
1486 |
|
1487 /**Getlist using SAPI core class*/ |
|
1488 |
|
1489 //__UHEAP_MARK; |
|
1490 //serviceHandle = CContactService::NewL(); |
|
1491 // CleanupStack::PushL(serviceHandle); |
|
1492 iLog->Log( KServiceOpen ); |
|
1493 |
|
1494 iOperation = EGetContact; |
|
1495 serviceHandle->GetListL(this,0,EContacts); |
|
1496 iLog->Log(_L("GetListL called\n")); |
|
1497 iLog->Log(_L("Start Active Scheduler\n")); |
|
1498 CActiveScheduler::Start(); |
|
1499 |
|
1500 //iOperation = EGetContact; |
|
1501 //iServiceHandle->GetListL(this,0,EContacts,*iBuffer); |
|
1502 //CActiveScheduler::Start(); |
|
1503 |
|
1504 CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
1505 iLog->Log( KServiceClose ); |
|
1506 // __UHEAP_MARKEND; |
|
1507 |
|
1508 if(iErr) |
|
1509 { |
|
1510 return iErr; |
|
1511 } |
|
1512 /**Delete using virtual Phonebook */ |
|
1513 |
|
1514 |
|
1515 // Create find operation |
|
1516 iOp = iContactManager->MatchPhoneNumberL( |
|
1517 KPhone, KPhone().Length(), *this ); |
|
1518 CActiveScheduler::Start(); |
|
1519 |
|
1520 iErr = KErrGeneral; |
|
1521 TInt count(iFindResults->Count()); |
|
1522 while(count) |
|
1523 { |
|
1524 iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
1525 iContactToDelete->AppendL(&(const_cast<MVPbkContactLink&>(iFindResults->At(--count)))); |
|
1526 iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
1527 CActiveScheduler::Start(); |
|
1528 } |
|
1529 /**end */ |
|
1530 |
|
1531 |
|
1532 return iErr; |
|
1533 } |
|
1534 // ----------------------------------------------------------------------------- |
|
1535 // CContactsUT::?member_function |
|
1536 // ?implementation_description |
|
1537 // (other items were commented in a header). |
|
1538 // ----------------------------------------------------------------------------- |
|
1539 // |
|
1540 TInt CContactsUT::GetGroupsL( CStifItemParser& aItem ) |
|
1541 { |
|
1542 |
|
1543 // Print to UI |
|
1544 _LIT( KContactsTest, "ContactsUT" ); |
|
1545 _LIT( KExample, "In Add" ); |
|
1546 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
1547 // Print to log file |
|
1548 iLog->Log( KExample ); |
|
1549 |
|
1550 TInt i = 0; |
|
1551 TPtrC string; |
|
1552 _LIT( KParam, "Param[%i]: %S" ); |
|
1553 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
1554 { |
|
1555 TestModuleIf().Printf( i, KContactsTest, |
|
1556 KParam, i, &string ); |
|
1557 i++; |
|
1558 } |
|
1559 |
|
1560 iErr = KErrNone; |
|
1561 |
|
1562 /**Add 1 group using virtual phonebook */ |
|
1563 |
|
1564 |
|
1565 |
|
1566 iGroup = iStore->CreateNewContactGroupLC(); |
|
1567 iGroup->SetGroupLabelL(KGroup1); |
|
1568 iOperation = EGroup; |
|
1569 iGroup->CommitL(*this); |
|
1570 |
|
1571 CActiveScheduler::Start(); |
|
1572 CleanupStack::Pop(); |
|
1573 |
|
1574 |
|
1575 // __UHEAP_MARK; |
|
1576 iServiceHandle = CContactService::NewL(); |
|
1577 iLog->Log( KServiceOpen ); |
|
1578 |
|
1579 iOperation = EGetGroup; |
|
1580 iServiceHandle->GetListL(this,0,EGroups); |
|
1581 iLog->Log(_L("GetListL called\n")); |
|
1582 iLog->Log(_L("Start Active Scheduler\n")); |
|
1583 CActiveScheduler::Start(); |
|
1584 iOperation = EGetContactDelete; |
|
1585 iServiceHandle->GetListL(this, 0, EGroups, *iBuffer); |
|
1586 CActiveScheduler::Start(); |
|
1587 |
|
1588 delete iServiceHandle;//serviceHandle |
|
1589 iServiceHandle = NULL; |
|
1590 iLog->Log( KServiceClose ); |
|
1591 // __UHEAP_MARKEND; |
|
1592 |
|
1593 |
|
1594 |
|
1595 |
|
1596 return iErr; |
|
1597 |
|
1598 } |
|
1599 |
|
1600 TInt CContactsUT::GetDatabaseL( CStifItemParser& aItem ) |
|
1601 { |
|
1602 |
|
1603 // Print to UI |
|
1604 _LIT( KContactsTest, "ContactsUT" ); |
|
1605 _LIT( KExample, "In Add" ); |
|
1606 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
1607 // Print to log file |
|
1608 iLog->Log( KExample ); |
|
1609 |
|
1610 TInt i = 0; |
|
1611 TPtrC string; |
|
1612 _LIT( KParam, "Param[%i]: %S" ); |
|
1613 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
1614 { |
|
1615 TestModuleIf().Printf( i, KContactsTest, |
|
1616 KParam, i, &string ); |
|
1617 i++; |
|
1618 } |
|
1619 |
|
1620 iErr = KErrNone; |
|
1621 |
|
1622 |
|
1623 |
|
1624 // __UHEAP_MARK; |
|
1625 iServiceHandle = CContactService::NewL(); |
|
1626 iLog->Log( KServiceOpen ); |
|
1627 |
|
1628 iOperation = EGetDatabase; |
|
1629 |
|
1630 CContactIter* iter = CContactIter::NewL(); |
|
1631 iServiceHandle->GetListL(*iter); |
|
1632 iLog->Log(_L("GetListL called\n")); |
|
1633 TPtrC DbName; |
|
1634 iter->NextL(DbName); |
|
1635 |
|
1636 while(!DbName.Compare(KNullDesC)) |
|
1637 { |
|
1638 iter->NextL(DbName); |
|
1639 } |
|
1640 |
|
1641 delete iServiceHandle;//serviceHandle |
|
1642 iServiceHandle = NULL; |
|
1643 iLog->Log( KServiceClose ); |
|
1644 // __UHEAP_MARKEND; |
|
1645 |
|
1646 |
|
1647 |
|
1648 |
|
1649 return iErr; |
|
1650 |
|
1651 } |
|
1652 |
|
1653 // ----------------------------------------------------------------------------- |
|
1654 // CContactsUT::?member_function |
|
1655 // ?implementation_description |
|
1656 // (other items were commented in a header). |
|
1657 // ----------------------------------------------------------------------------- |
|
1658 // |
|
1659 TInt CContactsUT::GetContactsL( CStifItemParser& aItem ) |
|
1660 { |
|
1661 |
|
1662 // Print to UI |
|
1663 _LIT( KContactsTest, "ContactsUT" ); |
|
1664 _LIT( KExample, "In Add" ); |
|
1665 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
1666 // Print to log file |
|
1667 iLog->Log( KExample ); |
|
1668 |
|
1669 TInt i = 0; |
|
1670 TPtrC string; |
|
1671 _LIT( KParam, "Param[%i]: %S" ); |
|
1672 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
1673 { |
|
1674 TestModuleIf().Printf( i, KContactsTest, |
|
1675 KParam, i, &string ); |
|
1676 i++; |
|
1677 } |
|
1678 |
|
1679 iErr = KErrNone; |
|
1680 |
|
1681 /**Delete using virtual Phonebook */ |
|
1682 |
|
1683 _LIT(KPhone,"13579"); |
|
1684 // Create find operation |
|
1685 iOp = iContactManager->MatchPhoneNumberL( |
|
1686 KPhone, KPhone().Length(), *this ); |
|
1687 CActiveScheduler::Start(); |
|
1688 |
|
1689 iErr = KErrGeneral; |
|
1690 TInt count1(iFindResults->Count()); |
|
1691 while(count1) |
|
1692 { |
|
1693 iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
1694 iContactToDelete->AppendL(&(const_cast<MVPbkContactLink&>(iFindResults->At(--count1)))); |
|
1695 iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
1696 CActiveScheduler::Start(); |
|
1697 } |
|
1698 /**end */ |
|
1699 |
|
1700 /**Add 2 contacts using virtual phonebook*/ |
|
1701 |
|
1702 CVPbkFieldTypeRefsList* fieldTypeRefList = CVPbkFieldTypeRefsList::NewL(); |
|
1703 CleanupStack::PushL(fieldTypeRefList); |
|
1704 |
|
1705 fieldTypeRefList->AppendL( |
|
1706 *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_FIRSTNAME ) ); |
|
1707 fieldTypeRefList->AppendL( |
|
1708 *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN ) ); |
|
1709 |
|
1710 // Create first contact |
|
1711 iStoreContact = iStore->CreateNewContactLC(); |
|
1712 |
|
1713 // Create contact field for contact |
|
1714 MVPbkStoreContactField* field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
1715 // Set contact field data |
|
1716 _LIT(KFirstName,"Tenali"); |
|
1717 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstName ); |
|
1718 // Add the contact field to contact |
|
1719 iStoreContact->AddFieldL( field ); |
|
1720 CleanupStack::Pop(); // field |
|
1721 |
|
1722 // Create contact field for contact |
|
1723 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
1724 // Set contact field data |
|
1725 _LIT(KFirstNumber,"13579"); |
|
1726 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstNumber ); |
|
1727 // Add the contact field to contact |
|
1728 iStoreContact->AddFieldL( field ); |
|
1729 CleanupStack::Pop(); // field |
|
1730 |
|
1731 // Commit the new created contact to contact store |
|
1732 iStoreContact->CommitL( *this ); |
|
1733 CActiveScheduler::Start(); |
|
1734 CleanupStack::Pop(); // iStoreContact |
|
1735 |
|
1736 |
|
1737 // Create second contact |
|
1738 iStoreContact = iStore->CreateNewContactLC(); |
|
1739 |
|
1740 // Create contact field for contact |
|
1741 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
1742 // Set contact field data |
|
1743 _LIT(KSecondName,"Birbal"); |
|
1744 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondName ); |
|
1745 // Add the contact field to contact |
|
1746 iStoreContact->AddFieldL( field ); |
|
1747 CleanupStack::Pop(); // field |
|
1748 |
|
1749 // Create contact field for contact |
|
1750 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
1751 // Set contact field data |
|
1752 _LIT(KSecondNumber,"13579"); |
|
1753 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondNumber ); |
|
1754 // Add the contact field to contact |
|
1755 iStoreContact->AddFieldL( field ); |
|
1756 CleanupStack::Pop(); // field |
|
1757 |
|
1758 // Commit the new created contact to contact store |
|
1759 iStoreContact->CommitL( *this ); |
|
1760 CActiveScheduler::Start(); |
|
1761 CleanupStack::Pop(); // iStoreContact |
|
1762 |
|
1763 CleanupStack::PopAndDestroy(fieldTypeRefList); |
|
1764 /**end*/ |
|
1765 __UHEAP_MARK; |
|
1766 iServiceHandle = CContactService::NewL(); |
|
1767 iLog->Log( KServiceOpen ); |
|
1768 |
|
1769 iOperation = EGetContact; |
|
1770 iServiceHandle->GetListL(this,0,EContacts); |
|
1771 iLog->Log(_L("GetListL called\n")); |
|
1772 iLog->Log(_L("Start Active Scheduler\n")); |
|
1773 CActiveScheduler::Start(); |
|
1774 |
|
1775 delete iServiceHandle;//serviceHandle |
|
1776 iServiceHandle = NULL; |
|
1777 iLog->Log( KServiceClose ); |
|
1778 __UHEAP_MARKEND; |
|
1779 return iErr; |
|
1780 |
|
1781 } |
|
1782 |
|
1783 |
|
1784 TInt CContactsUT::GetContactsAscOrderL( CStifItemParser& aItem ) |
|
1785 { |
|
1786 |
|
1787 // Print to UI |
|
1788 _LIT( KContactsTest, "ContactsUT" ); |
|
1789 _LIT( KExample, "In Add" ); |
|
1790 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
1791 // Print to log file |
|
1792 iLog->Log( KExample ); |
|
1793 |
|
1794 TInt i = 0; |
|
1795 TPtrC string; |
|
1796 _LIT( KParam, "Param[%i]: %S" ); |
|
1797 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
1798 { |
|
1799 TestModuleIf().Printf( i, KContactsTest, |
|
1800 KParam, i, &string ); |
|
1801 i++; |
|
1802 } |
|
1803 |
|
1804 iErr = KErrNone; |
|
1805 |
|
1806 |
|
1807 _LIT(KPhone,"13579"); |
|
1808 // Create find operation |
|
1809 iOp = iContactManager->MatchPhoneNumberL( |
|
1810 KPhone, KPhone().Length(), *this ); |
|
1811 CActiveScheduler::Start(); |
|
1812 |
|
1813 iErr = KErrGeneral; |
|
1814 TInt count1(iFindResults->Count()); |
|
1815 while(count1) |
|
1816 { |
|
1817 iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
1818 iContactToDelete->AppendL(&(const_cast<MVPbkContactLink&>(iFindResults->At(--count1)))); |
|
1819 iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
1820 CActiveScheduler::Start(); |
|
1821 } |
|
1822 /*end */ |
|
1823 |
|
1824 /**Add 2 contact using virtual phonebook*/ |
|
1825 |
|
1826 CVPbkFieldTypeRefsList* fieldTypeRefList = CVPbkFieldTypeRefsList::NewL(); |
|
1827 CleanupStack::PushL(fieldTypeRefList); |
|
1828 |
|
1829 fieldTypeRefList->AppendL( |
|
1830 *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_FIRSTNAME ) ); |
|
1831 fieldTypeRefList->AppendL( |
|
1832 *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN ) ); |
|
1833 |
|
1834 // Create first contact |
|
1835 iStoreContact = iStore->CreateNewContactLC(); |
|
1836 |
|
1837 // Create contact field for contact |
|
1838 MVPbkStoreContactField* field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
1839 // Set contact field data |
|
1840 _LIT(KFirstName,"Tenali"); |
|
1841 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstName ); |
|
1842 // Add the contact field to contact |
|
1843 iStoreContact->AddFieldL( field ); |
|
1844 CleanupStack::Pop(); // field |
|
1845 |
|
1846 // Create contact field for contact |
|
1847 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
1848 // Set contact field data |
|
1849 _LIT(KFirstNumber,"13579"); |
|
1850 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstNumber ); |
|
1851 // Add the contact field to contact |
|
1852 iStoreContact->AddFieldL( field ); |
|
1853 CleanupStack::Pop(); // field |
|
1854 |
|
1855 // Commit the new created contact to contact store |
|
1856 iStoreContact->CommitL( *this ); |
|
1857 CActiveScheduler::Start(); |
|
1858 CleanupStack::Pop(); // iStoreContact |
|
1859 |
|
1860 |
|
1861 // Create second contact |
|
1862 iStoreContact = iStore->CreateNewContactLC(); |
|
1863 |
|
1864 // Create contact field for contact |
|
1865 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
1866 // Set contact field data |
|
1867 _LIT(KSecondName,"Birbal"); |
|
1868 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondName ); |
|
1869 // Add the contact field to contact |
|
1870 iStoreContact->AddFieldL( field ); |
|
1871 CleanupStack::Pop(); // field |
|
1872 |
|
1873 // Create contact field for contact |
|
1874 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
1875 // Set contact field data |
|
1876 _LIT(KSecondNumber,"13579"); |
|
1877 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondNumber ); |
|
1878 // Add the contact field to contact |
|
1879 iStoreContact->AddFieldL( field ); |
|
1880 CleanupStack::Pop(); // field |
|
1881 |
|
1882 // Commit the new created contact to contact store |
|
1883 iStoreContact->CommitL( *this ); |
|
1884 CActiveScheduler::Start(); |
|
1885 CleanupStack::Pop(); // iStoreContact |
|
1886 |
|
1887 CleanupStack::PopAndDestroy(fieldTypeRefList); |
|
1888 /**end*/ |
|
1889 |
|
1890 |
|
1891 |
|
1892 |
|
1893 |
|
1894 /**GetList using SAPI Core class */ |
|
1895 // __UHEAP_MARK; |
|
1896 iServiceHandle = CContactService::NewL(); |
|
1897 iLog->Log( KServiceOpen ); |
|
1898 |
|
1899 iOperation = EAscContact; |
|
1900 iServiceHandle->GetListL(this,0,EContacts,KNullDesC8,_L(""),NULL,EAsc); |
|
1901 iLog->Log(_L("GetListL called\n")); |
|
1902 iLog->Log(_L("Start Active Scheduler\n")); |
|
1903 CActiveScheduler::Start(); |
|
1904 |
|
1905 delete iServiceHandle;//serviceHandle |
|
1906 iServiceHandle = NULL; |
|
1907 iLog->Log( KServiceClose ); |
|
1908 |
|
1909 |
|
1910 return iErr; |
|
1911 |
|
1912 } |
|
1913 |
|
1914 |
|
1915 |
|
1916 TInt CContactsUT::GetContactsDscOrderL( CStifItemParser& aItem ) |
|
1917 { |
|
1918 |
|
1919 // Print to UI |
|
1920 _LIT( KContactsTest, "ContactsUT" ); |
|
1921 _LIT( KExample, "In Add" ); |
|
1922 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
1923 // Print to log file |
|
1924 iLog->Log( KExample ); |
|
1925 |
|
1926 TInt i = 0; |
|
1927 TPtrC string; |
|
1928 _LIT( KParam, "Param[%i]: %S" ); |
|
1929 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
1930 { |
|
1931 TestModuleIf().Printf( i, KContactsTest, |
|
1932 KParam, i, &string ); |
|
1933 i++; |
|
1934 } |
|
1935 |
|
1936 iErr = KErrNone; |
|
1937 |
|
1938 /**Delete using virtual Phonebook */ |
|
1939 |
|
1940 _LIT(KPhone,"13579"); |
|
1941 // Create find operation |
|
1942 iOp = iContactManager->MatchPhoneNumberL( |
|
1943 KPhone, KPhone().Length(), *this ); |
|
1944 CActiveScheduler::Start(); |
|
1945 |
|
1946 iErr = KErrGeneral; |
|
1947 TInt count1(iFindResults->Count()); |
|
1948 while(count1) |
|
1949 { |
|
1950 iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
1951 iContactToDelete->AppendL(&(const_cast<MVPbkContactLink&>(iFindResults->At(--count1)))); |
|
1952 iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
1953 CActiveScheduler::Start(); |
|
1954 } |
|
1955 /**end */ |
|
1956 |
|
1957 /**Add 2 contact using virtual phonebook*/ |
|
1958 |
|
1959 CVPbkFieldTypeRefsList* fieldTypeRefList = CVPbkFieldTypeRefsList::NewL(); |
|
1960 CleanupStack::PushL(fieldTypeRefList); |
|
1961 |
|
1962 fieldTypeRefList->AppendL( |
|
1963 *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_FIRSTNAME ) ); |
|
1964 fieldTypeRefList->AppendL( |
|
1965 *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN ) ); |
|
1966 |
|
1967 // Create first contact |
|
1968 iStoreContact = iStore->CreateNewContactLC(); |
|
1969 |
|
1970 // Create contact field for contact |
|
1971 MVPbkStoreContactField* field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
1972 // Set contact field data |
|
1973 _LIT(KFirstName,"Tenali"); |
|
1974 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstName ); |
|
1975 // Add the contact field to contact |
|
1976 iStoreContact->AddFieldL( field ); |
|
1977 CleanupStack::Pop(); // field |
|
1978 |
|
1979 // Create contact field for contact |
|
1980 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
1981 // Set contact field data |
|
1982 _LIT(KFirstNumber,"13579"); |
|
1983 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstNumber ); |
|
1984 // Add the contact field to contact |
|
1985 iStoreContact->AddFieldL( field ); |
|
1986 CleanupStack::Pop(); // field |
|
1987 |
|
1988 // Commit the new created contact to contact store |
|
1989 iStoreContact->CommitL( *this ); |
|
1990 CActiveScheduler::Start(); |
|
1991 CleanupStack::Pop(); // iStoreContact |
|
1992 |
|
1993 |
|
1994 // Create second contact |
|
1995 iStoreContact = iStore->CreateNewContactLC(); |
|
1996 |
|
1997 // Create contact field for contact |
|
1998 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
1999 // Set contact field data |
|
2000 _LIT(KSecondName,"Birbal"); |
|
2001 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondName ); |
|
2002 // Add the contact field to contact |
|
2003 iStoreContact->AddFieldL( field ); |
|
2004 CleanupStack::Pop(); // field |
|
2005 |
|
2006 // Create contact field for contact |
|
2007 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
2008 // Set contact field data |
|
2009 _LIT(KSecondNumber,"13579"); |
|
2010 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondNumber ); |
|
2011 // Add the contact field to contact |
|
2012 iStoreContact->AddFieldL( field ); |
|
2013 CleanupStack::Pop(); // field |
|
2014 |
|
2015 // Commit the new created contact to contact store |
|
2016 iStoreContact->CommitL( *this ); |
|
2017 CActiveScheduler::Start(); |
|
2018 CleanupStack::Pop(); // iStoreContact |
|
2019 |
|
2020 CleanupStack::PopAndDestroy(fieldTypeRefList); |
|
2021 /**end*/ |
|
2022 |
|
2023 |
|
2024 |
|
2025 |
|
2026 |
|
2027 /**GetList using SAPI Core class */ |
|
2028 // __UHEAP_MARK; |
|
2029 iServiceHandle = CContactService::NewL(); |
|
2030 iLog->Log( KServiceOpen ); |
|
2031 |
|
2032 iOperation = EDscContact; |
|
2033 iServiceHandle->GetListL(this,0,EContacts,KNullDesC8,_L(""),NULL,EDesc); |
|
2034 iLog->Log(_L("GetListL called\n")); |
|
2035 iLog->Log(_L("Start Active Scheduler\n")); |
|
2036 CActiveScheduler::Start(); |
|
2037 |
|
2038 |
|
2039 |
|
2040 delete iServiceHandle;//serviceHandle |
|
2041 iServiceHandle = NULL; |
|
2042 iLog->Log( KServiceClose ); |
|
2043 |
|
2044 |
|
2045 return iErr; |
|
2046 |
|
2047 } |
|
2048 |
|
2049 TInt CContactsUT::GetSearchContactL( CStifItemParser& aItem ) |
|
2050 { |
|
2051 |
|
2052 // Print to UI |
|
2053 _LIT( KContactsTest, "ContactsUT" ); |
|
2054 _LIT( KExample, "In Add" ); |
|
2055 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
2056 // Print to log file |
|
2057 iLog->Log( KExample ); |
|
2058 |
|
2059 TInt i = 0; |
|
2060 TPtrC string; |
|
2061 _LIT( KParam, "Param[%i]: %S" ); |
|
2062 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
2063 { |
|
2064 TestModuleIf().Printf( i, KContactsTest, |
|
2065 KParam, i, &string ); |
|
2066 i++; |
|
2067 } |
|
2068 |
|
2069 iErr = KErrNone; |
|
2070 |
|
2071 |
|
2072 /**Delete using virtual Phonebook */ |
|
2073 |
|
2074 _LIT(KPhone,"13579"); |
|
2075 // Create find operation |
|
2076 iOp = iContactManager->MatchPhoneNumberL( |
|
2077 KPhone, KPhone().Length(), *this ); |
|
2078 CActiveScheduler::Start(); |
|
2079 |
|
2080 iErr = KErrGeneral; |
|
2081 TInt count1(iFindResults->Count()); |
|
2082 while(count1) |
|
2083 { |
|
2084 iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
2085 iContactToDelete->AppendL(&(const_cast<MVPbkContactLink&>(iFindResults->At(--count1)))); |
|
2086 iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
2087 CActiveScheduler::Start(); |
|
2088 } |
|
2089 /**end */ |
|
2090 |
|
2091 /**Add 2 contact using virtual phonebook*/ |
|
2092 |
|
2093 CVPbkFieldTypeRefsList* fieldTypeRefList = CVPbkFieldTypeRefsList::NewL(); |
|
2094 CleanupStack::PushL(fieldTypeRefList); |
|
2095 |
|
2096 fieldTypeRefList->AppendL( |
|
2097 *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_FIRSTNAME ) ); |
|
2098 fieldTypeRefList->AppendL( |
|
2099 *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN ) ); |
|
2100 |
|
2101 // Create first contact |
|
2102 iStoreContact = iStore->CreateNewContactLC(); |
|
2103 |
|
2104 // Create contact field for contact |
|
2105 MVPbkStoreContactField* field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
2106 // Set contact field data |
|
2107 _LIT(KFirstName,"Tenali"); |
|
2108 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstName ); |
|
2109 // Add the contact field to contact |
|
2110 iStoreContact->AddFieldL( field ); |
|
2111 CleanupStack::Pop(); // field |
|
2112 |
|
2113 // Create contact field for contact |
|
2114 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
2115 // Set contact field data |
|
2116 _LIT(KFirstNumber,"13579"); |
|
2117 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstNumber ); |
|
2118 // Add the contact field to contact |
|
2119 iStoreContact->AddFieldL( field ); |
|
2120 CleanupStack::Pop(); // field |
|
2121 |
|
2122 // Commit the new created contact to contact store |
|
2123 iStoreContact->CommitL( *this ); |
|
2124 CActiveScheduler::Start(); |
|
2125 CleanupStack::Pop(); // iStoreContact |
|
2126 |
|
2127 |
|
2128 // Create second contact |
|
2129 iStoreContact = iStore->CreateNewContactLC(); |
|
2130 |
|
2131 // Create contact field for contact |
|
2132 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
2133 // Set contact field data |
|
2134 _LIT(KSecondName,"Birbal"); |
|
2135 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondName ); |
|
2136 // Add the contact field to contact |
|
2137 iStoreContact->AddFieldL( field ); |
|
2138 CleanupStack::Pop(); // field |
|
2139 |
|
2140 // Create contact field for contact |
|
2141 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
2142 // Set contact field data |
|
2143 _LIT(KSecondNumber,"13579"); |
|
2144 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondNumber ); |
|
2145 // Add the contact field to contact |
|
2146 iStoreContact->AddFieldL( field ); |
|
2147 CleanupStack::Pop(); // field |
|
2148 |
|
2149 // Commit the new created contact to contact store |
|
2150 iStoreContact->CommitL( *this ); |
|
2151 CActiveScheduler::Start(); |
|
2152 CleanupStack::Pop(); // iStoreContact |
|
2153 |
|
2154 CleanupStack::PopAndDestroy(fieldTypeRefList); |
|
2155 /**end*/ |
|
2156 |
|
2157 |
|
2158 |
|
2159 |
|
2160 |
|
2161 /**GetList using SAPI Core class */ |
|
2162 // __UHEAP_MARK; |
|
2163 iServiceHandle = CContactService::NewL(); |
|
2164 iLog->Log( KServiceOpen ); |
|
2165 |
|
2166 iOperation = ESearchContact; |
|
2167 iServiceHandle->GetListL(this,0,EContacts,KNullDesC8,_L(""),NULL,EAsc); |
|
2168 iLog->Log(_L("GetListL called\n")); |
|
2169 iLog->Log(_L("Start Active Scheduler\n")); |
|
2170 CActiveScheduler::Start(); |
|
2171 |
|
2172 |
|
2173 delete iServiceHandle;//serviceHandle |
|
2174 iServiceHandle = NULL; |
|
2175 iLog->Log( KServiceClose ); |
|
2176 |
|
2177 |
|
2178 return iErr; |
|
2179 |
|
2180 } |
|
2181 TInt CContactsUT::GetListConactIdL( CStifItemParser& aItem ) |
|
2182 { |
|
2183 // Print to UI |
|
2184 _LIT( KContactsTest, "ContactsUT" ); |
|
2185 _LIT( KExample, "In Add" ); |
|
2186 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
2187 // Print to log file |
|
2188 iLog->Log( KExample ); |
|
2189 |
|
2190 TInt i = 0; |
|
2191 TPtrC string; |
|
2192 _LIT( KParam, "Param[%i]: %S" ); |
|
2193 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
2194 { |
|
2195 TestModuleIf().Printf( i, KContactsTest, |
|
2196 KParam, i, &string ); |
|
2197 i++; |
|
2198 } |
|
2199 |
|
2200 iErr = KErrNone; |
|
2201 |
|
2202 |
|
2203 /**Delete using virtual Phonebook */ |
|
2204 |
|
2205 _LIT(KPhone,"13579"); |
|
2206 // Create find operation |
|
2207 iOp = iContactManager->MatchPhoneNumberL( |
|
2208 KPhone, KPhone().Length(), *this ); |
|
2209 CActiveScheduler::Start(); |
|
2210 |
|
2211 iErr = KErrGeneral; |
|
2212 TInt count1(iFindResults->Count()); |
|
2213 while(count1) |
|
2214 { |
|
2215 iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
2216 iContactToDelete->AppendL(&(const_cast<MVPbkContactLink&>(iFindResults->At(--count1)))); |
|
2217 iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
2218 CActiveScheduler::Start(); |
|
2219 } |
|
2220 /**end */ |
|
2221 |
|
2222 /**Add 2 contact using virtual phonebook*/ |
|
2223 |
|
2224 CVPbkFieldTypeRefsList* fieldTypeRefList = CVPbkFieldTypeRefsList::NewL(); |
|
2225 CleanupStack::PushL(fieldTypeRefList); |
|
2226 |
|
2227 fieldTypeRefList->AppendL( |
|
2228 *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_FIRSTNAME ) ); |
|
2229 fieldTypeRefList->AppendL( |
|
2230 *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN ) ); |
|
2231 |
|
2232 // Create first contact |
|
2233 iStoreContact = iStore->CreateNewContactLC(); |
|
2234 |
|
2235 // Create contact field for contact |
|
2236 MVPbkStoreContactField* field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
2237 // Set contact field data |
|
2238 _LIT(KFirstName,"Tenali"); |
|
2239 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstName ); |
|
2240 // Add the contact field to contact |
|
2241 iStoreContact->AddFieldL( field ); |
|
2242 CleanupStack::Pop(); // field |
|
2243 |
|
2244 // Create contact field for contact |
|
2245 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
2246 // Set contact field data |
|
2247 _LIT(KFirstNumber,"13579"); |
|
2248 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstNumber ); |
|
2249 // Add the contact field to contact |
|
2250 iStoreContact->AddFieldL( field ); |
|
2251 CleanupStack::Pop(); // field |
|
2252 |
|
2253 // Commit the new created contact to contact store |
|
2254 iStoreContact->CommitL( *this ); |
|
2255 CActiveScheduler::Start(); |
|
2256 CleanupStack::Pop(); // iStoreContact |
|
2257 |
|
2258 |
|
2259 // Create second contact |
|
2260 iStoreContact = iStore->CreateNewContactLC(); |
|
2261 |
|
2262 // Create contact field for contact |
|
2263 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
2264 // Set contact field data |
|
2265 _LIT(KSecondName,"Birbal"); |
|
2266 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondName ); |
|
2267 // Add the contact field to contact |
|
2268 iStoreContact->AddFieldL( field ); |
|
2269 CleanupStack::Pop(); // field |
|
2270 |
|
2271 // Create contact field for contact |
|
2272 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
2273 // Set contact field data |
|
2274 _LIT(KSecondNumber,"13579"); |
|
2275 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondNumber ); |
|
2276 // Add the contact field to contact |
|
2277 iStoreContact->AddFieldL( field ); |
|
2278 CleanupStack::Pop(); // field |
|
2279 |
|
2280 // Commit the new created contact to contact store |
|
2281 iStoreContact->CommitL( *this ); |
|
2282 CActiveScheduler::Start(); |
|
2283 CleanupStack::Pop(); // iStoreContact |
|
2284 |
|
2285 CleanupStack::PopAndDestroy(fieldTypeRefList); |
|
2286 /**end*/ |
|
2287 |
|
2288 |
|
2289 |
|
2290 |
|
2291 |
|
2292 /**GetList using SAPI Core class */ |
|
2293 // __UHEAP_MARK; |
|
2294 iServiceHandle = CContactService::NewL(); |
|
2295 iLog->Log( KServiceOpen ); |
|
2296 |
|
2297 iOperation = EContactId; |
|
2298 iServiceHandle->GetListL(this,0,EContacts); |
|
2299 iLog->Log(_L("GetListL called\n")); |
|
2300 iLog->Log(_L("Start Active Scheduler\n")); |
|
2301 CActiveScheduler::Start(); |
|
2302 |
|
2303 |
|
2304 delete iServiceHandle;//serviceHandle |
|
2305 iServiceHandle = NULL; |
|
2306 iLog->Log( KServiceClose ); |
|
2307 |
|
2308 |
|
2309 return iErr; |
|
2310 |
|
2311 } |
|
2312 |
|
2313 // ----------------------------------------------------------------------------- |
|
2314 // CContactsUT::?member_function |
|
2315 // ?implementation_description |
|
2316 // (other items were commented in a header). |
|
2317 // ----------------------------------------------------------------------------- |
|
2318 // |
|
2319 TInt CContactsUT::AddL( CStifItemParser& aItem ) |
|
2320 { |
|
2321 |
|
2322 // Print to UI |
|
2323 _LIT( KContactsTest, "ContactsUT" ); |
|
2324 _LIT( KExample, "In Add" ); |
|
2325 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
2326 // Print to log file |
|
2327 iLog->Log( KExample ); |
|
2328 |
|
2329 TInt i = 0; |
|
2330 TPtrC string; |
|
2331 _LIT( KParam, "Param[%i]: %S" ); |
|
2332 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
2333 { |
|
2334 TestModuleIf().Printf( i, KContactsTest, |
|
2335 KParam, i, &string ); |
|
2336 i++; |
|
2337 } |
|
2338 |
|
2339 iErr = KErrNone; |
|
2340 |
|
2341 /**Add contact using SAPI Core class*/ |
|
2342 |
|
2343 _LIT8(KFirstName,"FirstName"); |
|
2344 _LIT(KName,"Sikandar"); |
|
2345 _LIT8(KNumber,"MobilePhoneHome"); |
|
2346 _LIT(KPhone,"123456"); |
|
2347 |
|
2348 // __UHEAP_MARK; |
|
2349 //instantiate service class |
|
2350 CContactService* serviceHandle = CContactService::NewL(); |
|
2351 CleanupStack::PushL(serviceHandle); |
|
2352 iLog->Log( KServiceOpen ); |
|
2353 |
|
2354 CSingleContact* singleContact = CSingleContact::NewL(); |
|
2355 CleanupStack::PushL(singleContact); |
|
2356 iLog->Log(_L("single Contact created\n")); |
|
2357 |
|
2358 CSingleContactField* nameContactField = CSingleContactField::NewL(); |
|
2359 CleanupStack::PushL(nameContactField); |
|
2360 iLog->Log(_L("Name Contact Field created \n")); |
|
2361 |
|
2362 CSingleContactField* phoneContactField = CSingleContactField::NewL(); |
|
2363 CleanupStack::PushL(phoneContactField); |
|
2364 iLog->Log(_L("Phone Contact Field created \n")); |
|
2365 |
|
2366 nameContactField->SetFieldParamsL(KFirstName,KNullDesC,KName); |
|
2367 singleContact->AddFieldToContactL(nameContactField); |
|
2368 iLog->Log(_L("Name Contact Field added \n")); |
|
2369 |
|
2370 phoneContactField->SetFieldParamsL(KNumber,KNullDesC,KPhone); |
|
2371 singleContact->AddFieldToContactL(phoneContactField); |
|
2372 iLog->Log(_L("Phone Contact Field added \n")); |
|
2373 |
|
2374 serviceHandle->AddL(this,0,singleContact,KNullDesC8,KNullDesC); |
|
2375 iLog->Log(_L("AddL called\n")); |
|
2376 iLog->Log(_L("Start Active Scheduler\n")); |
|
2377 CActiveScheduler::Start(); |
|
2378 |
|
2379 CleanupStack::Pop(phoneContactField);//singleContactField |
|
2380 CleanupStack::Pop(nameContactField);//singleContactField |
|
2381 CleanupStack::PopAndDestroy(singleContact);//singleContact |
|
2382 CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
2383 iLog->Log( KServiceClose ); |
|
2384 // __UHEAP_MARKEND; |
|
2385 /**end */ |
|
2386 |
|
2387 if(iErr) |
|
2388 { |
|
2389 return iErr; |
|
2390 } |
|
2391 |
|
2392 /**Delete using virtual Phonebook */ |
|
2393 /* |
|
2394 |
|
2395 // Create find operation |
|
2396 iOp = iContactManager->MatchPhoneNumberL( |
|
2397 KPhone, KPhone().Length(), *this ); |
|
2398 CActiveScheduler::Start(); |
|
2399 |
|
2400 iErr = KErrGeneral; |
|
2401 TInt count(iFindResults->Count()); |
|
2402 while(count) |
|
2403 { |
|
2404 iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
2405 iContactToDelete->AppendL(&(const_cast<MVPbkContactLink&>(iFindResults->At(--count)))); |
|
2406 iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
2407 CActiveScheduler::Start(); |
|
2408 } |
|
2409 /**end */ |
|
2410 |
|
2411 |
|
2412 return iErr; |
|
2413 |
|
2414 } |
|
2415 |
|
2416 |
|
2417 // ----------------------------------------------------------------------------- |
|
2418 // CContactsUT::?member_function |
|
2419 // ?implementation_description |
|
2420 // (other items were commented in a header). |
|
2421 // ----------------------------------------------------------------------------- |
|
2422 // |
|
2423 TInt CContactsUT::AddInvalidFieldL( CStifItemParser& aItem ) |
|
2424 { |
|
2425 |
|
2426 // Print to UI |
|
2427 _LIT( KContactsTest, "ContactsUT" ); |
|
2428 _LIT( KExample, "In Add" ); |
|
2429 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
2430 // Print to log file |
|
2431 iLog->Log( KExample ); |
|
2432 |
|
2433 TInt i = 0; |
|
2434 TPtrC string; |
|
2435 _LIT( KParam, "Param[%i]: %S" ); |
|
2436 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
2437 { |
|
2438 TestModuleIf().Printf( i, KContactsTest, |
|
2439 KParam, i, &string ); |
|
2440 i++; |
|
2441 } |
|
2442 |
|
2443 iErr = KErrNone; |
|
2444 |
|
2445 /**Add contact using SAPI Core class*/ |
|
2446 |
|
2447 _LIT8(KFirstName,"FistName"); //invalid field |
|
2448 _LIT(KName,"Sikandar"); |
|
2449 _LIT8(KNumber,"MobilePhoneHome"); |
|
2450 _LIT(KPhone,"123456"); |
|
2451 |
|
2452 // __UHEAP_MARK; |
|
2453 //instantiate service class |
|
2454 CContactService* serviceHandle = CContactService::NewL(); |
|
2455 CleanupStack::PushL(serviceHandle); |
|
2456 iLog->Log( KServiceOpen ); |
|
2457 |
|
2458 CSingleContact* singleContact = CSingleContact::NewL(); |
|
2459 CleanupStack::PushL(singleContact); |
|
2460 iLog->Log(_L("single Contact created\n")); |
|
2461 |
|
2462 CSingleContactField* nameContactField = CSingleContactField::NewL(); |
|
2463 CleanupStack::PushL(nameContactField); |
|
2464 iLog->Log(_L("Name Contact Field created \n")); |
|
2465 |
|
2466 CSingleContactField* phoneContactField = CSingleContactField::NewL(); |
|
2467 CleanupStack::PushL(phoneContactField); |
|
2468 iLog->Log(_L("Phone Contact Field created \n")); |
|
2469 |
|
2470 nameContactField->SetFieldParamsL(KFirstName,KNullDesC,KName); |
|
2471 singleContact->AddFieldToContactL(nameContactField); |
|
2472 iLog->Log(_L("Name Contact Field added \n")); |
|
2473 |
|
2474 phoneContactField->SetFieldParamsL(KNumber,KNullDesC,KPhone); |
|
2475 singleContact->AddFieldToContactL(phoneContactField); |
|
2476 iLog->Log(_L("Phone Contact Field added \n")); |
|
2477 |
|
2478 serviceHandle->AddL(this,0,singleContact,KNullDesC8,KNullDesC); |
|
2479 iLog->Log(_L("AddL called\n")); |
|
2480 iLog->Log(_L("Start Active Scheduler\n")); |
|
2481 CActiveScheduler::Start(); |
|
2482 |
|
2483 CleanupStack::Pop(phoneContactField);//singleContactField |
|
2484 CleanupStack::Pop(nameContactField);//singleContactField |
|
2485 CleanupStack::PopAndDestroy(singleContact);//singleContact |
|
2486 CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
2487 iLog->Log( KServiceClose ); |
|
2488 // __UHEAP_MARKEND; |
|
2489 /**end */ |
|
2490 |
|
2491 if( KInvalidKey == iErr ) |
|
2492 { |
|
2493 return KErrNone; |
|
2494 } |
|
2495 |
|
2496 |
|
2497 return iErr; |
|
2498 |
|
2499 } |
|
2500 |
|
2501 |
|
2502 |
|
2503 // ----------------------------------------------------------------------------- |
|
2504 // CContactsUT::?member_function |
|
2505 // ?implementation_description |
|
2506 // (other items were commented in a header). |
|
2507 // ----------------------------------------------------------------------------- |
|
2508 // |
|
2509 TInt CContactsUT::AddMultiplePhoneNumbersContactL( CStifItemParser& aItem ) |
|
2510 { |
|
2511 |
|
2512 // Print to UI |
|
2513 _LIT( KContactsTest, "ContactsUT" ); |
|
2514 _LIT( KExample, "In Add" ); |
|
2515 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
2516 // Print to log file |
|
2517 iLog->Log( KExample ); |
|
2518 |
|
2519 TInt i = 0; |
|
2520 TPtrC string; |
|
2521 _LIT( KParam, "Param[%i]: %S" ); |
|
2522 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
2523 { |
|
2524 TestModuleIf().Printf( i, KContactsTest, |
|
2525 KParam, i, &string ); |
|
2526 i++; |
|
2527 } |
|
2528 |
|
2529 iErr = KErrNone; |
|
2530 |
|
2531 /**Add contact using SAPI Core class*/ |
|
2532 |
|
2533 _LIT8(KFirstName,"FirstName"); |
|
2534 _LIT(KName,"Sikandar"); |
|
2535 _LIT8(KNumber,"MobilePhoneHome"); |
|
2536 _LIT(KPhone,"123456"); |
|
2537 _LIT8(KNumber2,"MobilePhoneWork"); |
|
2538 _LIT(KPhone2,"654321"); |
|
2539 |
|
2540 // __UHEAP_MARK; |
|
2541 //instantiate service class |
|
2542 CContactService* serviceHandle = CContactService::NewL(); |
|
2543 CleanupStack::PushL(serviceHandle); |
|
2544 iLog->Log( KServiceOpen ); |
|
2545 |
|
2546 CSingleContact* singleContact = CSingleContact::NewL(); |
|
2547 CleanupStack::PushL(singleContact); |
|
2548 iLog->Log(_L("single Contact created\n")); |
|
2549 |
|
2550 CSingleContactField* nameContactField = CSingleContactField::NewL(); |
|
2551 CleanupStack::PushL(nameContactField); |
|
2552 iLog->Log(_L("Name Contact Field created \n")); |
|
2553 |
|
2554 CSingleContactField* phoneContactField = CSingleContactField::NewL(); |
|
2555 CleanupStack::PushL(phoneContactField); |
|
2556 iLog->Log(_L("Phone Contact Field created \n")); |
|
2557 |
|
2558 CSingleContactField* workPhoneContactField = CSingleContactField::NewL(); |
|
2559 CleanupStack::PushL(workPhoneContactField); |
|
2560 iLog->Log(_L("Work Phone Contact Field created \n")); |
|
2561 |
|
2562 nameContactField->SetFieldParamsL(KFirstName,KNullDesC,KName); |
|
2563 singleContact->AddFieldToContactL(nameContactField); |
|
2564 iLog->Log(_L("Name Contact Field added \n")); |
|
2565 |
|
2566 phoneContactField->SetFieldParamsL(KNumber,KNullDesC,KPhone); |
|
2567 singleContact->AddFieldToContactL(phoneContactField); |
|
2568 iLog->Log(_L("Phone Contact Field added \n")); |
|
2569 |
|
2570 workPhoneContactField->SetFieldParamsL(KNumber2,KNullDesC,KPhone2); |
|
2571 singleContact->AddFieldToContactL(workPhoneContactField); |
|
2572 iLog->Log(_L("Phone Contact Field added \n")); |
|
2573 |
|
2574 serviceHandle->AddL(this,0,singleContact,KNullDesC8,KNullDesC); |
|
2575 iLog->Log(_L("AddL called\n")); |
|
2576 iLog->Log(_L("Start Active Scheduler\n")); |
|
2577 CActiveScheduler::Start(); |
|
2578 |
|
2579 CleanupStack::Pop(workPhoneContactField);//singleContactField |
|
2580 CleanupStack::Pop(phoneContactField);//singleContactField |
|
2581 CleanupStack::Pop(nameContactField);//singleContactField |
|
2582 CleanupStack::PopAndDestroy(singleContact);//singleContact |
|
2583 CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
2584 iLog->Log( KServiceClose ); |
|
2585 // __UHEAP_MARKEND; |
|
2586 /**end */ |
|
2587 |
|
2588 if(iErr) |
|
2589 { |
|
2590 return iErr; |
|
2591 } |
|
2592 |
|
2593 /**Delete using virtual Phonebook */ |
|
2594 /* |
|
2595 |
|
2596 // Create find operation |
|
2597 iOp = iContactManager->MatchPhoneNumberL( |
|
2598 KPhone, KPhone().Length(), *this ); |
|
2599 CActiveScheduler::Start(); |
|
2600 |
|
2601 iErr = KErrGeneral; |
|
2602 TInt count(iFindResults->Count()); |
|
2603 while(count) |
|
2604 { |
|
2605 iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
2606 iContactToDelete->AppendL(&(const_cast<MVPbkContactLink&>(iFindResults->At(--count)))); |
|
2607 iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
2608 CActiveScheduler::Start(); |
|
2609 } |
|
2610 /**end */ |
|
2611 |
|
2612 |
|
2613 return iErr; |
|
2614 |
|
2615 } |
|
2616 |
|
2617 |
|
2618 |
|
2619 |
|
2620 // ----------------------------------------------------------------------------- |
|
2621 // CContactsUT::AddGroupL |
|
2622 // Example test method function. |
|
2623 // (other items were commented in a header). |
|
2624 // ----------------------------------------------------------------------------- |
|
2625 // |
|
2626 TInt CContactsUT::AddGroupL( CStifItemParser& aItem ) |
|
2627 { |
|
2628 |
|
2629 // Print to UI |
|
2630 _LIT( KContactsTest, "ContactsTest" ); |
|
2631 _LIT( KExample, "In AddGroup" ); |
|
2632 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
2633 // Print to log file |
|
2634 iLog->Log( KExample ); |
|
2635 |
|
2636 TInt i = 0; |
|
2637 TPtrC string; |
|
2638 _LIT( KParam, "Param[%i]: %S" ); |
|
2639 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
2640 { |
|
2641 TestModuleIf().Printf( i, KContactsTest, |
|
2642 KParam, i, &string ); |
|
2643 i++; |
|
2644 } |
|
2645 |
|
2646 iErr = KErrNone; |
|
2647 |
|
2648 /**Add group using SAPI core class */ |
|
2649 __UHEAP_MARK; |
|
2650 _LIT(KGroup,"Test"); |
|
2651 //instantiate service class |
|
2652 CContactService* serviceHandle = CContactService::NewL(); |
|
2653 CleanupStack::PushL(serviceHandle); |
|
2654 iLog->Log( KServiceOpen ); |
|
2655 |
|
2656 serviceHandle->AddL(this,0,NULL,KNullDesC8,KGroup); |
|
2657 iLog->Log(_L("AddL called\n")); |
|
2658 iLog->Log(_L("Start Active Scheduler\n")); |
|
2659 CActiveScheduler::Start(); |
|
2660 |
|
2661 CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
2662 iLog->Log( KServiceClose ); |
|
2663 /**end */ |
|
2664 __UHEAP_MARKEND; |
|
2665 if(iErr) |
|
2666 { |
|
2667 return iErr; |
|
2668 } |
|
2669 |
|
2670 /** Check for the added group using virtual phonebook classes */ |
|
2671 iFindResults = iStore->ContactGroupsLC(); |
|
2672 TInt count(iFindResults->Count()); |
|
2673 while(count) |
|
2674 { |
|
2675 iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
2676 iOp = iContactManager->RetrieveContactL(*iResult,*this); |
|
2677 CActiveScheduler::Start(); |
|
2678 |
|
2679 if(iErr) |
|
2680 { |
|
2681 break; |
|
2682 } |
|
2683 iErr = KErrGeneral; |
|
2684 iGroup = iStoreContact->Group(); |
|
2685 if(!iGroup->GroupLabel().Compare(KGroup)) |
|
2686 { |
|
2687 iErr = KErrNone; |
|
2688 iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
2689 iContactToDelete->AppendL(iResult); |
|
2690 iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
2691 CActiveScheduler::Start(); |
|
2692 break; |
|
2693 } |
|
2694 } |
|
2695 CleanupStack::Pop(); |
|
2696 iFindResults = NULL; |
|
2697 /**end */ |
|
2698 |
|
2699 return iErr; |
|
2700 |
|
2701 } |
|
2702 |
|
2703 |
|
2704 // ----------------------------------------------------------------------------- |
|
2705 // CContactsUT::DeleteL |
|
2706 // Example test method function. |
|
2707 // (other items were commented in a header). |
|
2708 // ----------------------------------------------------------------------------- |
|
2709 // |
|
2710 TInt CContactsUT::DeleteContactL( CStifItemParser& aItem ) |
|
2711 { |
|
2712 |
|
2713 // Print to UI |
|
2714 _LIT( KContactsTest, "ContactsTest" ); |
|
2715 _LIT( KExample, "In Delete" ); |
|
2716 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
2717 // Print to log file |
|
2718 iLog->Log( KExample ); |
|
2719 |
|
2720 TInt i = 0; |
|
2721 TPtrC string; |
|
2722 _LIT( KParam, "Param[%i]: %S" ); |
|
2723 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
2724 { |
|
2725 TestModuleIf().Printf( i, KContactsTest, |
|
2726 KParam, i, &string ); |
|
2727 i++; |
|
2728 } |
|
2729 |
|
2730 iErr = KErrNone; |
|
2731 |
|
2732 /**Add 2 contacts using virtual phonebook*/ |
|
2733 |
|
2734 CVPbkFieldTypeRefsList* fieldTypeRefList = CVPbkFieldTypeRefsList::NewL(); |
|
2735 CleanupStack::PushL(fieldTypeRefList); |
|
2736 |
|
2737 fieldTypeRefList->AppendL( |
|
2738 *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_FIRSTNAME ) ); |
|
2739 fieldTypeRefList->AppendL( |
|
2740 *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN ) ); |
|
2741 |
|
2742 // Create first contact |
|
2743 iStoreContact = iStore->CreateNewContactLC(); |
|
2744 |
|
2745 // Create contact field for contact |
|
2746 MVPbkStoreContactField* field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
2747 // Set contact field data |
|
2748 _LIT(KFirstName,"Tenali"); |
|
2749 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstName ); |
|
2750 // Add the contact field to contact |
|
2751 iStoreContact->AddFieldL( field ); |
|
2752 CleanupStack::Pop(); // field |
|
2753 |
|
2754 // Create contact field for contact |
|
2755 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
2756 // Set contact field data |
|
2757 _LIT(KFirstNumber,"13579"); |
|
2758 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstNumber ); |
|
2759 // Add the contact field to contact |
|
2760 iStoreContact->AddFieldL( field ); |
|
2761 CleanupStack::Pop(); // field |
|
2762 |
|
2763 // Commit the new created contact to contact store |
|
2764 iStoreContact->CommitL( *this ); |
|
2765 CActiveScheduler::Start(); |
|
2766 CleanupStack::Pop(); // iStoreContact |
|
2767 |
|
2768 |
|
2769 // Create second contact |
|
2770 iStoreContact = iStore->CreateNewContactLC(); |
|
2771 |
|
2772 // Create contact field for contact |
|
2773 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
2774 // Set contact field data |
|
2775 _LIT(KSecondName,"Birbal"); |
|
2776 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondName ); |
|
2777 // Add the contact field to contact |
|
2778 iStoreContact->AddFieldL( field ); |
|
2779 CleanupStack::Pop(); // field |
|
2780 |
|
2781 // Create contact field for contact |
|
2782 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
2783 // Set contact field data |
|
2784 _LIT(KSecondNumber,"13579"); |
|
2785 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondNumber ); |
|
2786 // Add the contact field to contact |
|
2787 iStoreContact->AddFieldL( field ); |
|
2788 CleanupStack::Pop(); // field |
|
2789 |
|
2790 // Commit the new created contact to contact store |
|
2791 iStoreContact->CommitL( *this ); |
|
2792 CActiveScheduler::Start(); |
|
2793 CleanupStack::Pop(); // iStoreContact |
|
2794 |
|
2795 CleanupStack::PopAndDestroy(fieldTypeRefList); |
|
2796 /**end*/ |
|
2797 |
|
2798 /** Search for the added contacts*/ |
|
2799 |
|
2800 // Phone number to be searched for |
|
2801 _LIT( KMatchNo, "13579" ); |
|
2802 // Create find operation |
|
2803 iOp = iContactManager->MatchPhoneNumberL( |
|
2804 KMatchNo, KMatchNo().Length(), *this ); |
|
2805 |
|
2806 CActiveScheduler::Start(); |
|
2807 TInt count(iFindResults->Count()); |
|
2808 /**end*/ |
|
2809 |
|
2810 /**Delete using SAPI core class*/ |
|
2811 |
|
2812 if(count>1) |
|
2813 { |
|
2814 __UHEAP_MARK; |
|
2815 RPointerArray<TDesC8> idArray; |
|
2816 CleanupClosePushL(idArray); |
|
2817 TInt num(count); |
|
2818 while(count) |
|
2819 { |
|
2820 HBufC8* contactId = (const_cast<MVPbkContactLink&>(iFindResults->At(--count))).PackLC(); |
|
2821 idArray.AppendL(contactId); |
|
2822 } |
|
2823 |
|
2824 CContactService* serviceHandle = CContactService::NewL(); |
|
2825 CleanupStack::PushL(serviceHandle); |
|
2826 iLog->Log( KServiceOpen ); |
|
2827 |
|
2828 serviceHandle->DeleteL(this,0,idArray); |
|
2829 iLog->Log(_L("DeleteL called\n")); |
|
2830 iLog->Log(_L("Start Active Scheduler\n")); |
|
2831 CActiveScheduler::Start(); |
|
2832 |
|
2833 CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
2834 |
|
2835 CleanupStack::PopAndDestroy(num);//destroy all contactIds |
|
2836 CleanupStack::PopAndDestroy(&idArray);//singleContactField |
|
2837 |
|
2838 iLog->Log( KServiceClose ); |
|
2839 __UHEAP_MARKEND; |
|
2840 |
|
2841 } |
|
2842 /**end*/ |
|
2843 |
|
2844 return iErr; |
|
2845 |
|
2846 } |
|
2847 |
|
2848 |
|
2849 // ----------------------------------------------------------------------------- |
|
2850 // CContactsUT::DeleteInvalidContactL |
|
2851 // Example test method function. |
|
2852 // (other items were commented in a header). |
|
2853 // ----------------------------------------------------------------------------- |
|
2854 // |
|
2855 TInt CContactsUT::DeleteSingleContactL( CStifItemParser& aItem ) |
|
2856 { |
|
2857 |
|
2858 // Print to UI |
|
2859 _LIT( KContactsTest, "ContactsTest" ); |
|
2860 _LIT( KExample, "In Delete" ); |
|
2861 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
2862 // Print to log file |
|
2863 iLog->Log( KExample ); |
|
2864 |
|
2865 TInt i = 0; |
|
2866 TPtrC string; |
|
2867 _LIT( KParam, "Param[%i]: %S" ); |
|
2868 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
2869 { |
|
2870 TestModuleIf().Printf( i, KContactsTest, |
|
2871 KParam, i, &string ); |
|
2872 i++; |
|
2873 } |
|
2874 |
|
2875 iErr = KErrNone; |
|
2876 |
|
2877 /**Add 2 contacts using virtual phonebook*/ |
|
2878 |
|
2879 CVPbkFieldTypeRefsList* fieldTypeRefList = CVPbkFieldTypeRefsList::NewL(); |
|
2880 CleanupStack::PushL(fieldTypeRefList); |
|
2881 |
|
2882 fieldTypeRefList->AppendL( |
|
2883 *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_FIRSTNAME ) ); |
|
2884 fieldTypeRefList->AppendL( |
|
2885 *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN ) ); |
|
2886 |
|
2887 // Create first contact |
|
2888 iStoreContact = iStore->CreateNewContactLC(); |
|
2889 |
|
2890 // Create contact field for contact |
|
2891 MVPbkStoreContactField* field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
2892 // Set contact field data |
|
2893 _LIT(KFirstName,"Tenali"); |
|
2894 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstName ); |
|
2895 // Add the contact field to contact |
|
2896 iStoreContact->AddFieldL( field ); |
|
2897 CleanupStack::Pop(); // field |
|
2898 |
|
2899 // Create contact field for contact |
|
2900 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
2901 // Set contact field data |
|
2902 _LIT(KFirstNumber,"13579"); |
|
2903 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstNumber ); |
|
2904 // Add the contact field to contact |
|
2905 iStoreContact->AddFieldL( field ); |
|
2906 CleanupStack::Pop(); // field |
|
2907 |
|
2908 // Commit the new created contact to contact store |
|
2909 iStoreContact->CommitL( *this ); |
|
2910 CActiveScheduler::Start(); |
|
2911 CleanupStack::Pop(); // iStoreContact |
|
2912 |
|
2913 |
|
2914 // Create second contact |
|
2915 iStoreContact = iStore->CreateNewContactLC(); |
|
2916 |
|
2917 // Create contact field for contact |
|
2918 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
2919 // Set contact field data |
|
2920 _LIT(KSecondName,"Birbal"); |
|
2921 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondName ); |
|
2922 // Add the contact field to contact |
|
2923 iStoreContact->AddFieldL( field ); |
|
2924 CleanupStack::Pop(); // field |
|
2925 |
|
2926 // Create contact field for contact |
|
2927 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
2928 // Set contact field data |
|
2929 _LIT(KSecondNumber,"13579"); |
|
2930 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondNumber ); |
|
2931 // Add the contact field to contact |
|
2932 iStoreContact->AddFieldL( field ); |
|
2933 CleanupStack::Pop(); // field |
|
2934 |
|
2935 // Commit the new created contact to contact store |
|
2936 iStoreContact->CommitL( *this ); |
|
2937 CActiveScheduler::Start(); |
|
2938 CleanupStack::Pop(); // iStoreContact |
|
2939 |
|
2940 CleanupStack::PopAndDestroy(fieldTypeRefList); |
|
2941 /**end*/ |
|
2942 |
|
2943 /** Search for the added contacts*/ |
|
2944 |
|
2945 // Phone number to be searched for |
|
2946 _LIT( KMatchNo, "13579" ); |
|
2947 // Create find operation |
|
2948 iOp = iContactManager->MatchPhoneNumberL( |
|
2949 KMatchNo, KMatchNo().Length(), *this ); |
|
2950 |
|
2951 CActiveScheduler::Start(); |
|
2952 TInt count(iFindResults->Count()); |
|
2953 /**end*/ |
|
2954 |
|
2955 /**Delete using SAPI core class*/ |
|
2956 |
|
2957 if(count>1) |
|
2958 { |
|
2959 __UHEAP_MARK; |
|
2960 RPointerArray<TDesC8> idArray; |
|
2961 CleanupClosePushL(idArray); |
|
2962 TInt num(1); |
|
2963 if(count) |
|
2964 { |
|
2965 HBufC8* contactId = (const_cast<MVPbkContactLink&>(iFindResults->At(--count))).PackLC(); |
|
2966 idArray.AppendL(contactId); |
|
2967 } |
|
2968 |
|
2969 CContactService* serviceHandle = CContactService::NewL(); |
|
2970 CleanupStack::PushL(serviceHandle); |
|
2971 iLog->Log( KServiceOpen ); |
|
2972 |
|
2973 serviceHandle->DeleteL(this,0,idArray); |
|
2974 iLog->Log(_L("DeleteL called\n")); |
|
2975 iLog->Log(_L("Start Active Scheduler\n")); |
|
2976 CActiveScheduler::Start(); |
|
2977 |
|
2978 CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
2979 |
|
2980 CleanupStack::PopAndDestroy(num);//destroy all contactIds |
|
2981 CleanupStack::PopAndDestroy(&idArray);//singleContactField |
|
2982 |
|
2983 iLog->Log( KServiceClose ); |
|
2984 __UHEAP_MARKEND; |
|
2985 |
|
2986 } |
|
2987 /**end*/ |
|
2988 |
|
2989 return iErr; |
|
2990 |
|
2991 } |
|
2992 |
|
2993 // ----------------------------------------------------------------------------- |
|
2994 // CContactsUT::DeleteListL |
|
2995 // Example test method function. |
|
2996 // (other items were commented in a header). |
|
2997 // ----------------------------------------------------------------------------- |
|
2998 // |
|
2999 TInt CContactsUT::DeleteGroupL( CStifItemParser& aItem ) |
|
3000 { |
|
3001 |
|
3002 // Print to UI |
|
3003 _LIT( KContactsTest, "ContactsTest" ); |
|
3004 _LIT( KExample, "In DeleteList" ); |
|
3005 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
3006 // Print to log file |
|
3007 iLog->Log( KExample ); |
|
3008 |
|
3009 TInt i = 0; |
|
3010 TPtrC string; |
|
3011 _LIT( KParam, "Param[%i]: %S" ); |
|
3012 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
3013 { |
|
3014 TestModuleIf().Printf( i, KContactsTest, |
|
3015 KParam, i, &string ); |
|
3016 i++; |
|
3017 } |
|
3018 iErr = KErrNone; |
|
3019 |
|
3020 /**Add 2 groups using virtual phonebook */ |
|
3021 |
|
3022 _LIT(KGroup1,"Test1"); |
|
3023 _LIT(KGroup2,"Test2"); |
|
3024 iGroup = iStore->CreateNewContactGroupLC(); |
|
3025 iGroup->SetGroupLabelL(KGroup1); |
|
3026 iOperation = EGroup; |
|
3027 iGroup->CommitL(*this); |
|
3028 |
|
3029 CActiveScheduler::Start(); |
|
3030 CleanupStack::Pop(); |
|
3031 |
|
3032 iGroup = iStore->CreateNewContactGroupLC(); |
|
3033 iGroup->SetGroupLabelL(KGroup2); |
|
3034 iOperation = EGroup; |
|
3035 iGroup->CommitL(*this); |
|
3036 |
|
3037 CActiveScheduler::Start(); |
|
3038 CleanupStack::Pop(); |
|
3039 /**end */ |
|
3040 |
|
3041 if(iErr) |
|
3042 { |
|
3043 return iErr; |
|
3044 } |
|
3045 |
|
3046 /**Delete the groups using SAPI core class */ |
|
3047 |
|
3048 /** Check for the added group using virtual phonebook classes */ |
|
3049 |
|
3050 iFindResults = iStore->ContactGroupsLC(); |
|
3051 TInt count(iFindResults->Count()); |
|
3052 if(count>1) |
|
3053 { |
|
3054 HBufC8* groupId; |
|
3055 RPointerArray<TDesC8> idArray; |
|
3056 CleanupClosePushL(idArray); |
|
3057 while(count) |
|
3058 { |
|
3059 iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
3060 iOp = iContactManager->RetrieveContactL(*iResult,*this); |
|
3061 CActiveScheduler::Start(); |
|
3062 |
|
3063 iGroup = iStoreContact->Group(); |
|
3064 if(!iGroup->GroupLabel().Compare(KGroup1) || !iGroup->GroupLabel().Compare(KGroup2)) |
|
3065 { |
|
3066 groupId = iResult->PackLC(); |
|
3067 idArray.AppendL(groupId); |
|
3068 } |
|
3069 } |
|
3070 TInt num(idArray.Count()); |
|
3071 if( num < 2) |
|
3072 { |
|
3073 return KErrGeneral; |
|
3074 } |
|
3075 __UHEAP_MARK; |
|
3076 CContactService* serviceHandle = CContactService::NewL(); |
|
3077 CleanupStack::PushL(serviceHandle); |
|
3078 iLog->Log( KServiceOpen ); |
|
3079 |
|
3080 serviceHandle->DeleteL(this,0,idArray); |
|
3081 iLog->Log(_L("DeleteL called\n")); |
|
3082 iLog->Log(_L("Start Active Scheduler\n")); |
|
3083 CActiveScheduler::Start(); |
|
3084 |
|
3085 CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
3086 __UHEAP_MARKEND; |
|
3087 CleanupStack::PopAndDestroy(num);//destroy all contactIds |
|
3088 CleanupStack::PopAndDestroy(&idArray);//singleContactField |
|
3089 |
|
3090 iLog->Log( KServiceClose ); |
|
3091 } |
|
3092 CleanupStack::Pop(); |
|
3093 iFindResults = NULL; |
|
3094 /**end */ |
|
3095 |
|
3096 return iErr; |
|
3097 |
|
3098 } |
|
3099 |
|
3100 // ----------------------------------------------------------------------------- |
|
3101 // CContactsUT::ModifyL |
|
3102 // Example test method function. |
|
3103 // (other items were commented in a header). |
|
3104 // ----------------------------------------------------------------------------- |
|
3105 // |
|
3106 TInt CContactsUT::ModifyL( CStifItemParser& aItem ) |
|
3107 { |
|
3108 |
|
3109 |
|
3110 // Print to UI |
|
3111 _LIT( KContactsTest, "ContactsTest" ); |
|
3112 _LIT( KExample, "In Modify" ); |
|
3113 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
3114 // Print to log file |
|
3115 iLog->Log( KExample ); |
|
3116 |
|
3117 TInt i = 0; |
|
3118 TPtrC string; |
|
3119 _LIT( KParam, "Param[%i]: %S" ); |
|
3120 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
3121 { |
|
3122 TestModuleIf().Printf( i, KContactsTest, |
|
3123 KParam, i, &string ); |
|
3124 i++; |
|
3125 } |
|
3126 iErr = KErrNone; |
|
3127 |
|
3128 DeleteAllL(); |
|
3129 _LIT(KFirstName,"Tenali"); |
|
3130 TPtrC ptr(KFirstName); |
|
3131 AddOneContactL(ptr); |
|
3132 |
|
3133 /** Retrieve contact ids and modify using SAPI core class */ |
|
3134 |
|
3135 // Create find operation |
|
3136 iOp = iContactManager->MatchPhoneNumberL( |
|
3137 KPhoneNumber, KPhoneNumber().Length(), *this ); |
|
3138 |
|
3139 CActiveScheduler::Start(); |
|
3140 |
|
3141 TInt count(iFindResults->Count()); |
|
3142 /**end*/ |
|
3143 |
|
3144 /**Modify using SAPI core class*/ |
|
3145 |
|
3146 if(count) |
|
3147 { |
|
3148 while(count) |
|
3149 { |
|
3150 //__UHEAP_MARK; |
|
3151 iBuffer = (const_cast<MVPbkContactLink&>(iFindResults->At(--count))).PackLC(); |
|
3152 CleanupStack::Pop();//iBuffer |
|
3153 iServiceHandle = CContactService::NewL(); |
|
3154 iLog->Log( KServiceOpen ); |
|
3155 |
|
3156 iOperation = EContact; |
|
3157 iServiceHandle->GetListL(this,0,EContacts,*iBuffer); |
|
3158 iLog->Log(_L("GetListL called\n")); |
|
3159 iLog->Log(_L("Start Active Scheduler\n")); |
|
3160 CActiveScheduler::Start(); |
|
3161 |
|
3162 delete iServiceHandle;//serviceHandle |
|
3163 iServiceHandle = NULL; |
|
3164 iLog->Log( KServiceClose ); |
|
3165 //__UHEAP_MARKEND; |
|
3166 } |
|
3167 |
|
3168 } |
|
3169 |
|
3170 /** ends */ |
|
3171 |
|
3172 return iErr; |
|
3173 |
|
3174 } |
|
3175 |
|
3176 // ----------------------------------------------------------------------------- |
|
3177 // CContactsUT::ModifyGroupL |
|
3178 // Example test method function. |
|
3179 // (other items were commented in a header). |
|
3180 // ----------------------------------------------------------------------------- |
|
3181 // |
|
3182 TInt CContactsUT::ModifyGroupL( CStifItemParser& aItem ) |
|
3183 { |
|
3184 |
|
3185 // Print to UI |
|
3186 _LIT( KContactsTest, "ContactsTest" ); |
|
3187 _LIT( KExample, "In ModifyGroup" ); |
|
3188 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
3189 // Print to log file |
|
3190 iLog->Log( KExample ); |
|
3191 |
|
3192 TInt i = 0; |
|
3193 TPtrC string; |
|
3194 _LIT( KParam, "Param[%i]: %S" ); |
|
3195 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
3196 { |
|
3197 TestModuleIf().Printf( i, KContactsTest, |
|
3198 KParam, i, &string ); |
|
3199 i++; |
|
3200 } |
|
3201 iErr = KErrNone; |
|
3202 /**Add 1 group using virtual phonebook */ |
|
3203 |
|
3204 _LIT(KGroup1,"Modify1"); |
|
3205 _LIT(KGroup2,"Modify2"); |
|
3206 iGroup = iStore->CreateNewContactGroupLC(); |
|
3207 iGroup->SetGroupLabelL(KGroup1); |
|
3208 iOperation = EGroup; |
|
3209 iGroup->CommitL(*this); |
|
3210 |
|
3211 CActiveScheduler::Start(); |
|
3212 CleanupStack::Pop(); |
|
3213 /**end */ |
|
3214 |
|
3215 /** Check for the added group using virtual phonebook classes */ |
|
3216 iFindResults = iStore->ContactGroupsLC(); |
|
3217 TInt count(iFindResults->Count()); |
|
3218 while(count) |
|
3219 { |
|
3220 iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
3221 iOp = iContactManager->RetrieveContactL(*iResult,*this); |
|
3222 CActiveScheduler::Start(); |
|
3223 |
|
3224 if(iErr) |
|
3225 { |
|
3226 break; |
|
3227 } |
|
3228 iErr = KErrGeneral; |
|
3229 iGroup = iStoreContact->Group(); |
|
3230 if(!iGroup->GroupLabel().Compare(KGroup1)) |
|
3231 { |
|
3232 __UHEAP_MARK; |
|
3233 CContactService* serviceHandle = CContactService::NewL(); |
|
3234 CleanupStack::PushL(serviceHandle); |
|
3235 iLog->Log( KServiceOpen ); |
|
3236 |
|
3237 serviceHandle->AddL(this,0,NULL,KNullDesC8,KGroup2); |
|
3238 iLog->Log(_L("ModifyGroupL called\n")); |
|
3239 iLog->Log(_L("Start Active Scheduler\n")); |
|
3240 CActiveScheduler::Start(); |
|
3241 |
|
3242 CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
3243 iLog->Log( KServiceClose ); |
|
3244 __UHEAP_MARKEND; |
|
3245 } |
|
3246 } |
|
3247 CleanupStack::Pop(); |
|
3248 iFindResults = NULL; |
|
3249 /**end */ |
|
3250 |
|
3251 /** Check for the added group using virtual phonebook classes */ |
|
3252 iFindResults = iStore->ContactGroupsLC(); |
|
3253 count = iFindResults->Count(); |
|
3254 while(count) |
|
3255 { |
|
3256 iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
3257 iOp = iContactManager->RetrieveContactL(*iResult,*this); |
|
3258 CActiveScheduler::Start(); |
|
3259 |
|
3260 if(iErr) |
|
3261 { |
|
3262 break; |
|
3263 } |
|
3264 iErr = KErrGeneral; |
|
3265 iGroup = iStoreContact->Group(); |
|
3266 if(!iGroup->GroupLabel().Compare(KGroup2)) |
|
3267 { |
|
3268 iErr = KErrNone; |
|
3269 iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
3270 iContactToDelete->AppendL(iResult); |
|
3271 iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
3272 CActiveScheduler::Start(); |
|
3273 break; |
|
3274 } |
|
3275 } |
|
3276 CleanupStack::Pop(); |
|
3277 iFindResults = NULL; |
|
3278 |
|
3279 /**end */ |
|
3280 return iErr; |
|
3281 |
|
3282 } |
|
3283 |
|
3284 // ----------------------------------------------------------------------------- |
|
3285 // CContactsUT::OrganiseAddL |
|
3286 // Example test method function. |
|
3287 // (other items were commented in a header). |
|
3288 // ----------------------------------------------------------------------------- |
|
3289 // |
|
3290 TInt CContactsUT::OrganiseAddL( CStifItemParser& aItem ) |
|
3291 { |
|
3292 |
|
3293 // Print to UI |
|
3294 _LIT( KContactsTest, "ContactsTest" ); |
|
3295 _LIT( KExample, "In OrganiseAdd" ); |
|
3296 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
3297 // Print to log file |
|
3298 iLog->Log( KExample ); |
|
3299 |
|
3300 TInt i = 0; |
|
3301 TPtrC string; |
|
3302 _LIT( KParam, "Param[%i]: %S" ); |
|
3303 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
3304 { |
|
3305 TestModuleIf().Printf( i, KContactsTest, |
|
3306 KParam, i, &string ); |
|
3307 i++; |
|
3308 } |
|
3309 |
|
3310 iErr = KErrNone; |
|
3311 |
|
3312 /** Add 1 group */ |
|
3313 |
|
3314 _LIT(KGroup,"OrganiseTest1"); |
|
3315 iGroup = iStore->CreateNewContactGroupLC(); |
|
3316 iGroup->SetGroupLabelL(KGroup); |
|
3317 iOperation = EGroup; |
|
3318 iGroup->CommitL(*this); |
|
3319 |
|
3320 CActiveScheduler::Start(); |
|
3321 CleanupStack::Pop(); |
|
3322 /** ends */ |
|
3323 |
|
3324 |
|
3325 if(iErr) |
|
3326 { |
|
3327 return iErr; |
|
3328 } |
|
3329 |
|
3330 /** Retrieve the group id */ |
|
3331 HBufC8* groupId = NULL; |
|
3332 iFindResults = iStore->ContactGroupsLC(); |
|
3333 TInt count(iFindResults->Count()); |
|
3334 iErr = KErrGeneral; |
|
3335 while(count) |
|
3336 { |
|
3337 iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
3338 iOp = iContactManager->RetrieveContactL(*iResult,*this); |
|
3339 CActiveScheduler::Start(); |
|
3340 |
|
3341 iGroup = iStoreContact->Group(); |
|
3342 if(!iGroup->GroupLabel().Compare(KGroup)) |
|
3343 { |
|
3344 groupId =iResult->PackLC(); |
|
3345 CleanupStack::Pop();//groupId |
|
3346 break; |
|
3347 } |
|
3348 } |
|
3349 CleanupStack::Pop();//iFindResults |
|
3350 CleanupStack::PushL(groupId); |
|
3351 iFindResults = NULL; |
|
3352 /** ends */ |
|
3353 |
|
3354 |
|
3355 /** Add 2 contacts */ |
|
3356 |
|
3357 DeleteAllL(); |
|
3358 _LIT(KFirstName,"Tenali"); |
|
3359 _LIT(KSecondName,"Birbal"); |
|
3360 |
|
3361 TPtrC ptr1(KFirstName); |
|
3362 TPtrC ptr2(KSecondName); |
|
3363 |
|
3364 AddOneContactL(ptr1); |
|
3365 AddOneContactL(ptr2); |
|
3366 |
|
3367 |
|
3368 |
|
3369 /** Retrieve the 2 contacts */ |
|
3370 |
|
3371 // Phone number to be searched for |
|
3372 // Create find operation |
|
3373 iOp = iContactManager->MatchPhoneNumberL( |
|
3374 KPhoneNumber, KPhoneNumber().Length(), *this ); |
|
3375 |
|
3376 CActiveScheduler::Start(); |
|
3377 count = iFindResults->Count(); |
|
3378 /**end*/ |
|
3379 |
|
3380 /**Organise using SAPI core class*/ |
|
3381 if(count>1 && groupId) |
|
3382 { |
|
3383 RPointerArray<TDesC8> idArray; |
|
3384 CleanupClosePushL(idArray); |
|
3385 TInt num(count); |
|
3386 while(count) |
|
3387 { |
|
3388 HBufC8* contactId = (const_cast<MVPbkContactLink&>(iFindResults->At(--count))).PackLC(); |
|
3389 idArray.AppendL(contactId); |
|
3390 } |
|
3391 __UHEAP_MARK; |
|
3392 CContactService* serviceHandle = CContactService::NewL(); |
|
3393 CleanupStack::PushL(serviceHandle); |
|
3394 iLog->Log( KServiceOpen ); |
|
3395 |
|
3396 serviceHandle->OrganiseGroupsL(this,0,*groupId,idArray,ETrue); |
|
3397 iLog->Log(_L("OrganiseGroupsL called\n")); |
|
3398 iLog->Log(_L("Start Active Scheduler\n")); |
|
3399 CActiveScheduler::Start(); |
|
3400 |
|
3401 |
|
3402 CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
3403 __UHEAP_MARKEND; |
|
3404 CleanupStack::PopAndDestroy(num);//destroy all contactIds |
|
3405 CleanupStack::PopAndDestroy(&idArray);//singleContactField |
|
3406 |
|
3407 iLog->Log( KServiceClose ); |
|
3408 } |
|
3409 /** ends */ |
|
3410 |
|
3411 |
|
3412 /** Check for the group and delete*/ |
|
3413 iFindResults = iStore->ContactGroupsLC(); |
|
3414 count = iFindResults->Count(); |
|
3415 iErr = KErrGeneral; |
|
3416 while(count) |
|
3417 { |
|
3418 iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
3419 if(!(iResult->PackLC())->Compare(*groupId)) |
|
3420 { |
|
3421 iOp = iContactManager->RetrieveContactL(*iResult,*this); |
|
3422 CActiveScheduler::Start(); |
|
3423 |
|
3424 iGroup = iStoreContact->Group(); |
|
3425 MVPbkContactLinkArray* linkArray = iGroup->ItemsContainedLC(); |
|
3426 if(linkArray->Count() == 2 ) |
|
3427 { |
|
3428 iErr = KErrNone; |
|
3429 } |
|
3430 CleanupStack::Pop();//linkArray |
|
3431 |
|
3432 iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
3433 iContactToDelete->AppendL(iResult); |
|
3434 iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
3435 CActiveScheduler::Start(); |
|
3436 } |
|
3437 CleanupStack::PopAndDestroy(); |
|
3438 } |
|
3439 CleanupStack::Pop(); |
|
3440 iFindResults = NULL; |
|
3441 /**end */ |
|
3442 CleanupStack::PopAndDestroy(groupId); |
|
3443 |
|
3444 return iErr; |
|
3445 } |
|
3446 |
|
3447 |
|
3448 // ----------------------------------------------------------------------------- |
|
3449 // CContactsUT::OrganiseDeleteL |
|
3450 // Example test method function. |
|
3451 // (other items were commented in a header). |
|
3452 // ----------------------------------------------------------------------------- |
|
3453 // |
|
3454 TInt CContactsUT::OrganiseDeleteL( CStifItemParser& aItem ) |
|
3455 { |
|
3456 |
|
3457 // Print to UI |
|
3458 _LIT( KContactsTest, "ContactsTest" ); |
|
3459 _LIT( KExample, "In OrganiseDelete" ); |
|
3460 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
3461 // Print to log file |
|
3462 iLog->Log( KExample ); |
|
3463 |
|
3464 TInt i = 0; |
|
3465 TPtrC string; |
|
3466 _LIT( KParam, "Param[%i]: %S" ); |
|
3467 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
3468 { |
|
3469 TestModuleIf().Printf( i, KContactsTest, |
|
3470 KParam, i, &string ); |
|
3471 i++; |
|
3472 } |
|
3473 iErr = KErrNone; |
|
3474 |
|
3475 /** Add 1 group */ |
|
3476 |
|
3477 _LIT(KGroup,"OrganiseTest1"); |
|
3478 iGroup = iStore->CreateNewContactGroupLC(); |
|
3479 iGroup->SetGroupLabelL(KGroup); |
|
3480 iOperation = EGroup; |
|
3481 iGroup->CommitL(*this); |
|
3482 |
|
3483 CActiveScheduler::Start(); |
|
3484 CleanupStack::Pop(); |
|
3485 /** ends */ |
|
3486 |
|
3487 |
|
3488 if(iErr) |
|
3489 { |
|
3490 return iErr; |
|
3491 } |
|
3492 |
|
3493 |
|
3494 /** Add 2 contacts */ |
|
3495 |
|
3496 CVPbkFieldTypeRefsList* fieldTypeRefList = CVPbkFieldTypeRefsList::NewL(); |
|
3497 CleanupStack::PushL(fieldTypeRefList); |
|
3498 |
|
3499 fieldTypeRefList->AppendL( |
|
3500 *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_FIRSTNAME ) ); |
|
3501 fieldTypeRefList->AppendL( |
|
3502 *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN ) ); |
|
3503 |
|
3504 // Create first contact |
|
3505 iStoreContact = iStore->CreateNewContactLC(); |
|
3506 |
|
3507 // Create contact field for contact |
|
3508 MVPbkStoreContactField* field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
3509 // Set contact field data |
|
3510 _LIT(KFirstName,"Tenali"); |
|
3511 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstName ); |
|
3512 // Add the contact field to contact |
|
3513 iStoreContact->AddFieldL( field ); |
|
3514 CleanupStack::Pop(); // field |
|
3515 |
|
3516 // Create contact field for contact |
|
3517 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
3518 // Set contact field data |
|
3519 _LIT(KFirstNumber,"97531"); |
|
3520 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstNumber ); |
|
3521 // Add the contact field to contact |
|
3522 iStoreContact->AddFieldL( field ); |
|
3523 CleanupStack::Pop(); // field |
|
3524 |
|
3525 // Commit the new created contact to contact store |
|
3526 iStoreContact->CommitL( *this ); |
|
3527 CActiveScheduler::Start(); |
|
3528 CleanupStack::Pop(); // iStoreContact |
|
3529 |
|
3530 |
|
3531 // Create second contact |
|
3532 iStoreContact = iStore->CreateNewContactLC(); |
|
3533 |
|
3534 // Create contact field for contact |
|
3535 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
3536 // Set contact field data |
|
3537 _LIT(KSecondName,"Birbal"); |
|
3538 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondName ); |
|
3539 // Add the contact field to contact |
|
3540 iStoreContact->AddFieldL( field ); |
|
3541 CleanupStack::Pop(); // field |
|
3542 |
|
3543 // Create contact field for contact |
|
3544 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
3545 // Set contact field data |
|
3546 _LIT(KSecondNumber,"97531"); |
|
3547 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondNumber ); |
|
3548 // Add the contact field to contact |
|
3549 iStoreContact->AddFieldL( field ); |
|
3550 CleanupStack::Pop(); // field |
|
3551 |
|
3552 // Commit the new created contact to contact store |
|
3553 iStoreContact->CommitL( *this ); |
|
3554 CActiveScheduler::Start(); |
|
3555 CleanupStack::Pop(); // iStoreContact |
|
3556 |
|
3557 CleanupStack::PopAndDestroy(fieldTypeRefList); |
|
3558 /** end */ |
|
3559 |
|
3560 |
|
3561 if(iErr) |
|
3562 { |
|
3563 return iErr; |
|
3564 } |
|
3565 |
|
3566 /** Retrieve the 2 contacts */ |
|
3567 RPointerArray<TDesC8> idArray; |
|
3568 CleanupClosePushL(idArray); |
|
3569 // Phone number to be searched for |
|
3570 _LIT( KMatchNo, "97531" ); |
|
3571 // Create find operation |
|
3572 iOp = iContactManager->MatchPhoneNumberL( |
|
3573 KMatchNo, KMatchNo().Length(), *this ); |
|
3574 |
|
3575 CActiveScheduler::Start(); |
|
3576 TInt count = iFindResults->Count(); |
|
3577 TInt num(count); |
|
3578 iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
3579 while(count) |
|
3580 { |
|
3581 iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
3582 iContactToDelete->AppendL(iResult); |
|
3583 idArray.AppendL(iResult->PackLC()); |
|
3584 } |
|
3585 /** ends */ |
|
3586 |
|
3587 /** Retrieve the group id */ |
|
3588 HBufC8* groupId = NULL; |
|
3589 iFindResults = iStore->ContactGroupsLC(); |
|
3590 count = iFindResults->Count(); |
|
3591 iErr = KErrGeneral; |
|
3592 while(count) |
|
3593 { |
|
3594 iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
3595 iOp = iContactManager->RetrieveContactL(*iResult,*this); |
|
3596 CActiveScheduler::Start(); |
|
3597 |
|
3598 iGroup = iStoreContact->Group(); |
|
3599 if(!iGroup->GroupLabel().Compare(KGroup)) |
|
3600 { |
|
3601 groupId =iResult->PackLC(); |
|
3602 TInt count(iContactToDelete->Count()); |
|
3603 while(count) |
|
3604 { |
|
3605 iGroup->AddContactL(iContactToDelete->At(--count)); |
|
3606 } |
|
3607 CleanupStack::Pop(); |
|
3608 break; |
|
3609 } |
|
3610 } |
|
3611 CleanupStack::Pop(); |
|
3612 CleanupStack::PushL(groupId); |
|
3613 iFindResults = NULL; |
|
3614 delete iContactToDelete; |
|
3615 iContactToDelete = NULL; |
|
3616 /** ends */ |
|
3617 |
|
3618 /**Organise using SAPI core class*/ |
|
3619 if(groupId) |
|
3620 { |
|
3621 __UHEAP_MARK; |
|
3622 CContactService* serviceHandle = CContactService::NewL(); |
|
3623 CleanupStack::PushL(serviceHandle); |
|
3624 iLog->Log( KServiceOpen ); |
|
3625 |
|
3626 serviceHandle->OrganiseGroupsL(this,0,*groupId,idArray,EFalse); |
|
3627 iLog->Log(_L("OrganiseGroupsL called\n")); |
|
3628 iLog->Log(_L("Start Active Scheduler\n")); |
|
3629 CActiveScheduler::Start(); |
|
3630 |
|
3631 |
|
3632 CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
3633 |
|
3634 iLog->Log( KServiceClose ); |
|
3635 __UHEAP_MARKEND; |
|
3636 } |
|
3637 /** ends */ |
|
3638 |
|
3639 |
|
3640 /** Check for the group */ |
|
3641 iFindResults = iStore->ContactGroupsLC(); |
|
3642 count = iFindResults->Count(); |
|
3643 iErr = KErrGeneral; |
|
3644 while(count) |
|
3645 { |
|
3646 iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
3647 if(!(iResult->PackLC())->Compare(*groupId)) |
|
3648 { |
|
3649 iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
3650 iContactToDelete->AppendL(iResult); |
|
3651 iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
3652 CActiveScheduler::Start(); |
|
3653 } |
|
3654 CleanupStack::PopAndDestroy(); |
|
3655 } |
|
3656 CleanupStack::Pop(); //iFindResults |
|
3657 iFindResults = NULL; |
|
3658 /**end */ |
|
3659 CleanupStack::PopAndDestroy(groupId); |
|
3660 CleanupStack::PopAndDestroy(num);//destroy all contactIds |
|
3661 CleanupStack::PopAndDestroy(&idArray);//singleContactField |
|
3662 |
|
3663 return iErr; |
|
3664 } |
|
3665 |
|
3666 // ----------------------------------------------------------------------------- |
|
3667 // CContactsUT::OrganiseDeleteL |
|
3668 // Example test method function. |
|
3669 // (other items were commented in a header). |
|
3670 // ----------------------------------------------------------------------------- |
|
3671 // |
|
3672 TInt CContactsUT::ImportL( CStifItemParser& aItem ) |
|
3673 { |
|
3674 |
|
3675 // Print to UI |
|
3676 _LIT( KContactsTest, "ContactsTest" ); |
|
3677 _LIT( KExample, "In Import" ); |
|
3678 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
3679 // Print to log file |
|
3680 iLog->Log( KExample ); |
|
3681 |
|
3682 TInt i = 0; |
|
3683 TPtrC string; |
|
3684 _LIT( KParam, "Param[%i]: %S" ); |
|
3685 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
3686 { |
|
3687 TestModuleIf().Printf( i, KContactsTest, |
|
3688 KParam, i, &string ); |
|
3689 i++; |
|
3690 } |
|
3691 iErr = KErrNone; |
|
3692 _LIT(KFileName,"c:\\vcardex.vcf"); |
|
3693 |
|
3694 /** Add 1 contact */ |
|
3695 CVPbkFieldTypeRefsList* fieldTypeRefList = CVPbkFieldTypeRefsList::NewL(); |
|
3696 CleanupStack::PushL(fieldTypeRefList); |
|
3697 |
|
3698 fieldTypeRefList->AppendL( |
|
3699 *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_FIRSTNAME ) ); |
|
3700 fieldTypeRefList->AppendL( |
|
3701 *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN ) ); |
|
3702 |
|
3703 // Create first contact |
|
3704 iStoreContact = iStore->CreateNewContactLC(); |
|
3705 |
|
3706 // Create contact field for contact |
|
3707 MVPbkStoreContactField* field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
3708 // Set contact field data |
|
3709 _LIT(KFirstName,"Tenali"); |
|
3710 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstName ); |
|
3711 // Add the contact field to contact |
|
3712 iStoreContact->AddFieldL( field ); |
|
3713 CleanupStack::Pop(); // field |
|
3714 |
|
3715 // Create contact field for contact |
|
3716 field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
3717 // Set contact field data |
|
3718 _LIT(KFirstNumber,"45678"); |
|
3719 (MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstNumber ); |
|
3720 // Add the contact field to contact |
|
3721 iStoreContact->AddFieldL( field ); |
|
3722 CleanupStack::Pop(); // field |
|
3723 |
|
3724 // Commit the new created contact to contact store |
|
3725 iStoreContact->CommitL( *this ); |
|
3726 CActiveScheduler::Start(); |
|
3727 CleanupStack::Pop(); // iStoreContact |
|
3728 |
|
3729 CleanupStack::PopAndDestroy(fieldTypeRefList); |
|
3730 /** end */ |
|
3731 |
|
3732 /** Retrieve the contact */ |
|
3733 |
|
3734 // Phone number to be searched for |
|
3735 _LIT( KMatchNo, "45678" ); |
|
3736 // Create find operation |
|
3737 iOp = iContactManager->MatchPhoneNumberL( |
|
3738 KMatchNo, KMatchNo().Length(), *this ); |
|
3739 |
|
3740 CActiveScheduler::Start(); |
|
3741 TInt count = iFindResults->Count(); |
|
3742 while(count) |
|
3743 { |
|
3744 iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
3745 iVCardEngine = CVPbkVCardEng::NewL( *iContactManager ); |
|
3746 |
|
3747 // Create the buffer to store the contact |
|
3748 iBuffer = HBufC8::NewL( 1024 ); |
|
3749 TPtr8 bufferPtr( iBuffer->Des() ); |
|
3750 iDestStream.Open( bufferPtr ); |
|
3751 |
|
3752 iOperation = EVCard; |
|
3753 |
|
3754 //export the contact from MVPbkContactLink |
|
3755 iOp = iVCardEngine->ExportVCardL( iDestStream, *iResult, *this ); |
|
3756 CActiveScheduler::Start(); |
|
3757 |
|
3758 delete iVCardEngine; |
|
3759 iVCardEngine = NULL; |
|
3760 |
|
3761 if(iBuffer) |
|
3762 { |
|
3763 RFile file; |
|
3764 CleanupClosePushL(file); |
|
3765 file.Replace(iRfs,KFileName,EFileWrite); |
|
3766 file.Write(0,*iBuffer); |
|
3767 CleanupStack::PopAndDestroy(&file); |
|
3768 delete iBuffer; |
|
3769 iBuffer = NULL; |
|
3770 } |
|
3771 |
|
3772 iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
3773 iContactToDelete->AppendL(iResult); |
|
3774 iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
3775 CActiveScheduler::Start(); |
|
3776 } |
|
3777 iFindResults = NULL; |
|
3778 __UHEAP_MARK; |
|
3779 //using sapi |
|
3780 CContactService* serviceHandle = CContactService::NewL(); |
|
3781 CleanupStack::PushL(serviceHandle); |
|
3782 iLog->Log( KServiceOpen ); |
|
3783 |
|
3784 TFileName file(KFileName); |
|
3785 |
|
3786 serviceHandle->ImportVCardToStoreL(this,0,file); |
|
3787 iLog->Log(_L("ImportVCardToStoreL called\n")); |
|
3788 iLog->Log(_L("Start Active Scheduler\n")); |
|
3789 CActiveScheduler::Start(); |
|
3790 |
|
3791 CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
3792 iLog->Log( KServiceClose ); |
|
3793 __UHEAP_MARKEND; |
|
3794 /**Delete using virtual Phonebook */ |
|
3795 |
|
3796 |
|
3797 // Create find operation |
|
3798 iOp = iContactManager->MatchPhoneNumberL( |
|
3799 KMatchNo, KMatchNo().Length(), *this ); |
|
3800 CActiveScheduler::Start(); |
|
3801 iErr = KErrGeneral; |
|
3802 count = iFindResults->Count(); |
|
3803 while(count) |
|
3804 { |
|
3805 iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
3806 iContactToDelete->AppendL(&(const_cast<MVPbkContactLink&>(iFindResults->At(--count)))); |
|
3807 iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
3808 CActiveScheduler::Start(); |
|
3809 } |
|
3810 /**end */ |
|
3811 |
|
3812 return iErr; |
|
3813 } |
|
3814 // ----------------------------------------------------------------------------- |
|
3815 // CContactsUT::OrganiseDeleteL |
|
3816 // Example test method function. |
|
3817 // (other items were commented in a header). |
|
3818 // ----------------------------------------------------------------------------- |
|
3819 // |
|
3820 TInt CContactsUT::ExportL( CStifItemParser& aItem ) |
|
3821 { |
|
3822 |
|
3823 // Print to UI |
|
3824 _LIT( KContactsTest, "ContactsTest" ); |
|
3825 _LIT( KExample, "In Import" ); |
|
3826 TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
3827 // Print to log file |
|
3828 iLog->Log( KExample ); |
|
3829 |
|
3830 TInt i = 0; |
|
3831 TPtrC string; |
|
3832 _LIT( KParam, "Param[%i]: %S" ); |
|
3833 while ( aItem.GetNextString ( string ) == KErrNone ) |
|
3834 { |
|
3835 TestModuleIf().Printf( i, KContactsTest, |
|
3836 KParam, i, &string ); |
|
3837 i++; |
|
3838 } |
|
3839 iErr = KErrNone; |
|
3840 _LIT(KFileName,"c:\\vcardim.vcf"); |
|
3841 RFs fs; |
|
3842 CleanupClosePushL(fs); |
|
3843 User::LeaveIfError(fs.Connect()); |
|
3844 RFile file; |
|
3845 if(!file.Open(fs,KFileName,EFileRead)) |
|
3846 { |
|
3847 file.Close(); |
|
3848 fs.Delete(KFileName); |
|
3849 } |
|
3850 CleanupStack::PopAndDestroy(&fs); |
|
3851 |
|
3852 DeleteAllL(); |
|
3853 _LIT(KFirstName,"Akbar"); |
|
3854 TPtrC ptr(KFirstName); |
|
3855 AddOneContactL(ptr); |
|
3856 |
|
3857 /** Retrieve the contact */ |
|
3858 |
|
3859 // Phone number to be searched for |
|
3860 // Create find operation |
|
3861 iOp = iContactManager->MatchPhoneNumberL( |
|
3862 KPhoneNumber, KPhoneNumber().Length(), *this ); |
|
3863 |
|
3864 CActiveScheduler::Start(); |
|
3865 TInt count = iFindResults->Count(); |
|
3866 while(count) |
|
3867 { |
|
3868 iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
3869 iBuffer = iResult->PackLC(); |
|
3870 CleanupStack::Pop(); |
|
3871 |
|
3872 // __UHEAP_MARK; |
|
3873 //using sapi |
|
3874 CContactService* serviceHandle = CContactService::NewL(); |
|
3875 CleanupStack::PushL(serviceHandle); |
|
3876 iLog->Log( KServiceOpen ); |
|
3877 |
|
3878 TFileName file(KFileName); |
|
3879 serviceHandle->ExportVCardL(this,0,file,*iBuffer); |
|
3880 iLog->Log(_L("ExportVCardL called\n")); |
|
3881 iLog->Log(_L("Start Active Scheduler\n")); |
|
3882 CActiveScheduler::Start(); |
|
3883 |
|
3884 CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
3885 iLog->Log( KServiceClose ); |
|
3886 // __UHEAP_MARKEND; |
|
3887 |
|
3888 iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
3889 iContactToDelete->AppendL(iResult); |
|
3890 iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
3891 CActiveScheduler::Start(); |
|
3892 |
|
3893 delete iBuffer; |
|
3894 iBuffer = NULL; |
|
3895 |
|
3896 RPointerArray< MVPbkStoreContact > importedContacts; |
|
3897 CleanupClosePushL(importedContacts); |
|
3898 |
|
3899 iVCardEngine = CVPbkVCardEng::NewL( *iContactManager ); |
|
3900 |
|
3901 // Open the RFileReadStream that holds the vCard content |
|
3902 iErr = iSource.Open( iRfs, KFileName, EFileRead ); |
|
3903 |
|
3904 // Import the contact from RFileReadStream asynchronously |
|
3905 // The operation status is reported via MVPbkSingleContactOperationObserver. |
|
3906 iOp = iVCardEngine->ImportVCardL( importedContacts, *iStore, iSource, *this ); |
|
3907 CActiveScheduler::Start(); |
|
3908 |
|
3909 if(!importedContacts.Count()) |
|
3910 { |
|
3911 return KErrGeneral; |
|
3912 |
|
3913 } |
|
3914 |
|
3915 // Close iImportedContacts |
|
3916 // |
|
3917 importedContacts.ResetAndDestroy(); |
|
3918 CleanupStack::PopAndDestroy(&importedContacts); |
|
3919 } |
|
3920 iFindResults = NULL; |
|
3921 |
|
3922 |
|
3923 return iErr; |
|
3924 } |
|
3925 |
|
3926 |
|
3927 TInt CContactsUT::GetListCancelL( CStifItemParser& /*aItem*/) |
|
3928 { |
|
3929 |
|
3930 int ret=0; |
|
3931 ret = getlist_cancel(0, NULL); |
|
3932 |
|
3933 if(ret==0) |
|
3934 return KErrNone; |
|
3935 else |
|
3936 return KErrGeneral; |
|
3937 } |
|
3938 |
|
3939 |
|
3940 TInt CContactsUT::GetListSrchCancelL( CStifItemParser& /*aItem*/) |
|
3941 { |
|
3942 |
|
3943 int ret=0; |
|
3944 ret = getlistsrh_cancel(0, NULL); |
|
3945 |
|
3946 if(ret==0) |
|
3947 return KErrNone; |
|
3948 else |
|
3949 return KErrGeneral; |
|
3950 } |
|
3951 |
|
3952 |
|
3953 |
|
3954 TInt CContactsUT::ExportCancelL( CStifItemParser& /*aItem*/) |
|
3955 { |
|
3956 |
|
3957 int ret=0; |
|
3958 ret = export_cancel(0, NULL); |
|
3959 |
|
3960 if(ret==0) |
|
3961 return KErrNone; |
|
3962 else |
|
3963 return KErrGeneral; |
|
3964 |
|
3965 |
|
3966 } |
|
3967 |
|
3968 TInt CContactsUT::AddCancelL( CStifItemParser& /*aItem*/ ) |
|
3969 { |
|
3970 int ret=0; |
|
3971 ret = add_cancel(0, NULL); |
|
3972 |
|
3973 if(ret==0) |
|
3974 return KErrNone; |
|
3975 else |
|
3976 return KErrGeneral; |
|
3977 } |
|
3978 |
|
3979 TInt CContactsUT::ImportCancelL( CStifItemParser& /*aItem*/) |
|
3980 { |
|
3981 |
|
3982 int ret=0; |
|
3983 ret = import_cancel(0, NULL); |
|
3984 |
|
3985 if(ret==0) |
|
3986 return KErrNone; |
|
3987 else |
|
3988 return KErrGeneral; |
|
3989 |
|
3990 |
|
3991 } |
|
3992 |
|
3993 TInt CContactsUT::DeleteCancelL( CStifItemParser& /*aItem*/) |
|
3994 { |
|
3995 |
|
3996 int ret=0; |
|
3997 ret = delete_cancel(0, NULL); |
|
3998 |
|
3999 if(ret==0) |
|
4000 return KErrNone; |
|
4001 else |
|
4002 return KErrGeneral; |
|
4003 |
|
4004 } |
|
4005 TInt CContactsUT::OrganiseCancelL( CStifItemParser& /*aItem*/) |
|
4006 { |
|
4007 |
|
4008 int ret=0; |
|
4009 ret = organise_cancel(0, NULL); |
|
4010 |
|
4011 if(ret==0) |
|
4012 return KErrNone; |
|
4013 else |
|
4014 return KErrGeneral; |
|
4015 |
|
4016 } |
|
4017 //End of file |