os/ossrv/lowlevellibsandfws/pluginfw/Framework/PluginDiscoveryTests/t_plugindiscovery.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200 (2012-06-15)
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Contains tests with invalid/missing plugin DLLs
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
sl@0
    19
#include <ecom/ecom.h>
sl@0
    20
#include "EComUidCodes.h"
sl@0
    21
#include "Interface.h" // interface to Plugins
sl@0
    22
#include "../EcomTestUtils/EcomTestUtils.h"
sl@0
    23
sl@0
    24
#include <e32test.h>
sl@0
    25
#include <f32file.h>
sl@0
    26
#include <bautils.h>
sl@0
    27
sl@0
    28
LOCAL_D RTest test(_L("t_plugindiscovery.exe"));
sl@0
    29
sl@0
    30
LOCAL_D CTrapCleanup* 	  TheTrapCleanup 	 = NULL;
sl@0
    31
sl@0
    32
LOCAL_D CActiveScheduler* TheActiveScheduler = NULL;
sl@0
    33
sl@0
    34
LOCAL_D RFs					TheFs;
sl@0
    35
sl@0
    36
// Implementaion ID used for testing
sl@0
    37
const TUid KUidTestImplementation = {0x101F847C};
sl@0
    38
sl@0
    39
sl@0
    40
//It is used by some test methods which are called two times:
sl@0
    41
//from normal test and from OOM test.
sl@0
    42
static void LeaveIfErrNoMemory(TInt aError)
sl@0
    43
	{
sl@0
    44
	if(aError == KErrNoMemory)
sl@0
    45
		{
sl@0
    46
		REComSession::FinalClose();
sl@0
    47
		User::Leave(aError);
sl@0
    48
		}
sl@0
    49
	}
sl@0
    50
sl@0
    51
sl@0
    52
// Plugins used in tests.
sl@0
    53
_LIT(KEComInvalidDllOnZ, "z:\\RAMOnly\\InvalidSIDPlugin.dll");
sl@0
    54
_LIT(KEComInvalidRscOnZ, "z:\\RAMOnly\\InvalidSIDPlugin.rsc");
sl@0
    55
_LIT(KEComInvalidDllOnC, "c:\\sys\\bin\\InvalidSIDPlugin.dll");
sl@0
    56
_LIT(KEComInvalidRscOnC, "c:\\resource\\plugins\\InvalidSIDPlugin.rsc");
sl@0
    57
sl@0
    58
_LIT(KEComExample5RscOnZ, "z:\\RAMOnly\\EComExample5.rsc");
sl@0
    59
_LIT(KEComExample5RscOnC, "c:\\resource\\plugins\\EComExample5.rsc");
sl@0
    60
_LIT(KEComRomRslvrExampleRscOnCRomLocation, "z:\\RAMOnly\\EComRomRslvrExampleOnC.RSC");
sl@0
    61
_LIT(KEComRomRslvrExampleRscOnCRamLocation, "c:\\resource\\plugins\\EComRomRslvrExampleOnZ.RSC");
sl@0
    62
sl@0
    63
// Plugins used in plugins directory removing test
sl@0
    64
_LIT(KEComDefectPluginDLLOnZ,			"Z:\\RAMOnly\\DefectPlugin.dll");
sl@0
    65
_LIT(KEComDefectPluginRSCOnZ,			"Z:\\RAMOnly\\DefectPlugin.rsc");
sl@0
    66
_LIT(KEComDefectPluginDLLOnC,			"C:\\sys\\bin\\DefectPlugin.dll");
sl@0
    67
_LIT(KEComDefectPluginRSCOnC,			"C:\\Resource\\Plugins\\DefectPlugin.rsc");
sl@0
    68
_LIT(KEComResourcePluginDirNameOnC,		"C:\\Resource\\Plugins\\");
sl@0
    69
_LIT(KEComResourcePluginDirNameOffOnC,	"C:\\Resource\\PluginsNameOff\\");
sl@0
    70
sl@0
    71
