os/ossrv/lowlevellibsandfws/pluginfw/Framework/ResolverTest/ResolverUnitTests.inl
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 implementation of the CResolver unit test classes.
18 #include "ResolverStateAccessor.h"
20 const TUid KCExampleInterfaceUid = {0x10009DC0};
21 const TUid KCExampleInterfaceImp = {0x10009DC1};
23 // ______________________________________________________________________________
25 _LIT(KDefaultResolverCreateAndDestroyUnitTest,"CDefaultResolver_CreateAndDestroy_UnitTest");
27 CDefaultResolver_CreateAndDestroy_UnitTest* CDefaultResolver_CreateAndDestroy_UnitTest::NewL(CDataLogger& aDataLogger,
28 MUnitTestObserver& aObserver)
30 CDefaultResolver_CreateAndDestroy_UnitTest* self =
31 new(ELeave) CDefaultResolver_CreateAndDestroy_UnitTest(aDataLogger,
33 CleanupStack::PushL(self);
39 inline TInt CDefaultResolver_CreateAndDestroy_UnitTest::RunError(TInt aError)
41 // The RunL left so chain to the base first and then cleanup
42 TInt error = CUnitTest::RunError(aError); // Chain to base
45 delete iStateAccessor;
46 iStateAccessor = NULL;
47 /* delete any validators used */
48 delete iCtorValidator;
49 iCtorValidator = NULL;
50 delete iDtorValidator;
51 iDtorValidator = NULL;
55 inline CDefaultResolver_CreateAndDestroy_UnitTest::~CDefaultResolver_CreateAndDestroy_UnitTest()
57 // Simply delete our test class instance
59 delete iStateAccessor;
61 // delete any validators used
62 delete iCtorValidator;
63 delete iDtorValidator;
66 inline CDefaultResolver_CreateAndDestroy_UnitTest::CDefaultResolver_CreateAndDestroy_UnitTest(CDataLogger& aDataLogger,
67 MUnitTestObserver& aObserver)
68 : CUnitTest(KDefaultResolverCreateAndDestroyUnitTest, aDataLogger, aObserver)
73 // Now the Individual transitions need to be added.
74 inline void CDefaultResolver_CreateAndDestroy_UnitTest::ConstructL()
76 // Perform the base class initialization
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,
86 User::LeaveIfError(iUTContext->iFs.Connect());
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);
93 AddTransitionL(new(ELeave)CDefaultResolver_NewL_Transition(*iUTContext,*iCtorValidator));
94 AddTransitionL(new(ELeave)CDefaultResolver_Dtor_Transition(*iUTContext,*iDtorValidator));
97 void CDefaultResolver_CreateAndDestroy_UnitTest::PrepareUnitTestL()
99 iUTContext->iRegistry = CRegistryData::NewL(iUTContext->iFs);
102 // ______________________________________________________________________________
104 _LIT(KDefaultResolverIdentifyImplementationUnitTest,"CDefaultResolver_IdentifyImplementation_UnitTest");
106 CDefaultResolver_IdentifyImplementation_UnitTest* CDefaultResolver_IdentifyImplementation_UnitTest::NewL(CDataLogger& aDataLogger,
107 MUnitTestObserver& aObserver)
109 CDefaultResolver_IdentifyImplementation_UnitTest* self =
110 new(ELeave) CDefaultResolver_IdentifyImplementation_UnitTest(aDataLogger,
112 CleanupStack::PushL(self);
118 inline TInt CDefaultResolver_IdentifyImplementation_UnitTest::RunError(TInt aError)
120 // The RunL left so chain to the base first and then cleanup
121 TInt error = CUnitTest::RunError(aError); // Chain to base
123 // Delete all the iImplementationData (which we created)
124 while(iUTContext->iImplementationData.Count())
126 CImplementationInformation* impInfo = iUTContext->iImplementationData[0];
127 iUTContext->iImplementationData.Remove(0);
132 delete iStateAccessor;
133 // delete any validators used
134 delete iCtorValidator;
135 delete iDefaultValidator;
136 delete iMatchValidator;
137 delete iIdentifyImplementationValidator;
138 delete iDtorValidator;
143 inline CDefaultResolver_IdentifyImplementation_UnitTest::~CDefaultResolver_IdentifyImplementation_UnitTest()
147 // Delete all the iImplementationData (which we created)
148 while(iUTContext->iImplementationData.Count())
150 CImplementationInformation* impInfo = iUTContext->iImplementationData[0];
151 iUTContext->iImplementationData.Remove(0);
157 delete iStateAccessor;
158 // delete any validators used
159 delete iCtorValidator;
160 delete iDefaultValidator;
161 delete iMatchValidator;
162 delete iIdentifyImplementationValidator;
163 delete iDtorValidator;
166 inline CDefaultResolver_IdentifyImplementation_UnitTest::CDefaultResolver_IdentifyImplementation_UnitTest(CDataLogger& aDataLogger,
167 MUnitTestObserver& aObserver)
168 : CUnitTest(KDefaultResolverIdentifyImplementationUnitTest, aDataLogger, aObserver)
173 // Now the Individual transitions need to be added.
174 inline void CDefaultResolver_IdentifyImplementation_UnitTest::ConstructL()
176 // Perform the base class initialization
177 UnitTestConstructL();
179 // Create the Unit test state accessor
180 iStateAccessor = new(ELeave) TDefaultResolver_StateAccessor;
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);
187 // Set up the match type and implementation type for use in the Match transition
188 _LIT8(KResolveImplementationType, "DataType2||DataType1");
189 _LIT8(KResolveMatchType, "DataType1");
191 iUTContext->iImplementationType = HBufC8::NewMaxL(KResolveImplementationType().Length());
192 TPtr8 impType = iUTContext->iImplementationType->Des();
193 impType = KResolveImplementationType;
195 iUTContext->iMatchType = HBufC8::NewMaxL(KResolveMatchType().Length());
196 TPtr8 matchType = iUTContext->iMatchType->Des();
197 matchType = KResolveMatchType;
199 iUTContext->iExpectedMatchResult = ETrue; // Based on iMatchType and iImplementationType
201 iUTContext->iInterfaceUid.iUid = KCExampleInterfaceUid.iUid;
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);
215 iUTContext->iAdditionalParameters.SetDataType(*iUTContext->iMatchType);
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);
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));
231 // Add the permissible error codes for failures
232 AddLeaveErrorCodeL(KEComErrNoInterfaceIdentified);