CUnitTest Class Reference

class CUnitTest : public CTimer

Comments : Abstract base class upon which a test developer can base his unit test class. Most functionality is implemented in this base class, to write a derived class just implement a NewL() and a ConstructL() on the new object. ConstructL() should first call UnitTestConstructL() and then create the transitions which make up this unit test. Eg.

		_LIT(KExampleUnitTest,"CExampleUnitTest");

		CExampleUnitTest* CExampleUnitTest::NewL(CDataLogger&		aDataLogger,
												 MUnitTestObserver& aObserver)
			{
			CExampleUnitTest* self = new(ELeave) CExampleUnitTest(aDataLogger,
																  aObserver);
			self->ConstructL();
			return self; 
			}

		TInt CExampleUnitTest::RunError(TInt aError)
			{
			// The RunL left so chain to the base first and then cleanup
			TInt error = CUnitTest::RunError(aError);	// Chain to base
			delete iTestClass;
			iTestClass = NULL;
			return error;
			}

		CExampleUnitTest::~CExampleUnitTest()
			{
			// delete the test context information
			delete iStateAccessor;
			delete iUTContext;
			delete iValidator;

			// Simply delete our test class instance
			delete iTestClass;
			}

		CExampleUnitTest::CExampleUnitTest(CDataLogger& aDataLogger,
											MUnitTestObserver& aObserver, 
											MStateAccessor& aStateAccessor)
		: CUnitTest(KExampleUnitTest, aDataLogger, aObserver, aStateAccessor)
			{
			//Do nothing
			}

		// Now the Individual transitions need to be added.
		void CExampleUnitTest::ConstructL()
			{
			// Perform base class initialization
			UnitTestConstructL();

			// Create the input variables to the transition creation
			iStateAccessor = new(ELeave) TExampleStateAccessor();
			iUTContext = new(ELeave) CUnitTestContext(iDataLogger, *iStateAccessor, *this);
			iValidator = new(ELeave) TTransitionValidator(*iUTContext);

			// Add the Transitions in the order they are to run
			// C'tor first, D'tor last...
			AddTransitionL(new(ELeave)CExampleNewLTransition(*iUTContext, *iValidator, iTestClass));
			AddTransitionL(new(ELeave)CExampleDtorTransition(*iUTContext, *iValidator, iTestClass));
			}

Inherits from

Public Member Functions
~CUnitTest()
IMPORT_C voidComplete(CTransition &, TInt)
IMPORT_C CTransition &GetCurrentTransition()
voidPrepareUnitTestL()
IMPORT_C voidRunTest(TTimeIntervalMicroSeconds32)
IMPORT_C voidSetCurrentTransition(CTransition &)
IMPORT_C voidSetParametersL(TAny *)
voidSetRTest(RTest *)
CUnitTestInfo *TransitionSetL()
const TDesC &UnitTestName()
Protected Member Functions
CUnitTest(const TDesC &, CDataLogger &, MUnitTestObserver &)
IMPORT_C voidAddBlockingTransitionL(CTransition *)
IMPORT_C voidAddLeaveErrorCodeL(TInt)
IMPORT_C voidAddTransitionL(CTransition *)
IMPORT_C voidConstructL()
IMPORT_C voidDoCancel()
IMPORT_C voidRunL()
IMPORT_C voidUnitTestConstructL()
Inherited Functions
CActive::CActive(TInt)
CActive::Cancel()
CActive::Deque()
CActive::Extension_(TUint,TAny *&,TAny *)
CActive::IsActive()const
CActive::IsAdded()const
CActive::Priority()const
CActive::RunError(TInt)
CActive::SetActive()
CActive::SetPriority(TInt)
CActive::~CActive()
CBase::CBase()
CBase::Delete(CBase *)
CBase::operator new(TUint)
CBase::operator new(TUint,TAny *)
CBase::operator new(TUint,TLeave)
CBase::operator new(TUint,TLeave,TUint)
CBase::operator new(TUint,TUint)
CBase::~CBase()
CTimer::After(TTimeIntervalMicroSeconds32)
CTimer::At(const TTime &)
CTimer::AtUTC(const TTime &)
CTimer::CTimer(TInt)
CTimer::HighRes(TTimeIntervalMicroSeconds32)
CTimer::Inactivity(TTimeIntervalSeconds)
CTimer::Lock(TTimerLockSpec)
CTimer::~CTimer()
Inherited Enumerations
CActive:TPriority
Protected Attributes
CTransition *iCurrentlyExecutingTransition
CDataLogger &iDataLogger
CFileMan *iFileMan
RFs iFs
RArray< TInt >iLeaveErrorArray
TInt iNextTransitionIndex
RPointerArray< CTransition > *iOutstandingTransitions
RTest *iRTest
RPointerArray< CTransition > *iTransitions
const TDesC &iUnitTestName
MUnitTestObserver &iUnitTestObserver
TBool iWaitingForCompletion
Inherited Attributes
CActive::iStatus

