os/kernelhwsrv/kerneltest/e32test/resourceman/acctst/t_prmacctst.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) 2007-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
//
sl@0
    15
sl@0
    16
#define __E32TEST_EXTENSION__
sl@0
    17
#include <e32test.h>
sl@0
    18
#include "d_prmacctst.h"
sl@0
    19
sl@0
    20
_LIT8(KTestToc, "TOC");
sl@0
    21
_LIT8(KTestTac1, "TAC1");
sl@0
    22
_LIT8(KTestTac2, "TAC2");
sl@0
    23
_LIT8(KTestTac3, "TAC3");
sl@0
    24
sl@0
    25
// The number of test values for multi-level resources
sl@0
    26
static const TInt KTestMultiLevelValues = 10;
sl@0
    27
sl@0
    28
// Bit 16 in the resource ID indicates that the resource has dependencies
sl@0
    29
static const TUint32 KTestIdHasDependencies = 0x00010000;
sl@0
    30
static const TInt    KTestMaxDependencies = 256;
sl@0
    31
sl@0
    32
static const TInt    KTestResourceNotInUse = -1;
sl@0
    33
sl@0
    34
// structure for holding ResId and ResPrty
sl@0
    35
struct SResDepInfo
sl@0
    36
	{
sl@0
    37
	TUint iResourceId;
sl@0
    38
	TUint8 iDependencyPriority;
sl@0
    39
	};
sl@0
    40
class CTestPrmAccTst : public CBase
sl@0
    41
	{
sl@0
    42
public:
sl@0
    43
	CTestPrmAccTst();
sl@0
    44
	~CTestPrmAccTst();
sl@0
    45
	TInt DoTestPreamble();
sl@0
    46
	void DoTest();
sl@0
    47
	void DoTestPostamble();
sl@0
    48
protected:
sl@0
    49
	TBool ResourceInterdependency(TInt aResourceIdOrig, TInt aCurrentResourceId, TInt aResourceIdTarget);
sl@0
    50
	void TestEnumerateResources();
sl@0
    51
	void TestSingleUserResources(TInt aResourceNo);
sl@0
    52
	void TestSharedResources(TInt aResourceNo);
sl@0
    53
	void TestBinaryResources(TInt aResourceNo);
sl@0
    54
	void TestMultilevelResources(TInt aResourceNo);
sl@0
    55
	void TestLatency(TInt aResourceNo);
sl@0
    56
	void TestSense(TInt aResourceNo);
sl@0
    57
	void TestCustomSense(TInt aResourceNo);
sl@0
    58
	void TestDefaultPowerResumption();
sl@0
    59
	void TestDependenciesAreDeclared(TInt aResourceNo);
sl@0
    60
private:
sl@0
    61
	enum TBinary
sl@0
    62
		{
sl@0
    63
		EBinaryOff = 0,
sl@0
    64
		EBinaryOn = 1
sl@0
    65
		};
sl@0
    66
protected:
sl@0
    67
	RTest test;
sl@0
    68
private:
sl@0
    69
	// The test PRM clients
sl@0
    70
	RPrmIf iToc;   // Test Observer Client (never owns any resource)
sl@0
    71
	RPrmIf iTac1;  // Active clients...
sl@0
    72
	RPrmIf iTac2;
sl@0
    73
	RPrmIf iTac3;
sl@0
    74
	RPrmIf iKextc;	// The Kernel Extension Client (owns Single User Resources)
sl@0
    75
	//
sl@0
    76
	TBool iIsPrmSupported;
sl@0
    77
	//
sl@0
    78
	RBuf8 iResources;
sl@0
    79
	TUint iNoResources;
sl@0
    80
	//
sl@0
    81
	static CTestPrmAccTst* iSingletonInstance;
sl@0
    82
	};
sl@0
    83
sl@0
    84
CTestPrmAccTst::CTestPrmAccTst()
sl@0
    85
	:test(_L("T_PRMACCTST")),
sl@0
    86
		iIsPrmSupported(EFalse),
sl@0
    87
		iNoResources(0)
sl@0
    88
	{
sl@0
    89
	}
sl@0
    90
sl@0
    91
CTestPrmAccTst::~CTestPrmAccTst()
sl@0
    92
	{
sl@0
    93
	iResources.Close();
sl@0
    94
	TInt r = User::FreeLogicalDevice(KPrmIfLddName);
sl@0
    95
	test(r==KErrNone);
sl@0
    96
#ifdef RESOURCE_MANAGER_SIMULATED_PSL
sl@0
    97
	r = User::FreePhysicalDevice(_L("resourcecontrollerextended.pdd"));
sl@0
    98
	test(r==KErrNone);
sl@0
    99
#endif
sl@0
   100
	User::After(100000);
sl@0
   101
	}
sl@0
   102
sl@0
   103
/* ----------------------------------------------------------------------------
sl@0
   104
@SYMTestCaseID		PBASE-PRMACCTST-ENUMRES-0559
sl@0
   105
@SYMTestCaseDesc	Ensure current resource state of PRM is correctly listed
sl@0
   106
@SYMREQ				REQ7751
sl@0
   107
@SYMPREQ			PREQ1398
sl@0
   108
@SYMTestPriority	Critical
sl@0
   109
@SYMTestActions
sl@0
   110
	1.	Display all resources and their properties
sl@0
   111
	2.	Ensure the resource state range is coherent
sl@0
   112
@SYMTestExpectedResults
sl@0
   113
	1.	All resources are shown with the correct properties
sl@0
   114
	2.	Min <= Default <= Max and Min < Max if Negative Sense
sl@0
   115
		Min >= Default >= Max and Max > Min if Positive Sense
sl@0
   116
		Binary resources states are '0' or '1'
sl@0
   117
*/
sl@0
   118
sl@0
   119
