Update contrib.
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.
20 #include "../EcomTestUtils/EcomTestUtils.h"
21 #include "LoadManager.h"
22 #include <ecom/ecom.h>
23 #include "EComUidCodes.h"
24 #include "Interface.h" // interface to Plugins
26 _LIT(KEComExDllOnC, "c:\\sys\\bin\\EComExample5.dll");
27 _LIT(KEComRscFileOnZ, "z:\\RAMOnly\\EComExample5.rsc");
28 _LIT(KEComRscFileOnC, "c:\\resource\\plugins\\EComExample5.rsc");
30 _LIT(KEComExampleDllOnC, "C:\\sys\\bin\\EComExample.dll");
31 _LIT(KEComExample2DllOnC, "C:\\sys\\bin\\EComExample2.dll");
32 _LIT(KEComExample3DllOnC, "C:\\sys\\bin\\EComExample3.dll");
34 _LIT(KEComExampleRscOnC, "C:\\resource\\plugins\\EComExample.rsc");
35 _LIT(KEComExample2RscOnC, "C:\\resource\\plugins\\EComExample2.rsc");
36 _LIT(KEComExample3RscOnC, "C:\\resource\\plugins\\EComExample3.rsc");
38 _LIT(KEComExampleRscOnZ, "Z:\\RAMOnly\\EComExample.rsc");
39 _LIT(KEComExample2RscOnZ, "Z:\\RAMOnly\\EComExample2.rsc");
40 _LIT(KEComExample3RscOnZ, "Z:\\RAMOnly\\EComExample3.rsc");
43 _LIT(KEComExDllOnZ, "z:\\RAMOnly\\EComExample5.dll");
44 _LIT(KEComExampleDllOnZ, "Z:\\RAMOnly\\EComExample.dll");
45 _LIT(KEComExample2DllOnZ, "Z:\\RAMOnly\\EComExample2.dll");
46 _LIT(KEComExample3DllOnZ, "Z:\\RAMOnly\\EComExample3.dll");
48 /** Test cases covered in this test code:
49 1. Thread create imp destroy then not calling FinalClose() will cause a panic inside the thread( capture this panic)(memory leak)
51 2. Thread list implementation then not calling FinalClose() will cause a panic inside the thread(capture this panic)(memory leak).
53 3. Thread Create Impl1, Create Impl2, Destroy Impl2, Destory Impl1 then FinalClose() no memory leak.
55 4. Thread create Impl1, call FinalClose() 2x, Destroy Impl1 then FinalClose() to show that FinalClose() can be called many times with no unknown consequence.
57 5. REComSession::public constructor (without OpenL), called FinalClose () 2x, then Close(), no problem and memory leak.
59 6. REComSession::OpenL,call Close() then call FinalClose() to show no memory leak problem.
61 7. Test calling REComSession::FinalClose() to show no memory leak, errors, crash problem
64 LOCAL_D RTest test(_L("Final Close Test"));
70 static TInt Create_Destroy_Without_FinalClose(TAny*);
71 static TInt Create_Destroy_With_FinalCloseL();
72 static TInt Create_Destroy_TestL();
75 static TInt ListImpl_Without_FinalClose(TAny*);
76 static TInt ListImpl_With_FinalCloseL();
77 static void ListImplementation_TestL();
80 static void Create_Destroy2_With_FinalCloseL();
83 static void Create_Destroy3_With_FinalCloseL();
86 static void Create_Destroy4_With_FinalCloseL();
89 static void FinalClose();
92 static void NonConstructL_Create_Destroy();
94 static void ThreadPanicTest(const TDesC& aName,TThreadFunction aFunction);
98 Test creating an implementation, deleting the implementation
99 and then call FinalClose(). Check that there is no crash and memory leak
101 @SYMTestCaseID SYSLIB-ECOM-CT-0759
102 @SYMTestCaseDesc Tests for creating and destroying an implementation
103 @SYMTestPriority High
104 @SYMTestActions Create and delete a new implementation with UID and initialisation parameters.
105 Call up REComSession::FinalClose
106 Check for no crash and memory leaks.
107 @SYMTestExpectedResults The test must not fail.
110 TInt RFinalCloseTest::Create_Destroy_With_FinalCloseL()
114 Create_Destroy_TestL();
116 REComSession::FinalClose();
123 Test creating an implementation, deleting the implementation
124 Never call FinalClose() to show memory leak panic
126 @SYMTestCaseID SYSLIB-ECOM-CT-0760
127 @SYMTestCaseDesc Tests for creating and destroying an implementation
128 @SYMTestPriority High
129 @SYMTestActions Create and delete a new implementation with UID and initialisation parameters.
130 FinalClose is omitted to show memory leak panic
131 @SYMTestExpectedResults The test must not fail.
134 TInt RFinalCloseTest::Create_Destroy_Without_FinalClose(TAny*)
138 CTrapCleanup* threadcleanup = CTrapCleanup::New();
140 TRAPD(err,Create_Destroy_TestL());
143 //This FinalClose() is purposely omitted for testing the PANIC
144 //REComSession::FinalClose();
146 delete threadcleanup;
151 //The test code for creating and destroying an implementation
152 //To be used in the two test cases above
153 TInt RFinalCloseTest::Create_Destroy_TestL()
156 TUid implUid={0x101F8478};
158 // Set up some empty initialisation parameters
159 CExampleInterface::TExampleInterfaceInitParams initParams;
160 initParams.integer = 0;
161 initParams.descriptor = NULL;
163 CExampleInterface* dllPtr = REINTERPRET_CAST(CExampleInterface*,
164 REComSession::CreateImplementationL(implUid,dTorKey,&initParams));
166 //Check the return implementation instantiation has the same implementation uid
167 test(dllPtr->ImplId()==implUid);
168 //The returned Uid to be used in Destruction should match the implementation uid as well
169 CInstanceInfoSimple* instanceInfo = reinterpret_cast <CInstanceInfoSimple*> (dTorKey.iUid);
170 test(instanceInfo->ImplementationUid()==implUid);
172 REComSession::DestroyedImplementation(dTorKey);
180 //The test code for listing implementation of an interface Uid.
181 //The test also verify all the implementations in the list by
182 //checking all the implementation Uid and their version.
183 void RFinalCloseTest::ListImplementation_TestL()
186 Some Plugin in Z that can be used for testing purposes
187 Interface UID DLL UID Implementation UID Version DllFile
188 -------------------------------------------------------------------
189 0x10009DC0 0x10009DB1 0x10009DC3 1 Z:\\..\\EComExample.dll old_version
190 0x10009DB1 0x10009DC4 1 Z:\\..\\EComExample.dll old_version
191 0x10009DB3 0x10009DC3 2 Z:\\..\\EComExample2.dll =
192 0x10009DB3 0x10009DC4 2 Z:\\..\\EComExample2.dll =
193 0x101F8477 0x101F8478 1 Z:\\..\\EComExample3.dll =
194 0x101F8479 0x101F847A 1 Z:\\..\\EComExample4.dll =
195 0x10009DB2 0x10009DC5 1 Z:\\..\\Suidical.dll =
198 TUid interfaceUid={0x10009DC0};
199 RImplInfoPtrArray implArray;
201 //Array of all the expected implementation Uid;
202 RArray<TInt> expectedUidArray;
203 expectedUidArray.Append(0x10009DC3);
204 expectedUidArray.Append(0x10009DC4);
205 expectedUidArray.Append(0x101F8478);
206 expectedUidArray.Append(0x101F847A);
207 expectedUidArray.Append(0x10009DC5);
209 REComSession::ListImplementationsL(interfaceUid,implArray);
211 //Expected number of implementations retured=5
212 //This line has been removed as it is not safe to always assume there will be
213 //a fixed number of implementations based on an the interface 0x10009DC0.
214 //test(implArray.Count()==5);
217 //Check that the implementation uid returned matched the specs above
218 for (TInt i=0;i<implArray.Count();i++)
220 TUid implUid=implArray[i]->ImplementationUid();
221 if (expectedUidArray.Find(implUid.iUid)!=KErrNotFound)
223 //check for the latest version for 10009DC3 & 10009DC4
224 if (implUid.iUid==0x10009DC3 || implUid.iUid==0x10009DC4)
225 test(implArray[i]->Version()==2);
226 //all the other implementations have version 1
228 test(implArray[i]->Version()==1);
231 expectedUidArray.Reset();
232 expectedUidArray.Close();
233 implArray.ResetAndDestroy();
237 The test code for testing the proper use of ListImplementationsL where
238 after calling that function we call REComSession::FinalClose()
240 @SYMTestCaseID SYSLIB-ECOM-CT-0761
241 @SYMTestCaseDesc Tests for proper listing of implementation of an interface UID
242 @SYMTestPriority High
243 @SYMTestActions Call up REComSession::FinalClose after ListImplementation_TestL
244 @SYMTestExpectedResults The test must not fail.
247 TInt RFinalCloseTest::ListImpl_With_FinalCloseL()
251 ListImplementation_TestL();
253 REComSession::FinalClose();
261 The test code for testing the improper use of ListImplementationsL where
262 after the call, we never invoke REComSession::FinalClose().This will
263 result in some memory leak panic.
265 @SYMTestCaseID SYSLIB-ECOM-CT-0762
266 @SYMTestCaseDesc Tests for proper listing of implementation of an interface UID
267 @SYMTestPriority High
268 @SYMTestActions Call to REComSession::FinalClose is omitted to show memory leak panic
269 @SYMTestExpectedResults The test must not fail.
272 TInt RFinalCloseTest::ListImpl_Without_FinalClose(TAny*)
277 CTrapCleanup* threadcleanup = CTrapCleanup::New();
278 TRAPD(err,ListImplementation_TestL());
281 //This FinalClose() is purposely omitted for testing the PANIC
282 //REComSession::FinalClose();
284 delete threadcleanup;
289 The test code for testing the implementation creation and deletion
290 where we create two different implementation using two different plugins
291 destroy them and call FinalClose() to show there is no problem and memory leak
293 @SYMTestCaseID SYSLIB-ECOM-CT-0763
294 @SYMTestCaseDesc Tests for proper creation and deletion of implementation using two different plugins
295 @SYMTestPriority High
296 @SYMTestActions Create the implementation with a call to REComSession::CreateImplementationL twice with different UIDs
297 Signal the destruction of an interface implementation to ECOM with a call to REComSession::DestroyedImplementation
298 Call up REComSession::FinalClose
299 @SYMTestExpectedResults The test must not fail.
302 void RFinalCloseTest::Create_Destroy2_With_FinalCloseL()
306 TUid implUid1={0x10009DC3};
307 TUid implUid2={0x101F847A};
310 // Set up some empty initialisation parameters
311 CExampleInterface::TExampleInterfaceInitParams initParams;
312 initParams.integer = 0;
313 initParams.descriptor = NULL;
315 //Creating implementation 1
316 CExampleInterface* impl1 = REINTERPRET_CAST(CExampleInterface*,
317 REComSession::CreateImplementationL(implUid1,dTorKey1,&initParams));
318 test(impl1->ImplId()==implUid1);
320 //Creating implementation 2
321 CExampleInterface* impl2 = REINTERPRET_CAST(CExampleInterface*,
322 REComSession::CreateImplementationL(implUid2,dTorKey2,&initParams));
323 test(impl2->ImplId()==implUid2);
325 //Destroy implementation 2
326 REComSession::DestroyedImplementation(dTorKey2);
331 //Now Destroy implementation 1
332 REComSession::DestroyedImplementation(dTorKey1);
337 REComSession::FinalClose();
344 The test code for testing that REComSession::FinalClose() can be called many times
345 without introducing any strange behaviour, memory leak and crash problem.
347 @SYMTestCaseID SYSLIB-ECOM-CT-0764
348 @SYMTestCaseDesc Tests to show that FinalClose() can be called many times with no unknown consequence.
349 @SYMTestPriority High
350 @SYMTestActions Create the implementation with some empty initialisation parameters
351 Call up REComSession::FinalClose twice before destroying the implementation and once after the deletion
352 Check for any strange behaviour, memory leak and crash problem.
353 @SYMTestExpectedResults The test must not fail.
356 void RFinalCloseTest::Create_Destroy3_With_FinalCloseL()
359 TUid implUid1={0x10009DC3};
361 // Set up some empty initialisation parameters
362 CExampleInterface::TExampleInterfaceInitParams initParams;
363 initParams.integer = 0;
364 initParams.descriptor = NULL;
366 //Creating implementation 1
367 CExampleInterface* impl1 = REINTERPRET_CAST(CExampleInterface*,
368 REComSession::CreateImplementationL(implUid1,dTorKey1,&initParams));
369 test(impl1->ImplId()==implUid1);
371 //Called FinalClose() twice
372 REComSession::FinalClose();
373 REComSession::FinalClose();
375 REComSession::DestroyedImplementation(dTorKey1);
378 REComSession::FinalClose();
384 The test code for testing the functionality of REComSession::FinalClose()
385 without introducing any strange behaviour,memory leak and crash problem
387 @SYMTestCaseID SYSLIB-ECOM-CT-0765
388 @SYMTestCaseDesc Tests for the REComSession::FinalClose() function
389 @SYMTestPriority High
390 @SYMTestActions Open and close single connection to the the ECom server.
391 Call FinalClose, to check for any strange behaviour,memory leak and crash problem
392 @SYMTestExpectedResults The test must not fail.
395 void RFinalCloseTest::Create_Destroy4_With_FinalCloseL()
397 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0765 "));
400 REComSession& ecomsession = ecomsession.OpenL();
404 REComSession::FinalClose();
409 The test code for testing the functionality of REComSession::FinalClose()
410 without introducing any strange behaviour,memory leak and crash problem
412 @SYMTestCaseID SYSLIB-ECOM-CT-0766
413 @SYMTestCaseDesc Tests for the REComSession::FinalClose() function
414 @SYMTestPriority High
415 @SYMTestActions Call FinalClose() function,to check for any memory leak and crash problem
416 @SYMTestExpectedResults The test must not fail.
419 void RFinalCloseTest::FinalClose()
421 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0766 "));
424 REComSession::FinalClose();
429 LOCAL_C void NonConstructL_Create_Destroy_helper()
431 REComSession session;
435 @SYMTestCaseID SYSLIB-ECOM-CT-0767
436 @SYMTestCaseDesc Tests for the REComSession::FinalClose() function
437 @SYMTestPriority High
438 @SYMTestActions Open and close connection to ECOM server
439 Check for any memory leak and crash problem
440 @SYMTestExpectedResults The test must not fail.
443 void RFinalCloseTest::NonConstructL_Create_Destroy()
448 ::NonConstructL_Create_Destroy_helper();
451 REComSession* ptr = new REComSession;
458 The test code is used for capturing the PANIC that occurs as a result of not
459 calling REComSession::FinalClose() when using ECOM plugins.
461 @SYMTestCaseID SYSLIB-ECOM-CT-0768
462 @SYMTestCaseDesc Tests for PANIC when REComSession::FinalClose() is called using ECOM plugins
463 @SYMTestPriority High
464 @SYMTestActions Check for memory leak panic
465 @SYMTestExpectedResults The test must not fail.
468 void RFinalCloseTest::ThreadPanicTest(const TDesC& aName,TThreadFunction aFunction)
470 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0768 "));
472 TRequestStatus threadStatus;
475 jit=User::JustInTime();
476 User::SetJustInTime(EFalse);
478 TInt err=thread.Create(aName,aFunction,KDefaultStackSize*8,KMinHeapSize,0x100000,0);
480 thread.Logon(threadStatus) ;
483 User::WaitForRequest(threadStatus);
485 //Now check why the thread Exit
487 test(thread.ExitType()==EExitPanic);
488 test(thread.ExitReason()==0);
489 //A memory leak will have the exit category of form ALLOC:xxxxxx
490 //test.Printf(_L("Exit xcat: %S"), thread.ExitCategory().Left(6));
491 test(thread.ExitCategory().Left(6).CompareF(_L("ALLOC:"))==0);
493 User::SetJustInTime(jit);
497 Copies the Plugins to specific folder for testing purpose
499 LOCAL_C void CopyPlugins()
501 // Copy the dlls and .rsc files on to RAM
502 TRAPD(err, EComTestUtils::FileManCopyFileL(KEComExDllOnZ, KEComExDllOnC));
505 TRAP(err, EComTestUtils::FileManCopyFileL(KEComRscFileOnZ, KEComRscFileOnC));
508 TRAP(err, EComTestUtils::FileManCopyFileL(KEComExampleDllOnZ, KEComExampleDllOnC));
510 TRAP(err, EComTestUtils::FileManCopyFileL(KEComExample2DllOnZ, KEComExample2DllOnC));
512 TRAP(err, EComTestUtils::FileManCopyFileL(KEComExample3DllOnZ, KEComExample3DllOnC));
515 TRAP(err, EComTestUtils::FileManCopyFileL(KEComExampleRscOnZ, KEComExampleRscOnC));
517 TRAP(err, EComTestUtils::FileManCopyFileL(KEComExample2RscOnZ, KEComExample2RscOnC));
519 TRAP(err, EComTestUtils::FileManCopyFileL(KEComExample3RscOnZ, KEComExample3RscOnC));
523 // Deleting plugin from the RAM for cleanup purpose
524 inline LOCAL_C void DeleteTestPlugin()
526 TRAPD(err, EComTestUtils::FileManDeleteFileL(KEComExDllOnC));
527 TRAP(err, EComTestUtils::FileManDeleteFileL(KEComRscFileOnC));
528 TRAP(err, EComTestUtils::FileManDeleteFileL(KEComExampleDllOnC));
529 TRAP(err, EComTestUtils::FileManDeleteFileL(KEComExample2DllOnC));
530 TRAP(err, EComTestUtils::FileManDeleteFileL(KEComExample3DllOnC));
531 TRAP(err, EComTestUtils::FileManDeleteFileL(KEComExampleRscOnC));
532 TRAP(err, EComTestUtils::FileManDeleteFileL(KEComExample2RscOnC));
533 TRAP(err, EComTestUtils::FileManDeleteFileL(KEComExample3RscOnC));
536 LOCAL_C void RunTestL()
540 test.Next(_L("FinalClose"));
541 RFinalCloseTest::FinalClose();
542 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0759 Create_Destroy_With_FinalCloseL "));
543 RFinalCloseTest::Create_Destroy_With_FinalCloseL();
544 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0761 ListImpl_With_FinalCloseL "));
545 RFinalCloseTest::ListImpl_With_FinalCloseL();
546 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0763 Create_Destroy2_With_FinalCloseL "));
547 RFinalCloseTest::Create_Destroy2_With_FinalCloseL();
548 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0764 Create_Destroy3_With_FinalCloseL "));
549 RFinalCloseTest::Create_Destroy3_With_FinalCloseL();
550 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0767 NonConstructL_Create_Destroy "));
551 RFinalCloseTest::NonConstructL_Create_Destroy();
553 //ECOM FinalClose() Panic Test
555 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0760 "));
556 RFinalCloseTest::ThreadPanicTest(_L("Create Destroy Panic Testing"),RFinalCloseTest::Create_Destroy_Without_FinalClose);
557 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0762 "));
558 RFinalCloseTest::ThreadPanicTest(_L("List Implementation Panic Testing"),RFinalCloseTest::ListImpl_Without_FinalClose);
564 GLDEF_C TInt E32Main()
569 test.Start(_L("Final Close tests."));
573 CTrapCleanup* cleanup = CTrapCleanup::New();
574 CActiveScheduler* scheduler = new(ELeave)CActiveScheduler;
575 CActiveScheduler::Install(scheduler);
577 TRAPD(err,RunTestL());
580 // Cleanup files. If the cleanup fails that is no problem,
581 // as any subsequent tests will replace them. The only downside
582 // would be the disk not being tidied