os/ossrv/lowlevellibsandfws/pluginfw/Framework/RegistrarTest/RegistrarUnitTests.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 unit test classes for the CRegistrar.
18 #include "RegistrarTransitions.h"
19 #include "RegistrarStateAccessor.h"
21 _LIT(KRegistrarNotificationMsg,"Notification %d recieved from CRegistrar!");
23 // ______________________________________________________________________________
25 _LIT(KRegistrarCreateAndDestroyUnitTest,"CRegistrar_CreateAndDestroy_UnitTest");
27 CRegistrar_CreateAndDestroy_UnitTest* CRegistrar_CreateAndDestroy_UnitTest::NewL(
28 CDataLogger& aDataLogger,
29 MUnitTestObserver& aObserver)
31 CRegistrar_CreateAndDestroy_UnitTest* self =
32 new(ELeave) CRegistrar_CreateAndDestroy_UnitTest(aDataLogger, aObserver);
33 CleanupStack::PushL(self);
39 inline TInt CRegistrar_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
44 delete iStateAccessor;
45 // delete any validators used
46 delete iCtorValidator;
47 delete iDtorValidator;
52 inline CRegistrar_CreateAndDestroy_UnitTest::~CRegistrar_CreateAndDestroy_UnitTest()
54 // Simply delete our test class instance
56 delete iStateAccessor;
60 // delete any validators used
61 delete iCtorValidator;
62 delete iDtorValidator;
65 inline CRegistrar_CreateAndDestroy_UnitTest::CRegistrar_CreateAndDestroy_UnitTest(
66 CDataLogger& aDataLogger,
67 MUnitTestObserver& aObserver)
68 : CUnitTest(KRegistrarCreateAndDestroyUnitTest, aDataLogger, aObserver)
73 // Now the Individual transitions need to be added.
74 inline void CRegistrar_CreateAndDestroy_UnitTest::ConstructL()
76 // Perform the base class initialization
79 // Create the Unit test state accessor
80 iStateAccessor = new(ELeave) TRegistrar_StateAccessor;
81 // Construct the Unit test context.
82 iUTContext = new(ELeave) CRegistrar_UnitTestContext(iDataLogger,
88 // Add the Transitions in the order they are to run
89 // C'tor first, D'tor last...
90 iCtorValidator = new(ELeave) TRegistrar_Ctor_TransitionValidator(*iUTContext);
91 AddTransitionL(new(ELeave)CRegistrar_NewL_Transition(*iUTContext,*iCtorValidator));
92 iDtorValidator = new(ELeave) TRegistrar_Dtor_TransitionValidator(*iUTContext);
93 AddTransitionL(new(ELeave)CRegistrar_Dtor_Transition(*iUTContext,*iDtorValidator));
96 void CRegistrar_CreateAndDestroy_UnitTest::PrepareUnitTestL()
98 iRegistryData = CRegistryData::NewL(iFs);
101 void CRegistrar_CreateAndDestroy_UnitTest::Notification(TInt aNotificationCode)
103 iDataLogger.LogInformationWithParameters(KRegistrarNotificationMsg, aNotificationCode);
106 // ______________________________________________________________________________
108 _LIT(KRegistrarBeginCompleteUnitTest,"CRegistrar_BeginComplete_UnitTest");
110 CRegistrar_BeginComplete_UnitTest* CRegistrar_BeginComplete_UnitTest::NewL(CDataLogger& aDataLogger,
111 MUnitTestObserver& aObserver)
113 CRegistrar_BeginComplete_UnitTest* self =
114 new(ELeave) CRegistrar_BeginComplete_UnitTest(aDataLogger,
116 CleanupStack::PushL(self);
122 inline TInt CRegistrar_BeginComplete_UnitTest::RunError(TInt aError)
124 // The RunL left so chain to the base first and then cleanup
125 TInt error = CUnitTest::RunError(aError); // Chain to base
127 delete iStateAccessor;
129 delete iRegistryData;
131 delete iCtorValidator;
132 delete iDefaultValidator;
133 delete iDtorValidator;
138 inline CRegistrar_BeginComplete_UnitTest::~CRegistrar_BeginComplete_UnitTest()
140 // Simply delete our test class instance
142 delete iStateAccessor;
144 delete iRegistryData;
146 delete iCtorValidator;
147 delete iDefaultValidator;
148 delete iDtorValidator;
151 inline CRegistrar_BeginComplete_UnitTest::CRegistrar_BeginComplete_UnitTest(CDataLogger& aDataLogger,
152 MUnitTestObserver& aObserver)
153 : CUnitTest(KRegistrarBeginCompleteUnitTest, aDataLogger, aObserver)
158 // Now the Individual transitions need to be added.
159 inline void CRegistrar_BeginComplete_UnitTest::ConstructL()
161 // Perform the base class initialization
162 UnitTestConstructL();
164 iRegistryData = CRegistryData::NewL(iFs);
166 // Create the Unit test state accessor
167 iStateAccessor = new(ELeave) TRegistrar_StateAccessor;
168 // Construct the Unit test context.
169 iUTContext = new(ELeave) CRegistrar_UnitTestContext(iDataLogger,
175 iUTContext->iDllData = CRegistryData::CDllData::NewLC();
176 CleanupStack::Pop(); //iDllData
178 // Create the validators which are used by the transitions
179 iCtorValidator = new(ELeave) TRegistrar_Ctor_TransitionValidator(*iUTContext);
180 iDefaultValidator = new(ELeave) TRegistrar_Default_TransitionValidator(*iUTContext);
181 iDtorValidator = new(ELeave) TRegistrar_Dtor_TransitionValidator(*iUTContext);
183 // Add the Transitions in the order they are to run
184 // C'tor, Begin, Complete, D'tor
185 AddTransitionL(new(ELeave)CRegistrar_NewL_Transition(*iUTContext,*iCtorValidator));
186 AddTransitionL(new(ELeave)CRegistrar_DiscoveriesBegin_Transition(*iUTContext,*iDefaultValidator));
187 // AddTransitionL(new(ELeave)CRegistrar_ParseL_Transition(*iUTContext,*iDefaultValidator));
188 AddTransitionL(new(ELeave)CRegistrar_DiscoveriesComplete_Transition(*iUTContext,*iDefaultValidator));
189 AddTransitionL(new(ELeave)CRegistrar_Dtor_Transition(*iUTContext,*iDtorValidator));
192 void CRegistrar_BeginComplete_UnitTest::Notification(TInt aNotificationCode)
194 iDataLogger.LogInformationWithParameters(KRegistrarNotificationMsg, aNotificationCode);
197 // ______________________________________________________________________________
199 _LIT(KRegistrarRegisterDiscoveryUnitTest,"CRegistrar_RegisterDiscovery_UnitTest");
201 CRegistrar_RegisterDiscovery_UnitTest* CRegistrar_RegisterDiscovery_UnitTest::NewL(CDataLogger& aDataLogger,
202 MUnitTestObserver& aObserver)
204 CRegistrar_RegisterDiscovery_UnitTest* self =
205 new(ELeave) CRegistrar_RegisterDiscovery_UnitTest(aDataLogger,
207 CleanupStack::PushL(self);
213 inline TInt CRegistrar_RegisterDiscovery_UnitTest::RunError(TInt aError)
215 // The RunL left so chain to the base first and then cleanup
216 TInt error = CUnitTest::RunError(aError); // Chain to base
218 delete iStateAccessor;
220 delete iRegistryData;
222 // delete any validators used
223 delete iCtorValidator;
224 delete iRegisterDiscoveryValidator;
225 delete iDtorValidator;
230 inline CRegistrar_RegisterDiscovery_UnitTest::~CRegistrar_RegisterDiscovery_UnitTest()
232 // Simply delete our test class instance
234 delete iStateAccessor;
236 delete iRegistryData;
238 // delete any validators used
239 delete iCtorValidator;
240 delete iRegisterDiscoveryValidator;
241 delete iDtorValidator;
244 inline CRegistrar_RegisterDiscovery_UnitTest::CRegistrar_RegisterDiscovery_UnitTest(CDataLogger& aDataLogger,
245 MUnitTestObserver& aObserver)
246 : CUnitTest(KRegistrarRegisterDiscoveryUnitTest, aDataLogger, aObserver)
251 // Now the Individual transitions need to be added.
252 inline void CRegistrar_RegisterDiscovery_UnitTest::ConstructL()
254 // Perform the base class initialization
255 UnitTestConstructL();
257 iRegistryData = CRegistryData::NewL(iFs);
258 TDriveUnit drive(EDriveZ);
259 iRegistryData->UndoTemporaryUninstallL(drive);
261 // Create the Unit test state accessor
262 iStateAccessor = new(ELeave) TRegistrar_StateAccessor;
263 // Construct the Unit test context.
264 iUTContext = new(ELeave) CRegistrar_UnitTestContext(iDataLogger,
270 iUTContext->iDllData = CRegistryData::CDllData::NewLC();
271 CleanupStack::Pop(); //iDllData
273 // Artificially set up the TEntry info on the dll
274 TPtr dllName = iUTContext->iDllEntry.iName.Des();
275 dllName = KExampleDllFileName();
277 // Only the third entry (unique dll id) matters in this case
278 TUid uid1, uid2, uid3;
281 uid3.iUid = 0x10009DB0;
282 iUTContext->iDllEntry.iType = TUidType(uid1, uid2, uid3);
284 // Set the modified time to an unrealistic time to ensure it is reloaded
285 iUTContext->iDllEntry.iModified = 5;
286 iUTContext->iUpdate = EFalse;
287 iUTContext->iIndex = KErrNotFound;
289 iCtorValidator = new(ELeave) TRegistrar_Ctor_TransitionValidator(*iUTContext);
290 iRegisterDiscoveryValidator = new(ELeave) TRegistrar_RegisterDiscoveryL_TransitionValidator(*iUTContext);
291 iDtorValidator = new(ELeave) TRegistrar_Dtor_TransitionValidator(*iUTContext);
293 AddTransitionL(new(ELeave)CRegistrar_NewL_Transition(*iUTContext,*iCtorValidator));
294 AddTransitionL(new(ELeave)CRegistrar_ParseL_Transition(*iUTContext,*iRegisterDiscoveryValidator));
295 AddTransitionL(new(ELeave)CRegistrar_ParseRegistrationDataL_Transition(*iUTContext,*iRegisterDiscoveryValidator));
296 AddTransitionL(new(ELeave)CRegistrar_RegisterDiscoveryL_Transition(*iUTContext,*iRegisterDiscoveryValidator));
297 AddTransitionL(new(ELeave)CRegistrar_Dtor_Transition(*iUTContext,*iDtorValidator));
300 void CRegistrar_RegisterDiscovery_UnitTest::Notification(TInt aNotificationCode)
302 iDataLogger.LogInformationWithParameters(KRegistrarNotificationMsg, aNotificationCode);
305 // ______________________________________________________________________________
307 _LIT(KRegistrarRegisterTwiceUnitTest,"CRegistrar_RegisterTwice_UnitTest");
309 CRegistrar_RegisterTwice_UnitTest* CRegistrar_RegisterTwice_UnitTest::NewL(CDataLogger& aDataLogger,
310 MUnitTestObserver& aObserver)
312 CRegistrar_RegisterTwice_UnitTest* self =
313 new(ELeave) CRegistrar_RegisterTwice_UnitTest(aDataLogger,
315 CleanupStack::PushL(self);
321 inline TInt CRegistrar_RegisterTwice_UnitTest::RunError(TInt aError)
323 // The RunL left so chain to the base first and then cleanup
324 TInt error = CUnitTest::RunError(aError); // Chain to base
326 delete iStateAccessor;
328 delete iRegistryData;
330 // delete any validators used
331 delete iCtorValidator;
332 delete iRegisterDiscoveryValidator;
333 delete iDefaultValidator;
334 delete iDtorValidator;
339 inline CRegistrar_RegisterTwice_UnitTest::~CRegistrar_RegisterTwice_UnitTest()
341 // Simply delete our test class instance
343 delete iStateAccessor;
345 delete iRegistryData;
347 // delete any validators used
348 delete iCtorValidator;
349 delete iRegisterDiscoveryValidator;
350 delete iDefaultValidator;
351 delete iDtorValidator;
354 inline CRegistrar_RegisterTwice_UnitTest::CRegistrar_RegisterTwice_UnitTest(CDataLogger& aDataLogger,
355 MUnitTestObserver& aObserver)
356 : CUnitTest(KRegistrarRegisterTwiceUnitTest, aDataLogger, aObserver)
361 // Now the Individual transitions need to be added.
362 inline void CRegistrar_RegisterTwice_UnitTest::ConstructL()
364 // Perform the base class initialization
365 UnitTestConstructL();
367 iRegistryData = CRegistryData::NewL(iFs);
368 TDriveUnit drive(EDriveZ);
369 iRegistryData->UndoTemporaryUninstallL(drive);
371 // Create the Unit test state accessor
372 iStateAccessor = new(ELeave) TRegistrar_StateAccessor;
373 // Construct the Unit test context.
374 iUTContext = new(ELeave) CRegistrar_UnitTestContext(iDataLogger,
380 iUTContext->iDllData = CRegistryData::CDllData::NewLC();
381 CleanupStack::Pop(); //iDllData
383 // Artificially set up the TEntry info on the dll
384 TPtr dllName = iUTContext->iDllEntry.iName.Des();
385 dllName = KExampleDllFileName();
387 // Only the third entry (unique dll id) matters in this case
388 TUid uid1, uid2, uid3;
391 uid3.iUid = 0x10009DB1;
392 iUTContext->iDllEntry.iType = TUidType(uid1, uid2, uid3);
394 // Set the modified time to an unrealistic time to ensure it is reloaded
395 iUTContext->iDllEntry.iModified = 5;
396 iUTContext->iUpdate = EFalse;
397 iUTContext->iIndex = KErrNotFound;
399 iCtorValidator = new(ELeave) TRegistrar_Ctor_TransitionValidator(*iUTContext);
400 iRegisterDiscoveryValidator = new(ELeave) TRegistrar_RegisterDiscoveryL_TransitionValidator(*iUTContext);
401 iDefaultValidator = new(ELeave) TRegistrar_Default_TransitionValidator(*iUTContext);
402 iDtorValidator = new(ELeave) TRegistrar_Dtor_TransitionValidator(*iUTContext);
404 AddTransitionL(new(ELeave)CRegistrar_NewL_Transition(*iUTContext,*iCtorValidator));
405 AddTransitionL(new(ELeave)CRegistrar_RegisterDiscoveryL_Transition(*iUTContext,*iRegisterDiscoveryValidator));
406 AddTransitionL(new(ELeave)CRegistrar_DiscoveriesComplete_Transition(*iUTContext,*iDefaultValidator));
407 AddTransitionL(new(ELeave)CRegistrar_RegisterDiscoveryL_Transition(*iUTContext,*iRegisterDiscoveryValidator));
408 AddTransitionL(new(ELeave)CRegistrar_DiscoveriesComplete_Transition(*iUTContext,*iDefaultValidator));
409 AddTransitionL(new(ELeave)CRegistrar_Dtor_Transition(*iUTContext,*iDtorValidator));
412 void CRegistrar_RegisterTwice_UnitTest::Notification(TInt aNotificationCode)
414 iDataLogger.LogInformationWithParameters(KRegistrarNotificationMsg, aNotificationCode);
417 // ______________________________________________________________________________
419 _LIT(KRegistrarUseWhileDiscoveringUnitTest,"CRegistrar_UseWhileDiscovering_UnitTest");
421 CRegistrar_UseWhileDiscovering_UnitTest* CRegistrar_UseWhileDiscovering_UnitTest::NewL(CDataLogger& aDataLogger,
422 MUnitTestObserver& aObserver)
424 CRegistrar_UseWhileDiscovering_UnitTest* self =
425 new(ELeave) CRegistrar_UseWhileDiscovering_UnitTest(aDataLogger,
427 CleanupStack::PushL(self);
429 CleanupStack::Pop(self);
433 inline TInt CRegistrar_UseWhileDiscovering_UnitTest::RunError(TInt aError)
435 // The RunL left so chain to the base first and then cleanup
436 TInt error = CUnitTest::RunError(aError); // Chain to base
438 delete iStateAccessor;
440 delete iRegistryData;
442 // delete any validators used
443 delete iCtorValidator;
444 iCtorValidator = NULL;
445 delete iCheckRegValidator;
446 iCheckRegValidator = NULL;
447 delete iDtorValidator;
448 iDtorValidator = NULL;
453 inline CRegistrar_UseWhileDiscovering_UnitTest::~CRegistrar_UseWhileDiscovering_UnitTest()
455 // Simply delete our test class instance
457 delete iStateAccessor;
459 delete iRegistryData;
461 // delete any validators used
462 delete iCtorValidator;
463 delete iCheckRegValidator;
464 delete iDtorValidator;
467 inline CRegistrar_UseWhileDiscovering_UnitTest::CRegistrar_UseWhileDiscovering_UnitTest(CDataLogger& aDataLogger,
468 MUnitTestObserver& aObserver)
469 : CUnitTest(KRegistrarUseWhileDiscoveringUnitTest, aDataLogger, aObserver)
474 // Now the Individual transitions need to be added.
475 inline void CRegistrar_UseWhileDiscovering_UnitTest::ConstructL()
477 // Perform the base class initialization
478 UnitTestConstructL();
480 iRegistryData = CRegistryData::NewL(iFs);
482 // Create the Unit test state accessor
483 iStateAccessor = new(ELeave) TRegistrar_StateAccessor;
484 // Construct the Unit test context.
485 iUTContext = new(ELeave) CRegistrar_UnitTestContext(iDataLogger,
491 iUTContext->iDllData = CRegistryData::CDllData::NewLC();
492 CleanupStack::Pop(); //iDllData
494 iUTContext->iInterfaceUid.iUid = 0x10009DC0;
496 // Artificially set up the TEntry info on the dll
497 TPtr dllName = iUTContext->iDllEntry.iName.Des();
498 dllName = KExampleDllFileName();
500 iUTContext->iIndex = KErrNotFound;
502 iUTContext->iDriveUnit = EDriveZ;
504 iUTContext->iDriveUnit = EDriveC;
507 iCtorValidator = new(ELeave) TRegistrar_Ctor_TransitionValidator(*iUTContext);
508 iCheckRegValidator = new(ELeave) TRegistrar_CheckRegWhileDiscovering_TransitionValidator(*iUTContext);
509 iDtorValidator = new(ELeave) TRegistrar_Dtor_TransitionValidator(*iUTContext);
511 AddTransitionL(new(ELeave)CRegistrar_NewL_Transition(*iUTContext,*iCtorValidator));
512 AddTransitionL(new(ELeave)CRegistrar_DiscoveriesBegin_Transition(*iUTContext,*iCheckRegValidator));
513 AddTransitionL(new(ELeave)CRegistrar_Dtor_Transition(*iUTContext,*iDtorValidator));
516 void CRegistrar_UseWhileDiscovering_UnitTest::Notification(TInt aNotificationCode)
518 iDataLogger.LogInformationWithParameters(KRegistrarNotificationMsg, aNotificationCode);