persistentstorage/centralrepository/test/t_oomcenrepsrv.cpp
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2005-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 // t_oomcenrep.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "t_cenrep_helper.h"
       
    19 #include <e32test.h>
       
    20 #include <f32file.h>
       
    21 #include <utf.h>
       
    22 #include "srvsess.h"
       
    23 #include "sessmgr.h"
       
    24 #include "srvres.h"
       
    25 #include "srvreqs.h"
       
    26 #include "cachemgr.h"
       
    27 #include "clientrequest.h"
       
    28 #include "install.h"
       
    29 #include <bautils.h>
       
    30 
       
    31 LOCAL_D RFs					TheFs;
       
    32 LOCAL_D RTest				TheTest (_L ("t_oomcenrep.exe"));
       
    33 
       
    34 #ifdef __SECURE_DATA__
       
    35 _LIT(KInstallDirFile,			"c:\\private\\10202BE9\\persists\\installdir.bin");
       
    36 
       
    37 _LIT(KPersistsFile,				"c:\\private\\10202BE9\\persists\\11111111.cre");
       
    38 _LIT(KInstallPersistsFile,		"c:\\private\\10202BE9\\persists\\11111110.cre");
       
    39 _LIT(KPersistsFileNoUpgrade,	"c:\\private\\10202BE9\\bur\\11111111.crn");
       
    40 _LIT(KPersistsFileUpgraded,		"c:\\private\\10202BE9\\bur\\11111111.cru");
       
    41 
       
    42 _LIT(KRomUpgradeRev1File,		"z:\\private\\10202BE9\\11111111.txu");
       
    43 _LIT(KRomUpgradeRev2File,		"z:\\private\\10202BE9\\11111112.txu");
       
    44 _LIT(KUpgradeFile,				"c:\\private\\10202BE9\\11111111.txt");
       
    45 
       
    46 _LIT(KInstallOnlyFile,			"z:\\private\\10202BE9\\11111110.cri");
       
    47 _LIT(KInstallOnlyUpgradeFile,	"z:\\private\\10202BE9\\11111110.cru");
       
    48 _LIT(KInstallFile,				"c:\\private\\10202BE9\\11111110.cre");
       
    49 
       
    50 #else
       
    51 _LIT(KPersistsFiles, 			"c:\\system\\data\\cenrep\\persists\\*.*");
       
    52 #endif
       
    53 
       
    54 
       
    55 //Test repositories Uid
       
    56 const TUid KTestRepositoryUid={0x11111111};
       
    57 const TUid KCorruptRepositoryUid={0xBADBADBB};
       
    58 
       
    59 static TUid KCurrentTestUid;
       
    60 
       
    61 ///////////////////////////////////////////////////////////////////////////////////////
       
    62 //Test macroses and functions
       
    63 LOCAL_C void CheckL(TInt aValue, TInt aLine)
       
    64 	{
       
    65 	if(!aValue)
       
    66 		{
       
    67 		RDebug::Print(_L("Error\r\n"));
       
    68 		CleanupCDriveL();
       
    69 		TheTest(EFalse, aLine);
       
    70 		}
       
    71 	}
       
    72 LOCAL_C void CheckL(TInt aValue, TInt aExpected, TInt aLine)
       
    73 	{
       
    74 	if(aValue != aExpected)
       
    75 		{
       
    76 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
       
    77 		CleanupCDriveL();
       
    78 		TheTest(EFalse, aLine);
       
    79 		}
       
    80 	}
       
    81 #define TESTL(arg) ::CheckL((arg), __LINE__)
       
    82 #define TEST2L(aValue, aExpected) ::CheckL(aValue, aExpected, __LINE__)
       
    83 #define TESTKErrNoneL(aValue) ::CheckL(aValue,0,__LINE__);
       
    84 
       
    85 /////////////////////////////////////////////////////////////////////////////////////////
       
    86 class CenrepSrvOOMTest :public CBase
       
    87 {
       
    88 public:
       
    89 	void GetL();
       
    90 	void FindL();
       
    91 	void ResetL();
       
    92 	void NotifyL();
       
    93 	void SetL();
       
    94 	void CreateL();
       
    95 	void DeleteL();
       
    96 	void MoveL();
       
    97 
       
    98 	CenrepSrvOOMTest();
       
    99 	~CenrepSrvOOMTest();
       
   100 	static CenrepSrvOOMTest* NewL();
       
   101 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
       
   102 	void DoHeapRepositoryContentCheckL();
       
   103 #endif
       
   104 private:
       
   105 	void ConstructL();
       
   106 public:
       
   107 	CServerRepository* iServerRepo;
       
   108 	CSessionNotifier* iSessionNotif;
       
   109 };
       
   110 
       
   111 //////////////////////////////////////////////////////////////////////////////////////////////////
       
   112 class CenrepSwiOOMTest :public CBase
       
   113 {
       
   114 public:
       
   115 	void UpgradeROMRev1L(TBool aIsSetup);
       
   116 	void UpgradeROMRev2L(TBool aIsSetup);
       
   117 	void UninstallROMUpgradeL(TBool aIsSetup);
       
   118 
       
   119 	void InstallL(TBool aIsSetup);
       
   120 	void UpgradeInstallL(TBool aIsSetup);
       
   121 	void UninstallL(TBool aIsSetup);
       
   122 
       
   123 	CenrepSwiOOMTest();
       
   124 	~CenrepSwiOOMTest();
       
   125 	static CenrepSwiOOMTest* NewL();
       
   126 private:
       
   127 	void ConstructL();
       
   128 	CCentRepSWIWatcher* iSwiWatcher;
       
   129 public:
       
   130 };
       
   131 //////////////////////////////////////////////////////////////////////////////////////////////////
       
   132 
       
   133 CenrepSrvOOMTest::CenrepSrvOOMTest(){}
       
   134 
       
   135 CenrepSrvOOMTest::~CenrepSrvOOMTest()
       
   136 	{
       
   137 	if (iServerRepo)
       
   138 		{
       
   139 		if (iSessionNotif)
       
   140 			{
       
   141 			iServerRepo->Close();
       
   142 			}
       
   143 		delete iServerRepo;
       
   144 		}
       
   145 	if (iSessionNotif)
       
   146 		delete iSessionNotif;
       
   147 
       
   148 	// Cache must be disabled here. Otherwise, if any idle repositories exists, they will
       
   149 	// still be open (have their pointers in the iOpenRepositories list) and the list will leak.
       
   150 	TServerResources::iCacheManager->DisableCache();
       
   151 	TServerResources::iObserver->CloseiOpenRepositories();
       
   152 	}
       
   153 
       
   154 CenrepSrvOOMTest* CenrepSrvOOMTest::NewL()
       
   155 	{
       
   156 	CenrepSrvOOMTest* self=new (ELeave)CenrepSrvOOMTest;
       
   157 	CleanupStack::PushL(self);
       
   158 	self->ConstructL();
       
   159 	CleanupStack::Pop(self);
       
   160 	return self;
       
   161 	}
       
   162 
       
   163 void CenrepSrvOOMTest::ConstructL()
       
   164 	{
       
   165 	iServerRepo=new (ELeave)CServerRepository();
       
   166 	iSessionNotif=new (ELeave) CSessionNotifier();
       
   167 
       
   168 	iServerRepo->OpenL(KCurrentTestUid,*iSessionNotif);
       
   169 	}
       
   170 
       
   171 //////////////////////////////////////////////////////////////////////////////////////////////////
       
   172 
       
   173 CenrepSwiOOMTest::CenrepSwiOOMTest(){}
       
   174 
       
   175 CenrepSwiOOMTest::~CenrepSwiOOMTest()
       
   176 	{
       
   177 	delete iSwiWatcher;
       
   178 	}
       
   179 
       
   180 CenrepSwiOOMTest* CenrepSwiOOMTest::NewL()
       
   181 	{
       
   182 	CenrepSwiOOMTest* self=new (ELeave)CenrepSwiOOMTest;
       
   183 	CleanupStack::PushL(self);
       
   184 	self->ConstructL();
       
   185 	CleanupStack::Pop(self);
       
   186 	return self;
       
   187 	}
       
   188 
       
   189 void CenrepSwiOOMTest::ConstructL()
       
   190 	{
       
   191 	iSwiWatcher = CCentRepSWIWatcher::NewL(TServerResources::iFs);
       
   192 	}
       
   193 
       
   194 //Getting various information and security policy from the repository
       
   195 //TInt 				CServerRepository::Get(TUint32 aId,T& aVal)
       
   196 //TServerSetting* 	CServerRepository::GetSetting(TUint32 aId)
       
   197 void CenrepSrvOOMTest::GetL()
       
   198 	{
       
   199 	TInt err=KErrNone;
       
   200 	TInt keyInt=0;
       
   201 	TServerSetting* srvsetting;
       
   202 	//----------Getting the TInt(1-15)-----------------------------
       
   203 	for (TInt i=1;i<=15;i++)
       
   204 		{
       
   205 		err=iServerRepo->Get(i,keyInt);
       
   206 		//Remember the policy check is done at the session level
       
   207 		TESTKErrNoneL(err);
       
   208 		TESTL(i==keyInt);
       
   209 		srvsetting=iServerRepo->GetSetting(i);
       
   210 		TESTL(srvsetting->Key()==static_cast<TUint32>(i));
       
   211 		}
       
   212 	//---------Getting the TReal(16-19)---------------------------
       
   213 	TReal keyValue;
       
   214 	err=iServerRepo->Get(16,keyValue);
       
   215 	TESTKErrNoneL(err);
       
   216 	TESTL(keyValue==10.1010);
       
   217 	srvsetting=iServerRepo->GetSetting(16);
       
   218 	TESTL(srvsetting->Key()==16);
       
   219 
       
   220 	err=iServerRepo->Get(19,keyValue);
       
   221 	TESTKErrNoneL(err);
       
   222 	TESTL(keyValue==13.1313);
       
   223 
       
   224 	//----------Getting the String(20-23)-----------------------
       
   225 	TBuf8<50> keyString;
       
   226 	_LIT(KFourteen,"fourteen");
       
   227 	err=iServerRepo->Get(20,keyString);
       
   228 	TESTKErrNoneL(err);
       
   229 	//Even ascii(8 bytes) are stored as 16 bytes!!!
       
   230 	TPtr16 str16((TUint16*) keyString.Ptr(),keyString.Length()/2,keyString.Length()/2);
       
   231 	TESTL(str16.Compare(KFourteen)==0);
       
   232 	srvsetting=iServerRepo->GetSetting(20);
       
   233 	TESTL(srvsetting->Key()==20);
       
   234 
       
   235 	//---------Getting the String8(0x79)------------------------
       
   236 	TBuf8<50> keyString8;
       
   237 	_LIT8(KString8,"string8");
       
   238 	err=iServerRepo->Get(0x79,keyString8);
       
   239 	TESTKErrNoneL(err);
       
   240 	TESTL(keyString8.Compare(KString8)==0);
       
   241 	srvsetting=iServerRepo->GetSetting(0x79);
       
   242 	TESTL(srvsetting->Key()==0x79);
       
   243 
       
   244 	//---------Getting the binary(0x82)-------------------------
       
   245 	TBuf8<50> keyBinary;
       
   246 	_LIT8(KBinary8,"\x12\x34\xAB\xCD");
       
   247 	err=iServerRepo->Get(0x82,keyBinary);
       
   248 	TESTKErrNoneL(err);
       
   249 	//temporarily added to solve coverage problem in WINSCW
       
   250 #ifdef __EPOC32__
       
   251 	TESTL(keyBinary.Compare(KBinary8)==0);
       
   252 #endif
       
   253 	srvsetting=iServerRepo->GetSetting(0x82);
       
   254 	TESTL(srvsetting->Key()==0x82);
       
   255 
       
   256 	//----------Getting individual policy-----------------------
       
   257 	//Current Exe has caps AllFiles+WriteDeviceData+ReadDeviceData
       
   258 	RThread currentThread;
       
   259 	TSecurityPolicy secPolicy;
       
   260 	//default policy
       
   261 	secPolicy=iServerRepo->GetDefaultReadAccessPolicy();
       
   262 	TESTL(secPolicy.CheckPolicy(currentThread)==1);
       
   263 	secPolicy=iServerRepo->GetDefaultWriteAccessPolicy();
       
   264 	TESTL(secPolicy.CheckPolicy(currentThread)==1);
       
   265 
       
   266 	//check settings policies
       
   267 	//0x2 int 2 1 cap_rd=CommDD cap_wr=WriteDeviceData
       
   268 	//0x19 int 25 0 //defined in range policies with cap_rd=NetworkServices
       
   269 	secPolicy=iServerRepo->GetReadAccessPolicy(2);
       
   270 	TESTL(secPolicy.CheckPolicy(currentThread)==0);
       
   271 	secPolicy=iServerRepo->GetWriteAccessPolicy(2);
       
   272 	TESTL(secPolicy.CheckPolicy(currentThread)==1);
       
   273 	secPolicy=iServerRepo->GetReadAccessPolicy(25);
       
   274 	TESTL(secPolicy.CheckPolicy(currentThread)==0);
       
   275 
       
   276 	}
       
   277 
       
   278 // now that write operations must be done in transactions, setting up this helper
       
   279 // function to perform single Sets for the purpose of this test.
       
   280 template<class T>
       
   281 static TInt RepositorySingleSetL(CServerRepository& aRep, TUint32 aKey, const T& aValue)
       
   282 	{
       
   283 	aRep.StartTransaction(EConcurrentReadWriteTransaction);
       
   284 	aRep.CleanupCancelTransactionPushL();
       
   285 	aRep.TransactionSetL(aKey, aValue);
       
   286 	CleanupStack::Pop();
       
   287 	TUint32 keyInfo;
       
   288 	return User::LeaveIfError(aRep.CommitTransaction(keyInfo));
       
   289 	};
       
   290 
       
   291 //Setting OOM testing
       
   292 void CenrepSrvOOMTest::SetL()
       
   293 	{
       
   294 	TInt ret=KErrNone;
       
   295 	TInt intValue=0;
       
   296 	TReal realValue=0;
       
   297 
       
   298 	//---------------SetL-----------------------------------
       
   299 	//Setting an integer key
       
   300 	ret = RepositorySingleSetL(*iServerRepo, 0x60, 600);
       
   301 	TESTKErrNoneL(ret);
       
   302 	ret=iServerRepo->Get(0x60,intValue);
       
   303 	TESTL(intValue== 600);
       
   304 
       
   305 	//Setting a real key
       
   306 	ret = RepositorySingleSetL(*iServerRepo, 0x66, 99.99);
       
   307 	TESTKErrNoneL(ret);
       
   308 	ret=iServerRepo->Get(0x66,realValue);
       
   309 	TESTL(realValue==99.99);
       
   310 
       
   311 	//Setting a string key
       
   312 	//Even ascii(8 bytes) are stored as 16 bytes!!!
       
   313 	_LIT8(KString,"sixhundred");
       
   314 	TBuf8<50> stringChangeValue=KString();
       
   315 	ret = RepositorySingleSetL(*iServerRepo, 0x69, stringChangeValue);
       
   316 	TESTKErrNoneL(ret);
       
   317 
       
   318 	TBuf8<50> keyString;
       
   319 	ret=iServerRepo->Get(0x69,keyString);
       
   320 	TESTKErrNoneL(ret);
       
   321 	TESTL(keyString.Compare(KString)==0);
       
   322 	}
       
   323 
       
   324 // now that write operations must be done in transactions, setting up this helper
       
   325 // function to perform single Creates for the purpose of this test.
       
   326 template<class T>
       
   327 static TInt RepositorySingleCreateL(CServerRepository& aRep, TUint32 aKey, const T& aValue, TUint32* aMeta)
       
   328 	{
       
   329 	aRep.StartTransaction(EConcurrentReadWriteTransaction);
       
   330 	aRep.CleanupCancelTransactionPushL();
       
   331 	aRep.TransactionCreateL(aKey, aValue, aMeta);
       
   332 	CleanupStack::Pop();
       
   333 	TUint32 keyInfo;
       
   334 	return User::LeaveIfError(aRep.CommitTransaction(keyInfo));
       
   335 	};
       
   336 
       
   337 void CenrepSrvOOMTest::CreateL()
       
   338 	{
       
   339 	TInt ret=KErrNone;
       
   340 	TInt intValue=0;
       
   341 	TReal realValue=0;
       
   342 
       
   343 	//--------------CreateL-----------------------------------
       
   344 	//Creating an integer key
       
   345 	TInt intRetValue;
       
   346 	intValue=9000;
       
   347 	RepositorySingleCreateL(*iServerRepo, 0x90, intValue, NULL);
       
   348 	TESTKErrNoneL(ret);
       
   349 	ret=iServerRepo->Get(0x90,intRetValue);
       
   350 	TESTKErrNoneL(ret);
       
   351 	TESTL(intRetValue==intValue);
       
   352 
       
   353 	//Creating a real key
       
   354 	TReal realRetValue;
       
   355 	realValue=33.3333;
       
   356 	RepositorySingleCreateL(*iServerRepo, 0x92, realValue, NULL);
       
   357 	TESTKErrNoneL(ret);
       
   358 	ret=iServerRepo->Get(0x92,realRetValue);
       
   359 	TESTKErrNoneL(ret);
       
   360 	TESTL(realValue==realRetValue);
       
   361 
       
   362 	//Creating a string key
       
   363 	_LIT8(KStringValue,"creatingkey");
       
   364 	TBuf8<50> stringCreateValue=KStringValue();
       
   365 	RepositorySingleCreateL(*iServerRepo, 0x93, stringCreateValue, NULL);
       
   366 	TESTKErrNoneL(ret);
       
   367 	}
       
   368 
       
   369 // now that write operations must be done in transactions, setting up this helper
       
   370 // function to perform single Creates for the purpose of this test.
       
   371 static TInt RepositorySingleDeleteL(CServerRepository& aRep, TUint32 aKey)
       
   372 	{
       
   373 	aRep.StartTransaction(EConcurrentReadWriteTransaction);
       
   374 	aRep.CleanupCancelTransactionPushL();
       
   375 	aRep.TransactionDeleteL(aKey);
       
   376 	CleanupStack::Pop();
       
   377 	TUint32 keyInfo;
       
   378 	return User::LeaveIfError(aRep.CommitTransaction(keyInfo));
       
   379 	};
       
   380 
       
   381 void CenrepSrvOOMTest::DeleteL()
       
   382 	{
       
   383 	TInt ret=KErrNone;
       
   384 	//--------------Delete-----------------------------------
       
   385 	//Find the settings 0x10A-0x10C to ensure it is still there
       
   386 	RSettingPointerArray matchingArray;
       
   387 	TUint32 partialId=0x100;
       
   388 	TUint32 idMask=0xFFFFFFF0;
       
   389 	ret=iServerRepo->FindSettings(partialId,idMask,matchingArray);
       
   390 	if (ret==KErrNoMemory)
       
   391 		{
       
   392 		matchingArray.Close();
       
   393 		User::LeaveNoMemory();
       
   394 		}
       
   395 
       
   396 	TESTKErrNoneL(ret);
       
   397 	TESTL(matchingArray.Count()==3);
       
   398 	matchingArray.Close();
       
   399 
       
   400 	//Deleting settings 0x10A to 0x10C
       
   401 	for (TInt i=0x10A;i<=0x10C;i++)
       
   402 		{
       
   403 		RepositorySingleDeleteL(*iServerRepo, i);
       
   404 		TESTKErrNoneL(ret);
       
   405 		}
       
   406 	//After deleting try to find the persistent settings again
       
   407 	ret=iServerRepo->FindSettings(partialId,idMask,matchingArray);
       
   408 	if (ret==KErrNoMemory)
       
   409 		{
       
   410 		matchingArray.Close();
       
   411 		User::LeaveNoMemory();
       
   412 		}
       
   413 	TESTKErrNoneL(ret);
       
   414 	TESTL(matchingArray.Count()==0);
       
   415 	matchingArray.Close();
       
   416 
       
   417 	//-------------DeleteRange---------------------------------
       
   418 	//Deleting settings 0x1 to 0xF
       
   419 	TClientRequest dummyrequest;
       
   420 	TUint32 errId=0;
       
   421 	partialId=0;
       
   422 	idMask=0xFFFFFFF0;
       
   423 	ret=iServerRepo->FindSettings(partialId,idMask,matchingArray);
       
   424 	if (ret==KErrNoMemory)
       
   425 		{
       
   426 		matchingArray.Close();
       
   427 		User::LeaveNoMemory();
       
   428 		}
       
   429 	TESTKErrNoneL(ret)	;
       
   430 	TESTL(matchingArray.Count()==15);
       
   431 	matchingArray.Close();
       
   432 
       
   433 	//Deleting settings using the DeleteRange
       
   434 	dummyrequest.SetParam(0,partialId);
       
   435 	dummyrequest.SetParam(1,idMask);
       
   436 	dummyrequest.SetPolicyCheck(ETrue);
       
   437 
       
   438 	// write operation must take place in a transaction
       
   439 	iServerRepo->StartTransaction(EConcurrentReadWriteTransaction);
       
   440 	iServerRepo->CleanupCancelTransactionPushL();
       
   441 	iServerRepo->TransactionDeleteRangeL(dummyrequest,errId);
       
   442 	CleanupStack::Pop();
       
   443 	TUint32 keyInfo;
       
   444 	User::LeaveIfError(iServerRepo->CommitTransaction(keyInfo));
       
   445 
       
   446 	//Now try to find the key being deleted
       
   447 	ret=iServerRepo->FindSettings(partialId,idMask,matchingArray);
       
   448 	if (ret==KErrNoMemory)
       
   449 		{
       
   450 		matchingArray.Close();
       
   451 		User::LeaveNoMemory();
       
   452 		}
       
   453 	TESTKErrNoneL(ret);
       
   454 	TESTL(matchingArray.Count()==0);
       
   455 	matchingArray.Close();
       
   456 	}
       
   457 
       
   458 //Setting existing key value then follow by commit
       
   459 void CenrepSrvOOMTest::MoveL()
       
   460 	{
       
   461 	RSettingPointerArray matchingArray;
       
   462 	TUint32 idMask=0xFFFFFFF0;
       
   463 
       
   464 	/*---------------MoveL-------------------------------------
       
   465 	TUint32 sourcePartialId = aMessage.Int0();
       
   466 	TUint32 targetPartialId = aMessage.Int1();
       
   467 	TUint32 idMask = aMessage.Int2();
       
   468 	*/
       
   469 	TClientRequest dummyrequest;
       
   470 	TUint32 errId=0;
       
   471 	TUint32 sourcePartialId=0x110;
       
   472 	TUint32 targetPartialId=0x120;
       
   473 	idMask=0xFFFFFFF0;
       
   474 
       
   475 	TKeyFilter srcKeyIdentifier = {sourcePartialId, idMask};
       
   476 	TPckg<TKeyFilter> pSrcIdentifier(srcKeyIdentifier);
       
   477 	TKeyFilter tgtKeyIdentifier = {targetPartialId, idMask};
       
   478 	TPckg<TKeyFilter> pTgtIdentifier(tgtKeyIdentifier);
       
   479 
       
   480 	//First check to ensure the target key before move does not exist
       
   481 	User::LeaveIfError(iServerRepo->FindSettings(targetPartialId,idMask,matchingArray));
       
   482 	TESTL(matchingArray.Count()==0);
       
   483 	matchingArray.Close();
       
   484 
       
   485 	//moving from 0x110(0x11B,0x11C,0x11E) to 0x120
       
   486 	dummyrequest.SetParam(0, &pSrcIdentifier);
       
   487 	dummyrequest.SetParam(1, &pTgtIdentifier);
       
   488 	dummyrequest.SetPolicyCheck(ETrue);
       
   489 
       
   490 	// write operation must take place in a transaction
       
   491 	iServerRepo->StartTransaction(EConcurrentReadWriteTransaction);
       
   492 	iServerRepo->CleanupCancelTransactionPushL();
       
   493 	iServerRepo->TransactionMoveL(dummyrequest,errId);
       
   494 	CleanupStack::Pop();
       
   495 	TUint32 keyInfo;
       
   496 	User::LeaveIfError(iServerRepo->CommitTransaction(keyInfo));
       
   497 
       
   498 	//Now try to find the key being moved
       
   499 	User::LeaveIfError(iServerRepo->FindSettings(targetPartialId,idMask,matchingArray));
       
   500 	TESTL(matchingArray.Count()==3);
       
   501 	matchingArray.Close();
       
   502 	}
       
   503 
       
   504 //Finding keys from the settings
       
   505 //TInt FindSettings(TUint32 aPartialId,TUint32 aIdMask,RSettingPointerArray& aMatches)
       
   506 //Guarantees the heap free in aMatches if this function fail
       
   507 void CenrepSrvOOMTest::FindL()
       
   508 	{
       
   509 	TInt ret=KErrNone;
       
   510 	RSettingPointerArray foundIdArray;
       
   511 	TUint32 partialId=0;
       
   512 	TUint32 idMask=0;
       
   513 	//-----------Finding settings array using partial id & mask------
       
   514 
       
   515 	//------------------Real type---------------------------------
       
   516 	//0x42,0x44,0x45,0x48
       
   517 	partialId=0x40;
       
   518 	idMask=0xFFFFFFF0;
       
   519 	User::LeaveIfError(iServerRepo->FindSettings(partialId,idMask,foundIdArray));
       
   520 	TESTKErrNoneL(ret);
       
   521 	TESTL(foundIdArray.Count()==4);
       
   522 	foundIdArray.Close();
       
   523 
       
   524 	//-----------------String type-------------------------------
       
   525 	//0x51,0x54,0x5B
       
   526 	partialId=0x50;
       
   527 	idMask=0xFFFFFFF0;
       
   528 	User::LeaveIfError(iServerRepo->FindSettings(partialId,idMask,foundIdArray));
       
   529 	TESTKErrNoneL(ret);
       
   530 	TESTL(foundIdArray.Count()==3);
       
   531 	foundIdArray.Close();
       
   532 
       
   533 	//--------------------Int type----------------------------------------------------
       
   534 	partialId=0x30;
       
   535 	idMask=0xFFFFFFF0;
       
   536 	//This should return only 0x30,0x34,0x35,0x39,0x3B( 5 items)
       
   537 	User::LeaveIfError(iServerRepo->FindSettings(partialId,idMask,foundIdArray));
       
   538 	TESTKErrNoneL(ret);
       
   539 	TESTL(foundIdArray.Count()==5);
       
   540 
       
   541 	//----------------Find comparison using EEqual & ENotEqual------------------------
       
   542 	TInt searchValue=100;
       
   543 	TClientRequest dummyrequest;
       
   544 	RArray<TUint32> idArray;
       
   545 	//Set the policycheck to always pass
       
   546 	dummyrequest.SetPolicyCheck(ETrue);
       
   547 	//Comparison using Equal
       
   548 	TRAP(ret,iServerRepo->FindCompareL(foundIdArray,searchValue,EEqual,idArray));
       
   549 	if (ret==KErrNoMemory)
       
   550 		{
       
   551 		//do not need to reset idArray as it is done inside the function itself when it returns not KErrNone
       
   552 		foundIdArray.Close();
       
   553 		User::LeaveNoMemory();
       
   554 		}
       
   555 	TESTL(idArray.Count()==2);
       
   556 	TESTL((idArray[0]==0x30 && idArray[1]==0x34) || (idArray[0]==0x34 && idArray[1]==0x30));
       
   557 	idArray.Close();
       
   558 	//Comparison using ENotEqual
       
   559 	TRAP(ret,iServerRepo->FindCompareL(foundIdArray,searchValue,ENotEqual,idArray));
       
   560 	if (ret==KErrNoMemory)
       
   561 		{
       
   562 		//do not need to reset idArray as it is done inside the function itself when it returns not KErrNone
       
   563 		foundIdArray.Close();
       
   564 		User::LeaveNoMemory();
       
   565 		}
       
   566 	TESTL(idArray.Count()==3);
       
   567 	idArray.Close();
       
   568 	foundIdArray.Close();
       
   569 
       
   570 	}
       
   571 
       
   572 //Resetting settings
       
   573 void CenrepSrvOOMTest::ResetL()
       
   574 	{
       
   575 	TInt ret=KErrNone;
       
   576 	TInt retValue=0;
       
   577 	TReal realValue=0;
       
   578 
       
   579 	//-------------Single key reset----------------------------
       
   580 
       
   581 	ret = RepositorySingleSetL(*iServerRepo, 1, 500);
       
   582 	TESTKErrNoneL(ret);
       
   583 	ret=iServerRepo->Get(1,retValue);
       
   584 	TESTL(retValue==500);
       
   585 
       
   586 	//Resetting individual settings
       
   587 	ret=iServerRepo->ResetL(1);
       
   588 	TESTKErrNoneL(ret);
       
   589 
       
   590 	//Check for value once being reset
       
   591 	ret=iServerRepo->Get(1,retValue);
       
   592 	TESTL(retValue==1);
       
   593 
       
   594 	//------------All keys reset------------------------------
       
   595 	ret = RepositorySingleSetL(*iServerRepo, 17, 3.1343424);
       
   596 	TESTKErrNoneL(ret);
       
   597 
       
   598 	//Reset all settings from Rom
       
   599 	User::LeaveIfError(iServerRepo->ResetAllL());
       
   600 	TESTKErrNoneL(ret);
       
   601 
       
   602 	//Check for value once all being reset
       
   603 
       
   604 	ret=iServerRepo->Get(17,realValue);
       
   605 	TESTL(realValue==11.1111);
       
   606 	}
       
   607 
       
   608 void CenrepSrvOOMTest::NotifyL()
       
   609 	{
       
   610 	TInt err=KErrNone;
       
   611 
       
   612 	//addding individual requests
       
   613 	for (TInt i=0;i<10;i++)
       
   614 		{
       
   615 		TClientRequest dummyRequest;
       
   616 		User::LeaveIfError(iSessionNotif->AddRequest(i,dummyRequest));
       
   617 		}
       
   618 
       
   619 	//adding group requests
       
   620 	for (TInt i=0;i<10;i++)
       
   621 		{
       
   622 		TClientRequest dummyRequest;
       
   623 		TUint32 partialId=100*i;
       
   624 		TUint32 idMask=0xFFFFFFF0;
       
   625 		User::LeaveIfError(iSessionNotif->AddRequest(partialId,idMask,dummyRequest));
       
   626 		}
       
   627 
       
   628 	//cancelling individual requests
       
   629 	User::LeaveIfError(iSessionNotif->CancelRequest(5));
       
   630 	//Check to ensure that it has been deleted so calling cancel again will return KErrNotFound
       
   631 	err=iSessionNotif->CancelRequest(5);
       
   632 	TESTL(err==KErrNotFound);
       
   633 
       
   634 	//cancelling group requests
       
   635 	User::LeaveIfError(iSessionNotif->CancelRequest(500,0xFFFFFFF0));
       
   636 	err=iSessionNotif->CancelRequest(500,0xFFFFFF0);
       
   637 	TESTL(err==KErrNotFound);
       
   638 
       
   639 	//Finally cancel ALL requests
       
   640 	iSessionNotif->CancelAllRequests();
       
   641 
       
   642 	}
       
   643 
       
   644 //Deletes the CServerRepository object properly
       
   645 LOCAL_C void ReleaseRepository(TAny* aServerRepository)
       
   646 	{
       
   647 	CServerRepository* serverRepository = static_cast<CServerRepository*>(aServerRepository);
       
   648 
       
   649 	TServerResources::iCacheManager->DisableCache();
       
   650 	TServerResources::iObserver->CloseiOpenRepositories();
       
   651 	delete serverRepository;
       
   652 	TServerResources::iCacheManager->EnableCache();
       
   653 	}
       
   654 
       
   655 //Opening a repository and closing the repository
       
   656 LOCAL_C void CreateDeleteL(TBool /*aOOMMode*/)
       
   657 {
       
   658 	CServerRepository* serverRepo=new (ELeave)CServerRepository();
       
   659 	TCleanupItem cleanupItem(&ReleaseRepository, serverRepo);
       
   660 	CleanupStack::PushL(cleanupItem);
       
   661 
       
   662 	CSessionNotifier* sessNotif=new (ELeave)CSessionNotifier();
       
   663 	CleanupStack::PushL(sessNotif);
       
   664 
       
   665 // 	test access to a valid repository
       
   666 	serverRepo->OpenL(KCurrentTestUid,*sessNotif);
       
   667 	serverRepo->Close();
       
   668 
       
   669 	CleanupStack::PopAndDestroy(sessNotif);
       
   670 	CleanupStack::PopAndDestroy(1);
       
   671 }
       
   672 
       
   673 LOCAL_C void CreateDeleteCorruptL(TBool /*aOOMMode*/)
       
   674 {
       
   675 	CServerRepository* serverRepo=new (ELeave)CServerRepository();
       
   676 	TCleanupItem cleanupItem(&ReleaseRepository, serverRepo);
       
   677 	CleanupStack::PushL(cleanupItem);
       
   678 
       
   679 	CSessionNotifier* sessNotif=new (ELeave)CSessionNotifier();
       
   680 	CleanupStack::PushL(sessNotif);
       
   681 
       
   682 // 	test access to a corrupt repository
       
   683 	// trap KErrCorrupt
       
   684 	TRAPD(err, serverRepo->OpenL(KCorruptRepositoryUid,*sessNotif));
       
   685 	// leave if not KErrCorrupt
       
   686 	User::LeaveIfError((err == KErrCorrupt) ? KErrNone : err);
       
   687 	serverRepo->Close();
       
   688 
       
   689 	CleanupStack::PopAndDestroy(sessNotif);
       
   690 	CleanupStack::PopAndDestroy(1);
       
   691 }
       
   692 
       
   693 void CenrepSwiOOMTest::UpgradeROMRev1L(TBool aIsSetup)
       
   694 	{
       
   695 	if(aIsSetup)
       
   696 		{
       
   697 		RFs fs;
       
   698 		User::LeaveIfError(fs.Connect());
       
   699 		CleanupClosePushL(fs);
       
   700 		CFileMan* fm = CFileMan::NewL(fs);
       
   701 		CleanupStack::PushL(fm);
       
   702 
       
   703 		// Copy rev 1 file into install dir & Reset read-only bit
       
   704 		User::LeaveIfError(fm->Copy(KRomUpgradeRev1File, KUpgradeFile));
       
   705 		User::LeaveIfError(fm->Attribs(KUpgradeFile,0,KEntryAttReadOnly,TTime(0)));
       
   706 		CleanupStack::PopAndDestroy(2); // fs and fm
       
   707 		}
       
   708 	else
       
   709 		{
       
   710 		iSwiWatcher->HandleSWIEventL(ESASwisInstall | ESASwisStatusSuccess);
       
   711 		}
       
   712 	}
       
   713 
       
   714 LOCAL_C void ModifyTimeStampL(RFs &fs, TDesC *fileName, TTime aTime)
       
   715 	{
       
   716 	// Reset read-only bit
       
   717 	User::LeaveIfError(fs.SetAtt(*fileName, 0, KEntryAttReadOnly));
       
   718 	TTimeIntervalHours interval(1);
       
   719 	TTime newTime=aTime+interval;
       
   720 	User::LeaveIfError(fs.SetModified(*fileName, newTime));
       
   721 	}
       
   722 
       
   723 
       
   724 void CenrepSwiOOMTest::UpgradeROMRev2L(TBool aIsSetup)
       
   725 	{
       
   726 	if(aIsSetup)
       
   727 		{
       
   728 		// Set up rev 1
       
   729 		UpgradeROMRev1L(ETrue);
       
   730 		UpgradeROMRev1L(EFalse);
       
   731 
       
   732 		RFs fs;
       
   733 		User::LeaveIfError(fs.Connect());
       
   734 		CleanupClosePushL(fs);
       
   735 		CFileMan* fm = CFileMan::NewL(fs);
       
   736 		CleanupStack::PushL(fm);
       
   737 
       
   738 		// Get modification time
       
   739 		TTime time;
       
   740 		TBuf<50> fileName(KUpgradeFile);
       
   741 		fs.Modified(fileName, time);
       
   742 
       
   743 		// Copy rev2 file into install dir & Reset read-only bit
       
   744 		User::LeaveIfError(fm->Copy(KRomUpgradeRev2File, KUpgradeFile));
       
   745 		User::LeaveIfError(fm->Attribs(KUpgradeFile,0,KEntryAttReadOnly,TTime(0)));
       
   746 		// Modify timestamp to cause upgrade
       
   747 		ModifyTimeStampL(fs,&fileName, time);
       
   748 
       
   749 		CleanupStack::PopAndDestroy(2); // fs and fm
       
   750 		}
       
   751 	else
       
   752 		{
       
   753 		iSwiWatcher->HandleSWIEventL(ESASwisInstall | ESASwisStatusSuccess);
       
   754 		}
       
   755 
       
   756 	}
       
   757 
       
   758 void CenrepSwiOOMTest::UninstallROMUpgradeL(TBool aIsSetup)
       
   759 	{
       
   760 	if(aIsSetup)
       
   761 		{
       
   762 		// Install rev 2
       
   763 		UpgradeROMRev2L(ETrue);
       
   764 		UpgradeROMRev2L(EFalse);
       
   765 
       
   766 		RFs fs;
       
   767 		User::LeaveIfError(fs.Connect());
       
   768 		CleanupClosePushL(fs);
       
   769 		CFileMan* fm = CFileMan::NewL(fs);
       
   770 		CleanupStack::PushL(fm);
       
   771 
       
   772 		// Delete file from install dir
       
   773 		User::LeaveIfError(fm->Attribs(KUpgradeFile,0,KEntryAttReadOnly,TTime(0)));
       
   774 		TInt err=fs.Delete(KUpgradeFile);
       
   775 		if((err!=KErrNone)&&(err!=KErrNotFound))
       
   776 			User::Leave(err);
       
   777 
       
   778 		CleanupStack::PopAndDestroy(2); // fs and fm
       
   779 		}
       
   780 	else
       
   781 		{
       
   782 		iSwiWatcher->HandleSWIEventL(ESASwisUninstall | ESASwisStatusSuccess);
       
   783 		}
       
   784 	}
       
   785 
       
   786 void CenrepSwiOOMTest::InstallL(TBool aIsSetup)
       
   787 	{
       
   788 	if(aIsSetup)
       
   789 		{
       
   790 		RFs fs;
       
   791 		User::LeaveIfError(fs.Connect());
       
   792 		CleanupClosePushL(fs);
       
   793 		CFileMan* fm = CFileMan::NewL(fs);
       
   794 		CleanupStack::PushL(fm);
       
   795 
       
   796 		// Copy rev 1 file into install dir & Reset read-only bit
       
   797 		User::LeaveIfError(fm->Copy(KInstallOnlyFile, KInstallFile));
       
   798 		User::LeaveIfError(fm->Attribs(KInstallFile,0,KEntryAttReadOnly,TTime(0)));
       
   799 
       
   800 		CleanupStack::PopAndDestroy(2); // fs and fm
       
   801 		}
       
   802 	else
       
   803 		{
       
   804 		iSwiWatcher->HandleSWIEventL(ESASwisInstall | ESASwisStatusSuccess);
       
   805 		}
       
   806 	}
       
   807 
       
   808 void CenrepSwiOOMTest::UpgradeInstallL(TBool aIsSetup)
       
   809 	{
       
   810 	if(aIsSetup)
       
   811 		{
       
   812 		// Install file
       
   813 		InstallL(ETrue);
       
   814 		InstallL(EFalse);
       
   815 
       
   816 		RFs fs;
       
   817 		User::LeaveIfError(fs.Connect());
       
   818 		CleanupClosePushL(fs);
       
   819 		CFileMan* fm = CFileMan::NewL(fs);
       
   820 		CleanupStack::PushL(fm);
       
   821 
       
   822 		// Get modification time
       
   823 		TTime time;
       
   824 		TBuf<50> fileName(KInstallFile);
       
   825 		fs.Modified(fileName, time);
       
   826 
       
   827 		// Copy upgrade file into install dir & Reset read-only bit
       
   828 		User::LeaveIfError(fm->Copy(KInstallOnlyUpgradeFile, KInstallFile));
       
   829 		User::LeaveIfError(fm->Attribs(KInstallFile,0,KEntryAttReadOnly,TTime(0)));
       
   830 		// Modify timestamp to cause upgrade
       
   831 		ModifyTimeStampL(fs,&fileName, time);
       
   832 
       
   833 		CleanupStack::PopAndDestroy(2); // fs and fm
       
   834 		}
       
   835 	else
       
   836 		{
       
   837 		iSwiWatcher->HandleSWIEventL(ESASwisInstall | ESASwisStatusSuccess);
       
   838 		}
       
   839 	}
       
   840 
       
   841 void CenrepSwiOOMTest::UninstallL(TBool aIsSetup)
       
   842 	{
       
   843 	if(aIsSetup)
       
   844 		{
       
   845 		// Install upgrade
       
   846 		UpgradeInstallL(ETrue);
       
   847 		UpgradeInstallL(EFalse);
       
   848 
       
   849 		RFs fs;
       
   850 		User::LeaveIfError(fs.Connect());
       
   851 		CleanupClosePushL(fs);
       
   852 		CFileMan* fm = CFileMan::NewL(fs);
       
   853 		CleanupStack::PushL(fm);
       
   854 
       
   855 		// Delete file from install dir
       
   856 		User::LeaveIfError(fm->Attribs(KInstallFile,0,KEntryAttReadOnly,TTime(0)));
       
   857 		TInt err=fs.Delete(KInstallFile);
       
   858 		if((err!=KErrNone)&&(err!=KErrNotFound))
       
   859 			User::Leave(err);
       
   860 
       
   861 		// Create a cre persists file, doesn't matter what's in it, it should be deleted
       
   862 		User::LeaveIfError(fm->Copy(KPersistsFileUpgraded, KInstallPersistsFile));
       
   863 		User::LeaveIfError(fm->Attribs(KInstallPersistsFile,0,KEntryAttReadOnly,TTime(0)));
       
   864 
       
   865 		CleanupStack::PopAndDestroy(2); // fs and fm
       
   866 		}
       
   867 	else
       
   868 		{
       
   869 		iSwiWatcher->HandleSWIEventL(ESASwisUninstall | ESASwisStatusSuccess);
       
   870 		}
       
   871 	}
       
   872 
       
   873 LOCAL_C void StartupUpgradeL(TBool aIsSetup)
       
   874 {
       
   875 	if(aIsSetup)
       
   876 		{
       
   877 		// Set up files for test
       
   878 		RFs fs;
       
   879 		User::LeaveIfError(fs.Connect());
       
   880 		CleanupClosePushL(fs);
       
   881 		CFileMan* fm = CFileMan::NewL(fs);
       
   882 		CleanupStack::PushL(fm);
       
   883 
       
   884 		// Clean out files
       
   885 		TInt err=fs.Delete(KInstallDirFile);
       
   886 		if((err!=KErrNone)&&(err!=KErrNotFound))
       
   887 			User::Leave(err);
       
   888 
       
   889 		// Cause directory listing with no files to be written
       
   890 		CCentRepSWIWatcher*	swiWatcher = CCentRepSWIWatcher::NewL(TServerResources::iFs);
       
   891 		delete swiWatcher;
       
   892 
       
   893 		User::LeaveIfError(fm->Copy(KPersistsFileNoUpgrade, KPersistsFile));
       
   894 		User::LeaveIfError(fm->Attribs(KPersistsFile,0,KEntryAttReadOnly,TTime(0)));
       
   895 
       
   896 		User::LeaveIfError(fm->Copy(KRomUpgradeRev1File, KUpgradeFile));
       
   897 		User::LeaveIfError(fm->Attribs(KUpgradeFile,0,KEntryAttReadOnly,TTime(0)));
       
   898 
       
   899 		CleanupStack::PopAndDestroy(2); // fs and fm
       
   900 		}
       
   901 	else
       
   902 		{
       
   903 		CCentRepSWIWatcher*	swiWatcher = CCentRepSWIWatcher::NewL(TServerResources::iFs);
       
   904 		delete swiWatcher;
       
   905 		}
       
   906 }
       
   907 
       
   908 LOCAL_C void StartupDowngradeL(TBool aIsSetup)
       
   909 {
       
   910 	if(aIsSetup)
       
   911 		{
       
   912 		StartupUpgradeL(ETrue);
       
   913 		StartupUpgradeL(EFalse);
       
   914 
       
   915 		// Set up files for test
       
   916 		RFs fs;
       
   917 		User::LeaveIfError(fs.Connect());
       
   918 		CleanupClosePushL(fs);
       
   919 		TInt err=fs.Delete(KUpgradeFile);
       
   920 		if((err!=KErrNone)&&(err!=KErrNotFound))
       
   921 			User::Leave(err);
       
   922 
       
   923 		CleanupStack::PopAndDestroy(); // fs
       
   924 		}
       
   925 	else
       
   926 		{
       
   927 		CCentRepSWIWatcher*	swiWatcher = CCentRepSWIWatcher::NewL(TServerResources::iFs);
       
   928 		delete swiWatcher;
       
   929 		}
       
   930 }
       
   931 
       
   932 LOCAL_C void StartupUninstallL(TBool aIsSetup)
       
   933 {
       
   934 	if(aIsSetup)
       
   935 		{
       
   936 		RFs fs;
       
   937 		User::LeaveIfError(fs.Connect());
       
   938 		CleanupClosePushL(fs);
       
   939 		CFileMan* fm = CFileMan::NewL(fs);
       
   940 		CleanupStack::PushL(fm);
       
   941 
       
   942 		// Copy rev 1 file into install dir & Reset read-only bit
       
   943 		User::LeaveIfError(fm->Copy(KInstallOnlyFile, KInstallFile));
       
   944 		User::LeaveIfError(fm->Attribs(KInstallFile,0,KEntryAttReadOnly,TTime(0)));
       
   945 
       
   946 		// Cause directory listing to be written and file to be installed
       
   947 		CCentRepSWIWatcher*	swiWatcher = CCentRepSWIWatcher::NewL(TServerResources::iFs);
       
   948 		delete swiWatcher;
       
   949 
       
   950 		// Create a persists file that will be deleted
       
   951 		User::LeaveIfError(fm->Copy(KPersistsFileUpgraded, KInstallPersistsFile));
       
   952 		User::LeaveIfError(fm->Attribs(KInstallPersistsFile,0,KEntryAttReadOnly,TTime(0)));
       
   953 
       
   954 		TInt err=fs.Delete(KInstallFile);
       
   955 		if((err!=KErrNone)&&(err!=KErrNotFound))
       
   956 			User::Leave(err);
       
   957 
       
   958 		CleanupStack::PopAndDestroy(2); // fs and fm
       
   959 		}
       
   960 	else
       
   961 		{
       
   962 		CCentRepSWIWatcher*	swiWatcher = CCentRepSWIWatcher::NewL(TServerResources::iFs);
       
   963 		delete swiWatcher;
       
   964 		}
       
   965 }
       
   966 
       
   967 // Type definition for pointer to function
       
   968 // Used for functions that can't use CenrepSrvOOMTest::ConstructL
       
   969 typedef void (*FuncPtrL) (TBool);
       
   970 /**
       
   971 Wrapper function to call all OOM test functions
       
   972 @param		testFuncL pointer to OOM test function
       
   973 @param		aTestDesc test function name
       
   974 */
       
   975 LOCAL_C void DoOOMNoServReposL( FuncPtrL atestFuncL, const TDesC& aTestDesc, TBool aOOMMode)
       
   976 	{
       
   977 	TheTest.Next(aTestDesc);
       
   978 
       
   979 	TInt err;
       
   980 	TInt tryCount = 0;
       
   981 	do
       
   982 		{
       
   983 		__UHEAP_MARK;
       
   984 
       
   985 		//Initializing the server resources
       
   986 		TServerResources::InitialiseL ();
       
   987 		//Clear any files in the persist directory
       
   988 		CleanupCDriveL();
       
   989 
       
   990 		// find out the number of open handles
       
   991 		TInt startProcessHandleCount;
       
   992 		TInt startThreadHandleCount;
       
   993 		RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
       
   994 
       
   995 		(*atestFuncL)(ETrue);
       
   996 
       
   997 		if (aOOMMode)
       
   998 			__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
       
   999 
       
  1000 		TRAP(err, (*atestFuncL)(EFalse));
       
  1001 		if (err!=KErrNoMemory)
       
  1002 			TESTKErrNoneL(err);
       
  1003 
       
  1004 		if (aOOMMode)
       
  1005 			__UHEAP_SETFAIL(RHeap::ENone, 0);
       
  1006 
       
  1007 		// check that no handles have leaked
       
  1008 		TInt endProcessHandleCount;
       
  1009 		TInt endThreadHandleCount;
       
  1010 		RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
       
  1011 		TEST2L(startProcessHandleCount, endProcessHandleCount);
       
  1012 		TEST2L(startThreadHandleCount, endThreadHandleCount);
       
  1013 
       
  1014 		//Freeing the server resources
       
  1015 		TServerResources::Close();
       
  1016 
       
  1017 		__UHEAP_MARKEND;
       
  1018 		} while(err == KErrNoMemory);
       
  1019 
       
  1020  	TESTKErrNoneL(err);
       
  1021  	if (aOOMMode)
       
  1022 		TheTest.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount);
       
  1023 	}
       
  1024 
       
  1025 // Type definition for pointer to member function.
       
  1026 // Used in calling the CRegistryDataTest member function for testing.
       
  1027 typedef void (CenrepSrvOOMTest::*ClassFuncPtrL) (void);
       
  1028 /**
       
  1029 Wrapper function to call all OOM test functions
       
  1030 @param		testFuncL pointer to OOM test function
       
  1031 @param		aTestDesc test function name
       
  1032 @param		aOOMMode to enable/disable the OOM environment
       
  1033 */
       
  1034 LOCAL_C void DoOOMTestL(ClassFuncPtrL testFuncL, const TDesC& aTestDesc,TBool aOOMMode)
       
  1035 	{
       
  1036 	TheTest.Next(aTestDesc);
       
  1037 
       
  1038 	TInt err=KErrNone;
       
  1039 	TInt tryCount = 0;
       
  1040 	do
       
  1041 		{
       
  1042 		__UHEAP_MARK;
       
  1043 
       
  1044 		//Initializing the server resources
       
  1045 		TServerResources::InitialiseL ();
       
  1046 
       
  1047 		//Clear any files in the persist directory
       
  1048 		CleanupCDriveL();
       
  1049 
       
  1050 		CenrepSrvOOMTest* theTest=CenrepSrvOOMTest::NewL();
       
  1051 		CleanupStack::PushL(theTest);
       
  1052 
       
  1053 		TInt startProcessHandleCount;
       
  1054 		TInt startThreadHandleCount;
       
  1055 		RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
       
  1056 
       
  1057 		if (aOOMMode)
       
  1058 			__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
       
  1059 
       
  1060 		TRAP(err, (theTest->*testFuncL)());
       
  1061 
       
  1062 		if (aOOMMode)
       
  1063 			__UHEAP_SETFAIL(RHeap::ENone, 0);
       
  1064 
       
  1065 		if (err!=KErrNoMemory)
       
  1066 			TESTKErrNoneL(err);
       
  1067 
       
  1068 		CleanupStack::PopAndDestroy(theTest);
       
  1069 
       
  1070 		// check that no handles have leaked
       
  1071 		TInt endProcessHandleCount;
       
  1072 		TInt endThreadHandleCount;
       
  1073 		RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
       
  1074 
       
  1075 		TEST2L(startProcessHandleCount, endProcessHandleCount);
       
  1076 		TEST2L(startThreadHandleCount, endThreadHandleCount);
       
  1077 
       
  1078 		//Freeing the server resources
       
  1079 		TServerResources::Close();
       
  1080 		__UHEAP_MARKEND;
       
  1081 		} while(err == KErrNoMemory);
       
  1082 
       
  1083  	TESTKErrNoneL(err);
       
  1084  	if (aOOMMode)
       
  1085 		TheTest.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount);
       
  1086 	}
       
  1087 
       
  1088 // Type definition for pointer to member function.
       
  1089 // Used in calling the CRegistryDataTest member function for testing.
       
  1090 typedef void (CenrepSwiOOMTest::*ClassSwiFuncPtrL) (TBool);
       
  1091 /**
       
  1092 Wrapper function to call all OOM test functions
       
  1093 @param		testFuncL pointer to OOM test function
       
  1094 @param		aTestDesc test function name
       
  1095 @param		aOOMMode to enable/disable the OOM environment
       
  1096 */
       
  1097 LOCAL_C void DoOOMSwiTestL(ClassSwiFuncPtrL aTestFuncL, const TDesC& aTestDesc,TBool aOOMMode)
       
  1098 	{
       
  1099 	TheTest.Next(aTestDesc);
       
  1100 
       
  1101 	TInt err=KErrNone;
       
  1102 	TInt tryCount = 0;
       
  1103 	do
       
  1104 		{
       
  1105 		__UHEAP_MARK;
       
  1106 
       
  1107 		//Initializing the server resources
       
  1108 		TServerResources::InitialiseL ();
       
  1109 		//Clear any files in the persist directory
       
  1110 		CleanupCDriveL();
       
  1111 
       
  1112 		TInt startProcessHandleCount;
       
  1113 		TInt startThreadHandleCount;
       
  1114 		RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
       
  1115 
       
  1116 		CenrepSwiOOMTest* theTest=CenrepSwiOOMTest::NewL();
       
  1117 		CleanupStack::PushL(theTest);
       
  1118 
       
  1119 		// Set up test
       
  1120 		(theTest->*aTestFuncL)(ETrue);
       
  1121 
       
  1122 		if (aOOMMode)
       
  1123 			__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
       
  1124 
       
  1125 		TRAP(err, (theTest->*aTestFuncL)(EFalse));
       
  1126 
       
  1127 		if (aOOMMode)
       
  1128 			__UHEAP_SETFAIL(RHeap::ENone, 0);
       
  1129 
       
  1130 		if (err!=KErrNoMemory)
       
  1131 			TESTKErrNoneL(err);
       
  1132 
       
  1133 		CleanupStack::PopAndDestroy(theTest);
       
  1134 
       
  1135 		// check that no handles have leaked
       
  1136 		TInt endProcessHandleCount;
       
  1137 		TInt endThreadHandleCount;
       
  1138 		RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
       
  1139 
       
  1140 		TEST2L(startProcessHandleCount, endProcessHandleCount);
       
  1141 		TEST2L(startThreadHandleCount, endThreadHandleCount);
       
  1142 
       
  1143 		//Freeing the server resources
       
  1144 		TServerResources::Close();
       
  1145 		__UHEAP_MARKEND;
       
  1146 		} while(err == KErrNoMemory);
       
  1147 
       
  1148  	TESTKErrNoneL(err);
       
  1149  	if (aOOMMode)
       
  1150 		TheTest.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount);
       
  1151 	}
       
  1152 
       
  1153 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
       
  1154 void CenrepSrvOOMTest::DoHeapRepositoryContentCheckL()
       
  1155 	{
       
  1156 	CServerRepository* srv=iServerRepo;
       
  1157 	//check setting and its meta
       
  1158 	TServerSetting* setting=NULL;
       
  1159 
       
  1160 	setting=srv->GetSetting(1);
       
  1161 	TESTL(setting->iKey==1);
       
  1162 	TESTL(setting->iMeta==0x80000010);
       
  1163 	//points to global default policy here
       
  1164 	TESTL(setting->iAccessPolicy->LowKey()==KUnspecifiedKey);
       
  1165 	TESTL(setting->iAccessPolicy->HighKey()==1);
       
  1166 	TESTL(setting->iAccessPolicy->KeyMask()==1);
       
  1167 
       
  1168 	setting=srv->GetSetting(2);
       
  1169 	TESTL(setting->iKey==2);
       
  1170 	TESTL(setting->iMeta==0xA0000010);
       
  1171 	//points to global default policy here
       
  1172 	TESTL(setting->iAccessPolicy->LowKey()==KUnspecifiedKey);
       
  1173 	TESTL(setting->iAccessPolicy->HighKey()==1);
       
  1174 	TESTL(setting->iAccessPolicy->KeyMask()==1);
       
  1175 
       
  1176 	setting=srv->GetSetting(3);
       
  1177 	TESTL(setting->iKey==3);
       
  1178 	TESTL(setting->iMeta==0x800000FF);
       
  1179 	//points to global default policy here
       
  1180 	TESTL(setting->iAccessPolicy->LowKey()==KUnspecifiedKey);
       
  1181 	TESTL(setting->iAccessPolicy->HighKey()==1);
       
  1182 	TESTL(setting->iAccessPolicy->KeyMask()==1);
       
  1183 
       
  1184 	setting=srv->GetSetting(4);
       
  1185 	TESTL(setting->iKey==4);
       
  1186 	TESTL(setting->iMeta==0x80000010);
       
  1187 	TESTL(setting->iAccessPolicy->LowKey()==4);
       
  1188 	TESTL(setting->iAccessPolicy->HighKey()==1);
       
  1189 	TESTL(setting->iAccessPolicy->KeyMask()==0);
       
  1190 
       
  1191 	setting=srv->GetSetting(5);
       
  1192 	TESTL(setting->iKey==5);
       
  1193 	TESTL(setting->iMeta==0xC0000063);
       
  1194 	//points to global default policy here
       
  1195 	TESTL(setting->iAccessPolicy->LowKey()==KUnspecifiedKey);
       
  1196 	TESTL(setting->iAccessPolicy->HighKey()==1);
       
  1197 	TESTL(setting->iAccessPolicy->KeyMask()==1);
       
  1198 
       
  1199 	setting=srv->GetSetting(6);
       
  1200 	TESTL(setting->iKey==6);
       
  1201 	TESTL(setting->iMeta==0x90000010);
       
  1202 	TESTL(setting->iAccessPolicy->LowKey()==6);
       
  1203 	TESTL(setting->iAccessPolicy->HighKey()==1);
       
  1204 	TESTL(setting->iAccessPolicy->KeyMask()==0);
       
  1205 
       
  1206 	setting=srv->GetSetting(7);
       
  1207 	TESTL(setting->iKey==7);
       
  1208 	TESTL(setting->iMeta==0x80000010);
       
  1209 	TESTL(setting->iAccessPolicy->LowKey()==7);
       
  1210 	TESTL(setting->iAccessPolicy->HighKey()==1);
       
  1211 	TESTL(setting->iAccessPolicy->KeyMask()==0);
       
  1212 
       
  1213 	setting=srv->GetSetting(9);
       
  1214 	TESTL(setting->iKey==9);
       
  1215 	TESTL(setting->iMeta==0x80000010);
       
  1216 	TESTL(setting->iAccessPolicy->LowKey()==KUnspecifiedKey);
       
  1217 	TESTL(setting->iAccessPolicy->HighKey()==1);
       
  1218 	TESTL(setting->iAccessPolicy->KeyMask()==1);
       
  1219 
       
  1220 	setting=srv->GetSetting(10);
       
  1221 	TESTL(setting->iKey==10);
       
  1222 	TESTL(setting->iMeta==0x80000010);
       
  1223 	TESTL(setting->iAccessPolicy->LowKey()==10);
       
  1224 	TESTL(setting->iAccessPolicy->HighKey()==1);
       
  1225 	TESTL(setting->iAccessPolicy->KeyMask()==0);
       
  1226 
       
  1227 	setting=srv->GetSetting(300);
       
  1228 	TESTL(setting->iKey==300);
       
  1229 	TESTL(setting->iMeta==0x900003E7);
       
  1230 	TESTL(setting->iAccessPolicy->LowKey()==KUnspecifiedKey);
       
  1231 	TESTL(setting->iAccessPolicy->HighKey()==1);
       
  1232 	TESTL(setting->iAccessPolicy->KeyMask()==1);
       
  1233 	}
       
  1234 
       
  1235 LOCAL_C void DoAdditionalCheckingL()
       
  1236 	{
       
  1237 	TServerResources::InitialiseL ();
       
  1238 
       
  1239 	CenrepSrvOOMTest* test=CenrepSrvOOMTest::NewL();
       
  1240 	CleanupStack::PushL(test);
       
  1241 	test->DoHeapRepositoryContentCheckL();
       
  1242 
       
  1243 	CleanupStack::PopAndDestroy();
       
  1244 
       
  1245 	TServerResources::Close();
       
  1246 	}
       
  1247 
       
  1248 /**
       
  1249 @SYMTestCaseID PDS-CENTRALREPOSITORY-UT-4050
       
  1250 @SYMTestCaseDesc Verifying that CRE generated will have the latest CRE version which is currently 2
       
  1251 @SYMTestPriority High
       
  1252 @SYMTestActions  Validating that CRE files generated with post PREQ2112 code will always contain version 2.
       
  1253 				 The unit test will load a txt repository and then modify some settings so that it gets persisted
       
  1254 				 in the persists directory. The test then read the cre files to verify that the version persisted
       
  1255 				 is the latest which is 2.
       
  1256 @SYMTestExpectedResults The correct file version is returned.
       
  1257 @SYMREQ REQ11282
       
  1258 */
       
  1259 LOCAL_C void DoPersistedVersionCheckingL()
       
  1260 	{
       
  1261 	TheTest.Next (_L (" @SYMTestCaseID:PDS-CENTRALREPOSITORY-UT-4050 Verifying CRE generated will always be version 2 "));
       
  1262 	TServerResources::InitialiseL ();
       
  1263 
       
  1264 	const TUid KTestUid={0x88880000};
       
  1265 	KCurrentTestUid=KTestUid;
       
  1266 
       
  1267 	CenrepSrvOOMTest* test=CenrepSrvOOMTest::NewL();
       
  1268 	CleanupStack::PushL(test);
       
  1269 
       
  1270 	//persist immediately
       
  1271 	test->iServerRepo->CommitChangesL();
       
  1272 
       
  1273 	//now check the version of the CRE file
       
  1274 	CHeapRepository* heap=CHeapRepository::NewL(KTestUid);
       
  1275 	CleanupStack::PushL(heap);
       
  1276 	TUint8 creVersion;
       
  1277 	heap->CreateRepositoryFromCreFileL(TServerResources::iFs,_L("c:\\private\\10202be9\\persists\\88880000.cre"),creVersion);
       
  1278 	TESTL(creVersion==KPersistFormatSupportsIndMetaIndicator);
       
  1279 
       
  1280 	CleanupStack::PopAndDestroy(2,test);
       
  1281 	TServerResources::Close();
       
  1282 	}
       
  1283 /**
       
  1284 @SYMTestCaseID PDS-CENTRALREPOSITORY-UT-4051
       
  1285 @SYMTestCaseDesc Server side OOM loading of a multiple repository files
       
  1286 @SYMTestPriority High
       
  1287 @SYMTestActions  Create the server class CServerRepository and used it to load the multi ROFS keyspace.
       
  1288 				 Test are repeated for the following keyspace combination such as TXT/TXT, CRE/TXT or TXT/CRE and CRE/CRE.
       
  1289 				 Test will also verify the resulting merged settings which includes checking
       
  1290 				 individual metadata bits and security policy bits
       
  1291 @SYMTestExpectedResults Server loading of the multi rofs keypsace should not fail and leak memory under OOM condition.
       
  1292 @SYMREQ REQ11282
       
  1293 */
       
  1294 LOCAL_C void DoOOMMultiRofsTestL()
       
  1295 	{
       
  1296 	TheTest.Next (_L (" @SYMTestCaseID:PDS-CENTRALREPOSITORY-UT-4051 CENREPSRV MultiROFS OOM Test "));
       
  1297 
       
  1298 	const TUid KMultiRofsRepositoryUid1={0xFFFF0000};
       
  1299 	const TUid KMultiRofsRepositoryUid2={0xEEEE0000};
       
  1300 	const TUid KMultiRofsRepositoryUid3={0xDDDD0000};
       
  1301 	const TUid KMultiRofsRepositoryUid4={0xCCCC0000};
       
  1302 
       
  1303 	//First Testuid=KMultiRofsRepositoryUid
       
  1304 	//Testing the OOM of multi rofs processing
       
  1305 	KCurrentTestUid=KMultiRofsRepositoryUid1;
       
  1306 	DoOOMNoServReposL(&CreateDeleteL, _L("Create Delete OOM Multi ROFS Test"),ETrue);
       
  1307 	DoAdditionalCheckingL();
       
  1308 	KCurrentTestUid=KMultiRofsRepositoryUid2;
       
  1309 	DoOOMNoServReposL(&CreateDeleteL, _L("Create Delete OOM Multi ROFS Test"),ETrue);
       
  1310 	DoAdditionalCheckingL();
       
  1311 	KCurrentTestUid=KMultiRofsRepositoryUid3;
       
  1312 	DoOOMNoServReposL(&CreateDeleteL, _L("Create Delete OOM Multi ROFS Test"),ETrue);
       
  1313 	DoAdditionalCheckingL();
       
  1314 	KCurrentTestUid=KMultiRofsRepositoryUid4;
       
  1315 	DoOOMNoServReposL(&CreateDeleteL, _L("Create Delete OOM Multi ROFS Test"),ETrue);
       
  1316 	DoAdditionalCheckingL();
       
  1317 	}
       
  1318 #endif
       
  1319 
       
  1320 LOCAL_C void DoOOMTestsL()
       
  1321 	{
       
  1322 	TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-LEGACY-T_OOMCENREP-0001 Starting CENREPSRV OOM Test "));
       
  1323 	RFs fs;
       
  1324 	User::LeaveIfError(fs.Connect());
       
  1325 	CleanupClosePushL(fs);
       
  1326 	CFileMan* fm = CFileMan::NewL(fs);
       
  1327 	CleanupStack::PushL(fm);
       
  1328 
       
  1329 	//Clear any files in the persist directory
       
  1330 	CleanupCDriveL();
       
  1331 
       
  1332 	//First Testuid=KTestRepositoryUid
       
  1333 	KCurrentTestUid=KTestRepositoryUid;
       
  1334 
       
  1335 	DoOOMTestL(&CenrepSrvOOMTest::GetL,_L("Get Basic Test"),EFalse);
       
  1336 	DoOOMTestL(&CenrepSrvOOMTest::FindL,_L("FindL Basic Test"),EFalse);
       
  1337 	DoOOMTestL(&CenrepSrvOOMTest::NotifyL,_L("NotifyL Basic Test"),EFalse);
       
  1338 	DoOOMTestL(&CenrepSrvOOMTest::ResetL,_L("ResetL Basic Test"),EFalse);
       
  1339 	// Save file without timestamp
       
  1340 	User::LeaveIfError(fm->Copy(KPersistsFile, KPersistsFileNoUpgrade));
       
  1341 	DoOOMTestL(&CenrepSrvOOMTest::SetL,_L("SetL Basic Test"),EFalse);
       
  1342 	DoOOMTestL(&CenrepSrvOOMTest::CreateL,_L("CreateL Basic Test"),EFalse);
       
  1343 	DoOOMTestL(&CenrepSrvOOMTest::DeleteL,_L("DeleteL Basic Test"),EFalse);
       
  1344 	DoOOMTestL(&CenrepSrvOOMTest::MoveL,_L("MoveL Basic Test"),EFalse);
       
  1345 
       
  1346 	//Clear any files in the persist directory
       
  1347 	CleanupCDriveL();
       
  1348 
       
  1349 	// Simulate response to SWI rom-upgrade and downgrade events
       
  1350 	DoOOMSwiTestL(&CenrepSwiOOMTest::UpgradeROMRev1L,_L("SwiUpgradeROMRev1L Basic Test"),EFalse);
       
  1351 	// Save file with timestamp
       
  1352 	User::LeaveIfError(fm->Copy(KPersistsFile, KPersistsFileUpgraded));
       
  1353 	DoOOMSwiTestL(&CenrepSwiOOMTest::UpgradeROMRev2L,_L("SwiUpgradeROMRev2L Basic Test"),EFalse);
       
  1354 	DoOOMSwiTestL(&CenrepSwiOOMTest::UninstallROMUpgradeL,_L("SwiUninstallROMUpgradeL Basic Test"),EFalse);
       
  1355 
       
  1356 	// Simulate response to SWI new rep install/uninstall event events
       
  1357 	DoOOMSwiTestL(&CenrepSwiOOMTest::InstallL,_L("SwiInstallL Basic Test"),EFalse);
       
  1358 	DoOOMSwiTestL(&CenrepSwiOOMTest::UpgradeInstallL,_L("SwiUpgradeInstallL Basic Test"),EFalse);
       
  1359 	DoOOMSwiTestL(&CenrepSwiOOMTest::UninstallL,_L("SwiUninstallL Basic Test"),EFalse);
       
  1360 
       
  1361 	// Simulate SWI events before server startup
       
  1362 	DoOOMNoServReposL(&StartupUpgradeL, _L("Startup Upgrade Basic Test"), EFalse);
       
  1363 	DoOOMNoServReposL(&StartupDowngradeL, _L("Startup Downgrade Basic Test"), EFalse);
       
  1364 	DoOOMNoServReposL(&StartupUninstallL,_L("Startup Uninstall Basic Test"), EFalse);
       
  1365 
       
  1366 	//OOM Test aOOMMode=ETrue
       
  1367 	DoOOMNoServReposL(&CreateDeleteL, _L("Create Delete OOM Test"),ETrue);
       
  1368 	DoOOMNoServReposL(&CreateDeleteCorruptL, _L("Create Delete Corrupt OOM Test"),ETrue);
       
  1369 	DoOOMTestL(&CenrepSrvOOMTest::GetL,_L("Get OOM Test"),ETrue);
       
  1370 	DoOOMTestL(&CenrepSrvOOMTest::FindL,_L("FindL OOM Test"),ETrue);
       
  1371 	DoOOMTestL(&CenrepSrvOOMTest::NotifyL,_L("NotifyL OOM Test"),ETrue);
       
  1372 	DoOOMTestL(&CenrepSrvOOMTest::ResetL,_L("ResetL OOM Test"),ETrue);
       
  1373 	DoOOMTestL(&CenrepSrvOOMTest::SetL,_L("SetL OOM Test"),ETrue);
       
  1374 	DoOOMTestL(&CenrepSrvOOMTest::CreateL,_L("CreateL OOM Test"),ETrue);
       
  1375 	DoOOMTestL(&CenrepSrvOOMTest::DeleteL,_L("DeleteL OOM Test"),ETrue);
       
  1376 	DoOOMTestL(&CenrepSrvOOMTest::MoveL,_L("MoveL OOM Test"),ETrue);
       
  1377 
       
  1378 	//Clear any files in the persist directory
       
  1379 	CleanupCDriveL();
       
  1380 
       
  1381 	DoOOMSwiTestL(&CenrepSwiOOMTest::UpgradeROMRev1L,_L("SwiUpgradeROMRev1L OOM Test"),ETrue);
       
  1382 	DoOOMSwiTestL(&CenrepSwiOOMTest::UpgradeROMRev2L,_L("SwiUpgradeROMRev2L OOM Test"),ETrue);
       
  1383 	DoOOMSwiTestL(&CenrepSwiOOMTest::UninstallROMUpgradeL,_L("SwiUninstallROMUpgradeL OOM Test"),ETrue);
       
  1384 
       
  1385 	DoOOMSwiTestL(&CenrepSwiOOMTest::InstallL,_L("SwiInstallL OOM Test"),ETrue);
       
  1386 	DoOOMSwiTestL(&CenrepSwiOOMTest::UpgradeInstallL,_L("SwiUpgradeInstallL OOM Test"),ETrue);
       
  1387 	DoOOMSwiTestL(&CenrepSwiOOMTest::UninstallL,_L("SwiUninstallL OOM Test"),ETrue);
       
  1388 
       
  1389 	DoOOMNoServReposL(&StartupUpgradeL, _L("Startup Upgrade OOM Test"), ETrue);
       
  1390 	DoOOMNoServReposL(&StartupDowngradeL, _L("Startup Downgrade OOM Test"), ETrue);
       
  1391 	DoOOMNoServReposL(&StartupUninstallL, _L("Startup Uninstall OOM Test"), ETrue);
       
  1392 
       
  1393 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
       
  1394 	DoPersistedVersionCheckingL();
       
  1395 	DoOOMMultiRofsTestL();
       
  1396 #endif
       
  1397 
       
  1398 	// Delete files from bur dir
       
  1399 	User::LeaveIfError(fm->Attribs(KPersistsFileNoUpgrade,0,KEntryAttReadOnly,TTime(0)));
       
  1400 	TInt err=fs.Delete(KPersistsFileNoUpgrade);
       
  1401 	if((err!=KErrNone)&&(err!=KErrNotFound))
       
  1402 		User::Leave(err);
       
  1403 
       
  1404 	User::LeaveIfError(fm->Attribs(KPersistsFileUpgraded,0,KEntryAttReadOnly,TTime(0)));
       
  1405 	err=fs.Delete(KPersistsFileUpgraded);
       
  1406 	if((err!=KErrNone)&&(err!=KErrNotFound))
       
  1407 		User::Leave(err);
       
  1408 
       
  1409 
       
  1410 	//Clear any files in the persist directory
       
  1411 	CleanupCDriveL();
       
  1412 
       
  1413 	CleanupStack::PopAndDestroy (2);	// fs and fm
       
  1414 	}
       
  1415 
       
  1416 
       
  1417 LOCAL_C void MainL()
       
  1418 	{
       
  1419 	TheTest.Title ();
       
  1420 	TheTest.Start (_L("OOM Cenrepserv Test"));
       
  1421 
       
  1422 	CActiveScheduler* scheduler = new(ELeave)CActiveScheduler;
       
  1423 	CActiveScheduler::Install(scheduler);
       
  1424 
       
  1425 	DoOOMTestsL();
       
  1426 
       
  1427 	//Clear any files in the persist directory
       
  1428 	CleanupCDriveL();
       
  1429 
       
  1430 	TheFs.Close ();
       
  1431 
       
  1432 	delete scheduler;
       
  1433 
       
  1434 	TheTest.End ();
       
  1435 	TheTest.Close ();
       
  1436 	}
       
  1437 
       
  1438 TInt E32Main ()
       
  1439 	{
       
  1440 
       
  1441 	__UHEAP_MARK;
       
  1442 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
  1443 	if(!cleanup)
       
  1444 		return KErrNoMemory;
       
  1445 
       
  1446 	TRAPD(err, MainL());
       
  1447 	if (err != KErrNone)
       
  1448 		User::Panic(_L("Testing failed: "), err);
       
  1449 
       
  1450 	delete cleanup;
       
  1451 	__UHEAP_MARKEND;
       
  1452 
       
  1453 	return KErrNone;
       
  1454 	}