lowlevellibsandfws/pluginfw/Framework/ResolverTest/t_resolver.cpp
changeset 31 ce057bb09d0b
child 45 4b03adbd26ca
child 52 bf6a71c50e42
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     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 test classes and their implementations that test
       
    15 // class CDefaultResolver. Demonstrates a simple set of derived class
       
    16 // implementations using RTest.
       
    17 // 
       
    18 //
       
    19 
       
    20 #include <ecom/ecom.h>
       
    21 #include "EComUidCodes.h"
       
    22 #include "RegistryData.h"
       
    23 #include "Registrar.h"
       
    24 #include "RegistrarObserver.h"
       
    25 #include "EComResolverParams.h"
       
    26 #include "DefaultResolver.h"
       
    27 #include "../EcomTestUtils/EcomTestUtils.h"
       
    28 #include "DriveInfo.h"
       
    29 #include "RegistryResolveTransaction.h"
       
    30 
       
    31 
       
    32 #include <e32test.h>
       
    33 #include <f32file.h>
       
    34 #include <bautils.h>
       
    35 #include <startup.hrh>
       
    36 
       
    37 // Used for suppressing warning in OOM tests
       
    38 #define __UNUSED_VAR(var) var = var
       
    39 
       
    40 // Used for OOM test
       
    41 #define TEST_OOM_ERR if(err == KErrNoMemory) User::Leave(err)
       
    42 
       
    43 // Interface Uids used within tests
       
    44 const TUid KCExampleInterfaceUid = {0x10009DC0};
       
    45 const TUid KCExampleInterfaceImp = {0x10009DC1};
       
    46 const TInt KOneSecond = 1000000;
       
    47 
       
    48 // Interface Implementation Uids used for testing
       
    49 const TInt KUidImplementation1 = 0x10009DC3;
       
    50 const TInt KUidImplementation2 = 0x10009DC4;
       
    51 
       
    52 // Dlls copied to RAM for testing purpose
       
    53 _LIT(KEComExDllOnZ, "z:\\RAMOnly\\EComExample5.dll");
       
    54 
       
    55 // Contains .rsc files of dlls that be copied to RAM
       
    56 // for testing purpose
       
    57 _LIT(KEComExDllOnC, "c:\\sys\\bin\\EComExample5.dll");
       
    58 _LIT(KEComRscFileOnZ, "z:\\RAMOnly\\EComExample5.rsc");
       
    59 _LIT(KEComRscFileOnC, "c:\\resource\\plugins\\EComExample5.rsc");
       
    60 
       
    61 _LIT(KEComExampleDllOnC,		"C:\\sys\\bin\\EComExample.dll");
       
    62 _LIT(KEComExample2DllOnC,		"C:\\sys\\bin\\EComExample2.dll");
       
    63 _LIT(KEComExample3DllOnC,		"C:\\sys\\bin\\EComExample3.dll");
       
    64 
       
    65 _LIT(KEComExampleRscOnC,		"C:\\resource\\plugins\\EComExample.rsc");
       
    66 _LIT(KEComExample2RscOnC,		"C:\\resource\\plugins\\EComExample2.rsc");
       
    67 _LIT(KEComExample3RscOnC,		"C:\\resource\\plugins\\EComExample3.rsc");
       
    68 
       
    69 _LIT(KEComExampleRscOnZ,		"Z:\\RAMOnly\\EComExample.rsc");
       
    70 _LIT(KEComExample2RscOnZ,		"Z:\\RAMOnly\\EComExample2.rsc");
       
    71 _LIT(KEComExample3RscOnZ,		"Z:\\RAMOnly\\EComExample3.rsc");
       
    72 
       
    73 
       
    74 _LIT(KEComExampleDllOnZ,			"Z:\\RAMOnly\\EComExample.dll");
       
    75 _LIT(KEComExample2DllOnZ,		"Z:\\RAMOnly\\EComExample2.dll");
       
    76 _LIT(KEComExample3DllOnZ,		"Z:\\RAMOnly\\EComExample3.dll");
       
    77 
       
    78 // Datatype on implementations that .rsc file contains
       
    79 _LIT8(KResolveMatchType, "text/wml");
       
    80 // Datatype to look for
       
    81 _LIT8(KResolveImplementationType, "text/wml||data");
       
    82 
       
    83 LOCAL_D CTrapCleanup*		TheTrapCleanup=NULL;
       
    84 
       
    85 LOCAL_D CActiveScheduler*	TheActiveScheduler=NULL;
       
    86 
       
    87 LOCAL_D RFs					TheFs;
       
    88 
       
    89 LOCAL_D RTest				test(_L("t_resolver.exe"));
       
    90 
       
    91 //LOCAL_D TCapabilitySet		dummycaps;
       
    92 // Utility clean up function
       
    93 LOCAL_C void CleanupEComPtrArray(TAny* aArray);
       
    94 
       
    95 /**
       
    96 This friend class allows us to access private and protected members of production
       
    97 code class CDefaultResolver
       
    98 */
       
    99 class TDefaultResolver_StateAccessor
       
   100 	{
       
   101 public:
       
   102 	//Auxiliary methods that provide access to private members
       
   103 	TBool Match(CDefaultResolver& aResolver,
       
   104 				const TDesC8& aImplementationType,
       
   105 				const TDesC8& aMatchType,
       
   106 				TBool aIsGeneric) const;
       
   107 
       
   108 	TUid Resolve(CDefaultResolver& aResolver,
       
   109 				 RImplInfoArray& aImplementationInfo,
       
   110 				 const TEComResolverParams& aAdditionalParameters) const;
       
   111 	};
       
   112 
       
   113 /**
       
   114 Searches for a match of a data type on an implementation type.
       
   115 Match returns ETrue if aMatchType is found within aImplementationType
       
   116 @param		aResolver resolver object on which implementations are matched
       
   117 @param		aImplementationType The implementation data type to search for a match
       
   118 @param		aMatchType Search data that identifies/matches to  implementations
       
   119 @param		aIsGeneric ETrue if wildcard matching is allowed
       
   120 @return		TBool ETrue if a match is found, EFalse if match is not found
       
   121 */
       
   122 TBool TDefaultResolver_StateAccessor::Match(CDefaultResolver& aResolver,
       
   123 											const TDesC8& aImplementationType,
       
   124 											const TDesC8& aMatchType,
       
   125 											TBool aIsGeneric) const
       
   126 	{
       
   127 	return aResolver.Match(aImplementationType, aMatchType, aIsGeneric);
       
   128 	}
       
   129 
       
   130 /**
       
   131 Selects	an appropriate implementation from a list of possibles
       
   132 @param		aResolver resolver object on which implementations are resolved
       
   133 @param		aImplementationInfo Information on the potential implementations
       
   134 @param		aAdditionalParameters The data to match against to determine the
       
   135 			implementation
       
   136 @return		The Uid of a suitable implementation
       
   137 */
       
   138 TUid TDefaultResolver_StateAccessor::Resolve(CDefaultResolver& aResolver,
       
   139 											 RImplInfoArray& aImplementationInfo,
       
   140 											 const TEComResolverParams& aAdditionalParameters) const
       
   141 	{
       
   142 	return aResolver.Resolve(aImplementationInfo, aAdditionalParameters);
       
   143 	}
       
   144 
       
   145 /**
       
   146 The implementation of the abstract Registrar Observer class,
       
   147 used for recieving notifications of registry changes.
       
   148 Stub class(for CEComServer) used for the creation of CRegistrar class object.
       
   149 CEComServer class acts as observer for CRegistrar.
       
   150 */
       
   151 class CTestRegistrarObserver : public MRegistrarObserver
       
   152 	{
       
   153 public:
       
   154 	// This function is used by RegistrarObserver (i.e.CEComServer) to notify its
       
   155 	// clients(REComSession objects) that some change has happened in Registry.
       
   156 	// Here we have no clients to notify, so no implementaion.
       
   157 	void Notification( TInt /*aNotification*/ ) {}
       
   158 	};
       
   159 
       
   160 /**
       
   161 Test class encloses necessary members that aid to test CDefaultResolver
       
   162 */
       
   163 class CResolverTest: public CBase
       
   164 	{
       
   165 public:
       
   166 	static CResolverTest* NewL();
       
   167 	virtual ~CResolverTest();
       
   168 
       
   169 	void IdentifyImplementationTestL();
       
   170 	void ListAllTestL();
       
   171 	void MatchTest();
       
   172 	void ResolveTestL();
       
   173 
       
   174 private:
       
   175 	CResolverTest();
       
   176 	void ConstructL();
       
   177 
       
   178 public:
       
   179 	/** The instance of the class under test */
       
   180 	CDefaultResolver*	iDefaultResolver;
       
   181 	/** The data store which is used by the resolver */
       
   182 	CRegistryData*		iRegistryData;
       
   183 	/** Friend class pointer used for accessing private members */
       
   184 	TDefaultResolver_StateAccessor*	iStateAccessor;
       
   185 	/** An array of potential implementations to resolve between */
       
   186 	RImplInfoArray		iImplementationData;
       
   187 	/** ECom example interface Uid */
       
   188 	TUid				iInterfaceUid;
       
   189 	/** The Uid returned by IdentifyImplementationL(), used to resolve
       
   190 	the implementation. */
       
   191 	TUid				iResolvedImpUid;
       
   192 	/** Additional parameters used for resolving between implementations */
       
   193 	TEComResolverParams	iAdditionalParameters;
       
   194 	/** CRegistrar */
       
   195 	CRegistrar* iRegistrar;
       
   196 	/** Registrar observer test class */
       
   197 	CTestRegistrarObserver* iRegistrarObserver;
       
   198 	/** CRegistryResolveTransaction */
       
   199 	CRegistryResolveTransaction* iRegistryResolveTransaction;
       
   200 	/** ExtendedInterfaces List*/
       
   201 	RArray<TUid> iExtendedInterfaces;
       
   202 	/** Client Request*/
       
   203 	TClientRequest iClientReq;
       
   204 	};
       
   205 
       
   206 /**
       
   207 Create a CResolverTest object on the CleanupStack
       
   208 @return			A pointer to the newly created class.
       
   209 */
       
   210 CResolverTest* CResolverTest::NewL()
       
   211 	{
       
   212 	CResolverTest* self = new (ELeave) CResolverTest();
       
   213 	CleanupStack::PushL(self);
       
   214 	self->ConstructL();
       
   215 	CleanupStack::Pop();
       
   216 	return self;
       
   217 	}
       
   218 
       
   219 /**
       
   220 Standardized default constructor
       
   221 @post		CRegistrarTest is fully constructed.
       
   222 */
       
   223 CResolverTest::CResolverTest()
       
   224 :	CBase()
       
   225 	{
       
   226 	// Interface uid to find implemenations
       
   227 	iInterfaceUid.iUid = KCExampleInterfaceUid.iUid;
       
   228 	}
       
   229 
       
   230 /**
       
   231 Standardized 2nd(Initialization) phase of two phase construction.
       
   232 Completes the safe construction of the CResolverTest object
       
   233 @post		CRegistrarTest is fully constructed.
       
   234 @leave		KErrNoMemory.
       
   235 */
       
   236 void CResolverTest::ConstructL()
       
   237 	{
       
   238 	iStateAccessor = new(ELeave) TDefaultResolver_StateAccessor;
       
   239 	iRegistryData = CRegistryData::NewL(TheFs);
       
   240 	iRegistrarObserver=new (ELeave) CTestRegistrarObserver;
       
   241 	// construct the registry resolve transaction object here
       
   242 	TBool capability= ETrue;
       
   243 	iRegistryResolveTransaction = CRegistryResolveTransaction::NewL(*iRegistryData,iExtendedInterfaces,iClientReq,capability);
       
   244 	iRegistrar=CRegistrar::NewL(*iRegistryData, *iRegistrarObserver, TheFs);
       
   245 	iRegistrar->ProcessSSAEventL(EStartupStateNonCritical);
       
   246 	// next the default resolver
       
   247 	iDefaultResolver = CDefaultResolver::NewL(*iRegistryResolveTransaction);
       
   248 	}
       
   249 
       
   250 /**
       
   251 Standardized default destructor
       
   252 @post		This object is properly destroyed.
       
   253 */
       
   254 CResolverTest::~CResolverTest()
       
   255 	{
       
   256 	delete iStateAccessor;
       
   257 	delete iDefaultResolver;
       
   258 	delete iRegistrar;
       
   259 	delete iRegistrarObserver;
       
   260 	delete iRegistryData;
       
   261 	delete iRegistryResolveTransaction;
       
   262 	iExtendedInterfaces.Close();
       
   263 	}
       
   264 
       
   265 /**
       
   266 @SYMTestCaseID          SYSLIB-ECOM-CT-0659
       
   267 @SYMTestCaseDesc	    Create and delete Resolver object test
       
   268 @SYMTestPriority 	    High
       
   269 @SYMTestActions  	    Creates and deletes the resolver object
       
   270 @SYMTestExpectedResults The test must not fail.
       
   271 @SYMREQ                 REQ0000
       
   272 */
       
   273 LOCAL_C void CreateDeleteTestL()
       
   274 	{
       
   275 	test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0659 CreateDeleteTestL "));
       
   276 	//
       
   277 	// Creates and deletes resolver object
       
   278 	// ------------------------------------------------------------------
       
   279 	//
       
   280 	// Set up for heap leak checking
       
   281 	__UHEAP_MARK;
       
   282 	// and leaking thread handles
       
   283 	TInt startProcessHandleCount;
       
   284 	TInt startThreadHandleCount;
       
   285 	TInt endProcessHandleCount;
       
   286 	TInt endThreadHandleCount;
       
   287 
       
   288 	// Test Starts...
       
   289 	RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
       
   290 
       
   291 	CResolverTest* theTest=NULL;
       
   292 
       
   293 	TRAPD(err, theTest = CResolverTest::NewL());
       
   294 	test(err == KErrNone);
       
   295 	delete theTest;
       
   296 
       
   297 	// Check for open handles
       
   298 	RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
       
   299 	test(startThreadHandleCount == endThreadHandleCount);
       
   300 
       
   301 	// Test Ends...
       
   302 	__UHEAP_MARKEND;
       
   303 	}
       
   304 
       
   305 /**
       
   306 @SYMTestCaseID          SYSLIB-ECOM-CT-1324
       
   307 @SYMTestCaseDesc	    Tests for CDefaultResolver::IdentifyImplementationL() function
       
   308 @SYMTestPriority 	    High
       
   309 @SYMTestActions  	    Tests that the resolver identifies most appropriate
       
   310 						interface implementation
       
   311 @SYMTestExpectedResults The test must not fail.
       
   312 @SYMREQ                 REQ0000
       
   313 */
       
   314 void CResolverTest::IdentifyImplementationTestL()
       
   315 	{
       
   316 	// Tests that the resolver identifies most appropriate
       
   317 	// interface implementation
       
   318 	test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1324 "));
       
   319 	iAdditionalParameters.SetDataType(KResolveMatchType);
       
   320 	iAdditionalParameters.SetGenericMatch(ETrue);//Allow wildcard matching
       
   321 	TRAPD(err, iResolvedImpUid =
       
   322 		iDefaultResolver->IdentifyImplementationL(iInterfaceUid, iAdditionalParameters));
       
   323 	TEST_OOM_ERR;
       
   324 	test(err == KErrNone);
       
   325 	// Check the Appropriate implementation id that should be identified
       
   326 	test(iResolvedImpUid.iUid == KUidImplementation1);
       
   327 
       
   328 	test.Printf(_L("Interface Uid 0x%08x\n"), iInterfaceUid);
       
   329 	test.Printf(_L("Resolved Implementation Uid = 0x%08x\n"), iResolvedImpUid);
       
   330 
       
   331 	}
       
   332 
       
   333 /**
       
   334 @SYMTestCaseID          SYSLIB-ECOM-CT-1325
       
   335 @SYMTestCaseDesc	    Tests for CDefaultResolver::ListAllL() function
       
   336 @SYMTestPriority 	    High
       
   337 @SYMTestActions  	    The test executes by sending an interface id and data type to match.
       
   338 						Prints all the implementation for the interface id
       
   339 @SYMTestExpectedResults The test must not fail.
       
   340 @SYMREQ                 REQ0000
       
   341 */
       
   342 void CResolverTest::ListAllTestL()
       
   343 	{
       
   344 	// Tests that ListAll() lists implementations for a specified interface
       
   345 	test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1325 "));
       
   346 
       
   347 	// set datatype to text/wml and enable wildcard match
       
   348 	iAdditionalParameters.SetDataType(KResolveMatchType);
       
   349 	iAdditionalParameters.SetGenericMatch(ETrue);
       
   350 	RImplInfoArray*	implData=NULL;
       
   351 
       
   352 	/* This should list two implementations given below
       
   353 	depending on additional parameter and wildcard match
       
   354 	10009DC3	Ver 2/"text/ wml"/10009DB3
       
   355 	10009DC4	Ver 2/"text/ *"/10009DB3
       
   356 	*/
       
   357 	TRAPD(err, implData = iDefaultResolver->ListAllL(iInterfaceUid,	iAdditionalParameters));
       
   358 
       
   359 	TEST_OOM_ERR;
       
   360 	test(err == KErrNone);
       
   361 	CleanupStack::PushL(TCleanupItem(CleanupEComPtrArray, implData));
       
   362 
       
   363 	const TInt availCount = implData->Count();
       
   364 	test(availCount == 2);
       
   365 
       
   366 	test.Printf(_L("Found %d implementations.\n"),availCount);
       
   367 
       
   368 	for (TInt count=0;count<availCount;++count)
       
   369 		{
       
   370 		const CImplementationInformation* info = (*implData)[count];
       
   371 
       
   372 		TDriveName driveName = info->Drive().Name();
       
   373 		test.Printf(_L("%d. uid={%x} version=%d on drive %S\n"), count+1,
       
   374 			info->ImplementationUid(), info->Version(), &driveName);
       
   375 
       
   376 		switch(info->ImplementationUid().iUid)
       
   377 			{
       
   378 			case KUidImplementation1:
       
   379 				test(info->Version()==2);
       
   380 				test(info->Drive()==EDriveC);
       
   381 				break;
       
   382 
       
   383 			case KUidImplementation2:
       
   384 				test(info->Version()==2);
       
   385 				test(info->Drive()==EDriveC);
       
   386 				break;
       
   387 
       
   388 			default:
       
   389 				test.Printf(_L("Mismatched implementation Uid\n"));
       
   390 				test(EFalse);
       
   391 			}
       
   392 		}
       
   393 	// Empty the array of implementations
       
   394 	CleanupStack::PopAndDestroy();//ifArray, results in a call to CleanupEComPtrArray
       
   395 
       
   396 	}
       
   397 
       
   398 /**
       
   399 @SYMTestCaseID          SYSLIB-ECOM-CT-1326
       
   400 @SYMTestCaseDesc	    Tests for TDefaultResolver_StateAccessor::Match() function
       
   401 @SYMTestPriority 	    High
       
   402 @SYMTestActions  	    The test executes by searching for a match of a data type on an implementation type
       
   403 @SYMTestExpectedResults The test must not fail.
       
   404 @SYMREQ                 REQ0000
       
   405 */
       
   406 void CResolverTest::MatchTest()
       
   407 	{
       
   408 	// 1.Search using search parameters that result in a Match to a particular
       
   409 	// Implementation.
       
   410 	// 2.Search using search parameters that result in a mismatch.
       
   411 	// 3.Finally, search using search parameters with wildcards that result in a Match
       
   412 
       
   413 	// Searches for KResolveMatchType (text/wml) on implementations
       
   414 	// KResolveImplementationType(text/wml||data)
       
   415 	test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1326 "));
       
   416 	TBool matchResult = iStateAccessor->Match(*iDefaultResolver,
       
   417 											  KResolveImplementationType,
       
   418 										      KResolveMatchType,
       
   419 										      EFalse);
       
   420 	test(matchResult);
       
   421 
       
   422 	_LIT8(KUnResolveableImplType, "Abc||xyz");
       
   423 	// Pass data "Abc||xyz" which is not present on implementation type
       
   424 	// to look for and test for failure
       
   425 	matchResult = iStateAccessor->Match(*iDefaultResolver,
       
   426 										KUnResolveableImplType,
       
   427 										KResolveMatchType,
       
   428 										EFalse);
       
   429 	test(!matchResult);
       
   430 
       
   431 	// Wild card in data type
       
   432 	_LIT8(KResolveWildImplType, "text*||xyz");
       
   433 
       
   434 	// Set to enable wild card search and test for success
       
   435 	matchResult = iStateAccessor->Match(*iDefaultResolver,
       
   436 										KResolveWildImplType,
       
   437 										KResolveMatchType,
       
   438 										ETrue);
       
   439 	test(matchResult);
       
   440 
       
   441 	}
       
   442 
       
   443 /**
       
   444 @SYMTestCaseID          SYSLIB-ECOM-CT-1327
       
   445 @SYMTestCaseDesc	    Tests the TDefaultResolver_StateAccessor::Resolve() function
       
   446 @SYMTestPriority 	    High
       
   447 @SYMTestActions  	    The test executes by sending an implementation data with additional parameter
       
   448 @SYMTestExpectedResults The test must not fail.
       
   449 @SYMREQ                 REQ0000
       
   450 */
       
   451 void CResolverTest::ResolveTestL()
       
   452 	{
       
   453 	// Resolves a appropriate implementation from a list of possibles
       
   454 
       
   455 	// Create iImplementationType on heap so that address can be passed to
       
   456 	// CImplementationInformation::NewL method
       
   457 	test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1327 "));
       
   458 	HBufC8* implementationType = HBufC8::NewL(KResolveImplementationType().Length());
       
   459 	CleanupStack::PushL(implementationType);
       
   460 	TPtr8 impPtr = implementationType->Des();
       
   461 	impPtr = KResolveImplementationType;
       
   462 
       
   463 	// Interface Uid to create an item of implementation data
       
   464 	iResolvedImpUid.iUid=KCExampleInterfaceImp.iUid;
       
   465 
       
   466 	TDriveUnit drive(EDriveC);
       
   467 	CImplementationInformation* impData = CImplementationInformation::NewL(iResolvedImpUid,
       
   468 																		  0,
       
   469 																		  NULL,
       
   470 																		  implementationType,
       
   471 																		  NULL,
       
   472 																		  drive,
       
   473 																		  EFalse,
       
   474 																		  EFalse);
       
   475 	// Pop now before pushing impData since ownership is not with it
       
   476 	CleanupStack::Pop(implementationType);
       
   477 	CleanupStack::PushL(impData);
       
   478 	// Add implementation data so that you can resolve the same
       
   479 	User::LeaveIfError(iImplementationData.Append(impData));
       
   480 	CleanupStack::Pop(impData);
       
   481 
       
   482 	// set datatype to text/wml and enable wildcard match
       
   483 	iAdditionalParameters.SetDataType(KResolveMatchType);
       
   484 	iAdditionalParameters.SetGenericMatch(ETrue);
       
   485 
       
   486 	// Newly resolved id
       
   487 	TUid resolvedUid;
       
   488 	TRAPD(err, resolvedUid = iStateAccessor->Resolve(*iDefaultResolver,
       
   489 													 iImplementationData,
       
   490 													 iAdditionalParameters));
       
   491 	TEST_OOM_ERR;
       
   492 	test(err == KErrNone);
       
   493 	// confirm newly created interface id
       
   494 	test(resolvedUid == iResolvedImpUid);
       
   495 
       
   496 	// Logging and cleaning up the array elements
       
   497 	while(iImplementationData.Count())
       
   498 		{
       
   499 		// Fetch the address at first location and empty it
       
   500 		CImplementationInformation* impInfo = iImplementationData[0];
       
   501 		test.Printf(_L("Resolved Uid is 0x%x \n"), impInfo->ImplementationUid());
       
   502 		iImplementationData.Remove(0);
       
   503 		delete impInfo;
       
   504 		}
       
   505 	iImplementationData.Reset();
       
   506 	}
       
   507 
       
   508 /**
       
   509 @SYMTestCaseID          SYSLIB-ECOM-CT-0660
       
   510 @SYMTestCaseDesc	    Tests for OOM while create and delete test
       
   511 @SYMTestPriority 	    High
       
   512 @SYMTestActions  	    Calls the CResolverTest test function
       
   513 @SYMTestExpectedResults The test must not fail.
       
   514 @SYMREQ                 REQ0000
       
   515 */
       
   516 LOCAL_C void OOMCreateDeleteTest()
       
   517 	{
       
   518 	test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0660 OOM CreateDeleteTest"));
       
   519 	TInt err;
       
   520 	TInt failAt = 1;
       
   521 	__UNUSED_VAR(failAt);
       
   522 
       
   523 	CResolverTest* resolverTest = NULL;
       
   524 
       
   525 	do
       
   526 		{
       
   527 		__UHEAP_MARK;
       
   528   		// find out the number of open handles
       
   529 		TInt startProcessHandleCount;
       
   530 		TInt startThreadHandleCount;
       
   531 		RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
       
   532 
       
   533 		__UHEAP_SETFAIL(RHeap::EDeterministic, failAt+=100);
       
   534 
       
   535 		TRAP(err, resolverTest = CResolverTest::NewL());
       
   536 
       
   537 		__UHEAP_SETFAIL(RHeap::ENone, 0);
       
   538 
       
   539 		delete resolverTest;
       
   540 		resolverTest = NULL;
       
   541 
       
   542 		// check that no handles have leaked
       
   543 		TInt endProcessHandleCount;
       
   544 		TInt endThreadHandleCount;
       
   545 		RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
       
   546 
       
   547 		test(startProcessHandleCount == endProcessHandleCount);
       
   548 		test(startThreadHandleCount  == endThreadHandleCount);
       
   549 
       
   550 		__UHEAP_MARKEND;
       
   551 		}
       
   552 	while(err == KErrNoMemory);
       
   553 
       
   554 	test.Printf(_L("- Succeeded at heap failure rate of %i\n"), failAt);
       
   555 	test(err == KErrNone);
       
   556 	}
       
   557 
       
   558 // Type definition for pointer to member function.
       
   559 // Used in calling the CResolverTest member function for testing.
       
   560 typedef void (CResolverTest::*ClassFuncPtrL) (void);
       
   561 
       
   562 /**
       
   563 This function is used to force a discovery prior to the tests commencing.
       
   564 */
       
   565 LOCAL_C void ForceDiscovery()
       
   566     {
       
   567 	CTestRegistrarObserver* registrarObserver = new (ELeave) CTestRegistrarObserver;
       
   568 	CleanupStack::PushL(registrarObserver);
       
   569 	CRegistryData* registryData = CRegistryData::NewL(TheFs);
       
   570 	CleanupStack::PushL(registryData);
       
   571 	CRegistrar* registrar = CRegistrar::NewL(*registryData, *registrarObserver, TheFs);
       
   572 	CleanupStack::PushL(registrar);
       
   573 	registrar->ProcessSSAEventL(EStartupStateNonCritical);
       
   574 
       
   575 	CleanupStack::PopAndDestroy(registrar);
       
   576 	CleanupStack::PopAndDestroy(registryData);
       
   577 	CleanupStack::PopAndDestroy(registrarObserver);
       
   578     }
       
   579 
       
   580 /**
       
   581 @SYMTestCaseID          SYSLIB-ECOM-CT-0661
       
   582 @SYMTestCaseDesc	    Wrapper function which calls other test functions
       
   583 @SYMTestPriority 	    High
       
   584 @SYMTestActions  	    Calls the CResolverTest test function
       
   585 @SYMTestExpectedResults The test must not fail.
       
   586 @SYMREQ                 REQ0000
       
   587 */
       
   588 /**
       
   589 Wrapper function to call all test functions
       
   590 
       
   591 @param		testFunc pointer to test function
       
   592 @param		aTestDesc test function name
       
   593 */
       
   594 LOCAL_C void DoBasicTestL(ClassFuncPtrL testFuncL, const TDesC& aTestDesc)
       
   595 	{
       
   596 	test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0661 "));
       
   597 	test.Next(aTestDesc);
       
   598 
       
   599 	__UHEAP_MARK;
       
   600   	// find out the number of open handles
       
   601 	TInt startProcessHandleCount;
       
   602 	TInt startThreadHandleCount;
       
   603 	RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
       
   604 
       
   605 	CResolverTest* resolverTest = CResolverTest::NewL();
       
   606 	CleanupStack::PushL(resolverTest);
       
   607 
       
   608 	(resolverTest->*testFuncL)();
       
   609 
       
   610 	CleanupStack::PopAndDestroy(resolverTest);
       
   611 
       
   612 	// check that no handles have leaked
       
   613 	TInt endProcessHandleCount;
       
   614 	TInt endThreadHandleCount;
       
   615 	RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
       
   616 
       
   617 	test(startProcessHandleCount == endProcessHandleCount);
       
   618 	test(startThreadHandleCount  == endThreadHandleCount);
       
   619 
       
   620 	__UHEAP_MARKEND;
       
   621 	}
       
   622 
       
   623 /**
       
   624 @SYMTestCaseID          SYSLIB-ECOM-CT-0662
       
   625 @SYMTestCaseDesc	    Function to call all OOM test functions
       
   626 @SYMTestPriority 	    High
       
   627 @SYMTestActions  	    Calls the CResolverTest test function
       
   628 @SYMTestExpectedResults The test must not fail.
       
   629 @SYMREQ                 REQ0000
       
   630 */
       
   631 /**
       
   632 Wrapper function to call all OOM test functions
       
   633 
       
   634 @param		testFuncL pointer to OOM test function
       
   635 @param		aTestDesc test function name
       
   636 */
       
   637 LOCAL_C void DoOOMTestL(ClassFuncPtrL testFuncL, const TDesC& aTestDesc)
       
   638 	{
       
   639 	test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0662 "));
       
   640 	test.Next(aTestDesc);
       
   641 
       
   642 	TInt err;
       
   643 	TInt tryCount = 0;
       
   644 	do
       
   645 		{
       
   646 		__UHEAP_MARK;
       
   647   		// find out the number of open handles
       
   648 		TInt startProcessHandleCount;
       
   649 		TInt startThreadHandleCount;
       
   650 		RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
       
   651 
       
   652 		CResolverTest* resolverTest = CResolverTest::NewL();
       
   653 		CleanupStack::PushL(resolverTest);
       
   654 
       
   655 		__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
       
   656 
       
   657 		TRAP(err, (resolverTest->*testFuncL)());
       
   658 
       
   659 		__UHEAP_SETFAIL(RHeap::ENone, 0);
       
   660 
       
   661 		CleanupStack::PopAndDestroy(resolverTest);
       
   662 		resolverTest = NULL;
       
   663 		// check that no handles have leaked
       
   664 		TInt endProcessHandleCount;
       
   665 		TInt endThreadHandleCount;
       
   666 		RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
       
   667 
       
   668 		test(startProcessHandleCount == endProcessHandleCount);
       
   669 		test(startThreadHandleCount  == endThreadHandleCount);
       
   670 
       
   671 		__UHEAP_MARKEND;
       
   672 		} while(err == KErrNoMemory);
       
   673 
       
   674 	test(err == KErrNone);
       
   675 	test.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount);
       
   676 	}
       
   677 
       
   678 LOCAL_C void DoTestsL()
       
   679 	{
       
   680 	__UHEAP_MARK;
       
   681 
       
   682 	// Force a discovery to ensure that the ecom.dat file is updated with the data from the plugins
       
   683 	// required for this test. The plugins for this test are copied by calling CopyPlugins() from E32Main().
       
   684 	// They are deleted by calling DeleteTestPlugin() also from E32Main().
       
   685 	ForceDiscovery();
       
   686 
       
   687 	// Basic tests
       
   688 	CreateDeleteTestL();
       
   689 	DoBasicTestL(&CResolverTest::IdentifyImplementationTestL, _L("Identify implementation test"));
       
   690 	DoBasicTestL(&CResolverTest::ListAllTestL, _L("ListAllTestL"));
       
   691 	DoBasicTestL(&CResolverTest::MatchTest, _L("MatchTest"));
       
   692 	DoBasicTestL(&CResolverTest::ResolveTestL, _L("ResolveTestL"));
       
   693 
       
   694 	// OOM tests
       
   695 	OOMCreateDeleteTest();
       
   696 	DoOOMTestL(&CResolverTest::IdentifyImplementationTestL, _L("OOM IdentifyImplementationTestL"));
       
   697 	DoOOMTestL(&CResolverTest::ListAllTestL, _L("OOM ListAllTestL"));
       
   698 	DoOOMTestL(&CResolverTest::MatchTest, _L("OOM MatchTest"));
       
   699 	DoOOMTestL(&CResolverTest::ResolveTestL, _L("OOM ResolveTestL"));
       
   700 
       
   701 	__UHEAP_MARKEND;
       
   702 	}
       
   703 
       
   704 /**
       
   705 This function is used for cleanup support of locally declared arrays
       
   706 */
       
   707 LOCAL_C void CleanupEComPtrArray(TAny* aArray)
       
   708 	{
       
   709 
       
   710 	(static_cast<RImplInfoArray*>(aArray))->Reset();
       
   711 	delete aArray;// delete here
       
   712 
       
   713 	}
       
   714 
       
   715 /**
       
   716 Copies the Plugins to specific folder for testing purpose
       
   717 */
       
   718 LOCAL_C void CopyPlugins()
       
   719     {
       
   720 	// Copy the dlls and .rsc files on to RAM
       
   721 	TRAPD(err, EComTestUtils::FileManCopyFileL(KEComExDllOnZ, KEComExDllOnC));
       
   722 	test(err==KErrNone);
       
   723 
       
   724 	TRAP(err, EComTestUtils::FileManCopyFileL(KEComRscFileOnZ, KEComRscFileOnC));
       
   725 	test(err==KErrNone);
       
   726 
       
   727 	TRAP(err, EComTestUtils::FileManCopyFileL(KEComExampleDllOnZ, KEComExampleDllOnC));
       
   728 	test(err==KErrNone);
       
   729 	TRAP(err, EComTestUtils::FileManCopyFileL(KEComExample2DllOnZ, KEComExample2DllOnC));
       
   730 	test(err==KErrNone);
       
   731  	TRAP(err, EComTestUtils::FileManCopyFileL(KEComExample3DllOnZ, KEComExample3DllOnC));
       
   732 	test(err==KErrNone);
       
   733 
       
   734 	TRAP(err, EComTestUtils::FileManCopyFileL(KEComExampleRscOnZ, KEComExampleRscOnC));
       
   735 	test(err==KErrNone);
       
   736 	TRAP(err, EComTestUtils::FileManCopyFileL(KEComExample2RscOnZ, KEComExample2RscOnC));
       
   737 	test(err==KErrNone);
       
   738 	TRAP(err, EComTestUtils::FileManCopyFileL(KEComExample3RscOnZ, KEComExample3RscOnC));
       
   739 	test(err==KErrNone);
       
   740 	}
       
   741 
       
   742 // Deleting plugin from the RAM for cleanup purpose
       
   743 inline LOCAL_C void DeleteTestPlugin()
       
   744 	{
       
   745 	TRAPD(err, EComTestUtils::FileManDeleteFileL(KEComExDllOnC));
       
   746 	TRAP(err, EComTestUtils::FileManDeleteFileL(KEComRscFileOnC));
       
   747  	TRAP(err, EComTestUtils::FileManDeleteFileL(KEComExampleDllOnC));
       
   748  	TRAP(err, EComTestUtils::FileManDeleteFileL(KEComExample2DllOnC));
       
   749  	TRAP(err, EComTestUtils::FileManDeleteFileL(KEComExample3DllOnC));
       
   750  	TRAP(err, EComTestUtils::FileManDeleteFileL(KEComExampleRscOnC));
       
   751  	TRAP(err, EComTestUtils::FileManDeleteFileL(KEComExample2RscOnC));
       
   752  	TRAP(err, EComTestUtils::FileManDeleteFileL(KEComExample3RscOnC));
       
   753 	}
       
   754 
       
   755 //Initialise the Active Scheduler
       
   756 LOCAL_C void SetupL()
       
   757     {
       
   758 	// Construct and install the Active Scheduler. The Active Schedular is needed
       
   759 	// by components used by this test as they are ActiveObjects.
       
   760 	TheActiveScheduler = new(ELeave)CActiveScheduler;
       
   761 	CActiveScheduler::Install(TheActiveScheduler);
       
   762 	}
       
   763 
       
   764 
       
   765 GLDEF_C TInt E32Main()
       
   766 	{
       
   767 	__UHEAP_MARK;
       
   768 
       
   769 	test.Printf(_L("\n"));
       
   770 	test.Title();
       
   771 	test.Start(_L("Resolver Tests"));
       
   772 
       
   773 	TheTrapCleanup = CTrapCleanup::New();
       
   774 
       
   775 	TRAPD(err, SetupL());
       
   776 	test(err == KErrNone);
       
   777 
       
   778 	// Connect the file server instance
       
   779 	User::LeaveIfError(TheFs.Connect());
       
   780 
       
   781 	CopyPlugins();
       
   782 
       
   783 	// Wait, so that ECom server looks for plugins copied from Z: to C drive
       
   784 	// ECOM server could be already started. It means that when we copy some
       
   785 	// ECOM plugins from Z: to C: drive - ECOM server should look for and
       
   786 	// find the new ECOM plugins. The ECOM server uses for that CDiscoverer::CIdleScanningTimer
       
   787 	// which is an active object. So the discovering service is asynchronous. We have to
       
   788 	// wait some time until it finishes. Otherwise ListImplementationsL could fail to find
       
   789 	// requested implementations.
       
   790 	User::After(KOneSecond * 3);
       
   791 
       
   792 	TRAP(err, DoTestsL());
       
   793 	test(err == KErrNone);
       
   794 
       
   795 	// Cleanup files. If the cleanup fails that is no problem,
       
   796 	// as any subsequent tests will replace them. The only downside
       
   797 	// would be the disk not being tidied
       
   798 	DeleteTestPlugin();
       
   799 
       
   800 	TheFs.Close();
       
   801 	delete TheTrapCleanup;
       
   802 	delete TheActiveScheduler;
       
   803 	test.End();
       
   804 	test.Close();
       
   805 
       
   806 	__UHEAP_MARKEND;
       
   807 	return(KErrNone);
       
   808 	}