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));
}
Constructor & Destructor Documentation
CUnitTest(const TDesC &, CDataLogger &, MUnitTestObserver &)
Intended Usage : Standard Constructor Error Condition :
- Since
- 7.0
Parameters
const TDesC & aName | The identifier of this unit test |
CDataLogger & aDataLogger | Provides the logging capability |
MUnitTestObserver & aUnitTestObserver | Is informed when this unit test completes |
~CUnitTest()
Intended Usage : Standard Destructor
- Since
- 7.0
Member Functions Documentation
AddBlockingTransitionL(CTransition *)
IMPORT_C void | AddBlockingTransitionL | ( | 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 * aTransition | The transition to be added to the list |
AddLeaveErrorCodeL(TInt)
IMPORT_C void | AddLeaveErrorCodeL | ( | TInt | aLeaveErrorCode | ) | [protected] |
AddTransitionL(CTransition *)
IMPORT_C void | AddTransitionL | ( | 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 * aTransition | The transition to be added to the list |
Complete(CTransition &, TInt)
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 & aTransition | The transition which has completed an async function. |
TInt aAsyncPostCheckError | An 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 void | ConstructL | ( | ) | [protected, pure virtual] |
Intended Usage : Must be overridden in derived class to complete construction Error Condition :
- Since
- 7.0
DoCancel()
IMPORT_C void | DoCancel | ( | ) | [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()
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()
void | PrepareUnitTestL | ( | ) | [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 void | RunL | ( | ) | [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)
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.
SetCurrentTransition(CTransition &)
IMPORT_C void | SetCurrentTransition | ( | 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 & aTransition | A reference to the transition to set as current |
SetParametersL(TAny *)
IMPORT_C void | SetParametersL | ( | 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 * aParams | The parameter block which the unit test will use |
SetRTest(RTest *)
void | SetRTest | ( | RTest * | aRTest | ) | [inline] |
TransitionSetL()
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 void | UnitTestConstructL | ( | ) | [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
The currently executing transition : NOT OWNED
CDataLogger & iDataLogger
The test logging mechanism
CFileMan * iFileMan
File manager - useful in PrepareUnitTestL if copying files is required
RFs
iFs
Connection to the file server - required by iFileMan
RArray< TInt > iLeaveErrorArray
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
List of the asyncronous transitions which have requests outstanding
RTest * iRTest
Optional reference to the RTest object used in the EXE test harness code which kicked off this test framework
RPointerArray< CTransition > * iTransitions
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
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
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.