persistentstorage/centralrepository/test/multirofs/src/t_cenrep_preq2112u.cpp
changeset 0 08ec8eefde2f
child 55 44f437012c90
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2008-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 "obsrvr_noc.h"
       
    23 #include "panic.h"
       
    24 #include "srvres.h"
       
    25 
       
    26 using namespace NCentralRepositoryConstants;
       
    27 
       
    28 RTest TheTest(_L("Central Repository Defect Tests"));
       
    29 
       
    30 
       
    31 ///////////////////////////////////////////////////////////////////////////////////////
       
    32 ///////////////////////////////////////////////////////////////////////////////////////
       
    33 //Test macroses and functions
       
    34 LOCAL_C void CheckL(TInt aValue, TInt aLine)
       
    35 	{
       
    36 	if(!aValue)
       
    37 		{
       
    38 		CleanupCDriveL();
       
    39 		TheTest(EFalse, aLine);
       
    40 		}
       
    41 	}
       
    42 LOCAL_C void CheckL(TInt aValue, TInt aExpected, TInt aLine)
       
    43 	{
       
    44 	if(aValue != aExpected)
       
    45 		{
       
    46 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
       
    47 		CleanupCDriveL();
       
    48 		TheTest(EFalse, aLine);
       
    49 		}
       
    50 	}
       
    51 
       
    52 #define TEST(arg) ::CheckL((arg), __LINE__)
       
    53 #define TEST2(aValue, aExpected) ::CheckL(aValue, aExpected, __LINE__)
       
    54 
       
    55 struct TExitDetails
       
    56 	{
       
    57 	TExitCategoryName iCategory;
       
    58 	TExitType iExitType;
       
    59 	TInt iReason;
       
    60 	};
       
    61 
       
    62 typedef void (*TestFunction)();
       
    63 
       
    64 ///////////////////////////////////////////////////////////////////////////////////////
       
    65 ///////////////////////////////////////////////////////////////////////////////////////
       
    66 
       
    67 
       
    68 LOCAL_C void PREQ2112L(TUid aUid)
       
    69 	{
       
    70 	__UHEAP_MARK;
       
    71 
       
    72 	CRepository* multi=CRepository::NewLC(aUid);
       
    73 
       
    74 	//Test retrieving the merged contents
       
    75 
       
    76 	RArray<TUint32> foundSettings;
       
    77 	CleanupClosePushL(foundSettings);
       
    78 
       
    79 	//Check number of settings first(see spreadsheet)
       
    80 	multi->FindL(0xFFFFFFFF,0,foundSettings);
       
    81 	TEST(foundSettings.Count()==10);
       
    82 
       
    83 	//now check value of individual settings value first
       
    84 	TInt intVal;
       
    85 	TReal realVal;
       
    86 	TBuf8<255> string8;
       
    87 	User::LeaveIfError(multi->Get(1,intVal));
       
    88 	TEST2(intVal,101);
       
    89 	User::LeaveIfError(multi->Get(2,string8));
       
    90 	TEST(string8.Compare(_L8("abc"))==0);
       
    91 	User::LeaveIfError(multi->Get(3,intVal));
       
    92 	TEST(intVal==100);
       
    93 	User::LeaveIfError(multi->Get(4,intVal));
       
    94 	TEST(intVal==100);
       
    95 	User::LeaveIfError(multi->Get(5,intVal));
       
    96 	TEST(intVal==101);
       
    97 	User::LeaveIfError(multi->Get(6,realVal));
       
    98 	TEST(realVal==102.102);
       
    99 	User::LeaveIfError(multi->Get(7,intVal));
       
   100 	TEST(intVal==100);
       
   101 	User::LeaveIfError(multi->Get(9,intVal));
       
   102 	TEST(intVal==900);
       
   103 	//FOR id=10 if overriding is scucessufl we will fail to read
       
   104 	//this as it require sid_wr=200
       
   105 	TInt err=multi->Get(10,intVal);
       
   106 	TEST(err==KErrPermissionDenied);
       
   107 	User::LeaveIfError(multi->Get(300,realVal));
       
   108 	TEST(realVal==1.23);
       
   109 
       
   110 	//now check the meta
       
   111 	TUint32 meta;
       
   112 	User::LeaveIfError(multi->GetMeta(1,meta));
       
   113 	TEST(meta==0x10);
       
   114 	User::LeaveIfError(multi->GetMeta(2,meta));
       
   115 	TEST(meta==0x10);
       
   116 	User::LeaveIfError(multi->GetMeta(3,meta));
       
   117 	TEST(meta==0xFF);
       
   118 	User::LeaveIfError(multi->GetMeta(4,meta));
       
   119 	TEST(meta==0x10);
       
   120 	User::LeaveIfError(multi->GetMeta(5,meta));
       
   121 	TEST(meta==99);
       
   122 	User::LeaveIfError(multi->GetMeta(6,meta));
       
   123 	TEST(meta==0x10);
       
   124 	User::LeaveIfError(multi->GetMeta(7,meta));
       
   125 	TEST(meta==0x10);
       
   126 	User::LeaveIfError(multi->GetMeta(9,meta));
       
   127 	TEST(meta==0x10);
       
   128 	err=multi->GetMeta(10,meta);
       
   129 	TEST(err==KErrPermissionDenied);
       
   130 	User::LeaveIfError(multi->GetMeta(300,meta));
       
   131 	TEST(meta==999);
       
   132 
       
   133 	//now check the platsec
       
   134 	err=multi->Set(7,7);
       
   135 	TEST(err==KErrPermissionDenied);
       
   136 
       
   137 
       
   138 	//lets make some modification to test for ResetAll and Reset key
       
   139 	//modification to existing key
       
   140 	err=multi->Set(5,123);
       
   141 	TEST(err==KErrNone);
       
   142 	//creation of a new key
       
   143 	err=multi->Set(150,150);
       
   144 	TEST(err==KErrNone);
       
   145 
       
   146 	//validating what we set just now
       
   147 	err=multi->Get(5,intVal);
       
   148 	TEST(err==KErrNone);
       
   149 	TEST(intVal==123);
       
   150 	err=multi->Get(150,intVal);
       
   151 	TEST(err==KErrNone);
       
   152 	TEST(intVal==150);
       
   153 
       
   154 	//SINGLE RESET
       
   155 	err=multi->Reset(5);
       
   156 	TEST(err==KErrNone);
       
   157 
       
   158 	//check value following reset
       
   159 	err=multi->Get(5,intVal);
       
   160 	TEST(err==KErrNone);
       
   161 	TEST(intVal==101);
       
   162 	err=multi->Get(150,intVal);
       
   163 	TEST(err==KErrNone);
       
   164 	TEST(intVal==150);
       
   165 
       
   166 	//modification again before calling ResetAll
       
   167 	err=multi->Set(5,132);
       
   168 	TEST(err==KErrNone);
       
   169 	err=multi->Get(5,intVal);
       
   170 	TEST(err==KErrNone);
       
   171 	TEST(intVal==132);
       
   172 
       
   173 	//RESET ALL
       
   174 	err=multi->Reset();
       
   175 	TEST(err==KErrNone);
       
   176 	//checking value following reset
       
   177 	err=multi->Get(5,intVal);
       
   178 	TEST(err==KErrNone);
       
   179 	TEST(intVal==101);	//merged ROM value
       
   180 	err=multi->Get(150,intVal);
       
   181 	TEST(err==KErrNotFound);
       
   182 
       
   183 	CleanupStack::PopAndDestroy(2);
       
   184 
       
   185 	__UHEAP_MARKEND;
       
   186 	}
       
   187 
       
   188 /**
       
   189 @SYMTestCaseID PDS-CENTRALREPOSITORY-CT-4078
       
   190 @SYMTestCaseDesc Testing single Reset and ResetAll in a multi rofs environment
       
   191 @SYMTestPriority High
       
   192 @SYMTestActions  This test the centrep API that will result in reopening of the ROM files in this test case, the
       
   193 				 main use case is single Reset and ResetAll.This test is repeated for the following ROFS keyspace
       
   194                  combination (ROFS1/ROFS2) such as TXT/TXT , CRE/TXT or TXT/CRE and CRE/CRE.
       
   195 @SYMTestExpectedResults The merged values of the settings should match the expected values.
       
   196 @SYMREQ REQ11282
       
   197 */
       
   198 LOCAL_C void FuncTestsL()
       
   199 	{
       
   200 	TheTest.Next (_L (" @SYMTestCaseID:PDS-CENTRALREPOSITORY-CT-4078 Testing single Reset and ResetAll in a multi rofs environment "));
       
   201 	__UHEAP_MARK;
       
   202 
       
   203 	//txt version both core and rofs
       
   204 	TUid test_uid={0xFFFF0000};
       
   205 	PREQ2112L(test_uid);
       
   206 
       
   207 	//cre version both core and rofs(equiv to txt above)
       
   208 
       
   209 	test_uid.iUid=0xEEEE0000;
       
   210 	PREQ2112L(test_uid);
       
   211 
       
   212 	//txt/cre mix core=txt rofs=cre
       
   213 	test_uid.iUid=0xDDDD0000;
       
   214 	PREQ2112L(test_uid);
       
   215 
       
   216 	//txt/cre mix core=cre rofs=txt
       
   217 	test_uid.iUid=0xCCCC0000;
       
   218 	PREQ2112L(test_uid);
       
   219 
       
   220 	__UHEAP_MARKEND;
       
   221 	}
       
   222 
       
   223 /**
       
   224 @SYMTestCaseID PDS-CENTRALREPOSITORY-UT-4052
       
   225 @SYMTestCaseDesc Server side resolving/processing of multi rofs entry list
       
   226 @SYMTestPriority High
       
   227 @SYMTestActions  Call to the static function in TServerResources to generate the cache list and verify each entry
       
   228                  in the cache list is correct.The environment for this testing should contain at least one multi
       
   229                  rofs keyspace of the following combination (ROFS1/ROFS2) such as TXT/TXT , CRE/TXT or TXT/CRE and CRE/CRE.
       
   230 @SYMTestExpectedResults The correct cache list should be returned with respect to the order and content.
       
   231 @SYMREQ REQ11282
       
   232 */
       
   233 LOCAL_C void DoOOML(const TDesC& aTestDesc, TBool aOOMMode)
       
   234 	{
       
   235 	TheTest.Next (_L (" @SYMTestCaseID:PDS-CENTRALREPOSITORY-UT-4052 CENREPSRV server side multirofs list resolving "));
       
   236 
       
   237 	__UHEAP_MARK;
       
   238 
       
   239 	CActiveScheduler* s=new(ELeave) CActiveScheduler;
       
   240 	CleanupStack::PushL(s);
       
   241 	CActiveScheduler::Install(s);
       
   242 
       
   243 	TheTest.Next(aTestDesc);
       
   244 
       
   245 	//Initializing the server resources
       
   246 	TServerResources::InitialiseL ();
       
   247 
       
   248 	//now lets open up some files
       
   249 	CDir* fileList;
       
   250 	TFileName searchFileFormat;
       
   251 	searchFileFormat.Append(_L("z:\\private\\10202be9\\????0000.???[*-00]"));
       
   252 	User::LeaveIfError(TServerResources::iFs.GetDir(searchFileFormat,KEntryAttNormal,ESortByName,fileList));
       
   253 
       
   254 	TInt err;
       
   255 	TInt tryCount = 0;
       
   256 	do
       
   257 		{
       
   258 		for (TInt i=0;i<TServerResources::iObserver->GetMultiRofsList().Count();i++)
       
   259 			{
       
   260 			TServerResources::iObserver->GetMultiRofsList()[i].iMountFlagList.Close();
       
   261 			}
       
   262 		TServerResources::iObserver->GetMultiRofsList().Reset();
       
   263 		TEST(TServerResources::iObserver->GetMultiRofsList().Count()==0);
       
   264 
       
   265 		__UHEAP_MARK;
       
   266 
       
   267 		// find out the number of open handles
       
   268 		TInt startProcessHandleCount;
       
   269 		TInt startThreadHandleCount;
       
   270 		RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
       
   271 
       
   272 		if (aOOMMode)
       
   273 			__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
       
   274 
       
   275 		TRAP(err, TServerResources::iObserver->ProcessMultiRofsListL(*fileList));
       
   276 		if (err!=KErrNoMemory)
       
   277 			TEST(err==KErrNone);
       
   278 
       
   279 		if (aOOMMode)
       
   280 			__UHEAP_SETFAIL(RHeap::ENone, 0);
       
   281 
       
   282 		// check that no handles have leaked
       
   283 		TInt endProcessHandleCount;
       
   284 		TInt endThreadHandleCount;
       
   285 		RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
       
   286 		TEST2(startProcessHandleCount, endProcessHandleCount);
       
   287 		TEST2(startThreadHandleCount, endThreadHandleCount);
       
   288 
       
   289 		//validate the result if ok
       
   290 		if (err==KErrNone)
       
   291 			{
       
   292 			//now check the processedList
       
   293 			RArray<TMultiRofsList> list=TServerResources::iObserver->GetMultiRofsList();
       
   294 			TEST(list.Count()==6);
       
   295 			TEST(list[0].iRepUid.iUid==0xaaaa0000);
       
   296 			TEST(list[0].iMountFlagList.Count()==1);
       
   297 			TEST(list[0].iMountFlagList[0].iFlag==0x80000001);
       
   298 			TEST(list[1].iRepUid.iUid==0xbbbb0000);
       
   299 			TEST(list[1].iMountFlagList.Count()==1);
       
   300 			TEST(list[1].iMountFlagList[0].iFlag==0x80000001);
       
   301 			TEST(list[2].iRepUid.iUid==0xcccc0000);
       
   302 			TEST(list[2].iMountFlagList.Count()==1);
       
   303 			TEST(list[2].iMountFlagList[0].iFlag==0x80000001);
       
   304 			TEST(list[3].iRepUid.iUid==0xdddd0000);
       
   305 			TEST(list[3].iMountFlagList.Count()==1);
       
   306 			TEST(list[3].iMountFlagList[0].iFlag==0x00000001);
       
   307 			TEST(list[4].iRepUid.iUid==0xeeee0000);
       
   308 			TEST(list[4].iMountFlagList.Count()==1);
       
   309 			TEST(list[4].iMountFlagList[0].iFlag==0x00000001);
       
   310 			TEST(list[5].iRepUid.iUid==0xffff0000);
       
   311 			TEST(list[5].iMountFlagList.Count()==1);
       
   312 			TEST(list[5].iMountFlagList[0].iFlag==0x80000001);
       
   313 			}
       
   314 
       
   315 		for (TInt i=0;i<TServerResources::iObserver->GetMultiRofsList().Count();i++)
       
   316 			{
       
   317 			TServerResources::iObserver->GetMultiRofsList()[i].iMountFlagList.Close();
       
   318 			}
       
   319 		TServerResources::iObserver->GetMultiRofsList().Reset();
       
   320 
       
   321 		__UHEAP_MARKEND;
       
   322 		} while(err == KErrNoMemory);
       
   323 
       
   324 	TEST(err==KErrNone);
       
   325 
       
   326  	if (aOOMMode)
       
   327 		TheTest.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount);
       
   328  	//deleting the file list
       
   329  	delete fileList;
       
   330  	TServerResources::Close();
       
   331  	CleanupStack::PopAndDestroy();
       
   332 
       
   333  	__UHEAP_MARKEND;
       
   334 	}
       
   335 
       
   336 LOCAL_C void MainL()
       
   337 	{
       
   338 	TheTest.Start(_L("Defect tests"));
       
   339 	CleanupCDriveL();
       
   340 
       
   341 	FuncTestsL();
       
   342 
       
   343 	//Testing the processing/resolving of multiple repository list
       
   344 	DoOOML(_L("Basic Unit Test"),EFalse);
       
   345 	DoOOML(_L("OOM Unit Test"),ETrue);
       
   346 
       
   347 	TheTest.Next(_L("Clean out C: files"));
       
   348 	CleanupCDriveL();
       
   349 
       
   350 	TheTest.End();
       
   351 	TheTest.Close();
       
   352 	}
       
   353 
       
   354 TInt E32Main()
       
   355 	{
       
   356 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   357 	if(!cleanup)
       
   358 		return KErrNoMemory;
       
   359 
       
   360 	TRAPD(err, MainL());
       
   361 	if (err != KErrNone)
       
   362 		User::Panic(_L("Testing failed: "), err);
       
   363 
       
   364 	delete cleanup;
       
   365 
       
   366 	return 0;
       
   367 	}