os/kernelhwsrv/kerneltest/e32test/resmanus/t_resmanus.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
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
#include <e32test.h>
sl@0
    17
#include <e32def.h>
sl@0
    18
#include <e32def_private.h>
sl@0
    19
sl@0
    20
#include <d32resmanus.h>
sl@0
    21
sl@0
    22
#ifdef PRM_ENABLE_EXTENDED_VERSION
sl@0
    23
#define LDD_NAME _L("resourcecontrollerextended.ldd")
sl@0
    24
#else
sl@0
    25
#define LDD_NAME _L("resourcecontrol.ldd")
sl@0
    26
#endif
sl@0
    27
sl@0
    28
#ifdef PRM_ENABLE_EXTENDED_VERSION
sl@0
    29
#define PDD_NAME _L("resourcecontrollerextended.pdd")
sl@0
    30
#else
sl@0
    31
#define PDD_NAME _L("resourcecontroller.pdd")
sl@0
    32
#endif
sl@0
    33
sl@0
    34
//#define PIRATE_THREAD_TESTS
sl@0
    35
sl@0
    36
_LIT(testableResourceName,"SymbianSimulResource");
sl@0
    37
sl@0
    38
#ifdef RESMANUS_KERN
sl@0
    39
_LIT(testName,"t_resmanuskern");
sl@0
    40
#else
sl@0
    41
_LIT(testName,"t_resmanus");
sl@0
    42
#endif
sl@0
    43
sl@0
    44
TBuf<16> gTestName(testName);
sl@0
    45
sl@0
    46
GLDEF_D RTest gTest(testName);
sl@0
    47
GLDEF_D RBusDevResManUs gChannel;
sl@0
    48
sl@0
    49
TUint8 KNoOfGetStateRequests = 5;
sl@0
    50
TUint8 KNoOfSetStateRequests = 4;
sl@0
    51
TUint8 KNoOfNotifyRequests = 7;
sl@0
    52
#define MAX_NUM_REQUESTS 8		// Must be (at least) one greater than the largest of 
sl@0
    53
								// KNoOfGetStateRequests, KNoOfSetStateRequests, KNoOfNotifyRequests
sl@0
    54
#ifdef _DEBUG
sl@0
    55
TUint gLongLatencyResource;
sl@0
    56
TBool gHaveAsyncRes = EFalse;
sl@0
    57
TInt gAsyncResStateDelta = 0;
sl@0
    58
sl@0
    59
TUint gSharedResource;
sl@0
    60
TBool gHaveSharedRes = EFalse;
sl@0
    61
TInt gSharedResStateDelta = 0;
sl@0
    62
#else
sl@0
    63
// The UREL version of the driver will not implement the arrays and functionality required
sl@0
    64
// to determine the async and shared resources to use at runtime. The values provided here
sl@0
    65
// have been pre-determined to operate successfully with the simulated PSL.
sl@0
    66
//
sl@0
    67
TUint gLongLatencyResource = 6;
sl@0
    68
TBool gHaveAsyncRes = ETrue;
sl@0
    69
TInt gAsyncResStateDelta = -1;
sl@0
    70
sl@0
    71
TUint gSharedResource = 12;
sl@0
    72
TBool gHaveSharedRes = ETrue;
sl@0
    73
TInt gSharedResStateDelta = -1;
sl@0
    74
#endif
sl@0
    75
sl@0
    76
TBool gUseCached = EFalse;
sl@0
    77
sl@0
    78
LOCAL_C TInt OpenChannel(TDesC16& aName, RBusDevResManUs& aChannel)
sl@0
    79
	{
sl@0
    80
	TInt r = KErrNone;
sl@0
    81
	// API accepts 8-bit descriptors, only - so convert name accordingly
sl@0
    82
	TBuf8<MAX_RESOURCE_NAME_LENGTH+1>EightBitName;
sl@0
    83
	EightBitName.Copy(aName);
sl@0
    84
    r=(aChannel.Open(EightBitName));
sl@0
    85
    if (r!=KErrNone)
sl@0
    86
		gTest.Printf(_L("OpenChannel: Handle for channel %S error code =0x%x\n"),&aName,r);
sl@0
    87
	else
sl@0
    88
		gTest.Printf(_L("OpenChannel: Handle for channel %S =0x%x\n"),&aName,aChannel.Handle());
sl@0
    89
	return r;
sl@0
    90
	}
sl@0
    91
sl@0
    92
LOCAL_C TInt HelperResources()
sl@0
    93
//
sl@0
    94
// Helper method to support OpenAndRegisterChannel
sl@0
    95
// Invokes GetNoOfResources, GetAllResourcesInfo and GetResourceIdByName
sl@0
    96
//
sl@0
    97
	{
sl@0
    98
	TInt r = KErrNone;
sl@0
    99
sl@0
   100
	__KHEAP_MARK;
sl@0
   101
sl@0
   102
	// Check what resources are available
sl@0
   103
    gTest.Printf(_L("**Test GetNoOfResources\n"));
sl@0
   104
	TUint numResources=0;
sl@0
   105
	if((r=gChannel.GetNoOfResources(numResources))!=KErrNone)
sl@0
   106
		{
sl@0
   107
		gTest.Printf(_L("GetNoOfResources for test channel returned %d\n"),r);
sl@0
   108
		return r;
sl@0
   109
		}
sl@0
   110
	gTest.Printf(_L("Number of resources = %d (=0x%x)\n"),numResources,numResources);
sl@0
   111
sl@0
   112
	// Read the resource information
sl@0
   113
    gTest.Printf(_L("**Test GetAllResourcesInfo\n"));
sl@0
   114
sl@0
   115
	// To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects
sl@0
   116
	// and reference via an RSimplePointerArray
sl@0
   117
	TUint bufSize = numResources;
sl@0
   118
	RSimplePointerArray<TResourceInfoBuf> infoPtrs(bufSize);
sl@0
   119
	for(TUint i=0;i<bufSize;i++)
sl@0
   120
		{
sl@0
   121
		TResourceInfoBuf *info = new TResourceInfoBuf();
sl@0
   122
		if((r=infoPtrs.Insert(info, i))!=KErrNone)
sl@0
   123
			{
sl@0
   124
			gTest.Printf(_L("GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),i,r);
sl@0
   125
			}
sl@0
   126
		}
sl@0
   127
	TUint updateNumResources=numResources;
sl@0
   128
	if((r=gChannel.GetAllResourcesInfo(&infoPtrs,updateNumResources))!=KErrNone)
sl@0
   129
		{
sl@0
   130
		gTest.Printf(_L("GetAllResourcesInfo for channel returned %d\n"),r);
sl@0
   131
		return r;
sl@0
   132
		}
sl@0
   133
	gTest.Printf(_L("Updated number of resources = %d\n"),updateNumResources);
sl@0
   134
sl@0
   135
#ifdef _DEBUG
sl@0
   136
	// Print resource names
sl@0
   137
	{
sl@0
   138
	TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name;
sl@0
   139
	for(TUint i=0; i<updateNumResources; i++)
sl@0
   140
		{
sl@0
   141
		TResourceInfoBuf* currRes = infoPtrs[i];
sl@0
   142
		name.Copy((*currRes)().iName);
sl@0
   143
		name.PtrZ();
sl@0
   144
		gTest.Printf(_L("Resource %d name = %S \n"),i,&name);
sl@0
   145
		};
sl@0
   146
	}
sl@0
   147
#endif
sl@0
   148
sl@0
   149
	// Select a resource to use, then pass its name to GetResourceIdByName
sl@0
   150
	// to check that the corresponding resource ID is acquired.
sl@0
   151
	TResourceInfo currRes = (*infoPtrs[0])(); 
sl@0
   152
	if(updateNumResources>1)
sl@0
   153
		currRes=(*infoPtrs[1])();// First resource may be a dummy
sl@0
   154
	TUint resourceId;
sl@0
   155
	gTest.Printf(_L("Invoking GetResourceIdByName for last resource name extracted \n"));
sl@0
   156
	if((r=gChannel.GetResourceIdByName(currRes.iName, resourceId))!=KErrNone)
sl@0
   157
		{
sl@0
   158
		gTest.Printf(_L("GetResourceIdByName for channel returned %d \n"),r);
sl@0
   159
		return r;
sl@0
   160
		}
sl@0
   161
	gTest.Printf(_L("GetResourceIdByName gave ID = %d\n"),resourceId);
sl@0
   162
sl@0
   163
	infoPtrs.Close();
sl@0
   164
sl@0
   165
	__KHEAP_MARKEND;
sl@0
   166
sl@0
   167
	return r;
sl@0
   168
	}
sl@0
   169
sl@0
   170
LOCAL_C TInt CheckForSimulatedResources()
sl@0
   171
//
sl@0
   172
// Get the name of the first resource - if it does not match the expected name
sl@0
   173
// then the testing must not proceed, so return the relevant error code
sl@0
   174
//
sl@0
   175
	{
sl@0
   176
    TInt r = KErrNone;
sl@0
   177
	TResourceInfoBuf buffer;
sl@0
   178
	if((r=gChannel.GetResourceInfo(1, &buffer))!=KErrNone)	// first resource ID = 1
sl@0
   179
		{
sl@0
   180
		gTest.Printf(_L("CheckForSimulatedResources, candidate get resource info returned %d\n"),r);
sl@0
   181
		return r;
sl@0
   182
		}
sl@0
   183
	// Check the name of the resource
sl@0
   184
	TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name;
sl@0
   185
	name.Copy(buffer().iName);
sl@0
   186
	name.PtrZ();
sl@0
   187
	if((r=name.Compare(testableResourceName))!=KErrNone)
sl@0
   188
		{
sl@0
   189
		gTest.Printf(_L("Resource name = %S, require %S \n"),&name,&testableResourceName);
sl@0
   190
		r=KErrNotSupported;
sl@0
   191
		}
sl@0
   192
	return r;
sl@0
   193
	}
sl@0
   194
sl@0
   195
//----------------------------------------------------------------------------------------------
sl@0
   196
//! @SYMTestCaseID      KBASE-T_RESMANUS-0607
sl@0
   197
//! @SYMTestType        UT
sl@0
   198
//! @SYMPREQ            PREQ1398
sl@0
   199
//! @SYMTestCaseDesc    This test case tests channel opening and initialisation APIs.
sl@0
   200
//! @SYMTestActions     0) Call Open API with a valid name.
sl@0
   201
//! 
sl@0
   202
//!						1) Call Open API for two more channels 
sl@0
   203
//!						(to demonstrate multiple clients (channels) can be supported concurrently).
sl@0
   204
//! 
sl@0
   205
//!						2) Call Open with an oversized name. 
sl@0
   206
//! 
sl@0
   207
//!						3) Call GetNoOfResources API
sl@0
   208
//! 
sl@0
   209
//!						4) Call GetAllResourcesInfo API
sl@0
   210
//! 
sl@0
   211
//!						5) Call GetResourceIdByName API for last of resource names gathered
sl@0
   212
//!						in previous step
sl@0
   213
//! 
sl@0
   214
//!						6) Call Initialise API on the channel originally created, with non-zero arguments.
sl@0
   215
//!
sl@0
   216
//! @SYMTestExpectedResults 0) API should return with KErrNone, exits otherwise.
sl@0
   217
//!						1) API should return with KErrNone, exits otherwise.
sl@0
   218
//!						2) API should return with KErrBadName, exits otherwise.
sl@0
   219
//!						3) API should return with KErrNone, exits otherwise.
sl@0
   220
//!						4) API should return with KErrNone, exits otherwise.
sl@0
   221
//!						5) API should return with KErrNone, exits otherwise.
sl@0
   222
//!						6) API should return with KErrNone, exits otherwise.
sl@0
   223
//!
sl@0
   224
//! @SYMTestPriority        High
sl@0
   225
//! @SYMTestStatus          Implemented
sl@0
   226
//----------------------------------------------------------------------------------------------
sl@0
   227
LOCAL_C TInt OpenAndRegisterChannel()
sl@0
   228
//
sl@0
   229
// Test Open and Initialise functionality
sl@0
   230
// Also invokes Resource inspection methods via HelperResource
sl@0
   231
//
sl@0
   232
    {
sl@0
   233
    TInt r;
sl@0
   234
sl@0
   235
	if((r=OpenChannel(gTestName, gChannel))!=KErrNone)
sl@0
   236
		return r;
sl@0
   237
sl@0
   238
	// Check that the simulated resources required to support this testing are present
sl@0
   239
	// If not, close the channel and return the propagated error code.
sl@0
   240
	if((r=CheckForSimulatedResources())!=KErrNone)
sl@0
   241
		{
sl@0
   242
		gChannel.Close();
sl@0
   243
		return r;
sl@0
   244
		}
sl@0
   245
sl@0
   246
	__KHEAP_MARK; // gTestName will remain open (allocated) when heap is checked
sl@0
   247
sl@0
   248
	// Open a couple of additional channels to prove that more than one
sl@0
   249
	// can exist
sl@0
   250
	_LIT(tempStr1,"temp1");
sl@0
   251
	TBufC<16> tempName1(tempStr1);
sl@0
   252
	_LIT(tempStr2,"temp2");
sl@0
   253
	TBufC<16> tempName2(tempStr2);
sl@0
   254
sl@0
   255
	RBusDevResManUs channelTwo;
sl@0
   256
	RBusDevResManUs channelThree;
sl@0
   257
sl@0
   258
	if((r=OpenChannel(tempName1, channelTwo))!=KErrNone)
sl@0
   259
		return r;
sl@0
   260
	if((r=OpenChannel(tempName2, channelThree))!=KErrNone)
sl@0
   261
		return r;
sl@0
   262
sl@0
   263
	// The following test requires manual enabling in resource controller of macro
sl@0
   264
	// DEBUG_VERSION - this is not done by default, so test is deactivated here.
sl@0
   265
	//
sl@0
   266
#if 0
sl@0
   267
	// Test rejection if try a name already in use
sl@0
   268
	//
sl@0
   269
	// (For UREL builds, duplicate names are allowed; but
sl@0
   270
	//  for UDEB builds, they are monitored and rejected)
sl@0
   271
	//
sl@0
   272
	RBusDevResManUs channelSameName;
sl@0
   273
	r=OpenChannel(tempName1, channelSameName);
sl@0
   274
	channelSameName.Close(); // Channel not used after here
sl@0
   275
    if (r==KErrNone)
sl@0
   276
		{
sl@0
   277
		gTest.Printf(_L("Error: Handle for re-used name channel =0x%x\n"),channelSameName.Handle());
sl@0
   278
		return KErrGeneral;
sl@0
   279
		}
sl@0
   280
	else if(r!=KErrCouldNotConnect)
sl@0
   281
		{
sl@0
   282
		gTest.Printf(_L("Error: re-used name gave unexpected error code =0x%x\n"),r);
sl@0
   283
		return r;
sl@0
   284
		}
sl@0
   285
	else // if(r==KErrCouldNotConnect)
sl@0
   286
		{
sl@0
   287
		gTest.Printf(_L("Re-used channel name rejected with correct error code\n"));
sl@0
   288
		}
sl@0
   289
#endif // if 0
sl@0
   290
sl@0
   291
	// Test oversized name rejection
sl@0
   292
	_LIT(longStr,"1abcdefghijklmnopqrstuvwxyz2abcdefghijklmnopqrstuvwxyz3abcdefghijklmnopqrstuvwxyz4abcdefghijklmnopqrstuvwxyz5abcdefghijklmnopqrstuvwxyz6abcdefghijklmnopqrstuvwxyz7abcdefghijklmnopqrstuvwxyz8abcdefghijklmnopqrstuvwxyz9abcdefghijklmnopqrstuvwxyz10abcdefghijklmnopqrstuvwxyz");
sl@0
   293
	TBufC<271> longName(longStr);
sl@0
   294
sl@0
   295
	// API accepts 8-bit descriptors for names, only
sl@0
   296
	TBuf8<271>longName_8Bit;
sl@0
   297
	longName_8Bit.Copy(longName);
sl@0
   298
sl@0
   299
	RBusDevResManUs channelLong;
sl@0
   300
    r=(channelLong.Open(longName_8Bit));
sl@0
   301
	channelLong.Close(); // Channel not used after here
sl@0
   302
    if (r==KErrNone)
sl@0
   303
		{
sl@0
   304
		gTest.Printf(_L("Error: Handle for oversize name channel =0x%x\n"),channelLong.Handle());
sl@0
   305
		return KErrGeneral;
sl@0
   306
		}
sl@0
   307
	else if(r!=KErrBadName)
sl@0
   308
		{
sl@0
   309
		gTest.Printf(_L("Error: oversized name gave unexpected error code =0x%x\n"),r);
sl@0
   310
		return r;
sl@0
   311
		}
sl@0
   312
	else // if(r==KErrBadName)
sl@0
   313
		{
sl@0
   314
		gTest.Printf(_L("Oversized name for channel rejected with correct error code\n"));
sl@0
   315
		}
sl@0
   316
sl@0
   317
	// Invokes GetNoOfResources, GetAllResourcesInfo and GetResourceIdByName
sl@0
   318
	if((r=HelperResources())!=KErrNone)
sl@0
   319
		return r;
sl@0
   320
sl@0
   321
	// Close the temporary channels
sl@0
   322
	// Do this before  channel registration to enable valid check of kernel heap
sl@0
   323
	channelTwo.Close();
sl@0
   324
	channelThree.Close();
sl@0
   325
sl@0
   326
	__KHEAP_MARKEND;
sl@0
   327
sl@0
   328
	// Channel registration
sl@0
   329
    gTest.Printf(_L("Invoking Initialise with values 0x%x, 0x%x, 0x%x\n"),KNoOfGetStateRequests,KNoOfSetStateRequests,KNoOfNotifyRequests);
sl@0
   330
    if ((r=gChannel.Initialise(KNoOfGetStateRequests,KNoOfSetStateRequests,KNoOfNotifyRequests))!=KErrNone)
sl@0
   331
		{
sl@0
   332
		gTest.Printf(_L("Initialise for channel returned %d\n"),r);
sl@0
   333
		return r;
sl@0
   334
		}
sl@0
   335
sl@0
   336
    return KErrNone;
sl@0
   337
    }
sl@0
   338
sl@0
   339
sl@0
   340
LOCAL_C TInt HelperClients()
sl@0
   341
//
sl@0
   342
// Helper method to support TestGetClientGetResourceInfo
sl@0
   343
// Invokes GetNoOfClients and GetNamesAllClients
sl@0
   344
//
sl@0
   345
	{
sl@0
   346
	__KHEAP_MARK;
sl@0
   347
sl@0
   348
	TInt r = KErrNone;
sl@0
   349
	TUint numClients = 0;
sl@0
   350
	TUint numAllClients = 0;
sl@0
   351
	//
sl@0
   352
	// GetNoOfClients - with aIncludeKern=EFalse
sl@0
   353
	//
sl@0
   354
	if((r=gChannel.GetNoOfClients(numClients, EFalse)) != KErrNone)
sl@0
   355
		{
sl@0
   356
		gTest.Printf(_L("GetNoOfClients (aIncludeKern==EFalse) returned %d\n"),r);
sl@0
   357
		return r;
sl@0
   358
		}
sl@0
   359
	gTest.Printf(_L("GetNoOfClients (aIncludeKern==EFalse) gave 0x%x clients\n"),numClients);
sl@0
   360
sl@0
   361
	//
sl@0
   362
	// GetNoOfClients - with aIncludeKern=ETrue
sl@0
   363
	//
sl@0
   364
	r=gChannel.GetNoOfClients(numAllClients, ETrue);
sl@0
   365
#ifdef RESMANUS_KERN
sl@0
   366
	if(r==KErrNone)
sl@0
   367
		gTest.Printf(_L("GetNoOfClients (aIncludeKern==ETrue) returned KErrNone\n"));
sl@0
   368
#else
sl@0
   369
	if(r==KErrPermissionDenied)
sl@0
   370
		gTest.Printf(_L("GetNoOfClients (aIncludeKern==ETrue) returned KErrPermissionDenied\n"));
sl@0
   371
#endif
sl@0
   372
	else
sl@0
   373
		{
sl@0
   374
		gTest.Printf(_L("GetNoOfClients (aIncludeKern==ETrue) returned %d"),r);
sl@0
   375
		return KErrGeneral;
sl@0
   376
		}
sl@0
   377
sl@0
   378
	// To support the GetNamesAllClients testing, instantiate TClientName objects
sl@0
   379
	// and reference via an RSimplePointerArray
sl@0
   380
	TUint bufSize = (numAllClients>numClients)?numAllClients:numClients;
sl@0
   381
	RSimplePointerArray<TClientName> infoPtrs(bufSize);
sl@0
   382
	for(TUint i=0;i<bufSize;i++)
sl@0
   383
		{
sl@0
   384
		TClientName *info = new TClientName();
sl@0
   385
		if((r=infoPtrs.Insert(info, i))!=KErrNone)
sl@0
   386
			{
sl@0
   387
			gTest.Printf(_L("GetNamesAllClients infoPtrs.Insert at index %d returned %d\n"),i,r);
sl@0
   388
			}
sl@0
   389
		}
sl@0
   390
sl@0
   391
	//
sl@0
   392
	// GetNamesAllClients - with aIncludeKern=EFalse
sl@0
   393
	//
sl@0
   394
	if((r=gChannel.GetNamesAllClients(&infoPtrs, numClients, EFalse)) != KErrNone)
sl@0
   395
		{
sl@0
   396
		gTest.Printf(_L("GetNamesAllClients (aIncludeKern==EFalse) returned %d\n"),r);
sl@0
   397
		return r;
sl@0
   398
		}
sl@0
   399
#ifdef _DEBUG
sl@0
   400
	else
sl@0
   401
		{
sl@0
   402
		gTest.Printf(_L("GetNamesAllClients (aIncludeKern==EFalse) returned KErrNone, names follow\n"));
sl@0
   403
		for(TUint i=0;i<numClients;i++)
sl@0
   404
			{
sl@0
   405
			TClientName *currName = infoPtrs[i];
sl@0
   406
			TBuf16<sizeof(TClientName)> name;
sl@0
   407
			name.Copy(*currName);
sl@0
   408
			gTest.Printf(_L("Client name %d = %S\n"),i,&name);
sl@0
   409
			}
sl@0
   410
		}
sl@0
   411
#endif
sl@0
   412
sl@0
   413
	//
sl@0
   414
	// GetNamesAllClients - with aIncludeKern=ETrue
sl@0
   415
	//
sl@0
   416
#ifdef RESMANUS_KERN
sl@0
   417
	if((r=gChannel.GetNamesAllClients(&infoPtrs, numAllClients, ETrue)) != KErrNone)
sl@0
   418
		{
sl@0
   419
		gTest.Printf(_L("GetNamesAllClients (aIncludeKern==ETrue) returned %d\n"),r);
sl@0
   420
		return r;
sl@0
   421
		}
sl@0
   422
#ifdef _DEBUG
sl@0
   423
	else
sl@0
   424
		{
sl@0
   425
		gTest.Printf(_L("GetNamesAllClients (aIncludeKern==ETrue) returned KErrNone, names follow\n"));
sl@0
   426
		for(TUint i=0;i<numAllClients;i++)
sl@0
   427
			{
sl@0
   428
			TClientName *currName = infoPtrs[i];
sl@0
   429
			TBuf16<sizeof(TClientName)> name;
sl@0
   430
			name.Copy(*currName);
sl@0
   431
			gTest.Printf(_L("Client name %d = %S\n"),i,&name);
sl@0
   432
			}
sl@0
   433
		}
sl@0
   434
#endif
sl@0
   435
#else
sl@0
   436
	if((r=gChannel.GetNamesAllClients(&infoPtrs, numClients, ETrue)) == KErrPermissionDenied)
sl@0
   437
		{
sl@0
   438
		gTest.Printf(_L("GetNamesAllClients (aIncludeKern==ETrue) returned KErrPermissionDenied\n"));
sl@0
   439
		r=KErrNone; // Ensure misleading status is not returned
sl@0
   440
		}
sl@0
   441
	else
sl@0
   442
		{
sl@0
   443
		gTest.Printf(_L("GetNamesAllClients (aIncludeKern==ETrue) returned %d"),r);
sl@0
   444
		return r;
sl@0
   445
		}
sl@0
   446
#endif
sl@0
   447
sl@0
   448
	infoPtrs.Close();
sl@0
   449
	__KHEAP_MARKEND;
sl@0
   450
sl@0
   451
	return r;
sl@0
   452
	}
sl@0
   453
sl@0
   454
LOCAL_C TInt HelperClientsUsingResource(TUint aResourceId)
sl@0
   455
//
sl@0
   456
// Helper method to support TestGetClientGetResourceInfo
sl@0
   457
// Invokes GetNumClientsUsingResource and GetInfoOnClientsUsingResource
sl@0
   458
//
sl@0
   459
	{
sl@0
   460
	__KHEAP_MARK;
sl@0
   461
sl@0
   462
	TInt r = KErrNone;
sl@0
   463
	//
sl@0
   464
	// GetNumClientsUsingResource - with aIncludeKern=ETrue
sl@0
   465
	//
sl@0
   466
	TUint resourceAllClients = 0;
sl@0
   467
	if((r=gChannel.GetNumClientsUsingResource(aResourceId, resourceAllClients, ETrue)) == KErrPermissionDenied)
sl@0
   468
		{
sl@0
   469
		gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==ETrue) returned KErrPermissionDenied\n"));
sl@0
   470
#ifdef RESMANUS_KERN
sl@0
   471
		return r;
sl@0
   472
		}
sl@0
   473
	else
sl@0
   474
		{
sl@0
   475
		if(r!=KErrNone)
sl@0
   476
			{
sl@0
   477
			gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==ETrue) returned %d\n"),r);
sl@0
   478
			return r;
sl@0
   479
			}
sl@0
   480
		else
sl@0
   481
			gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==ETrue) reported 0x%x clients\n"),resourceAllClients);
sl@0
   482
		}
sl@0
   483
#else
sl@0
   484
		}
sl@0
   485
	else
sl@0
   486
		{
sl@0
   487
		gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==ETrue) returned %d\n"),r);
sl@0
   488
		return r;
sl@0
   489
		}
sl@0
   490
#endif
sl@0
   491
	//
sl@0
   492
	// GetNumClientsUsingResource - with aIncludeKern=EFalse
sl@0
   493
	//
sl@0
   494
	TUint resourceClients = 0;
sl@0
   495
	if((r=gChannel.GetNumClientsUsingResource(aResourceId, resourceClients, EFalse)) != KErrNone)
sl@0
   496
		{
sl@0
   497
		// If there are no clients that have requested a level then the Resource Controller will
sl@0
   498
		// the client ID as a bad argument
sl@0
   499
		if(!((resourceClients==0)&&(r==KErrArgument)))
sl@0
   500
			{
sl@0
   501
			gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==EFalse) returned %d\n"),r);
sl@0
   502
			return r;
sl@0
   503
			}
sl@0
   504
		else
sl@0
   505
			r=KErrNone;	// Ensure expected error is not misinterpeted
sl@0
   506
		}
sl@0
   507
	else
sl@0
   508
		gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==EFalse) reported 0x%x clients\n"),resourceClients);
sl@0
   509
		
sl@0
   510
	// To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects
sl@0
   511
	// and reference via an RSimplePointerArray
sl@0
   512
	TUint bufSize = (resourceAllClients>resourceClients)?resourceAllClients:resourceClients;
sl@0
   513
	if(bufSize>0)
sl@0
   514
		{
sl@0
   515
		RSimplePointerArray<TClientInfoBuf> infoPtrs(bufSize);
sl@0
   516
		for(TUint i=0;i<bufSize;i++)
sl@0
   517
			{
sl@0
   518
			TClientInfoBuf *info = new TClientInfoBuf();
sl@0
   519
			if((r=infoPtrs.Insert(info, i))!=KErrNone)
sl@0
   520
				{
sl@0
   521
				gTest.Printf(_L("GetInfoOnClientsUsingResource infoPtrs.Insert at index %d returned %d\n"),i,r);
sl@0
   522
				}
sl@0
   523
			}
sl@0
   524
sl@0
   525
		//
sl@0
   526
		// GetInfoOnClientsUsingResource - with aIncludeKern=EFalse
sl@0
   527
		//
sl@0
   528
		if((r=gChannel.GetInfoOnClientsUsingResource(aResourceId, resourceClients, &infoPtrs, EFalse)) != KErrNone)
sl@0
   529
			{
sl@0
   530
			// If there are no clients that have requested a level then the resource will not
sl@0
   531
			// have been found
sl@0
   532
			if(!((resourceClients==0)&&(r==KErrNotFound)))
sl@0
   533
				{
sl@0
   534
				gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==EFalse) returned %d\n"),r);
sl@0
   535
				return r;
sl@0
   536
				}
sl@0
   537
			}
sl@0
   538
#ifdef _DEBUG
sl@0
   539
		else
sl@0
   540
			{
sl@0
   541
			gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==EFalse) returned KErrNone, info follows\n"));
sl@0
   542
			for(TUint i=0;i<resourceClients;i++)
sl@0
   543
				{
sl@0
   544
				TClientInfoBuf* currInfoBuf = infoPtrs[i];
sl@0
   545
				TClientInfo currInfo=(*currInfoBuf)();
sl@0
   546
				TBuf16<sizeof(TClientName)> name;
sl@0
   547
				name.Copy(currInfo.iName);
sl@0
   548
				gTest.Printf(_L("Client name %d = %S, ID=0x%x\n"),i,&name,currInfo.iId);
sl@0
   549
				}
sl@0
   550
			}
sl@0
   551
#endif
sl@0
   552
		//
sl@0
   553
		// GetInfoOnClientsUsingResource - with aIncludeKern=ETrue
sl@0
   554
		//
sl@0
   555
		r=gChannel.GetInfoOnClientsUsingResource(aResourceId, resourceAllClients, &infoPtrs, ETrue);
