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 implementation of the CResolver unit test classes. sl@0: // sl@0: // sl@0: sl@0: #include "ResolverStateAccessor.h" sl@0: sl@0: const TUid KCExampleInterfaceUid = {0x10009DC0}; sl@0: const TUid KCExampleInterfaceImp = {0x10009DC1}; sl@0: sl@0: // ______________________________________________________________________________ sl@0: // sl@0: _LIT(KDefaultResolverCreateAndDestroyUnitTest,"CDefaultResolver_CreateAndDestroy_UnitTest"); sl@0: sl@0: CDefaultResolver_CreateAndDestroy_UnitTest* CDefaultResolver_CreateAndDestroy_UnitTest::NewL(CDataLogger& aDataLogger, sl@0: MUnitTestObserver& aObserver) sl@0: { sl@0: CDefaultResolver_CreateAndDestroy_UnitTest* self = sl@0: new(ELeave) CDefaultResolver_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 CDefaultResolver_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 CDefaultResolver_CreateAndDestroy_UnitTest::~CDefaultResolver_CreateAndDestroy_UnitTest() sl@0: { sl@0: // Simply delete our test class instance sl@0: delete iUTContext; sl@0: delete iStateAccessor; sl@0: sl@0: // delete any validators used sl@0: delete iCtorValidator; sl@0: delete iDtorValidator; sl@0: } sl@0: sl@0: inline CDefaultResolver_CreateAndDestroy_UnitTest::CDefaultResolver_CreateAndDestroy_UnitTest(CDataLogger& aDataLogger, sl@0: MUnitTestObserver& aObserver) sl@0: : CUnitTest(KDefaultResolverCreateAndDestroyUnitTest, 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 CDefaultResolver_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) TDefaultResolver_StateAccessor; sl@0: // Construct the Unit test context. sl@0: iUTContext = new(ELeave) CDefaultResolver_UnitTestContext(iDataLogger, sl@0: *iStateAccessor, sl@0: *this); sl@0: sl@0: User::LeaveIfError(iUTContext->iFs.Connect()); 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) TDefaultResolver_Ctor_TransitionValidator(*iUTContext); sl@0: iDtorValidator = new(ELeave) TDefaultResolver_Dtor_TransitionValidator(*iUTContext); sl@0: sl@0: AddTransitionL(new(ELeave)CDefaultResolver_NewL_Transition(*iUTContext,*iCtorValidator)); sl@0: AddTransitionL(new(ELeave)CDefaultResolver_Dtor_Transition(*iUTContext,*iDtorValidator)); sl@0: } sl@0: sl@0: void CDefaultResolver_CreateAndDestroy_UnitTest::PrepareUnitTestL() sl@0: { sl@0: iUTContext->iRegistry = CRegistryData::NewL(iUTContext->iFs); sl@0: } sl@0: sl@0: // ______________________________________________________________________________ sl@0: // sl@0: _LIT(KDefaultResolverIdentifyImplementationUnitTest,"CDefaultResolver_IdentifyImplementation_UnitTest"); sl@0: sl@0: CDefaultResolver_IdentifyImplementation_UnitTest* CDefaultResolver_IdentifyImplementation_UnitTest::NewL(CDataLogger& aDataLogger, sl@0: MUnitTestObserver& aObserver) sl@0: { sl@0: CDefaultResolver_IdentifyImplementation_UnitTest* self = sl@0: new(ELeave) CDefaultResolver_IdentifyImplementation_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 CDefaultResolver_IdentifyImplementation_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: sl@0: // Delete all the iImplementationData (which we created) sl@0: while(iUTContext->iImplementationData.Count()) sl@0: { sl@0: CImplementationInformation* impInfo = iUTContext->iImplementationData[0]; sl@0: iUTContext->iImplementationData.Remove(0); sl@0: delete impInfo; sl@0: } sl@0: sl@0: delete iUTContext; sl@0: delete iStateAccessor; sl@0: // delete any validators used sl@0: delete iCtorValidator; sl@0: delete iDefaultValidator; sl@0: delete iMatchValidator; sl@0: delete iIdentifyImplementationValidator; sl@0: delete iDtorValidator; sl@0: sl@0: return error; sl@0: } sl@0: sl@0: inline CDefaultResolver_IdentifyImplementation_UnitTest::~CDefaultResolver_IdentifyImplementation_UnitTest() sl@0: { sl@0: if(iUTContext) sl@0: { sl@0: // Delete all the iImplementationData (which we created) sl@0: while(iUTContext->iImplementationData.Count()) sl@0: { sl@0: CImplementationInformation* impInfo = iUTContext->iImplementationData[0]; sl@0: iUTContext->iImplementationData.Remove(0); sl@0: delete impInfo; sl@0: } sl@0: delete iUTContext; sl@0: } sl@0: sl@0: delete iStateAccessor; sl@0: // delete any validators used sl@0: delete iCtorValidator; sl@0: delete iDefaultValidator; sl@0: delete iMatchValidator; sl@0: delete iIdentifyImplementationValidator; sl@0: delete iDtorValidator; sl@0: } sl@0: sl@0: inline CDefaultResolver_IdentifyImplementation_UnitTest::CDefaultResolver_IdentifyImplementation_UnitTest(CDataLogger& aDataLogger, sl@0: MUnitTestObserver& aObserver) sl@0: : CUnitTest(KDefaultResolverIdentifyImplementationUnitTest, 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 CDefaultResolver_IdentifyImplementation_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) TDefaultResolver_StateAccessor; sl@0: sl@0: // Construct the Unit test context. sl@0: iUTContext = new(ELeave) CDefaultResolver_UnitTestContext(iDataLogger, *iStateAccessor, *this); sl@0: User::LeaveIfError(iUTContext->iFs.Connect()); sl@0: iUTContext->iRegistry = CRegistryData::NewL(iUTContext->iFs); sl@0: sl@0: // Set up the match type and implementation type for use in the Match transition sl@0: _LIT8(KResolveImplementationType, "DataType2||DataType1"); sl@0: _LIT8(KResolveMatchType, "DataType1"); sl@0: sl@0: iUTContext->iImplementationType = HBufC8::NewMaxL(KResolveImplementationType().Length()); sl@0: TPtr8 impType = iUTContext->iImplementationType->Des(); sl@0: impType = KResolveImplementationType; sl@0: sl@0: iUTContext->iMatchType = HBufC8::NewMaxL(KResolveMatchType().Length()); sl@0: TPtr8 matchType = iUTContext->iMatchType->Des(); sl@0: matchType = KResolveMatchType; sl@0: sl@0: iUTContext->iExpectedMatchResult = ETrue; // Based on iMatchType and iImplementationType sl@0: sl@0: iUTContext->iInterfaceUid.iUid = KCExampleInterfaceUid.iUid; sl@0: sl@0: TUid impUid; sl@0: impUid.iUid = KCExampleInterfaceImp.iUid; sl@0: HBufC8* implType = HBufC8::NewMaxL(KResolveImplementationType().Length()); sl@0: TPtr8 impPtr = implType->Des(); sl@0: impPtr = KResolveImplementationType; sl@0: TDriveUnit drive(EDriveC); sl@0: CImplementationInformation* impData = sl@0: CImplementationInformation::NewL(impUid, 0, NULL, implType, NULL, drive, EFalse, EFalse); sl@0: CleanupStack::PushL(impData); sl@0: User::LeaveIfError(iUTContext->iImplementationData.Append(impData)); sl@0: CleanupStack::Pop(impData); sl@0: sl@0: iUTContext->iAdditionalParameters.SetDataType(*iUTContext->iMatchType); 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) TDefaultResolver_Ctor_TransitionValidator(*iUTContext); sl@0: iIdentifyImplementationValidator = new(ELeave) TDefaultResolver_IdentifyImplementationL_TransitionValidator(*iUTContext); sl@0: iDefaultValidator = new(ELeave) TDefaultResolver_Default_TransitionValidator(*iUTContext); sl@0: iMatchValidator = new(ELeave) TDefaultResolver_Match_TransitionValidator(*iUTContext); sl@0: iDtorValidator = new(ELeave) TDefaultResolver_Dtor_TransitionValidator(*iUTContext); sl@0: sl@0: AddTransitionL(new(ELeave)CDefaultResolver_NewL_Transition(*iUTContext,*iCtorValidator)); sl@0: AddTransitionL(new(ELeave)CDefaultResolver_Match_Transition(*iUTContext,*iMatchValidator)); sl@0: AddTransitionL(new(ELeave)CDefaultResolver_Resolve_Transition(*iUTContext,*iDefaultValidator)); sl@0: AddTransitionL(new(ELeave)CDefaultResolver_IdentifyImplementationL_Transition(*iUTContext,*iIdentifyImplementationValidator)); sl@0: AddTransitionL(new(ELeave)CDefaultResolver_Dtor_Transition(*iUTContext,*iDtorValidator)); sl@0: sl@0: // Add the permissible error codes for failures sl@0: AddLeaveErrorCodeL(KEComErrNoInterfaceIdentified); sl@0: } sl@0: