os/ossrv/lowlevellibsandfws/pluginfw/Test_Bed/DataLoggerTest/DataLoggerUnitTest.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 CDataLogger class.
    15 // 
    16 //
    17 
    18 #include "DataLoggerUnitTest.h"
    19 
    20 // ______________________________________________________________________________
    21 //
    22 _LIT(KDataLoggerCreateAndDestroyUnitTest,"CDataLogger_CreateAndDestroy_UnitTest");
    23 
    24 CDataLogger_CreateAndDestroy_UnitTest* CDataLogger_CreateAndDestroy_UnitTest::NewL(CDataLogger& aDataLogger,
    25 											MUnitTestObserver& aObserver)
    26 	{
    27 	CDataLogger_CreateAndDestroy_UnitTest* self = 
    28 					new(ELeave) CDataLogger_CreateAndDestroy_UnitTest(aDataLogger,
    29 																aObserver);
    30 	CleanupStack::PushL(self);
    31 	self->ConstructL();
    32 	CleanupStack::Pop();
    33 	return self; 
    34 	}
    35 
    36 inline TInt CDataLogger_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 CDataLogger_CreateAndDestroy_UnitTest::~CDataLogger_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 CDataLogger_CreateAndDestroy_UnitTest::CDataLogger_CreateAndDestroy_UnitTest(CDataLogger& aDataLogger,
    63 																	MUnitTestObserver& aObserver)
    64 : CUnitTest(KDataLoggerCreateAndDestroyUnitTest, aDataLogger, aObserver)
    65 	{
    66 	//Do nothing
    67 	}
    68 
    69 // Now the Individual transitions need to be added.
    70 inline void CDataLogger_CreateAndDestroy_UnitTest::ConstructL()
    71 	{
    72 	// Perform the base class initialization
    73 	UnitTestConstructL();
    74 
    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);
    79 
    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);
    84 	
    85 	AddTransitionL(new(ELeave)CDataLogger_NewL_Transition(*iUTContext,*iCtorValidator));
    86 	AddTransitionL(new(ELeave)CDataLogger_Dtor_Transition(*iUTContext,*iDtorValidator));
    87 	}
    88 
    89 // ______________________________________________________________________________
    90 //
    91 _LIT(KDataLoggerDumpMemoryBlockUnitTest,"CDataLogger_DumpMemoryBlock_UnitTest");
    92 
    93 CDataLogger_DumpMemoryBlock_UnitTest* CDataLogger_DumpMemoryBlock_UnitTest::NewL(CDataLogger& aDataLogger,
    94 											MUnitTestObserver& aObserver)
    95 	{
    96 	CDataLogger_DumpMemoryBlock_UnitTest* self = 
    97 					new(ELeave) CDataLogger_DumpMemoryBlock_UnitTest(aDataLogger,
    98 																aObserver);
    99 	CleanupStack::PushL(self);
   100 	self->ConstructL();
   101 	CleanupStack::Pop();
   102 	return self; 
   103 	}
   104 
   105 inline TInt CDataLogger_DumpMemoryBlock_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 iDumpMemoryBlockValidator;
   117 	iDumpMemoryBlockValidator = NULL;
   118 	delete iDtorValidator;
   119 	iDtorValidator = NULL;
   120 	return error;
   121 	}
   122 
   123 inline CDataLogger_DumpMemoryBlock_UnitTest::~CDataLogger_DumpMemoryBlock_UnitTest()
   124 	{
   125 	// Simply delete our test class instance
   126 	delete iUTContext;
   127 	delete iStateAccessor;
   128 	/* delete any validators used */
   129 	delete iCtorValidator;
   130 	delete iDumpMemoryBlockValidator;
   131 	delete iDtorValidator;
   132 	}
   133 
   134 inline CDataLogger_DumpMemoryBlock_UnitTest::CDataLogger_DumpMemoryBlock_UnitTest(CDataLogger& aDataLogger,
   135 																	MUnitTestObserver& aObserver)
   136 : CUnitTest(KDataLoggerDumpMemoryBlockUnitTest, aDataLogger, aObserver)
   137 	{
   138 	//Do nothing
   139 	}
   140 
   141 // Now the Individual transitions need to be added.
   142 inline void CDataLogger_DumpMemoryBlock_UnitTest::ConstructL()
   143 	{
   144 	// Perform the base class initialization
   145 	UnitTestConstructL();
   146 
   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);
   151 
   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();
   155 
   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;
   159 
   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);	
   165 	
   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));
   169 	}
   170 
   171 // ______________________________________________________________________________
   172 //
   173 _LIT(KDataLoggerLogInformationUnitTest,"CDataLogger_LogInformation_UnitTest");
   174 
   175 CDataLogger_LogInformation_UnitTest* CDataLogger_LogInformation_UnitTest::NewL(CDataLogger& aDataLogger,
   176 											MUnitTestObserver& aObserver)
   177 	{
   178 	CDataLogger_LogInformation_UnitTest* self = 
   179 					new(ELeave) CDataLogger_LogInformation_UnitTest(aDataLogger,
   180 																aObserver);
   181 	CleanupStack::PushL(self);
   182 	self->ConstructL();
   183 	CleanupStack::Pop();
   184 	return self; 
   185 	}
   186 
   187 inline TInt CDataLogger_LogInformation_UnitTest::RunError(TInt aError)
   188 	{
   189 	// The RunL left so chain to the base first and then cleanup
   190 	TInt error = CUnitTest::RunError(aError);	// Chain to base
   191 	delete iUTContext;
   192 	iUTContext = NULL;
   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;
   208 
   209 	return error;
   210 	}
   211 
   212 inline CDataLogger_LogInformation_UnitTest::~CDataLogger_LogInformation_UnitTest()
   213 	{
   214 	// Simply delete our test class instance
   215 	delete iUTContext;
   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;
   224 	}
   225 
   226 inline CDataLogger_LogInformation_UnitTest::CDataLogger_LogInformation_UnitTest(CDataLogger& aDataLogger,
   227 																	MUnitTestObserver& aObserver)
   228 : CUnitTest(KDataLoggerLogInformationUnitTest, aDataLogger, aObserver)
   229 	{
   230 	//Do nothing
   231 	}
   232 
   233 // Now the Individual transitions need to be added.
   234 inline void CDataLogger_LogInformation_UnitTest::ConstructL()
   235 	{
   236 	// Perform the base class initialization
   237 	UnitTestConstructL();
   238 
   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);
   243 
   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;
   248 
   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;
   253 
   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);
   262 
   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));
   269 	}
   270 
   271 // ______________________________________________________________________________
   272 //
   273 _LIT(KDataLoggerReportInformationUnitTest,"CDataLogger_ReportInformation_UnitTest");
   274 
   275 CDataLogger_ReportInformation_UnitTest* CDataLogger_ReportInformation_UnitTest::NewL(CDataLogger& aDataLogger,
   276 											MUnitTestObserver& aObserver)
   277 	{
   278 	CDataLogger_ReportInformation_UnitTest* self = 
   279 					new(ELeave) CDataLogger_ReportInformation_UnitTest(aDataLogger,
   280 																aObserver);
   281 	CleanupStack::PushL(self);
   282 	self->ConstructL();
   283 	CleanupStack::Pop();
   284 	return self; 
   285 	}
   286 
   287 inline TInt CDataLogger_ReportInformation_UnitTest::RunError(TInt aError)
   288 	{
   289 	// The RunL left so chain to the base first and then cleanup
   290 	TInt error = CUnitTest::RunError(aError);	// Chain to base
   291 	delete iUTContext;
   292 	iUTContext = NULL;
   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;
   304 
   305 	return error;
   306 	}
   307 
   308 inline CDataLogger_ReportInformation_UnitTest::~CDataLogger_ReportInformation_UnitTest()
   309 	{
   310 	// Simply delete our test class instance
   311 	delete iUTContext;
   312 	delete iStateAccessor;
   313 	/* delete any validators used */
   314 	delete iCtorValidator;
   315 	delete iReportInformationValidator;
   316 	delete iReportInformationWithParametersValidator;
   317 	delete iDtorValidator;
   318 	}
   319 
   320 inline CDataLogger_ReportInformation_UnitTest::CDataLogger_ReportInformation_UnitTest(CDataLogger& aDataLogger,
   321 																	MUnitTestObserver& aObserver)
   322 : CUnitTest(KDataLoggerReportInformationUnitTest, aDataLogger, aObserver)
   323 	{
   324 	//Do nothing
   325 	}
   326 
   327 // Now the Individual transitions need to be added.
   328 inline void CDataLogger_ReportInformation_UnitTest::ConstructL()
   329 	{
   330 	// Perform the base class initialization
   331 	UnitTestConstructL();
   332 
   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);
   337 
   338 	// Text to be inserted into the report by the ReportInformation method
   339 	_LIT(KReportComment, "This is a report comment");
   340 	iUTContext->iReportComment = &KReportComment();
   341 
   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();
   345 
   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();
   349 
   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);
   356 		
   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));
   361 	}
   362 
   363