LOCAL_C void ResetTransactionL() { #ifdef PENDING_REMOVAL // reset operations are not supported in transactions for now. // ResetAll will not ever be: still to decide on individual setting reset // Both are very slow. TUint32 errorId; CRepository* repository; User::LeaveIfNull(repository = CRepository::NewLC(KUidPlatsecTestRepository)); // Remember that this repository need to be reset ::AddRepositoryToReset(KUidPlatsecTestRepository); TInt r = repository->Set(KInt1, KInt1_UpdatedValue); TEST2(r, KErrNone); TInt x,y; r = repository->Get(KInt1, x); TEST2(r, KErrNone); r = repository->StartTransaction(CRepository::EReadWriteTransaction); TEST2(r, KErrNone); r = repository->Reset(KInt1); TEST2(r, KErrNone); r = repository->CommitTransaction(errorId); TEST2(r, KErrNone); r = repository->Get(KInt1, y); TEST2(r, KErrNone); // did we get what expected after commit? TEST(x!=KInt1_InitialValue); TEST(y==KInt1_InitialValue); CleanupStack::PopAndDestroy(repository); // Repository B // lets prepare for reset User::LeaveIfNull(repository = CRepository::NewLC(KUidTransactionTestRepository)); // Remember that this repository need to be reset ::AddRepositoryToReset(KUidTransactionTestRepository); const TInt KNewSettingAlwaysPass = 0x101; r = repository->StartTransaction(CRepository::EReadWriteTransaction); TEST2(r, KErrNone); TInt i = 0; for(i=KNewSettingAlwaysPass;i<KNewSettingAlwaysPass+10;i++) { r = repository->Create(i, i); TEST2(r, KErrNone); } TRequestStatus status = -1; r = repository->NotifyRequest(0, 0, status); TEST2(r, KErrNone); r = repository->CommitTransaction(errorId); TEST2(r, KErrNone); TInt xArray[10]; TInt xx=0; for(i=0;i<10;i++) { r = repository->Get(KNewSettingAlwaysPass+i, xArray[i]); TEST2(r, KErrNone); } //and do the reset business now r = repository->StartTransaction(CRepository::EReadWriteTransaction); TEST2(r, KErrNone); r = repository->Reset(); TEST2(r, KErrNone); r = repository->CommitTransaction(errorId); TEST2(r, KErrNone); // test reset after commit TEST(status==KNewSettingAlwaysPass); for(i=0;i<10;i++) { TEST(xArray[i]==(KNewSettingAlwaysPass+i)); } for(i=KNewSettingAlwaysPass;i<KNewSettingAlwaysPass+10;i++) { r = repository->Get(i, xx); TEST2(r, KErrNotFound); } CleanupStack::PopAndDestroy(repository); #endif // PENDING_REMOVAL }
LOCAL_C void NotifyL() { CRepository* repository; User::LeaveIfNull(repository = CRepository::NewLC(KUidPlatsecTestRepository)); // Remember that this repository need to be reset ::AddRepositoryToReset(KUidPlatsecTestRepository); PlatSec platsec; // // Notification on non-existent setting // TRequestStatus intStatus; TInt r = repository->NotifyRequest(KNonExisitent, intStatus); TEST2(r, KErrNotFound); // // Basic notification // r = repository->NotifyRequest(KInt1, intStatus); TEST2(r, KErrNone); TRequestStatus realStatus; r = repository->NotifyRequest(KReal1, realStatus); TEST2(r, KErrNone); TRequestStatus stringStatus; r = repository->NotifyRequest(KString1, stringStatus); if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) { TEST2(r, KErrNone); } else { TEST2(r, KErrPermissionDenied); } // Setting to the same value should not cause a notification TInt intval; r = repository->Get(KInt1, intval); TEST2(r, KErrNone); r = repository->Set(KInt1, intval); TEST2(r, KErrNone); TEST(intStatus==KRequestPending); TEST(realStatus==KRequestPending); if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) TEST(stringStatus==KRequestPending); RThread thisThread; TEST(thisThread.RequestCount()==0); // First change to setting should cause notification r = repository->Set(KInt1, 0); TEST2(r, KErrNone); User::WaitForAnyRequest(); TEST(intStatus==KInt1); TEST(realStatus==KRequestPending); if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) TEST(stringStatus==KRequestPending); // Second change to setting should not cause notification intStatus = 7777; r = repository->Set(KInt1, 0); TEST2(r, KErrNone); TEST(intStatus==7777); TEST(realStatus==KRequestPending); if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) TEST(stringStatus==KRequestPending); TEST(thisThread.RequestCount()==0); // Setting to the same value should not cause a notification TReal realval; r = repository->Get(KReal1, realval); TEST2(r, KErrNone); r = repository->Set(KReal1, realval); TEST2(r, KErrNone); TEST(intStatus==7777); TEST(realStatus==KRequestPending); if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) TEST(stringStatus==KRequestPending); TEST(thisThread.RequestCount()==0); r = repository->Set(KReal1, 0.0); TEST2(r, KErrNone); User::WaitForAnyRequest(); TEST(intStatus==7777); TEST(realStatus==KReal1); if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) TEST(stringStatus==KRequestPending); // Setting to the same value should not cause a notification realStatus = 8888; TBuf<20> stringval; r = repository->Get(KString1, stringval); if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) TEST2(r, KErrNone); else TEST2(r, KErrPermissionDenied); r = repository->Set(KString1, stringval); if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) TEST2(r, KErrNone); else TEST2(r, KErrPermissionDenied); TEST(intStatus==7777); TEST(realStatus==8888); if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) TEST(stringStatus==KRequestPending); TEST(thisThread.RequestCount()==0); _LIT(KStringValue2, "string2"); r = repository->Set(KString1, KStringValue2); if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) { TEST2(r, KErrNone); User::WaitForAnyRequest(); } else TEST2(r, KErrPermissionDenied); TEST(intStatus==7777); TEST(realStatus==8888); if(!platsec.ConfigSetting(PlatSec::EPlatSecEnforcement)) TEST(stringStatus==KString1); // // Cancelling single notifications // r = repository->NotifyRequest(KInt1, intStatus); TEST2(r, KErrNone); r = repository->NotifyCancel(KInt1); TEST2(r, KErrNone); User::WaitForAnyRequest(); TEST(intStatus==KUnspecifiedKey); intStatus = 7777; r = repository->NotifyRequest(KReal1, realStatus); TEST2(r, KErrNone); r = repository->Set(KInt1, 1); TEST2(r, KErrNone); r = repository->Set(KReal1, 1.1); TEST2(r, KErrNone); User::WaitForAnyRequest(); TEST(intStatus==7777); TEST(realStatus==KReal1); TEST(thisThread.RequestCount()==0); // // Cancelling all notifications // realStatus = 8888; r = repository->NotifyRequest(KInt1, intStatus); TEST2(r, KErrNone); r = repository->NotifyRequest(KReal1, realStatus); TEST2(r, KErrNone); r = repository->NotifyCancelAll(); TEST2(r, KErrNone); User::WaitForAnyRequest(); User::WaitForAnyRequest(); TEST(intStatus==KUnspecifiedKey); TEST(realStatus==KUnspecifiedKey); intStatus = 7777; realStatus = 8888; r = repository->Set(KInt1, 2); TEST2(r, KErrNone); r = repository->Set(KReal1, 2.2); TEST2(r, KErrNone); TEST(intStatus==7777); TEST(realStatus==8888); TEST(thisThread.RequestCount()==0); // // Group notifications // r = repository->NotifyRequest(0, 0, intStatus); TEST2(r, KErrNone); User::WaitForAnyRequest(); // we do not have capabilities for all settings TEST(intStatus==KErrPermissionDenied); CleanupStack::PopAndDestroy(repository); }
LOCAL_C void ResetL() { CRepository* repository; User::LeaveIfNull(repository = CRepository::NewLC(KUidPlatsecTestRepository)); TInt x; TInt r = repository->Get(KInt1, x); TEST2(r, KErrNone); TEST(x!=KInt1_InitialValue); r = repository->Reset(KInt1); TEST2(r, KErrNone); r = repository->Get(KInt1, x); TEST2(r, KErrNone); TEST(x==KInt1_InitialValue); CleanupStack::PopAndDestroy(repository); // Repository D User::LeaveIfNull(repository = CRepository::NewLC(KUidResetTestRepository)); // Remember that this repository need to be reset ::AddRepositoryToReset(KUidResetTestRepository); const TInt KNewSetting1 = 5; const TInt KNewSetting2 = 6; r = repository->Create(KNewSetting1, 0); TEST2(r, KErrNone); r = repository->Create(KNewSetting2, 0); TEST2(r, KErrNone); r = repository->Create(65, 1); TEST2(r, KErrNone); r = repository->Set(70, 1); TEST2(r, KErrNone); r = repository->Create(80, 1); TEST2(r, KErrNone); r = repository->Create(90, 1); TEST2(r, KErrNone); TRequestStatus status = -1; r = repository->NotifyRequest(0, 0, status); TEST2(r, KErrNone); r = repository->Reset(); TEST2(r, KErrNone); TEST(status==KUnspecifiedKey); RThread thisThread; TEST(thisThread.RequestCount()==1); r = repository->Get(10, x); TEST2(r, KErrNone); TEST(x==10); r = repository->Get(40, x); TEST2(r, KErrNone); TEST(x==0); r = repository->Get(50, x); TEST2(r, KErrNone); TEST(x==0); r = repository->Get(60, x); TEST2(r, KErrNone); TEST(x==0); r = repository->Get(70, x); TEST2(r, KErrNone); TEST(x==0); TBuf<10> z; r = repository->Get(20, z); TEST2(r, KErrNone); TEST(z==_L("string")); TReal y; r = repository->Get(30, y); TEST2(r, KErrNone); TEST(y==1); r = repository->Get(5, x); TEST2(r, KErrNotFound); r = repository->Get(6, x); TEST2(r, KErrNotFound); r = repository->Get(65, x); TEST2(r, KErrNotFound); r = repository->Get(80, x); TEST2(r, KErrNotFound); r = repository->Get(90, x); TEST2(r, KErrNotFound); CleanupStack::PopAndDestroy(repository); }