void CTestPrmAccTst::TestEnumerateResources()
sl@0
   120
	{
sl@0
   121
	test.Printf(_L("Id       Resource name                    C LG LS T  U  S DefltLvl MinLevel MaxLevel\n"));
sl@0
   122
	test.Printf(_L("--------+--------------------------------+-+--+--+--+--+-+--------+--------+--------\n"));
sl@0
   123
	TInt i;
sl@0
   124
	for (i = 0; i < (TInt) iNoResources; i++)
sl@0
   125
		{
sl@0
   126
		TResInfo& res = *((TResInfo*) iResources.Ptr() + i);
sl@0
   127
sl@0
   128
		// Display properties
sl@0
   129
		test.Printf(_L("%08x "), res.iResourceId);
sl@0
   130
		test_Compare(res.iResourceName->Length(), <=, KNameMaxLength);
sl@0
   131
		TBuf<KNameMaxLength> tmp;
sl@0
   132
		tmp.Copy(*res.iResourceName);
sl@0
   133
		test.Printf(_L("%-.32S "), &tmp);
sl@0
   134
		//
sl@0
   135
		if (res.iClass == TResInfo::EPhysical)
sl@0
   136
			{
sl@0
   137
			test.Printf(_L("P "));
sl@0
   138
			}
sl@0
   139
		else if (res.iClass == TResInfo::ELogical)
sl@0
   140
			{
sl@0
   141
			test.Printf(_L("L "));
sl@0
   142
			}
sl@0
   143
		else
sl@0
   144
			{
sl@0
   145
			test(EFalse);
sl@0
   146
			}
sl@0
   147
		//
sl@0
   148
		if (res.iLatencyGet == TResInfo::EInstantaneous)
sl@0
   149
			{
sl@0
   150
			test.Printf(_L("In "));
sl@0
   151
			}
sl@0
   152
		else if (res.iLatencyGet == TResInfo::ELongLatency)
sl@0
   153
			{
sl@0
   154
			test.Printf(_L("Lo "));
sl@0
   155
			}
sl@0
   156
		else
sl@0
   157
			{
sl@0
   158
			test(EFalse);
sl@0
   159
			}
sl@0
   160
		//
sl@0
   161
		if (res.iLatencySet == TResInfo::EInstantaneous)
sl@0
   162
			{
sl@0
   163
			test.Printf(_L("In "));
sl@0
   164
			}
sl@0
   165
		else if (res.iLatencySet == TResInfo::ELongLatency)
sl@0
   166
			{
sl@0
   167
			test.Printf(_L("Lo "));
sl@0
   168
			}
sl@0
   169
		else
sl@0
   170
			{
sl@0
   171
			test(EFalse);
sl@0
   172
			}
sl@0
   173
		//
sl@0
   174
		if (res.iType == TResInfo::EBinary)
sl@0
   175
			{
sl@0
   176
			test.Printf(_L("B  "));
sl@0
   177
			}
sl@0
   178
		else if (res.iType == TResInfo::EMultiLevel)
sl@0
   179
			{
sl@0
   180
			test.Printf(_L("ML "));
sl@0
   181
			}
sl@0
   182
		else if (res.iType == TResInfo::EMultiProperty)
sl@0
   183
			{
sl@0
   184
			test.Printf(_L("MP "));
sl@0
   185
			}
sl@0
   186
		else
sl@0
   187
			{
sl@0
   188
			test(EFalse);
sl@0
   189
			}
sl@0
   190
		//
sl@0
   191
		if (res.iUsage == TResInfo::ESingleUse)
sl@0
   192
			{
sl@0
   193
			test.Printf(_L("SU "));
sl@0
   194
			}
sl@0
   195
		else if (res.iUsage == TResInfo::EShared)
sl@0
   196
			{
sl@0
   197
			test.Printf(_L("Sh "));
sl@0
   198
			}
sl@0
   199
		else
sl@0
   200
			{
sl@0
   201
			test(EFalse);
sl@0
   202
			}
sl@0
   203
		//
sl@0
   204
		if (res.iSense == TResInfo::EPositive)
sl@0
   205
			{
sl@0
   206
			test.Printf(_L("+ "));
sl@0
   207
			}
sl@0
   208
		else if (res.iSense == TResInfo::ENegative)
sl@0
   209
			{
sl@0
   210
			test.Printf(_L("- "));
sl@0
   211
			}
sl@0
   212
		else if (res.iSense == TResInfo::ECustom)
sl@0
   213
			{
sl@0
   214
			test.Printf(_L("C "));
sl@0
   215
			}
sl@0
   216
		else
sl@0
   217
			{
sl@0
   218
			test(EFalse);
sl@0
   219
			}
sl@0
   220
		//
sl@0
   221
		test.Printf(_L("%08x "), res.iDefaultLevel);
sl@0
   222
		test.Printf(_L("%08x "), res.iMinLevel);
sl@0
   223
		test.Printf(_L("%08x\n"), res.iMaxLevel);
sl@0
   224
		
sl@0
   225
		// Retrieve resource dependencies
sl@0
   226
		if (res.iResourceId & KTestIdHasDependencies)
sl@0
   227
			{
sl@0
   228
			RBuf8 deplist;
sl@0
   229
			deplist.Create(sizeof(SResDepInfo) * KTestMaxDependencies);
sl@0
   230
			iToc.GetResourceDependencies(res.iResourceId, deplist);
sl@0
   231
			TInt j;
sl@0
   232
			test.Printf(_L("  Direct Dependencies:"));
sl@0
   233
			SResDepInfo* ptr = (SResDepInfo*)deplist.Ptr();
sl@0
   234
			for (j = 0; j < (TInt) (deplist.Length() / sizeof(SResDepInfo)); j++, ptr++)
sl@0
   235
				{
sl@0
   236
				test.Printf(_L("ResourceId: %08x"), ptr->iResourceId);
sl@0
   237
				test.Printf(_L("Resource Priority: %08x"), ptr->iDependencyPriority);
sl@0
   238
				}
sl@0
   239
			test.Printf(_L("\n"));
sl@0
   240
			deplist.Close();
sl@0
   241
			}
sl@0
   242
		test.Printf(_L("C:Class,P:Physical,L:Logical"));
sl@0
   243
		test.Printf(_L("LG/LS:Latency Get/Set,In:Instantaneous,Lo:Long Latency"));
sl@0
   244
		test.Printf(_L("T:Type,MP:Multiproperty,ML:Multilevel,B:Binary"));
sl@0
   245
		test.Printf(_L("U:Usage,SU:Single-User,Sh:Shared"));
sl@0
   246
		test.Printf(_L("S:Sense,+:Positive,-:Negative,C:Custom"));
sl@0
   247
sl@0
   248
		// Ensure the state range of the resource does not contradict its properties
sl@0
   249
		if (res.iType == TResInfo::EBinary)
sl@0
   250
			{
sl@0
   251
			if (res.iSense == TResInfo::EPositive)
sl@0
   252
				{
sl@0
   253
				test(res.iMinLevel == EBinaryOff);
sl@0
   254
				test(res.iMaxLevel == EBinaryOn);
sl@0
   255
				}
sl@0
   256
			else if (res.iSense == TResInfo::ENegative)
sl@0
   257
				{
sl@0
   258
				test(res.iMinLevel == EBinaryOn);
sl@0
   259
				test(res.iMaxLevel == EBinaryOff);
sl@0
   260
				}
sl@0
   261
			else if (res.iSense == TResInfo::ECustom)
sl@0
   262
				{
sl@0
   263
				test(res.iMinLevel == EBinaryOff || res.iMinLevel == EBinaryOn);
sl@0
   264
				test(res.iMaxLevel == EBinaryOff || res.iMaxLevel == EBinaryOn);
sl@0
   265
				test_Compare(res.iMinLevel, !=, res.iMaxLevel);
sl@0
   266
				}
sl@0
   267
			test((res.iDefaultLevel == EBinaryOff) || (res.iDefaultLevel == EBinaryOn));
sl@0
   268
			}
sl@0
   269
		// Level range must respect resource sense
sl@0
   270
		if (res.iSense == TResInfo::EPositive)
sl@0
   271
			{
sl@0
   272
			test_Compare(res.iMinLevel, <=, res.iMaxLevel);
sl@0
   273
			test_Compare(res.iMinLevel, <=, res.iDefaultLevel);
sl@0
   274
			test_Compare(res.iDefaultLevel, <=, res.iMaxLevel);
sl@0
   275
			test_Compare(res.iMinLevel, <, res.iMaxLevel);
sl@0
   276
			}
sl@0
   277
		else if (res.iSense == TResInfo::ENegative)
sl@0
   278
			{
sl@0
   279
			test_Compare(res.iMinLevel, >=, res.iMaxLevel);
sl@0
   280
			test_Compare(res.iMinLevel, >=, res.iDefaultLevel);
sl@0
   281
			test_Compare(res.iDefaultLevel, >=, res.iMaxLevel);
sl@0
   282
			test_Compare(res.iMinLevel, >, res.iMaxLevel);
sl@0
   283
			}
sl@0
   284
		}
sl@0
   285
	}
sl@0
   286
sl@0
   287
/* ----------------------------------------------------------------------------
sl@0
   288
@SYMTestCaseID		PBASE-PRMACCTST-SINGLEUSER-0560
sl@0
   289
@SYMTestCaseDesc	Ensure Single User resources can only be used by one client
sl@0
   290
					at a time
sl@0
   291
@SYMREQ				REQ7751
sl@0
   292
@SYMPREQ			PREQ1398
sl@0
   293
@SYMTestPriority	High
sl@0
   294
@SYMTestActions
sl@0
   295
Pre-condition:
sl@0
   296
	The resource is not in use
sl@0
   297
For each Single User resource:
sl@0
   298
	1.	Register TAC1 & TAC2
sl@0
   299
	2.	TAC1 changes resource state
sl@0
   300
	3.	TAC2 changes resource state
sl@0
   301
	4.	De-register TAC1
sl@0
   302
	---
sl@0
   303
	5.	Register TAC1
sl@0
   304
	6.	TAC2 changes resource state
sl@0
   305
	7.	TAC1 changes resource state
sl@0
   306
	8.	De-register TAC1 & TAC2
sl@0
   307
@SYMTestExpectedResults
sl@0
   308
	1.	Clients registered
sl@0
   309
	2.	Resource state changed
sl@0
   310
	3.	KErrAccessDenied as there is already one registered client
sl@0
   311
	4.	Client de-registered
sl@0
   312
	---
sl@0
   313
	5.	Client registered
sl@0
   314
	6.	Resource state changed
sl@0
   315
	7.	KErrAccessDenied as there is already one registered client
sl@0
   316
	8.	Both clients de-registered
sl@0
   317
*/
sl@0
   318
sl@0
   319
void CTestPrmAccTst::TestSingleUserResources(TInt aResourceNo)
sl@0
   320
	{
sl@0
   321
	test.Printf(_L("---Single-User "));
sl@0
   322
	TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
sl@0
   323
	// Test pre-condition: resource not in use
sl@0
   324
	TInt levelowner;
sl@0
   325
	TInt r = iToc.GetLevelOwner(res.iResourceId, levelowner);
sl@0
   326
	test_KErrNone(r);
sl@0
   327
	if (levelowner != KTestResourceNotInUse)
sl@0
   328
		{
sl@0
   329
		test.Printf(_L("Not tested (Single-User resource already in use)\n"));
sl@0
   330
		return;
sl@0
   331
		}
sl@0
   332
	// Define two test values
sl@0
   333
	TInt state;
sl@0
   334
	r = iToc.GetResourceState(res.iResourceId, state);
sl@0
   335
	test_KErrNone(r);
sl@0
   336
	//
sl@0
   337
	TInt tstval1;
sl@0
   338
	TInt tstval2;
sl@0
   339
	if (state == res.iMinLevel)
sl@0
   340
		{
sl@0
   341
		tstval1 = res.iMaxLevel;
sl@0
   342
		tstval2 = res.iMinLevel;
sl@0
   343
		}
sl@0
   344
	else
sl@0
   345
		{
sl@0
   346
		tstval1 = res.iMinLevel;
sl@0
   347
		tstval2 = res.iMaxLevel;
sl@0
   348
		}
sl@0
   349
	// Test starts here
sl@0
   350
	r = iTac1.Open();
sl@0
   351
	test_KErrNone(r);
sl@0
   352
	r = iTac2.Open();
sl@0
   353
	test_KErrNone(r);
sl@0
   354
	r = iTac1.RegisterClient(KTestTac1);
sl@0
   355
	test_KErrNone(r);
sl@0
   356
	r = iTac2.RegisterClient(KTestTac2);
sl@0
   357
	test_KErrNone(r);
sl@0
   358
	//
sl@0
   359
	r = iTac1.ChangeResourceState(res.iResourceId, tstval1);
sl@0
   360
	test_KErrNone(r);
sl@0
   361
	r = iTac1.GetResourceState(res.iResourceId, state);
sl@0
   362
	test_KErrNone(r);
sl@0
   363
	test_Equal(tstval1, state);
sl@0
   364
	r = iTac2.GetResourceState(res.iResourceId, state);
sl@0
   365
	test_KErrNone(r);
sl@0
   366
	test_Equal(tstval1, state);
sl@0
   367
	r = iTac2.ChangeResourceState(res.iResourceId, tstval2);
sl@0
   368
	test_Equal(KErrAccessDenied, r); // TAC2 cannot change the resource state
sl@0
   369
	//
sl@0
   370
	r = iTac1.DeRegisterClient();
sl@0
   371
	test_KErrNone(r);
sl@0
   372
	r = iTac1.RegisterClient(KTestTac1);
sl@0
   373
	test_KErrNone(r);
sl@0
   374
	r = iTac2.ChangeResourceState(res.iResourceId, tstval2);
sl@0
   375
	test_KErrNone(r);
sl@0
   376
	r = iTac1.GetResourceState(res.iResourceId, state);
sl@0
   377
	test_KErrNone(r); // TAC1 can still access the resource state...
sl@0
   378
	test_Equal(tstval2, state);
sl@0
   379
	r = iTac1.ChangeResourceState(res.iResourceId, tstval1);
sl@0
   380
	test_Equal(KErrAccessDenied, r); // ... but cannot change it
sl@0
   381
	r = iTac2.GetResourceState(res.iResourceId, state);
sl@0
   382
	test_KErrNone(r);
sl@0
   383
	test_Equal(tstval2, state); // The resource state remains unchanged indeed
sl@0
   384
	//
sl@0
   385
	r = iTac1.DeRegisterClient();
sl@0
   386
	test_KErrNone(r);
sl@0
   387
	r = iTac2.DeRegisterClient();
sl@0
   388
	test_KErrNone(r);
sl@0
   389
	iTac1.Close();
sl@0
   390
	iTac2.Close();
sl@0
   391
	test.Printf(_L("\n"));
sl@0
   392
	}