Constructor & Destructor Documentation

CUnitTest(const TDesC &, CDataLogger &, MUnitTestObserver &)

CUnitTest(const TDesC &aName,
CDataLogger &aDataLogger,
MUnitTestObserver &aUnitTestObserver
)[protected, inline]
Intended Usage : Standard Constructor Error Condition :
Since
7.0

Parameters

const TDesC & aNameThe identifier of this unit test
CDataLogger & aDataLoggerProvides the logging capability
MUnitTestObserver & aUnitTestObserverIs informed when this unit test completes

~CUnitTest()

IMPORT_C~CUnitTest()
Intended Usage : Standard Destructor
Since
7.0

Member Functions Documentation

AddBlockingTransitionL(CTransition *)

IMPORT_C voidAddBlockingTransitionL(CTransition *aTransition)[protected]
Intended Usage : Adds a transition to the unit test which will block until all previous asynchronous transitions have completed before running.
leave
KErrNoMemory
Since
7.0
Pre-condition
Should be used in developer implemented ConstructL() to add transitions to the Unit Test
Post-condition
The specified transition is added to the list to be run for this unit test

Parameters

CTransition * aTransitionThe transition to be added to the list

AddLeaveErrorCodeL(TInt)

IMPORT_C voidAddLeaveErrorCodeL(TIntaLeaveErrorCode)[protected]

Parameters

TInt aLeaveErrorCode

AddTransitionL(CTransition *)

IMPORT_C voidAddTransitionL(CTransition *aTransition)[protected]
Intended Usage : Adds the transition to the list to be run during this unit test
leave
KErrNoMemory
Since
7.0
Pre-condition
Should be used in developer implemented ConstructL() to add transitions to the Unit Test
Post-condition
The specified transition is added to the list to be run for this unit test

Parameters

CTransition * aTransitionThe transition to be added to the list

Complete(CTransition &, TInt)

IMPORT_C voidComplete(CTransition &aTransition,
TIntaAsyncPostCheckError
)
Intended Usage : MTransitionObserver override that is called to indicate that an asynchronous function on the specified transition has completed.
Since
7.0
Pre-condition
The specified transition has launched an asynchronous function
Post-condition
The transition has fully completed, if all transitions are complete then the unittest is complete.

Parameters

CTransition & aTransitionThe transition which has completed an async function.
TInt aAsyncPostCheckErrorAn error code from the second phase of post-condition validation done after the transition's asynchronous request had completed. Used for asynchronous transitions only - for synchronous transitions, 2-phase post-condition checking does not apply, and a value of KErrNone is supplied.

ConstructL()

IMPORT_C voidConstructL()[protected, pure virtual]
Intended Usage : Must be overridden in derived class to complete construction Error Condition :
Since
7.0

DoCancel()

IMPORT_C voidDoCancel()[protected, virtual]
Intended Usage : Standard Active Object method for cancelling the current request
Since
7.0
Pre-condition
None
Post-condition
Any outstanding requests are cancelled

GetCurrentTransition()

IMPORT_C CTransition &GetCurrentTransition()const
Intended Usage : Retrieve a reference to the transition whose RunL() method is currently executing. This allows transition information can be retrieved and RepeatOnce() can be called on the transition.
Since
7.0
Pre-condition
None
Post-condition
No change.

PrepareUnitTestL()

voidPrepareUnitTestL()[inline, virtual]
Intended Usage : May be overidden in the derived unit test to perform any unit test specific environment setup (eg copying data files into place). The default implementation is to do nothing. Error Condition : Depends on implementation.
Since
7.0
Pre-condition
This CUnitTest is constructed
Post-condition
Depends on implementation

