os/kernelhwsrv/kerneltest/e32test/hcr/t_hcr.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 the License "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 // Hardware Configuration Respoitory Test Application
    15 //
    16 
    17 #define __E32TEST_EXTENSION__
    18 #include <e32test.h>
    19 #include <e32rom.h>
    20 #include <e32svr.h>
    21 #include <e32hashtab.h>
    22 #include <e32base.h>
    23 #include "d_hcrsim.h"
    24 #include "d_hcrsim_testdata.h"
    25 #include "hcr_uids.h"
    26 
    27 _LIT8(KTestFileRepos,	"filerepos.dat");
    28 _LIT8(KTestNandRepos,	"nandrepos.dat");
    29 _LIT8(KTestCorrupt1,	"corrupt1.dat");
    30 _LIT8(KTestCorrupt2,	"corrupt2.dat");
    31 _LIT8(KTestEmpty,		"empty.dat");
    32 _LIT8(KTestMegaLarge1,	"megalarge1.dat");
    33 _LIT8(KTestMegaLarge2,	"megalarge2.dat");
    34 _LIT8(KTestClearRepos,	"");
    35 
    36 
    37 static const TInt KSimOwnThread = 0;
    38 static const TInt KSimClientThread = 1;
    39 static TInt gHcrThread = KSimOwnThread;
    40 
    41 //Calculation of the fraction defined by f for the number x
    42 #define _FRACTION(x, f)    (x>f ? x/f : x)
    43 
    44 
    45 RTest test(_L("T_HCR"));
    46 RHcrSimTestChannel HcrSimTest;
    47 
    48 //Helper function to compare two SSettingId parameters. It's used in 
    49 //GetMultipleWord settings array
    50 TInt CompareEntries (const SSettingC& a1, const SSettingC& a2)
    51 	{
    52 	if (a1.iName.iId.iCat > a2.iName.iId.iCat)
    53 		return (1); 
    54 
    55 	if (a1.iName.iId.iCat < a2.iName.iId.iCat)
    56 		return (-1);
    57 
    58 	// Categories are the same at this point, check keys.
    59 	if (a1.iName.iId.iKey > a2.iName.iId.iKey)
    60 		return (1); 
    61 
    62 	if (a1.iName.iId.iKey < a2.iName.iId.iKey)
    63 		return (-1);
    64 
    65 	// Both Categories and jeys are the same here.
    66 	return (0); 
    67 	}
    68 
    69 
    70 
    71 void HcrSimGetSettings(SSettingC* aRepository, TUint aNumberOfSettings)
    72 	{
    73 	test.Next(_L("GetSettings"));
    74 	TInt r;
    75 	SSettingC* setting;
    76 	for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
    77 		{
    78 		TSettingId id(setting->iName.iId.iCat, setting->iName.iId.iKey);
    79 		test.Printf(_L("(0x%08x, 0x%08x)\n"), id.iCat, id.iKey);
    80 		switch (setting->iName.iType)
    81 			{
    82 			case ETypeInt32:
    83 				{
    84 				TInt32 val;
    85 				r = HcrSimTest.GetInt(id, val);
    86 				test_KErrNone(r);
    87 				test_Equal(setting->iValue.iLit.iInt32, val);
    88 				break;
    89 				}
    90 			case ETypeInt16:
    91 				{
    92 				TInt16 val;
    93 				r = HcrSimTest.GetInt(id, val);
    94 				test_KErrNone(r);
    95 				test_Equal(setting->iValue.iLit.iInt16, val);
    96 				break;
    97 				}
    98 			case ETypeInt8:
    99 				{
   100 				TInt8 val;
   101 				r = HcrSimTest.GetInt(id, val);
   102 				test_KErrNone(r);
   103 				test_Equal(setting->iValue.iLit.iInt8, val);
   104 				break;
   105 				}
   106 			case ETypeBool:
   107 				{
   108 				TBool val;
   109 				r = HcrSimTest.GetBool(id, val);
   110 				test_KErrNone(r);
   111 				test_Equal(setting->iValue.iLit.iBool, val);
   112 				break;
   113 				}
   114 			case ETypeUInt32:
   115 				{
   116 				TUint32 val;
   117 				r = HcrSimTest.GetUInt(id, val);
   118 				test_KErrNone(r);
   119 				test_Equal(setting->iValue.iLit.iUInt32, val);
   120 				break;
   121 				}
   122 			case ETypeUInt16:
   123 				{
   124 				TUint16 val;
   125 				r = HcrSimTest.GetUInt(id, val);
   126 				test_KErrNone(r);
   127 				test_Equal(setting->iValue.iLit.iUInt16, val);
   128 				break;
   129 				}
   130 			case ETypeUInt8:
   131 				{
   132 				TUint8 val;
   133 				r = HcrSimTest.GetUInt(id, val);
   134 				test_KErrNone(r);
   135 				test_Equal(setting->iValue.iLit.iUInt8, val);
   136 				break;
   137 				}
   138 			case ETypeLinAddr:
   139 				{
   140 				TLinAddr val;
   141 				r = HcrSimTest.GetLinAddr(id, val);
   142 				test_KErrNone(r);
   143 				test_Equal(setting->iValue.iLit.iAddress, val);
   144 				break;
   145 				}
   146 			case ETypeBinData:
   147 				{
   148 				TBuf8<KMaxSettingLength> dval;
   149 				TUint8* pval;
   150 				pval = (TUint8*) User::Alloc(setting->iName.iLen);
   151 				test_NotNull(pval);
   152 				//
   153 				r = HcrSimTest.GetData(id, dval);
   154 				test_KErrNone(r);
   155 				//
   156 				TUint16 actuallength;
   157 				r = HcrSimTest.GetData(id, setting->iName.iLen, pval, actuallength);
   158 				test_KErrNone(r);
   159 				//
   160 				test_Equal(0, Mem::Compare(
   161 						setting->iValue.iPtr.iData, setting->iName.iLen,
   162 						pval, actuallength));
   163 				test_Equal(0, Mem::Compare(
   164 						setting->iValue.iPtr.iData, setting->iName.iLen,
   165 						dval.Ptr(), dval.Length()));
   166 				User::Free(pval);
   167 				break;
   168 				}
   169 			case ETypeText8:
   170 				{
   171 				TBuf8<KMaxSettingLength> dval;
   172 				TText8* pval;
   173 				pval = (TText8*) User::Alloc(setting->iName.iLen);
   174 				test_NotNull(pval);
   175 				//
   176 				r = HcrSimTest.GetString(id, dval);
   177 				test_KErrNone(r);
   178 				//
   179 				TUint16 actuallength;
   180 				r = HcrSimTest.GetString(id, setting->iName.iLen, pval, actuallength);
   181 				test_KErrNone(r);
   182 				//
   183 				test_Equal(0, Mem::Compare(
   184 						setting->iValue.iPtr.iString8, setting->iName.iLen,
   185 						pval, actuallength));
   186 				test_Equal(0, Mem::Compare(
   187 						setting->iValue.iPtr.iString8, setting->iName.iLen,
   188 						dval.Ptr(), dval.Length()));
   189 				User::Free(pval);
   190 				break;
   191 				}
   192 			case ETypeArrayInt32:
   193 				{
   194 				TInt32* pval;
   195 				pval = (TInt32*) User::Alloc(setting->iName.iLen);
   196 				test_NotNull(pval);
   197 				//
   198 				TUint16 actuallength;
   199 				r = HcrSimTest.GetArray(id, setting->iName.iLen, pval, actuallength);
   200 				test_KErrNone(r);
   201 				//
   202 				test_Equal(setting->iName.iLen, actuallength);
   203 				TInt32* pexpected = setting->iValue.iPtr.iArrayInt32;
   204 				TUint i;
   205 				for (i = 0; i < setting->iName.iLen / sizeof(TInt32); i++)
   206 					{
   207 					test_Equal(*(pexpected + i), *(pval + i));
   208 					}
   209 				User::Free(pval);
   210 				break;
   211 				}
   212 			case ETypeArrayUInt32:
   213 				{
   214 				TUint32* pval;
   215 				pval = (TUint32*) User::Alloc(setting->iName.iLen);
   216 				test_NotNull(pval);
   217 				//
   218 				TUint16 actuallength;
   219 				r = HcrSimTest.GetArray(id, setting->iName.iLen, pval, actuallength);
   220 				test_KErrNone(r);
   221 				//
   222 				test_Equal(setting->iName.iLen, actuallength);
   223 				TUint32* pexpected = setting->iValue.iPtr.iArrayUInt32;
   224 				TUint i;
   225 				for (i = 0; i < setting->iName.iLen / sizeof(TUint32); i++)
   226 					{
   227 					test_Equal(*(pexpected + i), *(pval + i));
   228 					}
   229 				User::Free(pval);
   230 				break;
   231 				}
   232 			case ETypeInt64:
   233 				{
   234 				TInt64 val;
   235 				r = HcrSimTest.GetInt(id, val);
   236 				test_KErrNone(r);
   237 				test_Equal(*setting->iValue.iPtr.iInt64, val);
   238 				break;
   239 				}
   240 			case ETypeUInt64:
   241 				{
   242 				TUint64 val;
   243 				r = HcrSimTest.GetUInt(id, val);
   244 				test_KErrNone(r);
   245 				test_Equal(*setting->iValue.iPtr.iUInt64, val);
   246 				break;
   247 				}
   248 			default:
   249 				test(EFalse);
   250 			}
   251 		}
   252 	}
   253 
   254 void HcrSimGetSettingsNegative(SSettingC* aRepository, TUint aNumberOfSettings)
   255 	{
   256 	test.Next(_L("GetSettingsNegative"));
   257 	TInt r;
   258 	SSettingC* setting;
   259 	for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
   260 		{
   261 		TSettingId id(setting->iName.iId.iCat, setting->iName.iId.iKey);
   262 		test.Printf(_L("(0x%08x, 0x%08x)\n"), id.iCat, id.iKey);
   263 		if (setting->iName.iType != ETypeInt32)
   264 			{
   265 			TInt32 val;
   266 			r = HcrSimTest.GetInt(id, val);
   267 			test_Equal(KErrArgument, r);
   268 			}
   269 		if (setting->iName.iType != ETypeInt16)
   270 			{
   271 			TInt16 val;
   272 			r = HcrSimTest.GetInt(id, val);
   273 			test_Equal(KErrArgument, r);
   274 			}
   275 		if (setting->iName.iType != ETypeInt8)
   276 			{
   277 			TInt8 val;
   278 			r = HcrSimTest.GetInt(id, val);
   279 			test_Equal(KErrArgument, r);
   280 			}
   281 		if (setting->iName.iType != ETypeBool)
   282 			{
   283 			TBool val;
   284 			r = HcrSimTest.GetBool(id, val);
   285 			test_Equal(KErrArgument, r);
   286 			}
   287 		if (setting->iName.iType != ETypeUInt32)
   288 			{
   289 			TUint32 val;
   290 			r = HcrSimTest.GetUInt(id, val);
   291 			test_Equal(KErrArgument, r);
   292 			}
   293 		if (setting->iName.iType != ETypeUInt16)
   294 			{
   295 			TUint16 val;
   296 			r = HcrSimTest.GetUInt(id, val);
   297 			test_Equal(KErrArgument, r);
   298 			}
   299 		if (setting->iName.iType != ETypeUInt8)
   300 			{
   301 			TUint8 val;
   302 			r = HcrSimTest.GetUInt(id, val);
   303 			test_Equal(KErrArgument, r);
   304 			}
   305 		if (setting->iName.iType != ETypeLinAddr)
   306 			{
   307 			TLinAddr val;
   308 			r = HcrSimTest.GetLinAddr(id, val);
   309 			test_Equal(KErrArgument, r);
   310 			}
   311 		if (setting->iName.iType != ETypeBinData)
   312 			{
   313 			TBuf8<KMaxSettingLength> dval;
   314 			TUint8* pval;
   315 			pval = (TUint8*) User::Alloc(setting->iName.iLen);
   316 			test_NotNull(pval);
   317 			//
   318 			r = HcrSimTest.GetData(id, dval);
   319 			test_Equal(KErrArgument, r);
   320 			//
   321 			TUint16 actuallength;
   322 			r = HcrSimTest.GetData(id, setting->iName.iLen, pval, actuallength);
   323 			test_Equal(KErrArgument, r);
   324 			//
   325 			User::Free(pval);
   326 			}
   327 		else if (setting->iName.iLen > 1)
   328 			{
   329 			RBuf8 dval;
   330 			r = dval.Create(setting->iName.iLen - 1);
   331 			test_KErrNone(r);
   332 			r = HcrSimTest.GetData(id, dval);
   333 			test_Equal(KErrTooBig, r);
   334 			dval.Close();
   335 			
   336 			TUint8* pval;
   337 			pval = (TUint8*) User::Alloc(setting->iName.iLen);
   338 			test_NotNull(pval);
   339 			//
   340 			TUint16 actuallength;
   341 			r = HcrSimTest.GetData(id, (unsigned short)( setting->iName.iLen - 1), pval, actuallength);
   342 			test_Equal(KErrTooBig, r);
   343 			//
   344 			User::Free(pval);
   345 			}
   346 		if (setting->iName.iType != ETypeText8)
   347 			{
   348 			TBuf8<KMaxSettingLength> dval;
   349 			TText8* pval;
   350 			pval = (TText8*) User::Alloc(setting->iName.iLen);
   351 			test_NotNull(pval);
   352 			//
   353 			r = HcrSimTest.GetString(id, dval);
   354 			test_Equal(KErrArgument, r);
   355 			//
   356 			TUint16 actuallength;
   357 			r = HcrSimTest.GetString(id, setting->iName.iLen, pval, actuallength);
   358 			test_Equal(KErrArgument, r);
   359 			//
   360 			User::Free(pval);
   361 			}
   362 		else if (setting->iName.iLen > 1)
   363 			{
   364 			RBuf8 dval;
   365 			r = dval.Create(setting->iName.iLen - 1);
   366 			test_KErrNone(r);
   367 			r = HcrSimTest.GetString(id, dval);
   368 			test_Equal(KErrTooBig, r);
   369 			dval.Close();
   370 			
   371 			TText8* pval;
   372 			pval = (TText8*) User::Alloc(setting->iName.iLen);
   373 			test_NotNull(pval);
   374 			//
   375 			TUint16 actuallength;
   376 			r = HcrSimTest.GetString(id, (unsigned short)(setting->iName.iLen >> 1), pval, actuallength);
   377 			test_Equal(KErrTooBig, r);
   378 			//
   379 			User::Free(pval);
   380 			}
   381 		if (setting->iName.iType != ETypeArrayInt32)
   382 			{
   383 			TInt32* pval;
   384 			pval = (TInt32*) User::Alloc(setting->iName.iLen);
   385 			test_NotNull(pval);
   386 			//
   387 			TUint16 actuallength;
   388 			r = HcrSimTest.GetArray(id, setting->iName.iLen, pval, actuallength);
   389 			test_Equal(KErrArgument, r);
   390 			//
   391 			User::Free(pval);
   392 			}
   393 		else
   394 			{
   395 			TInt32* pval;
   396 			pval = (TInt32*) User::Alloc(setting->iName.iLen);
   397 			test_NotNull(pval);
   398 			//
   399 			TUint16 actuallength;
   400 			r = HcrSimTest.GetArray(id, (TUint16) (setting->iName.iLen >> 1), pval, actuallength);
   401 			test_Equal(KErrTooBig, r);
   402 			//
   403 			User::Free(pval);
   404 			}
   405 		if (setting->iName.iType != ETypeArrayUInt32)
   406 			{
   407 			TUint32* pval;
   408 			pval = (TUint32*) User::Alloc(setting->iName.iLen);
   409 			test_NotNull(pval);
   410 			//
   411 			TUint16 actuallength;
   412 			r = HcrSimTest.GetArray(id, setting->iName.iLen, pval, actuallength);
   413 			test_Equal(KErrArgument, r);
   414 			//
   415 			User::Free(pval);
   416 			}
   417 		if (setting->iName.iType != ETypeInt64)
   418 			{
   419 			TInt64 val;
   420 			r = HcrSimTest.GetInt(id, val);
   421 			test_Equal(KErrArgument, r);
   422 			}
   423 		if (setting->iName.iType != ETypeUInt64)
   424 			{
   425 			TUint64 val;
   426 			r = HcrSimTest.GetUInt(id, val);
   427 			test_Equal(KErrArgument, r);
   428 			}
   429 		}
   430 	}
   431 
   432 void HcrSimSettingProperties(SSettingC* aRepository, TUint aNumberOfSettings)
   433 	{
   434 	test.Next(_L("SettingProperties"));
   435 	TInt r;
   436 	SSettingC* setting;
   437 	for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
   438 		{
   439 		TSettingId id(setting->iName.iId.iCat, setting->iName.iId.iKey);
   440 		test.Printf(_L("(0x%08x, 0x%08x)\n"), id.iCat, id.iKey);
   441 		TSettingType type = ETypeUndefined;
   442 		TUint16 size = KMaxSettingLength + 1;
   443 		r = HcrSimTest.GetTypeAndSize(id, type, size);
   444 		test_KErrNone(r);
   445 		switch (setting->iName.iType)
   446 			{
   447 			case ETypeInt32:
   448 			case ETypeInt16:
   449 			case ETypeInt8:
   450 			case ETypeBool:
   451 			case ETypeUInt32:
   452 			case ETypeUInt16:
   453 			case ETypeUInt8:
   454 			case ETypeLinAddr:
   455 				test_Equal(setting->iName.iType, type);
   456 				test_Equal(0, size);
   457 				break;
   458 				// Fall-through
   459 			case ETypeBinData:
   460 			case ETypeText8:
   461 			case ETypeArrayInt32:
   462 			case ETypeArrayUInt32:
   463 			case ETypeInt64:
   464 			case ETypeUInt64:
   465 				test_Equal(setting->iName.iType, type);
   466 				test_Equal(setting->iName.iLen, size);
   467 				break;
   468 			default:
   469 				test(EFalse);
   470 			}
   471 		test.Printf(_L("."));
   472 		}
   473 	test.Printf(_L("\n"));
   474 	}
   475 
   476 void HcrSimMultipleGet(SSettingC* aRepository, TUint aNumberOfSettings)
   477 	{
   478 	test.Next(_L("MultipleGet"));
   479 	TInt r;
   480 	SSettingId largesetting;
   481 	largesetting.iCat = 0;
   482 	largesetting.iKey = 0;
   483 	
   484 	SSettingC* setting;
   485 	SSettingId id;
   486 	id.iCat = 0;
   487 	id.iKey = 0;
   488 	
   489 	
   490 
   491 	test.Start(_L("Multiple Get on individual settings"));
   492 	
   493 	for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
   494 		{
   495 		if (setting->iName.iType < 0x00010000)
   496 			{
   497 			test.Printf(_L("(0x%08x, 0x%08x)\n"), id.iCat, id.iKey);
   498 			TInt i;
   499 
   500 			TInt32 val;
   501 			TSettingType type;
   502 			TInt err;
   503 
   504 
   505 		    test.Next(_L("Multiple Get, with non-existing category or element id"));
   506 		    
   507 			// Try all permutations of optional values
   508 		    // i == 0 || i == 1     Just a single setting from the repostitory
   509 		    // i == 2 || i == 3     Valid category and invalid element id
   510 		    // i == 4 || i == 5     Invalid category and valid element id 
   511 		    // i == 6 || i == 7     Invalid category and element id 
   512 			for (i = 0; i < 8; i++)
   513 				{
   514 				//Just a single setting from the repository
   515 				if(i == 0 || i == 1)
   516 					{
   517 					//test.Printf(_L("Single setting, valid element && valid category\n"));
   518 					id.iCat = setting->iName.iId.iCat;
   519 					id.iKey = setting->iName.iId.iKey;
   520 
   521 					//test.Printf(_L("-Permutation %02x\n"), i);
   522 					r = HcrSimTest.GetWordSettings(1, &id, &val,
   523 							(i & 0x1  ? &type : NULL), &err);
   524 					//HCR should return 1
   525 					test_Equal(1, r);
   526 					test_Equal(setting->iValue.iLit.iInt32, val);
   527 					if (i & 0x1)
   528 						{
   529 						test_Equal(setting->iName.iType, type);
   530 						}
   531 
   532 					test_KErrNone(err);
   533 					}
   534 
   535 				//Valid category and invalid element id
   536 				if(i == 2 || i == 3)
   537 					{
   538 					//test.Printf(_L("Single setting, invalid element && valid category\n"));
   539 					id.iCat = setting->iName.iId.iCat;
   540 					id.iKey = KTestInvalidSettingId;
   541 
   542 
   543 					r = HcrSimTest.GetWordSettings(1, &id, &val,
   544 							(i & 0x1  ? &type : NULL), &err);
   545 
   546 					//HCR should return 0
   547 					test_Equal(0, r);
   548 					test_Equal(0, val);
   549 					if (i & 0x1)
   550 						{
   551 						//HCR returns ETypeUndefined
   552 						test_Equal(0, type);
   553 						}
   554 
   555 					test_Equal(KErrNotFound,err);
   556 					}
   557 
   558 				//Invalid category and valid element id
   559 				if(i == 4 || i == 5)
   560 					{
   561 					id.iCat = KTestInvalidCategory;
   562 					id.iKey = setting->iName.iId.iKey;
   563 
   564 					//test.Printf(_L("Single setting, invalid element && valid category\n"));
   565 					r = HcrSimTest.GetWordSettings(1, &id, &val,
   566 							(i & 0x1  ? &type : NULL), &err);
   567 					//HCR should return 1
   568 					test_Equal(0, r);
   569 					test_Equal(0, val);
   570 					if (i & 0x1)
   571 						{
   572 						//HCR returns ETypeUndefined
   573 						test_Equal(0, type);
   574 						}
   575 
   576 					test_Equal(KErrNotFound, err);
   577 					}
   578 				
   579 				//Invalid category and element id 
   580 				if(i == 6 || i == 7)
   581 					{
   582 					id.iCat = KTestInvalidCategory;
   583 					id.iKey = KTestInvalidSettingId;
   584 
   585 					//test.Printf(_L("Single setting, invalid element && valid category\n"));
   586 					r = HcrSimTest.GetWordSettings(1, &id, &val,
   587 							(i & 0x1  ? &type : NULL), &err);
   588 					//HCR should return 1
   589 					test_Equal(0, r);
   590 					test_Equal(0, val);
   591 					if (i & 0x1)
   592 						{
   593 						//HCR returns ETypeUndefined
   594 						test_Equal(0, type);
   595 						}
   596 					test_Equal(KErrNotFound, err);
   597 					}
   598 				}
   599 			}
   600 		else if (largesetting.iKey == 0)
   601 			{
   602 			// save for later
   603 			largesetting.iCat = setting->iName.iId.iCat;
   604 			largesetting.iKey = setting->iName.iId.iKey;
   605 			}
   606 		}
   607 
   608 	
   609 	
   610 	test.Next(_L("Multiple Get, some user input parameters are wrong"));
   611 	
   612 
   613 	TInt nosettings = 0;
   614 	for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
   615 		{
   616 		if (setting->iName.iType < 0x00010000)
   617 			{
   618 			nosettings++;
   619 			}
   620 		test_Compare(0, <, nosettings);
   621 		}
   622 	
   623 
   624 	SSettingId* ids;
   625 	TInt32* vals;
   626 	TSettingType* types;
   627 	TInt* errs;
   628 
   629 	
   630 	ids = (SSettingId*) User::Alloc(sizeof(SSettingId) * nosettings);
   631 	test_NotNull(ids);
   632 	vals = (TInt32*) User::Alloc(sizeof(TInt32) * nosettings);
   633 	test_NotNull(vals);
   634 	types = (TSettingType*) User::Alloc(sizeof(TSettingType) * nosettings);
   635 	test_NotNull(types);
   636 	errs = (TInt*) User::Alloc(sizeof(TInt) * nosettings);
   637 	test_NotNull(errs);
   638 	
   639 	TUint n = 0;
   640 
   641 	for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
   642 		{
   643 		if (setting->iName.iType < 0x00010000)
   644 			{
   645 			ids[n].iCat = setting->iName.iId.iCat;
   646 			ids[n].iKey = setting->iName.iId.iKey;
   647 			n++;
   648 			}
   649 		}
   650 	test_Equal(nosettings, n);
   651 	
   652 
   653 
   654     test.Next(_L("Number of settings is negative \n"));
   655     r = HcrSimTest.GetWordSettings(-1 * nosettings, ids, vals, types, errs);
   656 
   657     //HCR returns KErrArgument
   658     test_Equal(KErrArgument, r);
   659     
   660 
   661     test.Printf(_L("Pointer to errors array is NULL \n"));
   662     r = HcrSimTest.GetWordSettings(nosettings, ids, vals, types, NULL);
   663 
   664     //HCR returns KErrArgument
   665     test_Equal(KErrArgument, r);
   666 
   667 
   668     test.Printf(_L("Pointer to ids is NULL \n"));
   669     r = HcrSimTest.GetWordSettings(nosettings, NULL, vals, types, errs);
   670 
   671     //HCR returns KErrArgument
   672     test_Equal(KErrArgument, r);
   673 
   674 	User::Free(ids);
   675 	User::Free(vals);
   676 	User::Free(types);
   677 	User::Free(errs);
   678 
   679 	
   680 	
   681 	test.Next(_L("Multiple Get on all settings"));
   682 	nosettings = 0;
   683 	for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
   684 		{
   685 		if (setting->iName.iType < 0x00010000)
   686 			{
   687 			nosettings++;
   688 			}
   689 		test_Compare(0, <, nosettings);
   690 		}
   691 	
   692 	ids = (SSettingId*) User::Alloc(sizeof(SSettingId) * nosettings);
   693 	test_NotNull(ids);
   694 	vals = (TInt32*) User::Alloc(sizeof(TInt32) * nosettings);
   695 	test_NotNull(vals);
   696 	types = (TSettingType*) User::Alloc(sizeof(TSettingType) * nosettings);
   697 	test_NotNull(types);
   698 	errs = (TInt*) User::Alloc(sizeof(TInt) * nosettings);
   699 	test_NotNull(errs);
   700 	
   701 	n = 0;
   702 
   703 	for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
   704 		{
   705 		if (setting->iName.iType < 0x00010000)
   706 			{
   707 			ids[n].iCat = setting->iName.iId.iCat;
   708 			ids[n].iKey = setting->iName.iId.iKey;
   709 			n++;
   710 			}
   711 		}
   712 	test_Equal(nosettings, n);
   713     
   714 	
   715 	// Try all permutations of optional values
   716 	TInt i;
   717 	for (i = 0; i < 2; i++)
   718 		{
   719 		r = HcrSimTest.GetWordSettings(nosettings, ids, vals,
   720 				(i & 0x1  ? types : NULL), errs);
   721 		//HCR returns number of found elements
   722 		test_Equal(nosettings, r);
   723 		
   724 		// Check values
   725 		n = 0;
   726 		for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
   727 			{
   728 			if (setting->iName.iType < 0x00010000)
   729 				{
   730 				test_Equal(setting->iValue.iLit.iInt32, vals[n]);
   731 				if (i & 0x1)
   732 					{
   733 					test_Equal(setting->iName.iType,types[n]);
   734 					}
   735 				test_KErrNone(errs[n]);
   736 				n++;
   737 				}
   738 			}
   739 		test_Equal(nosettings, n);
   740 		}
   741 	User::Free(ids);
   742 	User::Free(vals);
   743 	User::Free(types);
   744 	User::Free(errs);
   745 	
   746 	test.Next(_L("Multiple Get on all settings + inexistent"));
   747 	nosettings = 1;
   748 	for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
   749 		{
   750 		if (setting->iName.iType < 0x00010000)
   751 			{
   752 			nosettings++;
   753 			}
   754 		test_Compare(0, <, nosettings);
   755 		}
   756 	ids = (SSettingId*) User::Alloc(sizeof(SSettingId) * nosettings);
   757 	test_NotNull(ids);
   758 	vals = (TInt32*) User::Alloc(sizeof(TInt32) * nosettings);
   759 	test_NotNull(vals);
   760 	types = (TSettingType*) User::Alloc(sizeof(TSettingType) * nosettings);
   761 	test_NotNull(types);
   762 	errs = (TInt*) User::Alloc(sizeof(TInt) * nosettings);
   763 	test_NotNull(errs);
   764 	ids[0].iCat = KTestInvalidCategory;
   765 	ids[0].iKey = KTestInvalidSettingId;
   766 	
   767 
   768 	n = 1;
   769 	for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
   770 		{
   771 		if (setting->iName.iType < 0x00010000)
   772 			{
   773 			ids[n].iCat = setting->iName.iId.iCat;
   774 			ids[n].iKey = setting->iName.iId.iKey;
   775 			n++;
   776 			}
   777 		}
   778 	
   779 	test_Equal(nosettings, n);
   780 
   781 	// Try all permutations of optional values
   782 	for (i = 0; i < 2; i++)
   783 		{
   784 		r = HcrSimTest.GetWordSettings(nosettings, ids, vals,
   785 				(i & 0x1  ? types : NULL), errs);
   786 		test_Equal(nosettings - 1, r);
   787 		
   788 		// Check values
   789 		if (i & 0x1)
   790 			{
   791 			test_Equal(ETypeUndefined, types[0]);
   792 			}
   793 			test_Equal(KErrNotFound, errs[0]);
   794 
   795 		n = 1;
   796 		for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
   797 			{
   798 			if (setting->iName.iType < 0x00010000)
   799 				{
   800 				test_Equal(setting->iValue.iLit.iInt32, vals[n]);
   801 				if (i & 0x1)
   802 					{
   803 					test_Equal(setting->iName.iType, types[n]);
   804 					}
   805 
   806 				test_KErrNone(errs[n]);
   807 
   808 				n++;
   809 				}
   810 			}
   811 		test_Equal(nosettings, n);
   812 		}
   813 	User::Free(ids);
   814 	User::Free(vals);
   815 	User::Free(types);
   816 	User::Free(errs);
   817 
   818 	test.Next(_L("Multiple Get on a large setting"));
   819 	if (largesetting.iKey)
   820 		{
   821 		TInt32 value;
   822 		TSettingType type;
   823 		TInt theerror = 1;
   824 		r = HcrSimTest.GetWordSettings(1, &largesetting, &value, &type, &theerror);
   825 		test_Equal(0, r);
   826 		test_Equal(KErrArgument, theerror);
   827 		}
   828 	else
   829 		{
   830 		test.Printf(_L("No large setting found in repositories!\n"));
   831 		}
   832 	test.End();
   833 	}
   834 
   835 void HcrSimNumSettingsInCategory(SSettingC* aRepository, TUint aNumberOfSettings)
   836 	{
   837 	test.Next(_L("NumSettingsInCategory"));
   838 	TInt r;
   839 	// Build a hash table with number of settings for each category
   840 	RHashMap<TUint32, TInt> numsettings;
   841 	SSettingC* setting;
   842 	TInt* pV = NULL;
   843 	TInt value = 0;
   844 	for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
   845 		{
   846 		pV = numsettings.Find(setting->iName.iId.iCat);
   847 		if(pV)
   848 		    value = *pV;
   849 		if (!pV)
   850 			{
   851 			r = numsettings.Insert(setting->iName.iId.iCat, 1);
   852 			test_KErrNone(r);
   853 			}
   854 		else
   855 			{
   856 			r = numsettings.Remove(setting->iName.iId.iCat);
   857 			test_KErrNone(r);
   858 			r = numsettings.Insert(setting->iName.iId.iCat, value + 1);
   859 			test_KErrNone(r);
   860 			}
   861 		}
   862 
   863 	// Now compare hash table with values returned by FindNumSettingsInCategory
   864 	RHashMap<TUint32, TInt>::TIter catiter(numsettings);
   865 	for (;;)
   866 		{
   867 		const TUint32* nextcat = catiter.NextKey();
   868 		if (!nextcat)
   869 			{
   870 			break;
   871 			}
   872 		test.Printf(_L("Category %08x\n"), *nextcat);
   873 		const TInt* v = numsettings.Find(*nextcat);
   874 		test_NotNull(v);
   875 		r = HcrSimTest.FindNumSettingsInCategory(*nextcat);
   876 		test_Equal(*v, r);
   877 		}
   878 	numsettings.Close();
   879 	}
   880 
   881 
   882 
   883 void HcrSimFindSettingsCategory(SSettingC* aRepository, TUint aNumberOfSettings)
   884     {
   885     test.Next(_L("FindSettingsCategory"));
   886     TInt r;
   887     
   888     // Build a hash table with number of settings for each category
   889     RHashMap<TUint32, TInt> numsettings;
   890     SSettingC* setting;
   891     TInt* pV = NULL;
   892     TInt value = 0;
   893     for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
   894         {
   895         pV = numsettings.Find(setting->iName.iId.iCat);
   896         if(pV)
   897             value = *pV;
   898         if (!pV)
   899             {
   900             r = numsettings.Insert(setting->iName.iId.iCat, 1);
   901             test_KErrNone(r);
   902             }
   903         else
   904             {
   905             r = numsettings.Remove(setting->iName.iId.iCat);
   906             test_KErrNone(r);
   907             r = numsettings.Insert(setting->iName.iId.iCat, value + 1);
   908             test_KErrNone(r);
   909             }
   910         }
   911 
   912     // 
   913     RHashMap<TUint32, TInt>::TIter catiter(numsettings);
   914     for (;;)
   915         {
   916         const TUint32* nextcat = catiter.NextKey();
   917         if (!nextcat)
   918             {
   919             break;
   920             }
   921         test.Printf(_L("Category %08x"), *nextcat);
   922         const TInt* v = numsettings.Find(*nextcat);
   923         test_NotNull(v);
   924 
   925         // Allocate memory for holding array of settings
   926         TElementId* elids;
   927         TSettingType* types;
   928         TUint16* lens;
   929         
   930         TInt maxNum;
   931         
   932         
   933         // Try all permutations of optional values
   934         TInt i;
   935         for (i = 0; i < 3; i++)
   936             {
   937             test.Printf(_L("."));
   938 
   939             TUint32 numfound;
   940 
   941             //maxNum is equal:  
   942             //0 - 1, the total elements from the category
   943             //1 - 1/2 of total number of elements from the category
   944             //2 - 1 + 1/2 of total number of element from the category
   945 
   946             if(i == 0)
   947                 maxNum = *v;
   948             else if(i == 1)
   949                 maxNum = _FRACTION((*v), 2);
   950             else
   951                 maxNum = *v + _FRACTION((*v), 2);
   952 
   953 
   954             elids = (TElementId*) User::Alloc(maxNum * sizeof(TElementId));
   955             test_NotNull(elids);
   956             types = (TSettingType*) User::Alloc(maxNum * sizeof(TSettingType));
   957             test_NotNull(types);
   958             lens = (TUint16*) User::Alloc(maxNum * sizeof(TUint16));
   959             test_NotNull(lens);
   960 
   961             Mem::Fill(elids, maxNum * sizeof(TElementId), 0xcc);
   962             Mem::Fill(types, maxNum * sizeof(TSettingType), 0xcc);
   963             Mem::Fill(lens,  maxNum * sizeof(TUint16), 0xcc);
   964 
   965 
   966             r = HcrSimTest.FindSettings(*nextcat,
   967                     maxNum, elids,
   968                     i & 0x1 ? types : NULL,
   969                     i & 0x2 ? lens : NULL);
   970             numfound = r;
   971             test_Compare(0, <=, r);
   972             
   973             if(i < 2)
   974                 {
   975                 //for 0 & 1 the number of settings returned must be equal maxNum
   976                 test_Equal(maxNum, r);
   977                 }
   978             else
   979                 {
   980                 //for 2, it's equal the real number of settings
   981                 test_Equal((*v), r);
   982                 }
   983 
   984 
   985 
   986             // Check returned list of element ids
   987             TUint j;
   988             for (j = 0; j < numfound; j++)
   989                 {
   990                 // Find current element in the test array
   991                 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
   992                     {
   993                     if ((setting->iName.iId.iCat == *nextcat) && (setting->iName.iId.iKey == elids[j]))
   994                         {
   995                         break;
   996                         }
   997                     }
   998                 test_Compare(setting,<,aRepository+aNumberOfSettings); // Fail if element not found
   999                 switch (setting->iName.iType)
  1000                     {
  1001                     case ETypeInt32:
  1002                     case ETypeInt16:
  1003                     case ETypeInt8:
  1004                     case ETypeBool:
  1005                     case ETypeUInt32:
  1006                     case ETypeUInt16:
  1007                     case ETypeUInt8:
  1008                     case ETypeLinAddr:
  1009                         if (i & 0x1)
  1010                             {
  1011                             test_Equal(setting->iName.iType, types[j]);
  1012                             }
  1013                         if (i & 0x2)
  1014                             {
  1015                             test_Equal(0, lens[j]);
  1016                             }
  1017                         break;
  1018                         // Fall-through
  1019                     case ETypeBinData:
  1020                     case ETypeText8:
  1021                     case ETypeArrayInt32:
  1022                     case ETypeArrayUInt32:
  1023                     case ETypeInt64:
  1024                     case ETypeUInt64:
  1025                         if (i & 0x1)
  1026                             {
  1027                             test_Equal(setting->iName.iType, types[j]);
  1028                             }
  1029                         if (i & 0x2)
  1030                             {
  1031                             test_Equal(setting->iName.iLen, lens[j]);
  1032                             }
  1033                         break;
  1034                     default:
  1035                         test(EFalse);
  1036                     }
  1037                 }
  1038             // Check all expected elements are in the returned list of element ids
  1039             for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
  1040                 {
  1041                 if ((setting->iName.iId.iCat == *nextcat))
  1042                     {
  1043                     for (j = 0; j < numfound; j++)
  1044                         {
  1045                         if (elids[j] == setting->iName.iId.iKey)
  1046                             {
  1047                             break;
  1048                             }
  1049                         }
  1050                     test_Compare(j, <=, numfound);
  1051                     }
  1052                 }
  1053 
  1054             User::Free(elids);
  1055             User::Free(types);
  1056             User::Free(lens);
  1057             }
  1058 
  1059         test.Printf(_L("\n"));
  1060         }
  1061     numsettings.Close();
  1062     }
  1063 
  1064 struct TTestFindSettingsPatternArgs
  1065 	{
  1066 	TUint32 iMask;
  1067 	TUint32 iPattern;
  1068 	};
  1069 
  1070 const TTestFindSettingsPatternArgs KTestFindSettingsPatternArgs[] = {
  1071 //	 iMask	   iPattern
  1072 	{0x00000000, 0x00000000},
  1073     {0xfffffff0, 0x00000000},
  1074 	{0xffffffff, 0x00000001}
  1075 };
  1076 
  1077 void HcrSimFindSettingsPattern(SSettingC* aRepository, TUint aNumberOfSettings)
  1078     {
  1079     test.Next(_L("FindSettingsPattern"));
  1080     TInt r;
  1081     TUint i;
  1082 
  1083     // Allocate memory for holding array of settings
  1084     TElementId* elids;
  1085     TSettingType* types;
  1086     TUint16* lens;
  1087     TInt maxNum;
  1088 
  1089     // Build a hash table with number of settings for each category
  1090     RHashMap<TUint32, TInt> numsettings;
  1091     SSettingC* setting;
  1092     TInt* pV = NULL;
  1093     TInt value = 0;
  1094     for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
  1095         {
  1096         pV = numsettings.Find(setting->iName.iId.iCat);
  1097         if(pV)
  1098             value = *pV;
  1099         if (!pV)
  1100             {
  1101             r = numsettings.Insert(setting->iName.iId.iCat, 1);
  1102             test_KErrNone(r);
  1103             }
  1104         else
  1105             {
  1106             r = numsettings.Remove(setting->iName.iId.iCat);
  1107             test_KErrNone(r);
  1108             r = numsettings.Insert(setting->iName.iId.iCat, value + 1);
  1109             test_KErrNone(r);
  1110             }
  1111         }
  1112 
  1113     // Hash map includes the number of settings of each category 
  1114     RHashMap<TUint32, TInt>::TIter catiter(numsettings);
  1115     for (;;)
  1116         {
  1117         const TUint32* nextcat = catiter.NextKey();
  1118         if (!nextcat)
  1119             {
  1120             break;
  1121             }
  1122         test.Printf(_L("Category %08x"), *nextcat);
  1123         const TInt* v = numsettings.Find(*nextcat);
  1124         test_NotNull(v);
  1125 
  1126 
  1127 
  1128         for (i = 0; i < sizeof(KTestFindSettingsPatternArgs) / sizeof(TTestFindSettingsPatternArgs); i++)
  1129             {
  1130             test.Printf(_L("iMask=0x%08x iPattern=0x%08x\n"),
  1131                     KTestFindSettingsPatternArgs[i].iMask,
  1132                     KTestFindSettingsPatternArgs[i].iPattern);
  1133 
  1134             TUint k;
  1135             for (k = 0; k < 3; k++)
  1136                 {
  1137                 TUint32 numfound;
  1138 
  1139                 // aMaxNum is less than the total number of settings in the 
  1140                 // category
  1141                 //0 - all elements from the category are requested
  1142                 //1 - 1/2 of total number of elements from the category
  1143                 //2 - 1 + 1/2 of total number of element from the category
  1144                 if(k == 0)
  1145                     maxNum = *v;
  1146                 else if(k == 1)
  1147                     maxNum = _FRACTION((*v), 2);
  1148                 else
  1149                     maxNum = (*v) + _FRACTION((*v), 2);
  1150 
  1151                 elids = (TElementId*) User::Alloc(maxNum * sizeof(TElementId));
  1152                 test_NotNull(elids);
  1153                 types = (TSettingType*) User::Alloc(maxNum * sizeof(TSettingType));
  1154                 test_NotNull(types);
  1155                 lens = (TUint16*) User::Alloc(maxNum * sizeof(TUint16));
  1156                 test_NotNull(lens);
  1157 
  1158 
  1159                 // Actual API call
  1160                 r = HcrSimTest.FindSettings(
  1161                         *nextcat,
  1162                         maxNum,
  1163                         KTestFindSettingsPatternArgs[i].iMask,
  1164                         KTestFindSettingsPatternArgs[i].iPattern,
  1165                         elids,
  1166                         (k & 0x1 ? types : NULL),
  1167                         (k & 0x2 ? lens : NULL));
  1168                 test_Compare(0, <=, r);
  1169                 test_Compare(maxNum, >=, r);
  1170 
  1171                 numfound = r;
  1172                 test.Printf(_L("%d match(es)\n"), r);
  1173 
  1174                 // Check that all returned element ids satisfy the conditions
  1175                 TUint32 l;
  1176                 for (l = 0; l < numfound; l++)
  1177                     {
  1178                     test_Assert(
  1179                             (KTestFindSettingsPatternArgs[i].iMask & KTestFindSettingsPatternArgs[i].iPattern) ==
  1180                             (KTestFindSettingsPatternArgs[i].iMask & elids[l]), test.Printf(_L("!!%08x!!\n"), elids[l])
  1181                     );
  1182 
  1183                     //Somehow the macro test_Compare consider TInt32 instead TUint32
  1184                     //as a result comparasion is done by this way:
  1185                     //RTEST: (0x0 (0) < 0x80000000 (-2147483648)) == EFalse at line 1038
  1186                     //althought 0x80000000 > 0, with the signed form this number will be
  1187                     //-2147483648.
  1188                     //test_Compare(KTestFindSettingsPatternArgs[i].iAtId, <=, elids[l]);
  1189                     }
  1190 
  1191                 // Check that all elements that satisfy the conditions have been returned
  1192                 SSettingC* setting;
  1193                 TUint32 numsettings = 0;
  1194 
  1195                 //Flag indicates that the element is found
  1196                 TBool fFlag = EFalse;
  1197 
  1198                 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
  1199                     {
  1200                     if ((setting->iName.iId.iCat == *nextcat)
  1201                             && ((KTestFindSettingsPatternArgs[i].iMask & KTestFindSettingsPatternArgs[i].iPattern) ==
  1202                             (KTestFindSettingsPatternArgs[i].iMask & setting->iName.iId.iKey)))
  1203                         {
  1204                         for (l = 0; l < numfound; l++)
  1205                             {
  1206                             if (setting->iName.iId.iKey == elids[l])
  1207                                 {
  1208                                 fFlag = ETrue;
  1209                                 break;
  1210                                 }
  1211                             }
  1212 
  1213                         if(fFlag)
  1214                             {
  1215                             test_Assert(l < numfound, test.Printf(_L("!!%08x!!\n"), elids[l]));
  1216 
  1217                             // Check type and size returned
  1218                             switch (setting->iName.iType)
  1219                                 {
  1220                                 case ETypeInt32:
  1221                                 case ETypeInt16:
  1222                                 case ETypeInt8:
  1223                                 case ETypeBool:
  1224                                 case ETypeUInt32:
  1225                                 case ETypeUInt16:
  1226                                 case ETypeUInt8:
  1227                                 case ETypeLinAddr:
  1228                                     if (k & 0x1)
  1229                                         {
  1230                                         test_Equal(setting->iName.iType, types[l]);
  1231                                         }
  1232                                      if (k & 0x2)
  1233                                         {
  1234                                         test_Equal(0, lens[l]);
  1235                                         }
  1236                                     break;
  1237                                     // Fall-through
  1238                                 case ETypeBinData:
  1239                                 case ETypeText8:
  1240                                 case ETypeArrayInt32:
  1241                                 case ETypeArrayUInt32:
  1242                                 case ETypeInt64:
  1243                                 case ETypeUInt64:
  1244                                     if (k & 0x1)
  1245                                         {
  1246                                         test_Equal(setting->iName.iType, types[l]);
  1247                                         }
  1248                                     if (k & 0x2)
  1249                                         {
  1250                                         test_Equal(setting->iName.iLen, lens[l]);
  1251                                         }
  1252                                     break;
  1253                                 default:
  1254                                     test(EFalse);
  1255                                 }
  1256                             numsettings++;
  1257                             fFlag = EFalse;
  1258                             }
  1259                         }
  1260                     }
  1261                 
  1262                 test_Equal(numsettings, numfound);
  1263 
  1264                 // Free memory
  1265                 User::Free(elids);
  1266                 User::Free(types);
  1267                 User::Free(lens);
  1268 
  1269                 }
  1270             }
  1271         }
  1272     numsettings.Close();
  1273 	}
  1274 
  1275 
  1276 
  1277 void HcrSimFindSettingsCategoryNegative(SSettingC* aRepository, TUint aNumberOfSettings)
  1278     {
  1279     
  1280     TInt r;
  1281     // Build a hash table with number of settings for each category
  1282     RHashMap<TUint32, TInt> numsettings;
  1283     SSettingC* setting;
  1284     TInt* pV = NULL;
  1285     TInt value = 0;
  1286     //Iterator object of the number of elements in the category
  1287     RHashMap<TUint32, TInt>::TIter catiter(numsettings);
  1288 
  1289     
  1290     test.Next(_L("FindSettingsCategoryNegative invalid user parameters"));
  1291         for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
  1292             {
  1293             pV = numsettings.Find(setting->iName.iId.iCat);
  1294             if(pV)
  1295                 value = *pV;
  1296             if (!pV)
  1297                 {
  1298                 r = numsettings.Insert(setting->iName.iId.iCat, 1);
  1299                 test_KErrNone(r);
  1300                 }
  1301             else
  1302                 {
  1303                 r = numsettings.Remove(setting->iName.iId.iCat);
  1304                 test_KErrNone(r);
  1305                 r = numsettings.Insert(setting->iName.iId.iCat, value + 1);
  1306                 test_KErrNone(r);
  1307                 }
  1308             }
  1309 
  1310         // 
  1311         for (;;)
  1312             {
  1313             const TUint32* nextcat = catiter.NextKey();
  1314             if (!nextcat)
  1315                 {
  1316                 break;
  1317                 }
  1318             test.Printf(_L("Category %08x"), *nextcat);
  1319             const TInt* v = numsettings.Find(*nextcat);
  1320             test_NotNull(v);
  1321 
  1322             // Allocate memory for holding array of settings
  1323             TElementId* elids;
  1324             TSettingType* types;
  1325             TUint16* lens;
  1326             elids = (TElementId*) User::Alloc(*v * sizeof(TElementId));
  1327             test_NotNull(elids);
  1328             types = (TSettingType*) User::Alloc(*v * sizeof(TSettingType));
  1329             test_NotNull(types);
  1330             lens = (TUint16*) User::Alloc(*v * sizeof(TUint16));
  1331             test_NotNull(lens);
  1332 
  1333             
  1334             test.Printf(_L("."));
  1335             Mem::Fill(elids, *v * sizeof(TElementId), 0xcc);
  1336             Mem::Fill(types, *v * sizeof(TSettingType), 0xcc);
  1337             Mem::Fill(lens, *v * sizeof(TUint16), 0xcc);
  1338 
  1339             TInt i;
  1340             for (i = 0; i < 3; i++)
  1341                 {
  1342                 //Perform the following permutations:
  1343                 // 0 - negative aMaxNum AND aElIds != NULL
  1344                 // 1 - positive aMaxNum AND aElIds == NULL
  1345                 // 2 - negative aMaxNum AND aElIds == NULL
  1346                 
  1347                 switch(i)
  1348                     {
  1349                     case 0:
  1350                         r = HcrSimTest.FindSettings(*nextcat,
  1351                                 (-1)*(*v), elids, types, lens);
  1352 
  1353                         test_Equal(KErrArgument, r);
  1354                         break;
  1355 
  1356                     case 1:
  1357                         r = HcrSimTest.FindSettings(*nextcat,
  1358                                 *v, NULL, types, lens);
  1359 
  1360                         test_Equal(KErrArgument, r);
  1361                         break;
  1362 
  1363                     case 2:
  1364                         r = HcrSimTest.FindSettings(*nextcat,
  1365                                 (-1)*(*v), NULL, types, lens);
  1366 
  1367                         test_Equal(KErrArgument, r);
  1368                         break;
  1369                     
  1370                     }
  1371                 }
  1372 
  1373 
  1374                 User::Free(elids);
  1375                 User::Free(types);
  1376                 User::Free(lens);
  1377                 test.Printf(_L("\n"));
  1378             }
  1379         numsettings.Close();
  1380 
  1381     }
  1382 
  1383 
  1384 void HcrSimFindSettingsPatternNegative(TUint aNumberOfSettings)
  1385     {
  1386     
  1387     TInt r;
  1388     TUint i;
  1389 
  1390     // Allocate memory for holding array of settings
  1391     TElementId* elids;
  1392     TSettingType* types;
  1393     TUint16* lens;
  1394     elids = (TElementId*) User::Alloc(aNumberOfSettings * sizeof(TElementId));
  1395     test_NotNull(elids);
  1396     types = (TSettingType*) User::Alloc(aNumberOfSettings * sizeof(TSettingType));
  1397     test_NotNull(types);
  1398     lens = (TUint16*) User::Alloc(aNumberOfSettings * sizeof(TUint16));
  1399     test_NotNull(lens);
  1400 
  1401     test.Next(_L("FindSettingsPattern, invalid user parameters"));
  1402     for (i = 0; i < sizeof(KTestFindSettingsPatternArgs) / sizeof(TTestFindSettingsPatternArgs); i++)
  1403         {
  1404         test.Printf(_L("iMask=0x%08x iPattern=0x%08x\n"),
  1405                 KTestFindSettingsPatternArgs[i].iMask,
  1406                 KTestFindSettingsPatternArgs[i].iPattern);
  1407 
  1408         // Test each category
  1409         TUint j;
  1410         for (j = 0; j < sizeof(KTestCategories) / sizeof(TCategoryUid); j++)
  1411             {
  1412             test.Printf(_L("Category 0x%08x: "), KTestCategories[j]);
  1413 
  1414             // Test all possible permutations of optional arguments
  1415             TInt k;
  1416             for (k = 0; k < 3; k++)
  1417                 {
  1418                 //Perform the following permutations:
  1419                 // 0 - negative aMaxNum AND aElIds != NULL
  1420                 // 1 - positive aMaxNum AND aElIds == NULL
  1421                 // 2 - negative aMaxNum AND aElIds == NULL
  1422                 
  1423                 switch(k)
  1424                     {
  1425                     case 0:
  1426                     // Actual API call
  1427                     r = HcrSimTest.FindSettings(
  1428                             KTestCategories[j],
  1429                             (-1) * static_cast<TInt>(aNumberOfSettings),
  1430                             KTestFindSettingsPatternArgs[i].iMask,
  1431                             KTestFindSettingsPatternArgs[i].iPattern,
  1432                             elids,
  1433                             types, lens);
  1434                     test_Equal(KErrArgument,r);
  1435                     break;
  1436 
  1437                     
  1438                     case 1:
  1439                         // Actual API call
  1440                         r = HcrSimTest.FindSettings(
  1441                                 KTestCategories[j],
  1442                                 aNumberOfSettings,
  1443                                 KTestFindSettingsPatternArgs[i].iMask,
  1444                                 KTestFindSettingsPatternArgs[i].iPattern,
  1445                                 NULL,
  1446                                 types, lens);
  1447                         test_Equal(KErrArgument,r);
  1448                         break;
  1449 
  1450                         
  1451                     case 2:
  1452                         // Actual API call
  1453                         r = HcrSimTest.FindSettings(
  1454                                 KTestCategories[j],
  1455                                 (-1) * static_cast<TInt>(aNumberOfSettings),
  1456                                 KTestFindSettingsPatternArgs[i].iMask,
  1457                                 KTestFindSettingsPatternArgs[i].iPattern,
  1458                                 NULL,
  1459                                 types, lens);
  1460                         test_Equal(KErrArgument,r);
  1461                         break;
  1462                 
  1463                     }
  1464                 
  1465                 }
  1466             }
  1467         }
  1468     
  1469     // Free memory
  1470     User::Free(elids);
  1471     User::Free(types);
  1472     User::Free(lens);
  1473     }        
  1474 
  1475          
  1476             
  1477 
  1478 void HcrSimFindSettingsPatternMemAllocFails(TUint aNumberOfSettings)
  1479     {
  1480     TInt r;
  1481     TUint i;
  1482 
  1483     // Allocate memory for holding array of settings
  1484     TElementId* elids;
  1485     TSettingType* types;
  1486     TUint16* lens;
  1487     elids = (TElementId*) User::Alloc(aNumberOfSettings * sizeof(TElementId));
  1488     test_NotNull(elids);
  1489     types = (TSettingType*) User::Alloc(aNumberOfSettings * sizeof(TSettingType));
  1490     test_NotNull(types);
  1491     lens = (TUint16*) User::Alloc(aNumberOfSettings * sizeof(TUint16));
  1492     test_NotNull(lens);
  1493 
  1494     test.Next(_L("FindSettingsPattern, memory allocation failure"));
  1495     for (i = 0; i < sizeof(KTestFindSettingsPatternArgs) / sizeof(TTestFindSettingsPatternArgs); i++)
  1496         {
  1497         test.Printf(_L("iMask=0x%08x iPattern=0x%08x\n"),
  1498                 KTestFindSettingsPatternArgs[i].iMask,
  1499                 KTestFindSettingsPatternArgs[i].iPattern);
  1500 
  1501         // Test each category
  1502         TUint j;
  1503         for (j = 0; j < sizeof(KTestCategories) / sizeof(TCategoryUid); j++)
  1504             {
  1505             test.Printf(_L("Category 0x%08x: "), KTestCategories[j]);
  1506             //Memory allocation fail test. By this code we simulate the memory
  1507             //allocation failure at place defined by allocFactor. The loop will 
  1508             //continue until the next allocation is not failed. When we reached 
  1509             //this point it means we've gone through all possible allocations in
  1510             //the tested method below.
  1511             TInt allocFactor = 1;
  1512             //Memory allocation fails
  1513             do
  1514                 {
  1515                 __KHEAP_MARK;
  1516                 __KHEAP_SETFAIL(RAllocator::EFailNext, allocFactor);
  1517                 r = HcrSimTest.FindSettings(
  1518                         KTestCategories[j],
  1519                         aNumberOfSettings,
  1520                         KTestFindSettingsPatternArgs[i].iMask,
  1521                         KTestFindSettingsPatternArgs[i].iPattern,
  1522                         elids,
  1523                         types, lens);
  1524                 __KHEAP_MARKEND;
  1525 
  1526                 __KHEAP_RESET;
  1527 
  1528                 //Let's arrise the memory allocation failure at another place
  1529                 allocFactor ++;
  1530 
  1531                 }while(r == KErrNoMemory);
  1532 
  1533             }
  1534         }
  1535 
  1536 
  1537 
  1538     // Free memory
  1539     User::Free(elids);
  1540     User::Free(types);
  1541     User::Free(lens);
  1542 
  1543     }
  1544 
  1545 
  1546 void HcrSimApiNegative(const TInt aExpectedErrorCode, const TUint32 aCategory, const TUint32 aSettingId)
  1547 	{
  1548 	test.Next(_L("ApiNegative"));
  1549 	test.Printf(_L("Expected error: %d\nSetting (%08x, %08x)\n"), aExpectedErrorCode, aCategory, aSettingId);
  1550 	TSettingId id(aCategory, aSettingId);
  1551 	TInt r;
  1552 		{
  1553 		TInt32 val;
  1554 		r = HcrSimTest.GetInt(id, val);
  1555 		test_Equal(aExpectedErrorCode, r);
  1556 		}
  1557 		{
  1558 		TInt16 val;
  1559 		r = HcrSimTest.GetInt(id, val);
  1560 		test_Equal(aExpectedErrorCode, r);
  1561 		}
  1562 		{
  1563 		TInt8 val;
  1564 		r = HcrSimTest.GetInt(id, val);
  1565 		test_Equal(aExpectedErrorCode, r);
  1566 		}
  1567 		{
  1568 		TBool val;
  1569 		r = HcrSimTest.GetBool(id, val);
  1570 		test_Equal(aExpectedErrorCode, r);
  1571 		}
  1572 		{
  1573 		TUint32 val;
  1574 		r = HcrSimTest.GetUInt(id, val);
  1575 		test_Equal(aExpectedErrorCode, r);
  1576 		}
  1577 		{
  1578 		TUint16 val;
  1579 		r = HcrSimTest.GetUInt(id, val);
  1580 		test_Equal(aExpectedErrorCode, r);
  1581 		}
  1582 		{
  1583 		TUint8 val;
  1584 		r = HcrSimTest.GetUInt(id, val);
  1585 		test_Equal(aExpectedErrorCode, r);
  1586 		}
  1587 		{
  1588 		TLinAddr val;
  1589 		r = HcrSimTest.GetLinAddr(id, val);
  1590 		test_Equal(aExpectedErrorCode, r);
  1591 		}
  1592 		{
  1593 		TBuf8<KMaxSettingLength> dval;
  1594 		TUint8* pval;
  1595 		pval = (TUint8*) User::Alloc(KMaxSettingLength);
  1596 		test_NotNull(pval);
  1597 		//
  1598 		r = HcrSimTest.GetData(id, dval);
  1599 		test_Equal(aExpectedErrorCode, r);
  1600 		//
  1601 		TUint16 actuallength;
  1602 		r = HcrSimTest.GetData(id, KMaxSettingLength, pval, actuallength);
  1603 		test_Equal(aExpectedErrorCode, r);
  1604 		//
  1605 		User::Free(pval);
  1606 		}
  1607 		{
  1608 		TBuf8<KMaxSettingLength> dval;
  1609 		TText8* pval;
  1610 		pval = (TText8*) User::Alloc(KMaxSettingLength);
  1611 		test_NotNull(pval);
  1612 		//
  1613 		r = HcrSimTest.GetString(id, dval);
  1614 		test_Equal(aExpectedErrorCode, r);
  1615 		//
  1616 		TUint16 actuallength;
  1617 		r = HcrSimTest.GetString(id, KMaxSettingLength, pval, actuallength);
  1618 		test_Equal(aExpectedErrorCode, r);
  1619 		//
  1620 		User::Free(pval);
  1621 		}
  1622 		{
  1623 		TInt32* pval;
  1624 		pval = (TInt32*) User::Alloc(KMaxSettingLength);
  1625 		test_NotNull(pval);
  1626 		//
  1627 		TUint16 actuallength;
  1628 		r = HcrSimTest.GetArray(id, KMaxSettingLength, pval, actuallength);
  1629 		test_Equal(aExpectedErrorCode, r);
  1630 		//
  1631 		User::Free(pval);
  1632 		}
  1633 		{
  1634 		TUint32* pval;
  1635 		pval = (TUint32*) User::Alloc(KMaxSettingLength);
  1636 		test_NotNull(pval);
  1637 		//
  1638 		TUint16 actuallength;
  1639 		r = HcrSimTest.GetArray(id, KMaxSettingLength, pval, actuallength);
  1640 		test_Equal(aExpectedErrorCode, r);
  1641 		//
  1642 		User::Free(pval);
  1643 		}
  1644 		{
  1645 		TInt64 val;
  1646 		r = HcrSimTest.GetInt(id, val);
  1647 		test_Equal(aExpectedErrorCode, r);
  1648 		}
  1649 		{
  1650 		TUint64 val;
  1651 		r = HcrSimTest.GetUInt(id, val);
  1652 		test_Equal(aExpectedErrorCode, r);
  1653 		}
  1654 
  1655 		{
  1656 		TSettingType type = ETypeUndefined;
  1657 		TUint16 len = 0;
  1658 		TElementId elid = 0;
  1659 		
  1660 
  1661 		//
  1662 		r = HcrSimTest.GetTypeAndSize(id, type, len);
  1663 		test_Equal(aExpectedErrorCode, r);
  1664 
  1665 		//
  1666 		r = HcrSimTest.FindNumSettingsInCategory(id.iCat);
  1667 		if (aExpectedErrorCode == KErrNotFound)
  1668 			{
  1669 			test_Equal(0, r);
  1670 			}
  1671 		else
  1672 			{
  1673 			test_Equal(aExpectedErrorCode, r);
  1674 			}
  1675 		
  1676 		//
  1677 		r = HcrSimTest.FindSettings(id.iCat, 1, &elid, &type, &len);
  1678 		if (aExpectedErrorCode == KErrNotFound)
  1679 			{
  1680 			test_Equal(0, r);
  1681 			}
  1682 		else
  1683 			{
  1684 			test_Equal(aExpectedErrorCode, r);
  1685 			}
  1686 
  1687 		//
  1688 		r = HcrSimTest.FindSettings(id.iCat, 1, 0, 0, &elid, &type, &len);
  1689 		if (aExpectedErrorCode == KErrNotFound)
  1690 			{
  1691 			test_Equal(0, r);
  1692 			}
  1693 		else
  1694 			{
  1695 			test_Equal(aExpectedErrorCode, r);
  1696 			}
  1697 		}
  1698 		{
  1699 		SSettingId settingid;
  1700 		settingid.iCat = id.iCat;
  1701 		settingid.iKey = id.iKey;	
  1702 	
  1703 		TInt32 val;
  1704 		TInt err;
  1705 		TSettingType type;
  1706 		TInt i;
  1707 
  1708 		for(i = 0; i < 5; ++i)
  1709 			{
  1710 			// test parameter combinations where aIds[], aValues[], aErrors[] are NULL
  1711 			r = HcrSimTest.GetWordSettings((i==1)?0:1, (i==2)?NULL:&settingid, (i==3)?NULL:&val, &type, (i==4)?NULL:&err);
  1712 			if (aExpectedErrorCode != KErrNotFound)
  1713 				{
  1714 				// HCR did not initialise properly - HCR will not bother checking validity of arguments
  1715 				test_Equal(aExpectedErrorCode, r);
  1716 				}
  1717 			else if (i > 0)
  1718 				{
  1719 				// One of the arguments is invalid
  1720 				test_Equal(KErrArgument, r);
  1721 				}
  1722 			else
  1723 				{
  1724 				// Arguments are fine but element does not exist
  1725 				test_Equal(0, r);
  1726 				}
  1727 			}	
  1728 		}
  1729 
  1730 	}
  1731 
  1732 
  1733 void HcrSimTestApiTests(SSettingC* aRepository, TUint aNumberOfSettings)
  1734 	{
  1735 	if (aRepository && aNumberOfSettings > 0)
  1736 		{
  1737 		HcrSimGetSettings(aRepository, aNumberOfSettings);
  1738 		HcrSimGetSettingsNegative(aRepository, aNumberOfSettings);
  1739 		HcrSimSettingProperties(aRepository, aNumberOfSettings);
  1740 		HcrSimMultipleGet(aRepository, aNumberOfSettings);
  1741 		HcrSimNumSettingsInCategory(aRepository, aNumberOfSettings);
  1742 		HcrSimFindSettingsCategory(aRepository, aNumberOfSettings);
  1743 		HcrSimFindSettingsPattern(aRepository, aNumberOfSettings);
  1744 		
  1745 		HcrSimFindSettingsCategoryNegative(aRepository, aNumberOfSettings);
  1746 		HcrSimFindSettingsPatternNegative(aNumberOfSettings);
  1747 		if(gHcrThread == KSimOwnThread)
  1748 		    HcrSimFindSettingsPatternMemAllocFails(aNumberOfSettings);
  1749 		}
  1750 
  1751 	HcrSimApiNegative(KErrNotFound, KTestInvalidCategory, KTestInvalidSettingId);
  1752 	HcrSimApiNegative(KErrNotFound, KTestInvalidCategory, 1);
  1753 	}
  1754 
  1755 void HcrPslTests(const TDesC& aDriver)
  1756 	{
  1757 	test.Next(_L("PSL tests"));
  1758 	test.Start(_L("Load Device Driver"));
  1759 	test.Printf(_L("%S\n"), &aDriver);
  1760 	TInt r;
  1761 	r = User::LoadLogicalDevice(aDriver);
  1762 	if (r == KErrAlreadyExists)
  1763 		{
  1764 		test.Printf(_L("Unload Device Driver and load it again\n"));
  1765 		r = User::FreeLogicalDevice(aDriver);
  1766 		test_KErrNone(r);
  1767 		r = User::LoadLogicalDevice(aDriver);
  1768 		test_KErrNone(r);
  1769 		}
  1770 	else
  1771 		{
  1772 		test_KErrNone(r);
  1773 		}
  1774 
  1775 	test.Next(_L("Open test channel"));
  1776 	r = HcrSimTest.Open(aDriver);
  1777 	test_KErrNone(r);
  1778 
  1779 	test.Next(_L("Fail PSL object creation"));
  1780 	r = HcrSimTest.InitExtension(ETestVariantObjectCreateFail);
  1781 	test_Equal(KErrNoMemory, r);
  1782 	HcrSimApiNegative(KErrNotReady, 1, 1);
  1783 
  1784 	test.Next(_L("Fail PSL initialisation"));
  1785 	r = HcrSimTest.InitExtension(ETestInitialisationFail);
  1786 	test_Equal(KErrBadPower, r); // the random error code used in the test PSL
  1787 	HcrSimApiNegative(KErrNotReady, 1, 1);
  1788 
  1789 	test.Next(_L("PSL's GetCompiledRepositoryAddress negative tests"));
  1790 	r = HcrSimTest.InitExtension(ETestNullRepositoryKErrNone); // *** Null Repository but returns KErrNone
  1791 	test_Equal(KErrArgument, r);
  1792 
  1793 	test.Next(_L("PSL's GetCompiledRepositoryAddress return wrong error code"));
  1794 	r = HcrSimTest.InitExtension(ETestBadErrorCode); // *** Null Repository but returns KErrNone
  1795 	test_Equal(KErrCommsParity, r);
  1796 
  1797 	test.Next(_L("Close test channel and unload device driver"));
  1798 	HcrSimTest.Close();
  1799 	r = User::FreeLogicalDevice(aDriver);
  1800 	test_KErrNone(r);
  1801 	test.End();
  1802 	}
  1803 
  1804 void HcrSimTests(const TDesC& aDriver)
  1805 	{
  1806 	test.Next(_L("HCR Simulator tests"));
  1807 	test.Start(_L("Load Device Driver"));
  1808 	test.Printf(_L("%S\n"), &aDriver);
  1809 	TInt r;
  1810 	
  1811 	r = User::LoadLogicalDevice(aDriver);
  1812 	if (r == KErrAlreadyExists)
  1813 		{
  1814 		test.Printf(_L("Unload Device Driver and load it again\n"));
  1815 		r = User::FreeLogicalDevice(aDriver);
  1816 		test_KErrNone(r);
  1817 		r = User::LoadLogicalDevice(aDriver);
  1818 		test_KErrNone(r);
  1819 		}
  1820 	else
  1821 		{
  1822 		test_KErrNone(r);
  1823 		}
  1824 
  1825 	test.Next(_L("Open test channel"));
  1826 	r = HcrSimTest.Open(aDriver);
  1827 	test_KErrNone(r);
  1828 	HcrSimApiNegative(KErrNotReady, 1, 1);
  1829 	
  1830 	test.Next(_L("Initialise HCR"));
  1831 	r = HcrSimTest.InitExtension();
  1832 	test_KErrNone(r);
  1833 	
  1834 	//Initialize static variable with the right HCR client type
  1835 	if(aDriver.Compare(KTestHcrSimOwn) == 0)
  1836 	    gHcrThread = KSimOwnThread;
  1837 	else if(aDriver.Compare(KTestHcrSimClient) == 0)
  1838 	    gHcrThread = KSimClientThread;
  1839 	else
  1840 		test(EFalse);
  1841 	
  1842 	test.Next(_L("Compiled"));
  1843 	test.Start(_L("Initialisation"));
  1844 	r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::ECoreRepos);
  1845 	test_KErrNone(r);
  1846 	r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::EOverrideRepos);
  1847 	test_KErrNone(r);
  1848 	HcrSimTestApiTests(SettingsList, sizeof(SettingsList) / sizeof(SSettingC));
  1849 	test.End();    
  1850 		
  1851 	test.Next(_L("Compiled+File"));
  1852 	test.Start(_L("Initialisation"));
  1853 	r = HcrSimTest.SwitchRepository(KTestFileRepos, HCRInternal::ECoreRepos);
  1854 	test_KErrNone(r);
  1855 	r = HcrSimTest.CheckIntegrity();
  1856 	test_KErrNone(r);
  1857 	HcrSimTestApiTests(SettingsList2, sizeof(SettingsList2) / sizeof(SSettingC));
  1858 	test.End();
  1859 	
  1860 	test.Next(_L("Compiled+File+Nand"));
  1861 	test.Start(_L("Initialisation"));
  1862 	r = HcrSimTest.SwitchRepository(KTestNandRepos, HCRInternal::EOverrideRepos);
  1863 	test_KErrNone(r);
  1864 	r = HcrSimTest.CheckIntegrity();
  1865 	test_KErrNone(r);
  1866 	HcrSimTestApiTests(SettingsList3, sizeof(SettingsList3) / sizeof(SSettingC));
  1867 	test.End();
  1868 
  1869 	test.Next(_L("Compiled+Nand"));
  1870 	test.Start(_L("Initialisation"));
  1871 	r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::ECoreRepos);
  1872 	test_KErrNone(r);
  1873 	r = HcrSimTest.CheckIntegrity();
  1874 	test_KErrNone(r);
  1875 	HcrSimTestApiTests(SettingsList4, sizeof(SettingsList4) / sizeof(SSettingC));
  1876 	test.End();
  1877 
  1878 	test.Next(_L("Compiled+Empty+Nand"));
  1879 	test.Start(_L("Initialisation"));
  1880 	r = HcrSimTest.SwitchRepository(KTestEmpty, HCRInternal::ECoreRepos);
  1881 	test_KErrNone(r);
  1882 	r = HcrSimTest.CheckIntegrity();
  1883 	test_KErrNone(r);
  1884 	HcrSimTestApiTests(SettingsList4, sizeof(SettingsList4) / sizeof(SSettingC));
  1885 	test.End();
  1886 
  1887 	// Reload device driver without a compiled repository this time
  1888 	test.Next(_L("Reload Device Driver"));
  1889 	HcrSimTest.Close();
  1890 	r = User::FreeLogicalDevice(aDriver);
  1891 	test_KErrNone(r);
  1892 	r = User::LoadLogicalDevice(aDriver);
  1893 	test_KErrNone(r);
  1894 	r = HcrSimTest.Open(aDriver);
  1895 	test_KErrNone(r);
  1896 	r = HcrSimTest.InitExtension(ETestNullRepository); // *** The NULL Repository ***
  1897 	test_KErrNone(r);
  1898 	
  1899 	test.Next(_L("NULL+File"));
  1900 	test.Start(_L("Initialisation"));
  1901 	r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::EOverrideRepos);
  1902 	test_KErrNone(r);
  1903 	r = HcrSimTest.CheckIntegrity();
  1904 	test_KErrNone(r);
  1905 	HcrSimTestApiTests(SettingsList7, sizeof(SettingsList7) / sizeof(SSettingC));
  1906 	test.End();
  1907 	
  1908 	test.Next(_L("NULL+File+Nand"));
  1909 	test.Start(_L("Initialisation"));
  1910 	r = HcrSimTest.SwitchRepository(KTestNandRepos, HCRInternal::EOverrideRepos);
  1911 	test_KErrNone(r);
  1912 	r = HcrSimTest.CheckIntegrity();
  1913 	test_KErrNone(r);
  1914 	HcrSimTestApiTests(SettingsList6, sizeof(SettingsList6) / sizeof(SSettingC));
  1915 	test.End();
  1916 
  1917 	test.Next(_L("NULL+Nand"));
  1918 	test.Start(_L("Initialisation"));
  1919 	r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::ECoreRepos);
  1920 	test_KErrNone(r);
  1921 	r = HcrSimTest.CheckIntegrity();
  1922 	test_KErrNone(r);
  1923 	HcrSimTestApiTests(SettingsList5, sizeof(SettingsList5) / sizeof(SSettingC));
  1924 	test.End();
  1925 
  1926 	test.Next(_L("Reload Device Driver"));
  1927 	HcrSimTest.Close();
  1928 	r = User::FreeLogicalDevice(aDriver);
  1929 	test_KErrNone(r);
  1930 	r = User::LoadLogicalDevice(aDriver);
  1931 	test_KErrNone(r);
  1932 	r = HcrSimTest.Open(aDriver);
  1933 	test_KErrNone(r);
  1934 	r = HcrSimTest.InitExtension(ETestEmptyRepository); // *** The Empty Repository ***
  1935 	test_KErrNone(r);
  1936 
  1937 	test.Next(_L("Empty+Nand"));
  1938 	test.Start(_L("Initialisation"));
  1939 	r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::ECoreRepos);
  1940 	test_KErrNone(r);
  1941 	r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::EOverrideRepos);
  1942 	test_KErrNone(r);
  1943 	r = HcrSimTest.SwitchRepository(KTestNandRepos, HCRInternal::EOverrideRepos);
  1944 	test_KErrNone(r);
  1945 	r = HcrSimTest.CheckIntegrity();
  1946 	test_KErrNone(r);
  1947 	HcrSimTestApiTests(SettingsList5, sizeof(SettingsList5) / sizeof(SSettingC));
  1948 	test.End();
  1949 
  1950 	test.Next(_L("Empty+File+Nand"));
  1951 	test.Start(_L("Initialisation"));
  1952 	r = HcrSimTest.SwitchRepository(KTestFileRepos, HCRInternal::ECoreRepos);
  1953 	test_KErrNone(r);
  1954 	r = HcrSimTest.CheckIntegrity();
  1955 	test_KErrNone(r);
  1956 	HcrSimTestApiTests(SettingsList6, sizeof(SettingsList6) / sizeof(SSettingC));
  1957 	test.End();
  1958 
  1959 	test.Next(_L("Empty+File"));
  1960 	test.Start(_L("Initialisation"));
  1961 	r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::EOverrideRepos);
  1962 	test_KErrNone(r);
  1963 	r = HcrSimTest.CheckIntegrity();
  1964 	test_KErrNone(r);
  1965 	HcrSimTestApiTests(SettingsList7, sizeof(SettingsList7) / sizeof(SSettingC));
  1966 	test.End();
  1967 
  1968 	test.Next(_L("Empty+File+Empty"));
  1969 	test.Start(_L("Initialisation"));
  1970 	r = HcrSimTest.SwitchRepository(KTestEmpty, HCRInternal::EOverrideRepos);
  1971 	test_KErrNone(r);
  1972 	r = HcrSimTest.CheckIntegrity();
  1973 	test_KErrNone(r);
  1974 	HcrSimTestApiTests(SettingsList7, sizeof(SettingsList7) / sizeof(SSettingC));
  1975 	test.End();
  1976 
  1977 	test.Next(_L("No Repository (Empty)"));
  1978 	test.Start(_L("Initialisation"));
  1979 	r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::ECoreRepos);
  1980 	test_KErrNone(r);
  1981 	r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::EOverrideRepos);
  1982 	test_KErrNone(r);
  1983 	r = HcrSimTest.CheckIntegrity();
  1984 	test_KErrNone(r);
  1985 	HcrSimTestApiTests(NULL, 0);
  1986 	test.End();
  1987 
  1988 	test.Next(_L("All Repositories Empty"));
  1989 	test.Start(_L("Initialisation"));
  1990 	r = HcrSimTest.SwitchRepository(KTestEmpty, HCRInternal::ECoreRepos);
  1991 	test_KErrNone(r);
  1992 	r = HcrSimTest.SwitchRepository(KTestEmpty, HCRInternal::EOverrideRepos);
  1993 	test_KErrNone(r);
  1994 	r = HcrSimTest.CheckIntegrity();
  1995 	test_KErrNone(r);
  1996 	HcrSimTestApiTests(NULL, 0);
  1997 	test.End();
  1998 
  1999 	test.Next(_L("Reload Device Driver"));
  2000 	HcrSimTest.Close();
  2001 	r = User::FreeLogicalDevice(aDriver);
  2002 	test_KErrNone(r);
  2003 	r = User::LoadLogicalDevice(aDriver);
  2004 	test_KErrNone(r);
  2005 	r = HcrSimTest.Open(aDriver);
  2006 	test_KErrNone(r);
  2007 	r = HcrSimTest.InitExtension(ETestIgnoreCoreImgRepository); // *** Ignore Core Image Repository ***
  2008 	test_KErrNone(r);
  2009 
  2010 	test.Next(_L("Compiled+File(Ignored)+Nand")); // Should be same as Compiled+Nand
  2011 	test.Start(_L("Initialisation"));
  2012 	r = HcrSimTest.SwitchRepository(KTestNandRepos, HCRInternal::EOverrideRepos);
  2013 	test_KErrNone(r);
  2014 	r = HcrSimTest.CheckIntegrity();
  2015 	test_KErrNone(r);
  2016 	HcrSimTestApiTests(SettingsList4, sizeof(SettingsList4) / sizeof(SSettingC));
  2017 	test.End();
  2018 
  2019 	test.Next(_L("Reload Device Driver (Corrupt1)"));
  2020 	HcrSimTest.Close();
  2021 	r = User::FreeLogicalDevice(aDriver);
  2022 	test_KErrNone(r);
  2023 	r = User::LoadLogicalDevice(aDriver);
  2024 	test_KErrNone(r);
  2025 	r = HcrSimTest.Open(aDriver);
  2026 	test_KErrNone(r);
  2027 	r = HcrSimTest.InitExtension(ETestCorruptRepository1); // *** Repository not ordered ***
  2028 #ifdef _DEBUG
  2029 	test_Equal(KErrCorrupt, r);
  2030 #else
  2031 	test_KErrNone(r);
  2032 #endif // _DEBUG
  2033 
  2034 	test.Next(_L("Reload Device Driver (Corrupt2)"));
  2035 	HcrSimTest.Close();
  2036 	r = User::FreeLogicalDevice(aDriver);
  2037 	test_KErrNone(r);
  2038 	r = User::LoadLogicalDevice(aDriver);
  2039 	test_KErrNone(r);
  2040 	r = HcrSimTest.Open(aDriver);
  2041 	test_KErrNone(r);
  2042 	r = HcrSimTest.InitExtension(ETestCorruptRepository2); // *** Repository with duplicates ***
  2043 #ifdef _DEBUG
  2044 	test_Equal(KErrAlreadyExists, r);
  2045 #else
  2046 	test_KErrNone(r);
  2047 #endif // _DEBUG
  2048 
  2049 	test.Next(_L("Reload Device Driver (NULL ordered list)"));
  2050 	HcrSimTest.Close();
  2051 	r = User::FreeLogicalDevice(aDriver);
  2052 	test_KErrNone(r);
  2053 	r = User::LoadLogicalDevice(aDriver);
  2054 	test_KErrNone(r);
  2055 	r = HcrSimTest.Open(aDriver);
  2056 	test_KErrNone(r);
  2057 	r = HcrSimTest.InitExtension(ETestNullOrderedList); // *** Repository where iOrderedSettingList==NULL ***
  2058 #ifdef _DEBUG
  2059 	test_Equal(KErrNotFound, r);
  2060 #else
  2061 	test_KErrNone(r);
  2062 #endif // _DEBUG
  2063 
  2064 	test.Next(_L("Reload Device Driver (Default)"));
  2065 	HcrSimTest.Close();
  2066 	r = User::FreeLogicalDevice(aDriver);
  2067 	test_KErrNone(r);
  2068 	r = User::LoadLogicalDevice(aDriver);
  2069 	test_KErrNone(r);
  2070 	r = HcrSimTest.Open(aDriver);
  2071 	test_KErrNone(r);
  2072 	r = HcrSimTest.InitExtension(); // *** Default Repository ***
  2073 	test_KErrNone(r);
  2074 
  2075 	test.Next(_L("Compiled+Corrupt1+Nand"));
  2076 	test.Start(_L("Initialisation"));
  2077 	r = HcrSimTest.SwitchRepository(KTestCorrupt1, HCRInternal::ECoreRepos);
  2078 	test_KErrNone(r);
  2079 	r = HcrSimTest.SwitchRepository(KTestNandRepos, HCRInternal::EOverrideRepos);
  2080 	test_KErrNone(r);
  2081 	r = HcrSimTest.CheckIntegrity();
  2082 	test_Equal(KErrCorrupt, r);
  2083 	test.End();
  2084 
  2085 	test.Next(_L("Compiled+Corrupt2+Nand"));
  2086 	test.Start(_L("Initialisation"));
  2087 	r = HcrSimTest.SwitchRepository(KTestCorrupt2, HCRInternal::ECoreRepos);
  2088 	test_KErrNone(r);
  2089 	r = HcrSimTest.CheckIntegrity();
  2090 	test_Equal(KErrAlreadyExists, r);
  2091 	test.End();
  2092 
  2093 	test.Next(_L("Compiled+File+Corrupt1"));
  2094 	test.Start(_L("Initialisation"));
  2095 	r = HcrSimTest.SwitchRepository(KTestFileRepos, HCRInternal::ECoreRepos);
  2096 	test_KErrNone(r);
  2097 	r = HcrSimTest.SwitchRepository(KTestCorrupt1, HCRInternal::EOverrideRepos);
  2098 	test_KErrNone(r);
  2099 	r = HcrSimTest.CheckIntegrity();
  2100 	test_Equal(KErrCorrupt, r);
  2101 	test.End();
  2102 
  2103 	test.Next(_L("Compiled+File+Corrupt2"));
  2104 	test.Start(_L("Initialisation"));
  2105 	r = HcrSimTest.SwitchRepository(KTestCorrupt2, HCRInternal::EOverrideRepos);
  2106 	test_KErrNone(r);
  2107 	r = HcrSimTest.CheckIntegrity();
  2108 	test_Equal(KErrAlreadyExists, r);
  2109 	test.End();
  2110 
  2111 	test.Next(_L("Close test channel and unload device driver"));
  2112 	HcrSimTest.Close();
  2113 	r = User::FreeLogicalDevice(aDriver);
  2114 	test_KErrNone(r);
  2115 	test.End();
  2116 	}
  2117 
  2118 void RomHeaderTests()
  2119 	{
  2120 	test.Next(_L("Rom Header"));
  2121 #ifdef __WINS__
  2122 	test.Printf(_L("Not available on the emulator.\n"));
  2123 #else
  2124 	const TRomHeader* romheader = (TRomHeader*) UserSvr::RomHeaderAddress();
  2125 	test.Printf(_L("HCR File Address: %08x\n"), romheader->iHcrFileAddress);
  2126 	test(romheader->iHcrFileAddress);
  2127 	if (romheader->iPageableRomStart)
  2128 		{
  2129 		// If this is a paged ROM, HCR file must be in the unpaged area
  2130 		test_Compare(romheader->iRomBase + romheader->iPageableRomStart, >, romheader->iHcrFileAddress);
  2131 		}
  2132 #endif // __WINS__
  2133 	}
  2134 
  2135 void HcrRealSettingDiscovery()
  2136 	{
  2137 	test.Next(_L("Setting Discovery"));
  2138 	TInt r;
  2139 	TCategoryUid cat;
  2140 	test.Printf(_L("Category Element  Type     Len  Value\n"));
  2141 	test.Printf(_L("--------------------------------------------------\n"));
  2142 	for (cat = KHCRUID_ALLOCATED_MIN; cat <= KHCRUID_ALLOCATED_MAX; cat++)
  2143 		{
  2144 		TInt nosettings;
  2145 		nosettings = HcrSimTest.FindNumSettingsInCategory(cat);
  2146 		test_Compare(0, <=, nosettings);
  2147 		if (nosettings > 0)
  2148 			{
  2149 			TElementId* elids;
  2150 			TSettingType* types;
  2151 			TUint16* lens;
  2152 			elids = (TElementId*) User::Alloc(nosettings * sizeof(TElementId));
  2153 			test_NotNull(elids);
  2154 			types = (TSettingType*) User::Alloc(nosettings * sizeof(TSettingType));
  2155 			test_NotNull(types);
  2156 			lens = (TUint16*) User::Alloc(nosettings * sizeof(TUint16));
  2157 			test_NotNull(lens);
  2158 			r = HcrSimTest.FindSettings(cat, nosettings, elids, types, lens);
  2159 			test_Equal(nosettings, r);
  2160 			
  2161 			TInt i;
  2162 			for (i = 0; i < nosettings; i++)
  2163 				{
  2164 				TSettingId id(cat, *(elids + i));
  2165 				test.Printf(_L("%08x %08x %08x %04x "), cat, *(elids + i), *(types + i), *(lens + i));
  2166 				switch (*(types + i))
  2167 					{
  2168 					case ETypeInt32:
  2169 						{
  2170 						TInt32 val;
  2171 						r = HcrSimTest.GetInt(id, val);
  2172 						test_KErrNone(r);
  2173 						test.Printf(_L("%08x"), val);
  2174 						break;
  2175 						}
  2176 					case ETypeInt16:
  2177 						{
  2178 						TInt16 val;
  2179 						r = HcrSimTest.GetInt(id, val);
  2180 						test_KErrNone(r);
  2181 						test.Printf(_L("%04x"), val);
  2182 						break;
  2183 						}
  2184 					case ETypeInt8:
  2185 						{
  2186 						TInt8 val;
  2187 						r = HcrSimTest.GetInt(id, val);
  2188 						test_KErrNone(r);
  2189 						test.Printf(_L("%02x"), val);
  2190 						break;
  2191 						}
  2192 					case ETypeBool:
  2193 						{
  2194 						TBool val;
  2195 						r = HcrSimTest.GetBool(id, val);
  2196 						test_KErrNone(r);
  2197 						test.Printf(_L("%b"), val ? 1 : 0);
  2198 						break;
  2199 						}
  2200 					case ETypeUInt32:
  2201 						{
  2202 						TUint32 val;
  2203 						r = HcrSimTest.GetUInt(id, val);
  2204 						test_KErrNone(r);
  2205 						test.Printf(_L("%08x"), val);
  2206 						break;
  2207 						}
  2208 					case ETypeUInt16:
  2209 						{
  2210 						TUint16 val;
  2211 						r = HcrSimTest.GetUInt(id, val);
  2212 						test_KErrNone(r);
  2213 						test.Printf(_L("%04x"), val);
  2214 						break;
  2215 						}
  2216 					case ETypeUInt8:
  2217 						{
  2218 						TUint8 val;
  2219 						r = HcrSimTest.GetUInt(id, val);
  2220 						test_KErrNone(r);
  2221 						test.Printf(_L("%02x"), val);
  2222 						break;
  2223 						}
  2224 					case ETypeLinAddr:
  2225 						{
  2226 						TLinAddr val;
  2227 						r = HcrSimTest.GetLinAddr(id, val);
  2228 						test_KErrNone(r);
  2229 						test.Printf(_L("%08x"), val);
  2230 						break;
  2231 						}
  2232 					case ETypeBinData:
  2233 						{
  2234 						TBuf8<KMaxSettingLength> dval;
  2235 						TUint8* pval;
  2236 						pval = (TUint8*) User::Alloc(*(lens + i));
  2237 						test_NotNull(pval);
  2238 						//
  2239 						r = HcrSimTest.GetData(id, dval);
  2240 						test_KErrNone(r);
  2241 						test_Equal(*(lens + i), dval.Length());
  2242 						//
  2243 						TUint16 actuallength;
  2244 						r = HcrSimTest.GetData(id, *(lens + i), pval, actuallength);
  2245 						test_KErrNone(r);
  2246 						test_Equal(*(lens + i), actuallength);
  2247 						//
  2248 						TInt j;
  2249 						for (j = 0; j < 6 && j < dval.Length(); j++)
  2250 							{
  2251 							test.Printf(_L("%02x "), dval[j]);
  2252 							}
  2253 							
  2254 						//
  2255 						User::Free(pval);
  2256 						break;
  2257 						}
  2258 					case ETypeText8:
  2259 						{
  2260 						TBuf8<KMaxSettingLength> dval;
  2261 						TText8* pval;
  2262 						pval = (TText8*) User::Alloc(*(lens + i));
  2263 						test_NotNull(pval);
  2264 						//
  2265 						r = HcrSimTest.GetString(id, dval);
  2266 						test_KErrNone(r);
  2267 						test_Equal(*(lens + i), dval.Length());
  2268 						//
  2269 						TUint16 actuallength;
  2270 						r = HcrSimTest.GetString(id, *(lens + i), pval, actuallength);
  2271 						test_KErrNone(r);
  2272 						test_Equal(*(lens + i), actuallength);
  2273 						//
  2274 						TInt j;
  2275 						for (j = 0; j < 15 && j < dval.Length(); j++)
  2276 							{
  2277 							test.Printf(_L("%c "), dval[j]);
  2278 							}
  2279 						//
  2280 						User::Free(pval);
  2281 						break;
  2282 						}
  2283 					case ETypeArrayInt32:
  2284 						{
  2285 						TInt32* pval;
  2286 						pval = (TInt32*) User::Alloc(*(lens + i));
  2287 						test_NotNull(pval);
  2288 						//
  2289 						TUint16 actuallength;
  2290 						r = HcrSimTest.GetArray(id, *(lens + i), pval, actuallength);
  2291 						test_KErrNone(r);
  2292 						//
  2293 						test_Equal(*(lens + i), actuallength);
  2294 						//
  2295 						TUint j;
  2296 						for (j = 0; j < 2 && j < actuallength / sizeof(TInt32); j++)
  2297 							{
  2298 							test.Printf(_L("%08x "), pval[0]);
  2299 							}
  2300 						//
  2301 						User::Free(pval);
  2302 						break;
  2303 						}
  2304 					case ETypeArrayUInt32:
  2305 						{
  2306 						TUint32* pval;
  2307 						pval = (TUint32*) User::Alloc(*(lens + i));
  2308 						test_NotNull(pval);
  2309 						//
  2310 						TUint16 actuallength;
  2311 						r = HcrSimTest.GetArray(id, *(lens + i), pval, actuallength);
  2312 						test_KErrNone(r);
  2313 						//
  2314 						TUint j;
  2315 						for (j = 0; j < 2 && j < actuallength / sizeof(TUint32); j++)
  2316 							{
  2317 							test.Printf(_L("%08x "), pval[0]);
  2318 							}
  2319 						//
  2320 						test_Equal(*(lens + i), actuallength);
  2321 						User::Free(pval);
  2322 						break;
  2323 						}
  2324 					case ETypeInt64:
  2325 						{
  2326 						TInt64 val;
  2327 						r = HcrSimTest.GetInt(id, val);
  2328 						test_KErrNone(r);
  2329 						test.Printf(_L("%016lx"), val);
  2330 						
  2331 						break;
  2332 						}
  2333 					case ETypeUInt64:
  2334 						{
  2335 						TUint64 val;
  2336 						r = HcrSimTest.GetUInt(id, val);
  2337 						test_KErrNone(r);
  2338 						test.Printf(_L("%016lx"), val);
  2339 						break;
  2340 						}
  2341 					default:
  2342 						test(EFalse);
  2343 					}
  2344 				test.Printf(_L("\n"));
  2345 				}
  2346 			User::Free(elids);
  2347 			User::Free(types);
  2348 			User::Free(lens);
  2349 			}
  2350 		}
  2351 	}
  2352 void HcrRealRetrieveKernelExtensionTestResults()
  2353 	{
  2354 	test.Next(_L("Retrieve kernel extension test results"));
  2355 	TInt r;
  2356 	TInt kextline;
  2357 	TInt kexterror;
  2358 	r = HcrSimTest.GetInitExtensionTestResults(kextline, kexterror);
  2359 	test_KErrNone(r);
  2360 	if (kextline == -1)
  2361 		{
  2362 		test.Printf(_L("Test not run\n"));
  2363 		}
  2364 	else if (kextline == 0)
  2365 		{
  2366 		test.Printf(_L("Test passed\n"));
  2367 		}
  2368 	else
  2369 		{
  2370 		test.Printf(_L("Test kernel extension error at line %d (error %d)\n"), kextline, kexterror);
  2371 		test(EFalse);
  2372 		}
  2373 	}
  2374 
  2375 void HcrRealTests(const TDesC& aDriver)
  2376 	{
  2377 	test.Next(_L("HCR real tests"));
  2378 	test.Start(_L("Load LDD"));
  2379 	test.Printf(_L("%S\n"), &aDriver);
  2380 	TInt r;
  2381 	r = User::LoadLogicalDevice(aDriver);
  2382 	if (r == KErrNotFound)
  2383 		{
  2384 		test.Printf(_L("%S not found. Skipping tests.\n"), &aDriver);
  2385 		}
  2386 	else
  2387 		{
  2388 		if (r == KErrAlreadyExists)
  2389 			{
  2390 			test.Printf(_L("Unload Device Driver and load it again\n"));
  2391 			r = User::FreeLogicalDevice(aDriver);
  2392 			test_KErrNone(r);
  2393 			r = User::LoadLogicalDevice(aDriver);
  2394 			}
  2395 		test_KErrNone(r);
  2396 		r = HcrSimTest.Open(aDriver);
  2397 		test_KErrNone(r);
  2398 		//
  2399 		HcrRealRetrieveKernelExtensionTestResults();
  2400 		HcrRealSettingDiscovery();
  2401 
  2402 		// Initialize static variable with the right HCR client type
  2403 		if(aDriver.Compare(KTestHcrRealOwn) == 0)
  2404 			gHcrThread = KSimOwnThread;
  2405 		else if(aDriver.Compare(KTestHcrRealClient) == 0)
  2406 			gHcrThread = KSimClientThread;
  2407 		else
  2408 			test(EFalse);
  2409 		//
  2410 		TBool smr;
  2411 		TBool smrrep;
  2412 		r = HcrSimTest.HasRepositoryInSmr(smr, smrrep);
  2413 		test_KErrNone(r);
  2414 		if (smrrep)
  2415 			{
  2416 			// File + NAND
  2417 			HcrSimTestApiTests(SettingsList6, sizeof(SettingsList6) / sizeof(SSettingC));
  2418 			}
  2419 		else
  2420 			{
  2421 			// File
  2422 			HcrSimTestApiTests(SettingsList7, sizeof(SettingsList7) / sizeof(SSettingC));
  2423 			}
  2424 		//
  2425 		test.Next(_L("Close LDD"));
  2426 		HcrSimTest.Close();
  2427 		r = User::FreeLogicalDevice(aDriver);
  2428 		test_KErrNone(r);
  2429 		}
  2430 	test.End();
  2431 	}
  2432 
  2433 void HcrSimBenchmarkTests(const TDesC& aDriver)
  2434 	{
  2435 	test.Next(_L("Simulated HCR Benchmark"));
  2436 	test.Start(_L("Initialisation"));
  2437 	test.Printf(_L("%S\n"), &aDriver);
  2438 	TInt r;
  2439 	r = User::LoadLogicalDevice(aDriver);
  2440 	if (r == KErrAlreadyExists)
  2441 		{
  2442 		test.Printf(_L("Unload Device Driver and load it again\n"));
  2443 		r = User::FreeLogicalDevice(aDriver);
  2444 		test_KErrNone(r);
  2445 		r = User::LoadLogicalDevice(aDriver);
  2446 		test_KErrNone(r);
  2447 		}
  2448 	else
  2449 		{
  2450 		test_KErrNone(r);
  2451 		}
  2452 	r = HcrSimTest.Open(aDriver);
  2453 	test_KErrNone(r);
  2454 	r = HcrSimTest.InitExtension();
  2455 	test_KErrNone(r);
  2456 	r = HcrSimTest.CheckIntegrity();
  2457 	test_KErrNone(r);
  2458 
  2459 	test.Next(_L("Get Setting"));
  2460 	// Timings in ms
  2461 	TUint32 int1 = 0;
  2462 	TUint32 int1000 = 0;
  2463 	TUint32 array1 = 0;
  2464 	TUint32 array1000 = 0;
  2465 	TUint32 des1 = 0;
  2466 	TUint32 des1000 = 0;
  2467 	TUint32 fns = 0;
  2468 	TUint32 fs = 0;
  2469 	TUint32 gts = 0;
  2470 	TUint32 gws = 0;
  2471 	_LIT(KTestBenchLine, "%-6d   %-6d   %-6d   %-6d   %-6d   %-6d   %-6d   %-6d   %-6d   %-6d\n");
  2472 	test.Printf(_L("HCR  Int1     Int1000  Arr1     Arr1000  Des1     Des1000  FNS      FS       GTS      GWS\n"));
  2473 	// Default configuration
  2474 	TSettingId idint1(1, 1);
  2475 	TSettingId idstring1(KTestCategories[2], 0x6000);
  2476 	test_KErrNone(HcrSimTest.BenchmarkGetSettingInt(idint1, int1));
  2477 	test_KErrNone(HcrSimTest.BenchmarkGetSettingArray(idstring1, array1));
  2478 	test_KErrNone(HcrSimTest.BenchmarkGetSettingDes(idstring1, des1));
  2479 	test.Printf(_L("C??  "));
  2480 	test.Printf(KTestBenchLine, int1, int1000, array1, array1000, des1, des1000, fns, fs, gts, gws);
  2481 	
  2482 	r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::ECoreRepos);
  2483 	test_KErrNone(r);
  2484 	r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::EOverrideRepos);
  2485 	test_KErrNone(r);
  2486 	r = HcrSimTest.CheckIntegrity();
  2487 	test_KErrNone(r);
  2488 	test_KErrNone(HcrSimTest.BenchmarkGetSettingInt(idint1, int1));
  2489 	test_KErrNone(HcrSimTest.BenchmarkGetSettingArray(idstring1, array1));
  2490 	test_KErrNone(HcrSimTest.BenchmarkGetSettingDes(idstring1, des1));
  2491 	test.Printf(_L("C__  "));
  2492 	test.Printf(KTestBenchLine, int1, int1000, array1, array1000, des1, des1000, fns, fs, gts, gws);
  2493 	//
  2494 	TSettingId idint1000(KTestBenchmarkCategoryId, 1000);
  2495 	TSettingId idstring1000(KTestBenchmarkCategoryId, 1001);
  2496 	r = HcrSimTest.SwitchRepository(KTestMegaLarge1, HCRInternal::ECoreRepos);
  2497 	test_KErrNone(r);
  2498 	r = HcrSimTest.CheckIntegrity();
  2499 	test_KErrNone(r);
  2500 	test_KErrNone(HcrSimTest.BenchmarkGetSettingInt(idint1, int1));
  2501 	test_KErrNone(HcrSimTest.BenchmarkGetSettingInt(idint1000, int1000));
  2502 	test_KErrNone(HcrSimTest.BenchmarkGetSettingArray(idstring1, array1));
  2503 	test_KErrNone(HcrSimTest.BenchmarkGetSettingArray(idstring1000, array1000));
  2504 	test_KErrNone(HcrSimTest.BenchmarkGetSettingDes(idstring1, des1));
  2505 	test_KErrNone(HcrSimTest.BenchmarkGetSettingDes(idstring1000, des1000));
  2506 
  2507 	test_Equal(KTestBenchmarkNumberOfSettingsInCategory, HcrSimTest.BenchmarkFindNumSettingsInCategory(KTestBenchmarkCategoryId, fns));
  2508 	test_Equal(KTestBenchmarkNumberOfSettingsInCategory, HcrSimTest.BenchmarkFindSettings(KTestBenchmarkCategoryId, fs));
  2509 	test_KErrNone(HcrSimTest.BenchmarkGetTypeAndSize(idstring1000, gts));
  2510 	test_Equal(KTestBenchmarkNumberOfSettingsInCategory - 1, HcrSimTest.BenchmarkGetWordSettings(KTestBenchmarkCategoryId, gws));
  2511 
  2512 	test.Printf(_L("CF_  "));
  2513 	test.Printf(KTestBenchLine, int1, int1000, array1, array1000, des1, des1000, fns, fs, gts, gws);
  2514 	//
  2515 	r = HcrSimTest.SwitchRepository(KTestMegaLarge2, HCRInternal::EOverrideRepos);
  2516 	test_KErrNone(r);
  2517 	r = HcrSimTest.CheckIntegrity();
  2518 	test_KErrNone(r);
  2519 	test_KErrNone(HcrSimTest.BenchmarkGetSettingInt(idint1, int1));
  2520 	test_KErrNone(HcrSimTest.BenchmarkGetSettingInt(idint1000, int1000));
  2521 	test_KErrNone(HcrSimTest.BenchmarkGetSettingArray(idstring1, array1));
  2522 	test_KErrNone(HcrSimTest.BenchmarkGetSettingArray(idstring1000, array1000));
  2523 	test_KErrNone(HcrSimTest.BenchmarkGetSettingDes(idstring1, des1));
  2524 	test_KErrNone(HcrSimTest.BenchmarkGetSettingDes(idstring1000, des1000));
  2525 
  2526 	test_Equal(KTestBenchmarkNumberOfSettingsInCategory, HcrSimTest.BenchmarkFindNumSettingsInCategory(KTestBenchmarkCategoryId, fns));
  2527 	test_Equal(KTestBenchmarkNumberOfSettingsInCategory, HcrSimTest.BenchmarkFindSettings(KTestBenchmarkCategoryId, fs));
  2528 	test_KErrNone(HcrSimTest.BenchmarkGetTypeAndSize(idstring1000, gts));
  2529 	test_Equal(KTestBenchmarkNumberOfSettingsInCategory - 1, HcrSimTest.BenchmarkGetWordSettings(KTestBenchmarkCategoryId, gws));
  2530 
  2531 	test.Printf(_L("CFN  "));
  2532 	test.Printf(KTestBenchLine, int1, int1000, array1, array1000, des1, des1000, fns, fs, gts, gws);
  2533 	//
  2534 	r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::EOverrideRepos);
  2535 	test_KErrNone(r);
  2536 	r = HcrSimTest.CheckIntegrity();
  2537 	test_KErrNone(r);
  2538 	test_KErrNone(HcrSimTest.BenchmarkGetSettingInt(idint1, int1));
  2539 	test_KErrNone(HcrSimTest.BenchmarkGetSettingInt(idint1000, int1000));
  2540 	test_KErrNone(HcrSimTest.BenchmarkGetSettingArray(idstring1, array1));
  2541 	test_KErrNone(HcrSimTest.BenchmarkGetSettingArray(idstring1000, array1000));
  2542 	test_KErrNone(HcrSimTest.BenchmarkGetSettingDes(idstring1, des1));
  2543 	test_KErrNone(HcrSimTest.BenchmarkGetSettingDes(idstring1000, des1000));
  2544 
  2545 	test_Equal(KTestBenchmarkNumberOfSettingsInCategory, HcrSimTest.BenchmarkFindNumSettingsInCategory(KTestBenchmarkCategoryId, fns));
  2546 	test_Equal(KTestBenchmarkNumberOfSettingsInCategory, HcrSimTest.BenchmarkFindSettings(KTestBenchmarkCategoryId, fs));
  2547 	test_KErrNone(HcrSimTest.BenchmarkGetTypeAndSize(idstring1000, gts));
  2548 	test_Equal(KTestBenchmarkNumberOfSettingsInCategory - 1, HcrSimTest.BenchmarkGetWordSettings(KTestBenchmarkCategoryId, gws));
  2549 
  2550 	test.Printf(_L("C_N  "));
  2551 	test.Printf(KTestBenchLine, int1, int1000, array1, array1000, des1, des1000, fns, fs, gts, gws);
  2552 
  2553 	test.Next(_L("Unload LDD"));
  2554 	HcrSimTest.Close();
  2555 	r = User::FreeLogicalDevice(aDriver);
  2556 	test_KErrNone(r);
  2557 	test.End();
  2558 	}
  2559 
  2560 void HcrRealBenchmarkTests(const TDesC& aDriver)
  2561 	{
  2562 	TInt r;
  2563 	test.Next(_L("Real HCR Benchmark"));
  2564 	test.Start(_L("Initialisation"));
  2565 	test.Printf(_L("%S\n"), &aDriver);
  2566 	r = User::LoadLogicalDevice(aDriver);
  2567 	if (r == KErrNotFound)
  2568 		{
  2569 		test.Printf(_L("%S not found. Skipping tests.\n"), &aDriver);
  2570 		}
  2571 	else
  2572 		{
  2573 		if (r == KErrAlreadyExists)
  2574 			{
  2575 			test.Printf(_L("Unload Device Driver and load it again\n"));
  2576 			r = User::FreeLogicalDevice(aDriver);
  2577 			test_KErrNone(r);
  2578 			r = User::LoadLogicalDevice(aDriver);
  2579 			}
  2580 		test_KErrNone(r);
  2581 		r = HcrSimTest.Open(aDriver);
  2582 		test_KErrNone(r);
  2583 		//
  2584 		test.Next(_L("Close LDD"));
  2585 		HcrSimTest.Close();
  2586 		r = User::FreeLogicalDevice(aDriver);
  2587 		test_KErrNone(r);
  2588 		}
  2589 	test.End();
  2590 	}
  2591 
  2592 GLDEF_C TInt E32Main()
  2593 	{
  2594 	__UHEAP_MARK;
  2595 
  2596 	test.Title();
  2597 	test.Start(_L("HCR Test Suite"));
  2598 		
  2599 	
  2600 	//Order the the test lists in descend(the setting with the smallest
  2601 	//setting Id is first)
  2602 	TLinearOrder<SSettingC> order(CompareEntries);
  2603 	//Build the ordered ids arrays
  2604 	RArray<SSettingC> rSettingsList(sizeof(SSettingC), SettingsList,
  2605 			sizeof(SettingsList)/sizeof(SettingsList[0]));
  2606 	
  2607 	rSettingsList.Sort(order);
  2608 	
  2609 	RArray<SSettingC> rSettingsList2(sizeof(SSettingC), SettingsList2,
  2610 			sizeof(SettingsList2)/sizeof(SettingsList2[0]));
  2611 	rSettingsList2.Sort(order);
  2612 
  2613 	RArray<SSettingC> rSettingsList3(sizeof(SSettingC), SettingsList3,
  2614 			sizeof(SettingsList3)/sizeof(SettingsList3[0]));
  2615 	rSettingsList3.Sort(order);
  2616 
  2617 	RArray<SSettingC> rSettingsList4(sizeof(SSettingC), SettingsList4,
  2618 			sizeof(SettingsList4)/sizeof(SettingsList4[0]));
  2619 	rSettingsList4.Sort(order);
  2620 
  2621 	RArray<SSettingC> rSettingsList5(sizeof(SSettingC), SettingsList5,
  2622 			sizeof(SettingsList5)/sizeof(SettingsList5[0]));
  2623 	rSettingsList5.Sort(order);
  2624 
  2625 	RArray<SSettingC> rSettingsList6(sizeof(SSettingC), SettingsList6,
  2626 			sizeof(SettingsList6)/sizeof(SettingsList6[0]));
  2627 	rSettingsList6.Sort(order);
  2628 
  2629 	RArray<SSettingC> rSettingsList7(sizeof(SSettingC), SettingsList7,
  2630 			sizeof(SettingsList7)/sizeof(SettingsList7[0]));
  2631 	rSettingsList7.Sort(order);
  2632 
  2633 	
  2634     //Functional API test
  2635 	RomHeaderTests();
  2636 	HcrRealTests(KTestHcrRealOwn);
  2637 	HcrRealTests(KTestHcrRealClient);
  2638 	HcrPslTests(KTestHcrSimOwn);
  2639 	HcrPslTests(KTestHcrSimClient);
  2640 	HcrSimTests(KTestHcrSimOwn);
  2641 	HcrSimTests(KTestHcrSimClient);
  2642 
  2643 
  2644 	//Benchmark tests
  2645 	HcrSimBenchmarkTests(KTestHcrSimOwn);
  2646 	HcrSimBenchmarkTests(KTestHcrSimClient);
  2647 	HcrRealBenchmarkTests(KTestHcrRealOwn);
  2648 	HcrRealBenchmarkTests(KTestHcrRealClient);
  2649 
  2650 	test.End();
  2651 	test.Close();
  2652 
  2653 	__UHEAP_MARKEND;
  2654 	return KErrNone;
  2655 	}