persistentstorage/centralrepository/test/t_cenrep_defects.cpp
changeset 0 08ec8eefde2f
child 1 c084286672be
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2004-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 "t_cenrep_helper.h"
       
    17 #include <centralrepository.h>
       
    18 #include <e32property.h>
       
    19 #include <e32test.h>
       
    20 #include <f32file.h>
       
    21 #include <bautils.h>
       
    22 #include <cenrepnotifyhandler.h>
       
    23 
       
    24 #include "e32math.h"
       
    25 #include "srvparams.h"
       
    26 #include "srvreqs.h"
       
    27 #include "srvdefs.h"
       
    28 #include "transstate.h"
       
    29 #include "obsrvr_noc.h"
       
    30 #include "shrepos.h"
       
    31 #include "install.h"
       
    32 
       
    33 using namespace NCentralRepositoryConstants;
       
    34 
       
    35 RTest TheTest(_L("Central Repository Defect Tests"));
       
    36 
       
    37 _LIT( KCentralRepositoryServerName, "Centralrepositorysrv");
       
    38 
       
    39 const TUid KUidDEF060843LRepository1    = { 0x00000001 };
       
    40 const TUid KUidRep1						= { 0x00000100 };
       
    41 const TUid KUidDEF053500LTestRepository = { 0x00000102 };
       
    42 const TUid KUidDEF054368TestRepository  = { 0x00000103 };
       
    43 const TUid KUidINC054688TestRepository  = { 0x100058db };
       
    44 const TUid KUidDEF054632TestRepository  = { 0x10054632 };
       
    45 const TUid KUidDEF054633TestRepository  = { 0x10054633 };
       
    46 const TUid KUidLargeRepository          = { 0xCCCCCC01 };
       
    47 const TUid KUidDEF055661TestRepository  = { 0x10055661 };
       
    48 const TUid KUidINC056194TestRepository  = { 0x00056194 };
       
    49 const TUid KUidDEF057778TestRepository  = { 0x00057778 };
       
    50 const TUid KUidDEF057470TestRepository 	= { 0x10057470 };
       
    51 const TUid KUidDEF058900TestRepository 	= { 0x10058900 };
       
    52 const TUid KUidINC069013TestRepository 	= { 0x00000104 };
       
    53 const TUid KUidPDEF098500LRepository		= { 0x10098500 };
       
    54 
       
    55 const TUint32 KRangeDeletePartialKey 			= 0x04010000 ;
       
    56 const TUint32 KDeleteKeyDoesntExist  			= 0x07000000 ;
       
    57 const TUint32 KDeleteForbidden     				= 0x03010000 ;
       
    58 const TUint32 KTransactionRangeDeletePartialKey = 0x02010000 ;
       
    59 const TUint32 KRangeDeleteMask       			= 0x0F0F0000 ;
       
    60 const TUint32 KNullKey							= 0x00000000 ;
       
    61 
       
    62 const TUint32 KNotifyBannedKey					= static_cast<TUint32>(KRequestPending) ;
       
    63 const TUint32 KNotificationKey1					= 0x80000101;
       
    64 const TUint32 KNotificationKey2					= 0x80000201;
       
    65 const TUint32 KNotificationKey3					= 0x80000301;
       
    66 const TUint32 KNotificationKey4					= 0x80000401;
       
    67 
       
    68 //
       
    69 // Repository A
       
    70 //
       
    71 
       
    72 const TUint32 KNewInt = 1000;
       
    73 const TInt KIntValue = 1234;
       
    74 
       
    75 
       
    76 // Definitions for test DEF116629L()
       
    77 // The structure to construct a TServerSetting object with a TInt value.
       
    78 struct ServerSettingStruct
       
    79 	{
       
    80 	TUint32 key;
       
    81 	TUint32 meta;
       
    82 	TInt value;
       
    83 	};
       
    84 // The merge types to be tested
       
    85 const TMergeType KMergerTypes[] = {ETransactionMerge,ERestoreMerge, ESWIUpgradeMerge, ESWIDowngradeMerge, ERomFlash};
       
    86 
       
    87 
       
    88 ///////////////////////////////////////////////////////////////////////////////////////
       
    89 ///////////////////////////////////////////////////////////////////////////////////////
       
    90 //Test macroses and functions
       
    91 LOCAL_C void CheckL(TInt aValue, TInt aLine)
       
    92 	{
       
    93 	if(!aValue)
       
    94 		{
       
    95 		CleanupCDriveL();
       
    96 		TheTest(EFalse, aLine);
       
    97 		}
       
    98 	}
       
    99 LOCAL_C void CheckL(TInt aValue, TInt aExpected, TInt aLine)
       
   100 	{
       
   101 	if(aValue != aExpected)
       
   102 		{
       
   103 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
       
   104 		CleanupCDriveL();
       
   105 		TheTest(EFalse, aLine);
       
   106 		}
       
   107 	}
       
   108 
       
   109 #define TEST(arg) ::CheckL((arg), __LINE__)
       
   110 #define TEST2(aValue, aExpected) ::CheckL(aValue, aExpected, __LINE__)
       
   111 
       
   112 ///////////////////////////////////////////////////////////////////////////////////////
       
   113 ///////////////////////////////////////////////////////////////////////////////////////
       
   114 
       
   115 /**
       
   116 @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-4015
       
   117 @SYMTestCaseDesc When having multiple connections to a particular repository, starting a
       
   118 transaction and then killing that connection, should not cause a reset.
       
   119 @SYMTestPriority High
       
   120 @SYMTestActions
       
   121 	Essentially - this deals with multiple connections, the lack of cancelling a transaction,
       
   122  	either by shutting the sub-session to the CR server directly (or by a crashing application
       
   123  	where all open sub-sessions to CR from that application are closed) and the cache manager
       
   124  	inside CR.
       
   125 
       
   126    Previously, CR's cache manager would reclaim repository memory regardless of the state
       
   127    of the repository (in transaction or not).  However, if a repository is closed and its
       
   128    no longer an open repository (cache manager reclaimed the memory), it would not remove
       
   129    references to the sub-session for this repository in the transaction queue.  Simply put,
       
   130    the sub-session's data would be deleted but there would still be references to that
       
   131    deleted data.  When you established a new connection (any operation would cause this) you'd
       
   132    walk down an invalid pointer.  Most of the time this would cause the server to crash.
       
   133 
       
   134    Now, if you're in an active transaction, the cache manager does not reclaim the data.
       
   135    Which means that there will always be valid references in the transaction queue.
       
   136 
       
   137    ThreadA                                   CR                        CR Cache Manager
       
   138    Connection 1.
       
   139    CRepository::NewLC(X) --------------->   EInitialize
       
   140 
       
   141    Connection 2.
       
   142    CRepository::NewLC(X) --------------->   EInitialize
       
   143 
       
   144    Connection 2, Start Transaction
       
   145    StartTransaction     ---------------->   ETransactionStart
       
   146 
       
   147    Before
       
   148    ----------------------------------------------------------------------------------
       
   149    Wait 10 seconds
       
   150 
       
   151                                                  <--------------------------- Evict(X)
       
   152 
       
   153    Connection 2. Close
       
   154    delete connection2 ------------------>   EClose (would leave invalid references)
       
   155 
       
   156    Connection 1.
       
   157    GetInt             ------------------>   EGetInt (would attach to repository, derefence
       
   158                                                      invalid pointer, CR would crash)
       
   159 
       
   160    -----------------------------------------------------------------------------------
       
   161    Now
       
   162 
       
   163    Wait 10 seconds
       
   164 
       
   165                                                                               Reschedule
       
   166                                                   (CR cache manager sees that Repository X
       
   167                                                    is in a transaction and just reschedules
       
   168                                                    it)
       
   169    Connection 2. Close
       
   170    delete connection2 --------------------> EClose (memory is now available so it cancels
       
   171                                                     the active transaction)
       
   172 
       
   173    GetInt             --------------------> EGetInt (attaches to the open repository, all is
       
   174                                                      fine)
       
   175    delete connection2 --------------------> EClose (repository X has no more observers so
       
   176                                                     it is scheduled to have its memory reclaimed
       
   177                                                     by CR cache manager)
       
   178 
       
   179 @SYMTestExpectedResults The test must not fail.
       
   180 @SYMDEF DEF111734
       
   181 */
       
   182 
       
   183 LOCAL_C void DEF111734L()
       
   184 	{
       
   185 	/* first establish a connection. this is important because if there are no observers
       
   186 	 * on a repository, the repository's shared data is deleted directly */
       
   187 	CRepository* rep;
       
   188 	User::LeaveIfNull(rep = CRepository::NewLC(KUidDEF054368TestRepository));
       
   189 
       
   190 	/* second establish a second connection.  this will be used to start a transaction */
       
   191 	CRepository* rep2;
       
   192 	User::LeaveIfNull(rep2 = CRepository::NewLC(KUidDEF054368TestRepository));
       
   193 
       
   194 	/* establish a transaction, this manipulates the transaction queue for this repository */
       
   195 	rep2->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
       
   196 
       
   197 	/* now wait.  this should be plenty of time to allow cache manager in CR to reclaim
       
   198 	 * the data for this repository */
       
   199 	User::After(5050000 + 9500000);
       
   200 
       
   201 	TInt i = 0;
       
   202 	const TInt KInt1_InitialValue = 100;
       
   203 	const TUint32 KInt1 = 0x1;
       
   204 
       
   205 	/* destory the connection - this will cause a "close" operation in CR */
       
   206 	CleanupStack::PopAndDestroy(rep2);
       
   207 
       
   208 	/* attempt to reconnect to the repository. */
       
   209 	TInt r = rep->Get(KInt1, i);
       
   210 
       
   211 	/* if the fix is not in the build, then CR will crash.
       
   212 	 * Errcode will be KErrServerTerminated */
       
   213 	TEST2(r, KErrNone);
       
   214 
       
   215 	/* just for completion's sake, check the return value */
       
   216 	TEST(i == KInt1_InitialValue);
       
   217 
       
   218 	// Close repository
       
   219 
       
   220 	CleanupStack::PopAndDestroy(rep);
       
   221 	}
       
   222 
       
   223 
       
   224 LOCAL_C void DEF053500L()
       
   225 	{
       
   226 	CRepository* rep;
       
   227 	// Open repository with hex key value setting
       
   228 	User::LeaveIfNull(rep = CRepository::NewLC(KUidDEF053500LTestRepository));
       
   229 	// Close repository
       
   230 	CleanupStack::PopAndDestroy(rep);
       
   231 	}
       
   232 
       
   233 LOCAL_C void DEF054368L()
       
   234 	{
       
   235 	CRepository* rep;
       
   236 	User::LeaveIfNull(rep = CRepository::NewLC(KUidDEF054368TestRepository));
       
   237 
       
   238 	TInt i = 0;
       
   239 	const TInt KInt1_InitialValue = 100;
       
   240 	const TInt KInt2_InitialValue = 200;
       
   241 	const TInt KInt3_InitialValue = -100;
       
   242 	const TInt KInt4_InitialValue = -200;
       
   243 	const TInt KInt5_InitialValue = 0xc8;
       
   244 
       
   245 	const TUint32 KInt1 = 0x1;
       
   246 	const TUint32 KInt2 = 0x2;
       
   247 	const TUint32 KInt3 = 0x3;
       
   248 	const TUint32 KInt4 = 0x4;
       
   249     const TUint32 KInt5 = 0x5;
       
   250 
       
   251 	TInt r = rep->Get(KInt1, i);
       
   252 	TEST2(r, KErrNone);
       
   253 	TEST(i==KInt1_InitialValue);
       
   254 
       
   255 	r = rep->Get(KInt2, i);
       
   256 	TEST2(r, KErrNone);
       
   257 	TEST(i==KInt2_InitialValue);
       
   258 
       
   259 	r = rep->Get(KInt3, i);
       
   260 	TEST2(r, KErrNone);
       
   261 	TEST(i==KInt3_InitialValue);
       
   262 
       
   263 	r = rep->Get(KInt4, i);
       
   264 	TEST2(r, KErrNone);
       
   265 	TEST(i==KInt4_InitialValue);
       
   266 
       
   267 	r = rep->Get(KInt5, i);
       
   268 	TEST2(r, KErrNone);
       
   269 	TEST(i==KInt5_InitialValue);
       
   270 
       
   271 	// Close repository
       
   272 	CleanupStack::PopAndDestroy(rep);
       
   273 	}
       
   274 
       
   275 LOCAL_C void DEF055680L()
       
   276 	{
       
   277 	CRepository* rep;
       
   278 	// Open repository
       
   279 	User::LeaveIfNull(rep = CRepository::NewLC(KUidLargeRepository));
       
   280 
       
   281 	// Find setting whose value the test doesn't have permission to look at
       
   282 	RArray<TUint32> foundIds;
       
   283 	TInt r = KErrNone;
       
   284 	r = rep->FindL(0x810100, 0xFFFFFFFF, foundIds);
       
   285 	TEST2(r, KErrNone);
       
   286 	TEST2(foundIds.Count(), 1);
       
   287 
       
   288 	TInt val;
       
   289 	r = rep->Get(foundIds[0], val);
       
   290 	TEST2(r, KErrPermissionDenied);
       
   291 	foundIds.Reset();
       
   292 
       
   293 	r = rep->Create(KNewInt, KIntValue);
       
   294 	TEST2(r, KErrNone);
       
   295 
       
   296 	//Reset repository to remove any changes made during this test
       
   297 	r = rep->Reset();
       
   298 	TEST2(r, KErrNone);
       
   299 
       
   300 	// Close repository
       
   301 	CleanupStack::PopAndDestroy(rep);
       
   302 
       
   303 	}
       
   304 
       
   305 LOCAL_C void DEF054632L()
       
   306 	{
       
   307 	CRepository* rep;
       
   308 
       
   309 	//----------Testing for correct default policy behaviour---------------
       
   310 	/*---------------------10054632.txt------------------------------------
       
   311 	[platsec]
       
   312 	cap_rd=ReadDeviceData cap_wr=WriteDeviceData
       
   313 	0x3 0x4 cap_wr=NetworkServices
       
   314 	[Main]
       
   315 	0x1 int 1 0 cap_rd=CommDD
       
   316 	0x2 int 2 1 cap_wr=CommDD
       
   317 	0x3 int 3 0
       
   318 	0x4 int 4 0
       
   319 	0x5 int 5 0 cap_rd=CommDD
       
   320 	---------------------------------------------------------------------*/
       
   321 	User::LeaveIfNull(rep = CRepository::NewLC(KUidDEF054632TestRepository));
       
   322 
       
   323 	//testing single policies
       
   324 	TInt err=KErrNone;
       
   325 	const TInt key_2=2;
       
   326 	const TInt key_1=1;
       
   327 	TInt value=0;
       
   328 
       
   329 	err=rep->Get(key_2,value);
       
   330 	TEST2(err,KErrNone);
       
   331 
       
   332 	err=rep->Set(key_1,value);
       
   333 	TEST2(err,KErrNone);
       
   334 
       
   335 	//testing range policies
       
   336 	const TInt key_3=3;
       
   337 	err=rep->Get(key_3,value);
       
   338 	TEST2(err,KErrNone);
       
   339 
       
   340 	CleanupStack::PopAndDestroy(rep);
       
   341 
       
   342 	//------Testing for correct policy behaviour with no default policies-----
       
   343 	/*--------------------------10054633.txt----------------------------------
       
   344 	[platsec]
       
   345 	0x3 0x4 cap_rd=CommDD
       
   346 	[Main]
       
   347 	0x1 int 1 0 cap_rd=CommDD
       
   348 	0x2 int 2 1 cap_wr=CommDD
       
   349 	0x3 int 3 0
       
   350 	0x4 int 4 0
       
   351 	------------------------------------------------------------------------*/
       
   352 	User::LeaveIfNull(rep=CRepository::NewLC(KUidDEF054633TestRepository));
       
   353 
       
   354 	//testing single policies
       
   355 	err=rep->Get(key_1,value);
       
   356 	TEST2(err,KErrPermissionDenied);
       
   357 	err=rep->Set(key_1,value);
       
   358 	TEST2(err,KErrPermissionDenied);
       
   359 
       
   360 	err=rep->Set(key_2,value);
       
   361 	TEST2(err,KErrPermissionDenied);
       
   362 	err=rep->Get(key_2,value);
       
   363 	TEST2(err,KErrPermissionDenied);
       
   364 
       
   365 	//testing range policies
       
   366 	err=rep->Get(key_3,value);
       
   367 	TEST2(err,KErrPermissionDenied);
       
   368 	const TInt key_4=4;
       
   369 	err=rep->Set(key_4,value);
       
   370 	TEST2(err,KErrPermissionDenied);
       
   371 	err=rep->Get(key_4,value);
       
   372 	TEST2(err,KErrPermissionDenied);
       
   373 
       
   374 	CleanupStack::PopAndDestroy(rep);
       
   375 	}
       
   376 
       
   377 /**
       
   378 This test will be checking the robustness of the modified array structure
       
   379 for the single policies, range policies.
       
   380 */
       
   381 LOCAL_C void INC054688L()
       
   382 	{
       
   383 	CRepository* rep;
       
   384 	User::LeaveIfNull(rep = CRepository::NewLC(KUidINC054688TestRepository));
       
   385 
       
   386 	//--------------CHECKING THE SINGLE POLICIES ARRAY----------------------
       
   387 	//The ini file has been structured so that the key will be equal to the
       
   388 	//key value so we can test it using a loop.
       
   389 	//and also to check some policy checking, we set all the even entries to
       
   390 	//be non accessible due to insufficient capabilities
       
   391 	//The key tested for the single policies are from 1 to 24
       
   392 	const TInt KMaxKeyEntry=24;
       
   393 	TInt err=KErrNone;
       
   394 	TInt key_value=0;
       
   395 	for (TInt i=1;i<=KMaxKeyEntry;i++)
       
   396 		{
       
   397 		err=rep->Get(i,key_value);
       
   398 		//even entries alway not accessible due to insufficient caps
       
   399 		if (i%2==0)
       
   400 			TEST2(err,KErrPermissionDenied);
       
   401 		else
       
   402 			{
       
   403 			TEST2(err,KErrNone);
       
   404 			TEST2(i,key_value);
       
   405 			}
       
   406 		}
       
   407 
       
   408 	//--------------CHECKING THE RANGE POLICIES ARRAY----------------------
       
   409 	//The range policies in the [platsec] section are arranged in key pairs
       
   410 	//e.g 25-26,27-28.For testing purpose, the odd pairs(e.g 25-26 is the
       
   411 	//first pair) will require capabilities that the test lacks off hence
       
   412 	//causing KErrPermissionDenied when trying to read those range.
       
   413 	//The key tested for the arary policies are from 25-38 and the value
       
   414 	//matches the key
       
   415 
       
   416 	const TInt startRangeKey=25;
       
   417 	const TInt KMaxRangeKey=38;
       
   418 	TInt numberOfPairs=(KMaxRangeKey-startRangeKey+1)/2;
       
   419 	TInt key_value1=0;
       
   420 	TInt err1=KErrNone;
       
   421 	for (TInt j=0;j<numberOfPairs;j++)
       
   422 		{
       
   423 		//Get first key of the pair
       
   424 		err=rep->Get(startRangeKey+(2*j),key_value);
       
   425 		//Get second key of the pair
       
   426 		err1=rep->Get(startRangeKey+(2*j)+1,key_value1);
       
   427 		//start from j=0(first pair)
       
   428 		if ((j+1)%2==0)
       
   429 			{
       
   430 			TEST2(err,KErrNone);
       
   431 			TEST2(err1,KErrNone);
       
   432 			TEST2(startRangeKey+(2*j),key_value);
       
   433 			TEST2(startRangeKey+(2*j)+1,key_value1);
       
   434 			}
       
   435 		//only odd pairs are non-accessible due to insufficient caps
       
   436 		else
       
   437 			{
       
   438 			TEST2(err,KErrPermissionDenied);
       
   439 			TEST2(err1,KErrPermissionDenied);
       
   440 			}
       
   441 		}
       
   442 
       
   443 	//Before closing the repository, modify one of the key to see whether
       
   444 	//the policy array behaves similarly after a rewrite of the ini file
       
   445 	const TInt keyToChange=3;
       
   446 	const TInt modifiedValue=3;
       
   447 	err=rep->Set(keyToChange,modifiedValue);
       
   448 	TEST2(err,KErrNone);
       
   449 
       
   450 	// Close repository
       
   451 	CleanupStack::PopAndDestroy(rep);
       
   452 	User::After(KGeneralDelay);
       
   453 
       
   454 	//Reopen the repository again after that minor update which will cause
       
   455 	//all the entry in the ini file to be reversed
       
   456 	User::LeaveIfNull(rep = CRepository::NewLC(KUidINC054688TestRepository));
       
   457 
       
   458 	//---------RECHECKING THE POLICY ARRAY AFTER UPDATE--------------------
       
   459 	for (TInt i=1;i<=KMaxKeyEntry;i++)
       
   460 		{
       
   461 		err=rep->Get(i,key_value);
       
   462 		//even entries alway not accessible due to insufficient caps
       
   463 		if (i%2==0)
       
   464 			TEST2(err,KErrPermissionDenied);
       
   465 		else
       
   466 			{
       
   467 			TEST2(err,KErrNone);
       
   468 			TEST2(i,key_value);
       
   469 			}
       
   470 		}
       
   471 
       
   472 
       
   473 	//---------RECHECKING THE RANGE POLICY ARRAY AFTER UPDATE-------------
       
   474 	for (TInt j=0;j<numberOfPairs;j++)
       
   475 		{
       
   476 		//Get first key of the pair
       
   477 		err=rep->Get(startRangeKey+(2*j),key_value);
       
   478 		//Get second key of the pair
       
   479 		err1=rep->Get(startRangeKey+(2*j)+1,key_value1);
       
   480 		//start from j=0(first pair)
       
   481 		if ((j+1)%2==0)
       
   482 			{
       
   483 			TEST2(err,KErrNone);
       
   484 			TEST2(err1,KErrNone);
       
   485 			TEST2(startRangeKey+(2*j),key_value);
       
   486 			TEST2(startRangeKey+(2*j)+1,key_value1);
       
   487 			}
       
   488 		//only odd pairs are non-accessible due to insufficient caps
       
   489 		else
       
   490 			{
       
   491 			TEST2(err,KErrPermissionDenied);
       
   492 			TEST2(err1,KErrPermissionDenied);
       
   493 			}
       
   494 		}
       
   495 
       
   496 	CleanupStack::PopAndDestroy(rep);
       
   497 	}
       
   498 
       
   499 LOCAL_C void DEF055661L()
       
   500 	{
       
   501 	/*--------------------10055661.txt----------------------------------------
       
   502 	[platsec]
       
   503 	cap_rd=ReadDeviceData cap_wr=AlwaysFail
       
   504 	0x3 0x4 cap_wr=NetworkServices
       
   505 	[Main]
       
   506 	0x1 int 1 0 cap_rd=AlwaysPass
       
   507 	0x2 int 2 1 cap_rd=AlwaysFail
       
   508 	0x3 int 3 0
       
   509 	0x4 int 4 0 cap_rd=AlwaysFail
       
   510 	0x5 int 5 0 cap_wr=AlwaysPass
       
   511 	-------------------------------------------------------------------------*/
       
   512 	CRepository* rep;
       
   513 	User::LeaveIfNull(rep = CRepository::NewLC(KUidDEF055661TestRepository));
       
   514 
       
   515 	TInt err=KErrNone;
       
   516 	TInt keyValue=0;
       
   517 
       
   518 	//Key 1
       
   519 	err=rep->Get(1,keyValue);
       
   520 	TEST2(err,KErrNone);
       
   521 	TEST2(keyValue,1);
       
   522 	err=rep->Set(1,keyValue);
       
   523 	TEST2(err,KErrPermissionDenied);
       
   524 
       
   525 	//Key 2
       
   526 	err=rep->Get(2,keyValue);
       
   527 	TEST2(err,KErrPermissionDenied);
       
   528 	err=rep->Set(2,keyValue);
       
   529 	TEST2(err,KErrPermissionDenied);
       
   530 
       
   531 	//Key 3
       
   532 	err=rep->Get(3,keyValue);
       
   533 	TEST2(err,KErrNone);
       
   534 	TEST2(keyValue,3);
       
   535 	err=rep->Set(3,keyValue);
       
   536 	TEST2(err,KErrPermissionDenied);
       
   537 
       
   538 	//Key 4
       
   539 	err=rep->Get(4,keyValue);
       
   540 	TEST2(err,KErrPermissionDenied);
       
   541 	err=rep->Set(4,keyValue);
       
   542 	TEST2(err,KErrPermissionDenied);
       
   543 
       
   544 	//Key 5
       
   545 	err=rep->Get(5,keyValue);
       
   546 	TEST2(err,KErrNone);
       
   547 	err=rep->Set(5,keyValue);
       
   548 	TEST2(err,KErrNone);
       
   549 
       
   550 	CleanupStack::PopAndDestroy(rep);
       
   551 	}
       
   552 
       
   553 LOCAL_C void DEF055267L()
       
   554 	{
       
   555 	CRepository* rep;
       
   556 	// Open repository
       
   557 	User::LeaveIfNull(rep = CRepository::NewLC(KUidLargeRepository));
       
   558 
       
   559 	TInt r;
       
   560 	TUint32 errorId;
       
   561 	// The following loop creates enough settings to blow the server heap
       
   562 	// when it's 1 M. If it passes it proves that the server heap is > 1M
       
   563 	// Increasing the server heap allows the messaging test to pass
       
   564 	_LIT(KString, "Long test string !!!!!!!!!!!");
       
   565 	const TInt KNumTransactions=25;
       
   566 	const TInt KNumSettingsInTrans=100;
       
   567 	for(TInt numTransactions=0; numTransactions<KNumTransactions;numTransactions++)
       
   568 		{
       
   569 		r = rep->StartTransaction(CRepository::EReadWriteTransaction);
       
   570 		TEST2(r, KErrNone);
       
   571 		for(TInt numSettingsInTrans=0; numSettingsInTrans<KNumSettingsInTrans; numSettingsInTrans++)
       
   572 			{
       
   573 			r = rep->Create((numTransactions*KNumSettingsInTrans)+numSettingsInTrans, KString);
       
   574 			TEST2(r, KErrNone);
       
   575 			}
       
   576 		r = rep->CommitTransaction(errorId);
       
   577 		TEST2(r, KErrNone);
       
   578 		}
       
   579 
       
   580 	//Reset repository to remove any changes made during this test
       
   581 	r = rep->Reset();
       
   582 	TEST2(r, KErrNone);
       
   583 
       
   584 	// Close repository
       
   585 	CleanupStack::PopAndDestroy(rep);
       
   586 	}
       
   587 
       
   588 LOCAL_C void INC056194L()
       
   589 	{
       
   590 	CRepository* repository;
       
   591 	// Open repository
       
   592 	User::LeaveIfNull(repository = CRepository::NewLC(KUidINC056194TestRepository));
       
   593 
       
   594 	const TUint32 KInt1 = 1;
       
   595 	TRequestStatus intStatus;
       
   596 
       
   597 	TInt r = repository->NotifyRequest(KInt1, intStatus);
       
   598 	TEST2(r, KErrNone);
       
   599 	r = repository->NotifyCancel(KInt1);
       
   600 	TEST2(r, KErrNone);
       
   601 	User::WaitForAnyRequest();
       
   602 	TEST(intStatus==KUnspecifiedKey);
       
   603 
       
   604 	r = repository->NotifyRequest(KInt1, intStatus);
       
   605 	TEST2(r, KErrNone);
       
   606 	r = repository->NotifyCancelAll();
       
   607 	TEST2(r, KErrNone);
       
   608 	User::WaitForAnyRequest();
       
   609 	TEST(intStatus==KUnspecifiedKey);
       
   610 
       
   611 	r = repository->NotifyRequest(0, KInt1, intStatus);
       
   612 	TEST2(r, KErrNone);
       
   613 	r = repository->NotifyCancel(0, KInt1);
       
   614 	TEST2(r, KErrNone);
       
   615 	User::WaitForAnyRequest();
       
   616 	TEST(intStatus==KUnspecifiedKey);
       
   617 
       
   618 	RThread thisThread;
       
   619 	TEST(thisThread.RequestCount()==0);
       
   620 
       
   621 	// Close repository
       
   622 	CleanupStack::PopAndDestroy(repository);
       
   623 	}
       
   624 
       
   625 LOCAL_C void DEF057145L()
       
   626 	{
       
   627 	TInt err=KErrNone;
       
   628 	const TUid testUid={0x10057145};
       
   629 	RArray<TUint32> idArray;
       
   630 	CRepository* repository;
       
   631 	User::LeaveIfNull(repository = CRepository::NewLC(testUid));
       
   632 
       
   633 	//Start Transaction
       
   634 	err=repository->StartTransaction(CRepository::EReadWriteTransaction);
       
   635 	TEST2(err,KErrNone);
       
   636 
       
   637 	//Before creating new entries get the number of persistent settings
       
   638 	err=repository->FindL(0,0xFFFFF000,idArray);
       
   639 	TEST2(err,KErrNone);
       
   640 	TInt persistentSettingsCount=idArray.Count();
       
   641 	idArray.Close();
       
   642 
       
   643 	//Try creating new entries during transaction between the two extreme points
       
   644 	//ROM persistent file has low key of 1 and high key of 201
       
   645 	//We try creating new entries in between during transaction
       
   646 	for (TInt i=100;i<150;i++)
       
   647 		{
       
   648 		err=repository->Create(i,i);
       
   649 		TEST2(err,KErrNone);
       
   650 		}
       
   651 
       
   652 	//Now check the merge with the persistent settings is fine by checking
       
   653 	//the array count after the merge.
       
   654 	err=repository->FindL(0x000,0xFFFFF000,idArray);
       
   655 	TEST2(err,KErrNone);
       
   656 	TEST(idArray.Count()==(persistentSettingsCount+50));
       
   657 	idArray.Close();
       
   658 
       
   659 	TUint32 errId;
       
   660 	err=repository->CommitTransaction(errId);
       
   661 	TEST2(err,KErrNone);
       
   662 
       
   663 	idArray.Close();
       
   664 	CleanupStack::PopAndDestroy(repository);
       
   665 	}
       
   666 
       
   667 
       
   668 LOCAL_C void DEF057778L()
       
   669 	{
       
   670 	TInt r;
       
   671 	CRepository* repository;
       
   672 	// Open repository
       
   673 	User::LeaveIfNull(repository = CRepository::NewLC(KUidDEF057778TestRepository));
       
   674 
       
   675 	const TUint32 KInt14=14;
       
   676 	const TInt KInt14NewValue=0;
       
   677 
       
   678 	r=repository->Set(KInt14,KInt14NewValue);
       
   679 	TEST2(r, KErrNone);
       
   680 
       
   681 	// Reset setting that has a single policy
       
   682 	r=repository->Reset(KInt14);
       
   683 	TEST2(r, KErrNone);
       
   684 
       
   685 	// Attempt to access and write setting
       
   686 	r=repository->Set(KInt14,KInt14NewValue);
       
   687 	TEST2(r, KErrNone);
       
   688 
       
   689 	// Reset entire repository
       
   690 	r=repository->Reset();
       
   691 	TEST2(r, KErrNone);
       
   692 
       
   693 	// Attempt to access and write setting
       
   694 	r=repository->Set(KInt14,KInt14NewValue);
       
   695 	TEST2(r, KErrNone);
       
   696 
       
   697 	// Reset entire repository
       
   698 	r=repository->Reset();
       
   699 	TEST2(r, KErrNone);
       
   700 
       
   701 	// Close repository
       
   702 	CleanupStack::PopAndDestroy(repository);
       
   703 	}
       
   704 
       
   705 
       
   706 LOCAL_C void DEF057999L()
       
   707  	{
       
   708 
       
   709  	TInt err=KErrNone;
       
   710  	TInt retValue=0;
       
   711  	const TUid testUid={0x10057145};
       
   712  	RArray<TUint32> idArray;
       
   713 
       
   714   	CRepository* repository;
       
   715  	User::LeaveIfNull(repository = CRepository::NewLC(testUid));
       
   716 
       
   717   	//--------------Start Transaction------------------------------------
       
   718  	err=repository->StartTransaction(CRepository::EReadWriteTransaction);
       
   719  	TEST2(err,KErrNone);
       
   720 
       
   721  	//--------------Create follow by delete-----------------------------
       
   722   	err=repository->Create(3400,3400);
       
   723  	TEST2(err,KErrNone);
       
   724  	err=repository->Delete(3400);
       
   725  	TEST2(err,KErrNone);
       
   726  	err=repository->Delete(3400);
       
   727  	TEST2(err,KErrNotFound);
       
   728 
       
   729 	//--------------Deleting existing romkey-----------------------------
       
   730   	err=repository->Delete(200);
       
   731   	TEST2(err,KErrNone);
       
   732 
       
   733    	err=repository->FindL(200,0xFFFFFFFF,idArray);
       
   734   	TEST2(err,KErrNotFound);
       
   735 
       
   736  	//--------------Commit Transaction------------------------------------
       
   737    	TUint32 errId;
       
   738    	err=repository->CommitTransaction(errId);
       
   739    	TEST2(err,KErrNone);
       
   740 
       
   741   	idArray.Close();
       
   742    	CleanupStack::PopAndDestroy(repository);
       
   743 
       
   744 	//--------------Reopen and check the deleted keys are gone-------------
       
   745    	User::LeaveIfNull(repository = CRepository::NewLC(testUid));
       
   746 
       
   747 	//Check for the key created and deleted during transaction
       
   748 	err=repository->FindL(3400,0xFFFFFFFF,idArray);
       
   749 	TEST2(err,KErrNotFound);
       
   750 
       
   751 	//Check for the rom key deleted during transaction
       
   752    	err=repository->Get(200,retValue);
       
   753 	TEST2(err,KErrNotFound);
       
   754 
       
   755 	//--------------Start Transaction------------------------------------
       
   756  	err=repository->StartTransaction(CRepository::EReadWriteTransaction);
       
   757  	TEST2(err,KErrNone);
       
   758 
       
   759  	//--------------Delete follow by create-----------------------------
       
   760   	err=repository->Delete(201);
       
   761  	TEST2(err,KErrNone);
       
   762  	err=repository->Create(201, 201);
       
   763  	TEST2(err,KErrNone);
       
   764 
       
   765  	//--------------Commit Transaction------------------------------------
       
   766    	err=repository->CommitTransaction(errId);
       
   767    	TEST2(err,KErrNone);
       
   768 
       
   769 	err=repository->Get(201,retValue);
       
   770 	TEST2(err,KErrNone);
       
   771 	TEST2(retValue, 201);
       
   772 
       
   773  	CleanupStack::PopAndDestroy(repository);
       
   774    	}
       
   775 
       
   776 LOCAL_C void DEF057522L()
       
   777 	{
       
   778 	TInt r=KErrNone;
       
   779 	CRepository* repository;
       
   780 	TUid testUidRepository={0x10057522};
       
   781 
       
   782 	//Opening a repository with Max number of capabilities supported should not return KErrCorrupt
       
   783 	User::LeaveIfNull(repository = CRepository::NewLC(testUidRepository));
       
   784 
       
   785 	//Test reading some of the settings with the max capabilities defined
       
   786 	TInt retVal=0;
       
   787 	r=repository->Get(17,retVal);
       
   788 	TEST2(r,KErrNone);
       
   789 	r=repository->Set(17,retVal);
       
   790 	TEST2(r,KErrNone);
       
   791 
       
   792 	r=repository->Get(18,retVal);
       
   793 	TEST2(r,KErrPermissionDenied);
       
   794 	r=repository->Set(18,retVal);
       
   795 	TEST2(r,KErrNone);
       
   796 
       
   797 	//Test that AlwaysPass and AlwaysFail behave as expected when not followed by sid
       
   798 	r=repository->Get(21,retVal);
       
   799 	TEST2(r,KErrPermissionDenied);
       
   800 	r=repository->Set(21,retVal);
       
   801 	TEST2(r,KErrPermissionDenied);
       
   802 	r=repository->Get(22,retVal);
       
   803 	TEST2(r,KErrNone);
       
   804 	r=repository->Set(22,retVal);
       
   805 	TEST2(r,KErrNone);
       
   806 
       
   807 
       
   808 	//Test that AlwaysPass and AlwaysFail behave as expected when followed by sid
       
   809 	r=repository->Get(19,retVal);
       
   810 	TEST2(r,KErrPermissionDenied);
       
   811 	r=repository->Set(19,retVal);
       
   812 	TEST2(r,KErrNone);
       
   813 
       
   814 	//Additional test cases
       
   815 	//Test single policies with max 3 caps for both read and write
       
   816 	r=repository->Get(28,retVal);
       
   817 	TEST2(r,KErrPermissionDenied);
       
   818 	r=repository->Set(28,retVal);
       
   819 	TEST2(r,KErrNone);
       
   820 
       
   821 	//Test single policies with max 7 caps for both read and write
       
   822 	r=repository->Get(33,retVal);
       
   823 	TEST2(r,KErrPermissionDenied);
       
   824 	r=repository->Set(33,retVal);
       
   825 	TEST2(r,KErrPermissionDenied);
       
   826 
       
   827 	//Test range policies with max 3 caps when followed by sid
       
   828 	r=repository->Get(201,retVal);
       
   829 	TEST2(r,KErrPermissionDenied);
       
   830 	r=repository->Set(201,retVal);
       
   831 	TEST2(r,KErrNone);
       
   832 
       
   833 	//Test range policies with max 7 caps not with sid
       
   834 	r=repository->Get(300,retVal);
       
   835 	TEST2(r,KErrPermissionDenied);
       
   836 	r=repository->Set(300,retVal);
       
   837 	TEST2(r,KErrPermissionDenied);
       
   838 
       
   839 	//Test behaviour when single policies are specified with just sid
       
   840 	r=repository->Get(400,retVal);
       
   841 	TEST2(r,KErrNone);
       
   842 	r=repository->Set(400,retVal);
       
   843 	TEST2(r,KErrPermissionDenied);		// default read cap for sid 0 is AlwaysFail
       
   844 
       
   845 	r=repository->Get(401,retVal);
       
   846 	TEST2(r,KErrNone);					// default write cap for sid 0 is AlwaysPass
       
   847 	r=repository->Set(401,retVal);
       
   848 	TEST2(r,KErrNone);
       
   849 
       
   850 	//Test that default policies are picked up when no policies are specified
       
   851 	r=repository->Get(500,retVal);
       
   852 	TEST2(r,KErrNone);
       
   853 
       
   854 	r=repository->Set(500,retVal);
       
   855 	TEST2(r,KErrPermissionDenied);
       
   856 
       
   857 	CleanupStack::PopAndDestroy(repository);
       
   858 	}
       
   859 
       
   860 LOCAL_C void DEF057470L()
       
   861 	{
       
   862 
       
   863 	TInt r=KErrNone;
       
   864 	TUint32 errId=0;
       
   865 	CRepository* repository;
       
   866 
       
   867 	User::LeaveIfNull(repository = CRepository::NewLC(KUidDEF057470TestRepository));
       
   868 
       
   869 	//-------------- 1. Simple Range Delete Operation-----------------------------
       
   870 	// Confirm that keys exist
       
   871 	RArray<TUint32> foundIds;
       
   872 	r = repository->FindL(KRangeDeletePartialKey, KRangeDeleteMask, foundIds);
       
   873 	TEST2(r, KErrNone);
       
   874 	TEST(foundIds.Count()==5);
       
   875 	foundIds.Reset();
       
   876 	// Delete a set of keys
       
   877 	r = repository->Delete(KRangeDeletePartialKey, KRangeDeleteMask, errId) ;
       
   878 	TEST2(r, KErrNone);
       
   879 	// Confirm that deleted keys do not exist
       
   880 	r = repository->FindL(KRangeDeletePartialKey, KRangeDeleteMask, foundIds);
       
   881 	TEST2(r, KErrNotFound);
       
   882 	TEST(foundIds.Count()==0);
       
   883 	foundIds.Reset();
       
   884 	CleanupStack::PopAndDestroy(repository);
       
   885 	// Try to find keys again just to double check whether the changes have persisted
       
   886 	User::LeaveIfNull(repository = CRepository::NewLC(KUidDEF057470TestRepository));
       
   887 	r = repository->FindL(KRangeDeletePartialKey, KRangeDeleteMask, foundIds);
       
   888 	TEST2(r, KErrNotFound);
       
   889 	TEST(foundIds.Count()==0);
       
   890 	foundIds.Reset();
       
   891 
       
   892 
       
   893 	//--------------- 2. Range Delete Operation where keys don't exist--------------
       
   894 	// Confirm that keys don't exist.
       
   895 	r = repository->FindL(KDeleteKeyDoesntExist, KRangeDeleteMask, foundIds);
       
   896 	TEST2(r, KErrNotFound);
       
   897 	TEST(foundIds.Count()==0);
       
   898 	foundIds.Reset();
       
   899 	// Attempt delete and check result
       
   900 	r = repository->Delete(KDeleteKeyDoesntExist, KRangeDeleteMask, errId) ;
       
   901 	TEST2(r, KErrNotFound);
       
   902 	errId &= KRangeDeleteMask ;
       
   903 	TEST2(errId, KDeleteKeyDoesntExist) ;
       
   904 
       
   905 
       
   906 	//-------3. Range Delete Operation where client doesn't have write capabilities for key range.----
       
   907 	// Attempt delete and check result
       
   908 	r = repository->Delete(KDeleteForbidden, KRangeDeleteMask, errId) ;
       
   909 	TEST2(r, KErrPermissionDenied);
       
   910 	errId &= KRangeDeleteMask ;
       
   911 	TEST2(errId, KDeleteForbidden) ;
       
   912 	// Close repository
       
   913 	CleanupStack::PopAndDestroy(repository);
       
   914 
       
   915 	//------ 4. Range Delete Operation which deletes all the keys and Resets the entire repository back its original state.
       
   916 	TInt numberOfIds;
       
   917 	User::LeaveIfNull(repository = CRepository::NewLC(KUidLargeRepository));
       
   918 	// Find how many keys are originally present
       
   919 	r = repository->FindL(KNullKey, KNullKey, foundIds);
       
   920 	TEST2(r, KErrNone);
       
   921 	numberOfIds = foundIds.Count();
       
   922 	TEST(foundIds.Count()!=0);
       
   923 	foundIds.Reset();
       
   924 	// Range delete all the keys in the repository
       
   925 	r = repository->Delete(KNullKey, KNullKey, errId);
       
   926 	TEST2(r, KErrNone);
       
   927 	// Check all the keys have been deleted from cache
       
   928 	r = repository->FindL(KNullKey, KNullKey, foundIds);
       
   929 	TEST2(r, KErrNotFound);
       
   930 	TEST(foundIds.Count()==0);
       
   931 	foundIds.Reset();
       
   932 	// Close and re-open the repository to check if the deleted keys have persisted.
       
   933 	CleanupStack::PopAndDestroy(repository);	
       
   934 	// Existance of caching functionality invalidates some tests and
       
   935 	// makes them fail, so kill the server to force clearing the cache
       
   936 	r = KillProcess(KCentralRepositoryServerName);
       
   937 	TEST2(r,KErrNone);
       
   938 	User::LeaveIfNull(repository = CRepository::NewLC(KUidLargeRepository));
       
   939 	// Check all the deleted keys have persisted.
       
   940 	r = repository->FindL(KNullKey, KNullKey, foundIds);
       
   941 	TEST2(r, KErrNotFound);
       
   942 	TEST(foundIds.Count()==0);
       
   943 	foundIds.Reset();
       
   944 	// Reset repository back to its original state from ROM
       
   945 	r = repository->Reset();
       
   946 	TEST2(r, KErrNone);
       
   947 	// Check that number of keys is same as when we started.
       
   948 	r = repository->FindL(KNullKey, KNullKey, foundIds);
       
   949 	TEST2(r, KErrNone);
       
   950 	TEST(foundIds.Count()==numberOfIds);
       
   951 	foundIds.Reset();
       
   952 	// Close the repository
       
   953 	CleanupStack::PopAndDestroy(repository);
       
   954 
       
   955 	//**********************Delete Range within Transacrions**********************
       
   956 	//--------- 5. Range Delete within a transaction where key's don't exist.------------
       
   957 	User::LeaveIfNull(repository = CRepository::NewLC(KUidDEF057470TestRepository));
       
   958 	// Begin read write transaction.
       
   959 	r = repository->StartTransaction(CRepository::EReadWriteTransaction);
       
   960 	TEST2(r, KErrNone);
       
   961 	r = TransactionState(repository);
       
   962 	TEST2(r, EReadWriteTransaction);
       
   963 	r = repository->Delete(KDeleteKeyDoesntExist, KRangeDeleteMask, errId) ;
       
   964 	TEST2(r, KErrNotFound);
       
   965 	// Check that transaction hasn't failed.
       
   966 	r = TransactionState(repository);
       
   967 	TEST2(r, EReadWriteTransaction);
       
   968 	// Fail transaction.
       
   969 	repository->FailTransaction();
       
   970 	r = TransactionState(repository);
       
   971 	TEST2(r, EReadWriteTransaction | EFailedBit);
       
   972 	repository->RollbackTransaction();
       
   973 	r = TransactionState(repository);
       
   974 	TEST2(r, ENoTransaction);
       
   975 
       
   976 
       
   977 	//---------- 6. Range delete within a transaction where client doesn't have capabilities to write to key range.
       
   978 	// Begin read write transaction.
       
   979 	r = repository->StartTransaction(CRepository::EReadWriteTransaction);
       
   980 	TEST2(r, KErrNone);
       
   981 	r = repository->Delete(KDeleteForbidden, KRangeDeleteMask, errId) ;
       
   982 	TEST2(r, KErrPermissionDenied);
       
   983 	errId &= KRangeDeleteMask ;
       
   984 	TEST2(errId, KDeleteForbidden) ;
       
   985 	// check that transaction has failed.
       
   986 	r = TransactionState(repository);
       
   987 	TEST2(r, EReadWriteTransaction | EFailedBit);
       
   988 	// Rollback the failed transaction.
       
   989 	repository->RollbackTransaction();
       
   990 	r = TransactionState(repository);
       
   991 	TEST2(r, ENoTransaction);
       
   992 
       
   993 
       
   994 	//---------- 7. Range delete while not in transaction fails other session's transaction with KErrLocked.
       
   995 	// Open another repository
       
   996 	CRepository* repository2;
       
   997 	User::LeaveIfNull(repository2 = CRepository::NewLC(KUidDEF057470TestRepository));
       
   998 	// Begin read write transaction
       
   999 	r = repository->StartTransaction(CRepository::EReadWriteTransaction);
       
  1000 	TEST2(r, KErrNone);
       
  1001 	r = TransactionState(repository);
       
  1002 	TEST2(r, EReadWriteTransaction);
       
  1003 	// Delete keys in the first session.
       
  1004 	r = repository->Delete(KTransactionRangeDeletePartialKey, KRangeDeleteMask, errId) ;
       
  1005 	TEST2(r, KErrNone);
       
  1006 	// Delete keys in the second session.
       
  1007 	r = repository2->Delete(KTransactionRangeDeletePartialKey, KRangeDeleteMask, errId) ;
       
  1008 	TEST2(r, KErrNone);
       
  1009 	// first session's transaction should have failed with KErrLocked
       
  1010 	TInt state = TransactionState(repository);
       
  1011 	TEST2(state, EReadWriteTransaction | EFailedBit);
       
  1012 	// Commit transaction should report failure reason:
       
  1013 	TUint32 keyInfo;
       
  1014 	r = repository->CommitTransaction(keyInfo);
       
  1015 	TEST2(r, KErrLocked);
       
  1016 	TEST(keyInfo == KUnspecifiedKey);
       
  1017 	r = TransactionState(repository);
       
  1018 	TEST2(r, ENoTransaction);
       
  1019 	// Close the repositories
       
  1020 	CleanupStack::PopAndDestroy(repository2);
       
  1021 
       
  1022 
       
  1023 	//----------- 8. Range Delete within a Transaction and Commit.-----------------------
       
  1024 	//Before doing this we need to reset from the ROM first to restore the deleted keys in
       
  1025 	//non transaction test earlier
       
  1026 	r=repository->Reset();
       
  1027 	TEST2(r,KErrNone);
       
  1028 	r = repository->FindL(KRangeDeletePartialKey, KRangeDeleteMask, foundIds);
       
  1029 	TEST2(r,KErrNone);
       
  1030 	TEST(foundIds.Count()==5);
       
  1031 	foundIds.Reset();
       
  1032 	// Begin read write transaction
       
  1033 	r = repository->StartTransaction(CRepository::EReadWriteTransaction);
       
  1034 	TEST2(r, KErrNone);
       
  1035 	r = repository->Delete(KTransactionRangeDeletePartialKey, KRangeDeleteMask, errId) ;
       
  1036 	TEST2(r, KErrNone);
       
  1037 	// Commit transaction
       
  1038 	r = repository->CommitTransaction(errId);
       
  1039 	TEST2(r, KErrNone);
       
  1040 	//The number of keys changed should be equal to the number of keys deleted
       
  1041 	TEST(errId==5);
       
  1042 
       
  1043 	//Reset repository to remove any changes made during this test
       
  1044 	r=repository->Reset();
       
  1045 	TEST2(r, KErrNone);
       
  1046 
       
  1047 	// Close the repositories
       
  1048 	CleanupStack::PopAndDestroy(repository);
       
  1049 	}
       
  1050 
       
  1051 LOCAL_C void INC058229L()
       
  1052 	{
       
  1053 	RFs fs;
       
  1054 	User::LeaveIfError(fs.Connect());
       
  1055 	CleanupClosePushL(fs);
       
  1056 
       
  1057 	CFileMan* fm = CFileMan::NewL(fs);
       
  1058 	CleanupStack::PushL(fm);
       
  1059 
       
  1060 	// Open repository to ensure server is running
       
  1061 	CRepository* rep;
       
  1062 	User::LeaveIfNull(rep = CRepository::NewLC(KUidLargeRepository));
       
  1063 	// Close repository
       
  1064 	CleanupStack::PopAndDestroy(rep);
       
  1065 
       
  1066 	// Remove install dir
       
  1067 	TInt r = fm->RmDir(KCInstallDir);
       
  1068 	if(r!=KErrNone && r!=KErrNotFound && r!=KErrPathNotFound)
       
  1069 		User::Leave(r);
       
  1070 	// Wait so that watcher will see directory is gone
       
  1071 	User::After(KGeneralDelay);
       
  1072 
       
  1073 	// Kill server so that next test will reconnect and recreate resources
       
  1074 	r=KillProcess(KCentralRepositoryServerName);
       
  1075 	TEST2(r,KErrNone);
       
  1076 
       
  1077 	// Open repository to ensure directories are restored
       
  1078 	User::LeaveIfNull(rep = CRepository::NewLC(KUidLargeRepository));
       
  1079 	// Close repository
       
  1080 	CleanupStack::PopAndDestroy(3);	// rep, fs, fm
       
  1081 	}
       
  1082 
       
  1083 LOCAL_C void DEF058900L()
       
  1084 	{
       
  1085 
       
  1086 	CRepository* repository;
       
  1087 	User::LeaveIfNull(repository = CRepository::NewLC(KUidDEF058900TestRepository));
       
  1088 	TRequestStatus intStatus;
       
  1089 	RThread thisThread;
       
  1090 
       
  1091 	//
       
  1092 	// Basic notification to test notification for one banned key
       
  1093 	//
       
  1094 	TInt r = repository->NotifyRequest(KNotifyBannedKey, intStatus);
       
  1095 	TEST2(r, KErrNone);
       
  1096 	TEST(intStatus == KRequestPending);
       
  1097 
       
  1098 	// First change to setting should cause notification
       
  1099 	r = repository->Set(KNotifyBannedKey, 100);
       
  1100 	TEST2(r, KErrNone);
       
  1101 	User::WaitForAnyRequest();
       
  1102 	TEST(intStatus==KUnspecifiedKey);
       
  1103 
       
  1104 	//
       
  1105 	// Group notification to test notification when the banned key is in a range
       
  1106 	//
       
  1107 	r = repository->NotifyRequest(KNullKey, KNullKey, intStatus);
       
  1108 	TEST2(r, KErrNone);
       
  1109 
       
  1110 	r = repository->Set(KNotifyBannedKey, 50);
       
  1111 	TEST2(r, KErrNone);
       
  1112 	User::WaitForAnyRequest();
       
  1113 	TEST(intStatus==KUnspecifiedKey);
       
  1114 	TEST(thisThread.RequestCount()==0);
       
  1115 
       
  1116 	//
       
  1117 	// Group notification to test notification when many keys including the banned key change
       
  1118 	// i.e. a repository wide reset
       
  1119 	//
       
  1120 	// First change values for alot of the keys before a reset.
       
  1121 	r = repository->Set(KNotificationKey1, 80);
       
  1122 	TEST2(r, KErrNone);
       
  1123 	r = repository->Set(KNotifyBannedKey, 50);
       
  1124 	TEST2(r, KErrNone);
       
  1125 	r = repository->Set(KNotificationKey2, 70);
       
  1126 	TEST2(r, KErrNone);
       
  1127 	r = repository->Set(KNotificationKey3, 60);
       
  1128 	TEST2(r, KErrNone);
       
  1129 	r = repository->Set(KNotificationKey4, 30);
       
  1130 	TEST2(r, KErrNone);
       
  1131 
       
  1132 	r = repository->NotifyRequest(KNullKey, KNullKey, intStatus); // Request notification
       
  1133 																  // for all keys in repository.
       
  1134 	TEST2(r, KErrNone);
       
  1135 
       
  1136 	//Reset the whole repository to original settings
       
  1137 	r = repository->Reset();
       
  1138 	TEST2(r, KErrNone);
       
  1139 
       
  1140 	User::WaitForAnyRequest();
       
  1141 	TEST(intStatus==KUnspecifiedKey);
       
  1142 	TEST(thisThread.RequestCount()==0);
       
  1143 
       
  1144 
       
  1145 	CleanupStack::PopAndDestroy(repository);
       
  1146 	}
       
  1147 
       
  1148 LOCAL_C void DEF061087L()
       
  1149 	{
       
  1150 	TInt r=KErrNone;
       
  1151 	TUid testUid={0x10061087};
       
  1152 	CRepository* repository;
       
  1153 	User::LeaveIfNull(repository = CRepository::NewLC(testUid));
       
  1154 
       
  1155 	/*--------------Scenario 1---------------------
       
  1156 	100 300 cap_wr=ReadDeviceData
       
  1157 	100 200 cap_wr=TCB */
       
  1158 	r=repository->Create(150,100);
       
  1159 	TEST2(r,KErrPermissionDenied);
       
  1160 	r=repository->Create(201,201);
       
  1161 	TEST2(r,KErrNone);
       
  1162 
       
  1163 	/*--------------Scenario 2---------------------
       
  1164 	400 500 cap_wr=ReadDeviceData
       
  1165 	400 500 cap_wr=TCB */
       
  1166 	r=repository->Create(500,100);
       
  1167 	TEST2(r,KErrPermissionDenied);
       
  1168 
       
  1169 	/*--------------Scenario 3---------------------
       
  1170 	0x600 0x700 cap_wr=ReadDeviceData
       
  1171 	# Odd entry from 600-700
       
  1172 	0x601 mask=0xF01 cap_wr=TCB*/
       
  1173 	r=repository->Create(0x601,601);
       
  1174 	TEST2(r,KErrPermissionDenied);
       
  1175 	r=repository->Create(0x657,647);
       
  1176 	TEST2(r,KErrPermissionDenied);
       
  1177 	//0x602 will be even so it will check agains the next matched range policies
       
  1178 	//which is 0x600 0x700 cap_wr=ReadDeviceData
       
  1179 	r=repository->Create(0x602,600);
       
  1180 	TEST2(r,KErrNone);
       
  1181 
       
  1182 	/*--------------Scenario 4---------------------
       
  1183 	# protected data
       
  1184 	0x00000100 mask=0x00000100 cap_wr=NetworkControl
       
  1185 	# private data
       
  1186 	0x000000F0 mask=0x00000080 cap_rd=ReadDeviceData */
       
  1187 	r=repository->Create(0x01000100,123);
       
  1188 	TEST2(r,KErrPermissionDenied);
       
  1189 	r=repository->Create(0x03450700,123);
       
  1190 	TEST2(r,KErrPermissionDenied);
       
  1191 	r=repository->Create(0x00450080,123);
       
  1192 	TEST2(r,KErrNone);
       
  1193 	r=repository->Create(0x06450081,123);
       
  1194 	TEST2(r,KErrNone);
       
  1195 
       
  1196 
       
  1197 	CleanupStack::PopAndDestroy(repository);
       
  1198 	}
       
  1199 
       
  1200 
       
  1201 LOCAL_C void DEF060843L()
       
  1202     {
       
  1203     CRepository* repository;
       
  1204 	User::LeaveIfNull(repository = CRepository::NewLC(KUidDEF060843LRepository1));
       
  1205 
       
  1206     _LIT8(KString12_InitialValue, "string");
       
  1207     TPtrC8 p8(KString12_InitialValue);
       
  1208     TInt len8 = p8.Length();
       
  1209 
       
  1210     _LIT(KString11_InitialValue, "string");
       
  1211     TPtrC p16(KString11_InitialValue);
       
  1212     TInt len16 = p16.Length();
       
  1213 
       
  1214     //setting ids in a test repository
       
  1215     const TUint32 KReal1 = 2;
       
  1216     const TUint32 KString11 = 11;
       
  1217     const TUint32 KString12 = 12;
       
  1218 
       
  1219     TInt r;
       
  1220     TInt i(0);
       
  1221 
       
  1222     TBuf<15> str;
       
  1223 	TInt strLen;
       
  1224 
       
  1225 	TBuf8<15> str8;
       
  1226 	TInt strLen8;
       
  1227 
       
  1228     //================read real using int ========================
       
  1229     r = repository->Get(KReal1, i);
       
  1230 	TEST2(r, KErrArgument);
       
  1231 	TEST(i==0);
       
  1232 
       
  1233 	//================read TDes16 using TDes8=====================
       
  1234     r = repository->Get(KString11, str8);
       
  1235 	TEST2(r, KErrNone);
       
  1236 
       
  1237 	//8-bit descriptor holding the same data as 16-bit descriptor
       
  1238 	//should twice as long as 16-bit des.
       
  1239 	strLen8 = str8.Length();
       
  1240 	TEST2(strLen8,len16*2);
       
  1241 
       
  1242     const TUint16* p16a  = (TUint16*)str8.Ptr();
       
  1243     const TUint16* p16b = p16.Ptr();
       
  1244     //compares content of descriptors byte by byte
       
  1245     r = Mem::Compare(p16a,strLen8/2,p16b,len16);
       
  1246     TEST2(r,KErrNone);
       
  1247 
       
  1248     //=================read TDes8 using TDes16=====================
       
  1249     r = repository->Get(KString12, str);
       
  1250     TEST2(r, KErrNone);
       
  1251 
       
  1252     //16-bit descriptor holding the same data as 8-bit descriptor
       
  1253     //should be half a length of a 8-bit desc
       
  1254     strLen = str.Length();
       
  1255     TEST2(strLen,len8/2);
       
  1256 
       
  1257 	const TUint8* p8a = (TUint8*)str.Ptr();
       
  1258     const TUint8* p8b = p8.Ptr();
       
  1259     //compares content of descriptors byte by byte
       
  1260     r = Mem::Compare(p8a,strLen*2,p8b,len8);
       
  1261     TEST2(r,KErrNone);
       
  1262 
       
  1263 	//================writting to TDes16 using TDes8===============
       
  1264 	r = repository->Set(KString11,KString12_InitialValue);
       
  1265 	TEST2(r, KErrNone);
       
  1266 	CleanupStack::PopAndDestroy(repository);
       
  1267 	User::LeaveIfNull(repository = CRepository::NewLC(KUidDEF060843LRepository1));
       
  1268 	r = repository->Get(KString11, str8);
       
  1269 	strLen8 = str8.Length();
       
  1270 	TEST2(strLen8,len8);
       
  1271 	TEST(str8==KString12_InitialValue);
       
  1272 
       
  1273 	//================writting to TDes8 using TDes16===============
       
  1274 	r = repository->Set(KString12,KString11_InitialValue);
       
  1275 	TEST2(r, KErrNone);
       
  1276 	CleanupStack::PopAndDestroy(repository);
       
  1277 	User::LeaveIfNull(repository = CRepository::NewLC(KUidDEF060843LRepository1));
       
  1278 	r = repository->Get(KString12, str);
       
  1279 	strLen = str.Length();
       
  1280 	TEST2(strLen,len16);
       
  1281 	TEST(str==KString11_InitialValue);
       
  1282     CleanupStack::PopAndDestroy(repository);
       
  1283 	}
       
  1284 
       
  1285 /**
       
  1286 @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-1433
       
  1287 @SYMTestCaseDesc Central repository panics the client when trying to read 8-bit descriptor with uneven length
       
  1288 @SYMTestPriority High
       
  1289 @SYMTestActions  Read 8-bit descriptor with uneven length
       
  1290 @SYMTestExpectedResults The test must not fail or panic .
       
  1291 @SYMDEF INC069013
       
  1292 */
       
  1293 LOCAL_C void INC069013L()
       
  1294 	{
       
  1295 	CRepository* repository;
       
  1296 	User::LeaveIfNull(repository = CRepository::NewLC(KUidINC069013TestRepository));
       
  1297 
       
  1298 	_LIT(KString16, "16BitString");
       
  1299 	_LIT8(KString8Odd, "8BitOddString");
       
  1300 	_LIT8(KString8Even, "8BitEvenString");
       
  1301 
       
  1302 	const TUint32 KString16ID = 1;
       
  1303 	const TUint32 KString8OddID = 2;
       
  1304 	const TUint32 KString8EvenID = 3;
       
  1305 
       
  1306 	TBuf<20> buf;
       
  1307 	TInt r = KErrNone;
       
  1308 	TInt actualLength = 0;
       
  1309 
       
  1310 	//test for string stored as 16 bit
       
  1311 	r = repository->Get(KString16ID, buf);
       
  1312 	TEST2(r, KErrNone);
       
  1313 
       
  1314 	r = repository->Get(KString16ID, buf, actualLength);
       
  1315 	TEST2(r, KErrNone);
       
  1316 	TEST2(actualLength, KString16().Length());
       
  1317 
       
  1318 	//test for string stored as 8 bit with odd length
       
  1319 	r = repository->Get(KString8OddID, buf);
       
  1320 	TEST2(r, KErrNone);
       
  1321 
       
  1322 	r = repository->Get(KString8OddID, buf, actualLength);
       
  1323 	TEST2(r, KErrNone);
       
  1324 	TEST2(actualLength, (KString8Odd().Length() + 1) / 2);
       
  1325 
       
  1326 	//test for string stored as 8 bit with even length
       
  1327 	r = repository->Get(KString8EvenID, buf);
       
  1328 	TEST2(r, KErrNone);
       
  1329 
       
  1330 	r = repository->Get(KString8EvenID, buf, actualLength);
       
  1331 	TEST2(r, KErrNone);
       
  1332 	TEST2(actualLength, (KString8Even().Length() + 1) / 2);
       
  1333 
       
  1334 	CleanupStack::PopAndDestroy(repository);
       
  1335 	}
       
  1336 
       
  1337 /**
       
  1338 @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-1434
       
  1339 @SYMTestCaseDesc Central repository doesn't handle corrupt .cre files correctly.
       
  1340 @SYMTestPriority High
       
  1341 @SYMTestActions  Open corrupt files from ROM and persists
       
  1342 @SYMTestExpectedResults The test must not fail.
       
  1343 @SYMDEF DEF070731
       
  1344 */
       
  1345 const TUid KUidCorruptEOF = { 0x00000e0f };
       
  1346 const TUid KUidCorrupt    = { 0x00000bad };
       
  1347 
       
  1348 _LIT(KCRep1File,                                "c:\\private\\10202BE9\\persists\\00000100.cre");
       
  1349 _LIT(KZCorruptEOFFile,                          "z:\\private\\10202BE9\\00000e0f.cre");
       
  1350 _LIT(KZCorruptFile,                             "z:\\private\\10202BE9\\00000bad.cre");
       
  1351 
       
  1352 LOCAL_C void DEF070731L()
       
  1353 	{
       
  1354 	RFs fs;
       
  1355 	User::LeaveIfError(fs.Connect());
       
  1356 	CleanupClosePushL(fs);
       
  1357 
       
  1358 	CFileMan* fm = CFileMan::NewL(fs);
       
  1359 	CleanupStack::PushL(fm);
       
  1360 
       
  1361 	CRepository* rep;
       
  1362 
       
  1363 	// Open ROM cre file with EOF corruption
       
  1364 	TheTest.Printf(_L("\nOpen ROM cre file with EOF corruption\n"));
       
  1365 	TRAPD(errH, rep=CRepository::NewLC(KUidCorruptEOF));
       
  1366 	TEST2(errH, KErrCorrupt);
       
  1367 
       
  1368 	// Open corrupt ROM file
       
  1369 	TheTest.Printf(_L("\nOpen corrupt ROM file\n"));
       
  1370 	TRAPD(errS,rep=CRepository::NewLC(KUidCorrupt));
       
  1371 	TEST2(errS, KErrCorrupt);
       
  1372 
       
  1373 	// Edit repos with new setting
       
  1374 	TheTest.Printf(_L("\nEdit repos with new setting\n"));
       
  1375 	User::LeaveIfNull(rep = CRepository::NewLC(KUidRep1));
       
  1376 	TInt r = rep->Create(KNewInt, KIntValue);
       
  1377 	TEST2(r, KErrNone);
       
  1378 	CleanupStack::PopAndDestroy(rep);
       
  1379 
       
  1380 	// Reopen repos to read from persists file
       
  1381 	User::LeaveIfNull(rep = CRepository::NewLC(KUidRep1));
       
  1382 	TInt newInt;
       
  1383 	r=rep->Get(KNewInt, newInt);
       
  1384 	TEST2(r, KErrNone);
       
  1385 	CleanupStack::PopAndDestroy(rep);
       
  1386 
       
  1387 	// Existance of caching functionality invalidates some tests and
       
  1388 	// makes them fail, so kill the server to force clearing the cache
       
  1389 	r=KillProcess(KCentralRepositoryServerName);
       
  1390 	TEST2(r,KErrNone);
       
  1391 
       
  1392 	// Copy corrupt EOF file into persists
       
  1393 	TheTest.Printf(_L("\nCopy corrupt EOF file into persists dir\n"));
       
  1394 	User::LeaveIfError(fm->Copy(KZCorruptEOFFile, KCRep1File));
       
  1395 	// Reset read-only bit
       
  1396 	User::LeaveIfError(fm->Attribs(KCRep1File,0,KEntryAttReadOnly,TTime(0)));
       
  1397 	User::After(KGeneralDelay);
       
  1398 	// Open repos, should find corrupt file and use ROM file
       
  1399 	User::LeaveIfNull(rep = CRepository::NewLC(KUidRep1));
       
  1400 	// If we can't find KNewInt, this proves that we are using ROM file
       
  1401 	r=rep->Get(KNewInt, newInt);
       
  1402 	TEST2(r, KErrNotFound);
       
  1403 	// Test that persists file is deleted
       
  1404 	TheTest.Printf(_L("\nCheck corrupt EOF file deleted from persists dir\n"));
       
  1405 	TEST2 (BaflUtils::FileExists (fs, KCRep1File), EFalse);
       
  1406 	// Close repository
       
  1407 	CleanupStack::PopAndDestroy(rep);
       
  1408 
       
  1409 	// Existance of caching functionality invalidates some tests and
       
  1410 	// makes them fail, so kill the server to force clearing the cache
       
  1411 	r=KillProcess(KCentralRepositoryServerName);
       
  1412 	TEST2(r,KErrNone);
       
  1413 
       
  1414 	// Copy corrupt file into persists
       
  1415 	TheTest.Printf(_L("\nCopy corrupt file into persists dir\n"));
       
  1416 	User::LeaveIfError(fm->Copy(KZCorruptFile, KCRep1File));
       
  1417 	// Reset read-only bit
       
  1418 	User::LeaveIfError(fm->Attribs(KCRep1File,0,KEntryAttReadOnly,TTime(0)));
       
  1419 	User::After(KGeneralDelay);
       
  1420 	// Open repos, should find corrupt file and use ROM file
       
  1421 	User::LeaveIfNull(rep = CRepository::NewLC(KUidRep1));
       
  1422 	// Test that file is deleted
       
  1423 	TheTest.Printf(_L("\nCheck corrupt file deleted from persists dir\n"));
       
  1424 	TEST2 (BaflUtils::FileExists (fs, KCRep1File), EFalse);
       
  1425 
       
  1426 	// Close repository
       
  1427 	CleanupStack::PopAndDestroy(3);// rep, fs,fm
       
  1428 
       
  1429 	}
       
  1430 
       
  1431 // Helper function for DEF084700L
       
  1432 LOCAL_C void ConnectAndCommitSuicideL(void)
       
  1433 	{
       
  1434 	CRepository* repository;
       
  1435 	User::LeaveIfNull(repository = CRepository::NewLC(KUidDEF060843LRepository1));
       
  1436 
       
  1437 	RThread currentThread;
       
  1438 	currentThread.Kill(KErrDied);
       
  1439 
       
  1440 	// Should never get executed
       
  1441 	CleanupStack::PopAndDestroy(repository);
       
  1442 	}
       
  1443 
       
  1444 // Helper function for DEF084700L
       
  1445 LOCAL_C TInt SuicidalThread(TAny*)
       
  1446 	{
       
  1447 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
  1448 	if(!cleanup)
       
  1449 		return KErrNoMemory;
       
  1450 
       
  1451 	TRAP_IGNORE(ConnectAndCommitSuicideL());
       
  1452 
       
  1453 	// Should never get executed
       
  1454 	delete cleanup;
       
  1455 	return KErrNone;
       
  1456 	}
       
  1457 
       
  1458 // Helper function for DEF084700L
       
  1459 LOCAL_C void ConnectAndDisconnectL(void)
       
  1460 	{
       
  1461 	CRepository* repository;
       
  1462 	User::LeaveIfNull(repository = CRepository::NewLC(KUidDEF060843LRepository1));
       
  1463 
       
  1464 	CleanupStack::PopAndDestroy(repository);
       
  1465 	}
       
  1466 
       
  1467 // Helper function for DEF084700L
       
  1468 LOCAL_C TInt WellBehavedThread(TAny*)
       
  1469 	{
       
  1470 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
  1471 	if(!cleanup)
       
  1472 		return KErrNoMemory;
       
  1473 
       
  1474 	TRAP_IGNORE(ConnectAndDisconnectL());
       
  1475 
       
  1476 	delete cleanup;
       
  1477 	return KErrNone;
       
  1478 	}
       
  1479 
       
  1480 /**
       
  1481 @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-1683
       
  1482 @SYMTestCaseDesc UIF automated tests crash H4 board
       
  1483 @SYMTestPriority High
       
  1484 @SYMTestActions  Open a repository, create a thread, open same repository from that thread, kill the thread
       
  1485 				 before closing repository, update a setting from main body (trigger notifications). Do the same
       
  1486 				 thing for a thread which terminates normally for making sure the previous behaviour is maintained
       
  1487 @SYMTestExpectedResults The test must not panic or fail.
       
  1488 @SYMDEF DEF084700
       
  1489 */
       
  1490 LOCAL_C void DEF084700L()
       
  1491 	{
       
  1492 	CRepository* repository;
       
  1493 	User::LeaveIfNull(repository = CRepository::NewLC(KUidDEF060843LRepository1));
       
  1494 
       
  1495 	RThread testThread;
       
  1496 	_LIT(KThreadName1, "SuicidalTestThread");
       
  1497 
       
  1498 	testThread.Create(KThreadName1, SuicidalThread, KDefaultStackSize, KMinHeapSize, 0x100000, NULL);
       
  1499 
       
  1500 	TRequestStatus requestStatus;
       
  1501 	// Request notification when the thread kills itself
       
  1502 	testThread.Logon(requestStatus);
       
  1503 	// Let the thread execute
       
  1504 	testThread.Resume();
       
  1505 
       
  1506 	// Wait for suicide
       
  1507 	User::WaitForRequest(requestStatus);
       
  1508 	// Make sure it's dead
       
  1509 	TEST2(requestStatus.Int(), KErrDied);
       
  1510 
       
  1511 	const TUint32 KInt1 = 0x1;
       
  1512 	TInt i, r = KErrNone;
       
  1513 
       
  1514 	r = repository->Get(KInt1, i);
       
  1515 	TEST2(r, KErrNone);
       
  1516 	r = repository->Set(KInt1, i+1);
       
  1517 	// Fails here with KErrServerTerminated before fix because server crashes
       
  1518 	TEST2(r, KErrNone);
       
  1519 
       
  1520 	// Create another thread which accesses the repository but terminates normally
       
  1521 	_LIT(KThreadName2, "WellBehavedTestThread");
       
  1522 
       
  1523 	testThread.Create(KThreadName2, WellBehavedThread, KDefaultStackSize, KMinHeapSize, 0x100000, NULL);
       
  1524 
       
  1525 	// Request notification when the thread terminates normally
       
  1526 	testThread.Logon(requestStatus);
       
  1527 	// Let the thread execute
       
  1528 	testThread.Resume();
       
  1529 
       
  1530 	// Wait for old age
       
  1531 	User::WaitForRequest(requestStatus);
       
  1532 	// Make sure the cause of death is natural
       
  1533 	TEST2(requestStatus.Int(), KErrNone);
       
  1534 
       
  1535 	r = repository->Get(KInt1, i);
       
  1536 	TEST2(r, KErrNone);
       
  1537 	r = repository->Set(KInt1, i+1);
       
  1538 
       
  1539 	TEST2(r, KErrNone);
       
  1540 
       
  1541 	//Reset repository to remove any changes made during this test
       
  1542 	r = repository->Reset();
       
  1543 	TEST2(r, KErrNone);
       
  1544 
       
  1545 	CleanupStack::PopAndDestroy(repository);
       
  1546 	}
       
  1547 
       
  1548 /**
       
  1549 @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-1862
       
  1550 @SYMTestCaseDesc [AQP] CommitTransaction returns incorrect error code if Find~L methods run OOM
       
  1551 @SYMTestPriority High
       
  1552 @SYMTestActions  Open a repository, start a transaction, then simulate a OOM failure in a TRAPPED
       
  1553 				 FindL, this will result in client side error and this error should be the returned
       
  1554 				 error of CommitTransaction.
       
  1555 @SYMTestExpectedResults The test must not panic or fail.
       
  1556 @SYMDEF DEF089945
       
  1557 */
       
  1558 LOCAL_C void DEF089945L()
       
  1559 	{
       
  1560  	TInt err=KErrNone;
       
  1561  	const TUid testUid={0x10057145};
       
  1562  	RArray<TUint32> idArray;
       
  1563 
       
  1564 	CRepository* repository;
       
  1565  	User::LeaveIfNull(repository = CRepository::NewLC(testUid));
       
  1566 
       
  1567  	//-----------SIMULATE CLIENT SIDE TRANSACTION ERROR------------------------------
       
  1568  	err=repository->StartTransaction(CRepository::EReadWriteTransaction);
       
  1569  	TEST2(err,KErrNone);
       
  1570 
       
  1571  	//set the next allocation to fail in the FindL method
       
  1572 	__UHEAP_FAILNEXT(1);
       
  1573    	TRAP(err,repository->FindL(1,0xFFFFFFFF,idArray));
       
  1574  	__UHEAP_TOTAL_RESET;
       
  1575  	//uheap failure only happens in debug build
       
  1576 #ifdef _DEBUG
       
  1577   	TEST2(err,KErrNoMemory);
       
  1578 #else
       
  1579 	TEST2(err,KErrNone);
       
  1580 #endif
       
  1581 
       
  1582    	TUint32 errId;
       
  1583    	//ensure that the returned code from Commit is same as the last failure error in client
       
  1584    	err=repository->CommitTransaction(errId);
       
  1585 #ifdef _DEBUG
       
  1586    	TEST2(err,KErrNoMemory);
       
  1587    	TEST2(errId,KUnspecifiedKey);
       
  1588 #else
       
  1589    	TEST2(err,KErrNone);
       
  1590 #endif
       
  1591    	idArray.Reset();
       
  1592 
       
  1593    	//----------SIMULATE CLIENT SIDE TRANSACTION ERROR FOLLOWED BY ADDITIONAL OPERATION-----
       
  1594  	err=repository->StartTransaction(CRepository::EReadWriteTransaction);
       
  1595  	TEST2(err,KErrNone);
       
  1596  	//set the next allocation to fail in the FindL method
       
  1597 	__UHEAP_FAILNEXT(1);
       
  1598    	TRAP(err,repository->FindL(1,0xFFFFFFFF,idArray));
       
  1599  	__UHEAP_TOTAL_RESET;
       
  1600 #ifdef _DEBUG
       
  1601   	TEST2(err,KErrNoMemory);
       
  1602 #else
       
  1603 	TEST2(err,KErrNone);
       
  1604 #endif
       
  1605 
       
  1606   	//now try to execute another operation following the failure
       
  1607   	TReal realValue;
       
  1608  	err=repository->Set(1,realValue);
       
  1609 #ifdef _DEBUG
       
  1610  	TEST2(err,KErrAbort);
       
  1611 #else
       
  1612 	TEST2(err,KErrArgument);
       
  1613 #endif
       
  1614 
       
  1615     err=repository->CommitTransaction(errId);
       
  1616     //confirms that the error returned is the last failure in client side
       
  1617 #ifdef _DEBUG
       
  1618    	TEST2(err,KErrNoMemory);
       
  1619    	TEST2(errId,KUnspecifiedKey);
       
  1620 #else
       
  1621 	TEST2(err,KErrArgument);
       
  1622 #endif
       
  1623 	idArray.Reset();
       
  1624 
       
  1625 	//---------SIMULATE SERVER SIDE ERROR FOLLOWED BY CLIENT SIDE ERROR-------------------
       
  1626  	err=repository->StartTransaction(CRepository::EReadWriteTransaction);
       
  1627  	TEST2(err,KErrNone);
       
  1628 
       
  1629  	//server error
       
  1630  	err=repository->Set(1,realValue);
       
  1631  	TEST2(err,KErrArgument);
       
  1632 
       
  1633  	//client error
       
  1634  	__UHEAP_FAILNEXT(1);
       
  1635  	TInt ret=KErrNone;
       
  1636    	TRAP(err,ret=repository->FindL(1,0xFFFFFFFF,idArray));
       
  1637  	__UHEAP_TOTAL_RESET;
       
  1638   	TEST2(ret,KErrAbort);
       
  1639 
       
  1640     err=repository->CommitTransaction(errId);
       
  1641     //confirms that the error returned is the last failure in server side
       
  1642    	TEST2(err,KErrArgument);
       
  1643    	TEST2(errId,1);
       
  1644 	idArray.Reset();
       
  1645 
       
  1646    	//clean up stuff
       
  1647    	idArray.Close();
       
  1648    	CleanupStack::PopAndDestroy(repository);
       
  1649 	}
       
  1650 
       
  1651 /**
       
  1652 @SYMTestCaseID 	 SYSLIB-CENTRALREPOSITORY-CT-3242
       
  1653 @SYMTestCaseDesc Memory card: Backup to memory card causes phone freeze.
       
  1654 @SYMTestPriority High
       
  1655 @SYMTestActions  Open a repository with a corrupt ini file and check that
       
  1656 				 the call to CRepository::NewLC leaves with KErrCorrupt and does not panic.
       
  1657 @SYMTestExpectedResults The call to CRepository::NewLC should return with KErrCorrupt and
       
  1658 				the test must not panic or fail.
       
  1659 @SYMDEF PDEF098500
       
  1660 */
       
  1661 LOCAL_C void PDEF098500()
       
  1662 	{
       
  1663 	CRepository* repository = NULL;
       
  1664 
       
  1665 	TRAPD(err,repository = CRepository::NewLC(KUidPDEF098500LRepository));
       
  1666 
       
  1667 	//We expect the above call to leave with KErrCorrupt so repository should be NULL
       
  1668 	TEST(repository == NULL);
       
  1669 	TEST2(err, KErrCorrupt);
       
  1670 
       
  1671 	//No PopAndDestroy required as above call is expected to leave
       
  1672 
       
  1673 	}
       
  1674 
       
  1675 /**
       
  1676 @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-1884
       
  1677 @SYMTestCaseDesc DEF093855: CenRep cancels transactions if they exceed 5 seconds...
       
  1678 @SYMTestPriority High
       
  1679 @SYMTestActions  Open a repository, start a transaction, then wait more than default cache timeout
       
  1680 				 to let the normal eviction clean out the cache, call a function to reload the repository,
       
  1681 				 check that the transaction is still valid, rollback the transaction to check the
       
  1682 				 repository unload/reload during an open transaction doesn't cause a panic when transaction is rolled back.
       
  1683 @SYMTestExpectedResults The test must not panic or fail.
       
  1684 @SYMDEF DEF093855
       
  1685 */
       
  1686 LOCAL_C void DEF093855L()
       
  1687 	{
       
  1688  	TInt err=KErrNone;
       
  1689 
       
  1690 	// make sure no items are in the cache
       
  1691  	KillProcess(KCentralRepositoryServerName);
       
  1692 
       
  1693 	// connect
       
  1694 	CRepository* repository;
       
  1695 	User::LeaveIfNull(repository = CRepository::NewLC(KUidRep1));
       
  1696 
       
  1697 	// Begin concurrent read write transaction
       
  1698 	err = repository->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
       
  1699 	TEST2(err, KErrNone);
       
  1700 
       
  1701 	TInt val;
       
  1702 	const TInt KIntTestValue = 10;
       
  1703 	// get test value, make sure it is KIntTestValue
       
  1704     err = repository->Get(0x02010100,val);
       
  1705 	TEST2(err, KErrNone);
       
  1706 	TEST2(val, KIntTestValue);
       
  1707 
       
  1708     // change the value in transaction
       
  1709 	TInt r = repository->Set(0x02010100, KIntValue);
       
  1710 	TEST2(r, KErrNone);
       
  1711 
       
  1712 	// wait for the repository to be removed from memory
       
  1713 	CleanupRepositoryCache();
       
  1714 
       
  1715 	// check that the transaction is not aborted, still in memory and keeps the value set during the transaction
       
  1716     err = repository->Get(0x02010100,val);
       
  1717 	TEST2(err, KErrNone);
       
  1718 	TEST2(val, KIntValue);
       
  1719 
       
  1720 	// rollback to check if RollbackTransaction works, and to reset the value to KIntTestValue
       
  1721     repository->RollbackTransaction();
       
  1722 
       
  1723 	// Begin another transaction
       
  1724 	err = repository->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
       
  1725 	TEST2(err, KErrNone);
       
  1726 
       
  1727 	// get test value, make sure it is still KIntTestValue (successfully rolled back)
       
  1728     err = repository->Get(0x02010100,val);
       
  1729 	TEST2(err, KErrNone);
       
  1730 	TEST2(val, KIntTestValue);
       
  1731 
       
  1732     // change the value in transaction
       
  1733 	r = repository->Set(0x02010100, KIntValue);
       
  1734 	TEST2(r, KErrNone);
       
  1735 
       
  1736 	// wait for the repository to be removed from memory
       
  1737 	CleanupRepositoryCache();
       
  1738 
       
  1739 	// check that the transaction is not aborted, still in memory and keeps the value set during the transaction
       
  1740     err = repository->Get(0x02010100,val);
       
  1741 	TEST2(err, KErrNone);
       
  1742 	TEST2(val, KIntValue);
       
  1743 
       
  1744 	// commit to check if CommitTransaction works
       
  1745 	TUint32 keyInfo;
       
  1746     repository->CommitTransaction(keyInfo);
       
  1747 	TEST2(err, KErrNone);
       
  1748 	TEST2(keyInfo, 1);
       
  1749 
       
  1750 	// check that the value is set during the transaction (in shared rep settings)
       
  1751     err = repository->Get(0x02010100,val);
       
  1752 	TEST2(err, KErrNone);
       
  1753 	TEST2(val, KIntValue);
       
  1754 
       
  1755 	// close repository
       
  1756 	CleanupStack::PopAndDestroy(repository);
       
  1757 
       
  1758 	// make sure the repository is unloaded from cache
       
  1759 	KillProcess(KCentralRepositoryServerName);
       
  1760 
       
  1761 	// reopen the repository
       
  1762 	User::LeaveIfNull(repository = CRepository::NewLC(KUidRep1));
       
  1763 
       
  1764 	// get test value, to check if it had been successfully persisted
       
  1765     err = repository->Get(0x02010100,val);
       
  1766 	TEST2(err, KErrNone);
       
  1767 	TEST2(val, KIntValue);
       
  1768 
       
  1769     // reset the setting back to the original value
       
  1770 	r = repository->Set(0x02010100, KIntTestValue);
       
  1771 	TEST2(r, KErrNone);
       
  1772 
       
  1773 	//Reset repository to remove any changes made during this test
       
  1774 	r = repository->Reset();
       
  1775 	TEST2(r, KErrNone);
       
  1776 
       
  1777 	// close repository
       
  1778 	CleanupStack::PopAndDestroy(repository);
       
  1779 	}
       
  1780 
       
  1781 /**
       
  1782 @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-3477
       
  1783 @SYMTestCaseDesc PDEF106507: Central repository doesn't handle corruption of the installdir.bin file properly
       
  1784 @SYMTestPriority High
       
  1785 @SYMTestActions  Replaces installdir.bin file with a corrupted version, then shuts down the server and restarts it (with CRepository::NewL)  This causes the file to be re-read, and as it is corrupt it should get deleted and re-created.  The test checks that the server does not panic.
       
  1786 @SYMTestExpectedResults The Server should not panic when trying to read the corrupt file, and should return KErrNone
       
  1787 @SYMDEF PDEF106507
       
  1788 */
       
  1789 LOCAL_C void PDEF106507L()
       
  1790 	{
       
  1791 	_LIT(KInstallDirFile, "C:\\private\\10202be9\\persists\\installdir.bin");
       
  1792 	_LIT(KInstallDirFileBad1, "Z:\\private\\10202be9\\installdir_corrupt1.bin");
       
  1793 	_LIT(KInstallDirFileBad2, "Z:\\private\\10202be9\\installdir_corrupt2.bin");
       
  1794 	RFs fs;
       
  1795 	User::LeaveIfError(fs.Connect());
       
  1796 	CleanupClosePushL(fs);
       
  1797 
       
  1798 	CFileMan* fm = CFileMan::NewL(fs);
       
  1799 	CleanupStack::PushL(fm);
       
  1800 
       
  1801 	// copy first corrupt file into centrep private directory (this file has data area corrupted)
       
  1802 	TheTest.Printf(_L("\nCopy first corrupt installdir.bin file into persists dir\n"));
       
  1803 	User::LeaveIfError(fm->Copy(KInstallDirFileBad1, KInstallDirFile));
       
  1804 	// Reset read-only bit
       
  1805 	User::LeaveIfError(fm->Attribs(KInstallDirFile,0,KEntryAttReadOnly,TTime(0)));
       
  1806 
       
  1807 	// Kill server so that next test will restart and internalize file
       
  1808 	TInt error = KillProcess(KCentralRepositoryServerName);
       
  1809 	TEST2(error, KErrNone);
       
  1810 
       
  1811 	// Start server and check it does not panic
       
  1812 	CRepository* repository = NULL;
       
  1813 	TRAP(error, repository = CRepository::NewL(KUidRep1));
       
  1814 	TEST2(error, KErrNone);
       
  1815 	delete repository;
       
  1816 
       
  1817 	// test the second corrupted file (this file has header information corrupted)
       
  1818 	TheTest.Printf(_L("\nCopy second corrupt installdir.bin file into persists dir\n"));
       
  1819 	User::LeaveIfError(fm->Copy(KInstallDirFileBad2, KInstallDirFile));
       
  1820 	// Reset read-only bit
       
  1821 	User::LeaveIfError(fm->Attribs(KInstallDirFile,0,KEntryAttReadOnly,TTime(0)));
       
  1822 
       
  1823 	// Kill server so that next test will reconnect and recreate resources
       
  1824 	error = KillProcess(KCentralRepositoryServerName);
       
  1825 	TEST2(error, KErrNone);
       
  1826 
       
  1827 	// Start server and check it does not panic
       
  1828 	TRAP(error, repository = CRepository::NewL(KUidRep1));
       
  1829 	TEST2(error, KErrNone);
       
  1830 	delete repository;
       
  1831 
       
  1832 	CleanupStack::PopAndDestroy(2); //fs, fm
       
  1833 	}
       
  1834 
       
  1835 /**
       
  1836 @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-3517
       
  1837 @SYMTestCaseDesc R3.2 stability problems: CentralRepositorySrv crash
       
  1838 @SYMTestPriority High
       
  1839 @SYMTestActions  Attempt to open a .cre file which has a corrupt UID. Ensure that
       
  1840 				 the error is dealt with properly.
       
  1841 @SYMTestExpectedResults The test must not fail.
       
  1842 @SYMDEF INC108803
       
  1843 */
       
  1844 
       
  1845 _LIT(KZCorruptFile1, "z:\\private\\10202BE9\\101f8764.cre");
       
  1846 _LIT(KCCorruptFile1, "c:\\private\\10202BE9\\persists\\101f8764.cre");
       
  1847 _LIT(KCCorruptFile2, "c:\\private\\10202BE9\\persists\\101f8765.cre");
       
  1848 
       
  1849 const TUid KUidCorruptUid1 	= { 0x101f8764 };
       
  1850 const TUid KUidCorruptUid2 	= { 0x101f8765 };
       
  1851 
       
  1852 LOCAL_C void INC108803L()
       
  1853 	{
       
  1854 
       
  1855 	TInt err = KErrNone;
       
  1856 
       
  1857 	RFs fs;
       
  1858 	User::LeaveIfError(fs.Connect());
       
  1859 	CleanupClosePushL(fs);
       
  1860 
       
  1861 	CFileMan* fm = CFileMan::NewL(fs);
       
  1862 	CleanupStack::PushL(fm);
       
  1863 
       
  1864 	CRepository* rep = NULL;
       
  1865 
       
  1866 	// Attempt to open a repository from a .cre file which has a corrupt UID
       
  1867 	// The .cre file exists on the Z drive only. This test ensures that
       
  1868 	// the corruption of the .cre file is detected and that the correct error
       
  1869 	// code, KErrCorrupt, is returned to the client.
       
  1870 	// This test will
       
  1871 	// 1. Look on c drive, be unable to find the file
       
  1872 	// 2. Look in z drive, find the file with the specified UID,
       
  1873 	// determine that the file is corrupt and return KErrCorupt.
       
  1874 
       
  1875 	TheTest.Printf(_L("\nAttempt to open ROM cre file with UID corruption\n"));
       
  1876 	TRAP(err, rep = CRepository::NewLC(KUidCorruptUid1); CleanupStack::Pop(rep););
       
  1877 	TEST2(err, KErrCorrupt);
       
  1878 
       
  1879 	// Copy the corrupt .cre file into the persists directory for the next test
       
  1880  	User::LeaveIfError(fm->Copy(KZCorruptFile1, KCCorruptFile1 ));
       
  1881  	// Reset read-only bit
       
  1882 	User::LeaveIfError(fm->Attribs(KCCorruptFile1,0,KEntryAttReadOnly,TTime(0)));
       
  1883 	User::After(KGeneralDelay);
       
  1884 
       
  1885 	// Attempt to open a repository which has a .cre file with a corrupt UID.
       
  1886 	// The .cre file exists on the C and Z drives. (This test ensures that the
       
  1887 	// corrupt .cre file on the C Drive is deleted).
       
  1888 	// This test will
       
  1889 	// 1.Look in the C Drive, find the file with the specified UID
       
  1890 	// determine that the file is corrupt and delete the file
       
  1891 	// 2. Look in the Z Drive, find the file with the specified UID,
       
  1892 	// determine that the file is corrupt and return KErrCorupt.
       
  1893 
       
  1894  	TheTest.Printf(_L("\nAttempt to open persists cre file with UID corruption\n"));
       
  1895 	TRAP (err, rep = CRepository::NewLC(KUidCorruptUid1); CleanupStack::Pop(rep););
       
  1896 	TEST2(err, KErrCorrupt);
       
  1897 	TheTest.Printf(_L("\nCheck corrupt file deleted from persists dir\n"));
       
  1898 	TEST2 (BaflUtils::FileExists (fs, KCCorruptFile1), EFalse);
       
  1899 
       
  1900  	// Copy a second corrupt .cre file into the persists directory
       
  1901  	// (Note that an associated ini file
       
  1902  	// z:\\private\\10202BE9\\101f8765.txt exists and is not corrupt)
       
  1903 
       
  1904  	User::LeaveIfError(fm->Copy(KZCorruptFile1, KCCorruptFile2));
       
  1905  	TEST2 (BaflUtils::FileExists (fs, KCCorruptFile2), ETrue);
       
  1906  	// Reset read-only bit
       
  1907 	User::LeaveIfError(fm->Attribs(KCCorruptFile2,0,KEntryAttReadOnly,TTime(0)));
       
  1908 	User::After(KGeneralDelay);
       
  1909 
       
  1910  	// Attempt to open a corrupt repository. This will fail and the .cre file on the
       
  1911  	// C Drive will be deleted. Fall-back to the Z drive occurs. The associated ini file
       
  1912  	// is found.
       
  1913  	// Attempt to use the resulting repository by using a Reset operation. No panics should
       
  1914  	// occur.
       
  1915  	TheTest.Printf(_L("\nAttempt to open corrupt persists cre file, re-create from txt file\n"));
       
  1916 	TRAP (err, rep = CRepository::NewLC(KUidCorruptUid2); CleanupStack::Pop(rep););
       
  1917 	TEST2 (BaflUtils::FileExists (fs, KCCorruptFile2), EFalse);
       
  1918  	TEST2(err, KErrNone);
       
  1919   	ASSERT(rep != NULL);
       
  1920 	rep->Reset();
       
  1921 
       
  1922  	// Clean up any files created on the C Drive
       
  1923  	CleanupFileFromCDriveL(KUidCorruptUid1);
       
  1924  	CleanupFileFromCDriveL(KUidCorruptUid2);
       
  1925 
       
  1926 	delete rep;
       
  1927 	CleanupStack::PopAndDestroy(2, &fs); // fm, fs
       
  1928 	}
       
  1929 
       
  1930 
       
  1931 /**
       
  1932 @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-3545
       
  1933 @SYMTestCaseDesc The corrupted Cache ini file should cause CentralRepositorySrv panic in debug mode
       
  1934 				 but keep running with the default values in release mode.
       
  1935 @SYMTestPriority High
       
  1936 @SYMTestActions  Kill CentralRepositorySrv and restart it with the corrupted Cache ini file.
       
  1937 				 Ensure that:
       
  1938 				 . in debug mode, the client will fail to create a CRepository pointer because
       
  1939 				 the server has panicked.
       
  1940 				 . in release mode, the client will be able to create a CRepository pointer because
       
  1941 				 the server keeps running with the default values.
       
  1942 @SYMTestExpectedResults The test must not fail.
       
  1943 @SYMDEF DEF109390
       
  1944 */
       
  1945 
       
  1946 _LIT(KZCorruptIniFile, "z:\\private\\10202BE9\\cache_corrupt.ini");
       
  1947 _LIT(KCCorruptIniFile, "c:\\private\\10202BE9\\centrep.ini");
       
  1948 _LIT(KZRepFile, 	 "z:\\private\\10202BE9\\00000001.txt");
       
  1949 _LIT(KCRepFile, 	 "c:\\private\\10202BE9\\persists\\00000001.txt");
       
  1950 
       
  1951 const TUid KTestRepUid 	= { 0x00000001};
       
  1952 
       
  1953 LOCAL_C void DEF109390L()
       
  1954 	{
       
  1955  	TInt err(KErrNone);
       
  1956 
       
  1957 	RFs fs;
       
  1958 	User::LeaveIfError(fs.Connect());
       
  1959 	CleanupClosePushL(fs);
       
  1960 
       
  1961 	CFileMan* fm = CFileMan::NewL(fs);
       
  1962 	CleanupStack::PushL(fm);
       
  1963 
       
  1964 	// Copy the corrupted Cache ini file to install directory.
       
  1965 	TheTest.Printf(_L("\nCopy the corrupted Cache ini file to install directory.\n"));
       
  1966  	User::LeaveIfError(fm->Copy(KZCorruptIniFile, KCCorruptIniFile));
       
  1967 	// Reset read-only bit
       
  1968 	User::LeaveIfError(fm->Attribs(KCCorruptIniFile,0,KEntryAttReadOnly,TTime(0)));
       
  1969 
       
  1970 	// Copy a good repository file to persist directory to verify whether the cenrep server is
       
  1971 	// able to start up.
       
  1972 	TheTest.Printf(_L("\nCopy the repository file to persist directory.\n"));
       
  1973  	User::LeaveIfError(fm->Copy(KZRepFile, KCRepFile));
       
  1974 	// Reset read-only bit
       
  1975 	User::LeaveIfError(fm->Attribs(KCRepFile,0,KEntryAttReadOnly,TTime(0)));
       
  1976 
       
  1977 	// Kill server so that next test will restart it.
       
  1978 	err=KillProcess(KCentralRepositoryServerName);
       
  1979 	TEST2(err,KErrNone);
       
  1980 
       
  1981 	User::After(KGeneralDelay);
       
  1982 
       
  1983 	CRepository* rep = NULL;
       
  1984 	TRAP(err, rep = CRepository::NewLC(KTestRepUid); CleanupStack::PopAndDestroy(rep););
       
  1985 
       
  1986 	#ifdef _DEBUG
       
  1987 		// in debug mode, CRepository::NewLC should leave with leave code KErrGeneral.
       
  1988 		TheTest.Printf(_L("Debug mode err = %d.\n"),err);
       
  1989 		TEST2(err, KErrGeneral);
       
  1990 	#else
       
  1991 		// in release mode, CRepository::NewLC should return a valid CRepository pointer successfully.
       
  1992 		TheTest.Printf(_L("Release mode err = %d.\n"),err);
       
  1993 		TEST2(err, KErrNone);
       
  1994 	#endif
       
  1995 
       
  1996  	// Clean up the repository files created on the C Drive
       
  1997  	CleanupFileFromCDriveL(KTestRepUid);
       
  1998 
       
  1999  	// Clean up the corrupted ini file on the C Drive
       
  2000  	User::LeaveIfError(fm->Delete(KCCorruptIniFile));
       
  2001 
       
  2002  	// pop the cleanup stack for fm & fs
       
  2003 	CleanupStack::PopAndDestroy(2, &fs);
       
  2004 
       
  2005 	// Kill the Cenrep server so that it can it can be restarted by the client
       
  2006 	// without the corrupted Cache ini file.
       
  2007 	err=KillProcess(KCentralRepositoryServerName);
       
  2008 	TEST2(err,KErrNone);
       
  2009 	}
       
  2010 
       
  2011 /**
       
  2012 @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-UT-4024
       
  2013 @SYMTestCaseDesc
       
  2014 Test that the UID compare function works properly with large UID's.  Since
       
  2015 CObservable::CompareTUidValues() is a private function and cannot be accessed
       
  2016 directly, CObservable::AddObserverL()and CObservable::FindConnectedRepository()
       
  2017 are used to infer the correct operation.
       
  2018 @SYMTestPriority High
       
  2019 @SYMTestActions
       
  2020 -Compare a large positive UID and a very negative UID
       
  2021 -Compare a large positive UID and a large positive UID
       
  2022 -Compare a very negative UID and a very negative UID
       
  2023 -Compare two very large but equivalent UID's.
       
  2024 @SYMTestExpectedResults All UID's added to a sorted list can be found later, regardless of size and sign.
       
  2025 @SYMDEF DEF116043
       
  2026 @SYMUnit CObservable::CompareTUidValues()
       
  2027 */
       
  2028 LOCAL_C void DEF116043L()
       
  2029 	{
       
  2030 	const TUid KLargePositive1 = {0x7FFFFFFF};
       
  2031 	const TUid KLargePositive2 = {0x7FFFFFFE};
       
  2032 	const TUid KLargeNegative = {0x8FFFFFFF};
       
  2033 
       
  2034 	CObservable* ob = CObservable::NewLC();
       
  2035 
       
  2036 	// Add a variety of UID's to work with, including large positives, a very negative,
       
  2037 	// and duplicates
       
  2038 	ob->AddObserverL(KLargePositive1, NULL);
       
  2039 	ob->AddObserverL(KLargeNegative, NULL);
       
  2040 	ob->AddObserverL(KLargePositive2, NULL);
       
  2041 	ob->AddObserverL(KLargePositive1, NULL);
       
  2042 
       
  2043 	// Look for a large positive and expect a non-negative index
       
  2044 	TEST(ob->FindConnectedRepository(KLargePositive1) >= 0);
       
  2045 
       
  2046 	// Look for another large positive and expect a non-negative index
       
  2047 	TEST(ob->FindConnectedRepository(KLargePositive2) >= 0);
       
  2048 
       
  2049 	// Look for a very negative and expect a non-negative index.
       
  2050 	// This will fail under 'UID1 - UID2' implementations.
       
  2051 	TEST(ob->FindConnectedRepository(KLargeNegative) >= 0);
       
  2052 
       
  2053 	CleanupStack::PopAndDestroy(ob);
       
  2054 	}
       
  2055 	
       
  2056 /**
       
  2057 @SYMTestCaseID PDS-CENTRALREPOSITORY-UT-4081
       
  2058 @SYMTestCaseDesc
       
  2059 Test that the Observer compare function works properly with large UID's
       
  2060 @SYMTestPriority High
       
  2061 @SYMTestActions The test will insert a set of pointers with very big and small unsigned address
       
  2062 and ensure that the correct order is inserted in the list
       
  2063 @SYMTestExpectedResults the pointer is inserted in the correct order
       
  2064 @SYMDEF DEF132807
       
  2065 */	
       
  2066 LOCAL_C void DEF132807L()
       
  2067 	{
       
  2068 	CObservable* ob = CObservable::NewLC();
       
  2069 	
       
  2070 	const TUid KReposUid={0x87654321};
       
  2071 	
       
  2072 	ob->AddObserverL(KReposUid,(CServerRepository*)0x7FFFFFFF);
       
  2073 	ob->AddObserverL(KReposUid,(CServerRepository*)0x7FFFFFFE);
       
  2074 	ob->AddObserverL(KReposUid,(CServerRepository*)0x8FFFFFFF);
       
  2075 	ob->AddObserverL(KReposUid,(CServerRepository*)0x00000001);		
       
  2076 
       
  2077 	TEST(ob->iObservers.Count()==4);
       
  2078 	CObservable::TRepositoryObserverInfo pos1=ob->iObservers[0];
       
  2079 	TEST(pos1.iRepositoryPointer==(CServerRepository*)0x00000001);
       
  2080 	CObservable::TRepositoryObserverInfo pos2=ob->iObservers[1];
       
  2081 	TEST(pos2.iRepositoryPointer==(CServerRepository*)0x7FFFFFFE);	
       
  2082 	CObservable::TRepositoryObserverInfo pos3=ob->iObservers[2];
       
  2083 	TEST(pos3.iRepositoryPointer==(CServerRepository*)0x7FFFFFFF);	
       
  2084 	CObservable::TRepositoryObserverInfo pos4=ob->iObservers[3];
       
  2085 	TEST(pos4.iRepositoryPointer==(CServerRepository*)0x8FFFFFFF);	
       
  2086 	CleanupStack::PopAndDestroy(ob);
       
  2087 	}
       
  2088 
       
  2089 //a test class notify handler
       
  2090 //the notify handler will check the value for different test case
       
  2091 static TInt currentTestCaseID=0;
       
  2092 
       
  2093 class CTestNotifyHandler : public CBase, public MCenRepNotifyHandlerCallback
       
  2094 	{
       
  2095 public:
       
  2096 	static CTestNotifyHandler* NewL()
       
  2097 		{
       
  2098 		return new (ELeave)CTestNotifyHandler;
       
  2099 		}
       
  2100 	~CTestNotifyHandler(){}
       
  2101 	// Notification handlers
       
  2102 	void HandleNotifyInt(TUint32 aId, TInt aNewValue)
       
  2103 		{
       
  2104 		if (currentTestCaseID==0)
       
  2105 			return;
       
  2106 		else if(currentTestCaseID==1)
       
  2107 			TEST(aId==1 && aNewValue==208);
       
  2108 		}
       
  2109 	void HandleNotifyReal(TUint32 aId, TReal /*aNewValue*/)
       
  2110 		{
       
  2111 		if (currentTestCaseID==2)
       
  2112 			{
       
  2113 			TEST(aId==1);
       
  2114 			CActiveScheduler::Stop();
       
  2115 			}
       
  2116 		}
       
  2117 	void HandleNotifyString(TUint32 /*aId*/, const TDesC16& /*aNewValue*/)
       
  2118 		{
       
  2119 		}
       
  2120 	void HandleNotifyBinary(TUint32 /*aId*/, const TDesC8& /*aNewValue*/)
       
  2121 		{
       
  2122 		}
       
  2123 	void HandleNotifyGeneric(TUint32 /*aId*/)
       
  2124 		{
       
  2125 		}
       
  2126 	void HandleNotifyError(TUint32 aId, TInt error, CCenRepNotifyHandler* /*aHandler*/)
       
  2127 		{
       
  2128 		if (currentTestCaseID==0)
       
  2129 			return;
       
  2130 		else if (currentTestCaseID==1)
       
  2131 			TEST((TInt)aId==-11 && error==KErrArgument);
       
  2132 		else if (currentTestCaseID==2)
       
  2133 			TEST(aId==1 && error==KErrArgument);
       
  2134 		else if (currentTestCaseID==3)
       
  2135 			TEST(aId== 10000 && error==KErrPermissionDenied);
       
  2136 		
       
  2137 		CActiveScheduler::Stop();
       
  2138 		}
       
  2139 private:
       
  2140 	CTestNotifyHandler(){}
       
  2141 	};
       
  2142 
       
  2143 /**
       
  2144 @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-4035
       
  2145 @SYMTestCaseDesc Notify Handling in centralrepository under different error conditions
       
  2146 @SYMTestPriority High
       
  2147 @SYMTestActions Testing the CRepository::NotifyRequest under different error condition
       
  2148 				Testing the CCenrepNotifierHandler under different error condition
       
  2149 @SYMTestExpectedResults Test should pass and exhibit the expected behaviour
       
  2150 @SYMDEF DEF117987
       
  2151 */
       
  2152 LOCAL_C void DEF117987L()
       
  2153 	{
       
  2154 	__UHEAP_MARK;
       
  2155 
       
  2156 	CActiveScheduler* s=new(ELeave) CActiveScheduler;
       
  2157 	CleanupStack::PushL(s);
       
  2158 	CActiveScheduler::Install(s);
       
  2159 
       
  2160 	const TUid KCDUid = {0xF0000001};
       
  2161 	CRepository* rep=CRepository::NewL(KCDUid);
       
  2162 
       
  2163 	TRequestStatus ts,ts1;
       
  2164 
       
  2165 	//-----------------single notification test-----------------------
       
  2166 	//Negative testing for Double notification on same setting
       
  2167 	TInt ret=rep->NotifyRequest(1,ts);
       
  2168 	TEST(ret==KErrNone);
       
  2169 	ret=rep->NotifyRequest(1,ts1);
       
  2170 	TEST(ret==KErrNone);
       
  2171 	ret=rep->Set(1,123);
       
  2172 	User::WaitForRequest(ts);
       
  2173 	User::WaitForRequest(ts1);
       
  2174 	TEST(ts==1);
       
  2175 	TEST(ts1==KErrAlreadyExists);
       
  2176 	
       
  2177 	//Negative testing for non-existent key---------------------------
       
  2178 	ts=KRequestPending;
       
  2179 	ret=rep->NotifyRequest(10303,ts);
       
  2180 	TEST(ret==KErrNotFound);
       
  2181 	TEST(ts==KRequestPending);
       
  2182 
       
  2183 	//Negative testing for key we dont have permission----------------
       
  2184 	ret=rep->NotifyRequest(10000,ts);
       
  2185 	TEST(ret==KErrPermissionDenied);
       
  2186 	TEST(ts==KRequestPending);
       
  2187 
       
  2188 	//---------------------group notification test--------------------------
       
  2189 	ts=KRequestPending;
       
  2190 	ts1=KRequestPending;
       
  2191 
       
  2192 	//Negative testing for double notification on the same setting range
       
  2193 	//set partial key 0 and mask 0xFFFFFF00 to filter only 0-255
       
  2194 	ret=rep->NotifyRequest(0,0xFFFFFF00,ts);
       
  2195 	TEST(ret==KErrNone);
       
  2196 	//second notification request on the same partial key and mask should not fail
       
  2197 	ret=rep->NotifyRequest(0,0xFFFFFF00,ts1);
       
  2198 	TEST(ret==KErrNone);
       
  2199 	ret=rep->Set(1,246);
       
  2200 	User::WaitForRequest(ts);
       
  2201 	User::WaitForRequest(ts1);
       
  2202 	TEST(ts==1);
       
  2203 	TEST(ts1==1);
       
  2204 	
       
  2205 	//Negative testing for unknown range------------------------------
       
  2206 	//this will not return error code for range notification as it is intended for
       
  2207 	//to cover keys created later in the future.
       
  2208 	ts=KRequestPending;
       
  2209 	ret=rep->NotifyRequest(100000,0xFFFFFFFF,ts);
       
  2210 	TEST(ret==KErrNone);
       
  2211 	ret=rep->NotifyCancel(100000,0xFFFFFFFF);
       
  2212 	User::WaitForAnyRequest();
       
  2213 	TEST(ret==KErrNone);
       
  2214 	TEST(ts==KUnspecifiedKey);
       
  2215 
       
  2216 	//Negative testing for key we dont have permission------------------------------
       
  2217 	ts=KRequestPending;
       
  2218 	ret=rep->NotifyRequest(10000,0xFFFFFFFF,ts);
       
  2219 	TEST(ret==KErrNone);
       
  2220 	User::WaitForRequest(ts);
       
  2221 	TEST(ts==KErrPermissionDenied);
       
  2222 
       
  2223 	delete rep;
       
  2224 
       
  2225 	//----------------single notification using cenrepnotifhandler-----------
       
  2226 	currentTestCaseID=1;
       
  2227 	rep=CRepository::NewL(KCDUid);
       
  2228 	//create the handler callback
       
  2229 	CTestNotifyHandler* callback=CTestNotifyHandler::NewL();
       
  2230 
       
  2231 	//now setup the handler
       
  2232 	CCenRepNotifyHandler* handler=CCenRepNotifyHandler::NewLC(*callback,*rep,CCenRepNotifyHandler::EIntKey,1);
       
  2233 	CCenRepNotifyHandler* handler2=CCenRepNotifyHandler::NewLC(*callback,*rep,CCenRepNotifyHandler::EIntKey,1);
       
  2234 
       
  2235 	handler->StartListeningL();
       
  2236 	handler2->StartListeningL();
       
  2237 
       
  2238 	ret=rep->Set(1,208);
       
  2239 	TEST(ret==KErrNone);
       
  2240 
       
  2241 	CActiveScheduler::Start();
       
  2242 	
       
  2243 	User::After(1000000);
       
  2244 	CleanupStack::PopAndDestroy(2);
       
  2245 	
       
  2246 	delete callback;
       
  2247 	delete rep;
       
  2248 
       
  2249 	CleanupStack::PopAndDestroy();
       
  2250 
       
  2251 	__UHEAP_MARKEND;
       
  2252 	}
       
  2253 
       
  2254 /**
       
  2255 @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-4034
       
  2256 @SYMTestCaseDesc Centrep notifier handler does not check return codes
       
  2257 @SYMTestPriority High
       
  2258 @SYMTestActions	 Test that error code encountered during handling of notification
       
  2259 				 results in the HandleNotifyError being invoked
       
  2260 @SYMTestExpectedResults Test should pass and exhibit the expected behaviour
       
  2261 @SYMDEF DEF117848
       
  2262 */
       
  2263 LOCAL_C void DEF117848L()
       
  2264 	{
       
  2265 	__UHEAP_MARK;
       
  2266 
       
  2267 	CActiveScheduler* s=new(ELeave) CActiveScheduler;
       
  2268 	CleanupStack::PushL(s);
       
  2269 	CActiveScheduler::Install(s);
       
  2270 
       
  2271 	const TUid KCDUid = {0xF0000001};
       
  2272 
       
  2273 	//create the handler callback
       
  2274 	CTestNotifyHandler* callback=CTestNotifyHandler::NewL();
       
  2275 
       
  2276 	//----------------notify handle error test case------------------------------
       
  2277 	currentTestCaseID=2;
       
  2278 	CRepository* rep=CRepository::NewL(KCDUid);
       
  2279 
       
  2280 	//purposely set the notify handler for a key but specifying the wrong type
       
  2281 	//this will only be detected during the notification
       
  2282 	CCenRepNotifyHandler* handler=CCenRepNotifyHandler::NewLC(*callback,*rep,CCenRepNotifyHandler::ERealKey,1);
       
  2283 	handler->StartListeningL();
       
  2284 	TInt ret=rep->Set(1,199);
       
  2285 	TEST(ret==KErrNone);
       
  2286 	
       
  2287 	CActiveScheduler::Start();	
       
  2288 	//handlenotify error will be called and validate the error code and then stop the scheduler
       
  2289 	handler->StopListening();
       
  2290 	
       
  2291 	CleanupStack::PopAndDestroy();
       
  2292 	
       
  2293 	//test for other type of settings
       
  2294 	handler=CCenRepNotifyHandler::NewLC(*callback,*rep,CCenRepNotifyHandler::EStringKey,1);
       
  2295 	handler->StartListeningL();
       
  2296 	ret=rep->Set(1,209);
       
  2297 	TEST(ret==KErrNone);
       
  2298 	CActiveScheduler::Start();
       
  2299 	handler->StopListening();
       
  2300 	CleanupStack::PopAndDestroy();
       
  2301 
       
  2302 	//test for other type of settings
       
  2303 	handler=CCenRepNotifyHandler::NewLC(*callback,*rep,CCenRepNotifyHandler::EBinaryKey,1);
       
  2304 	handler->StartListeningL();
       
  2305 	ret=rep->Set(1,309);
       
  2306 	TEST(ret==KErrNone);
       
  2307 	
       
  2308 	CActiveScheduler::Start();
       
  2309 	handler->StopListening();
       
  2310 	CleanupStack::PopAndDestroy();	
       
  2311 	
       
  2312 	delete callback;
       
  2313 	delete rep;
       
  2314 
       
  2315 	CleanupStack::PopAndDestroy();
       
  2316 	
       
  2317 	__UHEAP_MARKEND;			
       
  2318 	}
       
  2319 
       
  2320 /**
       
  2321 @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-4036
       
  2322 @SYMTestCaseDesc  Central Repository Notification Handler flooded with notifications
       
  2323 @SYMTestPriority High
       
  2324 @SYMTestActions	Testing the CCenrepNotifierHandler when the client does not have
       
  2325 				enough permission when setting up the whole repository notifier.
       
  2326 @SYMTestExpectedResults Test should pass and exhibit the expected behaviour
       
  2327 @SYMDEF DEF118107
       
  2328 */
       
  2329 LOCAL_C void DEF118107L()
       
  2330 	{
       
  2331 	__UHEAP_MARK;
       
  2332 	
       
  2333 	currentTestCaseID = 3;
       
  2334 	CActiveScheduler* s=new(ELeave) CActiveScheduler;
       
  2335 	CleanupStack::PushL(s);
       
  2336 	CActiveScheduler::Install(s);
       
  2337 	
       
  2338 	const TUid KCDUid = {0xF0000001};	
       
  2339 	CRepository* rep=CRepository::NewL(KCDUid);
       
  2340 
       
  2341 	//create the handler callback
       
  2342 	CTestNotifyHandler* callback=CTestNotifyHandler::NewL();	
       
  2343 	
       
  2344 	//create a handler to listen to the whole repository
       
  2345 	CCenRepNotifyHandler* handler=CCenRepNotifyHandler::NewLC(*callback,*rep);	
       
  2346 	
       
  2347 	//Start listening as a fail should occur as one of repository entries does not
       
  2348 	//have the correct capabilities
       
  2349 	handler->StartListeningL();
       
  2350 	
       
  2351 	//This causes the handlenotifyerror to be called which checks that 
       
  2352 	//KErrPermissionDenied has occured and stops the scheduler.
       
  2353 	CActiveScheduler::Start();
       
  2354 	handler->StopListening();
       
  2355 	
       
  2356 	//Cleanup
       
  2357 	CleanupStack::PopAndDestroy();
       
  2358 	
       
  2359 	delete callback;
       
  2360 	delete rep;
       
  2361 
       
  2362 	CleanupStack::PopAndDestroy();
       
  2363 	
       
  2364 	__UHEAP_MARKEND;		
       
  2365 	}
       
  2366 
       
  2367 
       
  2368 // This function creates TServerSetting objects with the data in the ServerSettingStruct array and then
       
  2369 // appends them to the specified RSettingsArray object.
       
  2370 LOCAL_C void SetupSettingsArrayL(RSettingsArray& aSettingsArray,const ServerSettingStruct aSettingStructArr[], TInt aSettingStructArrSize)
       
  2371 	{
       
  2372 	for(TInt i = 0; i < aSettingStructArrSize; i++)
       
  2373 		{
       
  2374 		TServerSetting newSetting(aSettingStructArr[i].key);
       
  2375 		TInt error;
       
  2376 		newSetting.SetIntValue(aSettingStructArr[i].value);
       
  2377 		newSetting.SetType(aSettingStructArr[i].meta);
       
  2378 		newSetting.SetMeta(aSettingStructArr[i].meta);
       
  2379 
       
  2380 		error = aSettingsArray.OrderedInsert(newSetting);
       
  2381 		
       
  2382 		if(KErrNone != error)
       
  2383 			{
       
  2384 			newSetting.Reset();	// for safety in case of newSetting is not TInt type.
       
  2385 			User::Leave(error);
       
  2386 			}
       
  2387 		}
       
  2388 	}
       
  2389 	
       
  2390 // This function compares 2 RSettingsArray arrays. Panics if they are not identical
       
  2391 LOCAL_C void CompareSettingsArrays(const RSettingsArray& aArr1, const RSettingsArray& aArr2)	
       
  2392 	{
       
  2393 	TEST2(aArr1.Count(), aArr2.Count());
       
  2394 	for(TInt i = 0; i < aArr2.Count(); i++)
       
  2395 		{
       
  2396 		if(aArr1[i].IsDeleted())
       
  2397 			{
       
  2398 			TEST(aArr2[i].IsDeleted());	
       
  2399 			}
       
  2400 		else
       
  2401 			{
       
  2402 			TEST(aArr1[i] == aArr2[i]);				
       
  2403 			}
       
  2404 		}
       
  2405 	}
       
  2406 
       
  2407 // This function compares 2 RArray<TUint32> arrays. Panics if they are not identical
       
  2408 LOCAL_C void CompareUint32Arrays(const RArray<TUint32>& aArr1, const RArray<TUint32>& aArr2)	
       
  2409 	{
       
  2410 	TEST2(aArr1.Count(), aArr2.Count());
       
  2411 	for(TInt i = 0; i < aArr2.Count(); i++)
       
  2412 		{
       
  2413 		TEST(aArr1[i] == aArr2[i]);				
       
  2414 		}
       
  2415 	}
       
  2416 
       
  2417 // This function calls MergerArray() with the pre-set parameters for each merge type and compares the results to 
       
  2418 // the reference arrays.
       
  2419 // Also used as the OOM test if aOOMMode is ETrue.
       
  2420 LOCAL_C void MergerArrayTestL(const RSettingsArray aPersistRef[], const RSettingsArray aChangeRef[], const RArray<TUint32> aDeletedRef[], TBool aOOMMode)
       
  2421 
       
  2422 	{
       
  2423 	// Data used to construct the persistence array for all merge types	
       
  2424 	static const ServerSettingStruct settingStructPersist[] = {{1,0,1}, {3,KMetaBackup,3}, {5,0,5}, {7,0,7}, {9,KMetaDefaultValue,9}, {11,0,11}, {13,KMetaDefaultValue,13}};
       
  2425 	
       
  2426 	// Data used to construct the changes array for merge type: ETransactionMerge. Some are marked as deleted.
       
  2427 	static const ServerSettingStruct settingStructChangeTrans[] = {{1,TServerSetting::EDeleted,1}, {2,TServerSetting::EDeleted,2}, \
       
  2428 		{3,TServerSetting::EDeleted,3}, {4,0,4}, {5,0,5}, {6,0,6}, {7,0,8}, {9,0,10}};
       
  2429 	
       
  2430 	// Data used to construct the changes array for all other merge types than ETransactionMerge. No deleted items.
       
  2431 	static const ServerSettingStruct settingStructChange[] = {{1,0,1}, {2,0,2}, {3,0,3}, {4,0,4}, {5,0,5}, {6,0,6}, {7,0,8}, {9,0,10}};
       
  2432 	
       
  2433 	for(TInt i = 0; i < sizeof(KMergerTypes) / sizeof(TMergeType); i++)
       
  2434 		{
       
  2435 		RSettingsArray persist;
       
  2436 		RSettingsArray change;
       
  2437 		RArray<TUint32> deleted; 
       
  2438 		TInt error = KErrNone ;
       
  2439 		TInt count = 0;
       
  2440 		
       
  2441 		do
       
  2442 			{
       
  2443 			__UHEAP_MARK;
       
  2444 			
       
  2445 			// Sets up arrays passed into MergeArray()
       
  2446 			SetupSettingsArrayL(persist,settingStructPersist, sizeof(settingStructPersist)/sizeof(ServerSettingStruct));
       
  2447 			if( ETransactionMerge == KMergerTypes[i] )
       
  2448 				{
       
  2449 				SetupSettingsArrayL(change,settingStructChangeTrans, sizeof(settingStructChangeTrans)/sizeof(ServerSettingStruct));	
       
  2450 				}
       
  2451 			else
       
  2452 				{
       
  2453 				SetupSettingsArrayL(change,settingStructChange, sizeof(settingStructChange)/sizeof(ServerSettingStruct));	
       
  2454 				}
       
  2455 			
       
  2456 			deleted.InsertInUnsignedKeyOrderL(4);
       
  2457 			
       
  2458 			if(aOOMMode)
       
  2459 				{
       
  2460 				__UHEAP_SETFAIL(RHeap::EFailNext, ++count);
       
  2461 				}
       
  2462 			
       
  2463 			error = persist.MergeArray(change, deleted, KMergerTypes[i]);
       
  2464 			
       
  2465 			if (aOOMMode)
       
  2466 				{
       
  2467 				TEST(KErrNone == error || KErrNoMemory == error);
       
  2468 				__UHEAP_SETFAIL(RHeap::ENone, 0);
       
  2469 				}
       
  2470 			else 
       
  2471 				{
       
  2472 				TEST(KErrNone == error);
       
  2473 				// Verifies affected arrays.
       
  2474 				CompareSettingsArrays(persist, aPersistRef[i]);
       
  2475 				CompareSettingsArrays(change, aChangeRef[i]);
       
  2476 				CompareUint32Arrays(deleted, aDeletedRef[i]);
       
  2477 				} 
       
  2478 
       
  2479 			// Resets the arrays.			
       
  2480 			persist.Reset();
       
  2481 			change.Reset();		
       
  2482 			deleted.Reset();
       
  2483 			
       
  2484 			__UHEAP_MARKEND;
       
  2485 			} while(KErrNoMemory == error);
       
  2486 	 	if (aOOMMode)
       
  2487 	 		{
       
  2488 			TheTest.Printf(_L("- MergeArray for type %d succeeded at heap failure rate of %i\n"), KMergerTypes[i], count);	 		
       
  2489 	 		}
       
  2490 		}
       
  2491 	}
       
  2492 
       
  2493 /**
       
  2494 @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-UT-4037
       
  2495 @SYMTestCaseDesc This test case verifies the re-factored CentralRepository internal merge function (MergeArray).
       
  2496 @SYMTestPriority High
       
  2497 @SYMTestActions	 For each merger type, calls MergeArray() with the pre-defined arrays: this, aChanges, aDeleted, 
       
  2498                  which would be changed by the function. Verifies these 3 arrays with the reference arrays as well as 
       
  2499                  the return code after MergeArray() returns.
       
  2500                  This case also carries out the OOM test for function MergeArray().
       
  2501 @SYMTestExpectedResults MergeArray() should return no error and these 3 arrays should be identical with the reference
       
  2502                         arrays. In OOM mode, only KErrNoMemory or KErrNone should be returned.
       
  2503 @SYMDEF DEF116629
       
  2504 */
       
  2505 LOCAL_C void DEF116629L()
       
  2506 	{
       
  2507 
       
  2508 	// Data used to construct the reference arrays of each merge type:
       
  2509 	// ETransactionMerge
       
  2510 	const ServerSettingStruct settingStructPersistAfterTrans[] = {{4,0,4}, {5,0,5}, {6,0,6}, {7,0,8}, {9,0,10}, {11,0,11}, {13,0,13}};
       
  2511 	const ServerSettingStruct settingStructChangeAfterTrans[] = {{1,TServerSetting::EDeleted,1}, 
       
  2512 		{3,TServerSetting::EDeleted,3}, {4,0,4}, {6,0,6}, {7,0,8}, {9,0,10}};
       
  2513 
       
  2514 	// ERestoreMerge
       
  2515 	const ServerSettingStruct settingStructPersistAfterRest[] = {{1,0,1}, {2,0,2}, {3,KMetaBackup,3}, {4,0,4}, {5,0,5}, {6,0,6}, {7,0,8}, {9,0,10}, {11,0,11}, {13,0,13}};
       
  2516 	const ServerSettingStruct settingStructChangeAfterRest[] = {{2,0,2}, {4,0,4}, {6,0,6}, {7,0,8}, {9,0,10}};
       
  2517 	
       
  2518 	// ESWIUpgradeMerge
       
  2519 	const ServerSettingStruct settingStructPersistAfterSWIUp[] = {{1,0,1}, {2,0,2}, {3,KMetaBackup,3}, {4,0,4}, {5,0,5}, {6,0,6}, {7,0,7}, {9,0,10}, {11,0,11}, {13,0,13}};
       
  2520 	const ServerSettingStruct settingStructChangeAfterSWIUp[] = {{2,0,2}, {4,0,4}, {6,0,6}, {9,0,10}};
       
  2521 			
       
  2522 	// ESWIDowngradeMerge
       
  2523 	const ServerSettingStruct settingStructPersistAfterSWIDown[] = {{1,0,1}, {2,0,2}, {3,KMetaBackup,3}, {4,0,4}, {5,0,5}, {6,0,6}, {7,0,7}, {9,0,10}, {11,0,11}};
       
  2524 	const ServerSettingStruct settingStructChangeAfterSWIDown[] = {{2,0,2}, {4,0,4}, {6,0,6}, {9,0,10}, {13,0,0}};
       
  2525 
       
  2526 	// ERomFlash
       
  2527 	const ServerSettingStruct settingStructPersistAfterRomFlash[] = {{1,0,1}, {2,0,2}, {3,KMetaBackup,3}, {4,0,4}, {5,0,5}, {6,0,6}, {7,0,7}, {9,0,10}, {11,0,11}};	
       
  2528 	const ServerSettingStruct settingStructChangeAfterRomFlash[] = {{1,0,1}, {2,0,2}, {3,0,3}, {4,0,4}, {5,0,5}, {6,0,6}, {7,0,8}, {9,0,10}};			
       
  2529 	
       
  2530 	// Reference arrays
       
  2531 	RSettingsArray persistAfter[5];
       
  2532 	RSettingsArray changeAfter[5];
       
  2533 	RArray<TUint32> deletedAfter[5]; 
       
  2534 	
       
  2535 	// Sets up the reference arrays for each merge type:
       
  2536 	// ETransactionMerge
       
  2537 	SetupSettingsArrayL(persistAfter[0],settingStructPersistAfterTrans, sizeof(settingStructPersistAfterTrans)/sizeof(ServerSettingStruct));
       
  2538 	SetupSettingsArrayL(changeAfter[0],settingStructChangeAfterTrans, sizeof(settingStructChangeAfterTrans)/sizeof(ServerSettingStruct));
       
  2539 	deletedAfter[0].InsertInUnsignedKeyOrderL(3);
       
  2540 	
       
  2541 	// ERestoreMerge
       
  2542 	SetupSettingsArrayL(persistAfter[1],settingStructPersistAfterRest, sizeof(settingStructPersistAfterRest)/sizeof(ServerSettingStruct));
       
  2543 	SetupSettingsArrayL(changeAfter[1],settingStructChangeAfterRest, sizeof(settingStructChangeAfterRest)/sizeof(ServerSettingStruct));
       
  2544 	//deletedAfter[1] should be empty because Restore Merge should not delete any setting.
       
  2545 
       
  2546 	// ESWIUpgradeMerge
       
  2547 	SetupSettingsArrayL(persistAfter[2],settingStructPersistAfterSWIUp, sizeof(settingStructPersistAfterSWIUp)/sizeof(ServerSettingStruct));
       
  2548 	SetupSettingsArrayL(changeAfter[2],settingStructChangeAfterSWIUp, sizeof(settingStructChangeAfterSWIUp)/sizeof(ServerSettingStruct));
       
  2549 	//deletedAfter[2] should be empty because SWIUpgrade Merge should not delete any setting.
       
  2550 
       
  2551 	// ESWIDowngradeMerge
       
  2552 	SetupSettingsArrayL(persistAfter[3],settingStructPersistAfterSWIDown, sizeof(settingStructPersistAfterSWIDown)/sizeof(ServerSettingStruct));
       
  2553 	SetupSettingsArrayL(changeAfter[3],settingStructChangeAfterSWIDown, sizeof(settingStructChangeAfterSWIDown)/sizeof(ServerSettingStruct));
       
  2554 	//deletedAfter[3] should be empty because settings deleted by SWIDowngrade Merge are recorded in aChanges.
       
  2555 
       
  2556 	// ERomFlash
       
  2557 	SetupSettingsArrayL(persistAfter[4],settingStructPersistAfterRomFlash, sizeof(settingStructPersistAfterRomFlash)/sizeof(ServerSettingStruct));
       
  2558 	SetupSettingsArrayL(changeAfter[4],settingStructChangeAfterRomFlash, sizeof(settingStructChangeAfterRomFlash)/sizeof(ServerSettingStruct));
       
  2559 	//deletedAfter[4] should be empty because settings deleted by RomFlash Merge are recorded in aChanges.
       
  2560 	
       
  2561 	TheTest.Printf(_L("- Verification test for MergeArray.\n"));
       
  2562 	MergerArrayTestL(persistAfter, changeAfter, deletedAfter, EFalse);
       
  2563 	
       
  2564 	TheTest.Printf(_L("- OOM test for MergeArray.\n"));
       
  2565 	MergerArrayTestL(persistAfter, changeAfter, deletedAfter, ETrue);
       
  2566 
       
  2567 	// Resets the reference arrays.		
       
  2568 	for(TInt i = 0; i < sizeof(KMergerTypes) / sizeof(TMergeType); i++)
       
  2569 		{
       
  2570 		persistAfter[i].Reset();
       
  2571 		changeAfter[i].Reset();
       
  2572 		deletedAfter[i].Reset();
       
  2573 		}
       
  2574 	}
       
  2575 /**
       
  2576 @SYMTestCaseID 				PDS-CENTRALREPOSITORY-UT-4046	
       
  2577 @SYMTestCaseDesc 			The centrep server panics when it reads a repository text file where 
       
  2578 							the value of a binary settings is missing.
       
  2579 @SYMTestPriority 			Medium
       
  2580 @SYMTestActions  			- Provide a repository text file for this test which have a binary 
       
  2581 							setting which value is missing. 
       
  2582  							- Open the repository text file, 
       
  2583 							this should return KErrCorrupt when parsing the repository text file.
       
  2584 @SYMTestExpectedResults 	The test must not fail. 
       
  2585 @SYMDEF 					PDEF126904 
       
  2586 */    
       
  2587 LOCAL_C void PDEF126904L()
       
  2588    	{
       
  2589    	const TUid KUidBinaryValueRepositoryFile ={0x1020506B};
       
  2590    	const TInt KBinaryValueRepKey = 0xA;
       
  2591    	TInt binaryValue = 0;
       
  2592    	CRepository* repository = NULL;
       
  2593    	
       
  2594    	TRAPD(res, repository = CRepository::NewL(KUidBinaryValueRepositoryFile));		
       
  2595    	if (res == KErrNone)
       
  2596  		{
       
  2597  		TInt err = KErrNone;
       
  2598  		CleanupStack::PushL(repository);
       
  2599  		err = repository->Get(KBinaryValueRepKey, binaryValue);
       
  2600 		User::LeaveIfError(err);
       
  2601  		CleanupStack::PopAndDestroy(repository);
       
  2602  		}
       
  2603  	else if (res == KErrCorrupt)
       
  2604  		{
       
  2605  		//This is just to confirm that the err should be KErrCorrupt.
       
  2606 		TheTest.Printf(_L("The error is KErrCorrupt as expected.\n"));
       
  2607 		}
       
  2608  	else
       
  2609 		{
       
  2610  		User::Leave(res);
       
  2611  		}
       
  2612 }	
       
  2613 
       
  2614 /**
       
  2615 @SYMTestCaseID 				PDS-CENTRALREPOSITORY-UT-4084	
       
  2616 @SYMTestCaseDesc 			Ensure that the timestamp in a TXT file is always zero when not specified
       
  2617 							instead of arbitrary value
       
  2618 @SYMTestPriority 			Medium
       
  2619 @SYMTestActions  			Create the CHeapRepository object from a TXT keyspace file where no timestamp(legacy)
       
  2620 							section is specified. The timestamp should be set to zero
       
  2621 @SYMTestExpectedResults 	The test must not fail. 
       
  2622 @SYMDEF 					DEF136161 
       
  2623 */ 
       
  2624 LOCAL_C void DEF136161L()
       
  2625 	{
       
  2626 	RFs fs;
       
  2627 	User::LeaveIfError(fs.Connect());
       
  2628 	
       
  2629 	//this is a TXT based ROM keyspace
       
  2630 	const TUid KTestUid={0x00000001};
       
  2631 
       
  2632 	CHeapRepository* repos=CHeapRepository::NewL(KTestUid);
       
  2633 	CIniFileIn* iniFile;
       
  2634 	TInt ret=CIniFileIn::NewLC(fs,iniFile,_L("z:\\private\\10202be9\\00000001.txt"));
       
  2635 	User::LeaveIfError(ret);
       
  2636 	repos->ReloadContentL(*iniFile);
       
  2637 	
       
  2638 	//check the timestamp is always set to zero
       
  2639 	TEST(repos->TimeStamp()==TTime(0));
       
  2640 	
       
  2641 	CleanupStack::PopAndDestroy(iniFile);
       
  2642 	delete repos;
       
  2643 	
       
  2644 	fs.Close();
       
  2645 	}
       
  2646 
       
  2647 /**
       
  2648 @SYMTestCaseID PDS-CENTRALREPOSITORY-UT-4085
       
  2649 @SYMTestCaseDesc  Central Repository: Trying to configure Central Repository cache with centrep.in 
       
  2650 @SYMTestPriority High
       
  2651 @SYMTestActions	Testing that the SWIWatcher does nto leave when the cache configuration exists within
       
  2652 the private data cate
       
  2653 @SYMTestExpectedResults Test should pass and exhibit the expected behaviour
       
  2654 @SYMDEF PDEF139979
       
  2655 */
       
  2656 LOCAL_C void PDEF139979L()
       
  2657     {
       
  2658     __UHEAP_MARK;   
       
  2659     CActiveScheduler* s=new(ELeave) CActiveScheduler;
       
  2660     CleanupStack::PushL(s);
       
  2661     CActiveScheduler::Install(s);
       
  2662         
       
  2663     RFs fs;
       
  2664     User::LeaveIfError(fs.Connect());
       
  2665     CleanupClosePushL(fs);
       
  2666     
       
  2667     CFileMan* fm = CFileMan::NewL(fs);
       
  2668     CleanupStack::PushL(fm);    
       
  2669 
       
  2670     TRAPD(err,TServerResources::InitialiseL());
       
  2671     TEST2(err,KErrNone);    
       
  2672     
       
  2673     delete TServerResources::iInstallDirectory;
       
  2674     _LIT(KInstallFolder,"c:\\private\\12345678\\");
       
  2675     TServerResources::iInstallDirectory=(KInstallFolder()).AllocL();
       
  2676     TInt erro=fm->Delete(_L("c:\\private\\12345678\\*.*"));
       
  2677     //copy centrep.ini file to the install folder
       
  2678     _LIT(KSource,"z:\\private\\10202be9\\centrepcache.ini0");
       
  2679     _LIT(KDestination,"c:\\private\\12345678\\centrep.ini");
       
  2680     TRAP(err,CopyTestFilesL(*fm,KSource(),KDestination()));
       
  2681     
       
  2682     CCentRepSWIWatcher* swi=CCentRepSWIWatcher::NewL(fs);
       
  2683     TRAP(err,swi->FindChangedEntriesL(EFalse));
       
  2684     TEST2(err,KErrNone);
       
  2685     
       
  2686     delete swi;
       
  2687     TServerResources::Close();
       
  2688     
       
  2689     //delete the c file before we exit
       
  2690     fm->Delete(KDestination());
       
  2691     
       
  2692     CleanupStack::PopAndDestroy(3);
       
  2693     __UHEAP_MARKEND;  
       
  2694     }
       
  2695 
       
  2696 /**
       
  2697 @SYMTestCaseID PDS-CENTRALREPOSITORY-UT-4086
       
  2698 @SYMTestCaseDesc centralrepositorysrv.exe crashes and phone doesn't boot up 
       
  2699 @SYMTestPriority High
       
  2700 @SYMTestActions  Test merging two settings of different type, one type exist for
       
  2701 persist and one type for the new rom, when the type differes, we expect the
       
  2702 persist setting to be completely replaced by the rom.
       
  2703 @SYMTestExpectedResults The test must not panic or fail.
       
  2704 @SYMDEF PDEF141519
       
  2705 */
       
  2706 LOCAL_C void PDEF141519L()
       
  2707     {
       
  2708     __UHEAP_MARK;
       
  2709     
       
  2710     RSettingsArray persist;
       
  2711     RSettingsArray newRom;
       
  2712     RArray<TUint32> deletedSettings;
       
  2713     //persist setting
       
  2714     TServerSetting a(0x10);
       
  2715     a.SetType(TServerSetting::EInt);
       
  2716     a.SetIntValue(100);
       
  2717     persist.OrderedInsertL(a);
       
  2718     
       
  2719     //new rom setting
       
  2720     TServerSetting b(0x10);
       
  2721     b.SetType(TServerSetting::EString);
       
  2722     TBuf8<5> buffer(_L8("abc"));
       
  2723     HBufC8* hbuf=buffer.AllocL();
       
  2724     b.SetStrValue(hbuf);
       
  2725     newRom.OrderedInsertL(b);   
       
  2726     
       
  2727     User::LeaveIfError(persist.MergeArray(newRom,deletedSettings,ERomFlash));
       
  2728     TServerSetting* persistEntry=persist.Find(0x10);
       
  2729     TEST2(persistEntry->Key(),0x10);
       
  2730     TEST2(persistEntry->Type(),TServerSetting::EString);
       
  2731     const HBufC8* val=persistEntry->GetStrValue();
       
  2732     TEST2(val->Compare(buffer),0);
       
  2733     
       
  2734     persist.Close();
       
  2735     newRom.Close();
       
  2736     
       
  2737     __UHEAP_MARKEND;
       
  2738     } 
       
  2739 
       
  2740 	
       
  2741 LOCAL_C void FuncTestsL()
       
  2742 	{
       
  2743 
       
  2744 	TheTest.Start(_L("DEF053500 - Central repository integer type key entries cannot handle hex values"));
       
  2745 
       
  2746 	DEF053500L();
       
  2747 
       
  2748 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-4015 DEF111734 - Central repository crashes when accessing a closed repository with active transaction "));
       
  2749 	DEF111734L();
       
  2750 
       
  2751     TheTest.Next(_L("DEF054368 - MetaData value in CentRep setting is not optional"));
       
  2752 	DEF054368L();
       
  2753 
       
  2754 	TheTest.Next(_L("DEF055680 - Central repository find performance could be improved "));
       
  2755 	DEF055680L();
       
  2756 
       
  2757     TheTest.Next(_L("INC054688 - Key based capabilities in ini-file crashes cenrep server "));
       
  2758 	INC054688L();
       
  2759 
       
  2760 	TheTest.Next(_L("DEF054632 - CenRep Initialisation default data does not work as expected"));
       
  2761 	DEF054632L();
       
  2762 
       
  2763 	TheTest.Next(_L("DEF055661 - Central Repository does not allow AlwaysFail to be set for access control. "));
       
  2764 	DEF055661L();
       
  2765 
       
  2766 	TheTest.Next(_L("DEF055267 - Can not insert more than 71 records into WapAccessPoint Table "));
       
  2767 	DEF055267L();
       
  2768 
       
  2769 	TheTest.Next(_L("INC056194 - NTT - Central Repository checks DefaultWriteAccessPolicy when cancelling notif "));
       
  2770 	INC056194L();
       
  2771 
       
  2772 	TheTest.Next(_L("DEF057145 - CenRepSrv KERN-EXEC3 when running CommDB test harness "));
       
  2773 	DEF057145L();
       
  2774 
       
  2775 	TheTest.Next(_L("DEF057778 - Central repository ResetAll can cause user Panic 190 "));
       
  2776 	DEF057778L();
       
  2777 
       
  2778 	TheTest.Next(_L("DEF057522 - Centralrepository security policy incorrect behaviour "));
       
  2779 	DEF057522L();
       
  2780 
       
  2781 	TheTest.Next(_L("DEF057999 - Creating and deleting the same setting in a transaction doesn't work "));
       
  2782 	DEF057999L();
       
  2783 
       
  2784 	TheTest.Next(_L("DEF057470 - Central repository lacks a range delete method "));
       
  2785 	DEF057470L();
       
  2786 
       
  2787     TheTest.Next(_L("INC058229 - CInstallFileWatcher::ReadInstallDirL contains insufficient error handling "));
       
  2788 	INC058229L();
       
  2789 
       
  2790 	TheTest.Next(_L("DEF058900 - CentralRepository Notification section document needs update "));
       
  2791 	DEF058900L();
       
  2792 
       
  2793 	TheTest.Next(_L("DEF061087 - Central repository cannot handle more than one range policy "));
       
  2794 	DEF061087L();
       
  2795 
       
  2796 	TheTest.Next(_L("DEF060843 - [PSAudit] Lack of centralrep. data type checking could cause instability & bugs "));
       
  2797 	DEF060843L();
       
  2798 
       
  2799 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-1433 INC069013 - Central repository panics the client when trying to read 8-bit descriptor with uneven length "));
       
  2800 	INC069013L();
       
  2801 
       
  2802 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-1434 DEF070731 - Central repository doesn't handle corrupt .cre files correctly. "));
       
  2803 	DEF070731L();
       
  2804 
       
  2805 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-1683 DEF084700 - UIF automated tests crash H4 board. "));
       
  2806 	DEF084700L();
       
  2807 
       
  2808 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-1862 DEF089945: [AQP] CommitTransaction returns incorrect error code if Find~L methods run OOM "));
       
  2809 	DEF089945L();
       
  2810 
       
  2811 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-3242 PDEF098500 - Backup to memory card causes phone freeze "));
       
  2812 	PDEF098500();
       
  2813 
       
  2814 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-1884 DEF093855: CenRep cancels transactions if they exceed 5 seconds... "));
       
  2815 	DEF093855L();
       
  2816 	
       
  2817 	
       
  2818 //	When adding a new defect test, if you decide to reuse a repository that has already been used 
       
  2819 //  in another defect test, make sure you modify the existing test which uses the repository and 
       
  2820 //  add the cache delay after that test closes the repository. e.g. DEF055680L
       
  2821 
       
  2822 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-3477 PDEF106507 - Currupt installdir.bin file causes server to crash "));
       
  2823 	PDEF106507L();
       
  2824 
       
  2825 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-3517 INC108803 - R3.2 stability problems: CentralRepositorySrv crash "));
       
  2826 	INC108803L();
       
  2827 	
       
  2828 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-3545 DEF109390: Centrep cache ini file corruption should not cause server crash. "));
       
  2829 	DEF109390L();
       
  2830 
       
  2831 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-UT-4024 DEF116043: Cenrep doesn't protect against overflows in sorting "));
       
  2832 	DEF116043L();
       
  2833 
       
  2834 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-4035 DEF117987: CenrepNotify handler does not leave/return error "));
       
  2835 	DEF117987L();
       
  2836 
       
  2837 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-4034 DEF117848: Centrep notifier handler does not check return codes "));
       
  2838 	DEF117848L();
       
  2839 
       
  2840 	TheTest.Next(_L(" @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-4036 DEF118107: Central Repository Notification Handler flooded with notifications "));
       
  2841 	DEF118107L();
       
  2842 	
       
  2843 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-UT-4037 DEF116629: CentralRepository internal merge function need to be refactored and documented")); 
       
  2844 	DEF116629L();
       
  2845 	
       
  2846 	TheTest.Next(_L(" @SYMTestCaseID:PDS-CENTRALREPOSITORY-UT-4046 PDEF126904  - Ini-file parsing of Symbian provided central repository server crashes"));
       
  2847 	PDEF126904L();
       
  2848 	TheTest.Next(_L(" @SYMTestCaseID:PDS-CENTRALREPOSITORY-UT-4081 DEF132807 - CObservable::ObserverSortOrder ordering algorithm is wrong "));	
       
  2849 	DEF132807L();	
       
  2850 
       
  2851 	TheTest.Next(_L("@SYMTestCaseID:PDS-CENTRALREPOSITORY-UT-4084 DEF136161: CenRep file timestamp is never intialised  "));
       
  2852 	DEF136161L();
       
  2853 
       
  2854 	TheTest.Next(_L("@SYMTestCaseID:PDS-CENTRALREPOSITORY-UT-4085 PDEF139979: Central Repository: Trying to configure Central Repository cache with centrep.in  "));
       
  2855   PDEF139979L();
       
  2856 
       
  2857 	TheTest.Next(_L("@SYMTestCaseID:PDS-CENTRALREPOSITORY-UT-4086 PDEF141518: centralrepositorysrv.exe crashes and phone doesn't boot up "));
       
  2858 	PDEF141519L(); 
       
  2859 
       
  2860 	TheTest.End();
       
  2861 	}
       
  2862 
       
  2863 LOCAL_C void MainL()
       
  2864 	{
       
  2865 	TheTest.Start(_L("Defect tests"));
       
  2866 	CleanupCDriveL();
       
  2867 
       
  2868 	FuncTestsL();
       
  2869 
       
  2870 	TheTest.Next(_L("Clean out C: files"));
       
  2871 	CleanupCDriveL();
       
  2872 
       
  2873 	TheTest.End();
       
  2874 	TheTest.Close();
       
  2875 	}
       
  2876 
       
  2877 TInt E32Main()
       
  2878 	{
       
  2879 	//
       
  2880 	// For the tests to work we need SID policing enforced plus the specific
       
  2881 	// capabilities listed below.
       
  2882 	//
       
  2883 	// These are dependent on the capabilities set in the platform security
       
  2884 	// repository test initialisation file 87654321.txt.  If the content
       
  2885 	// of that file changes then the following clauses may need to be
       
  2886 	// updated.
       
  2887 	//
       
  2888 	if(!PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement) ||
       
  2889 			!PlatSec::IsCapabilityEnforced(ECapabilityNetworkServices) ||
       
  2890 			!PlatSec::IsCapabilityEnforced(ECapabilityDRM) ||
       
  2891 			!PlatSec::IsCapabilityEnforced(ECapabilityLocalServices) ||
       
  2892 			!PlatSec::IsCapabilityEnforced(ECapabilityCommDD))
       
  2893 		{
       
  2894 		TheTest.Start(_L("NOTE: Skipping tests due to incompatible PlatSec enforcement settings"));
       
  2895 		TheTest.End();
       
  2896 		TheTest.Close();
       
  2897 		return 0;
       
  2898 		}
       
  2899 
       
  2900 	__UHEAP_MARK;
       
  2901 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
  2902 	if(!cleanup)
       
  2903 		return KErrNoMemory;
       
  2904 
       
  2905 	TRAPD(err, MainL());
       
  2906 	if (err != KErrNone)
       
  2907 		User::Panic(_L("Testing failed: "), err);
       
  2908 
       
  2909 	delete cleanup;
       
  2910 	__UHEAP_MARKEND;
       
  2911 
       
  2912 	return 0;
       
  2913 	}