os/persistentdata/persistentstorage/centralrepository/test/t_cenrep_meta.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/centralrepository/test/t_cenrep_meta.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,779 @@
     1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <e32test.h>
    1.20 +#include <f32file.h>
    1.21 +#include <centralrepository.h>
    1.22 +#include "t_cenrep_helper.h"
    1.23 +#include <e32debug.h>
    1.24 +
    1.25 +RTest TheTest(_L("Central Repository Settings Tests"));
    1.26 +RFs fs;
    1.27 +
    1.28 +const TUid KUidTestRepository = { 0x00000005 };
    1.29 +const TInt KIntOrigValue = 1;
    1.30 +const TUint32 KGlobalDefaultMeta = 0;
    1.31 +const TUint32 KRange2DefaultMeta = 2;
    1.32 +const TUint32 KMetaAtKeyPos24    = 4;
    1.33 +
    1.34 +const TUint32 KDefMeta0SingleMeta0Key = 0x1;
    1.35 +const TUint32 KDefMeta0SingleMeta1Key = 0x2;
    1.36 +const TUint32 KDefMeta1SingleMeta0Key = 0x10;
    1.37 +const TUint32 KDefMeta1SingleMeta1Key = 0x11;
    1.38 +const TUint32 KMissingSingleMetaKey   = 0x20;
    1.39 +
    1.40 +const TUint32 KPlatsecFailureKey      = 0x21;
    1.41 +
    1.42 +const TUint32 KRange2KeyWithMeta4     = 0x24;
    1.43 +
    1.44 +_LIT( KSrcTxaPath, "z:\\private\\10202BE9\\00000005.txa" );
    1.45 +_LIT( KSrcCacheIniPath, "z:\\private\\10202BE9\\centrepcache.ini9" );
    1.46 +
    1.47 +_LIT( KInstallTxtPath, "C:\\private\\10202BE9\\00000005.txt" );
    1.48 +_LIT( KInstallCrePath, "C:\\private\\10202BE9\\00000005.cre" );
    1.49 +_LIT( KPersistsCrePath, "C:\\private\\10202BE9\\persists\\00000005.cre" );
    1.50 +_LIT( KCacheIniPath, "C:\\private\\10202BE9\\centrep.ini" );
    1.51 +
    1.52 +
    1.53 +TPtrC metaTestFiles[] =
    1.54 +	{
    1.55 +	TPtrC(KInstallTxtPath),
    1.56 +	TPtrC(KInstallCrePath),
    1.57 +	TPtrC(KPersistsCrePath),
    1.58 +
    1.59 +	// This one last because we do not always delete it.
    1.60 +	TPtrC(KCacheIniPath)
    1.61 +    };
    1.62 +
    1.63 +const TInt KNumMetaTestFiles = sizeof(metaTestFiles) / sizeof(TPtrC);
    1.64 +
    1.65 +_LIT( KCentralRepositoryServerName, "Centralrepositorysrv");
    1.66 +
    1.67 +//===========================================================
    1.68 +// Test macroses and functions
    1.69 +//===========================================================
    1.70 +
    1.71 +LOCAL_C TInt DeleteFile(const TDesC& aFileName, CFileMan& aFileMan)
    1.72 +	{
    1.73 +	TInt r = aFileMan.Delete( aFileName );
    1.74 +	if ( r != KErrNone && r != KErrNotFound && r != KErrPathNotFound )
    1.75 +		{
    1.76 +		return r;
    1.77 +		}
    1.78 +	return KErrNone;
    1.79 +	}
    1.80 +
    1.81 +LOCAL_C TInt DeleteFilesL(TPtrC aFileList[], TInt aNumFiles)
    1.82 +	{
    1.83 +	CFileMan* fm = CFileMan::NewL(fs);
    1.84 +	CleanupStack::PushL( fm );
    1.85 +
    1.86 +	TInt ret = KErrNone;
    1.87 +	for (TInt i = 0; i < aNumFiles; i++)
    1.88 +		{
    1.89 +		TInt r = DeleteFile( aFileList[i], *fm );
    1.90 +		if (r != KErrNone)
    1.91 +			{
    1.92 +			ret = r;
    1.93 +			}
    1.94 +		}
    1.95 +	CleanupStack::PopAndDestroy( fm );
    1.96 +	return ret;
    1.97 +	}
    1.98 +
    1.99 +LOCAL_C void TestCleanupL()
   1.100 +    {
   1.101 +    DeleteFilesL(metaTestFiles, KNumMetaTestFiles);
   1.102 +    KillProcess(KCentralRepositoryServerName);
   1.103 +    }
   1.104 +
   1.105 +LOCAL_C void CheckL( TInt aValue, TInt aLine )
   1.106 +	{
   1.107 +	if ( !aValue )
   1.108 +		{
   1.109 +		TestCleanupL();
   1.110 +		TheTest( EFalse, aLine );
   1.111 +		}
   1.112 +	}
   1.113 +
   1.114 +LOCAL_C void CheckL( TInt aValue, TInt aExpected, TInt aLine )
   1.115 +	{
   1.116 +	if ( aValue != aExpected )
   1.117 +		{
   1.118 +		TheTest.Printf( _L( "*** Expected value: %d, got: %d\r\n"), aExpected, aValue );
   1.119 +		TestCleanupL();
   1.120 +		TheTest( EFalse, aLine );
   1.121 +		}
   1.122 +	}
   1.123 +
   1.124 +#define TEST(arg) ::CheckL((arg), __LINE__)
   1.125 +#define TEST2(aValue, aExpected) ::CheckL(aValue, aExpected, __LINE__)
   1.126 +
   1.127 +LOCAL_C void CopyFileL(const TDesC& aSrc,
   1.128 +					   const TDesC& aDest,
   1.129 +					   TBool aClearROAttrib)
   1.130 +	{
   1.131 +	CFileMan* fm = CFileMan::NewL( fs );
   1.132 +	CleanupStack::PushL( fm );
   1.133 +
   1.134 +	TInt ret = fm->Copy(aSrc, aDest);
   1.135 +	if (aClearROAttrib && (ret == KErrNone))
   1.136 +		{
   1.137 +		ret = fm->Attribs( aDest, KEntryAttArchive, KEntryAttReadOnly, TTime( 0 ), CFileMan::ERecurse );
   1.138 +		}
   1.139 +
   1.140 +	User::LeaveIfError(ret);
   1.141 +
   1.142 +	CleanupStack::PopAndDestroy( fm );
   1.143 +	}
   1.144 +
   1.145 +//=============================================================
   1.146 +// class to encapsulate metadata test
   1.147 +class TMetadataTest
   1.148 +	{
   1.149 +public:
   1.150 +	inline TMetadataTest() {}
   1.151 +	~TMetadataTest();
   1.152 +	void InitialiseL();
   1.153 +	void InstallCreFileL();
   1.154 +	void RunTestsL();
   1.155 +	void RunSetTestL();
   1.156 +	void RunDeleteResetTestL();
   1.157 +	void RunDeleteCreateTestL();
   1.158 +	void RunDeleteCreateTest2L();
   1.159 +	void RunMoveTestL();
   1.160 +
   1.161 +	void RunBasicGetMetaTestsL();
   1.162 +
   1.163 +	TBool VerifyMetaDataUnchangedL();
   1.164 +	};
   1.165 +
   1.166 +//==========================================
   1.167 +TMetadataTest::~TMetadataTest()
   1.168 +	{
   1.169 +	TRAPD(err, ::TestCleanupL());
   1.170 +	if (err != KErrNone)
   1.171 +	    {
   1.172 +	    RDebug::Printf("err = %d in ~TMetadataTest.", err);
   1.173 +	    }
   1.174 +	}
   1.175 +
   1.176 +//==========================================
   1.177 +void TMetadataTest::InitialiseL()
   1.178 +	{
   1.179 +	::TestCleanupL();
   1.180 +	User::After(1000000); // pause after KillProcess
   1.181 +	::CopyFileL(KSrcTxaPath, KInstallTxtPath, ETrue);
   1.182 +	::CopyFileL(KSrcCacheIniPath, KCacheIniPath, ETrue);
   1.183 +	}
   1.184 +
   1.185 +//==========================================
   1.186 +void TMetadataTest::InstallCreFileL()
   1.187 +	{
   1.188 +	// Ensure start with original 00000005.txa file.
   1.189 +	// Be careful. Do not delete centrep.ini
   1.190 +	::DeleteFilesL(metaTestFiles, KNumMetaTestFiles - 1);
   1.191 +	::CopyFileL(KSrcTxaPath, KInstallTxtPath, ETrue);
   1.192 +
   1.193 +	CRepository* rep = CRepository::NewLC(KUidTestRepository);
   1.194 +
   1.195 +	// Create/Delete to persist the .txt to .cre
   1.196 +	TInt r = rep->Create(0xA5A5, 1);
   1.197 +	TEST2(r, KErrNone);
   1.198 +
   1.199 +	rep->Delete(0xA5A5);
   1.200 +	TEST2(r, KErrNone);
   1.201 +
   1.202 +	CleanupStack::PopAndDestroy(rep);
   1.203 +
   1.204 +	::CopyFileL(KPersistsCrePath, KInstallCrePath, EFalse);
   1.205 +
   1.206 +	TPtrC onefile[1] = { TPtrC(KPersistsCrePath) };
   1.207 +	::DeleteFilesL(onefile, 1);
   1.208 +	}
   1.209 +
   1.210 +//==========================================
   1.211 +void TMetadataTest::RunTestsL()
   1.212 +	{
   1.213 +	RunSetTestL();
   1.214 +	RunDeleteResetTestL();
   1.215 +	RunDeleteCreateTestL();
   1.216 +	RunDeleteCreateTest2L();
   1.217 +	RunMoveTestL();
   1.218 +	}
   1.219 +
   1.220 +//============================================
   1.221 +TBool TMetadataTest::VerifyMetaDataUnchangedL()
   1.222 +	{
   1.223 +	CRepository* rep = CRepository::NewLC(KUidTestRepository);
   1.224 +
   1.225 +	TInt ret = ETrue;
   1.226 +	TUint32 meta;
   1.227 +
   1.228 +	TInt r = rep->GetMeta(KMissingSingleMetaKey, meta);
   1.229 +	TEST2(r, KErrNone);
   1.230 +	if ( meta !=  KRange2DefaultMeta)
   1.231 +		{
   1.232 +		TheTest.Printf(_L("Key: 0x%x, meta is %d"), KMissingSingleMetaKey, meta);
   1.233 +		ret = EFalse;
   1.234 +		}
   1.235 +
   1.236 +	r = rep->GetMeta(KDefMeta0SingleMeta0Key, meta);
   1.237 +	TEST2(r, KErrNone);
   1.238 +	if ( meta !=  0)
   1.239 +		{
   1.240 +		TheTest.Printf(_L("Key: 0x%x, meta is %d"), KDefMeta0SingleMeta0Key, meta);
   1.241 +		ret = EFalse;
   1.242 +		}
   1.243 +
   1.244 +	r = rep->GetMeta(KDefMeta0SingleMeta1Key, meta);
   1.245 +	TEST2(r, KErrNone);
   1.246 +	if ( meta !=  1)
   1.247 +		{
   1.248 +		TheTest.Printf(_L("Key: 0x%x, meta is %d"), KDefMeta0SingleMeta1Key, meta);
   1.249 +		ret = EFalse;
   1.250 +		}
   1.251 +
   1.252 +	r = rep->GetMeta(KDefMeta1SingleMeta0Key, meta);
   1.253 +	TEST2(r, KErrNone);
   1.254 +	if ( meta !=  0)
   1.255 +		{
   1.256 +		TheTest.Printf(_L("Key: 0x%x, meta is %d"), KDefMeta1SingleMeta0Key, meta);
   1.257 +		ret = EFalse;
   1.258 +		}
   1.259 +
   1.260 +	r = rep->GetMeta(KDefMeta1SingleMeta1Key, meta);
   1.261 +	TEST2(r, KErrNone);
   1.262 +	if ( meta !=  1)
   1.263 +		{
   1.264 +		TheTest.Printf(_L("Key: 0x%x, meta is %d"), KDefMeta1SingleMeta1Key, meta);
   1.265 +		ret = EFalse;
   1.266 +		}
   1.267 +
   1.268 +	CleanupStack::PopAndDestroy(rep);
   1.269 +	return ret;
   1.270 +	}
   1.271 +
   1.272 +//============================================
   1.273 +void TMetadataTest::RunBasicGetMetaTestsL()
   1.274 +	{
   1.275 +	TheTest.Next(_L("Basic functional tests on the GetMeta API\r\n"));
   1.276 +
   1.277 +	CRepository* rep = CRepository::NewLC(KUidTestRepository);
   1.278 +
   1.279 +	TUint32 meta;
   1.280 +
   1.281 +	// GetMeta on non-existing key.
   1.282 +	const TUint32 KNonExistingKey = 0xFACE;
   1.283 +	TInt r = rep->GetMeta(KNonExistingKey, meta);
   1.284 +	TEST2(r, KErrNotFound);
   1.285 +
   1.286 +	// Missing capability to read meta of following key.
   1.287 +	r = rep->GetMeta(KPlatsecFailureKey, meta);
   1.288 +	TEST2(r, KErrPermissionDenied);
   1.289 +
   1.290 +	// GetMeta in transaction
   1.291 +	r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   1.292 +	TEST2(r, KErrNone);
   1.293 +	rep->CleanupCancelTransactionPushL();
   1.294 +
   1.295 +	r = rep->Set(KMissingSingleMetaKey, KIntOrigValue+1);
   1.296 +	TEST2(r, KErrNone);
   1.297 +
   1.298 +	r = rep->GetMeta(KMissingSingleMetaKey, meta);
   1.299 +	TEST2(r, KErrNone);
   1.300 +	TEST2(meta, KRange2DefaultMeta);
   1.301 +
   1.302 +	CleanupStack::PopAndDestroy(); // cancel transaction
   1.303 +
   1.304 +	CleanupStack::PopAndDestroy(rep);
   1.305 +	}
   1.306 +
   1.307 +//============================================
   1.308 +void TMetadataTest::RunMoveTestL()
   1.309 +	{
   1.310 +	TheTest.Next(_L("Metadata Move settings test\r\n"));
   1.311 +
   1.312 +	const TUint32 KDefRangeKeyForCreate = 0x3A;
   1.313 +	const TUint32 KRange2KeyForCreate   = 0x2A;
   1.314 +	const TUint32 KDefRangeKeyForMove   = 0x3B;
   1.315 +	const TUint32 KRange2KeyForMove     = 0x2B;
   1.316 +
   1.317 +	CRepository* rep = CRepository::NewLC(KUidTestRepository);
   1.318 +
   1.319 +	TInt r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   1.320 +	TEST2(r, KErrNone);
   1.321 +	rep->CleanupCancelTransactionPushL();
   1.322 +
   1.323 +	r = rep->Create(KDefRangeKeyForCreate, KIntOrigValue);
   1.324 +	TEST2(r, KErrNone);
   1.325 +
   1.326 +	r = rep->Create(KRange2KeyForCreate, KIntOrigValue);
   1.327 +	TEST2(r, KErrNone);
   1.328 +
   1.329 +	CleanupStack::Pop(); // transaction
   1.330 +	TUint32 errKey;
   1.331 +	r = rep->CommitTransaction(errKey);
   1.332 +	TEST2(r, KErrNone);
   1.333 +
   1.334 +	// Check that the keys are created with correct meta
   1.335 +
   1.336 +	TUint32 meta;
   1.337 +	// This key is not covered by any rangemeta. The global
   1.338 +	// default meta should be used.
   1.339 +	r = rep->GetMeta(KDefRangeKeyForCreate, meta);
   1.340 +	TEST2(r, KErrNone);
   1.341 +	TEST2(meta, KGlobalDefaultMeta);
   1.342 +
   1.343 +	// This key is covered by a rangemeta.
   1.344 +	r = rep->GetMeta(KRange2KeyForCreate, meta);
   1.345 +	TEST2(r, KErrNone);
   1.346 +	TEST2(meta, KRange2DefaultMeta);
   1.347 +
   1.348 +	// move the created keys to different ranges
   1.349 +	r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   1.350 +	TEST2(r, KErrNone);
   1.351 +	rep->CleanupCancelTransactionPushL();
   1.352 +
   1.353 +	const TUint32 KMoveMask = 0x3F;
   1.354 +	r = rep->Move(KDefRangeKeyForCreate, KRange2KeyForMove, KMoveMask,
   1.355 +			errKey);
   1.356 +	TEST2(r, KErrNone);
   1.357 +
   1.358 +	r = rep->Move(KRange2KeyForCreate, KDefRangeKeyForMove, KMoveMask,
   1.359 +			errKey);
   1.360 +	TEST2(r, KErrNone);
   1.361 +
   1.362 +	CleanupStack::Pop(); // transaction
   1.363 +	r = rep->CommitTransaction(errKey);
   1.364 +	TEST2(r, KErrNone);
   1.365 +
   1.366 +	// This key is moved from range where rangemeta is 2 to range
   1.367 +	// where meta is defined by the global default meta.
   1.368 +	r = rep->GetMeta(KDefRangeKeyForMove, meta);
   1.369 +	TEST2(r, KErrNone);
   1.370 +	TEST2(meta, KGlobalDefaultMeta);
   1.371 +
   1.372 +	// This key is moved from range where meta is defined by the
   1.373 +	// global default meta to a range where rangemeta is 2.
   1.374 +	r = rep->GetMeta(KRange2KeyForMove, meta);
   1.375 +	TEST2(r, KErrNone);
   1.376 +	TEST2(meta, KRange2DefaultMeta);
   1.377 +
   1.378 +
   1.379 +	// Test Move a key to a position which has just been deleted but
   1.380 +	// not yet commited.
   1.381 +
   1.382 +	// Create two keys to be moved. To save typing, no transaction.
   1.383 +	r = rep->Create(KDefRangeKeyForCreate, KIntOrigValue);
   1.384 +	TEST2(r, KErrNone);
   1.385 +	r = rep->Create(KRange2KeyForCreate, KIntOrigValue);
   1.386 +	TEST2(r, KErrNone);
   1.387 +
   1.388 +	r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   1.389 +	TEST2(r, KErrNone);
   1.390 +	rep->CleanupCancelTransactionPushL();
   1.391 +
   1.392 +	// delete the targeted keys but do not commit
   1.393 +	r = rep->Delete(KDefRangeKeyForMove);
   1.394 +	TEST2(r, KErrNone);
   1.395 +	r = rep->Delete(KRange2KeyForMove);
   1.396 +	TEST2(r, KErrNone);
   1.397 +
   1.398 +	// move the created keys to target positions
   1.399 +	r = rep->Move(KDefRangeKeyForCreate, KRange2KeyForMove, KMoveMask,
   1.400 +			errKey);
   1.401 +	TEST2(r, KErrNone);
   1.402 +	r = rep->Move(KRange2KeyForCreate, KDefRangeKeyForMove, KMoveMask,
   1.403 +			errKey);
   1.404 +	TEST2(r, KErrNone);
   1.405 +
   1.406 +	CleanupStack::Pop(); // transaction
   1.407 +	r = rep->CommitTransaction(errKey);
   1.408 +	TEST2(r, KErrNone);
   1.409 +
   1.410 +
   1.411 +	// This key is moved from range where rangemeta is 2 to range
   1.412 +	// where meta is defined by the global default meta.
   1.413 +	r = rep->GetMeta(KDefRangeKeyForMove, meta);
   1.414 +	TEST2(r, KErrNone);
   1.415 +	TEST2(meta, KGlobalDefaultMeta);
   1.416 +
   1.417 +	// This key is moved from range where meta is defined by the
   1.418 +	// global default meta to a range where rangemeta is 2.
   1.419 +	r = rep->GetMeta(KRange2KeyForMove, meta);
   1.420 +	TEST2(r, KErrNone);
   1.421 +	TEST2(meta, KRange2DefaultMeta);
   1.422 +
   1.423 +	// Test Move a key to a position which has a setting defined
   1.424 +	// in the INI file. The metadata of this pre-existing key
   1.425 +	// is permanently attached to that key position and takes
   1.426 +	// precedent over defaultmeta.
   1.427 +
   1.428 +	// Create the setting to be moved.
   1.429 +	r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   1.430 +	TEST2(r, KErrNone);
   1.431 +	rep->CleanupCancelTransactionPushL();
   1.432 +
   1.433 +	r = rep->Create(KRange2KeyForCreate, KIntOrigValue);
   1.434 +	TEST2(r, KErrNone);
   1.435 +
   1.436 +	// delete the key occuping the destination of the move.
   1.437 +	r = rep->Delete(KRange2KeyWithMeta4);
   1.438 +	TEST2(r, KErrNone);
   1.439 +
   1.440 +	CleanupStack::Pop(); // transaction
   1.441 +	r = rep->CommitTransaction(errKey);
   1.442 +	TEST2(r, KErrNone);
   1.443 +
   1.444 +	// Verify target has been deleted.
   1.445 +	TInt a;
   1.446 +	r = rep->Get(KRange2KeyWithMeta4, a);
   1.447 +	TEST2(r, KErrNotFound);
   1.448 +
   1.449 +	// move the created keys to target positions
   1.450 +	r = rep->Move(KRange2KeyForCreate, KRange2KeyWithMeta4, KMoveMask,
   1.451 +			errKey);
   1.452 +	TEST2(r, KErrNone);
   1.453 +
   1.454 +	// This key is moved within range where rangemeta is 2.
   1.455 +	// Target position of the Move has a setting defined
   1.456 +	// in the INI file. The metadata of this pre-existing key
   1.457 +	// is permanently attached to that key position and takes
   1.458 +	// precedent over the rangemeta.
   1.459 +	r = rep->GetMeta(KRange2KeyWithMeta4, meta);
   1.460 +	TEST2(r, KErrNone);
   1.461 +	TEST2(meta, KMetaAtKeyPos24);
   1.462 +
   1.463 +	// cleanup
   1.464 +	r = rep->Reset();
   1.465 +	TEST2(r, KErrNone);
   1.466 +
   1.467 +	CleanupStack::PopAndDestroy(rep);
   1.468 +	}
   1.469 +
   1.470 +//============================================
   1.471 +void TMetadataTest::RunSetTestL()
   1.472 +	{
   1.473 +	TheTest.Next(_L("Metadata Set settings test\r\n"));
   1.474 +
   1.475 +	CRepository* rep = CRepository::NewLC(KUidTestRepository);
   1.476 +
   1.477 +	TInt r;
   1.478 +	r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   1.479 +	TEST2(r, KErrNone);
   1.480 +	rep->CleanupCancelTransactionPushL();
   1.481 +
   1.482 +	const TInt KNewValue = KIntOrigValue + 1;
   1.483 +	r = rep->Set(KMissingSingleMetaKey, KNewValue);
   1.484 +	TEST2(r, KErrNone);
   1.485 +	r = rep->Set(KDefMeta0SingleMeta0Key, KNewValue);
   1.486 +	TEST2(r, KErrNone);
   1.487 +	r = rep->Set(KDefMeta0SingleMeta1Key, KNewValue);
   1.488 +	TEST2(r, KErrNone);
   1.489 +	r = rep->Set(KDefMeta1SingleMeta0Key, KNewValue);
   1.490 +	TEST2(r, KErrNone);
   1.491 +	r = rep->Set(KDefMeta1SingleMeta1Key, KNewValue);
   1.492 +	TEST2(r, KErrNone);
   1.493 +
   1.494 +	CleanupStack::Pop(); // transaction
   1.495 +	TUint32 keyInfo;
   1.496 +	r = rep->CommitTransaction(keyInfo);
   1.497 +	TEST2(r, KErrNone);
   1.498 +
   1.499 +	// check that the Set has changed the settings.
   1.500 +	TInt a;
   1.501 +	r = rep->Get(KMissingSingleMetaKey, a);
   1.502 +	TEST2(r, KErrNone);
   1.503 +	TEST2(a, KNewValue);
   1.504 +
   1.505 +	r = rep->Get(KDefMeta0SingleMeta0Key, a);
   1.506 +	TEST2(r, KErrNone);
   1.507 +	TEST2(a, KNewValue);
   1.508 +
   1.509 +	r = rep->Get(KDefMeta0SingleMeta1Key, a);
   1.510 +	TEST2(r, KErrNone);
   1.511 +	TEST2(a, KNewValue);
   1.512 +
   1.513 +	r = rep->Get(KDefMeta1SingleMeta0Key, a);
   1.514 +	TEST2(r, KErrNone);
   1.515 +	TEST2(a, KNewValue);
   1.516 +
   1.517 +	r = rep->Get(KDefMeta1SingleMeta1Key, a);
   1.518 +	TEST2(r, KErrNone);
   1.519 +	TEST2(a, KNewValue);
   1.520 +
   1.521 +	// Check the Set's have not change the metadata
   1.522 +	TEST(VerifyMetaDataUnchangedL());
   1.523 +
   1.524 +	// Take this opportunity to Reset the keys to exercise the
   1.525 +	// Set-then-Reset path.
   1.526 +
   1.527 +	// Transaction not available for Reset.
   1.528 +	r = rep->Reset(KMissingSingleMetaKey);
   1.529 +	TEST2(r, KErrNone);
   1.530 +	r = rep->Reset(KDefMeta0SingleMeta0Key);
   1.531 +	TEST2(r, KErrNone);
   1.532 +	r = rep->Reset(KDefMeta0SingleMeta1Key);
   1.533 +	TEST2(r, KErrNone);
   1.534 +	r = rep->Reset(KDefMeta1SingleMeta0Key);
   1.535 +	TEST2(r, KErrNone);
   1.536 +	r = rep->Reset(KDefMeta1SingleMeta1Key);
   1.537 +	TEST2(r, KErrNone);
   1.538 +
   1.539 +	CleanupStack::PopAndDestroy(rep);
   1.540 +
   1.541 +	TEST(VerifyMetaDataUnchangedL());
   1.542 +	}
   1.543 +
   1.544 +void TMetadataTest::RunDeleteCreateTestL()
   1.545 +	{
   1.546 +	TheTest.Next(_L("Metadata Delete-Create settings test\r\n"));
   1.547 +
   1.548 +	CRepository* rep = CRepository::NewLC(KUidTestRepository);
   1.549 +
   1.550 +	TInt r;
   1.551 +	r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   1.552 +	TEST2(r, KErrNone);
   1.553 +	rep->CleanupCancelTransactionPushL();
   1.554 +
   1.555 +	r = rep->Delete(KMissingSingleMetaKey);
   1.556 +	TEST2(r, KErrNone);
   1.557 +	r = rep->Delete(KDefMeta0SingleMeta0Key);
   1.558 +	TEST2(r, KErrNone);
   1.559 +	r = rep->Delete(KDefMeta0SingleMeta1Key);
   1.560 +	TEST2(r, KErrNone);
   1.561 +	r = rep->Delete(KDefMeta1SingleMeta0Key);
   1.562 +	TEST2(r, KErrNone);
   1.563 +	r = rep->Delete(KDefMeta1SingleMeta1Key);
   1.564 +	TEST2(r, KErrNone);
   1.565 +
   1.566 +	CleanupStack::Pop(); // transaction
   1.567 +	TUint32 keyInfo;
   1.568 +	r = rep->CommitTransaction(keyInfo);
   1.569 +	TEST2(r, KErrNone);
   1.570 +
   1.571 +	CleanupStack::PopAndDestroy(rep);
   1.572 +
   1.573 +	// Now open the repository again and create the deleted keys.
   1.574 +	rep = CRepository::NewLC(KUidTestRepository);
   1.575 +
   1.576 +	// Before Create, check if the Delete's actually happened.
   1.577 +	TInt a;
   1.578 +	r = rep->Get(KMissingSingleMetaKey, a);
   1.579 +	TEST2(r, KErrNotFound);
   1.580 +	r = rep->Get(KDefMeta0SingleMeta0Key, a);
   1.581 +	TEST2(r, KErrNotFound);
   1.582 +	r = rep->Get(KDefMeta0SingleMeta1Key, a);
   1.583 +	TEST2(r, KErrNotFound);
   1.584 +	r = rep->Get(KDefMeta1SingleMeta0Key, a);
   1.585 +	TEST2(r, KErrNotFound);
   1.586 +	r = rep->Get(KDefMeta1SingleMeta1Key, a);
   1.587 +	TEST2(r, KErrNotFound);
   1.588 +
   1.589 +	r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   1.590 +	TEST2(r, KErrNone);
   1.591 +	rep->CleanupCancelTransactionPushL();
   1.592 +
   1.593 +	r = rep->Create(KMissingSingleMetaKey, KIntOrigValue);
   1.594 +	TEST2(r, KErrNone);
   1.595 +	r = rep->Create(KDefMeta0SingleMeta0Key, KIntOrigValue);
   1.596 +	TEST2(r, KErrNone);
   1.597 +	r = rep->Create(KDefMeta0SingleMeta1Key, KIntOrigValue);
   1.598 +	TEST2(r, KErrNone);
   1.599 +	r = rep->Create(KDefMeta1SingleMeta0Key, KIntOrigValue);
   1.600 +	TEST2(r, KErrNone);
   1.601 +	r = rep->Create(KDefMeta1SingleMeta1Key, KIntOrigValue);
   1.602 +	TEST2(r, KErrNone);
   1.603 +
   1.604 +	CleanupStack::Pop(); // transaction
   1.605 +	r = rep->CommitTransaction(keyInfo);
   1.606 +	TEST2(r, KErrNone);
   1.607 +
   1.608 +	CleanupStack::PopAndDestroy(rep);
   1.609 +
   1.610 +	TEST(VerifyMetaDataUnchangedL());
   1.611 +	}
   1.612 +
   1.613 +//=================================================
   1.614 +void TMetadataTest::RunDeleteCreateTest2L()
   1.615 +	{
   1.616 +	TheTest.Next(_L("Metadata Delete-Create settings (uncommitted) test\r\n"));
   1.617 +
   1.618 +	CRepository* rep = CRepository::NewLC(KUidTestRepository);
   1.619 +
   1.620 +	TInt r;
   1.621 +	r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   1.622 +	TEST2(r, KErrNone);
   1.623 +	rep->CleanupCancelTransactionPushL();
   1.624 +
   1.625 +	r = rep->Delete(KMissingSingleMetaKey);
   1.626 +	TEST2(r, KErrNone);
   1.627 +	r = rep->Delete(KDefMeta0SingleMeta0Key);
   1.628 +	TEST2(r, KErrNone);
   1.629 +	r = rep->Delete(KDefMeta0SingleMeta1Key);
   1.630 +	TEST2(r, KErrNone);
   1.631 +	r = rep->Delete(KDefMeta1SingleMeta0Key);
   1.632 +	TEST2(r, KErrNone);
   1.633 +	r = rep->Delete(KDefMeta1SingleMeta1Key);
   1.634 +	TEST2(r, KErrNone);
   1.635 +
   1.636 +	// Next Create while Delete still in transaction.
   1.637 +	r = rep->Create(KMissingSingleMetaKey, KIntOrigValue);
   1.638 +	TEST2(r, KErrNone);
   1.639 +	r = rep->Create(KDefMeta0SingleMeta0Key, KIntOrigValue);
   1.640 +	TEST2(r, KErrNone);
   1.641 +	r = rep->Create(KDefMeta0SingleMeta1Key, KIntOrigValue);
   1.642 +	TEST2(r, KErrNone);
   1.643 +	r = rep->Create(KDefMeta1SingleMeta0Key, KIntOrigValue);
   1.644 +	TEST2(r, KErrNone);
   1.645 +	r = rep->Create(KDefMeta1SingleMeta1Key, KIntOrigValue);
   1.646 +	TEST2(r, KErrNone);
   1.647 +
   1.648 +	// Make a dummy change in case the Delete/Create cancel each
   1.649 +	// other, ending up with nothing to commit.
   1.650 +	r = rep->Create(0xA5A5, KIntOrigValue);
   1.651 +	TEST2(r, KErrNone);
   1.652 +
   1.653 +	CleanupStack::Pop(); // transaction
   1.654 +	TUint32 keyInfo;
   1.655 +	r = rep->CommitTransaction(keyInfo);
   1.656 +	TEST2(r, KErrNone);
   1.657 +	r = rep->Delete(0xA5A5);
   1.658 +	TEST2(r, KErrNone);
   1.659 +
   1.660 +	CleanupStack::PopAndDestroy(rep);
   1.661 +
   1.662 +	TEST(VerifyMetaDataUnchangedL());
   1.663 +	}
   1.664 +
   1.665 +//===============================================
   1.666 +void TMetadataTest::RunDeleteResetTestL()
   1.667 +	{
   1.668 +	TheTest.Next(_L("Metadata Delete-Reset settings test\r\n"));
   1.669 +
   1.670 +	CRepository* rep = CRepository::NewLC(KUidTestRepository);
   1.671 +
   1.672 +	TInt r;
   1.673 +	r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   1.674 +	TEST2(r, KErrNone);
   1.675 +	rep->CleanupCancelTransactionPushL();
   1.676 +
   1.677 +	r = rep->Delete(KMissingSingleMetaKey);
   1.678 +	TEST2(r, KErrNone);
   1.679 +	r = rep->Delete(KDefMeta0SingleMeta0Key);
   1.680 +	TEST2(r, KErrNone);
   1.681 +	r = rep->Delete(KDefMeta0SingleMeta1Key);
   1.682 +	TEST2(r, KErrNone);
   1.683 +	r = rep->Delete(KDefMeta1SingleMeta0Key);
   1.684 +	TEST2(r, KErrNone);
   1.685 +	r = rep->Delete(KDefMeta1SingleMeta1Key);
   1.686 +	TEST2(r, KErrNone);
   1.687 +
   1.688 +	CleanupStack::Pop(); // transaction
   1.689 +	TUint32 keyInfo;
   1.690 +	r = rep->CommitTransaction(keyInfo);
   1.691 +	TEST2(r, KErrNone);
   1.692 +
   1.693 +	CleanupStack::PopAndDestroy(rep);
   1.694 +
   1.695 +	// check if the delete's actually happened
   1.696 +	rep = CRepository::NewLC(KUidTestRepository);
   1.697 +
   1.698 +	TInt a;
   1.699 +	r = rep->Get(KMissingSingleMetaKey, a);
   1.700 +	TEST2(r, KErrNotFound);
   1.701 +	r = rep->Get(KDefMeta0SingleMeta0Key, a);
   1.702 +	TEST2(r, KErrNotFound);
   1.703 +	r = rep->Get(KDefMeta0SingleMeta1Key, a);
   1.704 +	TEST2(r, KErrNotFound);
   1.705 +	r = rep->Get(KDefMeta1SingleMeta0Key, a);
   1.706 +	TEST2(r, KErrNotFound);
   1.707 +	r = rep->Get(KDefMeta1SingleMeta1Key, a);
   1.708 +	TEST2(r, KErrNotFound);
   1.709 +
   1.710 +	// Next Reset on each deleted key.
   1.711 +
   1.712 +	// Transaction not available for Reset.
   1.713 +	r = rep->Reset(KMissingSingleMetaKey);
   1.714 +	TEST2(r, KErrNone);
   1.715 +	r = rep->Reset(KDefMeta0SingleMeta0Key);
   1.716 +	TEST2(r, KErrNone);
   1.717 +	r = rep->Reset(KDefMeta0SingleMeta1Key);
   1.718 +	TEST2(r, KErrNone);
   1.719 +	r = rep->Reset(KDefMeta1SingleMeta0Key);
   1.720 +	TEST2(r, KErrNone);
   1.721 +	r = rep->Reset(KDefMeta1SingleMeta1Key);
   1.722 +	TEST2(r, KErrNone);
   1.723 +
   1.724 +	CleanupStack::PopAndDestroy(rep);
   1.725 +
   1.726 +	TEST(VerifyMetaDataUnchangedL());
   1.727 +	}
   1.728 +
   1.729 +/**
   1.730 +@SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-1717
   1.731 +@SYMTestCaseDesc Test Set, Delete, Create and Reset on a key with meta of 0 while defaultmeta is non-zero.
   1.732 +@SYMTestPriority High
   1.733 +@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.
   1.734 +@SYMTestExpectedResults The test must not fail.
   1.735 +@SYMDEF INC086298
   1.736 +*/
   1.737 +LOCAL_C void INC086298L()
   1.738 +	{
   1.739 +	TheTest.Printf(_L("INC086298 - Setting with no backup meta value is backed up\r\n"));
   1.740 +
   1.741 +	TMetadataTest metaDataTester;
   1.742 +	metaDataTester.InitialiseL();
   1.743 +
   1.744 +	metaDataTester.RunBasicGetMetaTestsL();
   1.745 +
   1.746 +	TheTest.Printf( _L("Metadata tests on .txt file\r\n") );
   1.747 +	metaDataTester.RunTestsL();
   1.748 +
   1.749 +	TheTest.Printf( _L("Metadata tests on .cre file\r\n") );
   1.750 +	metaDataTester.InstallCreFileL();
   1.751 +	metaDataTester.RunTestsL();
   1.752 +	}
   1.753 +
   1.754 +LOCAL_C void MainL()
   1.755 +	{
   1.756 +	TheTest.Start( _L( " @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-1717 CentralRepository metadata test " ) );
   1.757 +	User::LeaveIfError(fs.Connect());
   1.758 +
   1.759 +	CleanupClosePushL(fs);
   1.760 +
   1.761 +    INC086298L();
   1.762 +
   1.763 +	CleanupStack::PopAndDestroy(&fs);
   1.764 +
   1.765 +	TheTest.End();
   1.766 +	TheTest.Close();
   1.767 +	}
   1.768 +
   1.769 +TInt E32Main()
   1.770 +	{
   1.771 +	__UHEAP_MARK;
   1.772 +	CTrapCleanup* cleanup = CTrapCleanup::New();
   1.773 +	if ( !cleanup )
   1.774 +		return KErrNoMemory;
   1.775 +
   1.776 +	TRAPD( err, MainL()  );
   1.777 +
   1.778 +	delete cleanup;
   1.779 +	__UHEAP_MARKEND;
   1.780 +
   1.781 +	return err;
   1.782 +	}