os/ossrv/lowlevellibsandfws/pluginfw/Framework/ResolverTest/ResolverUnitTests.inl
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 implementation of the CResolver unit test classes.
    15 // 
    16 //
    17 
    18 #include "ResolverStateAccessor.h"
    19 
    20 const TUid KCExampleInterfaceUid			= {0x10009DC0};
    21 const TUid KCExampleInterfaceImp			= {0x10009DC1};
    22 
    23 // ______________________________________________________________________________
    24 //
    25 _LIT(KDefaultResolverCreateAndDestroyUnitTest,"CDefaultResolver_CreateAndDestroy_UnitTest");
    26 
    27 CDefaultResolver_CreateAndDestroy_UnitTest* CDefaultResolver_CreateAndDestroy_UnitTest::NewL(CDataLogger& aDataLogger,
    28 											MUnitTestObserver& aObserver)
    29 	{
    30 	CDefaultResolver_CreateAndDestroy_UnitTest* self = 
    31 					new(ELeave) CDefaultResolver_CreateAndDestroy_UnitTest(aDataLogger,
    32 																aObserver);
    33 	CleanupStack::PushL(self);
    34 	self->ConstructL();
    35 	CleanupStack::Pop();
    36 	return self; 
    37 	}
    38 
    39 inline TInt CDefaultResolver_CreateAndDestroy_UnitTest::RunError(TInt aError)
    40 	{
    41 	// The RunL left so chain to the base first and then cleanup
    42 	TInt error = CUnitTest::RunError(aError);	// Chain to base
    43 	delete iUTContext;
    44 	iUTContext = NULL;
    45 	delete iStateAccessor;
    46 	iStateAccessor = NULL;
    47 	/* delete any validators used */
    48 	delete iCtorValidator;
    49 	iCtorValidator = NULL;
    50 	delete iDtorValidator;
    51 	iDtorValidator = NULL;
    52 	return error;
    53 	}
    54 
    55 inline CDefaultResolver_CreateAndDestroy_UnitTest::~CDefaultResolver_CreateAndDestroy_UnitTest()
    56 	{
    57 	// Simply delete our test class instance
    58 	delete iUTContext;
    59 	delete iStateAccessor;
    60 
    61 	// delete any validators used
    62 	delete iCtorValidator;
    63 	delete iDtorValidator;
    64 	}
    65 
    66 inline CDefaultResolver_CreateAndDestroy_UnitTest::CDefaultResolver_CreateAndDestroy_UnitTest(CDataLogger& aDataLogger,
    67 																	MUnitTestObserver& aObserver)
    68 : CUnitTest(KDefaultResolverCreateAndDestroyUnitTest, aDataLogger, aObserver)
    69 	{
    70 	//Do nothing
    71 	}
    72 
    73 // Now the Individual transitions need to be added.
    74 inline void CDefaultResolver_CreateAndDestroy_UnitTest::ConstructL()
    75 	{
    76 	// Perform the base class initialization
    77 	UnitTestConstructL();
    78 
    79 	// Create the Unit test state accessor
    80 	iStateAccessor = new(ELeave) TDefaultResolver_StateAccessor;
    81 	// Construct the Unit test context.
    82 	iUTContext = new(ELeave) CDefaultResolver_UnitTestContext(iDataLogger, 
    83 															  *iStateAccessor, 
    84 															  *this);
    85 
    86 	User::LeaveIfError(iUTContext->iFs.Connect());
    87 
    88 	// Add the Transitions in the order they are to run
    89 	// C'tor first, D'tor last...
    90 	iCtorValidator = new(ELeave) TDefaultResolver_Ctor_TransitionValidator(*iUTContext);
    91 	iDtorValidator = new(ELeave) TDefaultResolver_Dtor_TransitionValidator(*iUTContext);
    92 
    93 	AddTransitionL(new(ELeave)CDefaultResolver_NewL_Transition(*iUTContext,*iCtorValidator));
    94 	AddTransitionL(new(ELeave)CDefaultResolver_Dtor_Transition(*iUTContext,*iDtorValidator));
    95 	}
    96 
    97 void CDefaultResolver_CreateAndDestroy_UnitTest::PrepareUnitTestL()
    98 	{
    99 	iUTContext->iRegistry = CRegistryData::NewL(iUTContext->iFs);
   100 	}
   101 
   102 // ______________________________________________________________________________
   103 //
   104 _LIT(KDefaultResolverIdentifyImplementationUnitTest,"CDefaultResolver_IdentifyImplementation_UnitTest");
   105 
   106 CDefaultResolver_IdentifyImplementation_UnitTest* CDefaultResolver_IdentifyImplementation_UnitTest::NewL(CDataLogger& aDataLogger,
   107 											MUnitTestObserver& aObserver)
   108 	{
   109 	CDefaultResolver_IdentifyImplementation_UnitTest* self = 
   110 					new(ELeave) CDefaultResolver_IdentifyImplementation_UnitTest(aDataLogger,
   111 																aObserver);
   112 	CleanupStack::PushL(self);
   113 	self->ConstructL();
   114 	CleanupStack::Pop();
   115 	return self; 
   116 	}
   117 
   118 inline TInt CDefaultResolver_IdentifyImplementation_UnitTest::RunError(TInt aError)
   119 	{
   120 	// The RunL left so chain to the base first and then cleanup
   121 	TInt error = CUnitTest::RunError(aError);	// Chain to base
   122 
   123 	// Delete all the iImplementationData (which we created)
   124 	while(iUTContext->iImplementationData.Count())
   125 		{
   126 		CImplementationInformation* impInfo = iUTContext->iImplementationData[0];
   127 		iUTContext->iImplementationData.Remove(0);
   128 		delete impInfo;
   129 		}
   130 
   131 	delete iUTContext;
   132 	delete iStateAccessor;
   133 	// delete any validators used
   134 	delete iCtorValidator;
   135 	delete iDefaultValidator;
   136 	delete iMatchValidator;
   137 	delete iIdentifyImplementationValidator;
   138 	delete iDtorValidator;
   139 
   140 	return error;
   141 	}
   142 
   143 inline CDefaultResolver_IdentifyImplementation_UnitTest::~CDefaultResolver_IdentifyImplementation_UnitTest()
   144 	{
   145 	if(iUTContext)
   146 		{
   147 		// Delete all the iImplementationData (which we created)
   148 		while(iUTContext->iImplementationData.Count())
   149 			{
   150 			CImplementationInformation* impInfo = iUTContext->iImplementationData[0];
   151 			iUTContext->iImplementationData.Remove(0);
   152 			delete impInfo;
   153 			}
   154 		delete iUTContext;
   155 		}
   156 
   157 	delete iStateAccessor;
   158 	// delete any validators used
   159 	delete iCtorValidator;
   160 	delete iDefaultValidator;
   161 	delete iMatchValidator;
   162 	delete iIdentifyImplementationValidator;
   163 	delete iDtorValidator;
   164 	}
   165 
   166 inline CDefaultResolver_IdentifyImplementation_UnitTest::CDefaultResolver_IdentifyImplementation_UnitTest(CDataLogger& aDataLogger,
   167 																	MUnitTestObserver& aObserver)
   168 : CUnitTest(KDefaultResolverIdentifyImplementationUnitTest, aDataLogger, aObserver)
   169 	{
   170 	//Do nothing
   171 	}
   172 
   173 // Now the Individual transitions need to be added.
   174 inline void CDefaultResolver_IdentifyImplementation_UnitTest::ConstructL()
   175 	{
   176 	// Perform the base class initialization
   177 	UnitTestConstructL();
   178 
   179 	// Create the Unit test state accessor
   180 	iStateAccessor = new(ELeave) TDefaultResolver_StateAccessor;
   181 
   182 	// Construct the Unit test context.
   183 	iUTContext = new(ELeave) CDefaultResolver_UnitTestContext(iDataLogger, *iStateAccessor, *this);
   184 	User::LeaveIfError(iUTContext->iFs.Connect());
   185 	iUTContext->iRegistry = CRegistryData::NewL(iUTContext->iFs);
   186 
   187 	// Set up the match type and implementation type for use in the Match transition
   188 	_LIT8(KResolveImplementationType, "DataType2||DataType1");
   189 	_LIT8(KResolveMatchType, "DataType1");
   190 
   191 	iUTContext->iImplementationType = HBufC8::NewMaxL(KResolveImplementationType().Length());
   192 	TPtr8 impType = iUTContext->iImplementationType->Des();
   193 	impType = KResolveImplementationType;
   194 
   195 	iUTContext->iMatchType = HBufC8::NewMaxL(KResolveMatchType().Length());
   196 	TPtr8 matchType = iUTContext->iMatchType->Des();
   197 	matchType = KResolveMatchType;
   198 
   199 	iUTContext->iExpectedMatchResult = ETrue; // Based on iMatchType and iImplementationType
   200 
   201 	iUTContext->iInterfaceUid.iUid = KCExampleInterfaceUid.iUid;
   202 
   203 	TUid impUid;
   204 	impUid.iUid = KCExampleInterfaceImp.iUid;
   205 	HBufC8* implType = HBufC8::NewMaxL(KResolveImplementationType().Length());
   206 	TPtr8 impPtr = implType->Des();
   207 	impPtr = KResolveImplementationType;
   208 	TDriveUnit drive(EDriveC);
   209 	CImplementationInformation* impData = 
   210 		CImplementationInformation::NewL(impUid, 0, NULL, implType, NULL, drive, EFalse, EFalse);
   211 	CleanupStack::PushL(impData);
   212 	User::LeaveIfError(iUTContext->iImplementationData.Append(impData));
   213 	CleanupStack::Pop(impData);
   214 
   215 	iUTContext->iAdditionalParameters.SetDataType(*iUTContext->iMatchType);
   216 
   217 	// Add the Transitions in the order they are to run
   218 	// C'tor first, D'tor last...
   219 	iCtorValidator = new(ELeave) TDefaultResolver_Ctor_TransitionValidator(*iUTContext);
   220 	iIdentifyImplementationValidator = new(ELeave) TDefaultResolver_IdentifyImplementationL_TransitionValidator(*iUTContext);
   221 	iDefaultValidator = new(ELeave) TDefaultResolver_Default_TransitionValidator(*iUTContext);
   222 	iMatchValidator = new(ELeave) TDefaultResolver_Match_TransitionValidator(*iUTContext);
   223 	iDtorValidator = new(ELeave) TDefaultResolver_Dtor_TransitionValidator(*iUTContext);
   224 
   225 	AddTransitionL(new(ELeave)CDefaultResolver_NewL_Transition(*iUTContext,*iCtorValidator));
   226 	AddTransitionL(new(ELeave)CDefaultResolver_Match_Transition(*iUTContext,*iMatchValidator));
   227 	AddTransitionL(new(ELeave)CDefaultResolver_Resolve_Transition(*iUTContext,*iDefaultValidator));
   228 	AddTransitionL(new(ELeave)CDefaultResolver_IdentifyImplementationL_Transition(*iUTContext,*iIdentifyImplementationValidator));
   229 	AddTransitionL(new(ELeave)CDefaultResolver_Dtor_Transition(*iUTContext,*iDtorValidator));
   230 
   231 	// Add the permissible error codes for failures
   232 	AddLeaveErrorCodeL(KEComErrNoInterfaceIdentified);
   233 	}
   234