/**
 * Deletes the specified number of contact cards from the database
 */
void CTestContactViewCRUDOperationsStep::DeleteContactCardsL()
	{
	_LIT(KNumOfContactsToBeDeleted, "NumOfContactsToBeDeleted");
	TInt numOfContactsToBeDeleted;
	GetIntFromConfig(ConfigSection(), KNumOfContactsToBeDeleted, numOfContactsToBeDeleted);


	TPtrC deleteContactInGroups;
	_LIT(KDeleteContactInGroups, "grouplist");
	GetStringFromConfig(ConfigSection(), KDeleteContactInGroups, deleteContactInGroups);

	if(deleteContactInGroups != KNullDesC)
		{
		DeleteContactsInGroupL(numOfContactsToBeDeleted, deleteContactInGroups);
		}
	else
		{
		CCntFilter* filter = CCntFilter::NewL();
		CleanupStack::PushL(filter);
		filter->SetContactFilterTypeCard(ETrue);
		DatabaseReference().FilterDatabaseL(*filter);

		for(TInt i = 0; i < numOfContactsToBeDeleted; ++i)
			{
			TContactItemId contactItemId = (*filter->iIds)[i];
			DatabaseReference().DeleteContactL(contactItemId);
			}

		CleanupStack::PopAndDestroy(filter);
		}
	}
Exemple #2
0
/**
 * Updates the specified group with details like group name, number of contacts in the group
 * @param aGroupSection - section in the ini file contains necessary details for group update
 * @param aGroup - Group to be updated
 */
void CTestContactViewDatabaseUtilitiesStep::UpdateGroupsL(const TPtrC& aGroupSection, CContactGroup& aGroup)
	{
	_LIT(KGroupName, "groupname");
	TPtrC groupName;
	GetStringFromConfig(aGroupSection, KGroupName, groupName);

	aGroup.SetGroupLabelL(groupName);

	_LIT(KNumOfContacts, "numofcontacts");
	TInt numOfContacts;
	GetIntFromConfig(aGroupSection, KNumOfContacts, numOfContacts);

	CCntFilter* filter = CCntFilter::NewL();
	CleanupStack::PushL(filter);
	filter->SetContactFilterTypeCard(ETrue);
	DatabaseReference().FilterDatabaseL(*filter);

	for(TInt i = 0; i < numOfContacts; ++i)
		{
		CContactIdArray* idArray = filter->iIds;
		TContactItemId contactItemId = (*idArray)[i];
		CContactItem* contactItem = DatabaseReference().OpenContactL(contactItemId);
		CleanupStack::PushL(contactItem);
		TRAP_IGNORE(DatabaseReference().RemoveContactFromGroupL(*contactItem, aGroup));
		TRAP_IGNORE(DatabaseReference().AddContactToGroupL(*contactItem, aGroup));
		CleanupStack::PopAndDestroy(contactItem);
		DatabaseReference().CloseContactL(contactItemId);
		}

	CleanupStack::PopAndDestroy(filter);
	}
Exemple #3
0
/* In this section, we edit the desired number of groups in the database
 * Set label for them and associate them with desired number of groups
 * With this database updation, group views can be constructed and accessed
 */
void CTestContactViewDatabaseUtilitiesStep::IterateThroAllGroupSectionsAndUpdateL()
	{
	_LIT(KListOfGroupsSectionsString, "listofgroupsections");
	TPtrC listOfGroupsSectionsString;
	GetStringFromConfig(ConfigSection(), KListOfGroupsSectionsString, listOfGroupsSectionsString);

	RArray<TPtrC>	listOfGroupsSections;
	CleanupClosePushL(listOfGroupsSections);
	ViewUtilityReference().TokenizeStringL(listOfGroupsSectionsString, listOfGroupsSections);

	CCntFilter* filter = CCntFilter::NewL();
	CleanupStack::PushL(filter);
	filter->SetContactFilterTypeGroup(ETrue);
	DatabaseReference().FilterDatabaseL(*filter);

	for ( TInt i = 0; i < listOfGroupsSections.Count(); ++i )
		{
		CContactIdArray* idArray = filter->iIds;
		TContactItemId groupId = (*idArray)[i];
		CContactItem* group = DatabaseReference().OpenContactL(groupId);
		CleanupStack::PushL(group);
		CContactGroup* newGroup = static_cast<CContactGroup*>(group);
		UpdateGroupsL(listOfGroupsSections[i], *newGroup);
		DatabaseReference().CommitContactL(*group);
		DatabaseReference().CloseContactL(groupId);
		CleanupStack::PopAndDestroy(group);
		}

	CleanupStack::PopAndDestroy(2, &listOfGroupsSections);
	}
