os/mm/mmlibs/mmfw/tsrc/mmfunittest/MidiClnt/TestStepMidiClntAllocFailOpen.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2004-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 // This file contains an example Test step implementation 
    15 // This demonstrates the various functions provided
    16 // by the CTestStep base class which are available within
    17 // a test step 
    18 // 
    19 //
    20 
    21 // EPOC includes
    22 #include <e32base.h>
    23 #include <e32test.h>
    24 #include <e32keys.h>
    25 #include <c32comm.h>
    26 #include <f32file.h>
    27 #include <etel.h>
    28 #include <etelmm.h>
    29 #include <testframework.h>
    30 
    31 // Test system includes
    32 #include <testframework.h>
    33 
    34 #include "TSU_MMFMIDICLNT.h"
    35 #include "TS_MMFMIDICLNTsuite.h"
    36 
    37 #include "TestStepMidiClntAllocFailOpen.h"
    38 
    39 // --------------------------------------------
    40 
    41 /**
    42  *
    43  * Static constructor for CTestStepMidiClntAllocFailOpenFile.
    44  *
    45  *
    46  * @return	"CTestStepMidiClntAllocFailOpenFile*"
    47  *			The constructed CTestStepMidiClntAllocFailOpenFile
    48  *
    49  * @xxxx
    50  * 
    51  */
    52 CTestStepMidiClntAllocFailOpenFile* CTestStepMidiClntAllocFailOpenFile::NewL(const TDesC& aTestName)
    53 	{
    54 	CTestStepMidiClntAllocFailOpenFile* self = new(ELeave) CTestStepMidiClntAllocFailOpenFile(aTestName);
    55 	return self;
    56 	}
    57 
    58 /**
    59  *
    60  * Test step constructor.
    61  * Each test step initialises its own name.
    62  *
    63  * @xxxx
    64  * 
    65  */
    66 CTestStepMidiClntAllocFailOpenFile::CTestStepMidiClntAllocFailOpenFile(const TDesC& aTestName)
    67 	{
    68 	// store the name of this test case
    69 	// this is the name that is used by the script file
    70 	iTestStepName = aTestName;
    71 	}
    72 
    73 /**
    74  *
    75  * Test step destructor.
    76  *
    77  * @xxxx
    78  * 
    79  */
    80 CTestStepMidiClntAllocFailOpenFile::~CTestStepMidiClntAllocFailOpenFile()
    81 	{
    82 	}
    83 
    84 
    85 /**
    86  *
    87  * Test step Preamble.
    88  *
    89  * @xxxx
    90  * 
    91  */
    92 TVerdict CTestStepMidiClntAllocFailOpenFile::DoTestStepPreambleL(void)
    93 	{
    94 	enum TVerdict verdict;
    95 	// This installs the scheduler
    96 	verdict = CTestMmfMidiClntStep::DoTestStepPreambleL();
    97 
    98 	//[ Printing to the console and log file ]
    99 	INFO_PRINTF1(iTestStepName);
   100 	INFO_PRINTF1(_L("This is a memory allocation failure test of CTestStepMidiClntAllocFailOpenFile"));
   101 	
   102 	if(!GetStringFromConfig(_L("SectionOne"), _L("filename"), iFileName))
   103 		{
   104 		verdict =  EInconclusive;
   105 		}
   106 		
   107 	//[ Create the MidiClientUtility ]
   108 	if ( (iMidiClnt = CMidiClientUtility::NewL(*this)) == NULL )
   109 		{
   110 		verdict = EInconclusive;
   111 		}
   112 
   113 	//[ Connect to File System using RFs ]
   114 	User::LeaveIfError(iFs.Connect());
   115 	User::LeaveIfError(iFs.ShareProtected());
   116 
   117 	//[ Open the file using RFile ]
   118 	INFO_PRINTF2(_L("Opening the file : %S"), &iFileName);
   119 	
   120 	TInt theRes = iFile.Open(iFs, iFileName, EFileRead);
   121 	if (theRes != KErrNone)
   122 		{
   123 		INFO_PRINTF2(_L("Errors in Opening the file : %S"), &iFileName);
   124 		User::Leave(theRes);
   125 		}
   126 		
   127 	return verdict;
   128 	}
   129 
   130 /**
   131  *
   132  * Test step Postamble.
   133  *
   134  * @xxxx
   135  * 
   136  */
   137 TVerdict CTestStepMidiClntAllocFailOpenFile::DoTestStepPostambleL(void)
   138 	{
   139 	//[ Create the MidiClientUtility ]
   140 	delete iMidiClnt;
   141 	iMidiClnt = NULL;
   142 	//[ Close Files ]
   143 	iFile.Close();
   144 	iFs.Close();
   145 	//[ Destroy the scheduler ]
   146 	return CTestMmfMidiClntStep::DoTestStepPostambleL();
   147 	}
   148 
   149 void CTestStepMidiClntAllocFailOpenFile::OpenFileAndStartSchedulerL()
   150 	{
   151 	iMidiClnt->OpenFile(iFileName);
   152 	CActiveScheduler::Start();
   153 	}
   154 
   155 void CTestStepMidiClntAllocFailOpenFile::OpenFileByHandleAndStartSchedulerL()
   156 	{
   157 	iMidiClnt->OpenFile(iFile);
   158 	CActiveScheduler::Start();
   159 	}
   160 
   161 
   162 /**
   163  *
   164  * Do the test step.
   165  * Each test step must supply an implementation for DoTestStepL.
   166  *
   167  * @return	"TVerdict"
   168  *			The result of the test step
   169  *
   170  * @xxxx
   171  * 
   172  */
   173 TVerdict CTestStepMidiClntAllocFailOpenFile::DoTestStepL()
   174 	{
   175 	//[ Initialise Class Variables ]
   176 	iTestStepResult = EPass;
   177 	
   178 	//[ Declare Local Variables ]
   179     TInt err       = KErrNone;
   180 	TInt failCount = 1;
   181 	TBool completed = EFalse;
   182 	TBool badResult = EFalse; 
   183 	TBool reachedEnd = EFalse; // Note: declare outside loop to help with debugging
   184 	TBool useFileHandle = EFalse;
   185 	
   186 	if(iTestStepName.Compare(_L("MM-MMF-MIDICLNT-U-1003")) == 0)
   187 		{
   188 		useFileHandle = ETrue;
   189 		}
   190 	
   191 	
   192 	//[ Start of main ALLOC test loop ]
   193 	for(;;)	
   194 		{
   195 		__UHEAP_SETFAIL(RHeap::EFailNext ,failCount);
   196 		__MM_HEAP_MARK;
   197 		
   198 		if(!useFileHandle)
   199 			{
   200 			TRAP( err, OpenFileAndStartSchedulerL() );
   201 			}
   202 		else 
   203 			{
   204 			TRAP( err, OpenFileByHandleAndStartSchedulerL() );
   205 			}
   206 		
   207 		completed = EFalse;
   208 		if ((err == KErrNone) && (iError == KErrNone))
   209 			{
   210 			TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
   211 			if (testAlloc==NULL)
   212 				{
   213 				reachedEnd = ETrue;
   214 				failCount--; // -= 1;
   215 				}
   216 			else
   217 				{
   218 				User::Free(testAlloc);
   219 				}
   220 			
   221 			// see if valid result and break if wrong - might be premature result
   222 			if (iMidiClnt == NULL || iError != KErrNone )
   223 				{
   224 				badResult = ETrue;
   225 				}
   226 			
   227 			if(iMidiClnt)
   228 				{
   229 				iMidiClnt->Close();
   230 				}
   231 
   232 			completed = reachedEnd || badResult;
   233 			}
   234 		else 
   235 			{
   236 				
   237 			if (((err != KErrNone) && (err != KErrNoMemory)) || 
   238 				((iError != KErrNone) && (iError != KErrNoMemory))) // bad error code
   239 				{
   240 				completed = ETrue;
   241 				}
   242 			}
   243 
   244 		__MM_HEAP_MARKEND;
   245 		__UHEAP_SETFAIL(RHeap::ENone ,0);
   246 
   247 		if (completed)
   248 			{
   249 			break; // exit loop
   250 			}
   251 		failCount++;
   252 		}
   253 
   254 	failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc.
   255 	
   256 	if (err != KErrNone || badResult)
   257 		{
   258 		if (badResult)
   259 			{
   260 			INFO_PRINTF2(_L("Bad result with %d memory allocations tested"), failCount);
   261 			}
   262 		else
   263 			{
   264 			INFO_PRINTF3(_L("Error(%d) with %d memory allocations tested"), err, failCount);
   265 			}
   266 		iTestStepResult = EFail;
   267 		}
   268 	else 
   269 		{
   270 		INFO_PRINTF2(_L("Completed OK with %d memory allocations tested"), failCount);
   271 		iTestStepResult = EPass;
   272 		}
   273 
   274 
   275 	INFO_PRINTF1(_L("finished with this test step"));
   276 	return iTestStepResult;
   277 	}
   278 
   279 // from MMidiClientUtilityObserver
   280 void CTestStepMidiClntAllocFailOpenFile::MmcuoStateChanged(TMidiState /*aOldState*/,TMidiState /*aNewState*/,const TTimeIntervalMicroSeconds& /*aTime*/,TInt aError)
   281 	{
   282 	iError = aError;
   283 	CActiveScheduler::Stop();
   284 	}
   285 
   286 void CTestStepMidiClntAllocFailOpenFile::MmcuoTempoChanged(TInt /*aMicroBeatsPerMinute*/)
   287 	{
   288 	}
   289 void CTestStepMidiClntAllocFailOpenFile::MmcuoVolumeChanged(TInt /*aChannel*/,TReal32 /*aVolumeInDecibels*/)
   290 	{
   291 	}
   292 void CTestStepMidiClntAllocFailOpenFile::MmcuoMuteChanged(TInt /*aChannel*/,TBool /*aMuted*/)
   293 	{
   294 	}
   295 void CTestStepMidiClntAllocFailOpenFile::MmcuoSyncUpdate(const TTimeIntervalMicroSeconds& /*aMicroSeconds*/,TInt64 /*aMicroBeats*/)
   296 	{
   297 	}
   298 void CTestStepMidiClntAllocFailOpenFile::MmcuoMetaDataEntryFound(const TInt /*aMetaDataEntryId*/,const TTimeIntervalMicroSeconds& /*aPosition*/)
   299 	{
   300 	}
   301 void CTestStepMidiClntAllocFailOpenFile::MmcuoMipMessageReceived(const RArray<TMipMessageEntry>& /*aEntry*/)
   302 	{
   303 	}
   304 void CTestStepMidiClntAllocFailOpenFile::MmcuoPolyphonyChanged(TInt /*aNewPolyphony*/)
   305 	{
   306 	}
   307 void CTestStepMidiClntAllocFailOpenFile::MmcuoInstrumentChanged(TInt /*aChannel*/,TInt /*aBankId*/,TInt /*aInstrumentId*/)
   308 	{
   309 	}
   310 
   311 
   312 // --------------------------------------------
   313 
   314 /**
   315  *
   316  * Static constructor for CTestStepMidiClntAllocFailOpenDes.
   317  *
   318  *
   319  * @return	"CTestStepMidiClntAllocFailOpenDes*"
   320  *			The constructed CTestStepMidiClntAllocFailOpenDes
   321  *
   322  * @xxxx
   323  * 
   324  */
   325 CTestStepMidiClntAllocFailOpenDes* CTestStepMidiClntAllocFailOpenDes::NewL()
   326 	{
   327 	CTestStepMidiClntAllocFailOpenDes* self = new(ELeave) CTestStepMidiClntAllocFailOpenDes;
   328 	return self;
   329 	}
   330 
   331 /**
   332  *
   333  * Test step constructor.
   334  * Each test step initialises its own name.
   335  *
   336  * @xxxx
   337  * 
   338  */
   339 CTestStepMidiClntAllocFailOpenDes::CTestStepMidiClntAllocFailOpenDes()
   340 	{
   341 	// store the name of this test case
   342 	// this is the name that is used by the script file
   343 	iTestStepName = _L("MM-MMF-MIDICLNT-U-0201-CP");
   344 	}
   345 
   346 /**
   347  *
   348  * Test step destructor.
   349  *
   350  * @xxxx
   351  * 
   352  */
   353 CTestStepMidiClntAllocFailOpenDes::~CTestStepMidiClntAllocFailOpenDes()
   354 	{
   355 	}
   356 
   357 
   358 /**
   359  *
   360  * Test step Preamble.
   361  *
   362  * @xxxx
   363  * 
   364  */
   365 TVerdict CTestStepMidiClntAllocFailOpenDes::DoTestStepPreambleL(void)
   366 	{
   367 	 enum TVerdict verdict;
   368 	 //this installs the scheduler
   369 	 verdict = CTestMmfMidiClntStep::DoTestStepPreambleL();
   370 
   371 	// Printing to the console and log file
   372 	INFO_PRINTF1(_L("MM-MMF-MIDICLNT-U-0201-CP"));
   373 	INFO_PRINTF1(_L("this is a memory allocation failure test of CTestStepMidiClntAllocFailOpenDes"));
   374 	
   375 	if(!GetStringFromConfig(_L("SectionOne"), _L("filename"), iFilename))
   376 		return EInconclusive;
   377 
   378 	RFs fs;
   379 	RFile file;
   380 	TInt size = 0;
   381 
   382 	// connect to file system and open file
   383 	User::LeaveIfError(fs.Connect());
   384 	User::LeaveIfError(file.Open(fs,iFilename,EFileRead));
   385 	CleanupClosePushL(file);
   386 
   387 	// Set HBuf size
   388 	User::LeaveIfError(file.Size(size));
   389 	INFO_PRINTF2(_L("size of file = %d\n"),size);
   390 
   391 	iAudio = HBufC8::NewMaxL(size);
   392 
   393 	// read data into Hbuf
   394 	TPtr8 bufferDes(iAudio->Des());
   395 	User::LeaveIfError(file.Read(bufferDes));
   396 	
   397 	CleanupStack::PopAndDestroy(); //file
   398 
   399 	// create the Midi utility
   400 	if ( (iMidiClnt = CMidiClientUtility::NewL(*this)) == NULL )
   401 		return EInconclusive;
   402 
   403 	return verdict;
   404 	}
   405 
   406 /**
   407  *
   408  * Test step Postamble.
   409  *
   410  * @xxxx
   411  * 
   412  */
   413 TVerdict CTestStepMidiClntAllocFailOpenDes::DoTestStepPostambleL(void)
   414 	{
   415 	delete iMidiClnt;
   416 	iMidiClnt = NULL;
   417 	delete iAudio;
   418 	iAudio = NULL;
   419 	//[ Destroy the scheduler ]
   420 	return CTestMmfMidiClntStep::DoTestStepPostambleL();
   421 	}
   422 
   423 void CTestStepMidiClntAllocFailOpenDes::OpenDesAndStartSchedulerL()
   424 	{
   425 	iMidiClnt->OpenDes(iAudio->Des());
   426 	CActiveScheduler::Start();
   427 	}
   428 
   429 /**
   430  *
   431  * Do the test step.
   432  * Each test step must supply an implementation for DoTestStepL.
   433  *
   434  * @return	"TVerdict"
   435  *			The result of the test step
   436  *
   437  * @xxxx
   438  * 
   439  */
   440 TVerdict CTestStepMidiClntAllocFailOpenDes::DoTestStepL()
   441 	{
   442 	iTestStepResult = EPass;
   443     TInt err       = KErrNone;
   444 
   445 	TInt failCount = 1;
   446 	TBool completed = EFalse;
   447 	TBool badResult = EFalse; 
   448 	TBool reachedEnd = EFalse; // Note: declare outside loop to help with debugging
   449 	for(;;)	
   450 		{
   451 		__UHEAP_SETFAIL(RHeap::EFailNext ,failCount);
   452 		__MM_HEAP_MARK;
   453 
   454 		TRAP( err, OpenDesAndStartSchedulerL() );
   455 
   456 		completed = EFalse;
   457 		if ((err == KErrNone) && (iError == KErrNone))
   458 			{
   459 			TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
   460 			if (testAlloc==NULL)
   461 				{
   462 				reachedEnd = ETrue;
   463 				failCount--; // -= 1;
   464 				}
   465 			else
   466 				User::Free(testAlloc);
   467 
   468 			
   469 			// see if valid result and break if wrong - might be premature result
   470 			if (iMidiClnt == NULL ||
   471 				iError != KErrNone )
   472 				badResult = ETrue;
   473 
   474 			if(iMidiClnt)
   475 				iMidiClnt->Close();
   476 			
   477 			completed = reachedEnd || badResult;
   478 			}
   479 		else if (((err != KErrNone) && (err != KErrNoMemory)) || 
   480 				((iError != KErrNone) && (iError != KErrNoMemory))) // bad error code
   481 			completed = ETrue;
   482 
   483 		__MM_HEAP_MARKEND;
   484 		__UHEAP_SETFAIL(RHeap::ENone ,0);
   485 
   486 		if (completed)
   487 			break; // exit loop
   488 
   489 		failCount++;
   490 		}
   491 
   492 	delete iMidiClnt;
   493 	iMidiClnt = NULL;
   494 
   495 	//failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc.
   496 
   497 	if (err != KErrNone || badResult)
   498 		{
   499 		if (badResult)
   500 			INFO_PRINTF2(_L("  Bad result with %d memory allocations tested"), failCount);
   501 		else
   502 			INFO_PRINTF3(_L("  Error(%d) with %d memory allocations tested"), err, failCount);
   503 		iTestStepResult = EFail;
   504 		}
   505 	else 
   506 		{
   507 		INFO_PRINTF2(_L("  Completed OK with %d memory allocations tested"), failCount);
   508 		iTestStepResult = EPass;
   509 		}
   510 
   511 	INFO_PRINTF1(_L("finished with this test step"));
   512 	// test steps return a result
   513 	return iTestStepResult;
   514 	}
   515 
   516 	// from MMidiClientUtilityObserver
   517 void CTestStepMidiClntAllocFailOpenDes::MmcuoStateChanged(TMidiState /*aOldState*/,TMidiState /*aNewState*/,const TTimeIntervalMicroSeconds& /*aTime*/,TInt aError)
   518 	{
   519 	iError = aError;
   520 	CActiveScheduler::Stop();
   521 	}
   522 
   523 void CTestStepMidiClntAllocFailOpenDes::MmcuoTempoChanged(TInt /*aMicroBeatsPerMinute*/)
   524 	{
   525 	}
   526 void CTestStepMidiClntAllocFailOpenDes::MmcuoVolumeChanged(TInt /*aChannel*/,TReal32 /*aVolumeInDecibels*/)
   527 	{
   528 	}
   529 void CTestStepMidiClntAllocFailOpenDes::MmcuoMuteChanged(TInt /*aChannel*/,TBool /*aMuted*/)
   530 	{
   531 	}
   532 void CTestStepMidiClntAllocFailOpenDes::MmcuoSyncUpdate(const TTimeIntervalMicroSeconds& /*aMicroSeconds*/,TInt64 /*aMicroBeats*/)
   533 	{
   534 	}
   535 void CTestStepMidiClntAllocFailOpenDes::MmcuoMetaDataEntryFound(const TInt /*aMetaDataEntryId*/,const TTimeIntervalMicroSeconds& /*aPosition*/)
   536 	{
   537 	}
   538 void CTestStepMidiClntAllocFailOpenDes::MmcuoMipMessageReceived(const RArray<TMipMessageEntry>& /*aEntry*/)
   539 	{
   540 	}
   541 void CTestStepMidiClntAllocFailOpenDes::MmcuoPolyphonyChanged(TInt /*aNewPolyphony*/)
   542 	{
   543 	}
   544 void CTestStepMidiClntAllocFailOpenDes::MmcuoInstrumentChanged(TInt /*aChannel*/,TInt /*aBankId*/,TInt /*aInstrumentId*/)
   545 	{
   546 	}
   547 
   548 
   549 // --------------------------------------------
   550 
   551 /**
   552  *
   553  * Static constructor for CTestStepMidiClntAllocFailOpenUrl.
   554  *
   555  *
   556  * @return	"CTestStepMidiClntAllocFailOpenUrl*"
   557  *			The constructed CTestStepMidiClntAllocFailOpenUrl
   558  *
   559  * @xxxx
   560  * 
   561  */
   562 CTestStepMidiClntAllocFailOpenUrl* CTestStepMidiClntAllocFailOpenUrl::NewL()
   563 	{
   564 	CTestStepMidiClntAllocFailOpenUrl* self = new(ELeave) CTestStepMidiClntAllocFailOpenUrl;
   565 	return self;
   566 	}
   567 
   568 /**
   569  *
   570  * Test step constructor.
   571  * Each test step initialises its own name.
   572  *
   573  * @xxxx
   574  * 
   575  */
   576 CTestStepMidiClntAllocFailOpenUrl::CTestStepMidiClntAllocFailOpenUrl()
   577 	{
   578 	// store the name of this test case
   579 	// this is the name that is used by the script file
   580 	iTestStepName = _L("MM-MMF-MIDICLNT-U-0202-CP");
   581 	}
   582 
   583 /**
   584  *
   585  * Test step destructor.
   586  *
   587  * @xxxx
   588  * 
   589  */
   590 CTestStepMidiClntAllocFailOpenUrl::~CTestStepMidiClntAllocFailOpenUrl()
   591 	{
   592 	}
   593 
   594 
   595 /**
   596  *
   597  * Test step Preamble.
   598  *
   599  * @xxxx
   600  * 
   601  */
   602 TVerdict CTestStepMidiClntAllocFailOpenUrl::DoTestStepPreambleL(void)
   603 	{
   604 	 enum TVerdict verdict;
   605 	 // this installs the scheduler
   606 	 verdict = CTestMmfMidiClntStep::DoTestStepPreambleL();
   607 
   608 	// Printing to the console and log file
   609 	INFO_PRINTF1(_L("MM-MMF-MIDICLNT-U-0202-CP"));
   610 	INFO_PRINTF1(_L("this is a memory allocation failure test of CTestStepMidiClntAllocFailOpenUrl"));
   611 	
   612 	if(!GetStringFromConfig(iSectName,iKeyName,iUrlname))
   613 		return EInconclusive;
   614 
   615 	/*
   616 	if(!GetStringFromConfig(_L("SectionOne"), _L("AudioPlayFName7"), iFileName) ||
   617 	   !GetStringFromConfig(_L("SectionOne"), _L("AudioFNameToConvert"), iFileName2))
   618 		{
   619 		//INFO_PRINTF2(_L("file name %s not found..."), fileptr);
   620 		return EInconclusive;
   621 		}
   622 	*/
   623 
   624 	// create the Midi utility
   625 	if ( (iMidiClnt = CMidiClientUtility::NewL(*this)) == NULL )
   626 		verdict = EInconclusive;
   627 
   628 	return verdict;
   629 
   630 	}
   631 
   632 /**
   633  *
   634  * Test step Postamble.
   635  *
   636  * @xxxx
   637  * 
   638  */
   639 TVerdict CTestStepMidiClntAllocFailOpenUrl::DoTestStepPostambleL(void)
   640 	{
   641 	delete iMidiClnt;
   642 	iMidiClnt = NULL;
   643 	//[ Destroy the scheduler ]
   644 	return CTestMmfMidiClntStep::DoTestStepPostambleL();
   645 	}
   646 
   647 void CTestStepMidiClntAllocFailOpenUrl::OpenUrlAndStartSchedulerL()
   648 	{
   649 	iMidiClnt->OpenUrl(iUrlname);
   650 	CActiveScheduler::Start();
   651 	}
   652 
   653 /**
   654  *
   655  * Do the test step.
   656  * Each test step must supply an implementation for DoTestStepL.
   657  *
   658  * @return	"TVerdict"
   659  *			The result of the test step
   660  *
   661  * @xxxx
   662  * 
   663  */
   664 TVerdict CTestStepMidiClntAllocFailOpenUrl::DoTestStepL()
   665 	{
   666 	iTestStepResult = EPass;
   667     TInt err       = KErrNone;
   668 
   669 	TInt failCount = 1;
   670 	TBool completed = EFalse;
   671 	TBool badResult = EFalse; 
   672 	TBool reachedEnd = EFalse; // Note: declare outside loop to help with debugging
   673 	for(;;)	
   674 		{
   675 		__UHEAP_SETFAIL(RHeap::EFailNext ,failCount);
   676 		__MM_HEAP_MARK;
   677 
   678 		TRAP( err, OpenUrlAndStartSchedulerL() );
   679 
   680 		completed = EFalse;
   681 		if ((err == KErrNone) && (iError == KErrNone))
   682 			{
   683 			TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
   684 			if (testAlloc==NULL)
   685 				{
   686 				reachedEnd = ETrue;
   687 				failCount--; // -= 1;
   688 				}
   689 			else
   690 				User::Free(testAlloc);
   691 
   692 			
   693 			// see if valid result and break if wrong - might be premature result
   694 			if (iMidiClnt == NULL ||
   695 				iError != KErrNone )
   696 				badResult = ETrue;
   697 
   698 			if(iMidiClnt)
   699 				iMidiClnt->Close();
   700 			
   701 			completed = reachedEnd || badResult;
   702 			}
   703 		else if (((err != KErrNone) && (err != KErrNoMemory)) || 
   704 				((iError != KErrNone) && (iError != KErrNoMemory))) // bad error code
   705 			completed = ETrue;
   706 
   707 		__MM_HEAP_MARKEND;
   708 		__UHEAP_SETFAIL(RHeap::ENone ,0);
   709 
   710 		if (completed)
   711 			break; // exit loop
   712 
   713 		failCount++;
   714 		}
   715 
   716 	delete iMidiClnt;
   717 	iMidiClnt = NULL;
   718 
   719 	//failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc.
   720 
   721 	if (err != KErrNone || badResult)
   722 		{
   723 		if (badResult)
   724 			INFO_PRINTF2(_L("  Bad result with %d memory allocations tested"), failCount);
   725 		else
   726 			INFO_PRINTF3(_L("  Error(%d) with %d memory allocations tested"), err, failCount);
   727 		iTestStepResult = EFail;
   728 		}
   729 	else 
   730 		{
   731 		INFO_PRINTF2(_L("  Completed OK with %d memory allocations tested"), failCount);
   732 		iTestStepResult = EPass;
   733 		}
   734 
   735 	INFO_PRINTF1(_L("finished with this test step"));
   736 	// test steps return a result
   737 	return iTestStepResult;
   738 	}
   739 
   740 	// from MMidiClientUtilityObserver
   741 void CTestStepMidiClntAllocFailOpenUrl::MmcuoStateChanged(TMidiState /*aOldState*/,TMidiState /*aNewState*/,const TTimeIntervalMicroSeconds& /*aTime*/,TInt aError)
   742 	{
   743 	iError = aError;
   744 	CActiveScheduler::Stop();
   745 	}
   746 
   747 void CTestStepMidiClntAllocFailOpenUrl::MmcuoTempoChanged(TInt /*aMicroBeatsPerMinute*/)
   748 	{
   749 	}
   750 void CTestStepMidiClntAllocFailOpenUrl::MmcuoVolumeChanged(TInt /*aChannel*/,TReal32 /*aVolumeInDecibels*/)
   751 	{
   752 	}
   753 void CTestStepMidiClntAllocFailOpenUrl::MmcuoMuteChanged(TInt /*aChannel*/,TBool /*aMuted*/)
   754 	{
   755 	}
   756 void CTestStepMidiClntAllocFailOpenUrl::MmcuoSyncUpdate(const TTimeIntervalMicroSeconds& /*aMicroSeconds*/,TInt64 /*aMicroBeats*/)
   757 	{
   758 	}
   759 void CTestStepMidiClntAllocFailOpenUrl::MmcuoMetaDataEntryFound(const TInt /*aMetaDataEntryId*/,const TTimeIntervalMicroSeconds& /*aPosition*/)
   760 	{
   761 	}
   762 void CTestStepMidiClntAllocFailOpenUrl::MmcuoMipMessageReceived(const RArray<TMipMessageEntry>& /*aEntry*/)
   763 	{
   764 	}
   765 void CTestStepMidiClntAllocFailOpenUrl::MmcuoPolyphonyChanged(TInt /*aNewPolyphony*/)
   766 	{
   767 	}
   768 void CTestStepMidiClntAllocFailOpenUrl::MmcuoInstrumentChanged(TInt /*aChannel*/,TInt /*aBankId*/,TInt /*aInstrumentId*/)
   769 	{
   770 	}
   771 
   772 
   773