os/security/authorisation/userpromptservice/policies/test/tupspolicies/source/tupsplugins.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #include "tupsplugins.h"
    20 
    21 #include <ecom/ecom.h>
    22 #include <ups/upsconst.h>
    23 #include <ups/fingerprint.h>
    24 #include <ups/upserr.h>
    25 #include "cleanuputils.h"
    26 #include "util.h"
    27 
    28 using namespace UserPromptService;
    29 
    30 _LIT(KRequestsSection, "requests");
    31 
    32 void CTestPlugins::SetupL()
    33 /**
    34 Initialise policy library objects.
    35  */
    36 	{
    37 	__UHEAP_MARK;
    38 	User::LeaveIfError(iFs.Connect());
    39 	iActiveWaiter = new(ELeave)CActiveWaiter(Logger());
    40 
    41 	// Dummy decision record for ForcePromptL
    42 	iDecisionRecord = CDecisionRecord::NewL(TSecureId(0), TUid::Null(),	TUid::Null(),
    43 			TSecureId(0), _L8("foo"), KNullDesC8, KNullDesC, EFalse, 0, 0);		
    44 	}
    45 
    46 void CTestPlugins::TearDownL()
    47 /**
    48 Destroy policy library objects.
    49  */
    50 	{
    51 	iRequests.ResetAndDestroy();
    52 	iExpectedValues.ResetAndDestroy();		
    53 	delete iDecisionRecord;
    54 	iDecisionRecord = 0;
    55 	delete iActiveWaiter;
    56 	iActiveWaiter = 0;
    57 	iFs.Close();
    58 	__UHEAP_MARKEND;
    59 	}
    60 
    61 void CTestPlugins::DoCancel() 
    62 	{
    63 	}
    64 
    65 void CTestPlugins::TestCacheL()
    66 /**
    67  */
    68 	{
    69 	TBool passed(ETrue);
    70 			
    71 	TInt numRequests;	
    72 	ASSERT_TRUE(iConfig.GetInt(KRequestsSection,_L("numrequests"), numRequests));
    73 	ASSERT_TRUE(numRequests > 0);
    74 	
    75 	LoadTestDataL(numRequests);
    76 	for (TInt i = 0; i < numRequests; ++i)
    77 		{
    78 		TBuf<16> section(_L("request"));
    79 		section.AppendNum(i);
    80 		
    81 		// Is the test expected to fail ?
    82 		iExpectedError = KErrNone;	
    83 		(void) iConfig.GetInt(section, _L("expectederror"), iExpectedError);				
    84 		
    85 		if (! iInteractive)	GetResponseL(section);
    86 		
    87 		if (iOom) 
    88 			{
    89 			INFO_PRINTF2(_L("Running OOM test for request %d"), i);
    90 			passed &= DoOomRequestL(*iExpectedValues[i], *iRequests[i]);
    91 			}
    92 		else
    93 			{
    94 			TRAPD(err, passed &= DoRequestL(*iExpectedValues[i], *iRequests[i]));
    95 			if (err == KErrNoMemory) User::Leave(err);		
    96 			passed &= CheckExpectedError(Logger(), iExpectedError, err);					
    97 			}				
    98 		}
    99 	if (!passed) 
   100 		{
   101 		User::Leave(KErrTEFUnitFail);
   102 		}
   103 	}
   104 
   105 void CTestPlugins::LoadTestDataL(TInt aNumRequests)
   106 	{
   107 	(void) iConfig.GetBool(KRequestsSection,_L("oom"), iOom);
   108 	// Gets the scripted prompt response
   109 	(void) iConfig.GetBool(KRequestsSection,_L("interactive"), iInteractive);
   110 
   111 	// Read all the requests up front
   112 	for (TInt i = 0; i < aNumRequests; ++i)
   113 		{		
   114 		TBuf<16> section(_L("request"));
   115 		section.AppendNum(i);
   116 		
   117 		GetExpectedValuesL(section);
   118 		CPromptRequest* req = GetRequestParamsLC(section, iExpectedValues[i]->iClientEntity);			
   119 		iRequests.AppendL(req);
   120 		CleanupStack::Pop(req);				
   121 		}	
   122 	}
   123 
   124 void CTestPlugins::GetResponseL(const TDesC& aSection)
   125 	{
   126 	TPtrC response;
   127 	TBool ret = iConfig.GetString(aSection, _L("response"), response);
   128 	ASSERT_TRUE(ret);	
   129 	iResponse = static_cast<CPolicy::TOptions>(StringToOptionL(response));
   130 	
   131 	RFile file;
   132 	TBuf<21> name(_L("!:\\upsrefnotifier.txt"));
   133 	name[0] = iFs.GetSystemDriveChar();	
   134 	User::LeaveIfError(file.Replace(iFs, name, EFileShareExclusive | EFileWrite));
   135 	CleanupClosePushL(file);
   136 	
   137 	HBufC* opt = OptionToString(iResponse).AllocLC();	
   138 	User::LeaveIfError(file.Write(opt->Des().Collapse()));
   139 	
   140 	if (! iOom) INFO_PRINTF2(_L("Scripted prompt response = %S"), &OptionToString(iResponse));
   141 	CleanupStack::PopAndDestroy(2, &file); // file, opt
   142 	}
   143 
   144 TBool CTestPlugins::DoRequestL(const TExpectedValue& aExpected, const CPromptRequest& aRequest)
   145 	{
   146 	TBool passed(ETrue);
   147 	
   148 	CPluginManager* pluginManager = CPluginManager::NewL();
   149 	CleanupStack::PushL(pluginManager);	
   150 	CPolicyCache* policyCache = CPolicyCache::NewL(iFs, _L("\\tups\\tpolicies\\policies\\"));	
   151 	CleanupStack::PushL(policyCache);
   152 	
   153 	TBool protectedSid = ((aRequest.ClientSid().iId & 0x80000000) == 0);
   154 	if (protectedSid != aRequest.IsClientSidProtected())
   155 		{
   156 		ERR_PRINTF3(_L("Expected value for CPromptRequest::IsProtectedSid() = %d, actual value = %d"),
   157 			protectedSid, aRequest.IsClientSidProtected());
   158 		passed = EFalse;
   159 		}
   160 	
   161 	const CPolicy* policy = policyCache->MatchL(aRequest);	
   162 	ASSERT_NOT_NULL(policy);
   163 	// Attempt to load the policy a second time, should get the same 
   164 	// policy object and policy cache should not leak.
   165 	__UHEAP_MARK;
   166 	ASSERT_EQUALS(policy, policyCache->MatchL(aRequest));
   167 	__UHEAP_MARKEND;
   168 	
   169 	// It should also be safe to load the service configuration if we have loaded a single
   170 	// policy file.
   171 	RArray<TServiceConfig> configs;
   172 	CleanupClosePushL(configs);
   173 	policyCache->ServiceConfigL(aRequest.ServerSid().iId, configs);
   174 	ASSERT_TRUE(configs.Count() > 0);	// If policy was loaded there must be at least one service config	
   175 	CleanupStack::PopAndDestroy(&configs);
   176 	
   177 	passed &= CheckPolicyL(aExpected, policy);
   178 	
   179 	if (policy->PromptRequired())
   180 		{	
   181 		// Just verify that GetExtension doesn't crash
   182 		TAny* extensionPtr(0);		
   183 		CPlugin<CPolicyEvaluator>* policyEvaluator = 
   184 			pluginManager->CreateEvaluatorL(policy->PolicyEvaluator());
   185 		CleanupStack::PushL(policyEvaluator);
   186 		policyEvaluator->Imp().GetExtension(0, extensionPtr, NULL);		
   187 
   188 		RPointerArray<CFingerprint> fingerprints;
   189 		CleanupResetAndDestroyPushL(fingerprints);
   190 		const CClientEntity* clientEntity(0);
   191 		const TAny* dialogCreatorParams(0);
   192 		
   193 		policyEvaluator->Imp().GenerateFingerprints(aRequest, *policy, 
   194 			fingerprints, clientEntity, dialogCreatorParams, iActiveWaiter->iStatus);		
   195 		iActiveWaiter->WaitActive(KErrNone);
   196 					
   197 		if (! iOom) INFO_PRINTF3(_L("Policy Evaluator 0x%08x: num fingerprints = %d"), 
   198 			policy->PolicyEvaluator(), fingerprints.Count());
   199 			
   200 		if (aExpected.iClientEntity.Length())
   201 			{
   202 			if (! clientEntity)
   203 				{	
   204 				ERR_PRINTF1(_L("Client entity expected"));
   205 				passed = EFalse;
   206 				}
   207 			else if (clientEntity->Name() != aExpected.iClientEntity)
   208 				{
   209 				ERR_PRINTF1(_L("Cliententity name mismatch"));
   210 				passed = EFalse;
   211 				}
   212 			}
   213 		else if (aExpected.iClientEntity.Length() == 0 && clientEntity)
   214 			{
   215 			ERR_PRINTF1(_L("Unexpected client entity"));
   216 			passed = EFalse;
   217 			}
   218 		
   219 		// Make sure base class implementation for ForcePromptL returns EFalse
   220 		TUint evaluatorInfo(0);
   221 		ASSERT_FALSE(policyEvaluator->Imp().CPolicyEvaluator::ForcePromptL(*iDecisionRecord, evaluatorInfo));
   222 		
   223 		CPlugin<CDialogCreator>* dialogCreator
   224 			= pluginManager->CreateDialogCreatorL(policy->DialogCreator());
   225 		CleanupStack::PushL(dialogCreator);
   226 		dialogCreator->Imp().GetExtension(0, extensionPtr, NULL);
   227 				
   228 		dialogCreator->Imp().PrepareDialog(
   229 			aRequest, *policy, fingerprints, clientEntity, dialogCreatorParams, iActiveWaiter->iStatus);
   230 		iActiveWaiter->WaitActive(KErrNone);
   231 		
   232 		const CFingerprint* fingerprint(0);
   233 		CPolicy::TOptions selected;
   234 		dialogCreator->Imp().DisplayDialog(
   235 			selected, fingerprint, evaluatorInfo, iActiveWaiter->iStatus);
   236 		iActiveWaiter->WaitActive(KErrNone);
   237 		
   238 		if (! iOom) INFO_PRINTF2(_L("User response: %S"), &OptionToString(selected));
   239 		if (! iInteractive && selected != iResponse) // don't check response in interactive mode
   240 			{
   241 			ERR_PRINTF3(_L("Expected user response = %S, actual user response = %S"), 
   242 				&OptionToString(iResponse), &OptionToString(selected));
   243 				passed = EFalse;
   244 			}				
   245 		
   246 		if (fingerprint) 
   247 			{
   248 			if (! iOom) INFO_PRINTF2(_L("Description for selected fingerprint: %S"), &fingerprint->Description());
   249 			}
   250 		CleanupStack::PopAndDestroy(3, policyEvaluator); // fingerprint, dialogcreator
   251 		}
   252 	else 
   253 		{
   254 		if (! iOom) INFO_PRINTF2(_L("Policy %d does not require a prompt to be displayed"), policy->Flags());
   255 		}	
   256 	CleanupStack::PopAndDestroy(2, pluginManager); // policyCache
   257 	return passed;
   258 	}
   259 
   260 void CTestPlugins::GetExpectedValuesL(const TDesC& aSection)
   261 	{
   262 	TExpectedValue* expected = new(ELeave) TExpectedValue();
   263 	CleanupStack::PushL(expected);
   264 	iExpectedValues.AppendL(expected);
   265 	CleanupStack::Pop(expected);
   266 	
   267 	iConfig.GetHex(aSection, _L("expectedflags"), expected->iFlags);
   268 	iConfig.GetHex(aSection, _L("expectedmajorversion"), expected->iMajorVersion);
   269 	iConfig.GetHex(aSection, _L("expectedminorversion"), expected->iMinorVersion);
   270 	iConfig.GetBool(aSection, _L("expectedsilent"), expected->iSilent);		
   271 	iConfig.GetHex(aSection, _L("expectedpolicyevaluator"), expected->iPolicyEvaluator);
   272 
   273 	TPtrC clientEntity;
   274 	if (iConfig.GetString(aSection, _L("cliententity"), clientEntity))
   275 		{
   276 		ASSERT_TRUE(clientEntity.Length() < expected->iClientEntity.MaxLength());		
   277 		expected->iClientEntity.Copy(clientEntity);
   278 		}	
   279 	}
   280 
   281 TBool CTestPlugins::CheckPolicyL(const TExpectedValue& aExpected, const CPolicy* aPolicy)
   282 /**
   283 Checks the correct policy was found for the request.
   284 @param	aPolicy	The policy object returned by the policy cache.
   285 @return			ETrue if successful; otherwise, EFalse is returned.
   286 */
   287 	{
   288 	TBool passed = ETrue;
   289 		
   290 	if (aExpected.iFlags != aPolicy->Flags())
   291 		{
   292 		ERR_PRINTF3(_L("Expected flags = 0x%04x, actual flags 0x%04x"),
   293 			aExpected.iFlags, aPolicy->Flags());
   294 			passed = EFalse;
   295 		}
   296 	
   297 	if (aExpected.iMajorVersion != aPolicy->MajorVersion())
   298 		{
   299 		ERR_PRINTF3(_L("Expected major version = %d, actual major version = %d"),
   300 			aExpected.iMajorVersion, aPolicy->MajorVersion());
   301 		passed = EFalse;
   302 		}
   303 	
   304 	if (aExpected.iMinorVersion != aPolicy->MinorVersion())
   305 		{
   306 		ERR_PRINTF3(_L("Expected minor version = %d, actual minor version = %d"),
   307 			aExpected.iMinorVersion, aPolicy->MinorVersion());
   308 		passed = EFalse;
   309 		}					
   310 
   311 	if ((TUint)aExpected.iPolicyEvaluator != aPolicy->PolicyEvaluator().iUid) 
   312 		{
   313 		ERR_PRINTF3(_L("Expected policy evaluator = %08x, actual policy evaluator = %08x"),
   314 			aExpected.iPolicyEvaluator, aPolicy->PolicyEvaluator().iUid)
   315 		passed = EFalse;
   316 		}
   317 
   318 	TBool silent = ! aPolicy->PromptRequired();	
   319 	if (silent) 
   320 		{
   321 		if (! iOom) INFO_PRINTF1(_L("Policy never requires a prompt."));
   322 		}
   323 	
   324 	if (silent != aExpected.iSilent)
   325 		{
   326 		ERR_PRINTF3(_L("Expected value for silent policy = %d, actual = %d"),
   327 			aExpected.iSilent, silent);
   328 			passed = EFalse;
   329 		}
   330 					
   331 	return passed;
   332 	}
   333 
   334 CTestSuite* CTestPlugins::CreateSuiteL(const TDesC& aName)
   335 /**
   336 Creates the test suite for User Prompt Service ECOM plug-ins
   337 @param aName - Suite name
   338 @return - Suite
   339 */
   340 	{
   341 	SUB_SUITE
   342 	AddAsyncTestCase(lTestSuite, _L("TestCacheL"), &CTestPlugins::TestCacheL);
   343 	AddAsyncTestCase(lTestSuite, _L("TestPluginManagerL"), &CTestPlugins::TestPluginManagerL);
   344 	AddAsyncTestCase(lTestSuite, _L("TestLengthsL"), &CTestPlugins::TestLengthsL);
   345 	END_SUITE
   346 	}
   347 
   348 CPromptRequest* CTestPlugins::GetRequestParamsLC(const TDesC& aSection, const TDesC8& aClientEntity)
   349 /**
   350 Gets the data from the CPromptRequest from a section in the config file.
   351 @param aSection The name of the section containing the prompt request data.
   352 @return			The new CPromptRequest object.
   353 */
   354 {
   355 	TInt clientSid;		
   356 	ASSERT_TRUE(iConfig.GetHex(aSection,_L("clientsid"), clientSid));
   357 	
   358 	TInt clientVid;
   359 	ASSERT_TRUE(iConfig.GetHex(aSection,_L("clientvid"), clientVid));
   360 	
   361 	TInt serverSid;
   362 	ASSERT_TRUE(iConfig.GetHex(aSection,_L("serversid"), serverSid));
   363 
   364 	TInt serviceId;
   365 	ASSERT_TRUE(iConfig.GetHex(aSection,_L("serviceid"), serviceId));
   366 
   367 	TPtrC destination;
   368 	ASSERT_TRUE(iConfig.GetString(aSection,_L("destination"), destination));
   369 
   370 	TBool securityResult;	
   371 	ASSERT_TRUE(iConfig.GetBool(aSection,_L("securityresult"), securityResult));
   372 	
   373 	TPtrC opaqueData;
   374 	ASSERT_TRUE(iConfig.GetString(aSection,_L("opaquedata"), opaqueData));
   375 	
   376 	TThreadId myThreadId;
   377 	RThread me;
   378 	myThreadId = me.Id();
   379 	me.Close();
   380 
   381 	TProcessId myProcessId;
   382 	RProcess mep;
   383 	myProcessId = mep.Id();
   384 	mep.Close();
   385 	
   386 	RBuf destinationRb;
   387 	destinationRb.CreateL(destination);
   388 	CleanupClosePushL(destinationRb);
   389 	
   390 	RBuf8 opaqueDataRb;
   391 	opaqueDataRb.CreateL(opaqueData.Length() + aClientEntity.Length() + 64);	
   392 	CleanupClosePushL(opaqueDataRb);
   393 	opaqueDataRb.Copy(opaqueData);
   394 	if (aClientEntity.Length())
   395 		{
   396 		opaqueDataRb.Append(_L8("<ce>"));
   397 		opaqueDataRb.Append(aClientEntity);
   398 		opaqueDataRb.Append(_L8("</ce>"));		
   399 		}
   400 
   401 
   402 	CPromptRequest* req = 
   403 		CPromptRequest::NewL(TUid::Uid(clientSid), TUid::Uid(clientVid), myThreadId, myProcessId,
   404 				TUid::Uid(serverSid), TUid::Uid(serviceId), 
   405 				destinationRb, opaqueDataRb, securityResult);
   406 				
   407 	CleanupStack::PopAndDestroy(&opaqueDataRb);
   408 	CleanupStack::PopAndDestroy(&destinationRb);
   409 
   410 	CleanupStack::PushL(req);
   411 
   412 	return req;
   413 }
   414 
   415 void CTestPlugins::TestLengthsL()
   416 /**
   417 Tests length constrains in the CFingerprint and CClientEntity classes
   418 */
   419 	{
   420 	TInt maxLen = KUpsMaxFingerprintLength + 1;
   421 	HBufC8* bigBuffer = HBufC8::NewMaxLC(maxLen);
   422 	TPtrC8 emptyBuf;
   423 	
   424 	_LIT8(K32Bytes, "01234567890123456789012345678901");
   425 	_LIT(KDescription, "description");
   426 	
   427 	CFingerprint* fp(0);
   428 	CClientEntity* ce(0);
   429 	
   430 	TInt err(KErrNone);
   431 		
   432 	if (! iOom) INFO_PRINTF1(_L("Create a fingerprint with an empty value - should pass"));
   433 	fp = CFingerprint::NewL(emptyBuf, KDescription);
   434 	delete fp;
   435 	
   436 	if (! iOom) INFO_PRINTF1(_L("Create a fingerprint with value that's too long  - should fail"));
   437 	TRAP(err, fp = CFingerprint::NewL(*bigBuffer, KDescription));
   438 	ASSERT_EQUALS(err, KErrUpsBadFingerprintLength);
   439 	
   440 	if (! iOom) INFO_PRINTF1(_L("Create a fingerprint with 32 bytes of data - should pass"));
   441 	fp = CFingerprint::NewLC(K32Bytes, KDescription);
   442 	ASSERT_TRUE(fp->Fingerprint() == K32Bytes);
   443 	ASSERT_TRUE(fp->Description() == KDescription);
   444 	CleanupStack::PopAndDestroy(fp);
   445 	
   446 	if (! iOom) INFO_PRINTF1(_L("Create a client entity with an empty value - should pass"));
   447 	ce = CClientEntity::NewLC(emptyBuf);
   448 	ASSERT_TRUE(ce->Name() == emptyBuf);
   449 	CleanupStack::PopAndDestroy(ce);
   450 	
   451 	if (! iOom) INFO_PRINTF1(_L("Create a client entity with a name that's too long - should fail"));
   452 	TRAP(err, ce = CClientEntity::NewL(*bigBuffer));
   453 	ASSERT_EQUALS(err, KErrUpsBadClientEntityLength);
   454 	
   455 	if (! iOom) INFO_PRINTF1(_L("Create a client entity with a 32 byte name - should pass"));
   456 	ce = CClientEntity::NewLC(K32Bytes);
   457 	ASSERT_TRUE(ce->Name() == K32Bytes);
   458 	CleanupStack::PopAndDestroy(ce);
   459 	
   460 	CleanupStack::PopAndDestroy(bigBuffer);
   461 	}
   462 
   463 void CTestPlugins::TestPluginManagerL()
   464 /**
   465  Creates and destroy UPS plug-ins to test CPluginManager.
   466  */
   467 	{
   468 	TInt uidVal;
   469 	CPluginManager* pluginManager = CPluginManager::NewL();
   470 	CleanupStack::PushL(pluginManager);
   471 	
   472 	CPlugin<CPolicyEvaluator>* policyEvaluator(0);
   473 	CPlugin<CDialogCreator>* dialogCreator(0);	
   474 	
   475 	ASSERT_TRUE(iConfig.GetHex(_L("pluginmanager"),_L("policyevaluatoruid"), uidVal));
   476 	TUid policyEvaluatorUid = TUid::Uid(uidVal);
   477 	
   478 	ASSERT_TRUE(iConfig.GetHex(_L("pluginmanager"),_L("dialogcreatoruid"), uidVal));
   479 	TUid dialogCreatorUid = TUid::Uid(uidVal);
   480 	
   481 	if (! iOom) INFO_PRINTF1(_L("Calling unload with no active plug-ins"));
   482 	pluginManager->Unload();
   483 	ASSERT_EQUALS(pluginManager->iPluginCount, 0);
   484 
   485 	if (! iOom) INFO_PRINTF1(_L("Calling unload after creating and destroying a plug-in"));
   486 	policyEvaluator = pluginManager->CreateEvaluatorL(policyEvaluatorUid);	
   487 	ASSERT_EQUALS(pluginManager->iPluginCount, 1);
   488 	delete policyEvaluator;
   489 	ASSERT_EQUALS(pluginManager->iPluginCount, 0);
   490 	pluginManager->Unload();
   491 	ASSERT_EQUALS(pluginManager->iPluginCount, 0);
   492 	
   493 	if (! iOom) INFO_PRINTF1(_L("Calling unload after deleting last plug-in"));
   494 	policyEvaluator = pluginManager->CreateEvaluatorL(policyEvaluatorUid);	
   495 	ASSERT_EQUALS(pluginManager->iPluginCount, 1);
   496 	delete policyEvaluator;
   497 	ASSERT_EQUALS(pluginManager->iPluginCount, 0);
   498 	policyEvaluator = pluginManager->CreateEvaluatorL(policyEvaluatorUid);	
   499 	ASSERT_EQUALS(pluginManager->iPluginCount, 1);
   500 	pluginManager->Unload();
   501 	ASSERT_EQUALS(pluginManager->iPluginCount, 1);	
   502 	delete policyEvaluator;
   503 	ASSERT_EQUALS(pluginManager->iPluginCount, 0);
   504 	
   505 	INFO_PRINTF1(_L("Policy evaluators and dialog creators"));
   506 	policyEvaluator = pluginManager->CreateEvaluatorL(policyEvaluatorUid);	
   507 	ASSERT_EQUALS(pluginManager->iPluginCount, 1);
   508 	CleanupStack::PushL(policyEvaluator);
   509 	pluginManager->Unload();
   510 	ASSERT_EQUALS(pluginManager->iPluginCount, 1);
   511 	dialogCreator = pluginManager->CreateDialogCreatorL(dialogCreatorUid);	
   512 	ASSERT_EQUALS(pluginManager->iPluginCount, 2);
   513 	CleanupStack::PushL(dialogCreator);
   514 	CleanupStack::PopAndDestroy(2, policyEvaluator); // dialogCreator	
   515 	ASSERT_EQUALS(pluginManager->iPluginCount, 0);
   516 	
   517 	CleanupStack::PopAndDestroy(pluginManager);
   518 	}
   519 
   520 TBool CTestPlugins::DoOomRequestL(const TExpectedValue& aExpected, const CPromptRequest& aRequest)
   521 /**
   522 	Performs OOM test
   523  */
   524 	{
   525 	TBool passed = EFalse;
   526 	
   527 	TInt countAfter = 0;
   528 	TInt countBefore = 0;
   529 	for (TInt oomCount = 0; ; oomCount++)
   530 		{
   531 		INFO_PRINTF2(_L("\n ==== Number of memory allocations %d ===="), oomCount);
   532 		passed = EFalse;
   533 		__UHEAP_RESET;
   534 		__UHEAP_SETFAIL(RHeap::EDeterministic, oomCount);
   535 		countBefore = User::CountAllocCells();
   536 		TRAPD(error, DoRequestL(aExpected, aRequest));// ----> This is the actual test that runs under OOM conditions.
   537 		countAfter = User::CountAllocCells();
   538 		__UHEAP_RESET;
   539 		
   540 		ASSERT_TRUE(error == KErrNone || error == KErrNoMemory);
   541 		
   542 		if (error == KErrNone)
   543 			{
   544 			passed = ETrue;
   545 			INFO_PRINTF2(_L("OOM Status %d"),error);
   546 			INFO_PRINTF1(_L("Test outcome : Passed"));
   547 			break;
   548 			}
   549 		else
   550 			{
   551 			if (countBefore != countAfter)
   552 				{
   553 				INFO_PRINTF2(_L("OOM Status %d"),error);
   554 				INFO_PRINTF2(_L("OOM Failed at %d"), oomCount);
   555 				break;
   556 				}
   557 			}
   558 		INFO_PRINTF2(_L("OOM Failed Point status %d"), error);
   559 		}
   560 	INFO_PRINTF3(_L("Heap alloc count ok: %d final vs %d initial"), countAfter,countBefore);
   561 	return passed;
   562 	}