Exemple #4
0
LOCAL_C void TestFilteringL()
{
    _LIT(KProgressIndicator,".");
    test.Printf(KProgressIndicator);

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

    filter->SetContactFilterTypeCard(ETrue);
    TTime time;
    time.UniversalTime();
    time-=TTimeIntervalMinutes(20); // changes in the last 20 mins
    filter->SetFilterDateTime(time);
    filter->SetIncludeNewContacts(ETrue);
    CntTest->Db()->FilterDatabaseL(*filter);
    test(filter->iIds->Count()==KTotalNumRecords);

// modified contact
    User::After(4000000);	// Let time pass to distinguish between mod  / new
    // this may still fail if the device is running too slow (e.g. under a heavy load)

    filter->Reset();
    time.UniversalTime();
    filter->SetFilterDateTime(time);
    filter->SetIncludeModifiedContacts(ETrue);
    CntTest->Db()->FilterDatabaseL(*filter);
    test(filter->iIds->Count()==0);

    CContactItem* contact = CntTest->Db()->OpenContactLX(5);
    CleanupStack::PushL(contact);
    contact->IncAccessCount();
    CntTest->Db()->CommitContactL(*contact);
    CleanupStack::PopAndDestroy(contact);
    CleanupStack::Pop(); // contact.Close()

    CntTest->Db()->FilterDatabaseL(*filter);
    test(filter->iIds->Count()==1);

// deleted contact
    filter->Reset();
    filter->SetFilterDateTime(time); // same time as for modified
    filter->SetIncludeDeletedContacts(ETrue);
    CntTest->Db()->FilterDatabaseL(*filter);
    test(filter->iIds->Count()==0);

    CntTest->Db()->DeleteContactL(5);
    CntTest->Db()->FilterDatabaseL(*filter);
    TInt deletedContactCount = filter->iIds->Count();
    test(deletedContactCount ==1);

#ifdef _DEBUG
    CContactIdArray* deletedCntArray = CntTest->Db()->DeletedContactsLC();
    test(deletedCntArray->Count()==deletedContactCount);
    CleanupStack::PopAndDestroy(deletedCntArray );
#endif

    CleanupStack::PopAndDestroy(filter);
}
Exemple #5
0
// Construction tests
// NewL methods are called by NewLC variants so there's no tests for that
//
LOCAL_C void TestFilterConstructionL()
{
    CCntFilter* filter = CCntFilter::NewLC();
    TTime time;
    time.UniversalTime();
    filter->SetFilterDateTime(time);

    CCntFilter* clone = CCntFilter::NewLC(filter);
    test(clone->GetFilterDateTime()==time);

    CleanupStack::PopAndDestroy(2); //filter,clone
}
TBool CPackagerCntComparator::DoCompareCCntFilterContactTypeL(const CCntFilter& aFilter1, const CCntFilter& aFilter2) const
/** Compares two CCntFilter ContactType items. 

@param aFilter1 The first CCntFilter with its ContactType item to be compared.
@param aFilter2 The second CCntFilter  with its ContactType item to be compared.
@return ETrue if the two items are equal, EFalse otherwise. */
	{
	return ((aFilter1.ContactFilterTypeALL()==aFilter2.ContactFilterTypeALL())		&
	(aFilter1.ContactFilterTypeCard()		==aFilter2.ContactFilterTypeCard())		&
	(aFilter1.ContactFilterTypeGroup()		==aFilter2.ContactFilterTypeGroup())	&			
	(aFilter1.ContactFilterTypeOwnCard()	==aFilter2.ContactFilterTypeOwnCard())	&
	(aFilter1.ContactFilterTypeTemplate()	==aFilter2.ContactFilterTypeTemplate()));
	}
Exemple #7
0
LOCAL_C void SimpleFilterTestL()
{
    CCntFilter* filter = CCntFilter::NewL();
    CleanupStack::PushL(filter);
    filter->SetContactFilterTypeCard(ETrue);
    TTime time;
    time.UniversalTime();
    time-=TTimeIntervalMinutes(20); // changes in the last 20 mins
    filter->SetFilterDateTime(time);
    filter->SetIncludeNewContacts(ETrue);
    CntTest->Db()->FilterDatabaseL(*filter);
    test(filter->iIds->Count()==KTotalNumRecords);
    CleanupStack::PopAndDestroy(filter);
}
CCntFilter* CPackagerCntFactory::doCreateDefaultCCntFilterL() const
/** Implementation method for constructing a new default CCntFilter object. 

@return a Pointer to the CCntFilter object. */
	{
	CCntFilter* theFilter = CCntFilter::NewLC();
	theFilter->SetContactFilterTypeCard(ETrue);
	TTime time;
	time.UniversalTime();
	time-=TTimeIntervalMinutes(KInterval); // changes in the last KInterval mins
	theFilter->SetFilterDateTime(time);
	theFilter->SetIncludeNewContacts(ETrue);
	theFilter->SetContactFilterTypeALL(ETrue);
	theFilter->iIds = doCreateDefaultCContactIdArrayL();
	CleanupStack::Pop(theFilter);
	return theFilter;
	}	