RunL()

IMPORT_C voidRunL()[protected, virtual]
Intended Usage : Implementation of CActive method. Each iteration of RunL() causes one transition to be run. Error Condition :
Since
7.0
Pre-condition
Preconditions are ensured by RunTest()
Post-condition
Transition has been activated

RunTest(TTimeIntervalMicroSeconds32)

IMPORT_C voidRunTest(TTimeIntervalMicroSeconds32aTimeAfter = 0)
Intended Usage : Sets up the Timer Object request to cause the test to run. Error Condition :
Since
7.0
Pre-condition
None
Post-condition
RunL() will be set up to run after the specified time.

Parameters

TTimeIntervalMicroSeconds32 aTimeAfter = 0The time after which the unit test should be run

SetCurrentTransition(CTransition &)

IMPORT_C voidSetCurrentTransition(CTransition &aTransition)
Intended Usage : MTransitionObserver override that recieves a reference to the transition whose RnunL() method is executing. This allows transition information can be retrieved and RepeatOnce() can be called on the transition.
Since
7.0
Pre-condition
None
Post-condition
aTransition will be recorded as the currently executing transition.

Parameters

CTransition & aTransitionA reference to the transition to set as current

SetParametersL(TAny *)

IMPORT_C voidSetParametersL(TAny *aParams)[virtual]
Intended Usage : Should be overridden in the derived unit test to accept parameters to be used in the unit test. The default implementation is to do nothing. Error Condition :
Since
7.0
Pre-condition
This CUnitTest is constructed
Post-condition
The parameters are stored and ready for use in the test

Parameters

TAny * aParamsThe parameter block which the unit test will use

SetRTest(RTest *)

voidSetRTest(RTest *aRTest)[inline]

Parameters

RTest * aRTest

TransitionSetL()

CUnitTestInfo *TransitionSetL()const
Intended Usage : Creates and returns a CUnitTestInfo containing information on this UnitTest. Passes ownership of the CUnitTestInfo to the calling object. Error Condition :
Since
7.0
Pre-condition
None

UnitTestConstructL()

IMPORT_C voidUnitTestConstructL()[protected]
Intended Usage : Called from derived class construction to perform all base class initialisation. Error Condition :
Since
7.0
Pre-condition
Should be called during construction of the derived class to perform base class initialisation.
Post-condition
Unspecified

UnitTestName()

const TDesC &UnitTestName()const [inline]
Intended Usage : Return the name identifier of this Unit Test Error Condition :
Since
7.0
Pre-condition
None

Member Data Documentation

CTransition * iCurrentlyExecutingTransition

CTransition *iCurrentlyExecutingTransition[protected]

The currently executing transition : NOT OWNED

CDataLogger & iDataLogger

CDataLogger &iDataLogger[protected]

The test logging mechanism

CFileMan * iFileMan

CFileMan *iFileMan[protected]

File manager - useful in PrepareUnitTestL if copying files is required

RFs iFs

RFs iFs[protected]

Connection to the file server - required by iFileMan

RArray< TInt > iLeaveErrorArray

RArray< TInt >iLeaveErrorArray[protected]

List of all the acceptable error codes

TInt iNextTransitionIndex

TInt iNextTransitionIndex[protected]

The index in iTransitions of the next transition to be run

RPointerArray< CTransition > * iOutstandingTransitions

RPointerArray< CTransition > *iOutstandingTransitions[protected]

List of the asyncronous transitions which have requests outstanding

RTest * iRTest

RTest *iRTest[protected]

Optional reference to the RTest object used in the EXE test harness code which kicked off this test framework

RPointerArray< CTransition > * iTransitions

RPointerArray< CTransition > *iTransitions[protected]

List of the transitions which make up this Unit Test

const TDesC & iUnitTestName

const TDesC &iUnitTestName[protected]

The identifier of this Unit Test

MUnitTestObserver & iUnitTestObserver

MUnitTestObserver &iUnitTestObserver[protected]

Used to call back to the test controller that the test has finished

TBool iWaitingForCompletion

TBool iWaitingForCompletion[protected]

Indicates that the next transition is waiting for the completion of async requests before it will be run