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: // sl@0: sl@0: #include "t_cenrep_helper.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "e32math.h" sl@0: #include "srvparams.h" sl@0: #include "transstate.h" sl@0: #include "clientrequest.h" sl@0: #include "panic.h" sl@0: sl@0: //#define Additional_Test sl@0: sl@0: using namespace NCentralRepositoryConstants; sl@0: sl@0: RTest TheTest(_L("Central Repository Transaction Tests")); sl@0: sl@0: const TUid KUidTestRepository = { 0x0000101 }; sl@0: sl@0: // sl@0: // Repository A sl@0: // sl@0: sl@0: const TUint32 KUnprotectedSettingsMask = 0xFF000000 ; sl@0: sl@0: const TInt KThreadStackSize =0x2000; // 8k sl@0: const TInt KThreadMinHeapSize =0x4000; // 16k sl@0: const TInt KThreadMaxHeapSize =0xa000; // 60k sl@0: sl@0: const TUint32 KInt1 = 1; sl@0: const TInt KInt1_InitialValue = 1; sl@0: sl@0: const TUint32 KReal1 = 2; sl@0: const TReal KReal1_InitialValue = 2.732; sl@0: const TUint32 KString8 = 5; sl@0: const TUint32 KString16 = 6; sl@0: _LIT(KString16_InitialValue, "test\\\"string\""); sl@0: _LIT8(KString8_InitialValue, "test\\\"string\""); sl@0: sl@0: const TInt KInt2 = 3; sl@0: const TInt KInt2_InitialValue = 20; sl@0: const TUint32 KReal2 = 28; sl@0: const TReal KReal2_InitialValue = 2.5; sl@0: const TReal KReal2_SecondValue = 3.5; sl@0: const TUint32 KNewString8 = 21; sl@0: const TUint32 KNewString16 = 22; sl@0: _LIT(KString16_InitialValue2, "another\\\"string\""); sl@0: _LIT8(KString8_InitialValue2, "another\\\"string\""); sl@0: sl@0: _LIT(KString16_Small_Value, "te"); sl@0: _LIT8(KString8_Small_Value, "te"); sl@0: sl@0: const TUint32 KMoveTarget = 0x02000001 ; sl@0: const TUint32 KMoveSourceDoesntExist = 0x01000000 ; sl@0: const TUint32 KMoveMask = 0xFF0000FF ; sl@0: sl@0: const TUint32 KInt3 = 10; //Ranged Policy Key sl@0: const TInt KInt3_InitialValue = 34; sl@0: const TUint32 KInt4 = 0x201; //Default Policy Key sl@0: const TInt KInt4_InitialValue = 10; sl@0: const TUint32 KInt5 = 0x1000001; //Single Policy Key sl@0: const TInt KInt5_SecondValue = 123; 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: 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 TEST(arg) ::CheckL((arg), __LINE__) sl@0: #define TEST2(aValue, aExpected) ::CheckL(aValue, aExpected, __LINE__) sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: typedef void (*TRepositoryFunc)(CRepository&); sl@0: sl@0: void ChangeByCreate(CRepository& aRep) sl@0: { sl@0: TInt r; sl@0: // Create a setting outside of a transaction sl@0: r = aRep.Create(KReal2, KReal2_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: // confirm setting created sl@0: TReal value; sl@0: r = aRep.Get(KReal2, value); sl@0: TEST2(r, KErrNone); sl@0: TEST(value == KReal2_InitialValue); sl@0: } sl@0: sl@0: void ChangeBySet(CRepository& aRep) sl@0: { sl@0: TInt r; sl@0: // Set a value outside of a transaction sl@0: r = aRep.Set(KReal2, KReal2_SecondValue); sl@0: TEST2(r, KErrNone); sl@0: // confirm value changed sl@0: TReal value; sl@0: r = aRep.Get(KReal2, value); sl@0: TEST2(r, KErrNone); sl@0: TEST(value == KReal2_SecondValue); sl@0: } sl@0: sl@0: void ChangeByDelete(CRepository& aRep) sl@0: { sl@0: TInt r; sl@0: // Delete a setting outside of a transaction sl@0: r = aRep.Delete(KReal2); sl@0: TEST2(r, KErrNone); sl@0: // confirm it's deleted sl@0: TReal value; sl@0: r = aRep.Get(KReal2, value); sl@0: TEST2(r, KErrNotFound); sl@0: } sl@0: sl@0: void ChangeByTransaction(CRepository& aRep) sl@0: { sl@0: TInt r; sl@0: TUint32 keyInfo; sl@0: sl@0: // Lock should prevent ERead/WriteTransactions from being able to start from sl@0: // within function CommittingChangesFailsOtherTransactions. sl@0: r = aRep.StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrLocked); sl@0: r = aRep.StartTransaction(CRepository::EReadTransaction); sl@0: TEST2(r, KErrLocked); sl@0: sl@0: // Concurrent Read/Write transactions can be opened at any time sl@0: r = aRep.StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: r = TransactionState(&aRep); sl@0: TEST2(r, EConcurrentReadWriteTransaction); sl@0: sl@0: // Create a setting within transaction sl@0: r = aRep.Create(KReal2, KReal2_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: // confirm setting created sl@0: TReal value; sl@0: r = aRep.Get(KReal2, value); sl@0: TEST2(r, KErrNone); sl@0: TEST(value == KReal2_InitialValue); sl@0: sl@0: r = aRep.CommitTransaction(keyInfo); sl@0: TEST2(r, KErrNone); sl@0: TEST2(keyInfo, 1); // 1 successful change sl@0: sl@0: // re-confirm setting is still there sl@0: r = aRep.Get(KReal2, value); sl@0: TEST2(r, KErrNone); sl@0: TEST(value == KReal2_InitialValue); sl@0: } sl@0: sl@0: // checking that async start and commit, with WaitForRequest do same as ChangeByTransaction sl@0: void ChangeByAsyncTransaction(CRepository& aRep) sl@0: { sl@0: TInt r; sl@0: CRepository::TTransactionKeyInfoBuf keyInfoBuf; sl@0: TRequestStatus status; sl@0: sl@0: // Lock should prevent ERead/WriteTransactions from being able to start from sl@0: // within function CommittingChangesFailsOtherTransactions. sl@0: aRep.StartTransaction(CRepository::EReadWriteTransaction, status); sl@0: User::WaitForRequest(status); sl@0: TEST2(status.Int(), KErrLocked); sl@0: aRep.StartTransaction(CRepository::EReadTransaction, status); sl@0: User::WaitForRequest(status); sl@0: TEST2(status.Int(), KErrLocked); sl@0: sl@0: // Concurrent Read/Write transactions can be opened at any time sl@0: aRep.StartTransaction(CRepository::EConcurrentReadWriteTransaction, status); sl@0: // can't predict whether status will be KRequestPending at this time, so don't check sl@0: User::WaitForRequest(status); sl@0: TEST2(status.Int(), KErrNone); sl@0: r = TransactionState(&aRep); sl@0: TEST2(r, EConcurrentReadWriteTransaction); sl@0: sl@0: // Create a setting within transaction sl@0: r = aRep.Create(KReal2, KReal2_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: // confirm setting created sl@0: TReal value; sl@0: r = aRep.Get(KReal2, value); sl@0: TEST2(r, KErrNone); sl@0: TEST(value == KReal2_InitialValue); sl@0: sl@0: aRep.CommitTransaction(keyInfoBuf, status); sl@0: User::WaitForRequest(status); sl@0: TEST2(status.Int(), KErrNone); sl@0: TEST2(keyInfoBuf(), 1); // 1 successful change sl@0: sl@0: // re-confirm setting is still there sl@0: r = aRep.Get(KReal2, value); sl@0: TEST2(r, KErrNone); sl@0: TEST(value == KReal2_InitialValue); sl@0: } sl@0: sl@0: void ChangeByReset(CRepository& aRep) sl@0: { sl@0: TInt r; sl@0: // Delete a setting outside of a transaction sl@0: r = aRep.Reset(KReal2); sl@0: TEST2(r, KErrNone); sl@0: // confirm it's reset (should be deleted) sl@0: TReal value; sl@0: r = aRep.Get(KReal2, value); sl@0: TEST2(r, KErrNotFound); sl@0: } sl@0: sl@0: void ChangeByResetAll(CRepository& aRep) sl@0: { sl@0: TInt r; sl@0: // Delete a setting outside of a transaction sl@0: r = aRep.Reset(); sl@0: TEST2(r, KErrNone); sl@0: // confirm it's reset (should be deleted) sl@0: TReal value; sl@0: r = aRep.Get(KReal2, value); sl@0: TEST2(r, KErrNotFound); sl@0: } sl@0: sl@0: // tests that changes made by calling ChangeFunc with aCommittingRepository fail active sl@0: // transactions with reason KErrLocked, and correctly discard changes sl@0: LOCAL_C void CallFuncCheckOtherTransactionsFail(TRepositoryFunc ChangeFunc, CRepository& aCommittingRepository) sl@0: { sl@0: TInt r; sl@0: TUint32 keyInfo; sl@0: CRepository* repository1; sl@0: CRepository* repository2; sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: User::LeaveIfNull(repository2 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // Start two types of transaction sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: r = repository2->StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // check transactions haven't failed yet. sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: r = TransactionState(repository2); sl@0: TEST2(r, EConcurrentReadWriteTransaction); sl@0: sl@0: // create a value in repository2's transaction and check it is there sl@0: r = repository2->Create(KInt1, KInt1_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: TInt value; sl@0: r = repository2->Get(KInt1, value); sl@0: TEST2(r, KErrNone); sl@0: TEST(value == KInt1_InitialValue); sl@0: sl@0: (*ChangeFunc)(aCommittingRepository); sl@0: sl@0: // check transactions have now failed sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction | EFailedBit); sl@0: r = TransactionState(repository2); sl@0: TEST2(r, EConcurrentReadWriteTransaction | EFailedBit); sl@0: sl@0: // operations should abort after failing sl@0: r = repository2->Get(KInt1, value); sl@0: TEST2(r, KErrAbort); sl@0: r = repository1->Set(KInt1, value); sl@0: TEST2(r, KErrAbort); sl@0: sl@0: // commits should fail with KErrLocked sl@0: r = repository2->CommitTransaction(keyInfo); sl@0: TEST2(r, KErrLocked); sl@0: TEST2(keyInfo, KUnspecifiedKey); sl@0: r = repository1->CommitTransaction(keyInfo); sl@0: TEST2(r, KErrLocked); sl@0: TEST2(keyInfo, KUnspecifiedKey); sl@0: sl@0: // integer should not be persistent sl@0: r = repository2->Get(KInt1, value); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: CleanupStack::PopAndDestroy(repository2); sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0150 sl@0: @SYMTestCaseDesc Check committing changes causes other transactions to fail. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Run a series of commands that modify repository, check they fail active transactions. sl@0: Start concurrent read write transaction and try to create and get values using other repository. sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMPREQ PREQ752 sl@0: */ sl@0: LOCAL_C void CommittingChangesFailsOtherTransactionsL() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0150 ")); sl@0: CRepository* repository; sl@0: sl@0: User::LeaveIfNull(repository = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: repository->Reset(); sl@0: sl@0: // non-transaction create should fail active transactions sl@0: CallFuncCheckOtherTransactionsFail(ChangeByCreate, *repository); sl@0: sl@0: // non-transaction set should fail active transactions sl@0: CallFuncCheckOtherTransactionsFail(ChangeBySet, *repository); sl@0: sl@0: // non-transaction delete should fail active transactions sl@0: CallFuncCheckOtherTransactionsFail(ChangeByDelete, *repository); sl@0: sl@0: // transaction commit with changes should fail active transactions sl@0: CallFuncCheckOtherTransactionsFail(ChangeByTransaction, *repository); sl@0: sl@0: ChangeByDelete(*repository); // just to ready for next test sl@0: sl@0: // async started and committed transaction with changes should fail active transactions sl@0: CallFuncCheckOtherTransactionsFail(ChangeByAsyncTransaction, *repository); sl@0: sl@0: // individual reset that has an effect should fail active transactions sl@0: CallFuncCheckOtherTransactionsFail(ChangeByReset, *repository); sl@0: sl@0: ChangeByCreate(*repository); // just to ready for next test sl@0: sl@0: // reset all should fail active transactions sl@0: CallFuncCheckOtherTransactionsFail(ChangeByResetAll, *repository); sl@0: sl@0: CleanupStack::PopAndDestroy(repository); sl@0: } sl@0: sl@0: void NoChangeByTransactionCreateDelete(CRepository& aRep) sl@0: { sl@0: TInt r; sl@0: TUint32 keyInfo; sl@0: // Concurrent Read/Write transactions can be opened at any time sl@0: r = aRep.StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: r = TransactionState(&aRep); sl@0: TEST2(r, EConcurrentReadWriteTransaction); sl@0: // deleting the setting that was just added should result in no change when committing: sl@0: ChangeByCreate(aRep); sl@0: ChangeByDelete(aRep); sl@0: r = aRep.CommitTransaction(keyInfo); sl@0: TEST2(r, KErrNone); sl@0: TEST2(keyInfo, 0); // no changes sl@0: } sl@0: sl@0: void NoChangeByTransactionSetSameValue(CRepository& aRep) sl@0: { sl@0: TInt r; sl@0: TUint32 keyInfo; sl@0: // Concurrent Read/Write transactions can be opened at any time sl@0: r = aRep.StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: r = TransactionState(&aRep); sl@0: TEST2(r, EConcurrentReadWriteTransaction); sl@0: // changing setting to the value it already has should result in no change when committing: sl@0: ChangeBySet(aRep); sl@0: r = aRep.CommitTransaction(keyInfo); sl@0: TEST2(r, KErrNone); sl@0: TEST2(keyInfo, 0); // no changes sl@0: } sl@0: sl@0: void NoChangeByReadTransaction(CRepository& aRep) sl@0: { sl@0: TInt r; sl@0: TUint32 keyInfo; sl@0: // Read transactions can be opened now because there is no EReadWriteTransaction open sl@0: r = aRep.StartTransaction(CRepository::EReadTransaction); sl@0: TEST2(r, KErrNone); sl@0: r = TransactionState(&aRep); sl@0: TEST2(r, EReadTransaction); sl@0: // Getting a value should result in no change when committing: sl@0: TReal value; sl@0: r = aRep.Get(KReal2, value); sl@0: TEST2(r, KErrNone); sl@0: TEST(value == KReal2_InitialValue); sl@0: r = aRep.CommitTransaction(keyInfo); sl@0: TEST2(r, KErrNone); sl@0: TEST2(keyInfo, 0); // no changes sl@0: } sl@0: sl@0: void NoChangeByEmptyWriteTransaction(CRepository& aRep) sl@0: { sl@0: TInt r; sl@0: TUint32 keyInfo; sl@0: // can't start an EReadWriteTransaction because a ReadTransaction is active sl@0: r = aRep.StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrLocked); sl@0: // Concurrent Read/Write transactions can be opened at any time sl@0: r = aRep.StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: r = TransactionState(&aRep); sl@0: TEST2(r, EConcurrentReadWriteTransaction); sl@0: // make no changes before committing sl@0: r = aRep.CommitTransaction(keyInfo); sl@0: TEST2(r, KErrNone); sl@0: TEST2(keyInfo, 0); // no changes sl@0: } sl@0: sl@0: // tests that changes made by calling ChangeFunc with aCommittingRepository sl@0: // do not fail active transactions. Must Reset before calling this. sl@0: LOCAL_C void CallFuncCheckOtherTransactionsDoNotFail(TRepositoryFunc ChangeFunc, CRepository& aCommittingRepository) sl@0: { sl@0: TInt r; sl@0: CRepository::TTransactionKeyInfoBuf keyInfoBuf; sl@0: TUint32 keyInfo; sl@0: TRequestStatus status; sl@0: CRepository* repository1; sl@0: CRepository* repository2; sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: User::LeaveIfNull(repository2 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // Start two types of transaction and wait for completion sl@0: r = repository1->StartTransaction(CRepository::EReadTransaction); sl@0: TEST2(r, KErrNone); sl@0: repository2->StartTransaction(CRepository::EConcurrentReadWriteTransaction, status); sl@0: User::WaitForRequest(status); sl@0: TEST2(status.Int(), KErrNone); sl@0: sl@0: // create values in repository2's transaction cache sl@0: r = repository2->Create(KNewString8, KString8_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: r = repository2->Create(KNewString16, KString16_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // check transactions not failed sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadTransaction); sl@0: r = TransactionState(repository2); sl@0: TEST2(r, EConcurrentReadWriteTransaction); sl@0: sl@0: (*ChangeFunc)(aCommittingRepository); sl@0: sl@0: // create setting in repository 1's cache sl@0: r = repository1->Create(KInt2, KInt2_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // check transactions not failed & Read upgraded to ReadWrite sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: r = TransactionState(repository2); sl@0: TEST2(r, EConcurrentReadWriteTransaction); sl@0: sl@0: // commit repository2 asynchronously sl@0: repository2->CommitTransaction(keyInfoBuf, status); sl@0: User::WaitForRequest(status); sl@0: TEST2(status.Int(), KErrNone); sl@0: TEST2(keyInfoBuf(), 2); // 2 successful changes sl@0: sl@0: // check transaction2 finished, transaction 1 failed sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction | EFailedBit); sl@0: r = TransactionState(repository2); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: // operations on repository 1 should abort after failing sl@0: TInt intValue; sl@0: r = repository1->Get(KInt1, intValue); sl@0: TEST2(r, KErrAbort); sl@0: r = repository1->Set(KInt1, intValue); sl@0: TEST2(r, KErrAbort); sl@0: sl@0: // commit of repository 1 should fail with KErrLocked sl@0: r = repository1->CommitTransaction(keyInfo); sl@0: TEST2(r, KErrLocked); sl@0: TEST2(keyInfo, KUnspecifiedKey); sl@0: sl@0: // check changes by repository 2 are still present sl@0: TBuf8<40> buf8Value; sl@0: TBuf16<40> buf16Value; sl@0: sl@0: r = repository2->Get(KNewString8, buf8Value); sl@0: TEST2(r, KErrNone); sl@0: TEST(buf8Value == KString8_InitialValue); sl@0: r = repository2->Get(KNewString16, buf16Value); sl@0: TEST2(r, KErrNone); sl@0: TEST(buf16Value == KString16_InitialValue); sl@0: sl@0: CleanupStack::PopAndDestroy(repository2); sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0151 sl@0: @SYMTestCaseDesc Check committing no changes (incl. setting same value) does not cause other transactions to fail. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Run a series of commands that modify repository, check they fail active transactions. sl@0: Start concurrent read write transaction and try to create and get values using other repository. sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMPREQ PREQ752 sl@0: */ sl@0: LOCAL_C void CommittingNoChangesDoesNotFailOtherTransactionsL() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0151 ")); sl@0: CRepository* repository; sl@0: sl@0: User::LeaveIfNull(repository = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // creating and deleting the same setting in the same transaction should have no effect sl@0: repository->Reset(); sl@0: CallFuncCheckOtherTransactionsDoNotFail(NoChangeByTransactionCreateDelete, *repository); sl@0: sl@0: // changing a setting to the same value in a transaction should have no effect sl@0: repository->Reset(); sl@0: ChangeByCreate(*repository); sl@0: ChangeBySet(*repository); sl@0: CallFuncCheckOtherTransactionsDoNotFail(NoChangeByTransactionSetSameValue, *repository); sl@0: sl@0: // committing a Read transaction should have no effect sl@0: repository->Reset(); sl@0: ChangeByCreate(*repository); sl@0: CallFuncCheckOtherTransactionsDoNotFail(NoChangeByReadTransaction, *repository); sl@0: sl@0: // committing an empty transaction should have no effect sl@0: repository->Reset(); sl@0: CallFuncCheckOtherTransactionsDoNotFail(NoChangeByEmptyWriteTransaction, *repository); sl@0: sl@0: CleanupStack::PopAndDestroy(repository); sl@0: sl@0: // restart session and check values are indeed saved sl@0: User::LeaveIfNull(repository = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: TInt r; sl@0: TBuf8<40> buf8Value; sl@0: TBuf16<40> buf16Value; sl@0: r = repository->Get(KNewString8, buf8Value); sl@0: TEST2(r, KErrNone); sl@0: TEST(buf8Value == KString8_InitialValue); sl@0: r = repository->Get(KNewString16, buf16Value); sl@0: TEST2(r, KErrNone); sl@0: TEST(buf16Value == KString16_InitialValue); sl@0: // final cleanup sl@0: repository->Reset(); sl@0: sl@0: CleanupStack::PopAndDestroy(repository); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0152 sl@0: @SYMTestCaseDesc Testing creates in a read write transaction sl@0: @SYMTestPriority High sl@0: @SYMTestActions Starts a read write transaction which creates values for KInt1, KReal1, KString8 and KString16 sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMPREQ PREQ752 sl@0: */ sl@0: LOCAL_C void CreateValueUsingTransactionL() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0152 ")); sl@0: TInt r; sl@0: TUint32 errorId; sl@0: sl@0: CRepository* repository; sl@0: User::LeaveIfNull(repository = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // Begin read write transaction sl@0: r = repository->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Create(KInt1, KInt1_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Create(KReal1, KReal1_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Create(KString8, KString8_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Create(KString16, KString16_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Commit transaction sl@0: r = repository->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: // Test for the value of errorId for a successful read write transaction = 4 changes sl@0: TEST2(errorId, 4); sl@0: sl@0: CleanupStack::PopAndDestroy(repository); sl@0: sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0153 sl@0: @SYMTestCaseDesc Testing state and rollback in a transaction sl@0: @SYMTestPriority High sl@0: @SYMTestActions Use both transactionstate and failtransaction while being in a transaction and not in a transaction. sl@0: Check on the state and test to see if rollback occurs when required. sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMPREQ PREQ752 sl@0: */ sl@0: LOCAL_C void TransactionStateAndRollBackL() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0153 ")); sl@0: TInt r; sl@0: TUint32 errorId; sl@0: TReal getValue; sl@0: sl@0: CRepository* repository; sl@0: User::LeaveIfNull(repository = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: r = TransactionState(repository); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: // Try to fail transaction without being in a transaction sl@0: repository->FailTransaction(); sl@0: sl@0: r = TransactionState(repository); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: // Begin concurrent read write transaction sl@0: r = repository->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = TransactionState(repository); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: r = repository->Create(KReal2, KReal2_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Get(KReal2, getValue); sl@0: TEST(getValue == KReal2_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Fail transaction should roll back transaction i.e. Create KReal2 should not work. sl@0: repository->FailTransaction(); sl@0: sl@0: r = TransactionState(repository); sl@0: TEST2(r, EReadWriteTransaction | EFailedBit); sl@0: sl@0: // Commit transaction sl@0: r = repository->CommitTransaction(errorId); sl@0: TEST2(r, KErrAbort); sl@0: // Test the value of errorId for a failed read write transaction sl@0: TEST2(errorId, KUnspecifiedKey); sl@0: sl@0: // Try to get a value which should not exist as transaction failed sl@0: r = repository->Get(KReal2, getValue); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: r = TransactionState(repository); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: r = repository->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Create(KReal2, KReal2_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: repository->RollbackTransaction(); sl@0: sl@0: // Try to get a value which should not exist as transaction rolled back sl@0: r = repository->Get(KReal2, getValue); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: // Transaction state should be ENoTransaction due to call to RollbackTransaction() sl@0: r = TransactionState(repository); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: // Begin read transaction sl@0: r = repository->StartTransaction(CRepository::EReadTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = TransactionState(repository); sl@0: TEST2(r, EReadTransaction); sl@0: sl@0: r = repository->Get(KReal1, getValue); sl@0: TEST2(r, KErrNone); sl@0: TEST(getValue == KReal1_InitialValue); sl@0: sl@0: // Fail transaction sl@0: repository->FailTransaction(); sl@0: sl@0: r = TransactionState(repository); sl@0: TEST2(r, EReadTransaction | EFailedBit); sl@0: sl@0: // Commit transaction sl@0: r = repository->CommitTransaction(errorId); sl@0: TEST2(r, KErrAbort); sl@0: sl@0: r = TransactionState(repository); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: // Begin another read transaction sl@0: r = repository->StartTransaction(CRepository::EReadTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository->Get(KReal1, getValue); sl@0: TEST2(r, KErrNone); sl@0: TEST(getValue == KReal1_InitialValue); sl@0: sl@0: r = TransactionState(repository); sl@0: TEST2(r, EReadTransaction); sl@0: sl@0: // Perform Create in a ReadTransaction as upgrade has occured sl@0: r = repository->Create(KReal2, KReal2_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // The state should be updated to be EInReadWriteTransaction sl@0: r = TransactionState(repository); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: r = repository->Get(KReal2, getValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Commit transaction sl@0: r = repository->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Delete KReal2 to reset available test case variables sl@0: r = repository->Delete(KReal2); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = TransactionState(repository); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: CleanupStack::PopAndDestroy(repository); sl@0: } sl@0: sl@0: LOCAL_C void StartTransactionPanicConditionsL() sl@0: { sl@0: TInt r; sl@0: TUint32 errorId; sl@0: sl@0: CRepository* repository1; sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // Begin read write transaction sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // This should panic can't start second transaction in one session sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Commit transaction sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: } sl@0: sl@0: LOCAL_C TInt TestStartTransactionPanics(TAny* /*aData*/) 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, StartTransactionPanicConditionsL()); sl@0: sl@0: // Won't get here but add this line to get rid of ARMV5 warning sl@0: TEST2(err, KErrNone); sl@0: sl@0: delete cleanup; sl@0: __UHEAP_MARKEND; sl@0: sl@0: return (KErrNone); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0154 sl@0: @SYMTestCaseDesc Testing valid panics while using StartTransaction sl@0: @SYMTestPriority High sl@0: @SYMTestActions Start a separate thread and within that thread try to start transaction twice sl@0: @SYMTestExpectedResults The thread should exit with the exit type EExitPanic and exit reason EStartAlreadyInTransaction sl@0: @SYMPREQ PREQ752 sl@0: */ sl@0: LOCAL_C void TransactionPanicConditionsThread() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0154 ")); sl@0: TBool jitEnabled = User::JustInTime(); sl@0: User::SetJustInTime(EFalse); sl@0: sl@0: TRequestStatus status; sl@0: sl@0: _LIT(KName, "Transaction_Panic_Thread"); sl@0: sl@0: RThread thread; sl@0: TInt rc = thread.Create(KName,TestStartTransactionPanics,KThreadStackSize,KThreadMinHeapSize,KThreadMaxHeapSize,NULL); sl@0: sl@0: TEST2(rc,KErrNone); sl@0: sl@0: thread.Logon(status); sl@0: thread.Resume(); sl@0: sl@0: User::WaitForRequest(status); sl@0: sl@0: // Should result in a EExitPanic exit type and an EStartAlreadyInTransaction exit reason sl@0: TEST2(thread.ExitType(), EExitPanic); sl@0: TEST2(thread.ExitReason(), EStartAlreadyInTransaction); sl@0: sl@0: thread.Close(); sl@0: sl@0: User::SetJustInTime(jitEnabled); sl@0: } sl@0: sl@0: LOCAL_C void CommitTransactionPanicConditionL() sl@0: { sl@0: TInt r; sl@0: TUint32 errorId; sl@0: sl@0: CRepository* repository1; sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // Commit transaction when there is not transaction should cause a panic sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: } sl@0: sl@0: sl@0: LOCAL_C TInt TestCommitTransactionPanics(TAny* /*aData*/) 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,CommitTransactionPanicConditionL()); sl@0: sl@0: // Won't get here but add this line to get rid of ARMV5 warning sl@0: TEST2(err, KErrNone); sl@0: sl@0: delete cleanup; sl@0: __UHEAP_MARKEND; sl@0: return (KErrNone); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0155 sl@0: @SYMTestCaseDesc Testing valid panics while using CommitTransaction sl@0: @SYMTestPriority High sl@0: @SYMTestActions Start a separate thread and within that thread try to commit a transaction without being in one sl@0: @SYMTestExpectedResults The thread should exit with the exit type EExitPanic and the exit reason ECommitNotInTransaction sl@0: @SYMPREQ PREQ752 sl@0: */ sl@0: LOCAL_C void CommitTransactionPanicConditionsThread() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0155 ")); sl@0: TBool jitEnabled = User::JustInTime(); sl@0: User::SetJustInTime(EFalse); sl@0: sl@0: TRequestStatus status; sl@0: sl@0: _LIT(KName, "Commit_Transaction_Panic_Thread"); sl@0: sl@0: RThread thread; sl@0: TInt rc = thread.Create(KName,TestCommitTransactionPanics,KThreadStackSize,KThreadMinHeapSize,KThreadMaxHeapSize,NULL); sl@0: sl@0: TEST2(rc,KErrNone); sl@0: sl@0: thread.Logon(status); sl@0: thread.Resume(); sl@0: sl@0: User::WaitForRequest(status); sl@0: sl@0: // Should result in a EExitPanic exit type and an ECommitNotInTransaction exit reason sl@0: TEST2(thread.ExitType(), EExitPanic); sl@0: TEST2(thread.ExitReason(), ECommitNotInTransaction); sl@0: sl@0: thread.Close(); sl@0: sl@0: User::SetJustInTime(jitEnabled); sl@0: } sl@0: sl@0: LOCAL_C void LeaveWithCleanupRollbackTransactionPushL(CRepository& aRepository) sl@0: { sl@0: TInt r = TransactionState(&aRepository); sl@0: TEST2(r, CRepository::EReadWriteTransaction); sl@0: sl@0: aRepository.CleanupRollbackTransactionPushL(); sl@0: sl@0: // Purposely leave in a transaction... sl@0: User::LeaveNoMemory(); sl@0: sl@0: // this code should never be reached... sl@0: TEST(EFalse); sl@0: // ...but if it did we'd have to cleanup the PushL sl@0: CleanupStack::Pop(); sl@0: } sl@0: sl@0: LOCAL_C void LeaveWithCleanupFailTransactionPushL(CRepository& aRepository) sl@0: { sl@0: TInt r = TransactionState(&aRepository); sl@0: TEST2(r, CRepository::EReadWriteTransaction); sl@0: sl@0: aRepository.CleanupFailTransactionPushL(); sl@0: sl@0: // Purposely leave in a transaction... sl@0: User::LeaveNoMemory(); sl@0: sl@0: // this code should never be reached... sl@0: TEST(EFalse); sl@0: // ...but if it did we'd have to cleanup the PushL sl@0: CleanupStack::Pop(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0156 sl@0: @SYMTestCaseDesc Testing CleanupRollbackTransactionPushL and CleanupFailTransactionPushL sl@0: @SYMTestPriority High sl@0: @SYMTestActions Start a transaction and use CleanupRollbackTransactionPushL. Within the transaction purposely leave, as this will sl@0: result in CleanupRollbackTransactionPushL being used. Similar operation required for CleanupFailTransactionPushL sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMPREQ PREQ752 sl@0: */ sl@0: LOCAL_C void CleanupRollBackAndFailTransactionL() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0156 ")); sl@0: TInt r; sl@0: TUint32 errorId; sl@0: TReal getValue; sl@0: sl@0: CRepository* repository; sl@0: sl@0: User::LeaveIfNull(repository = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: r = repository->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: repository->CleanupRollbackTransactionPushL(); sl@0: sl@0: r = repository->Create(KReal2, KReal2_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Purposely leave in a transaction... sl@0: TRAP(r, LeaveWithCleanupRollbackTransactionPushL(*repository)); sl@0: TEST2(r, KErrNoMemory); sl@0: sl@0: // should cause RollbackTransaction, therefore transaction state should be ENoTransaction... sl@0: sl@0: r = TransactionState(repository); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: // and getting the value KReal2 should result in KErrNotFound sl@0: r = repository->Get(KReal2, getValue); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: CleanupStack::Pop(); // CleanupRollbackTransaction sl@0: sl@0: r = repository->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: repository->CleanupFailTransactionPushL(); sl@0: sl@0: r = repository->Create(KReal2, KReal2_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Purposely leave in a transaction... sl@0: TRAP(r, LeaveWithCleanupFailTransactionPushL(*repository)); sl@0: TEST2(r, KErrNoMemory); sl@0: sl@0: // should cause FailTransaction, therefore transaction state should be EInFailedReadWriteTransaction... sl@0: r = TransactionState(repository); sl@0: TEST2(r, EReadWriteTransaction | EFailedBit); sl@0: sl@0: // only after commit will Fail Transaction call roll back... sl@0: r = repository->CommitTransaction(errorId); sl@0: TEST2(r, KErrAbort); sl@0: sl@0: // so getting the value KReal2 should result in KErrNotFound sl@0: r = repository->Get(KReal2, getValue); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: r = TransactionState(repository); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: CleanupStack::Pop(); // CleanupRollbackTransaction sl@0: sl@0: CleanupStack::PopAndDestroy(repository); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0157 sl@0: @SYMTestCaseDesc Test Read Transaction Conditions sl@0: @SYMTestPriority High sl@0: @SYMTestActions Start read transactions and perform read operations sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMPREQ PREQ752 sl@0: */ sl@0: LOCAL_C void ReadTransactionConditionsL() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0157 ")); sl@0: TInt r; sl@0: TUint32 errorId; sl@0: TInt intVal; sl@0: sl@0: CRepository* repository1; sl@0: CRepository* repository2; sl@0: CRepository* repository3; sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: User::LeaveIfNull(repository2 = CRepository::NewLC(KUidTestRepository)); sl@0: User::LeaveIfNull(repository3 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Should be able to start another read transaction sl@0: r = repository2->StartTransaction(CRepository::EReadTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Perform some gets using the open transactions and repository sl@0: r = repository1->Get(KInt1, intVal); sl@0: TEST2(r, KErrNone); sl@0: TEST2(intVal, KInt1_InitialValue); sl@0: sl@0: r = repository2->Get(KInt1, intVal); sl@0: TEST2(r, KErrNone); sl@0: TEST2(intVal, KInt1_InitialValue); sl@0: sl@0: r = repository3->Get(KInt1, intVal); sl@0: TEST2(r, KErrNone); sl@0: TEST2(intVal, KInt1_InitialValue); sl@0: sl@0: // Get the state of Transactions sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadTransaction); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadTransaction); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: // Test for the value of errorId for a successful read transaction: no changes sl@0: TEST2(errorId, 0); sl@0: sl@0: r = repository2->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: // Test for the value of errorId for a successful read transaction: no changes sl@0: TEST2(errorId, 0); sl@0: sl@0: CleanupStack::PopAndDestroy(repository3); sl@0: CleanupStack::PopAndDestroy(repository2); sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0158 sl@0: @SYMTestCaseDesc Test upgrade read transaction with error conditions sl@0: @SYMTestPriority High sl@0: @SYMTestActions Start read transactions and try to upgrade one of the read transactions sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMPREQ PREQ752 sl@0: */ sl@0: LOCAL_C void UpgradeReadTransactionErrorConditionsL() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0158 ")); sl@0: TInt r; sl@0: TUint32 errorId; sl@0: TInt intVal; sl@0: sl@0: CRepository* repository1; sl@0: CRepository* repository2; sl@0: CRepository* repository3; sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: User::LeaveIfNull(repository2 = CRepository::NewLC(KUidTestRepository)); sl@0: User::LeaveIfNull(repository3 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Should be able to start another read transaction sl@0: r = repository2->StartTransaction(CRepository::EReadTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Perform get using open transaction sl@0: r = repository2->Get(KInt1, intVal); sl@0: TEST2(r, KErrNone); sl@0: TEST2(intVal, KInt1_InitialValue); sl@0: sl@0: // Perform create which should fail transaction with KErrLocked sl@0: r = repository1->Create(KInt2, KInt2_InitialValue); sl@0: TEST2(r, KErrLocked); sl@0: sl@0: // check the value is not there as far as repository 3 is concerned sl@0: r = repository3->Get(KInt2, intVal); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: // Get the state of Transactions sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadTransaction | EFailedBit); sl@0: sl@0: r = TransactionState(repository2); sl@0: TEST2(r, EReadTransaction); sl@0: sl@0: r = repository2->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrLocked); sl@0: // Check the key responsible for the failed read transaction promote sl@0: TEST2(errorId, KInt2); sl@0: sl@0: CleanupStack::PopAndDestroy(repository3); sl@0: CleanupStack::PopAndDestroy(repository2); sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0159 sl@0: @SYMTestCaseDesc Test read operations with a read write transaction open sl@0: @SYMTestPriority High sl@0: @SYMTestActions Start a transaction and try to perform some read operations outside of the open transaction sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMPREQ PREQ752 sl@0: */ sl@0: LOCAL_C void TransactionConditionsForReadL() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0159 ")); sl@0: TInt r; sl@0: TUint32 errorId; sl@0: RArray foundIds; sl@0: sl@0: CRepository* repository1; sl@0: CRepository* repository2; sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: User::LeaveIfNull(repository2 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: // Should be able to get values regardless of transaction1 being open sl@0: TInt intVal; sl@0: r = repository2->Get(KInt1, intVal); sl@0: TEST2(r, KErrNone); sl@0: TEST2(intVal, KInt1_InitialValue); sl@0: sl@0: TReal realVal; sl@0: r = repository2->Get(KReal1, realVal); sl@0: TEST2(r, KErrNone); sl@0: TEST(realVal==KReal1_InitialValue); sl@0: sl@0: TBuf8<14> buf8Val; sl@0: r = repository2->Get(KString8, buf8Val); sl@0: TEST2(r, KErrNone); sl@0: TEST(buf8Val==KString8_InitialValue); sl@0: sl@0: TBuf16<14> buf16Val; sl@0: r = repository2->Get(KString16, buf16Val); sl@0: TEST2(r, KErrNone); sl@0: TEST(buf16Val==KString16_InitialValue); sl@0: sl@0: r = repository2->FindL(0, KUnprotectedSettingsMask, foundIds); sl@0: TEST2(r, KErrNone); sl@0: TEST(foundIds.Count()==4); sl@0: sl@0: foundIds.Reset(); sl@0: sl@0: // Find in range for values equal to KInt1_InitialValue sl@0: r = repository2->FindEqL(0, KUnprotectedSettingsMask, KInt1_InitialValue, foundIds); sl@0: TEST2(r, KErrNone); sl@0: TEST(foundIds.Count()==1); sl@0: sl@0: foundIds.Reset(); sl@0: sl@0: // Find in range for values NOT equal to KInt1_InitialValue sl@0: r = repository2->FindNeqL(0, KUnprotectedSettingsMask, KInt1_InitialValue, foundIds); sl@0: TEST2(r, KErrNone); sl@0: TEST(foundIds.Count()==3); sl@0: sl@0: foundIds.Reset(); sl@0: sl@0: // Find in range for values equal to KReal1_InitialValue sl@0: r = repository2->FindEqL(0, KUnprotectedSettingsMask, KReal1_InitialValue, foundIds); sl@0: TEST2(r, KErrNone); sl@0: TEST2(foundIds.Count(),1); sl@0: sl@0: foundIds.Reset(); sl@0: sl@0: // Find in range for values NOT equal to KReal1_InitialValue sl@0: r = repository2->FindNeqL(0, KUnprotectedSettingsMask, KReal1_InitialValue, foundIds); sl@0: TEST2(r, KErrNone); sl@0: TEST2(foundIds.Count(),3); sl@0: sl@0: // Find in range for values equal to KString8_InitialValue sl@0: r = repository2->FindEqL(0, KUnprotectedSettingsMask, KString8_InitialValue, foundIds); sl@0: TEST2(r, KErrNone); sl@0: TEST(foundIds.Count()==1); sl@0: sl@0: foundIds.Reset(); sl@0: sl@0: // Find in range for values NOT equal to KString8_InitialValue sl@0: r = repository2->FindNeqL(0, KUnprotectedSettingsMask, KString8_InitialValue, foundIds); sl@0: TEST2(r, KErrNone); sl@0: TEST2(foundIds.Count(),3); sl@0: sl@0: sl@0: // Find in range for values equal to KString16_InitialValue sl@0: r = repository2->FindEqL(0, KUnprotectedSettingsMask, KString16_InitialValue, foundIds); sl@0: TEST2(r, KErrNone); sl@0: TEST2(foundIds.Count(),1); sl@0: sl@0: foundIds.Reset(); sl@0: sl@0: // Find in range for values NOT equal to KString16_InitialValue sl@0: r = repository2->FindNeqL(0, KUnprotectedSettingsMask, KString16_InitialValue, foundIds); sl@0: TEST2(r, KErrNone); sl@0: TEST2(foundIds.Count(),3); sl@0: sl@0: foundIds.Reset(); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::PopAndDestroy(repository2); sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0160 sl@0: @SYMTestCaseDesc Test Transaction error conditions with get sl@0: @SYMTestPriority High sl@0: @SYMTestActions Start a transaction and perform some problematic gets. Test to see if it fails transactions or not. sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMPREQ PREQ752 sl@0: */ sl@0: LOCAL_C void TransactionErrorConditionsForGetL() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0160 ")); sl@0: TInt r; sl@0: TUint32 errorId; sl@0: sl@0: CRepository* repository1; sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Should NOT fail transaction sl@0: TInt intVal; sl@0: r = repository1->Get(KInt2, intVal); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: // Should NOT fail transaction sl@0: TReal realVal; sl@0: r = repository1->Get(KInt1, realVal); sl@0: TEST2(r, KErrArgument); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: // Should NOT fail transaction sl@0: r = repository1->Get(KReal2, realVal); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: // Should NOT fail transaction sl@0: r = repository1->Get(KReal1, intVal); sl@0: TEST2(r, KErrArgument); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: // Should NOT fail transaction sl@0: TBuf8<14> buf8Val; sl@0: r = repository1->Get(KNewString8, buf8Val); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: // Should NOT fail transaction sl@0: r = repository1->Get(KString8, intVal); sl@0: TEST2(r, KErrArgument); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: // Should NOT fail transaction sl@0: TBuf8<2> smallBuf8Val; sl@0: r = repository1->Get(KString8, smallBuf8Val); sl@0: TEST2(r, KErrOverflow); sl@0: TEST(smallBuf8Val==KString8_Small_Value); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: // Should NOT fail transaction sl@0: TBuf16<14> buf16Val; sl@0: r = repository1->Get(KNewString16, buf16Val); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: // Should NOT fail transaction sl@0: r = repository1->Get(KString16, intVal); sl@0: TEST2(r, KErrArgument); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: // Should NOT fail transaction sl@0: TBuf16<2> smallBuf16Val; sl@0: r = repository1->Get(KString16, smallBuf16Val); sl@0: TEST2(r, KErrOverflow); sl@0: TEST(smallBuf16Val==KString16_Small_Value); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0161 sl@0: @SYMTestCaseDesc Test Transaction error conditions with find sl@0: @SYMTestPriority High sl@0: @SYMTestActions Start a transaction and perform some problematic find operations. Test to see if it fails transactions or not. sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMPREQ PREQ752 sl@0: */ sl@0: LOCAL_C void TransactionErrorConditionsForFindL() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0161 ")); sl@0: TInt r; sl@0: TUint32 errorId; sl@0: RArray foundIds; sl@0: sl@0: CRepository* repository1; sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: repository1->CleanupRollbackTransactionPushL(); sl@0: sl@0: // Should NOT fail transaction sl@0: r = repository1->FindL(100, 110, foundIds); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: foundIds.Reset(); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::Pop(); // CleanupRollbackTransaction sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0162 sl@0: @SYMTestCaseDesc Test Transaction error conditions with findeq sl@0: @SYMTestPriority High sl@0: @SYMTestActions Start a transaction and perform some problematic findeq operations. Test to see if it fails transactions or not. sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMPREQ PREQ752 sl@0: */ sl@0: LOCAL_C void TransactionErrorConditionsForFindEqL() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0162 ")); sl@0: TInt r; sl@0: TUint32 errorId; sl@0: RArray foundIds; sl@0: sl@0: CRepository* repository1; sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: repository1->CleanupRollbackTransactionPushL(); sl@0: sl@0: // Should NOT fail transaction sl@0: r = repository1->FindEqL(0, KUnprotectedSettingsMask, KInt2_InitialValue, foundIds); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: foundIds.Reset(); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::Pop(); // CleanupRollbackTransaction sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: repository1->CleanupRollbackTransactionPushL(); sl@0: sl@0: // Should NOT fail transaction sl@0: r = repository1->FindEqL(0, KUnprotectedSettingsMask, KReal2_InitialValue, foundIds); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: foundIds.Reset(); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::Pop(); // CleanupRollbackTransaction sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: repository1->CleanupRollbackTransactionPushL(); sl@0: sl@0: // Should NOT fail transaction sl@0: r = repository1->FindEqL(0, KUnprotectedSettingsMask, KString8_InitialValue2, foundIds); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: foundIds.Reset(); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::Pop(); // CleanupRollbackTransaction sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: repository1->CleanupRollbackTransactionPushL(); sl@0: sl@0: // Should NOT fail transaction sl@0: r = repository1->FindEqL(0, KUnprotectedSettingsMask, KString16_InitialValue2, foundIds); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: foundIds.Reset(); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::Pop(); // CleanupRollbackTransaction sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0163 sl@0: @SYMTestCaseDesc Test Transaction error conditions with findneq sl@0: @SYMTestPriority High sl@0: @SYMTestActions Start a transaction and perform some problematic findneq operations. Test to see if it fails transactions or not. sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMPREQ PREQ752 sl@0: */ sl@0: LOCAL_C void TransactionErrorConditionsForFindNeqL() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0163 ")); sl@0: TInt r; sl@0: TUint32 errorId; sl@0: RArray foundIds; sl@0: sl@0: CRepository* repository1; sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: repository1->CleanupRollbackTransactionPushL(); sl@0: sl@0: // Should NOT fail transaction sl@0: r = repository1->FindNeqL(100, 110, KInt1_InitialValue, foundIds); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: foundIds.Reset(); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::Pop(); // CleanupRollbackTransaction sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: repository1->CleanupRollbackTransactionPushL(); sl@0: sl@0: // Should NOT fail transaction sl@0: r = repository1->FindNeqL(100, 110, KReal1_InitialValue, foundIds); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: foundIds.Reset(); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::Pop(); // CleanupRollbackTransaction sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: repository1->CleanupRollbackTransactionPushL(); sl@0: sl@0: // Should NOT fail transaction sl@0: r = repository1->FindNeqL(100, 110, KString8_InitialValue, foundIds); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: foundIds.Reset(); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::Pop(); // CleanupRollbackTransaction sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: repository1->CleanupRollbackTransactionPushL(); sl@0: sl@0: // Should NOT fail transaction sl@0: r = repository1->FindNeqL(100, 110, KString16_InitialValue, foundIds); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: foundIds.Reset(); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::Pop(); // CleanupRollbackTransaction sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0164 sl@0: @SYMTestCaseDesc Test Transaction error conditions with create sl@0: @SYMTestPriority High sl@0: @SYMTestActions Start a transaction and perform some problematic create operations. Test to see if it fails transactions or not. sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMPREQ PREQ752 sl@0: */ sl@0: LOCAL_C void TransactionErrorConditionsForCreateL() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0164 ")); sl@0: TInt r; sl@0: TUint32 errorId; sl@0: sl@0: CRepository* repository1; sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Should fail the transaction sl@0: r = repository1->Create(KInt1, KInt1_InitialValue); sl@0: TEST2(r, KErrAlreadyExists); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction | EFailedBit); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrAlreadyExists); sl@0: TEST2(errorId, KInt1); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Should fail the transaction sl@0: r = repository1->Create(KReal1, KReal1_InitialValue); sl@0: TEST2(r, KErrAlreadyExists); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction | EFailedBit); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrAlreadyExists); sl@0: TEST2(errorId, KReal1); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Should fail the transaction sl@0: r = repository1->Create(KString8, KString8_InitialValue); sl@0: TEST2(r, KErrAlreadyExists); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction | EFailedBit); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrAlreadyExists); sl@0: TEST2(errorId, KString8); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Should fail the transaction sl@0: r = repository1->Create(KString16, KString16_InitialValue); sl@0: TEST2(r, KErrAlreadyExists); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction | EFailedBit); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrAlreadyExists); sl@0: TEST2(errorId, KString16); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0165 sl@0: @SYMTestCaseDesc Test Transaction error conditions with delete sl@0: @SYMTestPriority High sl@0: @SYMTestActions Start a transaction and perform some problematic delete operations. Test to see if it fails transactions or not. sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMPREQ PREQ752 sl@0: */ sl@0: LOCAL_C void TransactionErrorConditionsForDeleteL() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0165 ")); sl@0: TInt r; sl@0: TUint32 errorId; sl@0: sl@0: CRepository* repository1; sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Delete KInt2 which does not exist sl@0: r = repository1->Delete(KInt2); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0166 sl@0: @SYMTestCaseDesc Test Transaction error conditions with set sl@0: @SYMTestPriority High sl@0: @SYMTestActions Start a transaction and perform some problematic set operations. Test to see if it fails transactions or not. sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMPREQ PREQ752 sl@0: */ sl@0: LOCAL_C void TransactionErrorConditionsForSetL() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0166 ")); sl@0: TInt r; sl@0: TUint32 errorId; sl@0: TInt i; sl@0: sl@0: CRepository* repository1; sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository1->Get(KInt2, i); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: // Set KInt2 which does not exist sl@0: r = repository1->Set(KInt2, KInt2_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository1->Get(KInt2, i); sl@0: TEST2(r, KErrNone); sl@0: TEST2(i, KInt2_InitialValue); sl@0: sl@0: // Set KInt2 to a value of real type sl@0: r = repository1->Set(KInt2, KReal2_InitialValue); sl@0: TEST2(r, KErrArgument); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction | EFailedBit); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrArgument); sl@0: TEST2(errorId, KInt2); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository1->Set(KInt2, KInt2_InitialValue + 1); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Set KInt2 to a value of string8 type sl@0: r = repository1->Set(KInt2, KString8_InitialValue); sl@0: TEST2(r, KErrArgument); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction | EFailedBit); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrArgument); sl@0: TEST2(errorId, KInt2); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository1->Set(KInt2, KInt2_InitialValue + 1); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Set KInt2 to a value of string16 type sl@0: r = repository1->Set(KInt2, KString16_InitialValue); sl@0: TEST2(r, KErrArgument); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction | EFailedBit); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrArgument); sl@0: TEST2(errorId, KInt2); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0167 sl@0: @SYMTestCaseDesc Test Transaction error conditions with move sl@0: @SYMTestPriority High sl@0: @SYMTestActions Start a transaction and perform some problematic move operations. Test to see if it fails transactions or not. sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMPREQ PREQ752 sl@0: */ sl@0: LOCAL_C void TransactionErrorConditionsForMoveL() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0167 ")); sl@0: TInt r; sl@0: TUint32 errorId; sl@0: sl@0: CRepository* repository1; sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Move a set of keys which does not exist sl@0: r = repository1->Move(KMoveSourceDoesntExist, KMoveTarget, KMoveMask, errorId) ; sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: r = repository1->Move(KInt1, KInt1, KMoveMask, errorId) ; sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0168 sl@0: @SYMTestCaseDesc Test move operation with more comprehensive test cases sl@0: @SYMTestPriority High sl@0: @SYMTestActions Start a transaction and try to perform some problematic move operations. Check result of operation. sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMPREQ PREQ752 sl@0: */ sl@0: LOCAL_C void TransactionConditionsForMoveL() sl@0: { sl@0: // More comprehensive test cases for MOVE sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0168 ")); sl@0: TInt r; sl@0: TUint32 errorId; sl@0: TBuf8<16> buf8Val; sl@0: sl@0: CRepository* repository1; sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Move a set of keys which does not exist sl@0: r = repository1->Move(KNewString8, KMoveTarget, KMoveMask, errorId); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: r = repository1->Create(KNewString8, KString8_InitialValue2); sl@0: TEST2(r, KErrNone); sl@0: sl@0: //Move KNewString8 to KMoveTarget sl@0: r = repository1->Move(KNewString8, KMoveTarget, KMoveMask, errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository1->Get(KNewString8, buf8Val); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EReadWriteTransaction); sl@0: sl@0: // Move keys back again sl@0: r = repository1->Move(KMoveTarget, KNewString8, KMoveMask, errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository1->Get(KNewString8, buf8Val); sl@0: TEST2(r, KErrNone); sl@0: TEST(buf8Val==KString8_InitialValue2); sl@0: sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Reset the test by deleting KNewString8... sl@0: r = repository1->Delete(KNewString8); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0169 sl@0: @SYMTestCaseDesc Test concurrent read and write transactions sl@0: @SYMTestPriority High sl@0: @SYMTestActions Start a concurrent read write transaction and perform some operations. Check the state of transaction sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMPREQ PREQ752 sl@0: */ sl@0: LOCAL_C void ConcurrentReadWriteTransactionStatesL() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0169 ")); sl@0: TInt r; sl@0: TUint32 errorId; sl@0: TReal getValue; sl@0: sl@0: CRepository* repository1; sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // Begin transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EConcurrentReadWriteTransaction); sl@0: sl@0: r = repository1->Create(KReal2, KReal2_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository1->Get(KReal2, getValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Fail transaction should roll back transaction i.e. Create KReal2 should not work. sl@0: repository1->FailTransaction(); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EConcurrentReadWriteTransaction | EFailedBit); sl@0: sl@0: // Commit transaction sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrAbort); sl@0: sl@0: // Try to get a value which should not exist as transaction failed sl@0: r = repository1->Get(KReal2, getValue); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, ENoTransaction); sl@0: sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENREP-CT-0170 sl@0: @SYMTestCaseDesc Test concurrent read and write transaction with read operations sl@0: @SYMTestPriority High sl@0: @SYMTestActions Start a concurrent read write and a read transaction and perform some read operations. Check the state of transaction sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMPREQ PREQ752 sl@0: */ sl@0: LOCAL_C void ConcurrentReadWriteTransactionWithReadOperationsL() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0170 ")); sl@0: TInt r; sl@0: TUint32 errorId; sl@0: TReal getValue; sl@0: sl@0: CRepository* repository1; sl@0: CRepository* repository2; sl@0: CRepository* repository3; sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: User::LeaveIfNull(repository2 = CRepository::NewLC(KUidTestRepository)); sl@0: User::LeaveIfNull(repository3 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // Begin concurrent read write transaction for repository1 sl@0: r = repository1->StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Begin read transaction for repository2 sl@0: r = repository2->StartTransaction(CRepository::EReadTransaction); sl@0: sl@0: r = TransactionState(repository1); sl@0: TEST2(r, EConcurrentReadWriteTransaction); sl@0: sl@0: r = TransactionState(repository2); sl@0: TEST2(r, EReadTransaction); sl@0: sl@0: // Create value in with a concurrent read write transaction sl@0: r = repository1->Create(KReal2, KReal2_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Get value set using another transaction sl@0: r = repository2->Get(KReal1, getValue); sl@0: TEST2(r, KErrNone); sl@0: TEST(getValue == KReal1_InitialValue); sl@0: sl@0: // Get value set outside of a transaction using repository3 sl@0: r = repository3->Get(KReal1, getValue); sl@0: TEST2(r, KErrNone); sl@0: TEST(getValue == KReal1_InitialValue); sl@0: sl@0: // Get value set within another transaction but not commited, within a transaction sl@0: r = repository2->Get(KReal2, getValue); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: // Get value set within another transaction but not commited, outside of a transaction sl@0: r = repository3->Get(KReal2, getValue); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: // Commit repository2 sl@0: r = repository2->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Commit repository1 sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::PopAndDestroy(repository3); sl@0: CleanupStack::PopAndDestroy(repository2); sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // Check that value was persisted sl@0: r = repository1->Get(KReal2, getValue); sl@0: TEST2(r, KErrNone); sl@0: TEST(getValue == KReal2_InitialValue); sl@0: sl@0: // Delete KReal2 to reset available test case variables sl@0: r = repository1->Delete(KReal2); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: } sl@0: sl@0: LOCAL_C void Defect058796() sl@0: { sl@0: TInt r; sl@0: TUint32 errorId; sl@0: sl@0: TBuf8<2> buf8ValSmall; sl@0: TBuf16<2> buf16ValSmall; sl@0: sl@0: TBuf8<16> buf8Val; sl@0: TBuf16<16> buf16Val; sl@0: sl@0: TInt length; sl@0: sl@0: CRepository* repository1; sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: // Start a read write transaction sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Try to get a string value using a TBuf8 with length which is too small sl@0: r = repository1->Get(KString8, buf8ValSmall, length); sl@0: TEST2(r, KErrOverflow); sl@0: TEST(buf8ValSmall == KString8_Small_Value); sl@0: TEST2(length, 13); sl@0: sl@0: // Try to get a string value using a TBuf16 with length which is too small sl@0: r = repository1->Get(KString16, buf16ValSmall, length); sl@0: TEST2(r, KErrOverflow); sl@0: TEST(buf16ValSmall == KString16_Small_Value); sl@0: TEST2(length, 13); sl@0: sl@0: // Set KNewString16 and KNewString8 sl@0: r = repository1->Create(KNewString16, KString16_InitialValue2); sl@0: TEST2(r, KErrNone); sl@0: r = repository1->Create(KNewString8, KString8_InitialValue2); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Try to get KNewString16 with a TBuf16 which is a suitable size sl@0: r = repository1->Get(KNewString16, buf16Val, length); sl@0: TEST2(r, KErrNone); sl@0: TEST(buf16Val == KString16_InitialValue2); sl@0: TEST2(length, 16); sl@0: sl@0: // Try to get KNewString8 with a TBuf8 which is a suitable size sl@0: r = repository1->Get(KNewString8, buf8Val, length); sl@0: TEST2(r, KErrNone); sl@0: TEST(buf8Val == KString8_InitialValue2); sl@0: TEST2(length, 16); sl@0: sl@0: // Commit the transaction sl@0: r = repository1->CommitTransaction(errorId); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Delete KNewString8 to reset available test case variables sl@0: r = repository1->Delete(KNewString8); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Delete KNewString16 to reset available test case variables sl@0: r = repository1->Delete(KNewString16); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void UnloadedPolicyKeyTest() sl@0: { sl@0: TInt r; sl@0: TUint32 KeyId; sl@0: CRepository* repository1; sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: //Creating Single Policy Key sl@0: r = repository1->Create(KInt5, KInt5_SecondValue ); sl@0: TEST2(r,KErrNone); sl@0: sl@0: //Creating Ranged Policy Key sl@0: r = repository1->Create(KInt3, KInt3_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: //Creating Default Policy Key sl@0: r = repository1->Create(KInt4, KInt4_InitialValue); sl@0: TEST2(r,KErrNone); sl@0: sl@0: //Waiting for enough time for the repository to be evicted sl@0: User::After(1000000); sl@0: sl@0: r = repository1->CommitTransaction(KeyId); sl@0: TEST2(r, KErrNone); sl@0: TEST2(KeyId, 3); sl@0: sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: //Deleting Default Policy Key sl@0: r = repository1->Delete(KInt5); sl@0: TEST2(r, KErrNone); sl@0: sl@0: //Deleting Ranged Policy Key sl@0: r = repository1->Delete(KInt3); sl@0: TEST2(r, KErrNone); sl@0: sl@0: //Deleting Single Policy Key sl@0: r = repository1->Delete(KInt4); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository1->CommitTransaction(KeyId); sl@0: TEST2(r, KErrNone); sl@0: TEST2(KeyId, 3); sl@0: sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-3239 sl@0: @SYMTestCaseDesc Test for corrupt access policy when a repository is evicted and reloaded during a transaction sl@0: @SYMTestPriority High sl@0: @SYMTestActions Start a transaction and create keys with different access policies but evicts the repository prior to commiting it sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMDEF DEF095718 sl@0: */ sl@0: LOCAL_C void Defect095718() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-3239 ")); sl@0: CRepository* repository1; sl@0: TInt r; sl@0: TUint32 KeyId; sl@0: TBuf src1; sl@0: TBuf dest1; sl@0: _LIT(KDest, "c:\\private\\10202BE9\\centrep.ini"); sl@0: _LIT(KSrc, "z:\\private\\10202BE9\\centrepcache.ini10"); sl@0: _LIT( KCentralRepositoryServerName, "Centralrepositorysrv"); sl@0: const TInt test_total = 3; //The test runs 3 times sl@0: sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: r = repository1->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: //Deleting the existing key so that we can re-create it later sl@0: r = repository1->Delete(KInt5); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository1->CommitTransaction(KeyId); sl@0: TEST2(r, KErrNone); sl@0: TEST2(KeyId, 1); sl@0: sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: sl@0: //Kill the server so that a new .ini file can be loaded when the server restarts sl@0: KillProcess(KCentralRepositoryServerName); sl@0: //Copy the .ini file from z: to c: so the server will load it sl@0: RFs FileServer; sl@0: FileServer.Connect(); sl@0: CleanupClosePushL(FileServer); sl@0: CFileMan* fm = CFileMan::NewL(FileServer); sl@0: CleanupStack::PushL(fm); sl@0: dest1.Copy(KDest); sl@0: src1.Copy(KSrc); sl@0: r = fm->Delete(dest1); sl@0: User::LeaveIfError(fm->Copy(src1,dest1)); sl@0: r = fm->Attribs(dest1, KEntryAttArchive, KEntryAttReadOnly, TTime(0), CFileMan::ERecurse); sl@0: TEST2(r, KErrNone); sl@0: sl@0: //Test for unloaded policy key a set amount of times sl@0: for(TInt i=0; iDelete(dest1); sl@0: TEST2(r, KErrNone); sl@0: sl@0: //Killing the server and restarting it so that default values are loaded sl@0: KillProcess(KCentralRepositoryServerName); sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: CleanupStack::PopAndDestroy(fm); sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-3243 sl@0: @SYMTestCaseDesc Test that a repository client can be reused after a CommitTransaction and CancelTransaction Operation involving mulitple concurrent transactions sl@0: @SYMTestPriority High sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMTestActions Start concurrent transactions and create keys in each one. Cancel one transaction and commit the others. Then restart the transactions to test for panics sl@0: @SYMDEF DEF098242 sl@0: */ sl@0: LOCAL_C void Defect098242() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-3243 ")); sl@0: TInt r; sl@0: TUint32 KeyId; sl@0: CRepository* repository1; sl@0: CRepository* repository2; sl@0: CRepository* repository3; sl@0: User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository)); sl@0: User::LeaveIfNull(repository2 = CRepository::NewLC(KUidTestRepository)); sl@0: User::LeaveIfNull(repository3 = CRepository::NewLC(KUidTestRepository)); sl@0: sl@0: //Starting 3 transactions sl@0: r = repository1->StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository2->StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository3->StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: //Adding values in each sl@0: r = repository1->Create(KInt2, KInt2_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository2->Create(KInt3, KInt3_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = repository3->Create(KInt4, KInt4_InitialValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: //Cancel the transaction of the first client sl@0: repository1->CancelTransaction(); sl@0: sl@0: //Committing the other 2 transactions sl@0: r = repository2->CommitTransaction(KeyId); sl@0: TEST2(r, KErrNone); sl@0: TEST2(KeyId,1); sl@0: sl@0: r = repository3->CommitTransaction(KeyId); sl@0: TEST2(r, KErrLocked); sl@0: TEST2(KeyId,KUnspecifiedKey); sl@0: sl@0: //Try Re-starting a transaction with the clients sl@0: r = repository1->StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: r = repository1->CommitTransaction(KeyId); sl@0: TEST2(r, KErrNone); sl@0: TEST2(KeyId,0); sl@0: sl@0: r = repository2->StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: sl@0: //Deleting the key so the repository is in the same state as prior to the function call sl@0: r = repository2->Delete(KInt3); sl@0: TEST2(r, KErrNone); sl@0: sl@0: //Checking that these values were not made persistent sl@0: r = repository2->Delete(KInt2); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: r = repository2->Delete(KInt4); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: r = repository2->CommitTransaction(KeyId); sl@0: TEST2(r, KErrNone); sl@0: TEST2(KeyId,1); sl@0: sl@0: r = repository1->Reset(); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::PopAndDestroy(repository3); sl@0: CleanupStack::PopAndDestroy(repository2); sl@0: CleanupStack::PopAndDestroy(repository1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-UT-4011 sl@0: @SYMTestCaseDesc Test for PDEF112273 - When creating commsdat Backup & restore metadata is not set correctly sl@0: @SYMTestPriority High sl@0: @SYMTestActions The test uses the 00112273.TXT ini file, where the default meta data value is set to be 0x00100000. sl@0: The test creates a CRepository object with UID=0x00112273 and creates a single integer setting with sl@0: value 1 and no meta data. In this case the setting meta data should be the default one - 0x00100000. sl@0: Then the test begins a transaction and within the transaction: the setting gets deleted and then - recreated sl@0: again but with a different value and no meta data. The transaction is commited. sl@0: The setting meta data value should be 0x00100000 within the transaction and outisde the transaction. sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMDEF PDEF112273 sl@0: */ sl@0: void DoPDEF112273Test1L() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-UT-4011 ")); sl@0: const TUid KTestCenRepUid = {0x00112273}; sl@0: CRepository* repository = CRepository::NewLC(KTestCenRepUid); sl@0: //Create a setting sl@0: const TInt KTestSettingId = 123; sl@0: TInt err = repository->Create(KTestSettingId, 1); sl@0: TEST2(err, KErrNone); sl@0: sl@0: const TUint32 KDefaultMeta = 0x00100000; sl@0: //Check setting meta. The meta value should be KDefaultMeta. sl@0: TUint32 meta = 0; sl@0: err = repository->GetMeta(KTestSettingId, meta); sl@0: TEST2(err, KErrNone); sl@0: TEST2(meta, KDefaultMeta); sl@0: sl@0: err = repository->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(err, KErrNone); sl@0: //In a transaction. Delete the created setting. sl@0: err = repository->Delete(KTestSettingId); sl@0: TEST2(err, KErrNone); sl@0: //In a transaction. Re-create the deleted setting but with a different value. sl@0: err = repository->Create(KTestSettingId, 2); sl@0: TEST2(err, KErrNone); sl@0: //In a transaction. Get the setting meta. The meta value should be KDefaultMeta. sl@0: err = repository->GetMeta(KTestSettingId, meta); sl@0: TEST2(err, KErrNone); sl@0: TEST2(meta, KDefaultMeta); sl@0: sl@0: TUint32 keyInfo = 0; sl@0: err = repository->CommitTransaction(keyInfo); sl@0: TEST2(err, KErrNone); sl@0: sl@0: //Not in transaction. Get the setting meta. The meta value should be KDefaultMeta. sl@0: err = repository->GetMeta(KTestSettingId, meta); sl@0: TEST2(err, KErrNone); sl@0: TEST2(meta, KDefaultMeta); sl@0: sl@0: CleanupStack::PopAndDestroy(repository); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-UT-4012 sl@0: @SYMTestCaseDesc Test for PDEF112273 - When creating commsdat Backup & restore metadata is not set correctly sl@0: @SYMTestPriority High sl@0: @SYMTestActions The test uses the 00112273.TXT ini file, where the default meta data value is set to be 0x00100000. sl@0: The test creates a CRepository object with UID=0x00112273. sl@0: Then the test begins a transaction and within the transaction: setting with id=0x0000001 (from the ini file) sl@0: and setting meta=0x00200000 will be deleted and then recreated again with a different value and no meta. sl@0: The transaction is commited. sl@0: The setting meta data value should be 0x00200000 within the transaction and outisde the transaction. sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMDEF PDEF112273 sl@0: */ sl@0: void DoPDEF112273Test2L() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-UT-4012 ")); sl@0: const TUid KTestCenRepUid = {0x00112273}; sl@0: CRepository* repository = CRepository::NewLC(KTestCenRepUid); sl@0: //Ini file - KTestSettingId setting properties: sl@0: const TInt KTestSettingId = 0x0000001; sl@0: const TInt KTestSettingVal = 1; sl@0: const TUint32 KSettingMeta = 0x00200000; sl@0: //Check setting meta. The meta value should be KDefaultMeta. sl@0: TUint32 meta = 0; sl@0: TInt err = repository->GetMeta(KTestSettingId, meta); sl@0: TEST2(err, KErrNone); sl@0: TEST2(meta, KSettingMeta); sl@0: sl@0: err = repository->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(err, KErrNone); sl@0: //In a transaction. Delete the created setting. sl@0: err = repository->Delete(KTestSettingId); sl@0: TEST2(err, KErrNone); sl@0: //In a transaction. Re-create the deleted setting with different value. sl@0: err = repository->Create(KTestSettingId, KTestSettingVal + 1); sl@0: TEST2(err, KErrNone); sl@0: //In a transaction. Get the setting meta. The meta value should be KSettingMeta. sl@0: err = repository->GetMeta(KTestSettingId, meta); sl@0: TEST2(err, KErrNone); sl@0: TEST2(meta, KSettingMeta); sl@0: sl@0: TUint32 keyInfo = 0; sl@0: err = repository->CommitTransaction(keyInfo); sl@0: TEST2(err, KErrNone); sl@0: sl@0: //Not in transaction. Get the setting meta. The meta value should be KSettingMeta. sl@0: err = repository->GetMeta(KTestSettingId, meta); sl@0: TEST2(err, KErrNone); sl@0: TEST2(meta, KSettingMeta); sl@0: sl@0: CleanupStack::PopAndDestroy(repository); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-UT-4013 sl@0: @SYMTestCaseDesc Test for PDEF112273 - When creating commsdat Backup & restore metadata is not set correctly sl@0: @SYMTestPriority High sl@0: @SYMTestActions The test uses the 00112273.TXT ini file, where the default meta data value is set to be 0x00100000. sl@0: The test creates a CRepository object with UID=0x00112273. sl@0: Then the test begins a transaction and within the transaction: a new setting with no meta is created. sl@0: The transaction is commited. sl@0: The setting meta data value should be 0x00100000 within the transaction and outisde the transaction. sl@0: @SYMTestExpectedResults The test should not fail with any panics sl@0: @SYMDEF PDEF112273 sl@0: */ sl@0: void DoPDEF112273Test3L() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-UT-4013 ")); sl@0: const TUid KTestCenRepUid = {0x00112273}; sl@0: CRepository* repository = CRepository::NewLC(KTestCenRepUid); sl@0: sl@0: TInt err = repository->StartTransaction(CRepository::EReadWriteTransaction); sl@0: TEST2(err, KErrNone); sl@0: //In a transaction. Create a setting sl@0: const TInt KTestSettingId = 1234; sl@0: err = repository->Create(KTestSettingId, 1); sl@0: TEST2(err, KErrNone); sl@0: sl@0: const TUint32 KDefaultMeta = 0x00100000; sl@0: TUint32 meta = 0; sl@0: //In a transaction. Get the setting meta. The meta value should be KDefaultMeta. sl@0: err = repository->GetMeta(KTestSettingId, meta); sl@0: TEST2(err, KErrNone); sl@0: TEST2(meta, KDefaultMeta); sl@0: sl@0: TUint32 keyInfo = 0; sl@0: err = repository->CommitTransaction(keyInfo); sl@0: TEST2(err, KErrNone); sl@0: sl@0: //Not in transaction. Get the setting meta. The meta value should be KDefaultMeta. sl@0: err = repository->GetMeta(KTestSettingId, meta); sl@0: TEST2(err, KErrNone); sl@0: TEST2(meta, KDefaultMeta); sl@0: sl@0: CleanupStack::PopAndDestroy(repository); sl@0: } sl@0: sl@0: void PDEF112273L() sl@0: { sl@0: DoPDEF112273Test1L(); sl@0: DoPDEF112273Test2L(); sl@0: DoPDEF112273Test3L(); sl@0: } sl@0: sl@0: LOCAL_C void TransactionsFuncTestsL() sl@0: { sl@0: TheTest.Next(_L("Committing changes causes other sessions' active transactions to fail with KErrLocked")); sl@0: CommittingChangesFailsOtherTransactionsL(); sl@0: sl@0: TheTest.Next(_L("Committing no changes does not fail other sessions' active transactions")); sl@0: CommittingNoChangesDoesNotFailOtherTransactionsL(); sl@0: sl@0: TheTest.Start(_L("Create values using transaction")); sl@0: CreateValueUsingTransactionL(); sl@0: sl@0: TheTest.Next(_L("Get transaction state in transactions and test for rollback in failed transactions")); sl@0: TransactionStateAndRollBackL(); sl@0: sl@0: TheTest.Next(_L("Multiple Read-Write Transaction error and panic conditions")); sl@0: TransactionPanicConditionsThread(); sl@0: sl@0: TheTest.Next(_L("Commit Transaction error and panic condition")); sl@0: CommitTransactionPanicConditionsThread(); sl@0: sl@0: TheTest.Next(_L("Clean up using rollback and failed transactions")); sl@0: CleanupRollBackAndFailTransactionL(); sl@0: sl@0: TheTest.Next(_L("Multiple Read Transaction conditions")); sl@0: ReadTransactionConditionsL(); sl@0: sl@0: TheTest.Next(_L("Multiple Read Transaction with upgrade error conditions")); sl@0: UpgradeReadTransactionErrorConditionsL(); sl@0: sl@0: TheTest.Next(_L("Transaction conditions with read operations")); sl@0: TransactionConditionsForReadL(); sl@0: sl@0: TheTest.Next(_L("Transaction error conditions with get operations")); sl@0: TransactionErrorConditionsForGetL(); sl@0: sl@0: TheTest.Next(_L("Transaction error conditions with find operations")); sl@0: TransactionErrorConditionsForFindL(); sl@0: sl@0: TheTest.Next(_L("Transaction error conditions with findeq operations")); sl@0: TransactionErrorConditionsForFindEqL(); sl@0: sl@0: TheTest.Next(_L("Transaction error conditions with findneq operations")); sl@0: TransactionErrorConditionsForFindNeqL(); sl@0: sl@0: TheTest.Next(_L("Transaction error conditions with create operations")); sl@0: TransactionErrorConditionsForCreateL(); sl@0: sl@0: TheTest.Next(_L("Transaction error conditions with delete operations")); sl@0: TransactionErrorConditionsForDeleteL(); sl@0: sl@0: TheTest.Next(_L("Transaction error conditions with set operations")); sl@0: TransactionErrorConditionsForSetL(); sl@0: sl@0: TheTest.Next(_L("Transaction error conditions with move operations")); sl@0: TransactionErrorConditionsForMoveL(); sl@0: sl@0: TheTest.Next(_L("Transaction conditions with move operations")); sl@0: TransactionConditionsForMoveL(); sl@0: sl@0: // Concurrent read/write transactions... sl@0: sl@0: TheTest.Next(_L("Concurrent read/write transaction")); sl@0: ConcurrentReadWriteTransactionStatesL(); sl@0: sl@0: TheTest.Next(_L("Concurrent read/write transaction with other reads operations")); sl@0: ConcurrentReadWriteTransactionWithReadOperationsL(); sl@0: sl@0: // Test cases for defects ... sl@0: sl@0: TheTest.Next(_L("Tests for get functions, as required in DEF058796")); sl@0: Defect058796(); sl@0: sl@0: TheTest.Next(_L("Checks for corrupt policy keys, as required in DEF095718")); sl@0: Defect095718(); sl@0: sl@0: TheTest.Next(_L("Test for restarting a transaction from the same client, as required in DEF098242")); sl@0: Defect098242(); sl@0: sl@0: TheTest.Next(_L("PDEF112273 - When creating commsdat Backup & restore metadata is not set correctly")); sl@0: PDEF112273L(); sl@0: sl@0: TheTest.End(); sl@0: } sl@0: sl@0: LOCAL_C void MainL() sl@0: { sl@0: TheTest.Start(_L("Central Repository transactions functional tests")); sl@0: CleanupCDriveL(); sl@0: TransactionsFuncTestsL(); sl@0: sl@0: TheTest.Next(_L("Clean out C: files")); sl@0: CleanupCDriveL(); sl@0: sl@0: TheTest.End(); sl@0: TheTest.Close(); sl@0: } sl@0: sl@0: TInt E32Main() 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: } sl@0: