示例#1
0
/**
add agent field to contact b. set value of agent to contact a.
export contacts a & b. check access count for a & b(should be 0), 
check value of agent(should equal b) open contact b, delete all fields.
commit. import contacts a and b. check that agent field is not imported.
*/
void CAccessCountTests::AgentExportImportAccessTestL()
	{
	const TContactItemId KFirstContactId = iIterate->NextL();//contact a
	const TContactItemId KSecondContactId = iIterate->NextL();//contact b
	
	//open contact a and populate all fields
	OpenL(KFirstContactId, *iViewAll);
	SetContactFieldsL(*iContactItem);
	CommitL();
	
	//open contact b
	OpenL(KSecondContactId,*iViewAll);
	//populate all fields
	SetContactFieldsL(*iContactItem);
	//add contact a id as an agent field value
	AddAgentFieldL(KFirstContactId);
	CommitL();
	
	CContactIdArray *ArrayOfExportedContactIds = CContactIdArray::NewLC();
	//set contact a and b to be export
	ArrayOfExportedContactIds->AddL(KFirstContactId);
	ArrayOfExportedContactIds->AddL(KSecondContactId);
	
	//export contact a & b
	ExportVcardL(*ArrayOfExportedContactIds);
	
	const TInt KFirstContactAccessCountAfterExport = GetAccessCountL(KFirstContactId);
	const TInt KSecondContactAccessCountAfterExport = GetAccessCountL(KSecondContactId);
	const TInt KSecondContactAgentFieldAfterExport = GetAgentFieldL(KSecondContactId);
	CleanupStack::PopAndDestroy(ArrayOfExportedContactIds);
	
	//delete all fields from contact b
	OpenL(KSecondContactId,*iViewAll);
	iFields->Reset();
	CommitL();
	
	//import exported contacts
	ImportVcardL();
	
	const TInt KFirstContactAccessCountAfterImport = GetAccessCountL(KFirstContactId);
	const TInt KSecondContactAccessCountAfterImport = GetAccessCountL(KSecondContactId);
	const TContactItemId KSecondContactAgentFieldAfterImport = GetAgentFieldL(KSecondContactId);
	
	//importing & exporting contacts should not affect the access count
	INTCOMPARE( KFirstContactAccessCountAfterExport , ==,  0, 0, 0 ); 
	INTCOMPARE( KSecondContactAccessCountAfterExport , ==,  0, 0, 0 ); 
	INTCOMPARE( KFirstContactAccessCountAfterExport , ==,  KFirstContactAccessCountAfterImport, 0, 0 );
	INTCOMPARE( KSecondContactAccessCountAfterExport , ==,  KSecondContactAccessCountAfterImport, 0, 0 );
	
	//agent field values should not be exported/imported
	INTCOMPARE( KFirstContactId , ==,  KSecondContactAgentFieldAfterImport, 0, 0 ); 
	//exporting contacts should not affect the internal state of the contacts agent field
	INTCOMPARE( KSecondContactAgentFieldAfterExport , ==,  KFirstContactId, 0, 0 );
	
	iParent->Fs().Delete(KVcardFile);//cleanup of exported vcard file
	}
// Creates a few test contacts.
void CTestResources::CreateTestContactsL()
    {
    TContactItemId id;
    id = CreateTestContactL(*iDb, _L("Hakkinen"), _L("Mika"), _L("McLaren"));
    iContacts->AddL(id);
    id = CreateTestContactL(*iDb, _L("Coulthard"), _L("David"), _L("McLaren"));
    iContacts->AddL(id);
    id = CreateTestContactL(*iDb, _L("Schumacher"), _L("Michael"), _L("Ferrari"));
    iContacts->AddL(id);
    id = CreateTestContactL(*iDb, _L("Raikkonen"), _L("Kimi"), _L("Sauber"));
    iContacts->AddL(id);
    }
CContactIdArray* CPackagerCntFactory::doCreateDefaultCContactIdArrayL() const
/** Implementation method for constructing a new default CContactIdArray object. 

@return a Pointer to the CContactIdArray object. */
	{
	CContactIdArray* theArray = CContactIdArray::NewL();
	CleanupStack::PushL(theArray);
	theArray->AddL(KId1);
	theArray->AddL(KId2);
	theArray->AddL(KId3);
	theArray->AddL(KId4);
	theArray->AddL(KId5);
	CleanupStack::Pop(theArray);
	return theArray;
	}	