sl@0
   556
			{
sl@0
   557
#ifdef RESMANUS_KERN
sl@0
   558
			if(r != KErrNone)
sl@0
   559
				{
sl@0
   560
				// If there are no clients that have requested a level then the Resource Controller
sl@0
   561
				// will report a request for information on 0 clients as a bad argument
sl@0
   562
				if(!((resourceClients==0)&&(r==KErrArgument)))
sl@0
   563
					{
sl@0
   564
					gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned %d\n"),r);
sl@0
   565
					return r;
sl@0
   566
					}
sl@0
   567
				else
sl@0
   568
					r=KErrNone; // Ensure misleading result is not returned
sl@0
   569
				}
sl@0
   570
#ifdef _DEBUG
sl@0
   571
			else
sl@0
   572
				{
sl@0
   573
				gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned KErrNone, info follows\n"));
sl@0
   574
				for(TUint i=0;i<resourceClients;i++)
sl@0
   575
					{
sl@0
   576
					TClientInfoBuf* currInfoBuf = infoPtrs[i];
sl@0
   577
					TClientInfo currInfo=(*currInfoBuf)();
sl@0
   578
					TBuf16<sizeof(TClientName)> name;
sl@0
   579
					name.Copy(currInfo.iName);
sl@0
   580
					gTest.Printf(_L("Client name %d = %S, ID=0x%x\n"),i,&name,currInfo.iId);
sl@0
   581
					}
sl@0
   582
				}
sl@0
   583
#endif
sl@0
   584
#else
sl@0
   585
			if(r == KErrNone)
sl@0
   586
				{
sl@0
   587
				gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned KErrNone"));
sl@0
   588
				return KErrGeneral;
sl@0
   589
				}
sl@0
   590
			else if(r==KErrPermissionDenied)
sl@0
   591
				{
sl@0
   592
				gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned KErrPermissionDenied\n"));
sl@0
   593
				r=KErrNone; // Ensure that misleading result is not propagated
sl@0
   594
				}
sl@0
   595
			else
sl@0
   596
				{
sl@0
   597
				gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned %d\n"),r);
sl@0
   598
				// If there are no clients that have requested a level then the Resource Controller
sl@0
   599
				// will report a request for information on 0 clients as a bad argument
sl@0
   600
				if(!((resourceClients==0)&&(r==KErrArgument)))
sl@0
   601
					return r;
sl@0
   602
				}
sl@0
   603
#endif
sl@0
   604
			}
sl@0
   605
		}
sl@0
   606
sl@0
   607
	__KHEAP_MARKEND;
sl@0
   608
sl@0
   609
	return r;
sl@0
   610
	}
sl@0
   611
sl@0
   612
sl@0
   613
sl@0
   614
LOCAL_C TInt HelperResourcesInUseByClient()
sl@0
   615
//
sl@0
   616
// Helper method to supportTestGetClientGetResourceInfo
sl@0
   617
// Invokes GetNumResourcesInUseByClient and GetInfoOnResourcesInUseByClient
sl@0
   618
//
sl@0
   619
	{
sl@0
   620
	__KHEAP_MARK;
sl@0
   621
sl@0
   622
	TInt r = KErrNone;
sl@0
   623
	//
sl@0
   624
	// GetNumResourcesInUseByClient
sl@0
   625
	//
sl@0
   626
	// API accepts 8-bit descriptors, only - so convert name accordingly
sl@0
   627
	TBuf8<MAX_RESOURCE_NAME_LENGTH+1>name8Bit;
sl@0
   628
	name8Bit.Copy(gTestName);
sl@0
   629
	TClientName* clientName = (TClientName*)&name8Bit;
sl@0
   630
#if _DEBUG
sl@0
   631
	TBuf <MAX_CLIENT_NAME_LENGTH> clientName16Bit;
sl@0
   632
	clientName16Bit.Copy(*clientName);
sl@0
   633
	clientName16Bit.SetLength(clientName->Length());
sl@0
   634
	gTest.Printf(_L("Invoking GetNumResourcesInUseByClient with %S (expect KErrPermissionDenied if no levels requested yet)\n"),&clientName16Bit);
sl@0
   635
#endif
sl@0
   636
	TUint numResourcesForClient;
sl@0
   637
	if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResourcesForClient)) != KErrNone)
sl@0
   638
		{
sl@0
   639
		gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r);
sl@0
   640
		return r;
sl@0
   641
		}
sl@0
   642
	gTest.Printf(_L("GetNumResourcesInUseByClient gave number of resources = %d\n"),numResourcesForClient);
sl@0
   643
	//
sl@0
   644
	// In addition, check response when the name of an unknown client is passed
sl@0
   645
	//
sl@0
   646
	// Negative test - ensure that an unknown client name fails
sl@0
   647
	_LIT(dumName,"DoesNotExist");
sl@0
   648
	TBuf<16> dumNameBuf(dumName);
sl@0
   649
	TBuf8<MAX_RESOURCE_NAME_LENGTH+1>dumName8Bit;
sl@0
   650
	dumName8Bit.Copy(dumNameBuf);
sl@0
   651
	TClientName* dumClientName = (TClientName*)&dumName8Bit;
sl@0
   652
#if _DEBUG
sl@0
   653
	gTest.Printf(_L("Invoking GetNumResourcesInUseByClient with %S\n"),&dumNameBuf);
sl@0
   654
#endif
sl@0
   655
	TUint numResForDumClient;
sl@0
   656
	if((r=gChannel.GetNumResourcesInUseByClient(*dumClientName, numResForDumClient)) != KErrNotFound)
sl@0
   657
		{
sl@0
   658
		gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r);
sl@0
   659
		if(r==KErrNone)
sl@0
   660
			r=KErrGeneral;
sl@0
   661
		return r;
sl@0
   662
		}
sl@0
   663
	gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r);
sl@0
   664
	r=KErrNone;	// Ensure misleading error code is not propagated
sl@0
   665
sl@0
   666
	//
sl@0
   667
	// GetInfoOnResourcesInUseByClient
sl@0
   668
	//
sl@0
   669
	// If the (TUint) number of resources in use by the client is zero skip the attempt to read the resource information
sl@0
   670
	TUint updatedNumResourcesForClient = numResourcesForClient;
sl@0
   671
	if(numResourcesForClient!=0)
sl@0
   672
		{
sl@0
   673
		TUint bufSize = numResourcesForClient;
sl@0
   674
		RSimplePointerArray<TResourceInfoBuf> infoPtrs(bufSize);
sl@0
   675
		for(TUint i=0;i<bufSize;i++)
sl@0
   676
			{
sl@0
   677
			TResourceInfoBuf *info = new TResourceInfoBuf();
sl@0
   678
			if((r=infoPtrs.Insert(info, i))!=KErrNone)
sl@0
   679
				{
sl@0
   680
				gTest.Printf(_L("GetInfoOnResourcesInUseByClient infoPtrs.Insert at index %d returned %d\n"),i,r);
sl@0
   681
				}
sl@0
   682
			}
sl@0
   683
sl@0
   684
		if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, updatedNumResourcesForClient, &infoPtrs)) != KErrNone)
sl@0
   685
			{
sl@0
   686
			gTest.Printf(_L("GetInfoOnResourcesInUseByClient returned %d\n"),r);
sl@0
   687
			// If there are no clients that have requested a level then the Resource Controller
sl@0
   688
			// will report a request for information on 0 clients as a bad argument
sl@0
   689
			if(!((updatedNumResourcesForClient==0)&&(r==KErrArgument)))
sl@0
   690
				return r;
sl@0
   691
			else
sl@0
   692
				r=KErrNone; // Ensure misleading value is not returned by this function
sl@0
   693
			}
sl@0
   694
		else
sl@0
   695
			{
sl@0
   696
			gTest.Printf(_L("GetInfoOnResourcesInUseByClient gave updated number of resources %d\n"),updatedNumResourcesForClient);
sl@0
   697
#ifdef _DEBUG
sl@0
   698
			// Print resource names
sl@0
   699
			TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name;
sl@0
   700
			for(TUint i=0; i<updatedNumResourcesForClient; i++)
sl@0
   701
				{
sl@0
   702
				TResourceInfoBuf* currRes = infoPtrs[i];
sl@0
   703
				name.Copy((*currRes)().iName);
sl@0
   704
				name.PtrZ();
sl@0
   705
				gTest.Printf(_L("Resource %d name = %S \n"),i,&name);
sl@0
   706
				};
sl@0
   707
#endif
sl@0
   708
			}
sl@0
   709
		//
sl@0
   710
		// In addition, check response when the name of an unknown client is passed
sl@0
   711
		//
sl@0
   712
		// Negative test - ensure that an unknown client name fails
sl@0
   713
		r=gChannel.GetInfoOnResourcesInUseByClient(*dumClientName, updatedNumResourcesForClient, &infoPtrs);
sl@0
   714
		gTest.Printf(_L("GetInfoOnResourcesInUseByClient for dummy client returned %d\n"),r);
sl@0
   715
		if(r==KErrNone)
sl@0
   716
			return KErrGeneral;
sl@0
   717
		else if(r!=KErrNotFound)
sl@0
   718
			return r;
sl@0
   719
		// Ensure that misleading information is not returned to the calling function
sl@0
   720
		r=KErrNone;
sl@0
   721
sl@0
   722
		infoPtrs.Close();
sl@0
   723
		}
sl@0
   724
	
sl@0
   725
	__KHEAP_MARKEND;
sl@0
   726
sl@0
   727
	return r;
sl@0
   728
	}
sl@0
   729
sl@0
   730
sl@0
   731
LOCAL_C TInt HelperGetClientResourceInfo()
sl@0
   732
//
sl@0
   733
// Test methods to access information about clients and resources
sl@0
   734
//
sl@0
   735
	{
sl@0
   736
	__KHEAP_MARK;
sl@0
   737
sl@0
   738
	TInt r = KErrNone;
sl@0
   739
	// Invokes GetNoOfClients and GetNamesAllClients
sl@0
   740
	if((r=HelperClients())!=KErrNone)
sl@0
   741
		return r;
sl@0
   742
sl@0
   743
	// Invokes GetNumClientsUsingResource and GetInfoOnClientsUsingResource
sl@0
   744
	//
sl@0
   745
	// First invoke on the Async resource
sl@0
   746
	TUint resourceId = 1;	// Arbitrary
sl@0
   747
	if(gHaveAsyncRes)
sl@0
   748
		{
sl@0
   749
		resourceId = gLongLatencyResource;
sl@0
   750
		gTest.Printf(_L("Invoking HelperClientsUsinResource for Async resource ID %d\n"),resourceId);
sl@0
   751
		}
sl@0
   752
	else
sl@0
   753
		{
sl@0
   754
		gTest.Printf(_L("Invoking HelperClientsUsinResource for default resource ID %d (Async resource not yet accessed)\n"),resourceId);
sl@0
   755
		}
sl@0
   756
	if((r=HelperClientsUsingResource(resourceId))!=KErrNone)
sl@0
   757
		return r;
sl@0
   758
	//
sl@0
   759
	// Second invoke on the Shared resource - skip if not available
sl@0
   760
	if(gHaveSharedRes)
sl@0
   761
		{
sl@0
   762
		resourceId = gSharedResource;
sl@0
   763
		gTest.Printf(_L("Invoking HelperClientsUsinResource for Shared resource ID %d\n"),resourceId);
sl@0
   764
		if((r=HelperClientsUsingResource(resourceId))!=KErrNone)
sl@0
   765
			return r;
sl@0
   766
		}
sl@0
   767
sl@0
   768
	// Invokes GetNumResourcesInUseByClient and GetInfoOnResourcesInUseByClient
sl@0
   769
	if((r=HelperResourcesInUseByClient())!=KErrNone)
sl@0
   770
		return r;
sl@0
   771
sl@0
   772
	__KHEAP_MARKEND;
sl@0
   773
sl@0
   774
	return r;
sl@0
   775
	}
sl@0
   776
sl@0
   777
#ifdef _DEBUG
sl@0
   778
LOCAL_C TInt SetAsyncResource()
sl@0
   779
//
sl@0
   780
// Support function for tests of asynchronous API methods
sl@0
   781
//
sl@0
   782
	{
sl@0
   783
	if(!gHaveAsyncRes)
sl@0
   784
		{
sl@0
   785
		gTest.Printf(_L("SetAsyncResource, Find Async resource to use\n"));
sl@0
   786
		TRequestStatus status;
sl@0
   787
		TBool cached = gUseCached;
sl@0
   788
		TInt readValue = 0;
sl@0
   789
		TInt levelOwnerId = 0;
sl@0
   790
		TUint numPotentialResources;
sl@0
   791
		TUint index=0;
sl@0
   792
		TInt r=gChannel.GetNumCandidateAsyncResources(numPotentialResources);
sl@0
   793
		if(r!=KErrNone)
sl@0
   794
			{
sl@0
   795
			gTest.Printf(_L("SetAsyncResource, GetNumCandidateAsyncResources returned %d\n"),r);
sl@0
   796
			return r;
sl@0
   797
			}
sl@0
   798
		gTest.Printf(_L("SetAsyncResource, GetNumCandidateAsyncResources found %d resources\n"),numPotentialResources);
sl@0
   799
		while((numPotentialResources>0) && !gHaveAsyncRes)
sl@0
   800
			{
sl@0
   801
			TUint tryResourceId=0;
sl@0
   802
			r=gChannel.GetCandidateAsyncResourceId(index,tryResourceId);
sl@0
   803
			if(r!=KErrNone)
sl@0
   804
				{
sl@0
   805
				gTest.Printf(_L("SetAsyncResource, GetCandidateAsyncResourceId returned %d\n"),r);
sl@0
   806
				break;
sl@0
   807
				}
sl@0
   808
			gTest.Printf(_L("SetAsyncResource, GetNumCandidateAsyncResources index %d, resource ID %d\n"),index,tryResourceId);
sl@0
   809
			// For the candidate resource to be usable, we need its current state
sl@0
   810
			// to be sufficiently less the maximum for positive sense (or sufficiently
sl@0
   811
			// more than the greater than the minimum for negative sense - but the current 
sl@0
   812
			// version of the code only considers positive sense).
sl@0
   813
			gChannel.GetResourceState(status,tryResourceId,cached,&readValue,&levelOwnerId);
sl@0
   814
			User::WaitForRequest(status);
sl@0
   815
			if(status.Int() != KErrNone)
sl@0
   816
				{
sl@0
   817
				gTest.Printf(_L("SetAsyncResource, candidate get state returned %d\n"),r);
sl@0
   818
				return r;
sl@0
   819
				}
sl@0
   820
			gTest.Printf(_L("SetAsyncResource, candidate get state gave %d, levelOwnerId = %d\n"),readValue,levelOwnerId);
sl@0
   821
			TResourceInfoBuf buffer;
sl@0
   822
			if((r=gChannel.GetResourceInfo(tryResourceId, &buffer))!=KErrNone)
sl@0
   823
				{
sl@0
   824
				gTest.Printf(_L("SetAsyncResource, candidate get resource info returned %d\n"),r);
sl@0
   825
				return r;
sl@0
   826
				}
sl@0
   827
			// Print resource info
sl@0
   828
			TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name;
sl@0
   829
			TResourceInfo* infoPtr = &(buffer());
sl@0
   830
			name.Copy(infoPtr->iName);
sl@0
   831
			gTest.Printf(_L("SetAsyncResource: Resource name = %S \n"),&name);
sl@0
   832
			gTest.Printf(_L("SetAsyncResource: Resource Class =%d\n"),infoPtr->iClass);
sl@0
   833
			gTest.Printf(_L("SetAsyncResource: Resource Type =%d\n"), infoPtr->iType);
sl@0
   834
			gTest.Printf(_L("SetAsyncResource: Resource Usage =%d\n"), infoPtr->iUsage);
sl@0
   835
			gTest.Printf(_L("SetAsyncResource: Resource Sense =%d\n"), infoPtr->iSense);
sl@0
   836
			gTest.Printf(_L("SetAsyncResource: Resource MinLevel =%d\n"),infoPtr->iMinLevel);
sl@0
   837
			gTest.Printf(_L("SetAsyncResource: Resource MaxLevel =%d\n"),infoPtr->iMaxLevel);
sl@0
   838
sl@0
   839
			if((infoPtr->iMaxLevel - readValue) > LEVEL_GAP_REQUIRED_FOR_ASYNC_TESTING)
sl@0
   840
				{
sl@0
   841
				gLongLatencyResource = tryResourceId;
sl@0
   842
				gAsyncResStateDelta = 1;  // Will change resource level in positive direction
sl@0
   843
				gHaveAsyncRes = ETrue;
sl@0
   844
				}
sl@0
   845
			else if((readValue - infoPtr->iMinLevel) > LEVEL_GAP_REQUIRED_FOR_ASYNC_TESTING)
sl@0
   846
				{
sl@0
   847
				gLongLatencyResource = tryResourceId;
sl@0
   848
				gAsyncResStateDelta = -1;  // Will change resource level in negative direction
sl@0
   849
				gHaveAsyncRes = ETrue;
sl@0
   850
				}
sl@0
   851
			else
sl@0
   852
				{
sl@0
   853
				++index;
sl@0
   854
				--numPotentialResources;
sl@0
   855
				}
sl@0
   856
			};
sl@0
   857
		}
sl@0
   858
	if(!gHaveAsyncRes)
sl@0
   859
		{
sl@0
   860
	    gTest.Printf(_L("**Test SetAsyncResource - don't have suitable resource ... exiting\n"));
sl@0
   861
		return KErrNotReady;
sl@0
   862
		}
sl@0
   863
sl@0
   864
	return KErrNone;
sl@0
   865
	}
sl@0
   866
sl@0
   867
LOCAL_C TInt SetSharedResource()
sl@0
   868
//
sl@0
   869
// Support function for tests of shareable resources
sl@0
   870
//
sl@0
   871
	{
sl@0
   872
	__KHEAP_MARK;
sl@0
   873
sl@0
   874
	if(!gHaveSharedRes)
sl@0
   875
		{
sl@0
   876
		TRequestStatus status;
sl@0
   877
		TBool cached = gUseCached;
sl@0
   878
		TInt readValue = 0;
sl@0
   879
		TUint numPotentialResources;
sl@0
   880
		TUint index=0;
sl@0
   881
		TInt r=gChannel.GetNumCandidateSharedResources(numPotentialResources);
sl@0
   882
		if(r!=KErrNone)
sl@0
   883
			{
sl@0
   884
			gTest.Printf(_L("SetSharedResource, GetNumCandidateSharedResources returned %d\n"),r);
sl@0
   885
			return r;
sl@0
   886
			}
sl@0
   887
		gTest.Printf(_L("SetSharedResource, GetNumCandidateSharedResources found %d resources\n"),numPotentialResources);
sl@0
   888
		while((numPotentialResources>0) && !gHaveSharedRes)
sl@0
   889
			{
sl@0
   890
			TUint tryResourceId=0;
sl@0
   891
			r=gChannel.GetCandidateSharedResourceId(index,tryResourceId);
sl@0
   892
			if(r!=KErrNone)
sl@0
   893
				{
sl@0
   894
				gTest.Printf(_L("SetSharedResource, GetCandidateSharedResourceId returned %d\n"),r);
sl@0
   895
				break;
sl@0
   896
				}
sl@0
   897
			gTest.Printf(_L("SetSharedResource, GetNumCandidateSharedResources index %d, resource ID %d\n"),index,tryResourceId);
sl@0
   898
			// To support the tests, the selected shareable resource must not be the same
sl@0
   899
			// resource as that selected for asynchronous testing
sl@0
   900
			if(gHaveAsyncRes)
sl@0
   901
				if(tryResourceId==gLongLatencyResource)
sl@0
   902
					{
sl@0
   903
					gTest.Printf(_L("SetSharedResource - skipping candidate resource %d - already used for async testing\n"),tryResourceId);
sl@0
   904
					continue;
sl@0
   905
					}
sl@0
   906
			// For the candidate resource to be usable, we need its current state
sl@0
   907
			// to be sufficiently less the maximum for positive sense (or sufficiently
sl@0
   908
			// more than the greater than the minimum for negative sense - but the current 
sl@0
   909
			// version of the code only considers positive sense).
sl@0
   910
			TInt levelOwnerId = 0;
sl@0
   911
			gChannel.GetResourceState(status,tryResourceId,cached,&readValue,&levelOwnerId);
sl@0
   912
			User::WaitForRequest(status);
sl@0
   913
			if(status.Int() != KErrNone)
sl@0
   914
				{
sl@0
   915
				gTest.Printf(_L("SetSharedResource, candidate get state returned %d\n"),r);
sl@0
   916
				return r;
sl@0
   917
				}
sl@0
   918
			gTest.Printf(_L("SetSharedResource, candidate get state gave %d, levelOwnerId = %d\n"),readValue,levelOwnerId);
sl@0
   919
			TResourceInfoBuf buffer;
sl@0
   920
			if((r=gChannel.GetResourceInfo(tryResourceId, &buffer))!=KErrNone)
sl@0
   921
				{
sl@0
   922
				gTest.Printf(_L("SetSharedResource, candidate get resource info returned %d\n"),r);
sl@0
   923
				return r;
sl@0
   924
				}
sl@0
   925
			// Print resource info
sl@0
   926
			TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name;
sl@0
   927
			TResourceInfo* infoPtr = &buffer();
sl@0
   928
			name.Copy(infoPtr->iName);
sl@0
   929
			gTest.Printf(_L("SetSharedResource: Resource name = %S \n"),&name);
sl@0
   930
			gTest.Printf(_L("SetSharedResource: Resource Class =%d\n"),infoPtr->iClass);
sl@0
   931
			gTest.Printf(_L("SetSharedResource: Resource Type =%d\n"), infoPtr->iType);
sl@0
   932
			gTest.Printf(_L("SetSharedResource: Resource Usage =%d\n"), infoPtr->iUsage);
sl@0
   933
			gTest.Printf(_L("SetSharedResource: Resource Sense =%d\n"), infoPtr->iSense);
sl@0
   934
			gTest.Printf(_L("SetSharedResource: Resource MinLevel =%d\n"),infoPtr->iMinLevel);
sl@0
   935
			gTest.Printf(_L("SetSharedResource: Resource MaxLevel =%d\n"),infoPtr->iMaxLevel);
sl@0
   936
sl@0
   937
			if((infoPtr->iMaxLevel - readValue) > LEVEL_GAP_REQUIRED_FOR_ASYNC_TESTING)
sl@0
   938
				{
sl@0
   939
				gSharedResource = tryResourceId;
sl@0
   940
				gSharedResStateDelta = 1;  // Will change resource level in positive direction
sl@0
   941
				gHaveSharedRes = ETrue;
sl@0
   942
				}
sl@0
   943
			else if((readValue - infoPtr->iMinLevel) > LEVEL_GAP_REQUIRED_FOR_ASYNC_TESTING)
sl@0
   944
				{
sl@0
   945
				gSharedResource = tryResourceId;
sl@0
   946
				gSharedResStateDelta = -1;  // Will change resource level in negative direction
sl@0
   947
				gHaveSharedRes = ETrue;
sl@0
   948
				}
sl@0
   949
			else
sl@0
   950
				{
sl@0
   951
				++index;
sl@0
   952
				--numPotentialResources;
sl@0
   953
				}
sl@0
   954
			};
sl@0
   955
		}
sl@0
   956
	if(!gHaveSharedRes)
sl@0
   957
		{
sl@0
   958
	    gTest.Printf(_L("**Test SetSharedResource - don't have suitable resource ... exiting\n"));
sl@0
   959
		return KErrNotReady;
sl@0
   960
		}
sl@0
   961
sl@0
   962
	__KHEAP_MARKEND;
sl@0
   963
	return KErrNone;
sl@0
   964
	}
sl@0
   965
sl@0
   966
#endif
sl@0
   967
sl@0
   968
sl@0
   969
//----------------------------------------------------------------------------------------------
sl@0
   970
//! @SYMTestCaseID      KBASE-T_RESMANUS-0609
sl@0
   971
//! @SYMTestType        UT
sl@0
   972
//! @SYMPREQ            PREQ1398
sl@0
   973
//! @SYMTestCaseDesc    This test case tests APIs for retrieving information about 
sl@0
   974
//!						(1) clients of the channel and 
sl@0
   975
//!						(2) power resources. 
sl@0
   976
//!						Since the client lacks the ReadDeviceData PlatSec capability it will not
sl@0
   977
//!						be permitted to access information about kernel-side clients
sl@0
   978
//! 
sl@0
   979
//!						The tests are invoked a number of times:
sl@0
   980
//!						-	first, to examine the starting state
sl@0
   981
//!						-	then, to examine the effect of adding a new client (channel)
sl@0
   982
//!						-	then, the examine the effect of adding a new client that requests a
sl@0
   983
//|							level on a resource
sl@0
   984
//!						-	then, to test the effect of the original client requesting a level 
sl@0
   985
//!							on a resource
sl@0
   986
//! 
sl@0
   987
//! @SYMTestActions     0) Call GetNoOfClients API with default aIncludeKern=EFalse.
sl@0
   988
//! 
sl@0
   989
//!						1) Call GetNoOfClients API with aIncludeKern=ETrue.
sl@0
   990
//!
sl@0
   991
//!						2) Call GetNamesAllClients API with default aIncludeKern=EFalse.
sl@0
   992
//!
sl@0
   993
//!						3) Call GetNamesAllClients API with aIncludeKern=ETrue.
sl@0
   994
//!
sl@0
   995
//!						4) Call GetNumClientsUsingResource API with aIncludeKern=ETrue.
sl@0
   996
//!
sl@0
   997
//!						5) Call GetNumClientsUsingResource API with default aIncludeKern=EFalse.
sl@0
   998
//!
sl@0
   999
//!						6) Call GetInfoOnClientsUsingResource API with default aIncludeKern=EFalse.
sl@0
  1000
//!
sl@0
  1001
//!						7) Call GetInfoOnClientsUsingResource API with aIncludeKern=ETrue.
sl@0
  1002
//!
sl@0
  1003
//!						8) GetNumResourcesInUseByClient for the original client
sl@0
  1004
//!
sl@0
  1005
//!						9) GetNumResourcesInUseByClient for a non-existent client
sl@0
  1006
//!
sl@0
  1007
//!						10) GetInfoOnResourcesInUseByClient for the original client
sl@0
  1008
//!
sl@0
  1009
//!						11) GetInfoOnResourcesInUseByClient for a non-existent client
sl@0
  1010
//!
sl@0
  1011
//! @SYMTestExpectedResults 0) API should return with KErrNone, exits otherwise.
sl@0
  1012
//!
sl@0
  1013
//!						1) If client exhibits PlatSec capability ReadDeviceData, API should return with KErrNone, exits otherwise.
sl@0
  1014
//!						   If client lacks PlatSec capability ReadDeviceData, API should return with KErrPermissionDenied, exits otherwise.
sl@0
  1015
//!
sl@0
  1016
//!						2) API should return with KErrNone, exits otherwise.
sl@0
  1017
//!
sl@0
  1018
//!						3) If client exhibits PlatSec capability ReadDeviceData, API should return with KErrNone, exits otherwise
sl@0
  1019
//!						   If client lacks PlatSec capability ReadDeviceData, API should return with KErrPermissionDenied, exits otherwise
sl@0
  1020
//!
sl@0
  1021
//!						4) If client exhibits PlatSec capability ReadDeviceData, API should return with KErrNone, exits otherwise.
sl@0
  1022
//!						   If client lacks PlatSec capability ReadDeviceData, API should return with KErrPermissionDenied, exits otherwise.
sl@0
  1023
//!
sl@0
  1024
//!						5) API should return with KErrNone, exits otherwise
sl@0
  1025
//!
sl@0
  1026
//!						6) API should return with KErrNone, exits otherwise.
sl@0
  1027
//!
sl@0
  1028
//!						7) If client exhibits PlatSec capability ReadDeviceData, API should return with KErrNone, exits otherwise
sl@0
  1029
//!						   If client lacks PlatSec capability ReadDeviceData, API should return with KErrPermissionDenied, exits otherwise
sl@0
  1030
//!
sl@0
  1031
//!						8) API should return with KErrNone, exits otherwise.
sl@0
  1032
//!
sl@0
  1033
//!						9) API should return with KErrNotFound, exits otherwise.
sl@0
  1034
//!
sl@0
  1035
//!						10) API should return with KErrNone, exits otherwise.
sl@0
  1036
//!
sl@0
  1037
//!						11) API should return with KErrNotFound, exits otherwise.
sl@0
  1038
//!
sl@0
  1039
//! @SYMTestPriority        High
sl@0
  1040
//! @SYMTestStatus          Implemented
sl@0
  1041
//----------------------------------------------------------------------------------------------
sl@0
  1042
LOCAL_C TInt TestGetClientGetResourceInfo()
sl@0
  1043
//
sl@0
  1044
// Test methods to access information about clients and resources
sl@0
  1045
