sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // The unit test class implementations for the CDataLogger class. sl@0: // sl@0: // sl@0: sl@0: #include "DataLoggerUnitTest.h" sl@0: sl@0: // ______________________________________________________________________________ sl@0: // sl@0: _LIT(KDataLoggerCreateAndDestroyUnitTest,"CDataLogger_CreateAndDestroy_UnitTest"); sl@0: sl@0: CDataLogger_CreateAndDestroy_UnitTest* CDataLogger_CreateAndDestroy_UnitTest::NewL(CDataLogger& aDataLogger, sl@0: MUnitTestObserver& aObserver) sl@0: { sl@0: CDataLogger_CreateAndDestroy_UnitTest* self = sl@0: new(ELeave) CDataLogger_CreateAndDestroy_UnitTest(aDataLogger, sl@0: aObserver); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: inline TInt CDataLogger_CreateAndDestroy_UnitTest::RunError(TInt aError) sl@0: { sl@0: // The RunL left so chain to the base first and then cleanup sl@0: TInt error = CUnitTest::RunError(aError); // Chain to base sl@0: delete iUTContext; sl@0: iUTContext = NULL; sl@0: delete iStateAccessor; sl@0: iStateAccessor = NULL; sl@0: /* delete any validators used */ sl@0: delete iCtorValidator; sl@0: iCtorValidator = NULL; sl@0: delete iDtorValidator; sl@0: iDtorValidator = NULL; sl@0: return error; sl@0: } sl@0: sl@0: inline CDataLogger_CreateAndDestroy_UnitTest::~CDataLogger_CreateAndDestroy_UnitTest() sl@0: { sl@0: // Simply delete our test class instance sl@0: delete iUTContext; sl@0: delete iStateAccessor; sl@0: /* delete any validators used */ sl@0: delete iCtorValidator; sl@0: delete iDtorValidator; sl@0: } sl@0: sl@0: inline CDataLogger_CreateAndDestroy_UnitTest::CDataLogger_CreateAndDestroy_UnitTest(CDataLogger& aDataLogger, sl@0: MUnitTestObserver& aObserver) sl@0: : CUnitTest(KDataLoggerCreateAndDestroyUnitTest, aDataLogger, aObserver) sl@0: { sl@0: //Do nothing sl@0: } sl@0: sl@0: // Now the Individual transitions need to be added. sl@0: inline void CDataLogger_CreateAndDestroy_UnitTest::ConstructL() sl@0: { sl@0: // Perform the base class initialization sl@0: UnitTestConstructL(); sl@0: sl@0: // Create the Unit test state accessor sl@0: iStateAccessor = new(ELeave) TDataLogger_StateAccessor; sl@0: // Construct the Unit test context. sl@0: iUTContext = new(ELeave) CDataLogger_UnitTestContext(iDataLogger, *iStateAccessor, *this); sl@0: sl@0: // Add the Transitions in the order they are to run sl@0: // C'tor first, D'tor last... sl@0: iCtorValidator = new(ELeave) TDataLogger_Ctor_TransitionValidator(*iUTContext); sl@0: iDtorValidator = new(ELeave) TDataLogger_Dtor_TransitionValidator(*iUTContext); sl@0: sl@0: AddTransitionL(new(ELeave)CDataLogger_NewL_Transition(*iUTContext,*iCtorValidator)); sl@0: AddTransitionL(new(ELeave)CDataLogger_Dtor_Transition(*iUTContext,*iDtorValidator)); sl@0: } sl@0: sl@0: // ______________________________________________________________________________ sl@0: // sl@0: _LIT(KDataLoggerDumpMemoryBlockUnitTest,"CDataLogger_DumpMemoryBlock_UnitTest"); sl@0: sl@0: CDataLogger_DumpMemoryBlock_UnitTest* CDataLogger_DumpMemoryBlock_UnitTest::NewL(CDataLogger& aDataLogger, sl@0: MUnitTestObserver& aObserver) sl@0: { sl@0: CDataLogger_DumpMemoryBlock_UnitTest* self = sl@0: new(ELeave) CDataLogger_DumpMemoryBlock_UnitTest(aDataLogger, sl@0: aObserver); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: inline TInt CDataLogger_DumpMemoryBlock_UnitTest::RunError(TInt aError) sl@0: { sl@0: // The RunL left so chain to the base first and then cleanup sl@0: TInt error = CUnitTest::RunError(aError); // Chain to base sl@0: delete iUTContext; sl@0: iUTContext = NULL; sl@0: delete iStateAccessor; sl@0: iStateAccessor = NULL; sl@0: /* delete any validators used */ sl@0: delete iCtorValidator; sl@0: iCtorValidator = NULL; sl@0: delete iDumpMemoryBlockValidator; sl@0: iDumpMemoryBlockValidator = NULL; sl@0: delete iDtorValidator; sl@0: iDtorValidator = NULL; sl@0: return error; sl@0: } sl@0: sl@0: inline CDataLogger_DumpMemoryBlock_UnitTest::~CDataLogger_DumpMemoryBlock_UnitTest() sl@0: { sl@0: // Simply delete our test class instance sl@0: delete iUTContext; sl@0: delete iStateAccessor; sl@0: /* delete any validators used */ sl@0: delete iCtorValidator; sl@0: delete iDumpMemoryBlockValidator; sl@0: delete iDtorValidator; sl@0: } sl@0: sl@0: inline CDataLogger_DumpMemoryBlock_UnitTest::CDataLogger_DumpMemoryBlock_UnitTest(CDataLogger& aDataLogger, sl@0: MUnitTestObserver& aObserver) sl@0: : CUnitTest(KDataLoggerDumpMemoryBlockUnitTest, aDataLogger, aObserver) sl@0: { sl@0: //Do nothing sl@0: } sl@0: sl@0: // Now the Individual transitions need to be added. sl@0: inline void CDataLogger_DumpMemoryBlock_UnitTest::ConstructL() sl@0: { sl@0: // Perform the base class initialization sl@0: UnitTestConstructL(); sl@0: sl@0: // Create the Unit test state accessor sl@0: iStateAccessor = new(ELeave) TDataLogger_StateAccessor; sl@0: // Construct the Unit test context. sl@0: iUTContext = new(ELeave) CDataLogger_UnitTestContext(iDataLogger, *iStateAccessor, *this); sl@0: sl@0: // Set the address of the block to be logged as the address of the literal sl@0: _LIT8(KDumpedText, "Text dumped by the DumpMemoryBlock method"); sl@0: iUTContext->iAddress = KDumpedText().Ptr(); sl@0: sl@0: // Set the number of bytes to be logged to as the length of the text to be dumped sl@0: TInt byteLength = KDumpedText().Length(); sl@0: iUTContext->iLength = byteLength; sl@0: sl@0: // Add the Transitions in the order they are to run sl@0: // C'tor first, D'tor last... sl@0: iCtorValidator = new(ELeave) TDataLogger_Ctor_TransitionValidator(*iUTContext); sl@0: iDumpMemoryBlockValidator = new(ELeave) TDataLogger_DumpMemoryBlock_TransitionValidator(*iUTContext); sl@0: iDtorValidator = new(ELeave) TDataLogger_Dtor_TransitionValidator(*iUTContext); sl@0: sl@0: AddTransitionL(new(ELeave)CDataLogger_NewL_Transition(*iUTContext,*iCtorValidator)); sl@0: AddTransitionL(new(ELeave)CDataLogger_DumpMemoryBlock_Transition(*iUTContext,*iDumpMemoryBlockValidator)); sl@0: AddTransitionL(new(ELeave)CDataLogger_Dtor_Transition(*iUTContext,*iDtorValidator)); sl@0: } sl@0: sl@0: // ______________________________________________________________________________ sl@0: // sl@0: _LIT(KDataLoggerLogInformationUnitTest,"CDataLogger_LogInformation_UnitTest"); sl@0: sl@0: CDataLogger_LogInformation_UnitTest* CDataLogger_LogInformation_UnitTest::NewL(CDataLogger& aDataLogger, sl@0: MUnitTestObserver& aObserver) sl@0: { sl@0: CDataLogger_LogInformation_UnitTest* self = sl@0: new(ELeave) CDataLogger_LogInformation_UnitTest(aDataLogger, sl@0: aObserver); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: inline TInt CDataLogger_LogInformation_UnitTest::RunError(TInt aError) sl@0: { sl@0: // The RunL left so chain to the base first and then cleanup sl@0: TInt error = CUnitTest::RunError(aError); // Chain to base sl@0: delete iUTContext; sl@0: iUTContext = NULL; sl@0: delete iStateAccessor; sl@0: iStateAccessor = NULL; sl@0: /* delete any validators used */ sl@0: delete iCtorValidator; sl@0: iCtorValidator = NULL; sl@0: delete iLogInformationValidator; sl@0: iLogInformationValidator = NULL; sl@0: delete iLogInformationNarrowValidator; sl@0: iLogInformationNarrowValidator =NULL; sl@0: delete iLogInformationWithParametersValidator; sl@0: iLogInformationWithParametersValidator = NULL; sl@0: delete iLogInformationWithParametersNarrowValidator; sl@0: iLogInformationWithParametersNarrowValidator = NULL; sl@0: delete iDtorValidator; sl@0: iDtorValidator = NULL; sl@0: sl@0: return error; sl@0: } sl@0: sl@0: inline CDataLogger_LogInformation_UnitTest::~CDataLogger_LogInformation_UnitTest() sl@0: { sl@0: // Simply delete our test class instance sl@0: delete iUTContext; sl@0: delete iStateAccessor; sl@0: /* delete any validators used */ sl@0: delete iCtorValidator; sl@0: delete iLogInformationValidator; sl@0: delete iLogInformationNarrowValidator; sl@0: delete iLogInformationWithParametersValidator; sl@0: delete iLogInformationWithParametersNarrowValidator; sl@0: delete iDtorValidator; sl@0: } sl@0: sl@0: inline CDataLogger_LogInformation_UnitTest::CDataLogger_LogInformation_UnitTest(CDataLogger& aDataLogger, sl@0: MUnitTestObserver& aObserver) sl@0: : CUnitTest(KDataLoggerLogInformationUnitTest, aDataLogger, aObserver) sl@0: { sl@0: //Do nothing sl@0: } sl@0: sl@0: // Now the Individual transitions need to be added. sl@0: inline void CDataLogger_LogInformation_UnitTest::ConstructL() sl@0: { sl@0: // Perform the base class initialization sl@0: UnitTestConstructL(); sl@0: sl@0: // Create the Unit test state accessor sl@0: iStateAccessor = new(ELeave) TDataLogger_StateAccessor; sl@0: // Construct the Unit test context. sl@0: iUTContext = new(ELeave) CDataLogger_UnitTestContext(iDataLogger, *iStateAccessor, *this); sl@0: sl@0: // Wide descriptor to be used as passed in parameter in LogInformationWithParameters transition sl@0: _LIT(KTextWide,"Parameter - wide descriptor version"); sl@0: HBufC* hptr1 = KTextWide().AllocL(); sl@0: iUTContext->iArg = hptr1; sl@0: sl@0: // Narrow descriptor to be used as passed in parameter in LogInformationWithParametersNarrow transition sl@0: _LIT8(KTextNarrow,"Parameter - narrow descriptor version"); sl@0: HBufC8* hptr2 = KTextNarrow().AllocL();; sl@0: iUTContext->iArgNarrow = hptr2; sl@0: sl@0: // Add the Transitions in the order they are to run sl@0: // C'tor first, D'tor last... sl@0: iCtorValidator = new(ELeave) TDataLogger_Ctor_TransitionValidator(*iUTContext); sl@0: iLogInformationValidator = new(ELeave) TDataLogger_LogInformation_TransitionValidator(*iUTContext); sl@0: iLogInformationNarrowValidator = new(ELeave) TDataLogger_LogInformationNarrow_TransitionValidator(*iUTContext); sl@0: iLogInformationWithParametersValidator = new(ELeave) TDataLogger_LogInformationWithParameters_TransitionValidator(*iUTContext); sl@0: iLogInformationWithParametersNarrowValidator = new(ELeave) TDataLogger_LogInformationWithParametersNarrow_TransitionValidator(*iUTContext); sl@0: iDtorValidator = new(ELeave) TDataLogger_Dtor_TransitionValidator(*iUTContext); sl@0: sl@0: AddTransitionL(new(ELeave)CDataLogger_NewL_Transition(*iUTContext,*iCtorValidator)); sl@0: AddTransitionL(new(ELeave)CDataLogger_LogInformation_Transition(*iUTContext,*iLogInformationValidator)); sl@0: AddTransitionL(new(ELeave)CDataLogger_LogInformationNarrow_Transition(*iUTContext,*iLogInformationNarrowValidator)); sl@0: AddTransitionL(new(ELeave)CDataLogger_LogInformationWithParameters_Transition(*iUTContext,*iLogInformationWithParametersValidator)); sl@0: AddTransitionL(new(ELeave)CDataLogger_LogInformationWithParametersNarrow_Transition(*iUTContext,*iLogInformationWithParametersNarrowValidator)); sl@0: AddTransitionL(new(ELeave)CDataLogger_Dtor_Transition(*iUTContext,*iDtorValidator)); sl@0: } sl@0: sl@0: // ______________________________________________________________________________ sl@0: // sl@0: _LIT(KDataLoggerReportInformationUnitTest,"CDataLogger_ReportInformation_UnitTest"); sl@0: sl@0: CDataLogger_ReportInformation_UnitTest* CDataLogger_ReportInformation_UnitTest::NewL(CDataLogger& aDataLogger, sl@0: MUnitTestObserver& aObserver) sl@0: { sl@0: CDataLogger_ReportInformation_UnitTest* self = sl@0: new(ELeave) CDataLogger_ReportInformation_UnitTest(aDataLogger, sl@0: aObserver); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: inline TInt CDataLogger_ReportInformation_UnitTest::RunError(TInt aError) sl@0: { sl@0: // The RunL left so chain to the base first and then cleanup sl@0: TInt error = CUnitTest::RunError(aError); // Chain to base sl@0: delete iUTContext; sl@0: iUTContext = NULL; sl@0: delete iStateAccessor; sl@0: iStateAccessor = NULL; sl@0: /* delete any validators used */ sl@0: delete iCtorValidator; sl@0: iCtorValidator = NULL; sl@0: delete iReportInformationValidator; sl@0: iReportInformationValidator = NULL; sl@0: delete iReportInformationWithParametersValidator; sl@0: iReportInformationWithParametersValidator = NULL; sl@0: delete iDtorValidator; sl@0: iDtorValidator = NULL; sl@0: sl@0: return error; sl@0: } sl@0: sl@0: inline CDataLogger_ReportInformation_UnitTest::~CDataLogger_ReportInformation_UnitTest() sl@0: { sl@0: // Simply delete our test class instance sl@0: delete iUTContext; sl@0: delete iStateAccessor; sl@0: /* delete any validators used */ sl@0: delete iCtorValidator; sl@0: delete iReportInformationValidator; sl@0: delete iReportInformationWithParametersValidator; sl@0: delete iDtorValidator; sl@0: } sl@0: sl@0: inline CDataLogger_ReportInformation_UnitTest::CDataLogger_ReportInformation_UnitTest(CDataLogger& aDataLogger, sl@0: MUnitTestObserver& aObserver) sl@0: : CUnitTest(KDataLoggerReportInformationUnitTest, aDataLogger, aObserver) sl@0: { sl@0: //Do nothing sl@0: } sl@0: sl@0: // Now the Individual transitions need to be added. sl@0: inline void CDataLogger_ReportInformation_UnitTest::ConstructL() sl@0: { sl@0: // Perform the base class initialization sl@0: UnitTestConstructL(); sl@0: sl@0: // Create the Unit test state accessor sl@0: iStateAccessor = new(ELeave) TDataLogger_StateAccessor; sl@0: // Construct the Unit test context. sl@0: iUTContext = new(ELeave) CDataLogger_UnitTestContext(iDataLogger, *iStateAccessor, *this); sl@0: sl@0: // Text to be inserted into the report by the ReportInformation method sl@0: _LIT(KReportComment, "This is a report comment"); sl@0: iUTContext->iReportComment = &KReportComment(); sl@0: sl@0: // The text to be inserted into the report by the ReportInformationWithParameters method sl@0: _LIT(KFormatReport, "This report text will be followed by a parameter: %S"); sl@0: iUTContext->iFormatReport = &KFormatReport(); sl@0: sl@0: // The parameter to be appended to the end of the text above by the ReportInformationWithParameters method sl@0: _LIT(KReportArg, "This is the report parameter"); sl@0: iUTContext->iReportArg = &KReportArg(); sl@0: sl@0: // Add the Transitions in the order they are to run sl@0: // C'tor first, D'tor last... sl@0: iCtorValidator = new(ELeave) TDataLogger_Ctor_TransitionValidator(*iUTContext); sl@0: iReportInformationValidator = new(ELeave) TDataLogger_ReportInformation_TransitionValidator(*iUTContext); sl@0: iReportInformationWithParametersValidator = new(ELeave) TDataLogger_ReportInformationWithParameters_TransitionValidator(*iUTContext); sl@0: iDtorValidator = new(ELeave) TDataLogger_Dtor_TransitionValidator(*iUTContext); sl@0: sl@0: AddTransitionL(new(ELeave)CDataLogger_NewL_Transition(*iUTContext,*iCtorValidator)); sl@0: AddTransitionL(new(ELeave)CDataLogger_ReportInformation_Transition(*iUTContext,*iReportInformationValidator)); sl@0: AddTransitionL(new(ELeave)CDataLogger_ReportInformationWithParameters_Transition(*iUTContext,*iReportInformationWithParametersValidator)); sl@0: AddTransitionL(new(ELeave)CDataLogger_Dtor_Transition(*iUTContext,*iDtorValidator)); sl@0: } sl@0: sl@0: