phonebookengines/contactsmodel/tsrc/Integration/PerfFuncSuite/src/CRUDOOMStep.cpp
changeset 0 e686773b3f54
child 24 0ba2181d7c28
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2006-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 // These are all out of memory tests.
       
    15 // Call api first in order that all lazy initializations take place
       
    16 // check heap balance is maintained for client side tests
       
    17 // make sure all failures result only in KErrNoMemory only.
       
    18 // 
       
    19 //
       
    20 
       
    21 /**
       
    22  @file 
       
    23  @publishedAll
       
    24  @released
       
    25 */
       
    26 
       
    27 #include "CRUDOOMStep.h"
       
    28 #include "PerformanceFunctionalityDefs.h"
       
    29 
       
    30 _LIT(KRun1,"Read");
       
    31 _LIT(KRun2,"Open");
       
    32 _LIT(KRun3,"Delete");
       
    33 _LIT(KRun4,"Add");
       
    34 _LIT(KRun5,"Close");
       
    35 _LIT(KRun6,"Commit");
       
    36 _LIT(KRun7,"Update");
       
    37 _LIT(KRun8,"ViewsRemote");
       
    38 _LIT(KRun9,"ViewsLocal");
       
    39 _LIT(KRun10,"ViewsLocalFS");
       
    40 
       
    41 _LIT(KTest1, "Read test");
       
    42 _LIT(KTest2, "Open test");
       
    43 _LIT(KTest3, "Delete test");
       
    44 _LIT(KTest4, "Add contact test");
       
    45 _LIT(KTest5, "Close contact test");
       
    46 _LIT(KTest6, "Commit contact test");
       
    47 _LIT(KTest7, "Update contact test");
       
    48 _LIT(KTest8, "Remote View test");
       
    49 _LIT(KTest9, "Local View test");
       
    50 
       
    51 _LIT(KView, "Views");
       
    52 
       
    53 _LIT(KStars,"***************************");
       
    54 
       
    55 const static TInt KNumberOfContacts = 10;
       
    56 
       
    57 const static TInt32 KExistingUidsArray[] = 
       
    58 	{
       
    59 	KUidContactFieldAddressValue,
       
    60 	KUidContactFieldPostOfficeValue,
       
    61 	KUidContactFieldExtendedAddressValue,
       
    62 	KUidContactFieldLocalityValue,
       
    63 	KUidContactFieldRegionValue,
       
    64 	KUidContactFieldPostCodeValue,
       
    65 	KUidContactFieldCountryValue,
       
    66 	KUidContactFieldCompanyNameValue,
       
    67 	KUidContactFieldCompanyNamePronunciationValue,
       
    68 	KUidContactFieldPhoneNumberValue,
       
    69 	KUidContactFieldGivenNameValue,
       
    70 	KUidContactFieldFamilyNameValue,
       
    71 	KUidContactFieldGivenNamePronunciationValue,
       
    72 	KUidContactFieldFamilyNamePronunciationValue,
       
    73 	KUidContactFieldAdditionalNameValue,
       
    74 	KUidContactFieldSuffixNameValue,
       
    75 	KUidContactFieldPrefixNameValue,
       
    76 	KUidContactFieldHiddenValue,
       
    77 	KUidContactFieldEMailValue,
       
    78 	KUidContactFieldMsgValue,
       
    79 	KUidContactFieldSmsValue,
       
    80 	KUidContactFieldFaxValue,
       
    81 	KUidContactFieldDefinedTextValue,
       
    82 	KUidContactFieldNoteValue,
       
    83 	KUidContactFieldBirthdayValue,
       
    84 	KUidContactFieldUrlValue,
       
    85 	KUidContactFieldStorageInlineValue,
       
    86 	KUidContactFieldTemplateLabelValue,
       
    87 	KUidContactFieldPictureValue,
       
    88 	KUidContactFieldRingToneValue,
       
    89 	KUidContactFieldDTMFValue,
       
    90 	KUidContactsVoiceDialFieldValue,
       
    91 	KUidContactFieldNoneValue,
       
    92 	KUidContactFieldJobTitleValue,
       
    93 	KUidContactFieldICCSlotValue,
       
    94 	KUidContactFieldICCPhonebookValue,
       
    95 	KUidContactFieldICCGroupValue,
       
    96 	KUidContactFieldIMAddressValue,
       
    97 	KUidContactFieldSecondNameValue,
       
    98 	KUidContactFieldSIPIDValue,
       
    99 	KIntContactFieldVCardMapWORK,
       
   100 	KIntContactFieldVCardMapHOME,
       
   101 	KIntContactFieldVCardMapMSG,
       
   102 	KIntContactFieldVCardMapVOICE,
       
   103 	KIntContactFieldVCardMapFAX,
       
   104 	KIntContactFieldVCardMapPREF,
       
   105 	KIntContactFieldVCardMapCELL,
       
   106 	KIntContactFieldVCardMapPAGER,
       
   107 	KIntContactFieldVCardMapBBS,
       
   108 	KIntContactFieldVCardMapMODEM,
       
   109 	KIntContactFieldVCardMapCAR,
       
   110 	KIntContactFieldVCardMapISDN,
       
   111 	KIntContactFieldVCardMapVIDEO,
       
   112 	KIntContactFieldVCardMapDOM,
       
   113 	KIntContactFieldVCardMapADR,
       
   114 	KIntContactFieldVCardMapPOSTOFFICE,
       
   115 	KIntContactFieldVCardMapEXTENDEDADR,
       
   116 	KIntContactFieldVCardMapLOCALITY,
       
   117 	KIntContactFieldVCardMapREGION,
       
   118 	KIntContactFieldVCardMapPOSTCODE,
       
   119 	KIntContactFieldVCardMapCOUNTRY,
       
   120 	KIntContactFieldVCardMapAGENT,
       
   121 	KIntContactFieldVCardMapBDAY,
       
   122 	KIntContactFieldVCardMapEMAILINTERNET,
       
   123 	KIntContactFieldVCardMapGEO,
       
   124 	KIntContactFieldVCardMapLABEL,
       
   125 	KIntContactFieldVCardMapLOGO,
       
   126 	KIntContactFieldVCardMapMAILER,
       
   127 	KIntContactFieldVCardMapNOTE,
       
   128 	KIntContactFieldVCardMapORG,
       
   129 	KIntContactFieldVCardMapORGPronunciation,
       
   130 	KIntContactFieldVCardMapPHOTO,
       
   131 	KIntContactFieldVCardMapROLE,
       
   132 	KIntContactFieldVCardMapSOUND,
       
   133 	KIntContactFieldVCardMapTEL,
       
   134 	KIntContactFieldVCardMapTELFAX,
       
   135 	KIntContactFieldVCardMapTITLE,
       
   136 	KIntContactFieldVCardMapURL,
       
   137 	KIntContactFieldVCardMapUnusedN,
       
   138 	KIntContactFieldVCardMapUnusedFN,
       
   139 	KIntContactFieldVCardMapNotRequired,
       
   140 	KIntContactFieldVCardMapUnknownXDash,
       
   141 	KIntContactFieldVCardMapUnknown,
       
   142 	KIntContactFieldVCardMapUID,
       
   143 	KIntContactFieldVCardMapINTL,
       
   144 	KIntContactFieldVCardMapPOSTAL,
       
   145 	KIntContactFieldVCardMapPARCEL,
       
   146 	KIntContactFieldVCardMapGIF,
       
   147 	KIntContactFieldVCardMapCGM,
       
   148 	KIntContactFieldVCardMapWMF,
       
   149 	KIntContactFieldVCardMapBMP,
       
   150 	KIntContactFieldVCardMapMET,
       
   151 	KIntContactFieldVCardMapPMB,
       
   152 	KIntContactFieldVCardMapDIB,
       
   153 	KIntContactFieldVCardMapPICT,
       
   154 	KIntContactFieldVCardMapTIFF,
       
   155 	KIntContactFieldVCardMapPDF,
       
   156 	KIntContactFieldVCardMapPS,
       
   157 	KIntContactFieldVCardMapJPEG,
       
   158 	KIntContactFieldVCardMapMPEG,
       
   159 	KIntContactFieldVCardMapMPEG2,
       
   160 	KIntContactFieldVCardMapAVI,
       
   161 	KIntContactFieldVCardMapQTIME,
       
   162 	KIntContactFieldVCardMapTZ,
       
   163 	KIntContactFieldVCardMapKEY,
       
   164 	KIntContactFieldVCardMapX509,
       
   165 	KIntContactFieldVCardMapPGP,
       
   166 	KIntContactFieldVCardMapSMIME,
       
   167 	KIntContactFieldVCardMapWV,
       
   168 	KIntContactFieldVCardMapSECONDNAME,
       
   169 	KIntContactFieldVCardMapSIPID,
       
   170 	KIntContactFieldVCardMapPOC,
       
   171 	KIntContactFieldVCardMapSWIS,
       
   172 	KIntContactFieldVCardMapVOIP
       
   173 	};
       
   174 
       
   175 	
       
   176 CCRUDOOMStep::CCRUDOOMStep() 
       
   177 		: CPerformanceFunctionalityBase(KNumberOfContacts)
       
   178 	{
       
   179 	SetTestStepName(KCRUDOOMStep);
       
   180 	}
       
   181 
       
   182 void CCRUDOOMStep::PreTestL()
       
   183 	{
       
   184 	const TDesC &run = ConfigSection();//for views tests only use one contact, otherwise tests too slow
       
   185 	if( run.Find(KView) == 0 )
       
   186 		{
       
   187 		iContacts = 1;
       
   188 		}
       
   189 	}
       
   190 
       
   191 void CCRUDOOMStep::InitializeL()
       
   192 	{
       
   193 	CPerformanceFunctionalityBase::InitializeL();
       
   194 	iDestroyView = new (ELeave) CDestroyView( this );
       
   195 	CActiveScheduler::Add(iDestroyView);
       
   196 	}
       
   197 
       
   198 void CCRUDOOMStep::Cleanup()
       
   199 	{
       
   200 	CLEAR( iDestroyView );
       
   201 	CPerformanceFunctionalityBase::Cleanup();
       
   202 	}
       
   203 
       
   204 TVerdict CCRUDOOMStep::doTestStepL()
       
   205 /**
       
   206  * @return - TVerdict code
       
   207  * Override of base class pure virtual
       
   208  * Our implementation only gets called if the base class doTestStepPreambleL() did
       
   209  * not leave. That being the case, the current test result value will be EPass.
       
   210  */
       
   211 	{
       
   212 	__UHEAP_MARK;
       
   213 	InitializeL();
       
   214 	_LIT(KDostepPrint,"CCRUDOOMStep::doTestStepL()");
       
   215 	INFO_PRINTF1(KDostepPrint);
       
   216 	iIterate->Reset();
       
   217 	
       
   218 	const TDesC &run = ConfigSection();
       
   219 	_LIT(KFullContactOOMTest,"Full contacts OOM testing");
       
   220 	_LIT(KEmptyOOMTest,"Empty contacts OOM testing");
       
   221 	
       
   222 	//perform clientside and serverside testing when contacts are empty
       
   223 	if( run != KRun10 )
       
   224 		{
       
   225 		INFO_PRINTF1(KNullDesC);
       
   226 		INFO_PRINTF1(KStars);
       
   227 		INFO_PRINTF1(KEmptyOOMTest);
       
   228 		INFO_PRINTF1(KStars);
       
   229 		INFO_PRINTF1(KNullDesC);
       
   230 		RunAllTestsL(ETrue);
       
   231 		RunAllTestsL(EFalse);
       
   232 		}
       
   233 	
       
   234 	//perform clientside and serverside testing when contacts are full
       
   235 	INFO_PRINTF1(KNullDesC);
       
   236 	INFO_PRINTF1(KStars);
       
   237 	INFO_PRINTF1(KFullContactOOMTest);
       
   238 	INFO_PRINTF1(KStars);
       
   239 	INFO_PRINTF1(KNullDesC);
       
   240 	iIterate->Reset();
       
   241 	
       
   242 	TInt j = 0;
       
   243 	for(; j < iContacts; ++j)
       
   244 		{
       
   245 		OpenL(iIterate->NextL());
       
   246 		SetAllFieldsL( GetFieldL(KStringFields, KField, 2) );
       
   247 		CommitL(EFalse);
       
   248 		}
       
   249 	iIterate->Reset();	
       
   250 	if( run != KRun10 )
       
   251 		{
       
   252 		RunAllTestsL(ETrue);
       
   253 		}
       
   254 	if( run != KRun9 ) //with full contacts, localview serverside oom test is too slow, run as sperate step
       
   255 		{
       
   256 		RunAllTestsL(EFalse);
       
   257 		}
       
   258 	Cleanup();
       
   259 	__UHEAP_MARKEND;
       
   260 
       
   261 	return TestStepResult();
       
   262 	}
       
   263 /**
       
   264 If aClient is true perform client side OOM testing 
       
   265 Otherwise perform Serverside Heap testing
       
   266 */
       
   267 void CCRUDOOMStep::RunAllTestsL(const TBool aClient)
       
   268 	{
       
   269 	if(aClient)
       
   270 		{
       
   271 		_LIT(KClientOOM,"Clientside OOM testing");
       
   272 		INFO_PRINTF1(KClientOOM);
       
   273 		INFO_PRINTF1(KNullDesC);
       
   274 		}
       
   275 	else
       
   276 		{
       
   277 		INFO_PRINTF1(KNullDesC);
       
   278 		_LIT(KServerOOM,"Serverside OOM testing");
       
   279 		INFO_PRINTF1(KServerOOM);
       
   280 		INFO_PRINTF1(KNullDesC);
       
   281 		}
       
   282 	
       
   283 	const TDesC &run = ConfigSection();
       
   284 	
       
   285 	if( run == KRun1 )
       
   286 		{
       
   287 		ReadOOML(aClient);
       
   288 		}
       
   289 	else if( run == KRun2 )
       
   290 		{
       
   291 		OpenOOML(aClient);
       
   292 		}
       
   293 	else if( run == KRun3 )
       
   294 		{
       
   295 		DeleteOOML(aClient);
       
   296 		}
       
   297 	else if( run == KRun4 )
       
   298 		{
       
   299 		AddContactOOML(aClient);
       
   300 		}
       
   301 	else if( run == KRun5 )
       
   302 		{	
       
   303 		CloseContactOOML(aClient);
       
   304 		}
       
   305 	else if( run == KRun6 )
       
   306 		{
       
   307 		CommitContactOOML(aClient);
       
   308 		}
       
   309 	else if( run == KRun7 )
       
   310 		{
       
   311 		UpdateContactOOML(aClient);
       
   312 		}
       
   313 	else if( run == KRun8 )
       
   314 		{
       
   315 		INFO_PRINTF1(KTest8);
       
   316 		ViewOOMTestL(ETrue, aClient);
       
   317 		}
       
   318 	else if( run == KRun9 || run == KRun10 )
       
   319 		{
       
   320 		INFO_PRINTF1(KTest9);
       
   321 		ViewOOMTestL(EFalse, aClient);
       
   322 		}
       
   323 	else
       
   324 		{
       
   325 		MissingTestPanic();
       
   326 		}
       
   327 	}
       
   328 /**
       
   329 set heapmark and set heap failure to aFailAt
       
   330 performs testing on client or serverside
       
   331 */
       
   332 void CCRUDOOMStep::StartHeapCheck(const TInt aFailAt, const TBool aClient)
       
   333 	{
       
   334 	if( aClient)
       
   335 		{
       
   336 		__UHEAP_SETFAIL(RHeap::EDeterministic, aFailAt); // leavescan thinks this macro is a leaver but it isn't
       
   337 		__UHEAP_MARK;
       
   338 		}
       
   339 	else
       
   340 		{
       
   341 		iContactsDatabase->SetCntServerHeapFailure(RHeap::EDeterministic, aFailAt); //__UHEAP_SETFAIL
       
   342 		}
       
   343 	}
       
   344 
       
   345 
       
   346 /**
       
   347 reset heapmark and reset heap failure
       
   348 check that error receved from api failiure equals KErrNoMemory or there was no failiure
       
   349 performs checking on client or serverside
       
   350 */
       
   351 TBool CCRUDOOMStep::EndHeapCheckL(const TInt aErr, const TBool aClient)
       
   352 	{	
       
   353 	TBool ret = EFalse;
       
   354 	if( aClient)
       
   355 		{
       
   356 		__UHEAP_RESET;
       
   357 		RecoverL(aErr);
       
   358 		__UHEAP_MARKEND;
       
   359 		}
       
   360 	else
       
   361 		{
       
   362 		iContactsDatabase->SetCntServerHeapFailure(RHeap::ENone, 1);//__UHEAP_RESET
       
   363 		RecoverL(aErr);
       
   364 		}
       
   365 	TESTPRINT( ret = ( (KErrNoMemory == aErr) || (KErrNone == aErr) ) );
       
   366 	return ret;
       
   367 	}
       
   368 
       
   369 /**
       
   370 check value of received error and print relevant error message as necessary
       
   371 */
       
   372 void CCRUDOOMStep::ErrorProcess(const TInt aFailAt, const TInt aErr, 
       
   373 								const TBool aClient, const TBool aCleanup)
       
   374 	{
       
   375 	_LIT(KNonMemoryError,"iteration %d failed - non-memory error in OOM test: %d");
       
   376 	_LIT(KCleanupError,"iteration %d failed - cleanup error in OOM test");
       
   377 	if( aClient )
       
   378 		{
       
   379 		if( (KErrNoMemory != aErr) && (KErrNone != aErr)  )
       
   380 			{
       
   381 			ERR_PRINTF3(KNonMemoryError, aFailAt, aErr);
       
   382 			}
       
   383 		else
       
   384 			{
       
   385 			ERR_PRINTF2(KCleanupError, aFailAt);
       
   386 			}
       
   387 		}
       
   388 	else
       
   389 		{
       
   390 		if( (KErrNoMemory == aErr) || (KErrNone == aErr) )
       
   391 			{
       
   392 			if( aCleanup )
       
   393 				{
       
   394 				ERR_PRINTF2(KCleanupError, aFailAt);
       
   395 				}
       
   396 			else
       
   397 				{
       
   398 				_LIT(KHeapError,"iteration %d failed - server-heap imbalance error in OOM test");
       
   399 				ERR_PRINTF2(KHeapError, aFailAt);
       
   400 				}
       
   401 			}
       
   402 		else
       
   403 			{
       
   404 			ERR_PRINTF3(KNonMemoryError, aFailAt, aErr);
       
   405 			}
       
   406 		}
       
   407 	}
       
   408 
       
   409 /**
       
   410 recover database if it is damaged
       
   411 */
       
   412 void CCRUDOOMStep::RecoverL(const TInt aErr)
       
   413 	{
       
   414 	if( aErr != KErrNone )
       
   415 		{
       
   416 		if( iContactsDatabase->IsDamaged() )
       
   417 			{
       
   418 			iContactsDatabase->RecoverL();
       
   419 			}
       
   420 		}
       
   421 	}
       
   422 
       
   423 /**
       
   424 perform oom testing for read contact
       
   425 */
       
   426 void CCRUDOOMStep::ReadOOML(const TBool aClient)
       
   427 	{
       
   428 	INFO_PRINTF1(KTest1);
       
   429 	TBool ErrorCheckTest = EFalse;
       
   430 	TContactItemId cid = iIterate->NextL();
       
   431 	CContactItem *contactItem = NULL;
       
   432 	
       
   433 	//any lazy initialization should be performed here, so that it doesnt interfere with oom testing
       
   434 	ReadL( cid );
       
   435 	CloseL( EFalse );
       
   436 	iContactsDatabase->CompactL();
       
   437 	
       
   438 	TInt err = KErrNone;
       
   439 	TInt failAt = 0;
       
   440 	do
       
   441 		{
       
   442 		++failAt;
       
   443 		//set heap failure on client/server
       
   444 		StartHeapCheck(failAt, aClient);
       
   445 		
       
   446 		//perform read	
       
   447 		TRAP(err, contactItem = iContactsDatabase->ReadContactL( cid, *iViewAll ); );
       
   448 		
       
   449 		if (err == KErrNone)
       
   450 			{
       
   451 			CLEAR(contactItem);	
       
   452 			}
       
   453 		
       
   454 		//reset heap failure on client/server, check that there is no memory leak on client
       
   455 		TESTPRINTI( ErrorCheckTest = EndHeapCheckL(err, aClient), failAt);
       
   456 		
       
   457 		if(!ErrorCheckTest)
       
   458 			{
       
   459 			//if test failed print appropriate message
       
   460 			ErrorProcess(failAt, err, aClient, EFalse);
       
   461 			break;
       
   462 			}
       
   463 		}
       
   464 	while(err != KErrNone);
       
   465 	}
       
   466 
       
   467 
       
   468 /**
       
   469 perform oom testing for open contact
       
   470 */	
       
   471 void CCRUDOOMStep::OpenOOML(const TBool aClient)
       
   472 	{
       
   473 	INFO_PRINTF1(KTest2);
       
   474 	TBool ErrorCheckTest = EFalse;
       
   475 	TContactItemId cid = iIterate->NextL();
       
   476 	CContactItem *contactItem = NULL;
       
   477 	
       
   478 	//any lazy initialization should be performed here, so that it doesnt interfere with oom testing
       
   479 	OpenL( cid );
       
   480 	CloseL( ETrue );
       
   481 	iContactsDatabase->CompactL();
       
   482 	
       
   483 	TInt err = KErrNone;
       
   484 	TInt failAt = 0;
       
   485 	do
       
   486 		{
       
   487 		++failAt;
       
   488 		//set heap failure on client/server
       
   489 		StartHeapCheck(failAt, aClient);
       
   490 		
       
   491 		//perform open contact				
       
   492 		TRAP(err, contactItem = iContactsDatabase->OpenContactL( cid, *iViewAll ); );
       
   493 		
       
   494 		if (err == KErrNone)
       
   495 			{
       
   496 			CLEAR(contactItem);	
       
   497 			}
       
   498 		
       
   499 		
       
   500 		//reset heap failure on client/server, check that there is no memory leak on client	
       
   501 		TESTPRINTI( ErrorCheckTest = EndHeapCheckL(err, aClient), failAt );
       
   502 		
       
   503 		if(!ErrorCheckTest)
       
   504 			{
       
   505 			//if test failed print appropriate message
       
   506 			ErrorProcess(failAt, err, aClient, EFalse);
       
   507 			iIterate->RemoveL(cid);	
       
   508 			break;
       
   509 			}
       
   510 		}
       
   511 	while(err != KErrNone);
       
   512 	
       
   513 	iContactsDatabase->CloseContactL( cid );
       
   514 	}
       
   515 
       
   516 
       
   517 /**
       
   518 perform oom testing for delete contact
       
   519 */	
       
   520 void CCRUDOOMStep::DeleteOOML(const TBool aClient)
       
   521 	{
       
   522 	INFO_PRINTF1(KTest3);
       
   523 	TBool ErrorCheckAllTests 	= EFalse;
       
   524 	TBool ErrorCheckSingleTest 	= EFalse;
       
   525 	TBool cleanupError = EFalse;
       
   526 	TContactItemId cid = iIterate->NextL();
       
   527 	
       
   528 	//any lazy initialization should be performed here, so that it doesnt interfere with oom testing
       
   529 	DeleteContactL( cid, EFalse );
       
   530 	iContactsDatabase->CompactL();
       
   531 	
       
   532 	cid = iIterate->NextL();
       
   533 		
       
   534 	TInt err = KErrNone;
       
   535 	TInt failAt = 0;
       
   536 	
       
   537 	const TInt KInitialCount = iContactsDatabase->CountL();
       
   538 	
       
   539 	do
       
   540 		{
       
   541 		++failAt;
       
   542 		//set heap failure on client/server
       
   543 		StartHeapCheck(failAt, aClient);
       
   544 			
       
   545 		//perform delete contact	
       
   546 		TRAP(err, iContactsDatabase->DeleteContactL( cid ); );
       
   547 			
       
   548 		//reset heap failure on client/server, check that there is no memory leak on client	
       
   549 		TESTPRINTI( ErrorCheckSingleTest = EndHeapCheckL(err, aClient), failAt);
       
   550 		ErrorCheckAllTests = ErrorCheckSingleTest;
       
   551 		
       
   552 		if (err == KErrNone)
       
   553 			{
       
   554 			//if no error, check that contact was deleted
       
   555 			iIterate->RemoveL(cid);
       
   556 			//if initial count -1 doesn't equal number of contact, there is a cleanup error
       
   557 			cleanupError = ( (KInitialCount - 1) != iContactsDatabase->CountL() );
       
   558 			TESTPRINTI( ErrorCheckSingleTest = !cleanupError, failAt );	
       
   559 			ErrorCheckAllTests = ErrorCheckAllTests && ErrorCheckSingleTest;
       
   560 			}
       
   561 		else
       
   562 			{
       
   563 			//if error, check that contact wasn't deleted
       
   564 			cleanupError = ( KInitialCount != iContactsDatabase->CountL() );
       
   565 			TESTPRINTI( ErrorCheckSingleTest = !cleanupError , failAt );
       
   566 			ErrorCheckAllTests = ErrorCheckAllTests && ErrorCheckSingleTest;
       
   567 			}
       
   568 		if(!ErrorCheckAllTests)
       
   569 			{
       
   570 			//if checking error, print message, end test
       
   571 			ErrorProcess(failAt, err, aClient, cleanupError);
       
   572 			break;
       
   573 			}
       
   574 		}
       
   575 	while(err != KErrNone);
       
   576 	}
       
   577 
       
   578 
       
   579 /**
       
   580 perform oom testing for add contact
       
   581 */	
       
   582 void CCRUDOOMStep::AddContactOOML(const TBool aClient)
       
   583 	{
       
   584 	INFO_PRINTF1(KTest4);
       
   585 	TBool ErrorCheckAllTests 	= EFalse;
       
   586 	TBool ErrorCheckSingleTest 	= EFalse;
       
   587 	TBool cleanupError = EFalse;
       
   588 	TContactItemId cid = 0;
       
   589 		
       
   590 	TInt err = KErrNone;
       
   591 	TInt failAt = 0;
       
   592 	//any lazy initialization should be performed here, so that it doesnt interfere with oom testing
       
   593 	CContactCard* contact = CContactCard::NewLC(iTemplate);
       
   594 	iContactsDatabase->AddNewContactL(*contact);
       
   595 	iContactsDatabase->CompactL();
       
   596 	
       
   597 	const TInt KInitialCount = iContactsDatabase->CountL();
       
   598 	
       
   599 	do
       
   600 		{
       
   601 		++failAt;
       
   602 		//set heap failure on client/server
       
   603 		StartHeapCheck(failAt, aClient);
       
   604 				
       
   605 		//perform add contact
       
   606 		TRAP(err, cid = iContactsDatabase->AddNewContactL(*contact); );
       
   607 			
       
   608 		//reset heap failure on client/server, check that there is no memory leak on client	
       
   609 		TESTPRINTI( ErrorCheckSingleTest = EndHeapCheckL(err, aClient), failAt );
       
   610 		ErrorCheckAllTests = ErrorCheckSingleTest;
       
   611 
       
   612 		if (err == KErrNone)
       
   613 			{
       
   614 			//if no error, check that contact was added
       
   615 			iIterate->AddL(cid);
       
   616 			//if initial count + 1 doesn't equal number of contact, there is a cleanup error
       
   617 			cleanupError = ( ( KInitialCount + 1 ) != iContactsDatabase->CountL() );
       
   618 			TESTPRINTI( ErrorCheckSingleTest = !cleanupError, failAt );		
       
   619 			ErrorCheckAllTests = ErrorCheckAllTests && ErrorCheckSingleTest;
       
   620 			}
       
   621 		else
       
   622 			{
       
   623 			//if error, check that contact wasn't added
       
   624 			cleanupError = ( KInitialCount != iContactsDatabase->CountL() );
       
   625 			TESTPRINTI( ErrorCheckSingleTest = !cleanupError , failAt );	
       
   626 			ErrorCheckAllTests = ErrorCheckAllTests && ErrorCheckSingleTest;
       
   627 			}
       
   628 		if(!ErrorCheckAllTests)
       
   629 			{
       
   630 			//if checking error, print message, end test
       
   631 			ErrorProcess(failAt, err, aClient, cleanupError);
       
   632 			break;
       
   633 			}
       
   634 		}
       
   635 	while(err != KErrNone);
       
   636 	
       
   637 	CleanupStack::PopAndDestroy(contact);	
       
   638 	}
       
   639 
       
   640 
       
   641 /**
       
   642 perform oom testing for close contact
       
   643 */	
       
   644 void CCRUDOOMStep::CloseContactOOML(const TBool aClient)
       
   645 	{
       
   646 	INFO_PRINTF1(KTest5);
       
   647 	TBool ErrorCheckAllTests 	= EFalse;
       
   648 	TBool ErrorCheckSingleTest 	= EFalse;
       
   649 	TContactItemId cid = iIterate->NextL();
       
   650 	CContactItem *contactItem = NULL;
       
   651 	
       
   652 	//any lazy initialization should be performed here, so that it doesnt interfere with oom testing
       
   653 	OpenL( cid );
       
   654 	CloseL( ETrue );
       
   655 	iContactsDatabase->CompactL();
       
   656 	
       
   657 	contactItem = iContactsDatabase->OpenContactL( cid, *iViewAll );
       
   658 	CleanupStack::PushL(contactItem);
       
   659 	TInt err = KErrNone;
       
   660 	TInt failAt = 0;
       
   661 	do
       
   662 		{
       
   663 		++failAt;
       
   664 		//set heap failure on client/server
       
   665 		StartHeapCheck(failAt, aClient);
       
   666 			
       
   667 		//perform close contact
       
   668 		TRAP(err, iContactsDatabase->CloseContactL( cid )  );
       
   669 			
       
   670 		//reset heap failure on client/server, check that there is no memory leak on client	
       
   671 		TESTPRINTI( ErrorCheckSingleTest = EndHeapCheckL(err, aClient), failAt );
       
   672 		ErrorCheckAllTests = ErrorCheckSingleTest;
       
   673 		
       
   674 		if ( KErrNone != err )
       
   675 			{
       
   676 			//if close successful and contact still locked there is a cleanup error
       
   677 			TRAP(err, 	CContactItem *contact = iContactsDatabase->OpenContactL( cid, *iViewAll );
       
   678 						CLEAR(contact); 
       
   679 				);
       
   680 			TESTPRINTI( ErrorCheckSingleTest = (KErrInUse == err), failAt );
       
   681 			ErrorCheckAllTests = ErrorCheckAllTests && ErrorCheckSingleTest;
       
   682 			}
       
   683 		
       
   684 		if( !ErrorCheckAllTests )
       
   685 			{
       
   686 			//if checking error, print message, end test
       
   687 			ErrorProcess(failAt, err, aClient, EFalse);
       
   688 			iIterate->RemoveL(cid);
       
   689 			break;
       
   690 			}
       
   691 		}
       
   692 	while(err != KErrNone);
       
   693 	
       
   694 	iContactsDatabase->CloseContactL( cid );
       
   695 	CleanupStack::PopAndDestroy(contactItem);
       
   696 	contactItem = NULL;
       
   697 	}
       
   698 
       
   699 
       
   700 /**
       
   701 perform oom testing for commit contact
       
   702 */	
       
   703 void CCRUDOOMStep::CommitContactOOML(const TBool aClient)
       
   704 	{
       
   705 	INFO_PRINTF1(KTest6);
       
   706 	TBool ErrorCheckAllTests 	= EFalse;
       
   707 	TBool ErrorCheckSingleTest 	= EFalse;
       
   708 	TContactItemId cid = iIterate->NextL();
       
   709 	CContactItem *contactItem = NULL;
       
   710 	
       
   711 	//any lazy initialization should be performed here, so that it doesnt interfere with oom testing
       
   712 	OpenL( cid );
       
   713 	CommitL(EFalse);
       
   714 	iContactsDatabase->CompactL();//lazy initialization
       
   715 	
       
   716 	TInt err = KErrNone;
       
   717 	TInt failAt = 0;
       
   718 	do
       
   719 		{
       
   720 		++failAt;
       
   721 		
       
   722 		// test set-up (pre-condition)
       
   723 		// need to open the Contact in case Commit succeeds up to a check that the Contact is locked
       
   724 		contactItem = iContactsDatabase->OpenContactL( cid, *iViewAll );
       
   725 	
       
   726 		iContactItem = contactItem;
       
   727 		iFields = &(iContactItem->CardFields());
       
   728 		SetFieldL(1, GetFieldL(KStringFields, KField, 1) );
       
   729 		iContactItem = NULL;
       
   730 		iFields = NULL;
       
   731 		CleanupStack::PushL(contactItem);			
       
   732 		
       
   733 		//set heap failure on client/server
       
   734 		StartHeapCheck(failAt, aClient);
       
   735 			
       
   736 		//perform commit contact
       
   737 		TRAP(err, iContactsDatabase->CommitContactL( *contactItem )  );
       
   738 			
       
   739 		//reset heap failure on client/server, check that there is no memory leak on client	
       
   740 		TESTPRINTI( ErrorCheckSingleTest = EndHeapCheckL(err, aClient), failAt );
       
   741 		ErrorCheckAllTests = ErrorCheckSingleTest;
       
   742 		
       
   743 		if( KErrNone != err )
       
   744 			{
       
   745 			//if commit successful and contact not fully updated there is a cleanup error
       
   746 			ReadL( cid );
       
   747 			TESTPRINTI( ErrorCheckSingleTest = !CompareFieldL(1, GetFieldL(KStringFields, KField, 1) ), failAt );
       
   748 			ErrorCheckAllTests = ErrorCheckAllTests && ErrorCheckSingleTest;
       
   749 			CloseL( EFalse );
       
   750 			}
       
   751 		if(!ErrorCheckAllTests)
       
   752 			{
       
   753 			//if checking error, print message, end test
       
   754 			ErrorProcess(failAt, err, aClient, EFalse);
       
   755 			iIterate->RemoveL(cid);
       
   756 			break;
       
   757 			}
       
   758 			
       
   759 			
       
   760 		// test set-up (post-condition)
       
   761 		// Close the Contact so it can be re-Opened in the loop above
       
   762 		TRAP_IGNORE(iContactsDatabase->CloseContactL(cid));	
       
   763 		CleanupStack::PopAndDestroy(contactItem);	
       
   764 		}
       
   765 	while(err != KErrNone);
       
   766 	}
       
   767 
       
   768 
       
   769 /**
       
   770 perform oom testing for update contact
       
   771 */	
       
   772 void CCRUDOOMStep::UpdateContactOOML(const TBool aClient)
       
   773 	{
       
   774 	INFO_PRINTF1(KTest7);
       
   775 	TBool ErrorCheckAllTests 	= EFalse;
       
   776 	TBool ErrorCheckSingleTest 	= EFalse;
       
   777 	TContactItemId cid = iIterate->NextL();
       
   778 	TContactItemId cid2 = iIterate->NextL();
       
   779 	CContactItem *contactItem = NULL;
       
   780 	
       
   781 	//do initial update so that any lazy initialization is performed, so that it doesnt interfere with oom testing
       
   782 	contactItem = iContactsDatabase->ReadContactL( cid, *iViewAll );
       
   783 	CleanupStack::PushL(contactItem);
       
   784 	iContactsDatabase->UpdateContactLC( cid2, contactItem );
       
   785 	CleanupStack::PopAndDestroy();
       
   786 	CleanupStack::PopAndDestroy(contactItem);
       
   787 	contactItem = NULL;
       
   788 	//end initial update
       
   789 	iContactsDatabase->CompactL();//lazy initialization
       
   790 	
       
   791 	ReadL( cid );
       
   792 	
       
   793 	SetFieldL(1, GetFieldL(KStringFields, KField, 1) );
       
   794 		
       
   795 	TInt err = KErrNone;
       
   796 	TInt failAt = 0;
       
   797 	do
       
   798 		{
       
   799 		++failAt;
       
   800 		//set heap failure on client/server
       
   801 		StartHeapCheck(failAt, aClient);
       
   802 			
       
   803 		//perform update contact
       
   804 		TRAP(err, 
       
   805 				iContactsDatabase->UpdateContactLC( cid2, iContactItem );
       
   806 				CleanupStack::PopAndDestroy();  
       
   807 			);
       
   808 			
       
   809 		//reset heap failure on client/server, check that there is no memory leak on client	
       
   810 		TESTPRINTI( ErrorCheckSingleTest = EndHeapCheckL(err, aClient), failAt );
       
   811 		ErrorCheckAllTests = ErrorCheckSingleTest;
       
   812 		
       
   813 		if( KErrNone != err )
       
   814 			{
       
   815 			CloseL( EFalse );//close read contact
       
   816 			//if update successful and contact not fully updated there is a cleanup error
       
   817 			ReadL( cid2 );
       
   818 			TESTPRINTI( ErrorCheckSingleTest = !CompareFieldL(1, GetFieldL(KStringFields, KField, 1) ), failAt );
       
   819 			ErrorCheckAllTests = ErrorCheckAllTests && ErrorCheckSingleTest;
       
   820 			CloseL( EFalse );
       
   821 			ReadL( cid );
       
   822 			}
       
   823 		if( !ErrorCheckAllTests )
       
   824 			{
       
   825 			//if checking error, print message, end test
       
   826 			ErrorProcess(failAt, err, aClient, EFalse);
       
   827 			break;
       
   828 			}
       
   829 		}
       
   830 	while(err != KErrNone);
       
   831 	
       
   832 	CloseL( EFalse );
       
   833 	}
       
   834 
       
   835 void CCRUDOOMStep::HandleContactViewEvent(const CContactViewBase& /*aView*/,const TContactViewEvent& aEvent)
       
   836 	{
       
   837 	iEvent = TContactViewEvent( aEvent.iEventType, aEvent.iInt, aEvent.iContactId );
       
   838 	
       
   839 	switch( aEvent.iEventType )
       
   840 		{
       
   841 		case TContactViewEvent::EUnavailable:
       
   842 		case TContactViewEvent::ESortError:
       
   843 		case TContactViewEvent::EServerError:
       
   844 		case TContactViewEvent::EIndexingError:
       
   845 			{
       
   846 			iError = aEvent.iInt;
       
   847 			if( iError != KErrNoMemory )
       
   848 				{
       
   849 				_LIT(KEventPrint,"EventType: %d, Error: %d, ContactId: %d");
       
   850 				INFO_PRINTF4(KEventPrint, aEvent.iEventType, aEvent.iInt, aEvent.iContactId );
       
   851 				}
       
   852 			break;
       
   853 			}
       
   854 		default:
       
   855 			{
       
   856 			iError = KErrNone;
       
   857 			break;
       
   858 			}
       
   859 		}
       
   860 	iDestroyView->Activate();
       
   861 	}
       
   862 
       
   863 void CCRUDOOMStep::PopulateFullViewL(const TBool aRemote, RContactViewSortOrder& aSortOrder)
       
   864 	{
       
   865 	CContactDatabase *cntdb = CContactDatabase::OpenL();
       
   866 	CleanupStack::PushL(cntdb);
       
   867 	if(aRemote)
       
   868 		{
       
   869 		iView = CContactRemoteView::NewL(	*this, *cntdb, aSortOrder, EContactsOnly);
       
   870 		}
       
   871 	else
       
   872 		{
       
   873 		iView = CContactLocalView::NewL(	*this, *cntdb, aSortOrder, EContactsOnly);
       
   874 		}
       
   875 	CActiveScheduler::Start();
       
   876 	CleanupStack::PopAndDestroy( cntdb );
       
   877 	}
       
   878 
       
   879 /**
       
   880 perform oom testing for remote/local views
       
   881 */
       
   882 void CCRUDOOMStep::ViewOOMTestL(const TBool aRemote, const TBool aClient)
       
   883 	{
       
   884 	TBool ErrorCheckAllTests 	= EFalse;
       
   885 	const TInt length = ( sizeof KExistingUidsArray ) / ( sizeof KExistingUidsArray[0] );
       
   886 	TInt i = 0;
       
   887 	RContactViewSortOrder sortOrder = RContactViewSortOrder();
       
   888 	CleanupClosePushL( sortOrder );
       
   889 	for(i = 0 ; i < length ; ++i)
       
   890 		{
       
   891 		sortOrder.AppendL( TUid::Uid( KExistingUidsArray[i] ) );
       
   892 		}
       
   893 	
       
   894 	//any lazy initialization should be performed here, so that it doesnt interfere with oom testing
       
   895 	PopulateFullViewL(aRemote, sortOrder);
       
   896 	
       
   897 	TInt err = KErrNone;
       
   898 	TInt failAt = 0;
       
   899 	do
       
   900 		{
       
   901 		++failAt;
       
   902 		//set heap failure on client/server
       
   903 		StartHeapCheck(failAt, aClient);
       
   904 		//reset view population error
       
   905 		iError = KErrNone;	
       
   906 		
       
   907 		//create view and wait to populate
       
   908 		TRAP(err, 
       
   909 				PopulateFullViewL(aRemote, sortOrder); 
       
   910 			);
       
   911 			
       
   912 		//reset heap failure on client/server, check that there is no memory leak on client	
       
   913 		TESTPRINTI( ErrorCheckAllTests = EndHeapCheckL( ( err != KErrNone ) ? err : (err = iError), aClient), i);
       
   914 		
       
   915 		if(!ErrorCheckAllTests)
       
   916 			{
       
   917 			//if checking error, print message, end test
       
   918 			ErrorProcess(failAt, err, aClient, EFalse);
       
   919 			break;
       
   920 			}
       
   921 		}
       
   922 	while(err != KErrNone);	
       
   923 			
       
   924 	CleanupStack::PopAndDestroy();//sortorder
       
   925 	
       
   926 	CLEAR( iContactsDatabase );
       
   927 	WaitForServerToExitL();
       
   928 	iContactsDatabase = CContactDatabase::OpenL();
       
   929 	}
       
   930 
       
   931 /**
       
   932 Active object that destroys view on first run
       
   933 then stop active scheduler on second run.
       
   934 this allows any view cleanup operation to take place in the 
       
   935 active scheduler after the view is closed
       
   936 */
       
   937 void CCRUDOOMStep::CDestroyView::RunL()
       
   938 	{
       
   939 	iInitial = !iInitial;
       
   940 	if( iInitial )
       
   941 		{
       
   942 		iTest->iView->Close( *iTest );
       
   943 		iTest->iView = NULL;
       
   944 		Activate();
       
   945 		}
       
   946 	else
       
   947 		{
       
   948 		CActiveScheduler::Stop();
       
   949 		}
       
   950 	}
       
   951 
       
   952 void CCRUDOOMStep::CDestroyView::Activate()
       
   953 	{
       
   954 	TRequestStatus *pS=&iStatus;
       
   955 	User::RequestComplete(pS,KErrNone);
       
   956 	SetActive();
       
   957 	}
       
   958 	
       
   959 void CCRUDOOMStep::CDestroyView::DoCancel()
       
   960 	{
       
   961 	//nothing to clean up
       
   962 	}
       
   963