//
sl@0
  1046
	{
sl@0
  1047
	TInt r = KErrNone;
sl@0
  1048
sl@0
  1049
	// Open a couple of additional channels  
sl@0
  1050
	_LIT(tempStr1,"ExtraChan1");
sl@0
  1051
	TBufC<16> tempName1(tempStr1);
sl@0
  1052
	_LIT(tempStr2,"ExtraChan2");
sl@0
  1053
	TBufC<16> tempName2(tempStr2);
sl@0
  1054
sl@0
  1055
	RBusDevResManUs channelTwo;
sl@0
  1056
	RBusDevResManUs channelThree;
sl@0
  1057
sl@0
  1058
	if((r=OpenChannel(tempName1, channelTwo))!=KErrNone)
sl@0
  1059
		return r;
sl@0
  1060
	if((r=OpenChannel(tempName2, channelThree))!=KErrNone)
sl@0
  1061
		return r;
sl@0
  1062
sl@0
  1063
	// Test the tracking of the client and resource info
sl@0
  1064
	//
sl@0
  1065
sl@0
  1066
	// First invocation to establish starting state
sl@0
  1067
#ifdef _DEBUG
sl@0
  1068
	gTest.Printf(_L("TestGetClientGetResourceInfo: First HelperGetClientResourceInfo call (starting state):\n"));
sl@0
  1069
#endif
sl@0
  1070
	if((r=HelperGetClientResourceInfo())!=KErrNone)
sl@0
  1071
		return r;
sl@0
  1072
sl@0
  1073
	// Second invocation - examine effect of adding a client
sl@0
  1074
	_LIT(tempStr3,"ExtraChan3");
sl@0
  1075
	TBufC<16> tempName3(tempStr3);
sl@0
  1076
	RBusDevResManUs channelFour;
sl@0
  1077
	if((r=OpenChannel(tempName3, channelFour))!=KErrNone)
sl@0
  1078
		return r;
sl@0
  1079
#ifdef _DEBUG
sl@0
  1080
	gTest.Printf(_L("TestGetClientGetResourceInfo: Second HelperGetClientResourceInfo call (added client ExtraChan3):\n"));
sl@0
  1081
#endif
sl@0
  1082
sl@0
  1083
	if((r=HelperGetClientResourceInfo())!=KErrNone)
sl@0
  1084
		return r;
sl@0
  1085
sl@0
  1086
	// Third invocation  - examine effect of new client requesting a level for a resource
sl@0
  1087
	// (This relies on getting and setting the state of gSharedResource - so skip the 
sl@0
  1088
	// test if this has not yet been identified
sl@0
  1089
	//
sl@0
  1090
	TUint startingLevel = 0;
sl@0
  1091
#ifdef _DEBUG
sl@0
  1092
	if((r=SetSharedResource())!=KErrNone)
sl@0
  1093
		return r;
sl@0
  1094
#endif
sl@0
  1095
	if(!gHaveSharedRes)
sl@0
  1096
		{
sl@0
  1097
		gTest.Printf(_L("TestGetClientGetResourceInfo: no suitable shareable resource, so skipping third call:\n"));
sl@0
  1098
		}
sl@0
  1099
	else
sl@0
  1100
		{
sl@0
  1101
		// Channel registration
sl@0
  1102
		gTest.Printf(_L("Initialise for temporary channel with arguments 1,1,0\n"));
sl@0
  1103
		if ((r=channelFour.Initialise(1,1,0))!=KErrNone)  // Just need 1 get and 1 set state
sl@0
  1104
			{
sl@0
  1105
			gTest.Printf(_L("Initialise for channel returned %d\n"),r);
sl@0
  1106
			return r;
sl@0
  1107
			}
sl@0
  1108
		// Get initial state
sl@0
  1109
		TRequestStatus status;
sl@0
  1110
		TBool cached = gUseCached;
sl@0
  1111
		TInt readValue;
sl@0
  1112
		TInt levelOwnerId = 0;
sl@0
  1113
		channelFour.GetResourceState(status,gSharedResource,cached,&readValue,&levelOwnerId);
sl@0
  1114
		User::WaitForRequest(status);
sl@0
  1115
		r=status.Int();
sl@0
  1116
		if(r != KErrNone)
sl@0
  1117
			{
sl@0
  1118
			gTest.Printf(_L("TestGetClientGetResourceInfo, first get state for shareable returned %d\n"),r);
sl@0
  1119
			return r;
sl@0
  1120
			}
sl@0
  1121
		startingLevel = (TUint)readValue;
sl@0
  1122
		// Write updated state
sl@0
  1123
		TUint newLevel = (TUint)(readValue + gSharedResStateDelta);
sl@0
  1124
		gTest.Printf(_L("TestGetClientGetResourceInfo: levelOwnerId = %d\n"), levelOwnerId);
sl@0
  1125
		gTest.Printf(_L("TestGetClientGetResourceInfo: shareable resource startingLevel=0x%x, writing 0x%x\n"), startingLevel, newLevel);
sl@0
  1126
		channelFour.ChangeResourceState(status,gSharedResource,newLevel);
sl@0
  1127
		User::WaitForRequest(status);
sl@0
  1128
		r=status.Int();
sl@0
  1129
		if(r != KErrNone)
sl@0
  1130
			{
sl@0
  1131
			gTest.Printf(_L("TestGetClientGetResourceInfo, first change state for shareable resource returned %d\n"),r);
sl@0
  1132
			return r;
sl@0
  1133
			}
sl@0
  1134
#ifdef _DEBUG
sl@0
  1135
		gTest.Printf(_L("TestGetClientGetResourceInfo: third HelperGetClientResourceInfo call (new client set level on shared resource):\n"));
sl@0
  1136
#endif
sl@0
  1137
		if((r=HelperGetClientResourceInfo())!=KErrNone)
sl@0
  1138
			return r;
sl@0
  1139
		}
sl@0
  1140
sl@0
  1141
sl@0
  1142
	// Fourth invocation - examine effect of orignal client requesting a level for 
sl@0
  1143
	// the Shared resource
sl@0
  1144
	if(gHaveSharedRes)
sl@0
  1145
		{
sl@0
  1146
		TRequestStatus status;
sl@0
  1147
		TBool cached = gUseCached;
sl@0
  1148
		TInt readValue;
sl@0
  1149
		TInt levelOwnerId;
sl@0
  1150
		gChannel.GetResourceState(status,gSharedResource,cached,&readValue,&levelOwnerId);
sl@0
  1151
		User::WaitForRequest(status);
sl@0
  1152
		r=status.Int();
sl@0
  1153
		if(r != KErrNone)
sl@0
  1154
			{
sl@0
  1155
			gTest.Printf(_L("TestGetClientGetResourceInfo, gChannel get state on Shareable resource returned %d\n"),r);
sl@0
  1156
			return r;
sl@0
  1157
			}
sl@0
  1158
		gTest.Printf(_L("TestGetClientGetResourceInfo, GetResourceState levelOwnerId =  %d\n"),levelOwnerId);		// Request a level on the resource
sl@0
  1159
		gChannel.ChangeResourceState(status,gSharedResource,(readValue+gSharedResStateDelta));
sl@0
  1160
		User::WaitForRequest(status);
sl@0
  1161
		if(status.Int() != KErrNone)
sl@0
  1162
			{
sl@0
  1163
			gTest.Printf(_L("TestGetClientGetResourceInfo, gChannel change state on Shareable returned %d\n"),r);
sl@0
  1164
			return r;
sl@0
  1165
			}
sl@0
  1166
#ifdef _DEBUG
sl@0
  1167
	gTest.Printf(_L("TestGetClientGetResourceInfo: fourth HelperGetClientResourceInfo call (gChannel set level on Shareable resource):\n"));
sl@0
  1168
#endif
sl@0
  1169
		if((r=HelperGetClientResourceInfo())!=KErrNone)
sl@0
  1170
		return r;
sl@0
  1171
		}
sl@0
  1172
sl@0
  1173
	// Return the resource to the state it was on function entry
sl@0
  1174
	if(gHaveSharedRes)
sl@0
  1175
		{
sl@0
  1176
		TRequestStatus status;
sl@0
  1177
		gTest.Printf(_L("TestGetClientGetResourceInfo: returning sharable resource to startingLevel=0x%x\n"), startingLevel);
sl@0
  1178
		gChannel.ChangeResourceState(status,gSharedResource,startingLevel);
sl@0
  1179
		User::WaitForRequest(status);
sl@0
  1180
		r=status.Int();
sl@0
  1181
		if(r != KErrNone)
sl@0
  1182
			{
sl@0
  1183
			gTest.Printf(_L("TestGetClientGetResourceInfo, attempt to reset shareable resource state returned %d\n"),r);
sl@0
  1184
			return r;
sl@0
  1185
			}
sl@0
  1186
		}
sl@0
  1187
sl@0
  1188
sl@0
  1189
	// Close the temporary channels
sl@0
  1190
	channelTwo.Close();
sl@0
  1191
	channelThree.Close();
sl@0
  1192
	channelFour.Close();
sl@0
  1193
sl@0
  1194
	return r;
sl@0
  1195
	}
sl@0
  1196
sl@0
  1197
sl@0
  1198
sl@0
  1199
//----------------------------------------------------------------------------------------------
sl@0
  1200
//! @SYMTestCaseID      KBASE-T_RESMANUS-0610
sl@0
  1201
//! @SYMTestType        UT
sl@0
  1202
//! @SYMPREQ            PREQ1398
sl@0
  1203
//! @SYMTestCaseDesc    This test case tests APIs for getting and setting the state of resources; 
sl@0
  1204
//!						it also tests APIs to cancel such requests.
sl@0
  1205
//! 
sl@0
  1206
//! @SYMTestActions     0) Call API to get the initial state of a selected resource.
sl@0
  1207
//! 
sl@0
  1208
//!						1) Call API to modify the state of the resource.
sl@0
  1209
//! 
sl@0
  1210
//!						2) Call API to get the new state of the resource and check it exhibits
sl@0
  1211
//!						the expected value.
sl@0
  1212
//! 
sl@0
  1213
//!						3) Call API to return the resource state to its original value.
sl@0
  1214
//! 
sl@0
  1215
//!						4) Call API to get the state of a long latency resource then call API
sl@0
  1216
//!						with operation-type qualifier cancel the request.
sl@0
  1217
//! 
sl@0
  1218
//!						5) Call API to modify the state of the long latency resource then call API
sl@0
  1219
//!						with operation-type qualifier to cancel the request.
sl@0
  1220
//! 
sl@0
  1221
//!						6) Call API to get the state of a long latency resource and wait for it 
sl@0
  1222
//!						to complete. Then call API with operation-type qualifier to cancel the request.
sl@0
  1223
//! 
sl@0
  1224
//!						7) Call API to modify the state of the long latency resource and wait for
sl@0
  1225
//!						it to complete. Then call API with operation-type qualifier to cancel the request.
sl@0
  1226
//! 
sl@0
  1227
//!						8) Call API to get the state of a long latency resource then call API
sl@0
  1228
//!						without operation-type qualifier to cancel the request.
sl@0
  1229
//! 
sl@0
  1230
//!						9) Call API to modify the state of the long latency resource then call API
sl@0
  1231
//!						without operation-type qualifier to cancel the request.
sl@0
  1232
//! 
sl@0
  1233
//!						10) Call API to get the state of a long latency resource and wait for it 
sl@0
  1234
//!						to complete. Then call API without operation-type qualifier to cancel the request.
sl@0
  1235
//! 
sl@0
  1236
//!						11) Call API to modify the state of the long latency resource and wait for
sl@0
  1237
//!						it to complete. Then call API without operation-type qualifier to cancel the request.
sl@0
  1238
//! 
sl@0
  1239
//!						12) Call API to get the state of a long latency resource 'n' times. Then call API with 
sl@0
  1240
//!						resource qualifier to cancel the requests.
sl@0
  1241
//! 
sl@0
  1242
//!						13) Call API to modify the state of a long latency resource 'm' times. Then call API with 
sl@0
  1243
//!						resource qualifier to cancel the requests.
sl@0
  1244
//! 
sl@0
  1245
//!						14) Call API to get the state of a long latency resource 'n' times and wait for them to complete.
sl@0
  1246
//!						Then call API with resource qualifier to cancel the requests.
sl@0
  1247
//! 
sl@0
  1248
//!						15) Call API to modify the state of a long latency resource 'm' times and wait for them to complete.
sl@0
  1249
//!						Then call API with resource qualifier to cancel the requests.
sl@0
  1250
//! 
sl@0
  1251
//!						16) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
sl@0
  1252
//!						a long latency resource 'm' times. Call the API to cancel the get operations with resource qualifier.
sl@0
  1253
//!						Wait for the operations to complete. Check the state of the associated TRequestStatus objects.
sl@0
  1254
//! 
sl@0
  1255
//!						17) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
sl@0
  1256
//!						a long latency resource 'm' times. Call the API to cancel the modify operations with resource qualifier.
sl@0
  1257
//!						Wait for the get operations to complete. Check the state of the associated TRequestStatus objects.
sl@0
  1258
//! 
sl@0
  1259
//!						18) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
sl@0
  1260
//!						a long latency resource 'm' times. Wait for the get operations to complete. Call the API to cancel the get
sl@0
  1261
//!						operations with resource qualifier. Check the state of the associated TRequestStatus objects.
sl@0
  1262
//! 
sl@0
  1263
//!						19) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
sl@0
  1264
//!						a long latency resource 'm' times. Wait for the modify operations to complete. Call the API to cancel the modify
sl@0
  1265
//!						operations with resource qualifier. Check the state of the associated TRequestStatus objects.
sl@0
  1266
//! 
sl@0
  1267
//!						20) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
sl@0
  1268
//!						a long latency resource 'm' times.
sl@0
  1269
//!						Then call API with operation-type qualifier to cancel the even-numbered get request(s).
sl@0
  1270
//!						Then call API without operation-type qualifier to cancel the even-numbered modify request(s).
sl@0
  1271
//!						Check the state of the associated TRequestStatus objects.
sl@0
  1272
//! 
sl@0
  1273
//! @SYMTestExpectedResults 0) The associated TRequestStatus object should indicate KErrNone, exits otherwise.
sl@0
  1274
//! 
sl@0
  1275
//!						1) The associated TRequestStatus object should indicate KErrNone, exits otherwise.
sl@0
  1276
//! 
sl@0
  1277
//!						2) The associated TRequestStatus object should indicate KErrNone, exits otherwise.
sl@0
  1278
//!						Exit if the value read back is not as expected.
sl@0
  1279
//! 
sl@0
  1280
//!						3) The associated TRequestStatus object should indicate KErrNone, exits otherwise.
sl@0
  1281
//! 
sl@0
  1282
//!						4) The associated TRequestStatus object should indicate KErrCancel if the cancel 
sl@0
  1283
//!						request was accepted, exits otherwise.
sl@0
  1284
//!						The associated TRequestStatus object should indicate KErrNone if the cancel request
sl@0
  1285
//!						was not accepted, exits otherwise.
sl@0
  1286
//! 
sl@0
  1287
//!						5) The associated TRequestStatus object should indicate KErrCancel if the cancel 
sl@0
  1288
//!						request was accepted, exits otherwise.
sl@0
  1289
//!						The associated TRequestStatus object should indicate KErrNone if the cancel request
sl@0
  1290
//!						was not accepted, exits otherwise.
sl@0
  1291
//! 
sl@0
  1292
//!						6) The TRequestStatus object associated with the get operation should indicate 
sl@0
  1293
//!						KErrNone - exits otherwise. The TRequestStatus object associated with the cancel
sl@0
  1294
//!						operation should indicate KErrNone - exits otherwise.
sl@0
  1295
//! 
sl@0
  1296
//!						7) The TRequestStatus object associated with the get operation should indicate
sl@0
  1297
//!						KErrNone - exits otherwise. The TRequestStatus object associated with the cancel
sl@0
  1298
//!						operation should indicate KErrNone - exits otherwise.
sl@0
  1299
//! 
sl@0
  1300
//!						8) The associated TRequestStatus object should indicate KErrCancel, exits otherwise.
sl@0
  1301
//! 
sl@0
  1302
//!						9) The associated TRequestStatus object should indicate KErrCancel, exits otherwise.
sl@0
  1303
//! 
sl@0
  1304
//!						10) The TRequestStatus object associated with the get operation should indicate 
sl@0
  1305
//!						KErrNone - exits otherwise. The TRequestStatus object associated with the cancel
sl@0
  1306
//!						operation should indicate KErrNone - exits otherwise.
sl@0
  1307
//! 
sl@0
  1308
//!						11) The TRequestStatus object associated with the get operation should indicate
sl@0
  1309
//!						KErrNone - exits otherwise. The TRequestStatus object associated with the cancel
sl@0
  1310
//!						operation should indicate KErrNone - exits otherwise.
sl@0
  1311
//!
sl@0
  1312
//!						12) The TRequestStatus objects should all exibit KErrCancel - exits otherwise.
sl@0
  1313
//! 
sl@0
  1314
//!						13) The TRequestStatus objects should all exibit KErrCancel - exits otherwise.
sl@0
  1315
//! 
sl@0
  1316
//!						14) The TRequestStatus objects associated with the get operations should all exibit KErrNone - exits otherwise.
sl@0
  1317
//!						The TRequestStatus objects associated with the cancel operations should all exibit KErrNone - exits otherwise
sl@0
  1318
//! 
sl@0
  1319
//!						15) The TRequestStatus objects associated with the modify operations should all exibit KErrNone - exits otherwise.
sl@0
  1320
//!						The TRequestStatus objects associated with the cancel operations should all exibit KErrNone - exits otherwise
sl@0
  1321
//! 
sl@0
  1322
//!						16) The TRequestStatus objects associated with the get operations should all exibit KErrCancel - exits otherwise.
sl@0
  1323
//!						The TRequestStatus objects associated with the modify operations should all exibit KErrNone - exits otherwise
sl@0
  1324
//! 
sl@0
  1325
//!						17) The TRequestStatus objects associated with the get operations should all exibit KErrNone - exits otherwise.
sl@0
  1326
//!						The TRequestStatus objects associated with the modify operations should all exibit KErrCancel - exits otherwise
sl@0
  1327
//! 
sl@0
  1328
//!						18) The TRequestStatus objects associated with the get and modify operations should all exibit KErrNone - exits otherwise.
sl@0
  1329
//! 
sl@0
  1330
//!						19) The TRequestStatus objects associated with the get and modify operations should all exibit KErrNone - exits otherwise.
sl@0
  1331
//!
sl@0
  1332
//!						20) The TRequestStatus objects associated with the even-numbered request should exhibit KErrCancel.
sl@0
  1333
//!						The TRequestStatus objects associated with the odd-numbered request should exhibit KErrNone.
sl@0
  1334
//!
sl@0
  1335
//! @SYMTestPriority        High
sl@0
  1336
//! @SYMTestStatus          Implemented
sl@0
  1337
//----------------------------------------------------------------------------------------------
sl@0
  1338
LOCAL_C TInt TestGetSetResourceStateOps()
sl@0
  1339
//
sl@0
  1340
// Test resource state access methods
sl@0
  1341
//
sl@0
  1342
	{
sl@0
  1343
	TInt r = KErrNone;
sl@0
  1344
sl@0
  1345
	TRequestStatus status;
sl@0
  1346
	TBool cached = gUseCached;
sl@0
  1347
	TInt readValue = 0;
sl@0
  1348
	TInt levelOwnerId = 0;
sl@0
  1349
	TInt testNo = 0;
sl@0
  1350
sl@0
  1351
#ifdef _DEBUG
sl@0
  1352
	// Ensure we have a resource we can use
sl@0
  1353
	if((r=SetAsyncResource())!=KErrNone)
sl@0
  1354
		return r;
sl@0
  1355
#endif
sl@0
  1356
sl@0
  1357
	// 0) Call API to get the initial state of a selected resource.
sl@0
  1358
	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
sl@0
  1359
	gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
sl@0
  1360
	User::WaitForRequest(status);
sl@0
  1361
	if(status.Int() != KErrNone)
sl@0
  1362
		{
sl@0
  1363
		gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r);
sl@0
  1364
		return r;
sl@0
  1365
		}
sl@0
  1366
	TUint startingLevel = (TUint)readValue;
sl@0
  1367
	gTest.Printf(_L("TestGetSetResourceStateOps: initial level read =0x%x, levelOwnerId = %d\n"),readValue,levelOwnerId);
sl@0
  1368
sl@0
  1369
	// 1) Call API to modify the state of the resource.
sl@0
  1370
	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
sl@0
  1371
	TUint newLevel = (TUint)(readValue + gAsyncResStateDelta);
sl@0
  1372
	gTest.Printf(_L("TestGetSetResourceStateOps: writing 0x%x\n"), newLevel);
sl@0
  1373
	gChannel.ChangeResourceState(status,gLongLatencyResource,newLevel);
sl@0
  1374
	User::WaitForRequest(status);
sl@0
  1375
	if(status.Int() != KErrNone)
sl@0
  1376
		{
sl@0
  1377
		gTest.Printf(_L("TestGetSetResourceStateOps, first change state returned %d\n"),r);
sl@0
  1378
		return r;
sl@0
  1379
		}
sl@0
  1380
sl@0
  1381
	// 2) Call API to get the new state of the resource and check it exhibits the expected value.
sl@0
  1382
	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
sl@0
  1383
	gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
sl@0
  1384
	User::WaitForRequest(status);
sl@0
  1385
	if(status.Int() != KErrNone)
sl@0
  1386
		{
sl@0
  1387
		gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r);
sl@0
  1388
		return r;
sl@0
  1389
		}
sl@0
  1390
	gTest.Printf(_L("TestGetSetResourceStateOps: level read back =0x%x, levelOwnerId=%d\n"),readValue,levelOwnerId);
sl@0
  1391
	gTest(newLevel==(TUint)readValue);
sl@0
  1392
sl@0
  1393
	// 3) Call API to return the resource state to its original value.
sl@0
  1394
	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
sl@0
  1395
	gTest.Printf(_L("TestGetSetResourceStateOps: write original level 0x%x\n"), startingLevel);
sl@0
  1396
	gChannel.ChangeResourceState(status,gLongLatencyResource,startingLevel);
sl@0
  1397
	User::WaitForRequest(status);
sl@0
  1398
	if(status.Int() != KErrNone)
sl@0
  1399
		{
sl@0
  1400
		gTest.Printf(_L("TestGetSetResourceStateOps, change state status = %d\n"),r);
sl@0
  1401
		return r;
sl@0
  1402
		}
sl@0
  1403
	gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
sl@0
  1404
	User::WaitForRequest(status);
sl@0
  1405
	if(status.Int() != KErrNone)
sl@0
  1406
		{
sl@0
  1407
		gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r);
sl@0
  1408
		return r;
sl@0
  1409
		}
sl@0
  1410
	gTest.Printf(_L("TestGetSetResourceStateOps: check original level read back =0x%x, levelOwnerId=%d\n"),readValue,levelOwnerId);
sl@0
  1411
sl@0
  1412
	// 4) Call API to get the state of a long latency resource then call API with operation-type qualifier cancel the request.
sl@0
  1413
	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
sl@0
  1414
	gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
sl@0
  1415
	r=gChannel.CancelGetResourceState(status);
sl@0
  1416
	if(r!=KErrInUse)
sl@0
  1417
		{
sl@0
  1418
		gTest.Printf(_L("TestGetSetResourceStateOps, CancelGetResourceState returned %d\n"),r);
sl@0
  1419
		}
sl@0
  1420
	if(r!=KErrCompletion) // If request had not completed before cancellation request
sl@0
  1421
		{
sl@0
  1422
		User::WaitForRequest(status);
sl@0
  1423
		if(r==KErrNone)	// Cancel expected to proceed as requested
sl@0
  1424
			{
sl@0
  1425
			if(status.Int() != KErrCancel)
sl@0
  1426
				{
sl@0
  1427
				gTest.Printf(_L("TestGetSetResourceStateOps, expected KErrCancel but cancelled get state status = %d\n"),r);
sl@0
  1428
				return r;
sl@0
  1429
				}
sl@0
  1430
			}
sl@0
  1431
		else if(r==KErrInUse)	// Cancel failed since request was being processed - so expect successful completion
sl@0
  1432
			{
sl@0
  1433
			if(status.Int() != KErrNone)
sl@0
  1434
				{
sl@0
  1435
				gTest.Printf(_L("TestGetSetResourceStateOps, expected KErrNone but cancelled get state status = %d\n"),r);
sl@0
  1436
				return r;
sl@0
  1437
				}
sl@0
  1438
			}
sl@0
  1439
		else if(status.Int() != KErrCancel)	// Just report the error code and return
sl@0
  1440
			{
sl@0
  1441
			gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status = %d\n"),r);
sl@0
  1442
			return r;
sl@0
  1443
			}
sl@0
  1444
sl@0
  1445
		}
sl@0
  1446
sl@0
  1447
	// 5) Call API to modify the state of the long latency resource then call API with operation-type qualifier to cancel the request.
sl@0
  1448
	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
sl@0
  1449
	newLevel = (TUint)(readValue + gAsyncResStateDelta);
sl@0
  1450
	gChannel.ChangeResourceState(status,gLongLatencyResource,newLevel);
sl@0
  1451
	r=gChannel.CancelChangeResourceState(status);
sl@0
  1452
	if(r!=KErrInUse)
sl@0
  1453
		{
sl@0
  1454
		gTest.Printf(_L("TestGetSetResourceStateOps, CancelChangeResourceState returned %d\n"),r);
sl@0
  1455
		}
sl@0
  1456
	if(r!=KErrCompletion) // If request had not completed before cancellation request
sl@0
  1457
		{
sl@0
  1458
		User::WaitForRequest(status);
sl@0
  1459
		if(r==KErrNone)	// Cancel expected to proceed as requested
sl@0
  1460
			{
sl@0
  1461
			if(status.Int() != KErrCancel)
sl@0
  1462
				{
sl@0
  1463
				gTest.Printf(_L("TestGetSetResourceStateOps, expected KErrCancel but cancelled get state status = %d\n"),r);
sl@0
  1464
				return r;
sl@0
  1465
				}
sl@0
  1466
			}
sl@0
  1467
		else if(r==KErrInUse)	// Cancel failed since request was being processed - so expect successful completion
sl@0
  1468
			{
sl@0
  1469
			if(status.Int() != KErrNone)
sl@0
  1470
				{
sl@0
  1471
				gTest.Printf(_L("TestGetSetResourceStateOps, expected KErrNone but cancelled get state status = %d\n"),r);
sl@0
  1472
				return r;
sl@0
  1473
				}
sl@0
  1474
			}
sl@0
  1475
		else if(status.Int() != KErrCancel)	// Just report the error code and return
sl@0
  1476
			{
sl@0
  1477
			gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status = %d\n"),r);
sl@0
  1478
			return r;
sl@0
  1479
			}
sl@0
  1480
		}
sl@0
  1481
sl@0
  1482
sl@0
  1483
	// 6) Call API to get the state of a long latency resource and wait for it to complete.
sl@0
  1484
	//    Then call API with operation-type qualifier to cancel the request.	
sl@0
  1485
	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
sl@0
  1486
	gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
sl@0
  1487
	User::WaitForRequest(status);
sl@0
  1488
	if(status.Int() != KErrNone)
sl@0
  1489
		{
sl@0
  1490
		gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r);
sl@0
  1491
		return r;
sl@0
  1492
		}
sl@0
  1493
	r=gChannel.CancelGetResourceState(status);
sl@0
  1494
	if(r!=KErrNone)
sl@0
  1495
		{
sl@0
  1496
		gTest.Printf(_L("TestGetSetResourceStateOps, CancelGetResourceState returned %d\n"),r);
sl@0
  1497
		}
sl@0
  1498
	if(status.Int() != KErrNone)	// TRequestStatus should be unchanged
sl@0
  1499
		{
sl@0
  1500
		gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled get state status = %d\n"),r);
sl@0
  1501
		return r;
sl@0
  1502
		}
sl@0
  1503
sl@0
  1504
	// 7) Call API to modify the state of the long latency resource and wait for it to complete. 
sl@0
  1505
	//    Then call API with operation-type qualifier to cancel the request.
sl@0
  1506
	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
sl@0
  1507
	gChannel.ChangeResourceState(status,gLongLatencyResource,(readValue + gAsyncResStateDelta));
sl@0
  1508
	User::WaitForRequest(status);
sl@0
  1509
	if(status.Int() != KErrNone)
sl@0
  1510
		{
sl@0
  1511
		gTest.Printf(_L("TestGetSetResourceStateOps, change state status = %d\n"),r);
sl@0
  1512
		return r;
sl@0
  1513
		}
sl@0
  1514
	r=gChannel.CancelChangeResourceState(status);
sl@0
  1515
	if(r!=KErrNone)
sl@0
  1516
		{
sl@0
  1517
		gTest.Printf(_L("TestGetSetResourceStateOps, CancelChangeResourceState returned %d\n"),r);
sl@0
  1518
		}
sl@0
  1519
	if(status.Int() != KErrNone)	// TRequestStatus should be unchanged
sl@0
  1520
		{
sl@0
  1521
		gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled change state status = %d\n"),r);
sl@0
  1522
		return r;
sl@0
  1523
		}
sl@0
  1524
sl@0
  1525
	// 8) Call API to get the state of a long latency resource then call API without operation-type qualifier to cancel the request.
sl@0
  1526
	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
sl@0
  1527
	gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
sl@0
  1528
	gChannel.CancelAsyncOperation(&status);
sl@0
  1529
	User::WaitForRequest(status);
sl@0
  1530
	if(status.Int() != KErrCancel)
sl@0
  1531
		{
sl@0
  1532
		gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status = %d\n"),r);
sl@0
  1533
		return r;
sl@0
  1534
		}
sl@0
  1535
sl@0
  1536
	// 9) Call API to modify the state of the long latency resource then call API without operation-type qualifier to cancel the request.
sl@0
  1537
	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
sl@0
  1538
	newLevel = (TUint)(readValue + gAsyncResStateDelta);
sl@0
  1539
	gChannel.ChangeResourceState(status,gLongLatencyResource,newLevel);
sl@0
  1540
	gChannel.CancelAsyncOperation(&status);
sl@0
  1541
	User::WaitForRequest(status);
sl@0
  1542
	if(status.Int() != KErrCancel)
sl@0
  1543
		{
sl@0
  1544
		gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status = %d\n"),r);
sl@0
  1545
		return r;
sl@0
  1546
		}
sl@0
  1547
sl@0
  1548
	// 10) Call API to get the state of a long latency resource and wait for it to complete.
sl@0
  1549
	//     Then call API without operation-type qualifier to cancel the request.
sl@0
  1550
	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
sl@0
  1551
	gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
sl@0
  1552
	User::WaitForRequest(status);
sl@0
  1553
	if(status.Int() != KErrNone)
sl@0
  1554
		{
sl@0
  1555
		gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r);
sl@0
  1556
		return r;
sl@0
  1557
		}
sl@0
  1558
	gChannel.CancelAsyncOperation(&status);
sl@0
  1559
	if(status.Int() != KErrNone)	// TRequestStatus should be unchanged
