lowlevellibsandfws/pluginfw/Framework/SimpleTests/t_ecomswi.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2007-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 <e32panic.h>
       
    18 #include <f32file.h>
       
    19 #include <bautils.h>
       
    20 #include <swi/swispubsubdefs.h>
       
    21 
       
    22 #include <ecom/ecom.h>
       
    23 #include "EComUidCodes.h"
       
    24 #include "Interface.h" // interface to Plugins
       
    25 //Test utils for copying the resolver to C
       
    26 #include "../EcomTestUtils/EcomTestUtils.h"
       
    27 #include "../EcomTestUtils/TPropertyManager.h"
       
    28 
       
    29 using namespace Swi;
       
    30 
       
    31 REComSession EComSess;
       
    32 
       
    33 LOCAL_D RTest TEST(_L("ECom SWI Test"));
       
    34 
       
    35 _LIT(KEComExDllOnZ,		"Z:\\ramonly\\EComSwiExample.dll");
       
    36 _LIT(KEComExDllOnC,		"C:\\sys\\bin\\EComSwiExample.dll");
       
    37 _LIT(KEComRscFileOnC,	"C:\\resource\\plugins\\EComSwiExample.rsc");
       
    38 _LIT(KEComRscFileOnZ,	"Z:\\ramonly\\EComSwiExample.rsc");
       
    39 _LIT(KEComRscPath,		"C:\\resource\\plugins\\");
       
    40 
       
    41 const TInt KWaitDuration = 5000000; //  delay in usecs
       
    42 
       
    43 #define UNUSED_VAR(a) a = a
       
    44 inline LOCAL_C TInt DeleteTestPlugin()
       
    45 	{
       
    46 	TRAPD(err, EComTestUtils::FileManDeleteFileL(KEComExDllOnC));
       
    47 	if((err == KErrNone)||(err == KErrNotFound))
       
    48 		{
       
    49 		TRAP(err, EComTestUtils::FileManDeleteFileL(KEComRscFileOnC));
       
    50 		}
       
    51 	if(err == KErrNotFound)
       
    52 		{
       
    53 		err = KErrNone;
       
    54 		}
       
    55 	return err;
       
    56 	}
       
    57 
       
    58 LOCAL_C TInt DeletePluginFolder()
       
    59 	{
       
    60 	TRAPD(err, EComTestUtils::FileManDeleteDirL(KEComRscPath));
       
    61 	User::After(1000000);
       
    62 	return err;
       
    63 	}
       
    64 /**
       
    65 Copies the Resolver Plugins to C:\ drive
       
    66 */
       
    67 LOCAL_C TInt CopyPluginsL()
       
    68     {
       
    69 	// Copy the dlls and .rsc files on to RAM
       
    70 	TRAPD(err, EComTestUtils::FileManCopyFileL(KEComExDllOnZ, KEComExDllOnC));
       
    71  	TEST(err==KErrNone, __LINE__);
       
    72  	TRAP(err, EComTestUtils::FileManCopyFileL(KEComRscFileOnZ, KEComRscFileOnC));
       
    73  	TEST(err==KErrNone, __LINE__);
       
    74  	User::After(1000000);
       
    75  	return err;
       
    76 	}
       
    77 
       
    78 LOCAL_C void RegisterForNotificationL(TRequestStatus& aNotifyStatus)
       
    79 	{
       
    80     REComSession& ecomSession = REComSession::OpenL();
       
    81 	CleanupClosePushL(ecomSession);
       
    82 
       
    83 	ecomSession.NotifyOnChange(aNotifyStatus);
       
    84 	TEST.Printf(_L("Request notification on ECom registration data change\n"));
       
    85 	TInt result = aNotifyStatus.Int();
       
    86 	TEST(result == KRequestPending);
       
    87 
       
    88 	ecomSession.Close();
       
    89 	CleanupStack::PopAndDestroy();
       
    90 	}
       
    91 
       
    92 LOCAL_C void WaitForNotificationL(TBool aExpected, TRequestStatus& aNotifyStatus)
       
    93 	{
       
    94     //Wait for ECOM Server notification to arrive with timeout
       
    95 	RTimer timer;
       
    96 	CleanupClosePushL(timer);
       
    97 	User::LeaveIfError(timer.CreateLocal());
       
    98 	TRequestStatus timerStatus;
       
    99 
       
   100 	//Wait for ECom notification
       
   101 	timer.After(timerStatus, KWaitDuration);
       
   102 	TEST(timerStatus.Int() == KRequestPending);
       
   103 
       
   104     TEST.Printf(_L("Waiting for notification from ECOM Server...\n"));
       
   105     User::WaitForRequest(timerStatus, aNotifyStatus);
       
   106 
       
   107     if(aExpected)
       
   108     	{
       
   109 	    //Verify that we recieved notification from ECom
       
   110 		TEST(timerStatus.Int() == KRequestPending);
       
   111 		TEST(aNotifyStatus.Int() == KErrNone);
       
   112     	}
       
   113     else
       
   114     	{
       
   115 	    //Verify that we have not recieved notification from ECom
       
   116 		TEST(timerStatus.Int() == KErrNone);
       
   117 		TEST(aNotifyStatus.Int() == KRequestPending);
       
   118     	}
       
   119 	timer.Cancel();
       
   120 
       
   121 	CleanupStack::PopAndDestroy();
       
   122 	}
       
   123 
       
   124 LOCAL_C void FindImplementationsL(TInt aExpected)
       
   125 	{
       
   126     REComSession& ecomSession = REComSession::OpenL();
       
   127 	CleanupClosePushL(ecomSession);
       
   128 
       
   129 	//Get a list of available implementations
       
   130 	TUid interfaceUid={0x10009DD9};
       
   131 	RImplInfoPtrArray ifArray;
       
   132 
       
   133 	ecomSession.ListImplementationsL(interfaceUid,ifArray);
       
   134 
       
   135 	//Verify that the expected number of implementations were found
       
   136 	TInt count = ifArray.Count();
       
   137 	TEST(count == aExpected);
       
   138 
       
   139 	TEST.Printf(_L("%d Implementations found...\n"),count);
       
   140 
       
   141 	//cleanup
       
   142 	ifArray.ResetAndDestroy();
       
   143 	ecomSession.Close();
       
   144 	CleanupStack::PopAndDestroy();
       
   145 	}
       
   146 
       
   147 /**
       
   148 @SYMTestCaseID          SYSLIB-ECOM-CT-3602
       
   149 @SYMTestCaseDesc		Tests notification processing when SWI does not exist
       
   150 						DEF108840: Undesireable interaction between ECOM and SWI
       
   151 @SYMTestActions  	    Request notifcation of ECom registry change
       
   152 						Copy plugin to c:\ and check that notification is recieved
       
   153 
       
   154 @SYMTestExpectedResults Notification should be recieved as normal if SWI is not present
       
   155 @SYMDEF                 DEF108840
       
   156 */
       
   157 LOCAL_C void DoSWITest1L()
       
   158 	{
       
   159 
       
   160 	TRequestStatus notifyStatus;
       
   161 	RegisterForNotificationL(notifyStatus);
       
   162 
       
   163 	FindImplementationsL(0);
       
   164 
       
   165 	//Copy plugin file to c:
       
   166 	TEST.Printf(_L("Copy Plugin Files...\n"));
       
   167 	CopyPluginsL();
       
   168 
       
   169 	WaitForNotificationL(ETrue,notifyStatus);
       
   170 
       
   171 	FindImplementationsL(1);
       
   172 
       
   173 	}
       
   174 
       
   175 /**
       
   176 @SYMTestCaseID          SYSLIB-ECOM-CT-3547
       
   177 @SYMTestCaseDesc	    Tests notification processing during SWI for
       
   178 						DEF108840: Undesireable interaction between ECOM and SWI
       
   179 @SYMTestActions  	    Set P&S variable to indicate SWI in progress.
       
   180 						Request notifcation of ECom registry change
       
   181 						Copy plugin to c:\ and check that notification is not recieved
       
   182 						Clear P&S variable to indicate SWI completion and verify that notification is recieved.
       
   183 @SYMTestExpectedResults Notification should not be recieved while SWI is in progress, but should be
       
   184 						recieved when SWI completes
       
   185 @SYMDEF                 DEF108840
       
   186 */
       
   187 LOCAL_C void DoSWITest2L()
       
   188 	{
       
   189 	//Set SWI as running
       
   190 	TInt r = PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue,ESASwisInstall);
       
   191 	TEST.Printf(_L("SWI Started\n"));
       
   192 
       
   193 	TRequestStatus notifyStatus;
       
   194 	RegisterForNotificationL(notifyStatus);
       
   195 
       
   196 	FindImplementationsL(0);
       
   197 
       
   198 	//Copy plugin file to c:
       
   199 	TEST.Printf(_L("Copy Plugin Files...\n"));
       
   200 	CopyPluginsL();
       
   201 
       
   202     //Verify that the wait timed out - we didn't recieve notification
       
   203 	WaitForNotificationL(EFalse,notifyStatus);
       
   204 
       
   205 	FindImplementationsL(0);
       
   206 
       
   207 	//Set SWI as complete
       
   208 	r = PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue,ESASwisNone);
       
   209 	TEST.Printf(_L("SWI Complete\n"));
       
   210 
       
   211 	WaitForNotificationL(ETrue,notifyStatus);
       
   212 
       
   213 	FindImplementationsL(1);
       
   214 
       
   215 	}
       
   216 
       
   217 /**
       
   218 @SYMTestCaseID          SYSLIB-ECOM-CT-3668
       
   219 @SYMTestCaseDesc	    Tests notification processing during SWI for
       
   220 						INC110470 ECOM does not notify when plug-ins get uninstalled
       
   221 @SYMTestActions  	    Uses P&S variables to simulate SWI install and uninstall
       
   222 						Request notification of ECom registry change
       
   223 						Verify that notifications are recieved after both install and uninstall
       
   224 @SYMTestExpectedResults Notification should be recieved after both SWI install and uninstall
       
   225 @SYMDEF                 INC110470
       
   226 */
       
   227 LOCAL_C void DoSWITest3L()
       
   228 	{
       
   229 
       
   230 	TRequestStatus notifyStatus;
       
   231 	RegisterForNotificationL(notifyStatus);
       
   232 
       
   233 	FindImplementationsL(0);
       
   234 
       
   235 	//Set SWI as running
       
   236 	TInt r = PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue,ESASwisInstall);
       
   237 	TEST.Printf(_L("SWI Started\n"));
       
   238 
       
   239 	//Copy plugin file to c:
       
   240 	TEST.Printf(_L("Copy Plugin Files...\n"));
       
   241 	CopyPluginsL();
       
   242 
       
   243 	//Set SWI as complete
       
   244 	r = PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue,ESASwisNone);
       
   245 	TEST.Printf(_L("SWI Complete\n"));
       
   246 
       
   247 	WaitForNotificationL(ETrue,notifyStatus);
       
   248 
       
   249 	FindImplementationsL(1);
       
   250 
       
   251 	RegisterForNotificationL(notifyStatus);
       
   252 
       
   253 	//Set SWI as running
       
   254 	r = PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue,ESASwisUninstall);
       
   255 	TEST.Printf(_L("SWI Started\n"));
       
   256 
       
   257 	//delete files from c:
       
   258 	TEST.Printf(_L("Delete Plugin Files...\n"));
       
   259 	DeleteTestPlugin();
       
   260 
       
   261 	//Delete plugin folder so that drive is unmounted by ECom
       
   262 	DeletePluginFolder();
       
   263 
       
   264 	//Set SWI as complete
       
   265 	r = PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue,ESASwisNone);
       
   266 	TEST.Printf(_L("SWI Complete\n"));
       
   267 
       
   268 	WaitForNotificationL(ETrue,notifyStatus);
       
   269 
       
   270 	FindImplementationsL(0);
       
   271 
       
   272 	RegisterForNotificationL(notifyStatus);
       
   273 
       
   274 	//Set SWI as running
       
   275 	r = PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue,ESASwisInstall);
       
   276 	TEST.Printf(_L("SWI Started\n"));
       
   277 
       
   278 	//Copy plugin file to c:
       
   279 	TEST.Printf(_L("Copy Plugin Files...\n"));
       
   280 	CopyPluginsL();
       
   281 
       
   282 	//Set SWI as complete
       
   283 	r = PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue,ESASwisNone);
       
   284 	TEST.Printf(_L("SWI Complete\n"));
       
   285 
       
   286 	WaitForNotificationL(ETrue,notifyStatus);
       
   287 
       
   288 	FindImplementationsL(1);
       
   289 	}
       
   290 
       
   291 /**
       
   292 @SYMTestCaseID          SYSLIB-ECOM-CT-3669
       
   293 @SYMTestCaseDesc	    Tests robustness of notification processing during SWI
       
   294 @SYMTestActions  	    Uses P&S variables to simulate SWI install and uninstall
       
   295 						Request notification of ECom registry change
       
   296 						Verify that notifications are recieved after both install and uninstall even
       
   297 						if a SWI scan is pending when SWI begins
       
   298 @SYMTestExpectedResults Notification should be recieved after both SWI install and uninstall
       
   299 @SYMDEF                 INC110470
       
   300 */
       
   301 LOCAL_C void DoSWITest4L()
       
   302 	{
       
   303 
       
   304 	TRequestStatus notifyStatus;
       
   305 	RegisterForNotificationL(notifyStatus);
       
   306 
       
   307 	//Set SWI as complete
       
   308 	PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue,ESASwisNone);
       
   309 	TEST.Printf(_L("SWI Complete\n"));
       
   310 
       
   311 	FindImplementationsL(0);
       
   312 
       
   313 	//Set SWI as running
       
   314 	TInt r = PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue,ESASwisInstall);
       
   315 	TEST.Printf(_L("SWI Started\n"));
       
   316 
       
   317 	//Copy plugin file to c:
       
   318 	TEST.Printf(_L("Copy Plugin Files...\n"));
       
   319 	CopyPluginsL();
       
   320 
       
   321 	//Set SWI as complete
       
   322 	r = PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue,ESASwisNone);
       
   323 	TEST.Printf(_L("SWI Complete\n"));
       
   324 
       
   325 	WaitForNotificationL(ETrue,notifyStatus);
       
   326 
       
   327 	FindImplementationsL(1);
       
   328 
       
   329 	RegisterForNotificationL(notifyStatus);
       
   330 
       
   331 	//Set SWI as running
       
   332 	r = PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue,ESASwisUninstall);
       
   333 	TEST.Printf(_L("SWI Started\n"));
       
   334 
       
   335 	//Delete plugin files
       
   336 	TEST.Printf(_L("Delete Plugin Files...\n"));
       
   337 	DeleteTestPlugin();
       
   338 
       
   339 	//Set SWI as complete
       
   340 	r = PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue,ESASwisNone);
       
   341 	TEST.Printf(_L("SWI Complete\n"));
       
   342 
       
   343 	//Wait again for ECom notification
       
   344 	WaitForNotificationL(ETrue,notifyStatus);
       
   345 
       
   346 	FindImplementationsL(0);
       
   347 	}
       
   348 
       
   349 LOCAL_C TInt SetupTest()
       
   350 	{
       
   351 	//Ensure plugin files are not on C:
       
   352 	TInt res = DeleteTestPlugin();
       
   353 	TEST.Printf(_L("Deleting test plugin...\n"));
       
   354 
       
   355 	//Wait to ensure files are deleted
       
   356 	User::After(2000000);
       
   357 
       
   358 	//Create an ECom session to ensure ECom is up and running
       
   359 	EComSess = REComSession::OpenL();
       
   360 
       
   361 	//Wait to ensure ECom startup has occurred
       
   362 	User::After(2000000);
       
   363 
       
   364 	return res;
       
   365 	}
       
   366 
       
   367 LOCAL_C void RunTestL()
       
   368 	{
       
   369 	__UHEAP_MARK;
       
   370 
       
   371 	TInt res = SetupTest();
       
   372 	TEST(res == KErrNone);
       
   373 
       
   374 	res = PropertyManager::DeleteProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue);
       
   375 	TEST(res == KErrNone);
       
   376 
       
   377 	//Run the test
       
   378 	TEST.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-3602 ECom SWI Test - SWI Not Present "));
       
   379 	DoSWITest1L();
       
   380 
       
   381 	//Cleanup
       
   382 	EComSess.Close();
       
   383 
       
   384 	res = SetupTest();
       
   385 	TEST(res == KErrNone);
       
   386 
       
   387 	res = PropertyManager::DefineProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue,RProperty::EInt);
       
   388 	TEST(res == KErrNone);
       
   389 
       
   390 	TEST.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-3547 ECom SWI Test - SWI Present "));
       
   391 	DoSWITest2L();
       
   392 
       
   393 	//Cleanup
       
   394 	EComSess.Close();
       
   395 
       
   396 	res = SetupTest();
       
   397 	TEST(res == KErrNone);
       
   398 
       
   399 	TEST.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-3668 ECom SWI Uninstall Test - SWI Present "));
       
   400 	DoSWITest3L();
       
   401 
       
   402 	//Cleanup
       
   403 	EComSess.Close();
       
   404 
       
   405 	res = SetupTest();
       
   406 	TEST(res == KErrNone);
       
   407 
       
   408 	TEST.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-3669 ECom SWI Robustness Test "));
       
   409 	DoSWITest4L();
       
   410 
       
   411 	res = PropertyManager::DeleteProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue);
       
   412 	TEST(res == KErrNone);
       
   413 
       
   414 	//Cleanup
       
   415 	EComSess.Close();
       
   416 	REComSession::FinalClose();
       
   417 
       
   418 	//Ensure plugin files are not on C:
       
   419 	res = DeleteTestPlugin();
       
   420 	TEST(res == KErrNone);
       
   421 
       
   422 	__UHEAP_MARKEND;
       
   423 	}
       
   424 
       
   425 GLDEF_C TInt E32Main()
       
   426 	{
       
   427 	__UHEAP_MARK;
       
   428 
       
   429 	TEST.Title();
       
   430 	TEST.Start(_L("ECom SWI tests."));
       
   431 
       
   432 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   433 	CActiveScheduler* scheduler = new(ELeave)CActiveScheduler;
       
   434 	CActiveScheduler::Install(scheduler);
       
   435 
       
   436 	TRAPD(err,RunTestL());
       
   437 	TEST(err==KErrNone, __LINE__);
       
   438 
       
   439 	delete scheduler;
       
   440 	delete cleanup;
       
   441 
       
   442 	TEST.End();
       
   443 	TEST.Close();
       
   444 
       
   445 	__UHEAP_MARKEND;
       
   446 	return(0);
       
   447 	}