os/ossrv/lowlevellibsandfws/pluginfw/Test_Bed/test_bed/LeakTestTransition.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/lowlevellibsandfws/pluginfw/Test_Bed/test_bed/LeakTestTransition.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,139 @@
     1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Overload of the CTransition test that provides
    1.18 +// Heap and Handle leak testing upon a test method.
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +#include <ecom/test_bed/datalogger.h>
    1.23 +#include "LeakTestTransition.h"
    1.24 +
    1.25 +EXPORT_C CLeakTestTransition::CLeakTestTransition(const TDesC&			aTransitionId, 
    1.26 +												  CUnitTestContext&		aUTContext,
    1.27 +												  TTransitionValidator&	aValidator) 
    1.28 +:	CTransition(aTransitionId, aUTContext, aValidator), 
    1.29 +	iFailStep(KMemoryLeakTestFailInit), 
    1.30 +	iBreakStep(KMemoryLeakTestBreakNone)
    1.31 +	{
    1.32 +	// Do nothing here
    1.33 +	}
    1.34 +
    1.35 +// Define the overloaded RunL behaviour here
    1.36 +EXPORT_C void CLeakTestTransition::RunL()
    1.37 +	{
    1.38 +	// Setup leak check and call the base RunL
    1.39 +	iThread.HandleCount(iStartProcessHandleCount, iStartThreadHandleCount);
    1.40 +	__UHEAP_SETFAIL(RHeap::EDeterministic,iFailStep);
    1.41 +	__UHEAP_MARK;
    1.42 +	if(iBreakStep == iFailStep)
    1.43 +		{
    1.44 +		// Drop into the debugger because an unexpected leave occured
    1.45 +		// on the last run of the RunL. (This is therefore a repeat run...)
    1.46 +		__DEBUGGER();
    1.47 +		iBreakStep = KMemoryLeakTestBreakNone;
    1.48 +		}
    1.49 +
    1.50 +    if(iStatus == KErrNoMemory) 
    1.51 +        { 
    1.52 +        // Special case of Async Process signalling 
    1.53 +        // a failure during the notification 
    1.54 +        _LIT(KAsyncProblem, "CLeakTestTransition::RunL() async completion with error %d."); 
    1.55 +        iUTContext.DataLogger().LogInformationWithParameters(KAsyncProblem, iStatus.Int()); 
    1.56 +        User::Leave(iStatus.Int()); 
    1.57 +        }
    1.58 +
    1.59 +	CTransition::RunL();
    1.60 +	if(iTransitionFinished)
    1.61 +		{
    1.62 +		// Successful completion.
    1.63 +		if(iStatus == KErrNone)
    1.64 +			{
    1.65 +			_LIT(KTransitionRunSuccess, "CLeakTestTransition::TransitMethodL() successful completion on iteration %d.");
    1.66 +			iUTContext.DataLogger().LogInformationWithParameters(KTransitionRunSuccess, iFailStep);
    1.67 +			}
    1.68 +		else if(iStatus == KRequestPending)
    1.69 +			{
    1.70 +			//This transition was to set up an asynchronous request
    1.71 +			_LIT(KTransitionRunAsync, "CLeakTestTransition::TransitMethodL() successful called async method on iteration %d.");
    1.72 +			iUTContext.DataLogger().LogInformationWithParameters(KTransitionRunAsync, iFailStep);
    1.73 +			}
    1.74 +		else
    1.75 +			{
    1.76 +			_LIT(KTransitionRunError, "CLeakTestTransition::TransitMethodL() error %d completion on iteration %d.");
    1.77 +			iUTContext.DataLogger().LogInformationWithParameters(KTransitionRunError, iStatus.Int(), iFailStep);
    1.78 +			}
    1.79 +		}
    1.80 +	else
    1.81 +		{
    1.82 +		__DEBUGGER();		// An impossible case ????
    1.83 +		}
    1.84 +	}
    1.85 +
    1.86 +EXPORT_C TInt CLeakTestTransition::RunError(TInt aErrorCode)
    1.87 +	{
    1.88 +	if(aErrorCode != KErrNoMemory)
    1.89 +		{
    1.90 +		iLeaveError = aErrorCode;
    1.91 +		// Check if the leave is associated with a repeat request
    1.92 +		// I.e. it was an execution path test from a stub.
    1.93 +		if(iLeaveError == KTestBedRepeatTest && iRepeatThis)
    1.94 +			{
    1.95 +			_LIT(KTransitionRunRepeat, "CLeakTestTransition::TransitMethodL() leaving on iteration %d for repeat test.");
    1.96 +			iUTContext.DataLogger().LogInformationWithParameters(KTransitionRunRepeat, iFailStep);
    1.97 +			User::RequestComplete(iUnitTestStatus, KTestBedRepeatTest);
    1.98 +			}
    1.99 +		else
   1.100 +			{
   1.101 +			iBreakStep = iFailStep;				// Unexpected so
   1.102 +			// Record the leave and signal completed with a leave code
   1.103 +			_LIT(KTransitionRunError, "CLeakTestTransition::TransitMethodL() leaving error %d on iteration %d.");
   1.104 +			iUTContext.DataLogger().LogInformationWithParameters(KTransitionRunError, 
   1.105 +																 aErrorCode, 
   1.106 +																 iFailStep);
   1.107 +			User::RequestComplete(iUnitTestStatus, KTestBedTestLeft);
   1.108 +			}
   1.109 +		}
   1.110 +	else
   1.111 +		{
   1.112 +		++iFailStep;					// Caused by this test harness
   1.113 +		// Safety check in case we are testing a function which always leaves with KErrNoMemory
   1.114 +		if(iFailStep > KProbablyInfinitelyLooping)
   1.115 +			User::RequestComplete(iUnitTestStatus, KTestBedLeakTestLoopDetected);
   1.116 +		else
   1.117 +			{
   1.118 +			// Re-Schedule
   1.119 +			// Only Reset if its not a stub repeat 
   1.120 +			// request via a leave
   1.121 +			if(aErrorCode != KTestBedRepeatTest)
   1.122 +				iTransitionInfo.iIteration = 0;	
   1.123 +			SetActive();
   1.124 +			TRequestStatus* status = &iStatus;
   1.125 +			User::RequestComplete(status, KErrNone);
   1.126 +			}
   1.127 +		}
   1.128 +	// Check leak cleanup
   1.129 +	iThread.HandleCount(iEndProcessHandleCount, iEndThreadHandleCount);
   1.130 +	if(iStartThreadHandleCount != iEndThreadHandleCount)
   1.131 +		{
   1.132 +		__DEBUGGER();										// Oops leaked some handles
   1.133 +		}
   1.134 +	__UHEAP_MARKEND;
   1.135 +	__UHEAP_SETFAIL(RHeap::ENone, KMemoryLeakTestFailInit);	// No more fails
   1.136 +	return KErrNone;
   1.137 +	}
   1.138 +
   1.139 +EXPORT_C void CLeakTestTransition::PostTransitionCleanup()
   1.140 +	{
   1.141 +	__UHEAP_SETFAIL(RHeap::ENone, KMemoryLeakTestFailInit);	// No more fails
   1.142 +	}