sl@0
  1560
		{
sl@0
  1561
		gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled get state status = %d\n"),r);
sl@0
  1562
		return r;
sl@0
  1563
		}
sl@0
  1564
sl@0
  1565
	// 11) Call API to modify the state of the long latency resource and wait for it to complete. 
sl@0
  1566
	//     Then call API without operation-type qualifier to cancel the request.
sl@0
  1567
	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
sl@0
  1568
	gChannel.ChangeResourceState(status,gLongLatencyResource,(readValue + gAsyncResStateDelta));
sl@0
  1569
	User::WaitForRequest(status);
sl@0
  1570
	if(status.Int() != KErrNone)
sl@0
  1571
		{
sl@0
  1572
		gTest.Printf(_L("TestGetSetResourceStateOps, change state status = %d\n"),r);
sl@0
  1573
		return r;
sl@0
  1574
		}
sl@0
  1575
	gChannel.CancelAsyncOperation(&status);
sl@0
  1576
	if(status.Int() != KErrNone)	// TRequestStatus should be unchanged
sl@0
  1577
		{
sl@0
  1578
		gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled change state status = %d\n"),r);
sl@0
  1579
		return r;
sl@0
  1580
		}
sl@0
  1581
sl@0
  1582
	// 'n' and 'm' values and support for cancellation of multiple requests
sl@0
  1583
	const TInt KLoopVarN = 2;
sl@0
  1584
	const TInt KLoopVarM = 3;
sl@0
  1585
	TRequestStatus getReqStatus[KLoopVarN];
sl@0
  1586
	TRequestStatus setReqStatus[KLoopVarM];
sl@0
  1587
	TInt i=0;
sl@0
  1588
sl@0
  1589
	// 12) Call API to get the state of a long latency resource 'n' times. 
sl@0
  1590
	//     Then call API with resource qualifier to cancel the requests.
sl@0
  1591
	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
sl@0
  1592
	for(i=0;i<KLoopVarN;i++)
sl@0
  1593
		{
sl@0
  1594
		gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId);
sl@0
  1595
		}
sl@0
  1596
	gChannel.CancelGetResourceStateRequests(gLongLatencyResource);
sl@0
  1597
	for(i=0;i<KLoopVarN;i++)
sl@0
  1598
		{
sl@0
  1599
		User::WaitForRequest(getReqStatus[i]);
sl@0
  1600
		if((r=getReqStatus[i].Int()) != KErrCancel)
sl@0
  1601
			{
sl@0
  1602
			gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status[%d] = %d\n"),i,r);
sl@0
  1603
			return r;
sl@0
  1604
			}
sl@0
  1605
		}
sl@0
  1606
sl@0
  1607
	// 13) Call API to modify the state of a long latency resource 'm' times. 
sl@0
  1608
	//     Then call API with resource qualifier to cancel the requests.
sl@0
  1609
	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
sl@0
  1610
	for(i=0;i<KLoopVarM;i++)
sl@0
  1611
		{
sl@0
  1612
		gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta));
sl@0
  1613
		}
sl@0
  1614
	gChannel.CancelChangeResourceStateRequests(gLongLatencyResource);
sl@0
  1615
	for(i=0;i<KLoopVarM;i++)
sl@0
  1616
		{
sl@0
  1617
		User::WaitForRequest(setReqStatus[i]);
sl@0
  1618
		if((r=setReqStatus[i].Int()) != KErrCancel)
sl@0
  1619
			{
sl@0
  1620
			gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status[%d] = %d\n"),i,r);
sl@0
  1621
			return r;
sl@0
  1622
			}
sl@0
  1623
		}
sl@0
  1624
sl@0
  1625
	// 14) Call API to get the state of a long latency resource 'n' times and wait for them to complete.
sl@0
  1626
	//     Then call API with resource qualifier to cancel the requests.
sl@0
  1627
	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
sl@0
  1628
	for(i=0;i<KLoopVarN;i++)
sl@0
  1629
		{
sl@0
  1630
		gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId);
sl@0
  1631
		}
sl@0
  1632
	for(i=0;i<KLoopVarN;i++)
sl@0
  1633
		{
sl@0
  1634
		User::WaitForRequest(getReqStatus[i]);
sl@0
  1635
		if((r=getReqStatus[i].Int()) != KErrNone)
sl@0
  1636
			{
sl@0
  1637
			gTest.Printf(_L("TestGetSetResourceStateOps, before cancel get state status[%d] = %d\n"),i,r);
sl@0
  1638
			return r;
sl@0
  1639
			}
sl@0
  1640
		}
sl@0
  1641
	gChannel.CancelGetResourceStateRequests(gLongLatencyResource);
sl@0
  1642
	for(i=0;i<KLoopVarN;i++)
sl@0
  1643
		{
sl@0
  1644
		if((r=getReqStatus[i].Int()) != KErrNone)
sl@0
  1645
			{
sl@0
  1646
			gTest.Printf(_L("TestGetSetResourceStateOps, after cancel get state status[%d] = %d\n"),i,r);
sl@0
  1647
			return r;
sl@0
  1648
			}
sl@0
  1649
		}
sl@0
  1650
sl@0
  1651
	// 15) Call API to modify the state of a long latency resource 'm' times and wait for them to complete.
sl@0
  1652
	//     Then call API with resource qualifier to cancel the requests.
sl@0
  1653
	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
sl@0
  1654
	for(i=0;i<KLoopVarM;i++)
sl@0
  1655
		{
sl@0
  1656
		gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta));
sl@0
  1657
		}
sl@0
  1658
	for(i=0;i<KLoopVarM;i++)
sl@0
  1659
		{
sl@0
  1660
		User::WaitForRequest(setReqStatus[i]);
sl@0
  1661
		if((r=setReqStatus[i].Int()) != KErrNone)
sl@0
  1662
			{
sl@0
  1663
			gTest.Printf(_L("TestGetSetResourceStateOps, before cancel change state status[%d] = %d\n"),i,r);
sl@0
  1664
			return r;
sl@0
  1665
			}
sl@0
  1666
		}
sl@0
  1667
	gChannel.CancelChangeResourceStateRequests(gLongLatencyResource);
sl@0
  1668
	for(i=0;i<KLoopVarM;i++)
sl@0
  1669
		{
sl@0
  1670
		if((r=setReqStatus[i].Int()) != KErrNone)
sl@0
  1671
			{
sl@0
  1672
			gTest.Printf(_L("TestGetSetResourceStateOps, after cancel change state status[%d] = %d\n"),i,r);
sl@0
  1673
			return r;
sl@0
  1674
			}
sl@0
  1675
		}
sl@0
  1676
sl@0
  1677
	// 16) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
sl@0
  1678
	//     a long latency resource 'm' times. 
sl@0
  1679
	//     Call the API to cancel the get operations with resource qualifier.
sl@0
  1680
	//     Wait for the operations to complete. Check the state of the associated TRequestStatus objects.
sl@0
  1681
	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
sl@0
  1682
	for(i=0;i<KLoopVarN;i++)
sl@0
  1683
		{
sl@0
  1684
		gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId);
sl@0
  1685
		}
sl@0
  1686
	for(i=0;i<KLoopVarM;i++)
sl@0
  1687
		{
sl@0
  1688
		gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta));
sl@0
  1689
		}
sl@0
  1690
	gChannel.CancelGetResourceStateRequests(gLongLatencyResource);
sl@0
  1691
	for(i=0;i<KLoopVarN;i++)
sl@0
  1692
		{
sl@0
  1693
		User::WaitForRequest(getReqStatus[i]);
sl@0
  1694
		if((r=getReqStatus[i].Int()) != KErrCancel)
sl@0
  1695
			{
sl@0
  1696
			gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status[%d] = %d\n"),i,r);
sl@0
  1697
			return r;
sl@0
  1698
			}
sl@0
  1699
		}
sl@0
  1700
	for(i=0;i<KLoopVarM;i++)
sl@0
  1701
		{
sl@0
  1702
		User::WaitForRequest(setReqStatus[i]);
sl@0
  1703
		if((r=setReqStatus[i].Int()) != KErrNone)
sl@0
  1704
			{
sl@0
  1705
			gTest.Printf(_L("TestGetSetResourceStateOps, completed  change state status[%d] = %d\n"),i,r);
sl@0
  1706
			return r;
sl@0
  1707
			}
sl@0
  1708
		}
sl@0
  1709
sl@0
  1710
	// 17) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
sl@0
  1711
	//     a long latency resource 'm' times. 
sl@0
  1712
	//     Call the API to cancel the modify operations with resource qualifier.
sl@0
  1713
	//     Wait for the get operations to complete. Check the state of the associated TRequestStatus objects.
sl@0
  1714
	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
sl@0
  1715
	for(i=0;i<KLoopVarN;i++)
sl@0
  1716
		{
sl@0
  1717
		gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId);
sl@0
  1718
		}
sl@0
  1719
	for(i=0;i<KLoopVarM;i++)
sl@0
  1720
		{
sl@0
  1721
		gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta));
sl@0
  1722
		}
sl@0
  1723
	gChannel.CancelChangeResourceStateRequests(gLongLatencyResource);
sl@0
  1724
	for(i=0;i<KLoopVarN;i++)
sl@0
  1725
		{
sl@0
  1726
		User::WaitForRequest(getReqStatus[i]);
sl@0
  1727
		if((r=getReqStatus[i].Int()) != KErrNone)
sl@0
  1728
			{
sl@0
  1729
			gTest.Printf(_L("TestGetSetResourceStateOps, completed get state status[%d] = %d\n"),i,r);
sl@0
  1730
			return r;
sl@0
  1731
			}
sl@0
  1732
		}
sl@0
  1733
	for(i=0;i<KLoopVarM;i++)
sl@0
  1734
		{
sl@0
  1735
		User::WaitForRequest(setReqStatus[i]);
sl@0
  1736
		if((r=setReqStatus[i].Int()) != KErrCancel)
sl@0
  1737
			{
sl@0
  1738
			gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status[%d] = %d\n"),i,r);
sl@0
  1739
			return r;
sl@0
  1740
			}
sl@0
  1741
		}
sl@0
  1742
sl@0
  1743
	// 18) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
sl@0
  1744
	//     a long latency resource 'm' times. Wait for the get operations to complete. 
sl@0
  1745
	//     Call the API to cancel the get operations with resource qualifier. Check the state of the associated TRequestStatus objects.
sl@0
  1746
	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
sl@0
  1747
	for(i=0;i<KLoopVarN;i++)
sl@0
  1748
		{
sl@0
  1749
		gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId);
sl@0
  1750
		}
sl@0
  1751
	TInt flipper = -1;
sl@0
  1752
	for(i=0;i<KLoopVarM;i++)
sl@0
  1753
		{
sl@0
  1754
		gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + (flipper*gAsyncResStateDelta)));
sl@0
  1755
		flipper*=-1;
sl@0
  1756
		}
sl@0
  1757
	for(i=0;i<KLoopVarN;i++)
sl@0
  1758
		{
sl@0
  1759
		User::WaitForRequest(getReqStatus[i]);
sl@0
  1760
		if((r=getReqStatus[i].Int()) != KErrNone)
sl@0
  1761
			{
sl@0
  1762
			gTest.Printf(_L("TestGetSetResourceStateOps, completed get state status[%d] = %d\n"),i,r);
sl@0
  1763
			return r;
sl@0
  1764
			}
sl@0
  1765
		}
sl@0
  1766
	gChannel.CancelGetResourceStateRequests(gLongLatencyResource);
sl@0
  1767
	for(i=0;i<KLoopVarM;i++)
sl@0
  1768
		{
sl@0
  1769
		User::WaitForRequest(setReqStatus[i]);
sl@0
  1770
		if((r=setReqStatus[i].Int()) != KErrNone)
sl@0
  1771
			{
sl@0
  1772
			gTest.Printf(_L("TestGetSetResourceStateOps, completed change state status[%d]= %d\n"),i,r);
sl@0
  1773
			return r;
sl@0
  1774
			}
sl@0
  1775
		}
sl@0
  1776
	for(i=0;i<KLoopVarN;i++)
sl@0
  1777
		{
sl@0
  1778
		if((r=getReqStatus[i].Int()) != KErrNone)
sl@0
  1779
			{
sl@0
  1780
			gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled get state status[%d]= %d\n"),i,r);
sl@0
  1781
			return r;
sl@0
  1782
			}
sl@0
  1783
		}
sl@0
  1784
sl@0
  1785
	// 19) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
sl@0
  1786
	//     a long latency resource 'm' times. Wait for the modify operations to complete. Call the API to cancel the modify
sl@0
  1787
	//     operations with resource qualifier. Check the state of the associated TRequestStatus objects.
sl@0
  1788
	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
sl@0
  1789
	for(i=0;i<KLoopVarN;i++)
sl@0
  1790
		{
sl@0
  1791
		gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId);
sl@0
  1792
		}
sl@0
  1793
	for(i=0;i<KLoopVarM;i++)
sl@0
  1794
		{
sl@0
  1795
		gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta));
sl@0
  1796
		}
sl@0
  1797
	for(i=0;i<KLoopVarM;i++)
sl@0
  1798
		{
sl@0
  1799
		User::WaitForRequest(setReqStatus[i]);
sl@0
  1800
		if((r=setReqStatus[i].Int()) != KErrNone)
sl@0
  1801
			{
sl@0
  1802
			gTest.Printf(_L("TestGetSetResourceStateOps, completed change state status[%d] = %d\n"),i,r);
sl@0
  1803
			return r;
sl@0
  1804
			}
sl@0
  1805
		}
sl@0
  1806
	gChannel.CancelChangeResourceStateRequests(gLongLatencyResource);
sl@0
  1807
	for(i=0;i<KLoopVarN;i++)
sl@0
  1808
		{
sl@0
  1809
		User::WaitForRequest(getReqStatus[i]);
sl@0
  1810
		if((r=getReqStatus[i].Int()) != KErrNone)
sl@0
  1811
			{
sl@0
  1812
			gTest.Printf(_L("TestGetSetResourceStateOps, completed get state status[%d] = %d\n"),i,r);
sl@0
  1813
			return r;
sl@0
  1814
			}
sl@0
  1815
		}
sl@0
  1816
	for(i=0;i<KLoopVarM;i++)
sl@0
  1817
		{
sl@0
  1818
		if((r=setReqStatus[i].Int()) != KErrNone)
sl@0
  1819
			{
sl@0
  1820
			gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status[%d] = %d\n"),i,r);
sl@0
  1821
			return r;
sl@0
  1822
			}
sl@0
  1823
		}
sl@0
  1824
sl@0
  1825
	// 20) Call API to get the state of a long latency resource 'n' times, call API to modify the state of a long latency resource 'm' times.
sl@0
  1826
	//     Then call API without operation-type qualifier to cancel the even-numbered modify request(s).
sl@0
  1827
	//     Then call API with operation-type qualifier to cancel the even-numbered get request(s).
sl@0
  1828
	//     Check the state of the associated TRequestStatus objects.
sl@0
  1829
	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
sl@0
  1830
	for(i=0;i<KLoopVarN;i++)
sl@0
  1831
		{
sl@0
  1832
		gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId);
sl@0
  1833
		}
sl@0
  1834
	for(i=0;i<KLoopVarM;i++)
sl@0
  1835
		{
sl@0
  1836
		gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta));
sl@0
  1837
		}
sl@0
  1838
	for(i=0;i<KLoopVarM;i+=2)
sl@0
  1839
		{
sl@0
  1840
		gChannel.CancelAsyncOperation(&(setReqStatus[i]));
sl@0
  1841
		}
sl@0
  1842
	for(i=0;i<KLoopVarN;i+=2)
sl@0
  1843
		{
sl@0
  1844
		r=gChannel.CancelGetResourceState(getReqStatus[i]);
sl@0
  1845
		if(r!=KErrNone)
sl@0
  1846
			{
sl@0
  1847
			gTest.Printf(_L("TestGetSetResourceStateOps, CancelGetResourceState for index %d returned %d\n"),i,r);
sl@0
  1848
			return r;
sl@0
  1849
			}
sl@0
  1850
		}
sl@0
  1851
	for(i=0;i<KLoopVarM;i++)
sl@0
  1852
		{
sl@0
  1853
		User::WaitForRequest(setReqStatus[i]);
sl@0
  1854
		if((r=setReqStatus[i].Int()) != KErrCancel)
sl@0
  1855
			{
sl@0
  1856
			gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status[%d] = %d\n"),i,r);
sl@0
  1857
			return r;
sl@0
  1858
			}
sl@0
  1859
		if(++i >= KLoopVarM)
sl@0
  1860
			break;
sl@0
  1861
		User::WaitForRequest(setReqStatus[i]);
sl@0
  1862
		if((r=setReqStatus[i].Int()) != KErrNone)
sl@0
  1863
			{
sl@0
  1864
			gTest.Printf(_L("TestGetSetResourceStateOps, completed change state status[%d] = %d\n"),i,r);
sl@0
  1865
			return r;
sl@0
  1866
			}
sl@0
  1867
		}
sl@0
  1868
	for(i=0;i<KLoopVarN;i++)
sl@0
  1869
		{
sl@0
  1870
		User::WaitForRequest(getReqStatus[i]);
sl@0
  1871
		if((r=getReqStatus[i].Int()) != KErrCancel)
sl@0
  1872
			{
sl@0
  1873
			gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status[%d] = %d\n"),i,r);
sl@0
  1874
			return r;
sl@0
  1875
			}
sl@0
  1876
		if(++i >= KLoopVarN)
sl@0
  1877
			break;
sl@0
  1878
		User::WaitForRequest(getReqStatus[i]);
sl@0
  1879
		if((r=getReqStatus[i].Int()) != KErrNone)
sl@0
  1880
			{
sl@0
  1881
			gTest.Printf(_L("TestGetSetResourceStateOps, completed get state status[%d] = %d\n"),i,r);
sl@0
  1882
			return r;
sl@0
  1883
			}
sl@0
  1884
		}	
sl@0
  1885
	return KErrNone;
sl@0
  1886
	}
sl@0
  1887
sl@0
  1888
sl@0
  1889
//----------------------------------------------------------------------------------------------
sl@0
  1890
//! @SYMTestCaseID      KBASE-T_RESMANUS-0611
sl@0
  1891
//! @SYMTestType        UT
sl@0
  1892
//! @SYMPREQ            PREQ1398
sl@0
  1893
//! @SYMTestCaseDesc    This test case tests APIs for regulating getting and setting the state of resources 
sl@0
  1894
//! 
sl@0
  1895
//! @SYMTestActions     0) Issue the maximum number (requested in the call to the Initialise API)
sl@0
  1896
//!						of requests to get the current state of a resource. Then issue one further request.
sl@0
  1897
//!
sl@0
  1898
//!						1) Issue the maximum number (requested in the call to the Initialise API) of 
sl@0
  1899
//!						requests to set the current state of a resource. Then issue one further request.
sl@0
  1900
//!
sl@0
  1901
//! @SYMTestExpectedResults 0) Test that the TRequestStatus object associated with the last request
sl@0
  1902
//!							exhibits status code KErrUnderflow - exit otherwise. Test that the 
sl@0
  1903
//!							TRequestStatus objects associated with the preceding requests exhibit 
sl@0
  1904
//!							status code KErrNone - exit otherwise.
sl@0
  1905
//!
sl@0
  1906
//!							1) Test that the TRequestStatus object associated with the last request
sl@0
  1907
//!							exhibits status code KErrUnderflow - exit otherwise. Test that the 
sl@0
  1908
//!							TRequestStatus objects associated with the preceding requests exhibit 
sl@0
  1909
//!							status code KErrNone - exit otherwise.
sl@0
  1910
//!
sl@0
  1911
//! @SYMTestPriority        High
sl@0
  1912
//! @SYMTestStatus          Implemented
sl@0
  1913
//----------------------------------------------------------------------------------------------
sl@0
  1914
LOCAL_C TInt TestGetSetResourceStateQuota()
sl@0
  1915
//
sl@0
  1916
// Test resource state access quota management
sl@0
  1917
//
sl@0
  1918
	{
sl@0
  1919
	TUint resourceId;
sl@0
  1920
sl@0
  1921
	// To perform the quota test we need a long latency resource
sl@0
  1922
	// If one has not been defined alert the user and return
sl@0
  1923
	if(!gHaveAsyncRes)
sl@0
  1924
		{
sl@0
  1925
		gTest.Printf(_L("TestGetSetResourceStateQuota: don't have suitable asynchronous resource ... exiting\n"));
sl@0
  1926
		return KErrNone;
sl@0
  1927
		}
sl@0
  1928
	else
sl@0
  1929
		resourceId = gLongLatencyResource;
sl@0
  1930
sl@0
  1931
	TInt r = KErrNone;
sl@0
  1932
	TBool lastErr = KErrNone;
sl@0
  1933
sl@0
  1934
	TInt i = 0;
sl@0
  1935
	TRequestStatus status[MAX_NUM_REQUESTS];
sl@0
  1936
	TInt state[MAX_NUM_REQUESTS];
sl@0
  1937
	TBool cached = gUseCached;
sl@0
  1938
	TInt levelOwnerId = 0;
sl@0
  1939
sl@0
  1940
	//
sl@0
  1941
	//	Test GetResourceState - check client can not exceed quota of requests
sl@0
  1942
	//
sl@0
  1943
    gTest.Printf(_L("**Test GetResourceState (quota management)\n"));
sl@0
  1944
sl@0
  1945
	// KNoOfGetStateRequests Get state requests (of the same resource, ID=1) to consume the client quota
sl@0
  1946
	for(i=0; i<KNoOfGetStateRequests; i++)
sl@0
  1947
		gChannel.GetResourceState(status[i],resourceId,cached,&(state[i]),&levelOwnerId);
sl@0
  1948
sl@0
  1949
	// Addition Get state request to exceed the quota - the provided TRequestStatus
sl@0
  1950
	// object should indicate KErrUnderflow
sl@0
  1951
	gChannel.GetResourceState(status[KNoOfGetStateRequests],resourceId,cached,&(state[KNoOfGetStateRequests]),&levelOwnerId);
sl@0
  1952
	User::WaitForRequest(status[KNoOfGetStateRequests]);
sl@0
  1953
	if(status[KNoOfGetStateRequests].Int() != KErrUnderflow)
sl@0
  1954
		{
sl@0
  1955
		gTest.Printf(_L("TestGetSetResourceStateQuota, extra get state returned %d\n"),r);
sl@0
  1956
		return r;
sl@0
  1957
		}
sl@0
  1958
sl@0
  1959
	// Need to check the TRequestStatus objects
sl@0
  1960
	for(i=0; i<KNoOfGetStateRequests; i++)
sl@0
  1961
		{
sl@0
  1962
		User::WaitForRequest(status[i]);
sl@0
  1963
		if((r=status[i].Int()) != KErrNone)
sl@0
  1964
			{
sl@0
  1965
			gTest.Printf(_L("TestGetSetResourceStateQuota, get state %d returned %d\n"),i, r);
sl@0
  1966
			lastErr = r;
sl@0
  1967
			}
sl@0
  1968
		}
sl@0
  1969
	if(lastErr != KErrNone)
sl@0
  1970
		return lastErr;
sl@0
  1971
sl@0
  1972
	//
sl@0
  1973
	//	Test ChangeResourceState - check client can not exceed quota of requests
sl@0
  1974
	//
sl@0
  1975
    gTest.Printf(_L("**Test ChangeResourceState (quota management)\n"));
sl@0
  1976
sl@0
  1977
	// KNoOfSetStateRequests Set state requests (of the same resource, ID=1) to consume the client quota
sl@0
  1978
	TInt newState = (state[1])+1;
sl@0
  1979
	for(i=0; i<KNoOfSetStateRequests; i++)
sl@0
  1980
		{
sl@0
  1981
		gChannel.ChangeResourceState(status[i],resourceId,newState);
sl@0
  1982
		}
sl@0
  1983
sl@0
  1984
	// Addition Set state request to exceed the quota - the provided TRequestStatus
sl@0
  1985
	// object should indicate KErrUnderflow
sl@0
  1986
	gChannel.ChangeResourceState(status[KNoOfSetStateRequests],resourceId,newState);
sl@0
  1987
	User::WaitForRequest(status[KNoOfSetStateRequests]);
sl@0
  1988
	if(status[KNoOfSetStateRequests].Int() != KErrUnderflow)
sl@0
  1989
		{
sl@0
  1990
		gTest.Printf(_L("TestGetSetResourceStateQuota, extra set state returned %d\n"),r);
sl@0
  1991
		return r;
sl@0
  1992
		}
sl@0
  1993
sl@0
  1994
	// Need to check the TRequestStatus objects
sl@0
  1995
	for(i=0; i<KNoOfSetStateRequests; i++)
sl@0
  1996
		{
sl@0
  1997
		User::WaitForRequest(status[i]);
sl@0
  1998
		if((r=status[i].Int()) != KErrNone)
sl@0
  1999
			{
sl@0
  2000
			gTest.Printf(_L("TestGetSetResourceStateQuota, set state %d returned %d\n"),i, r);
sl@0
  2001
			lastErr = r;
sl@0
  2002
			}
sl@0
  2003
		}
sl@0
  2004
	if(lastErr != KErrNone)
sl@0
  2005
		return lastErr;
sl@0
  2006
sl@0
  2007
	return r;
sl@0
  2008
	}
sl@0
  2009
sl@0
  2010
sl@0
  2011
LOCAL_C TInt TriggerNotification(TRequestStatus& aStatus, TUint aResourceId, TBool aCached, TInt aDelta)
sl@0
  2012
//
sl@0
  2013
// Support the notification tests - cause a notification for the specified resource
sl@0
  2014
//
sl@0
  2015
	{
sl@0
  2016
	TInt r = KErrNone;
sl@0
  2017
	TInt readValue = 0;
sl@0
  2018
	TInt levelOwnerId = 0;
sl@0
  2019
	// Get initial state
sl@0
  2020
	gChannel.GetResourceState(aStatus,aResourceId,aCached,&readValue,&levelOwnerId);
sl@0
  2021
	User::WaitForRequest(aStatus);
sl@0
  2022
	if(aStatus.Int() != KErrNone)
sl@0
  2023
		{
sl@0
  2024
		r=aStatus.Int();
sl@0
  2025
		gTest.Printf(_L("TriggerNotification, get state returned %d\n"),r);
sl@0
  2026
		return r;
sl@0
  2027
		}
sl@0
  2028
	TUint startingLevel = (TUint)readValue;
sl@0
  2029
sl@0
  2030
	// Write updated state
sl@0
  2031
	TUint newLevel = (TUint)(readValue + aDelta);
sl@0
  2032
	gTest.Printf(_L("TriggerNotification: startingLevel=0x%x, writing 0x%x\n"), startingLevel, newLevel);
sl@0
  2033
	gChannel.ChangeResourceState(aStatus,aResourceId,newLevel);
sl@0
  2034
	User::WaitForRequest(aStatus);
sl@0
  2035
	if(aStatus.Int() != KErrNone)
sl@0
  2036
		{
sl@0
  2037
		r=aStatus.Int();
sl@0
  2038
		gTest.Printf(_L("TriggerNotification, change state returned %d\n"),r);
sl@0
  2039
		return r;
sl@0
  2040
		}
sl@0
  2041
sl@0
  2042
	return r;
sl@0
  2043
	}
sl@0
  2044
sl@0
  2045
sl@0
  2046
LOCAL_C TInt CalcNotifyDirAndThr(TRequestStatus& aStatus, TUint aResourceId, TBool aCached, TInt& aThreshold, TBool& aDirection)
sl@0
  2047
//
sl@0
  2048
// Support the notification tests - determine an appropriate threshold and direction to request
sl@0
  2049
//
sl@0
  2050
	{
sl@0
  2051
	__KHEAP_MARK;
sl@0
  2052
sl@0
  2053
	// Need to know current state
sl@0
  2054
	TInt r = KErrNone;
sl@0
  2055
	TInt readValue = 0;
sl@0
  2056
	TInt levelOwnerId = 0;
sl@0
  2057
		{
sl@0
  2058
		gChannel.GetResourceState(aStatus,aResourceId,aCached,&readValue,&levelOwnerId);
sl@0
  2059
		User::WaitForRequest(aStatus);
sl@0
  2060
		if(aStatus.Int() != KErrNone)
sl@0
  2061
			{
sl@0
  2062
			r=aStatus.Int();
sl@0
  2063
			gTest.Printf(_L("TestNotificationOps, pre-qualified notify get state returned %d\n"),r);
sl@0
  2064
			return r;
sl@0
  2065
			}
sl@0
  2066
		}
sl@0
  2067
	aThreshold = readValue + gAsyncResStateDelta;
sl@0
  2068
	aDirection=(gAsyncResStateDelta>0)?ETrue:EFalse;
sl@0
  2069
sl@0
  2070
	__KHEAP_MARKEND;
sl@0
  2071
sl@0
  2072
	return r;
sl@0
  2073
	}
sl@0
  2074
sl@0
  2075
sl@0
  2076
//----------------------------------------------------------------------------------------------
sl@0
  2077
//! @SYMTestCaseID      KBASE-T_RESMANUS-0612
sl@0
  2078
//! @SYMTestType        UT
sl@0
  2079
//! @SYMPREQ            PREQ1398
sl@0
  2080
//! @SYMTestCaseDesc    This test case tests APIs for requesting both qualified and unqualified
sl@0
  2081
//!						notifications; it also tests APIs to cancel such requests. 
sl@0
  2082
//! 
sl@0
  2083
//! @SYMTestActions     0) Call API to request notification of an unqualified change in resource
sl@0
  2084
//!						state for a selected resource. Trigger a state change.
sl@0
  2085
//!
sl@0
  2086
//!						1) Call API to request notification of a qualified change in resource
sl@0
  2087
//!						state for a selected resource. Trigger a state change.
sl@0
  2088
//!	
sl@0
  2089
//!						2) Call API to request notification of an unqualified change in resource
sl@0
  2090
//!						state for a selected resource. Then call API to cancel all notifications for the resource.
sl@0
  2091
//!
sl@0
  2092