sl@0
   393
sl@0
   394
/* ----------------------------------------------------------------------------
sl@0
   395
@SYMTestCaseID		PBASE-PRMACCTST-SHARED-0561
sl@0
   396
@SYMTestCaseDesc	Ensure a Shared Resources can be changed by several
sl@0
   397
					clients
sl@0
   398
@SYMREQ				REQ7751
sl@0
   399
@SYMPREQ			PREQ1398
sl@0
   400
@SYMTestPriority	High
sl@0
   401
@SYMTestActions
sl@0
   402
Pre-conditions: 
sl@0
   403
	If in use, resource state is not equal to max level
sl@0
   404
	Resource is not Custom Sense
sl@0
   405
For each Shared resource:
sl@0
   406
	1.	Register TOC, TAC1 & TAC2
sl@0
   407
	2.	TAC1 changes resource state to level1
sl@0
   408
	3.	TAC2 changes resource state to level2
sl@0
   409
	4.	TAC2 changes resource state to level1
sl@0
   410
	5.	TAC1 changes resource state to level2
sl@0
   411
	6.	De-register TOC, TAC1 & TAC2
sl@0
   412
@SYMTestExpectedResults
sl@0
   413
	1.	Clients registered
sl@0
   414
	2.	Resource state changed
sl@0
   415
	3.	Resource state changed
sl@0
   416
	4.	Resource state changed
sl@0
   417
	5.	Resource state changed
sl@0
   418
	6.	Clients de-registered
sl@0
   419
*/
sl@0
   420
sl@0
   421
void CTestPrmAccTst::TestSharedResources(TInt aResourceNo)
sl@0
   422
	{
sl@0
   423
	test.Printf(_L("---Shared "));
sl@0
   424
	TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
sl@0
   425
	// Test pre-conditions
sl@0
   426
	if (res.iSense == TResInfo::ECustom)
sl@0
   427
		{
sl@0
   428
		test.Printf(_L("Not tested (Custom sense resource)\n"));
sl@0
   429
		return;
sl@0
   430
		}
sl@0
   431
	//
sl@0
   432
	TInt state;
sl@0
   433
	TInt r = iToc.GetResourceState(res.iResourceId, state);
sl@0
   434
	test_KErrNone(r);
sl@0
   435
	TInt levelowner;
sl@0
   436
	r = iToc.GetLevelOwner(res.iResourceId, levelowner);
sl@0
   437
	test_KErrNone(r);
sl@0
   438
	//
sl@0
   439
	if (levelowner != KTestResourceNotInUse && state == res.iMaxLevel)
sl@0
   440
		{
sl@0
   441
		test.Printf(_L("Not tested: Resource is already at maximum level\n"));
sl@0
   442
		return;
sl@0
   443
		}
sl@0
   444
	// Define two test values
sl@0
   445
	TInt tstval1;
sl@0
   446
	TInt tstval2;
sl@0
   447
	if (levelowner != KTestResourceNotInUse)
sl@0
   448
		{
sl@0
   449
		// Resource already in use
sl@0
   450
		tstval1 = state;
sl@0
   451
		tstval2 = res.iMaxLevel;
sl@0
   452
		}
sl@0
   453
	else
sl@0
   454
		{
sl@0
   455
		// Resource not in use
sl@0
   456
		tstval1 = res.iMinLevel;
sl@0
   457
		tstval2 = res.iMaxLevel;
sl@0
   458
		}
sl@0
   459
	// Test starts here
sl@0
   460
	r = iTac1.Open();
sl@0
   461
	test_KErrNone(r);
sl@0
   462
	r = iTac2.Open();
sl@0
   463
	test_KErrNone(r);
sl@0
   464
	r = iTac1.RegisterClient(KTestTac1);
sl@0
   465
	test_KErrNone(r);
sl@0
   466
	r = iTac2.RegisterClient(KTestTac2);
sl@0
   467
	test_KErrNone(r);
sl@0
   468
	//
sl@0
   469
	r = iTac1.ChangeResourceState(res.iResourceId, tstval1);
sl@0
   470
	test_KErrNone(r);
sl@0
   471
	r = iToc.GetResourceState(res.iResourceId, state);
sl@0
   472
	test_KErrNone(r);
sl@0
   473
	test_Equal(tstval1, state);
sl@0
   474
	//
sl@0
   475
	r = iTac2.ChangeResourceState(res.iResourceId, tstval2);
sl@0
   476
	test_KErrNone(r);
sl@0
   477
	r = iToc.GetResourceState(res.iResourceId, state);
sl@0
   478
	test_KErrNone(r);
sl@0
   479
	test_Equal(tstval2, state);
sl@0
   480
	//
sl@0
   481
	r = iTac2.ChangeResourceState(res.iResourceId, tstval1);
sl@0
   482
	test_KErrNone(r);
sl@0
   483
	r = iToc.GetResourceState(res.iResourceId, state);
sl@0
   484
	test_KErrNone(r);
sl@0
   485
	test_Equal(tstval1, state);
sl@0
   486
	//
sl@0
   487
	r = iTac1.ChangeResourceState(res.iResourceId, tstval2);
sl@0
   488
	test_KErrNone(r);
sl@0
   489
	r = iToc.GetResourceState(res.iResourceId, state);
sl@0
   490
	test_KErrNone(r);
sl@0
   491
	test_Equal(tstval2, state);
sl@0
   492
	//
sl@0
   493
	r = iTac1.DeRegisterClient();
sl@0
   494
	test_KErrNone(r);
sl@0
   495
	r = iTac2.DeRegisterClient();
sl@0
   496
	test_KErrNone(r);
sl@0
   497
	//
sl@0
   498
	iTac1.Close();
sl@0
   499
	iTac2.Close();
sl@0
   500
	test.Printf(_L("\n"));
sl@0
   501
	}
sl@0
   502
sl@0
   503
/* ----------------------------------------------------------------------------
sl@0
   504
@SYMTestCaseID		PBASE-PRMACCTST-BINARY-0562
sl@0
   505
@SYMTestCaseDesc	Ensure Binary Resources function as expected
sl@0
   506
@SYMREQ				REQ7751
sl@0
   507
@SYMPREQ			PREQ1398
sl@0
   508
@SYMTestPriority	High
sl@0
   509
@SYMTestActions
sl@0
   510
Pre-conditions:
sl@0
   511
Resource not in use, or...
sl@0
   512
	If Shared/Positive Sense, current resource must be off
sl@0
   513
	If Shared/Negative Sense, current resource must be on
sl@0
   514
Resource is not Custom Sense
sl@0
   515
For each Binary resource:
sl@0
   516
	1.	Register TAC1
sl@0
   517
	2.	Turn resource off and toggle resource state several times
sl@0
   518
	3.	De-register TAC1
sl@0
   519
@SYMTestExpectedResults
sl@0
   520
	1.	Client registered
sl@0
   521
	2.	Resource state changes as expected
sl@0
   522
	3.	De-register TAC1
sl@0
   523
*/
sl@0
   524
sl@0
   525
void CTestPrmAccTst::TestBinaryResources(TInt aResourceNo)
sl@0
   526
	{
sl@0
   527
	test.Printf(_L("---Binary "));
sl@0
   528
	TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
sl@0
   529
	// Test pre-conditions
sl@0
   530
	if (res.iSense == TResInfo::ECustom)
sl@0
   531
		{
sl@0
   532
		test.Printf(_L("Not tested (Custom sense resource)\n"));
sl@0
   533
		return;
sl@0
   534
		}
sl@0
   535
	TInt state;
sl@0
   536
	TInt r = iToc.GetResourceState(res.iResourceId, state);
sl@0
   537
	test_KErrNone(r);
sl@0
   538
	TInt levelowner;
sl@0
   539
	r = iToc.GetLevelOwner(res.iResourceId, levelowner);
sl@0
   540
	test_KErrNone(r);
sl@0
   541
	//
sl@0
   542
	if (levelowner != KTestResourceNotInUse)
sl@0
   543
		{
sl@0
   544
		if (res.iUsage == TResInfo::ESingleUse)
sl@0
   545
			{
sl@0
   546
			test.Printf(_L("Not tested (Single-User resource already in use)\n"));
sl@0
   547
			return;
sl@0
   548
			}
sl@0
   549
		if (res.iSense == TResInfo::EPositive && state == EBinaryOn)
sl@0
   550
			{
sl@0
   551
			test.Printf(_L("Not tested (Positive sense resource is already on)\n"));
sl@0
   552
			return;
sl@0
   553
			}
sl@0
   554
		if (res.iSense == TResInfo::ENegative && state == EBinaryOff)
sl@0
   555
			{
sl@0
   556
			test.Printf(_L("Not tested (Negative sense resource is already off)\n"));
sl@0
   557
			return;
sl@0
   558
			}
sl@0
   559
		}
sl@0
   560
	// Test starts here
sl@0
   561
	r = iTac1.Open();
sl@0
   562
	test_KErrNone(r);
sl@0
   563
	r = iTac1.RegisterClient(KTestTac1);
sl@0
   564
	test_KErrNone(r);
sl@0
   565
sl@0
   566
	// Turn Resource off
sl@0
   567
	r = iTac1.ChangeResourceState(res.iResourceId, EBinaryOff);
sl@0
   568
	test_KErrNone(r);
sl@0
   569
	r = iToc.GetResourceState(res.iResourceId, state);
sl@0
   570
	test_KErrNone(r);
sl@0
   571
	test_Equal(EBinaryOff, state);
sl@0
   572
sl@0
   573
	// Turn it on
sl@0
   574
	r = iTac1.ChangeResourceState(res.iResourceId, EBinaryOn);
sl@0
   575
	test_KErrNone(r);
sl@0
   576
	r = iToc.GetResourceState(res.iResourceId, state);
sl@0
   577
	test_KErrNone(r);
sl@0
   578
	test_Equal(EBinaryOn, state);
sl@0
   579
sl@0
   580
	// Turn it off
sl@0
   581
	r = iTac1.ChangeResourceState(res.iResourceId, EBinaryOff);
sl@0
   582
	test_KErrNone(r);
sl@0
   583
	r = iToc.GetResourceState(res.iResourceId, state);
sl@0
   584
	test_KErrNone(r);
sl@0
   585
	test_Equal(EBinaryOff, state);
sl@0
   586
	//
sl@0
   587
	r = iTac1.DeRegisterClient();
sl@0
   588
	test_KErrNone(r);
sl@0
   589
	iTac1.Close();
sl@0
   590
	test.Printf(_L("\n"));
sl@0
   591
	}
