lowlevellibsandfws/pluginfw/Framework/NotificationTest/t_ecomcancel.cpp
changeset 0 e4d67989cc36
child 44 97b0fb8a2cc2
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2003-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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32test.h>
       
    17 #include <ecom/ecom.h>
       
    18 #include <f32file.h>
       
    19 #include <e32base.h>
       
    20 #include <bautils.h>
       
    21 #include <e32ldr.h>
       
    22 
       
    23 #include "../EcomTestUtils/EcomTestUtils.h"
       
    24 #include "HeapTestInterface.h"
       
    25 
       
    26 LOCAL_D RTest TheTest(_L("t_ecomcancel"));
       
    27 LOCAL_D RFs TheFs;
       
    28 
       
    29 const TInt KWaitDuration = 30000000; // retry delay in usecs
       
    30 
       
    31 _LIT(KHTI_PluginAtRootOfZ,  "z:\\HeapTestImpl.dll");
       
    32 _LIT(KHTI_PluginAtRootOfC,  "c:\\HeapTestImpl.dll");
       
    33 _LIT(KHTIr_PluginAtRootOfZ, "z:\\HeapTestImpl.rsc");
       
    34 _LIT(KHTIr_PluginAtRootOfC, "c:\\HeapTestImpl.rsc");
       
    35 _LIT(KHTI_PluginInstalledOnC,  "c:\\sys\\bin\\HeapTestImpl.dll");
       
    36 _LIT(KHTIr_PluginInstalledOnC, "c:\\resource\\plugins\\HeapTestImpl.rsc");
       
    37 
       
    38 _LIT(KExample5DllOnC, "C:\\sys\\bin\\EComExample5.dll");
       
    39 _LIT(KExample5DllOnZ, "z:\\RAMOnly\\EComExample5.dll");
       
    40 _LIT(KExample5RscOnC, "C:\\resource\\plugins\\EComExample5.rsc");
       
    41 _LIT(KExample5RscOnZ, "z:\\RAMOnly\\EComExample5.rsc");
       
    42 _LIT(KExample5TmpRscOnC, "C:\\resource\\plugins\\EComExample5tmp.rsc");
       
    43 
       
    44 void CleanupFiles()
       
    45 	{
       
    46 	TRAPD(ignoreErr, EComTestUtils::FileManDeleteFileL(KHTI_PluginInstalledOnC));
       
    47 	TRAP(ignoreErr, EComTestUtils::FileManDeleteFileL(KHTIr_PluginInstalledOnC));
       
    48 
       
    49 	TRAP(ignoreErr, EComTestUtils::FileManDeleteFileL(KExample5TmpRscOnC));
       
    50 	TRAP(ignoreErr, EComTestUtils::FileManDeleteFileL(KExample5RscOnC));
       
    51 	TRAP(ignoreErr, EComTestUtils::FileManDeleteFileL(KExample5DllOnC));
       
    52 
       
    53 	WAIT_FOR3s;
       
    54 	}
       
    55 
       
    56 //
       
    57 //
       
    58 //Test macroses and functions
       
    59 LOCAL_C void Check(TInt aValue, TInt aLine)
       
    60 	{
       
    61 	if(!aValue)
       
    62 		{
       
    63 		::CleanupFiles();
       
    64 		TheTest(EFalse, aLine);
       
    65 		}
       
    66 	}
       
    67 LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
       
    68 	{
       
    69 	if(aValue != aExpected)
       
    70 		{
       
    71 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
       
    72 		::CleanupFiles();
       
    73 		TheTest(EFalse, aLine);
       
    74 		}
       
    75 	}
       
    76 #define TEST(arg) ::Check((arg), __LINE__)
       
    77 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
       
    78 //
       
    79 //
       
    80 
       
    81 
       
    82 // Setup files for test
       
    83 void SetUpPlugins()
       
    84 	{
       
    85 
       
    86 	TInt err;
       
    87 	TRAP(err, EComTestUtils::FileManCopyFileL(KHTI_PluginAtRootOfZ, KHTI_PluginAtRootOfC));
       
    88 	TEST2(err, KErrNone);
       
    89 	TRAP(err, EComTestUtils::FileManCopyFileL(KHTIr_PluginAtRootOfZ, KHTIr_PluginAtRootOfC));
       
    90 	TEST2(err, KErrNone);
       
    91 	TRAP(err, EComTestUtils::FileManCopyFileL(KHTI_PluginAtRootOfZ, KHTI_PluginInstalledOnC));
       
    92 	TEST2(err, KErrNone);
       
    93 	TRAP(err, EComTestUtils::FileManCopyFileL(KHTIr_PluginAtRootOfZ, KHTIr_PluginInstalledOnC));
       
    94 	TEST2(err, KErrNone);
       
    95 	WAIT_FOR3s;
       
    96 
       
    97 	}
       
    98 
       
    99 // Copying plugin to the RAM for test purposes
       
   100 void CopyTestPlugin()
       
   101 	{
       
   102 	TRAPD(err, EComTestUtils::FileManCopyFileL(KExample5RscOnZ, KExample5RscOnC));
       
   103 	TEST2(err, KErrNone);
       
   104 	TRAP(err, EComTestUtils::FileManCopyFileL(KExample5DllOnZ, KExample5DllOnC));
       
   105 	TEST2(err, KErrNone);
       
   106 	WAIT_FOR3s;
       
   107 	}
       
   108 
       
   109 void ResetEComEnvironmentL()
       
   110 	{
       
   111     ECOMTU_KILL_SERVER_L(TheTest);
       
   112 	}
       
   113 
       
   114 
       
   115 /**
       
   116 @SYMTestCaseID          SYSLIB-ECOM-CT-0657
       
   117 @SYMTestCaseDesc	    De-Registering for notification of messages test
       
   118                         Test for REComSession class
       
   119 @SYMTestPriority 	    High
       
   120 @SYMTestActions  	    Test for no side effects on trying to cancel a request that has been already cancelled
       
   121 						Test for updation of right status value after cancel request.
       
   122 @SYMTestExpectedResults The test must not fail.
       
   123 @SYMREQ                 REQ0000
       
   124 */
       
   125 void TestCancelL()
       
   126 	{
       
   127 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0657 TestCancelL "));
       
   128 
       
   129     // Test normal cancelling
       
   130     REComSession& session = REComSession::OpenL();
       
   131     TRequestStatus status;
       
   132     session.NotifyOnChange(status);
       
   133     session.CancelNotifyOnChange(status);
       
   134     User::WaitForRequest(status);
       
   135     TEST(status == KErrCancel);
       
   136     session.Close();
       
   137 
       
   138 	// Test no side effects on trying to cancel a request
       
   139 	//  that has already been cancelled
       
   140     session = REComSession::OpenL();
       
   141     session.NotifyOnChange(status);
       
   142     session.CancelNotifyOnChange(status);
       
   143     User::WaitForRequest(status);
       
   144     TEST(status == KErrCancel);
       
   145     session.CancelNotifyOnChange(status);
       
   146     session.CancelNotifyOnChange(status);
       
   147     TEST(status == KErrCancel);
       
   148 
       
   149 	// Make sure the right status value is updated after a cancel request.
       
   150     TRequestStatus status1, status2, status3;
       
   151     session.NotifyOnChange(status);
       
   152     TEST(status==KRequestPending);
       
   153     session.NotifyOnChange(status1);
       
   154     TEST(status1==KRequestPending);
       
   155     session.NotifyOnChange(status2);
       
   156     TEST(status2==KRequestPending);
       
   157     session.NotifyOnChange(status3);
       
   158     TEST(status3==KRequestPending);
       
   159     session.CancelNotifyOnChange(status);
       
   160     User::WaitForRequest(status);
       
   161     TEST(status==KErrCancel);
       
   162     session.CancelNotifyOnChange(status3);
       
   163     session.CancelNotifyOnChange(status2);
       
   164     User::WaitForRequest(status3);
       
   165     TEST(status3==KErrCancel);
       
   166     User::WaitForRequest(status2);
       
   167     TEST(status2==KErrCancel);
       
   168     session.CancelNotifyOnChange(status1);
       
   169     User::WaitForRequest(status1);
       
   170     TEST(status1==KErrCancel);
       
   171    	session.Close();
       
   172 
       
   173 	// Test Ends...
       
   174 	REComSession::FinalClose();
       
   175 	}
       
   176 
       
   177 
       
   178 void SimulateDiskChangeL()
       
   179 	{
       
   180 	// Set up for heap leak checking
       
   181 	__UHEAP_MARK;
       
   182 
       
   183 	// Make sure the file is not read-only
       
   184 	TRAPD(err, EComTestUtils::MakeFileWriteableL(KHTI_PluginAtRootOfC));
       
   185 	TRAP(err, EComTestUtils::MakeFileWriteableL(KHTIr_PluginAtRootOfC));
       
   186 
       
   187 	// Simulate that the implementation dll is changed - change resouce file timestamp
       
   188 	RFile file;
       
   189 	User::LeaveIfError(file.Open(TheFs, KHTIr_PluginAtRootOfC, EFileRead | EFileWrite));
       
   190 	TTime time;
       
   191 	User::LeaveIfError(file.Modified(time));
       
   192 	TTimeIntervalSeconds interval = 100;
       
   193 	time += interval;
       
   194 	User::LeaveIfError(file.SetModified(time));
       
   195 	file.Close();
       
   196 
       
   197 	// Replace the resource file with the newer version (newer timestamp)
       
   198 	// The ECOM server will run the discovery process and will unload the old dll
       
   199 	// and replace it with the newer dll
       
   200 	TRAP(err, EComTestUtils::FileManCopyFileL(KHTI_PluginAtRootOfC, KHTI_PluginInstalledOnC));
       
   201 	TEST2(err, KErrNone);
       
   202 	TRAP(err, EComTestUtils::FileManCopyFileL(KHTIr_PluginAtRootOfC, KHTIr_PluginInstalledOnC));
       
   203 	TEST2(err, KErrNone);
       
   204 
       
   205 	WAIT_FOR3s; // wait for copy to complete
       
   206 
       
   207 	__UHEAP_MARKEND;
       
   208 	}
       
   209 
       
   210 // This test step no longer uses bafl to move files as it does not have high
       
   211 // enough capability - uses CFileMan helper process instead.
       
   212 void SimulatePluginDeleteBaflL()
       
   213 	{
       
   214 	// Set up for heap leak checking
       
   215 	__UHEAP_MARK;
       
   216 
       
   217 	// Make sure the file is not read-only
       
   218 	TRAPD(err, EComTestUtils::MakeFileWriteableL(KExample5DllOnC));
       
   219 	TRAP(err, EComTestUtils::MakeFileWriteableL(KExample5RscOnC));
       
   220 
       
   221 	// Delete the plugins
       
   222 	// The ECOM server will send the notification to its clients for change.
       
   223 	TRAPD(ignoreErr, EComTestUtils::FileManDeleteFileL(KExample5RscOnC));
       
   224 	TRAP(ignoreErr, EComTestUtils::FileManDeleteFileL(KExample5DllOnC));
       
   225 	WAIT_FOR3s;
       
   226 
       
   227 	__UHEAP_MARKEND;
       
   228 	}
       
   229 
       
   230 // This test step no longer uses bafl to move files as it does not have high
       
   231 // enough capability - uses CFileMan helper process instead.
       
   232 void SimulatePluginCopyBaflL()
       
   233 	{
       
   234 	// Set up for heap leak checking
       
   235 	__UHEAP_MARK;
       
   236 
       
   237 
       
   238 	// Make sure the file is not read-only
       
   239 	TRAPD(err, EComTestUtils::MakeFileWriteableL(KExample5DllOnC));
       
   240 	TRAP(err, EComTestUtils::MakeFileWriteableL(KExample5RscOnC));
       
   241 
       
   242 	// Copy the plugins.
       
   243 	// The ECOM server will send the notification to its clients for change.
       
   244 	TRAP(err, EComTestUtils::FileManCopyFileL(KExample5RscOnZ, KExample5RscOnC));
       
   245 	TEST2(err, KErrNone);
       
   246 	TRAP(err, EComTestUtils::FileManCopyFileL(KExample5DllOnZ, KExample5DllOnC));
       
   247 	TEST2(err, KErrNone);
       
   248 
       
   249 	WAIT_FOR5s; // wait for copy to complete
       
   250 
       
   251 	__UHEAP_MARKEND;
       
   252 	}
       
   253 
       
   254 void SimulatePluginDeleteFileManL()
       
   255 	{
       
   256 	// Set up for heap leak checking
       
   257 	__UHEAP_MARK;
       
   258 
       
   259 	// Make sure the file is read-only
       
   260 	TRAPD(err, EComTestUtils::MakeFileWriteableL(KExample5DllOnC));
       
   261 	TRAP(err, EComTestUtils::MakeFileWriteableL(KExample5RscOnC));
       
   262 
       
   263 
       
   264 	// Delete the plugins.
       
   265 	// The ECOM server will send the notification to its clients for change.
       
   266 	TRAP(err, EComTestUtils::FileManDeleteFileL(KExample5RscOnC));
       
   267 	TRAP(err, EComTestUtils::FileManDeleteFileL(KExample5DllOnC));
       
   268 
       
   269 	WAIT_FOR5s; // wait for copy to complete
       
   270 
       
   271 	__UHEAP_MARKEND;
       
   272 	}
       
   273 
       
   274 void SimulatePluginCopyFileManL()
       
   275 	{
       
   276 	// Set up for heap leak checking
       
   277 	__UHEAP_MARK;
       
   278 
       
   279 	// Make sure the file is not read-only
       
   280 	TRAPD(err, EComTestUtils::MakeFileWriteableL(KExample5DllOnC));
       
   281 	TRAP(err, EComTestUtils::MakeFileWriteableL(KExample5RscOnC));
       
   282 
       
   283 	// Copy the plugins.
       
   284 	// The ECOM server will send the notification to its clients for change.
       
   285 	TRAP(err, EComTestUtils::FileManCopyFileL(KExample5RscOnZ, KExample5RscOnC));
       
   286 	TEST2(err, KErrNone);
       
   287 	TRAP(err, EComTestUtils::FileManCopyFileL(KExample5DllOnZ, KExample5DllOnC));
       
   288 	TEST2(err, KErrNone);
       
   289 
       
   290 	WAIT_FOR5s; // wait for copy to complete
       
   291 
       
   292 	__UHEAP_MARKEND;
       
   293 	}
       
   294 
       
   295 void SimulatePluginDeleteRFsL()
       
   296 	{
       
   297 	// Set up for heap leak checking
       
   298 	__UHEAP_MARK;
       
   299 
       
   300 	// Make sure the file is read-only
       
   301 	TRAPD(err, EComTestUtils::MakeFileWriteableL(KExample5DllOnC));
       
   302 	TRAP(err, EComTestUtils::MakeFileWriteableL(KExample5RscOnC));
       
   303 
       
   304 	// Delete the plugins using RFs.
       
   305 	// The ECOM server will send the notification to its clients for change.
       
   306 	TRAP(err, EComTestUtils::RfsDeleteFileL(KExample5RscOnC));
       
   307 	TRAP(err, EComTestUtils::RfsDeleteFileL(KExample5DllOnC));
       
   308 
       
   309 	WAIT_FOR5s; // wait for copy to complete
       
   310 
       
   311 	__UHEAP_MARKEND;
       
   312 	}
       
   313 
       
   314 void SimulatePluginReplaceRFsL()
       
   315 	{
       
   316 	// Set up for heap leak checking
       
   317 	__UHEAP_MARK;
       
   318 
       
   319 	// Make sure the file is not read-only
       
   320 	TRAPD(err, EComTestUtils::MakeFileWriteableL(KExample5DllOnC));
       
   321 
       
   322 	// Replace the plugins using RFs.
       
   323 	// The ECOM server will send the notification to its clients for change.
       
   324 	TRAP(err, EComTestUtils::RfsReplaceFileL(KExample5RscOnC,KExample5TmpRscOnC));
       
   325 	TEST2(err, KErrNone);
       
   326 
       
   327 	WAIT_FOR5s; // wait for operation to complete
       
   328 
       
   329 	__UHEAP_MARKEND;
       
   330 	}
       
   331 
       
   332 
       
   333 /**
       
   334 @SYMTestCaseID          SYSLIB-ECOM-CT-0658
       
   335 @SYMTestCaseDesc	    Tests for REComSession::NotifyOnChange() function
       
   336 @SYMTestPriority 	    High
       
   337 @SYMTestActions  	    Tests for changing the implementation dll(timestamp change) and checks for the notify status
       
   338 @SYMTestExpectedResults The test must not fail.
       
   339 @SYMREQ                 REQ0000
       
   340 */
       
   341 void TestNotifyL()
       
   342 	{
       
   343 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0658 TestNotifyL "));
       
   344 
       
   345 	// Set up for heap leak checking
       
   346 	__UHEAP_MARK;
       
   347 
       
   348 	// and leaking thread handles
       
   349 	TInt startProcessHandleCount;
       
   350 	TInt startThreadHandleCount;
       
   351 	TInt endProcessHandleCount;
       
   352 	TInt endThreadHandleCount;
       
   353 
       
   354 	// Test Starts...
       
   355 	RThread thisThread;
       
   356 	thisThread.HandleCount(startProcessHandleCount, startThreadHandleCount);
       
   357 
       
   358 
       
   359 	//-----
       
   360     REComSession& ecomSession = REComSession::OpenL();
       
   361 	CleanupClosePushL(ecomSession);
       
   362 
       
   363 	RTimer timer;
       
   364 	CleanupClosePushL(timer);
       
   365 	User::LeaveIfError(timer.CreateLocal());
       
   366 
       
   367 	TRequestStatus timerStatus;
       
   368 	TRequestStatus notifyStatus;
       
   369 
       
   370 	// 1st disk change
       
   371 	// Issue the requests
       
   372 	timer.After(timerStatus, KWaitDuration);
       
   373 	ecomSession.NotifyOnChange(notifyStatus);
       
   374 
       
   375 	// simulate a disk change
       
   376 	SimulateDiskChangeL();
       
   377 
       
   378 	User::WaitForAnyRequest();
       
   379 
       
   380 	TEST(notifyStatus==KErrNone);
       
   381 	TEST(timerStatus==KRequestPending);
       
   382 
       
   383 	timer.Cancel();
       
   384 
       
   385 	// 2nd disk change
       
   386 	// Issue the requests
       
   387 	timer.After(timerStatus, KWaitDuration);
       
   388 	ecomSession.NotifyOnChange(notifyStatus);
       
   389 
       
   390 	// simulate a disk change
       
   391 	SimulateDiskChangeL();
       
   392 
       
   393 	User::WaitForAnyRequest();
       
   394 
       
   395 	TEST(notifyStatus==KErrNone);
       
   396 	TEST(timerStatus==KRequestPending);
       
   397 
       
   398 	timer.Cancel();
       
   399 
       
   400 	// 3rd disk change
       
   401 	// Issue the requests
       
   402 	timer.After(timerStatus, KWaitDuration);
       
   403 	ecomSession.NotifyOnChange(notifyStatus);
       
   404 
       
   405 	// simulate a disk change
       
   406 	SimulateDiskChangeL();
       
   407 
       
   408 	User::WaitForAnyRequest();
       
   409 
       
   410 	TEST(notifyStatus==KErrNone);
       
   411 	TEST(timerStatus==KRequestPending);
       
   412 
       
   413 	timer.Cancel();
       
   414 
       
   415 	// 4th disk change
       
   416 	// Issue the requests
       
   417 	timer.After(timerStatus, KWaitDuration);
       
   418 	ecomSession.NotifyOnChange(notifyStatus);
       
   419 
       
   420 	// simulate a disk change
       
   421 	SimulateDiskChangeL();
       
   422 
       
   423 	User::WaitForAnyRequest();
       
   424 
       
   425 	TEST(notifyStatus==KErrNone);
       
   426 	TEST(timerStatus==KRequestPending);
       
   427 
       
   428 	timer.Cancel();
       
   429 
       
   430 	// 5th disk change
       
   431 	// Issue the requests
       
   432 	timer.After(timerStatus, KWaitDuration);
       
   433 	ecomSession.NotifyOnChange(notifyStatus);
       
   434 
       
   435 	// simulate a disk change
       
   436 	SimulateDiskChangeL();
       
   437 
       
   438 	User::WaitForAnyRequest();
       
   439 
       
   440 	TEST(notifyStatus==KErrNone);
       
   441 	TEST(timerStatus==KRequestPending);
       
   442 
       
   443 	timer.Cancel();
       
   444 
       
   445 	// 6th disk change
       
   446 	// Issue the requests
       
   447 	timer.After(timerStatus, KWaitDuration);
       
   448 	ecomSession.NotifyOnChange(notifyStatus);
       
   449 
       
   450 	// simulate a disk change
       
   451 	SimulateDiskChangeL();
       
   452 
       
   453 	User::WaitForAnyRequest();
       
   454 
       
   455 	TEST(notifyStatus==KErrNone);
       
   456 	TEST(timerStatus==KRequestPending);
       
   457 
       
   458 	timer.Cancel();
       
   459 
       
   460 	// 7th disk change
       
   461 	// Issue the requests
       
   462 	timer.After(timerStatus, KWaitDuration);
       
   463 	ecomSession.NotifyOnChange(notifyStatus);
       
   464 
       
   465 	// simulate a disk change
       
   466 	SimulateDiskChangeL();
       
   467 
       
   468 	User::WaitForAnyRequest();
       
   469 
       
   470 	TEST(notifyStatus==KErrNone);
       
   471 	TEST(timerStatus==KRequestPending);
       
   472 
       
   473 	timer.Cancel();
       
   474 
       
   475 	// 8th disk change
       
   476 	// Issue the requests
       
   477 	timer.After(timerStatus, KWaitDuration);
       
   478 	ecomSession.NotifyOnChange(notifyStatus);
       
   479 
       
   480 	// simulate a disk change
       
   481 	SimulateDiskChangeL();
       
   482 
       
   483 	User::WaitForAnyRequest();
       
   484 
       
   485 	TEST(notifyStatus==KErrNone);
       
   486 	TEST(timerStatus==KRequestPending);
       
   487 
       
   488 	timer.Cancel();
       
   489 
       
   490 	// 9th disk change
       
   491 	// Issue the requests
       
   492 	timer.After(timerStatus, KWaitDuration);
       
   493 	ecomSession.NotifyOnChange(notifyStatus);
       
   494 
       
   495 	// simulate a disk change
       
   496 	SimulateDiskChangeL();
       
   497 
       
   498 	User::WaitForAnyRequest();
       
   499 
       
   500 	TEST(notifyStatus==KErrNone);
       
   501 	TEST(timerStatus==KRequestPending);
       
   502 
       
   503 	timer.Cancel();
       
   504 
       
   505 	// 10th disk change
       
   506 	// Issue the requests
       
   507 	timer.After(timerStatus, KWaitDuration);
       
   508 	ecomSession.NotifyOnChange(notifyStatus);
       
   509 
       
   510 	// simulate a disk change
       
   511 	SimulateDiskChangeL();
       
   512 
       
   513 	User::WaitForAnyRequest();
       
   514 
       
   515 	TEST(notifyStatus==KErrNone);
       
   516 	TEST(timerStatus==KRequestPending);
       
   517 
       
   518 	timer.Cancel();
       
   519 
       
   520 	// 11th disk change
       
   521 	// Issue the requests
       
   522 	timer.After(timerStatus, KWaitDuration);
       
   523 	ecomSession.NotifyOnChange(notifyStatus);
       
   524 
       
   525 	// simulate a disk change
       
   526 	SimulatePluginDeleteBaflL();
       
   527 
       
   528 	User::WaitForAnyRequest();
       
   529 
       
   530 	TEST(notifyStatus==KErrNone);
       
   531 	TEST(timerStatus==KRequestPending);
       
   532 
       
   533 	timer.Cancel();
       
   534 
       
   535 	//Copy back the deleted plugin for the next test
       
   536 	CopyTestPlugin();
       
   537 
       
   538 	// 12th disk change
       
   539 	// Issue the requests
       
   540 	timer.After(timerStatus, KWaitDuration);
       
   541 	ecomSession.NotifyOnChange(notifyStatus);
       
   542 
       
   543 	// simulate a disk change, but no regigstry data changed
       
   544 	SimulatePluginCopyBaflL();
       
   545 
       
   546 	User::WaitForAnyRequest();
       
   547 
       
   548 	//since the file copied is same as before, no notify will be send
       
   549 	TEST(notifyStatus==KRequestPending);
       
   550 	TEST(timerStatus==KRequestPending);
       
   551 
       
   552 	timer.Cancel();
       
   553 
       
   554 
       
   555 	// 13th disk change
       
   556 	// Issue the requests
       
   557 	timer.After(timerStatus, KWaitDuration);
       
   558 	ecomSession.NotifyOnChange(notifyStatus);
       
   559 
       
   560 	// simulate a disk change
       
   561 	SimulatePluginDeleteFileManL();
       
   562 
       
   563 	User::WaitForAnyRequest();
       
   564 
       
   565 	TEST(notifyStatus==KErrNone);
       
   566 	TEST(timerStatus==KRequestPending);
       
   567 
       
   568 	timer.Cancel();
       
   569 
       
   570 	//Copy back the deleted plugin for the next test
       
   571 	CopyTestPlugin();
       
   572 
       
   573 	// 14th disk change
       
   574 	// Issue the requests
       
   575 	timer.After(timerStatus, KWaitDuration);
       
   576 	ecomSession.NotifyOnChange(notifyStatus);
       
   577 
       
   578 	// simulate a disk change
       
   579 	SimulatePluginCopyFileManL();
       
   580 
       
   581 	User::WaitForAnyRequest();
       
   582 
       
   583 	//since the file copied is same as before, no notify will be send
       
   584 	TEST(notifyStatus==KRequestPending);
       
   585 	TEST(timerStatus==KRequestPending);
       
   586 
       
   587 	timer.Cancel();
       
   588 
       
   589 
       
   590 	// 15th disk change
       
   591 	// Issue the requests
       
   592 	timer.After(timerStatus, KWaitDuration);
       
   593 	ecomSession.NotifyOnChange(notifyStatus);
       
   594 
       
   595 	// simulate a disk change
       
   596 	SimulatePluginDeleteRFsL();
       
   597 
       
   598 	User::WaitForAnyRequest();
       
   599 
       
   600 	TEST(notifyStatus==KErrNone);
       
   601 	TEST(timerStatus==KRequestPending);
       
   602 
       
   603 	timer.Cancel();
       
   604 
       
   605 	//Copy back the deleted plugin for the next test
       
   606 	CopyTestPlugin();
       
   607 
       
   608 	// 16th disk change
       
   609 	// Issue the requests
       
   610 	timer.After(timerStatus, KWaitDuration);
       
   611 	ecomSession.NotifyOnChange(notifyStatus);
       
   612 
       
   613 	// simulate a disk change
       
   614 	SimulatePluginReplaceRFsL();
       
   615 
       
   616 	User::WaitForAnyRequest();
       
   617 
       
   618 	TEST(notifyStatus==KErrNone);
       
   619 	TEST(timerStatus==KRequestPending);
       
   620 
       
   621 	timer.Cancel();
       
   622 
       
   623 	//Replace back the deleted plugin.
       
   624 	TRAPD(err, EComTestUtils::FileManCopyFileL(KExample5TmpRscOnC, KExample5RscOnC));
       
   625 	TEST2(err, KErrNone);
       
   626 
       
   627 	CleanupStack::PopAndDestroy(&timer);
       
   628 	CleanupStack::PopAndDestroy(&ecomSession);
       
   629 	//-----
       
   630 
       
   631 	// Test Ends...
       
   632 	REComSession::FinalClose();
       
   633 
       
   634 	// Check for open handles
       
   635 	thisThread.HandleCount(endProcessHandleCount, endThreadHandleCount);
       
   636 	TEST(startThreadHandleCount == endThreadHandleCount);
       
   637 
       
   638 	__UHEAP_MARKEND;
       
   639 
       
   640 	}
       
   641 
       
   642 /**
       
   643 @SYMTestCaseID          SYSLIB-ECOM-CT-1808
       
   644 @SYMTestCaseDesc	    Tests the uninstallation of an active plugin
       
   645 @SYMTestPriority 	    High
       
   646 @SYMTestActions  	    Creates a plugin implementation and then uninstalls the
       
   647                         plugin's files from the C: Drive and waits for an ECOM
       
   648                         notification completion, upon which it deletes the
       
   649                         plugin.
       
   650 @SYMTestExpectedResults The test must not fail.
       
   651 @SYMREQ                 REQ0000
       
   652 */
       
   653 void TestUninstallL()
       
   654 	{
       
   655 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1808 TestUninstallL "));
       
   656 
       
   657 	// Set up for heap leak checking and leaking thread handles
       
   658 	__UHEAP_MARK;
       
   659 	TInt startProcessHandleCount;
       
   660 	TInt startThreadHandleCount;
       
   661 	TInt endProcessHandleCount;
       
   662 	TInt endThreadHandleCount;
       
   663 	RThread thisThread;
       
   664 	thisThread.HandleCount(startProcessHandleCount, startThreadHandleCount);
       
   665 
       
   666     // Step 1: Setup the session to ECOM
       
   667     TInt err = KErrNone;
       
   668     REComSession& ecomSession = REComSession::OpenL();
       
   669 	CleanupClosePushL(ecomSession);
       
   670 
       
   671     // Step 2: Register for ECOM Server notification.
       
   672 	TRequestStatus notifyStatus;
       
   673     ecomSession.NotifyOnChange(notifyStatus);
       
   674 	TEST2(notifyStatus.Int(), KRequestPending);
       
   675 
       
   676     // Step 3. Create the plugin implementation we will uninstall
       
   677     TheTest.Printf(_L("CHeapTestInterface::NewL()\n"));
       
   678     CHeapTestInterface* implPtr = 0;
       
   679     TRAP(err, implPtr = CHeapTestInterface::NewL());
       
   680 	TEST2(err, KErrNone);
       
   681 
       
   682     // Step 4. Simulate the uninstall of the plugin files
       
   683     TheTest.Printf(_L("Deleting HTI plugin - attempt 1, wait 5s...\n"));
       
   684   	//TRAP(err, EComTestUtils::FileManDeleteFileL(KHTI_PluginInstalledOnC));
       
   685   	TRAP(err, EComTestUtils::RLoaderDeleteFileL(KHTI_PluginInstalledOnC));
       
   686 #if defined(__WINS__) || defined (__WINSCW__)
       
   687    	TEST2(err, KErrAccessDenied); // DLL File locked under Windows emulator due to it being demand paged
       
   688    	TheTest.Printf(_L("Error -21 (KErrAccessDenied) expected due to Windows keeping the DLL mapped in the emulator process adress space due to Windows demand paging/virtual memory system\n"));
       
   689 #elif defined(__EPOC32__)
       
   690    	TEST2(err, KErrNone); // DLL File not locked on target hardware under SOS
       
   691 //#else Do no test at all as its an unexpected platform.
       
   692 #endif
       
   693 
       
   694  	TRAP(err, EComTestUtils::FileManDeleteFileL(KHTIr_PluginInstalledOnC));
       
   695    	TEST2(err, KErrNone);
       
   696 
       
   697     // Step 5. Wait for ECOM Server notification to arrive, with precautionary hang timer.
       
   698 	RTimer timer;
       
   699 	CleanupClosePushL(timer);
       
   700 	User::LeaveIfError(timer.CreateLocal());
       
   701 	TRequestStatus timerStatus;
       
   702 	timer.After(timerStatus, KWaitDuration);
       
   703 	TEST2(timerStatus.Int(), KRequestPending);
       
   704 
       
   705     TheTest.Printf(_L("Before calling WaitForAnyRequest(): Timer Status: %d; ECOM Notif Status: %d\n"), timerStatus.Int(), notifyStatus.Int());
       
   706     TheTest.Printf(_L("Checking notification recieved for ECOM Server...\n"));
       
   707     User::WaitForRequest(timerStatus, notifyStatus);
       
   708 
       
   709 	TEST2(timerStatus.Int(), KRequestPending);
       
   710 	TEST2(notifyStatus.Int(), KErrNone);
       
   711 	timer.Cancel();
       
   712 
       
   713     // Step 6. Destroy the plugin
       
   714     TheTest.Printf(_L("DELETE implPtr\n"));
       
   715     delete implPtr;
       
   716 
       
   717 
       
   718 	//CleanupStack::PopAndDestroy(&timer);
       
   719     TheTest.Printf(_L("Test over, cleanup...\n"));
       
   720    	CleanupStack::PopAndDestroy(&timer);
       
   721 	CleanupStack::PopAndDestroy(&ecomSession);
       
   722 	REComSession::FinalClose();
       
   723 
       
   724 	// Check for open handles
       
   725 	thisThread.HandleCount(endProcessHandleCount, endThreadHandleCount);
       
   726 	TEST(startThreadHandleCount == endThreadHandleCount);
       
   727 
       
   728 	// Test Ends...
       
   729 	__UHEAP_MARKEND;
       
   730 
       
   731 	}
       
   732 
       
   733 void DoTestsL()
       
   734 	{
       
   735 	TestNotifyL();
       
   736 	TestCancelL();
       
   737     TestUninstallL();
       
   738 	}
       
   739 
       
   740 GLDEF_C TInt E32Main()
       
   741 	{
       
   742 	__UHEAP_MARK;
       
   743 	TheTest.Title();
       
   744 	TheTest.Start(_L("Starting tests..."));
       
   745 	TInt err = KErrNone;
       
   746 
       
   747 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   748 	CActiveScheduler* scheduler = new(ELeave)CActiveScheduler;
       
   749 	CActiveScheduler::Install(scheduler);
       
   750 	TheFs.Connect();
       
   751 
       
   752     // Reset the test environment under textshell in emulator/ROM
       
   753 	TRAP(err, ResetEComEnvironmentL());
       
   754 	TEST2(err, KErrNone);
       
   755 
       
   756 	// Initial setup, runtests, cleanup
       
   757 	SetUpPlugins();
       
   758 	CopyTestPlugin();
       
   759 	TRAP(err,DoTestsL());
       
   760 	TEST2(err, KErrNone);
       
   761 	CleanupFiles();
       
   762 
       
   763     // Reset the environment for next test executable
       
   764 	TRAP(err, ResetEComEnvironmentL());
       
   765 	TEST2(err, KErrNone);
       
   766 
       
   767 	TheFs.Close();
       
   768 	delete scheduler;
       
   769 	delete cleanup;
       
   770 	TheTest.End();
       
   771 	TheTest.Close();
       
   772 
       
   773 	__UHEAP_MARKEND;
       
   774 	return(0);
       
   775 	}