//!						3) Call API to request notification of a qualified change in resource 
sl@0
  2093
//!						state for a selected resource. Then call API to cancel all notifications for the resource.
sl@0
  2094
//!
sl@0
  2095
//!						4) Call API to request notification of an unqualified change in resource 
sl@0
  2096
//!						state for a selected resource. Trigger a state change. Then call API to cancel all
sl@0
  2097
//!						notifications for the resource.
sl@0
  2098
//!
sl@0
  2099
//!						5) Call API to request notification of a qualified change in resource 
sl@0
  2100
//!						state for a selected resource. Trigger a state change. Then call API to cancel all
sl@0
  2101
//!						notifications for the resource.
sl@0
  2102
//!
sl@0
  2103
//!						6) Call API to request notification of an unqualified change in resource
sl@0
  2104
//!						state for a selected resource. Then call API to cancel the notification request
sl@0
  2105
//!
sl@0
  2106
//!						7) Call API to request notification of a qualified change in resource 
sl@0
  2107
//!						state for a selected resource. Then call API to cancel the notification request
sl@0
  2108
//!
sl@0
  2109
//!						8) Call API to request notification of an unqualified change in resource 
sl@0
  2110
//!						state for a selected resource. Trigger a state change. Then call API to cancel the
sl@0
  2111
//!						notification request
sl@0
  2112
//!
sl@0
  2113
//!						9) Call API to request notification of a qualified change in resource 
sl@0
  2114
//!						state for a selected resource. Trigger a state change. Then call API to cancel the
sl@0
  2115
//!						notification request
sl@0
  2116
//!
sl@0
  2117
//!						10) Call API to request notification of an unqualified change in resource
sl@0
  2118
//!						state for a selected resource. Then call API to cancel generic async request
sl@0
  2119
//!
sl@0
  2120
//!						11) Call API to request notification of a qualified change in resource 
sl@0
  2121
//!						state for a selected resource. Then call API to cancel generic async request
sl@0
  2122
//!
sl@0
  2123
//!						12) Call API to request notification of an unqualified change in resource 
sl@0
  2124
//!						state for a selected resource. Trigger a state change. Then call API to cancel
sl@0
  2125
//!						generic async request
sl@0
  2126
//!
sl@0
  2127
//!						13) Call API to request notification of a qualified change in resource 
sl@0
  2128
//!						state for a selected resource. Trigger a state change. Then call API to cancel
sl@0
  2129
//!						generic async request
sl@0
  2130
//!
sl@0
  2131
//! @SYMTestExpectedResults 0) The associated TRequestStatus object should indicate KErrNone 
sl@0
  2132
//!						- exits otherwise.
sl@0
  2133
//!
sl@0
  2134
//!						1) The associated TRequestStatus object should indicate KErrNone 
sl@0
  2135
//!						- exits otherwise.
sl@0
  2136
//!
sl@0
  2137
//!						2) The associated TRequestStatus object should indicate KErrCancel 
sl@0
  2138
//!						- exits otherwise. 
sl@0
  2139
//!
sl@0
  2140
//!						3) The associated TRequestStatus object should indicate KErrCancel 
sl@0
  2141
//!						- exits otherwise. 
sl@0
  2142
//!
sl@0
  2143
//!						4) The TRequestStatus object should indicate state KRequestPending until
sl@0
  2144
//!						the state change is triggered, upon which it should exhibit state 
sl@0
  2145
//!						KErrNone. After the cancellation it should still exhibit state KErrNone.
sl@0
  2146
//!						Exit for any deviation from this behaviour.
sl@0
  2147
//!
sl@0
  2148
//!						5) The TRequestStatus object should indicate state KRequestPending until
sl@0
  2149
//!						the state change is triggered, upon which it should exhibit state 
sl@0
  2150
//!						KErrNone. After the cancellation it should still exhibit state KErrNone.
sl@0
  2151
//!						Exit for any deviation from this behaviour.
sl@0
  2152
//!
sl@0
  2153
//!						6) The associated TRequestStatus object should indicate KErrCancel 
sl@0
  2154
//!						- exits otherwise. 
sl@0
  2155
//!
sl@0
  2156
//!						7) The associated TRequestStatus object should indicate KErrCancel 
sl@0
  2157
//!						- exits otherwise. 
sl@0
  2158
//!
sl@0
  2159
//!						8) The TRequestStatus object should indicate state KRequestPending until
sl@0
  2160
//!						the state change is triggered, upon which it should exhibit state 
sl@0
  2161
//!						KErrNone. After the cancellation it should still exhibit state KErrNone.
sl@0
  2162
//!						Exit for any deviation from this behaviour.
sl@0
  2163
//!
sl@0
  2164
//!						9) The TRequestStatus object should indicate state KRequestPending until
sl@0
  2165
//!						the state change is triggered, upon which it should exhibit state 
sl@0
  2166
//!						KErrNone. After the cancellation it should still exhibit state KErrNone.
sl@0
  2167
//!						Exit for any deviation from this behaviour.
sl@0
  2168
//!
sl@0
  2169
//!						10) The associated TRequestStatus object should indicate KErrCancel 
sl@0
  2170
//!						- exits otherwise. 
sl@0
  2171
//!
sl@0
  2172
//!						11) The associated TRequestStatus object should indicate KErrCancel 
sl@0
  2173
//!						- exits otherwise. 
sl@0
  2174
//!
sl@0
  2175
//!						12) The TRequestStatus object should indicate state KRequestPending until
sl@0
  2176
//!						the state change is triggered, upon which it should exhibit state 
sl@0
  2177
//!						KErrNone. After the cancellation it should still exhibit state KErrNone.
sl@0
  2178
//!						Exit for any deviation from this behaviour.
sl@0
  2179
//!
sl@0
  2180
//!						13) The TRequestStatus object should indicate state KRequestPending until
sl@0
  2181
//!						the state change is triggered, upon which it should exhibit state 
sl@0
  2182
//!						KErrNone. After the cancellation it should still exhibit state KErrNone.
sl@0
  2183
//!						Exit for any deviation from this behaviour.
sl@0
  2184
//!
sl@0
  2185
//! @SYMTestPriority        High
sl@0
  2186
//! @SYMTestStatus          Implemented
sl@0
  2187
//----------------------------------------------------------------------------------------------
sl@0
  2188
LOCAL_C TInt TestNotificationOps()
sl@0
  2189
//
sl@0
  2190
// Test notification methods
sl@0
  2191
//
sl@0
  2192
	{
sl@0
  2193
	__KHEAP_MARK;
sl@0
  2194
sl@0
  2195
	TInt r = KErrNone;
sl@0
  2196
	TRequestStatus status;
sl@0
  2197
	TUint resourceId;
sl@0
  2198
	TInt stateDelta;
sl@0
  2199
	if(!gHaveAsyncRes)
sl@0
  2200
		{
sl@0
  2201
		resourceId = 2; // Arbitrary
sl@0
  2202
		stateDelta = 1; // Arbitrary
sl@0
  2203
		}
sl@0
  2204
	else
sl@0
  2205
		{
sl@0
  2206
		resourceId = gLongLatencyResource;
sl@0
  2207
		stateDelta = gAsyncResStateDelta;
sl@0
  2208
		}
sl@0
  2209
	TInt testIndex = 0;
sl@0
  2210
sl@0
  2211
	// 0) Call API to request notification of an unqualified change in resource
sl@0
  2212
	//    state for a selected resource. Trigger a state change.
sl@0
  2213
	gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
sl@0
  2214
	gChannel.RequestNotification(status, resourceId);
sl@0
  2215
	if(status.Int() != KRequestPending)
sl@0
  2216
		{
sl@0
  2217
		gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
sl@0
  2218
		return KErrGeneral;
sl@0
  2219
		}
sl@0
  2220
	TBool cached = gUseCached;
sl@0
  2221
	TRequestStatus triggerStatus;
sl@0
  2222
	if((r=TriggerNotification(triggerStatus, resourceId, cached, stateDelta))!=KErrNone)
sl@0
  2223
		return r;
sl@0
  2224
	User::WaitForRequest(status);
sl@0
  2225
	if(status.Int()!=KErrNone)
sl@0
  2226
		{
sl@0
  2227
		gTest.Printf(_L("TestNotificationOps: after TriggerNotification status = %d\n"),status.Int());
sl@0
  2228
		return r;
sl@0
  2229
		}
sl@0
  2230
sl@0
  2231
	// 1) Call API to request notification of a qualified change in resource
sl@0
  2232
	//    state for a selected resource. Trigger a state change.
sl@0
  2233
	gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
sl@0
  2234
	TInt dumThreshold=0;
sl@0
  2235
	TBool dumDirection=EFalse;
sl@0
  2236
	if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
sl@0
  2237
		return r;
sl@0
  2238
	gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection);
sl@0
  2239
	if(status.Int() != KRequestPending)
sl@0
  2240
		{
sl@0
  2241
		gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
sl@0
  2242
		return KErrGeneral;
sl@0
  2243
		}
sl@0
  2244
	// Pass gAsyncResStateDelta as this represents the delta value
sl@0
  2245
	if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
sl@0
  2246
		return r;
sl@0
  2247
	User::WaitForRequest(status);
sl@0
  2248
	if(status.Int()!=KErrNone)
sl@0
  2249
		{
sl@0
  2250
		gTest.Printf(_L("TestNotificationOps: after TriggerNotification status = %d\n"),status.Int());
sl@0
  2251
		return r;
sl@0
  2252
		}
sl@0
  2253
sl@0
  2254
	// 2) Call API to request notification of an unqualified change in resource
sl@0
  2255
	//    state for a selected resource. Then call API to cancel all notifications for the resource.
sl@0
  2256
	gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
sl@0
  2257
	gChannel.RequestNotification(status, resourceId);
sl@0
  2258
	if(status.Int() != KRequestPending)
sl@0
  2259
		{
sl@0
  2260
		gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
sl@0
  2261
		return KErrGeneral;
sl@0
  2262
		}
sl@0
  2263
	r=gChannel.CancelNotificationRequests(resourceId);
sl@0
  2264
	if(r!=KErrNone)
sl@0
  2265
		{
sl@0
  2266
		gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests returned %d\n"),r);
sl@0
  2267
		return r;
sl@0
  2268
		}
sl@0
  2269
	User::WaitForRequest(status);
sl@0
  2270
	if(status.Int()!=KErrCancel)
sl@0
  2271
		{
sl@0
  2272
		gTest.Printf(_L("TestNotificationOps: after cancel basic request status = %d\n"),status.Int());
sl@0
  2273
		return r;
sl@0
  2274
		}
sl@0
  2275
sl@0
  2276
	// 3) Call API to request notification of a qualified change in resource 
sl@0
  2277
	//    state for a selected resource. Then call API to cancel all notifications for the resource.
sl@0
  2278
	gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
sl@0
  2279
	dumThreshold = 0;			// Arbitrary
sl@0
  2280
	dumDirection = ETrue;		// Arbitrary
sl@0
  2281
	if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
sl@0
  2282
		return r;
sl@0
  2283
	gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection);
sl@0
  2284
	if(status.Int() != KRequestPending)
sl@0
  2285
		{
sl@0
  2286
		gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
sl@0
  2287
		return KErrGeneral;
sl@0
  2288
		}
sl@0
  2289
	r=gChannel.CancelNotificationRequests(resourceId);
sl@0
  2290
	if(r!=KErrNone)
sl@0
  2291
		{
sl@0
  2292
		gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests (qualified) returned %d\n"),r);
sl@0
  2293
		return r;
sl@0
  2294
		}
sl@0
  2295
	User::WaitForRequest(status);
sl@0
  2296
	if(status.Int()!=KErrCancel)
sl@0
  2297
		{
sl@0
  2298
		gTest.Printf(_L("TestNotificationOps: after qualified request cancel status = %d\n"),status.Int());
sl@0
  2299
		return r;
sl@0
  2300
		}
sl@0
  2301
sl@0
  2302
	// 4) Call API to request notification of an unqualified change in resource 
sl@0
  2303
	//    state for a selected resource. Trigger a state change. Then call API to cancel all
sl@0
  2304
	//    notifications for the resource.
sl@0
  2305
	gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
sl@0
  2306
	gChannel.RequestNotification(status, resourceId);
sl@0
  2307
	if(status.Int() != KRequestPending)
sl@0
  2308
		{
sl@0
  2309
		gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
sl@0
  2310
		return KErrGeneral;
sl@0
  2311
		}
sl@0
  2312
	// Pass gAsyncResStateDelta as this represents the delta value
sl@0
  2313
	if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
sl@0
  2314
		return r;
sl@0
  2315
	User::WaitForRequest(status);
sl@0
  2316
	if(status.Int()!=KErrNone)
sl@0
  2317
		{
sl@0
  2318
		gTest.Printf(_L("TestNotificationOps: trigger basic request before cancel, status = %d\n"),status.Int());
sl@0
  2319
		return r;
sl@0
  2320
		}
sl@0
  2321
	r=gChannel.CancelNotificationRequests(resourceId);
sl@0
  2322
	if(r!=KErrNone)
sl@0
  2323
		{
sl@0
  2324
		gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests returned %d\n"),r);
sl@0
  2325
		return r;
sl@0
  2326
		}
sl@0
  2327
	if(status.Int()!=KErrNone)
sl@0
  2328
		{
sl@0
  2329
		gTest.Printf(_L("TestNotificationOps: after cancel (completed) basic request status = %d\n"),status.Int());
sl@0
  2330
		return r;
sl@0
  2331
		}
sl@0
  2332
sl@0
  2333
	// 5) Call API to request notification of a qualified change in resource 
sl@0
  2334
	//    state for a selected resource. Trigger a state change. Then call API to cancel all
sl@0
  2335
	//    notifications for the resource.
sl@0
  2336
	gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
sl@0
  2337
	if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
sl@0
  2338
		return r;
sl@0
  2339
	gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection);
sl@0
  2340
	if(status.Int() != KRequestPending)
sl@0
  2341
		{
sl@0
  2342
		gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
sl@0
  2343
		return KErrGeneral;
sl@0
  2344
		}
sl@0
  2345
	// Pass gAsyncResStateDelta as this represents the delta value
sl@0
  2346
	if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
sl@0
  2347
		return r;
sl@0
  2348
	User::WaitForRequest(status);
sl@0
  2349
	if(status.Int()!=KErrNone)
sl@0
  2350
		{
sl@0
  2351
		gTest.Printf(_L("TestNotificationOps: trigger qualified request before cancel, status = %d\n"),status.Int());
sl@0
  2352
		return r;
sl@0
  2353
		}
sl@0
  2354
	r=gChannel.CancelNotificationRequests(resourceId);
sl@0
  2355
	if(r!=KErrNone)
sl@0
  2356
		{
sl@0
  2357
		gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests (qualified) returned %d\n"),r);
sl@0
  2358
		return r;
sl@0
  2359
		}
sl@0
  2360
	if(status.Int()!=KErrNone)
sl@0
  2361
		{
sl@0
  2362
		gTest.Printf(_L("TestNotificationOps: after cancel (completed) qualified request status = %d\n"),status.Int());
sl@0
  2363
		return r;
sl@0
  2364
		}
sl@0
  2365
sl@0
  2366
	// 6) Call API to request notification of an unqualified change in resource
sl@0
  2367
	//    state for a selected resource. Then call API to cancel the notification request
sl@0
  2368
	gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
sl@0
  2369
	gChannel.RequestNotification(status, resourceId);
sl@0
  2370
	if(status.Int() != KRequestPending)
sl@0
  2371
		{
sl@0
  2372
		gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
sl@0
  2373
		return KErrGeneral;
sl@0
  2374
		}
sl@0
  2375
	r=gChannel.CancelRequestNotification(status);
sl@0
  2376
	if(r!=KErrNone)
sl@0
  2377
		{
sl@0
  2378
		gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests returned %d\n"),r);
sl@0
  2379
		return r;
sl@0
  2380
		}
sl@0
  2381
	User::WaitForRequest(status);
sl@0
  2382
	if(status.Int()!=KErrCancel)
sl@0
  2383
		{
sl@0
  2384
		gTest.Printf(_L("TestNotificationOps: after cancel basic request status = %d\n"),status.Int());
sl@0
  2385
		return r;
sl@0
  2386
		}
sl@0
  2387
sl@0
  2388
	// 7) Call API to request notification of a qualified change in resource 
sl@0
  2389
	//    state for a selected resource. Then call API to cancel the notification request
sl@0
  2390
	gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
sl@0
  2391
	dumThreshold = 0;			// Arbitrary
sl@0
  2392
	dumDirection = ETrue;		// Arbitrary
sl@0
  2393
	if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
sl@0
  2394
		return r;
sl@0
  2395
	gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection);
sl@0
  2396
	if(status.Int() != KRequestPending)
sl@0
  2397
		{
sl@0
  2398
		gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
sl@0
  2399
		return KErrGeneral;
sl@0
  2400
		}
sl@0
  2401
	r=gChannel.CancelRequestNotification(status);
sl@0
  2402
	if(r!=KErrNone)
sl@0
  2403
		{
sl@0
  2404
		gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests (qualified) returned %d\n"),r);
sl@0
  2405
		return r;
sl@0
  2406
		}
sl@0
  2407
	User::WaitForRequest(status);
sl@0
  2408
	if(status.Int()!=KErrCancel)
sl@0
  2409
		{
sl@0
  2410
		gTest.Printf(_L("TestNotificationOps: after qualified request cancel status = %d\n"),status.Int());
sl@0
  2411
		return r;
sl@0
  2412
		}
sl@0
  2413
sl@0
  2414
	// 8) Call API to request notification of an unqualified change in resource 
sl@0
  2415
	//    state for a selected resource. Trigger a state change. Then call API to cancel the
sl@0
  2416
	//    notification request
sl@0
  2417
	gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
sl@0
  2418
	gChannel.RequestNotification(status, resourceId);
sl@0
  2419
	if(status.Int() != KRequestPending)
sl@0
  2420
		{
sl@0
  2421
		gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
sl@0
  2422
		return KErrGeneral;
sl@0
  2423
		}
sl@0
  2424
	// Pass gAsyncResStateDelta as this represents the delta value
sl@0
  2425
	if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
sl@0
  2426
		return r;
sl@0
  2427
	User::WaitForRequest(status);
sl@0
  2428
	if(status.Int()!=KErrNone)
sl@0
  2429
		{
sl@0
  2430
		gTest.Printf(_L("TestNotificationOps: trigger basic request before cancel, status = %d\n"),status.Int());
sl@0
  2431
		return r;
sl@0
  2432
		}
sl@0
  2433
	r=gChannel.CancelRequestNotification(status);
sl@0
  2434
	if(r!=KErrNone)
sl@0
  2435
		{
sl@0
  2436
		gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests returned %d\n"),r);
sl@0
  2437
		return r;
sl@0
  2438
		}
sl@0
  2439
	if(status.Int()!=KErrNone)
sl@0
  2440
		{
sl@0
  2441
		gTest.Printf(_L("TestNotificationOps: after cancel (completed) basic request status = %d\n"),status.Int());
sl@0
  2442
		return r;
sl@0
  2443
		}
sl@0
  2444
sl@0
  2445
	// 9) Call API to request notification of a qualified change in resource 
sl@0
  2446
	//    state for a selected resource. Trigger a state change. Then call API to cancel the
sl@0
  2447
	//    notification request
sl@0
  2448
	gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
sl@0
  2449
	if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
sl@0
  2450
		return r;
sl@0
  2451
	gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection);
sl@0
  2452
	if(status.Int() != KRequestPending)
sl@0
  2453
		{
sl@0
  2454
		gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
sl@0
  2455
		return KErrGeneral;
sl@0
  2456
		}
sl@0
  2457
	// Pass gAsyncResStateDelta as this represents the delta value
sl@0
  2458
	if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
sl@0
  2459
		return r;
sl@0
  2460
	User::WaitForRequest(status);
sl@0
  2461
	if(status.Int()!=KErrNone)
sl@0
  2462
		{
sl@0
  2463
		gTest.Printf(_L("TestNotificationOps: trigger qualified request before cancel, status = %d\n"),status.Int());
sl@0
  2464
		return r;
sl@0
  2465
		}
sl@0
  2466
	r=gChannel.CancelRequestNotification(status);
sl@0
  2467
	if(r!=KErrNone)
sl@0
  2468
		{
sl@0
  2469
		gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests (qualified) returned %d\n"),r);
sl@0
  2470
		return r;
sl@0
  2471
		}
sl@0
  2472
	if(status.Int()!=KErrNone)
sl@0
  2473
		{
sl@0
  2474
		gTest.Printf(_L("TestNotificationOps: after cancel (completed) qualified request status = %d\n"),status.Int());
sl@0
  2475
		return r;
sl@0
  2476
		}
sl@0
  2477
sl@0
  2478
sl@0
  2479
	// 10) Call API to request notification of an unqualified change in resource
sl@0
  2480
	//     state for a selected resource. Then call API to cancel generic async request
sl@0
  2481
	gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
sl@0
  2482
	gChannel.RequestNotification(status, resourceId);
sl@0
  2483
	if(status.Int() != KRequestPending)
sl@0
  2484
		{
sl@0
  2485
		gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
sl@0
  2486
		return KErrGeneral;
sl@0
  2487
		}
sl@0
  2488
	gChannel.CancelAsyncOperation(&status);
sl@0
  2489
	User::WaitForRequest(status);
sl@0
  2490
	if(status.Int()!=KErrCancel)
sl@0
  2491
		{
sl@0
  2492
		gTest.Printf(_L("TestNotificationOps: after cancel basic request status = %d\n"),status.Int());
sl@0
  2493
		return r;
sl@0
  2494
		}
sl@0
  2495
sl@0
  2496
	// 11) Call API to request notification of a qualified change in resource 
sl@0
  2497
	//     state for a selected resource. Then call API to cancel generic async request
sl@0
  2498
	gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
sl@0
  2499
	dumThreshold = 0;			// Arbitrary
sl@0
  2500
	dumDirection = ETrue;		// Arbitrary
sl@0
  2501
	if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
sl@0
  2502
		return r;
sl@0
  2503
	gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection);
sl@0
  2504
	if(status.Int() != KRequestPending)
sl@0
  2505
		{
sl@0
  2506
		gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
sl@0
  2507
		return KErrGeneral;
sl@0
  2508
		}
sl@0
  2509
	gChannel.CancelAsyncOperation(&status);
sl@0
  2510
	User::WaitForRequest(status);
sl@0
  2511
	if(status.Int()!=KErrCancel)
sl@0
  2512
		{
sl@0
  2513
		gTest.Printf(_L("TestNotificationOps: after qualified request cancel status = %d\n"),status.Int());
sl@0
  2514
		return r;
sl@0
  2515
		}
sl@0
  2516
sl@0
  2517
	// 12) Call API to request notification of an unqualified change in resource 
sl@0
  2518
	//     state for a selected resource. Trigger a state change. Then call API to cancel
sl@0
  2519
	//     generic async request
sl@0
  2520
	gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
sl@0
  2521
	gChannel.RequestNotification(status, resourceId);
sl@0
  2522
	if(status.Int() != KRequestPending)
sl@0
  2523
		{
sl@0
  2524
		gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
sl@0
  2525
		return KErrGeneral;
sl@0
  2526
		}
sl@0
  2527
	// Pass gAsyncResStateDelta as this represents the delta value
sl@0
  2528
	if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
sl@0
  2529
		return r;
sl@0
  2530
	User::WaitForRequest(status);
sl@0
  2531
	if(status.Int()!=KErrNone)
sl@0
  2532
		{
sl@0
  2533
		gTest.Printf(_L("TestNotificationOps: trigger basic request before cancel, status = %d\n"),status.Int());
sl@0
  2534
		return r;
sl@0
  2535
		}
sl@0
  2536
	gChannel.CancelAsyncOperation(&status);
sl@0
  2537
	if(status.Int()!=KErrNone)
sl@0
  2538
		{
sl@0
  2539
		gTest.Printf(_L("TestNotificationOps: after cancel (completed) basic request status = %d\n"),status.Int());
sl@0
  2540
		return r;
sl@0
  2541
		}
sl@0
  2542
sl@0
  2543
	// 13) Call API to request notification of a qualified change in resource 
sl@0
  2544
	//     state for a selected resource. Trigger a state change. Then call API to cancel
sl@0
  2545
	//     generic async request
sl@0
  2546
	gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
sl@0
  2547
	if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
sl@0
  2548
		return r;
sl@0
  2549
	gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection);
sl@0
  2550
	if(status.Int() != KRequestPending)
sl@0
  2551
		{
sl@0
  2552
		gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
sl@0
  2553
		return KErrGeneral;
sl@0
  2554
		}
sl@0
  2555
	// Pass gAsyncResStateDelta as this represents the delta value
sl@0
  2556
	if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
sl@0
  2557
		return r;
sl@0
  2558
	User::WaitForRequest(status);
sl@0
  2559
	if(status.Int()!=KErrNone)
sl@0
  2560
		{
sl@0
  2561
		gTest.Printf(_L("TestNotificationOps: trigger qualified request before cancel, status = %d\n"),status.Int());
sl@0
  2562
		return r;
sl@0
  2563
		}
sl@0
  2564
	gChannel.CancelAsyncOperation(&status);
sl@0
  2565
	if(status.Int()!=KErrNone)
sl@0
  2566
		{
sl@0
  2567
		gTest.Printf(_L("TestNotificationOps: after cancel (completed) qualified request status = %d\n"),status.Int());
sl@0
  2568
		return r;
sl@0
  2569
		}
sl@0
  2570
sl@0
  2571
	__KHEAP_MARKEND;
sl@0
  2572
	
sl@0
  2573
	return r;
sl@0
  2574
	}
sl@0
  2575
sl@0
  2576
//----------------------------------------------------------------------------------------------
sl@0
  2577
//! @SYMTestCaseID      KBASE-T_RESMANUS-0613
sl@0
  2578
//! @SYMTestType        UT
sl@0
  2579
//! @SYMPREQ            PREQ1398
sl@0
  2580
//! @SYMTestCaseDesc    This test case tests quota management for notification operations.
sl@0
  2581
//! 
sl@0
  2582
//! @SYMTestActions     0) Issue the maximum number (requested in the call to the Initialise API)
sl@0
  2583
//!						of requests for notification of unqualified changes to the state of a 
sl@0
  2584
//!						resource. Then issue one further request.
sl@0
  2585
//!
sl@0
  2586
//!						1) Issue the maximum number (requested in the call to the Initialise API)
sl@0
  2587
//!						of requests for notification of qualified changes to the state of a 
sl@0
  2588
//!						resource. Then issue one further request.
sl@0
  2589
//!
sl@0
  2590
//!						2) Issue the maximum number (requested in the call to the Initialise API)
sl@0
  2591
//!						of requests for notification changes to the state of a resource, where 
sl@0
  2592
//!						every odd request is for an unqualified change and every even request is
sl@0
  2593
//!						for a qualified change. Then issue one further request.
sl@0
  2594
//!
sl@0
  2595
//! @SYMTestExpectedResults 0) Test that the TRequestStatus object associated with the last 
sl@0
  2596
//!							request exhibits status code KErrUnderflow - exit otherwise. Test
sl@0
  2597
//!							that the TRequestStatus objects associated with the preceding requests
sl@0
  2598
//!							exhibit status code KErrNone - exit otherwise.
sl@0
  2599
//!
sl@0
  2600
//!							1) Test that the TRequestStatus object associated with the last request
sl@0
  2601
//!							exhibits status code KErrUnderflow - exit otherwise. Test that the 
sl@0
  2602
//!							TRequestStatus objects associated with the preceding requests exhibit
sl@0
  2603
//!							status code KErrNone - exit otherwise.
sl@0
  2604
//!
sl@0
  2605
//!							2) Test that the TRequestStatus object associated with the last request
sl@0
  2606
//!							exhibits status code KErrUnderflow - exit otherwise. Test that the 
sl@0
  2607
//!							TRequestStatus objects associated with the preceding requests exhibit
sl@0
  2608
//!							status code KErrNone - exit otherwise.
sl@0
  2609
//!
sl@0
  2610
//! @SYMTestPriority        High
sl@0
  2611
//! @SYMTestStatus          Implemented
sl@0
  2612
//----------------------------------------------------------------------------------------------
sl@0
  2613
LOCAL_C TInt TestNotificationQuota()
sl@0
  2614
//
sl@0
  2615
// Test notification request quota management
sl@0
  2616
//
sl@0
  2617
	{
sl@0
  2618
	__KHEAP_MARK;
sl@0
  2619
sl@0
  2620
	TInt r = KErrNone;
sl@0
  2621
	TRequestStatus status[MAX_NUM_REQUESTS];
sl@0
  2622
	TInt loopVar=0;
sl@0
  2623
	TBool cached = gUseCached;
sl@0
  2624
	TRequestStatus triggerStatus;
sl@0
  2625
	TUint resourceId = gLongLatencyResource;
sl@0
  2626
sl@0
  2627
	// Test quota for basic operation
sl@0
  2628
	//
sl@0
  2629
	// Loop to perform maximum number of requests, check TRequestStatus objects are pending
sl@0
  2630
	for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++)
sl@0
  2631
		{
sl@0
  2632
		gChannel.RequestNotification(status[loopVar], resourceId);
sl@0
  2633
		if(status[loopVar].Int() != KRequestPending)
sl@0
  2634
			{
sl@0
  2635
			gTest.Printf(_L("TestNotificationQuota: status not KRequestPending, =%d\n"),
sl@0
  2636
													status[loopVar].Int());
sl@0
  2637
			return KErrGeneral;
sl@0
  2638
			}
sl@0
  2639
		}
sl@0
  2640
	// Issue one more request, check that TRequestStatus object exhibits state KErrUnderflow
sl@0
  2641
	gChannel.RequestNotification(status[KNoOfNotifyRequests], resourceId);
sl@0
  2642
	if(status[KNoOfNotifyRequests].Int() != KErrUnderflow)