sl@0
   592
sl@0
   593
/* ----------------------------------------------------------------------------
sl@0
   594
@SYMTestCaseID		PBASE-PRMACCTST-MULTILEVEL-0563
sl@0
   595
@SYMTestCaseDesc	Ensure Multi-Level Resources function as expected
sl@0
   596
@SYMREQ				REQ7751
sl@0
   597
@SYMPREQ			PREQ1398
sl@0
   598
@SYMTestPriority	High
sl@0
   599
@SYMTestActions
sl@0
   600
Pre-condition:
sl@0
   601
	If in use, resource state is not equal to max level
sl@0
   602
	If in use, resource is not Single-User
sl@0
   603
	Resource is not Custom Sense
sl@0
   604
For each Multi-Level resource:
sl@0
   605
	1.	Register TOC and TAC1
sl@0
   606
	2.	Define a number of gradually increasing (or decreasing if negative
sl@0
   607
		sense resource) test values across the range of valid states. Attempt
sl@0
   608
		to change the resource state to each of these values.
sl@0
   609
	3.	De-register TOC and TAC1
sl@0
   610
@SYMTestExpectedResults
sl@0
   611
	1.	Clients registered
sl@0
   612
	2.	Resource state should be changed to the test value if this value is
sl@0
   613
		accepted by the PSL. If not, the resource state should be changed to
sl@0
   614
		the minimum valid value that satisfies this requirement.
sl@0
   615
	3.	Clients de-registered
sl@0
   616
*/
sl@0
   617
sl@0
   618
void CTestPrmAccTst::TestMultilevelResources(TInt aResourceNo)
sl@0
   619
	{
sl@0
   620
	test.Printf(_L("---Multi-level "));
sl@0
   621
	TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
sl@0
   622
	// Test pre-conditions
sl@0
   623
	if (res.iSense == TResInfo::ECustom)
sl@0
   624
		{
sl@0
   625
		test.Printf(_L("Not tested (Custom sense resource)\n"));
sl@0
   626
		return;
sl@0
   627
		}
sl@0
   628
	TInt state;
sl@0
   629
	TInt r = iToc.GetResourceState(res.iResourceId, state);
sl@0
   630
	test_KErrNone(r);
sl@0
   631
	TInt levelowner;
sl@0
   632
	r = iToc.GetLevelOwner(res.iResourceId, levelowner);
sl@0
   633
	test_KErrNone(r);
sl@0
   634
	//
sl@0
   635
	if (levelowner != KTestResourceNotInUse)
sl@0
   636
		{
sl@0
   637
		if (state == res.iMaxLevel)
sl@0
   638
			{
sl@0
   639
			test.Printf(_L("Not tested (Resource is already at maximum level)\n"));
sl@0
   640
			return;
sl@0
   641
			}
sl@0
   642
		if (res.iUsage == TResInfo::ESingleUse)
sl@0
   643
			{
sl@0
   644
			test.Printf(_L("Not tested (Single-User resource already in use)\n"));
sl@0
   645
			return;
sl@0
   646
			}
sl@0
   647
		}
sl@0
   648
	// Define test values
sl@0
   649
	TInt tstval[KTestMultiLevelValues];
sl@0
   650
	TInt i;
sl@0
   651
	for (i = 0; i < KTestMultiLevelValues; i++)
sl@0
   652
		{
sl@0
   653
		if (levelowner == KTestResourceNotInUse)
sl@0
   654
			{
sl@0
   655
			// If resource is not in use, we can use the entire state range
sl@0
   656
			tstval[i] = res.iMinLevel + i * (res.iMaxLevel - res.iMinLevel) / (KTestMultiLevelValues - 1);
sl@0
   657
			}
sl@0
   658
		else
sl@0
   659
			{
sl@0
   660
			// Or else we are limited to the Current State-MaxLevel range
sl@0
   661
			tstval[i] = state + i * (res.iMaxLevel - state) / (KTestMultiLevelValues - 1);
sl@0
   662
			}
sl@0
   663
		}
sl@0
   664
	test_Compare(tstval[0], !=, tstval[KTestMultiLevelValues - 1]);
sl@0
   665
	// Test starts here
sl@0
   666
	r = iTac1.Open();
sl@0
   667
	test_KErrNone(r);
sl@0
   668
	r = iTac1.RegisterClient(KTestTac1);
sl@0
   669
	test_KErrNone(r);
sl@0
   670
	//
sl@0
   671
	for (i = 0; i < KTestMultiLevelValues; i++)
sl@0
   672
		{
sl@0
   673
		r = iTac1.ChangeResourceState(res.iResourceId, tstval[i]);
sl@0
   674
		test_KErrNone(r);
sl@0
   675
		r = iToc.GetResourceState(res.iResourceId, state);
sl@0
   676
		test_KErrNone(r);
sl@0
   677
		// Resource state should be equal to the test value
sl@0
   678
		// or to the first valid value that satisfies the request
sl@0
   679
		if (res.iSense == TResInfo::EPositive)
sl@0
   680
			{
sl@0
   681
			test_Compare(state, >=, tstval[i]);
sl@0
   682
			}
sl@0
   683
		else
sl@0
   684
			{
sl@0
   685
			test_Compare(state, <=, tstval[i]);
sl@0
   686
			}
sl@0
   687
		test.Printf(_L("."));
sl@0
   688
		}
sl@0
   689
	//
sl@0
   690
	r = iTac1.DeRegisterClient();
sl@0
   691
	test_KErrNone(r);
sl@0
   692
	iTac1.Close();
sl@0
   693
	test.Printf(_L("\n"));
sl@0
   694
	}
sl@0
   695
sl@0
   696
/* ----------------------------------------------------------------------------
sl@0
   697
@SYMTestCaseID		PBASE-PRMACCTST-LATENCY-0564
sl@0
   698
@SYMTestCaseDesc	Ensure instantaneous resource change state instantaneously
sl@0
   699
@SYMREQ				REQ7751
sl@0
   700
@SYMPREQ			PREQ1398
sl@0
   701
@SYMTestPriority	High
sl@0
   702
@SYMTestActions
sl@0
   703
Pre-condition:
sl@0
   704
	If in use, resource is not Single-User
sl@0
   705
	If in use, resource state is not equal to max level
sl@0
   706
	If in use, resource is not Custom Sense
sl@0
   707
For each Multi-Level resource:
sl@0
   708
	1.	Register TAC1
sl@0
   709
	2.	TAC1 changes resource state to max value (async)
sl@0
   710
	3.	Immediately afterwards, TAC1 gets resource state (sync)
sl@0
   711
	4.	Wait for callback function
sl@0
   712
	5.	TAC1 changes resource state to min value (async)
sl@0
   713
	6.	Immediately afterwards, TAC1 gets resource state (sync)
sl@0
   714
	7.	Wait for callback function
sl@0
   715
	8.	De-register TAC1
sl@0
   716
@SYMTestExpectedResults
sl@0
   717
	1.	Client registered
sl@0
   718
	2.	No error reported.
sl@0
   719
	3.	If resource is Instantaneous Set, then the resource state is equal to
sl@0
   720
		the new state. If Long Latency Set, then the state is either the old or
sl@0
   721
		the new state.
sl@0
   722
	4.	Callback function is called.
sl@0
   723
	5.	No error reported.
sl@0
   724
	6.	If resource is Instantaneous Set, then the resource state is equal to
sl@0
   725
		the new state. If Long Latency Set, then the state is either the old or
sl@0
   726
		the new state.
sl@0
   727
	7.	Callback function is called.
sl@0
   728
	8.	Client de-registered.
sl@0
   729
*/
sl@0
   730
sl@0
   731
