serviceproviders/sapi_contacts_vpbk/tsrc/testing/tcontact_add/src/tcontact_addblocks.cpp
changeset 19 989d2f495d90
child 22 fc9cf246af83
equal deleted inserted replaced
14:a36b1e19a461 19:989d2f495d90
       
     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 "tContact_add.h"
       
    26 
       
    27 // EXTERNAL DATA STRUCTURES
       
    28 //extern  ?external_data;
       
    29 
       
    30 // EXTERNAL FUNCTION PROTOTYPES  
       
    31 //extern ?external_function( ?arg_type,?arg_type );
       
    32 
       
    33 // CONSTANTS
       
    34 //const ?type ?constant_var = ?constant;
       
    35 
       
    36 // MACROS
       
    37 //#define ?macro ?macro_def
       
    38 
       
    39 // LOCAL CONSTANTS AND MACROS
       
    40 //const ?type ?constant_var = ?constant;
       
    41 //#define ?macro_name ?macro_def
       
    42 
       
    43 // MODULE DATA STRUCTURES
       
    44 //enum ?declaration
       
    45 //typedef ?declaration
       
    46 
       
    47 // LOCAL FUNCTION PROTOTYPES
       
    48 //?type ?function_name( ?arg_type, ?arg_type );
       
    49 
       
    50 // FORWARD DECLARATIONS
       
    51 //class ?FORWARD_CLASSNAME;
       
    52 
       
    53 // ============================= LOCAL FUNCTIONS ===============================
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // ?function_name ?description.
       
    57 // ?description
       
    58 // Returns: ?value_1: ?description
       
    59 //          ?value_n: ?description_line1
       
    60 //                    ?description_line2
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 /*
       
    64 ?type ?function_name(
       
    65     ?arg_type arg,  // ?description
       
    66     ?arg_type arg)  // ?description
       
    67     {
       
    68 
       
    69     ?code  // ?comment
       
    70 
       
    71     // ?comment
       
    72     ?code
       
    73     }
       
    74 */
       
    75 
       
    76  TInt Iterator_cnt=0;
       
    77 
       
    78  //HBufC8 *contactid ;
       
    79  HBufC8* contactid=NULL;
       
    80 CSingleContact* myContact=NULL;
       
    81 
       
    82 
       
    83 
       
    84 void CContactCallback::HandleReturnValue( TOperationEvent aEventId, const TInt& aError, TInt aTransId )
       
    85 {
       
    86   
       
    87   CActiveScheduler::Stop();
       
    88   iError= aError ;
       
    89   
       
    90 }
       
    91 
       
    92 
       
    93  void CContactCallback:: HandleReturnIter( const TInt& aError, CContactIter* aIter, TInt aTransId )
       
    94  {
       
    95  
       
    96 	
       
    97      CActiveScheduler::Stop();
       
    98  CSingleContactField* field = NULL; 
       
    99     HBufC8* buf = NULL;
       
   100     TBuf8<100> buf1;
       
   101     TBuf<100> buf2;
       
   102     TBuf<100> buf3;
       
   103     TInt count=0 ;	     
       
   104 	
       
   105    
       
   106 if(aError==KErrNone)
       
   107 {
       
   108    aIter->NextL(myContact,contactid);
       
   109 }
       
   110 delete aIter;
       
   111 return; 
       
   112  } 
       
   113 
       
   114 // ============================ MEMBER FUNCTIONS ===============================
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // Ctdeleteadd::Delete
       
   118 // Delete here all resources allocated and opened from test methods. 
       
   119 // Called from destructor. 
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 void Ctdeleteadd::Delete() 
       
   123     {
       
   124 
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // Ctdeleteadd::RunMethodL
       
   129 // Run specified method. Contains also table of test mothods and their names.
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 TInt Ctdeleteadd::RunMethodL( 
       
   133     CStifItemParser& aItem ) 
       
   134     {
       
   135 
       
   136     static TStifFunctionInfo const KFunctions[] =
       
   137         {  
       
   138         // Copy this line for every implemented function.
       
   139         // First string is the function name used in TestScripter script file.
       
   140         // Second is the actual implementation member function. 
       
   141         ENTRY( "Add_Test1",  Ctdeleteadd::Add_Test1L ),
       
   142         ENTRY( "Add_Test2",  Ctdeleteadd::Add_Test2L ),
       
   143         ENTRY( "Add_Test3",  Ctdeleteadd::Add_Test3L ),
       
   144         ENTRY( "Add_Test4",  Ctdeleteadd::Add_Test4L ),
       
   145         ENTRY( "Add_Test5",  Ctdeleteadd::Add_Test5L ),
       
   146         ENTRY( "Add_Test6",  Ctdeleteadd::Add_Test6L ), 
       
   147         ENTRY( "Add_Test7",  Ctdeleteadd::Add_Test7L ), 
       
   148         ENTRY( "Add_Test8",  Ctdeleteadd::Add_Test8L ), 
       
   149         //ENTRY( "Add_Test9",  Ctdeleteadd::Add_Test9L ), 
       
   150         ENTRY( "Add_Test10", Ctdeleteadd::Add_Test10L ), 
       
   151         ENTRY( "Add_Test11", Ctdeleteadd::Add_Test11L ), 
       
   152         ENTRY( "Add_Test12", Ctdeleteadd::Add_Test12L ),
       
   153         ENTRY( "Add_Test13", Ctdeleteadd::Add_Test13L ),
       
   154         
       
   155         };
       
   156 
       
   157     const TInt count = sizeof( KFunctions ) / 
       
   158                         sizeof( TStifFunctionInfo );
       
   159 
       
   160     return RunInternalL( KFunctions, count, aItem );
       
   161 
       
   162     }
       
   163 
       
   164 	    
       
   165     
       
   166  /* Adding single contact to default database*/
       
   167   TInt Ctdeleteadd::Add_Test1L( CStifItemParser& aItem )
       
   168     {
       
   169 
       
   170 
       
   171     TInt count =KErrGeneral ;
       
   172     _LIT8(KFirstName,"FirstName");
       
   173     _LIT(KName,"Aaaa"); 
       
   174     //instantiate service class object
       
   175     
       
   176     /* create contactitem to add */
       
   177     CSingleContact* singleContact = CSingleContact::NewL();
       
   178     CSingleContactField* singleContactField = CSingleContactField::NewL();
       
   179     
       
   180        
       
   181     singleContactField->SetFieldParamsL(KFirstName,KNullDesC,KName);
       
   182     singleContact->AddFieldToContactL(singleContactField);
       
   183   
       
   184     
       
   185     aItem.GetNextInt(count);
       
   186     
       
   187     /* Add the contactitem */
       
   188     icontactservice->AddL(icallback,0,singleContact);
       
   189     CActiveScheduler::Start();
       
   190    
       
   191     /* check whether add api returns the expected error code */  
       
   192   if(count == icallback->iError )
       
   193       return KErrNone ;
       
   194       
       
   195     return KErrGeneral ;  
       
   196 
       
   197 
       
   198 	 }
       
   199 
       
   200   /* Adding contact with invalid fieldname */
       
   201  TInt Ctdeleteadd::Add_Test2L( CStifItemParser& aItem )
       
   202     {
       
   203 
       
   204 
       
   205     TInt count =KErrGeneral ;
       
   206     _LIT8(KFirstName,"FrstName");
       
   207     _LIT(KName,"Aaaa"); 
       
   208     //instantiate service class object
       
   209     
       
   210     /* create contactitem with invalid fieldname "FrstName */
       
   211     CSingleContact* singleContact = CSingleContact::NewL();
       
   212     CSingleContactField* singleContactField = CSingleContactField::NewL();
       
   213     
       
   214      
       
   215     singleContactField->SetFieldParamsL(KFirstName,KNullDesC,KName);
       
   216     singleContact->AddFieldToContactL(singleContactField);
       
   217   
       
   218     
       
   219    /* Add the contactitem */ 
       
   220     aItem.GetNextInt(count) ;
       
   221     TRAPD(err, icontactservice->AddL(icallback,0,singleContact))
       
   222     CActiveScheduler::Start();
       
   223      
       
   224   /* check whether Add api returns the expected error code */      
       
   225  if(-1 == icallback->iError )
       
   226       return KErrNone ;
       
   227       
       
   228     return KErrGeneral ;
       
   229 
       
   230  }
       
   231  
       
   232  /* adding contact with more fields */
       
   233  TInt Ctdeleteadd::Add_Test3L( CStifItemParser& aItem )
       
   234  {
       
   235  
       
   236  
       
   237     TInt count =KErrGeneral ;
       
   238     _LIT8(KFirstName,"FirstName");
       
   239     _LIT(KFName,"XYZ");
       
   240     _LIT8(KLastName,"LastName");
       
   241     _LIT(KLName,"123");
       
   242     _LIT8(KPrefix,"Prefix");
       
   243     _LIT(KPfix,"Z");
       
   244     _LIT8(KSuffix,"Suffix");
       
   245     _LIT(KSfix,"A");
       
   246      _LIT8(KLandline,"LandPhoneHome");
       
   247     _LIT(KLandno,"08216666");
       
   248      _LIT8(KMobile,"MobilePhoneHome");
       
   249     _LIT(KMobno,"9900870");
       
   250     _LIT8(KFax,"FaxNumberHome");
       
   251     _LIT(KFaxno,"12345");
       
   252     _LIT8(KNoteField,"Note");
       
   253     _LIT(KNote,"my details");
       
   254      _LIT8(KJobTitle,"JobTitle");
       
   255     _LIT(KJob,"software engg");
       
   256     _LIT8(KEmail,"EmailWork");
       
   257     _LIT(KMail,"xyz@mail.com");
       
   258     _LIT8(KRing,"Ringtone");
       
   259     _LIT(KName,"C:\\data\\sounds\\digital\\around.mp3");  
       
   260    //instantiate service class object
       
   261      /* create contactitem to add */
       
   262     CSingleContactField* FName = CSingleContactField::NewL();
       
   263     CSingleContactField* LName = CSingleContactField::NewL();
       
   264     CSingleContactField* Pfix = CSingleContactField::NewL();
       
   265      CSingleContactField* Sfix = CSingleContactField::NewL();
       
   266     CSingleContactField* Landno = CSingleContactField::NewL();
       
   267      CSingleContactField* Mobno = CSingleContactField::NewL();
       
   268     CSingleContactField* Faxno = CSingleContactField::NewL();
       
   269    CSingleContactField* Note = CSingleContactField::NewL(); 
       
   270     CSingleContactField* Job = CSingleContactField::NewL();     
       
   271     CSingleContactField* Mail = CSingleContactField::NewL();
       
   272     CSingleContactField* Ring = CSingleContactField::NewL();
       
   273       
       
   274     CSingleContact* singleContact = CSingleContact::NewL();
       
   275     
       
   276        
       
   277     FName->SetFieldParamsL(KFirstName,KNullDesC,KFName);
       
   278     singleContact->AddFieldToContactL(FName);
       
   279     
       
   280     LName->SetFieldParamsL(KLastName,KNullDesC,KLName);
       
   281     singleContact->AddFieldToContactL(LName);
       
   282     
       
   283     Pfix->SetFieldParamsL(KPrefix,KNullDesC,KPfix);
       
   284     singleContact->AddFieldToContactL(Pfix);
       
   285     
       
   286     Sfix->SetFieldParamsL(KSuffix,KNullDesC,KSfix);
       
   287     singleContact->AddFieldToContactL(Sfix);
       
   288     
       
   289     Landno->SetFieldParamsL(KLandline,KNullDesC,KLandno);
       
   290     singleContact->AddFieldToContactL(Landno);
       
   291     
       
   292     Mobno->SetFieldParamsL(KMobile,KNullDesC,KMobno);
       
   293     singleContact->AddFieldToContactL(Mobno);
       
   294     
       
   295     Faxno->SetFieldParamsL(KFax,KNullDesC,KFaxno);
       
   296     singleContact->AddFieldToContactL(Faxno);
       
   297     
       
   298     Note->SetFieldParamsL(KNoteField,KNullDesC,KNote);    
       
   299     singleContact->AddFieldToContactL(Note);
       
   300     
       
   301     Job->SetFieldParamsL(KJobTitle,KNullDesC,KJob);
       
   302     singleContact->AddFieldToContactL(Job);
       
   303     
       
   304     Mail->SetFieldParamsL(KEmail,KNullDesC,KMail);
       
   305     singleContact->AddFieldToContactL(Mail);
       
   306     
       
   307     Ring->SetFieldParamsL(KRing,KNullDesC,KName);
       
   308     singleContact->AddFieldToContactL(Ring);
       
   309   
       
   310     
       
   311     aItem.GetNextInt(count) ;
       
   312     
       
   313     /* Add the contactitem */
       
   314     icontactservice->AddL(icallback,0,singleContact);
       
   315     CActiveScheduler::Start();
       
   316    
       
   317    TPtrC String;
       
   318 
       
   319 //   TPtrC db1(_L("cntdb://c:testcontacts2.cdb"));
       
   320    
       
   321    /* get the filename for export */
       
   322      if(aItem.GetNextString(String) != KErrNone )  
       
   323      {
       
   324      	_LIT(Kerr ,"Failed to read input file name") ;
       
   325      	iLog->Log(Kerr) ;
       
   326      	return KErrGeneral ;
       
   327      }										
       
   328      
       
   329      TBuf<256> string1;
       
   330 	 string1.Copy(String);
       
   331    
       
   332    icontactservice->GetListL(icallback,1,EContacts,KNullDesC8) ;
       
   333    CActiveScheduler::Start();
       
   334  	 
       
   335 	
       
   336   icontactservice->ExportVCardL(icallback,2,string1,*contactid);
       
   337   CActiveScheduler::Start();
       
   338   
       
   339   
       
   340    	
       
   341     /* check whether add api returns the expected error code */  
       
   342   if(count == icallback->iError )
       
   343       return KErrNone ;
       
   344       
       
   345     return KErrGeneral ;   
       
   346  
       
   347 
       
   348  }
       
   349 
       
   350  
       
   351   /* Adding a group */
       
   352  TInt Ctdeleteadd::Add_Test4L( CStifItemParser& aItem )
       
   353   {
       
   354 
       
   355       // Print to UI
       
   356     _LIT( Ktsapicontacts, "tsapicontacts" );
       
   357     _LIT( KExample, "In GetList_Test1L" );
       
   358     TestModuleIf().Printf( 0, Ktsapicontacts, KExample );
       
   359     // Print to log file
       
   360     iLog->Log( KExample );
       
   361     
       
   362    
       
   363     TInt count;
       
   364    
       
   365    /* Group1 to add to phonebook */      
       
   366    _LIT(KGroup,"Group10")  ;
       
   367    
       
   368    aItem.GetNextInt(count) ;
       
   369    
       
   370    /*Add group1 to phonebook */
       
   371    icontactservice->AddL(icallback,0,NULL,KNullDesC8,KGroup);
       
   372      CActiveScheduler::Start();
       
   373      
       
   374   /* check whether add api returns the expected error code */
       
   375  if(count == icallback->iError )
       
   376       return KErrNone ;
       
   377       
       
   378     return KErrGeneral ;
       
   379 
       
   380  }
       
   381  
       
   382   
       
   383   
       
   384    
       
   385   /* Adding the same group name twice */
       
   386  TInt Ctdeleteadd::Add_Test5L( CStifItemParser& aItem )
       
   387   {
       
   388 
       
   389       // Print to UI
       
   390     _LIT( Ktsapicontacts, "tsapicontacts" );
       
   391     _LIT( KExample, "In GetList_Test1L" );
       
   392     TestModuleIf().Printf( 0, Ktsapicontacts, KExample );
       
   393     // Print to log file
       
   394     iLog->Log( KExample );
       
   395     
       
   396    
       
   397     TInt count;
       
   398    
       
   399    /* Group1 to add to phonebook */      
       
   400    _LIT(KGroup,"Group1")  ;
       
   401    
       
   402    aItem.GetNextInt(count) ;
       
   403    
       
   404    /*Add group1 to phonebook */
       
   405    icontactservice->AddL(icallback,0,NULL,KNullDesC8,KGroup);
       
   406      CActiveScheduler::Start();
       
   407      
       
   408   /* Add the same group1 to phonebook */   
       
   409    icontactservice->AddL(icallback,0,NULL,KNullDesC8,KGroup);
       
   410    CActiveScheduler::Start();
       
   411 
       
   412   /* check whether add api returns the expected error code */
       
   413  if(count == icallback->iError )
       
   414       return KErrNone ;
       
   415       
       
   416     return KErrGeneral ;
       
   417 
       
   418  }
       
   419  
       
   420 /* Adding same contact twice to default database*/
       
   421   TInt Ctdeleteadd::Add_Test6L( CStifItemParser& aItem )
       
   422     {
       
   423 
       
   424 
       
   425     TInt count =KErrGeneral ;
       
   426     _LIT8(KFirstName,"FirstName");
       
   427     _LIT(KName,"Aaaa"); 
       
   428     //instantiate service class object
       
   429     
       
   430     /* create contactitem to add */
       
   431     CSingleContact* singleContact = CSingleContact::NewL();
       
   432     CSingleContactField* singleContactField = CSingleContactField::NewL();
       
   433     
       
   434        
       
   435     singleContactField->SetFieldParamsL(KFirstName,KNullDesC,KName);
       
   436     singleContact->AddFieldToContactL(singleContactField);
       
   437   
       
   438     
       
   439     aItem.GetNextInt(count) ;
       
   440     
       
   441     /* Add the contactitem */
       
   442     icontactservice->AddL(icallback,0,singleContact);
       
   443     CActiveScheduler::Start();
       
   444     
       
   445     icontactservice->AddL(icallback,0,singleContact);
       
   446     CActiveScheduler::Start();
       
   447    
       
   448     /* check whether add api returns the expected error code */  
       
   449   if(count == icallback->iError )
       
   450       return KErrNone ;
       
   451       
       
   452     return KErrGeneral ;  
       
   453 
       
   454 
       
   455 	 }
       
   456 
       
   457 // same contact twice to different database
       
   458   TInt Ctdeleteadd::Add_Test7L( CStifItemParser& aItem )
       
   459     {
       
   460 
       
   461 	_LIT(KCntDbUri, "cntdb://c:contacts.cdb");			
       
   462     TInt count =KErrGeneral ;
       
   463     _LIT8(KFirstName,"FirstName");
       
   464     _LIT(KName,"Aaaa"); 
       
   465     //instantiate service class object
       
   466     
       
   467     /* create contactitem to add */
       
   468     CSingleContact* singleContact = CSingleContact::NewL();
       
   469     CSingleContactField* singleContactField = CSingleContactField::NewL();
       
   470     
       
   471        
       
   472     singleContactField->SetFieldParamsL(KFirstName,KNullDesC,KName);
       
   473     singleContact->AddFieldToContactL(singleContactField);
       
   474   
       
   475     
       
   476     aItem.GetNextInt(count) ;
       
   477     
       
   478     /* Add the contactitem */
       
   479     icontactservice->AddL(icallback,0,singleContact,KNullDesC8,KNullDesC,KCntDbUri);
       
   480     CActiveScheduler::Start();
       
   481     
       
   482     icontactservice->AddL(icallback,0,singleContact,KNullDesC8,KNullDesC,KCntDbUri);
       
   483     CActiveScheduler::Start();
       
   484    
       
   485     /* check whether add api returns the expected error code */  
       
   486   if(count == icallback->iError )
       
   487       return KErrNone ;
       
   488       
       
   489     return KErrGeneral ;  
       
   490 
       
   491 
       
   492 	 }	 
       
   493  
       
   494 /* Adding single contact to default database with the same key and different label*/
       
   495 
       
   496   TInt Ctdeleteadd::Add_Test8L( CStifItemParser& aItem )
       
   497     {
       
   498 
       
   499 
       
   500     TInt count =KErrGeneral ;
       
   501     
       
   502     _LIT8(KLandline,"LandPhoneHome");
       
   503     _LIT8(Anni,"Anniversary");
       
   504     _LIT(KLandno1,"08216666");
       
   505     
       
   506     _LIT(KLandno2,"08216667");
       
   507     _LIT(Land1,"no.1");
       
   508     _LIT(Land2,"no.2");
       
   509     //instantiate service class object
       
   510     
       
   511     /* create contactitem to add */ 
       
   512     CSingleContact* singleContact = CSingleContact::NewL();
       
   513     CSingleContactField* singleContactField1 = CSingleContactField::NewL();
       
   514     CSingleContactField* singleContactField2 = CSingleContactField::NewL();
       
   515        
       
   516     singleContactField1->SetFieldParamsL(KLandline,Land1,KLandno1);
       
   517     singleContactField2->SetFieldParamsL(KLandline,Land2,KLandno2);
       
   518     singleContact->AddFieldToContactL(singleContactField1);
       
   519   	singleContact->AddFieldToContactL(singleContactField2);
       
   520     
       
   521     CSingleContactField* singleContactField3 = CSingleContactField::NewL();
       
   522     CSingleContactField* singleContactField4 = CSingleContactField::NewL();
       
   523        
       
   524     singleContactField3->SetFieldParamsL(KLandline,Land1,KLandno1);
       
   525     singleContactField4->SetFieldParamsL(KLandline,Land2,KLandno2);
       
   526     singleContact->AddFieldToContactL(singleContactField1);
       
   527   	singleContact->AddFieldToContactL(singleContactField2);
       
   528     aItem.GetNextInt(count) ;
       
   529     
       
   530     /* Add the contactitem */
       
   531     icontactservice->AddL(icallback,0,singleContact);
       
   532     CActiveScheduler::Start();
       
   533    
       
   534     /* check whether add api returns the expected error code */  
       
   535   if(count == icallback->iError )
       
   536       return KErrNone ;
       
   537       
       
   538     return KErrGeneral ;  
       
   539 
       
   540 
       
   541 	 }
       
   542 	 
       
   543 	 /* adding a thumbnail*/
       
   544 //TInt Ctdeleteadd::Add_Test9L( CStifItemParser& aItem )
       
   545 //    {
       
   546 
       
   547 //
       
   548 //    TInt count =KErrGeneral ;
       
   549 //   _LIT8(Thumbnail,"ThumbNailPic");
       
   550 //    _LIT(KName,"C:\\data\\Images\\Pictures\\blue.png"); 
       
   551 //    //instantiate service class object
       
   552     
       
   553 //    /* create contactitem to add */
       
   554 //    CSingleContact* singleContact = CSingleContact::NewL();
       
   555 //   CSingleContactField* singleContactField = CSingleContactField::NewL();
       
   556     
       
   557        
       
   558 //    singleContactField->SetFieldParamsL(Thumbnail,KNullDesC,KName);
       
   559 //    singleContact->AddFieldToContactL(singleContactField);
       
   560   
       
   561     
       
   562 //   aItem.GetNextInt(count) ;
       
   563     
       
   564 //   /* Add the contactitem */
       
   565 //   icontactservice->AddL(icallback,0,singleContact);
       
   566 //    CActiveScheduler::Start();
       
   567    
       
   568 //    /* check whether add api returns the expected error code */  
       
   569 //  if(count == icallback->iError )
       
   570 //      return KErrNone ;
       
   571       
       
   572 //    return KErrGeneral ;  
       
   573 
       
   574 
       
   575 //	 }
       
   576 	 
       
   577 
       
   578 /* Adding single contact to default database using contactid*/
       
   579   TInt Ctdeleteadd::Add_Test10L( CStifItemParser& aItem )
       
   580     {
       
   581 
       
   582 	_LIT(KCntDbUri, "cntdb://c:contacts.cdb");
       
   583 	_LIT(KCntDbUri1, "cntdb://c:singlecontacts.cdb");										
       
   584     TInt count =KErrGeneral ;
       
   585     _LIT8(KFirstName,"FirstName");
       
   586     _LIT(KName,"Aaaa"); 
       
   587     //instantiate service class object
       
   588     
       
   589     /* create contactitem to add */
       
   590     CSingleContact* singleContact = CSingleContact::NewL();
       
   591     CSingleContactField* singleContactField = CSingleContactField::NewL();
       
   592     
       
   593        
       
   594     singleContactField->SetFieldParamsL(KFirstName,KNullDesC,KName);
       
   595     singleContact->AddFieldToContactL(singleContactField);
       
   596   
       
   597     
       
   598     aItem.GetNextInt(count) ;
       
   599     
       
   600     /* Add the contactitem */
       
   601     icontactservice->AddL(icallback,0,singleContact);
       
   602     CActiveScheduler::Start();
       
   603     
       
   604    	TPtrC searchval(_L("Aaaa"));
       
   605    	
       
   606    	TBuf8<15> fstname(_L8("FirstName"));
       
   607     CSearchFields *srchfield =CSearchFields :: NewL(icontactservice);
       
   608     
       
   609        
       
   610    srchfield->AppendL(fstname);
       
   611    iLog->Log(_L("Calling GetList"));
       
   612    icontactservice->GetListL(icallback,0,EContacts,KNullDesC8,searchval,srchfield,EAsc,KCntDbUri);
       
   613    CActiveScheduler::Start();
       
   614    iLog->Log(_L("End of GetList"));
       
   615    TInt err1,err2;
       
   616    iLog->Log(_L("Calling Add")); 
       
   617    
       
   618    /*
       
   619    //-----------------------------------
       
   620    HBufC8* invalidid = HBufC8::NewL(15);
       
   621    TPtr8 strPtr= invalidid->Des();
       
   622    TBuf8<4> data;
       
   623    data.Append(_L("xyz"));
       
   624    strPtr.Append(data);
       
   625       
       
   626    myContact->SetContactId(invalidid);
       
   627    
       
   628    //------------------------------------
       
   629    */
       
   630    
       
   631    TRAP(err1,icontactservice->AddL(icallback,0,myContact,KNullDesC8,KNullDesC,KCntDbUri1));
       
   632    if(err1!=0 )
       
   633    {
       
   634    	iLog->Log(_L("Error returned while calling add")); 
       
   635    	return KErrNone ;
       
   636    }
       
   637    
       
   638    iLog->Log(_L("Starting Schudular")); 
       
   639    CActiveScheduler::Start();
       
   640    iLog->Log(_L("Error %d\n"),icallback->iError);
       
   641    iLog->Log(_L("Add successful")); 
       
   642    
       
   643    
       
   644   if(count == icallback->iError )
       
   645       return KErrNone ;
       
   646       
       
   647     return KErrGeneral ;  
       
   648 
       
   649 
       
   650 	 }
       
   651 	 
       
   652 	 /* Adding a group and contact together*/
       
   653  TInt Ctdeleteadd::Add_Test11L( CStifItemParser& aItem )
       
   654   {
       
   655 
       
   656       // Print to UI
       
   657     _LIT( Ktsapicontacts, "tsapicontacts" );
       
   658     _LIT( KExample, "In GetList_Test1L" );
       
   659     TestModuleIf().Printf( 0, Ktsapicontacts, KExample );
       
   660     // Print to log file
       
   661     iLog->Log( KExample );
       
   662     
       
   663    
       
   664     TInt count;
       
   665    
       
   666    /* Group1 to add to phonebook */      
       
   667    _LIT(KGroup,"Group10")  ;
       
   668    
       
   669     _LIT8(KFirstName,"FirstName");
       
   670     _LIT(KName,"Aaaa"); 
       
   671     //instantiate service class object
       
   672     
       
   673     /* create contactitem to add */
       
   674     CSingleContact* singleContact = CSingleContact::NewL();
       
   675     CSingleContactField* singleContactField = CSingleContactField::NewL();
       
   676     
       
   677        
       
   678     singleContactField->SetFieldParamsL(KFirstName,KNullDesC,KName);
       
   679     singleContact->AddFieldToContactL(singleContactField);
       
   680    
       
   681    aItem.GetNextInt(count) ;
       
   682    
       
   683    /*Add group1 to phonebook */
       
   684    TInt err1;
       
   685    TRAPD(err,icontactservice->AddL(icallback,0,singleContact,KNullDesC8,KGroup));
       
   686    if(err || err1)
       
   687    return KErrNone;
       
   688     CActiveScheduler::Start();
       
   689      
       
   690   /* check whether add api returns the expected error code */
       
   691  if(count == icallback->iError )
       
   692       return KErrNone ;
       
   693       
       
   694     return KErrGeneral ;
       
   695 
       
   696  }
       
   697 
       
   698 
       
   699 /* Adding single contact to virtual database with the same key and different label*/
       
   700 
       
   701   TInt Ctdeleteadd::Add_Test12L( CStifItemParser& aItem )
       
   702     {
       
   703 
       
   704 
       
   705     TInt count =KErrGeneral ;
       
   706     _LIT(KCntDbUri, "cntdb://c:contacts.cdb");
       
   707     _LIT8(KLandline,"LandPhoneHome");
       
   708     _LIT8(Anni,"Anniversary");
       
   709     _LIT(KLandno1,"08216666");
       
   710     
       
   711     _LIT(KLandno2,"08216667");
       
   712     _LIT(Land1,"no.1");
       
   713     _LIT(Land2,"no.2");
       
   714     //instantiate service class object
       
   715     
       
   716     /* create contactitem to add */ 
       
   717     CSingleContact* singleContact = CSingleContact::NewL();
       
   718     CSingleContactField* singleContactField1 = CSingleContactField::NewL();
       
   719     CSingleContactField* singleContactField2 = CSingleContactField::NewL();
       
   720        
       
   721     singleContactField1->SetFieldParamsL(KLandline,Land1,KLandno1);
       
   722     singleContactField2->SetFieldParamsL(KLandline,Land2,KLandno2);
       
   723     singleContact->AddFieldToContactL(singleContactField1);
       
   724   	singleContact->AddFieldToContactL(singleContactField2);
       
   725     
       
   726     CSingleContactField* singleContactField3 = CSingleContactField::NewL();
       
   727     CSingleContactField* singleContactField4 = CSingleContactField::NewL();
       
   728        
       
   729     singleContactField3->SetFieldParamsL(KLandline,Land1,KLandno1);
       
   730     singleContactField4->SetFieldParamsL(KLandline,Land2,KLandno2);
       
   731     singleContact->AddFieldToContactL(singleContactField1);
       
   732   	singleContact->AddFieldToContactL(singleContactField2);
       
   733     aItem.GetNextInt(count) ;
       
   734     
       
   735     /* Add the contactitem */
       
   736     icontactservice->AddL(icallback,0,singleContact,KNullDesC8,KNullDesC,KCntDbUri);
       
   737     CActiveScheduler::Start();
       
   738    
       
   739     /* check whether add api returns the expected error code */  
       
   740   if(count == icallback->iError )
       
   741       return KErrNone ;
       
   742       
       
   743     return KErrGeneral ;  
       
   744 
       
   745  
       
   746 	 }
       
   747 	 
       
   748 	 
       
   749 	 /* Adding single contact to virtual database with the same key and same label*/
       
   750 
       
   751   TInt Ctdeleteadd::Add_Test13L( CStifItemParser& aItem )
       
   752     {
       
   753 
       
   754 
       
   755     TInt count =KErrGeneral ;
       
   756     _LIT(KCntDbUri, "cntdb://c:contacts.cdb");
       
   757     _LIT8(KLandline,"LandPhoneHome");
       
   758     _LIT8(Anni,"Anniversary");
       
   759     _LIT(KLandno1,"abc");
       
   760     
       
   761     _LIT(KLandno2,"cba");
       
   762     _LIT(Land1,"no.1");
       
   763     _LIT(Land2,"no.2");
       
   764     //instantiate service class object
       
   765     
       
   766     /* create contactitem to add */ 
       
   767     CSingleContact* singleContact = CSingleContact::NewL();
       
   768     CSingleContactField* singleContactField1 = CSingleContactField::NewL();
       
   769     CSingleContactField* singleContactField2 = CSingleContactField::NewL();
       
   770        
       
   771     singleContactField1->SetFieldParamsL(KLandline,Land1,KLandno1);
       
   772     singleContactField2->SetFieldParamsL(KLandline,Land1,KLandno2);
       
   773     singleContact->AddFieldToContactL(singleContactField1);
       
   774   	singleContact->AddFieldToContactL(singleContactField2);
       
   775     
       
   776     CSingleContactField* singleContactField3 = CSingleContactField::NewL();
       
   777     CSingleContactField* singleContactField4 = CSingleContactField::NewL();
       
   778        
       
   779     singleContactField3->SetFieldParamsL(KLandline,Land1,KLandno1);
       
   780     singleContactField4->SetFieldParamsL(KLandline,Land1,KLandno2);
       
   781     singleContact->AddFieldToContactL(singleContactField3);
       
   782   	singleContact->AddFieldToContactL(singleContactField4);
       
   783     aItem.GetNextInt(count) ;
       
   784     
       
   785     /* Add the contactitem */
       
   786     icontactservice->AddL(icallback,0,singleContact,KNullDesC8,KNullDesC,KCntDbUri);
       
   787     CActiveScheduler::Start();
       
   788    
       
   789     /* check whether add api returns the expected error code */  
       
   790   if(count == icallback->iError )
       
   791       return KErrNone ;
       
   792       
       
   793     return KErrGeneral ;  
       
   794 
       
   795  
       
   796 	 }
       
   797 	 
       
   798 
       
   799 
       
   800 //  End of File