sl@0
  2643
		{
sl@0
  2644
		gTest.Printf(_L("TestNotificationQuota: status[%d] not KErrUnderflow, =%d\n"),
sl@0
  2645
													KNoOfNotifyRequests,status[loopVar].Int());
sl@0
  2646
		return KErrGeneral;
sl@0
  2647
		}
sl@0
  2648
	// Loop to trigger previously-issued notifications, check TRequestStatus objects
sl@0
  2649
	for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++)
sl@0
  2650
		{
sl@0
  2651
		// Pass gAsyncResStateDelta as this represents the delta value
sl@0
  2652
		if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
sl@0
  2653
			return r;
sl@0
  2654
		User::WaitForRequest(status[loopVar]);
sl@0
  2655
		if(status[loopVar].Int()!=KErrNone)
sl@0
  2656
			{
sl@0
  2657
			gTest.Printf(_L("TestNotificationQuota: trigger basic request status[%d] = %d\n"),
sl@0
  2658
																loopVar,status[loopVar].Int());
sl@0
  2659
			return r;
sl@0
  2660
			}
sl@0
  2661
		}
sl@0
  2662
sl@0
  2663
sl@0
  2664
	// Test quota for qualified operation
sl@0
  2665
	//
sl@0
  2666
	TInt dumThreshold = -25;	// Arbitrary
sl@0
  2667
	TBool dumDirection = ETrue;	// Arbitrary
sl@0
  2668
	//
sl@0
  2669
	// Loop to perform maximum number of requests, check TRequestStatus objects are pending
sl@0
  2670
	for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++)
sl@0
  2671
		{
sl@0
  2672
	if((r=CalcNotifyDirAndThr(status[loopVar], resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
sl@0
  2673
		return r;
sl@0
  2674
		gChannel.RequestNotification(status[loopVar], resourceId, dumThreshold, dumDirection);
sl@0
  2675
		if(status[loopVar].Int() != KRequestPending)
sl@0
  2676
			{
sl@0
  2677
			gTest.Printf(_L("TestNotificationQuota: status[%d] not KRequestPending, =%d\n"),
sl@0
  2678
																loopVar,status[loopVar].Int());
sl@0
  2679
			return KErrGeneral;
sl@0
  2680
			}
sl@0
  2681
		}
sl@0
  2682
	// Issue one more request, check that TRequestStatus object exhibits state KErrUnderflow
sl@0
  2683
	if((r=CalcNotifyDirAndThr(status[KNoOfNotifyRequests], resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
sl@0
  2684
		return r;
sl@0
  2685
	gChannel.RequestNotification(status[KNoOfNotifyRequests], resourceId, dumThreshold, dumDirection);
sl@0
  2686
	if(status[KNoOfNotifyRequests].Int() != KErrUnderflow)
sl@0
  2687
		{
sl@0
  2688
		gTest.Printf(_L("TestNotificationQuota: status[%d] not KErrUnderflow, =%d\n"),
sl@0
  2689
													KNoOfNotifyRequests,status[loopVar].Int());
sl@0
  2690
		return KErrGeneral;
sl@0
  2691
		}
sl@0
  2692
	// Loop to trigger previously-issued notifications, check TRequestStatus objects
sl@0
  2693
	for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++)
sl@0
  2694
		{
sl@0
  2695
		// Pass gAsyncResStateDelta as this represents the delta value
sl@0
  2696
		if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
sl@0
  2697
			return r;
sl@0
  2698
		User::WaitForRequest(status[loopVar]);
sl@0
  2699
		if(status[loopVar].Int()!=KErrNone)
sl@0
  2700
			{
sl@0
  2701
			gTest.Printf(_L("TestNotificationQuota: trigger qualified request status[%d] = %d\n"),
sl@0
  2702
																loopVar,status[loopVar].Int());
sl@0
  2703
			return r;
sl@0
  2704
			}
sl@0
  2705
		}
sl@0
  2706
sl@0
  2707
	// Text quota with mixture of basic and qualified requests
sl@0
  2708
	//
sl@0
  2709
	TBool qualified = ETrue;
sl@0
  2710
	// Issue requests and check TRequestStatus objects are pending
sl@0
  2711
	for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++)
sl@0
  2712
		{
sl@0
  2713
		if(qualified)
sl@0
  2714
			{
sl@0
  2715
			if((r=CalcNotifyDirAndThr(status[loopVar], resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
sl@0
  2716
				return r;
sl@0
  2717
			gChannel.RequestNotification(status[loopVar], resourceId, dumThreshold, dumDirection);
sl@0
  2718
			}
sl@0
  2719
		else
sl@0
  2720
			{
sl@0
  2721
			gChannel.RequestNotification(status[loopVar], resourceId);
sl@0
  2722
			}
sl@0
  2723
		qualified=!qualified;
sl@0
  2724
		if(status[loopVar].Int() != KRequestPending)
sl@0
  2725
			{
sl@0
  2726
			gTest.Printf(_L("TestNotificationQuota: mixed loop status[%d] not KRequestPending, =%d\n"),
sl@0
  2727
																loopVar,status[loopVar].Int());
sl@0
  2728
			return KErrGeneral;
sl@0
  2729
			}
sl@0
  2730
		}
sl@0
  2731
	// Issue one more request, check that TRequestStatus object exhibits state KErrUnderflow
sl@0
  2732
	if(qualified)
sl@0
  2733
		{
sl@0
  2734
		if((r=CalcNotifyDirAndThr(status[KNoOfNotifyRequests], resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
sl@0
  2735
			return r;
sl@0
  2736
		gChannel.RequestNotification(status[KNoOfNotifyRequests], resourceId, dumThreshold, dumDirection);
sl@0
  2737
		}
sl@0
  2738
	else
sl@0
  2739
		{
sl@0
  2740
		gChannel.RequestNotification(status[KNoOfNotifyRequests], resourceId);
sl@0
  2741
		}
sl@0
  2742
	if(status[KNoOfNotifyRequests].Int() != KErrUnderflow)
sl@0
  2743
		{
sl@0
  2744
		gTest.Printf(_L("TestNotificationQuota: mixed loop status[%d] not KErrUnderflow, =%d\n"),
sl@0
  2745
													KNoOfNotifyRequests,status[loopVar].Int());
sl@0
  2746
		return KErrGeneral;
sl@0
  2747
		}
sl@0
  2748
	// Loop to trigger previously-issued notifications, check TRequestStatus objects
sl@0
  2749
	for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++)
sl@0
  2750
		{
sl@0
  2751
		// Pass gAsyncResStateDelta as this represents the delta value
sl@0
  2752
		if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
sl@0
  2753
			return r;
sl@0
  2754
		User::WaitForRequest(status[loopVar]);
sl@0
  2755
		if(status[loopVar].Int()!=KErrNone)
sl@0
  2756
			{
sl@0
  2757
			gTest.Printf(_L("TestNotificationQuota: trigger mixed request status[%d] = %d\n"),
sl@0
  2758
																loopVar,status[loopVar].Int());
sl@0
  2759
			return r;
sl@0
  2760
			}
sl@0
  2761
		}
sl@0
  2762
sl@0
  2763
	__KHEAP_MARKEND;
sl@0
  2764
sl@0
  2765
	return r;
sl@0
  2766
	}
sl@0
  2767
sl@0
  2768
#ifdef PIRATE_THREAD_TESTS
sl@0
  2769
sl@0
  2770
RThread PirateThread;
sl@0
  2771
TRequestStatus PirateStatus;
sl@0
  2772
const TInt KHeapSize=0x4000;
sl@0
  2773
const TInt KStackSize=0x4000;
sl@0
  2774
sl@0
  2775
_LIT(KPirateThreadName,"Pirate");
sl@0
  2776
sl@0
  2777
TInt PirateThreadFn(TAny* /*aSrcThread*/)
sl@0
  2778
	{
sl@0
  2779
#if 0
sl@0
  2780
	TInt r=KErrNone;
sl@0
  2781
	RBusDevResManUs pirateChannel = gChannel;
sl@0
  2782
	RThread& thread = *((RThread*)aSrcThread);
sl@0
  2783
sl@0
  2784
/* 1 - pirate with current thread - Panics kernel with KErrBadHandle */
sl@0
  2785
	if((r=pirateChannel.Duplicate(RThread(),EOwnerProcess))!=KErrAccessDenied)
sl@0
  2786
		{
sl@0
  2787
		gTest.Printf(_L("TestThreadExclusiveAccess: pirateChannel.Duplicate(RThread(),EOwnerProcess) returned %d\n"),r);
sl@0
  2788
		return KErrGeneral;
sl@0
  2789
		}
sl@0
  2790
sl@0
  2791
/* 2 - pirate with parent thread - Panics kernel with KErrBadHandle */
sl@0
  2792
	pirateChannel = gChannel;
sl@0
  2793
	if((r=pirateChannel.Duplicate(thread,EOwnerThread))!=KErrAccessDenied)
sl@0
  2794
		{
sl@0
  2795
		gTest.Printf(_L("TestThreadExclusiveAccess: pirateChannel.Duplicate(thread,EOwnerThread) returned %d\n"),r);
sl@0
  2796
		return KErrGeneral;
sl@0
  2797
		}
sl@0
  2798
sl@0
  2799
/* 3 - gChannel with current thread - Panics kernel with KErrBadHandle */
sl@0
  2800
	if((r=gChannel.Duplicate(RThread(),EOwnerThread))!=KErrAccessDenied)
sl@0
  2801
		{
sl@0
  2802
		gTest.Printf(_L("TestThreadExclusiveAccess: gChannel.Duplicate(RThread(),EOwnerThread) returned %d\n"),r);
sl@0
  2803
		return KErrGeneral;
sl@0
  2804
		}
sl@0
  2805
sl@0
  2806
/* 4 - gChannel with parent thread - Panics kernel with KErrBadHandle */
sl@0
  2807
	if((r=gChannel.Duplicate(thread,EOwnerThread))!=KErrAccessDenied)
sl@0
  2808
		{
sl@0
  2809
		gTest.Printf(_L("TestThreadExclusiveAccess: gChannel.Duplicate(thread,EOwnerThread)returned %d\n"),r);
sl@0
  2810
		return KErrGeneral;
sl@0
  2811
		}
sl@0
  2812
#endif
sl@0
  2813
sl@0
  2814
//	pirateChannel.Close();
sl@0
  2815
	return KErrNone;
sl@0
  2816
	}
sl@0
  2817
sl@0
  2818
TInt StartPirate(RThread& aSrcThread)
sl@0
  2819
	{
sl@0
  2820
	TAny* srcThread =(TAny*)(&aSrcThread);
sl@0
  2821
	TInt r=PirateThread.Create(KPirateThreadName,PirateThreadFn,KStackSize,KHeapSize,KHeapSize,srcThread,EOwnerThread);
sl@0
  2822
	if (r!=KErrNone)
sl@0
  2823
		return r;
sl@0
  2824
	PirateThread.Logon(PirateStatus);
sl@0
  2825
	PirateThread.Resume();
sl@0
  2826
	return KErrNone;
sl@0
  2827
	}
sl@0
  2828
sl@0
  2829
TInt WaitForPirateThread()
sl@0
  2830
	{
sl@0
  2831
	User::WaitForRequest(PirateStatus);
sl@0
  2832
	TInt exitType=PirateThread.ExitType();
sl@0
  2833
	TInt exitReason=PirateThread.ExitReason();
sl@0
  2834
	TBuf<16> exitCat=PirateThread.ExitCategory();
sl@0
  2835
	if((exitType!= EExitKill)||(exitReason!=KErrNone))
sl@0
  2836
		{
sl@0
  2837
		gTest.Printf(_L("Pirate thread error: %d\n"),PirateStatus.Int());
sl@0
  2838
		gTest.Printf(_L("Thread exit reason: %d,%d,%S\n"),exitType,exitReason,&exitCat);
sl@0
  2839
		gTest(0);		
sl@0
  2840
		}
sl@0
  2841
	PirateThread.Close();
sl@0
  2842
	return KErrNone;
sl@0
  2843
	}
sl@0
  2844
sl@0
  2845
#endif
sl@0
  2846
sl@0
  2847
//----------------------------------------------------------------------------------------------
sl@0
  2848
//! @SYMTestCaseID      KBASE-T_RESMANUS-0608
sl@0
  2849
//! @SYMTestType        UT
sl@0
  2850
//! @SYMPREQ            PREQ1398
sl@0
  2851
//! @SYMTestCaseDesc    This test case tests that channels can not be shared between threads.
sl@0
  2852
//! @SYMTestActions     0) Attempt to Duplicate the channel handle with EOwnerProcess as the owner type.
sl@0
  2853
//!
sl@0
  2854
//!						1) Attempt to Duplicate the channel handle with EOwnerThread
sl@0
  2855
//!
sl@0
  2856
//! @SYMTestExpectedResults 0) API should return with KErrAccessDenied, exits otherwise.
sl@0
  2857
//!						1) API should return with KErrNone, exits otherwise.
sl@0
  2858
//!
sl@0
  2859
//! @SYMTestPriority        High
sl@0
  2860
//! @SYMTestStatus          Implemented
sl@0
  2861
//----------------------------------------------------------------------------------------------
sl@0
  2862
LOCAL_C TInt TestThreadExclusiveAccess()
sl@0
  2863
//
sl@0
  2864
// Test mechanism to prevent other threads accessing a channel
sl@0
  2865
//
sl@0
  2866
	{
sl@0
  2867
	__KHEAP_MARK;
sl@0
  2868
sl@0
  2869
	TInt r;
sl@0
  2870
	RBusDevResManUs pirateChannel = gChannel;
sl@0
  2871
	if((r=pirateChannel.Duplicate(RThread(),EOwnerProcess))!=KErrAccessDenied)
sl@0
  2872
		{
sl@0
  2873
		gTest.Printf(_L("TestThreadExclusiveAccess: Duplicate with EOwnerProcess returned %d\n"),r);
sl@0
  2874
		if(r==KErrNone)
sl@0
  2875
			r=KErrGeneral;
sl@0
  2876
		return r;
sl@0
  2877
		}
sl@0
  2878
	pirateChannel = gChannel;
sl@0
  2879
	if((r=pirateChannel.Duplicate(RThread(),EOwnerThread))!=KErrNone)
sl@0
  2880
		{
sl@0
  2881
		gTest.Printf(_L("TestThreadExclusiveAccess: Duplicate with EOwnerThread returned %d\n"),r);
sl@0
  2882
		return r;
sl@0
  2883
		}
sl@0
  2884
#ifdef PIRATE_THREAD_TESTS
sl@0
  2885
	RThread& threadRef = RThread();
sl@0
  2886
	if((r=StartPirate(threadRef))!=KErrNone)
sl@0
  2887
		{
sl@0
  2888
		gTest.Printf(_L("TestThreadExclusiveAccess: StartPirate returned %d\n"),r);
sl@0
  2889
		return KErrGeneral;
sl@0
  2890
		}
sl@0
  2891
	if((r=WaitForPirateThread())!=KErrNone)
sl@0
  2892
		{
sl@0
  2893
		gTest.Printf(_L("TestThreadExclusiveAccess: WaitForPirateThread returned %d\n"),r);
sl@0
  2894
		return KErrGeneral;
sl@0
  2895
		}
sl@0
  2896
#endif
sl@0
  2897
	pirateChannel.Close();
sl@0
  2898
sl@0
  2899
	__KHEAP_MARKEND;
sl@0
  2900
sl@0
  2901
	return KErrNone;
sl@0
  2902
	}
sl@0
  2903
sl@0
  2904
RThread Thrd2;
sl@0
  2905
TRequestStatus Thrd2Status;
sl@0
  2906
const TInt KHeapSize=0x4000;
sl@0
  2907
const TInt KStackSize=0x4000;
sl@0
  2908
sl@0
  2909
_LIT(KThrd2Name,"Thread2");
sl@0
  2910
sl@0
  2911
sl@0
  2912
TInt Thread2Fn(TAny* /* */)
sl@0
  2913
//
sl@0
  2914
// Test that more than one thread can be supported
sl@0
  2915
//
sl@0
  2916
	{
sl@0
  2917
	TInt r;
sl@0
  2918
sl@0
  2919
	// Open a channel
sl@0
  2920
	//
sl@0
  2921
	_LIT(secThrdStr,"Thrd2Channel");
sl@0
  2922
	TBufC<16> secThrdName(secThrdStr);
sl@0
  2923
	// API accepts 8-bit descriptors, only - so convert name accordingly
sl@0
  2924
	TBuf8<MAX_RESOURCE_NAME_LENGTH+1>EightBitName;
sl@0
  2925
	EightBitName.Copy(secThrdName);
sl@0
  2926
	RBusDevResManUs secThrdChannel;
sl@0
  2927
    if((r=secThrdChannel.Open(EightBitName))!=KErrNone)
sl@0
  2928
		return r;
sl@0
  2929
sl@0
  2930
	// Read the resource information
sl@0
  2931
	//
sl@0
  2932
	TUint numResources=0;
sl@0
  2933
	if((r=secThrdChannel.GetNoOfResources(numResources))!=KErrNone)
sl@0
  2934
		return r;
sl@0
  2935
sl@0
  2936
	// To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects
sl@0
  2937
	// and reference via an RSimplePointerArray
sl@0
  2938
	TUint bufSize = numResources;
sl@0
  2939
	RSimplePointerArray<TResourceInfoBuf> resPtrs(bufSize);
sl@0
  2940
	for(TUint i=0;i<bufSize;i++)
sl@0
  2941
		{
sl@0
  2942
		TResourceInfoBuf *info = new TResourceInfoBuf();
sl@0
  2943
		if((r=resPtrs.Insert(info, i))!=KErrNone)
sl@0
  2944
			return r;
sl@0
  2945
		}
sl@0
  2946
sl@0
  2947
	TUint updateNumResources=numResources;
sl@0
  2948
	if((r=secThrdChannel.GetAllResourcesInfo(&resPtrs,updateNumResources))!=KErrNone)
sl@0
  2949
		return r;
sl@0
  2950
	resPtrs.Close();
sl@0
  2951
sl@0
  2952
sl@0
  2953
	// Read current client information
sl@0
  2954
	//
sl@0
  2955
	TUint numClients=0;
sl@0
  2956
	TUint numAllClients=0;
sl@0
  2957
	//
sl@0
  2958
	// GetNoOfClients - with default aIncludeKern=EFalse
sl@0
  2959
	//
sl@0
  2960
	if((r=secThrdChannel.GetNoOfClients(numClients,EFalse)) != KErrNone)
sl@0
  2961
		return r;
sl@0
  2962
	//
sl@0
  2963
	// GetNoOfClients - with aIncludeKern=ETrue
sl@0
  2964
	//
sl@0
  2965
	r=secThrdChannel.GetNoOfClients(numAllClients, ETrue);
sl@0
  2966
#ifdef RESMANUS_KERN
sl@0
  2967
	if(r!=KErrNone)
sl@0
  2968
#else
sl@0
  2969
	if(r!=KErrPermissionDenied)
sl@0
  2970
#endif
sl@0
  2971
		return KErrGeneral;
sl@0
  2972
	//
sl@0
  2973
	// Need a buffer big enough to contain numClients instances of TClientName
sl@0
  2974
	// To support the GetNamesAllClients testing, instantiate TClientName objects
sl@0
  2975
	// and reference via an RSimplePointerArray
sl@0
  2976
	TUint resBufSize = (numAllClients>numClients)?numAllClients:numClients;
sl@0
  2977
	RSimplePointerArray<TClientName> infoPtrs(resBufSize);
sl@0
  2978
	for(TUint j=0;j<resBufSize;j++)
sl@0
  2979
		{
sl@0
  2980
		TClientName *info = new TClientName();
sl@0
  2981
		if((r=infoPtrs.Insert(info, j))!=KErrNone)
sl@0
  2982
			return r;
sl@0
  2983
		}
sl@0
  2984
	//
sl@0
  2985
	// GetNamesAllClients - with aIncludeKern=EFalse
sl@0
  2986
	//
sl@0
  2987
	if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numClients, EFalse)) != KErrNone)
sl@0
  2988
		return r;
sl@0
  2989
	//
sl@0
  2990
	// GetNamesAllClients - with aIncludeKern=ETrue
sl@0
  2991
	//
sl@0
  2992
#ifdef RESMANUS_KERN
sl@0
  2993
	if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numAllClients, ETrue)) != KErrNone)
sl@0
  2994
		return r;
sl@0
  2995
#else
sl@0
  2996
	if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numClients, ETrue)) != KErrPermissionDenied)
sl@0
  2997
		{
sl@0
  2998
		if(r==KErrNone)
sl@0
  2999
			r=KErrGeneral;
sl@0
  3000
		return r;
sl@0
  3001
		}
sl@0
  3002
	else
sl@0
  3003
		r=KErrNone; // Ensure misleading result is not propagated
sl@0
  3004
#endif
sl@0
  3005
	infoPtrs.Close();
sl@0
  3006
sl@0
  3007
	// If we don't have a shared resource identified, skip the remaining tests
sl@0
  3008
	if(gHaveSharedRes)
sl@0
  3009
		{
sl@0
  3010
		// Register with the Resource Controller
sl@0
  3011
		//
sl@0
  3012
		if ((r=secThrdChannel.Initialise(1,1,0))!=KErrNone)  // Just need 1 get and 1 set state
sl@0
  3013
			return r;
sl@0
  3014
		// Set a level on the shared resource
sl@0
  3015
		//
sl@0
  3016
		// Get initial state
sl@0
  3017
		TRequestStatus status;
sl@0
  3018
		TBool cached = gUseCached;
sl@0
  3019
		TInt readValue;
sl@0
  3020
		TInt levelOwnerId;
sl@0
  3021
		secThrdChannel.GetResourceState(status,gSharedResource,cached,&readValue,&levelOwnerId);
sl@0
  3022
		User::WaitForRequest(status);
sl@0
  3023
		r=status.Int();
sl@0
  3024
		if(r != KErrNone)
sl@0
  3025
			return r;
sl@0
  3026
		// Write updated state
sl@0
  3027
		TUint newLevel = (TUint)(readValue + gSharedResStateDelta);
sl@0
  3028
		secThrdChannel.ChangeResourceState(status,gSharedResource,newLevel);
sl@0
  3029
		User::WaitForRequest(status);
sl@0
  3030
		r=status.Int();
sl@0
  3031
		if(r != KErrNone)
sl@0
  3032
			return r;
sl@0
  3033
		
sl@0
  3034
		// Read current client information
sl@0
  3035
		//
sl@0
  3036
		numClients=0;
sl@0
  3037
		numAllClients=0;
sl@0
  3038
		//
sl@0
  3039
		// GetNoOfClients - with default aIncludeKern=EFalse
sl@0
  3040
		//
sl@0
  3041
		if((r=secThrdChannel.GetNoOfClients(numClients,EFalse)) != KErrNone)
sl@0
  3042
			return r;
sl@0
  3043
		//
sl@0
  3044
		// GetNoOfClients - with aIncludeKern=ETrue
sl@0
  3045
		//
sl@0
  3046
#ifdef RESMANUS_KERN
sl@0
  3047
		if((r=secThrdChannel.GetNoOfClients(numAllClients, ETrue))!=KErrNone)
sl@0
  3048
#else
sl@0
  3049
		if((r=secThrdChannel.GetNoOfClients(numAllClients, ETrue))!=KErrPermissionDenied)
sl@0
  3050
#endif
sl@0
  3051
			return KErrGeneral;
sl@0
  3052
		//
sl@0
  3053
		// Need a buffer big enough to contain numClients instances of TClientName
sl@0
  3054
		// To support the GetNamesAllClients testing, instantiate TClientName objects
sl@0
  3055
		// and reference via an RSimplePointerArray
sl@0
  3056
		TUint bufSize = (numAllClients>numClients)?numAllClients:numClients;
sl@0
  3057
		RSimplePointerArray<TClientName> infoPtrs(bufSize);
sl@0
  3058
		for(TUint i=0;i<bufSize;i++)
sl@0
  3059
			{
sl@0
  3060
			TClientName *info = new TClientName();
sl@0
  3061
			if((r=infoPtrs.Insert(info, i))!=KErrNone)
sl@0
  3062
				return r;
sl@0
  3063
			}
sl@0
  3064
		//
sl@0
  3065
		// GetNamesAllClients - with aIncludeKern=EFalse
sl@0
  3066
		//
sl@0
  3067
		if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numClients, EFalse)) != KErrNone)
sl@0
  3068
			return r;
sl@0
  3069
		//
sl@0
  3070
		// GetNamesAllClients - with aIncludeKern=ETrue
sl@0
  3071
		//
sl@0
  3072
#ifdef RESMANUS_KERN
sl@0
  3073
		if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numAllClients, ETrue)) != KErrNone)
sl@0
  3074
			return r;
sl@0
  3075
#else
sl@0
  3076
		if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numClients, ETrue)) != KErrPermissionDenied)
sl@0
  3077
			{
sl@0
  3078
			if(r==KErrNone)
sl@0
  3079
				r=KErrGeneral;
sl@0
  3080
			return r;
sl@0
  3081
			}
sl@0
  3082
		else
sl@0
  3083
			r=KErrNone; // Ensure misleading result is not propagated
sl@0
  3084
#endif
sl@0
  3085
		infoPtrs.Close();
sl@0
  3086
sl@0
  3087
		// Read the resource information
sl@0
  3088
		//
sl@0
  3089
		numResources=0;
sl@0
  3090
		if((r=secThrdChannel.GetNoOfResources(numResources))!=KErrNone)
sl@0
  3091
			return r;
sl@0
  3092
sl@0
  3093
		//
sl@0
  3094
		// Need a buffer big enough to contain numResources instances of TResourceInfoBuf
sl@0
  3095
		// To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects
sl@0
  3096
		// and reference via an RSimplePointerArray
sl@0
  3097
		RSimplePointerArray<TResourceInfoBuf> resPtrs(numResources);
sl@0
  3098
		for(TUint j=0;j<numResources;j++)
sl@0
  3099
			{
sl@0
  3100
			TResourceInfoBuf *info = new TResourceInfoBuf();
sl@0
  3101
			if((r=resPtrs.Insert(info, j))!=KErrNone)
sl@0
  3102
				return r;
sl@0
  3103
			}
sl@0
  3104
sl@0
  3105
		if((r=secThrdChannel.GetAllResourcesInfo(&resPtrs,numResources))!=KErrNone)
sl@0
  3106
			return r;
sl@0
  3107
		resPtrs.Close();
sl@0
  3108
		}
sl@0
  3109
sl@0
  3110
	// Close the channel
sl@0
  3111
	secThrdChannel.Close();
sl@0
  3112
	return r;
sl@0
  3113
	}
sl@0
  3114
sl@0
  3115
TInt StartThread2()
sl@0
  3116
	{
sl@0
  3117
	TInt r=Thrd2.Create(KThrd2Name,Thread2Fn,KStackSize,KHeapSize,KHeapSize,NULL,EOwnerThread);
sl@0
  3118
	if (r!=KErrNone)
sl@0
  3119
		return r;
sl@0
  3120
	Thrd2.Logon(Thrd2Status);
sl@0
  3121
	Thrd2.Resume();
sl@0
  3122
	return KErrNone;
sl@0
  3123
	}
sl@0
  3124
sl@0
  3125
TInt WaitForThread2()
sl@0
  3126
	{
sl@0
  3127
	User::WaitForRequest(Thrd2Status);
sl@0
  3128
	TInt exitType=Thrd2.ExitType();
sl@0
  3129
	TInt exitReason=Thrd2.ExitReason();
sl@0
  3130
	TBuf<16> exitCat=Thrd2.ExitCategory();
sl@0
  3131
	if((exitType!= EExitKill)||(exitReason!=KErrNone))
sl@0
  3132
		{
sl@0
  3133
		gTest.Printf(_L("Thread2 error: %d\n"),Thrd2Status.Int());
sl@0
  3134
		gTest.Printf(_L("Thread exit reason: %d,%d,%S\n"),exitType,exitReason,&exitCat);
sl@0
  3135
		gTest(0);		
sl@0
  3136
		}
sl@0
  3137
	Thrd2.Close();
sl@0
  3138
	return KErrNone;
sl@0
  3139
	}
sl@0
  3140
sl@0
  3141
sl@0
  3142
//----------------------------------------------------------------------------------------------
sl@0
  3143
//! @SYMTestCaseID      KBASE-T_RESMANUS-0614
sl@0
  3144
//! @SYMTestType        UT
sl@0
  3145
//! @SYMPREQ            PREQ1398
sl@0
  3146
//! @SYMTestCaseDesc    This test case tests that an additional thread can open a channel and
sl@0
  3147
//!						exercise selected APIs.
sl@0
  3148
//! 
sl@0
  3149
//! @SYMTestActions     0) Call API to open a channel.
sl@0
  3150
//! 
sl@0
  3151
//!						1) Call GetNoOfResources API.
sl@0
  3152
//! 
sl@0
  3153
//!						2) Call GetAllResourcesInfo API.
sl@0
  3154
//! 
sl@0
  3155
//!						3) Call GetNoOfClients API with default aIncludeKern=EFalse.
sl@0
  3156
//! 
sl@0
  3157
//!						4) Call GetNoOfClients API with aIncludeKern=ETrue
sl@0
  3158
//! 
sl@0
  3159
//!						5) Call GetNamesAllClientsAPI with default aIncludeKern=EFalse.
sl@0
  3160
//! 
sl@0
  3161
//!						6) Call GetNamesAllClientsAPI with aIncludeKern=ETrue
sl@0
  3162
//! 
sl@0
  3163
//!						7) Call Initialise API.
sl@0
  3164
//! 
sl@0
  3165
//!						8) Call GetResourceState API for selected resource. 
sl@0
  3166
//! 
sl@0
  3167
//!						9) Call GetResourceState API for selected resource.
sl@0
  3168
//! 
sl@0
  3169
//!						10) Call GetNoOfClients API with default aIncludeKern=EFalse.
sl@0
  3170
//! 
sl@0
  3171
//!						11) Call GetNoOfClients API with aIncludeKern=ETrue
sl@0
  3172