void CFilteredViewTester::AddContactsL(TInt aCount)
	{
	for (TInt i = 0; i < aCount; ++i)
		{		
		iIdArray->AddL(DoAddContactL(i));
		}    
	}
/**
Searches the contacts database to find any contact items with an exact match on the address supplied.

@param aCommAddr A descriptor containing the address to be found in the database.
@param aAddrType The type of addresses that is being sought.
@return An array of contact IDs which match the supplied address.
*/
CContactIdArray* CPplCommAddrTable::MatchNonPhoneAddrL(const TDesC& aCommAddr, TCommAddrType aAddrType)
	{

	// build statement
	RSqlStatement stmnt;
	CleanupClosePushL(stmnt);
	stmnt.PrepareL(iDatabase, iMatchSelectStmnt->SqlStringL() );

	const TInt KValueParamIndex(KFirstParam);					// first parameter in query...
	const TInt KTypeParamIndex(KValueParamIndex + 1);	// ...and the second.
	User::LeaveIfError(stmnt.BindText(KValueParamIndex, aCommAddr) );
	User::LeaveIfError(stmnt.BindInt(KTypeParamIndex, aAddrType) );

	// fetch the list of any matching contact ids
	CContactIdArray* idArray = CContactIdArray::NewLC();
	TInt err(KErrNone);
	const TInt KContactIdIdx(iMatchSelectStmnt->ParameterIndex(KCommAddrContactId() ) );
	while ((err = stmnt.Next() ) == KSqlAtRow)
		{
		idArray->AddL(stmnt.ColumnInt(KContactIdIdx) );
		}

	// leave if we didn't complete going through the results properly
	if(err != KSqlAtEnd)
		{
		User::Leave(err);
		}

	CleanupStack::Pop(idArray);
	CleanupStack::PopAndDestroy(&stmnt);

	return idArray;
	}
/**
exports all contacts items in db to vcard file, if aDelete, cleans database afterwards
*/
void CPerformanceFunctionalityBase::ExportVcardL(const TBool aDelete, const TDesC &aVCard)
	{
	iIterate->Reset();
	CContactIdArray *ids = CContactIdArray::NewLC();
	TInt i = 0;
	for(; i < iContacts; ++i)
		{
		ids->AddL( iIterate->NextL() );
		}

	RFileWriteStream rfws;
	CleanupClosePushL(rfws);
	User::LeaveIfError( rfws.Replace( iParent->Fs(),aVCard , EFileWrite | EFileShareAny ) );

	iContactsDatabase->ExportSelectedContactsL(	TUid::Uid(KUidVCardConvDefaultImpl), *ids, rfws,
										CContactDatabase::EIncludeX | CContactDatabase::ETTFormat );

	CleanupStack::PopAndDestroy(&rfws);
	if( aDelete )
		{
		CLEAR( iContactsDatabase );
		iContactsDatabase = CContactDatabase::ReplaceL();
		}
	CleanupStack::PopAndDestroy(ids);
	}
示例#7
0
LOCAL_C void DoTestsL()
	{
    CleanupClosePushL(test);
	test.Start(_L("@SYMTESTCaseID:PIM-T-TEMPLATECACHE-0001 ----------- State Tests ----------"));


   	__UHEAP_MARK;

	RCntModel cntClient; 
	cntClient.ConnectL();
	cntClient.OpenDatabase();
	
	CCntTemplateCache* templateCache = CCntTemplateCache::NewL(cntClient);
	CleanupStack::PushL(templateCache);
	
	CContactIdArray* cardTemplateIds = CContactIdArray::NewLC();
	// Add 15 templates
	CContactTemplate* contactTemplate = NULL;
	TInt ii = 0;
	for (; ii < 15; ++ii)
		{
		contactTemplate = CContactTemplate::NewLC();
		cardTemplateIds->AddL(cntClient.CreateContactL(*contactTemplate));
		CleanupStack::PopAndDestroy(); // contactTemplate
		}
		
	// Create a contactItem
	CCntItemBuilder* cntItemBldr = CCntItemBuilder::NewLC(static_cast<CContactTemplate&>(templateCache->SystemTemplateL()));
	CContactItem* cntItem 		 = cntItemBldr->GetCntItemLC();
	/*TContactItemId cntId  		 = */cntClient.CreateContactL(*cntItem);

	ii = 0;
	for (; ii < 15; ++ii)
		{
		cntItem->SetTemplateRefId((*cardTemplateIds)[ii]);
		templateCache->MergeWithTemplateL(*cntItem);
		// Merge a second time... the template should now be cached
		templateCache->MergeWithTemplateL(*cntItem);
		}
	
	
	CleanupStack::PopAndDestroy(cntItem);
	CleanupStack::PopAndDestroy(cntItemBldr);
	CleanupStack::PopAndDestroy(cardTemplateIds);
	CleanupStack::PopAndDestroy(templateCache);
	cntClient.Close();
	
	__UHEAP_MARKEND;

  	test.Next(_L("---- All Tests Completed OK ----"));


	test.End();
    CleanupStack::PopAndDestroy(1); // test.Close
	}
