phonebookengines/contactsmodel/tsrc/Integration/TestImpExvCard/src/TestContactOperations.cpp
changeset 0 e686773b3f54
child 24 0ba2181d7c28
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "TestContactOperations.h"
       
    17 
       
    18 CTestContactOperations::~CTestContactOperations()
       
    19 /**
       
    20  * Destructor
       
    21  */
       
    22 	{
       
    23 	}
       
    24 
       
    25 CTestContactOperations::CTestContactOperations()
       
    26 /**
       
    27  * Constructor
       
    28  */
       
    29 	{
       
    30 	// **MUST** call SetTestStepName in the constructor as the controlling
       
    31 	// framework uses the test step name immediately following construction to set
       
    32 	// up the step's unique logging ID.
       
    33 	SetTestStepName(KTestContactOperations);
       
    34 	}
       
    35 
       
    36 TVerdict CTestContactOperations::doTestStepPreambleL()
       
    37 /**
       
    38  * @return - TVerdict code
       
    39  * Override of base class virtual
       
    40  */
       
    41 	{
       
    42 	INFO_PRINTF1(_L("Start deletion of Contact items"));
       
    43 
       
    44 	iScheduler = new (ELeave) CActiveScheduler;
       
    45 	CActiveScheduler::Install(iScheduler);
       
    46 
       
    47 	SetTestStepResult(EPass);
       
    48 	return TestStepResult();
       
    49 	}
       
    50 
       
    51 TVerdict CTestContactOperations::doTestStepL()
       
    52 /**
       
    53  * @return - TVerdict code
       
    54  * Override of base class pure virtual
       
    55  */
       
    56 	{
       
    57 	DeleteContactsL();
       
    58 	return TestStepResult();
       
    59 	}
       
    60 	
       
    61 /**
       
    62  * @return - TVerdict code
       
    63  * Override of base class virtual
       
    64  */
       
    65 TVerdict CTestContactOperations::doTestStepPostambleL()
       
    66  	{
       
    67 	CActiveScheduler::Install(NULL);
       
    68 	delete iScheduler;
       
    69 	
       
    70 	INFO_PRINTF1(_L("Completed deletion of Contact items"));
       
    71 	return TestStepResult();
       
    72 	}
       
    73 
       
    74 void CTestContactOperations::DeleteContactsL()
       
    75 	{
       
    76 	// existing database
       
    77    	TPtrC databaseFile(_L("C:contactDB.cdb"));
       
    78    	
       
    79    	TContactItemId itemId = KErrNotFound;
       
    80 	CContactDatabase* dBase = NULL;
       
    81 	CContactIdArray* idArray = NULL;
       
    82 	
       
    83 	dBase = CContactDatabase::OpenL(databaseFile);
       
    84 	CleanupStack::PushL(dBase);
       
    85 	
       
    86 	// Set the filter to select all the contact items in the database
       
    87 	CCntFilter* exportFilter = CCntFilter::NewL();
       
    88 	CleanupStack::PushL(exportFilter);
       
    89 	exportFilter->SetContactFilterTypeCard(ETrue);
       
    90 	dBase->FilterDatabaseL(*exportFilter);
       
    91 	idArray = exportFilter->iIds;	
       
    92 	CleanupStack::PushL(idArray);
       
    93 	
       
    94 	TInt numberOfContacts;
       
    95    	GetIntFromConfig(ConfigSection(), KNumberOfCont, numberOfContacts);
       
    96 	
       
    97 	INFO_PRINTF1(_L("Deleting Contacts....."));
       
    98 
       
    99 	// Delete the contacts one at a time
       
   100 	for(TInt i=(idArray->Count()-1);i>=0;i--)
       
   101 		{
       
   102 		dBase->DeleteContactL((*idArray)[i]);
       
   103 		}
       
   104 			
       
   105 	_LIT(KCount, "The number of contacts in the database is %d \n");
       
   106 	INFO_PRINTF2(KCount, dBase->CountL());
       
   107 	
       
   108 	// Close the contacts
       
   109     dBase->CloseContactL(itemId);
       
   110 	
       
   111 	// Cleanup
       
   112 	CleanupStack::Pop(idArray);
       
   113     CleanupStack::PopAndDestroy(exportFilter);
       
   114     CleanupStack::PopAndDestroy(dBase);
       
   115     }
       
   116