sl@0: // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // t_oomcenrep.cpp sl@0: // sl@0: // sl@0: sl@0: #include "t_cenrep_helper.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include "srvsess.h" sl@0: #include "sessmgr.h" sl@0: #include "srvres.h" sl@0: #include "srvreqs.h" sl@0: #include "cachemgr.h" sl@0: #include "clientrequest.h" sl@0: #include "install.h" sl@0: #include sl@0: sl@0: LOCAL_D RFs TheFs; sl@0: LOCAL_D RTest TheTest (_L ("t_oomcenrep.exe")); sl@0: sl@0: #ifdef __SECURE_DATA__ sl@0: _LIT(KInstallDirFile, "c:\\private\\10202BE9\\persists\\installdir.bin"); sl@0: sl@0: _LIT(KPersistsFile, "c:\\private\\10202BE9\\persists\\11111111.cre"); sl@0: _LIT(KInstallPersistsFile, "c:\\private\\10202BE9\\persists\\11111110.cre"); sl@0: _LIT(KPersistsFileNoUpgrade, "c:\\private\\10202BE9\\bur\\11111111.crn"); sl@0: _LIT(KPersistsFileUpgraded, "c:\\private\\10202BE9\\bur\\11111111.cru"); sl@0: sl@0: _LIT(KRomUpgradeRev1File, "z:\\private\\10202BE9\\11111111.txu"); sl@0: _LIT(KRomUpgradeRev2File, "z:\\private\\10202BE9\\11111112.txu"); sl@0: _LIT(KUpgradeFile, "c:\\private\\10202BE9\\11111111.txt"); sl@0: sl@0: _LIT(KInstallOnlyFile, "z:\\private\\10202BE9\\11111110.cri"); sl@0: _LIT(KInstallOnlyUpgradeFile, "z:\\private\\10202BE9\\11111110.cru"); sl@0: _LIT(KInstallFile, "c:\\private\\10202BE9\\11111110.cre"); sl@0: sl@0: #else sl@0: _LIT(KPersistsFiles, "c:\\system\\data\\cenrep\\persists\\*.*"); sl@0: #endif sl@0: sl@0: sl@0: //Test repositories Uid sl@0: const TUid KTestRepositoryUid={0x11111111}; sl@0: const TUid KCorruptRepositoryUid={0xBADBADBB}; sl@0: sl@0: static TUid KCurrentTestUid; sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: //Test macroses and functions sl@0: LOCAL_C void CheckL(TInt aValue, TInt aLine) sl@0: { sl@0: if(!aValue) sl@0: { sl@0: RDebug::Print(_L("Error\r\n")); sl@0: CleanupCDriveL(); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: LOCAL_C void CheckL(TInt aValue, TInt aExpected, TInt aLine) sl@0: { sl@0: if(aValue != aExpected) sl@0: { sl@0: RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); sl@0: CleanupCDriveL(); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: #define TESTL(arg) ::CheckL((arg), __LINE__) sl@0: #define TEST2L(aValue, aExpected) ::CheckL(aValue, aExpected, __LINE__) sl@0: #define TESTKErrNoneL(aValue) ::CheckL(aValue,0,__LINE__); sl@0: sl@0: ///////////////////////////////////////////////////////////////////////////////////////// sl@0: class CenrepSrvOOMTest :public CBase sl@0: { sl@0: public: sl@0: void GetL(); sl@0: void FindL(); sl@0: void ResetL(); sl@0: void NotifyL(); sl@0: void SetL(); sl@0: void CreateL(); sl@0: void DeleteL(); sl@0: void MoveL(); sl@0: sl@0: CenrepSrvOOMTest(); sl@0: ~CenrepSrvOOMTest(); sl@0: static CenrepSrvOOMTest* NewL(); sl@0: #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS sl@0: void DoHeapRepositoryContentCheckL(); sl@0: #endif sl@0: private: sl@0: void ConstructL(); sl@0: public: sl@0: CServerRepository* iServerRepo; sl@0: CSessionNotifier* iSessionNotif; sl@0: }; sl@0: sl@0: ////////////////////////////////////////////////////////////////////////////////////////////////// sl@0: class CenrepSwiOOMTest :public CBase sl@0: { sl@0: public: sl@0: void UpgradeROMRev1L(TBool aIsSetup); sl@0: void UpgradeROMRev2L(TBool aIsSetup); sl@0: void UninstallROMUpgradeL(TBool aIsSetup); sl@0: sl@0: void InstallL(TBool aIsSetup); sl@0: void UpgradeInstallL(TBool aIsSetup); sl@0: void UninstallL(TBool aIsSetup); sl@0: sl@0: CenrepSwiOOMTest(); sl@0: ~CenrepSwiOOMTest(); sl@0: static CenrepSwiOOMTest* NewL(); sl@0: private: sl@0: void ConstructL(); sl@0: CCentRepSWIWatcher* iSwiWatcher; sl@0: public: sl@0: }; sl@0: ////////////////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: CenrepSrvOOMTest::CenrepSrvOOMTest(){} sl@0: sl@0: CenrepSrvOOMTest::~CenrepSrvOOMTest() sl@0: { sl@0: if (iServerRepo) sl@0: { sl@0: if (iSessionNotif) sl@0: { sl@0: iServerRepo->Close(); sl@0: } sl@0: delete iServerRepo; sl@0: } sl@0: if (iSessionNotif) sl@0: delete iSessionNotif; sl@0: sl@0: // Cache must be disabled here. Otherwise, if any idle repositories exists, they will sl@0: // still be open (have their pointers in the iOpenRepositories list) and the list will leak. sl@0: TServerResources::iCacheManager->DisableCache(); sl@0: TServerResources::iObserver->CloseiOpenRepositories(); sl@0: } sl@0: sl@0: CenrepSrvOOMTest* CenrepSrvOOMTest::NewL() sl@0: { sl@0: CenrepSrvOOMTest* self=new (ELeave)CenrepSrvOOMTest; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: void CenrepSrvOOMTest::ConstructL() sl@0: { sl@0: iServerRepo=new (ELeave)CServerRepository(); sl@0: iSessionNotif=new (ELeave) CSessionNotifier(); sl@0: sl@0: iServerRepo->OpenL(KCurrentTestUid,*iSessionNotif); sl@0: } sl@0: sl@0: ////////////////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: CenrepSwiOOMTest::CenrepSwiOOMTest(){} sl@0: sl@0: CenrepSwiOOMTest::~CenrepSwiOOMTest() sl@0: { sl@0: delete iSwiWatcher; sl@0: } sl@0: sl@0: CenrepSwiOOMTest* CenrepSwiOOMTest::NewL() sl@0: { sl@0: CenrepSwiOOMTest* self=new (ELeave)CenrepSwiOOMTest; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: void CenrepSwiOOMTest::ConstructL() sl@0: { sl@0: iSwiWatcher = CCentRepSWIWatcher::NewL(TServerResources::iFs); sl@0: } sl@0: sl@0: //Getting various information and security policy from the repository sl@0: //TInt CServerRepository::Get(TUint32 aId,T& aVal) sl@0: //TServerSetting* CServerRepository::GetSetting(TUint32 aId) sl@0: void CenrepSrvOOMTest::GetL() sl@0: { sl@0: TInt err=KErrNone; sl@0: TInt keyInt=0; sl@0: TServerSetting* srvsetting; sl@0: //----------Getting the TInt(1-15)----------------------------- sl@0: for (TInt i=1;i<=15;i++) sl@0: { sl@0: err=iServerRepo->Get(i,keyInt); sl@0: //Remember the policy check is done at the session level sl@0: TESTKErrNoneL(err); sl@0: TESTL(i==keyInt); sl@0: srvsetting=iServerRepo->GetSetting(i); sl@0: TESTL(srvsetting->Key()==static_cast(i)); sl@0: } sl@0: //---------Getting the TReal(16-19)--------------------------- sl@0: TReal keyValue; sl@0: err=iServerRepo->Get(16,keyValue); sl@0: TESTKErrNoneL(err); sl@0: TESTL(keyValue==10.1010); sl@0: srvsetting=iServerRepo->GetSetting(16); sl@0: TESTL(srvsetting->Key()==16); sl@0: sl@0: err=iServerRepo->Get(19,keyValue); sl@0: TESTKErrNoneL(err); sl@0: TESTL(keyValue==13.1313); sl@0: sl@0: //----------Getting the String(20-23)----------------------- sl@0: TBuf8<50> keyString; sl@0: _LIT(KFourteen,"fourteen"); sl@0: err=iServerRepo->Get(20,keyString); sl@0: TESTKErrNoneL(err); sl@0: //Even ascii(8 bytes) are stored as 16 bytes!!! sl@0: TPtr16 str16((TUint16*) keyString.Ptr(),keyString.Length()/2,keyString.Length()/2); sl@0: TESTL(str16.Compare(KFourteen)==0); sl@0: srvsetting=iServerRepo->GetSetting(20); sl@0: TESTL(srvsetting->Key()==20); sl@0: sl@0: //---------Getting the String8(0x79)------------------------ sl@0: TBuf8<50> keyString8; sl@0: _LIT8(KString8,"string8"); sl@0: err=iServerRepo->Get(0x79,keyString8); sl@0: TESTKErrNoneL(err); sl@0: TESTL(keyString8.Compare(KString8)==0); sl@0: srvsetting=iServerRepo->GetSetting(0x79); sl@0: TESTL(srvsetting->Key()==0x79); sl@0: sl@0: //---------Getting the binary(0x82)------------------------- sl@0: TBuf8<50> keyBinary; sl@0: _LIT8(KBinary8,"\x12\x34\xAB\xCD"); sl@0: err=iServerRepo->Get(0x82,keyBinary); sl@0: TESTKErrNoneL(err); sl@0: //temporarily added to solve coverage problem in WINSCW sl@0: #ifdef __EPOC32__ sl@0: TESTL(keyBinary.Compare(KBinary8)==0); sl@0: #endif sl@0: srvsetting=iServerRepo->GetSetting(0x82); sl@0: TESTL(srvsetting->Key()==0x82); sl@0: sl@0: //----------Getting individual policy----------------------- sl@0: //Current Exe has caps AllFiles+WriteDeviceData+ReadDeviceData sl@0: RThread currentThread; sl@0: TSecurityPolicy secPolicy; sl@0: //default policy sl@0: secPolicy=iServerRepo->GetDefaultReadAccessPolicy(); sl@0: TESTL(secPolicy.CheckPolicy(currentThread)==1); sl@0: secPolicy=iServerRepo->GetDefaultWriteAccessPolicy(); sl@0: TESTL(secPolicy.CheckPolicy(currentThread)==1); sl@0: sl@0: //check settings policies sl@0: //0x2 int 2 1 cap_rd=CommDD cap_wr=WriteDeviceData sl@0: //0x19 int 25 0 //defined in range policies with cap_rd=NetworkServices sl@0: secPolicy=iServerRepo->GetReadAccessPolicy(2); sl@0: TESTL(secPolicy.CheckPolicy(currentThread)==0); sl@0: secPolicy=iServerRepo->GetWriteAccessPolicy(2); sl@0: TESTL(secPolicy.CheckPolicy(currentThread)==1); sl@0: secPolicy=iServerRepo->GetReadAccessPolicy(25); sl@0: TESTL(secPolicy.CheckPolicy(currentThread)==0); sl@0: sl@0: } sl@0: sl@0: // now that write operations must be done in transactions, setting up this helper sl@0: // function to perform single Sets for the purpose of this test. sl@0: template sl@0: static TInt RepositorySingleSetL(CServerRepository& aRep, TUint32 aKey, const T& aValue) sl@0: { sl@0: aRep.StartTransaction(EConcurrentReadWriteTransaction); sl@0: aRep.CleanupCancelTransactionPushL(); sl@0: aRep.TransactionSetL(aKey, aValue); sl@0: CleanupStack::Pop(); sl@0: TUint32 keyInfo; sl@0: return User::LeaveIfError(aRep.CommitTransaction(keyInfo)); sl@0: }; sl@0: sl@0: //Setting OOM testing sl@0: void CenrepSrvOOMTest::SetL() sl@0: { sl@0: TInt ret=KErrNone; sl@0: TInt intValue=0; sl@0: TReal realValue=0; sl@0: sl@0: //---------------SetL----------------------------------- sl@0: //Setting an integer key sl@0: ret = RepositorySingleSetL(*iServerRepo, 0x60, 600); sl@0: TESTKErrNoneL(ret); sl@0: ret=iServerRepo->Get(0x60,intValue); sl@0: TESTL(intValue== 600); sl@0: sl@0: //Setting a real key sl@0: ret = RepositorySingleSetL(*iServerRepo, 0x66, 99.99); sl@0: TESTKErrNoneL(ret); sl@0: ret=iServerRepo->Get(0x66,realValue); sl@0: TESTL(realValue==99.99); sl@0: sl@0: //Setting a string key sl@0: //Even ascii(8 bytes) are stored as 16 bytes!!! sl@0: _LIT8(KString,"sixhundred"); sl@0: TBuf8<50> stringChangeValue=KString(); sl@0: ret = RepositorySingleSetL(*iServerRepo, 0x69, stringChangeValue); sl@0: TESTKErrNoneL(ret); sl@0: sl@0: TBuf8<50> keyString; sl@0: ret=iServerRepo->Get(0x69,keyString); sl@0: TESTKErrNoneL(ret); sl@0: TESTL(keyString.Compare(KString)==0); sl@0: } sl@0: sl@0: // now that write operations must be done in transactions, setting up this helper sl@0: // function to perform single Creates for the purpose of this test. sl@0: template sl@0: static TInt RepositorySingleCreateL(CServerRepository& aRep, TUint32 aKey, const T& aValue, TUint32* aMeta) sl@0: { sl@0: aRep.StartTransaction(EConcurrentReadWriteTransaction); sl@0: aRep.CleanupCancelTransactionPushL(); sl@0: aRep.TransactionCreateL(aKey, aValue, aMeta); sl@0: CleanupStack::Pop(); sl@0: TUint32 keyInfo; sl@0: return User::LeaveIfError(aRep.CommitTransaction(keyInfo)); sl@0: }; sl@0: sl@0: void CenrepSrvOOMTest::CreateL() sl@0: { sl@0: TInt ret=KErrNone; sl@0: TInt intValue=0; sl@0: TReal realValue=0; sl@0: sl@0: //--------------CreateL----------------------------------- sl@0: //Creating an integer key sl@0: TInt intRetValue; sl@0: intValue=9000; sl@0: RepositorySingleCreateL(*iServerRepo, 0x90, intValue, NULL); sl@0: TESTKErrNoneL(ret); sl@0: ret=iServerRepo->Get(0x90,intRetValue); sl@0: TESTKErrNoneL(ret); sl@0: TESTL(intRetValue==intValue); sl@0: sl@0: //Creating a real key sl@0: TReal realRetValue; sl@0: realValue=33.3333; sl@0: RepositorySingleCreateL(*iServerRepo, 0x92, realValue, NULL); sl@0: TESTKErrNoneL(ret); sl@0: ret=iServerRepo->Get(0x92,realRetValue); sl@0: TESTKErrNoneL(ret); sl@0: TESTL(realValue==realRetValue); sl@0: sl@0: //Creating a string key sl@0: _LIT8(KStringValue,"creatingkey"); sl@0: TBuf8<50> stringCreateValue=KStringValue(); sl@0: RepositorySingleCreateL(*iServerRepo, 0x93, stringCreateValue, NULL); sl@0: TESTKErrNoneL(ret); sl@0: } sl@0: sl@0: // now that write operations must be done in transactions, setting up this helper sl@0: // function to perform single Creates for the purpose of this test. sl@0: static TInt RepositorySingleDeleteL(CServerRepository& aRep, TUint32 aKey) sl@0: { sl@0: aRep.StartTransaction(EConcurrentReadWriteTransaction); sl@0: aRep.CleanupCancelTransactionPushL(); sl@0: aRep.TransactionDeleteL(aKey); sl@0: CleanupStack::Pop(); sl@0: TUint32 keyInfo; sl@0: return User::LeaveIfError(aRep.CommitTransaction(keyInfo)); sl@0: }; sl@0: sl@0: void CenrepSrvOOMTest::DeleteL() sl@0: { sl@0: TInt ret=KErrNone; sl@0: //--------------Delete----------------------------------- sl@0: //Find the settings 0x10A-0x10C to ensure it is still there sl@0: RSettingPointerArray matchingArray; sl@0: TUint32 partialId=0x100; sl@0: TUint32 idMask=0xFFFFFFF0; sl@0: ret=iServerRepo->FindSettings(partialId,idMask,matchingArray); sl@0: if (ret==KErrNoMemory) sl@0: { sl@0: matchingArray.Close(); sl@0: User::LeaveNoMemory(); sl@0: } sl@0: sl@0: TESTKErrNoneL(ret); sl@0: TESTL(matchingArray.Count()==3); sl@0: matchingArray.Close(); sl@0: sl@0: //Deleting settings 0x10A to 0x10C sl@0: for (TInt i=0x10A;i<=0x10C;i++) sl@0: { sl@0: RepositorySingleDeleteL(*iServerRepo, i); sl@0: TESTKErrNoneL(ret); sl@0: } sl@0: //After deleting try to find the persistent settings again sl@0: ret=iServerRepo->FindSettings(partialId,idMask,matchingArray); sl@0: if (ret==KErrNoMemory) sl@0: { sl@0: matchingArray.Close(); sl@0: User::LeaveNoMemory(); sl@0: } sl@0: TESTKErrNoneL(ret); sl@0: TESTL(matchingArray.Count()==0); sl@0: matchingArray.Close(); sl@0: sl@0: //-------------DeleteRange--------------------------------- sl@0: //Deleting settings 0x1 to 0xF sl@0: TClientRequest dummyrequest; sl@0: TUint32 errId=0; sl@0: partialId=0; sl@0: idMask=0xFFFFFFF0; sl@0: ret=iServerRepo->FindSettings(partialId,idMask,matchingArray); sl@0: if (ret==KErrNoMemory) sl@0: { sl@0: matchingArray.Close(); sl@0: User::LeaveNoMemory(); sl@0: } sl@0: TESTKErrNoneL(ret) ; sl@0: TESTL(matchingArray.Count()==15); sl@0: matchingArray.Close(); sl@0: sl@0: //Deleting settings using the DeleteRange sl@0: dummyrequest.SetParam(0,partialId); sl@0: dummyrequest.SetParam(1,idMask); sl@0: dummyrequest.SetPolicyCheck(ETrue); sl@0: sl@0: // write operation must take place in a transaction sl@0: iServerRepo->StartTransaction(EConcurrentReadWriteTransaction); sl@0: iServerRepo->CleanupCancelTransactionPushL(); sl@0: iServerRepo->TransactionDeleteRangeL(dummyrequest,errId); sl@0: CleanupStack::Pop(); sl@0: TUint32 keyInfo; sl@0: User::LeaveIfError(iServerRepo->CommitTransaction(keyInfo)); sl@0: sl@0: //Now try to find the key being deleted sl@0: ret=iServerRepo->FindSettings(partialId,idMask,matchingArray); sl@0: if (ret==KErrNoMemory) sl@0: { sl@0: matchingArray.Close(); sl@0: User::LeaveNoMemory(); sl@0: } sl@0: TESTKErrNoneL(ret); sl@0: TESTL(matchingArray.Count()==0); sl@0: matchingArray.Close(); sl@0: } sl@0: sl@0: //Setting existing key value then follow by commit sl@0: void CenrepSrvOOMTest::MoveL() sl@0: { sl@0: RSettingPointerArray matchingArray; sl@0: TUint32 idMask=0xFFFFFFF0; sl@0: sl@0: /*---------------MoveL------------------------------------- sl@0: TUint32 sourcePartialId = aMessage.Int0(); sl@0: TUint32 targetPartialId = aMessage.Int1(); sl@0: TUint32 idMask = aMessage.Int2(); sl@0: */ sl@0: TClientRequest dummyrequest; sl@0: TUint32 errId=0; sl@0: TUint32 sourcePartialId=0x110; sl@0: TUint32 targetPartialId=0x120; sl@0: idMask=0xFFFFFFF0; sl@0: sl@0: TKeyFilter srcKeyIdentifier = {sourcePartialId, idMask}; sl@0: TPckg pSrcIdentifier(srcKeyIdentifier); sl@0: TKeyFilter tgtKeyIdentifier = {targetPartialId, idMask}; sl@0: TPckg pTgtIdentifier(tgtKeyIdentifier); sl@0: sl@0: //First check to ensure the target key before move does not exist sl@0: User::LeaveIfError(iServerRepo->FindSettings(targetPartialId,idMask,matchingArray)); sl@0: TESTL(matchingArray.Count()==0); sl@0: matchingArray.Close(); sl@0: sl@0: //moving from 0x110(0x11B,0x11C,0x11E) to 0x120 sl@0: dummyrequest.SetParam(0, &pSrcIdentifier); sl@0: dummyrequest.SetParam(1, &pTgtIdentifier); sl@0: dummyrequest.SetPolicyCheck(ETrue); sl@0: sl@0: // write operation must take place in a transaction sl@0: iServerRepo->StartTransaction(EConcurrentReadWriteTransaction); sl@0: iServerRepo->CleanupCancelTransactionPushL(); sl@0: iServerRepo->TransactionMoveL(dummyrequest,errId); sl@0: CleanupStack::Pop(); sl@0: TUint32 keyInfo; sl@0: User::LeaveIfError(iServerRepo->CommitTransaction(keyInfo)); sl@0: sl@0: //Now try to find the key being moved sl@0: User::LeaveIfError(iServerRepo->FindSettings(targetPartialId,idMask,matchingArray)); sl@0: TESTL(matchingArray.Count()==3); sl@0: matchingArray.Close(); sl@0: } sl@0: sl@0: //Finding keys from the settings sl@0: //TInt FindSettings(TUint32 aPartialId,TUint32 aIdMask,RSettingPointerArray& aMatches) sl@0: //Guarantees the heap free in aMatches if this function fail sl@0: void CenrepSrvOOMTest::FindL() sl@0: { sl@0: TInt ret=KErrNone; sl@0: RSettingPointerArray foundIdArray; sl@0: TUint32 partialId=0; sl@0: TUint32 idMask=0; sl@0: //-----------Finding settings array using partial id & mask------ sl@0: sl@0: //------------------Real type--------------------------------- sl@0: //0x42,0x44,0x45,0x48 sl@0: partialId=0x40; sl@0: idMask=0xFFFFFFF0; sl@0: User::LeaveIfError(iServerRepo->FindSettings(partialId,idMask,foundIdArray)); sl@0: TESTKErrNoneL(ret); sl@0: TESTL(foundIdArray.Count()==4); sl@0: foundIdArray.Close(); sl@0: sl@0: //-----------------String type------------------------------- sl@0: //0x51,0x54,0x5B sl@0: partialId=0x50; sl@0: idMask=0xFFFFFFF0; sl@0: User::LeaveIfError(iServerRepo->FindSettings(partialId,idMask,foundIdArray)); sl@0: TESTKErrNoneL(ret); sl@0: TESTL(foundIdArray.Count()==3); sl@0: foundIdArray.Close(); sl@0: sl@0: //--------------------Int type---------------------------------------------------- sl@0: partialId=0x30; sl@0: idMask=0xFFFFFFF0; sl@0: //This should return only 0x30,0x34,0x35,0x39,0x3B( 5 items) sl@0: User::LeaveIfError(iServerRepo->FindSettings(partialId,idMask,foundIdArray)); sl@0: TESTKErrNoneL(ret); sl@0: TESTL(foundIdArray.Count()==5); sl@0: sl@0: //----------------Find comparison using EEqual & ENotEqual------------------------ sl@0: TInt searchValue=100; sl@0: TClientRequest dummyrequest; sl@0: RArray idArray; sl@0: //Set the policycheck to always pass sl@0: dummyrequest.SetPolicyCheck(ETrue); sl@0: //Comparison using Equal sl@0: TRAP(ret,iServerRepo->FindCompareL(foundIdArray,searchValue,EEqual,idArray)); sl@0: if (ret==KErrNoMemory) sl@0: { sl@0: //do not need to reset idArray as it is done inside the function itself when it returns not KErrNone sl@0: foundIdArray.Close(); sl@0: User::LeaveNoMemory(); sl@0: } sl@0: TESTL(idArray.Count()==2); sl@0: TESTL((idArray[0]==0x30 && idArray[1]==0x34) || (idArray[0]==0x34 && idArray[1]==0x30)); sl@0: idArray.Close(); sl@0: //Comparison using ENotEqual sl@0: TRAP(ret,iServerRepo->FindCompareL(foundIdArray,searchValue,ENotEqual,idArray)); sl@0: if (ret==KErrNoMemory) sl@0: { sl@0: //do not need to reset idArray as it is done inside the function itself when it returns not KErrNone sl@0: foundIdArray.Close(); sl@0: User::LeaveNoMemory(); sl@0: } sl@0: TESTL(idArray.Count()==3); sl@0: idArray.Close(); sl@0: foundIdArray.Close(); sl@0: sl@0: } sl@0: sl@0: //Resetting settings sl@0: void CenrepSrvOOMTest::ResetL() sl@0: { sl@0: TInt ret=KErrNone; sl@0: TInt retValue=0; sl@0: TReal realValue=0; sl@0: sl@0: //-------------Single key reset---------------------------- sl@0: sl@0: ret = RepositorySingleSetL(*iServerRepo, 1, 500); sl@0: TESTKErrNoneL(ret); sl@0: ret=iServerRepo->Get(1,retValue); sl@0: TESTL(retValue==500); sl@0: sl@0: //Resetting individual settings sl@0: ret=iServerRepo->ResetL(1); sl@0: TESTKErrNoneL(ret); sl@0: sl@0: //Check for value once being reset sl@0: ret=iServerRepo->Get(1,retValue); sl@0: TESTL(retValue==1); sl@0: sl@0: //------------All keys reset------------------------------ sl@0: ret = RepositorySingleSetL(*iServerRepo, 17, 3.1343424); sl@0: TESTKErrNoneL(ret); sl@0: sl@0: //Reset all settings from Rom sl@0: User::LeaveIfError(iServerRepo->ResetAllL()); sl@0: TESTKErrNoneL(ret); sl@0: sl@0: //Check for value once all being reset sl@0: sl@0: ret=iServerRepo->Get(17,realValue); sl@0: TESTL(realValue==11.1111); sl@0: } sl@0: sl@0: void CenrepSrvOOMTest::NotifyL() sl@0: { sl@0: TInt err=KErrNone; sl@0: sl@0: //addding individual requests sl@0: for (TInt i=0;i<10;i++) sl@0: { sl@0: TClientRequest dummyRequest; sl@0: User::LeaveIfError(iSessionNotif->AddRequest(i,dummyRequest)); sl@0: } sl@0: sl@0: //adding group requests sl@0: for (TInt i=0;i<10;i++) sl@0: { sl@0: TClientRequest dummyRequest; sl@0: TUint32 partialId=100*i; sl@0: TUint32 idMask=0xFFFFFFF0; sl@0: User::LeaveIfError(iSessionNotif->AddRequest(partialId,idMask,dummyRequest)); sl@0: } sl@0: sl@0: //cancelling individual requests sl@0: User::LeaveIfError(iSessionNotif->CancelRequest(5)); sl@0: //Check to ensure that it has been deleted so calling cancel again will return KErrNotFound sl@0: err=iSessionNotif->CancelRequest(5); sl@0: TESTL(err==KErrNotFound); sl@0: sl@0: //cancelling group requests sl@0: User::LeaveIfError(iSessionNotif->CancelRequest(500,0xFFFFFFF0)); sl@0: err=iSessionNotif->CancelRequest(500,0xFFFFFF0); sl@0: TESTL(err==KErrNotFound); sl@0: sl@0: //Finally cancel ALL requests sl@0: iSessionNotif->CancelAllRequests(); sl@0: sl@0: } sl@0: sl@0: //Deletes the CServerRepository object properly sl@0: LOCAL_C void ReleaseRepository(TAny* aServerRepository) sl@0: { sl@0: CServerRepository* serverRepository = static_cast(aServerRepository); sl@0: sl@0: TServerResources::iCacheManager->DisableCache(); sl@0: TServerResources::iObserver->CloseiOpenRepositories(); sl@0: delete serverRepository; sl@0: TServerResources::iCacheManager->EnableCache(); sl@0: } sl@0: sl@0: //Opening a repository and closing the repository sl@0: LOCAL_C void CreateDeleteL(TBool /*aOOMMode*/) sl@0: { sl@0: CServerRepository* serverRepo=new (ELeave)CServerRepository(); sl@0: TCleanupItem cleanupItem(&ReleaseRepository, serverRepo); sl@0: CleanupStack::PushL(cleanupItem); sl@0: sl@0: CSessionNotifier* sessNotif=new (ELeave)CSessionNotifier(); sl@0: CleanupStack::PushL(sessNotif); sl@0: sl@0: // test access to a valid repository sl@0: serverRepo->OpenL(KCurrentTestUid,*sessNotif); sl@0: serverRepo->Close(); sl@0: sl@0: CleanupStack::PopAndDestroy(sessNotif); sl@0: CleanupStack::PopAndDestroy(1); sl@0: } sl@0: sl@0: LOCAL_C void CreateDeleteCorruptL(TBool /*aOOMMode*/) sl@0: { sl@0: CServerRepository* serverRepo=new (ELeave)CServerRepository(); sl@0: TCleanupItem cleanupItem(&ReleaseRepository, serverRepo); sl@0: CleanupStack::PushL(cleanupItem); sl@0: sl@0: CSessionNotifier* sessNotif=new (ELeave)CSessionNotifier(); sl@0: CleanupStack::PushL(sessNotif); sl@0: sl@0: // test access to a corrupt repository sl@0: // trap KErrCorrupt sl@0: TRAPD(err, serverRepo->OpenL(KCorruptRepositoryUid,*sessNotif)); sl@0: // leave if not KErrCorrupt sl@0: User::LeaveIfError((err == KErrCorrupt) ? KErrNone : err); sl@0: serverRepo->Close(); sl@0: sl@0: CleanupStack::PopAndDestroy(sessNotif); sl@0: CleanupStack::PopAndDestroy(1); sl@0: } sl@0: sl@0: void CenrepSwiOOMTest::UpgradeROMRev1L(TBool aIsSetup) sl@0: { sl@0: if(aIsSetup) sl@0: { sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: CleanupClosePushL(fs); sl@0: CFileMan* fm = CFileMan::NewL(fs); sl@0: CleanupStack::PushL(fm); sl@0: sl@0: // Copy rev 1 file into install dir & Reset read-only bit sl@0: User::LeaveIfError(fm->Copy(KRomUpgradeRev1File, KUpgradeFile)); sl@0: User::LeaveIfError(fm->Attribs(KUpgradeFile,0,KEntryAttReadOnly,TTime(0))); sl@0: CleanupStack::PopAndDestroy(2); // fs and fm sl@0: } sl@0: else sl@0: { sl@0: iSwiWatcher->HandleSWIEventL(ESASwisInstall | ESASwisStatusSuccess); sl@0: } sl@0: } sl@0: sl@0: LOCAL_C void ModifyTimeStampL(RFs &fs, TDesC *fileName, TTime aTime) sl@0: { sl@0: // Reset read-only bit sl@0: User::LeaveIfError(fs.SetAtt(*fileName, 0, KEntryAttReadOnly)); sl@0: TTimeIntervalHours interval(1); sl@0: TTime newTime=aTime+interval; sl@0: User::LeaveIfError(fs.SetModified(*fileName, newTime)); sl@0: } sl@0: sl@0: sl@0: void CenrepSwiOOMTest::UpgradeROMRev2L(TBool aIsSetup) sl@0: { sl@0: if(aIsSetup) sl@0: { sl@0: // Set up rev 1 sl@0: UpgradeROMRev1L(ETrue); sl@0: UpgradeROMRev1L(EFalse); sl@0: sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: CleanupClosePushL(fs); sl@0: CFileMan* fm = CFileMan::NewL(fs); sl@0: CleanupStack::PushL(fm); sl@0: sl@0: // Get modification time sl@0: TTime time; sl@0: TBuf<50> fileName(KUpgradeFile); sl@0: fs.Modified(fileName, time); sl@0: sl@0: // Copy rev2 file into install dir & Reset read-only bit sl@0: User::LeaveIfError(fm->Copy(KRomUpgradeRev2File, KUpgradeFile)); sl@0: User::LeaveIfError(fm->Attribs(KUpgradeFile,0,KEntryAttReadOnly,TTime(0))); sl@0: // Modify timestamp to cause upgrade sl@0: ModifyTimeStampL(fs,&fileName, time); sl@0: sl@0: CleanupStack::PopAndDestroy(2); // fs and fm sl@0: } sl@0: else sl@0: { sl@0: iSwiWatcher->HandleSWIEventL(ESASwisInstall | ESASwisStatusSuccess); sl@0: } sl@0: sl@0: } sl@0: sl@0: void CenrepSwiOOMTest::UninstallROMUpgradeL(TBool aIsSetup) sl@0: { sl@0: if(aIsSetup) sl@0: { sl@0: // Install rev 2 sl@0: UpgradeROMRev2L(ETrue); sl@0: UpgradeROMRev2L(EFalse); sl@0: sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: CleanupClosePushL(fs); sl@0: CFileMan* fm = CFileMan::NewL(fs); sl@0: CleanupStack::PushL(fm); sl@0: sl@0: // Delete file from install dir sl@0: User::LeaveIfError(fm->Attribs(KUpgradeFile,0,KEntryAttReadOnly,TTime(0))); sl@0: TInt err=fs.Delete(KUpgradeFile); sl@0: if((err!=KErrNone)&&(err!=KErrNotFound)) sl@0: User::Leave(err); sl@0: sl@0: CleanupStack::PopAndDestroy(2); // fs and fm sl@0: } sl@0: else sl@0: { sl@0: iSwiWatcher->HandleSWIEventL(ESASwisUninstall | ESASwisStatusSuccess); sl@0: } sl@0: } sl@0: sl@0: void CenrepSwiOOMTest::InstallL(TBool aIsSetup) sl@0: { sl@0: if(aIsSetup) sl@0: { sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: CleanupClosePushL(fs); sl@0: CFileMan* fm = CFileMan::NewL(fs); sl@0: CleanupStack::PushL(fm); sl@0: sl@0: // Copy rev 1 file into install dir & Reset read-only bit sl@0: User::LeaveIfError(fm->Copy(KInstallOnlyFile, KInstallFile)); sl@0: User::LeaveIfError(fm->Attribs(KInstallFile,0,KEntryAttReadOnly,TTime(0))); sl@0: sl@0: CleanupStack::PopAndDestroy(2); // fs and fm sl@0: } sl@0: else sl@0: { sl@0: iSwiWatcher->HandleSWIEventL(ESASwisInstall | ESASwisStatusSuccess); sl@0: } sl@0: } sl@0: sl@0: void CenrepSwiOOMTest::UpgradeInstallL(TBool aIsSetup) sl@0: { sl@0: if(aIsSetup) sl@0: { sl@0: // Install file sl@0: InstallL(ETrue); sl@0: InstallL(EFalse); sl@0: sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: CleanupClosePushL(fs); sl@0: CFileMan* fm = CFileMan::NewL(fs); sl@0: CleanupStack::PushL(fm); sl@0: sl@0: // Get modification time sl@0: TTime time; sl@0: TBuf<50> fileName(KInstallFile); sl@0: fs.Modified(fileName, time); sl@0: sl@0: // Copy upgrade file into install dir & Reset read-only bit sl@0: User::LeaveIfError(fm->Copy(KInstallOnlyUpgradeFile, KInstallFile)); sl@0: User::LeaveIfError(fm->Attribs(KInstallFile,0,KEntryAttReadOnly,TTime(0))); sl@0: // Modify timestamp to cause upgrade sl@0: ModifyTimeStampL(fs,&fileName, time); sl@0: sl@0: CleanupStack::PopAndDestroy(2); // fs and fm sl@0: } sl@0: else sl@0: { sl@0: iSwiWatcher->HandleSWIEventL(ESASwisInstall | ESASwisStatusSuccess); sl@0: } sl@0: } sl@0: sl@0: void CenrepSwiOOMTest::UninstallL(TBool aIsSetup) sl@0: { sl@0: if(aIsSetup) sl@0: { sl@0: // Install upgrade sl@0: UpgradeInstallL(ETrue); sl@0: UpgradeInstallL(EFalse); sl@0: sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: CleanupClosePushL(fs); sl@0: CFileMan* fm = CFileMan::NewL(fs); sl@0: CleanupStack::PushL(fm); sl@0: sl@0: // Delete file from install dir sl@0: User::LeaveIfError(fm->Attribs(KInstallFile,0,KEntryAttReadOnly,TTime(0))); sl@0: TInt err=fs.Delete(KInstallFile); sl@0: if((err!=KErrNone)&&(err!=KErrNotFound)) sl@0: User::Leave(err); sl@0: sl@0: // Create a cre persists file, doesn't matter what's in it, it should be deleted sl@0: User::LeaveIfError(fm->Copy(KPersistsFileUpgraded, KInstallPersistsFile)); sl@0: User::LeaveIfError(fm->Attribs(KInstallPersistsFile,0,KEntryAttReadOnly,TTime(0))); sl@0: sl@0: CleanupStack::PopAndDestroy(2); // fs and fm sl@0: } sl@0: else sl@0: { sl@0: iSwiWatcher->HandleSWIEventL(ESASwisUninstall | ESASwisStatusSuccess); sl@0: } sl@0: } sl@0: sl@0: LOCAL_C void StartupUpgradeL(TBool aIsSetup) sl@0: { sl@0: if(aIsSetup) sl@0: { sl@0: // Set up files for test sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: CleanupClosePushL(fs); sl@0: CFileMan* fm = CFileMan::NewL(fs); sl@0: CleanupStack::PushL(fm); sl@0: sl@0: // Clean out files sl@0: TInt err=fs.Delete(KInstallDirFile); sl@0: if((err!=KErrNone)&&(err!=KErrNotFound)) sl@0: User::Leave(err); sl@0: sl@0: // Cause directory listing with no files to be written sl@0: CCentRepSWIWatcher* swiWatcher = CCentRepSWIWatcher::NewL(TServerResources::iFs); sl@0: delete swiWatcher; sl@0: sl@0: User::LeaveIfError(fm->Copy(KPersistsFileNoUpgrade, KPersistsFile)); sl@0: User::LeaveIfError(fm->Attribs(KPersistsFile,0,KEntryAttReadOnly,TTime(0))); sl@0: sl@0: User::LeaveIfError(fm->Copy(KRomUpgradeRev1File, KUpgradeFile)); sl@0: User::LeaveIfError(fm->Attribs(KUpgradeFile,0,KEntryAttReadOnly,TTime(0))); sl@0: sl@0: CleanupStack::PopAndDestroy(2); // fs and fm sl@0: } sl@0: else sl@0: { sl@0: CCentRepSWIWatcher* swiWatcher = CCentRepSWIWatcher::NewL(TServerResources::iFs); sl@0: delete swiWatcher; sl@0: } sl@0: } sl@0: sl@0: LOCAL_C void StartupDowngradeL(TBool aIsSetup) sl@0: { sl@0: if(aIsSetup) sl@0: { sl@0: StartupUpgradeL(ETrue); sl@0: StartupUpgradeL(EFalse); sl@0: sl@0: // Set up files for test sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: CleanupClosePushL(fs); sl@0: TInt err=fs.Delete(KUpgradeFile); sl@0: if((err!=KErrNone)&&(err!=KErrNotFound)) sl@0: User::Leave(err); sl@0: sl@0: CleanupStack::PopAndDestroy(); // fs sl@0: } sl@0: else sl@0: { sl@0: CCentRepSWIWatcher* swiWatcher = CCentRepSWIWatcher::NewL(TServerResources::iFs); sl@0: delete swiWatcher; sl@0: } sl@0: } sl@0: sl@0: LOCAL_C void StartupUninstallL(TBool aIsSetup) sl@0: { sl@0: if(aIsSetup) sl@0: { sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: CleanupClosePushL(fs); sl@0: CFileMan* fm = CFileMan::NewL(fs); sl@0: CleanupStack::PushL(fm); sl@0: sl@0: // Copy rev 1 file into install dir & Reset read-only bit sl@0: User::LeaveIfError(fm->Copy(KInstallOnlyFile, KInstallFile)); sl@0: User::LeaveIfError(fm->Attribs(KInstallFile,0,KEntryAttReadOnly,TTime(0))); sl@0: sl@0: // Cause directory listing to be written and file to be installed sl@0: CCentRepSWIWatcher* swiWatcher = CCentRepSWIWatcher::NewL(TServerResources::iFs); sl@0: delete swiWatcher; sl@0: sl@0: // Create a persists file that will be deleted sl@0: User::LeaveIfError(fm->Copy(KPersistsFileUpgraded, KInstallPersistsFile)); sl@0: User::LeaveIfError(fm->Attribs(KInstallPersistsFile,0,KEntryAttReadOnly,TTime(0))); sl@0: sl@0: TInt err=fs.Delete(KInstallFile); sl@0: if((err!=KErrNone)&&(err!=KErrNotFound)) sl@0: User::Leave(err); sl@0: sl@0: CleanupStack::PopAndDestroy(2); // fs and fm sl@0: } sl@0: else sl@0: { sl@0: CCentRepSWIWatcher* swiWatcher = CCentRepSWIWatcher::NewL(TServerResources::iFs); sl@0: delete swiWatcher; sl@0: } sl@0: } sl@0: sl@0: // Type definition for pointer to function sl@0: // Used for functions that can't use CenrepSrvOOMTest::ConstructL sl@0: typedef void (*FuncPtrL) (TBool); sl@0: /** sl@0: Wrapper function to call all OOM test functions sl@0: @param testFuncL pointer to OOM test function sl@0: @param aTestDesc test function name sl@0: */ sl@0: LOCAL_C void DoOOMNoServReposL( FuncPtrL atestFuncL, const TDesC& aTestDesc, TBool aOOMMode) sl@0: { sl@0: TheTest.Next(aTestDesc); sl@0: sl@0: TInt err; sl@0: TInt tryCount = 0; sl@0: do sl@0: { sl@0: __UHEAP_MARK; sl@0: sl@0: //Initializing the server resources sl@0: TServerResources::InitialiseL (); sl@0: //Clear any files in the persist directory sl@0: CleanupCDriveL(); sl@0: sl@0: // find out the number of open handles sl@0: TInt startProcessHandleCount; sl@0: TInt startThreadHandleCount; sl@0: RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); sl@0: sl@0: (*atestFuncL)(ETrue); sl@0: sl@0: if (aOOMMode) sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount); sl@0: sl@0: TRAP(err, (*atestFuncL)(EFalse)); sl@0: if (err!=KErrNoMemory) sl@0: TESTKErrNoneL(err); sl@0: sl@0: if (aOOMMode) sl@0: __UHEAP_SETFAIL(RHeap::ENone, 0); sl@0: sl@0: // check that no handles have leaked sl@0: TInt endProcessHandleCount; sl@0: TInt endThreadHandleCount; sl@0: RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); sl@0: TEST2L(startProcessHandleCount, endProcessHandleCount); sl@0: TEST2L(startThreadHandleCount, endThreadHandleCount); sl@0: sl@0: //Freeing the server resources sl@0: TServerResources::Close(); sl@0: sl@0: __UHEAP_MARKEND; sl@0: } while(err == KErrNoMemory); sl@0: sl@0: TESTKErrNoneL(err); sl@0: if (aOOMMode) sl@0: TheTest.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount); sl@0: } sl@0: sl@0: // Type definition for pointer to member function. sl@0: // Used in calling the CRegistryDataTest member function for testing. sl@0: typedef void (CenrepSrvOOMTest::*ClassFuncPtrL) (void); sl@0: /** sl@0: Wrapper function to call all OOM test functions sl@0: @param testFuncL pointer to OOM test function sl@0: @param aTestDesc test function name sl@0: @param aOOMMode to enable/disable the OOM environment sl@0: */ sl@0: LOCAL_C void DoOOMTestL(ClassFuncPtrL testFuncL, const TDesC& aTestDesc,TBool aOOMMode) sl@0: { sl@0: TheTest.Next(aTestDesc); sl@0: sl@0: TInt err=KErrNone; sl@0: TInt tryCount = 0; sl@0: do sl@0: { sl@0: __UHEAP_MARK; sl@0: sl@0: //Initializing the server resources sl@0: TServerResources::InitialiseL (); sl@0: sl@0: //Clear any files in the persist directory sl@0: CleanupCDriveL(); sl@0: sl@0: CenrepSrvOOMTest* theTest=CenrepSrvOOMTest::NewL(); sl@0: CleanupStack::PushL(theTest); sl@0: sl@0: TInt startProcessHandleCount; sl@0: TInt startThreadHandleCount; sl@0: RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); sl@0: sl@0: if (aOOMMode) sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount); sl@0: sl@0: TRAP(err, (theTest->*testFuncL)()); sl@0: sl@0: if (aOOMMode) sl@0: __UHEAP_SETFAIL(RHeap::ENone, 0); sl@0: sl@0: if (err!=KErrNoMemory) sl@0: TESTKErrNoneL(err); sl@0: sl@0: CleanupStack::PopAndDestroy(theTest); sl@0: sl@0: // check that no handles have leaked sl@0: TInt endProcessHandleCount; sl@0: TInt endThreadHandleCount; sl@0: RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); sl@0: sl@0: TEST2L(startProcessHandleCount, endProcessHandleCount); sl@0: TEST2L(startThreadHandleCount, endThreadHandleCount); sl@0: sl@0: //Freeing the server resources sl@0: TServerResources::Close(); sl@0: __UHEAP_MARKEND; sl@0: } while(err == KErrNoMemory); sl@0: sl@0: TESTKErrNoneL(err); sl@0: if (aOOMMode) sl@0: TheTest.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount); sl@0: } sl@0: sl@0: // Type definition for pointer to member function. sl@0: // Used in calling the CRegistryDataTest member function for testing. sl@0: typedef void (CenrepSwiOOMTest::*ClassSwiFuncPtrL) (TBool); sl@0: /** sl@0: Wrapper function to call all OOM test functions sl@0: @param testFuncL pointer to OOM test function sl@0: @param aTestDesc test function name sl@0: @param aOOMMode to enable/disable the OOM environment sl@0: */ sl@0: LOCAL_C void DoOOMSwiTestL(ClassSwiFuncPtrL aTestFuncL, const TDesC& aTestDesc,TBool aOOMMode) sl@0: { sl@0: TheTest.Next(aTestDesc); sl@0: sl@0: TInt err=KErrNone; sl@0: TInt tryCount = 0; sl@0: do sl@0: { sl@0: __UHEAP_MARK; sl@0: sl@0: //Initializing the server resources sl@0: TServerResources::InitialiseL (); sl@0: //Clear any files in the persist directory sl@0: CleanupCDriveL(); sl@0: sl@0: TInt startProcessHandleCount; sl@0: TInt startThreadHandleCount; sl@0: RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); sl@0: sl@0: CenrepSwiOOMTest* theTest=CenrepSwiOOMTest::NewL(); sl@0: CleanupStack::PushL(theTest); sl@0: sl@0: // Set up test sl@0: (theTest->*aTestFuncL)(ETrue); sl@0: sl@0: if (aOOMMode) sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount); sl@0: sl@0: TRAP(err, (theTest->*aTestFuncL)(EFalse)); sl@0: sl@0: if (aOOMMode) sl@0: __UHEAP_SETFAIL(RHeap::ENone, 0); sl@0: sl@0: if (err!=KErrNoMemory) sl@0: TESTKErrNoneL(err); sl@0: sl@0: CleanupStack::PopAndDestroy(theTest); sl@0: sl@0: // check that no handles have leaked sl@0: TInt endProcessHandleCount; sl@0: TInt endThreadHandleCount; sl@0: RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); sl@0: sl@0: TEST2L(startProcessHandleCount, endProcessHandleCount); sl@0: TEST2L(startThreadHandleCount, endThreadHandleCount); sl@0: sl@0: //Freeing the server resources sl@0: TServerResources::Close(); sl@0: __UHEAP_MARKEND; sl@0: } while(err == KErrNoMemory); sl@0: sl@0: TESTKErrNoneL(err); sl@0: if (aOOMMode) sl@0: TheTest.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount); sl@0: } sl@0: sl@0: #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS sl@0: void CenrepSrvOOMTest::DoHeapRepositoryContentCheckL() sl@0: { sl@0: CServerRepository* srv=iServerRepo; sl@0: //check setting and its meta sl@0: TServerSetting* setting=NULL; sl@0: sl@0: setting=srv->GetSetting(1); sl@0: TESTL(setting->iKey==1); sl@0: TESTL(setting->iMeta==0x80000010); sl@0: //points to global default policy here sl@0: TESTL(setting->iAccessPolicy->LowKey()==KUnspecifiedKey); sl@0: TESTL(setting->iAccessPolicy->HighKey()==1); sl@0: TESTL(setting->iAccessPolicy->KeyMask()==1); sl@0: sl@0: setting=srv->GetSetting(2); sl@0: TESTL(setting->iKey==2); sl@0: TESTL(setting->iMeta==0xA0000010); sl@0: //points to global default policy here sl@0: TESTL(setting->iAccessPolicy->LowKey()==KUnspecifiedKey); sl@0: TESTL(setting->iAccessPolicy->HighKey()==1); sl@0: TESTL(setting->iAccessPolicy->KeyMask()==1); sl@0: sl@0: setting=srv->GetSetting(3); sl@0: TESTL(setting->iKey==3); sl@0: TESTL(setting->iMeta==0x800000FF); sl@0: //points to global default policy here sl@0: TESTL(setting->iAccessPolicy->LowKey()==KUnspecifiedKey); sl@0: TESTL(setting->iAccessPolicy->HighKey()==1); sl@0: TESTL(setting->iAccessPolicy->KeyMask()==1); sl@0: sl@0: setting=srv->GetSetting(4); sl@0: TESTL(setting->iKey==4); sl@0: TESTL(setting->iMeta==0x80000010); sl@0: TESTL(setting->iAccessPolicy->LowKey()==4); sl@0: TESTL(setting->iAccessPolicy->HighKey()==1); sl@0: TESTL(setting->iAccessPolicy->KeyMask()==0); sl@0: sl@0: setting=srv->GetSetting(5); sl@0: TESTL(setting->iKey==5); sl@0: TESTL(setting->iMeta==0xC0000063); sl@0: //points to global default policy here sl@0: TESTL(setting->iAccessPolicy->LowKey()==KUnspecifiedKey); sl@0: TESTL(setting->iAccessPolicy->HighKey()==1); sl@0: TESTL(setting->iAccessPolicy->KeyMask()==1); sl@0: sl@0: setting=srv->GetSetting(6); sl@0: TESTL(setting->iKey==6); sl@0: TESTL(setting->iMeta==0x90000010); sl@0: TESTL(setting->iAccessPolicy->LowKey()==6); sl@0: TESTL(setting->iAccessPolicy->HighKey()==1); sl@0: TESTL(setting->iAccessPolicy->KeyMask()==0); sl@0: sl@0: setting=srv->GetSetting(7); sl@0: TESTL(setting->iKey==7); sl@0: TESTL(setting->iMeta==0x80000010); sl@0: TESTL(setting->iAccessPolicy->LowKey()==7); sl@0: TESTL(setting->iAccessPolicy->HighKey()==1); sl@0: TESTL(setting->iAccessPolicy->KeyMask()==0); sl@0: sl@0: setting=srv->GetSetting(9); sl@0: TESTL(setting->iKey==9); sl@0: TESTL(setting->iMeta==0x80000010); sl@0: TESTL(setting->iAccessPolicy->LowKey()==KUnspecifiedKey); sl@0: TESTL(setting->iAccessPolicy->HighKey()==1); sl@0: TESTL(setting->iAccessPolicy->KeyMask()==1); sl@0: sl@0: setting=srv->GetSetting(10); sl@0: TESTL(setting->iKey==10); sl@0: TESTL(setting->iMeta==0x80000010); sl@0: TESTL(setting->iAccessPolicy->LowKey()==10); sl@0: TESTL(setting->iAccessPolicy->HighKey()==1); sl@0: TESTL(setting->iAccessPolicy->KeyMask()==0); sl@0: sl@0: setting=srv->GetSetting(300); sl@0: TESTL(setting->iKey==300); sl@0: TESTL(setting->iMeta==0x900003E7); sl@0: TESTL(setting->iAccessPolicy->LowKey()==KUnspecifiedKey); sl@0: TESTL(setting->iAccessPolicy->HighKey()==1); sl@0: TESTL(setting->iAccessPolicy->KeyMask()==1); sl@0: } sl@0: sl@0: LOCAL_C void DoAdditionalCheckingL() sl@0: { sl@0: TServerResources::InitialiseL (); sl@0: sl@0: CenrepSrvOOMTest* test=CenrepSrvOOMTest::NewL(); sl@0: CleanupStack::PushL(test); sl@0: test->DoHeapRepositoryContentCheckL(); sl@0: sl@0: CleanupStack::PopAndDestroy(); sl@0: sl@0: TServerResources::Close(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-CENTRALREPOSITORY-UT-4050 sl@0: @SYMTestCaseDesc Verifying that CRE generated will have the latest CRE version which is currently 2 sl@0: @SYMTestPriority High sl@0: @SYMTestActions Validating that CRE files generated with post PREQ2112 code will always contain version 2. sl@0: The unit test will load a txt repository and then modify some settings so that it gets persisted sl@0: in the persists directory. The test then read the cre files to verify that the version persisted sl@0: is the latest which is 2. sl@0: @SYMTestExpectedResults The correct file version is returned. sl@0: @SYMREQ REQ11282 sl@0: */ sl@0: LOCAL_C void DoPersistedVersionCheckingL() sl@0: { sl@0: TheTest.Next (_L (" @SYMTestCaseID:PDS-CENTRALREPOSITORY-UT-4050 Verifying CRE generated will always be version 2 ")); sl@0: TServerResources::InitialiseL (); sl@0: sl@0: const TUid KTestUid={0x88880000}; sl@0: KCurrentTestUid=KTestUid; sl@0: sl@0: CenrepSrvOOMTest* test=CenrepSrvOOMTest::NewL(); sl@0: CleanupStack::PushL(test); sl@0: sl@0: //persist immediately sl@0: test->iServerRepo->CommitChangesL(); sl@0: sl@0: //now check the version of the CRE file sl@0: CHeapRepository* heap=CHeapRepository::NewL(KTestUid); sl@0: CleanupStack::PushL(heap); sl@0: TUint8 creVersion; sl@0: heap->CreateRepositoryFromCreFileL(TServerResources::iFs,_L("c:\\private\\10202be9\\persists\\88880000.cre"),creVersion); sl@0: TESTL(creVersion==KPersistFormatSupportsIndMetaIndicator); sl@0: sl@0: CleanupStack::PopAndDestroy(2,test); sl@0: TServerResources::Close(); sl@0: } sl@0: /** sl@0: @SYMTestCaseID PDS-CENTRALREPOSITORY-UT-4051 sl@0: @SYMTestCaseDesc Server side OOM loading of a multiple repository files sl@0: @SYMTestPriority High sl@0: @SYMTestActions Create the server class CServerRepository and used it to load the multi ROFS keyspace. sl@0: Test are repeated for the following keyspace combination such as TXT/TXT, CRE/TXT or TXT/CRE and CRE/CRE. sl@0: Test will also verify the resulting merged settings which includes checking sl@0: individual metadata bits and security policy bits sl@0: @SYMTestExpectedResults Server loading of the multi rofs keypsace should not fail and leak memory under OOM condition. sl@0: @SYMREQ REQ11282 sl@0: */ sl@0: LOCAL_C void DoOOMMultiRofsTestL() sl@0: { sl@0: TheTest.Next (_L (" @SYMTestCaseID:PDS-CENTRALREPOSITORY-UT-4051 CENREPSRV MultiROFS OOM Test ")); sl@0: sl@0: const TUid KMultiRofsRepositoryUid1={0xFFFF0000}; sl@0: const TUid KMultiRofsRepositoryUid2={0xEEEE0000}; sl@0: const TUid KMultiRofsRepositoryUid3={0xDDDD0000}; sl@0: const TUid KMultiRofsRepositoryUid4={0xCCCC0000}; sl@0: sl@0: //First Testuid=KMultiRofsRepositoryUid sl@0: //Testing the OOM of multi rofs processing sl@0: KCurrentTestUid=KMultiRofsRepositoryUid1; sl@0: DoOOMNoServReposL(&CreateDeleteL, _L("Create Delete OOM Multi ROFS Test"),ETrue); sl@0: DoAdditionalCheckingL(); sl@0: KCurrentTestUid=KMultiRofsRepositoryUid2; sl@0: DoOOMNoServReposL(&CreateDeleteL, _L("Create Delete OOM Multi ROFS Test"),ETrue); sl@0: DoAdditionalCheckingL(); sl@0: KCurrentTestUid=KMultiRofsRepositoryUid3; sl@0: DoOOMNoServReposL(&CreateDeleteL, _L("Create Delete OOM Multi ROFS Test"),ETrue); sl@0: DoAdditionalCheckingL(); sl@0: KCurrentTestUid=KMultiRofsRepositoryUid4; sl@0: DoOOMNoServReposL(&CreateDeleteL, _L("Create Delete OOM Multi ROFS Test"),ETrue); sl@0: DoAdditionalCheckingL(); sl@0: } sl@0: #endif sl@0: sl@0: LOCAL_C void DoOOMTestsL() sl@0: { sl@0: TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-LEGACY-T_OOMCENREP-0001 Starting CENREPSRV OOM Test ")); sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: CleanupClosePushL(fs); sl@0: CFileMan* fm = CFileMan::NewL(fs); sl@0: CleanupStack::PushL(fm); sl@0: sl@0: //Clear any files in the persist directory sl@0: CleanupCDriveL(); sl@0: sl@0: //First Testuid=KTestRepositoryUid sl@0: KCurrentTestUid=KTestRepositoryUid; sl@0: sl@0: DoOOMTestL(&CenrepSrvOOMTest::GetL,_L("Get Basic Test"),EFalse); sl@0: DoOOMTestL(&CenrepSrvOOMTest::FindL,_L("FindL Basic Test"),EFalse); sl@0: DoOOMTestL(&CenrepSrvOOMTest::NotifyL,_L("NotifyL Basic Test"),EFalse); sl@0: DoOOMTestL(&CenrepSrvOOMTest::ResetL,_L("ResetL Basic Test"),EFalse); sl@0: // Save file without timestamp sl@0: User::LeaveIfError(fm->Copy(KPersistsFile, KPersistsFileNoUpgrade)); sl@0: DoOOMTestL(&CenrepSrvOOMTest::SetL,_L("SetL Basic Test"),EFalse); sl@0: DoOOMTestL(&CenrepSrvOOMTest::CreateL,_L("CreateL Basic Test"),EFalse); sl@0: DoOOMTestL(&CenrepSrvOOMTest::DeleteL,_L("DeleteL Basic Test"),EFalse); sl@0: DoOOMTestL(&CenrepSrvOOMTest::MoveL,_L("MoveL Basic Test"),EFalse); sl@0: sl@0: //Clear any files in the persist directory sl@0: CleanupCDriveL(); sl@0: sl@0: // Simulate response to SWI rom-upgrade and downgrade events sl@0: DoOOMSwiTestL(&CenrepSwiOOMTest::UpgradeROMRev1L,_L("SwiUpgradeROMRev1L Basic Test"),EFalse); sl@0: // Save file with timestamp sl@0: User::LeaveIfError(fm->Copy(KPersistsFile, KPersistsFileUpgraded)); sl@0: DoOOMSwiTestL(&CenrepSwiOOMTest::UpgradeROMRev2L,_L("SwiUpgradeROMRev2L Basic Test"),EFalse); sl@0: DoOOMSwiTestL(&CenrepSwiOOMTest::UninstallROMUpgradeL,_L("SwiUninstallROMUpgradeL Basic Test"),EFalse); sl@0: sl@0: // Simulate response to SWI new rep install/uninstall event events sl@0: DoOOMSwiTestL(&CenrepSwiOOMTest::InstallL,_L("SwiInstallL Basic Test"),EFalse); sl@0: DoOOMSwiTestL(&CenrepSwiOOMTest::UpgradeInstallL,_L("SwiUpgradeInstallL Basic Test"),EFalse); sl@0: DoOOMSwiTestL(&CenrepSwiOOMTest::UninstallL,_L("SwiUninstallL Basic Test"),EFalse); sl@0: sl@0: // Simulate SWI events before server startup sl@0: DoOOMNoServReposL(&StartupUpgradeL, _L("Startup Upgrade Basic Test"), EFalse); sl@0: DoOOMNoServReposL(&StartupDowngradeL, _L("Startup Downgrade Basic Test"), EFalse); sl@0: DoOOMNoServReposL(&StartupUninstallL,_L("Startup Uninstall Basic Test"), EFalse); sl@0: sl@0: //OOM Test aOOMMode=ETrue sl@0: DoOOMNoServReposL(&CreateDeleteL, _L("Create Delete OOM Test"),ETrue); sl@0: DoOOMNoServReposL(&CreateDeleteCorruptL, _L("Create Delete Corrupt OOM Test"),ETrue); sl@0: DoOOMTestL(&CenrepSrvOOMTest::GetL,_L("Get OOM Test"),ETrue); sl@0: DoOOMTestL(&CenrepSrvOOMTest::FindL,_L("FindL OOM Test"),ETrue); sl@0: DoOOMTestL(&CenrepSrvOOMTest::NotifyL,_L("NotifyL OOM Test"),ETrue); sl@0: DoOOMTestL(&CenrepSrvOOMTest::ResetL,_L("ResetL OOM Test"),ETrue); sl@0: DoOOMTestL(&CenrepSrvOOMTest::SetL,_L("SetL OOM Test"),ETrue); sl@0: DoOOMTestL(&CenrepSrvOOMTest::CreateL,_L("CreateL OOM Test"),ETrue); sl@0: DoOOMTestL(&CenrepSrvOOMTest::DeleteL,_L("DeleteL OOM Test"),ETrue); sl@0: DoOOMTestL(&CenrepSrvOOMTest::MoveL,_L("MoveL OOM Test"),ETrue); sl@0: sl@0: //Clear any files in the persist directory sl@0: CleanupCDriveL(); sl@0: sl@0: DoOOMSwiTestL(&CenrepSwiOOMTest::UpgradeROMRev1L,_L("SwiUpgradeROMRev1L OOM Test"),ETrue); sl@0: DoOOMSwiTestL(&CenrepSwiOOMTest::UpgradeROMRev2L,_L("SwiUpgradeROMRev2L OOM Test"),ETrue); sl@0: DoOOMSwiTestL(&CenrepSwiOOMTest::UninstallROMUpgradeL,_L("SwiUninstallROMUpgradeL OOM Test"),ETrue); sl@0: sl@0: DoOOMSwiTestL(&CenrepSwiOOMTest::InstallL,_L("SwiInstallL OOM Test"),ETrue); sl@0: DoOOMSwiTestL(&CenrepSwiOOMTest::UpgradeInstallL,_L("SwiUpgradeInstallL OOM Test"),ETrue); sl@0: DoOOMSwiTestL(&CenrepSwiOOMTest::UninstallL,_L("SwiUninstallL OOM Test"),ETrue); sl@0: sl@0: DoOOMNoServReposL(&StartupUpgradeL, _L("Startup Upgrade OOM Test"), ETrue); sl@0: DoOOMNoServReposL(&StartupDowngradeL, _L("Startup Downgrade OOM Test"), ETrue); sl@0: DoOOMNoServReposL(&StartupUninstallL, _L("Startup Uninstall OOM Test"), ETrue); sl@0: sl@0: #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS sl@0: DoPersistedVersionCheckingL(); sl@0: DoOOMMultiRofsTestL(); sl@0: #endif sl@0: sl@0: // Delete files from bur dir sl@0: User::LeaveIfError(fm->Attribs(KPersistsFileNoUpgrade,0,KEntryAttReadOnly,TTime(0))); sl@0: TInt err=fs.Delete(KPersistsFileNoUpgrade); sl@0: if((err!=KErrNone)&&(err!=KErrNotFound)) sl@0: User::Leave(err); sl@0: sl@0: User::LeaveIfError(fm->Attribs(KPersistsFileUpgraded,0,KEntryAttReadOnly,TTime(0))); sl@0: err=fs.Delete(KPersistsFileUpgraded); sl@0: if((err!=KErrNone)&&(err!=KErrNotFound)) sl@0: User::Leave(err); sl@0: sl@0: sl@0: //Clear any files in the persist directory sl@0: CleanupCDriveL(); sl@0: sl@0: CleanupStack::PopAndDestroy (2); // fs and fm sl@0: } sl@0: sl@0: sl@0: LOCAL_C void MainL() sl@0: { sl@0: TheTest.Title (); sl@0: TheTest.Start (_L("OOM Cenrepserv Test")); sl@0: sl@0: CActiveScheduler* scheduler = new(ELeave)CActiveScheduler; sl@0: CActiveScheduler::Install(scheduler); sl@0: sl@0: DoOOMTestsL(); sl@0: sl@0: //Clear any files in the persist directory sl@0: CleanupCDriveL(); sl@0: sl@0: TheFs.Close (); sl@0: sl@0: delete scheduler; sl@0: sl@0: TheTest.End (); sl@0: TheTest.Close (); sl@0: } sl@0: sl@0: TInt E32Main () sl@0: { sl@0: sl@0: __UHEAP_MARK; sl@0: CTrapCleanup* cleanup = CTrapCleanup::New(); sl@0: if(!cleanup) sl@0: return KErrNoMemory; sl@0: sl@0: TRAPD(err, MainL()); sl@0: if (err != KErrNone) sl@0: User::Panic(_L("Testing failed: "), err); sl@0: sl@0: delete cleanup; sl@0: __UHEAP_MARKEND; sl@0: sl@0: return KErrNone; sl@0: }