os/ossrv/lowlevellibsandfws/pluginfw/Test_Bed/ComponentTesterTest/ComponentTesterUnitTest.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 // The unit test class implementations for the CComponentTester class.
    15 // 
    16 //
    17 
    18 #include "ComponentTesterUnitTest.h"
    19 
    20 // ______________________________________________________________________________
    21 //
    22 _LIT(KComponentTesterCreateAndDestroyUnitTest,"CComponentTester_CreateAndDestroy_UnitTest");
    23 
    24 CComponentTester_CreateAndDestroy_UnitTest* CComponentTester_CreateAndDestroy_UnitTest::NewL(CDataLogger& aDataLogger,
    25 											MUnitTestObserver& aObserver)
    26 	{
    27 	CComponentTester_CreateAndDestroy_UnitTest* self = 
    28 					new(ELeave) CComponentTester_CreateAndDestroy_UnitTest(aDataLogger,
    29 																aObserver);
    30 	CleanupStack::PushL(self);
    31 	self->ConstructL();
    32 	CleanupStack::Pop();
    33 	return self; 
    34 	}
    35 
    36 inline TInt CComponentTester_CreateAndDestroy_UnitTest::RunError(TInt aError)
    37 	{
    38 	// The RunL left so chain to the base first and then cleanup
    39 	TInt error = CUnitTest::RunError(aError);	// Chain to base
    40 	delete iUTContext;
    41 	iUTContext = NULL;
    42 	delete iStateAccessor;
    43 	iStateAccessor = NULL;
    44 	/* delete any validators used */
    45 	delete iCtorValidator;
    46 	iCtorValidator = NULL;
    47 	delete iDtorValidator;
    48 	iDtorValidator = NULL;
    49 	return error;
    50 	}
    51 
    52 inline CComponentTester_CreateAndDestroy_UnitTest::~CComponentTester_CreateAndDestroy_UnitTest()
    53 	{
    54 	// Simply delete our test class instance
    55 	delete iUTContext;
    56 	delete iStateAccessor;
    57 	/* delete any validators used */
    58 	delete iCtorValidator;
    59 	delete iDtorValidator;
    60 	}
    61 
    62 inline CComponentTester_CreateAndDestroy_UnitTest::CComponentTester_CreateAndDestroy_UnitTest(CDataLogger& aDataLogger,
    63 																	MUnitTestObserver& aObserver)
    64 : CUnitTest(KComponentTesterCreateAndDestroyUnitTest, aDataLogger, aObserver)
    65 	{
    66 	//Do nothing
    67 	}
    68 
    69 // Now the Individual transitions need to be added.
    70 inline void CComponentTester_CreateAndDestroy_UnitTest::ConstructL()
    71 	{
    72 	// Perform the base class initialization
    73 	UnitTestConstructL();
    74 
    75 	// Create the Unit test state accessor
    76 	iStateAccessor = new(ELeave) TComponentTester_StateAccessor;
    77 	// Construct the Unit test context.
    78 	iUTContext = new(ELeave) CComponentTester_UnitTestContext(iDataLogger, *iStateAccessor, *this);
    79 
    80 	// Add the Transitions in the order they are to run
    81 	// C'tor first, D'tor last...
    82 	iCtorValidator = new(ELeave) TComponentTester_Ctor_TransitionValidator(*iUTContext);
    83 	iDtorValidator = new(ELeave) TComponentTester_Dtor_TransitionValidator(*iUTContext);
    84 
    85 	AddTransitionL(new(ELeave)CComponentTester_NewL_Transition(*iUTContext,*iCtorValidator));
    86 	AddTransitionL(new(ELeave)CComponentTester_Dtor_Transition(*iUTContext,*iDtorValidator));
    87 	}
    88 
    89 // ______________________________________________________________________________
    90 //
    91 _LIT(KComponentTesterManageUnitTestsUnitTest,"CComponentTester_ManageUnitTests_UnitTest");
    92 
    93 CComponentTester_ManageUnitTests_UnitTest* CComponentTester_ManageUnitTests_UnitTest::NewL(CDataLogger& aDataLogger,
    94 											MUnitTestObserver& aObserver)
    95 	{
    96 	CComponentTester_ManageUnitTests_UnitTest* self = 
    97 					new(ELeave) CComponentTester_ManageUnitTests_UnitTest(aDataLogger,
    98 																aObserver);
    99 	CleanupStack::PushL(self);
   100 	self->ConstructL();
   101 	CleanupStack::Pop();
   102 	return self; 
   103 	}
   104 
   105 inline TInt CComponentTester_ManageUnitTests_UnitTest::RunError(TInt aError)
   106 	{
   107 	// The RunL left so chain to the base first and then cleanup
   108 	TInt error = CUnitTest::RunError(aError);	// Chain to base
   109 	delete iUTContext;
   110 	iUTContext = NULL;
   111 	delete iStateAccessor;
   112 	iStateAccessor = NULL;
   113 	/* delete any validators used */
   114 	delete iCtorValidator;
   115 	iCtorValidator = NULL;
   116 	delete iTransitionSetsValidator;
   117 	iTransitionSetsValidator = NULL;
   118 	delete iAddUnitTestValidator;
   119 	iAddUnitTestValidator = NULL;
   120 	delete iAddParamUnitTestValidator;
   121 	iAddParamUnitTestValidator = NULL;
   122 	delete iDtorValidator;
   123 	iDtorValidator = NULL;
   124 	return error;
   125 	}
   126 
   127 inline CComponentTester_ManageUnitTests_UnitTest::~CComponentTester_ManageUnitTests_UnitTest()
   128 	{
   129 	// Simply delete our test class instance
   130 	delete iUTContext;
   131 	delete iStateAccessor;
   132 	/* delete any validators used */
   133 	delete iCtorValidator;
   134 	delete iTransitionSetsValidator;
   135 	delete iAddUnitTestValidator;
   136 	delete iAddParamUnitTestValidator;
   137 	delete iDtorValidator;
   138 	}
   139 
   140 inline CComponentTester_ManageUnitTests_UnitTest::CComponentTester_ManageUnitTests_UnitTest(CDataLogger& aDataLogger,
   141 																	MUnitTestObserver& aObserver)
   142 : CUnitTest(KComponentTesterManageUnitTestsUnitTest, aDataLogger, aObserver)
   143 	{
   144 	//Do nothing
   145 	}
   146 
   147 // Now the Individual transitions need to be added.
   148 inline void CComponentTester_ManageUnitTests_UnitTest::ConstructL()
   149 	{
   150 	// Perform the base class initialization
   151 	UnitTestConstructL();
   152 
   153 	// Create the Unit test state accessor
   154 	iStateAccessor = new(ELeave) TComponentTester_StateAccessor;
   155 	// Construct the Unit test context.
   156 	iUTContext = new(ELeave) CComponentTester_UnitTestContext(iDataLogger, *iStateAccessor, *this);
   157 
   158 	// Add the Transitions in the order they are to run
   159 	// C'tor first, D'tor last...
   160 	iCtorValidator = new(ELeave) TComponentTester_Ctor_TransitionValidator(*iUTContext);
   161 	iTransitionSetsValidator = new(ELeave) TComponentTester_TransitionSets_TransitionValidator(*iUTContext);
   162 	iAddUnitTestValidator = new(ELeave) TComponentTester_AddUnitTest_TransitionValidator(*iUTContext);
   163 	iAddParamUnitTestValidator = new(ELeave) TComponentTester_AddParamUnitTest_TransitionValidator(*iUTContext);
   164 	iDtorValidator = new(ELeave) TComponentTester_Dtor_TransitionValidator(*iUTContext);
   165 
   166 	AddTransitionL(new(ELeave)CComponentTester_NewL_Transition(*iUTContext,*iCtorValidator));
   167 	AddTransitionL(new(ELeave)CComponentTester_TransitionSetsL_Transition(*iUTContext,*iTransitionSetsValidator));
   168 	AddTransitionL(new(ELeave)CComponentTester_AddUnitTestL_Transition(*iUTContext,*iAddUnitTestValidator));
   169 	AddTransitionL(new(ELeave)CComponentTester_AddParamUnitTestL_Transition(*iUTContext,*iAddParamUnitTestValidator));
   170 	AddTransitionL(new(ELeave)CComponentTester_Dtor_Transition(*iUTContext,*iDtorValidator));
   171 	}
   172 
   173 // ______________________________________________________________________________
   174 //
   175 _LIT(KComponentTesterRunTestsUnitTest,"CComponentTester_RunTests_UnitTest");
   176 
   177 CComponentTester_RunTests_UnitTest* CComponentTester_RunTests_UnitTest::NewL(CDataLogger& aDataLogger,
   178 											MUnitTestObserver& aObserver)
   179 	{
   180 	CComponentTester_RunTests_UnitTest* self = 
   181 					new(ELeave) CComponentTester_RunTests_UnitTest(aDataLogger,
   182 																aObserver);
   183 	CleanupStack::PushL(self);
   184 	self->ConstructL();
   185 	CleanupStack::Pop();
   186 	return self; 
   187 	}
   188 
   189 inline TInt CComponentTester_RunTests_UnitTest::RunError(TInt aError)
   190 	{
   191 	// The RunL left so chain to the base first and then cleanup
   192 	TInt error = CUnitTest::RunError(aError);	// Chain to base
   193 	delete iUTContext;
   194 	iUTContext = NULL;
   195 	delete iStateAccessor;
   196 	iStateAccessor = NULL;
   197 	/* delete any validators used */
   198 	delete iCtorValidator;
   199 	iCtorValidator = NULL;
   200 	delete iTestComponentValidator;
   201 	iTestComponentValidator = NULL;
   202 	delete iRunValidator;
   203 	iRunValidator = NULL;
   204 	delete iCompleteValidator;
   205 	iCompleteValidator = NULL;
   206 	delete iDtorValidator;
   207 	iDtorValidator = NULL;
   208 	return error;
   209 	}
   210 
   211 inline CComponentTester_RunTests_UnitTest::~CComponentTester_RunTests_UnitTest()
   212 	{
   213 	// Simply delete our test class instance
   214 	delete iUTContext;
   215 	delete iStateAccessor;
   216 	/* delete any validators used */
   217 	delete iCtorValidator;
   218 	delete iTestComponentValidator;
   219 	delete iRunValidator;
   220 	delete iCompleteValidator;
   221 	delete iDtorValidator;
   222 	}
   223 
   224 inline CComponentTester_RunTests_UnitTest::CComponentTester_RunTests_UnitTest(CDataLogger& aDataLogger,
   225 																	MUnitTestObserver& aObserver)
   226 : CUnitTest(KComponentTesterRunTestsUnitTest, aDataLogger, aObserver)
   227 	{
   228 	//Do nothing
   229 	}
   230 
   231 // Now the Individual transitions need to be added.
   232 inline void CComponentTester_RunTests_UnitTest::ConstructL()
   233 	{
   234 	// Perform the base class initialization
   235 	UnitTestConstructL();
   236 
   237 	// Create the Unit test state accessor
   238 	iStateAccessor = new(ELeave) TComponentTester_StateAccessor;
   239 	// Construct the Unit test context.
   240 	iUTContext = new(ELeave) CComponentTester_UnitTestContext(iDataLogger, *iStateAccessor, *this);
   241 
   242 	// Specify the tests to be run by the TestComponent method. 0 means run all tests
   243 //	iUTContext->iTests = 0;
   244 	TTestInfo* testInfo = new(ELeave) TTestInfo;
   245 	testInfo->iComponentId = 0;		// Run the first component found
   246 	testInfo->iUnitTestId = 0;		// Run the first unit test from the the component found
   247 	testInfo->iRunTime = 0;			// Run the test immediately
   248 	testInfo->iParameters = NULL;
   249 	User::LeaveIfError(iUTContext->iTests.Append(testInfo));
   250 
   251 	// Add the Transitions in the order they are to run
   252 	// C'tor first, D'tor last...
   253 	iCtorValidator = new(ELeave) TComponentTester_Ctor_TransitionValidator(*iUTContext);
   254 	iTestComponentValidator = new(ELeave) TComponentTester_TestComponent_TransitionValidator(*iUTContext);
   255 	iRunValidator = new(ELeave) TComponentTester_Run_TransitionValidator(*iUTContext);
   256 	iCompleteValidator = new(ELeave) TComponentTester_Complete_TransitionValidator(*iUTContext);
   257 	iDtorValidator = new(ELeave) TComponentTester_Dtor_TransitionValidator(*iUTContext);
   258 
   259 	AddTransitionL(new(ELeave)CComponentTester_NewL_Transition(*iUTContext,*iCtorValidator));
   260 	AddTransitionL(new(ELeave)CComponentTester_TestComponent_Transition(*iUTContext,*iTestComponentValidator));
   261 	AddTransitionL(new(ELeave)CComponentTester_RunL_Transition(*iUTContext,*iRunValidator));
   262 	AddTransitionL(new(ELeave)CComponentTester_Complete_Transition(*iUTContext,*iCompleteValidator));
   263 	AddTransitionL(new(ELeave)CComponentTester_Dtor_Transition(*iUTContext,*iDtorValidator));
   264 	}
   265 
   266