phonebookengines/contactsmodel/tsrc/Integration/CntPerfTest/src/PrepareDataTestStep.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2007-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 "PrepareDataTestStep.h"
       
    17 
       
    18 /**
       
    19  * Constructor
       
    20  */
       
    21 CPrepareDataTestStep::CPrepareDataTestStep()
       
    22 	{
       
    23 	// Mandatory call to base class method to set up the human readable name for logging.
       
    24 	SetTestStepName(KPrepareDataTestStep);
       
    25 	}
       
    26 
       
    27 /**
       
    28  * Destructor
       
    29  */
       
    30 CPrepareDataTestStep::~CPrepareDataTestStep()
       
    31 	{
       
    32 	iListOfContactItemsInDatabase.Close();
       
    33 	}
       
    34 
       
    35 /**
       
    36  * Setup the environment required for test, install schedular in the current thread
       
    37  * Opens the relevant contacts database file
       
    38  */
       
    39 TVerdict CPrepareDataTestStep::doTestStepPreambleL()
       
    40 	{
       
    41  	CTestContactViewDatabaseUtilitiesStep::doTestStepPreambleL();
       
    42 	return TestStepResult();
       
    43 	}
       
    44 
       
    45 /**
       
    46  * Cleanup function for the test step
       
    47  */
       
    48 TVerdict CPrepareDataTestStep::doTestStepPostambleL()
       
    49 	{
       
    50  	CTestContactViewDatabaseUtilitiesStep::doTestStepPostambleL();
       
    51 	return TestStepResult();
       
    52 	}
       
    53 
       
    54 
       
    55 /**
       
    56 Base class pure virtual.
       
    57 * @return EPass or EFail indicating the result of the test step.
       
    58 */
       
    59 TVerdict CPrepareDataTestStep::doTestStepL()
       
    60 	{
       
    61 	ImportContactsL();
       
    62 	AddContactsInDatabaseL();
       
    63 	IterateThroAllSortOrderSectionsAndUpdateContactsInDatabaseL();
       
    64 	IterateThroAllFilterViewsSectionsAndUpdateL();
       
    65 	IterateThroAllMatchingStringSectionsAndUpdateL();
       
    66 	AddGroupsInDatabaseL();
       
    67 	IterateThroAllGroupSectionsAndUpdateL();
       
    68 	UpdateContactToSpecificStringL();
       
    69 	CloseDatabaseL();
       
    70 	CopyDatabaseL();
       
    71 	return TestStepResult();
       
    72 	}
       
    73 
       
    74 /**
       
    75 * Import Contact entries
       
    76 */
       
    77 void CPrepareDataTestStep::ImportContactsL()
       
    78 	{
       
    79 	ViewUtilityReference().ImportContactsL();
       
    80 	}
       
    81 
       
    82 /**
       
    83  * Here we are trying add blank contact items in the database
       
    84  * Say some 2000 thousand contacts are added to the database
       
    85  */
       
    86 void CPrepareDataTestStep::AddContactsInDatabaseL()
       
    87 	{
       
    88 	_LIT(KNumOfContacts, "numofcontacts");
       
    89 	TInt numOfContacts = 0;
       
    90 	GetIntFromConfig(ConfigSection(), KNumOfContacts, numOfContacts);
       
    91 
       
    92 	for(TInt i = 0; i < numOfContacts; ++i)
       
    93 		{
       
    94 		CContactCard* contactCard = CContactCard::NewL();
       
    95 		CleanupStack::PushL(contactCard);
       
    96 		TContactItemId contactId = DatabaseReference().AddNewContactL(*contactCard);
       
    97 		CleanupStack::PopAndDestroy(contactCard);
       
    98 		iListOfContactItemsInDatabase.AppendL(contactId);
       
    99 		DatabaseReference().CloseContactL(contactId);
       
   100 		}
       
   101 
       
   102 	TInt count = DatabaseReference().CountL();
       
   103 	_LIT(KDatabaseCount, "Total number of contact entries is %d :");
       
   104 	INFO_PRINTF2(KDatabaseCount, count);
       
   105 	}
       
   106 
       
   107 
       
   108 /* As mentioned earlier there will be some 1000 blank contacts in the database
       
   109  * Now any view will have it's own criteria like
       
   110  * -- view sort order i.e. the order in which the contact items in the view must be sorted
       
   111  * -- view preferences i.e. whether only contact cards or contact groups or both must be included in the view
       
   112  *    whether the unsorted contacts must be included in the view or not, if included, whether they must be included in the
       
   113  *    start of view or end  of view
       
   114  * It becomes necessary to supply the necessary envirnoment that meets the view criteia
       
   115  * Each view can supply its desired criteria. Based on this, the contacts in the database will be updated to meet the view specificattions
       
   116  */
       
   117 void CPrepareDataTestStep::IterateThroAllSortOrderSectionsAndUpdateContactsInDatabaseL()
       
   118 	{
       
   119 	_LIT(KListOfSortOrderSections, "listofsortorder");
       
   120 	TPtrC listOfSortOrderSectionsString;
       
   121 	GetStringFromConfig(ConfigSection(), KListOfSortOrderSections, listOfSortOrderSectionsString);
       
   122 
       
   123 	RArray<TPtrC>	listOfSortOrderSections;
       
   124 	CleanupClosePushL(listOfSortOrderSections);
       
   125 
       
   126 	ViewUtilityReference().TokenizeStringL(listOfSortOrderSectionsString, listOfSortOrderSections);
       
   127 
       
   128 	for ( TInt i = 0; i < listOfSortOrderSections.Count(); ++i )
       
   129 		{
       
   130 		UpdateContactFieldsSpecificToSortOrderL(listOfSortOrderSections[i]);
       
   131 		}
       
   132 
       
   133 	CleanupStack::PopAndDestroy(&listOfSortOrderSections);
       
   134 	}
       
   135 
       
   136 /**
       
   137  * Here we are trying add contacts fields in the existing contacts such that they meet the contact views
       
   138  * Sort Order. Intentionally some of the contacts are updated with the contact fields of Null data to meet
       
   139  * the unsorted contacts criteria
       
   140  */
       
   141 void CPrepareDataTestStep::UpdateContactFieldsSpecificToSortOrderL(const TPtrC& aSortOrderSection)
       
   142 	{
       
   143 	// Based on the sort order, the desired number of contacts will be updated i.e contact fields will be
       
   144 	// added to the contacts in the database. The new fields added will be as per the sort order
       
   145 	// at the end of this operation, if we constuct a contact view with this sort order
       
   146 	// then the desired number of contacts will be included in the view
       
   147 
       
   148 	_LIT(KViewSortOrder, "sortorder");
       
   149 	TPtrC viewSortOrderString;
       
   150 	GetStringFromConfig(aSortOrderSection, KViewSortOrder, viewSortOrderString);
       
   151 
       
   152 	RContactViewSortOrder sortOrder = ViewUtilityReference().ConvertStringToSortOrderL(viewSortOrderString) ;
       
   153 	CleanupClosePushL(sortOrder);
       
   154 
       
   155 	_LIT(KNumOfSortableContacts, "numofsortablecontacts");
       
   156 	TInt numOfSortableContacts;
       
   157 	GetIntFromConfig(aSortOrderSection, KNumOfSortableContacts, numOfSortableContacts);
       
   158 
       
   159 	// Here we are trying to update the desired number of contacts in the database
       
   160 	// with Null contact fields in order to meet the unsortable contacts requirement
       
   161 
       
   162 	_LIT(KNumUnSortableContacts, "numunsortedcontacts");
       
   163 	TInt numUnSortableContacts;
       
   164 	GetIntFromConfig(aSortOrderSection, KNumUnSortableContacts, numUnSortableContacts);
       
   165 
       
   166 	const TInt KTotalNumOfContactsSpecificToThisSortOrder =  numOfSortableContacts + numUnSortableContacts;
       
   167 
       
   168 	TInt numberOfReadySortableContacts = 0;
       
   169 	TInt numberOfReadyUnSortableContacts = 0;
       
   170 
       
   171 	// There may be contact items in the database that meet the sort order
       
   172 	// We need be sure about the contact items that we should update
       
   173 
       
   174 	RArray <TContactItemId> ListOfContactItemsThatCanUpdatedToMeetSortOrder;
       
   175 	CleanupClosePushL(ListOfContactItemsThatCanUpdatedToMeetSortOrder);
       
   176 
       
   177 
       
   178 	for(TInt i = 0; i < iListOfContactItemsInDatabase.Count(); ++i)
       
   179 		{
       
   180 		TContactItemId desiredContactItemId = iListOfContactItemsInDatabase[i];
       
   181 		CContactItem* contact = DatabaseReference().OpenContactL(desiredContactItemId);
       
   182 		CleanupStack::PushL(contact);
       
   183 		CContactItemFieldSet& fieldSet = contact->CardFields();
       
   184 
       
   185 		TInt firstContactFieldPosition = fieldSet.Find(sortOrder[0]);
       
   186 		TInt secondContactFieldPosition = fieldSet.Find(sortOrder[1]);
       
   187 		TInt thirdContactFieldPosition = fieldSet.Find(sortOrder[2]);
       
   188 
       
   189 		if ((firstContactFieldPosition != KErrNotFound) &&  (secondContactFieldPosition != KErrNotFound) && (thirdContactFieldPosition!= KErrNotFound))
       
   190 			{
       
   191 			CContactItemField& firstContactItemField = fieldSet[firstContactFieldPosition];
       
   192 			CContactItemField& secondContactItemField = fieldSet[secondContactFieldPosition];
       
   193 			CContactItemField& thirdContactItemField  = fieldSet[thirdContactFieldPosition];
       
   194 
       
   195 			if((firstContactItemField.Storage() == NULL) && (secondContactItemField.Storage() == NULL) && (thirdContactItemField.Storage() == NULL))
       
   196 				{
       
   197 		  		++numberOfReadyUnSortableContacts;
       
   198 				}
       
   199 			else
       
   200 				{
       
   201 				++numberOfReadySortableContacts;
       
   202 				}
       
   203 			}
       
   204 		else
       
   205 			{
       
   206 			ListOfContactItemsThatCanUpdatedToMeetSortOrder.AppendL(desiredContactItemId);
       
   207 			}
       
   208 
       
   209 		CleanupStack::PopAndDestroy(contact);
       
   210 		DatabaseReference().CloseContactL(desiredContactItemId);
       
   211 		}
       
   212 
       
   213 	if((numberOfReadyUnSortableContacts + numberOfReadySortableContacts) < KTotalNumOfContactsSpecificToThisSortOrder)
       
   214 		{
       
   215 		TInt j = 0;
       
   216 		for(; j < (numOfSortableContacts-numberOfReadySortableContacts); ++j)
       
   217 			{
       
   218 			TContactItemId contactItemIdToBeUpdated = ListOfContactItemsThatCanUpdatedToMeetSortOrder[j];
       
   219 			CContactItem* contact = DatabaseReference().OpenContactL(contactItemIdToBeUpdated);
       
   220 			CleanupStack::PushL(contact);
       
   221 			AddContactFieldL(*contact, sortOrder, ETrue);
       
   222 			DatabaseReference().CommitContactL(*contact);
       
   223 			DatabaseReference().CloseContactL(contactItemIdToBeUpdated);
       
   224 			CleanupStack::PopAndDestroy(contact);
       
   225 			}
       
   226 
       
   227 		for(TInt k = j; k < (j + (numUnSortableContacts-numberOfReadyUnSortableContacts)); ++k)
       
   228 			{
       
   229 			TContactItemId contactItemIdToBeUpdated = ListOfContactItemsThatCanUpdatedToMeetSortOrder[k];
       
   230 			CContactItem* contact = DatabaseReference().OpenContactL(contactItemIdToBeUpdated);
       
   231 			CleanupStack::PushL(contact);
       
   232 			AddContactFieldL(*contact, sortOrder);
       
   233 			DatabaseReference().CommitContactL(*contact);
       
   234 			DatabaseReference().CloseContactL(contactItemIdToBeUpdated);
       
   235 			CleanupStack::PopAndDestroy(contact);
       
   236 			}
       
   237 		}
       
   238 
       
   239 	CleanupStack::PopAndDestroy(2,&sortOrder);
       
   240 	}
       
   241 
       
   242 /** Adds contact fields specific to sort order,
       
   243  * Sort Order. Intentionally some of the contacts are updated with the contact fields of Null data to meet
       
   244  * the unsorted contacts criteria
       
   245  */
       
   246 void CPrepareDataTestStep::AddContactFieldL(CContactItem& aContact, const RContactViewSortOrder& aSortOrder,
       
   247 																								TBool aDataRequired)
       
   248 	{
       
   249 	const TInt KMaxSortOrderCount = 3;
       
   250 	for(TInt i = 0; i < KMaxSortOrderCount; ++i)
       
   251 		{
       
   252 		TFieldType fieldType = aSortOrder[i];
       
   253 		TStorageType storageType = GetStorageType(fieldType);
       
   254 		CContentType* contentType = CContentType::NewL();
       
   255 		CleanupStack::PushL(contentType);
       
   256 		contentType->AddFieldTypeL(fieldType);
       
   257 		CContactItemField* field = 	CContactItemField::NewL(storageType, *contentType);
       
   258 		CleanupStack::PushL(field);
       
   259 
       
   260 		if(aDataRequired)
       
   261 			{
       
   262 			SetDataL(fieldType, *field);
       
   263 			}
       
   264 
       
   265 		aContact.AddFieldL(*field);
       
   266 		CleanupStack::Pop(field);
       
   267 		CleanupStack::PopAndDestroy(contentType);
       
   268 		}
       
   269 	}
       
   270 
       
   271 /**
       
   272  * Reads all the sections in the ini file relevant for updating the contacts database
       
   273  * in order to meet filter view requirements
       
   274  */
       
   275 void CPrepareDataTestStep::IterateThroAllFilterViewsSectionsAndUpdateL()
       
   276 	{
       
   277 	_LIT(KListOfFilterViewSectionsString, "listoffilterviewsections");
       
   278 	TPtrC listOfFilterViewSectionsString;
       
   279 	GetStringFromConfig(ConfigSection(), KListOfFilterViewSectionsString, listOfFilterViewSectionsString);
       
   280 
       
   281 	RArray<TPtrC>	listOfFilterViewSections;
       
   282 	CleanupClosePushL(listOfFilterViewSections);
       
   283 	ViewUtilityReference().TokenizeStringL(listOfFilterViewSectionsString, listOfFilterViewSections);
       
   284 
       
   285 	for(TInt i = 0; i < listOfFilterViewSections.Count(); ++i)
       
   286 		{
       
   287 		UpdateContactsInDatabaseAsPerFilteredViewRequirementsL(listOfFilterViewSections[i]);
       
   288 		}
       
   289 
       
   290 	CleanupStack::PopAndDestroy(&listOfFilterViewSections);
       
   291 	}
       
   292 
       
   293 /**
       
   294  * Updates contacts in database as per filter view requirements specified in the ini section
       
   295  */
       
   296 void CPrepareDataTestStep::UpdateContactsInDatabaseAsPerFilteredViewRequirementsL(const TPtrC& aFilteredViewSection)
       
   297 	{
       
   298 	_LIT(KViewSortOrder, "sortorder");
       
   299 	TPtrC viewSortOrderString;
       
   300 	GetStringFromConfig(aFilteredViewSection, KViewSortOrder, viewSortOrderString);
       
   301 
       
   302 	RContactViewSortOrder sortOrder = 	ViewUtilityReference().ConvertStringToSortOrderL(viewSortOrderString);
       
   303 	CleanupClosePushL(sortOrder);
       
   304 
       
   305 	_LIT(KNumOfContactsWithFilter, "numofcontactswiththisfilter");
       
   306 	TInt numOfContactsWithFilter;
       
   307 	GetIntFromConfig(aFilteredViewSection, KNumOfContactsWithFilter, numOfContactsWithFilter);
       
   308 
       
   309 	_LIT(KDesiredFilterString, "desiredFilter");
       
   310 	TPtrC desiredFilterString;
       
   311 	GetStringFromConfig(aFilteredViewSection, KDesiredFilterString, desiredFilterString);
       
   312 
       
   313 	CContactDatabase::TContactViewFilter	viewFilter = ViewUtilityReference().GetContactViewFilterL(desiredFilterString);
       
   314 
       
   315 	RArray<TContactItemId> contactSpecificToSortOrder;
       
   316 	CleanupClosePushL(contactSpecificToSortOrder);
       
   317 
       
   318 	RetrieveContactsSpecificToSortOrderL(sortOrder, contactSpecificToSortOrder);
       
   319 
       
   320 	for(TInt i = 0; i < numOfContactsWithFilter; ++i)
       
   321 		{
       
   322 		TContactItemId id = contactSpecificToSortOrder[i];
       
   323 		CContactItem* contactItem = DatabaseReference().OpenContactL(id);
       
   324 		CleanupStack::PushL(contactItem);
       
   325 		AddFilterBasedFieldsL(*contactItem, viewFilter);
       
   326 		DatabaseReference().CommitContactL(*contactItem);
       
   327 		DatabaseReference().CloseContactL(id);
       
   328 		CleanupStack::PopAndDestroy(contactItem);
       
   329 		}
       
   330 
       
   331 	CleanupStack::PopAndDestroy(2, &sortOrder);
       
   332 	}
       
   333 
       
   334 
       
   335 /**
       
   336  * Retrieves contacts specific to desired sort order from the database
       
   337  */
       
   338 void CPrepareDataTestStep::RetrieveContactsSpecificToSortOrderL(const RContactViewSortOrder& aSortOrder, RArray<TContactItemId>& aContactSpecificToSorder)
       
   339 	{
       
   340 	for(TInt i = 0; i < iListOfContactItemsInDatabase.Count(); ++i)
       
   341 		{
       
   342 		TContactItemId contactId = iListOfContactItemsInDatabase[i];
       
   343 		CContactItem* contactItem = DatabaseReference().OpenContactL(contactId);
       
   344 		CleanupStack::PushL(contactItem);
       
   345 		TBool exists = CheckAllTheFieldsExists(*contactItem, aSortOrder);
       
   346 		if(exists)
       
   347 			{
       
   348 			aContactSpecificToSorder.AppendL(contactId);
       
   349 			}
       
   350 		DatabaseReference().CloseContactL(contactId);
       
   351 		CleanupStack::PopAndDestroy(contactItem);
       
   352 		}
       
   353 
       
   354 	}
       
   355 
       
   356 /**
       
   357  * Checks whether all the three desired contact fields are present in the contact or not
       
   358  */
       
   359 TBool CPrepareDataTestStep::CheckAllTheFieldsExists(const CContactItem& aContact, const RContactViewSortOrder& aSortOrder)
       
   360 	{
       
   361 	CContactItemFieldSet& fieldSet = aContact.CardFields();
       
   362 
       
   363 	TInt firstContactFieldPosition = fieldSet.Find(aSortOrder[0]);
       
   364 	TInt secondContactFieldPosition = fieldSet.Find(aSortOrder[1]);
       
   365 	TInt thirdContactFieldPosition = fieldSet.Find(aSortOrder[2]);
       
   366 
       
   367 	TInt error = KErrNotFound;
       
   368 
       
   369 	if ((firstContactFieldPosition != error) &&  (secondContactFieldPosition != error) && (thirdContactFieldPosition!= error))
       
   370 		{
       
   371 		return ETrue;
       
   372 		}
       
   373 	else
       
   374 		{
       
   375 		return EFalse;
       
   376 		}
       
   377 	}
       
   378 
       
   379 
       
   380 /**
       
   381  * Data is read from the ini file about the matching strings expected to be present in some of the
       
   382  * contact fields and desired number of contacts in the database are updated with this matching string info
       
   383  */
       
   384 void CPrepareDataTestStep::IterateThroAllMatchingStringSectionsAndUpdateL()
       
   385 	{
       
   386 	_LIT(KListOfMatchingStringSectionsString, "listofMatchingString");
       
   387 	TPtrC listOfMatchingStringSectionsString;
       
   388 	GetStringFromConfig(ConfigSection(), KListOfMatchingStringSectionsString, listOfMatchingStringSectionsString);
       
   389 
       
   390 	RArray<TPtrC>	listOfMatchingStringSections;
       
   391 	CleanupClosePushL(listOfMatchingStringSections);
       
   392 	ViewUtilityReference().TokenizeStringL(listOfMatchingStringSectionsString, listOfMatchingStringSections);
       
   393 
       
   394 	for(TInt i = 0; i < listOfMatchingStringSections.Count(); ++i)
       
   395 		{
       
   396 		UpdateContactsInDatabaseAsPerMatchingStringsL(listOfMatchingStringSections[i]);
       
   397 		}
       
   398 
       
   399 	CleanupStack::PopAndDestroy(&listOfMatchingStringSections);
       
   400 	}
       
   401 
       
   402 /**
       
   403  * Updates the contacts in the database based on the data available in the ini section
       
   404  * @param aMatchingStringSection - Relevant section in the ini file
       
   405  */
       
   406 void CPrepareDataTestStep::UpdateContactsInDatabaseAsPerMatchingStringsL(const TPtrC& aMatchingStringSection)
       
   407 	{
       
   408 	_LIT(KViewSortOrder, "sortorder");
       
   409 	TPtrC viewSortOrderString;
       
   410 	GetStringFromConfig(aMatchingStringSection, KViewSortOrder, viewSortOrderString);
       
   411 
       
   412 	RContactViewSortOrder sortOrder = ViewUtilityReference().ConvertStringToSortOrderL(viewSortOrderString);
       
   413 	CleanupClosePushL(sortOrder);
       
   414 
       
   415 
       
   416 	_LIT(KNumOfContactsWithFilter, "numofcontactswiththisstring");
       
   417 	TInt numOfContactsWithThisString;
       
   418 	GetIntFromConfig(aMatchingStringSection, KNumOfContactsWithFilter, numOfContactsWithThisString);
       
   419 
       
   420 	_LIT(KDesiredMatchingString, "matchingstring");
       
   421 	TPtrC desiredMatchingString;
       
   422 	GetStringFromConfig(aMatchingStringSection, KDesiredMatchingString, desiredMatchingString);
       
   423 
       
   424 	_LIT(KDesiredContactField, "contactfield");
       
   425 	TPtrC desiredContactField;
       
   426 	GetStringFromConfig(aMatchingStringSection, KDesiredContactField, desiredContactField);
       
   427 
       
   428 	TUid uidInfo = GetContactFieldType(desiredContactField);
       
   429 
       
   430 	RArray<TContactItemId> contactSpecificToSortOrder;
       
   431 	CleanupClosePushL(contactSpecificToSortOrder);
       
   432 
       
   433 	RetrieveContactsSpecificToSortOrderL(sortOrder, contactSpecificToSortOrder);
       
   434 
       
   435 	for(TInt i = 0; (i < (contactSpecificToSortOrder.Count()) && (i < numOfContactsWithThisString)); ++i)
       
   436 		{
       
   437 		TContactItemId id = contactSpecificToSortOrder[i];
       
   438 		CContactItem* contactItem = DatabaseReference().OpenContactL(id);
       
   439 		CleanupStack::PushL(contactItem);	// contactItem
       
   440 		AddMatchingStringToContactL(*contactItem, uidInfo, desiredMatchingString);
       
   441 		DatabaseReference().CommitContactL(*contactItem);
       
   442 		DatabaseReference().CloseContactL(id);
       
   443 		CleanupStack::PopAndDestroy(contactItem);
       
   444 		}
       
   445 
       
   446 	CleanupStack::PopAndDestroy(2, &sortOrder);
       
   447 
       
   448 	}
       
   449 
       
   450 /**
       
   451  * Update contacts in database with desired string
       
   452  * This feature is useful while constructing Find Views, Sub Views etc..
       
   453  * @param aContact - Contact to be updated
       
   454  * @param aUid - uid of field in the contact item to be updated
       
   455  * @param aDesiredMatchingString - Matching string
       
   456  */
       
   457 void CPrepareDataTestStep::AddMatchingStringToContactL(CContactItem& aContact, TUid aUid, const TPtrC& aDesiredMatchingString)
       
   458 	{
       
   459 	CContactItemFieldSet& fieldSet = aContact.CardFields();
       
   460 	TInt pos = fieldSet.Find(aUid);
       
   461 	if(pos == KErrNotFound)
       
   462 		{
       
   463 		TFieldType fieldType = aUid;
       
   464 		TStorageType storageType = GetStorageType(fieldType);
       
   465 		CContentType* contentType = CContentType::NewL();
       
   466 		contentType->AddFieldTypeL(fieldType);
       
   467 		CContactItemField* field = 	CContactItemField::NewL(storageType, *contentType);
       
   468 		CleanupStack::PushL(field);
       
   469 		field->TextStorage()->SetTextL(aDesiredMatchingString);
       
   470 		aContact.AddFieldL(*field);
       
   471 		CleanupStack::Pop();	// field
       
   472 		}
       
   473 	else
       
   474 		{
       
   475 		CContactItemField& field = fieldSet[pos];
       
   476 		field.TextStorage()->SetTextL(aDesiredMatchingString);
       
   477 		}
       
   478 	}
       
   479 
       
   480 void CPrepareDataTestStep::UpdateContactToSpecificStringL()
       
   481 	{
       
   482 		_LIT(KListOfSetDesiredStringSections, "listofcontacttoupdate");
       
   483 		TPtrC listOfSections;
       
   484 		GetStringFromConfig(ConfigSection(), KListOfSetDesiredStringSections, listOfSections);
       
   485 
       
   486 		RArray<TPtrC>	listOfUpdateContact;
       
   487 		CleanupClosePushL(listOfUpdateContact);
       
   488 
       
   489 		ViewUtilityReference().TokenizeStringL(listOfSections, listOfUpdateContact);
       
   490 
       
   491 		for ( TInt i = 0; i < listOfUpdateContact.Count(); ++i )
       
   492 			{
       
   493 			UpdateContactFieldsToDesireStingL(listOfUpdateContact[i]);
       
   494 			}
       
   495 
       
   496 		CleanupStack::PopAndDestroy(&listOfUpdateContact);
       
   497 
       
   498 	}
       
   499 
       
   500 void CPrepareDataTestStep::UpdateContactFieldsToDesireStingL(const TPtrC& aMatchingStringSection)
       
   501 	{
       
   502 	_LIT(KViewSortOrder, "sortorder");
       
   503 	_LIT(KContactId, "contactid");
       
   504 	_LIT(KDesiredString, "desiredstring");
       
   505 
       
   506 	TPtrC viewSortOrderString;
       
   507 	GetStringFromConfig(aMatchingStringSection, KViewSortOrder, viewSortOrderString);
       
   508 
       
   509 	RContactViewSortOrder sortOrder = ViewUtilityReference().ConvertStringToSortOrderL(viewSortOrderString) ;
       
   510 	CleanupClosePushL(sortOrder);
       
   511 
       
   512 	TInt contactId;
       
   513 	GetIntFromConfig(aMatchingStringSection, KContactId, contactId);
       
   514 
       
   515 	TPtrC desiredSting;
       
   516 	GetStringFromConfig(aMatchingStringSection, KDesiredString, desiredSting);
       
   517 
       
   518 	RArray<TContactItemId> contactSpecificToSortOrder;
       
   519 	CleanupClosePushL(contactSpecificToSortOrder);
       
   520 
       
   521 	RetrieveContactsSpecificToSortOrderL(sortOrder, contactSpecificToSortOrder);
       
   522 	CContactItem* contactItem = DatabaseReference().OpenContactL(contactId);
       
   523 	CleanupStack::PushL(contactItem);
       
   524 
       
   525 	CContactItemFieldSet& fieldSet = contactItem->CardFields();
       
   526 
       
   527 	TInt firstContactFieldPosition = fieldSet.Find(sortOrder[0]);
       
   528 	TInt secondContactFieldPosition = fieldSet.Find(sortOrder[1]);
       
   529 	TInt thirdContactFieldPosition = fieldSet.Find(sortOrder[2]);
       
   530 
       
   531 	// Check whether they have content.
       
   532 	CContactItemField& field1 = fieldSet[firstContactFieldPosition];
       
   533 	CContactFieldStorage* firstStorage = field1.Storage();
       
   534 
       
   535 	CContactItemField& field2 = fieldSet[secondContactFieldPosition];
       
   536 	CContactFieldStorage* secondStorage = field2.Storage();
       
   537 
       
   538 	CContactItemField& field3 = fieldSet[thirdContactFieldPosition];
       
   539 	CContactFieldStorage* thirdStorage = field3.Storage();
       
   540 
       
   541 	field1.TextStorage()->SetTextL(desiredSting);
       
   542 	field2.TextStorage()->SetTextL(desiredSting);
       
   543 	field3.TextStorage()->SetTextL(desiredSting);
       
   544 
       
   545 	DatabaseReference().CommitContactL(*contactItem);
       
   546 	DatabaseReference().CloseContactL(contactId);
       
   547 
       
   548 	CleanupStack::PopAndDestroy(contactItem);
       
   549 	CleanupStack::PopAndDestroy(&contactSpecificToSortOrder);
       
   550 	CleanupStack::PopAndDestroy(&sortOrder);
       
   551 	}
       
   552 
       
   553