phonebookengines/contactsmodel/tsrc/Integration/CntPerfTest/src/TestContactViewCRUDOperationsStep.cpp
changeset 0 e686773b3f54
child 24 0ba2181d7c28
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 "TestContactViewCRUDOperationsStep.h"
       
    17 
       
    18 /**
       
    19  * Test Step Constructor
       
    20  */
       
    21 CTestContactViewCRUDOperationsStep::CTestContactViewCRUDOperationsStep()
       
    22 :CTestContactViewDatabaseUtilitiesStep()
       
    23 	{
       
    24 	// Mandatory call to base class method to set up the human readable name for logging.
       
    25 	SetTestStepName(KTestContactViewCRUDOperationsStep);
       
    26 	}
       
    27 
       
    28 /**
       
    29  * Test Step Destructor
       
    30  */
       
    31 CTestContactViewCRUDOperationsStep::~CTestContactViewCRUDOperationsStep()
       
    32 	{
       
    33 	iChunk.Close();
       
    34 	iThread.Close();
       
    35 	iSemaphore.Close();
       
    36 	}
       
    37 
       
    38 /**
       
    39  * Test Step preamble function, setups the environment required for the test step
       
    40  */
       
    41 TVerdict CTestContactViewCRUDOperationsStep::doTestStepPreambleL()
       
    42 	{
       
    43 	CTestContactViewDatabaseUtilitiesStep::doTestStepPreambleL();
       
    44 	iChunk.CreateGlobal(KChunkName(), sizeof(TBool) + sizeof(TPtrC), sizeof(TBool) + sizeof(TPtrC));
       
    45 	iChunk.OpenGlobal(KChunkName(), ETrue);
       
    46 	iExecutionCompleted = reinterpret_cast<TBool*>(iChunk.Base());
       
    47 	iCurrentOperation = sizeof(TBool) + reinterpret_cast<TPtrC*>(iChunk.Base());
       
    48 	*iExecutionCompleted = EFalse;
       
    49 	return TestStepResult();
       
    50 	}
       
    51 
       
    52 /**
       
    53  * Test Step postamble function, part of cleanup activity for the test step
       
    54  */
       
    55 TVerdict CTestContactViewCRUDOperationsStep::doTestStepPostambleL()
       
    56 	{
       
    57 	CTestContactViewDatabaseUtilitiesStep::doTestStepPostambleL();
       
    58 	return TestStepResult();
       
    59 	}
       
    60 
       
    61 /**
       
    62 * Base class pure virtual.
       
    63 * @return EPass or EFail indicating the result of the test step.
       
    64 */
       
    65 TVerdict CTestContactViewCRUDOperationsStep::doTestStepL()
       
    66 	{
       
    67 	// Share the current teststep logger across threads
       
    68 	Logger().ShareAuto();
       
    69 
       
    70 	// Starts a separate contact views thread and reumes the same
       
    71 	LaunchContactViewsThreadL();
       
    72 	ResumeContactViewsThreadL();
       
    73 
       
    74 	CreateContactItemsL();
       
    75 	UpdateContactItemsL();
       
    76 	RemoveContactItemsL();
       
    77 
       
    78 	// Mark the execution completed flag to true and thereby stop the contact views thread
       
    79 	SetExecutionCompleted();
       
    80 	ResumeContactViewsThreadL();
       
    81 	return TestStepResult();
       
    82 	}
       
    83 
       
    84 
       
    85 /**
       
    86 * Adds contact cards and groups in the database
       
    87 */
       
    88 void CTestContactViewCRUDOperationsStep::CreateContactItemsL()
       
    89 	{
       
    90 	_LIT(KAddContacts, "add");
       
    91 	TBool addContacts = EFalse;
       
    92 	GetBoolFromConfig(ConfigSection(), KAddContacts, addContacts);
       
    93 
       
    94 	if(!addContacts)
       
    95 		{
       
    96 		return;
       
    97 		}
       
    98 
       
    99 	// Add contacts and groups in the main thread and validate the view count and view notifications
       
   100 	// in the contact views thread
       
   101 	TPtrC currentOperation(KAddContactOperations);
       
   102 	SetCurrentOperation(currentOperation);
       
   103 	AddContactEntriesL();
       
   104 	CloseDatabaseL();
       
   105 	OpenDataBaseL();
       
   106 	ResumeContactViewsThreadL();
       
   107 	}
       
   108 
       
   109 /**
       
   110 * Updates contact cards and groups in the database
       
   111 */
       
   112 void CTestContactViewCRUDOperationsStep::UpdateContactItemsL()
       
   113 	{
       
   114 	_LIT(KUpdateContacts, "update");
       
   115 	TBool updateContacts = EFalse;
       
   116 	GetBoolFromConfig(ConfigSection(), KUpdateContacts, updateContacts);
       
   117 
       
   118 	if(!updateContacts)
       
   119 		{
       
   120 		return;
       
   121 		}
       
   122 
       
   123 
       
   124 	// Update contacts in the main thread and validate the view count and view notifications
       
   125 	// in the contact views thread
       
   126 	TPtrC currentOperation(KUpdateContactOperations);
       
   127 	SetCurrentOperation(currentOperation);
       
   128 	UpdateContactEntriesL();
       
   129 	CloseDatabaseL();
       
   130 	OpenDataBaseL();
       
   131 	ResumeContactViewsThreadL();
       
   132 	}
       
   133 
       
   134 /**
       
   135 * Deletes contact items in the database
       
   136 */
       
   137 void CTestContactViewCRUDOperationsStep::RemoveContactItemsL()
       
   138 	{
       
   139 	_LIT(KDeleteContacts, "delete");
       
   140 	TBool deleteContacts = EFalse;
       
   141 	GetBoolFromConfig(ConfigSection(), KDeleteContacts, deleteContacts);
       
   142 
       
   143 	if(!deleteContacts)
       
   144 		{
       
   145 		return;
       
   146 		}
       
   147 
       
   148 	// Delete Contacts in the main thread and validate the view count and view notifications
       
   149 	// in the contact views thread
       
   150 	TPtrC currentOperation(KRemoveContactsOperations);
       
   151 	SetCurrentOperation(currentOperation);
       
   152 	DeleteContactCardsL();
       
   153 	CloseDatabaseL();
       
   154 	OpenDataBaseL();
       
   155 	ResumeContactViewsThreadL();
       
   156 	}
       
   157 
       
   158 
       
   159 /*
       
   160 * Creates a Contact Views Thread. This thread constructs the desired contact views
       
   161 * After every CRUD operation performed on the database, the contact views thread
       
   162 * validates the updated view count and view notifications
       
   163 */
       
   164 void CTestContactViewCRUDOperationsStep::LaunchContactViewsThreadL()
       
   165 	{
       
   166 
       
   167 	TInt error = iSemaphore.CreateGlobal(KSemaphoreName, 0);
       
   168 
       
   169 	if (error == KErrAlreadyExists || error == KErrNone)
       
   170 		{
       
   171 		iSemaphore.OpenGlobal(KSemaphoreName);
       
   172 		}
       
   173 	else
       
   174 		{
       
   175 		User::Leave(error);
       
   176 		}
       
   177 
       
   178 	HBufC* contactViewsThread = HBufC::NewLC(SharedConstants::KMaxBufferLength);
       
   179 	TPtr contactViewsThreadHandle = contactViewsThread->Des();
       
   180 
       
   181 	SetRandomAlphaString(contactViewsThreadHandle, SharedConstants::KMaxBufferLength);
       
   182     User::LeaveIfError( iThread.Create(contactViewsThreadHandle, RunContactViewsThreadL, KDefaultStackSize, NULL, this, EOwnerProcess));
       
   183     _LIT(KInfoContactsViewThread, "The contact views thread was created successfully");
       
   184    	INFO_PRINTF1(KInfoContactsViewThread);
       
   185 
       
   186 	CleanupStack::PopAndDestroy(contactViewsThread);
       
   187 
       
   188 	}
       
   189 
       
   190 /**
       
   191 * Resumes the contact views thread
       
   192 */
       
   193 void CTestContactViewCRUDOperationsStep::ResumeContactViewsThreadL()
       
   194 	{
       
   195 	iThread.Resume();
       
   196 	iSemaphore.Wait();
       
   197 	}
       
   198 
       
   199 /**
       
   200 * New contact entries are added in the database. The newly added contacts can have fields that meet the sort order
       
   201 * of some existing views, With the addition of such contact fields, the existing views needs resorting. The newly added
       
   202 * fields may also meet the filter criteria of some existing views. This is useful while testing filtered views
       
   203 * The new added contacts can have fields with some predefined string content, this is useful in case of Find Views and Sub Views.
       
   204 */
       
   205 void CTestContactViewCRUDOperationsStep::AddContactEntriesL()
       
   206 	{
       
   207 	_LIT(KViewSortOrder, "SortOrder");
       
   208 	TPtrC viewSortOrderString;
       
   209 	GetStringFromConfig(ConfigSection(), KViewSortOrder, viewSortOrderString);
       
   210 
       
   211 	RContactViewSortOrder sortOrder = ViewUtilityReference().ConvertStringToSortOrderL(viewSortOrderString);
       
   212 	CleanupClosePushL(sortOrder);
       
   213 
       
   214 	_LIT(KNumOfContactsToBeAdded, "NumOfContactsToBeAdded");
       
   215 	TInt numOfContactsToBeAdded;
       
   216 	GetIntFromConfig(ConfigSection(), KNumOfContactsToBeAdded, numOfContactsToBeAdded);
       
   217 
       
   218 
       
   219 	for(TInt i = 0; i < numOfContactsToBeAdded; ++i)
       
   220 		{
       
   221 		CContactCard* contactCard = CContactCard::NewL();
       
   222 		CleanupStack::PushL(contactCard);
       
   223 		AddContactFieldL(*contactCard, sortOrder);
       
   224 
       
   225 		TBool filterBasedFields;
       
   226 		_LIT(KFilterBasedFields, "FilterBasedFields");
       
   227 		GetBoolFromConfig(ConfigSection(), KFilterBasedFields, filterBasedFields);
       
   228 		if(filterBasedFields)
       
   229 			{
       
   230 			AddFieldsSpecificToFilterL(*contactCard);
       
   231 			}
       
   232 
       
   233 		TBool contactsWithDesiredString;
       
   234 		_LIT(KContactsWithDesiredString, "ContactsWithDesiredString");
       
   235 		GetBoolFromConfig(ConfigSection(), KContactsWithDesiredString, contactsWithDesiredString);
       
   236 		if(contactsWithDesiredString)
       
   237 			{
       
   238 			AddMatchingStringToContactL(*contactCard);
       
   239 			}
       
   240 
       
   241 
       
   242 		TContactItemId contactId = DatabaseReference().AddNewContactL(*contactCard);
       
   243 
       
   244 		TPtrC addContactToGroup;
       
   245 		_LIT(KAddContactToGroup, "grouplist");
       
   246 		GetStringFromConfig(ConfigSection(), KAddContactToGroup, addContactToGroup);
       
   247 		if(addContactToGroup != KNullDesC)
       
   248 			{
       
   249 			IterateThroAllGroupSectionsAndUpdateContactL(addContactToGroup, *contactCard);
       
   250 			}
       
   251 
       
   252 		CleanupStack::PopAndDestroy();// contactCard
       
   253 		DatabaseReference().CloseContactL(contactId);
       
   254 		}
       
   255 	CleanupStack::PopAndDestroy(); // sortOrder
       
   256 	}
       
   257 
       
   258 /**
       
   259 * Add fields that meet some desired sort order
       
   260 * @param aContact - Contact to be updated woth desired fields
       
   261 * @param aSortOrder - specifies information about the desired fields
       
   262 */
       
   263 void CTestContactViewCRUDOperationsStep::AddContactFieldL(CContactItem& aContact,
       
   264 															 const RContactViewSortOrder& aSortOrder)
       
   265 	{
       
   266 	const TInt KMaxSortOrderCount = 3;
       
   267 	for(TInt i = 0; i < KMaxSortOrderCount; ++i)
       
   268 		{
       
   269 		TFieldType fieldType = aSortOrder[i];
       
   270 		TStorageType storageType = GetStorageType(fieldType);
       
   271 		CContentType* contentType = CContentType::NewL();
       
   272 		CleanupStack::PushL(contentType);
       
   273 		contentType->AddFieldTypeL(fieldType);
       
   274 		CContactItemField* field = 	CContactItemField::NewL(storageType, *contentType);
       
   275 		CleanupStack::PushL(field);
       
   276 		SetDataL(fieldType, *field);
       
   277 		aContact.AddFieldL(*field);
       
   278 		CleanupStack::Pop(field);
       
   279 		CleanupStack::PopAndDestroy(contentType);
       
   280 		}
       
   281 	}
       
   282 
       
   283 /**
       
   284  * Adds contact fields to the contact, as per the desired contact view filter
       
   285  */
       
   286 void CTestContactViewCRUDOperationsStep::AddFieldsSpecificToFilterL(CContactItem& aContact)
       
   287 	{
       
   288 	_LIT(KDesiredFilterString, "desiredFilter");
       
   289 	TPtrC desiredFilterString;
       
   290 	GetStringFromConfig(ConfigSection(), KDesiredFilterString, desiredFilterString);
       
   291 	CContactDatabase::TContactViewFilter	viewFilter = ViewUtilityReference().GetContactViewFilterL(desiredFilterString);
       
   292 	AddFilterBasedFieldsL(aContact, viewFilter);
       
   293 	}
       
   294 
       
   295 /**
       
   296  * Updates the specified contact items with desired matching string
       
   297  */
       
   298 
       
   299 void CTestContactViewCRUDOperationsStep::AddMatchingStringToContactL(CContactItem& aContact)
       
   300 	{
       
   301 	_LIT(KDesiredMatchingString, "matchingstring");
       
   302 	TPtrC desiredMatchingString;
       
   303 	GetStringFromConfig(ConfigSection(), KDesiredMatchingString, desiredMatchingString);
       
   304 
       
   305 	_LIT(KDesiredContactField, "contactfield");
       
   306 	TPtrC desiredContactField;
       
   307 	GetStringFromConfig(ConfigSection(), KDesiredContactField, desiredContactField);
       
   308 
       
   309 	TUid uidInfo = GetContactFieldType(desiredContactField);
       
   310 
       
   311 	CContactItemFieldSet& fieldSet = aContact.CardFields();
       
   312 	TInt pos = fieldSet.Find(uidInfo);
       
   313 	if(pos == KErrNotFound)
       
   314 		{
       
   315 		TFieldType fieldType = uidInfo;
       
   316 		TStorageType storageType = GetStorageType(fieldType);
       
   317 		CContentType* contentType = CContentType::NewL();
       
   318 		CleanupStack::PushL(contentType);
       
   319 
       
   320 		contentType->AddFieldTypeL(fieldType);
       
   321 		CContactItemField* field = 	CContactItemField::NewL(storageType, *contentType);
       
   322 		CleanupStack::PushL(field);
       
   323 		field->TextStorage()->SetTextL(desiredMatchingString);
       
   324 		aContact.AddFieldL(*field);
       
   325 		CleanupStack::Pop(field);
       
   326 
       
   327 		CleanupStack::PopAndDestroy(contentType);
       
   328 		}
       
   329 	else
       
   330 		{
       
   331 		CContactItemField& field = fieldSet[pos];
       
   332 		field.TextStorage()->SetTextL(desiredMatchingString);
       
   333 		}
       
   334 	}
       
   335 
       
   336 /**
       
   337  * Updates the specified number of contact items from the database
       
   338  */
       
   339 void CTestContactViewCRUDOperationsStep::UpdateContactEntriesL()
       
   340 	{
       
   341 	_LIT(KNumOfContactsToBeUpdated, "NumOfContactsToBeUpdated");
       
   342 	TInt numOfContactToBeUpdated;
       
   343 	GetIntFromConfig(ConfigSection(), KNumOfContactsToBeUpdated, numOfContactToBeUpdated);
       
   344 
       
   345 	TPtrC deleteContactInGroups;
       
   346 	_LIT(KDeleteContactInGroups, "grouplist");
       
   347 	GetStringFromConfig(ConfigSection(), KDeleteContactInGroups, deleteContactInGroups);
       
   348 
       
   349 
       
   350 	if(deleteContactInGroups != KNullDesC)
       
   351 		{
       
   352 		UpdateContactsInGroupL(numOfContactToBeUpdated, deleteContactInGroups);
       
   353 		}
       
   354 	else
       
   355 		{
       
   356 		CCntFilter* filter = CCntFilter::NewL();
       
   357 		CleanupStack::PushL(filter);
       
   358 		filter->SetContactFilterTypeCard(ETrue);
       
   359 		DatabaseReference().FilterDatabaseL(*filter);
       
   360 
       
   361 		for(TInt i = 0; i < numOfContactToBeUpdated; ++i)
       
   362 			{
       
   363 			TContactItemId contactItemId = (*filter->iIds)[i];
       
   364 			CContactItem* contactItem = DatabaseReference().ReadContactL(contactItemId);
       
   365 			CleanupStack::PushL(contactItem);
       
   366 			UpdateFieldsL(*contactItem);
       
   367 			CContactItem* updatedContactItem = DatabaseReference().UpdateContactLC(contactItemId, contactItem);
       
   368 			CleanupStack::PopAndDestroy(updatedContactItem);
       
   369 			CleanupStack::PopAndDestroy(contactItem);
       
   370 			}
       
   371 
       
   372 		CleanupStack::PopAndDestroy(filter);
       
   373 		}
       
   374 	}
       
   375 
       
   376 /**
       
   377  * Deletes the specified number of contact cards from the database
       
   378  */
       
   379 void CTestContactViewCRUDOperationsStep::DeleteContactCardsL()
       
   380 	{
       
   381 	_LIT(KNumOfContactsToBeDeleted, "NumOfContactsToBeDeleted");
       
   382 	TInt numOfContactsToBeDeleted;
       
   383 	GetIntFromConfig(ConfigSection(), KNumOfContactsToBeDeleted, numOfContactsToBeDeleted);
       
   384 
       
   385 
       
   386 	TPtrC deleteContactInGroups;
       
   387 	_LIT(KDeleteContactInGroups, "grouplist");
       
   388 	GetStringFromConfig(ConfigSection(), KDeleteContactInGroups, deleteContactInGroups);
       
   389 
       
   390 	if(deleteContactInGroups != KNullDesC)
       
   391 		{
       
   392 		DeleteContactsInGroupL(numOfContactsToBeDeleted, deleteContactInGroups);
       
   393 		}
       
   394 	else
       
   395 		{
       
   396 		CCntFilter* filter = CCntFilter::NewL();
       
   397 		CleanupStack::PushL(filter);
       
   398 		filter->SetContactFilterTypeCard(ETrue);
       
   399 		DatabaseReference().FilterDatabaseL(*filter);
       
   400 
       
   401 		for(TInt i = 0; i < numOfContactsToBeDeleted; ++i)
       
   402 			{
       
   403 			TContactItemId contactItemId = (*filter->iIds)[i];
       
   404 			DatabaseReference().DeleteContactL(contactItemId);
       
   405 			}
       
   406 
       
   407 		CleanupStack::PopAndDestroy(filter);
       
   408 		}
       
   409 	}
       
   410 
       
   411 
       
   412 
       
   413 /**
       
   414 * Sets the program completion flag to True, thereby enables the
       
   415 * contact views thread to release all its resources
       
   416 */
       
   417 void CTestContactViewCRUDOperationsStep::SetExecutionCompleted()
       
   418 	{
       
   419 	*iExecutionCompleted = ETrue;
       
   420 	}
       
   421 
       
   422 /*
       
   423 * Sets information about the current operation being performed
       
   424 * This information is used by the contact views thread to validate the
       
   425 * view count and view notifications at the end of each CRUD Operations
       
   426 */
       
   427 void CTestContactViewCRUDOperationsStep::SetCurrentOperation
       
   428 		(TPtrC aCurrentOperation)
       
   429 	{
       
   430 	(*iCurrentOperation).Set(aCurrentOperation);
       
   431 	}
       
   432 
       
   433 
       
   434 /* In this section, we edit the desired number of groups in the database
       
   435  * Set label for them and associate them with contacts
       
   436  @ param aGroupSection - Desired Group Name
       
   437  @ param aContact - Contact to be updated
       
   438  */
       
   439 void CTestContactViewCRUDOperationsStep::IterateThroAllGroupSectionsAndUpdateContactL(const TPtrC& aGroupSection,
       
   440 																									 CContactCard& aContact)
       
   441 	{
       
   442 	RArray<TPtrC>	listOfGroupsSections;
       
   443 	CleanupClosePushL(listOfGroupsSections);
       
   444 	ViewUtilityReference().TokenizeStringL(aGroupSection, listOfGroupsSections);
       
   445 
       
   446 	for ( TInt i = 0; i < listOfGroupsSections.Count(); ++i )
       
   447 		{
       
   448 		CCntFilter* filter = CCntFilter::NewL();
       
   449 		CleanupStack::PushL(filter);
       
   450 		filter->SetContactFilterTypeGroup(ETrue);
       
   451 		DatabaseReference().FilterDatabaseL(*filter);
       
   452 
       
   453 		for ( TInt i = 0; i < filter->iIds->Count(); ++i )
       
   454 			{
       
   455 			TContactItemId groupId = (*filter->iIds)[i];
       
   456 			CContactItem* group = DatabaseReference().OpenContactL(groupId);
       
   457 			CContactGroup* newGroup = static_cast<CContactGroup*>(group);
       
   458 			if(aGroupSection.Compare(newGroup->GetGroupLabelL())  == 0)
       
   459 				{
       
   460 				TRAP_IGNORE(DatabaseReference().RemoveContactFromGroupL(aContact, *newGroup));
       
   461 				TRAP_IGNORE(DatabaseReference().AddContactToGroupL(aContact, *newGroup));
       
   462 				DatabaseReference().CommitContactL(*group);
       
   463 				const CContactIdArray* listOfContacts = newGroup->ItemsContained();
       
   464 				const TInt count = listOfContacts->Count();
       
   465 				delete listOfContacts;
       
   466 				DatabaseReference().CloseContactL(groupId);
       
   467 				break;
       
   468 				}
       
   469 			DatabaseReference().CloseContactL(groupId);
       
   470 			}
       
   471 
       
   472     	CleanupStack::PopAndDestroy(filter);
       
   473 		}
       
   474 
       
   475 	CleanupStack::PopAndDestroy(&listOfGroupsSections);
       
   476 	}
       
   477 
       
   478 /* In this section, we edit the desired number of groups in the database
       
   479  * Set label for them and associate them with contacts
       
   480  @ param aGroupSection - Desired Group Name
       
   481  @ param aContact - Contact to be updated
       
   482  */
       
   483 void CTestContactViewCRUDOperationsStep::DeleteContactsInGroupL(const TInt aNumberOfContactsToBeUpdated, const TPtrC& aGroupSection)
       
   484 	{
       
   485 	RArray<TPtrC>	listOfGroupsSections;
       
   486 	CleanupClosePushL(listOfGroupsSections);
       
   487 	ViewUtilityReference().TokenizeStringL(aGroupSection, listOfGroupsSections);
       
   488 
       
   489 	for ( TInt i = 0; i < listOfGroupsSections.Count(); ++i )
       
   490 		{
       
   491 		CCntFilter* filter = CCntFilter::NewL();
       
   492 		CleanupStack::PushL(filter);
       
   493 		filter->SetContactFilterTypeGroup(ETrue);
       
   494 		DatabaseReference().FilterDatabaseL(*filter);
       
   495 
       
   496 		for ( TInt i = 0; i < filter->iIds->Count(); ++i )
       
   497 			{
       
   498 			TContactItemId groupId = (*filter->iIds)[i];
       
   499 			CContactItem* group = DatabaseReference().OpenContactL(groupId);
       
   500 			CContactGroup* newGroup = static_cast<CContactGroup*>(group);
       
   501 
       
   502 
       
   503 			if(aGroupSection.Compare(newGroup->GetGroupLabelL())  == 0)
       
   504 				{
       
   505 				const CContactIdArray* listOfContacts = newGroup->ItemsContained();
       
   506 				for(TInt i(0); i < aNumberOfContactsToBeUpdated; i++)
       
   507 					{
       
   508 					TRAP_IGNORE(DatabaseReference().DeleteContactL((*listOfContacts)[i]));
       
   509 					}
       
   510 				delete listOfContacts;
       
   511 				DatabaseReference().CloseContactL(groupId);
       
   512 				break;
       
   513 				}
       
   514 			DatabaseReference().CloseContactL(groupId);
       
   515 			}
       
   516 
       
   517     	CleanupStack::PopAndDestroy(filter);
       
   518 		}
       
   519 
       
   520 	CleanupStack::PopAndDestroy(&listOfGroupsSections);
       
   521 	}
       
   522 
       
   523 /* In this section, we edit the desired number of groups in the database
       
   524  * Set label for them and associate them with contacts
       
   525  @ param aGroupSection - Desired Group Name
       
   526  @ param aContact - Contact to be updated
       
   527  */
       
   528 void CTestContactViewCRUDOperationsStep::UpdateContactsInGroupL(const TInt aNumberOfContactsToBeUpdated, const TPtrC& aGroupSection)
       
   529 	{
       
   530 	RArray<TPtrC>	listOfGroupsSections;
       
   531 	CleanupClosePushL(listOfGroupsSections);
       
   532 	ViewUtilityReference().TokenizeStringL(aGroupSection, listOfGroupsSections);
       
   533 
       
   534 	for ( TInt i = 0; i < listOfGroupsSections.Count(); ++i )
       
   535 		{
       
   536 		CCntFilter* filter = CCntFilter::NewL();
       
   537 		CleanupStack::PushL(filter);
       
   538 		filter->SetContactFilterTypeGroup(ETrue);
       
   539 		DatabaseReference().FilterDatabaseL(*filter);
       
   540 
       
   541 		for ( TInt i = 0; i < filter->iIds->Count(); ++i )
       
   542 			{
       
   543 			TContactItemId groupId = (*filter->iIds)[i];
       
   544 			CContactItem* group = DatabaseReference().OpenContactL(groupId);
       
   545 			CContactGroup* newGroup = static_cast<CContactGroup*>(group);
       
   546 
       
   547 
       
   548 			if(aGroupSection.Compare(newGroup->GetGroupLabelL())  == 0)
       
   549 				{
       
   550 				const CContactIdArray* listOfContacts = newGroup->ItemsContained();
       
   551 				for(TInt i(0); i < aNumberOfContactsToBeUpdated; i++)
       
   552 					{
       
   553 					TContactItemId contactItemId = (*listOfContacts)[i];
       
   554 					CContactItem* contactItem = DatabaseReference().ReadContactL(contactItemId);
       
   555 					CleanupStack::PushL(contactItem);
       
   556 					UpdateFieldsL(*contactItem);
       
   557 					CContactItem* updatedContactItem = DatabaseReference().UpdateContactLC(contactItemId, contactItem);
       
   558 					CleanupStack::PopAndDestroy(updatedContactItem);
       
   559 					CleanupStack::PopAndDestroy(contactItem);
       
   560 					}
       
   561 				delete listOfContacts;
       
   562 				DatabaseReference().CloseContactL(groupId);
       
   563 				break;
       
   564 				}
       
   565 			DatabaseReference().CloseContactL(groupId);
       
   566 			}
       
   567 
       
   568     	CleanupStack::PopAndDestroy(filter);
       
   569 		}
       
   570 
       
   571 	CleanupStack::PopAndDestroy(&listOfGroupsSections);
       
   572 	}
       
   573 
       
   574 
       
   575