/* In this section, we edit the desired number of groups in the database
 * Set label for them and associate them with contacts
 @ param aGroupSection - Desired Group Name
 @ param aContact - Contact to be updated
 */
void CTestContactViewCRUDOperationsStep::UpdateContactsInGroupL(const TInt aNumberOfContactsToBeUpdated, const TPtrC& aGroupSection)
	{
	RArray<TPtrC>	listOfGroupsSections;
	CleanupClosePushL(listOfGroupsSections);
	ViewUtilityReference().TokenizeStringL(aGroupSection, listOfGroupsSections);

	for ( TInt i = 0; i < listOfGroupsSections.Count(); ++i )
		{
		CCntFilter* filter = CCntFilter::NewL();
		CleanupStack::PushL(filter);
		filter->SetContactFilterTypeGroup(ETrue);
		DatabaseReference().FilterDatabaseL(*filter);

		for ( TInt i = 0; i < filter->iIds->Count(); ++i )
			{
			TContactItemId groupId = (*filter->iIds)[i];
			CContactItem* group = DatabaseReference().OpenContactL(groupId);
			CContactGroup* newGroup = static_cast<CContactGroup*>(group);


			if(aGroupSection.Compare(newGroup->GetGroupLabelL())  == 0)
				{
				const CContactIdArray* listOfContacts = newGroup->ItemsContained();
				for(TInt i(0); i < aNumberOfContactsToBeUpdated; i++)
					{
					TContactItemId contactItemId = (*listOfContacts)[i];
					CContactItem* contactItem = DatabaseReference().ReadContactL(contactItemId);
					CleanupStack::PushL(contactItem);
					UpdateFieldsL(*contactItem);
					CContactItem* updatedContactItem = DatabaseReference().UpdateContactLC(contactItemId, contactItem);
					CleanupStack::PopAndDestroy(updatedContactItem);
					CleanupStack::PopAndDestroy(contactItem);
					}
				delete listOfContacts;
				DatabaseReference().CloseContactL(groupId);
				break;
				}
			DatabaseReference().CloseContactL(groupId);
			}

    	CleanupStack::PopAndDestroy(filter);
		}

	CleanupStack::PopAndDestroy(&listOfGroupsSections);
	}
Exemple #10
0
LOCAL_C void NonDateBasedFilterTest()
{
    //This test has been created because, formerly,
    //CContactDatabase::FilterDatabase(...) could not
    //filter on contact types ONLY.
    //Previously, the CCntFilter passed in had to
    //have specified filtering based on the
    //time-based states as well (e.g. new, modified, deleted).
    //Addresses DEF036345
    CCntFilter* theFilter = CCntFilter::NewLC();
    theFilter->SetContactFilterTypeGroup(EFalse);
    theFilter->SetContactFilterTypeTemplate(EFalse);
    theFilter->SetContactFilterTypeOwnCard(EFalse);
    theFilter->SetContactFilterTypeCard(ETrue);
    //Get a filtered version of the database
    CntTest->Db()->FilterDatabaseL(*theFilter);
    test(theFilter->iIds->Count()==KTotalNumRecords);
    CleanupStack::PopAndDestroy(theFilter);
}
Exemple #11
0
void CTestContactOperations::DeleteContactsL()
	{
	// existing database
   	TPtrC databaseFile(_L("C:contactDB.cdb"));
   	
   	TContactItemId itemId = KErrNotFound;
	CContactDatabase* dBase = NULL;
	CContactIdArray* idArray = NULL;
	
	dBase = CContactDatabase::OpenL(databaseFile);
	CleanupStack::PushL(dBase);
	
	// Set the filter to select all the contact items in the database
	CCntFilter* exportFilter = CCntFilter::NewL();
	CleanupStack::PushL(exportFilter);
	exportFilter->SetContactFilterTypeCard(ETrue);
	dBase->FilterDatabaseL(*exportFilter);
	idArray = exportFilter->iIds;	
	CleanupStack::PushL(idArray);
	
	TInt numberOfContacts;
   	GetIntFromConfig(ConfigSection(), KNumberOfCont, numberOfContacts);
	
	INFO_PRINTF1(_L("Deleting Contacts....."));

	// Delete the contacts one at a time
	for(TInt i=(idArray->Count()-1);i>=0;i--)
		{
		dBase->DeleteContactL((*idArray)[i]);
		}
			
	_LIT(KCount, "The number of contacts in the database is %d \n");
	INFO_PRINTF2(KCount, dBase->CountL());
	
	// Close the contacts
    dBase->CloseContactL(itemId);
	
	// Cleanup
	CleanupStack::Pop(idArray);
    CleanupStack::PopAndDestroy(exportFilter);
    CleanupStack::PopAndDestroy(dBase);
    }