/**
sl@0
    72
@SYMTestCaseID SYSLIB-ECOM-CT-0030
sl@0
    73
@SYMTestCaseDesc Test that an orphaned resource file does not create a registry
sl@0
    74
				 entry.
sl@0
    75
@SYMTestPriority High
sl@0
    76
@SYMTestActions  EComExample5.rsc file copied to C: drive.
sl@0
    77
				 Check call to REComSession::CreateImplementationL() via test
sl@0
    78
				 CExampleInterface class fails to return the implementation.
sl@0
    79
@SYMTestExpectedResults The test must not fail.
sl@0
    80
@SYMREQ REQ3846
sl@0
    81
*/
sl@0
    82
LOCAL_C void TestOrphanedRscFileL()
sl@0
    83
	{
sl@0
    84
	test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0030 "));
sl@0
    85
	__UHEAP_MARK;
sl@0
    86
sl@0
    87
	// Copy plugin
sl@0
    88
	TRAPD(ignoreErr, EComTestUtils::FileManDeleteFileL(KEComExample5RscOnC));
sl@0
    89
	ignoreErr = ignoreErr;
sl@0
    90
sl@0
    91
	TRAPD(err, EComTestUtils::FileManCopyFileL(KEComExample5RscOnZ, KEComExample5RscOnC));
sl@0
    92
	test(err == KErrNone);
sl@0
    93
sl@0
    94
	// The reason for the folowing delay is:
sl@0
    95
	// ECOM server could be already started. It means that when we copy some
sl@0
    96
	// ECOM plugins from Z: to C: drive - ECOM server should look for and
sl@0
    97
	// find the new ECOM plugins. The ECOM server uses for that an active object,
sl@0
    98
	// which scans plugin directories. So the discovering service is asynchronous.
sl@0
    99
	// We have to wait some time until it finishes.
sl@0
   100
	// Otherwise CreateImplementationsL could fail to create requested implementations.
sl@0
   101
	WAIT_FOR3s;
sl@0
   102
sl@0
   103
	CExampleInterface* interfaceimpl = NULL;
sl@0
   104
	TRAP(err, interfaceimpl = CExampleInterface::NewL2(KUidTestImplementation));
sl@0
   105
	::LeaveIfErrNoMemory(err);
sl@0
   106
	test(err == KErrNotFound);
sl@0
   107
	CleanupStack::PushL(interfaceimpl);
sl@0
   108
sl@0
   109
	CleanupStack::PopAndDestroy(interfaceimpl);
sl@0
   110
	REComSession::FinalClose();
sl@0
   111
sl@0
   112
	// Delete plugin
sl@0
   113
	TRAP(err, EComTestUtils::FileManDeleteFileL(KEComExample5RscOnC));
sl@0
   114
	test(err == KErrNone);
sl@0
   115
	__UHEAP_MARK;
sl@0
   116
	}
sl@0
   117
sl@0
   118
sl@0
   119
/**
sl@0
   120
@SYMTestCaseID SYSLIB-ECOM-CT-1404
sl@0
   121
@SYMTestCaseDesc Test that an orphaned resource file does not create a registry entry.
sl@0
   122
			and that other valid implementations are discovered instead.
sl@0
   123
@SYMTestPriority High
sl@0
   124
@SYMTestActions  Copy EComRomRslvrExampleOnC to the plug-ins directory on the C drive, without the associated DLL
sl@0
   125
	Because the DLL is not there, Ecom should fall back to the implementations on the Z drive in EComRomRslvrExampleOnZ
sl@0
   126
@SYMTestExpectedResults ECom plugins with invalid DLLs fall back to the correct implementations.
sl@0
   127
@SYMPREQ	PREQ1192
sl@0
   128
*/
sl@0
   129