void CTestPrmAccTst::TestLatency(TInt aResourceNo)
sl@0
   732
	{
sl@0
   733
	test.Printf(_L("---Latency "));
sl@0
   734
	TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
sl@0
   735
	// Test pre-conditions
sl@0
   736
	if (res.iSense == TResInfo::ECustom)
sl@0
   737
		{
sl@0
   738
		test.Printf(_L("Not tested (Custom sense resource)\n"));
sl@0
   739
		return;
sl@0
   740
		}
sl@0
   741
	TInt state;
sl@0
   742
	TInt r = iToc.GetResourceState(res.iResourceId, state);
sl@0
   743
	test_KErrNone(r);
sl@0
   744
	TInt levelowner;
sl@0
   745
	r = iToc.GetLevelOwner(res.iResourceId, levelowner);
sl@0
   746
	test_KErrNone(r);
sl@0
   747
	//
sl@0
   748
	if (levelowner != KTestResourceNotInUse)
sl@0
   749
		{
sl@0
   750
		if (state == res.iMaxLevel)
sl@0
   751
			{
sl@0
   752
			test.Printf(_L("Not tested (Resource is already at maximum level)\n"));
sl@0
   753
			return;
sl@0
   754
			}
sl@0
   755
		if (res.iUsage == TResInfo::ESingleUse)
sl@0
   756
			{
sl@0
   757
			test.Printf(_L("Not tested (Single-User resource already in use)\n"));
sl@0
   758
			return;
sl@0
   759
			}
sl@0
   760
		}
sl@0
   761
	// Define the two test values
sl@0
   762
	TInt tstval1;
sl@0
   763
	TInt tstval2;
sl@0
   764
	if (levelowner != KTestResourceNotInUse)
sl@0
   765
		{
sl@0
   766
		// Resource in use
sl@0
   767
		tstval1 = res.iMaxLevel;
sl@0
   768
		tstval2 = state;
sl@0
   769
		}
sl@0
   770
	else
sl@0
   771
		{
sl@0
   772
		tstval1 = res.iMaxLevel;
sl@0
   773
		tstval2 = res.iMinLevel;
sl@0
   774
		}
sl@0
   775
	// Test starts here
sl@0
   776
	r = iTac1.Open();
sl@0
   777
	test_KErrNone(r);
sl@0
   778
	r = iTac1.RegisterClient(KTestTac1);
sl@0
   779
	test_KErrNone(r);
sl@0
   780
	//
sl@0
   781
	TTestResourceStateBuf buf;
sl@0
   782
	buf().iResourceId = res.iResourceId;
sl@0
   783
	buf().iNewState = tstval1;
sl@0
   784
	TRequestStatus rs;
sl@0
   785
	TInt tmpstate;
sl@0
   786
	iTac1.ChangeResourceStateAndGetState(rs, buf, tmpstate);
sl@0
   787
	User::WaitForRequest(rs);
sl@0
   788
	test_KErrNone(rs.Int());
sl@0
   789
	if (res.iLatencySet == TResInfo::EInstantaneous)
sl@0
   790
		{
sl@0
   791
		test_Equal(tstval1, tmpstate); // Temp state is equal to the new state
sl@0
   792
		}
sl@0
   793
	else if (tmpstate != state) // Temp state is not necessarily equal to the new state
sl@0
   794
		{
sl@0
   795
		test_Equal(tstval1, tmpstate);
sl@0
   796
		}
sl@0
   797
	TInt newstate;
sl@0
   798
	r = iToc.GetResourceState(res.iResourceId, newstate);
sl@0
   799
	test_KErrNone(r);
sl@0
   800
	test_Equal(tstval1, newstate);
sl@0
   801
	//
sl@0
   802
	buf().iNewState = tstval2;
sl@0
   803
	iTac1.ChangeResourceStateAndGetState(rs, buf, tmpstate);
sl@0
   804
	User::WaitForRequest(rs);
sl@0
   805
	test_KErrNone(rs.Int());
sl@0
   806
	if (res.iLatencySet == TResInfo::EInstantaneous)
sl@0
   807
		{
sl@0
   808
		test_Equal(tstval2, tmpstate); // Temp state is equal to the new state
sl@0
   809
		}
sl@0
   810
	else if (tmpstate != tstval1) // Temp state is not necessarily equal to the new state
sl@0
   811
		{
sl@0
   812
		test_Equal(tstval2, tmpstate);
sl@0
   813
		}
sl@0
   814
	r = iToc.GetResourceState(res.iResourceId, newstate);
sl@0
   815
	test_KErrNone(r);
sl@0
   816
	test_Equal(tstval2, newstate);
sl@0
   817
	//
sl@0
   818
	r = iTac1.DeRegisterClient();
sl@0
   819
	test_KErrNone(r);
sl@0
   820
	iTac1.Close();
sl@0
   821
	test.Printf(_L("\n"));
sl@0
   822
	}
sl@0
   823
sl@0
   824
/* ----------------------------------------------------------------------------
sl@0
   825
@SYMTestCaseID		PBASE-PRMACCTST-SENSE-0565
sl@0
   826
@SYMTestCaseDesc	Ensure Negative and Positive Sense resources behave as
sl@0
   827
					expected
sl@0
   828
@SYMREQ				REQ7751
sl@0
   829
@SYMPREQ			PREQ1398
sl@0
   830
@SYMTestPriority	High
sl@0
   831
@SYMTestActions
sl@0
   832
Pre-condition:
sl@0
   833
	Resource is Shared
sl@0
   834
	If in use, resource state is not equal to max level
sl@0
   835
For each Positive or Negative Sense resource:
sl@0
   836
	1.	Register TOC, TAC1, TAC2 and TAC3
sl@0
   837
	2.	Define three distincts test values, s1, s2 and s3, that correspond to
sl@0
   838
		actual resource states in the PSL. s1 and s3 are at opposite ends of
sl@0
   839
		the range of states the resource can be set to. s2 is an intermediate
sl@0
   840
		state. It might not always be possible to find a distinct value for s2
sl@0
   841
		(if the resource is binary or if its current use is limiting the number
sl@0
   842
		of states the resource can be set to). In this case, s2 = s1.
sl@0
   843
	3.	TAC1 sets resource state to s1
sl@0
   844
	4.	TAC2 sets resource state to s2
sl@0
   845
	5.	TAC3 sets resource state to s3
sl@0
   846
	6.	De-register TAC2
sl@0
   847
	7.	De-register TAC3
sl@0
   848
	8.	De-register TAC1 and register TAC1, TAC2 and TAC3 again.
sl@0
   849
	9.	TAC1 sets resource state to s1
sl@0
   850
	10.	TAC3 sets resource state to s3
sl@0
   851
	11.	TAC2 sets resource state to s2
sl@0
   852
	12.	De-register TAC3.
sl@0
   853
	13.	TAC3 sets resource state to s3
sl@0
   854
	14.	De-register TOC, TAC1, TAC2 and TAC3
sl@0
   855
@SYMTestExpectedResults
sl@0
   856
	1.	Clients registered
sl@0
   857
	2.	s1 <= s2 < s3
sl@0
   858
	3.	Resource state set to s1
sl@0
   859
	4.	Resource state set to s2
sl@0
   860
	5.	Resource state set to s3
sl@0
   861
	6.	Resource state remains unchanged (TAC3 owns level)
sl@0
   862
	7.	Resource state returns to s1 (TAC1 now owns level)
sl@0
   863
	8.	Clients registered
sl@0
   864
	9.	Resource state set to s1
sl@0
   865
	10.	Resource state set to s3
sl@0
   866
	11.	Resource state remains unchanged (TAC3 owns level)
sl@0
   867
	12.	Resource state changes to s2 (TAC2 now owns level)
sl@0
   868
	13.	Resource state set to s3
sl@0
   869
	14. Clients de-registered
sl@0
   870
*/
sl@0
   871
sl@0
   872
