os/ossrv/lowlevellibsandfws/pluginfw/Test_Bed/TransitionTest/TransitionUnitTest.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2001-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 CTransition class.
    15 // 
    16 //
    17 
    18 #include "TransitionUnitTest.h"
    19 
    20 // ______________________________________________________________________________
    21 //
    22 _LIT(KTransitionCreateAndDestroyUnitTest,"CTransition_CreateAndDestroy_UnitTest");
    23 
    24 CTransition_CreateAndDestroy_UnitTest* CTransition_CreateAndDestroy_UnitTest::NewL(CDataLogger& aDataLogger,
    25 											MUnitTestObserver& aObserver)
    26 	{
    27 	CTransition_CreateAndDestroy_UnitTest* self = 
    28 					new(ELeave) CTransition_CreateAndDestroy_UnitTest(aDataLogger,
    29 																aObserver);
    30 	CleanupStack::PushL(self);
    31 	self->ConstructL();
    32 	CleanupStack::Pop(self);
    33 	return self; 
    34 	}
    35 
    36 inline TInt CTransition_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 CTransition_CreateAndDestroy_UnitTest::~CTransition_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 CTransition_CreateAndDestroy_UnitTest::CTransition_CreateAndDestroy_UnitTest(CDataLogger& aDataLogger,
    63 																	MUnitTestObserver& aObserver)
    64 : CUnitTest(KTransitionCreateAndDestroyUnitTest, aDataLogger, aObserver)
    65 	{
    66 	//Do nothing
    67 	}
    68 
    69 // Now the Individual transitions need to be added.
    70 inline void CTransition_CreateAndDestroy_UnitTest::ConstructL()
    71 	{
    72 	// Perform the base class initialization
    73 	UnitTestConstructL();
    74 
    75 	// Create the Unit test state accessor
    76 	iStateAccessor = new(ELeave) TTransition_StateAccessor;
    77 	// Construct the Unit test context.
    78 	iUTContext = new(ELeave) CTransition_UnitTestContext(iDataLogger, *iStateAccessor, *this);
    79 
    80 	// Provide a valid context and validator for the target transition class under test.
    81 	iUTContext->iTargetContext = new(ELeave) CTargetTransition_UnitTestContext(iDataLogger, *iStateAccessor, *this);
    82 	iUTContext->iTargetValidator  = new(ELeave) TTransition_NULL_TransitionValidator(*(iUTContext->iTargetContext));
    83 
    84 	// Add the Transitions in the order they are to run
    85 	// C'tor first, D'tor last...
    86 	iCtorValidator = new(ELeave) TTransition_Ctor_TransitionValidator(*iUTContext);
    87 	AddTransitionL(new(ELeave)CTransition_NewL_Transition(*iUTContext,*iCtorValidator));
    88 
    89 	iDtorValidator = new(ELeave) TTransition_Dtor_TransitionValidator(*iUTContext);
    90 	AddTransitionL(new(ELeave)CTransition_Dtor_Transition(*iUTContext,*iDtorValidator));
    91 	}
    92 
    93 // ______________________________________________________________________________
    94 //
    95 _LIT(KTransitionTransitMethodLUnitTest,"CTransition_TransitMethodL_UnitTest");
    96 
    97 CTransition_TransitMethodL_UnitTest* CTransition_TransitMethodL_UnitTest::NewL(CDataLogger& aDataLogger,
    98 											MUnitTestObserver& aObserver)
    99 	{
   100 	CTransition_TransitMethodL_UnitTest* self = 
   101 					new(ELeave) CTransition_TransitMethodL_UnitTest(aDataLogger,
   102 																aObserver);
   103 	CleanupStack::PushL(self);
   104 	self->ConstructL();
   105 	CleanupStack::Pop(self);
   106 	return self; 
   107 	}
   108 
   109 inline TInt CTransition_TransitMethodL_UnitTest::RunError(TInt aError)
   110 	{
   111 	// The RunL left so chain to the base first and then cleanup
   112 	TInt error = CUnitTest::RunError(aError);	// Chain to base
   113 	delete iUTContext;
   114 	iUTContext = NULL;
   115 	delete iStateAccessor;
   116 	iStateAccessor = NULL;
   117 	/* delete any validators used */
   118 	delete iCtorValidator;
   119 	iCtorValidator = NULL;
   120 	delete iTransitMethodLValidator;
   121 	iTransitMethodLValidator = NULL;
   122 	delete iRepeatOnceValidator;
   123 	iRepeatOnceValidator = NULL;
   124 	delete iTransitionIdValidator;
   125 	iTransitionIdValidator = NULL;
   126 	delete iTransitionInfoValidator;
   127 	iTransitionInfoValidator = NULL;
   128 	delete iIsBlockingValidator;
   129 	iIsBlockingValidator = NULL;
   130 	delete iSetBlockingValidator;
   131 	iSetBlockingValidator = NULL;
   132 	delete iTransitMethodLValidator;
   133 	iTransitMethodLValidator = NULL;
   134 	delete iDtorValidator;
   135 	iDtorValidator = NULL;
   136 	return error;
   137 	}
   138 
   139 inline CTransition_TransitMethodL_UnitTest::~CTransition_TransitMethodL_UnitTest()
   140 	{
   141 	// Simply delete our test class instance
   142 	delete iUTContext;
   143 	delete iStateAccessor;
   144 	/* delete any validators used */
   145 	delete iCtorValidator;
   146 	delete iTransitionIdValidator;
   147 	delete iTransitionInfoValidator;
   148 	delete iIsBlockingValidator;
   149 	delete iSetBlockingValidator;
   150 	delete iTransitMethodLValidator;
   151 	delete iRepeatOnceValidator;
   152 	delete iDtorValidator;
   153 	}
   154 
   155 inline CTransition_TransitMethodL_UnitTest::CTransition_TransitMethodL_UnitTest(CDataLogger& aDataLogger,
   156 																	MUnitTestObserver& aObserver)
   157 : CUnitTest(KTransitionTransitMethodLUnitTest, aDataLogger, aObserver)
   158 	{
   159 	//Do nothing
   160 	}
   161 
   162 // Now the Individual transitions need to be added.
   163 inline void CTransition_TransitMethodL_UnitTest::ConstructL()
   164 	{
   165 	// Perform the base class initialization
   166 	UnitTestConstructL();
   167 
   168 	// Create the Unit test state accessor
   169 	iStateAccessor = new(ELeave) TTransition_StateAccessor;
   170 	// Construct the Unit test context.
   171 	iUTContext = new(ELeave) CTransition_UnitTestContext(iDataLogger, *iStateAccessor, *this);
   172 	// Provide a valid context and validator for the target transition class under test.
   173 	iUTContext->iTargetContext = new(ELeave) CTargetTransition_UnitTestContext(iDataLogger, *iStateAccessor, *this);
   174 	iUTContext->iTargetValidator  = new(ELeave) TTransition_NULL_TransitionValidator(*(iUTContext->iTargetContext));
   175 	// Add the Transitions in the order they are to run
   176 	// C'tor first, D'tor last...
   177 	iCtorValidator = new(ELeave) TTransition_Ctor_TransitionValidator(*iUTContext);
   178 	AddTransitionL(new(ELeave)CTransition_NewL_Transition(*iUTContext,*iCtorValidator));
   179 
   180 	// Test the flag setting
   181 	iTransitionIdValidator = new(ELeave) TTransition_TransitionId_TransitionValidator(*iUTContext);
   182 	AddTransitionL(new(ELeave)CTransition_TransitionId_Transition(*iUTContext,*iTransitionIdValidator));
   183 	iTransitionInfoValidator = new(ELeave) TTransition_TransitionInfo_TransitionValidator(*iUTContext);
   184 	AddTransitionL(new(ELeave)CTransition_TransitionInfo_Transition(*iUTContext,*iTransitionInfoValidator));
   185 	iIsBlockingValidator = new(ELeave) TTransition_IsBlocking_TransitionValidator(*iUTContext);
   186 	AddTransitionL(new(ELeave)CTransition_IsBlocking_Transition(*iUTContext,*iIsBlockingValidator));
   187 	iSetBlockingValidator = new(ELeave) TTransition_SetBlocking_TransitionValidator(*iUTContext);
   188 	AddTransitionL(new(ELeave)CTransition_SetBlocking_Transition(*iUTContext,*iSetBlockingValidator));
   189 	AddTransitionL(new(ELeave)CTransition_IsBlocking_Transition(*iUTContext,*iIsBlockingValidator));
   190 	AddTransitionL(new(ELeave)CTransition_SetBlocking_Transition(*iUTContext,*iSetBlockingValidator));
   191 	AddTransitionL(new(ELeave)CTransition_IsBlocking_Transition(*iUTContext,*iIsBlockingValidator));
   192 
   193 	// The transit
   194 	iTransitMethodLValidator = new(ELeave) TTransition_TransitMethodL_TransitionValidator(*iUTContext);
   195 	AddTransitionL(new(ELeave)CTransition_TransitMethodL_Transition(*iUTContext,*iTransitMethodLValidator));
   196 	// The repeat flag
   197 	iRepeatOnceValidator = new(ELeave) TTransition_RepeatOnce_TransitionValidator(*iUTContext);
   198 	AddTransitionL(new(ELeave)CTransition_RepeatOnce_Transition(*iUTContext,*iRepeatOnceValidator));
   199 	AddTransitionL(new(ELeave)CTransition_TransitMethodL_Transition(*iUTContext,*iTransitMethodLValidator));
   200 	// We are expecting the Abort code on the repeat call So no dtor required.
   201 	AddLeaveErrorCodeL(KErrAbort);
   202 	}
   203 
   204 
   205 // ______________________________________________________________________________
   206 //
   207 _LIT(KTransitionAsyncOperationUnitTest,"CTransition_AsyncOperation_UnitTest");
   208 
   209 CTransition_AsyncOperation_UnitTest* CTransition_AsyncOperation_UnitTest::NewL(CDataLogger& aDataLogger,
   210 											MUnitTestObserver& aObserver)
   211 	{
   212 	CTransition_AsyncOperation_UnitTest* self = 
   213 					new(ELeave) CTransition_AsyncOperation_UnitTest(aDataLogger,
   214 																aObserver);
   215 	CleanupStack::PushL(self);
   216 	self->ConstructL();
   217 	CleanupStack::Pop(self);
   218 	return self; 
   219 	}
   220 
   221 inline TInt CTransition_AsyncOperation_UnitTest::RunError(TInt aError)
   222 	{
   223 	// The RunL left so chain to the base first and then cleanup
   224 	TInt error = CUnitTest::RunError(aError);	// Chain to base
   225 	delete iUTContext;
   226 	iUTContext = NULL;
   227 	delete iStateAccessor;
   228 	iStateAccessor = NULL;
   229 	/* delete any validators used */
   230 	delete iCtorValidator;
   231 	iCtorValidator = NULL;
   232 	delete iRunTransitionValidator;
   233 	iRunTransitionValidator = NULL;
   234 	delete iCancelValidator;
   235 	iCancelValidator = NULL;
   236 	delete iGetErrorCodeValidator;
   237 	iGetErrorCodeValidator = NULL;
   238 	delete iDtorValidator;
   239 	iDtorValidator = NULL;
   240 	return error;
   241 	}
   242 
   243 inline CTransition_AsyncOperation_UnitTest::~CTransition_AsyncOperation_UnitTest()
   244 	{
   245 	// Simply delete our test class instance
   246 	delete iUTContext;
   247 	delete iStateAccessor;
   248 	/* delete any validators used */
   249 	delete iCtorValidator;
   250 	delete iRunTransitionValidator;
   251 	delete iCancelValidator;
   252 	delete iGetErrorCodeValidator;
   253 	delete iDtorValidator;
   254 	}
   255 
   256 inline CTransition_AsyncOperation_UnitTest::CTransition_AsyncOperation_UnitTest(CDataLogger& aDataLogger,
   257 																	MUnitTestObserver& aObserver)
   258 : CUnitTest(KTransitionAsyncOperationUnitTest, aDataLogger, aObserver)
   259 	{
   260 	//Do nothing
   261 	}
   262 
   263 // Now the Individual transitions need to be added.
   264 inline void CTransition_AsyncOperation_UnitTest::ConstructL()
   265 	{
   266 	// Perform the base class initialization
   267 	UnitTestConstructL();
   268 
   269 	// Create the Unit test state accessor
   270 	iStateAccessor = new(ELeave) TTransition_StateAccessor;
   271 	// Construct the Unit test context.
   272 	iUTContext = new(ELeave) CTransition_UnitTestContext(iDataLogger, *iStateAccessor, *this);
   273 	// Provide a valid context and validator for the target transition class under test.
   274 	iUTContext->iTargetContext = new(ELeave) CTargetTransition_UnitTestContext(iDataLogger, *iStateAccessor, *this);
   275 	iUTContext->iTargetValidator  = new(ELeave) TTransition_NULL_TransitionValidator(*(iUTContext->iTargetContext));
   276 	// Add the Transitions in the order they are to run
   277 	// C'tor first, D'tor last...
   278 	/*	Examples of C'tor and D'tor transitions on CTransition class.
   279 		using ctor and dtor validators */
   280 	iCtorValidator = new(ELeave) TTransition_Ctor_TransitionValidator(*iUTContext);
   281 	AddTransitionL(new(ELeave)CTransition_NewL_Transition(*iUTContext,*iCtorValidator));
   282 
   283 	// Run the target transition asynchronously, cancel, check the error code, 
   284 	// and then run asynchronously again to completion
   285 	iRunTransitionValidator = new(ELeave) TTransition_RunTransition_TransitionValidator(*iUTContext);
   286 	AddTransitionL(new(ELeave)CTransition_RunTransition_Transition(*iUTContext,*iRunTransitionValidator));
   287 	iCancelValidator = new(ELeave) TTransition_Cancel_TransitionValidator(*iUTContext);
   288 	AddTransitionL(new(ELeave)CTransition_Cancel_Transition(*iUTContext,*iRunTransitionValidator));
   289 	iGetErrorCodeValidator = new(ELeave) TTransition_GetErrorCode_TransitionValidator(*iUTContext);
   290 	AddTransitionL(new(ELeave)CTransition_GetErrorCode_Transition(*iUTContext,*iGetErrorCodeValidator));
   291 	AddTransitionL(new(ELeave)CTransition_RunTransition_Transition(*iUTContext,*iRunTransitionValidator));
   292 
   293 	iDtorValidator = new(ELeave) TTransition_Dtor_TransitionValidator(*iUTContext);
   294 	AddBlockingTransitionL(new(ELeave)CTransition_Dtor_Transition(*iUTContext,*iDtorValidator));
   295 	}