Update contrib.
1 // Copyright (c) 2005-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 // This file contains tests for testing resolver related
15 // functionality linking against ecom.lib, i.e. using public API
16 // Where necessary stubs are implemented to help in writing test
17 // harness using RTest.
18 // This test assumes the following setup:
20 // EComExample /10009DB1 on Z:
21 // EComExample2/10009DB3 on Z:
22 // EComExample3/101F8477 on Z:
23 // EComExample4/101F8479 on Z:
24 // EComExample5/101F847B on C:
25 // Suicidal /10009DB2 on Z:
26 // EComExample6/0x101F847D on Z:
27 // The tests work by checking that the correct implementations are chosen
28 // for interface 0x10009DC0 depending on parameters passed
30 // Impl ID On C: On Z: e.g:Version/Default_data/dll_uid
31 // 10009DC3 - Ver 1/"text/ wml"/10009DB1, Ver 2/"text/ wml"/10009DB3
32 // 10009DC4 - Ver 1/"text/ *"/10009DB1, Ver 2/"text/ *"/10009DB3
33 // 101F8478 - Ver 1/""/101F8477
34 // 101F847A - Ver 1/""/101F8479
35 // 101F847C Ver 1/""/101F847B -
36 // 10009DC5 - Ver 1/"Suicide"/10009DB2
37 // 101F847E on Z Ver 1/""/101F847D
41 #include <ecom/ecom.h>
42 #include "EComUidCodes.h"
43 #include "Interface.h" // interface to Plugins
44 #include "../EcomTestUtils/EcomTestUtils.h"
50 LOCAL_D RTest test(_L("t_suicide.exe"));
52 LOCAL_D CTrapCleanup* TheTrapCleanup = NULL;
54 LOCAL_D CActiveScheduler* TheActiveScheduler = NULL;
56 // Used for supressing warning in OOM tests
57 #define __UNUSED_VAR(var) var = var
59 const TInt KOneSecond = 1000000;
61 // Interface ID used for testing
62 const TUid KUidInterface = {0x10009DC0};
64 // Resolver ID used for testing
65 const TUid KUidResolver = {0x10009DD0};
67 // Implementaion ID used for testing
68 const TUid KUidTestImplementation = {0x10009DC5};
70 // Interface Implementation Uids used for testing
71 const TInt KUidImplementation1 = 0x10009DC3;
72 const TInt KUidImplementation2 = 0x10009DC4;
73 const TInt KUidImplementation3 = 0x10009DC5;
74 const TInt KUidImplementation4 = 0x101F8478;
75 const TInt KUidImplementation5 = 0x101F847A;
76 const TInt KUidImplementation6 = 0x101F847C;
77 const TInt KUidImplementation7 = 0x101F847E;
79 // Match string used for testing
80 _LIT8(KInterfaceResolveMatchStr,"suicidal");
82 _LIT(KSysBinDirectoryWildcard, "c:\\sys\\bin\\*.dll");
83 _LIT(KResourceDirectoryWildcard, "c:\\resource\\plugins\\*.rsc");
85 // Plugins used for this test program
86 _LIT(KEComExample5OnZ, "z:\\RAMOnly\\EComExample5.dll");
88 _LIT(KEComExample5OnC, "c:\\sys\\bin\\EComExample5.dll");
89 _LIT(KEComExample5RscOnC, "c:\\resource\\plugins\\EComExample5.rsc");
90 _LIT(KEComExample4OnC, "c:\\sys\\bin\\EComExample4.dll");
91 _LIT(KEComExample4RscOnC, "c:\\resource\\plugins\\EComExample4.rsc");
92 // ROM file copied to the RAM for test purposes
93 _LIT(KEComExample5RscOnZ, "z:\\RAMOnly\\EComExample5.rsc");
96 // Utility clean up function
97 LOCAL_C void CleanupEComArray(TAny* aArray);
99 //It is used by some test methods which are called two times:
100 //from normal test and from OOM test.
101 static void LeaveIfErrNoMemory(TInt aError)
103 if(aError == KErrNoMemory)
105 REComSession::FinalClose();
111 @SYMTestCaseID SYSLIB-ECOM-CT-0709
112 @SYMTestCaseDesc Tests for creation of plugin with resolver match string
113 @SYMTestPriority High
114 @SYMTestActions Checks for no error condition
115 @SYMTestExpectedResults The test must not fail.
118 LOCAL_C void TestCreateImplSuicideL()
120 // Tests creation of plugin with resolver match string
121 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0709 "));
124 10009DC5 Ver 1/"Suicide"/10009DB2
126 CExampleInterface* interfaceimpl = NULL;
127 TRAPD(err, interfaceimpl = CExampleInterface::NewL(KInterfaceResolveMatchStr()));
128 ::LeaveIfErrNoMemory(err);
129 test(err == KErrNone);
130 CleanupStack::PushL(interfaceimpl);
132 test(KUidTestImplementation == interfaceimpl->ImplId());
134 TRAP(err, interfaceimpl->DoMethodL());
135 ::LeaveIfErrNoMemory(err);
136 test(err == KErrNone);
138 CleanupStack::PopAndDestroy(interfaceimpl);
142 @SYMTestCaseID SYSLIB-ECOM-CT-0710
143 @SYMTestCaseDesc Tests for Listing all Implementations for the Interface KUidInterface
144 @SYMTestPriority High
145 @SYMTestActions Calls up REComSession::ListImplementationsL with interface UID.Picks up 6 implementations.
146 Checks for no memory exceptions.
147 @SYMTestExpectedResults The test must not fail.
150 LOCAL_C void TestListAllImplL()
152 // Test for Listing all Implementations for the Interface KUidInterface
154 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0710 "));
156 RImplInfoPtrArray ifArray;
157 CleanupStack::PushL(TCleanupItem(CleanupEComArray, &ifArray));
159 TRAPD(err, REComSession::ListImplementationsL(KUidInterface, ifArray));
160 ::LeaveIfErrNoMemory(err);
161 test(err == KErrNone);
163 /* This should pick 6 implementations given below
164 10009DC3 Ver 2/"text/ wml"/10009DB3
165 10009DC4 Ver 2/"text/ *"/10009DB3
166 101F8478 Ver 1/""/101F8477
167 101F847A Ver 1/""/101F8479
168 101F847C Ver 1/""/101F847B
169 10009DC5 Ver 1/"Suicide"/10009DB2
170 101F847E Ver 1/""/101F847D
173 const TInt availCount = ifArray.Count();
174 test.Printf(_L("Found %d implementations.\n"),availCount);
175 test(availCount == 7);
177 for (TInt count=0;count<availCount;++count)
179 const CImplementationInformation* info = ifArray[count];
181 TDriveName driveName = info->Drive().Name();
182 test.Printf(_L("%d. uid={%x} version=%d on drive %S\n"), count+1, info->ImplementationUid(), info->Version(), &driveName);
184 switch(info->ImplementationUid().iUid)
186 case KUidImplementation1:
187 test(info->Version()==2);
188 test(info->Drive()==EDriveZ);
191 case KUidImplementation2:
192 test(info->Version()==2);
193 test(info->Drive()==EDriveZ);
196 case KUidImplementation3:
197 test(info->Version()==1);
198 test(info->Drive()==EDriveZ);
201 case KUidImplementation4:
202 test(info->Version()==1);
203 test(info->Drive()==EDriveZ);
206 case KUidImplementation5:
207 test(info->Version()==1);
208 test(info->Drive()==EDriveZ);
211 case KUidImplementation6:
212 test(info->Version()==1);
213 test(info->Drive()==EDriveC);
216 case KUidImplementation7:
217 test(info->Version()==1);
218 test(info->Drive()==EDriveZ);
222 test.Printf(_L("Unknown implementation Uid\n"));
226 // Empty the array of implementations
227 CleanupStack::PopAndDestroy();//ifArray, results in a call to CleanupEComArray
231 @SYMTestCaseID SYSLIB-ECOM-CT-0711
232 @SYMTestCaseDesc Tests to list all implementations for an interface with specified
233 match string and wildcard match
234 @SYMTestPriority High
235 @SYMTestActions Calls up REComSession::ListImplementationsL with interface UID and resolver matching characteristics
236 Checks for no memory exceptions.
237 @SYMTestExpectedResults The test must not fail.
240 LOCAL_C void TestListImplMatchStrWildcardL()
242 // Test to list all implementations for an interface with match string
243 // and wildcard match
245 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0711 "));
247 TEComResolverParams resolverParams;
248 _LIT8(KImplementationTest,"text/wml");
249 resolverParams.SetDataType(KImplementationTest());//Match string
250 resolverParams.SetGenericMatch(ETrue); // Allow wildcard matching
252 RImplInfoPtrArray ifArray;
253 CleanupStack::PushL(TCleanupItem(CleanupEComArray, &ifArray));
255 TRAPD(err, REComSession::ListImplementationsL(KUidInterface, resolverParams, ifArray));
256 ::LeaveIfErrNoMemory(err);
257 test(err == KErrNone);
259 /* This should pick 2 implementations given below
260 10009DC3 Ver 2/"text/ wml"/10009DB3
261 10009DC4 Ver 2/"text/ *"/10009DB3
264 const TInt availCount = ifArray.Count();
265 test.Printf(_L("Found %d implementations.\n"),availCount);
266 test(availCount == 2);
268 for (TInt count=0;count<availCount;++count)
270 const CImplementationInformation* info = ifArray[count];
272 TDriveName driveName = info->Drive().Name();
273 test.Printf(_L("%d. uid={%x} version=%d on drive %S\n"), count+1, info->ImplementationUid(), info->Version(), &driveName);
275 switch(info->ImplementationUid().iUid)
277 case KUidImplementation1:
278 test(info->Version()==2);
279 test(info->Drive()==EDriveZ);
282 case KUidImplementation2:
283 test(info->Version()==2);
284 test(info->Drive()==EDriveZ);
288 test.Printf(_L("Unknown implementation UID\n"));
293 // Empty the array of implementations
294 CleanupStack::PopAndDestroy();//ifArray, results in a call to CleanupEComArray
298 @SYMTestCaseID SYSLIB-ECOM-CT-0712
299 @SYMTestCaseDesc Tests to list all implementations for an interface with specified
300 match string and no wildcard match
301 @SYMTestPriority High
302 @SYMTestActions Calls up REComSession::ListImplementationsL with interface UID and resolver matching characteristics
303 Checks for no memory exceptions.
304 @SYMTestExpectedResults The test must not fail.
307 LOCAL_C void TestListImplMatchStrL()
309 // Test to list all implementations for an interface with specified
310 // match string and no wildcard match
312 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0712 "));
314 TEComResolverParams resolverParams;
315 _LIT8(KImplementationTest,"text/wml");
316 resolverParams.SetDataType(KImplementationTest());//Match string
317 resolverParams.SetGenericMatch(EFalse); // Don't allow wildcard matching
319 RImplInfoPtrArray ifArray;
320 CleanupStack::PushL(TCleanupItem(CleanupEComArray, &ifArray));
322 TRAPD(err, REComSession::ListImplementationsL(KUidInterface, resolverParams, ifArray));
323 ::LeaveIfErrNoMemory(err);
324 test(err == KErrNone);
326 const TInt availCount = ifArray.Count();
327 test.Printf(_L("Found %d implementations.\n"),availCount);
328 test(availCount == 1);
331 10009DC3 Ver 2/"text/wml"/10009DB3
334 for (TInt count=0;count<availCount;++count)
336 const CImplementationInformation* info = ifArray[count];
338 TDriveName driveName = info->Drive().Name();
339 test.Printf(_L("%d. uid={%x} version=%d on drive %S\n"),
340 count+1, info->ImplementationUid(), info->Version(), &driveName);
342 switch(info->ImplementationUid().iUid)
344 case KUidImplementation1:
345 test(info->Version()==2);
346 test(info->Drive()==EDriveZ);
350 test.Printf(_L("Unknown implementation Uid\n"));
354 // Empty the array of implementations
355 CleanupStack::PopAndDestroy();//ifArray, results in a call to CleanupEComArray
359 @SYMTestCaseID SYSLIB-ECOM-CT-0713
360 @SYMTestCaseDesc Tests to list all Implementations for an Interface with specified
361 Resolver ID, Match String and Wildcard match
362 @SYMTestPriority High
363 @SYMTestActions Calls up REComSession::ListImplementationsL with interface UID Resolver ID, matching characteristics
364 Checks for no memory exceptions.
365 @SYMTestExpectedResults The test must not fail.
368 LOCAL_C void TestListAllImplResolverIDL()
370 // Test to list all Implementations for an Interface with specified
371 // Resolver ID, Match String and Wildcard match
373 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0713 "));
375 TEComResolverParams resolverParams;
376 resolverParams.SetDataType(KInterfaceResolveMatchStr());
377 resolverParams.SetGenericMatch(ETrue); // Allow wildcard matching
379 RImplInfoPtrArray ifArray;
380 CleanupStack::PushL(TCleanupItem(CleanupEComArray, &ifArray));
382 TRAPD(err, REComSession::ListImplementationsL(KUidInterface,
386 ::LeaveIfErrNoMemory(err);
387 test(err == KErrNone);
389 const TInt availCount = ifArray.Count();
390 test.Printf(_L("Found %d implementations.\n"), availCount);
391 test(availCount == 1);
394 10009DC5 Ver 1/"Suicide"/10009DB2
397 for (TInt count=0;count<availCount;++count)
399 const CImplementationInformation* info = ifArray[count];
401 TDriveName driveName = info->Drive().Name();
402 test.Printf(_L("%d. uid={%x} version=%d on drive %S\n"), count+1, info->ImplementationUid(), info->Version(), &driveName);
404 switch(info->ImplementationUid().iUid)
406 case KUidImplementation3:
407 test(info->Version()==1);
408 test(info->Drive()==EDriveZ);
412 test.Printf(_L("Unknown implementation UID\n"));
417 // Empty the array of implementations
418 CleanupStack::PopAndDestroy();//ifArray, results in a call to CleanupEComArray
421 typedef void (*ClassFuncPtrL) (void);
424 @SYMTestCaseID SYSLIB-ECOM-CT-0714
425 @SYMTestCaseDesc Function to call all test functions
426 @SYMTestPriority High
427 @SYMTestActions Calls up test function and checks for handle counts.
428 @SYMTestExpectedResults The test must not fail.
432 Wrapper function to call all test functions
434 @param testFuncL pointer to test function
435 @param aTestDesc test function name
437 LOCAL_C void DoBasicTestL(ClassFuncPtrL testFuncL, const TDesC& aTestDesc)
439 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0714 "));
440 test.Next(aTestDesc);
443 // find out the number of open handles
444 TInt startProcessHandleCount;
445 TInt startThreadHandleCount;
446 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
448 //Call the test function
451 REComSession::FinalClose();
453 // check that no handles have leaked
454 TInt endProcessHandleCount;
455 TInt endThreadHandleCount;
456 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
458 test(startThreadHandleCount == endThreadHandleCount);
464 @SYMTestCaseID SYSLIB-ECOM-CT-0715
465 @SYMTestCaseDesc Wrapper function to call all OOM test functions
466 @SYMTestPriority High
467 @SYMTestActions Calls up test function and checks for handle counts.
468 @SYMTestExpectedResults The test must not fail.
472 Wrapper function to call all OOM test functions
474 @param testFuncL pointer to OOM test function
475 @param aTestDesc test function name
477 LOCAL_C void DoOOMTest(ClassFuncPtrL testFuncL, const TDesC& aTestDesc)
479 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0715 "));
480 test.Next(aTestDesc);
482 TInt err, tryCount = 0;
486 // find out the number of open handles
487 TInt startProcessHandleCount;
488 TInt startThreadHandleCount;
489 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
491 // Setting Heap failure for OOM test
492 __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
494 TRAP(err, (*testFuncL)());
496 __UHEAP_SETFAIL(RHeap::ENone, 0);
501 REComSession::FinalClose();
504 // check that no handles have leaked
505 TInt endProcessHandleCount;
506 TInt endThreadHandleCount;
507 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
509 test(startProcessHandleCount == endProcessHandleCount);
510 test(startThreadHandleCount == endThreadHandleCount);
513 } while(err == KErrNoMemory);
515 test(err == KErrNone);
516 test.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount);
519 LOCAL_C void DoTestsL()
524 DoBasicTestL(TestCreateImplSuicideL, _L("TestCreateImplSuicideL"));
525 DoBasicTestL(TestListImplMatchStrL, _L("TestListImplMatchStrL"));
526 DoBasicTestL(TestListImplMatchStrWildcardL, _L("TestListImplMatchStrWildcardL"));
527 DoBasicTestL(TestListAllImplL, _L("TestListAllImplL"));
528 DoBasicTestL(TestListAllImplResolverIDL, _L("TestListAllImplResolverIDL"));
531 DoOOMTest(TestCreateImplSuicideL, _L("OOM TestCreateImplSuicide"));
532 DoOOMTest(TestListImplMatchStrL, _L("OOM TestListImplMatchStr"));
533 DoOOMTest(TestListImplMatchStrWildcardL, _L("OOM TestListImplMatchStrWildcard"));
534 DoOOMTest(TestListAllImplL, _L("OOM TestListAllImpl"));
535 DoOOMTest(TestListAllImplResolverIDL, _L("OOM TestListAllImplResolverID"));
540 // This function is used for cleanup support of locally declared arrays
541 LOCAL_C void CleanupEComArray(TAny* aArray)
543 (static_cast<RImplInfoPtrArray*>(aArray))->ResetAndDestroy();
546 // Deleting plugin from the RAM for cleanup purpose
547 inline LOCAL_C void DeleteTestPlugins()
549 TRAPD(err, EComTestUtils::FileManDeleteFileL(KSysBinDirectoryWildcard));
550 TRAP(err, EComTestUtils::FileManDeleteFileL(KResourceDirectoryWildcard));
553 // Copies the Plugins to specific folder for testing purpose
554 LOCAL_C void CopyPlugins()
558 TRAPD(err, EComTestUtils::FileManCopyFileL(KEComExample5OnZ, KEComExample5OnC));
561 TRAP(err, EComTestUtils::FileManCopyFileL(KEComExample5RscOnZ, KEComExample5RscOnC));
564 // KEComExample4OnC & KEComExample4RscOnC are copied to C: Drive for
565 // testing in t_listimplementation test program. These files should
566 // be present in Z:. Please make sure these are present in Z only.
567 TRAP(err, EComTestUtils::FileManDeleteFileL(KEComExample4OnC));
568 TRAP(err, EComTestUtils::FileManDeleteFileL(KEComExample4RscOnC));
572 //Initialise the Active Scheduler
574 LOCAL_C void SetupL()
576 // Construct and install the Active Scheduler. The Active Schedular is needed
577 // by components used by this test as they are ActiveObjects.
578 TheActiveScheduler = new(ELeave)CActiveScheduler;
579 CActiveScheduler::Install(TheActiveScheduler);
582 GLDEF_C TInt E32Main()
586 test.Printf(_L("\n"));
588 test.Start(_L("Suicide Tests"));
590 TheTrapCleanup = CTrapCleanup::New();
591 TRAPD(err, SetupL());
592 test(err == KErrNone);
595 // The reason for the folowing delay is:
596 // ECOM server could be already started. It means that when we copy some
597 // ECOM plugins from Z: to C: drive - ECOM server should look for and
598 // find the new ECOM plugins. The ECOM server uses for that an active object,
599 // which scans plugin directories. So the discovering service is asynchronous.
600 // We have to wait some time until it finishes.
601 // Otherwise ListImplementationsL could fail to find requested implementations.
602 User::After(KOneSecond * 3);
604 TRAP(err,DoTestsL());
607 // Cleanup files. If the cleanup fails that is no problem,
608 // as any subsequent tests will replace them. The only downside
609 // would be the disk not being tidied
612 delete TheActiveScheduler;
613 delete TheTrapCleanup;