void CTestPrmAccTst::TestSense(TInt aResourceNo)
sl@0
   873
	{
sl@0
   874
	test.Printf(_L("---Sense "));
sl@0
   875
	TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
sl@0
   876
	// Test pre-conditions
sl@0
   877
	if (res.iUsage != TResInfo::EShared)
sl@0
   878
		{
sl@0
   879
		test.Printf(_L("Not tested: Resource is Single-User\n"));
sl@0
   880
		return;
sl@0
   881
		}
sl@0
   882
	//
sl@0
   883
	TInt state;
sl@0
   884
	TInt r = iToc.GetResourceState(res.iResourceId, state);
sl@0
   885
	test_KErrNone(r);
sl@0
   886
	TInt levelowner;
sl@0
   887
	r = iToc.GetLevelOwner(res.iResourceId, levelowner);
sl@0
   888
	test_KErrNone(r);
sl@0
   889
	//
sl@0
   890
	if (levelowner != KTestResourceNotInUse && state == res.iMaxLevel)
sl@0
   891
		{
sl@0
   892
		test.Printf(_L("Not tested  (Resource is already at maximum level)\n"));
sl@0
   893
		return;
sl@0
   894
		}
sl@0
   895
	// Define three test values
sl@0
   896
	r = iTac1.Open();
sl@0
   897
	test_KErrNone(r);
sl@0
   898
	r = iTac1.RegisterClient(KTestTac1);
sl@0
   899
	test_KErrNone(r);
sl@0
   900
	TInt tstval1;
sl@0
   901
	TInt tstval2;
sl@0
   902
	TInt tstval3;
sl@0
   903
	if (levelowner == KTestResourceNotInUse)
sl@0
   904
		{
sl@0
   905
		tstval1 = res.iMinLevel;
sl@0
   906
		}
sl@0
   907
	else
sl@0
   908
		{
sl@0
   909
		tstval1 = state;
sl@0
   910
		}
sl@0
   911
	tstval3 = res.iMaxLevel;
sl@0
   912
	// Attempt to find a distinct intermediate value by dichotomy
sl@0
   913
	tstval2 = tstval3;
sl@0
   914
	while ((tstval2 - tstval1 < -1) || (tstval2 - tstval1 > 1))
sl@0
   915
		{
sl@0
   916
		tstval2 -= (tstval2 - tstval1 + (res.iSense == TResInfo::EPositive ? 1 : 0)) / 2;
sl@0
   917
		r = iTac1.ChangeResourceState(res.iResourceId, tstval2);
sl@0
   918
		test_KErrNone(r);
sl@0
   919
		r = iTac1.GetResourceState(res.iResourceId, state);
sl@0
   920
		test_KErrNone(r);
sl@0
   921
		}
sl@0
   922
	if (state == tstval1 && res.iType == TResInfo::EMultiLevel)
sl@0
   923
		{
sl@0
   924
		test.Printf(_L("(Could not find three distincts test values)"));
sl@0
   925
		}
sl@0
   926
	tstval2 = state;
sl@0
   927
	r = iTac1.DeRegisterClient();
sl@0
   928
	test_KErrNone(r);
sl@0
   929
	iTac1.Close();
sl@0
   930
	
sl@0
   931
	// Test starts here
sl@0
   932
	r = iTac1.Open();
sl@0
   933
	test_KErrNone(r);
sl@0
   934
	r = iTac2.Open();
sl@0
   935
	test_KErrNone(r);
sl@0
   936
	r = iTac3.Open();
sl@0
   937
	test_KErrNone(r);
sl@0
   938
	r = iTac1.RegisterClient(KTestTac1);
sl@0
   939
	test_KErrNone(r);
sl@0
   940
	r = iTac2.RegisterClient(KTestTac2);
sl@0
   941
	test_KErrNone(r);
sl@0
   942
	r = iTac3.RegisterClient(KTestTac3);
sl@0
   943
	test_KErrNone(r);
sl@0
   944
sl@0
   945
	// Set resource state to the first test value
sl@0
   946
	r = iTac1.ChangeResourceState(res.iResourceId, tstval1);
sl@0
   947
	test_KErrNone(r);
sl@0
   948
	r = iToc.GetResourceState(res.iResourceId, state);
sl@0
   949
	test_KErrNone(r);
sl@0
   950
	test_Equal(tstval1, state);
sl@0
   951
sl@0
   952
	// Set resource state to middle test value
sl@0
   953
	r = iTac2.ChangeResourceState(res.iResourceId, tstval2);
sl@0
   954
	test_KErrNone(r);
sl@0
   955
	r = iToc.GetResourceState(res.iResourceId, state);
sl@0
   956
	test_KErrNone(r);
sl@0
   957
	test_Equal(tstval2, state);
sl@0
   958
sl@0
   959
	// Set resource to the third test value
sl@0
   960
	r = iTac3.ChangeResourceState(res.iResourceId, tstval3);
sl@0
   961
	test_KErrNone(r);
sl@0
   962
	r = iToc.GetResourceState(res.iResourceId, state);
sl@0
   963
	test_KErrNone(r);
sl@0
   964
	test_Equal(tstval3, state);
sl@0
   965
sl@0
   966
	// De-register second client
sl@0
   967
	r = iTac2.DeRegisterClient();
sl@0
   968
	test_KErrNone(r);
sl@0
   969
	r = iToc.GetResourceState(res.iResourceId, state);
sl@0
   970
	test_KErrNone(r);
sl@0
   971
	test_Equal(tstval3, state); // state remains  unchanged
sl@0
   972
sl@0
   973
	// De-register third client
sl@0
   974
	r = iTac3.DeRegisterClient();
sl@0
   975
	test_KErrNone(r);
sl@0
   976
	r = iToc.GetResourceState(res.iResourceId, state);
sl@0
   977
	test_KErrNone(r);
sl@0
   978
	test_Equal(tstval1, state); // state changes
sl@0
   979
sl@0
   980
	// De-register and register all clients again
sl@0
   981
	r = iTac1.DeRegisterClient();
sl@0
   982
	test_KErrNone(r);
sl@0
   983
	r = iTac1.RegisterClient(KTestTac1);
sl@0
   984
	test_KErrNone(r);
sl@0
   985
	r = iTac2.RegisterClient(KTestTac2);
sl@0
   986
	test_KErrNone(r);
sl@0
   987
	r = iTac3.RegisterClient(KTestTac3);
sl@0
   988
	test_KErrNone(r);
sl@0
   989
sl@0
   990
	// Set resource state to the first test value
sl@0
   991
	r = iTac1.ChangeResourceState(res.iResourceId, tstval1);
sl@0
   992
	test_KErrNone(r);
sl@0
   993
	r = iToc.GetResourceState(res.iResourceId, state);
sl@0
   994
	test_KErrNone(r);
sl@0
   995
	test_Equal(tstval1, state);
sl@0
   996
sl@0
   997
	// Set resource to the third test value
sl@0
   998
	r = iTac3.ChangeResourceState(res.iResourceId, tstval3);
sl@0
   999
	test_KErrNone(r);
sl@0
  1000
	r = iToc.GetResourceState(res.iResourceId, state);
sl@0
  1001
	test_KErrNone(r);
sl@0
  1002
	test_Equal(tstval3, state);
sl@0
  1003
sl@0
  1004
	// Set resource state to middle test value
sl@0
  1005
	r = iTac2.ChangeResourceState(res.iResourceId, tstval2);
sl@0
  1006
	test_KErrNone(r);
sl@0
  1007
	r = iToc.GetResourceState(res.iResourceId, state);
sl@0
  1008
	test_KErrNone(r);
sl@0
  1009
	test_Equal(tstval3, state); // state does not change
sl@0
  1010
sl@0
  1011
	// De-register client holding resource
sl@0
  1012
	r = iTac3.DeRegisterClient();
sl@0
  1013
	test_KErrNone(r);
sl@0
  1014
	r = iToc.GetResourceState(res.iResourceId, state);
sl@0
  1015
	test_KErrNone(r);
sl@0
  1016
	test_Equal(tstval2, state);
sl@0
  1017
sl@0
  1018
	// Register client again
sl@0
  1019
	r = iTac3.RegisterClient(KTestTac3);
sl@0
  1020
	test_KErrNone(r);
sl@0
  1021
	r = iTac3.ChangeResourceState(res.iResourceId, tstval3);
sl@0
  1022
	test_KErrNone(r);
sl@0
  1023
	r = iToc.GetResourceState(res.iResourceId, state);
sl@0
  1024
	test_KErrNone(r);
sl@0
  1025
	test_Equal(tstval3, state);
sl@0
  1026
sl@0
  1027
	//
sl@0
  1028
	r = iTac3.DeRegisterClient();
sl@0
  1029
	test_KErrNone(r);
sl@0
  1030
	r = iTac2.DeRegisterClient();
sl@0
  1031
	test_KErrNone(r);
sl@0
  1032
	r = iTac1.DeRegisterClient();
sl@0
  1033
	test_KErrNone(r);
sl@0
  1034
	iTac3.Close();
sl@0
  1035
	iTac2.Close();
sl@0
  1036
	iTac1.Close();
sl@0
  1037
	test.Printf(_L("\n"));
sl@0
  1038
	}
sl@0
  1039
sl@0
  1040
/* ----------------------------------------------------------------------------
sl@0
  1041
@SYMTestCaseID		PBASE-PRMACCTST-CUSTOMSENSE-0566
sl@0
  1042
@SYMTestCaseDesc	Ensure the Custom Sense function is implemented
sl@0
  1043
@SYMREQ				REQ7751
sl@0
  1044
@SYMPREQ			PREQ1398
sl@0
  1045
@SYMTestPriority	High
sl@0
  1046
@SYMTestActions
sl@0
  1047
For each Custom Sense resource:
sl@0
  1048
	1.	Register TAC1
sl@0
  1049
	2.	Attempt to set the state of the resource to its current state. The
sl@0
  1050
		purpose of this test action is to ensure that the PSL's custom function
sl@0
  1051
		for this resource has been implemented. If the custom function is not
sl@0
  1052
		present, the PIL will generate a panic.
sl@0
  1053
	3.	De-register TAC1
sl@0
  1054
@SYMTestExpectedResults
sl@0
  1055
	1.	Client registered
sl@0
  1056
	2.	The resource change request does not cause a panic.
sl@0
  1057
	3.	Client de-registered
sl@0
  1058
*/
sl@0
  1059
sl@0
  1060
void CTestPrmAccTst::TestCustomSense(TInt aResourceNo)
sl@0
  1061
	{
sl@0
  1062
	test.Printf(_L("---Custom Sense"));
sl@0
  1063
	TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
sl@0
  1064
	TInt r = iTac1.Open();
sl@0
  1065
	test_KErrNone(r);
sl@0
  1066
	r = iTac1.RegisterClient(KTestTac1);
sl@0
  1067
	test_KErrNone(r);
sl@0
  1068
	//
sl@0
  1069
	TInt state;
sl@0
  1070
	r = iTac1.GetResourceState(res.iResourceId, state);
sl@0
  1071
	test_KErrNone(r);
sl@0
  1072
	r = iTac1.ChangeResourceState(res.iResourceId, state);
sl@0
  1073
	test_KErrNone(r);
sl@0
  1074
	//
sl@0
  1075
	r = iTac1.DeRegisterClient();
sl@0
  1076
	test_KErrNone(r);
sl@0
  1077
	iTac1.Close();
sl@0
  1078
	test.Printf(_L("\n"));
sl@0
  1079
	}
sl@0
  1080
sl@0
  1081
/* ----------------------------------------------------------------------------
sl@0
  1082
@SYMTestCaseID		PBASE-PRMACCTST-POWERRESUMPTION-0567
sl@0
  1083
@SYMTestCaseDesc	Ensure resources go back to their default state when not in
sl@0
  1084
					use
sl@0
  1085
@SYMREQ				REQ7751
sl@0
  1086
@SYMPREQ			PREQ1398
sl@0
  1087
@SYMTestPriority	High
sl@0
  1088
@SYMTestActions
sl@0
  1089
Pre-condition:
sl@0
  1090
	Resource not in use
sl@0
  1091
	Not a Custom Sense resource
sl@0
  1092
For each resource:
sl@0
  1093
	1.	Register TAC1
sl@0
  1094
	2.	Set resource state to something that is not the default level
sl@0
  1095
	3.	De-register TAC1
sl@0
  1096
	4.	Register TOC
sl@0
  1097
	5.	Get resource state
sl@0
  1098
	6.	De-register TOC
sl@0
  1099
@SYMTestExpectedResults
sl@0
  1100
	1.	Client registered
sl@0
  1101
	2.	Resource state changed
sl@0
  1102
	3.	Client de-registered
sl@0
  1103
	4.	Client registered
sl@0
  1104
	5.	Resource state is at the default level
sl@0
  1105
	6.	Client de-registered
sl@0
  1106
*/
sl@0
  1107
sl@0
  1108
