sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: // This file contains the definition of the class CTestManager
sl@0: // 
sl@0: //
sl@0: 
sl@0: /**
sl@0:  @test
sl@0: */
sl@0: 
sl@0: #ifndef __TESTMANAGER_H__
sl@0: #define __TESTMANAGER_H__
sl@0: 
sl@0: #include <e32base.h>
sl@0: #include <e32test.h>
sl@0: 
sl@0: #include <ecom/test_bed/componentinfo.h>
sl@0: #include <ecom/test_bed/datalogger.h>
sl@0: #include <ecom/test_bed/componenttester.h>
sl@0: #include <ecom/test_bed/componenttestobserver.h>
sl@0: #include <ecom/test_bed/managerobserver.h>
sl@0: 
sl@0: /**
sl@0: 	@internalAll
sl@0: 	Comments : Active object which launches all the tests which the TestController has 
sl@0: 	discovered.  Also, acts as an observer on each CComponentTester waiting for a Complete
sl@0: 	message to indicate the test has finished.
sl@0:  */
sl@0: 
sl@0: NONSHARABLE_CLASS(CTestManager) : public CActive, public MComponentTestObserver
sl@0: 	{
sl@0: public:
sl@0: /**
sl@0: 	@fn				static CTestManager* NewL(RPointerArray<CComponentInfo>* aTestList,
sl@0: 											  CDataLogger& aDataLogger,
sl@0:  											  MManagerObserver& aObserver,
sl@0: 											  RTest* aRTest = NULL);
sl@0: 	Intended Usage	:	Standard two-phase construction which leaves nothing on the 
sl@0: 	CleanupStack
sl@0: 	@since			7.0
sl@0: 	@param			aTestList List of tests available to be performed
sl@0: 	@param			aDataLogger Provides the file logging functionality
sl@0: 	@param			aObserver The object to inform when all the tests are complete
sl@0: 	@param			aRTest Optional RTest object to use in check unit test results
sl@0: 	@return			CTestManager* A pointer to the newly created class
sl@0: 	@pre 			None
sl@0: 	@post			Nothing is left on the CleanupStack
sl@0:  */
sl@0: 	
sl@0: 	static CTestManager* NewL(RPointerArray<CComponentInfo>* aTestList,
sl@0: 							  CDataLogger& aDataLogger,
sl@0:  							  MManagerObserver& aObserver,
sl@0: 							  RTest* aRTest = NULL);
sl@0: 
sl@0: /**
sl@0: 	@fn				~CTestManager()
sl@0: 	Intended Usage	:	Standard destructor
sl@0: 	@since			7.0
sl@0:  */
sl@0: 	
sl@0: 	~CTestManager();
sl@0: 
sl@0: /**
sl@0: 	@fn				void RunTests(RPointerArray<TTestInfo>* aTests)
sl@0: 	Intended Usage	:	Prepare for the test run.
sl@0: 	Error Condition	:	
sl@0: 	@since			7.0
sl@0: 	@param			aTests The list of tests to run, 0 means all tests
sl@0: 	@pre 			None
sl@0: 	@post			This is active and awaiting call to RunL() by the active scheduler
sl@0:  */
sl@0: 	
sl@0: 	void RunTests(RPointerArray<TTestInfo>* aTests);
sl@0: 
sl@0: /**
sl@0: 	@fn				void Complete(CComponentTester* aTester, TInt aUnitTestId)
sl@0: 	Intended Usage	:	Callback from the CComponentTester being observed to indicate 
sl@0: 	that it has completed a unit test
sl@0: 	@since			7.0
sl@0: 	@param			aTester The CComponentTester which is signalling
sl@0: 	@param			aUnitTestId The Id of the completed unit test
sl@0: 	@pre 			The specified unit test has been launched
sl@0: 	@post			If all unit tests are complete then the specified CComponentTester has been 
sl@0: 	added to the Garbage list ready for deletion at the next opportunity, this will also 
sl@0: 	unload the appropriate library. Otherwise launch the next unit test.
sl@0:  */
sl@0: 	
sl@0: 	void Complete(CComponentTester* aTester, TInt aUnitTestId);
sl@0: 
sl@0: /**
sl@0: 	@fn				StartedTests() const
sl@0: 	Intended Usage	:	Returns a flag indicating whether any tests have been started yet
sl@0: 	@since			7.0
sl@0: 	@return			ETrue if any tests have been launched, EFalse otherwise
sl@0: 	@pre 			This object is fully constructed
sl@0:  */
sl@0: 	TBool StartedTests() const;
sl@0: 
sl@0: protected:
sl@0: /**
sl@0: 	@fn				CTestManager(RPointerArray<CComponentInfo>* aTestList, 
sl@0: 								 CDataLogger& aDataLogger,
sl@0: 								 MManagerObserver& aObserver,
sl@0: 								 RTest* aRTest = NULL);
sl@0: 	Intended Usage	:	Constructor
sl@0: 	@since			7.0
sl@0: 	@param			aTestList The list of tests to be launched by this CTestManager
sl@0: 	@param			aDataLogger The file logging capability
sl@0: 	@param			aObserver The class to inform when all the tests are complete
sl@0: 	@param			aRTest Optional RTest object to use in check unit test results
sl@0:  */
sl@0: 	
sl@0: 	CTestManager(RPointerArray<CComponentInfo>* aTestList, 
sl@0: 				 CDataLogger& aDataLogger,
sl@0: 				 MManagerObserver& aObserver,
sl@0: 				 RTest* aRTest = NULL);
sl@0: 
sl@0: /**
sl@0: 	@fn				void ConstructL()
sl@0: 	Intended Usage	:	Second phase of safe two-phase construction method
sl@0: 	@since			7.0
sl@0: 	@pre 			First phase of construction is complete
sl@0: 	@post			Object is fully constructed and initialized
sl@0:  */
sl@0: 	
sl@0: 	void ConstructL();
sl@0: 
sl@0: /**
sl@0: 	@fn				void RunL()
sl@0: 	Intended Usage	:	Used to launch each test, in turn, and then to stop the active 
sl@0: 	scheduler when all tests have completed
sl@0: 	@since			7.0
sl@0: 	@pre 			None
sl@0: 	@post			Initially each run of RunL() will result in a ComponentTester being created and
sl@0: 					launched.  Once all the tests have launched RunL() will only be called at completion
sl@0: 					to stop the active scheduler.
sl@0:  */
sl@0: 	
sl@0: 	void RunL();
sl@0: 
sl@0: /**
sl@0: 	@fn				void DoCancel()
sl@0: 	Intended Usage	:	Standard Active Object method used to cancel any outstanding requests
sl@0: 	Error Condition	:	
sl@0: 	@since			7.0
sl@0: 	@pre 			Object is fully constructed and initialised
sl@0: 	@post			Any outstanding requests have been cancelled.
sl@0:  */
sl@0: 	
sl@0: 	void DoCancel();
sl@0: 
sl@0: /**
sl@0: 	@fn				void TestComponentL(TInt aComponentIndex)
sl@0: 	Intended Usage	:	Loads the appropriate library and test the specified component
sl@0: 	@since			7.0
sl@0: 	@param			aComponentIndex The zero base index of the component to test
sl@0: 	@pre 			Object is fully constructed and initialised
sl@0: 	@post			Specified component test has been activated to run
sl@0:  */
sl@0: 	
sl@0: 	void TestComponentL(TInt aComponentIndex);
sl@0: 
sl@0: /**
sl@0: 	@fn				RunError(TInt aErrorCode)
sl@0: 	Intended Usage	:	Handles the situation where the RunL leaves.  RunL will only leave 
sl@0: 	through a leave from TestComponentL, this will occur if the test to be run fails to 
sl@0: 	construct.
sl@0: 	Error Condition	:	None
sl@0: 	@since			7.0
sl@0: 	@param			aErrorCode The error code which RunL left with.
sl@0: 	@return			KErrNone because we handle the error.
sl@0: 	@pre 			This object is fully constructed and initialized
sl@0: 	@post			The test which failed to construct is cleaned up.
sl@0:  */
sl@0: 	
sl@0: 	TInt RunError(TInt aErrorCode);
sl@0: 
sl@0: protected:
sl@0: /** The observer to inform when all tests are complete */
sl@0: 	MManagerObserver&	iObserver;
sl@0: /** List of all the test to be run*/
sl@0: 	
sl@0: 	RPointerArray<CComponentInfo>*	iTestList;
sl@0: /** The index (in iTestList) of the test which is to be loaded next*/
sl@0: 	
sl@0: 	TInt iCurrentTestLoad;
sl@0: /** The test logging mechanism*/
sl@0: 	
sl@0: 	CDataLogger&	iDataLogger;
sl@0: /** Flag indicating that all tests have completed*/
sl@0: 	
sl@0: 	TBool			iAmStopping;
sl@0: /** List of the tests to be run, NULL means run all tests */
sl@0: 	
sl@0: 	RPointerArray<TTestInfo>* iTestsToRun;
sl@0: /** The test which is currently being run */
sl@0: 	
sl@0: 	CComponentTester* iCurrentTester;
sl@0: /** Optional reference to the RTest object used in the EXE test harness code which
sl@0: 	kicked off this test framework */
sl@0: 	RTest* iRTest;
sl@0: 
sl@0: 	friend class TTestManager_StateAccessor;
sl@0: 	};
sl@0: 
sl@0: #endif