/**
GetListForItemL has a dual nature. If aIsGroup is ETrue, a list of contact items belonging to
specified group is returned. Otherwise a list of group ids to which contact id belongs is returned.

@param aItemId contact item id
@param aIsGroup ETrue if the method will fill a group.
*/
CContactIdArray* CPplGroupsTable::GetListForItemL(TContactItemId aItemId, TBool aIsGroup)
	{
	/*
	// Check if group membership information was not requested or if the item
	// is not derived from CContactItemPlusGroup.
	if (!(aType == KUidContactGroup	  || aType == KUidContactCard ||
		  aType == KUidContactOwnCard || aType == KUidContactICCEntry) )
		{
		return NULL; 
		}
	*/	

	// build the RSqlStatement
	RSqlStatement stmnt;
	CleanupClosePushL(stmnt);
	TInt idIndex;

	// build the CCntSqlStatement statement
	const TInt KWhereParamIndex(KFirstIndex); // only one parameter in the query
	if (aIsGroup)
		{
		// group -> select members
		stmnt.PrepareL(iDatabase, iSelectMembersStmnt->SqlStringL() );
		User::LeaveIfError(stmnt.BindInt(KWhereParamIndex, aItemId ) );
		idIndex = stmnt.ColumnIndex(KGroupContactGroupMemberId() );
		}
	else
		{
		// member -> select groups
		stmnt.PrepareL(iDatabase, iSelectGroupsStmnt->SqlStringL() );
		User::LeaveIfError(stmnt.BindInt(KWhereParamIndex, aItemId ) );
		idIndex = stmnt.ColumnIndex(KGroupContactGroupId() );
		}
	User::LeaveIfError(idIndex);
	// fetch the list of any matching ids
	CContactIdArray* items = CContactIdArray::NewLC();
	TInt err(KErrNone);
	while ((err = stmnt.Next() ) == KSqlAtRow)
		{
		items->AddL(stmnt.ColumnInt(idIndex) );
		}

	// leave if we didn't complete going through the results properly
	if(err != KSqlAtEnd)
		{
		User::Leave(err);
		}
	
	CleanupStack::Pop(items);
	CleanupStack::PopAndDestroy(&stmnt);
	return items;
	}
/*
	Creates a random array of numbers corresponding to the Contacts Id in the 
	Contacts model.  No Contact Id is repeated  
*/
void CDeleteMany::CreateRandomIdArrayL(CContactIdArray& aUids, TInt aNumIds, TInt aNumEntriesInDb)
	{
	TTime now;
	now.UniversalTime();
	TInt64 KRandomSeed = now.DateTime().MicroSecond();

	TInt uid(0);
	for(TInt i = 0; i < aNumIds; ++i)
		{
		uid = (Math::Rand(KRandomSeed) % aNumEntriesInDb) + 1;
		while(aUids.Find(uid) != KErrNotFound)
			{
			uid = (Math::Rand(KRandomSeed) % aNumEntriesInDb) + 1;
			}
		aUids.AddL(uid);		
		}
	}
示例#10
0
/**
Convert between view indexes and contact ids.
This method makes the request to the server.
@capability ReadUserData
 */
