os/ossrv/lowlevellibsandfws/pluginfw/Test_Bed/DataLoggerTest/DataLoggerUnitTest.cpp
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // The unit test class implementations for the CDataLogger class.
18 #include "DataLoggerUnitTest.h"
20 // ______________________________________________________________________________
22 _LIT(KDataLoggerCreateAndDestroyUnitTest,"CDataLogger_CreateAndDestroy_UnitTest");
24 CDataLogger_CreateAndDestroy_UnitTest* CDataLogger_CreateAndDestroy_UnitTest::NewL(CDataLogger& aDataLogger,
25 MUnitTestObserver& aObserver)
27 CDataLogger_CreateAndDestroy_UnitTest* self =
28 new(ELeave) CDataLogger_CreateAndDestroy_UnitTest(aDataLogger,
30 CleanupStack::PushL(self);
36 inline TInt CDataLogger_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 CDataLogger_CreateAndDestroy_UnitTest::~CDataLogger_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 CDataLogger_CreateAndDestroy_UnitTest::CDataLogger_CreateAndDestroy_UnitTest(CDataLogger& aDataLogger,
63 MUnitTestObserver& aObserver)
64 : CUnitTest(KDataLoggerCreateAndDestroyUnitTest, aDataLogger, aObserver)
69 // Now the Individual transitions need to be added.
70 inline void CDataLogger_CreateAndDestroy_UnitTest::ConstructL()
72 // Perform the base class initialization
75 // Create the Unit test state accessor
76 iStateAccessor = new(ELeave) TDataLogger_StateAccessor;
77 // Construct the Unit test context.
78 iUTContext = new(ELeave) CDataLogger_UnitTestContext(iDataLogger, *iStateAccessor, *this);
80 // Add the Transitions in the order they are to run
81 // C'tor first, D'tor last...
82 iCtorValidator = new(ELeave) TDataLogger_Ctor_TransitionValidator(*iUTContext);
83 iDtorValidator = new(ELeave) TDataLogger_Dtor_TransitionValidator(*iUTContext);
85 AddTransitionL(new(ELeave)CDataLogger_NewL_Transition(*iUTContext,*iCtorValidator));
86 AddTransitionL(new(ELeave)CDataLogger_Dtor_Transition(*iUTContext,*iDtorValidator));
89 // ______________________________________________________________________________
91 _LIT(KDataLoggerDumpMemoryBlockUnitTest,"CDataLogger_DumpMemoryBlock_UnitTest");
93 CDataLogger_DumpMemoryBlock_UnitTest* CDataLogger_DumpMemoryBlock_UnitTest::NewL(CDataLogger& aDataLogger,
94 MUnitTestObserver& aObserver)
96 CDataLogger_DumpMemoryBlock_UnitTest* self =
97 new(ELeave) CDataLogger_DumpMemoryBlock_UnitTest(aDataLogger,
99 CleanupStack::PushL(self);
105 inline TInt CDataLogger_DumpMemoryBlock_UnitTest::RunError(TInt aError)
107 // The RunL left so chain to the base first and then cleanup
108 TInt error = CUnitTest::RunError(aError); // Chain to base
111 delete iStateAccessor;
112 iStateAccessor = NULL;
113 /* delete any validators used */
114 delete iCtorValidator;
115 iCtorValidator = NULL;
116 delete iDumpMemoryBlockValidator;
117 iDumpMemoryBlockValidator = NULL;
118 delete iDtorValidator;
119 iDtorValidator = NULL;
123 inline CDataLogger_DumpMemoryBlock_UnitTest::~CDataLogger_DumpMemoryBlock_UnitTest()
125 // Simply delete our test class instance
127 delete iStateAccessor;
128 /* delete any validators used */
129 delete iCtorValidator;
130 delete iDumpMemoryBlockValidator;
131 delete iDtorValidator;
134 inline CDataLogger_DumpMemoryBlock_UnitTest::CDataLogger_DumpMemoryBlock_UnitTest(CDataLogger& aDataLogger,
135 MUnitTestObserver& aObserver)
136 : CUnitTest(KDataLoggerDumpMemoryBlockUnitTest, aDataLogger, aObserver)
141 // Now the Individual transitions need to be added.
142 inline void CDataLogger_DumpMemoryBlock_UnitTest::ConstructL()
144 // Perform the base class initialization
145 UnitTestConstructL();
147 // Create the Unit test state accessor
148 iStateAccessor = new(ELeave) TDataLogger_StateAccessor;
149 // Construct the Unit test context.
150 iUTContext = new(ELeave) CDataLogger_UnitTestContext(iDataLogger, *iStateAccessor, *this);
152 // Set the address of the block to be logged as the address of the literal
153 _LIT8(KDumpedText, "Text dumped by the DumpMemoryBlock method");
154 iUTContext->iAddress = KDumpedText().Ptr();
156 // Set the number of bytes to be logged to as the length of the text to be dumped
157 TInt byteLength = KDumpedText().Length();
158 iUTContext->iLength = byteLength;
160 // Add the Transitions in the order they are to run
161 // C'tor first, D'tor last...
162 iCtorValidator = new(ELeave) TDataLogger_Ctor_TransitionValidator(*iUTContext);
163 iDumpMemoryBlockValidator = new(ELeave) TDataLogger_DumpMemoryBlock_TransitionValidator(*iUTContext);
164 iDtorValidator = new(ELeave) TDataLogger_Dtor_TransitionValidator(*iUTContext);
166 AddTransitionL(new(ELeave)CDataLogger_NewL_Transition(*iUTContext,*iCtorValidator));
167 AddTransitionL(new(ELeave)CDataLogger_DumpMemoryBlock_Transition(*iUTContext,*iDumpMemoryBlockValidator));
168 AddTransitionL(new(ELeave)CDataLogger_Dtor_Transition(*iUTContext,*iDtorValidator));
171 // ______________________________________________________________________________
173 _LIT(KDataLoggerLogInformationUnitTest,"CDataLogger_LogInformation_UnitTest");
175 CDataLogger_LogInformation_UnitTest* CDataLogger_LogInformation_UnitTest::NewL(CDataLogger& aDataLogger,
176 MUnitTestObserver& aObserver)
178 CDataLogger_LogInformation_UnitTest* self =
179 new(ELeave) CDataLogger_LogInformation_UnitTest(aDataLogger,
181 CleanupStack::PushL(self);
187 inline TInt CDataLogger_LogInformation_UnitTest::RunError(TInt aError)
189 // The RunL left so chain to the base first and then cleanup
190 TInt error = CUnitTest::RunError(aError); // Chain to base
193 delete iStateAccessor;
194 iStateAccessor = NULL;
195 /* delete any validators used */
196 delete iCtorValidator;
197 iCtorValidator = NULL;
198 delete iLogInformationValidator;
199 iLogInformationValidator = NULL;
200 delete iLogInformationNarrowValidator;
201 iLogInformationNarrowValidator =NULL;
202 delete iLogInformationWithParametersValidator;
203 iLogInformationWithParametersValidator = NULL;
204 delete iLogInformationWithParametersNarrowValidator;
205 iLogInformationWithParametersNarrowValidator = NULL;
206 delete iDtorValidator;
207 iDtorValidator = NULL;
212 inline CDataLogger_LogInformation_UnitTest::~CDataLogger_LogInformation_UnitTest()
214 // Simply delete our test class instance
216 delete iStateAccessor;
217 /* delete any validators used */
218 delete iCtorValidator;
219 delete iLogInformationValidator;
220 delete iLogInformationNarrowValidator;
221 delete iLogInformationWithParametersValidator;
222 delete iLogInformationWithParametersNarrowValidator;
223 delete iDtorValidator;
226 inline CDataLogger_LogInformation_UnitTest::CDataLogger_LogInformation_UnitTest(CDataLogger& aDataLogger,
227 MUnitTestObserver& aObserver)
228 : CUnitTest(KDataLoggerLogInformationUnitTest, aDataLogger, aObserver)
233 // Now the Individual transitions need to be added.
234 inline void CDataLogger_LogInformation_UnitTest::ConstructL()
236 // Perform the base class initialization
237 UnitTestConstructL();
239 // Create the Unit test state accessor
240 iStateAccessor = new(ELeave) TDataLogger_StateAccessor;
241 // Construct the Unit test context.
242 iUTContext = new(ELeave) CDataLogger_UnitTestContext(iDataLogger, *iStateAccessor, *this);
244 // Wide descriptor to be used as passed in parameter in LogInformationWithParameters transition
245 _LIT(KTextWide,"Parameter - wide descriptor version");
246 HBufC* hptr1 = KTextWide().AllocL();
247 iUTContext->iArg = hptr1;
249 // Narrow descriptor to be used as passed in parameter in LogInformationWithParametersNarrow transition
250 _LIT8(KTextNarrow,"Parameter - narrow descriptor version");
251 HBufC8* hptr2 = KTextNarrow().AllocL();;
252 iUTContext->iArgNarrow = hptr2;
254 // Add the Transitions in the order they are to run
255 // C'tor first, D'tor last...
256 iCtorValidator = new(ELeave) TDataLogger_Ctor_TransitionValidator(*iUTContext);
257 iLogInformationValidator = new(ELeave) TDataLogger_LogInformation_TransitionValidator(*iUTContext);
258 iLogInformationNarrowValidator = new(ELeave) TDataLogger_LogInformationNarrow_TransitionValidator(*iUTContext);
259 iLogInformationWithParametersValidator = new(ELeave) TDataLogger_LogInformationWithParameters_TransitionValidator(*iUTContext);
260 iLogInformationWithParametersNarrowValidator = new(ELeave) TDataLogger_LogInformationWithParametersNarrow_TransitionValidator(*iUTContext);
261 iDtorValidator = new(ELeave) TDataLogger_Dtor_TransitionValidator(*iUTContext);
263 AddTransitionL(new(ELeave)CDataLogger_NewL_Transition(*iUTContext,*iCtorValidator));
264 AddTransitionL(new(ELeave)CDataLogger_LogInformation_Transition(*iUTContext,*iLogInformationValidator));
265 AddTransitionL(new(ELeave)CDataLogger_LogInformationNarrow_Transition(*iUTContext,*iLogInformationNarrowValidator));
266 AddTransitionL(new(ELeave)CDataLogger_LogInformationWithParameters_Transition(*iUTContext,*iLogInformationWithParametersValidator));
267 AddTransitionL(new(ELeave)CDataLogger_LogInformationWithParametersNarrow_Transition(*iUTContext,*iLogInformationWithParametersNarrowValidator));
268 AddTransitionL(new(ELeave)CDataLogger_Dtor_Transition(*iUTContext,*iDtorValidator));
271 // ______________________________________________________________________________
273 _LIT(KDataLoggerReportInformationUnitTest,"CDataLogger_ReportInformation_UnitTest");
275 CDataLogger_ReportInformation_UnitTest* CDataLogger_ReportInformation_UnitTest::NewL(CDataLogger& aDataLogger,
276 MUnitTestObserver& aObserver)
278 CDataLogger_ReportInformation_UnitTest* self =
279 new(ELeave) CDataLogger_ReportInformation_UnitTest(aDataLogger,
281 CleanupStack::PushL(self);
287 inline TInt CDataLogger_ReportInformation_UnitTest::RunError(TInt aError)
289 // The RunL left so chain to the base first and then cleanup
290 TInt error = CUnitTest::RunError(aError); // Chain to base
293 delete iStateAccessor;
294 iStateAccessor = NULL;
295 /* delete any validators used */
296 delete iCtorValidator;
297 iCtorValidator = NULL;
298 delete iReportInformationValidator;
299 iReportInformationValidator = NULL;
300 delete iReportInformationWithParametersValidator;
301 iReportInformationWithParametersValidator = NULL;
302 delete iDtorValidator;
303 iDtorValidator = NULL;
308 inline CDataLogger_ReportInformation_UnitTest::~CDataLogger_ReportInformation_UnitTest()
310 // Simply delete our test class instance
312 delete iStateAccessor;
313 /* delete any validators used */
314 delete iCtorValidator;
315 delete iReportInformationValidator;
316 delete iReportInformationWithParametersValidator;
317 delete iDtorValidator;
320 inline CDataLogger_ReportInformation_UnitTest::CDataLogger_ReportInformation_UnitTest(CDataLogger& aDataLogger,
321 MUnitTestObserver& aObserver)
322 : CUnitTest(KDataLoggerReportInformationUnitTest, aDataLogger, aObserver)
327 // Now the Individual transitions need to be added.
328 inline void CDataLogger_ReportInformation_UnitTest::ConstructL()
330 // Perform the base class initialization
331 UnitTestConstructL();
333 // Create the Unit test state accessor
334 iStateAccessor = new(ELeave) TDataLogger_StateAccessor;
335 // Construct the Unit test context.
336 iUTContext = new(ELeave) CDataLogger_UnitTestContext(iDataLogger, *iStateAccessor, *this);
338 // Text to be inserted into the report by the ReportInformation method
339 _LIT(KReportComment, "This is a report comment");
340 iUTContext->iReportComment = &KReportComment();
342 // The text to be inserted into the report by the ReportInformationWithParameters method
343 _LIT(KFormatReport, "This report text will be followed by a parameter: %S");
344 iUTContext->iFormatReport = &KFormatReport();
346 // The parameter to be appended to the end of the text above by the ReportInformationWithParameters method
347 _LIT(KReportArg, "This is the report parameter");
348 iUTContext->iReportArg = &KReportArg();
350 // Add the Transitions in the order they are to run
351 // C'tor first, D'tor last...
352 iCtorValidator = new(ELeave) TDataLogger_Ctor_TransitionValidator(*iUTContext);
353 iReportInformationValidator = new(ELeave) TDataLogger_ReportInformation_TransitionValidator(*iUTContext);
354 iReportInformationWithParametersValidator = new(ELeave) TDataLogger_ReportInformationWithParameters_TransitionValidator(*iUTContext);
355 iDtorValidator = new(ELeave) TDataLogger_Dtor_TransitionValidator(*iUTContext);
357 AddTransitionL(new(ELeave)CDataLogger_NewL_Transition(*iUTContext,*iCtorValidator));
358 AddTransitionL(new(ELeave)CDataLogger_ReportInformation_Transition(*iUTContext,*iReportInformationValidator));
359 AddTransitionL(new(ELeave)CDataLogger_ReportInformationWithParameters_Transition(*iUTContext,*iReportInformationWithParametersValidator));
360 AddTransitionL(new(ELeave)CDataLogger_Dtor_Transition(*iUTContext,*iDtorValidator));