/* In this section, we edit the desired number of groups in the database
 * Set label for them and associate them with contacts
 @ param aGroupSection - Desired Group Name
 @ param aContact - Contact to be updated
 */
void CTestContactViewCRUDOperationsStep::IterateThroAllGroupSectionsAndUpdateContactL(const TPtrC& aGroupSection,
																									 CContactCard& aContact)
	{
	RArray<TPtrC>	listOfGroupsSections;
	CleanupClosePushL(listOfGroupsSections);
	ViewUtilityReference().TokenizeStringL(aGroupSection, listOfGroupsSections);

	for ( TInt i = 0; i < listOfGroupsSections.Count(); ++i )
		{
		CCntFilter* filter = CCntFilter::NewL();
		CleanupStack::PushL(filter);
		filter->SetContactFilterTypeGroup(ETrue);
		DatabaseReference().FilterDatabaseL(*filter);

		for ( TInt i = 0; i < filter->iIds->Count(); ++i )
			{
			TContactItemId groupId = (*filter->iIds)[i];
			CContactItem* group = DatabaseReference().OpenContactL(groupId);
			CContactGroup* newGroup = static_cast<CContactGroup*>(group);
			if(aGroupSection.Compare(newGroup->GetGroupLabelL())  == 0)
				{
				TRAP_IGNORE(DatabaseReference().RemoveContactFromGroupL(aContact, *newGroup));
				TRAP_IGNORE(DatabaseReference().AddContactToGroupL(aContact, *newGroup));
				DatabaseReference().CommitContactL(*group);
				const CContactIdArray* listOfContacts = newGroup->ItemsContained();
				const TInt count = listOfContacts->Count();
				delete listOfContacts;
				DatabaseReference().CloseContactL(groupId);
				break;
				}
			DatabaseReference().CloseContactL(groupId);
			}

    	CleanupStack::PopAndDestroy(filter);
		}

	CleanupStack::PopAndDestroy(&listOfGroupsSections);
	}
Exemple #13
0
// SetInclude* are exclusive
// SetContactFilterType* is cumulative
//
LOCAL_C void CheckFilterSettingsL(TBool aSetting)
{
    CCntFilter* filter = CCntFilter::NewLC();

    filter->Reset();
    filter->SetIncludeModifiedContacts(aSetting);
    if (aSetting)
    {
        test(filter->IncludeModifiedContacts());
        test(!filter->IncludeNewContacts());
        test(!filter->IncludeDeletedContacts());
    }

    filter->SetIncludeNewContacts(aSetting);
    if (aSetting)
    {
        test(filter->IncludeNewContacts());
        test(!filter->IncludeModifiedContacts());
        test(!filter->IncludeDeletedContacts());
    }


    filter->SetIncludeDeletedContacts(aSetting);
    if (aSetting)
    {
        test(filter->IncludeDeletedContacts());
        test(!filter->IncludeModifiedContacts());
        test(!filter->IncludeNewContacts());
    }

    filter->SetContactFilterTypeCard(aSetting);
    filter->SetContactFilterTypeGroup(aSetting);
    filter->SetContactFilterTypeTemplate(aSetting);
    filter->SetContactFilterTypeOwnCard(aSetting);
    if (aSetting)
    {
        test(filter->ContactFilterTypeGroup());
        test(filter->ContactFilterTypeCard());
        test(filter->ContactFilterTypeTemplate());
        test(filter->ContactFilterTypeOwnCard());
    }
    else
    {
        test(!filter->ContactFilterTypeGroup());
        test(!filter->ContactFilterTypeCard());
        test(!filter->ContactFilterTypeTemplate());
        test(!filter->ContactFilterTypeOwnCard());
    }

    filter->SetContactFilterTypeALL(aSetting);
    if (aSetting)
    {
        test(filter->ContactFilterTypeALL());
        test(filter->ContactFilterTypeGroup());
        test(filter->ContactFilterTypeCard());
        test(filter->ContactFilterTypeTemplate());
        test(filter->ContactFilterTypeOwnCard());
    }

    TTime time;
    time.UniversalTime();
    filter->SetFilterDateTime(time);
    test(filter->GetFilterDateTime()==time);

    CleanupStack::PopAndDestroy(filter);
}
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);
	}