void RContactRemoteView::GetContactIdsL(const CArrayFix<TInt>& aIndexes, CContactIdArray& aContactIds)
    {
    CBufBase* buffer = CBufFlat::NewL(32);
    CleanupStack::PushL(buffer);
    RBufWriteStream writeStream(*buffer);
    CleanupClosePushL(writeStream);

    const TInt count = aIndexes.Count();
    writeStream.WriteUint32L(count);
    for (TInt i=0; i<count; ++i)
        {
        writeStream.WriteUint32L(aIndexes[i]);
        }
    writeStream.CommitL();
    CleanupStack::PopAndDestroy(&writeStream); //writeStream.Close()


    TPtr8 indexes(buffer->Ptr(0));
    const TInt bufferSize = buffer->Size();
    TPckg<TInt> size(bufferSize);
    
    HBufC8* buf=HBufC8::NewLC(bufferSize);
    TPtr8 ids(buf->Des());
    
    TIpcArgs args(&size, &indexes, &ids);
    User::LeaveIfError(SendReceive(ECntGetContactIds,args));


    RDesReadStream readStream(ids);
    CleanupClosePushL(readStream);
    CContactIdArray* array = CContactIdArray::NewLC();
    readStream >> *array;

    const TInt arrayCount = array->Count();
    for(TInt loop=0;loop<arrayCount;loop++)
        aContactIds.AddL((*array)[loop]);

    CleanupStack::PopAndDestroy(4,buffer); //array, &readStream, buf, buffer
    }
void CTestResources::CreateTestContactsL()
    {
    const TInt KContacts = 4;
    TInt i;
    iContacts = CContactIdArray::NewL();

    // Create contacts
    for (i=1; i <= KContacts; ++i)
        {
        CContactCard* card = CContactCard::NewLC();
        CContactItemField* field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName);
        TBuf<30> name;
        name.Format(_L("Contact%02d"), i);
        field->TextStorage()->SetTextL(name);
        card->AddFieldL(*field);
        CleanupStack::Pop(field);
        const TContactItemId contactId = iDb->AddNewContactL(*card);
        iContacts->AddL(contactId);
        CleanupStack::PopAndDestroy(card);
        // Eat away contact db events
        TContactDbObserverEvent event;
        test(iDbEventQueue->ListenForEvent(10,event));
        }

    // Create a group
    CContactItem* group = iDb->CreateContactGroupLC(_L("TestGroup"));
    iGroupId = group->Id();
    CleanupStack::PopAndDestroy(group);

    // Connect half of the contacts to the group
    for (i=0; i < iContacts->Count(); ++i)
        {
        if (i%2 == 0)
            {
            iDb->AddContactToGroupL((*iContacts)[i], iGroupId);            
            }
        }
    }
/**
Returns an array of contact item IDs for all the contact items which may contain
the specified telephone number in a telephone, fax or SMS type field.

This is improved version of MatchPhoneNumberL method.
The number is compared starting from the right side of the number and 
the method returns an array of candidate matches.  
Punctuation (e.g. spaces) and other alphabetic characters are ignored
when comparing. Leading zeros are removed. Digits are compared up to 
the lenght of shorter number.

@param aNumber Phone number string.
@return Array of contact IDs which are candidate matches.
*/
CContactIdArray* CPplCommAddrTable::BestMatchingPhoneNumberL(const TDesC& aNumber)
    {
    const TInt KUpperMaxLength = KMaxPhoneMatchLength - KLowerSevenDigits;

    CContactIdArray* phoneMatchArray = CContactIdArray::NewLC();

    TMatch phoneDigits = CreatePaddedPhoneDigitsL(aNumber, KLowerSevenDigits, KUpperMaxLength);

    if (phoneDigits.iNumLowerDigits + phoneDigits.iNumUpperDigits > 0)
        {
        // build statement
        RSqlStatement stmnt;
        CleanupClosePushL(stmnt);
        stmnt.PrepareL(iDatabase, iMatchSelectStmnt->SqlStringL());

        const TInt KValueParamIndex(KFirstParam); // first parameter in query...
        const TInt KTypeParamIndex(KValueParamIndex + 1); // ...and the second.

        User::LeaveIfError(stmnt.BindInt(KValueParamIndex,
                phoneDigits.iLowerSevenDigits));
        User::LeaveIfError(stmnt.BindInt(KTypeParamIndex, EPhoneNumber));

        // fetch the list of any matching contact ids
        TInt err(KErrNone);
        const TInt KContactIdIdx(iMatchSelectStmnt->ParameterIndex( KCommAddrContactId()));
        const TInt KExtraValueIdx(iMatchSelectStmnt->ParameterIndex(KCommAddrExtraValue()));
        while ((err = stmnt.Next()) == KSqlAtRow)
            {
            // Check the upper digits...
            TInt32 number = phoneDigits.iUpperDigits;
            TPtrC extValString = stmnt.ColumnTextL(KExtraValueIdx);
            TInt32 storedUpperDigits;
            User::LeaveIfError(TLex(extValString).Val(storedUpperDigits));
            TInt32 stored = storedUpperDigits;

            TBool nonZeroInStoredFound = EFalse;
            TBool nonZeroInNumberFound = EFalse;
            while ((number != 0) && (stored != 0))
                {
                nonZeroInNumberFound |= (number % 10 != 0);
                nonZeroInStoredFound |= (stored % 10 != 0);
                if (nonZeroInStoredFound && nonZeroInNumberFound)
                    {
                    break;
                    }
                number /= 10;
                stored /= 10;
                }

            if ( (phoneDigits.iUpperDigits == 0) || (storedUpperDigits == 0) ||
                 (number == stored) )
                {
                phoneMatchArray->AddL(stmnt.ColumnInt(KContactIdIdx));
                }
            }

        // leave if we didn't complete going through the results properly
        if (err != KSqlAtEnd)
            {
            User::Leave(err);
            }
        CleanupStack::PopAndDestroy(&stmnt);
        }

    CleanupStack::Pop(phoneMatchArray);
    return phoneMatchArray;
    }