LOCAL_C void TestOrphanedRscFileFallBackL()
sl@0
   130
	{
sl@0
   131
	test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1404 "));
sl@0
   132
	__UHEAP_MARK;
sl@0
   133
sl@0
   134
	// Copy plugin resource file and NOT the associated DLL
sl@0
   135
	TRAPD(err, EComTestUtils::FileManCopyFileL(KEComRomRslvrExampleRscOnCRomLocation, KEComRomRslvrExampleRscOnCRamLocation));
sl@0
   136
	test(err == KErrNone);
sl@0
   137
sl@0
   138
	// The reason for the folowing delay is:
sl@0
   139
	// ECOM server could be already started. It means that when we copy some
sl@0
   140
	// ECOM plugins from Z: to C: drive - ECOM server should look for and
sl@0
   141
	// find the new ECOM plugins. The ECOM server uses for that an active object,
sl@0
   142
	// which scans plugin directories. So the discovering service is asynchronous.
sl@0
   143
	// We have to wait some time until it finishes.
sl@0
   144
	// Otherwise ListImplementationsL could fail to find requested implementations.
sl@0
   145
	WAIT_FOR3s;
sl@0
   146
sl@0
   147
	TUid romRslvrExampleInterfaceUid = {0x10009DC8};
sl@0
   148
	RImplInfoPtrArray ifArray;
sl@0
   149
	TRAP(err, REComSession::ListImplementationsL(romRslvrExampleInterfaceUid, ifArray));
sl@0
   150
	::LeaveIfErrNoMemory(err);
sl@0
   151
	test(err == KErrNone);
sl@0
   152
sl@0
   153
	// Go through the implementations for the given interface, and find the ones that match up with
sl@0
   154
	// EComRomRslvrExampleRscOnZ (and not EComRomRslvrExampleRscOnC becuase it's DLL is missing)
sl@0
   155
	// EComRomRslvrExampleOnZ contains the implementation 0x10009DC7v2 and 0x10009DC6v1 (these should be found)
sl@0
   156
	// EComRomRslvrExampleOnC contains the implementation 0x10009DC7v1 and 0x10009DC6v2 (these should NOT be returned becuase of the missing DLL)
sl@0
   157
	TBool foundRightImplementation1 = EFalse;
sl@0
   158
	TBool foundRightImplementation2 = EFalse;
sl@0
   159
	for(TInt index = 0; index < ifArray.Count(); ++index)
sl@0
   160
		{
sl@0
   161
		TUid uid = ifArray[index]->ImplementationUid();
sl@0
   162
		TInt version = ifArray[index]->Version();
sl@0
   163
		TInt drive = ifArray[index]->Drive();
sl@0
   164
		if (uid.iUid == 0x10009DC6)
sl@0
   165
			{
sl@0
   166
			test(version == 1);
sl@0
   167
			test(drive==EDriveZ);
sl@0
   168
			foundRightImplementation1 = ETrue;
sl@0
   169
			}
sl@0
   170
		if (uid.iUid == 0x10009DC7)
sl@0
   171
			{
sl@0
   172
			test(version == 2);
sl@0
   173
			test(drive==EDriveZ);
sl@0
   174
			foundRightImplementation2 = ETrue;
sl@0
   175
			}
sl@0
   176
		}
sl@0
   177
	test(foundRightImplementation1 && foundRightImplementation2);
sl@0
   178
sl@0
   179
	ifArray.ResetAndDestroy();
sl@0
   180
	REComSession::FinalClose();
sl@0
   181
sl@0
   182
	// Delete plugin
sl@0
   183
	TRAP(err, EComTestUtils::FileManDeleteFileL(KEComRomRslvrExampleRscOnCRamLocation));
sl@0
   184
	test(err == KErrNone);
sl@0
   185
	__UHEAP_MARK;
sl@0
   186
	}
sl@0
   187
sl@0
   188
sl@0
   189
/**
sl@0
   190
@SYMTestCaseID SYSLIB-ECOM-CT-0031
sl@0
   191
@SYMTestCaseDesc Test that a plugin whose SID does not match the value in it's
sl@0
   192
				 resource file will not be installed in the registry.
sl@0
   193
@SYMTestPriority High
sl@0
   194
@SYMTestActions  InvalidSIDPlugin dll and rsc files copied to C: drive.
sl@0
   195
				 Verify plugin is not registered by checking
sl@0
   196
				 ListImplementationsL returns zero plugins for this interface.
sl@0
   197
@SYMTestExpectedResults The test must not fail.
sl@0
   198
@SYMREQ REQ3846
sl@0
   199
*/
sl@0
   200