//! 
sl@0
  3173
//!						12) Call GetNamesAllClientsAPI with default aIncludeKern=EFalse.
sl@0
  3174
//! 
sl@0
  3175
//!						13) Call GetNamesAllClientsAPI with aIncludeKern=ETrue
sl@0
  3176
//! 
sl@0
  3177
//!						14) Call GetNoOfResources API.
sl@0
  3178
//! 
sl@0
  3179
//!						15) Call GetAllResourcesInfo API.
sl@0
  3180
//!
sl@0
  3181
//! @SYMTestExpectedResults 0) Test that the channel was opened - exit otherwise.
sl@0
  3182
//! 
sl@0
  3183
//!							1) Test that the API call returned KErrNone - exit otherwise.
sl@0
  3184
//! 
sl@0
  3185
//!							2) Test that the API call returned KErrNone - exit otherwise.
sl@0
  3186
//! 
sl@0
  3187
//!							3) Test that the API call returned KErrNone - exit otherwise.
sl@0
  3188
//! 
sl@0
  3189
//!							4) If client exhibits PlatSec capability ReadDeviceData, Test that the API call returned KErrNone - exit otherwise
sl@0
  3190
//!							   If client lacks PlatSec capability ReadDeviceData, Test that the API call returned KErrPermissionDenied - exit otherwise
sl@0
  3191
//! 
sl@0
  3192
//!							5) Test that the API call returned KErrNone - exit otherwise.
sl@0
  3193
//! 
sl@0
  3194
//!							6) If client exhibits PlatSec capability ReadDeviceData, Test that the API call returned KErrNone - exit otherwise
sl@0
  3195
//!							   If client lacks PlatSec capability ReadDeviceData, Test that the API call returned KErrPermissionDenied - exit otherwise
sl@0
  3196
//! 
sl@0
  3197
//!							7) Test that the API call returned KErrNone - exit otherwise
sl@0
  3198
//! 
sl@0
  3199
//!							8) Test that the associated TRequestStatus object exhibited state KErrNone - exit otherwise
sl@0
  3200
//! 
sl@0
  3201
//!							9) Test that the associated TRequestStatus object exhibited state KErrNone - exit otherwise
sl@0
  3202
//! 
sl@0
  3203
//!							10) Test that the API call returned KErrNone - exit otherwise.
sl@0
  3204
//! 
sl@0
  3205
//!							11) If client exhibits PlatSec capability ReadDeviceData, Test that the API call returned KErrNone - exit otherwise
sl@0
  3206
//!							    If client lacks PlatSec capability ReadDeviceData, Test that the API call returned KErrPermissionDenied - exit otherwise
sl@0
  3207
//! 
sl@0
  3208
//!							12) Test that the API call returned KErrNone - exit otherwise.
sl@0
  3209
//! 
sl@0
  3210
//!							13) If client exhibits PlatSec capability ReadDeviceData, Test that the API call returned KErrNone - exit otherwise
sl@0
  3211
//!							    If client lacks PlatSec capability ReadDeviceData, Test that the API call returned KErrPermissionDenied - exit otherwise
sl@0
  3212
//! 
sl@0
  3213
//!							14) Test that the API call returned KErrNone - exit otherwise.
sl@0
  3214
//! 
sl@0
  3215
//!							15) Test that the API call returned KErrNone - exit otherwise.
sl@0
  3216
//!
sl@0
  3217
//! @SYMTestPriority        High
sl@0
  3218
//! @SYMTestStatus          Implemented
sl@0
  3219
//----------------------------------------------------------------------------------------------
sl@0
  3220
LOCAL_C TInt TestAdditionalThread()
sl@0
  3221
//
sl@0
  3222
// Test that more than one thread can be supported
sl@0
  3223
//
sl@0
  3224
	{
sl@0
  3225
	TInt r;
sl@0
  3226
	if((r=StartThread2())!=KErrNone)
sl@0
  3227
		{
sl@0
  3228
		gTest.Printf(_L("TestAdditionalThread: StartThread2 returned %d\n"),r);
sl@0
  3229
		return KErrGeneral;
sl@0
  3230
		}
sl@0
  3231
	if((r=WaitForThread2())!=KErrNone)
sl@0
  3232
		{
sl@0
  3233
		gTest.Printf(_L("TestAdditionalThread: WaitForThread2 returned %d\n"),r);
sl@0
  3234
		return KErrGeneral;
sl@0
  3235
		}
sl@0
  3236
sl@0
  3237
	return r;
sl@0
  3238
	}
sl@0
  3239
sl@0
  3240
sl@0
  3241
LOCAL_C TInt LocateResourceWithDependencies(TUint &aNumResources, TUint &aResId, TUint &aNumDependents)
sl@0
  3242
//
sl@0
  3243
// Support function for tests of dependencies
sl@0
  3244
//
sl@0
  3245
	{
sl@0
  3246
	__KHEAP_MARK;
sl@0
  3247
sl@0
  3248
	TInt r = KErrNone;
sl@0
  3249
	if((r=gChannel.GetNoOfResources(aNumResources))!=KErrNone)
sl@0
  3250
		{
sl@0
  3251
		gTest.Printf(_L("GetNoOfResources for test channel returned %d\n"),r);
sl@0
  3252
		return r;
sl@0
  3253
		}
sl@0
  3254
	TUint bufSize = aNumResources;
sl@0
  3255
	RSimplePointerArray<TResourceInfoBuf> infoPtrs(bufSize);
sl@0
  3256
	for(TUint i=0;i<bufSize;i++)
sl@0
  3257
		{
sl@0
  3258
		TResourceInfoBuf *info = new TResourceInfoBuf();
sl@0
  3259
		if((r=infoPtrs.Insert(info, i))!=KErrNone)
sl@0
  3260
			{
sl@0
  3261
			gTest.Printf(_L("GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),i,r);
sl@0
  3262
			}
sl@0
  3263
		}
sl@0
  3264
	TUint updateNumResources=aNumResources;
sl@0
  3265
	if((r=gChannel.GetAllResourcesInfo(&infoPtrs,updateNumResources))!=KErrNone)
sl@0
  3266
		{
sl@0
  3267
		gTest.Printf(_L("GetAllResourcesInfo for channel returned %d\n"),r);
sl@0
  3268
		return r;
sl@0
  3269
		}
sl@0
  3270
	for(TUint resNo=0;resNo<aNumResources;resNo++)
sl@0
  3271
		{
sl@0
  3272
		TResourceInfoBuf *info = infoPtrs[resNo];
sl@0
  3273
		TUint resId = ((*info)()).iId;
sl@0
  3274
		TUint numDependents = 0;
sl@0
  3275
		r=gChannel.GetNumDependentsForResource(resId,&numDependents, EFalse); // EFalse - don't load the dependency info
sl@0
  3276
		if((r!=KErrNone)&&(r!=KErrNotFound)&&(r!=KErrNotSupported))
sl@0
  3277
			{
sl@0
  3278
			gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource returned %d\n"),r);
sl@0
  3279
			return r;
sl@0
  3280
			}
sl@0
  3281
		if(numDependents>0)
sl@0
  3282
			{
sl@0
  3283
			aResId = resId;
sl@0
  3284
			aNumDependents = numDependents;
sl@0
  3285
			break;
sl@0
  3286
			}
sl@0
  3287
		}
sl@0
  3288
sl@0
  3289
	infoPtrs.Close();
sl@0
  3290
sl@0
  3291
	__KHEAP_MARKEND;
sl@0
  3292
	
sl@0
  3293
	return r;
sl@0
  3294
	}
sl@0
  3295
sl@0
  3296
sl@0
  3297
sl@0
  3298
//----------------------------------------------------------------------------------------------
sl@0
  3299
//! @SYMTestCaseID      KBASE-T_RESMANUS-0615
sl@0
  3300
//! @SYMTestType        UT
sl@0
  3301
//! @SYMPREQ            PREQ1398
sl@0
  3302
//! @SYMTestCaseDesc    This test case tests the different options available for handling transient data.
sl@0
  3303
//! @SYMTestActions     0) Locate a resource that has at least one dependency.
sl@0
  3304
//! 
sl@0
  3305
//!						1) Read the number of dependencies without reading the dependency information. 
sl@0
  3306
//!						   Call to read the dependency information (without re-loading).
sl@0
  3307
//! 
sl@0
  3308
//!						2) Read the number of dependencies (with default option of reading the dependency information). 
sl@0
  3309
//!						   Then read the dependency information (without re-loading).
sl@0
  3310
//!
sl@0
  3311
//!						3) Repeat the read the number of dependencies without reading the dependency information
sl@0
  3312
//!						   Then read the dependency information (without re-loading).
sl@0
  3313
//!						   Then read the dependency information (with re-loading).
sl@0
  3314
//!
sl@0
  3315
//!						4) Attempt to read the dependency information (without re-loading) with a buffer of insufficient size 
sl@0
  3316
//! 
sl@0
  3317
//!						5) Read the number of (all) resources without reading the resource information. 
sl@0
  3318
//!						   Call to read (all) the resource information (without re-loading).
sl@0
  3319
//!
sl@0
  3320
//!						6) Read the number of (all) resources (with default option of reading the resource information). 
sl@0
  3321
//!						   Then read (all) the resource information (without re-loading).
sl@0
  3322
//!
sl@0
  3323
//!						7) Repeat the read the number of (all) resources without reading the resources information
sl@0
  3324
//!						   Then read (all) the resources information (without re-loading).
sl@0
  3325
//!						   Then read (all) the resources information (with re-loading).
sl@0
  3326
//!
sl@0
  3327
//!						8) Attempt to read (all) the resource information (without re-loading) with a buffer of insufficient size 
sl@0
  3328
//!
sl@0
  3329
//!						9) Read the number of user-side clients using a resource without reading the resource information. 
sl@0
  3330
//!						   Call to read the information for user-side clients using a resource (without re-loading).
sl@0
  3331
//!
sl@0
  3332
//!						10) Read the number of user-side clients (with loading of the client information)
sl@0
  3333
//!						   Call to read the client information (without re-loading) should return be successful
sl@0
  3334
//!						   Call to read the information for a resourceID with zero clients (without re-loading)
sl@0
  3335
//!						   Call to read the information for the first resourceID
sl@0
  3336
//!
sl@0
  3337
//!						11) Repeat the read of the number of user-side clients (without re-loading)
sl@0
  3338
//!						   Call to read the client information (without re-loading)
sl@0
  3339
//!						   Call to read the client information (with re-loading)
sl@0
  3340
//!
sl@0
  3341
//!						12) Open a second channel on the User-Side API, and call initialise support for resource state access
sl@0
  3342
//!						   Get the current state of a specific resource, then change the state
sl@0
  3343
//!						   Call to read the number of user-side clients for the resource (with loading of the client information)
sl@0
  3344
//!						   but with a buffer of insufficient size.
sl@0
  3345
//!
sl@0
  3346
//!						13) Read the number of resources in use by a specified client (without loading)
sl@0
  3347
//!						   Call to read the information on the resources in use by the client (without loading)
sl@0
  3348
//!
sl@0
  3349
//!						14) Open a third channel on the User-Side API, do not call initialise.
sl@0
  3350
//!						   Read the number of resources in use by a specified client (with loading)
sl@0
  3351
//!						   Call to read the information for resources in use by the third channel (without re-loading)
sl@0
  3352
//!						   Call to read the information for resources in use by the second channel (without re-loading)
sl@0
  3353
//!
sl@0
  3354
//!						15) Read the number of resources in use by a specified client (without loading)
sl@0
  3355
//!						   Call to read the information on the resources in use by the client (without loading)
sl@0
  3356
//!						   Call to read the information on the resources in use by the client (with loading)
sl@0
  3357
//!
sl@0
  3358
//!						16) Read the number of resources in use by a specified client (with loading)
sl@0
  3359
//!						   Call to read the information on the resources in use by the client (without loading) 
sl@0
  3360
//!						   with a buffer of insufficient size.
sl@0
  3361
//!
sl@0
  3362
//! @SYMTestExpectedResults 0) If a suitable resource is found, the number of dependencies is reported - exit otherwise.
sl@0
  3363
//!
sl@0
  3364
//!						1) Test that the read of the number of dependencies returns KErrNone - exit otherwise.
sl@0
  3365
//!						   Test that the read of the dependency information returned KErrNotReady - exit otherwise.
sl@0
  3366
//!
sl@0
  3367
//!						2) Test that the read of the number of dependencies returns KErrNone - exit otherwise.
sl@0
  3368
//!						   Test that the read of the dependency information returned KErrNone - exit otherwise.
sl@0
  3369
//!
sl@0
  3370
//!						3) Test that the read of the number of dependencies returns KErrNone - exit otherwise.
sl@0
  3371
//!						   Test that the read of the dependency information (without re-loading) returned KErrNotReady - exit otherwise.
sl@0
  3372
//!						   Test that the read of the dependency information (with re-loading) returned KErrNone - exit otherwise.
sl@0
  3373
//!
sl@0
  3374
//!						4) Test that the read of the dependency information returns KErrArgument - exit otherwise 
sl@0
  3375
//!
sl@0
  3376
//!						5) Test that the read of the number of resources returns KErrNone - exit otherwise.
sl@0
  3377
//!						   Test that the read of the resource information returned KErrNotReady - exit otherwise.
sl@0
  3378
//!
sl@0
  3379
//!						6) Test that the read of the number of resources returns KErrNone - exit otherwise.
sl@0
  3380
//!						   Test that the read of the resource information returned KErrNone - exit otherwise.
sl@0
  3381
//!
sl@0
  3382
//!						7) Test that the read of the number of resources returns KErrNone - exit otherwise.
sl@0
  3383
//!						   Test that the read of the resource information (without re-loading) returned KErrNotReady - exit otherwise.
sl@0
  3384
//!						   Test that the read of the resources information (with re-loading) returned KErrNone - exit otherwise.
sl@0
  3385
//!
sl@0
  3386
//!						8) Test that the read of the resource information returns KErrArgument - exit otherwise 
sl@0
  3387
//!
sl@0
  3388
//!						9) Test that the read of the number of clients returns KErrNone - exit otherwise.
sl@0
  3389
//!						   Test that the read of the client information returned KErrNotReady - exit otherwise.
sl@0
  3390
//!
sl@0
  3391
//!						10) Test that the read of the number of clients returns KErrNone - exit otherwise.
sl@0
  3392
//!						  Test that the read of the client information returned KErrNone - exit otherwise.
sl@0
  3393
//!						  Test that the read of the client information returned KErrNone and numClients==0 - exit otherwise.
sl@0
  3394
//!						  Test that the read of the client information returned KErrNotReady - exit otherwise.
sl@0
  3395
//!
sl@0
  3396
//!						11) Test that the read of the number of clients returns KErrNone - exit otherwise.
sl@0
  3397
//!						  Test that the read of the client information returned KErrNotReady - exit otherwise.
sl@0
  3398
//!						  Test that the read of the client information returned KErrNone - exit otherwise.
sl@0
  3399
//!
sl@0
  3400
//!						12) Test that the opening and initialisation of the channel was successful - exit otherwise.
sl@0
  3401
//!						  Test that the get and change of the resource state completed successfully - exit otherwise
sl@0
  3402
//!						  Test that the read of the client information returned KErrArgument - exit otherwise.
sl@0
  3403
//!
sl@0
  3404
//!						13) Test that the read of the number of resources returns KErrNone - exit otherwise.
sl@0
  3405
//!						  Test that the read of the resource information returned KErrNotReady - exit otherwise.
sl@0
  3406
//!
sl@0
  3407
//!						14) Test that the opening of the channel was successful - exit otherwise.
sl@0
  3408
//!						   Test that the read of the resource information returned KErrNone - exit otherwise.
sl@0
  3409
//!						   Test that the read of the client information returned KErrNone, and numResources = 0 - exit otherwise.
sl@0
  3410
//!						   Test that the read of the client information returned KErrNotReady - exit otherwise.
sl@0
  3411
//!
sl@0
  3412
//!						15) Test that the read of the number of resources returns KErrNone - exit otherwise.
sl@0
  3413
//!						   Test that the read of the resource information returned KErrNotReady - exit otherwise.
sl@0
  3414
//!						   Test that the read of the resource information returned KErrNone - exit otherwise.
sl@0
  3415
//!
sl@0
  3416
//!						16) Test that the read of the number of resources returns KErrNone - exit otherwise.
sl@0
  3417
//!						   Test that the read of the resource information returned KErrArgument - exit otherwise..
sl@0
  3418
//!
sl@0
  3419
//! @SYMTestPriority        High
sl@0
  3420
//! @SYMTestStatus          Implemented
sl@0
  3421
//----------------------------------------------------------------------------------------------
sl@0
  3422
LOCAL_C TInt TestTransientHandling()
sl@0
  3423
//
sl@0
  3424
// Test APIs with options for handling transient data (dependencies, resources and clients)
sl@0
  3425
//
sl@0
  3426
	{
sl@0
  3427
	TInt r = KErrNone;
sl@0
  3428
	TUint testNo = 1;
sl@0
  3429
sl@0
  3430
	TUint numDependents = 0; 
sl@0
  3431
	TUint resNo = 0;
sl@0
  3432
sl@0
  3433
	//
sl@0
  3434
	//					Dependency data tests
sl@0
  3435
	//
sl@0
  3436
sl@0
  3437
	gTest.Printf(_L("TestTransientHandling: dependency data tests ...\n"));
sl@0
  3438
sl@0
  3439
	// 0) Find a resource that has dependents - if none is located skip the remaining dependancy tests
sl@0
  3440
	// (this reads the number of dependencies, without loading the dependency data)
sl@0
  3441
	//
sl@0
  3442
	TUint numResources=0;
sl@0
  3443
	if((r=LocateResourceWithDependencies(numResources, resNo, numDependents))!=KErrNone)
sl@0
  3444
		{
sl@0
  3445
		gTest.Printf(_L("TestTransientHandling: no resource with dependencies found ... skipping tests\n"));
sl@0
  3446
		return KErrNone;
sl@0
  3447
		}
sl@0
  3448
	if(numDependents==0)
sl@0
  3449
		{
sl@0
  3450
		gTest.Printf(_L("TestTransientHandling: no resource with dependencies found ... skipping tests\n"));
sl@0
  3451
		}
sl@0
  3452
	else
sl@0
  3453
		{
sl@0
  3454
		// 1) Read the number of dependencies without reading the dependency information
sl@0
  3455
		// Subsequent call to read the dependency information (without re-loading) should return error KErrNotReady
sl@0
  3456
		gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
sl@0
  3457
		if((r=gChannel.GetNumDependentsForResource(resNo,&numDependents, EFalse))!=KErrNone)
sl@0
  3458
			{
sl@0
  3459
			gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource returned %d\n"),r);
sl@0
  3460
			return r;
sl@0
  3461
			}
sl@0
  3462
		gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource reported %d dependents for resource %d\n"),numDependents,resNo);
sl@0
  3463
		if(numDependents > 0)
sl@0
  3464
			{
sl@0
  3465
			RBuf8 buffer;
sl@0
  3466
			if((buffer.Create(numDependents*sizeof(SResourceDependencyInfo)))!=KErrNone)
sl@0
  3467
				return KErrGeneral;
sl@0
  3468
			buffer.SetLength(0);
sl@0
  3469
			if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents))!=KErrNotReady)
sl@0
  3470
				{
sl@0
  3471
				gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r);
sl@0
  3472
				return KErrGeneral;
sl@0
  3473
				}
sl@0
  3474
			buffer.Close();
sl@0
  3475
			}
sl@0
  3476
sl@0
  3477
		// 2) Read the number of dependencies (and, by default, read the dependency information)
sl@0
  3478
		// Subsequent call to read the dependency information (without re-loading) should return be successful
sl@0
  3479
		gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
sl@0
  3480
		if((r=gChannel.GetNumDependentsForResource(resNo,&numDependents))!=KErrNone)
sl@0
  3481
			{
sl@0
  3482
			gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource returned %d\n"),r);
sl@0
  3483
			return r;
sl@0
  3484
			}
sl@0
  3485
		gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource reported %d dependents for resource %d\n"),numDependents,resNo);
sl@0
  3486
		if(numDependents > 0)
sl@0
  3487
			{
sl@0
  3488
			RBuf8 buffer;
sl@0
  3489
			if((buffer.Create(numDependents*sizeof(SResourceDependencyInfo)))!=KErrNone)
sl@0
  3490
				return KErrGeneral;
sl@0
  3491
			buffer.SetLength(0);
sl@0
  3492
			if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents))!=KErrNone)
sl@0
  3493
				{
sl@0
  3494
				gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r);
sl@0
  3495
				return r;
sl@0
  3496
				}
sl@0
  3497
			SResourceDependencyInfo* tempPtr = (SResourceDependencyInfo*)(buffer.Ptr());
sl@0
  3498
			gTest.Printf(_L("TestTransientHandling: numDependents = %d\n"),numDependents);
sl@0
  3499
			for(TUint i=0; i<numDependents; i++,tempPtr++)
sl@0
  3500
				{
sl@0
  3501
				gTest.Printf(_L("TestTransientHandling: info.iResourceId = %d\n"),tempPtr->iResourceId);
sl@0
  3502
				gTest.Printf(_L("TestTransientHandling: info.iDependencyPriority= %d\n"),tempPtr->iDependencyPriority);
sl@0
  3503
				}
sl@0
  3504
			buffer.Close();
sl@0
  3505
			}
sl@0
  3506
sl@0
  3507
		// 3) Repeat the read the number of dependencies without reading the dependency information
sl@0
  3508
		// Subsequent call to read the dependency information (without re-loading) should return error KErrNotReady
sl@0
  3509
		// Then call to read the dependency information (with re-loading) should be successful
sl@0
  3510
		gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
sl@0
  3511
		if((r=gChannel.GetNumDependentsForResource(resNo,&numDependents, EFalse))!=KErrNone)
sl@0
  3512
			{
sl@0
  3513
			gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource returned %d\n"),r);
sl@0
  3514
			return r;
sl@0
  3515
			}
sl@0
  3516
		gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource reported %d dependents for resource %d\n"),numDependents,resNo);
sl@0
  3517
		if(numDependents > 0)
sl@0
  3518
			{
sl@0
  3519
			RBuf8 buffer;
sl@0
  3520
			if((buffer.Create(numDependents*sizeof(SResourceDependencyInfo)))!=KErrNone)
sl@0
  3521
				return KErrGeneral;
sl@0
  3522
			buffer.SetLength(0);
sl@0
  3523
sl@0
  3524
			if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents))!=KErrNotReady)
sl@0
  3525
				{
sl@0
  3526
				gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r);
sl@0
  3527
				return KErrGeneral;
sl@0
  3528
				}
sl@0
  3529
			if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents, ETrue))!=KErrNone)
sl@0
  3530
				{
sl@0
  3531
				gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r);
sl@0
  3532
				return KErrGeneral;
sl@0
  3533
				}
sl@0
  3534
			SResourceDependencyInfo* tempPtr = (SResourceDependencyInfo*)(buffer.Ptr());
sl@0
  3535
			for(TUint i=0; i<numDependents; i++,tempPtr++)
sl@0
  3536
				{
sl@0
  3537
				gTest.Printf(_L("TestTransientHandling: info.iResourceId = %d"),tempPtr->iResourceId);
sl@0
  3538
				gTest.Printf(_L("TestTransientHandling: info.iDependencyPriority= %d"),tempPtr->iDependencyPriority);
sl@0
  3539
				}
sl@0
  3540
			buffer.Close();
sl@0
  3541
			}
sl@0
  3542
sl@0
  3543
		// 4) Attempt to read the dependency information (without re-loading) with a buffer of insufficient size should
sl@0
  3544
		// return error KErrArgument
sl@0
  3545
		gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
sl@0
  3546
		if(numDependents > 0)
sl@0
  3547
			{
sl@0
  3548
			RBuf8 buffer;
sl@0
  3549
			if((buffer.Create((numDependents-1)*sizeof(SResourceDependencyInfo)))!=KErrNone)
sl@0
  3550
				return KErrGeneral;
sl@0
  3551
			buffer.SetLength(0);
sl@0
  3552
			if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents))!=KErrArgument)
sl@0
  3553
				{
sl@0
  3554
				gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r);
sl@0
  3555
				return KErrGeneral;
sl@0
  3556
				}
sl@0
  3557
			// Ensure misleading result is not returned
sl@0
  3558
			r=KErrNone;
sl@0
  3559
			buffer.Close();
sl@0
  3560
			}
sl@0
  3561
		}
sl@0
  3562
	
sl@0
  3563
sl@0
  3564
	//
sl@0
  3565
	//					All resource data tests
sl@0
  3566
	//
sl@0
  3567
sl@0
  3568
	gTest.Printf(_L("TestTransientHandling: All resource data tests ...\n"));
sl@0
  3569
	testNo=1;
sl@0
  3570
sl@0
  3571
	// 5) Attempt to read the resource information without having previously loaded it.
sl@0
  3572
	gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
sl@0
  3573
		{
sl@0
  3574
		TUint numResources = 0;
sl@0
  3575
		r = gChannel.GetNoOfResources(numResources, EFalse); // EFalse - don't load the resource info
sl@0
  3576
		if(r!=KErrNone)
sl@0
  3577
			{
sl@0
  3578
			gTest.Printf(_L("GetNoOfResources returned %d\n"),r);
sl@0
  3579
			return r;
sl@0
  3580
			}
sl@0
  3581
		// To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects
sl@0
  3582
		// and reference via an RSimplePointerArray
sl@0
  3583
		RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources);
sl@0
  3584
		for(TUint i=0;i<numResources;i++)
sl@0
  3585
			{
sl@0
  3586
			TResourceInfoBuf *info = new TResourceInfoBuf();
sl@0
  3587
			if((r=infoPtrs.Insert(info, i))!=KErrNone)
sl@0
  3588
				{
sl@0
  3589
				gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
sl@0
  3590
				}
sl@0
  3591
			}
sl@0
  3592
		if((r=gChannel.GetAllResourcesInfo(&infoPtrs, numResources))!=KErrNotReady)
sl@0
  3593
			{
sl@0
  3594
			gTest.Printf(_L("TestTransientHandling: GetAllResourcesInfo returned %d\n"),r);
sl@0
  3595
			return KErrGeneral;
sl@0
  3596
			}
sl@0
  3597
		else
sl@0
  3598
			r=KErrNone;	// Ensure misleading result is not propagated
sl@0
  3599
		infoPtrs.Close();
sl@0
  3600
		}
sl@0
  3601
sl@0
  3602
	// 6) Read the number of resources (and, by default, read the resource information)
sl@0
  3603
	// Subsequent call to read the resource information (without re-loading) should return be successful
sl@0
  3604
	gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
sl@0
  3605
		{
sl@0
  3606
		TUint numResources = 0;
sl@0
  3607
		if((r=gChannel.GetNoOfResources(numResources))!=KErrNone)
sl@0
  3608
			{
sl@0
  3609
			gTest.Printf(_L("GetNoOfResources returned %d\n"),r);
sl@0
  3610
			return r;
sl@0
  3611
			}
sl@0
  3612
		// To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects
sl@0
  3613
		// and reference via an RSimplePointerArray
sl@0
  3614
		RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources);
sl@0
  3615
		for(TUint i=0;i<numResources;i++)
sl@0
  3616
			{
sl@0
  3617
			TResourceInfoBuf *info = new TResourceInfoBuf();
sl@0
  3618
			if((r=infoPtrs.Insert(info, i))!=KErrNone)
sl@0
  3619
				{
sl@0
  3620
				gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
sl@0
  3621
				}
sl@0
  3622
			}
sl@0
  3623
		if((r=gChannel.GetAllResourcesInfo(&infoPtrs, numResources))!=KErrNone)
sl@0
  3624
			{
sl@0
  3625
			gTest.Printf(_L("TestTransientHandling: GetAllResourcesInfo returned %d\n"),r);
sl@0
  3626
			return r;
sl@0
  3627
			}
sl@0
  3628
		infoPtrs.Close();
sl@0
  3629
		}
sl@0
  3630
sl@0
  3631
	// 7) Repeat the read the number of resources without reading the resource information
sl@0
  3632
	// Subsequent call to read the resource information (without re-loading) should return error KErrNotReady
sl@0
  3633
	// Then call to read the resource information (with re-loading) should be successful
sl@0
  3634
	gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
sl@0
  3635
		{
sl@0
  3636
		TUint numResources = 0;
sl@0
  3637
		if((r=gChannel.GetNoOfResources(numResources, EFalse))!=KErrNone)	// EFalse - don't load the resource info
sl@0
  3638
			{
sl@0
  3639
			gTest.Printf(_L("GetNoOfResources returned %d\n"),r);
sl@0
  3640
			return r;
sl@0
  3641
			}
sl@0
  3642
		// To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects
sl@0
  3643
		// and reference via an RSimplePointerArray
sl@0
  3644
		RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources);
sl@0
  3645
		for(TUint i=0;i<numResources;i++)
sl@0
  3646
			{
sl@0
  3647
			TResourceInfoBuf *info = new TResourceInfoBuf();
sl@0
  3648
			if((r=infoPtrs.Insert(info, i))!=KErrNone)
sl@0
  3649
				{
sl@0
  3650
				gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
sl@0
  3651
				}
sl@0
  3652
			}
sl@0
  3653
		if((r=gChannel.GetAllResourcesInfo(&infoPtrs, numResources))!=KErrNotReady)
sl@0
  3654
			{
sl@0
  3655
			gTest.Printf(_L("TestTransientHandling: GetAllResourcesInfo returned %d\n"),r);
sl@0
  3656
			return KErrGeneral;
sl@0
  3657
			}
sl@0
  3658
		if((r=gChannel.GetAllResourcesInfo(&infoPtrs, numResources,ETrue))!=KErrNone)
sl@0
  3659
			{
sl@0
  3660
			gTest.Printf(_L("TestTransientHandling: GetAllResourcesInfo returned %d\n"),r);
sl@0
  3661
			return r;
sl@0
  3662
			}