/**
Returns an array of contact item IDs for all the contact items which may contain
the specified telephone number in a telephone, fax or SMS type field.

The comparison method used is not exact.  The number is compared starting from
the right side of the number and the method returns an array of candidate
matches.  Punctuation (e.g. spaces) and other alphabetic characters are ignored
when comparing.

Additionally, if the Contacts Model Phone Parser (CNTPHONE.DLL) is available,
then any DTMF digits are also excluded from the comparision.

Note that due to the way numbers are stored in the database, it is recommended
that at least 7 match digits are specified even when matching a number
containing fewer digits.  Failure to follow this guideline may (depending on the
database contents) mean that the function will not return the expected Contact
IDs.

@param aNumber Phone number string.
@param aMatchLengthFromRight Number of digits from the right of the phone number
to use.  Up to 15 digits can be specified, and it is recommended that at least 7
match digits are specified.
@param aDatabase The database.

@return Array of contact IDs which are candidate matches.
*/
CContactIdArray* CPplCommAddrTable::MatchPhoneNumberL(const TDesC& aNumber, const TInt aMatchLengthFromRight)
	{
	CContactIdArray* phoneMatchArray = CContactIdArray::NewLC();

	TInt numLowerDigits = aMatchLengthFromRight;
	TInt numUpperDigits = 0;

	if(numLowerDigits > KLowerSevenDigits)
		{
		// New style matching.
		numLowerDigits = KLowerSevenDigits;
		numUpperDigits = aMatchLengthFromRight - KLowerSevenDigits;
		}

	TMatch phoneDigits = CreatePaddedPhoneDigitsL(aNumber, numLowerDigits, numUpperDigits);

	if (phoneDigits.iNumLowerDigits + phoneDigits.iNumUpperDigits > 0)
		{
		// build statement
		RSqlStatement stmnt;
		CleanupClosePushL(stmnt);
		stmnt.PrepareL(iDatabase, iMatchSelectStmnt->SqlStringL() );

		const TInt KValueParamIndex(KFirstParam);			// first parameter in query...
		const TInt KTypeParamIndex(KValueParamIndex + 1);	// ...and the second.

    	User::LeaveIfError(stmnt.BindInt(KValueParamIndex, phoneDigits.iLowerSevenDigits ));
    	User::LeaveIfError(stmnt.BindInt(KTypeParamIndex, EPhoneNumber ));

		// fetch the list of any matching contact ids
		TInt err(KErrNone);
		const TInt KContactIdIdx(iMatchSelectStmnt->ParameterIndex(KCommAddrContactId() ) );
		const TInt KExtraValueIdx(iMatchSelectStmnt->ParameterIndex(KCommAddrExtraValue() ) );
		while ((err = stmnt.Next() ) == KSqlAtRow)
			{
			if (aMatchLengthFromRight <= KLowerSevenDigits)
				{
				// Matching 7 or less digits...we've already matched.
				phoneMatchArray->AddL(stmnt.ColumnInt(KContactIdIdx) );
				}
			else
				{
				// Check the upper digits...
				TInt32 storedUpperDigits(0);
				TPtrC extValString = stmnt.ColumnTextL(KExtraValueIdx);
				User::LeaveIfError(TLex(extValString).Val(storedUpperDigits) );

				const TInt KDigitsToRemove = KMaxPhoneMatchLength - KLowerSevenDigits - phoneDigits.iNumUpperDigits;
				for(TInt i = 0; i < KDigitsToRemove; ++i)
					{
					// repeatedly divide by 10 to lop off the appropriate number of digits from the right
					storedUpperDigits /= 10;
					}

				storedUpperDigits = TMatch::PadOutPhoneMatchNumber(storedUpperDigits, KDigitsToRemove);

				if (phoneDigits.iUpperDigits == storedUpperDigits)
					{
					phoneMatchArray->AddL(stmnt.ColumnInt(KContactIdIdx) );
					}
				}
			}

		// leave if we didn't complete going through the results properly
		if(err != KSqlAtEnd)
			{
			User::Leave(err);
			}
		CleanupStack::PopAndDestroy(&stmnt);
		}

	CleanupStack::Pop(phoneMatchArray);
	return phoneMatchArray;
	}