LOCAL_C void TestInvalidSIDPluginL()
sl@0
   201
	{
sl@0
   202
	// InvalidSIDPlugin .dll and .rsc are copied from EComExample5.dll and
sl@0
   203
	// HeapTestImpl.rsc.
sl@0
   204
sl@0
   205
	test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0031 "));
sl@0
   206
	__UHEAP_MARK;
sl@0
   207
sl@0
   208
	// Copy plugins
sl@0
   209
	TRAPD(err, EComTestUtils::FileManCopyFileL(KEComInvalidDllOnZ, KEComInvalidDllOnC));
sl@0
   210
	test(err == KErrNone);
sl@0
   211
	TRAP(err, EComTestUtils::FileManCopyFileL(KEComInvalidRscOnZ, KEComInvalidRscOnC));
sl@0
   212
	test(err == KErrNone);
sl@0
   213
sl@0
   214
	// The reason for the folowing delay is:
sl@0
   215
	// ECOM server could be already started. It means that when we copy some
sl@0
   216
	// ECOM plugins from Z: to C: drive - ECOM server should look for and
sl@0
   217
	// find the new ECOM plugins. The ECOM server uses for that an active object,
sl@0
   218
	// which scans plugin directories. So the discovering service is asynchronous.
sl@0
   219
	// We have to wait some time until it finishes.
sl@0
   220
	// Otherwise ListImplementationsL could fail to find requested implementations.
sl@0
   221
	WAIT_FOR3s;
sl@0
   222
sl@0
   223
	TUid ifUid = {0x101FE392};  // HeapTestImpl.rsc interface_uid
sl@0
   224
	RImplInfoPtrArray ifArray;
sl@0
   225
	REComSession::ListImplementationsL(ifUid, ifArray);
sl@0
   226
sl@0
   227
	const TInt availCount = ifArray.Count();
sl@0
   228
	test.Printf(_L("Found %d implementations.\n"),availCount);
sl@0
   229
	test(availCount == 0);
sl@0
   230
sl@0
   231
	ifArray.ResetAndDestroy();
sl@0
   232
	REComSession::FinalClose(); // Don't want leaks outside the test
sl@0
   233
sl@0
   234
	// Cleanup plugins
sl@0
   235
	TRAP(err, EComTestUtils::FileManDeleteFileL(KEComInvalidDllOnC));
sl@0
   236
	TRAP(err, EComTestUtils::FileManDeleteFileL(KEComInvalidRscOnC));
sl@0
   237
sl@0
   238
	__UHEAP_MARK;
sl@0
   239
	}
sl@0
   240
sl@0
   241
/**
sl@0
   242
@SYMTestCaseID SYSLIB-ECOM-CT-1858
sl@0
   243
@SYMTestCaseDesc Test that rediscovery of removing and adding "\Resource\Plugins" directory
sl@0
   244
					works properly.
sl@0
   245
@SYMTestPriority High
sl@0
   246
@SYMTestActions  Removes "\Resource\Plugins" directory on C: drive, check that
sl@0
   247
					rediscovery	works properly by verifying plugin's registration.
sl@0
   248
				 Adds "\Resource\Plugins" directory on C: drive, check that rediscovery works
sl@0
   249
				 	fine by verifying plugin's registration.
sl@0
   250
@SYMTestExpectedResults The test must not fail.
sl@0
   251
@SYMDEF DEF088454
sl@0
   252
*/
sl@0
   253
