lowlevellibsandfws/pluginfw/Test_Bed/test_bed/TestController.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32std.h>
       
    17 #include <e32uid.h>
       
    18 
       
    19 #include "TestController.h"
       
    20 #include "ComponentTester.h"
       
    21 #include <ecom/test_bed/testbeddefinitions.h>
       
    22 #include <ecom/test_bed/datalogger.h>
       
    23 
       
    24 
       
    25 CTestController::CTestController(CActiveScheduler* aScheduler, RTest* aRTest)
       
    26 : CBase(),
       
    27 iScheduler(aScheduler),
       
    28 iRTest(aRTest)
       
    29 	{
       
    30 	}
       
    31 
       
    32 
       
    33 EXPORT_C CTestController::~CTestController()
       
    34 	{
       
    35 	// Cancel any outstanding tests
       
    36 	Cancel();
       
    37 
       
    38 	iTestList.ResetAndDestroy();
       
    39 	delete iTestManager;
       
    40 	if(iOwnScheduler)
       
    41 		delete iScheduler;
       
    42 	Dll::SetTls(NULL);
       
    43 	delete iDataLogger;
       
    44 	}
       
    45 
       
    46 
       
    47 EXPORT_C CTestController* CTestController::NewLC(CActiveScheduler* aScheduler,
       
    48 												 ComponentTesterInitialiserLC aEntryPoint,
       
    49 												 RTest* aRTest,
       
    50 												 TLoggingInfo* aLogInfo)
       
    51 	{
       
    52 	CTestController* self = new (ELeave) CTestController(aScheduler, aRTest);
       
    53 	CleanupStack::PushL(self);
       
    54 	self->ConstructL(aLogInfo, aEntryPoint);
       
    55 	return self;
       
    56 	}
       
    57 
       
    58 
       
    59 EXPORT_C CTestController* CTestController::NewL(CActiveScheduler* aScheduler,
       
    60 												ComponentTesterInitialiserLC aEntryPoint,
       
    61 												RTest* aRTest,
       
    62 												TLoggingInfo* aLogInfo)
       
    63 	{
       
    64 	CTestController* self = NewLC(aScheduler, aEntryPoint, aRTest, aLogInfo);
       
    65 	CleanupStack::Pop();
       
    66 	return self;
       
    67 	}
       
    68 
       
    69 
       
    70 void CTestController::ConstructL(TLoggingInfo* aLogInfo, ComponentTesterInitialiserLC aEntryPoint)
       
    71 	{
       
    72 	if(iScheduler == NULL)
       
    73 		{
       
    74 		  // Construct and install the active scheduler
       
    75 		iScheduler = new (ELeave) CActiveScheduler;
       
    76 		iOwnScheduler = ETrue;
       
    77 		CActiveScheduler::Install(iScheduler); 
       
    78 		}
       
    79 
       
    80 	// Create a logging channel
       
    81 	iDataLogger = CDataLogger::NewL(aLogInfo);
       
    82 	Dll::SetTls(iDataLogger);
       
    83 
       
    84 	// Create the component tester object required for testing
       
    85 	InitialiseComponentTesterL(aEntryPoint);
       
    86 
       
    87 	_LIT(KCreatingTestManager,"Creating a test manager");
       
    88 	iDataLogger->LogInformation(KCreatingTestManager());
       
    89 
       
    90 	iTestManager = CTestManager::NewL(&iTestList, *iDataLogger, *this, iRTest);
       
    91 	}
       
    92 
       
    93 
       
    94 EXPORT_C void CTestController::Start()
       
    95 	{
       
    96 	iTestManager->RunTests(NULL);
       
    97 	iScheduler->Start();
       
    98 	}
       
    99 
       
   100 EXPORT_C void CTestController::Start(RPointerArray<TTestInfo>* aTests)
       
   101 	{
       
   102 	iTestManager->RunTests(aTests);
       
   103 	iScheduler->Start();
       
   104 	}
       
   105 
       
   106 EXPORT_C void CTestController::Start(TRequestStatus* aStatus)
       
   107 	{
       
   108 	Start(aStatus, NULL);
       
   109 	}
       
   110 
       
   111 EXPORT_C void CTestController::Start(TRequestStatus* aStatus, RPointerArray<TTestInfo>* aTests)
       
   112 	{
       
   113 	__ASSERT_DEBUG(CActiveScheduler::Current(), User::Invariant());
       
   114 	iClientStatus = aStatus;
       
   115 	iTestManager->RunTests(aTests);
       
   116 	}
       
   117 
       
   118 
       
   119 EXPORT_C const RPointerArray<CComponentInfo>& CTestController::FindComponents() const
       
   120 	{
       
   121 	// Return the list of classes that can be tested
       
   122 	return iTestList;
       
   123 	}
       
   124 
       
   125 /**
       
   126 	@fn				CleanupArray(TAny* aArray)
       
   127 	Intended Useage:The CleanupArray method is used for cleanup support 
       
   128 					of locally declared arrays
       
   129 	@internalComponent
       
   130 	@since			7.0
       
   131 	@param			aArray is the array whose contents should be destroyed
       
   132 */
       
   133 static void CleanupArray(TAny* aArray)
       
   134 	{
       
   135 	RPointerArray<CUnitTestInfo>* array = 
       
   136 		REINTERPRET_CAST(RPointerArray<CUnitTestInfo>*, aArray);
       
   137 	array->ResetAndDestroy();
       
   138 	delete array;
       
   139 	}
       
   140 
       
   141 void CTestController::InitialiseComponentTesterL(ComponentTesterInitialiserLC aEntryPointLC)
       
   142 	{
       
   143 	_LIT(KInitCompTester, "Initialising derived component tester object");
       
   144 	iDataLogger->LogInformation(KInitCompTester());
       
   145 	// Invoking the function passed in will result in a derived 
       
   146 	// CComponentTester object being created and pushed on the clean up 
       
   147 	// stack. Therefore we need to do a pop and destroy later.
       
   148 	CComponentTester* componentTesterFromEXE =  aEntryPointLC(*iDataLogger,*iTestManager);
       
   149    
       
   150 	_LIT(KCreateTranSets,"Creating component tester & Building Unit Test information.");
       
   151 	iDataLogger->LogInformation(KCreateTranSets());
       
   152 	RPointerArray<CUnitTestInfo>* unitTests = componentTesterFromEXE->TransitionSetsL();
       
   153 
       
   154 	CleanupStack::PopAndDestroy(componentTesterFromEXE);	//componentTester as pushed by aEntryPoint
       
   155 
       
   156 	TCleanupItem cleanup(CleanupArray, unitTests);
       
   157 	CleanupStack::PushL(cleanup);
       
   158 	
       
   159 	CComponentInfo* info = CComponentInfo::NewL(aEntryPointLC, unitTests);
       
   160 	CleanupStack::Pop(unitTests);	// unitTests, now owned by info
       
   161 	CleanupStack::PushL(info);
       
   162 	User::LeaveIfError(iTestList.Append(info));		// pass ownership onto the list.
       
   163 	CleanupStack::Pop(info); // now owned by iTestList
       
   164 	}
       
   165 
       
   166 EXPORT_C CDataLogger& CTestController::DataLogger()
       
   167 	{
       
   168 	return *(REINTERPRET_CAST(CDataLogger*,Dll::Tls()));
       
   169 	}
       
   170 
       
   171 EXPORT_C void CTestController::Cancel()
       
   172 	{
       
   173 	if(iTestManager)
       
   174 		{
       
   175 		iTestManager->Cancel();
       
   176 
       
   177 		if(!iTestManager->StartedTests() && iClientStatus)
       
   178 			{
       
   179 			User::RequestComplete(iClientStatus, KTestBedTestCancel);
       
   180 			iClientStatus = NULL;
       
   181 			}
       
   182 		}
       
   183 	}
       
   184 
       
   185 void CTestController::TestsComplete()
       
   186 	{
       
   187 	if(iClientStatus)
       
   188 		{
       
   189 		User::RequestComplete(iClientStatus, KErrNone);
       
   190 		iClientStatus = NULL;
       
   191 		}
       
   192 	else
       
   193 		CActiveScheduler::Stop();
       
   194 	}
       
   195