os/persistentdata/persistentstorage/centralrepository/test/t_cenrep_meta.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include <e32test.h>
    17 #include <f32file.h>
    18 #include <centralrepository.h>
    19 #include "t_cenrep_helper.h"
    20 #include <e32debug.h>
    21 
    22 RTest TheTest(_L("Central Repository Settings Tests"));
    23 RFs fs;
    24 
    25 const TUid KUidTestRepository = { 0x00000005 };
    26 const TInt KIntOrigValue = 1;
    27 const TUint32 KGlobalDefaultMeta = 0;
    28 const TUint32 KRange2DefaultMeta = 2;
    29 const TUint32 KMetaAtKeyPos24    = 4;
    30 
    31 const TUint32 KDefMeta0SingleMeta0Key = 0x1;
    32 const TUint32 KDefMeta0SingleMeta1Key = 0x2;
    33 const TUint32 KDefMeta1SingleMeta0Key = 0x10;
    34 const TUint32 KDefMeta1SingleMeta1Key = 0x11;
    35 const TUint32 KMissingSingleMetaKey   = 0x20;
    36 
    37 const TUint32 KPlatsecFailureKey      = 0x21;
    38 
    39 const TUint32 KRange2KeyWithMeta4     = 0x24;
    40 
    41 _LIT( KSrcTxaPath, "z:\\private\\10202BE9\\00000005.txa" );
    42 _LIT( KSrcCacheIniPath, "z:\\private\\10202BE9\\centrepcache.ini9" );
    43 
    44 _LIT( KInstallTxtPath, "C:\\private\\10202BE9\\00000005.txt" );
    45 _LIT( KInstallCrePath, "C:\\private\\10202BE9\\00000005.cre" );
    46 _LIT( KPersistsCrePath, "C:\\private\\10202BE9\\persists\\00000005.cre" );
    47 _LIT( KCacheIniPath, "C:\\private\\10202BE9\\centrep.ini" );
    48 
    49 
    50 TPtrC metaTestFiles[] =
    51 	{
    52 	TPtrC(KInstallTxtPath),
    53 	TPtrC(KInstallCrePath),
    54 	TPtrC(KPersistsCrePath),
    55 
    56 	// This one last because we do not always delete it.
    57 	TPtrC(KCacheIniPath)
    58     };
    59 
    60 const TInt KNumMetaTestFiles = sizeof(metaTestFiles) / sizeof(TPtrC);
    61 
    62 _LIT( KCentralRepositoryServerName, "Centralrepositorysrv");
    63 
    64 //===========================================================
    65 // Test macroses and functions
    66 //===========================================================
    67 
    68 LOCAL_C TInt DeleteFile(const TDesC& aFileName, CFileMan& aFileMan)
    69 	{
    70 	TInt r = aFileMan.Delete( aFileName );
    71 	if ( r != KErrNone && r != KErrNotFound && r != KErrPathNotFound )
    72 		{
    73 		return r;
    74 		}
    75 	return KErrNone;
    76 	}
    77 
    78 LOCAL_C TInt DeleteFilesL(TPtrC aFileList[], TInt aNumFiles)
    79 	{
    80 	CFileMan* fm = CFileMan::NewL(fs);
    81 	CleanupStack::PushL( fm );
    82 
    83 	TInt ret = KErrNone;
    84 	for (TInt i = 0; i < aNumFiles; i++)
    85 		{
    86 		TInt r = DeleteFile( aFileList[i], *fm );
    87 		if (r != KErrNone)
    88 			{
    89 			ret = r;
    90 			}
    91 		}
    92 	CleanupStack::PopAndDestroy( fm );
    93 	return ret;
    94 	}
    95 
    96 LOCAL_C void TestCleanupL()
    97     {
    98     DeleteFilesL(metaTestFiles, KNumMetaTestFiles);
    99     KillProcess(KCentralRepositoryServerName);
   100     }
   101 
   102 LOCAL_C void CheckL( TInt aValue, TInt aLine )
   103 	{
   104 	if ( !aValue )
   105 		{
   106 		TestCleanupL();
   107 		TheTest( EFalse, aLine );
   108 		}
   109 	}
   110 
   111 LOCAL_C void CheckL( TInt aValue, TInt aExpected, TInt aLine )
   112 	{
   113 	if ( aValue != aExpected )
   114 		{
   115 		TheTest.Printf( _L( "*** Expected value: %d, got: %d\r\n"), aExpected, aValue );
   116 		TestCleanupL();
   117 		TheTest( EFalse, aLine );
   118 		}
   119 	}
   120 
   121 #define TEST(arg) ::CheckL((arg), __LINE__)
   122 #define TEST2(aValue, aExpected) ::CheckL(aValue, aExpected, __LINE__)
   123 
   124 LOCAL_C void CopyFileL(const TDesC& aSrc,
   125 					   const TDesC& aDest,
   126 					   TBool aClearROAttrib)
   127 	{
   128 	CFileMan* fm = CFileMan::NewL( fs );
   129 	CleanupStack::PushL( fm );
   130 
   131 	TInt ret = fm->Copy(aSrc, aDest);
   132 	if (aClearROAttrib && (ret == KErrNone))
   133 		{
   134 		ret = fm->Attribs( aDest, KEntryAttArchive, KEntryAttReadOnly, TTime( 0 ), CFileMan::ERecurse );
   135 		}
   136 
   137 	User::LeaveIfError(ret);
   138 
   139 	CleanupStack::PopAndDestroy( fm );
   140 	}
   141 
   142 //=============================================================
   143 // class to encapsulate metadata test
   144 class TMetadataTest
   145 	{
   146 public:
   147 	inline TMetadataTest() {}
   148 	~TMetadataTest();
   149 	void InitialiseL();
   150 	void InstallCreFileL();
   151 	void RunTestsL();
   152 	void RunSetTestL();
   153 	void RunDeleteResetTestL();
   154 	void RunDeleteCreateTestL();
   155 	void RunDeleteCreateTest2L();
   156 	void RunMoveTestL();
   157 
   158 	void RunBasicGetMetaTestsL();
   159 
   160 	TBool VerifyMetaDataUnchangedL();
   161 	};
   162 
   163 //==========================================
   164 TMetadataTest::~TMetadataTest()
   165 	{
   166 	TRAPD(err, ::TestCleanupL());
   167 	if (err != KErrNone)
   168 	    {
   169 	    RDebug::Printf("err = %d in ~TMetadataTest.", err);
   170 	    }
   171 	}
   172 
   173 //==========================================
   174 void TMetadataTest::InitialiseL()
   175 	{
   176 	::TestCleanupL();
   177 	User::After(1000000); // pause after KillProcess
   178 	::CopyFileL(KSrcTxaPath, KInstallTxtPath, ETrue);
   179 	::CopyFileL(KSrcCacheIniPath, KCacheIniPath, ETrue);
   180 	}
   181 
   182 //==========================================
   183 void TMetadataTest::InstallCreFileL()
   184 	{
   185 	// Ensure start with original 00000005.txa file.
   186 	// Be careful. Do not delete centrep.ini
   187 	::DeleteFilesL(metaTestFiles, KNumMetaTestFiles - 1);
   188 	::CopyFileL(KSrcTxaPath, KInstallTxtPath, ETrue);
   189 
   190 	CRepository* rep = CRepository::NewLC(KUidTestRepository);
   191 
   192 	// Create/Delete to persist the .txt to .cre
   193 	TInt r = rep->Create(0xA5A5, 1);
   194 	TEST2(r, KErrNone);
   195 
   196 	rep->Delete(0xA5A5);
   197 	TEST2(r, KErrNone);
   198 
   199 	CleanupStack::PopAndDestroy(rep);
   200 
   201 	::CopyFileL(KPersistsCrePath, KInstallCrePath, EFalse);
   202 
   203 	TPtrC onefile[1] = { TPtrC(KPersistsCrePath) };
   204 	::DeleteFilesL(onefile, 1);
   205 	}
   206 
   207 //==========================================
   208 void TMetadataTest::RunTestsL()
   209 	{
   210 	RunSetTestL();
   211 	RunDeleteResetTestL();
   212 	RunDeleteCreateTestL();
   213 	RunDeleteCreateTest2L();
   214 	RunMoveTestL();
   215 	}
   216 
   217 //============================================
   218 TBool TMetadataTest::VerifyMetaDataUnchangedL()
   219 	{
   220 	CRepository* rep = CRepository::NewLC(KUidTestRepository);
   221 
   222 	TInt ret = ETrue;
   223 	TUint32 meta;
   224 
   225 	TInt r = rep->GetMeta(KMissingSingleMetaKey, meta);
   226 	TEST2(r, KErrNone);
   227 	if ( meta !=  KRange2DefaultMeta)
   228 		{
   229 		TheTest.Printf(_L("Key: 0x%x, meta is %d"), KMissingSingleMetaKey, meta);
   230 		ret = EFalse;
   231 		}
   232 
   233 	r = rep->GetMeta(KDefMeta0SingleMeta0Key, meta);
   234 	TEST2(r, KErrNone);
   235 	if ( meta !=  0)
   236 		{
   237 		TheTest.Printf(_L("Key: 0x%x, meta is %d"), KDefMeta0SingleMeta0Key, meta);
   238 		ret = EFalse;
   239 		}
   240 
   241 	r = rep->GetMeta(KDefMeta0SingleMeta1Key, meta);
   242 	TEST2(r, KErrNone);
   243 	if ( meta !=  1)
   244 		{
   245 		TheTest.Printf(_L("Key: 0x%x, meta is %d"), KDefMeta0SingleMeta1Key, meta);
   246 		ret = EFalse;
   247 		}
   248 
   249 	r = rep->GetMeta(KDefMeta1SingleMeta0Key, meta);
   250 	TEST2(r, KErrNone);
   251 	if ( meta !=  0)
   252 		{
   253 		TheTest.Printf(_L("Key: 0x%x, meta is %d"), KDefMeta1SingleMeta0Key, meta);
   254 		ret = EFalse;
   255 		}
   256 
   257 	r = rep->GetMeta(KDefMeta1SingleMeta1Key, meta);
   258 	TEST2(r, KErrNone);
   259 	if ( meta !=  1)
   260 		{
   261 		TheTest.Printf(_L("Key: 0x%x, meta is %d"), KDefMeta1SingleMeta1Key, meta);
   262 		ret = EFalse;
   263 		}
   264 
   265 	CleanupStack::PopAndDestroy(rep);
   266 	return ret;
   267 	}
   268 
   269 //============================================
   270 void TMetadataTest::RunBasicGetMetaTestsL()
   271 	{
   272 	TheTest.Next(_L("Basic functional tests on the GetMeta API\r\n"));
   273 
   274 	CRepository* rep = CRepository::NewLC(KUidTestRepository);
   275 
   276 	TUint32 meta;
   277 
   278 	// GetMeta on non-existing key.
   279 	const TUint32 KNonExistingKey = 0xFACE;
   280 	TInt r = rep->GetMeta(KNonExistingKey, meta);
   281 	TEST2(r, KErrNotFound);
   282 
   283 	// Missing capability to read meta of following key.
   284 	r = rep->GetMeta(KPlatsecFailureKey, meta);
   285 	TEST2(r, KErrPermissionDenied);
   286 
   287 	// GetMeta in transaction
   288 	r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   289 	TEST2(r, KErrNone);
   290 	rep->CleanupCancelTransactionPushL();
   291 
   292 	r = rep->Set(KMissingSingleMetaKey, KIntOrigValue+1);
   293 	TEST2(r, KErrNone);
   294 
   295 	r = rep->GetMeta(KMissingSingleMetaKey, meta);
   296 	TEST2(r, KErrNone);
   297 	TEST2(meta, KRange2DefaultMeta);
   298 
   299 	CleanupStack::PopAndDestroy(); // cancel transaction
   300 
   301 	CleanupStack::PopAndDestroy(rep);
   302 	}
   303 
   304 //============================================
   305 void TMetadataTest::RunMoveTestL()
   306 	{
   307 	TheTest.Next(_L("Metadata Move settings test\r\n"));
   308 
   309 	const TUint32 KDefRangeKeyForCreate = 0x3A;
   310 	const TUint32 KRange2KeyForCreate   = 0x2A;
   311 	const TUint32 KDefRangeKeyForMove   = 0x3B;
   312 	const TUint32 KRange2KeyForMove     = 0x2B;
   313 
   314 	CRepository* rep = CRepository::NewLC(KUidTestRepository);
   315 
   316 	TInt r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   317 	TEST2(r, KErrNone);
   318 	rep->CleanupCancelTransactionPushL();
   319 
   320 	r = rep->Create(KDefRangeKeyForCreate, KIntOrigValue);
   321 	TEST2(r, KErrNone);
   322 
   323 	r = rep->Create(KRange2KeyForCreate, KIntOrigValue);
   324 	TEST2(r, KErrNone);
   325 
   326 	CleanupStack::Pop(); // transaction
   327 	TUint32 errKey;
   328 	r = rep->CommitTransaction(errKey);
   329 	TEST2(r, KErrNone);
   330 
   331 	// Check that the keys are created with correct meta
   332 
   333 	TUint32 meta;
   334 	// This key is not covered by any rangemeta. The global
   335 	// default meta should be used.
   336 	r = rep->GetMeta(KDefRangeKeyForCreate, meta);
   337 	TEST2(r, KErrNone);
   338 	TEST2(meta, KGlobalDefaultMeta);
   339 
   340 	// This key is covered by a rangemeta.
   341 	r = rep->GetMeta(KRange2KeyForCreate, meta);
   342 	TEST2(r, KErrNone);
   343 	TEST2(meta, KRange2DefaultMeta);
   344 
   345 	// move the created keys to different ranges
   346 	r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   347 	TEST2(r, KErrNone);
   348 	rep->CleanupCancelTransactionPushL();
   349 
   350 	const TUint32 KMoveMask = 0x3F;
   351 	r = rep->Move(KDefRangeKeyForCreate, KRange2KeyForMove, KMoveMask,
   352 			errKey);
   353 	TEST2(r, KErrNone);
   354 
   355 	r = rep->Move(KRange2KeyForCreate, KDefRangeKeyForMove, KMoveMask,
   356 			errKey);
   357 	TEST2(r, KErrNone);
   358 
   359 	CleanupStack::Pop(); // transaction
   360 	r = rep->CommitTransaction(errKey);
   361 	TEST2(r, KErrNone);
   362 
   363 	// This key is moved from range where rangemeta is 2 to range
   364 	// where meta is defined by the global default meta.
   365 	r = rep->GetMeta(KDefRangeKeyForMove, meta);
   366 	TEST2(r, KErrNone);
   367 	TEST2(meta, KGlobalDefaultMeta);
   368 
   369 	// This key is moved from range where meta is defined by the
   370 	// global default meta to a range where rangemeta is 2.
   371 	r = rep->GetMeta(KRange2KeyForMove, meta);
   372 	TEST2(r, KErrNone);
   373 	TEST2(meta, KRange2DefaultMeta);
   374 
   375 
   376 	// Test Move a key to a position which has just been deleted but
   377 	// not yet commited.
   378 
   379 	// Create two keys to be moved. To save typing, no transaction.
   380 	r = rep->Create(KDefRangeKeyForCreate, KIntOrigValue);
   381 	TEST2(r, KErrNone);
   382 	r = rep->Create(KRange2KeyForCreate, KIntOrigValue);
   383 	TEST2(r, KErrNone);
   384 
   385 	r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   386 	TEST2(r, KErrNone);
   387 	rep->CleanupCancelTransactionPushL();
   388 
   389 	// delete the targeted keys but do not commit
   390 	r = rep->Delete(KDefRangeKeyForMove);
   391 	TEST2(r, KErrNone);
   392 	r = rep->Delete(KRange2KeyForMove);
   393 	TEST2(r, KErrNone);
   394 
   395 	// move the created keys to target positions
   396 	r = rep->Move(KDefRangeKeyForCreate, KRange2KeyForMove, KMoveMask,
   397 			errKey);
   398 	TEST2(r, KErrNone);
   399 	r = rep->Move(KRange2KeyForCreate, KDefRangeKeyForMove, KMoveMask,
   400 			errKey);
   401 	TEST2(r, KErrNone);
   402 
   403 	CleanupStack::Pop(); // transaction
   404 	r = rep->CommitTransaction(errKey);
   405 	TEST2(r, KErrNone);
   406 
   407 
   408 	// This key is moved from range where rangemeta is 2 to range
   409 	// where meta is defined by the global default meta.
   410 	r = rep->GetMeta(KDefRangeKeyForMove, meta);
   411 	TEST2(r, KErrNone);
   412 	TEST2(meta, KGlobalDefaultMeta);
   413 
   414 	// This key is moved from range where meta is defined by the
   415 	// global default meta to a range where rangemeta is 2.
   416 	r = rep->GetMeta(KRange2KeyForMove, meta);
   417 	TEST2(r, KErrNone);
   418 	TEST2(meta, KRange2DefaultMeta);
   419 
   420 	// Test Move a key to a position which has a setting defined
   421 	// in the INI file. The metadata of this pre-existing key
   422 	// is permanently attached to that key position and takes
   423 	// precedent over defaultmeta.
   424 
   425 	// Create the setting to be moved.
   426 	r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   427 	TEST2(r, KErrNone);
   428 	rep->CleanupCancelTransactionPushL();
   429 
   430 	r = rep->Create(KRange2KeyForCreate, KIntOrigValue);
   431 	TEST2(r, KErrNone);
   432 
   433 	// delete the key occuping the destination of the move.
   434 	r = rep->Delete(KRange2KeyWithMeta4);
   435 	TEST2(r, KErrNone);
   436 
   437 	CleanupStack::Pop(); // transaction
   438 	r = rep->CommitTransaction(errKey);
   439 	TEST2(r, KErrNone);
   440 
   441 	// Verify target has been deleted.
   442 	TInt a;
   443 	r = rep->Get(KRange2KeyWithMeta4, a);
   444 	TEST2(r, KErrNotFound);
   445 
   446 	// move the created keys to target positions
   447 	r = rep->Move(KRange2KeyForCreate, KRange2KeyWithMeta4, KMoveMask,
   448 			errKey);
   449 	TEST2(r, KErrNone);
   450 
   451 	// This key is moved within range where rangemeta is 2.
   452 	// Target position of the Move has a setting defined
   453 	// in the INI file. The metadata of this pre-existing key
   454 	// is permanently attached to that key position and takes
   455 	// precedent over the rangemeta.
   456 	r = rep->GetMeta(KRange2KeyWithMeta4, meta);
   457 	TEST2(r, KErrNone);
   458 	TEST2(meta, KMetaAtKeyPos24);
   459 
   460 	// cleanup
   461 	r = rep->Reset();
   462 	TEST2(r, KErrNone);
   463 
   464 	CleanupStack::PopAndDestroy(rep);
   465 	}
   466 
   467 //============================================
   468 void TMetadataTest::RunSetTestL()
   469 	{
   470 	TheTest.Next(_L("Metadata Set settings test\r\n"));
   471 
   472 	CRepository* rep = CRepository::NewLC(KUidTestRepository);
   473 
   474 	TInt r;
   475 	r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   476 	TEST2(r, KErrNone);
   477 	rep->CleanupCancelTransactionPushL();
   478 
   479 	const TInt KNewValue = KIntOrigValue + 1;
   480 	r = rep->Set(KMissingSingleMetaKey, KNewValue);
   481 	TEST2(r, KErrNone);
   482 	r = rep->Set(KDefMeta0SingleMeta0Key, KNewValue);
   483 	TEST2(r, KErrNone);
   484 	r = rep->Set(KDefMeta0SingleMeta1Key, KNewValue);
   485 	TEST2(r, KErrNone);
   486 	r = rep->Set(KDefMeta1SingleMeta0Key, KNewValue);
   487 	TEST2(r, KErrNone);
   488 	r = rep->Set(KDefMeta1SingleMeta1Key, KNewValue);
   489 	TEST2(r, KErrNone);
   490 
   491 	CleanupStack::Pop(); // transaction
   492 	TUint32 keyInfo;
   493 	r = rep->CommitTransaction(keyInfo);
   494 	TEST2(r, KErrNone);
   495 
   496 	// check that the Set has changed the settings.
   497 	TInt a;
   498 	r = rep->Get(KMissingSingleMetaKey, a);
   499 	TEST2(r, KErrNone);
   500 	TEST2(a, KNewValue);
   501 
   502 	r = rep->Get(KDefMeta0SingleMeta0Key, a);
   503 	TEST2(r, KErrNone);
   504 	TEST2(a, KNewValue);
   505 
   506 	r = rep->Get(KDefMeta0SingleMeta1Key, a);
   507 	TEST2(r, KErrNone);
   508 	TEST2(a, KNewValue);
   509 
   510 	r = rep->Get(KDefMeta1SingleMeta0Key, a);
   511 	TEST2(r, KErrNone);
   512 	TEST2(a, KNewValue);
   513 
   514 	r = rep->Get(KDefMeta1SingleMeta1Key, a);
   515 	TEST2(r, KErrNone);
   516 	TEST2(a, KNewValue);
   517 
   518 	// Check the Set's have not change the metadata
   519 	TEST(VerifyMetaDataUnchangedL());
   520 
   521 	// Take this opportunity to Reset the keys to exercise the
   522 	// Set-then-Reset path.
   523 
   524 	// Transaction not available for Reset.
   525 	r = rep->Reset(KMissingSingleMetaKey);
   526 	TEST2(r, KErrNone);
   527 	r = rep->Reset(KDefMeta0SingleMeta0Key);
   528 	TEST2(r, KErrNone);
   529 	r = rep->Reset(KDefMeta0SingleMeta1Key);
   530 	TEST2(r, KErrNone);
   531 	r = rep->Reset(KDefMeta1SingleMeta0Key);
   532 	TEST2(r, KErrNone);
   533 	r = rep->Reset(KDefMeta1SingleMeta1Key);
   534 	TEST2(r, KErrNone);
   535 
   536 	CleanupStack::PopAndDestroy(rep);
   537 
   538 	TEST(VerifyMetaDataUnchangedL());
   539 	}
   540 
   541 void TMetadataTest::RunDeleteCreateTestL()
   542 	{
   543 	TheTest.Next(_L("Metadata Delete-Create settings test\r\n"));
   544 
   545 	CRepository* rep = CRepository::NewLC(KUidTestRepository);
   546 
   547 	TInt r;
   548 	r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   549 	TEST2(r, KErrNone);
   550 	rep->CleanupCancelTransactionPushL();
   551 
   552 	r = rep->Delete(KMissingSingleMetaKey);
   553 	TEST2(r, KErrNone);
   554 	r = rep->Delete(KDefMeta0SingleMeta0Key);
   555 	TEST2(r, KErrNone);
   556 	r = rep->Delete(KDefMeta0SingleMeta1Key);
   557 	TEST2(r, KErrNone);
   558 	r = rep->Delete(KDefMeta1SingleMeta0Key);
   559 	TEST2(r, KErrNone);
   560 	r = rep->Delete(KDefMeta1SingleMeta1Key);
   561 	TEST2(r, KErrNone);
   562 
   563 	CleanupStack::Pop(); // transaction
   564 	TUint32 keyInfo;
   565 	r = rep->CommitTransaction(keyInfo);
   566 	TEST2(r, KErrNone);
   567 
   568 	CleanupStack::PopAndDestroy(rep);
   569 
   570 	// Now open the repository again and create the deleted keys.
   571 	rep = CRepository::NewLC(KUidTestRepository);
   572 
   573 	// Before Create, check if the Delete's actually happened.
   574 	TInt a;
   575 	r = rep->Get(KMissingSingleMetaKey, a);
   576 	TEST2(r, KErrNotFound);
   577 	r = rep->Get(KDefMeta0SingleMeta0Key, a);
   578 	TEST2(r, KErrNotFound);
   579 	r = rep->Get(KDefMeta0SingleMeta1Key, a);
   580 	TEST2(r, KErrNotFound);
   581 	r = rep->Get(KDefMeta1SingleMeta0Key, a);
   582 	TEST2(r, KErrNotFound);
   583 	r = rep->Get(KDefMeta1SingleMeta1Key, a);
   584 	TEST2(r, KErrNotFound);
   585 
   586 	r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   587 	TEST2(r, KErrNone);
   588 	rep->CleanupCancelTransactionPushL();
   589 
   590 	r = rep->Create(KMissingSingleMetaKey, KIntOrigValue);
   591 	TEST2(r, KErrNone);
   592 	r = rep->Create(KDefMeta0SingleMeta0Key, KIntOrigValue);
   593 	TEST2(r, KErrNone);
   594 	r = rep->Create(KDefMeta0SingleMeta1Key, KIntOrigValue);
   595 	TEST2(r, KErrNone);
   596 	r = rep->Create(KDefMeta1SingleMeta0Key, KIntOrigValue);
   597 	TEST2(r, KErrNone);
   598 	r = rep->Create(KDefMeta1SingleMeta1Key, KIntOrigValue);
   599 	TEST2(r, KErrNone);
   600 
   601 	CleanupStack::Pop(); // transaction
   602 	r = rep->CommitTransaction(keyInfo);
   603 	TEST2(r, KErrNone);
   604 
   605 	CleanupStack::PopAndDestroy(rep);
   606 
   607 	TEST(VerifyMetaDataUnchangedL());
   608 	}
   609 
   610 //=================================================
   611 void TMetadataTest::RunDeleteCreateTest2L()
   612 	{
   613 	TheTest.Next(_L("Metadata Delete-Create settings (uncommitted) test\r\n"));
   614 
   615 	CRepository* rep = CRepository::NewLC(KUidTestRepository);
   616 
   617 	TInt r;
   618 	r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   619 	TEST2(r, KErrNone);
   620 	rep->CleanupCancelTransactionPushL();
   621 
   622 	r = rep->Delete(KMissingSingleMetaKey);
   623 	TEST2(r, KErrNone);
   624 	r = rep->Delete(KDefMeta0SingleMeta0Key);
   625 	TEST2(r, KErrNone);
   626 	r = rep->Delete(KDefMeta0SingleMeta1Key);
   627 	TEST2(r, KErrNone);
   628 	r = rep->Delete(KDefMeta1SingleMeta0Key);
   629 	TEST2(r, KErrNone);
   630 	r = rep->Delete(KDefMeta1SingleMeta1Key);
   631 	TEST2(r, KErrNone);
   632 
   633 	// Next Create while Delete still in transaction.
   634 	r = rep->Create(KMissingSingleMetaKey, KIntOrigValue);
   635 	TEST2(r, KErrNone);
   636 	r = rep->Create(KDefMeta0SingleMeta0Key, KIntOrigValue);
   637 	TEST2(r, KErrNone);
   638 	r = rep->Create(KDefMeta0SingleMeta1Key, KIntOrigValue);
   639 	TEST2(r, KErrNone);
   640 	r = rep->Create(KDefMeta1SingleMeta0Key, KIntOrigValue);
   641 	TEST2(r, KErrNone);
   642 	r = rep->Create(KDefMeta1SingleMeta1Key, KIntOrigValue);
   643 	TEST2(r, KErrNone);
   644 
   645 	// Make a dummy change in case the Delete/Create cancel each
   646 	// other, ending up with nothing to commit.
   647 	r = rep->Create(0xA5A5, KIntOrigValue);
   648 	TEST2(r, KErrNone);
   649 
   650 	CleanupStack::Pop(); // transaction
   651 	TUint32 keyInfo;
   652 	r = rep->CommitTransaction(keyInfo);
   653 	TEST2(r, KErrNone);
   654 	r = rep->Delete(0xA5A5);
   655 	TEST2(r, KErrNone);
   656 
   657 	CleanupStack::PopAndDestroy(rep);
   658 
   659 	TEST(VerifyMetaDataUnchangedL());
   660 	}
   661 
   662 //===============================================
   663 void TMetadataTest::RunDeleteResetTestL()
   664 	{
   665 	TheTest.Next(_L("Metadata Delete-Reset settings test\r\n"));
   666 
   667 	CRepository* rep = CRepository::NewLC(KUidTestRepository);
   668 
   669 	TInt r;
   670 	r = rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   671 	TEST2(r, KErrNone);
   672 	rep->CleanupCancelTransactionPushL();
   673 
   674 	r = rep->Delete(KMissingSingleMetaKey);
   675 	TEST2(r, KErrNone);
   676 	r = rep->Delete(KDefMeta0SingleMeta0Key);
   677 	TEST2(r, KErrNone);
   678 	r = rep->Delete(KDefMeta0SingleMeta1Key);
   679 	TEST2(r, KErrNone);
   680 	r = rep->Delete(KDefMeta1SingleMeta0Key);
   681 	TEST2(r, KErrNone);
   682 	r = rep->Delete(KDefMeta1SingleMeta1Key);
   683 	TEST2(r, KErrNone);
   684 
   685 	CleanupStack::Pop(); // transaction
   686 	TUint32 keyInfo;
   687 	r = rep->CommitTransaction(keyInfo);
   688 	TEST2(r, KErrNone);
   689 
   690 	CleanupStack::PopAndDestroy(rep);
   691 
   692 	// check if the delete's actually happened
   693 	rep = CRepository::NewLC(KUidTestRepository);
   694 
   695 	TInt a;
   696 	r = rep->Get(KMissingSingleMetaKey, a);
   697 	TEST2(r, KErrNotFound);
   698 	r = rep->Get(KDefMeta0SingleMeta0Key, a);
   699 	TEST2(r, KErrNotFound);
   700 	r = rep->Get(KDefMeta0SingleMeta1Key, a);
   701 	TEST2(r, KErrNotFound);
   702 	r = rep->Get(KDefMeta1SingleMeta0Key, a);
   703 	TEST2(r, KErrNotFound);
   704 	r = rep->Get(KDefMeta1SingleMeta1Key, a);
   705 	TEST2(r, KErrNotFound);
   706 
   707 	// Next Reset on each deleted key.
   708 
   709 	// Transaction not available for Reset.
   710 	r = rep->Reset(KMissingSingleMetaKey);
   711 	TEST2(r, KErrNone);
   712 	r = rep->Reset(KDefMeta0SingleMeta0Key);
   713 	TEST2(r, KErrNone);
   714 	r = rep->Reset(KDefMeta0SingleMeta1Key);
   715 	TEST2(r, KErrNone);
   716 	r = rep->Reset(KDefMeta1SingleMeta0Key);
   717 	TEST2(r, KErrNone);
   718 	r = rep->Reset(KDefMeta1SingleMeta1Key);
   719 	TEST2(r, KErrNone);
   720 
   721 	CleanupStack::PopAndDestroy(rep);
   722 
   723 	TEST(VerifyMetaDataUnchangedL());
   724 	}
   725 
   726 /**
   727 @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-1717
   728 @SYMTestCaseDesc Test Set, Delete, Create and Reset on a key with meta of 0 while defaultmeta is non-zero.
   729 @SYMTestPriority High
   730 @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.
   731 @SYMTestExpectedResults The test must not fail.
   732 @SYMDEF INC086298
   733 */
   734 LOCAL_C void INC086298L()
   735 	{
   736 	TheTest.Printf(_L("INC086298 - Setting with no backup meta value is backed up\r\n"));
   737 
   738 	TMetadataTest metaDataTester;
   739 	metaDataTester.InitialiseL();
   740 
   741 	metaDataTester.RunBasicGetMetaTestsL();
   742 
   743 	TheTest.Printf( _L("Metadata tests on .txt file\r\n") );
   744 	metaDataTester.RunTestsL();
   745 
   746 	TheTest.Printf( _L("Metadata tests on .cre file\r\n") );
   747 	metaDataTester.InstallCreFileL();
   748 	metaDataTester.RunTestsL();
   749 	}
   750 
   751 LOCAL_C void MainL()
   752 	{
   753 	TheTest.Start( _L( " @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-1717 CentralRepository metadata test " ) );
   754 	User::LeaveIfError(fs.Connect());
   755 
   756 	CleanupClosePushL(fs);
   757 
   758     INC086298L();
   759 
   760 	CleanupStack::PopAndDestroy(&fs);
   761 
   762 	TheTest.End();
   763 	TheTest.Close();
   764 	}
   765 
   766 TInt E32Main()
   767 	{
   768 	__UHEAP_MARK;
   769 	CTrapCleanup* cleanup = CTrapCleanup::New();
   770 	if ( !cleanup )
   771 		return KErrNoMemory;
   772 
   773 	TRAPD( err, MainL()  );
   774 
   775 	delete cleanup;
   776 	__UHEAP_MARKEND;
   777 
   778 	return err;
   779 	}