LOCAL_C void TestPluginsDirectoryRemovingL()
sl@0
   254
	{
sl@0
   255
	test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1858 "));
sl@0
   256
	__UHEAP_MARK;
sl@0
   257
sl@0
   258
	/**
sl@0
   259
	Add The following plugin to C drive
sl@0
   260
sl@0
   261
	Interface UID		DLL	UID		Imp. UID		Version		DllFile
sl@0
   262
	------------------------------------------------------------------------------------------------------------------------------------------
sl@0
   263
	0x102797A1			0x102797A0	0x102797A2		1			C:\\..\\DefectPlugin.dll
sl@0
   264
sl@0
   265
	**/
sl@0
   266
	TRAPD(err, EComTestUtils::FileManCopyFileL(KEComDefectPluginDLLOnZ, KEComDefectPluginDLLOnC));
sl@0
   267
	test(err == KErrNone);
sl@0
   268
	TRAP(err, EComTestUtils::FileManCopyFileL(KEComDefectPluginRSCOnZ, KEComDefectPluginRSCOnC));
sl@0
   269
	test(err == KErrNone);
sl@0
   270
sl@0
   271
	WAIT_FOR3s;
sl@0
   272
sl@0
   273
	TUid interfaceUid={0x102797A1};
sl@0
   274
	RImplInfoPtrArray implArray;
sl@0
   275
sl@0
   276
	// Now start ecom discovery and get implementations for IF UID 0x102797A1
sl@0
   277
	TRAP(err, REComSession::ListImplementationsL(interfaceUid, implArray));
sl@0
   278
	::LeaveIfErrNoMemory(err);
sl@0
   279
	test(err == KErrNone);
sl@0
   280
sl@0
   281
	// Expected number of implementations returned
sl@0
   282
	test(implArray.Count()==1);
sl@0
   283
sl@0
   284
	// Check that the implementation uid returned matched the specs above
sl@0
   285
	TUid implUid = implArray[0]->ImplementationUid();
sl@0
   286
	TInt version = implArray[0]->Version();
sl@0
   287
	TInt drive = implArray[0]->Drive();
sl@0
   288
	// imp. uid
sl@0
   289
	test(implUid.iUid == 0x102797A2);
sl@0
   290
	// version
sl@0
   291
	test(version == 1);
sl@0
   292
	// C drive
sl@0
   293
	test(drive == EDriveC);
sl@0
   294
sl@0
   295
	implArray.ResetAndDestroy();
sl@0
   296
sl@0
   297
	// Now remove plugins directory
sl@0
   298
	TRAP(err, EComTestUtils::FileManRenameL(KEComResourcePluginDirNameOnC, KEComResourcePluginDirNameOffOnC));
sl@0
   299
	test(err == KErrNone);
sl@0
   300
	TRAP(err, EComTestUtils::FileManDeleteDirL(KEComResourcePluginDirNameOnC));
sl@0
   301
	test(err == KErrNone);
sl@0
   302
sl@0
   303
	TEntry entry;
sl@0
   304
	err = TheFs.Entry(KEComResourcePluginDirNameOnC, entry);
sl@0
   305
	// Test the plugins directory is now gone
sl@0
   306
	test(err == KErrNotFound);
sl@0
   307
sl@0
   308
	// Wait EComServer performing rediscovery
sl@0
   309
	WAIT_FOR3s;
sl@0
   310
sl@0
   311
	TRAP(err, REComSession::ListImplementationsL(interfaceUid, implArray));
sl@0
   312
	::LeaveIfErrNoMemory(err);
sl@0
   313
	test(err == KErrNone);
sl@0
   314
sl@0
   315
	// Test the rediscovery and directory scanning has been performed on renaming off event
sl@0
   316
	test(implArray.Count()==0);
sl@0
   317
sl@0
   318
	implArray.ResetAndDestroy();
sl@0
   319
sl@0
   320
	// Now rename plugins directory back
sl@0
   321
	TRAP(err, EComTestUtils::FileManRenameL(KEComResourcePluginDirNameOffOnC, KEComResourcePluginDirNameOnC));
sl@0
   322
	test(err == KErrNone);
sl@0
   323
	TRAP(err, EComTestUtils::FileManDeleteDirL(KEComResourcePluginDirNameOffOnC));
sl@0
   324
	test(err == KErrNone);
sl@0
   325
sl@0
   326
	// Test the plugins directory is added back
sl@0
   327
	err = TheFs.Entry(KEComResourcePluginDirNameOnC, entry);
sl@0
   328
	test(err == KErrNone);
sl@0
   329
sl@0
   330
	// Wait EComServer performing rediscovery
sl@0
   331
	WAIT_FOR3s;
sl@0
   332
sl@0
   333
	TRAP(err, REComSession::ListImplementationsL(interfaceUid, implArray));
sl@0
   334
	::LeaveIfErrNoMemory(err);
sl@0
   335
	test(err == KErrNone);
sl@0
   336
sl@0
   337
	// Test the rediscovery and directory scanning has been performed on renaming off event
sl@0
   338
	test(implArray.Count()==1);
sl@0
   339
sl@0
   340
	//Check that the implementation uid returned matched the specs above
sl@0
   341
	implUid = implArray[0]->ImplementationUid();
sl@0
   342
	version = implArray[0]->Version();
sl@0
   343
	drive = implArray[0]->Drive();
sl@0
   344
	test(implUid.iUid == 0x102797A2);
sl@0
   345
	test(version == 1);
sl@0
   346
	test(drive == EDriveC);
sl@0
   347
sl@0
   348
	implArray.ResetAndDestroy();
sl@0
   349
sl@0
   350
	REComSession::FinalClose(); // Don't want leaks outside the test
sl@0
   351
sl@0
   352
	// Cleanup plugins
sl@0
   353
	TRAP(err, EComTestUtils::FileManDeleteFileL(KEComDefectPluginDLLOnC));
sl@0
   354
	TRAP(err, EComTestUtils::FileManDeleteFileL(KEComDefectPluginRSCOnC));
sl@0
   355
sl@0
   356
	__UHEAP_MARK;
sl@0
   357
	}
