os/ossrv/lowlevellibsandfws/pluginfw/Framework/PluginDiscoveryTests/t_plugindiscovery.cpp
First public contribution.
1 // Copyright (c) 2004-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 // Contains tests with invalid/missing plugin DLLs
19 #include <ecom/ecom.h>
20 #include "EComUidCodes.h"
21 #include "Interface.h" // interface to Plugins
22 #include "../EcomTestUtils/EcomTestUtils.h"
28 LOCAL_D RTest test(_L("t_plugindiscovery.exe"));
30 LOCAL_D CTrapCleanup* TheTrapCleanup = NULL;
32 LOCAL_D CActiveScheduler* TheActiveScheduler = NULL;
36 // Implementaion ID used for testing
37 const TUid KUidTestImplementation = {0x101F847C};
40 //It is used by some test methods which are called two times:
41 //from normal test and from OOM test.
42 static void LeaveIfErrNoMemory(TInt aError)
44 if(aError == KErrNoMemory)
46 REComSession::FinalClose();
52 // Plugins used in tests.
53 _LIT(KEComInvalidDllOnZ, "z:\\RAMOnly\\InvalidSIDPlugin.dll");
54 _LIT(KEComInvalidRscOnZ, "z:\\RAMOnly\\InvalidSIDPlugin.rsc");
55 _LIT(KEComInvalidDllOnC, "c:\\sys\\bin\\InvalidSIDPlugin.dll");
56 _LIT(KEComInvalidRscOnC, "c:\\resource\\plugins\\InvalidSIDPlugin.rsc");
58 _LIT(KEComExample5RscOnZ, "z:\\RAMOnly\\EComExample5.rsc");
59 _LIT(KEComExample5RscOnC, "c:\\resource\\plugins\\EComExample5.rsc");
60 _LIT(KEComRomRslvrExampleRscOnCRomLocation, "z:\\RAMOnly\\EComRomRslvrExampleOnC.RSC");
61 _LIT(KEComRomRslvrExampleRscOnCRamLocation, "c:\\resource\\plugins\\EComRomRslvrExampleOnZ.RSC");
63 // Plugins used in plugins directory removing test
64 _LIT(KEComDefectPluginDLLOnZ, "Z:\\RAMOnly\\DefectPlugin.dll");
65 _LIT(KEComDefectPluginRSCOnZ, "Z:\\RAMOnly\\DefectPlugin.rsc");
66 _LIT(KEComDefectPluginDLLOnC, "C:\\sys\\bin\\DefectPlugin.dll");
67 _LIT(KEComDefectPluginRSCOnC, "C:\\Resource\\Plugins\\DefectPlugin.rsc");
68 _LIT(KEComResourcePluginDirNameOnC, "C:\\Resource\\Plugins\\");
69 _LIT(KEComResourcePluginDirNameOffOnC, "C:\\Resource\\PluginsNameOff\\");
72 @SYMTestCaseID SYSLIB-ECOM-CT-0030
73 @SYMTestCaseDesc Test that an orphaned resource file does not create a registry
76 @SYMTestActions EComExample5.rsc file copied to C: drive.
77 Check call to REComSession::CreateImplementationL() via test
78 CExampleInterface class fails to return the implementation.
79 @SYMTestExpectedResults The test must not fail.
82 LOCAL_C void TestOrphanedRscFileL()
84 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0030 "));
88 TRAPD(ignoreErr, EComTestUtils::FileManDeleteFileL(KEComExample5RscOnC));
89 ignoreErr = ignoreErr;
91 TRAPD(err, EComTestUtils::FileManCopyFileL(KEComExample5RscOnZ, KEComExample5RscOnC));
92 test(err == KErrNone);
94 // The reason for the folowing delay is:
95 // ECOM server could be already started. It means that when we copy some
96 // ECOM plugins from Z: to C: drive - ECOM server should look for and
97 // find the new ECOM plugins. The ECOM server uses for that an active object,
98 // which scans plugin directories. So the discovering service is asynchronous.
99 // We have to wait some time until it finishes.
100 // Otherwise CreateImplementationsL could fail to create requested implementations.
103 CExampleInterface* interfaceimpl = NULL;
104 TRAP(err, interfaceimpl = CExampleInterface::NewL2(KUidTestImplementation));
105 ::LeaveIfErrNoMemory(err);
106 test(err == KErrNotFound);
107 CleanupStack::PushL(interfaceimpl);
109 CleanupStack::PopAndDestroy(interfaceimpl);
110 REComSession::FinalClose();
113 TRAP(err, EComTestUtils::FileManDeleteFileL(KEComExample5RscOnC));
114 test(err == KErrNone);
120 @SYMTestCaseID SYSLIB-ECOM-CT-1404
121 @SYMTestCaseDesc Test that an orphaned resource file does not create a registry entry.
122 and that other valid implementations are discovered instead.
123 @SYMTestPriority High
124 @SYMTestActions Copy EComRomRslvrExampleOnC to the plug-ins directory on the C drive, without the associated DLL
125 Because the DLL is not there, Ecom should fall back to the implementations on the Z drive in EComRomRslvrExampleOnZ
126 @SYMTestExpectedResults ECom plugins with invalid DLLs fall back to the correct implementations.
129 LOCAL_C void TestOrphanedRscFileFallBackL()
131 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1404 "));
134 // Copy plugin resource file and NOT the associated DLL
135 TRAPD(err, EComTestUtils::FileManCopyFileL(KEComRomRslvrExampleRscOnCRomLocation, KEComRomRslvrExampleRscOnCRamLocation));
136 test(err == KErrNone);
138 // The reason for the folowing delay is:
139 // ECOM server could be already started. It means that when we copy some
140 // ECOM plugins from Z: to C: drive - ECOM server should look for and
141 // find the new ECOM plugins. The ECOM server uses for that an active object,
142 // which scans plugin directories. So the discovering service is asynchronous.
143 // We have to wait some time until it finishes.
144 // Otherwise ListImplementationsL could fail to find requested implementations.
147 TUid romRslvrExampleInterfaceUid = {0x10009DC8};
148 RImplInfoPtrArray ifArray;
149 TRAP(err, REComSession::ListImplementationsL(romRslvrExampleInterfaceUid, ifArray));
150 ::LeaveIfErrNoMemory(err);
151 test(err == KErrNone);
153 // Go through the implementations for the given interface, and find the ones that match up with
154 // EComRomRslvrExampleRscOnZ (and not EComRomRslvrExampleRscOnC becuase it's DLL is missing)
155 // EComRomRslvrExampleOnZ contains the implementation 0x10009DC7v2 and 0x10009DC6v1 (these should be found)
156 // EComRomRslvrExampleOnC contains the implementation 0x10009DC7v1 and 0x10009DC6v2 (these should NOT be returned becuase of the missing DLL)
157 TBool foundRightImplementation1 = EFalse;
158 TBool foundRightImplementation2 = EFalse;
159 for(TInt index = 0; index < ifArray.Count(); ++index)
161 TUid uid = ifArray[index]->ImplementationUid();
162 TInt version = ifArray[index]->Version();
163 TInt drive = ifArray[index]->Drive();
164 if (uid.iUid == 0x10009DC6)
167 test(drive==EDriveZ);
168 foundRightImplementation1 = ETrue;
170 if (uid.iUid == 0x10009DC7)
173 test(drive==EDriveZ);
174 foundRightImplementation2 = ETrue;
177 test(foundRightImplementation1 && foundRightImplementation2);
179 ifArray.ResetAndDestroy();
180 REComSession::FinalClose();
183 TRAP(err, EComTestUtils::FileManDeleteFileL(KEComRomRslvrExampleRscOnCRamLocation));
184 test(err == KErrNone);
190 @SYMTestCaseID SYSLIB-ECOM-CT-0031
191 @SYMTestCaseDesc Test that a plugin whose SID does not match the value in it's
192 resource file will not be installed in the registry.
193 @SYMTestPriority High
194 @SYMTestActions InvalidSIDPlugin dll and rsc files copied to C: drive.
195 Verify plugin is not registered by checking
196 ListImplementationsL returns zero plugins for this interface.
197 @SYMTestExpectedResults The test must not fail.
200 LOCAL_C void TestInvalidSIDPluginL()
202 // InvalidSIDPlugin .dll and .rsc are copied from EComExample5.dll and
205 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0031 "));
209 TRAPD(err, EComTestUtils::FileManCopyFileL(KEComInvalidDllOnZ, KEComInvalidDllOnC));
210 test(err == KErrNone);
211 TRAP(err, EComTestUtils::FileManCopyFileL(KEComInvalidRscOnZ, KEComInvalidRscOnC));
212 test(err == KErrNone);
214 // The reason for the folowing delay is:
215 // ECOM server could be already started. It means that when we copy some
216 // ECOM plugins from Z: to C: drive - ECOM server should look for and
217 // find the new ECOM plugins. The ECOM server uses for that an active object,
218 // which scans plugin directories. So the discovering service is asynchronous.
219 // We have to wait some time until it finishes.
220 // Otherwise ListImplementationsL could fail to find requested implementations.
223 TUid ifUid = {0x101FE392}; // HeapTestImpl.rsc interface_uid
224 RImplInfoPtrArray ifArray;
225 REComSession::ListImplementationsL(ifUid, ifArray);
227 const TInt availCount = ifArray.Count();
228 test.Printf(_L("Found %d implementations.\n"),availCount);
229 test(availCount == 0);
231 ifArray.ResetAndDestroy();
232 REComSession::FinalClose(); // Don't want leaks outside the test
235 TRAP(err, EComTestUtils::FileManDeleteFileL(KEComInvalidDllOnC));
236 TRAP(err, EComTestUtils::FileManDeleteFileL(KEComInvalidRscOnC));
242 @SYMTestCaseID SYSLIB-ECOM-CT-1858
243 @SYMTestCaseDesc Test that rediscovery of removing and adding "\Resource\Plugins" directory
245 @SYMTestPriority High
246 @SYMTestActions Removes "\Resource\Plugins" directory on C: drive, check that
247 rediscovery works properly by verifying plugin's registration.
248 Adds "\Resource\Plugins" directory on C: drive, check that rediscovery works
249 fine by verifying plugin's registration.
250 @SYMTestExpectedResults The test must not fail.
253 LOCAL_C void TestPluginsDirectoryRemovingL()
255 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1858 "));
259 Add The following plugin to C drive
261 Interface UID DLL UID Imp. UID Version DllFile
262 ------------------------------------------------------------------------------------------------------------------------------------------
263 0x102797A1 0x102797A0 0x102797A2 1 C:\\..\\DefectPlugin.dll
266 TRAPD(err, EComTestUtils::FileManCopyFileL(KEComDefectPluginDLLOnZ, KEComDefectPluginDLLOnC));
267 test(err == KErrNone);
268 TRAP(err, EComTestUtils::FileManCopyFileL(KEComDefectPluginRSCOnZ, KEComDefectPluginRSCOnC));
269 test(err == KErrNone);
273 TUid interfaceUid={0x102797A1};
274 RImplInfoPtrArray implArray;
276 // Now start ecom discovery and get implementations for IF UID 0x102797A1
277 TRAP(err, REComSession::ListImplementationsL(interfaceUid, implArray));
278 ::LeaveIfErrNoMemory(err);
279 test(err == KErrNone);
281 // Expected number of implementations returned
282 test(implArray.Count()==1);
284 // Check that the implementation uid returned matched the specs above
285 TUid implUid = implArray[0]->ImplementationUid();
286 TInt version = implArray[0]->Version();
287 TInt drive = implArray[0]->Drive();
289 test(implUid.iUid == 0x102797A2);
293 test(drive == EDriveC);
295 implArray.ResetAndDestroy();
297 // Now remove plugins directory
298 TRAP(err, EComTestUtils::FileManRenameL(KEComResourcePluginDirNameOnC, KEComResourcePluginDirNameOffOnC));
299 test(err == KErrNone);
300 TRAP(err, EComTestUtils::FileManDeleteDirL(KEComResourcePluginDirNameOnC));
301 test(err == KErrNone);
304 err = TheFs.Entry(KEComResourcePluginDirNameOnC, entry);
305 // Test the plugins directory is now gone
306 test(err == KErrNotFound);
308 // Wait EComServer performing rediscovery
311 TRAP(err, REComSession::ListImplementationsL(interfaceUid, implArray));
312 ::LeaveIfErrNoMemory(err);
313 test(err == KErrNone);
315 // Test the rediscovery and directory scanning has been performed on renaming off event
316 test(implArray.Count()==0);
318 implArray.ResetAndDestroy();
320 // Now rename plugins directory back
321 TRAP(err, EComTestUtils::FileManRenameL(KEComResourcePluginDirNameOffOnC, KEComResourcePluginDirNameOnC));
322 test(err == KErrNone);
323 TRAP(err, EComTestUtils::FileManDeleteDirL(KEComResourcePluginDirNameOffOnC));
324 test(err == KErrNone);
326 // Test the plugins directory is added back
327 err = TheFs.Entry(KEComResourcePluginDirNameOnC, entry);
328 test(err == KErrNone);
330 // Wait EComServer performing rediscovery
333 TRAP(err, REComSession::ListImplementationsL(interfaceUid, implArray));
334 ::LeaveIfErrNoMemory(err);
335 test(err == KErrNone);
337 // Test the rediscovery and directory scanning has been performed on renaming off event
338 test(implArray.Count()==1);
340 //Check that the implementation uid returned matched the specs above
341 implUid = implArray[0]->ImplementationUid();
342 version = implArray[0]->Version();
343 drive = implArray[0]->Drive();
344 test(implUid.iUid == 0x102797A2);
346 test(drive == EDriveC);
348 implArray.ResetAndDestroy();
350 REComSession::FinalClose(); // Don't want leaks outside the test
353 TRAP(err, EComTestUtils::FileManDeleteFileL(KEComDefectPluginDLLOnC));
354 TRAP(err, EComTestUtils::FileManDeleteFileL(KEComDefectPluginRSCOnC));
362 typedef void (*ClassFuncPtrL) (void);
365 Wrapper function to call all test functions
367 @param testFuncL pointer to test function
368 @param aTestDesc test function name
370 LOCAL_C void DoBasicTestL(ClassFuncPtrL testFuncL, const TDesC& aTestDesc)
372 test.Next(aTestDesc);
375 // find out the number of open handles
376 TInt startProcessHandleCount;
377 TInt startThreadHandleCount;
378 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
380 //Call the test function
383 // check that no handles have leaked
384 TInt endProcessHandleCount;
385 TInt endThreadHandleCount;
386 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
388 test(startThreadHandleCount == endThreadHandleCount);
394 Wrapper function to call all OOM test functions
395 @param testFuncL pointer to OOM test function
396 @param aTestDesc test function name
398 LOCAL_C void DoOOMTestL(ClassFuncPtrL testFuncL, const TDesC& aTestDesc)
400 test.Next(aTestDesc);
407 // find out the number of open handles
408 TInt startProcessHandleCount;
409 TInt startThreadHandleCount;
410 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
412 __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
414 //Call the test function
415 TRAP(err, ((*testFuncL)()));
417 __UHEAP_SETFAIL(RHeap::ENone, 0);
422 REComSession::FinalClose();
425 // check that no handles have leaked
426 TInt endProcessHandleCount;
427 TInt endThreadHandleCount;
428 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
430 test(startProcessHandleCount == endProcessHandleCount);
431 test(startThreadHandleCount == endThreadHandleCount);
434 } while(err == KErrNoMemory);
436 test(err == KErrNone);
437 test.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount);
442 LOCAL_C void DoTestsL()
447 test.Next(_L("Basic Test Suite"));
448 test.Start(_L("Basic Test Suite"));
449 DoBasicTestL(&TestOrphanedRscFileL, _L("TestOrphanedRscFileL"));
450 DoBasicTestL(&TestInvalidSIDPluginL, _L("TestInvalidSIDPluginL"));
451 DoBasicTestL(&TestOrphanedRscFileFallBackL, _L("TestOrphanedRscFileFallBackL"));
452 DoBasicTestL(&TestPluginsDirectoryRemovingL, _L("TestPluginsDirectoryRemovingL"));
456 test.Next(_L("Out-of-memory Repeat Tests"));
457 test.Start(_L("Out-of-memory Repeat Tests"));
458 DoOOMTestL(&TestOrphanedRscFileL, _L("TestOrphanedRscFileL"));
459 DoOOMTestL(&TestInvalidSIDPluginL, _L("TestInvalidSIDPluginL"));
460 DoOOMTestL(&TestOrphanedRscFileFallBackL, _L("TestOrphanedRscFileFallBackL"));
461 DoOOMTestL(&TestPluginsDirectoryRemovingL, _L("TestPluginsDirectoryRemovingL"));
468 //Initialise the Active Scheduler
470 LOCAL_C void SetupL()
472 // Construct and install the Active Scheduler. The Active Schedular is needed
473 // by components used by this test as they are ActiveObjects.
474 TheActiveScheduler = new(ELeave)CActiveScheduler;
475 CActiveScheduler::Install(TheActiveScheduler);
478 GLDEF_C TInt E32Main()
482 test.Printf(_L("\n"));
484 test.Start(_L("Dual-Mode Discovery Tests"));
486 TheTrapCleanup = CTrapCleanup::New();
487 TInt err = TheFs.Connect();
488 test(err == KErrNone);
490 test(err == KErrNone);
494 TRAP(err,DoTestsL());
497 delete TheActiveScheduler;
499 delete TheTrapCleanup;