void CGroupViewTester::RunL()
	{
	switch (iCurrentTest)
		{
		case ECreateLocalView:
			iLog.LogLine(_L("Creating local view"));
			iLocalView = CContactLocalView::NewL( *this, iDb, iSortOrder_1, 
                EContactAndGroups );
			break;

		case ECreateGroupOneView:
			iLog.LogLine(_L("Creating group view one."));
            
            // Create a version 2 object.
			iGroupViewOne = CContactGroupView::NewL( *iLocalView, iDb, *this,
                iGroupOne->Id(), CContactGroupView::EShowContactsInGroup );
			break;

        case ECreateGroupTwoView:
            {
			iLog.LogLine(_L("Creating group view two."));
			iGroupViewTwo = CContactGroupView::NewL( *iLocalView, iDb, *this,
                KNullContactId, CContactGroupView::EShowContactsNotInAnyGroup );
            }
            break;

        case EDeleteItemsFromView:
            {
            iLog.LogLine(_L("Deleting contacts from group one."));

            TInt id1 = 1;
            TInt index = iGroupViewOne->FindL( id1 );
            iLog.LogLine( _L("Deleting contact id %d. index = %d"), id1, index );

            TInt id2 = 2;
            index = iGroupViewOne->FindL( 2 );
            iLog.LogLine( _L("Deleting contact id %d. index = %d"), id2, index );

            // Delete two contacts using a bulk delete.
            TInt numContactsInGroup = iGroupViewOne->CountL();
            CContactIdArray* itemsToDelete = CContactIdArray::NewL();
            CleanupStack::PushL( itemsToDelete );
            itemsToDelete->AddL( id1 );
            itemsToDelete->AddL( id2 );
            iDb.DeleteContactsL( *itemsToDelete );
            CleanupStack::PopAndDestroy( itemsToDelete );

            break;
            }

        case EAddItemToGroup:
            {
            iLog.LogLine(_L("Adding contact to database and group one."));
            // Create a new item and add it to group one.
            iIdAdded = iTestConductor->AddRandomContactL();
            iDb.AddContactToGroupL( iIdAdded, iGroupOne->Id() );
            break;
            }

		case ENumTests:
            // Tests complete.
            iLog.LogLine(_L("All tests complete."));
			CActiveScheduler::Stop();
			delete this;
			break;

		default:
			ASSERT( EFalse );
			break;
		}
	}