sl@0
  3663
		else
sl@0
  3664
		infoPtrs.Close();
sl@0
  3665
		}
sl@0
  3666
sl@0
  3667
sl@0
  3668
	// 8) Attempt to read the resource information (without re-loading) with a buffer of insufficient size should
sl@0
  3669
	// return error KErrArgument
sl@0
  3670
	gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
sl@0
  3671
		{
sl@0
  3672
		TUint numResources = 0;
sl@0
  3673
		if((r=gChannel.GetNoOfResources(numResources, EFalse))!=KErrNone)	// EFalse - don't load the resource info
sl@0
  3674
			{
sl@0
  3675
			gTest.Printf(_L("GetNoOfResources returned %d\n"),r);
sl@0
  3676
			return r;
sl@0
  3677
			}
sl@0
  3678
		// To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects
sl@0
  3679
		// and reference via an RSimplePointerArray
sl@0
  3680
		RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources - 1);
sl@0
  3681
		for(TUint i=0;i<(numResources-1);i++)
sl@0
  3682
			{
sl@0
  3683
			TResourceInfoBuf *info = new TResourceInfoBuf();
sl@0
  3684
			if((r=infoPtrs.Insert(info, i))!=KErrNone)
sl@0
  3685
				{
sl@0
  3686
				gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
sl@0
  3687
				}
sl@0
  3688
			}
sl@0
  3689
		if((r=gChannel.GetAllResourcesInfo(&infoPtrs, numResources))!=KErrArgument)
sl@0
  3690
			{
sl@0
  3691
			gTest.Printf(_L("TestTransientHandling: GetAllResourcesInfo returned %d\n"),r);
sl@0
  3692
			return KErrGeneral;
sl@0
  3693
			}
sl@0
  3694
		// Ensure misleading result is not returned
sl@0
  3695
		r=KErrNone;
sl@0
  3696
		infoPtrs.Close();
sl@0
  3697
		}
sl@0
  3698
sl@0
  3699
	//
sl@0
  3700
	//					Specific resource data tests
sl@0
  3701
	//
sl@0
  3702
sl@0
  3703
	gTest.Printf(_L("TestTransientHandling: Resource-specific data tests ...\n"));
sl@0
  3704
	testNo=1;
sl@0
  3705
sl@0
  3706
	// 9) Attempt to read the resource information without having previously loaded it.
sl@0
  3707
	gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
sl@0
  3708
		{
sl@0
  3709
		TUint numClients = 0;
sl@0
  3710
		if((r=gChannel.GetNumClientsUsingResource(gLongLatencyResource, numClients, EFalse, EFalse))!=KErrNone) // user-side clients, don't load the info
sl@0
  3711
			{
sl@0
  3712
			gTest.Printf(_L("GetNumClientsUsingResource returned %d\n"),r);
sl@0
  3713
			return r;
sl@0
  3714
			}
sl@0
  3715
		// To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects
sl@0
  3716
		// and reference via an RSimplePointerArray
sl@0
  3717
		RSimplePointerArray<TClientInfoBuf> infoPtrs(numClients);
sl@0
  3718
		for(TUint i=0;i<numClients;i++)
sl@0
  3719
			{
sl@0
  3720
			TClientInfoBuf *info = new TClientInfoBuf();
sl@0
  3721
			if((r=infoPtrs.Insert(info, i))!=KErrNone)
sl@0
  3722
				{
sl@0
  3723
				gTest.Printf(_L("TestTransientHandling test, GetInfoOnClientsUsingResource infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
sl@0
  3724
				}
sl@0
  3725
			}
sl@0
  3726
		if((r=gChannel.GetInfoOnClientsUsingResource(gLongLatencyResource, numClients, &infoPtrs, EFalse))!=KErrNotReady)
sl@0
  3727
			{
sl@0
  3728
			gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource returned %d\n"),r);
sl@0
  3729
			return KErrGeneral;
sl@0
  3730
			}
sl@0
  3731
		else
sl@0
  3732
			r=KErrNone;	// Ensure misleading result is not propagated
sl@0
  3733
		infoPtrs.Close();
sl@0
  3734
		}
sl@0
  3735
sl@0
  3736
	// 10) Read the number of clients (and, by default, read the client information)
sl@0
  3737
	// Subsequent call to read the client information (without re-loading) should return be successful
sl@0
  3738
	// Call to read the information for a resourceID with zero clients (without re-loading) should return KErrNone, numClients==0
sl@0
  3739
	// Call to read the information for a resourceID with one or more clients (without re-loading) should return KErrNotReady
sl@0
  3740
	gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
sl@0
  3741
		{
sl@0
  3742
		TUint numClients = 0;
sl@0
  3743
		if((r=gChannel.GetNumClientsUsingResource(gLongLatencyResource, numClients, EFalse))!=KErrNone) // user-side clients, load the info
sl@0
  3744
			{
sl@0
  3745
			gTest.Printf(_L("GetNumClientsUsingResource returned %d\n"),r);
sl@0
  3746
			return r;
sl@0
  3747
			}
sl@0
  3748
		// To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects
sl@0
  3749
		// and reference via an RSimplePointerArray
sl@0
  3750
		RSimplePointerArray<TClientInfoBuf> infoPtrs(numClients);
sl@0
  3751
		for(TUint i=0;i<numClients;i++)
sl@0
  3752
			{
sl@0
  3753
			TClientInfoBuf *info = new TClientInfoBuf();
sl@0
  3754
			if((r=infoPtrs.Insert(info, i))!=KErrNone)
sl@0
  3755
				{
sl@0
  3756
				gTest.Printf(_L("TestTransientHandling test, GetInfoOnClientsUsingResource infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
sl@0
  3757
				}
sl@0
  3758
			}
sl@0
  3759
		if((r=gChannel.GetInfoOnClientsUsingResource(gLongLatencyResource, numClients, &infoPtrs, EFalse))!=KErrNone)
sl@0
  3760
			{
sl@0
  3761
			gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for gLongLatencyResource returned %d\n"),r);
sl@0
  3762
			return r;
sl@0
  3763
			}
sl@0
  3764
		if(((r=gChannel.GetInfoOnClientsUsingResource((gLongLatencyResource+1), numClients, &infoPtrs, EFalse))!=KErrNone) || (numClients!=0))
sl@0
  3765
			{
sl@0
  3766
			gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for (gLongLatencyResource+1) returned %d\n"),r);
sl@0
  3767
			if(numClients!=0)
sl@0
  3768
				gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for (gLongLatencyResource+1), %d clients\n"),numClients);
sl@0
  3769
			return KErrGeneral;
sl@0
  3770
			}
sl@0
  3771
		if((r=gChannel.GetInfoOnClientsUsingResource(gSharedResource, numClients, &infoPtrs, EFalse))!=KErrNotReady)
sl@0
  3772
			{
sl@0
  3773
			gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource (for gSharedResource) returned %d\n"),r);
sl@0
  3774
			return r;
sl@0
  3775
			}
sl@0
  3776
		infoPtrs.Close();
sl@0
  3777
		}
sl@0
  3778
sl@0
  3779
sl@0
  3780
	// 11) Repeat the read the number of clients without reading the client information
sl@0
  3781
	// Subsequent call to read the client information (without re-loading) should return error KErrNotReady
sl@0
  3782
	// Then call to read the client information (with re-loading) should be successful
sl@0
  3783
	gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
sl@0
  3784
		{
sl@0
  3785
		TUint numClients = 0;
sl@0
  3786
		if((r=gChannel.GetNumClientsUsingResource(gLongLatencyResource, numClients, EFalse, EFalse))!=KErrNone) // user-side clients, don't load the info
sl@0
  3787
			{
sl@0
  3788
			gTest.Printf(_L("GetNumClientsUsingResource returned %d\n"),r);
sl@0
  3789
			return r;
sl@0
  3790
			}
sl@0
  3791
		// To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects
sl@0
  3792
		// and reference via an RSimplePointerArray
sl@0
  3793
		RSimplePointerArray<TClientInfoBuf> infoPtrs(numClients);
sl@0
  3794
		for(TUint i=0;i<numClients;i++)
sl@0
  3795
			{
sl@0
  3796
			TClientInfoBuf *info = new TClientInfoBuf();
sl@0
  3797
			if((r=infoPtrs.Insert(info, i))!=KErrNone)
sl@0
  3798
				{
sl@0
  3799
				gTest.Printf(_L("TestTransientHandling test, GetInfoOnClientsUsingResource infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
sl@0
  3800
				}
sl@0
  3801
			}
sl@0
  3802
		if((r=gChannel.GetInfoOnClientsUsingResource(gLongLatencyResource, numClients, &infoPtrs, EFalse))!=KErrNotReady)
sl@0
  3803
			{
sl@0
  3804
			gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for gLongLatencyResource returned %d\n"),r);
sl@0
  3805
			return KErrGeneral;
sl@0
  3806
			}
sl@0
  3807
		if((r=gChannel.GetInfoOnClientsUsingResource(gLongLatencyResource, numClients, &infoPtrs, EFalse, ETrue))!=KErrNone)
sl@0
  3808
			{
sl@0
  3809
			gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for gLongLatencyResource returned %d\n"),r);
sl@0
  3810
			return r;
sl@0
  3811
			}
sl@0
  3812
sl@0
  3813
		infoPtrs.Close();
sl@0
  3814
		}
sl@0
  3815
sl@0
  3816
	// 12) To support the following test (and specific resource data tests, below) need a second channel to be using the resource
sl@0
  3817
	_LIT(tempStr1,"ExtraChan1");
sl@0
  3818
	TBufC<16> tempName1(tempStr1);
sl@0
  3819
	RBusDevResManUs channelTwo;
sl@0
  3820
	if((r=OpenChannel(tempName1, channelTwo))!=KErrNone)
sl@0
  3821
		{
sl@0
  3822
		gTest.Printf(_L("Failed to open channelTwo, %d\n"),r);
sl@0
  3823
		channelTwo.Close();
sl@0
  3824
		return r;
sl@0
  3825
		}
sl@0
  3826
	if ((r=channelTwo.Initialise(1,1,1))!=KErrNone)
sl@0
  3827
		{
sl@0
  3828
		gTest.Printf(_L("Failed to Initialise channelTwo, %d\n"),r);
sl@0
  3829
		channelTwo.Close();
sl@0
  3830
		return r;
sl@0
  3831
		}
sl@0
  3832
	// Attempt to change the resource level
sl@0
  3833
	// Get initial state
sl@0
  3834
	TRequestStatus status;
sl@0
  3835
	TBool cached = gUseCached;
sl@0
  3836
	TInt readValue;
sl@0
  3837
	TInt levelOwnerId = 0;
sl@0
  3838
	channelTwo.GetResourceState(status,gSharedResource,cached,&readValue,&levelOwnerId);
sl@0
  3839
	User::WaitForRequest(status);
sl@0
  3840
	r=status.Int();
sl@0
  3841
	if(r != KErrNone)
sl@0
  3842
		{
sl@0
  3843
		gTest.Printf(_L("GetResourceState for gSharedResource completed with = 0x%x\n"),r);
sl@0
  3844
		return r;
sl@0
  3845
		}
sl@0
  3846
	// Write updated state
sl@0
  3847
	TUint newLevel = (TUint)(readValue + gSharedResStateDelta);
sl@0
  3848
	channelTwo.ChangeResourceState(status,gSharedResource,newLevel);
sl@0
  3849
	User::WaitForRequest(status);
sl@0
  3850
	r=status.Int();
sl@0
  3851
	if(r != KErrNone)
sl@0
  3852
		{
sl@0
  3853
		gTest.Printf(_L("ChangeResourceState forgSharedResource completed with %d\n"),r);
sl@0
  3854
		return r;
sl@0
  3855
		}
sl@0
  3856
sl@0
  3857
	// Attempt to read the client information (without re-loading) with a buffer of insufficient size should
sl@0
  3858
	// return error KErrArgument
sl@0
  3859
	gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
sl@0
  3860
		{
sl@0
  3861
		TUint numClients = 0;
sl@0
  3862
		if((r=gChannel.GetNumClientsUsingResource(gSharedResource, numClients, EFalse))!=KErrNone) // user-side clients, load the info
sl@0
  3863
			{
sl@0
  3864
			gTest.Printf(_L("GetNumClientsUsingResource returned %d\n"),r);
sl@0
  3865
			channelTwo.Close();
sl@0
  3866
			return r;
sl@0
  3867
			}
sl@0
  3868
		// To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects
sl@0
  3869
		// and reference via an RSimplePointerArray
sl@0
  3870
		RSimplePointerArray<TClientInfoBuf> infoPtrs(numClients-1);
sl@0
  3871
		for(TUint i=0;i<(numClients-1);i++)
sl@0
  3872
			{
sl@0
  3873
			TClientInfoBuf *info = new TClientInfoBuf();
sl@0
  3874
			if((r=infoPtrs.Insert(info, i))!=KErrNone)
sl@0
  3875
				{
sl@0
  3876
				gTest.Printf(_L("TestTransientHandling test, GetInfoOnClientsUsingResource infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
sl@0
  3877
				channelTwo.Close();
sl@0
  3878
				}
sl@0
  3879
			}
sl@0
  3880
		if((r=gChannel.GetInfoOnClientsUsingResource(gSharedResource, numClients, &infoPtrs, EFalse))!=KErrArgument)
sl@0
  3881
			{
sl@0
  3882
			gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for gLongLatencyResource returned %d\n"),r);
sl@0
  3883
			channelTwo.Close();
sl@0
  3884
			return KErrGeneral;
sl@0
  3885
			}
sl@0
  3886
		// Ensure misleading result is not returned
sl@0
  3887
		r=KErrNone;
sl@0
  3888
		infoPtrs.Close();
sl@0
  3889
		}
sl@0
  3890
sl@0
  3891
sl@0
  3892
	//
sl@0
  3893
	//					Specific resource data tests
sl@0
  3894
	//
sl@0
  3895
sl@0
  3896
	gTest.Printf(_L("TestTransientHandling: Client-specific data tests ...\n"));
sl@0
  3897
	testNo=1;
sl@0
  3898
sl@0
  3899
	// These tests require a client name
sl@0
  3900
	TBuf8<MAX_RESOURCE_NAME_LENGTH+1>name8Bit;
sl@0
  3901
	name8Bit.Copy(gTestName);
sl@0
  3902
	TClientName* clientName = (TClientName*)&name8Bit;
sl@0
  3903
#if _DEBUG
sl@0
  3904
	TBuf <MAX_CLIENT_NAME_LENGTH> clientName16Bit;
sl@0
  3905
	clientName16Bit.Copy(*clientName);
sl@0
  3906
	clientName16Bit.SetLength(clientName->Length());
sl@0
  3907
	gTest.Printf(_L("Invoking TestTransientHandling client-specific data tests  with %S \n"),&clientName16Bit);
sl@0
  3908
#endif
sl@0
  3909
	// 13) Attempt to read the resource information without having previously loaded it.
sl@0
  3910
	gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
sl@0
  3911
		{
sl@0
  3912
		TUint numResources = 0;
sl@0
  3913
		if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResources, EFalse))!=KErrNone) // EFalse - don't load data
sl@0
  3914
			{
sl@0
  3915
			gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r);
sl@0
  3916
			return r;
sl@0
  3917
			}
sl@0
  3918
		// To support the GetInfoOnResourcesInUseByClient testing, instantiate TResourceInfoBuf objects
sl@0
  3919
		// and reference via an RSimplePointerArray
sl@0
  3920
		RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources);
sl@0
  3921
		for(TUint i=0;i<numResources;i++)
sl@0
  3922
			{
sl@0
  3923
			TResourceInfoBuf *info = new TResourceInfoBuf();
sl@0
  3924
			if((r=infoPtrs.Insert(info, i))!=KErrNone)
sl@0
  3925
				{
sl@0
  3926
				gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
sl@0
  3927
				}
sl@0
  3928
			}
sl@0
  3929
		if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, numResources, &infoPtrs))!=KErrNotReady)
sl@0
  3930
			{
sl@0
  3931
			gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource returned %d\n"),r);
sl@0
  3932
			return KErrGeneral;
sl@0
  3933
			}
sl@0
  3934
		else
sl@0
  3935
			r=KErrNone;	// Ensure misleading result is not propagated
sl@0
  3936
		infoPtrs.Close();
sl@0
  3937
		}
sl@0
  3938
sl@0
  3939
	// 14) To support the following test need a third channel
sl@0
  3940
	_LIT(tempStr2,"ExtraChan2");
sl@0
  3941
	TBufC<16> tempName2(tempStr2);
sl@0
  3942
	RBusDevResManUs channelThree;
sl@0
  3943
	if((r=OpenChannel(tempName2, channelThree))!=KErrNone)
sl@0
  3944
		{
sl@0
  3945
		gTest.Printf(_L("Failed to open channelThree, %d\n"),r);
sl@0
  3946
		channelTwo.Close();
sl@0
  3947
		return r;
sl@0
  3948
		}
sl@0
  3949
	// Read the number of resources (and, by default, read the resource information)
sl@0
  3950
	// Subsequent call to read the resource information (without re-loading) should return be successful
sl@0
  3951
	// Call to read the information for a client name with zero resource requirements (without re-loading) should return KErrNone, numResources==0
sl@0
  3952
	// Call to read the information for a client name with one or more resource requirements (without re-loading) should return KErrNotReady
sl@0
  3953
	gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
sl@0
  3954
		{
sl@0
  3955
		TUint numResources = 0;
sl@0
  3956
		if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResources))!=KErrNone) // load data
sl@0
  3957
			{
sl@0
  3958
			gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r);
sl@0
  3959
			return r;
sl@0
  3960
			}
sl@0
  3961
		// To support the GetInfoOnResourcesInUseByClient testing, instantiate TResourceInfoBuf objects
sl@0
  3962
		// and reference via an RSimplePointerArray
sl@0
  3963
		RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources);
sl@0
  3964
		for(TUint i=0;i<numResources;i++)
sl@0
  3965
			{
sl@0
  3966
			TResourceInfoBuf *info = new TResourceInfoBuf();
sl@0
  3967
			if((r=infoPtrs.Insert(info, i))!=KErrNone)
sl@0
  3968
				{
sl@0
  3969
				gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
sl@0
  3970
				}
sl@0
  3971
			}
sl@0
  3972
		if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, numResources, &infoPtrs))!=KErrNone)
sl@0
  3973
			{
sl@0
  3974
			gTest.Printf(_L("TestTransientHandling: gChannel GetInfoOnClientsUsingResource returned %d\n"),r);
sl@0
  3975
			return KErrGeneral;
sl@0
  3976
			}
sl@0
  3977
		TUint dumResources=0;
sl@0
  3978
		TBuf8<MAX_RESOURCE_NAME_LENGTH+1>name8Bit2;
sl@0
  3979
		name8Bit2.Copy(tempName2);
sl@0
  3980
		TClientName* clientName2 = (TClientName*)&name8Bit2;
sl@0
  3981
		if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName2, dumResources, &infoPtrs))!=KErrNone)
sl@0
  3982
			{
sl@0
  3983
			gTest.Printf(_L("TestTransientHandling: tempName2 GetInfoOnClientsUsingResource returned %d\n"),r);
sl@0
  3984
			return KErrGeneral;
sl@0
  3985
			}
sl@0
  3986
		if(dumResources!=0)
sl@0
  3987
			{
sl@0
  3988
			gTest.Printf(_L("TestTransientHandling: tempName2 GetInfoOnClientsUsingResource dumResources=%d\n"),dumResources);
sl@0
  3989
			return KErrGeneral;
sl@0
  3990
			}
sl@0
  3991
		TBuf8<MAX_RESOURCE_NAME_LENGTH+1>name8Bit1;
sl@0
  3992
		name8Bit1.Copy(tempName1);
sl@0
  3993
		TClientName* clientName1 = (TClientName*)&name8Bit1;
sl@0
  3994
		if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName1, numResources, &infoPtrs))!=KErrNotReady)
sl@0
  3995
			{
sl@0
  3996
			gTest.Printf(_L("TestTransientHandling: tempName1 GetInfoOnClientsUsingResource returned %d\n"),r);
sl@0
  3997
			return KErrGeneral;
sl@0
  3998
			}
sl@0
  3999
sl@0
  4000
		infoPtrs.Close();
sl@0
  4001
		}
sl@0
  4002
sl@0
  4003
sl@0
  4004
	// 15) Repeat the read the number of resources without reading the resource information
sl@0
  4005
	// Subsequent call to read the resources information (without re-loading) should return error KErrNotReady
sl@0
  4006
	// Then call to read the resources information (with re-loading) should be successful
sl@0
  4007
	gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
sl@0
  4008
		{
sl@0
  4009
		TUint numResources = 0;
sl@0
  4010
		if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResources, EFalse))!=KErrNone) // don't load data
sl@0
  4011
			{
sl@0
  4012
			gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r);
sl@0
  4013
			return r;
sl@0
  4014
			}
sl@0
  4015
		// To support the GetInfoOnResourcesInUseByClient testing, instantiate TResourceInfoBuf objects
sl@0
  4016
		// and reference via an RSimplePointerArray
sl@0
  4017
		RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources);
sl@0
  4018
		for(TUint i=0;i<numResources;i++)
sl@0
  4019
			{
sl@0
  4020
			TResourceInfoBuf *info = new TResourceInfoBuf();
sl@0
  4021
			if((r=infoPtrs.Insert(info, i))!=KErrNone)
sl@0
  4022
				{
sl@0
  4023
				gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
sl@0
  4024
				}
sl@0
  4025
			}
sl@0
  4026
		if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, numResources, &infoPtrs))!=KErrNotReady)
sl@0
  4027
			{
sl@0
  4028
			gTest.Printf(_L("TestTransientHandling: GetInfoOnResourcesInUseByClient returned %d\n"),r);
sl@0
  4029
			return KErrGeneral;
sl@0
  4030
			}
sl@0
  4031
		if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, numResources, &infoPtrs, ETrue))!=KErrNone)
sl@0
  4032
			{
sl@0
  4033
			gTest.Printf(_L("TestTransientHandling: GetInfoOnResourcesInUseByClient returned %d\n"),r);
sl@0
  4034
			return r;
sl@0
  4035
			}
sl@0
  4036
		infoPtrs.Close();
sl@0
  4037
		}
sl@0
  4038
sl@0
  4039
sl@0
  4040
	// 16) Attempt to read the resource information (without re-loading) with a buffer of insufficient size should
sl@0
  4041
	// return error KErrArgument
sl@0
  4042
	gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
sl@0
  4043
		{
sl@0
  4044
		TUint numResources = 0;
sl@0
  4045
		if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResources))!=KErrNone) // load data
sl@0
  4046
			{
sl@0
  4047
			gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r);
sl@0
  4048
			return r;
sl@0
  4049
			}
sl@0
  4050
		// To support the GetInfoOnResourcesInUseByClient testing, instantiate TResourceInfoBuf objects
sl@0
  4051
		// and reference via an RSimplePointerArray
sl@0
  4052
		RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources-1);
sl@0
  4053
		for(TUint i=0;i<(numResources-1);i++)
sl@0
  4054
			{
sl@0
  4055
			TResourceInfoBuf *info = new TResourceInfoBuf();
sl@0
  4056
			if((r=infoPtrs.Insert(info, i))!=KErrNone)
sl@0
  4057
				{
sl@0
  4058
				gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
sl@0
  4059
				}
sl@0
  4060
			}
sl@0
  4061
		if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, numResources, &infoPtrs))!=KErrArgument)
sl@0
  4062
			{
sl@0
  4063
			gTest.Printf(_L("TestTransientHandling: GetInfoOnResourcesInUseByClient returned %d\n"),r);
sl@0
  4064
			return KErrGeneral;
sl@0
  4065
			}
sl@0
  4066
sl@0
  4067
		// Ensure misleading result is not returned
sl@0
  4068
		r=KErrNone;
sl@0
  4069
		infoPtrs.Close();
sl@0
  4070
		}
sl@0
  4071
sl@0
  4072
	channelTwo.Close();
sl@0
  4073
	channelThree.Close();
sl@0
  4074
sl@0
  4075
	return r;
sl@0
  4076
	}
sl@0
  4077
sl@0
  4078
sl@0
  4079
EXPORT_C TInt E32Main()
sl@0
  4080
//
sl@0
  4081
// Main
sl@0
  4082
//
sl@0
  4083
    {
sl@0
  4084
	gTest.Start(_L("Test Power Resource Manager user side API\n"));
sl@0
  4085
  
sl@0
  4086
	TInt r = KErrNone;
sl@0
  4087
sl@0
  4088
	// Test attempted load of PDD
sl@0
  4089
    gTest.Next(_L("**Load PDD\n"));
sl@0
  4090
    r=User::LoadPhysicalDevice(PDD_NAME);
sl@0
  4091
    if((r!=KErrNone)&&(r!=KErrAlreadyExists))
sl@0
  4092
		{
sl@0
  4093
		gTest.Printf(_L("User::LoadPhysicalDevice error %d\n"),r);
sl@0
  4094
		}
sl@0
  4095
	else
sl@0
  4096
		{
sl@0
  4097
		// Test attempted load of LDD
sl@0
  4098
		gTest.Next(_L("**Load LDD\n"));
sl@0
  4099
		r=User::LoadLogicalDevice(LDD_NAME);
sl@0
  4100
		if((r!=KErrNone)&&(r!=KErrAlreadyExists))
sl@0
  4101
			gTest.Printf(_L("User::LoadLogicalDevice error - expected %d, got %d\n"),KErrAlreadyExists,r);
sl@0
  4102
		}
sl@0
  4103
    if((r==KErrNone)||(r==KErrAlreadyExists))
sl@0
  4104
		{
sl@0
  4105
		r = KErrNone; // Re-initialise in case set to KErrAlreadyExists
sl@0
  4106
		//
sl@0
  4107
		// Need a channel open for the following tests
sl@0
  4108
		gTest.Next(_L("**OpenAndRegisterChannel\n"));
sl@0
  4109
		r=OpenAndRegisterChannel();
sl@0
  4110
		if (r==KErrNone)
sl@0
  4111
			{
sl@0
  4112
			// Get the version of the ResourceController
sl@0
  4113
			TUint version;
sl@0
  4114
			if((r=gChannel.GetResourceControllerVersion(version))!=KErrNone)
sl@0
  4115
				{
sl@0
  4116
				gTest.Printf(_L("TestTransientHandling: GetResourceControllerVersion returned %d\n"),r);
sl@0
  4117
				return r;
sl@0
  4118
				}
sl@0
  4119
			gTest.Printf(_L("TestTransientHandling: ResourceController version =0x%x\n"),version);
sl@0
  4120
			}
sl@0
  4121
		if (r==KErrNone)
sl@0
  4122
			{
sl@0
  4123
			gTest.Next(_L("**TestThreadExclusiveAccess\n"));
sl@0
  4124
			r=TestThreadExclusiveAccess();
sl@0
  4125
			}
sl@0
  4126
		if (r==KErrNone)
sl@0
  4127
			{
sl@0
  4128
			gTest.Next(_L("**TestGetClientGetResourceInfo - initial state\n"));
sl@0
  4129
			r=TestGetClientGetResourceInfo();
sl@0
  4130
			}
sl@0
  4131
		if (r==KErrNone)
sl@0
  4132
			{
sl@0
  4133
			gTest.Next(_L("**TestGetSetResourceStateOps\n"));
sl@0
  4134
			r=TestGetSetResourceStateOps();
sl@0
  4135
			}
sl@0
  4136
		if (r==KErrNone)
sl@0
  4137
			{
sl@0
  4138
			gTest.Next(_L("**TestGetClientGetResourceInfo - after changing stateof Async resource\n"));
sl@0
  4139
			r=TestGetClientGetResourceInfo();
sl@0
  4140
			}
sl@0
  4141
		if (r==KErrNone)
sl@0
  4142
			{
sl@0
  4143
			gTest.Next(_L("**TestGetSetResourceStateQuota\n"));
sl@0
  4144
			r=TestGetSetResourceStateQuota();
sl@0
  4145
			}
sl@0
  4146
		if (r==KErrNone)
sl@0
  4147
			{
sl@0
  4148
			gTest.Next(_L("**TestNotificationOps\n"));
sl@0
  4149
			r=TestNotificationOps();
sl@0
  4150
			}
sl@0
  4151
		if (r==KErrNone)
sl@0
  4152
			{
sl@0
  4153
			gTest.Next(_L("**TestNotificationQuota\n"));
sl@0
  4154
			r=TestNotificationQuota();
sl@0
  4155
			}
sl@0
  4156
		if (r==KErrNone)
sl@0
  4157
			{
sl@0
  4158
			// Should be no change since last invocation (assuming that
sl@0
  4159
			// no clients other than those in this test)
sl@0
  4160
			gTest.Next(_L("**TestGetClientGetResourceInfo - last invocation\n"));
sl@0
  4161
			r=TestGetClientGetResourceInfo();
sl@0
  4162
			}
sl@0
  4163
		if (r==KErrNone)
sl@0
  4164
			{
sl@0
  4165
			gTest.Next(_L("**TestAdditionalThread\n"));
sl@0
  4166
			r=TestAdditionalThread();
sl@0
  4167
			}
sl@0
  4168
		if (r==KErrNone)
sl@0
  4169
			{
sl@0
  4170
			gTest.Next(_L("**TestTransientHandling\n"));
sl@0
  4171
			r=TestTransientHandling();
sl@0
  4172
			}
sl@0
  4173
		}
sl@0
  4174
	gChannel.Close();
sl@0
  4175
sl@0
  4176
    User::FreeLogicalDevice(KLddRootName);
sl@0
  4177
    User::FreePhysicalDevice(PDD_NAME);	
sl@0
  4178
	User::After(100000);	// Allow idle thread to run for driver unloading
sl@0
  4179
sl@0
  4180
	gTest.End();
sl@0
  4181
	return r;
sl@0
  4182
    }
sl@0
  4183