void CTestPrmAccTst::TestDefaultPowerResumption()
sl@0
  1109
	{
sl@0
  1110
	TInt i;
sl@0
  1111
	for (i = 0; i < (TInt) iNoResources; i++)
sl@0
  1112
		{
sl@0
  1113
		TResInfo& res = *((TResInfo*) iResources.Ptr() + i);
sl@0
  1114
		test.Printf(_L("Resource %08x "), res.iResourceId);
sl@0
  1115
		TInt levelowner;
sl@0
  1116
		TInt r = iToc.GetLevelOwner(res.iResourceId, levelowner);
sl@0
  1117
		test_KErrNone(r);
sl@0
  1118
sl@0
  1119
		// Test pre-condition: resource not in use
sl@0
  1120
		if (levelowner != KTestResourceNotInUse)
sl@0
  1121
			{
sl@0
  1122
			test.Printf(_L("Not tested (already in use)\n"));
sl@0
  1123
			continue;
sl@0
  1124
			}
sl@0
  1125
		if (res.iSense == TResInfo::ECustom)
sl@0
  1126
			{
sl@0
  1127
			test.Printf(_L("Not tested (custom sense)\n"));
sl@0
  1128
			continue;
sl@0
  1129
			}
sl@0
  1130
		
sl@0
  1131
		// Define a test value
sl@0
  1132
		TInt tstval;
sl@0
  1133
		if (res.iDefaultLevel == res.iMaxLevel)
sl@0
  1134
			{
sl@0
  1135
			tstval = res.iMinLevel;
sl@0
  1136
			}
sl@0
  1137
		else
sl@0
  1138
			{
sl@0
  1139
			tstval = res.iMaxLevel;
sl@0
  1140
			}
sl@0
  1141
		
sl@0
  1142
		// Test starts here
sl@0
  1143
		r = iTac1.Open();
sl@0
  1144
		test_KErrNone(r);
sl@0
  1145
		r = iTac1.RegisterClient(KTestTac1);
sl@0
  1146
		test_KErrNone(r);
sl@0
  1147
		// Change resource state
sl@0
  1148
		TInt state;
sl@0
  1149
		r = iToc.GetResourceState(res.iResourceId, state);
sl@0
  1150
		test_KErrNone(r);
sl@0
  1151
		test_Equal(res.iDefaultLevel, state);
sl@0
  1152
		r = iTac1.ChangeResourceState(res.iResourceId, tstval);
sl@0
  1153
		test_KErrNone(r);
sl@0
  1154
		r = iToc.GetResourceState(res.iResourceId, state);
sl@0
  1155
		test_KErrNone(r);
sl@0
  1156
		test_Equal(tstval, state);
sl@0
  1157
		// De-register active client so resource is freed
sl@0
  1158
		r = iTac1.DeRegisterClient();
sl@0
  1159
		test_KErrNone(r);
sl@0
  1160
		iTac1.Close();
sl@0
  1161
		// Read both cached and actual values
sl@0
  1162
		TInt cached;
sl@0
  1163
		r = iToc.GetResourceStateCached(res.iResourceId, cached);
sl@0
  1164
		test_KErrNone(r);
sl@0
  1165
		r = iToc.GetResourceState(res.iResourceId, state);
sl@0
  1166
		test_KErrNone(r);
sl@0
  1167
		test_Equal(cached, state);
sl@0
  1168
		test_Equal(res.iDefaultLevel, state);
sl@0
  1169
		test.Printf(_L("\n"));
sl@0
  1170
		}
sl@0
  1171
	//
sl@0
  1172
	test.Printf(_L("\n"));
sl@0
  1173
	}
sl@0
  1174
sl@0
  1175
/* ----------------------------------------------------------------------------
sl@0
  1176
@SYMTestCaseID		PBASE-PRMACCTST-DEPENDENCIESDECLARED-0568
sl@0
  1177
@SYMTestCaseDesc	Ensure all actual resources dependencies have been declared
sl@0
  1178
@SYMREQ				REQ7751
sl@0
  1179
@SYMPREQ			PREQ1398
sl@0
  1180
@SYMTestPriority	High
sl@0
  1181
@SYMTestActions
sl@0
  1182
Pre-condition:
sl@0
  1183
	Resource not in use
sl@0
  1184
	Not a Custom Sense resource
sl@0
  1185
For each resource:
sl@0
  1186
	1.	Register TOC & TAC1
sl@0
  1187
	2.	Get state of all resources
sl@0
  1188
	3.	Set the state of the resource under test state to something that is not
sl@0
  1189
		the default level
sl@0
  1190
	4.	Get state of all resource
sl@0
  1191
	5.	De-register TAC1 & TOC
sl@0
  1192
@SYMTestExpectedResults
sl@0
  1193
	1.	Clients registered
sl@0
  1194
	2.	None
sl@0
  1195
	3.	Resource state changed
sl@0
  1196
	4.	Only resources with a direct or indirect dependency on the resource
sl@0
  1197
		under test have changed.
sl@0
  1198
	5.	Client de-registered
sl@0
  1199
*/
sl@0
  1200
sl@0
  1201
TBool CTestPrmAccTst::ResourceInterdependency(TInt aResourceIdOrig, TInt aCurrentResourceId, TInt aResourceIdTarget)
sl@0
  1202
	{
sl@0
  1203
	// Get Reference on current resource node
sl@0
  1204
	TBool r = EFalse;
sl@0
  1205
	if (aCurrentResourceId & KTestIdHasDependencies)
sl@0
  1206
		{
sl@0
  1207
		// Get dependencies of current resources
sl@0
  1208
		RBuf8 deplist;
sl@0
  1209
		deplist.Create(sizeof(SResDepInfo) * KTestMaxDependencies);
sl@0
  1210
		r = iToc.GetResourceDependencies(aCurrentResourceId, deplist);
sl@0
  1211
		if (r)
sl@0
  1212
			{
sl@0
  1213
			test.Printf(_L("ERROR: aCurrentResourceId==%08x"), aCurrentResourceId);
sl@0
  1214
			test_KErrNone(r);
sl@0
  1215
			}
sl@0
  1216
		TInt i;
sl@0
  1217
		SResDepInfo *ptr = (SResDepInfo*)deplist.Ptr();
sl@0
  1218
		for (i = 0; i < (TInt) (deplist.Length() / sizeof(SResDepInfo)); i++, ptr++)
sl@0
  1219
			{
sl@0
  1220
			TInt depid = ptr->iResourceId;
sl@0
  1221
			if (depid == aResourceIdTarget)
sl@0
  1222
				{
sl@0
  1223
				// We've got a match
sl@0
  1224
				r = ETrue;
sl@0
  1225
				}
sl@0
  1226
			else if (depid == aResourceIdOrig)
sl@0
  1227
				{
sl@0
  1228
				// No going back to parent node
sl@0
  1229
				continue;
sl@0
  1230
				}
sl@0
  1231
			else
sl@0
  1232
				{
sl@0
  1233
				// Recurse down the tree
sl@0
  1234
				r = ResourceInterdependency(aCurrentResourceId, depid, aResourceIdTarget);
sl@0
  1235
				}
sl@0
  1236
			if (r)
sl@0
  1237
				{
sl@0
  1238
				break;
sl@0
  1239
				}
sl@0
  1240
			}
sl@0
  1241
		deplist.Close();
sl@0
  1242
		}
sl@0
  1243
	return r;
sl@0
  1244
	}
sl@0
  1245
sl@0
  1246
void CTestPrmAccTst::TestDependenciesAreDeclared(TInt aResourceNo)
sl@0
  1247
	{
sl@0
  1248
	test.Printf(_L("---Test all dependencies are declared\n"));
sl@0
  1249
	TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
sl@0
  1250
	//
sl@0
  1251
	TInt levelowner;
sl@0
  1252
	TInt r = iToc.GetLevelOwner(res.iResourceId, levelowner);
sl@0
  1253
	test_KErrNone(r);
sl@0
  1254
	// Test pre-condition: resource not in use
sl@0
  1255
	if (levelowner != KTestResourceNotInUse)
sl@0
  1256
		{
sl@0
  1257
		test.Printf(_L("Not tested (already in use)\n"));
sl@0
  1258
		return;
sl@0
  1259
		}
sl@0
  1260
	if (res.iSense == TResInfo::ECustom)
sl@0
  1261
		{
sl@0
  1262
		test.Printf(_L("Not tested (custom sense)\n"));
sl@0
  1263
		return;
sl@0
  1264
		}
sl@0
  1265
	// Define a test value
sl@0
  1266
	TInt tstval;
sl@0
  1267
	if (res.iDefaultLevel == res.iMaxLevel)
sl@0
  1268
		{
sl@0
  1269
		tstval = res.iMinLevel;
sl@0
  1270
		}
sl@0
  1271
	else
sl@0
  1272
		{
sl@0
  1273
		tstval = res.iMaxLevel;
sl@0
  1274
		}
sl@0
  1275
sl@0
  1276
	// Test starts here
sl@0
  1277
	// Save current state of all resources;
sl@0
  1278
	RArray<TInt> oldstate;
sl@0
  1279
	TInt i;
sl@0
  1280
	TInt state;
sl@0
  1281
	for (i = 0; i < (TInt) iNoResources; i++)
sl@0
  1282
		{
sl@0
  1283
		TResInfo& tmpres = *((TResInfo*) iResources.Ptr() + i);
sl@0
  1284
		r = iToc.GetResourceState(tmpres.iResourceId, state);
sl@0
  1285
		test_KErrNone(r);
sl@0
  1286
		r = oldstate.Append(state);
sl@0
  1287
		test_KErrNone(r);
sl@0
  1288
		}
sl@0
  1289
	//
sl@0
  1290
	r = iTac1.Open();
sl@0
  1291
	test_KErrNone(r);
sl@0
  1292
	r = iTac1.RegisterClient(KTestTac1);
sl@0
  1293
	test_KErrNone(r);
sl@0
  1294
sl@0
  1295
	// Change resource state
sl@0
  1296
	r = iToc.GetResourceState(res.iResourceId, state);
sl@0
  1297
	test_KErrNone(r);
sl@0
  1298
	test_Equal(res.iDefaultLevel, state);
sl@0
  1299
	r = iTac1.ChangeResourceState(res.iResourceId, tstval);
sl@0
  1300
	test_KErrNone(r);
sl@0
  1301
	r = iToc.GetResourceState(res.iResourceId, state);
sl@0
  1302
	test_KErrNone(r);
sl@0
  1303
	test_Equal(tstval, state);
sl@0
  1304
sl@0
  1305
	// Now we check that resources with no dependency on resource under test
sl@0
  1306
	// have not changed
sl@0
  1307
	for (i = 0; i < (TInt) iNoResources; i++)
sl@0
  1308
		{
sl@0
  1309
		test.Printf(_L("."));
sl@0
  1310
		if (i == aResourceNo)
sl@0
  1311
			{
sl@0
  1312
			continue;
sl@0
  1313
			}
sl@0
  1314
		TResInfo& tmpres = *((TResInfo*) iResources.Ptr() + i);
sl@0
  1315
		r = iToc.GetResourceState(tmpres.iResourceId, state);
sl@0
  1316
		test_KErrNone(r);
sl@0
  1317
		if (!ResourceInterdependency(0, res.iResourceId, tmpres.iResourceId) &&
sl@0
  1318
			(state != oldstate[i]))
sl@0
  1319
			{
sl@0
  1320
			test.Printf(_L("Resource %08x has changed!\n"), tmpres.iResourceId);
sl@0
  1321
			test_Equal(state, oldstate[i]);
sl@0
  1322
			}	
sl@0
  1323
		}
sl@0
  1324
	test.Printf(_L("\n"));
sl@0
  1325
sl@0
  1326
	// De-register active client
sl@0
  1327
	r = iTac1.DeRegisterClient();
sl@0
  1328
	test_KErrNone(r);
sl@0
  1329
	iTac1.Close();
sl@0
  1330
	//
sl@0
  1331
	oldstate.Close();
sl@0
  1332
	}
