Ejemplo n.º 1
0
void CTzUserDataTest::OOMTestL(OOMTestFunction aFunction, TOOMTest  aOOMTest)
	{
	TInt tryCount = 1;
	
	RTz tz;
	User::LeaveIfError(tz.Connect());
	CleanupClosePushL(tz);
	iUserData = CTzUserData::NewL(tz);

	TInt cellsBefore = 0;
			
	for (;;)
		{
		test.Printf(_L("Heap memory allocation set to fail at allocation #%d.\n"),
			tryCount);

		if(aOOMTest == EClientOOM)
			{
			__UHEAP_SETFAIL(RAllocator::EDeterministic, tryCount);
			__UHEAP_MARK;
			}
		else
			{
			TInt heapSize = 0;
			tz.__dbgSetHeapFailL(RAllocator::EDeterministic, tryCount);
			cellsBefore = tz.__dbgRequestAllocatedCellsL(heapSize);
			}
		
		TRAPD(err, (this->*aFunction)());

		if(err == KErrNone)
   			{
   			test.Printf(_L("OOM test complete.\n"));
   			break;
   			}
		
		test(err == KErrNoMemory);
		
		if(aOOMTest == EClientOOM)
			{
			__UHEAP_MARKEND;	
			}
		else
			{
			tz.__dbgResetHeapL();
			TInt heapSize = 0;
			TInt cellsAfter = tz.__dbgRequestAllocatedCellsL(heapSize);
			if(cellsBefore != cellsAfter)
				{
				test.Printf(_L("ERROR: Memory leak.  Heap cells: %d before, %d after.\n"),
					cellsBefore, cellsAfter);
				test(EFalse);
				}
			}
  	
		tryCount++;
		}
	
	__UHEAP_RESET;
	tz.__dbgResetHeapL();
	
	delete iUserData;
	iUserData = NULL;
	
	CleanupStack::PopAndDestroy(&tz);	
	}