os/ossrv/lowlevellibsandfws/pluginfw/Test_Bed/TransitionTest/TransitionUnitTest.cpp
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // The unit test class implementations for the CTransition class.
18 #include "TransitionUnitTest.h"
20 // ______________________________________________________________________________
22 _LIT(KTransitionCreateAndDestroyUnitTest,"CTransition_CreateAndDestroy_UnitTest");
24 CTransition_CreateAndDestroy_UnitTest* CTransition_CreateAndDestroy_UnitTest::NewL(CDataLogger& aDataLogger,
25 MUnitTestObserver& aObserver)
27 CTransition_CreateAndDestroy_UnitTest* self =
28 new(ELeave) CTransition_CreateAndDestroy_UnitTest(aDataLogger,
30 CleanupStack::PushL(self);
32 CleanupStack::Pop(self);
36 inline TInt CTransition_CreateAndDestroy_UnitTest::RunError(TInt aError)
38 // The RunL left so chain to the base first and then cleanup
39 TInt error = CUnitTest::RunError(aError); // Chain to base
42 delete iStateAccessor;
43 iStateAccessor = NULL;
44 /* delete any validators used */
45 delete iCtorValidator;
46 iCtorValidator = NULL;
47 delete iDtorValidator;
48 iDtorValidator = NULL;
52 inline CTransition_CreateAndDestroy_UnitTest::~CTransition_CreateAndDestroy_UnitTest()
54 // Simply delete our test class instance
56 delete iStateAccessor;
57 /* delete any validators used */
58 delete iCtorValidator;
59 delete iDtorValidator;
62 inline CTransition_CreateAndDestroy_UnitTest::CTransition_CreateAndDestroy_UnitTest(CDataLogger& aDataLogger,
63 MUnitTestObserver& aObserver)
64 : CUnitTest(KTransitionCreateAndDestroyUnitTest, aDataLogger, aObserver)
69 // Now the Individual transitions need to be added.
70 inline void CTransition_CreateAndDestroy_UnitTest::ConstructL()
72 // Perform the base class initialization
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);
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));
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));
89 iDtorValidator = new(ELeave) TTransition_Dtor_TransitionValidator(*iUTContext);
90 AddTransitionL(new(ELeave)CTransition_Dtor_Transition(*iUTContext,*iDtorValidator));
93 // ______________________________________________________________________________
95 _LIT(KTransitionTransitMethodLUnitTest,"CTransition_TransitMethodL_UnitTest");
97 CTransition_TransitMethodL_UnitTest* CTransition_TransitMethodL_UnitTest::NewL(CDataLogger& aDataLogger,
98 MUnitTestObserver& aObserver)
100 CTransition_TransitMethodL_UnitTest* self =
101 new(ELeave) CTransition_TransitMethodL_UnitTest(aDataLogger,
103 CleanupStack::PushL(self);
105 CleanupStack::Pop(self);
109 inline TInt CTransition_TransitMethodL_UnitTest::RunError(TInt aError)
111 // The RunL left so chain to the base first and then cleanup
112 TInt error = CUnitTest::RunError(aError); // Chain to base
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;
139 inline CTransition_TransitMethodL_UnitTest::~CTransition_TransitMethodL_UnitTest()
141 // Simply delete our test class instance
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;
155 inline CTransition_TransitMethodL_UnitTest::CTransition_TransitMethodL_UnitTest(CDataLogger& aDataLogger,
156 MUnitTestObserver& aObserver)
157 : CUnitTest(KTransitionTransitMethodLUnitTest, aDataLogger, aObserver)
162 // Now the Individual transitions need to be added.
163 inline void CTransition_TransitMethodL_UnitTest::ConstructL()
165 // Perform the base class initialization
166 UnitTestConstructL();
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));
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));
194 iTransitMethodLValidator = new(ELeave) TTransition_TransitMethodL_TransitionValidator(*iUTContext);
195 AddTransitionL(new(ELeave)CTransition_TransitMethodL_Transition(*iUTContext,*iTransitMethodLValidator));
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);
205 // ______________________________________________________________________________
207 _LIT(KTransitionAsyncOperationUnitTest,"CTransition_AsyncOperation_UnitTest");
209 CTransition_AsyncOperation_UnitTest* CTransition_AsyncOperation_UnitTest::NewL(CDataLogger& aDataLogger,
210 MUnitTestObserver& aObserver)
212 CTransition_AsyncOperation_UnitTest* self =
213 new(ELeave) CTransition_AsyncOperation_UnitTest(aDataLogger,
215 CleanupStack::PushL(self);
217 CleanupStack::Pop(self);
221 inline TInt CTransition_AsyncOperation_UnitTest::RunError(TInt aError)
223 // The RunL left so chain to the base first and then cleanup
224 TInt error = CUnitTest::RunError(aError); // Chain to base
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;
243 inline CTransition_AsyncOperation_UnitTest::~CTransition_AsyncOperation_UnitTest()
245 // Simply delete our test class instance
247 delete iStateAccessor;
248 /* delete any validators used */
249 delete iCtorValidator;
250 delete iRunTransitionValidator;
251 delete iCancelValidator;
252 delete iGetErrorCodeValidator;
253 delete iDtorValidator;
256 inline CTransition_AsyncOperation_UnitTest::CTransition_AsyncOperation_UnitTest(CDataLogger& aDataLogger,
257 MUnitTestObserver& aObserver)
258 : CUnitTest(KTransitionAsyncOperationUnitTest, aDataLogger, aObserver)
263 // Now the Individual transitions need to be added.
264 inline void CTransition_AsyncOperation_UnitTest::ConstructL()
266 // Perform the base class initialization
267 UnitTestConstructL();
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));
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));
293 iDtorValidator = new(ELeave) TTransition_Dtor_TransitionValidator(*iUTContext);
294 AddBlockingTransitionL(new(ELeave)CTransition_Dtor_Transition(*iUTContext,*iDtorValidator));