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