contacts_plat/virtual_phonebook_vcard_api/tsrc/T_VPbkVCardApi/src/VPbkVCardStifBlocks.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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 "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:  STIF test module for testing VirtualPhonebook VCard API
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "T_VPbkVCardApi.h"
       
    20 
       
    21 #include <barsread.h>
       
    22 #include <CVPbkVCardEng.h>
       
    23 #include <CVPbkContactManager.h>
       
    24 #include <CVPbkContactStoreUriArray.h>
       
    25 #include <TVPbkContactStoreUriPtr.h>
       
    26 #include <MVPbkContactStoreList.h>
       
    27 #include <MVPbkContactStore.h>
       
    28 #include <TVPbkFieldTypeMapping.h>
       
    29 #include <MVPbkContactOperationBase.h>
       
    30 #include <T_VPbkVCardApi.rsg>
       
    31 #include <MVPbkStoreContact.h>
       
    32 
       
    33 _LIT( KCntDbUri, "cntdb://c:testcontacts.cdb" );
       
    34 _LIT( KResourceFileName, "\\bctestlog\\testvcard.vcf" );
       
    35 _LIT( KCompactBCardFileName, "\\bctestlog\\testcbcard.ccf" );    
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CVPbkVCardApi::Delete
       
    39 // Delete here all resources allocated and opened from test methods. 
       
    40 // Called from destructor. 
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 void CT_VPbkVCardApi::Delete() 
       
    44     {
       
    45 //    iImportedContacts.ResetAndDestroy();
       
    46     delete iEngine;
       
    47     iEngine = NULL;             
       
    48     if ( iContactStore )
       
    49         {
       
    50         iContactStore->Close( *this );        
       
    51         }
       
    52     iContactStore = NULL;
       
    53     delete iContactManager;
       
    54     iContactManager = NULL;
       
    55     iFs.Close();
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CT_VPbkVCardApi::RunMethodL
       
    60 // Run specified method. Contains also table of test methods and their names.
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 TInt CT_VPbkVCardApi::RunMethodL( CStifItemParser& aItem ) 
       
    64     {
       
    65     static TStifFunctionInfo const KFunctions[] =
       
    66         {  
       
    67         // Copy this line for every implemented function.
       
    68         // First string is the function name used in TestScripter script file.
       
    69         // Second is the actual implementation member function. 
       
    70         ENTRY( "CreateVCardEng", 
       
    71         		CT_VPbkVCardApi::CreateVCardEng ),
       
    72         ENTRY( "DeleteVCardEng", 
       
    73         		CT_VPbkVCardApi::DeleteVCardEng ),
       
    74         ENTRY( "ImportVCardToStore", 
       
    75         		CT_VPbkVCardApi::ImportVCardToStore ),
       
    76         ENTRY( "ImportVCardToContacts", 
       
    77         		CT_VPbkVCardApi::ImportVCardToContacts ),
       
    78         ENTRY( "ImportBusinessCardToStore", 
       
    79         		CT_VPbkVCardApi::ImportBusinessCardToStore ),
       
    80         ENTRY( "ImportBusinessCardToContacts", 
       
    81         		CT_VPbkVCardApi::ImportBusinessCardToContacts ),
       
    82         ENTRY( "SupportsFieldType", 
       
    83         		CT_VPbkVCardApi::SupportsFieldType )
       
    84         };
       
    85 
       
    86     const TInt count = sizeof( KFunctions ) / 
       
    87                         sizeof( TStifFunctionInfo );
       
    88 
       
    89     return RunInternalL( KFunctions, count, aItem );    
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CT_VPbkVCardApi::CreateVCardEng
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 TInt CT_VPbkVCardApi::CreateVCardEng()
       
    97 	{
       
    98 	TRAPD( err, CreateVCardEngL() );
       
    99 	return err;
       
   100 	}
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CT_VPbkVCardApi::CreateVCardEngL
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 void CT_VPbkVCardApi::CreateVCardEngL()
       
   107 	{
       
   108     CVPbkContactStoreUriArray* uriList = CVPbkContactStoreUriArray::NewLC();
       
   109     uriList->AppendL( TVPbkContactStoreUriPtr( KCntDbUri ) );
       
   110     
       
   111     iContactManager = CVPbkContactManager::NewL( *uriList, &iFs );    
       
   112     CleanupStack::PopAndDestroy( uriList );
       
   113     
       
   114     MVPbkContactStoreList& stores = iContactManager->ContactStoresL();
       
   115     if ( stores.Count() > 0 )
       
   116         {
       
   117         iContactStore = &( stores.At( 0 ) );         
       
   118         }   
       
   119     
       
   120     iContactStore->ReplaceL( *this );
       
   121 
       
   122     iEngine = CVPbkVCardEng::NewL( *iContactManager );
       
   123 	}
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CT_VPbkVCardApi::DeleteVCardEng
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 TInt CT_VPbkVCardApi::DeleteVCardEng()
       
   130 	{
       
   131 	if(ioperation != NULL)
       
   132 	    {
       
   133 	    delete ioperation;
       
   134 	    ioperation = NULL;
       
   135 	    }
       
   136     delete iEngine;
       
   137     iEngine = NULL;             
       
   138     if ( iContactStore )
       
   139         {
       
   140         iContactStore->Close( *this );        
       
   141         }
       
   142     iContactStore = NULL;
       
   143     delete iContactManager;
       
   144     iContactManager = NULL;
       
   145     
       
   146     return 0;
       
   147 	}
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CT_VPbkVCardApi::StoreReady
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 void CT_VPbkVCardApi::StoreReady( MVPbkContactStore& /*aContactStore*/ )
       
   154     {    
       
   155     // Signal STIF test framework to continue processing the script file
       
   156     CScriptBase::Signal( 0 );
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CT_VPbkVCardApi::StoreUnavailable
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 void CT_VPbkVCardApi::StoreUnavailable( 
       
   164         MVPbkContactStore& /*aContactStore*/,
       
   165         TInt aError )
       
   166     {    
       
   167     // Signal STIF test framework to continue processing the script file
       
   168     CScriptBase::Signal( aError );
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CT_VPbkVCardApi::HandleStoreEventL
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 void CT_VPbkVCardApi::HandleStoreEventL(
       
   176         MVPbkContactStore& /*aContactStore*/, 
       
   177         TVPbkContactStoreEvent /*aStoreEvent*/ )
       
   178     {
       
   179     }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CT_VPbkVCardApi::OpenComplete
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 void CT_VPbkVCardApi::OpenComplete()
       
   186     {    
       
   187     // Signal STIF test framework to continue processing the script file
       
   188     CScriptBase::Signal( 0 );
       
   189     }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // CT_VPbkVCardApi::ContactOperationCompleted
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 void CT_VPbkVCardApi::ContactOperationCompleted( 
       
   196         TContactOpResult /*aResult*/ )
       
   197     {    
       
   198     // Signal STIF test framework to continue processing the script file
       
   199     CScriptBase::Signal( 0 );
       
   200     }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // CT_VPbkVCardApi::ContactOperationFailed
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 void CT_VPbkVCardApi::ContactOperationFailed(
       
   207         TContactOp /*aOpCode*/, TInt aErrorCode, 
       
   208         TBool /*aErrorNotified*/ )
       
   209     {    
       
   210     // Signal STIF test framework to continue processing the script file
       
   211     CScriptBase::Signal( aErrorCode );
       
   212     }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // CT_VPbkVCardApi::VPbkSingleContactOperationComplete
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 void CT_VPbkVCardApi::VPbkSingleContactOperationComplete(
       
   219         MVPbkContactOperationBase& /*aOperation*/,
       
   220         MVPbkStoreContact* )
       
   221 	{
       
   222     delete ioperation;
       
   223     ioperation = NULL;
       
   224     // Signal STIF test framework to continue processing the script file
       
   225     CScriptBase::Signal( 0 );
       
   226     }
       
   227 
       
   228 // -----------------------------------------------------------------------------
       
   229 // CT_VPbkVCardApi::VPbkSingleContactOperationFailed
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 void CT_VPbkVCardApi::VPbkSingleContactOperationFailed(
       
   233         MVPbkContactOperationBase& /*aOperation*/, TInt aError )
       
   234     {    
       
   235     delete ioperation;
       
   236     ioperation = NULL;
       
   237     // Signal STIF test framework to continue processing the script file
       
   238     CScriptBase::Signal( aError );
       
   239     }
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CT_VPbkVCardApi::FieldAddedToContact
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 void CT_VPbkVCardApi::FieldAddedToContact(
       
   246         MVPbkContactOperationBase& /*aOperation*/ )
       
   247     {    
       
   248     }
       
   249         
       
   250 // -----------------------------------------------------------------------------
       
   251 // CT_VPbkVCardApi::FieldAddingFailed
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 void CT_VPbkVCardApi::FieldAddingFailed(
       
   255         MVPbkContactOperationBase& /*aOperation*/, TInt /*aError*/ )
       
   256     {    
       
   257     }
       
   258         
       
   259 // -----------------------------------------------------------------------------
       
   260 // CT_VPbkVCardApi::ContactsSaved
       
   261 // -----------------------------------------------------------------------------
       
   262 //
       
   263 void CT_VPbkVCardApi::ContactsSaved( MVPbkContactOperationBase& /*aOp*/,
       
   264         MVPbkContactLinkArray* /*aResults*/ )
       
   265     {       
       
   266     // Signal STIF test framework to continue processing the script file
       
   267     CScriptBase::Signal( 0 );
       
   268     }
       
   269         
       
   270 // -----------------------------------------------------------------------------
       
   271 // CT_VPbkVCardApi::ContactsSavingFailed
       
   272 // -----------------------------------------------------------------------------
       
   273 //
       
   274 void CT_VPbkVCardApi::ContactsSavingFailed(
       
   275         MVPbkContactOperationBase& /*aOperation*/, TInt aError )
       
   276     {
       
   277     // Signal STIF test framework to continue processing the script file
       
   278     CScriptBase::Signal( aError );
       
   279     }
       
   280 
       
   281 // -----------------------------------------------------------------------------
       
   282 // CT_VPbkVCardApi::ImportVCardToStore
       
   283 // -----------------------------------------------------------------------------
       
   284 //
       
   285 TInt CT_VPbkVCardApi::ImportVCardToStore()
       
   286 	{
       
   287 	TRAPD( err, ImportVCardToStoreL() );
       
   288 	return err;
       
   289 	}
       
   290 
       
   291 // -----------------------------------------------------------------------------
       
   292 // CT_VPbkVCardApi::ImportVCardToStoreL
       
   293 // -----------------------------------------------------------------------------
       
   294 //
       
   295 void CT_VPbkVCardApi::ImportVCardToStoreL()
       
   296     {   
       
   297     User::LeaveIfError( iSource.Open( 
       
   298     		iFs, KResourceFileName, EFileRead ) );    
       
   299     ioperation = 
       
   300 	    iEngine->ImportVCardL( *iContactStore, iSource, *this );
       
   301     }
       
   302 
       
   303 // -----------------------------------------------------------------------------
       
   304 // CT_VPbkVCardApi::ImportVCardToContacts
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 TInt CT_VPbkVCardApi::ImportVCardToContacts()
       
   308 	{
       
   309 	TRAPD( err, ImportVCardToContactsL() );
       
   310 	return err;
       
   311 	}
       
   312 
       
   313 // -----------------------------------------------------------------------------
       
   314 // CT_VPbkVCardApi::ImportVCardToContactsL
       
   315 // -----------------------------------------------------------------------------
       
   316 //
       
   317 void CT_VPbkVCardApi::ImportVCardToContactsL()
       
   318 	{
       
   319     User::LeaveIfError( iSource.Open( 
       
   320     		iFs, KResourceFileName, EFileRead ) );	
       
   321     ioperation = 
       
   322 	    iEngine->ImportVCardL( iImportedContacts, *iContactStore, 
       
   323 	        iSource, *this );
       
   324 	}
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 // CT_VPbkVCardApi::ImportBusinessCardToStore
       
   328 // -----------------------------------------------------------------------------
       
   329 //
       
   330 TInt CT_VPbkVCardApi::ImportBusinessCardToStore()
       
   331 	{
       
   332 	TRAPD( err, ImportBusinessCardToStoreL() )
       
   333 	return err;
       
   334 	}
       
   335 
       
   336 // -----------------------------------------------------------------------------
       
   337 // CT_VPbkVCardApi::ImportBusinessCardToStoreL
       
   338 // -----------------------------------------------------------------------------
       
   339 //
       
   340 void CT_VPbkVCardApi::ImportBusinessCardToStoreL()
       
   341 	{
       
   342     User::LeaveIfError( iSource.Open( 
       
   343     		iFs, KCompactBCardFileName, EFileRead ) );
       
   344     ioperation = 
       
   345 	    iEngine->ImportCompactBusinessCardL( *iContactStore, iSource, *this );
       
   346 	}
       
   347 
       
   348 // -----------------------------------------------------------------------------
       
   349 // CT_VPbkVCardApi::ImportBusinessCardToContacts
       
   350 // -----------------------------------------------------------------------------
       
   351 //
       
   352 TInt CT_VPbkVCardApi::ImportBusinessCardToContacts()
       
   353 	{
       
   354 	TRAPD( err, ImportBusinessCardToContactsL() );
       
   355 	return err;
       
   356 	}
       
   357 
       
   358 // -----------------------------------------------------------------------------
       
   359 // CT_VPbkVCardApi::ImportBusinessCardToContactsL
       
   360 // -----------------------------------------------------------------------------
       
   361 //
       
   362 void CT_VPbkVCardApi::ImportBusinessCardToContactsL()
       
   363 	{
       
   364     User::LeaveIfError( iSource.Open( 
       
   365         iFs, KCompactBCardFileName, EFileRead ) );	
       
   366     ioperation = 
       
   367 	    iEngine->ImportCompactBusinessCardL( iImportedContacts, 
       
   368 	        *iContactStore, iSource, *this );
       
   369 	}
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 // CT_VPbkVCardApi::SupportsFieldType
       
   373 // -----------------------------------------------------------------------------
       
   374 //
       
   375 TInt CT_VPbkVCardApi::SupportsFieldType()
       
   376 	{
       
   377 	TResourceReader reader;
       
   378     iEikEnv->CreateResourceReaderLC( reader, 
       
   379         R_ORGNAME_TYPE ); 
       
   380 
       
   381     TVPbkFieldTypeMapping typeMapping( reader );
       
   382     const MVPbkFieldTypeList& fieldTypeList = iContactManager->FieldTypes();
       
   383     const MVPbkFieldType* fieldType = typeMapping.FindMatch( fieldTypeList );
       
   384     iEngine->SupportsFieldType( *fieldType );
       
   385 	
       
   386 	CleanupStack::PopAndDestroy();
       
   387 	
       
   388 	return 0;
       
   389 	}
       
   390 
       
   391 // End of File