sl@0: // Copyright (c) 2004-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: // sl@0: sl@0: #include "t_cenrep_helper.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "../cenrepsrv/srvparams.h" sl@0: #include "../cenrepsrv/srvreqs.h" sl@0: #include "../common/inc/srvdefs.h" sl@0: sl@0: using namespace NCentralRepositoryConstants; sl@0: sl@0: RTest TheTest(_L("Central Repository Platform Security Tests")); sl@0: sl@0: TBool OomTesting; sl@0: sl@0: const TUid KUidPlatsecTestRepository = { 0x00000100 }; sl@0: const TUid KUidTransactionTestRepository = { 0x00000101 }; sl@0: const TUid KUidResetTestRepository = { 0x00000004 }; sl@0: sl@0: const TInt KMaxNumRepsToReset = 3; sl@0: sl@0: // sl@0: // Platsec test repository sl@0: // sl@0: sl@0: const TUint32 KNonExisitent = 0; sl@0: sl@0: const TInt KNumSettings = 26; sl@0: sl@0: const TUint32 KInt1 = 1; sl@0: const TInt KInt1_InitialValue = 1; sl@0: const TInt KInt1_UpdatedValue = 73; sl@0: const TUint32 KNewInt = 1000; sl@0: // sl@0: const TUint32 KIntAlwaysPass = 0x201; sl@0: const TInt KIntAlwaysPass_Value = 200; sl@0: const TUint32 KIntAlwaysPassFail = 0x202; sl@0: sl@0: const TUint32 KReal1 = 2; sl@0: const TReal KReal1_InitialValue = 2.732; sl@0: const TReal KReal1_UpdatedValue = 72.8; sl@0: const TUint32 KNewReal = 2000; sl@0: sl@0: const TUint32 KString1 = 5; sl@0: _LIT(KString1_InitialValue, "test\\\"string\""); sl@0: _LIT(KString1_UpdatedValue, "another one"); sl@0: const TUint32 KNewString8 = 3000; sl@0: const TUint32 KNewString16 = 4000; sl@0: sl@0: RArray RepsToReset; sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: //Test macroses and functions sl@0: sl@0: LOCAL_C void CheckL(TInt aValue, TInt aLine) sl@0: { sl@0: if(!aValue) sl@0: { 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: CleanupCDriveL(); sl@0: RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: sl@0: #define TEST(arg) ::CheckL((arg), __LINE__) sl@0: #define TEST2(aValue, aExpected) ::CheckL(aValue, aExpected, __LINE__) sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: // Function to compare two TUid's. sl@0: LOCAL_C TInt CompareUid(const TUid& aUid1, const TUid& aUid2) sl@0: { sl@0: return aUid1.iUid - aUid2.iUid; sl@0: } sl@0: sl@0: LOCAL_C void AddRepositoryToReset(const TUid& aRepositoryUid) sl@0: { sl@0: // Use InsertInOrder not because of speed but to eliminate sl@0: // duplicates. sl@0: RepsToReset.InsertInOrder(aRepositoryUid, CompareUid); sl@0: } sl@0: sl@0: // NB: this test suite needs each test run to start with keyspaces with values from sl@0: // the initialization files in ROM dir. The best way to archive this is to send the sl@0: // EGetSetParameters IPC to centrep server to flush cache and then delete sl@0: // the .cre files. This option requires the CENTREP_SERVER_CACHETEST macro sl@0: // which is not available in release ONB. The second choice is to wait enough sl@0: // time for centrep server to flush out cache, then delete the .cre files from sl@0: // persists dir. This approach does not work well on the emulator because centrep sl@0: // server's cache timer sometimes is late by as much as a few seconds. sl@0: // Hence instead of wait and delete the .cre files, this RTest uses the ResetAll sl@0: // API. This trick works for the use case of this RTest but may not work in other sl@0: // situations. E.g., in this RTest centrep server always open repositories sl@0: // from cache. This changes the timing pattern and does not exercise the sl@0: // cache eviction code path. sl@0: LOCAL_C void ResetModifiedRepsL() sl@0: { sl@0: for (TInt i = RepsToReset.Count() - 1; i >= 0; i--) sl@0: { sl@0: CRepository* rep; sl@0: User::LeaveIfNull( rep = CRepository::NewL(RepsToReset[i]) ); sl@0: rep->Reset(); sl@0: delete rep; sl@0: sl@0: RepsToReset.Remove(i); sl@0: } sl@0: } sl@0: sl@0: LOCAL_C void OpenRepositoryL() sl@0: { sl@0: CRepository* repositoryA; sl@0: sl@0: TInt r; sl@0: sl@0: TRAP(r, CRepository::NewL(TUid::Null())); sl@0: if(OomTesting && r==KErrNoMemory) sl@0: User::Leave(KErrNoMemory); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: repositoryA = CRepository::NewLC(KUidPlatsecTestRepository); sl@0: sl@0: TInt a; sl@0: r = repositoryA->Get(KInt1, a); sl@0: TEST2(r, KErrNone); sl@0: TEST(a==KInt1_InitialValue); sl@0: sl@0: CleanupStack::PopAndDestroy(repositoryA); sl@0: sl@0: } sl@0: sl@0: LOCAL_C void GetSetL() sl@0: { sl@0: CRepository* repository; sl@0: User::LeaveIfNull(repository = CRepository::NewLC(KUidPlatsecTestRepository)); sl@0: sl@0: // Remember that this repository need to be reset sl@0: ::AddRepositoryToReset(KUidPlatsecTestRepository); sl@0: sl@0: // sl@0: // Integer get/set sl@0: // sl@0: sl@0: TInt i = 0; sl@0: sl@0: TInt r = repository->Get(KNonExisitent, i); sl@0: TEST2(r, KErrNotFound); sl@0: TEST(i==0); sl@0: sl@0: // no capability specified so deafult should do and should succeed sl@0: r = repository->Get(KReal1, i); sl@0: TEST2(r, KErrArgument); sl@0: TEST(i==0); sl@0: sl@0: // no capability specified so deafult should do and should succeed sl@0: r = repository->Get(KInt1, i); sl@0: TEST2(r, KErrNone); sl@0: TEST(i==KInt1_InitialValue); sl@0: sl@0: r = repository->Set(KNonExisitent, 0); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Delete(KNonExisitent); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Set(KReal1, 0); sl@0: TEST2(r, KErrArgument); sl@0: sl@0: r = repository->Set(KInt1, KInt1_UpdatedValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Get(KInt1, i); sl@0: TEST2(r, KErrNone); sl@0: TEST(i==KInt1_UpdatedValue); sl@0: sl@0: r = repository->Get(KIntAlwaysPass, i); sl@0: // range policy AlwaysPass sl@0: TEST2(r, KErrNone); sl@0: TEST(i==KIntAlwaysPass_Value); sl@0: sl@0: i=0; sl@0: r = repository->Get(KIntAlwaysPassFail, i); sl@0: // range policy overidden sl@0: TEST2(r, KErrPermissionDenied); sl@0: TEST(i!=KIntAlwaysPass_Value); sl@0: sl@0: sl@0: // sl@0: // Real get/set sl@0: // sl@0: sl@0: TReal y = 0; sl@0: sl@0: r = repository->Get(KNonExisitent, y); sl@0: TEST2(r, KErrNotFound); sl@0: TEST(y==0); sl@0: sl@0: r = repository->Get(KInt1, y); sl@0: TEST2(r, KErrArgument); sl@0: TEST(y==0); sl@0: sl@0: r = repository->Get(KReal1, y); sl@0: TEST2(r, KErrNone); sl@0: TEST(y==KReal1_InitialValue); sl@0: sl@0: r = repository->Set(KNonExisitent, 0.0); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Delete(KNonExisitent); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Set(KInt1, 0.0); sl@0: TEST2(r, KErrArgument); sl@0: sl@0: r = repository->Set(KReal1, KReal1_UpdatedValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Get(KReal1, y); sl@0: TEST2(r, KErrNone); sl@0: TEST(y==KReal1_UpdatedValue); sl@0: sl@0: // sl@0: // String get/set sl@0: // sl@0: sl@0: TBuf<20> str; sl@0: sl@0: r = repository->Get(KNonExisitent, str); sl@0: TEST2(r, KErrNotFound); sl@0: TEST(str.Length()==0); sl@0: sl@0: r = repository->Get(KInt1, str); sl@0: TEST2(r, KErrArgument); sl@0: TEST(str.Length()==0); sl@0: sl@0: r = repository->Get(KString1, str); sl@0: PlatSec platsec; sl@0: sl@0: if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) sl@0: { sl@0: TEST2(r, KErrNone); sl@0: TEST(str==KString1_InitialValue); sl@0: } sl@0: else sl@0: TEST2(r, KErrPermissionDenied); sl@0: sl@0: sl@0: TBuf<10> tooShort; sl@0: r = repository->Get(KString1, tooShort); sl@0: sl@0: if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) sl@0: { sl@0: TEST2(r, KErrOverflow); sl@0: TEST(tooShort.Length()==0); sl@0: } sl@0: else sl@0: TEST2(r, KErrPermissionDenied); sl@0: sl@0: sl@0: r = repository->Set(KNonExisitent, str); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Delete(KNonExisitent); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Set(KInt1, str); sl@0: TEST2(r, KErrArgument); sl@0: sl@0: r = repository->Set(KString1, KString1_UpdatedValue); sl@0: if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) sl@0: { sl@0: TEST2(r, KErrNone); sl@0: } sl@0: else sl@0: TEST2(r, KErrPermissionDenied); sl@0: sl@0: r = repository->Get(KString1, str); sl@0: sl@0: if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) sl@0: { sl@0: TEST2(r, KErrNone); sl@0: TEST(str==KString1_UpdatedValue); sl@0: } sl@0: else sl@0: TEST2(r, KErrPermissionDenied); sl@0: sl@0: const TInt KStringLengthTooBig = KMaxUnicodeStringLength + 1; sl@0: TBuf tooBig; sl@0: tooBig.SetLength(KStringLengthTooBig); sl@0: r = repository->Set(KString1, tooBig); sl@0: TEST2(r, KErrArgument); sl@0: sl@0: CleanupStack::PopAndDestroy(repository); sl@0: } sl@0: sl@0: LOCAL_C void CreateSetIntTransactionL() sl@0: { sl@0: CRepository* repository; sl@0: User::LeaveIfNull(repository = CRepository::NewLC(KUidTransactionTestRepository)); sl@0: sl@0: // Remember that this repository need to be reset sl@0: ::AddRepositoryToReset(KUidTransactionTestRepository); sl@0: sl@0: // sl@0: // Integer get/set sl@0: // sl@0: TInt r; sl@0: TInt i = 0; sl@0: const TInt imax = 0x0ff; sl@0: TUint32 errorId; sl@0: sl@0: r = repository->StartTransaction(CRepository::EReadWriteTransaction); sl@0: repository->CleanupRollbackTransactionPushL(); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // create sl@0: TInt KIntStartValue = 100; sl@0: const TUint32 KNewIntBase = 1; sl@0: for(i=0;iCreate(KNewIntBase+i, KIntStartValue+i); sl@0: if(OomTesting && (r==KErrNoMemory)) sl@0: User::Leave(KErrNoMemory); sl@0: else sl@0: TEST2(r, KErrNone); sl@0: } sl@0: sl@0: r = repository->CommitTransaction(errorId); sl@0: CleanupStack::Pop(); sl@0: if(OomTesting && r!=KErrNone) sl@0: { sl@0: // in OOM test we may have alredy created settings sl@0: TEST2(r, KErrAlreadyExists); sl@0: } sl@0: else sl@0: TEST2(r, KErrNone); sl@0: sl@0: TInt integer; sl@0: if(!(OomTesting && r==KErrAlreadyExists)) sl@0: { sl@0: // during OOM tests we have values from Sets rather then Create... sl@0: for(i=0;iGet(KNewIntBase+i,integer ); sl@0: TEST2(r, KErrNone); sl@0: TEST(KIntStartValue+i==integer); sl@0: } sl@0: } sl@0: r = repository->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: repository->CleanupRollbackTransactionPushL(); sl@0: sl@0: // set sl@0: KIntStartValue = 200; sl@0: for(i=0;iSet(KNewIntBase+i, KIntStartValue+i); sl@0: if(OomTesting && (r==KErrNoMemory)) sl@0: User::Leave(KErrNoMemory); sl@0: else sl@0: TEST2(r, KErrNone); sl@0: } sl@0: sl@0: r = repository->CommitTransaction(errorId); sl@0: CleanupStack::Pop(); sl@0: TEST2(r, KErrNone); sl@0: for(i=0;iGet(KNewIntBase+i,integer ); sl@0: TEST2(r, KErrNone); sl@0: TEST(KIntStartValue+i==integer); sl@0: } sl@0: sl@0: // lets check set where some are going to fail sl@0: // set sl@0: r = repository->StartTransaction(CRepository::EReadWriteTransaction); sl@0: repository->CleanupRollbackTransactionPushL(); sl@0: TEST2(r, KErrNone); sl@0: KIntStartValue = 400; sl@0: TInt base = KNewIntBase + 0x7f; // half the range ok other half should fail sl@0: for(i=0;iSet(base+i, KIntStartValue+i); sl@0: if(OomTesting && (r==KErrNoMemory)) sl@0: User::Leave(KErrNoMemory); sl@0: else sl@0: { sl@0: if (base + i < 0x100) sl@0: { sl@0: TEST2(r, KErrNone); sl@0: } sl@0: else if (base + i == 0x100) sl@0: { sl@0: TEST2(r, KErrNone); sl@0: // this causes transaction to fail sl@0: const TReal KRealValue = 1.234; sl@0: r = repository->Set(base+i, KRealValue); sl@0: TEST2(r, KErrArgument); sl@0: } sl@0: else sl@0: { sl@0: // after transaction has failed, repository returns KErrAbort for every request sl@0: TEST2(r, KErrAbort); sl@0: } sl@0: } sl@0: } sl@0: sl@0: r = repository->CommitTransaction(errorId); sl@0: TEST2(r, KErrArgument); sl@0: TEST2(errorId, 0x100); sl@0: CleanupStack::Pop(); sl@0: // should be able to open again sl@0: r = repository->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: repository->RollbackTransaction(); sl@0: sl@0: // and after the failed transaction it should be in previous state!! sl@0: KIntStartValue = 200; sl@0: for(i=0;iGet(KNewIntBase+i,integer ); sl@0: TEST2(r, KErrNone); sl@0: TEST(KIntStartValue+i==integer); sl@0: } sl@0: sl@0: // lets clear after ourselves sl@0: for(i=0;iDelete(KNewIntBase+i); sl@0: TEST2(r, KErrNone); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(repository); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void CreateSetDesTransactionL() sl@0: { sl@0: TUint32 errorId; sl@0: CRepository* repository; sl@0: User::LeaveIfNull(repository = CRepository::NewLC(KUidTransactionTestRepository)); sl@0: sl@0: // Remember that this repository need to be reset sl@0: ::AddRepositoryToReset(KUidTransactionTestRepository); sl@0: sl@0: sl@0: _LIT(KString1_TestValue, "test string 1"); sl@0: _LIT(KString2_TestValue, "test string 2"); sl@0: _LIT(KString3_TestValue, "test string 3"); sl@0: _LIT(KString4_TestValue, "test string 4"); sl@0: _LIT(KString5_TestValue, "test string 5"); sl@0: _LIT(KString1_UpdatedTestValue, "updated test string 1"); sl@0: _LIT(KString2_UpdatedTestValue, "updated test string 2"); sl@0: // sl@0: // Descriptor get/set sl@0: // sl@0: TInt r; sl@0: sl@0: sl@0: r = repository->StartTransaction(CRepository::EReadWriteTransaction); sl@0: repository->CleanupRollbackTransactionPushL(); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // create sl@0: r = repository->Create(1, KString1_TestValue); sl@0: if(OomTesting && (r==KErrNoMemory)) sl@0: User::Leave(KErrNoMemory); sl@0: else sl@0: TEST2(r, KErrNone); sl@0: r = repository->Create(2, KString2_TestValue); sl@0: if(OomTesting && (r==KErrNoMemory)) sl@0: User::Leave(KErrNoMemory); sl@0: else sl@0: TEST2(r, KErrNone); sl@0: r = repository->Create(3, KString3_TestValue); sl@0: if(OomTesting && (r==KErrNoMemory)) sl@0: User::Leave(KErrNoMemory); sl@0: else sl@0: TEST2(r, KErrNone); sl@0: r = repository->Create(4, KString4_TestValue); sl@0: if(OomTesting && (r==KErrNoMemory)) sl@0: User::Leave(KErrNoMemory); sl@0: else sl@0: TEST2(r, KErrNone); sl@0: r = repository->Create(5, KString5_TestValue); sl@0: if(OomTesting && (r==KErrNoMemory)) sl@0: User::Leave(KErrNoMemory); sl@0: else sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->CommitTransaction(errorId); sl@0: CleanupStack::Pop(); sl@0: if(OomTesting && r!=KErrNone) sl@0: { sl@0: // in OOM test we may have alredy created settings sl@0: TEST2(r, KErrAlreadyExists); sl@0: } sl@0: else sl@0: TEST2(r, KErrNone); sl@0: sl@0: TBuf<50> buf; sl@0: if(!OomTesting) sl@0: { sl@0: r = repository->Get(1,buf); sl@0: TEST2(r, KErrNone); sl@0: TEST(buf==KString1_TestValue); sl@0: r = repository->Get(2,buf); sl@0: TEST2(r, KErrNone); sl@0: TEST(buf==KString2_TestValue); sl@0: r = repository->Get(3,buf); sl@0: TEST2(r, KErrNone); sl@0: TEST(buf==KString3_TestValue); sl@0: r = repository->Get(4,buf); sl@0: TEST2(r, KErrNone); sl@0: TEST(buf==KString4_TestValue); sl@0: r = repository->Get(5,buf); sl@0: TEST2(r, KErrNone); sl@0: TEST(buf==KString5_TestValue); sl@0: } sl@0: sl@0: r = repository->StartTransaction(CRepository::EReadWriteTransaction); sl@0: repository->CleanupRollbackTransactionPushL(); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // set sl@0: r = repository->Set(1, KString1_UpdatedTestValue); sl@0: if(OomTesting && (r==KErrNoMemory)) sl@0: User::Leave(KErrNoMemory); sl@0: else sl@0: TEST2(r, KErrNone); sl@0: r = repository->Set(2, KString2_UpdatedTestValue); sl@0: if(OomTesting && (r==KErrNoMemory)) sl@0: User::Leave(KErrNoMemory); sl@0: else sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->CommitTransaction(errorId); sl@0: CleanupStack::Pop(); sl@0: TEST2(r, KErrNone); sl@0: sl@0: TBuf<50> buf1,buf2; sl@0: r = repository->Get(1,buf1); sl@0: TEST2(r, KErrNone); sl@0: r = repository->Get(2,buf2); sl@0: TEST2(r, KErrNone); sl@0: sl@0: TEST(buf1==KString1_UpdatedTestValue); sl@0: TEST(buf2==KString2_UpdatedTestValue); sl@0: sl@0: CleanupStack::PopAndDestroy(repository); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void CreateSetRealTransactionL() sl@0: { sl@0: CRepository* repository; sl@0: User::LeaveIfNull(repository = CRepository::NewLC(KUidTransactionTestRepository)); sl@0: sl@0: // Remember that this repository need to be reset sl@0: ::AddRepositoryToReset(KUidTransactionTestRepository); sl@0: sl@0: // sl@0: // Real transaction get/set sl@0: // sl@0: TInt r; sl@0: TInt i = 0; sl@0: const TInt imax = 0x0ff; sl@0: sl@0: r = repository->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // create sl@0: const TReal KRealStartValue = 100.05; sl@0: const TUint32 KNewRealBase = 1; sl@0: for(i=0;iCreate(KNewRealBase+i, KRealStartValue+i); sl@0: TEST2(r, KErrNone); sl@0: } sl@0: sl@0: TUint32 errorId; sl@0: r = repository->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: TReal real, real2; sl@0: for(i=0; iGet((KNewRealBase+i), real ); sl@0: real2 = KRealStartValue+i; sl@0: TEST2(r, KErrNone); sl@0: TEST( real2 == real ); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(repository); sl@0: } sl@0: sl@0: LOCAL_C void ResetTransactionL() sl@0: { sl@0: #ifdef PENDING_REMOVAL sl@0: // reset operations are not supported in transactions for now. sl@0: // ResetAll will not ever be: still to decide on individual setting reset sl@0: // Both are very slow. sl@0: sl@0: TUint32 errorId; sl@0: CRepository* repository; sl@0: User::LeaveIfNull(repository = CRepository::NewLC(KUidPlatsecTestRepository)); sl@0: sl@0: // Remember that this repository need to be reset sl@0: ::AddRepositoryToReset(KUidPlatsecTestRepository); sl@0: sl@0: TInt r = repository->Set(KInt1, KInt1_UpdatedValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: TInt x,y; sl@0: r = repository->Get(KInt1, x); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Reset(KInt1); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Get(KInt1, y); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // did we get what expected after commit? sl@0: TEST(x!=KInt1_InitialValue); sl@0: TEST(y==KInt1_InitialValue); sl@0: sl@0: CleanupStack::PopAndDestroy(repository); sl@0: sl@0: // Repository B sl@0: // lets prepare for reset sl@0: User::LeaveIfNull(repository = CRepository::NewLC(KUidTransactionTestRepository)); sl@0: sl@0: // Remember that this repository need to be reset sl@0: ::AddRepositoryToReset(KUidTransactionTestRepository); sl@0: sl@0: const TInt KNewSettingAlwaysPass = 0x101; sl@0: sl@0: r = repository->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: TInt i = 0; sl@0: for(i=KNewSettingAlwaysPass;iCreate(i, i); sl@0: TEST2(r, KErrNone); sl@0: } sl@0: sl@0: sl@0: TRequestStatus status = -1; sl@0: r = repository->NotifyRequest(0, 0, status); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: TInt xArray[10]; sl@0: TInt xx=0; sl@0: for(i=0;i<10;i++) sl@0: { sl@0: r = repository->Get(KNewSettingAlwaysPass+i, xArray[i]); sl@0: TEST2(r, KErrNone); sl@0: } sl@0: sl@0: //and do the reset business now sl@0: r = repository->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Reset(); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // test reset after commit sl@0: TEST(status==KNewSettingAlwaysPass); sl@0: sl@0: for(i=0;i<10;i++) sl@0: { sl@0: TEST(xArray[i]==(KNewSettingAlwaysPass+i)); sl@0: } sl@0: sl@0: for(i=KNewSettingAlwaysPass;iGet(i, xx); sl@0: TEST2(r, KErrNotFound); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(repository); sl@0: #endif // PENDING_REMOVAL sl@0: } sl@0: sl@0: LOCAL_C void FindL() sl@0: { sl@0: CRepository* repository; sl@0: User::LeaveIfNull(repository = CRepository::NewLC(KUidPlatsecTestRepository)); sl@0: sl@0: RArray foundIds; sl@0: CleanupClosePushL(foundIds); sl@0: sl@0: TInt r = KErrNone; sl@0: sl@0: TRAPD(leaveReason, r = repository->FindL(0, 0, foundIds)); sl@0: if(OomTesting && (r==KErrNoMemory || leaveReason==KErrNoMemory)) sl@0: { sl@0: CleanupStack::PopAndDestroy(); //foundIds sl@0: User::Leave(KErrNoMemory); sl@0: } sl@0: // Note that we are allowed to find any setting regardless of it's platsec sl@0: // what we can't do is return the value sl@0: TEST2(r, KErrNone); sl@0: TEST(foundIds.Count()==KNumSettings); sl@0: sl@0: foundIds.Reset(); sl@0: sl@0: TRAP(leaveReason, r = repository->FindL(23, 0, foundIds)); // 23 - just a random number, value is not important sl@0: if(OomTesting && (r==KErrNoMemory || leaveReason==KErrNoMemory)) sl@0: { sl@0: CleanupStack::PopAndDestroy(); //foundIds sl@0: User::Leave(KErrNoMemory); sl@0: } sl@0: TEST2(r, KErrNone); sl@0: TEST(foundIds.Count()==KNumSettings); sl@0: sl@0: foundIds.Reset(); sl@0: sl@0: TRAP(leaveReason, r = repository->FindL(0, 2, foundIds)); sl@0: if(OomTesting && (r==KErrNoMemory || leaveReason==KErrNoMemory)) sl@0: { sl@0: CleanupStack::PopAndDestroy(); //foundIds sl@0: User::Leave(KErrNoMemory); sl@0: } sl@0: TEST2(r, KErrNone); sl@0: TEST(foundIds.Count()==22); sl@0: sl@0: foundIds.Reset(); sl@0: sl@0: TRAP(leaveReason, r = repository->FindL(4, 6, foundIds)); sl@0: if(OomTesting && (r==KErrNoMemory || leaveReason==KErrNoMemory)) sl@0: { sl@0: CleanupStack::PopAndDestroy(); //foundIds sl@0: User::Leave(KErrNoMemory); sl@0: } sl@0: TEST2(r, KErrNone); sl@0: TEST(foundIds.Count()==1); sl@0: sl@0: foundIds.Reset(); sl@0: sl@0: TRAP(leaveReason, r = repository->FindL(15, 15, foundIds)); sl@0: if(OomTesting && (r==KErrNoMemory || leaveReason==KErrNoMemory)) sl@0: { sl@0: CleanupStack::PopAndDestroy(); //foundIds sl@0: User::Leave(KErrNoMemory); sl@0: } sl@0: TEST2(r, KErrNotFound); sl@0: TEST(foundIds.Count()==0); sl@0: sl@0: CleanupStack::PopAndDestroy(); //foundIds sl@0: CleanupStack::PopAndDestroy(repository); sl@0: } sl@0: sl@0: LOCAL_C void NotifyL() sl@0: { sl@0: CRepository* repository; sl@0: User::LeaveIfNull(repository = CRepository::NewLC(KUidPlatsecTestRepository)); sl@0: // Remember that this repository need to be reset sl@0: ::AddRepositoryToReset(KUidPlatsecTestRepository); sl@0: sl@0: PlatSec platsec; sl@0: sl@0: // sl@0: // Notification on non-existent setting sl@0: // sl@0: TRequestStatus intStatus; sl@0: TInt r = repository->NotifyRequest(KNonExisitent, intStatus); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: sl@0: // sl@0: // Basic notification sl@0: // sl@0: r = repository->NotifyRequest(KInt1, intStatus); sl@0: TEST2(r, KErrNone); sl@0: sl@0: TRequestStatus realStatus; sl@0: r = repository->NotifyRequest(KReal1, realStatus); sl@0: TEST2(r, KErrNone); sl@0: sl@0: TRequestStatus stringStatus; sl@0: r = repository->NotifyRequest(KString1, stringStatus); sl@0: if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) sl@0: { sl@0: TEST2(r, KErrNone); sl@0: } sl@0: else sl@0: { sl@0: TEST2(r, KErrPermissionDenied); sl@0: } sl@0: sl@0: sl@0: // Setting to the same value should not cause a notification sl@0: TInt intval; sl@0: r = repository->Get(KInt1, intval); sl@0: TEST2(r, KErrNone); sl@0: r = repository->Set(KInt1, intval); sl@0: TEST2(r, KErrNone); sl@0: TEST(intStatus==KRequestPending); sl@0: TEST(realStatus==KRequestPending); sl@0: if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) sl@0: TEST(stringStatus==KRequestPending); sl@0: RThread thisThread; sl@0: TEST(thisThread.RequestCount()==0); sl@0: sl@0: // First change to setting should cause notification sl@0: r = repository->Set(KInt1, 0); sl@0: TEST2(r, KErrNone); sl@0: User::WaitForAnyRequest(); sl@0: TEST(intStatus==KInt1); sl@0: TEST(realStatus==KRequestPending); sl@0: if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) sl@0: TEST(stringStatus==KRequestPending); sl@0: sl@0: // Second change to setting should not cause notification sl@0: intStatus = 7777; sl@0: r = repository->Set(KInt1, 0); sl@0: TEST2(r, KErrNone); sl@0: TEST(intStatus==7777); sl@0: TEST(realStatus==KRequestPending); sl@0: if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) sl@0: TEST(stringStatus==KRequestPending); sl@0: TEST(thisThread.RequestCount()==0); sl@0: sl@0: sl@0: // Setting to the same value should not cause a notification sl@0: TReal realval; sl@0: r = repository->Get(KReal1, realval); sl@0: TEST2(r, KErrNone); sl@0: r = repository->Set(KReal1, realval); sl@0: TEST2(r, KErrNone); sl@0: TEST(intStatus==7777); sl@0: TEST(realStatus==KRequestPending); sl@0: if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) sl@0: TEST(stringStatus==KRequestPending); sl@0: TEST(thisThread.RequestCount()==0); sl@0: sl@0: r = repository->Set(KReal1, 0.0); sl@0: TEST2(r, KErrNone); sl@0: User::WaitForAnyRequest(); sl@0: TEST(intStatus==7777); sl@0: TEST(realStatus==KReal1); sl@0: if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) sl@0: TEST(stringStatus==KRequestPending); sl@0: sl@0: sl@0: // Setting to the same value should not cause a notification sl@0: realStatus = 8888; sl@0: TBuf<20> stringval; sl@0: r = repository->Get(KString1, stringval); sl@0: if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) sl@0: TEST2(r, KErrNone); sl@0: else sl@0: TEST2(r, KErrPermissionDenied); sl@0: r = repository->Set(KString1, stringval); sl@0: if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) sl@0: TEST2(r, KErrNone); sl@0: else sl@0: TEST2(r, KErrPermissionDenied); sl@0: TEST(intStatus==7777); sl@0: TEST(realStatus==8888); sl@0: if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) sl@0: TEST(stringStatus==KRequestPending); sl@0: TEST(thisThread.RequestCount()==0); sl@0: sl@0: _LIT(KStringValue2, "string2"); sl@0: r = repository->Set(KString1, KStringValue2); sl@0: if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) sl@0: { sl@0: TEST2(r, KErrNone); sl@0: User::WaitForAnyRequest(); sl@0: } sl@0: else sl@0: TEST2(r, KErrPermissionDenied); sl@0: sl@0: TEST(intStatus==7777); sl@0: TEST(realStatus==8888); sl@0: if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) sl@0: TEST(stringStatus==KString1); sl@0: sl@0: sl@0: // sl@0: // Cancelling single notifications sl@0: // sl@0: r = repository->NotifyRequest(KInt1, intStatus); sl@0: TEST2(r, KErrNone); sl@0: r = repository->NotifyCancel(KInt1); sl@0: TEST2(r, KErrNone); sl@0: User::WaitForAnyRequest(); sl@0: TEST(intStatus==KUnspecifiedKey); sl@0: sl@0: intStatus = 7777; sl@0: r = repository->NotifyRequest(KReal1, realStatus); sl@0: TEST2(r, KErrNone); sl@0: r = repository->Set(KInt1, 1); sl@0: TEST2(r, KErrNone); sl@0: r = repository->Set(KReal1, 1.1); sl@0: TEST2(r, KErrNone); sl@0: User::WaitForAnyRequest(); sl@0: TEST(intStatus==7777); sl@0: TEST(realStatus==KReal1); sl@0: TEST(thisThread.RequestCount()==0); sl@0: sl@0: sl@0: // sl@0: // Cancelling all notifications sl@0: // sl@0: realStatus = 8888; sl@0: r = repository->NotifyRequest(KInt1, intStatus); sl@0: TEST2(r, KErrNone); sl@0: r = repository->NotifyRequest(KReal1, realStatus); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->NotifyCancelAll(); sl@0: TEST2(r, KErrNone); sl@0: User::WaitForAnyRequest(); sl@0: User::WaitForAnyRequest(); sl@0: TEST(intStatus==KUnspecifiedKey); sl@0: TEST(realStatus==KUnspecifiedKey); sl@0: sl@0: intStatus = 7777; sl@0: realStatus = 8888; sl@0: r = repository->Set(KInt1, 2); sl@0: TEST2(r, KErrNone); sl@0: r = repository->Set(KReal1, 2.2); sl@0: TEST2(r, KErrNone); sl@0: TEST(intStatus==7777); sl@0: TEST(realStatus==8888); sl@0: TEST(thisThread.RequestCount()==0); sl@0: sl@0: // sl@0: // Group notifications sl@0: // sl@0: r = repository->NotifyRequest(0, 0, intStatus); sl@0: TEST2(r, KErrNone); sl@0: User::WaitForAnyRequest(); sl@0: // we do not have capabilities for all settings sl@0: TEST(intStatus==KErrPermissionDenied); sl@0: sl@0: CleanupStack::PopAndDestroy(repository); sl@0: } sl@0: sl@0: LOCAL_C void CreateDeleteL() sl@0: { sl@0: CRepository* repository; sl@0: User::LeaveIfNull(repository = CRepository::NewLC(KUidPlatsecTestRepository)); sl@0: // Remember that this repository need to be reset sl@0: ::AddRepositoryToReset(KUidPlatsecTestRepository); sl@0: sl@0: TInt x; sl@0: TInt r = repository->Get(KNewInt, x); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: const TInt KIntValue = 1234; sl@0: r = repository->Create(KNewInt, KIntValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Get(KNewInt, x); sl@0: TEST2(r, KErrNone); sl@0: TEST(x==KIntValue); sl@0: sl@0: r = repository->Delete(KNewInt); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Get(KNewInt, x); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: r = repository->Create(KNewInt, KIntValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Get(KNewInt, x); sl@0: TEST2(r, KErrNone); sl@0: TEST(x==KIntValue); sl@0: sl@0: r = repository->Get(KNewInt, x); sl@0: TEST2(r, KErrNone); sl@0: TEST(x==KIntValue); sl@0: sl@0: TReal y; sl@0: r = repository->Get(KNewReal, y); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: const TReal KRealValue = 5678.0; sl@0: r = repository->Create(KNewReal, KRealValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Get(KNewReal, y); sl@0: TEST2(r, KErrNone); sl@0: TEST(y==KRealValue); sl@0: sl@0: r = repository->Delete(KNewReal); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Get(KNewReal, y); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: r = repository->Create(KNewReal, KRealValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Get(KNewReal, y); sl@0: TEST2(r, KErrNone); sl@0: TEST(y==KRealValue); sl@0: sl@0: r = repository->Get(KNewReal, y); sl@0: TEST2(r, KErrNone); sl@0: TEST(y==KRealValue); sl@0: sl@0: TBuf8<20> z8; sl@0: r = repository->Get(KNewString8, z8); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: _LIT8(KString8Value, "ABCDEF"); sl@0: r = repository->Create(KNewString8, KString8Value); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Get(KNewString8, z8); sl@0: TEST2(r, KErrNone); sl@0: TEST(z8==KString8Value); sl@0: sl@0: r = repository->Delete(KNewString8); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Get(KNewString8, z8); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: r = repository->Create(KNewString8, KString8Value); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Get(KNewString8, z8); sl@0: TEST2(r, KErrNone); sl@0: TEST(z8==KString8Value); sl@0: sl@0: r = repository->Get(KNewString8, z8); sl@0: TEST2(r, KErrNone); sl@0: TEST(z8==KString8Value); sl@0: sl@0: TBuf16<20> z16; sl@0: r = repository->Get(KNewString16, z16); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: _LIT(KString16Value, "ghijklmn"); sl@0: r = repository->Create(KNewString16, KString16Value); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Get(KNewString16, z16); sl@0: TEST2(r, KErrNone); sl@0: TEST(z16==KString16Value); sl@0: sl@0: r = repository->Delete(KNewString16); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Get(KNewString16, z16); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: r = repository->Create(KNewString16, KString16Value); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Get(KNewString16, z16); sl@0: TEST2(r, KErrNone); sl@0: TEST(z16==KString16Value); sl@0: sl@0: r = repository->Get(KNewString16, z16); sl@0: TEST2(r, KErrNone); sl@0: TEST(z16==KString16Value); sl@0: sl@0: CleanupStack::PopAndDestroy(repository); sl@0: } sl@0: sl@0: LOCAL_C void MultiClientL() sl@0: { sl@0: CRepository* repository1; sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidPlatsecTestRepository)); sl@0: CRepository* repository2; sl@0: User::LeaveIfNull(repository2 = CRepository::NewLC(KUidPlatsecTestRepository)); sl@0: sl@0: // Remember that this repository need to be reset sl@0: ::AddRepositoryToReset(KUidPlatsecTestRepository); sl@0: sl@0: // sl@0: // Get/Set sl@0: // sl@0: TInt i; sl@0: TInt r = repository1->Set(KInt1, 0); sl@0: TEST2(r, KErrNone); sl@0: r = repository2->Get(KInt1, i); sl@0: TEST2(r, KErrNone); sl@0: TEST(i==0); sl@0: sl@0: r = repository2->Set(KInt1, 123); sl@0: TEST2(r, KErrNone); sl@0: r = repository1->Get(KInt1, i); sl@0: TEST2(r, KErrNone); sl@0: TEST(i==123); sl@0: sl@0: // sl@0: // Notification sl@0: // sl@0: TRequestStatus status; sl@0: r = repository1->NotifyRequest(KInt1, status); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository2->Set(KInt1, 0); sl@0: TEST2(r, KErrNone); sl@0: User::WaitForAnyRequest(); sl@0: TEST(status==KInt1); sl@0: sl@0: CleanupStack::PopAndDestroy(2); sl@0: } sl@0: sl@0: LOCAL_C void ResetL() sl@0: { sl@0: CRepository* repository; sl@0: User::LeaveIfNull(repository = CRepository::NewLC(KUidPlatsecTestRepository)); sl@0: sl@0: TInt x; sl@0: TInt r = repository->Get(KInt1, x); sl@0: TEST2(r, KErrNone); sl@0: TEST(x!=KInt1_InitialValue); sl@0: sl@0: r = repository->Reset(KInt1); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Get(KInt1, x); sl@0: TEST2(r, KErrNone); sl@0: TEST(x==KInt1_InitialValue); sl@0: sl@0: CleanupStack::PopAndDestroy(repository); sl@0: sl@0: // Repository D sl@0: User::LeaveIfNull(repository = CRepository::NewLC(KUidResetTestRepository)); sl@0: // Remember that this repository need to be reset sl@0: ::AddRepositoryToReset(KUidResetTestRepository); sl@0: sl@0: sl@0: const TInt KNewSetting1 = 5; sl@0: const TInt KNewSetting2 = 6; sl@0: r = repository->Create(KNewSetting1, 0); sl@0: TEST2(r, KErrNone); sl@0: r = repository->Create(KNewSetting2, 0); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Create(65, 1); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Set(70, 1); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Create(80, 1); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Create(90, 1); sl@0: TEST2(r, KErrNone); sl@0: sl@0: TRequestStatus status = -1; sl@0: r = repository->NotifyRequest(0, 0, status); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Reset(); sl@0: TEST2(r, KErrNone); sl@0: TEST(status==KUnspecifiedKey); sl@0: RThread thisThread; sl@0: TEST(thisThread.RequestCount()==1); sl@0: sl@0: r = repository->Get(10, x); sl@0: TEST2(r, KErrNone); sl@0: TEST(x==10); sl@0: sl@0: r = repository->Get(40, x); sl@0: TEST2(r, KErrNone); sl@0: TEST(x==0); sl@0: sl@0: r = repository->Get(50, x); sl@0: TEST2(r, KErrNone); sl@0: TEST(x==0); sl@0: sl@0: r = repository->Get(60, x); sl@0: TEST2(r, KErrNone); sl@0: TEST(x==0); sl@0: sl@0: r = repository->Get(70, x); sl@0: TEST2(r, KErrNone); sl@0: TEST(x==0); sl@0: sl@0: TBuf<10> z; sl@0: r = repository->Get(20, z); sl@0: TEST2(r, KErrNone); sl@0: TEST(z==_L("string")); sl@0: sl@0: TReal y; sl@0: r = repository->Get(30, y); sl@0: TEST2(r, KErrNone); sl@0: TEST(y==1); sl@0: sl@0: r = repository->Get(5, x); sl@0: TEST2(r, KErrNotFound); sl@0: r = repository->Get(6, x); sl@0: TEST2(r, KErrNotFound); sl@0: r = repository->Get(65, x); sl@0: TEST2(r, KErrNotFound); sl@0: r = repository->Get(80, x); sl@0: TEST2(r, KErrNotFound); sl@0: r = repository->Get(90, x); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: CleanupStack::PopAndDestroy(repository); sl@0: } sl@0: sl@0: LOCAL_C void FuncBasicTestsL() sl@0: { sl@0: TheTest.Start(_L("Open/Close repository")); sl@0: OpenRepositoryL(); sl@0: sl@0: TheTest.Next(_L("Get/Set")); sl@0: GetSetL(); sl@0: sl@0: TheTest.Next(_L("Find")); sl@0: FindL(); sl@0: sl@0: TheTest.Next(_L("Notify")); sl@0: NotifyL(); sl@0: sl@0: TheTest.Next(_L("Create/Delete")); sl@0: CreateDeleteL(); sl@0: sl@0: TheTest.Next(_L("Multiple clients")); sl@0: MultiClientL(); sl@0: sl@0: TheTest.Next(_L("Restore factory settings")); sl@0: ResetL(); sl@0: sl@0: TheTest.End(); sl@0: } sl@0: sl@0: LOCAL_C void FuncTransactionTestsL() sl@0: { sl@0: TheTest.Start(_L("Open/Close repository")); sl@0: OpenRepositoryL(); sl@0: sl@0: TheTest.Next(_L("Create/Set Int Transaction")); sl@0: CreateSetIntTransactionL(); sl@0: sl@0: TheTest.Next(_L("Create/Set Real Transaction")); sl@0: CreateSetRealTransactionL(); sl@0: sl@0: TheTest.Next(_L("Create/Set Descriptor Transaction")); sl@0: sl@0: // Instead of wait for cache clear, this test uses the ResetAll API to sl@0: // restore keyspaces to original ROM settings. See the notes at implementation sl@0: // of ResetModifiedRepsL which explains why this is done and possible sl@0: // undesirable effects. sl@0: ::ResetModifiedRepsL(); sl@0: sl@0: CreateSetDesTransactionL(); sl@0: sl@0: TheTest.Next(_L("Restore factory settings")); sl@0: ResetTransactionL(); sl@0: sl@0: TheTest.End(); sl@0: } sl@0: sl@0: sl@0: // --------------------------------------------------- sl@0: // OomTest sl@0: // sl@0: // Function to convert a test into an OOM test sl@0: sl@0: LOCAL_C void OomTest(void (*testFuncL)()) sl@0: { sl@0: TInt error; sl@0: TInt count = 0; sl@0: sl@0: do sl@0: { sl@0: User::__DbgSetAllocFail(RHeap::EUser, RHeap::EFailNext, ++count); sl@0: User::__DbgMarkStart(RHeap::EUser); sl@0: TRAP(error, (testFuncL)()); sl@0: User::__DbgMarkEnd(RHeap::EUser, 0); sl@0: } while(error == KErrNoMemory); sl@0: sl@0: _LIT(KTestFailed, "Out of memory test failure on iteration %d\n"); sl@0: __ASSERT_ALWAYS(error==KErrNone, TheTest.Panic(error, KTestFailed, count)); sl@0: sl@0: User::__DbgSetAllocFail(RHeap::EUser, RHeap::ENone, 1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0032 sl@0: @SYMTestCaseDesc BasicPlatsecTestsL() function calls test for the Secure Cenrep (setting). sl@0: Methods of CRepository class are called for various combination of different settings sl@0: and the results are asserted. sl@0: @SYMTestPriority High sl@0: @SYMTestActions BasicPlatsecTestsL() method calls test. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMPREQ PREQ277 sl@0: PREQ280 sl@0: */ sl@0: LOCAL_C void BasicPlatsecTestsL() sl@0: { sl@0: TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0032 Basic functional tests for PlatSec ")); sl@0: OomTesting = EFalse; sl@0: sl@0: // Instead of wait for cache clear, this test uses the ResetAll API to sl@0: // restore keyspaces to original ROM settings. See the notes at implementation sl@0: // of ResetModifiedRepsL which explains why this is done and possible sl@0: // undesirable effects. sl@0: RepsToReset.AppendL(KUidPlatsecTestRepository); sl@0: RepsToReset.AppendL(KUidTransactionTestRepository); sl@0: RepsToReset.AppendL(KUidResetTestRepository); sl@0: ::ResetModifiedRepsL(); sl@0: sl@0: FuncBasicTestsL(); sl@0: sl@0: TheTest.Next(_L("Basic Out-of-memory tests")); sl@0: sl@0: // Instead of wait for cache clear, this test uses the ResetAll API to sl@0: // restore keyspaces to original ROM settings. See the notes at implementation sl@0: // of ResetModifiedRepsL which explains why this is done and possible sl@0: // undesirable effects. sl@0: ::ResetModifiedRepsL(); sl@0: sl@0: OomTesting = ETrue; sl@0: TheTest.Next(_L("OOM Open/Close repository")); sl@0: OomTest(OpenRepositoryL); sl@0: sl@0: GetSetL(); sl@0: sl@0: TheTest.Next(_L("OOM Find")); sl@0: OomTest(FindL); sl@0: sl@0: TheTest.End(); sl@0: } sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0033 sl@0: @SYMTestCaseDesc TransactionPlatsecTestsL() function calls test for the Secure Cenrep (setting). sl@0: Methods of CRepository class are called for various combination of different settings sl@0: in a 'transaction' mode and the results are asserted. sl@0: @SYMTestPriority High sl@0: @SYMTestActions TransactionPlatsecTestsL() method calls test. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMPREQ PREQ277 sl@0: PREQ280 sl@0: */ sl@0: LOCAL_C void TransactionPlatsecTestsL() sl@0: { sl@0: TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0033 Transaction functional tests for PlatSec ")); sl@0: OomTesting = EFalse; sl@0: sl@0: // Instead of wait for cache clear, this test uses the ResetAll API to sl@0: // restore keyspaces to original ROM settings. See the notes at implementation sl@0: // of ResetModifiedRepsL which explains why this is done and possible sl@0: // undesirable effects. sl@0: ::ResetModifiedRepsL(); sl@0: sl@0: FuncTransactionTestsL(); sl@0: sl@0: TheTest.Next(_L("Transaction Out-of-memory tests")); sl@0: sl@0: // Instead of wait for cache clear, this test uses the ResetAll API to sl@0: // restore keyspaces to original ROM settings. See the notes at implementation sl@0: // of ResetModifiedRepsL which explains why this is done and possible sl@0: // undesirable effects. sl@0: ::ResetModifiedRepsL(); sl@0: sl@0: OomTesting = ETrue; sl@0: TheTest.Next(_L("OOM Open/Close repository")); sl@0: OomTest(OpenRepositoryL); sl@0: sl@0: TheTest.Next(_L("OOM Transaction Int")); sl@0: OomTest(CreateSetIntTransactionL); sl@0: sl@0: // Instead of wait for cache clear, this test uses the ResetAll API to sl@0: // restore keyspaces to original ROM settings. See the notes at implementation sl@0: // of ResetModifiedRepsL which explains why this is done and possible sl@0: // undesirable effects. sl@0: ::ResetModifiedRepsL(); sl@0: sl@0: sl@0: TheTest.Next(_L("OOM Transaction Descriptors")); sl@0: OomTest(CreateSetDesTransactionL); sl@0: sl@0: // Instead of wait for cache clear, this test uses the ResetAll API to sl@0: // restore keyspaces to original ROM settings. See the notes at implementation sl@0: // of ResetModifiedRepsL which explains why this is done and possible sl@0: // undesirable effects. sl@0: ::ResetModifiedRepsL(); sl@0: sl@0: TheTest.End(); sl@0: } sl@0: sl@0: LOCAL_C void ServerPersistenceTest() sl@0: { sl@0: // Wait for a while after last test and ensure server is still running sl@0: User::After(KGeneralDelay); sl@0: sl@0: _LIT( KCentralRepositoryServerName, "Centralrepository*"); sl@0: TFullName serverName; sl@0: TFindProcess serverFind(KCentralRepositoryServerName); sl@0: TEST2(serverFind.Next(serverName), KErrNone); sl@0: } sl@0: sl@0: LOCAL_C void MainL() sl@0: { sl@0: // allocate slots ahead of time to avoid problems with OOM tests. sl@0: RepsToReset.ReserveL(KMaxNumRepsToReset); sl@0: sl@0: TheTest.Start(_L("Tests for basic PlatSec")); sl@0: BasicPlatsecTestsL(); sl@0: sl@0: TheTest.Next(_L("Tests for Transaction PlatSec")); sl@0: TransactionPlatsecTestsL(); sl@0: sl@0: TheTest.Next(_L("Server persistence test")); sl@0: ServerPersistenceTest(); sl@0: sl@0: TheTest.End(); sl@0: TheTest.Close(); sl@0: sl@0: RepsToReset.Reset(); sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: // sl@0: // For the tests to work we need SID policing enforced plus the specific sl@0: // capabilities listed below. sl@0: // sl@0: // These are dependent on the capabilities set in the platform security sl@0: // repository test initialisation file 87654321.txt. If the content sl@0: // of that file changes then the following clauses may need to be sl@0: // updated. sl@0: // sl@0: if(!PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement) || sl@0: !PlatSec::IsCapabilityEnforced(ECapabilityNetworkServices) || sl@0: !PlatSec::IsCapabilityEnforced(ECapabilityDRM) || sl@0: !PlatSec::IsCapabilityEnforced(ECapabilityLocalServices) || sl@0: !PlatSec::IsCapabilityEnforced(ECapabilityCommDD)) sl@0: { sl@0: TheTest.Start(_L("NOTE: Skipping tests due to incompatible PlatSec enforcement settings")); sl@0: TheTest.End(); sl@0: TheTest.Close(); sl@0: return 0; 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 0; sl@0: }