sl@0
   358
sl@0
   359
sl@0
   360
sl@0
   361
sl@0
   362
typedef void (*ClassFuncPtrL) (void);
sl@0
   363
sl@0
   364
/**
sl@0
   365
Wrapper function to call all test functions
sl@0
   366
sl@0
   367
@param		testFuncL pointer to test function
sl@0
   368
@param		aTestDesc test function name
sl@0
   369
*/
sl@0
   370
LOCAL_C void DoBasicTestL(ClassFuncPtrL testFuncL, const TDesC& aTestDesc)
sl@0
   371
	{
sl@0
   372
	test.Next(aTestDesc);
sl@0
   373
sl@0
   374
	__UHEAP_MARK;
sl@0
   375
  	// find out the number of open handles
sl@0
   376
	TInt startProcessHandleCount;
sl@0
   377
	TInt startThreadHandleCount;
sl@0
   378
	RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
sl@0
   379
sl@0
   380
	//Call the test function
sl@0
   381
	(*testFuncL)();
sl@0
   382
sl@0
   383
	// check that no handles have leaked
sl@0
   384
	TInt endProcessHandleCount;
sl@0
   385
	TInt endThreadHandleCount;
sl@0
   386
	RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
sl@0
   387
sl@0
   388
	test(startThreadHandleCount  == endThreadHandleCount);
sl@0
   389
sl@0
   390
	__UHEAP_MARKEND;
sl@0
   391
	}
sl@0
   392
sl@0
   393
/**
sl@0
   394
Wrapper function to call all OOM test functions
sl@0
   395
@param		testFuncL pointer to OOM test function
sl@0
   396
@param		aTestDesc test function name
sl@0
   397
*/
sl@0
   398
LOCAL_C void DoOOMTestL(ClassFuncPtrL testFuncL, const TDesC& aTestDesc)
sl@0
   399
	{
sl@0
   400
	test.Next(aTestDesc);
sl@0
   401
sl@0
   402
	TInt err;
sl@0
   403
	TInt tryCount = 0;
sl@0
   404
	do
sl@0
   405
		{
sl@0
   406
		__UHEAP_MARK;
sl@0
   407
  		// find out the number of open handles
sl@0
   408
		TInt startProcessHandleCount;
sl@0
   409
		TInt startThreadHandleCount;
sl@0
   410
		RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
sl@0
   411
sl@0
   412
		__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
sl@0
   413
sl@0
   414
		//Call the test function
sl@0
   415
		TRAP(err, ((*testFuncL)()));
sl@0
   416
sl@0
   417
		__UHEAP_SETFAIL(RHeap::ENone, 0);
sl@0
   418
sl@0
   419
		// release handles
sl@0
   420
		if(err == KErrNone)
sl@0
   421
			{
sl@0
   422
			REComSession::FinalClose();
sl@0
   423
			}
sl@0
   424
sl@0
   425
		// check that no handles have leaked
sl@0
   426
		TInt endProcessHandleCount;
sl@0
   427
		TInt endThreadHandleCount;
sl@0
   428
		RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
sl@0
   429
sl@0
   430
		test(startProcessHandleCount == endProcessHandleCount);
sl@0
   431
		test(startThreadHandleCount  == endThreadHandleCount);
sl@0
   432
sl@0
   433
		__UHEAP_MARKEND;
sl@0
   434
		} while(err == KErrNoMemory);
sl@0
   435
sl@0
   436
	test(err == KErrNone);
sl@0
   437
	test.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount);
