sl@0: // Copyright (c) 2006-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 sl@0: #include sl@0: #include sl@0: #include "t_cenrep_helper.h" sl@0: #include sl@0: sl@0: RTest TheTest(_L("Central Repository Settings Tests")); sl@0: RFs fs; sl@0: sl@0: const TUid KUidTestRepository = { 0x00000005 }; sl@0: const TInt KIntOrigValue = 1; sl@0: const TUint32 KGlobalDefaultMeta = 0; sl@0: const TUint32 KRange2DefaultMeta = 2; sl@0: const TUint32 KMetaAtKeyPos24 = 4; sl@0: sl@0: const TUint32 KDefMeta0SingleMeta0Key = 0x1; sl@0: const TUint32 KDefMeta0SingleMeta1Key = 0x2; sl@0: const TUint32 KDefMeta1SingleMeta0Key = 0x10; sl@0: const TUint32 KDefMeta1SingleMeta1Key = 0x11; sl@0: const TUint32 KMissingSingleMetaKey = 0x20; sl@0: sl@0: const TUint32 KPlatsecFailureKey = 0x21; sl@0: sl@0: const TUint32 KRange2KeyWithMeta4 = 0x24; sl@0: sl@0: _LIT( KSrcTxaPath, "z:\\private\\10202BE9\\00000005.txa" ); sl@0: _LIT( KSrcCacheIniPath, "z:\\private\\10202BE9\\centrepcache.ini9" ); sl@0: sl@0: _LIT( KInstallTxtPath, "C:\\private\\10202BE9\\00000005.txt" ); sl@0: _LIT( KInstallCrePath, "C:\\private\\10202BE9\\00000005.cre" ); sl@0: _LIT( KPersistsCrePath, "C:\\private\\10202BE9\\persists\\00000005.cre" ); sl@0: _LIT( KCacheIniPath, "C:\\private\\10202BE9\\centrep.ini" ); sl@0: sl@0: sl@0: TPtrC metaTestFiles[] = sl@0: { sl@0: TPtrC(KInstallTxtPath), sl@0: TPtrC(KInstallCrePath), sl@0: TPtrC(KPersistsCrePath), sl@0: sl@0: // This one last because we do not always delete it. sl@0: TPtrC(KCacheIniPath) sl@0: }; sl@0: sl@0: const TInt KNumMetaTestFiles = sizeof(metaTestFiles) / sizeof(TPtrC); sl@0: sl@0: _LIT( KCentralRepositoryServerName, "Centralrepositorysrv"); sl@0: sl@0: //=========================================================== sl@0: // Test macroses and functions sl@0: //=========================================================== sl@0: sl@0: LOCAL_C TInt DeleteFile(const TDesC& aFileName, CFileMan& aFileMan) sl@0: { sl@0: TInt r = aFileMan.Delete( aFileName ); sl@0: if ( r != KErrNone && r != KErrNotFound && r != KErrPathNotFound ) sl@0: { sl@0: return r; sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: LOCAL_C TInt DeleteFilesL(TPtrC aFileList[], TInt aNumFiles) sl@0: { sl@0: CFileMan* fm = CFileMan::NewL(fs); sl@0: CleanupStack::PushL( fm ); sl@0: sl@0: TInt ret = KErrNone; sl@0: for (TInt i = 0; i < aNumFiles; i++) sl@0: { sl@0: TInt r = DeleteFile( aFileList[i], *fm ); sl@0: if (r != KErrNone) sl@0: { sl@0: ret = r; sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy( fm ); sl@0: return ret; sl@0: } sl@0: sl@0: LOCAL_C void TestCleanupL() sl@0: { sl@0: DeleteFilesL(metaTestFiles, KNumMetaTestFiles); sl@0: KillProcess(KCentralRepositoryServerName); sl@0: } sl@0: sl@0: LOCAL_C void CheckL( TInt aValue, TInt aLine ) sl@0: { sl@0: if ( !aValue ) sl@0: { sl@0: TestCleanupL(); sl@0: TheTest( EFalse, aLine ); sl@0: } 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: TheTest.Printf( _L( "*** Expected value: %d, got: %d\r\n"), aExpected, aValue ); sl@0: TestCleanupL(); sl@0: TheTest( EFalse, aLine ); sl@0: } sl@0: } sl@0: sl@0: #define TEST(arg) ::CheckL((arg), __LINE__) sl@0: #define TEST2(aValue, aExpected) ::CheckL(aValue, aExpected, __LINE__) sl@0: sl@0: LOCAL_C void CopyFileL(const TDesC& aSrc, sl@0: const TDesC& aDest, sl@0: TBool aClearROAttrib) sl@0: { sl@0: CFileMan* fm = CFileMan::NewL( fs ); sl@0: CleanupStack::PushL( fm ); sl@0: sl@0: TInt ret = fm->Copy(aSrc, aDest); sl@0: if (aClearROAttrib && (ret == KErrNone)) sl@0: { sl@0: ret = fm->Attribs( aDest, KEntryAttArchive, KEntryAttReadOnly, TTime( 0 ), CFileMan::ERecurse ); sl@0: } sl@0: sl@0: User::LeaveIfError(ret); sl@0: sl@0: CleanupStack::PopAndDestroy( fm ); sl@0: } sl@0: sl@0: //============================================================= sl@0: // class to encapsulate metadata test sl@0: class TMetadataTest sl@0: { sl@0: public: sl@0: inline TMetadataTest() {} sl@0: ~TMetadataTest(); sl@0: void InitialiseL(); sl@0: void InstallCreFileL(); sl@0: void RunTestsL(); sl@0: void RunSetTestL(); sl@0: void RunDeleteResetTestL(); sl@0: void RunDeleteCreateTestL(); sl@0: void RunDeleteCreateTest2L(); sl@0: void RunMoveTestL(); sl@0: sl@0: void RunBasicGetMetaTestsL(); sl@0: sl@0: TBool VerifyMetaDataUnchangedL(); sl@0: }; sl@0: sl@0: //========================================== sl@0: TMetadataTest::~TMetadataTest() sl@0: { sl@0: TRAPD(err, ::TestCleanupL()); sl@0: if (err != KErrNone) sl@0: { sl@0: RDebug::Printf("err = %d in ~TMetadataTest.", err); sl@0: } sl@0: } sl@0: sl@0: //========================================== sl@0: void TMetadataTest::InitialiseL() sl@0: { sl@0: ::TestCleanupL(); sl@0: User::After(1000000); // pause after KillProcess sl@0: ::CopyFileL(KSrcTxaPath, KInstallTxtPath, ETrue); sl@0: ::CopyFileL(KSrcCacheIniPath, KCacheIniPath, ETrue); sl@0: } sl@0: sl@0: //========================================== sl@0: void TMetadataTest::InstallCreFileL() sl@0: { sl@0: // Ensure start with original 00000005.txa file. sl@0: // Be careful. Do not delete centrep.ini sl@0: ::DeleteFilesL(metaTestFiles, KNumMetaTestFiles - 1); sl@0: ::CopyFileL(KSrcTxaPath, KInstallTxtPath, ETrue); sl@0: sl@0: CRepository* rep = CRepository::NewLC(KUidTestRepository); sl@0: sl@0: // Create/Delete to persist the .txt to .cre sl@0: TInt r = rep->Create(0xA5A5, 1); sl@0: TEST2(r, KErrNone); sl@0: sl@0: rep->Delete(0xA5A5); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::PopAndDestroy(rep); sl@0: sl@0: ::CopyFileL(KPersistsCrePath, KInstallCrePath, EFalse); sl@0: sl@0: TPtrC onefile[1] = { TPtrC(KPersistsCrePath) }; sl@0: ::DeleteFilesL(onefile, 1); sl@0: } sl@0: sl@0: //========================================== sl@0: void TMetadataTest::RunTestsL() sl@0: { sl@0: RunSetTestL(); sl@0: RunDeleteResetTestL(); sl@0: RunDeleteCreateTestL(); sl@0: RunDeleteCreateTest2L(); sl@0: RunMoveTestL(); sl@0: } sl@0: sl@0: //============================================ sl@0: TBool TMetadataTest::VerifyMetaDataUnchangedL() sl@0: { sl@0: CRepository* rep = CRepository::NewLC(KUidTestRepository); sl@0: sl@0: TInt ret = ETrue; sl@0: TUint32 meta; sl@0: sl@0: TInt r = rep->GetMeta(KMissingSingleMetaKey, meta); sl@0: TEST2(r, KErrNone); sl@0: if ( meta != KRange2DefaultMeta) sl@0: { sl@0: TheTest.Printf(_L("Key: 0x%x, meta is %d"), KMissingSingleMetaKey, meta); sl@0: ret = EFalse; sl@0: } sl@0: sl@0: r = rep->GetMeta(KDefMeta0SingleMeta0Key, meta); sl@0: TEST2(r, KErrNone); sl@0: if ( meta != 0) sl@0: { sl@0: TheTest.Printf(_L("Key: 0x%x, meta is %d"), KDefMeta0SingleMeta0Key, meta); sl@0: ret = EFalse; sl@0: } sl@0: sl@0: r = rep->GetMeta(KDefMeta0SingleMeta1Key, meta); sl@0: TEST2(r, KErrNone); sl@0: if ( meta != 1) sl@0: { sl@0: TheTest.Printf(_L("Key: 0x%x, meta is %d"), KDefMeta0SingleMeta1Key, meta); sl@0: ret = EFalse; sl@0: } sl@0: sl@0: r = rep->GetMeta(KDefMeta1SingleMeta0Key, meta); sl@0: TEST2(r, KErrNone); sl@0: if ( meta != 0) sl@0: { sl@0: TheTest.Printf(_L("Key: 0x%x, meta is %d"), KDefMeta1SingleMeta0Key, meta); sl@0: ret = EFalse; sl@0: } sl@0: sl@0: r = rep->GetMeta(KDefMeta1SingleMeta1Key, meta); sl@0: TEST2(r, KErrNone); sl@0: if ( meta != 1) sl@0: { sl@0: TheTest.Printf(_L("Key: 0x%x, meta is %d"), KDefMeta1SingleMeta1Key, meta); sl@0: ret = EFalse; sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(rep); sl@0: return ret; sl@0: } sl@0: sl@0: //============================================ sl@0: void TMetadataTest::RunBasicGetMetaTestsL() sl@0: { sl@0: TheTest.Next(_L("Basic functional tests on the GetMeta API\r\n")); sl@0: sl@0: CRepository* rep = CRepository::NewLC(KUidTestRepository); sl@0: sl@0: TUint32 meta; sl@0: sl@0: // GetMeta on non-existing key. sl@0: const TUint32 KNonExistingKey = 0xFACE; sl@0: TInt r = rep->GetMeta(KNonExistingKey, meta); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: // Missing capability to read meta of following key. sl@0: r = rep->GetMeta(KPlatsecFailureKey, meta); sl@0: TEST2(r, KErrPermissionDenied); sl@0: sl@0: // GetMeta in transaction sl@0: r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: rep->CleanupCancelTransactionPushL(); sl@0: sl@0: r = rep->Set(KMissingSingleMetaKey, KIntOrigValue+1); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = rep->GetMeta(KMissingSingleMetaKey, meta); sl@0: TEST2(r, KErrNone); sl@0: TEST2(meta, KRange2DefaultMeta); sl@0: sl@0: CleanupStack::PopAndDestroy(); // cancel transaction sl@0: sl@0: CleanupStack::PopAndDestroy(rep); sl@0: } sl@0: sl@0: //============================================ sl@0: void TMetadataTest::RunMoveTestL() sl@0: { sl@0: TheTest.Next(_L("Metadata Move settings test\r\n")); sl@0: sl@0: const TUint32 KDefRangeKeyForCreate = 0x3A; sl@0: const TUint32 KRange2KeyForCreate = 0x2A; sl@0: const TUint32 KDefRangeKeyForMove = 0x3B; sl@0: const TUint32 KRange2KeyForMove = 0x2B; sl@0: sl@0: CRepository* rep = CRepository::NewLC(KUidTestRepository); sl@0: sl@0: TInt r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: rep->CleanupCancelTransactionPushL(); sl@0: sl@0: r = rep->Create(KDefRangeKeyForCreate, KIntOrigValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = rep->Create(KRange2KeyForCreate, KIntOrigValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::Pop(); // transaction sl@0: TUint32 errKey; sl@0: r = rep->CommitTransaction(errKey); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Check that the keys are created with correct meta sl@0: sl@0: TUint32 meta; sl@0: // This key is not covered by any rangemeta. The global sl@0: // default meta should be used. sl@0: r = rep->GetMeta(KDefRangeKeyForCreate, meta); sl@0: TEST2(r, KErrNone); sl@0: TEST2(meta, KGlobalDefaultMeta); sl@0: sl@0: // This key is covered by a rangemeta. sl@0: r = rep->GetMeta(KRange2KeyForCreate, meta); sl@0: TEST2(r, KErrNone); sl@0: TEST2(meta, KRange2DefaultMeta); sl@0: sl@0: // move the created keys to different ranges sl@0: r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: rep->CleanupCancelTransactionPushL(); sl@0: sl@0: const TUint32 KMoveMask = 0x3F; sl@0: r = rep->Move(KDefRangeKeyForCreate, KRange2KeyForMove, KMoveMask, sl@0: errKey); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = rep->Move(KRange2KeyForCreate, KDefRangeKeyForMove, KMoveMask, sl@0: errKey); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::Pop(); // transaction sl@0: r = rep->CommitTransaction(errKey); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // This key is moved from range where rangemeta is 2 to range sl@0: // where meta is defined by the global default meta. sl@0: r = rep->GetMeta(KDefRangeKeyForMove, meta); sl@0: TEST2(r, KErrNone); sl@0: TEST2(meta, KGlobalDefaultMeta); sl@0: sl@0: // This key is moved from range where meta is defined by the sl@0: // global default meta to a range where rangemeta is 2. sl@0: r = rep->GetMeta(KRange2KeyForMove, meta); sl@0: TEST2(r, KErrNone); sl@0: TEST2(meta, KRange2DefaultMeta); sl@0: sl@0: sl@0: // Test Move a key to a position which has just been deleted but sl@0: // not yet commited. sl@0: sl@0: // Create two keys to be moved. To save typing, no transaction. sl@0: r = rep->Create(KDefRangeKeyForCreate, KIntOrigValue); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Create(KRange2KeyForCreate, KIntOrigValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: rep->CleanupCancelTransactionPushL(); sl@0: sl@0: // delete the targeted keys but do not commit sl@0: r = rep->Delete(KDefRangeKeyForMove); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Delete(KRange2KeyForMove); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // move the created keys to target positions sl@0: r = rep->Move(KDefRangeKeyForCreate, KRange2KeyForMove, KMoveMask, sl@0: errKey); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Move(KRange2KeyForCreate, KDefRangeKeyForMove, KMoveMask, sl@0: errKey); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::Pop(); // transaction sl@0: r = rep->CommitTransaction(errKey); sl@0: TEST2(r, KErrNone); sl@0: sl@0: sl@0: // This key is moved from range where rangemeta is 2 to range sl@0: // where meta is defined by the global default meta. sl@0: r = rep->GetMeta(KDefRangeKeyForMove, meta); sl@0: TEST2(r, KErrNone); sl@0: TEST2(meta, KGlobalDefaultMeta); sl@0: sl@0: // This key is moved from range where meta is defined by the sl@0: // global default meta to a range where rangemeta is 2. sl@0: r = rep->GetMeta(KRange2KeyForMove, meta); sl@0: TEST2(r, KErrNone); sl@0: TEST2(meta, KRange2DefaultMeta); sl@0: sl@0: // Test Move a key to a position which has a setting defined sl@0: // in the INI file. The metadata of this pre-existing key sl@0: // is permanently attached to that key position and takes sl@0: // precedent over defaultmeta. sl@0: sl@0: // Create the setting to be moved. sl@0: r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: rep->CleanupCancelTransactionPushL(); sl@0: sl@0: r = rep->Create(KRange2KeyForCreate, KIntOrigValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // delete the key occuping the destination of the move. sl@0: r = rep->Delete(KRange2KeyWithMeta4); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::Pop(); // transaction sl@0: r = rep->CommitTransaction(errKey); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Verify target has been deleted. sl@0: TInt a; sl@0: r = rep->Get(KRange2KeyWithMeta4, a); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: // move the created keys to target positions sl@0: r = rep->Move(KRange2KeyForCreate, KRange2KeyWithMeta4, KMoveMask, sl@0: errKey); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // This key is moved within range where rangemeta is 2. sl@0: // Target position of the Move has a setting defined sl@0: // in the INI file. The metadata of this pre-existing key sl@0: // is permanently attached to that key position and takes sl@0: // precedent over the rangemeta. sl@0: r = rep->GetMeta(KRange2KeyWithMeta4, meta); sl@0: TEST2(r, KErrNone); sl@0: TEST2(meta, KMetaAtKeyPos24); sl@0: sl@0: // cleanup sl@0: r = rep->Reset(); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::PopAndDestroy(rep); sl@0: } sl@0: sl@0: //============================================ sl@0: void TMetadataTest::RunSetTestL() sl@0: { sl@0: TheTest.Next(_L("Metadata Set settings test\r\n")); sl@0: sl@0: CRepository* rep = CRepository::NewLC(KUidTestRepository); sl@0: sl@0: TInt r; sl@0: r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: rep->CleanupCancelTransactionPushL(); sl@0: sl@0: const TInt KNewValue = KIntOrigValue + 1; sl@0: r = rep->Set(KMissingSingleMetaKey, KNewValue); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Set(KDefMeta0SingleMeta0Key, KNewValue); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Set(KDefMeta0SingleMeta1Key, KNewValue); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Set(KDefMeta1SingleMeta0Key, KNewValue); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Set(KDefMeta1SingleMeta1Key, KNewValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::Pop(); // transaction sl@0: TUint32 keyInfo; sl@0: r = rep->CommitTransaction(keyInfo); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // check that the Set has changed the settings. sl@0: TInt a; sl@0: r = rep->Get(KMissingSingleMetaKey, a); sl@0: TEST2(r, KErrNone); sl@0: TEST2(a, KNewValue); sl@0: sl@0: r = rep->Get(KDefMeta0SingleMeta0Key, a); sl@0: TEST2(r, KErrNone); sl@0: TEST2(a, KNewValue); sl@0: sl@0: r = rep->Get(KDefMeta0SingleMeta1Key, a); sl@0: TEST2(r, KErrNone); sl@0: TEST2(a, KNewValue); sl@0: sl@0: r = rep->Get(KDefMeta1SingleMeta0Key, a); sl@0: TEST2(r, KErrNone); sl@0: TEST2(a, KNewValue); sl@0: sl@0: r = rep->Get(KDefMeta1SingleMeta1Key, a); sl@0: TEST2(r, KErrNone); sl@0: TEST2(a, KNewValue); sl@0: sl@0: // Check the Set's have not change the metadata sl@0: TEST(VerifyMetaDataUnchangedL()); sl@0: sl@0: // Take this opportunity to Reset the keys to exercise the sl@0: // Set-then-Reset path. sl@0: sl@0: // Transaction not available for Reset. sl@0: r = rep->Reset(KMissingSingleMetaKey); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Reset(KDefMeta0SingleMeta0Key); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Reset(KDefMeta0SingleMeta1Key); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Reset(KDefMeta1SingleMeta0Key); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Reset(KDefMeta1SingleMeta1Key); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::PopAndDestroy(rep); sl@0: sl@0: TEST(VerifyMetaDataUnchangedL()); sl@0: } sl@0: sl@0: void TMetadataTest::RunDeleteCreateTestL() sl@0: { sl@0: TheTest.Next(_L("Metadata Delete-Create settings test\r\n")); sl@0: sl@0: CRepository* rep = CRepository::NewLC(KUidTestRepository); sl@0: sl@0: TInt r; sl@0: r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: rep->CleanupCancelTransactionPushL(); sl@0: sl@0: r = rep->Delete(KMissingSingleMetaKey); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Delete(KDefMeta0SingleMeta0Key); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Delete(KDefMeta0SingleMeta1Key); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Delete(KDefMeta1SingleMeta0Key); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Delete(KDefMeta1SingleMeta1Key); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::Pop(); // transaction sl@0: TUint32 keyInfo; sl@0: r = rep->CommitTransaction(keyInfo); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::PopAndDestroy(rep); sl@0: sl@0: // Now open the repository again and create the deleted keys. sl@0: rep = CRepository::NewLC(KUidTestRepository); sl@0: sl@0: // Before Create, check if the Delete's actually happened. sl@0: TInt a; sl@0: r = rep->Get(KMissingSingleMetaKey, a); sl@0: TEST2(r, KErrNotFound); sl@0: r = rep->Get(KDefMeta0SingleMeta0Key, a); sl@0: TEST2(r, KErrNotFound); sl@0: r = rep->Get(KDefMeta0SingleMeta1Key, a); sl@0: TEST2(r, KErrNotFound); sl@0: r = rep->Get(KDefMeta1SingleMeta0Key, a); sl@0: TEST2(r, KErrNotFound); sl@0: r = rep->Get(KDefMeta1SingleMeta1Key, a); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: rep->CleanupCancelTransactionPushL(); sl@0: sl@0: r = rep->Create(KMissingSingleMetaKey, KIntOrigValue); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Create(KDefMeta0SingleMeta0Key, KIntOrigValue); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Create(KDefMeta0SingleMeta1Key, KIntOrigValue); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Create(KDefMeta1SingleMeta0Key, KIntOrigValue); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Create(KDefMeta1SingleMeta1Key, KIntOrigValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::Pop(); // transaction sl@0: r = rep->CommitTransaction(keyInfo); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::PopAndDestroy(rep); sl@0: sl@0: TEST(VerifyMetaDataUnchangedL()); sl@0: } sl@0: sl@0: //================================================= sl@0: void TMetadataTest::RunDeleteCreateTest2L() sl@0: { sl@0: TheTest.Next(_L("Metadata Delete-Create settings (uncommitted) test\r\n")); sl@0: sl@0: CRepository* rep = CRepository::NewLC(KUidTestRepository); sl@0: sl@0: TInt r; sl@0: r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: rep->CleanupCancelTransactionPushL(); sl@0: sl@0: r = rep->Delete(KMissingSingleMetaKey); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Delete(KDefMeta0SingleMeta0Key); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Delete(KDefMeta0SingleMeta1Key); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Delete(KDefMeta1SingleMeta0Key); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Delete(KDefMeta1SingleMeta1Key); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Next Create while Delete still in transaction. sl@0: r = rep->Create(KMissingSingleMetaKey, KIntOrigValue); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Create(KDefMeta0SingleMeta0Key, KIntOrigValue); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Create(KDefMeta0SingleMeta1Key, KIntOrigValue); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Create(KDefMeta1SingleMeta0Key, KIntOrigValue); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Create(KDefMeta1SingleMeta1Key, KIntOrigValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: // Make a dummy change in case the Delete/Create cancel each sl@0: // other, ending up with nothing to commit. sl@0: r = rep->Create(0xA5A5, KIntOrigValue); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::Pop(); // transaction sl@0: TUint32 keyInfo; sl@0: r = rep->CommitTransaction(keyInfo); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Delete(0xA5A5); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::PopAndDestroy(rep); sl@0: sl@0: TEST(VerifyMetaDataUnchangedL()); sl@0: } sl@0: sl@0: //=============================================== sl@0: void TMetadataTest::RunDeleteResetTestL() sl@0: { sl@0: TheTest.Next(_L("Metadata Delete-Reset settings test\r\n")); sl@0: sl@0: CRepository* rep = CRepository::NewLC(KUidTestRepository); sl@0: sl@0: TInt r; sl@0: r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TEST2(r, KErrNone); sl@0: rep->CleanupCancelTransactionPushL(); sl@0: sl@0: r = rep->Delete(KMissingSingleMetaKey); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Delete(KDefMeta0SingleMeta0Key); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Delete(KDefMeta0SingleMeta1Key); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Delete(KDefMeta1SingleMeta0Key); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Delete(KDefMeta1SingleMeta1Key); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::Pop(); // transaction sl@0: TUint32 keyInfo; sl@0: r = rep->CommitTransaction(keyInfo); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::PopAndDestroy(rep); sl@0: sl@0: // check if the delete's actually happened sl@0: rep = CRepository::NewLC(KUidTestRepository); sl@0: sl@0: TInt a; sl@0: r = rep->Get(KMissingSingleMetaKey, a); sl@0: TEST2(r, KErrNotFound); sl@0: r = rep->Get(KDefMeta0SingleMeta0Key, a); sl@0: TEST2(r, KErrNotFound); sl@0: r = rep->Get(KDefMeta0SingleMeta1Key, a); sl@0: TEST2(r, KErrNotFound); sl@0: r = rep->Get(KDefMeta1SingleMeta0Key, a); sl@0: TEST2(r, KErrNotFound); sl@0: r = rep->Get(KDefMeta1SingleMeta1Key, a); sl@0: TEST2(r, KErrNotFound); sl@0: sl@0: // Next Reset on each deleted key. sl@0: sl@0: // Transaction not available for Reset. sl@0: r = rep->Reset(KMissingSingleMetaKey); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Reset(KDefMeta0SingleMeta0Key); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Reset(KDefMeta0SingleMeta1Key); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Reset(KDefMeta1SingleMeta0Key); sl@0: TEST2(r, KErrNone); sl@0: r = rep->Reset(KDefMeta1SingleMeta1Key); sl@0: TEST2(r, KErrNone); sl@0: sl@0: CleanupStack::PopAndDestroy(rep); sl@0: sl@0: TEST(VerifyMetaDataUnchangedL()); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-1717 sl@0: @SYMTestCaseDesc Test Set, Delete, Create and Reset on a key with meta of 0 while defaultmeta is non-zero. sl@0: @SYMTestPriority High sl@0: @SYMTestActions 1. Do a Set. Verify meta does not change. 2. Delete and Create the key. Verify the non-zero defaultmeta is used. 3. Delete and Reset the key. Verify meta is zero. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMDEF INC086298 sl@0: */ sl@0: LOCAL_C void INC086298L() sl@0: { sl@0: TheTest.Printf(_L("INC086298 - Setting with no backup meta value is backed up\r\n")); sl@0: sl@0: TMetadataTest metaDataTester; sl@0: metaDataTester.InitialiseL(); sl@0: sl@0: metaDataTester.RunBasicGetMetaTestsL(); sl@0: sl@0: TheTest.Printf( _L("Metadata tests on .txt file\r\n") ); sl@0: metaDataTester.RunTestsL(); sl@0: sl@0: TheTest.Printf( _L("Metadata tests on .cre file\r\n") ); sl@0: metaDataTester.InstallCreFileL(); sl@0: metaDataTester.RunTestsL(); sl@0: } sl@0: sl@0: LOCAL_C void MainL() sl@0: { sl@0: TheTest.Start( _L( " @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-1717 CentralRepository metadata test " ) ); sl@0: User::LeaveIfError(fs.Connect()); sl@0: sl@0: CleanupClosePushL(fs); sl@0: sl@0: INC086298L(); sl@0: sl@0: CleanupStack::PopAndDestroy(&fs); 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: sl@0: delete cleanup; sl@0: __UHEAP_MARKEND; sl@0: sl@0: return err; sl@0: }