Exemple #1
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);
	}
/**
 * Reads data specified in the ini file and constructs all view validation objects
 */
void CTestContactViewUnderlyingViewUpdateStep::ReadIniAndConstructViewValidationObjectsL()
	{
	_LIT(KListOfViewsToBeValidated, "ListOfViewsToBeValidated");
	TPtrC listOfViewsToBeRemoved;
	TESTL(GetStringFromConfig(ConfigSection(), KListOfViewsToBeValidated, listOfViewsToBeRemoved));

	RArray<TPtrC>	sections;
	CleanupClosePushL(sections);
	ViewUtilityReference().TokenizeStringL(listOfViewsToBeRemoved, sections);

	for ( TInt i = 0; i < sections.Count(); ++i )
		{
		TViewValidationData ViewValidationData;

		_LIT(KContactViewType, "ViewType");
		TPtrC contactViewTypeString;
		GetStringFromConfig(sections[i], KContactViewType, contactViewTypeString);
		ViewValidationData.SetViewType(contactViewTypeString);

		_LIT(KContactViewIndex, "ViewIndex");
		TInt contactViewIndex;
		GetIntFromConfig(sections[i], KContactViewIndex, contactViewIndex);
		ViewValidationData.SetViewIndex(contactViewIndex);

		_LIT(KUpdatedViewCount, "UpdatedViewCount");
		TInt updatedViewCount = 0;
		GetIntFromConfig(sections[i], KUpdatedViewCount, updatedViewCount);
		ViewValidationData.SetExpectedViewCount(updatedViewCount);

		iViewValidationArray.AppendL(ViewValidationData);
		}

	CleanupStack::PopAndDestroy(&sections); 
	}
/**
 * Adds contact fields to the contact, as per the desired contact view filter
 */
void CTestContactViewCRUDOperationsStep::AddFieldsSpecificToFilterL(CContactItem& aContact)
	{
	_LIT(KDesiredFilterString, "desiredFilter");
	TPtrC desiredFilterString;
	GetStringFromConfig(ConfigSection(), KDesiredFilterString, desiredFilterString);
	CContactDatabase::TContactViewFilter	viewFilter = ViewUtilityReference().GetContactViewFilterL(desiredFilterString);
	AddFilterBasedFieldsL(aContact, viewFilter);
	}
/**
* New contact entries are added in the database. The newly added contacts can have fields that meet the sort order
* of some existing views, With the addition of such contact fields, the existing views needs resorting. The newly added
* fields may also meet the filter criteria of some existing views. This is useful while testing filtered views
* The new added contacts can have fields with some predefined string content, this is useful in case of Find Views and Sub Views.
*/
void CTestContactViewCRUDOperationsStep::AddContactEntriesL()
	{
	_LIT(KViewSortOrder, "SortOrder");
	TPtrC viewSortOrderString;
	GetStringFromConfig(ConfigSection(), KViewSortOrder, viewSortOrderString);

	RContactViewSortOrder sortOrder = ViewUtilityReference().ConvertStringToSortOrderL(viewSortOrderString);
	CleanupClosePushL(sortOrder);

	_LIT(KNumOfContactsToBeAdded, "NumOfContactsToBeAdded");
	TInt numOfContactsToBeAdded;
	GetIntFromConfig(ConfigSection(), KNumOfContactsToBeAdded, numOfContactsToBeAdded);


	for(TInt i = 0; i < numOfContactsToBeAdded; ++i)
		{
		CContactCard* contactCard = CContactCard::NewL();
		CleanupStack::PushL(contactCard);
		AddContactFieldL(*contactCard, sortOrder);

		TBool filterBasedFields;
		_LIT(KFilterBasedFields, "FilterBasedFields");
		GetBoolFromConfig(ConfigSection(), KFilterBasedFields, filterBasedFields);
		if(filterBasedFields)
			{
			AddFieldsSpecificToFilterL(*contactCard);
			}

		TBool contactsWithDesiredString;
		_LIT(KContactsWithDesiredString, "ContactsWithDesiredString");
		GetBoolFromConfig(ConfigSection(), KContactsWithDesiredString, contactsWithDesiredString);
		if(contactsWithDesiredString)
			{
			AddMatchingStringToContactL(*contactCard);
			}


		TContactItemId contactId = DatabaseReference().AddNewContactL(*contactCard);

		TPtrC addContactToGroup;
		_LIT(KAddContactToGroup, "grouplist");
		GetStringFromConfig(ConfigSection(), KAddContactToGroup, addContactToGroup);
		if(addContactToGroup != KNullDesC)
			{
			IterateThroAllGroupSectionsAndUpdateContactL(addContactToGroup, *contactCard);
			}

		CleanupStack::PopAndDestroy();// contactCard
		DatabaseReference().CloseContactL(contactId);
		}
	CleanupStack::PopAndDestroy(); // sortOrder
	}
/* 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);
	}
/* 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);
	}
/**
 * Reads data specified in the ini file and constructs all relevant view update objects
 * These view update objects serve as source for performing underlying view update operations
 */
void CTestContactViewUnderlyingViewUpdateStep::ReadIniAndConstructViewUpdateObjectsL()
	{
	_LIT(KListOfViewsToBeRemoved, "ListOfViewsToBeUpdated");
	TPtrC listOfViewsToBeUpdated;
	TESTL(GetStringFromConfig(ConfigSection(), KListOfViewsToBeRemoved, listOfViewsToBeUpdated));

	RArray<TPtrC>	sections;
	CleanupClosePushL(sections);
	ViewUtilityReference().TokenizeStringL(listOfViewsToBeUpdated, sections);

	for ( TInt i = 0; i < sections.Count(); ++i )
		{
		TViewModificationData viewModificationData;

		// Here data is read from the ini file about various contact view update operations
		// to be performed. This information comprises of view to be updated and number of contacts
		// to be removed in the specified view
		_LIT(KContactViewType, "ViewType");
		TPtrC contactViewTypeString;
		GetStringFromConfig(sections[i], KContactViewType, contactViewTypeString);
		viewModificationData.SetViewType(contactViewTypeString);

		_LIT(KContactViewIndex, "ViewIndex");
		TInt contactViewIndex;
		GetIntFromConfig(sections[i], KContactViewIndex, contactViewIndex);
		viewModificationData.SetViewIndex(contactViewIndex);

		_LIT(KNumberOfContactToBeRemoved, "NumberOfContactsToBeRemoved");
		TInt numberOfContactsToBeRemoved;
		GetIntFromConfig(sections[i], KNumberOfContactToBeRemoved, numberOfContactsToBeRemoved);
		viewModificationData.SetNumberOfContactsToBeRemoved(numberOfContactsToBeRemoved);

		iViewUpdateArray.AppendL(viewModificationData);
		}

	CleanupStack::PopAndDestroy(&sections); 
	}