lowlevellibsandfws/pluginfw/Framework/DriveMountTest/t_drivemount.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // This file contains code to test the plugin upgrade feature of ecom as required by CR 65BCA3.
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32test.h>
       
    19 #include <e32panic.h>
       
    20 #include <f32file.h>
       
    21 #include <bautils.h>
       
    22 #include "../EcomTestUtils/EcomTestUtils.h"
       
    23 #include "Discoverer.h"
       
    24 #include <ecom/ecom.h>
       
    25 #include "EComUidCodes.h"
       
    26 #include "Interface.h" // interface to Plugins
       
    27 
       
    28 // RAM Only RSC and DLL
       
    29 _LIT(KEComPluginDLL,		"Z:\\RAMOnly\\DefectPlugin.dll");
       
    30 _LIT(KEComPluginRSC,		"Z:\\RAMOnly\\DefectPlugin.rsc");
       
    31 
       
    32 _LIT(KEComPluginDLLOnC,			"C:\\sys\\bin\\DefectPlugin.dll");
       
    33 _LIT(KEComPluginRSCOnC,			"C:\\Resource\\Plugins\\DefectPlugin.rsc");
       
    34 _LIT(KClearEComResourceDir,		"C:\\Resource\\");
       
    35 _LIT(KClearEComSysDir,			"C:\\Sys\\");
       
    36 
       
    37 LOCAL_D RTest test(_L("Drive Mount Test"));
       
    38 
       
    39 /**
       
    40 Copies the Plugins to specific folder for testing purpose
       
    41 */
       
    42 LOCAL_C void CopyPlugin()
       
    43 	{
       
    44 	test.Printf(_L("\nCopying plugins into C drive... \n"));
       
    45 	TInt err=KErrNone;
       
    46 	TRAP(err, EComTestUtils::FileManCopyFileL(KEComPluginDLL, KEComPluginDLLOnC));
       
    47 	test(err==KErrNone);
       
    48 	TRAP(err, EComTestUtils::FileManCopyFileL(KEComPluginRSC, KEComPluginRSCOnC));
       
    49 	test(err==KErrNone);
       
    50 	// Give ECOM a chance to discover new plugins.
       
    51 	// Otherwise ListImplementationsL could fail to find requested implementations.
       
    52 	WAIT_FOR3s;
       
    53 	}
       
    54 
       
    55 /**
       
    56 Deletes Plugin from the RAM for cleanup purpose
       
    57 */
       
    58 LOCAL_C void DeletePlugin()
       
    59 	{
       
    60 	test.Printf(_L("\nRemoving plugins to clean environment... \n"));
       
    61 	TInt err=KErrNone;
       
    62 	TRAP(err, EComTestUtils::FileManDeleteFileL(KEComPluginDLLOnC));
       
    63 	test(err==KErrNone);
       
    64 	TRAP(err, EComTestUtils::FileManDeleteFileL(KEComPluginRSCOnC));
       
    65 	test(err==KErrNone);
       
    66 	// Give ECOM a chance to discover new plugins.
       
    67 	// Otherwise ListImplementationsL could fail to find requested implementations.
       
    68 	WAIT_FOR3s;
       
    69 	}
       
    70 
       
    71 /**
       
    72 Removes the Plugin folder together with its sub-folders
       
    73 */
       
    74 LOCAL_C void RemoveDir()
       
    75 	{
       
    76 	//Remove plugins from the folders before deleting the directory or else
       
    77 	//error -14 will be returned on the h2!
       
    78 	DeletePlugin();
       
    79 	TInt err=KErrNone;
       
    80 	test.Printf(_L("Removing 'Resource' & 'Sys' folders... \n"));
       
    81 	TRAP(err, EComTestUtils::FileManDeleteDirL(KClearEComResourceDir));
       
    82 	test(err==KErrNone);
       
    83 	TRAP(err, EComTestUtils::FileManDeleteDirL(KClearEComSysDir));
       
    84 	test(err==KErrNone);
       
    85 
       
    86 	// Give ECOM a chance to discover new plugins.
       
    87 	// Otherwise ListImplementationsL could fail to find requested implementations.
       
    88 	WAIT_FOR3s;
       
    89 	}
       
    90 
       
    91 
       
    92 /**
       
    93 Prepares test environment, before the tests get started. This is to ensure that ecom.lang is created,
       
    94 which mustn't change during the test run. Otherwise, the test (although it will pass), won't test
       
    95 the mounting of a drive.
       
    96 */
       
    97 LOCAL_C void PrepareTestEnvironmentL()
       
    98 	{
       
    99 	test.Printf(_L("preparing test environment\n"));
       
   100 	ECOMTU_KILL_SERVER_L(test);
       
   101 	TUid interfaceUid={0x102797A1};
       
   102 	RImplInfoPtrArray implArray;
       
   103 	//start ecom session, which will create ecom.lang
       
   104 	REComSession::ListImplementationsL(interfaceUid, implArray);
       
   105 	implArray.ResetAndDestroy();
       
   106 	//kill server
       
   107 	REComSession::FinalClose();
       
   108 	ECOMTU_KILL_SERVER_L(test);
       
   109 
       
   110 	//
       
   111 	//environment ready for the tests to start
       
   112 	}
       
   113 
       
   114 
       
   115 /**
       
   116 Cleans up the test environment after the test...
       
   117 */
       
   118 LOCAL_C void FinalCleanup()
       
   119 	{
       
   120 	DeletePlugin(); //remove plugins from the folders
       
   121 	}
       
   122 
       
   123 
       
   124 /**
       
   125 @SYMTestCaseID			SYSLIB-ECOM-CT-1446
       
   126 @SYMTestCaseDesc		Tests to ensure that the registry index gets updated when mounting
       
   127 						a drive at boot time
       
   128 @SYMTestPriority		High
       
   129 @SYMTestActions			Copy plugin into c-drive.
       
   130 						Call REComSession::ListImplementations() and check if implementation
       
   131 						on C drive exists.
       
   132 @SYMTestExpectedResults	The test must not fail.
       
   133 */
       
   134 LOCAL_C void MountFromBootL()
       
   135 	{
       
   136 	test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1446 "));
       
   137 	__UHEAP_MARK;
       
   138 
       
   139 	//Copy plugins into C drive
       
   140 	CopyPlugin();
       
   141 
       
   142 	TUid interfaceUid={0x102797A1};
       
   143 	RImplInfoPtrArray implArray;
       
   144 
       
   145 	/**
       
   146 	The following plugin is now added to the C drive and will be discovered by ECOM during startup.
       
   147 
       
   148 	Interface UID		DLL	UID		Imp. UID		Version		DllFile
       
   149 	------------------------------------------------------------------------------------------------------------------------------------------
       
   150 	0x102797A1		0x102797A0	0x102797A2	1			C:\\..\\DefectPlugin.dll
       
   151 
       
   152 	**/
       
   153 
       
   154 	// Now start ecom discovery and get implementations for IF UID 0x102797A1
       
   155 	REComSession::ListImplementationsL(interfaceUid, implArray);
       
   156 
       
   157 	//Expected number of implementations returned
       
   158 	test(implArray.Count()==1);
       
   159 
       
   160 	//Check that the implementation uid returned matched the specs above
       
   161 	TUid implUid = implArray[0]->ImplementationUid();
       
   162 	TInt version = implArray[0]->Version();
       
   163 	TInt drive = implArray[0]->Drive();
       
   164 
       
   165 	// imp. uid
       
   166 	test(implUid.iUid == 0x102797A2);
       
   167 	// version
       
   168 	test(version == 1);
       
   169 	// C drive
       
   170 	test(drive == EDriveC);
       
   171 
       
   172 	//destroy array
       
   173 	implArray.ResetAndDestroy();
       
   174 	//kill server
       
   175 	REComSession::FinalClose();
       
   176 	ECOMTU_KILL_SERVER_L(test);
       
   177 	__UHEAP_MARKEND;
       
   178 	}
       
   179 
       
   180 /**
       
   181 @SYMTestCaseID			SYSLIB-ECOM-CT-1448
       
   182 @SYMTestCaseDesc		Tests to ensure that the registry index gets updated when unmounting
       
   183 						a drive at boot time
       
   184 @SYMTestPriority		High
       
   185 @SYMTestActions			Pluginfolder (resource) is removed (to simulate the removal of an mmc card)
       
   186 						Call REComSession::ListImplementations() and check if implementation
       
   187 						on C drive exists.
       
   188 @SYMTestExpectedResults	The test must not fail.
       
   189 */
       
   190 LOCAL_C void UnmountFromBootL()
       
   191 	{
       
   192 	test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1448 "));
       
   193 	__UHEAP_MARK;
       
   194 	/**
       
   195 	The following plugin is added to the C drive and discovered by ECOM. The Plugin will be dismounted
       
   196 	and trigger a re-discovery.
       
   197 
       
   198 	Interface UID		DLL	UID		Imp. UID		Version		DllFile
       
   199 	------------------------------------------------------------------------------------------------------------------------------------------
       
   200 	0x102797A1		0x102797A0	0x102797A2	1			C:\\..\\DefectPlugin.dll
       
   201 
       
   202 	**/
       
   203 	RemoveDir();
       
   204 
       
   205 	TUid interfaceUid={0x102797A1};
       
   206 	RImplInfoPtrArray implArray;
       
   207 
       
   208 	// Get implementations for IF UID 0x102797A1
       
   209 	REComSession::ListImplementationsL(interfaceUid, implArray);
       
   210 
       
   211 	//Expected number of implementations returned
       
   212 	test(implArray.Count()==0);
       
   213 
       
   214 	//destroy array
       
   215 	implArray.ResetAndDestroy();
       
   216 
       
   217 	//kill server
       
   218 	REComSession::FinalClose();
       
   219 	ECOMTU_KILL_SERVER_L(test);
       
   220 	__UHEAP_MARKEND;
       
   221 	}
       
   222 
       
   223 
       
   224 /**
       
   225 @SYMTestCaseID			SYSLIB-ECOM-CT-1449
       
   226 @SYMTestCaseDesc		Tests to ensure that the registry index gets updated when mounting
       
   227 						a drive after boot time
       
   228 @SYMTestPriority		High
       
   229 @SYMTestActions			First clean the c-drive by removing the plugin folder
       
   230 						Next call REComSession::ListImplementations() with any z-drive plugin,
       
   231 						to start up ecom server and copy the plugins back into the c-drive, which
       
   232 						triggers ecom discovery.
       
   233 						Now call REComSession::ListImplementations() and check if implementation
       
   234 						on C drive exists.
       
   235 @SYMTestExpectedResults	The test must not fail.
       
   236 */
       
   237 LOCAL_C void MountAfterBootL()
       
   238 	{
       
   239 	test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1449 "));
       
   240 	__UHEAP_MARK;
       
   241 	//start ecom server and prepare test environment...
       
   242 	CopyPlugin();
       
   243 	TUid interfaceUid={0x102797A1};
       
   244 	RImplInfoPtrArray implArray;
       
   245 	REComSession::ListImplementationsL(interfaceUid, implArray);
       
   246 	RemoveDir();
       
   247 
       
   248 	/**
       
   249 	The following plugin will now be added to the C drive and ECOM will do a rediscovery and discover it.
       
   250 
       
   251 	Interface UID		DLL	UID		Imp. UID		Version		DllFile
       
   252 	------------------------------------------------------------------------------------------------------------------------------------------
       
   253 	0x102797A1		0x102797A0	0x102797A2	1			C:\\..\\DefectPlugin.dll
       
   254 
       
   255 	**/
       
   256 	//ECom server is running... Now test for mount after boot time.
       
   257 	CopyPlugin();
       
   258 	REComSession::ListImplementationsL(interfaceUid, implArray);
       
   259 
       
   260 	test(implArray.Count()==1);
       
   261 
       
   262 	//Check that the implementation uid returned matched the specs above
       
   263 	TUid implUid = implArray[0]->ImplementationUid();
       
   264 	TInt version = implArray[0]->Version();
       
   265 	TInt drive = implArray[0]->Drive();
       
   266 	// imp. uid
       
   267 	test(implUid.iUid == 0x102797A2);
       
   268 	// version
       
   269 	test(version == 1);
       
   270 	// C drive
       
   271 	test(drive == EDriveC);
       
   272 
       
   273 	//destroy array
       
   274 	implArray.ResetAndDestroy();
       
   275 	REComSession::FinalClose();
       
   276 	ECOMTU_KILL_SERVER_L(test);
       
   277 	__UHEAP_MARKEND;
       
   278 	}
       
   279 
       
   280 /**
       
   281 @SYMTestCaseID			SYSLIB-ECOM-CT-1450
       
   282 @SYMTestCaseDesc		Tests to ensure that the registry index gets updated when unmounting
       
   283 						a drive after boot time
       
   284 @SYMTestPriority		High
       
   285 @SYMTestActions			Remove plugin folders to unmount and call REComSession::ListImplementations()
       
   286 						to check if implementation on C drive exists.
       
   287 @SYMTestExpectedResults	The test must not fail.
       
   288 */
       
   289 LOCAL_C void UnmountAfterBootL()
       
   290 	{
       
   291 	test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1450 "));
       
   292 	__UHEAP_MARK;
       
   293 	//start ecom server and prepare test environment...
       
   294 	CopyPlugin();
       
   295 	TUid interfaceUid={0x102797A1};
       
   296 	RImplInfoPtrArray implArray;
       
   297 	REComSession::ListImplementationsL(interfaceUid, implArray);
       
   298 
       
   299 	/**
       
   300 	The following plugin is added to the C drive and discovered by ECOM. The Plugin will be dismounted
       
   301 	and trigger a re-discovery.
       
   302 
       
   303 	Interface UID		DLL	UID		Imp. UID		Version		DllFile
       
   304 	------------------------------------------------------------------------------------------------------------------------------------------
       
   305 	0x102797A1		0x102797A0	0x102797A2	1			C:\\..\\DefectPlugin.dll
       
   306 
       
   307 	**/
       
   308 	//Ecom server still running...
       
   309 	RemoveDir();
       
   310 
       
   311 	// Get implementations for IF UID 0x102797A1
       
   312 	REComSession::ListImplementationsL(interfaceUid, implArray);
       
   313 
       
   314 	//Expected number of implementations returned
       
   315 	test(implArray.Count()==0);
       
   316 
       
   317 	//destroy array
       
   318 	implArray.ResetAndDestroy();
       
   319 
       
   320 	REComSession::FinalClose();
       
   321 	ECOMTU_KILL_SERVER_L(test);
       
   322 	__UHEAP_MARKEND;
       
   323 	}
       
   324 
       
   325 typedef void (*ClassFuncPtrL) (void);
       
   326 
       
   327 /**
       
   328 Wrapper function to call all test functions
       
   329 
       
   330 @param		testFuncL pointer to test function
       
   331 @param		aTestDesc test function name
       
   332 */
       
   333 LOCAL_C void DoBasicTestL(ClassFuncPtrL testFuncL, const TDesC& aTestDesc)
       
   334 	{
       
   335 	test.Next(aTestDesc);
       
   336 
       
   337 	__UHEAP_MARK;
       
   338   	// find out the number of open handles
       
   339 	TInt startProcessHandleCount;
       
   340 	TInt startThreadHandleCount;
       
   341 	RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
       
   342 
       
   343 	//Call the test function
       
   344 	(*testFuncL)();
       
   345 
       
   346 	// check that no handles have leaked
       
   347 	TInt endProcessHandleCount;
       
   348 	TInt endThreadHandleCount;
       
   349 	RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
       
   350 
       
   351 	test(startThreadHandleCount  == endThreadHandleCount);
       
   352 
       
   353 	__UHEAP_MARKEND;
       
   354 	}
       
   355 
       
   356 
       
   357 LOCAL_C void DoTestsL()
       
   358 	{
       
   359 	//don't change the order of the tests!
       
   360 	__UHEAP_MARK;
       
   361 	PrepareTestEnvironmentL();
       
   362 	// Basic tests
       
   363 	DoBasicTestL(&MountFromBootL, _L("MountFromBoot"));
       
   364 	DoBasicTestL(&UnmountFromBootL, _L("UnmountFromBoot"));
       
   365 	DoBasicTestL(&MountAfterBootL, _L("MountAfterBoot"));
       
   366 	DoBasicTestL(&UnmountAfterBootL, _L("UnmountAfterBoot"));
       
   367 	FinalCleanup();
       
   368 	__UHEAP_MARKEND;
       
   369 	}
       
   370 
       
   371 
       
   372 GLDEF_C TInt E32Main()
       
   373 	{
       
   374 	__UHEAP_MARK;
       
   375 
       
   376 	test.Title();
       
   377 	test.Start(_L("Drive Mount Tests."));
       
   378 
       
   379 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   380 	CActiveScheduler* scheduler = new(ELeave)CActiveScheduler;
       
   381 	CActiveScheduler::Install(scheduler);
       
   382 
       
   383 	TRAPD(err,DoTestsL());
       
   384 	// Cleanup files
       
   385 	if(err != KErrNone)
       
   386 		{
       
   387 		FinalCleanup();
       
   388 		REComSession::FinalClose();
       
   389 		}
       
   390 
       
   391 	test(err==KErrNone);
       
   392 
       
   393 	delete scheduler;
       
   394 	delete cleanup;
       
   395 
       
   396 	test.End();
       
   397 	test.Close();
       
   398 
       
   399 	__UHEAP_MARKEND;
       
   400 	return(0);
       
   401 	}