sl@0
  1333
sl@0
  1334
TInt CTestPrmAccTst::DoTestPreamble()
sl@0
  1335
	{
sl@0
  1336
	test.Title();
sl@0
  1337
	test.Start(_L("Preamble"));
sl@0
  1338
sl@0
  1339
	// Load Device Driver
sl@0
  1340
	TInt r;
sl@0
  1341
#ifdef RESOURCE_MANAGER_SIMULATED_PSL
sl@0
  1342
	test.Printf(_L("Load Simulated PSL PDD\n"));
sl@0
  1343
	r = User::LoadPhysicalDevice(_L("RESOURCECONTROLLEREXTENDED.PDD"));
sl@0
  1344
	if (r == KErrNotFound)
sl@0
  1345
		{
sl@0
  1346
		test.Printf(_L("RESOURCECONTROLLEREXTENDED.PDD not found\nTest skipped\n"));
sl@0
  1347
		return r;
sl@0
  1348
		}
sl@0
  1349
	if (r)
sl@0
  1350
		{
sl@0
  1351
		test_Equal(KErrAlreadyExists, r);
sl@0
  1352
		test.Printf(_L("Already loaded\n"));
sl@0
  1353
		}
sl@0
  1354
	test.Printf(_L("Load test LDD\n"));
sl@0
  1355
	r = User::LoadLogicalDevice(_L("D_PRMACCTSTSIM.LDD"));
sl@0
  1356
	if (r)
sl@0
  1357
		{
sl@0
  1358
		test_Equal(KErrAlreadyExists, r);
sl@0
  1359
		test.Printf(_L("Already loaded\n"));
sl@0
  1360
		}
sl@0
  1361
#else
sl@0
  1362
	test.Printf(_L("Load test LDD\n"));
sl@0
  1363
	r = User::LoadLogicalDevice(_L("D_PRMACCTST.LDD"));
sl@0
  1364
	if (r)
sl@0
  1365
		{
sl@0
  1366
		test_Equal(KErrAlreadyExists, r);
sl@0
  1367
		test.Printf(_L("Already loaded\n"));
sl@0
  1368
		}
sl@0
  1369
#endif // RESOURCE_MANAGER_SIMULATED_PSL
sl@0
  1370
sl@0
  1371
	// Check if Device Driver was loaded as a Kernel Extension
sl@0
  1372
	iKextc.Open();
sl@0
  1373
	TUint clientId;
sl@0
  1374
	r = iKextc.GetKernelExtClientId(clientId);
sl@0
  1375
	test_KErrNone(r);
sl@0
  1376
	if (!clientId)
sl@0
  1377
		{
sl@0
  1378
		test.Printf(_L("No Kernel extension PRM client\n"));
sl@0
  1379
		iKextc.Close();
sl@0
  1380
		}
sl@0
  1381
	else
sl@0
  1382
		{
sl@0
  1383
		// De-register client so Single User resources can be tested
sl@0
  1384
		r = iKextc.OpenClient(clientId);
sl@0
  1385
		test_KErrNone(r);
sl@0
  1386
		r = iKextc.DeRegisterClient();
sl@0
  1387
		test_KErrNone(r);
sl@0
  1388
		iKextc.Close();
sl@0
  1389
		}
sl@0
  1390
sl@0
  1391
	// Register TOC (always on - de-registered in test postamble)
sl@0
  1392
	r = iToc.Open();
sl@0
  1393
	test_KErrNone(r);
sl@0
  1394
	r = iToc.RegisterClient(KTestToc);
sl@0
  1395
	test_KErrNone(r);
sl@0
  1396
sl@0
  1397
	// Get resources info
sl@0
  1398
	r = iToc.GetTotalNumberOfResources(iNoResources);
sl@0
  1399
	test_KErrNone(r);
sl@0
  1400
	test.Printf(_L("Resources found: %d\n"), iNoResources);
sl@0
  1401
	if (iNoResources > 0)
sl@0
  1402
		{
sl@0
  1403
		r = iResources.Create(iNoResources * sizeof(TResInfo));
sl@0
  1404
		test_KErrNone(r);
sl@0
  1405
		test.Printf(_L("Retrieving information on resources\n"));
sl@0
  1406
		r = iToc.GetInfoOnResourcesInUseByClient(0, iResources);
sl@0
  1407
		test_KErrNone(r);
sl@0
  1408
		iIsPrmSupported = ETrue;
sl@0
  1409
		}
sl@0
  1410
	else
sl@0
  1411
		{
sl@0
  1412
		test.Printf(_L("No resource found.\n"));
sl@0
  1413
		}
sl@0
  1414
	return KErrNone;
sl@0
  1415
	}
sl@0
  1416
sl@0
  1417
void CTestPrmAccTst::DoTest()
sl@0
  1418
	{
sl@0
  1419
	if (!iIsPrmSupported)
sl@0
  1420
		{
sl@0
  1421
		return;
sl@0
  1422
		}
sl@0
  1423
	//
sl@0
  1424
	test.Next(_L("Enumerate Resources"));
sl@0
  1425
	TestEnumerateResources();
sl@0
  1426
	//
sl@0
  1427
	TInt i;
sl@0
  1428
	test.Next(_L("Resource Properties"));
sl@0
  1429
	for (i = 0; i < (TInt) iNoResources; i++)
sl@0
  1430
		{
sl@0
  1431
		TResInfo& res = *((TResInfo*) iResources.Ptr() + i);
sl@0
  1432
		test.Printf(_L("+++Resource %08x\n"), res.iResourceId);
sl@0
  1433
		//
sl@0
  1434
		if (res.iUsage == TResInfo::ESingleUse)
sl@0
  1435
			{
sl@0
  1436
			TestSingleUserResources(i);
sl@0
  1437
			}
sl@0
  1438
		else if (res.iUsage == TResInfo::EShared)
sl@0
  1439
			{
sl@0
  1440
			TestSharedResources(i);
sl@0
  1441
			}
sl@0
  1442
		//
sl@0
  1443
		if (res.iType == TResInfo::EBinary)
sl@0
  1444
			{
sl@0
  1445
			TestBinaryResources(i);
sl@0
  1446
			}
sl@0
  1447
		else if (res.iType == TResInfo::EMultiLevel)
sl@0
  1448
			{
sl@0
  1449
			TestMultilevelResources(i);
sl@0
  1450
			}
sl@0
  1451
		//
sl@0
  1452
		TestLatency(i);
sl@0
  1453
		//
sl@0
  1454
		if ((res.iSense == TResInfo::EPositive) || (res.iSense == TResInfo::ENegative))
sl@0
  1455
			{
sl@0
  1456
			TestSense(i);
sl@0
  1457
			}
sl@0
  1458
		else if (res.iSense == TResInfo::ECustom)
sl@0
  1459
			{
sl@0
  1460
			TestCustomSense(i);
sl@0
  1461
			}
sl@0
  1462
		}
sl@0
  1463
	//
sl@0
  1464
	test.Next(_L("Default Power Resumption"));
sl@0
  1465
	TestDefaultPowerResumption();
sl@0
  1466
	//
sl@0
  1467
	test.Next(_L("PRM Extension - Dependencies"));
sl@0
  1468
	for (i = 0; i < (TInt) iNoResources; i++)
sl@0
  1469
		{
sl@0
  1470
		TResInfo& res = *((TResInfo*) iResources.Ptr() + i);
sl@0
  1471
		if (res.iResourceId & KTestIdHasDependencies)
sl@0
  1472
			{
sl@0
  1473
			test.Printf(_L("+++Resource %08x\n"), res.iResourceId);
sl@0
  1474
			TestDependenciesAreDeclared(i);
sl@0
  1475
			}
sl@0
  1476
		}
sl@0
  1477
	}
sl@0
  1478
sl@0
  1479
void CTestPrmAccTst::DoTestPostamble()
sl@0
  1480
	{
sl@0
  1481
	test.Next(_L("Postamble"));
sl@0
  1482
	if (iToc.Handle())
sl@0
  1483
		{
sl@0
  1484
		TInt r = iToc.DeRegisterClient();
sl@0
  1485
		test_KErrNone(r);
sl@0
  1486
		iToc.Close();
sl@0
  1487
		}
sl@0
  1488
	test.End();
sl@0
  1489
	test.Close();
sl@0
  1490
	}
sl@0
  1491
sl@0
  1492
GLDEF_C TInt MainL()
sl@0
  1493
	{
sl@0
  1494
	CTestPrmAccTst* testapp;
sl@0
  1495
	testapp = new (ELeave) CTestPrmAccTst();
sl@0
  1496
	CleanupStack::PushL(testapp);
sl@0
  1497
	if (testapp->DoTestPreamble() == KErrNone)
sl@0
  1498
		{
sl@0
  1499
		testapp->DoTest();
sl@0
  1500
		}
sl@0
  1501
	testapp->DoTestPostamble();
sl@0
  1502
	CleanupStack::PopAndDestroy(testapp);
sl@0
  1503
	return KErrNone;
sl@0
  1504
	}
sl@0
  1505
sl@0
  1506
GLDEF_C TInt E32Main()
sl@0
  1507
	{
sl@0
  1508
	__UHEAP_MARK;
sl@0
  1509
	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0
  1510
	if(cleanup == NULL)
sl@0
  1511
		{
sl@0
  1512
		return KErrNoMemory;
sl@0
  1513
		}
sl@0
  1514
	TRAP_IGNORE(MainL());
sl@0
  1515
	delete cleanup;
sl@0
  1516
	__UHEAP_MARKEND;
sl@0
  1517
	return KErrNone;
sl@0
  1518
	}