sl@0
   438
	}
sl@0
   439
sl@0
   440
sl@0
   441
sl@0
   442
LOCAL_C void DoTestsL()
sl@0
   443
	{
sl@0
   444
	__UHEAP_MARK;
sl@0
   445
sl@0
   446
	// Basic tests
sl@0
   447
	test.Next(_L("Basic Test Suite"));
sl@0
   448
	test.Start(_L("Basic Test Suite"));
sl@0
   449
	DoBasicTestL(&TestOrphanedRscFileL, _L("TestOrphanedRscFileL"));
sl@0
   450
	DoBasicTestL(&TestInvalidSIDPluginL, _L("TestInvalidSIDPluginL"));
sl@0
   451
	DoBasicTestL(&TestOrphanedRscFileFallBackL, _L("TestOrphanedRscFileFallBackL"));
sl@0
   452
	DoBasicTestL(&TestPluginsDirectoryRemovingL, _L("TestPluginsDirectoryRemovingL"));
sl@0
   453
	test.End();
sl@0
   454
sl@0
   455
	// OOM tests
sl@0
   456
	test.Next(_L("Out-of-memory Repeat Tests"));
sl@0
   457
	test.Start(_L("Out-of-memory Repeat Tests"));
sl@0
   458
	DoOOMTestL(&TestOrphanedRscFileL, _L("TestOrphanedRscFileL"));
sl@0
   459
	DoOOMTestL(&TestInvalidSIDPluginL, _L("TestInvalidSIDPluginL"));
sl@0
   460
	DoOOMTestL(&TestOrphanedRscFileFallBackL, _L("TestOrphanedRscFileFallBackL"));
sl@0
   461
	DoOOMTestL(&TestPluginsDirectoryRemovingL, _L("TestPluginsDirectoryRemovingL"));
sl@0
   462
	test.End();
sl@0
   463
sl@0
   464
	__UHEAP_MARKEND;
sl@0
   465
	}
sl@0
   466
sl@0
   467
sl@0
   468
//Initialise the Active Scheduler
sl@0
   469
//
sl@0
   470
LOCAL_C void SetupL()
sl@0
   471
	{
sl@0
   472
	// Construct and install the Active Scheduler. The Active Schedular is needed
sl@0
   473
	// by components used by this test as they are ActiveObjects.
sl@0
   474
	TheActiveScheduler = new(ELeave)CActiveScheduler;
sl@0
   475
	CActiveScheduler::Install(TheActiveScheduler);
sl@0
   476
	}
sl@0
   477
sl@0
   478
GLDEF_C TInt E32Main()
sl@0
   479
	{
sl@0
   480
	__UHEAP_MARK;
sl@0
   481
sl@0
   482
	test.Printf(_L("\n"));
sl@0
   483
	test.Title();
sl@0
   484
	test.Start(_L("Dual-Mode Discovery Tests"));
sl@0
   485
sl@0
   486
	TheTrapCleanup = CTrapCleanup::New();
sl@0
   487
	TInt err = TheFs.Connect();
sl@0
   488
	test(err == KErrNone);
sl@0
   489
	TRAP(err, SetupL());
sl@0
   490
	test(err == KErrNone);
sl@0
   491
sl@0
   492
sl@0
   493
	// Perform tests.
sl@0
   494
	TRAP(err,DoTestsL());
sl@0
   495
	test(err==KErrNone);
sl@0
   496
sl@0
   497
	delete TheActiveScheduler;
sl@0
   498
	TheFs.Close();
sl@0
   499
	delete TheTrapCleanup;
sl@0
   500
sl@0
   501
	test.End();
sl@0
   502
	test.Close();
sl@0
   503
sl@0
   504
	__UHEAP_MARKEND;
sl@0
   505
	return (KErrNone);
sl@0
   506
	}