void CTestContactsPBAPExport::ExportContactsL()
	{
	TInt err = KErrNone;
	// Retrieve the file name to which contact item is to be exported
   	RFs fsSession;
	RFileWriteStream writeStream;

	// connect to file system
	User::LeaveIfError(fsSession.Connect());
	CleanupClosePushL(fsSession);

	GetInputFromIni();

   	// Makes one or more directories.
   	fsSession.MkDirAll(iExportTo);

	// Replaces a single file with another
	User::LeaveIfError(writeStream.Replace(fsSession, iExportTo, EFileWrite));

	INFO_PRINTF1(_L("Exporting Contact....."));

	// Existing database
   	TPtrC databaseFile(_L("C:contactDb.cdb"));

	CContactDatabase* dBase = NULL;
	CContactIdArray* idArray = NULL;

	// Open the existing database
	dBase = CContactDatabase::OpenL(databaseFile);
	CleanupStack::PushL(dBase);

	// Create Utility class object, to export the contact from database
	CTestStep* self = static_cast<CTestStep*>(this);
	iExportObj = new(ELeave) CContactsPBAPExportUtilityClass(self);

	SetFilterL();

	CCntFilter* exportFilter = CCntFilter::NewL();
	CleanupStack::PushL(exportFilter);

	// Get all the contacts from the database to export
	exportFilter->SetContactFilterTypeCard(ETrue);
	dBase->FilterDatabaseL(*exportFilter);
	idArray = exportFilter->iIds;
	CleanupStack::PushL(idArray);

	if(iDamageDb)
		{
		#ifdef _DEBUG
		#ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__
		TRAPD(err1,dBase->DamageDatabaseL(0x666));
		if(err1 == KErrNone)
			{
			TRAPD(err,iExportObj->ExportvCardL(dBase, iStandard, idArray, writeStream, iContactFilter));
			INFO_PRINTF2(_L("Err:%d"),err);
			if(err == KErrNotReady)
				{
				SetTestStepResult(EPass);
				}
			else
				{
				SetTestStepResult(EFail);
				}
			if(dBase->IsDamaged())
				{
				dBase->RecoverL();
				}
			}
		else
			{
			INFO_PRINTF2(_L("Could not damage database Err:"),err1);
			}
		#else
			SetTestStepResult(EPass);
		#endif
		#endif
		}
    else
	    {
	    if(iInvalidFileSystem)
		    {
		    #ifdef _DEBUG
		    fsSession.SetErrorCondition(KErrNotReady);
		    TRAPD(err,iExportObj->ExportvCardL(dBase, iStandard, idArray, writeStream, iContactFilter));
			if(err == KErrNotReady)
				{
				SetTestStepResult(EPass);
				}
			else
				{
				SetTestStepResult(EFail);
				}
			fsSession.SetErrorCondition(KErrNone);
			#endif
			}
	    else
			{
			if(!iSetOOM)
				{
				if(idArray->Count() > 0)
					{
					for(TInt i=0; i<idArray->Count() ; i++)
						{
						TInt dCount = dBase->CountL();
						if(i>=dCount)
							{
							break;
							}

						// temporary array used to export one contact at a time
						CContactIdArray* tempIdArray = CContactIdArray::NewL();
						CleanupStack::PushL(tempIdArray);
						tempIdArray->AddL((*idArray)[i]);
						TRAPD(err,iExportObj->ExportvCardL(dBase, iStandard, tempIdArray, writeStream, iContactFilter));

						if(err != KErrNone )
							{
							if(err != KErrNotFound)
								{
								SetTestStepError(err);
								}
							}

						CleanupStack::PopAndDestroy(tempIdArray);
						}
					}
				else
					{
					if(idArray->Count()==0)
						{
						TRAPD(err,iExportObj->ExportvCardL(dBase, iStandard, idArray, writeStream, iContactFilter));
						if(err != KErrNone)
							{
							SetTestStepError(err);
							}
						}
					}

				}
			else
				{
				TInt tryCount = 1;
				for ( ;; )
					{
					__UHEAP_SETFAIL(RHeap::EDeterministic, tryCount);
					TRAP(err, iExportObj->ExportvCardL(dBase, iStandard, idArray, writeStream, iContactFilter));

					if ( err == KErrNone )
						{
						__UHEAP_RESET;
						INFO_PRINTF1(_L("OOM testing of CContactDatabase::ExportSelectedContactsL Api is done"));
						break;
						}
					if ( err != KErrNoMemory )
						{
						INFO_PRINTF2(_L("The unexpected error code is:%d"),err);
						SetTestStepResult(EFail);
						break;
						}
					__UHEAP_SETFAIL(RHeap::ENone, 0);
					tryCount++;
					}
				}
			}
	    }

	CleanupStack::Pop(idArray);
	CleanupStack::PopAndDestroy(exportFilter);

	INFO_PRINTF1(_L("Exported Contact"));
	writeStream.CommitL();
	writeStream.Close();

	INFO_PRINTF2(_L("Total number of contacts in database %d "), dBase->CountL());

	// Cleanup
	CleanupStack::PopAndDestroy(dBase);
    CleanupStack::PopAndDestroy(&fsSession);
	}