1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/resmanus/t_resmanus.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,4183 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <e32test.h>
1.20 +#include <e32def.h>
1.21 +#include <e32def_private.h>
1.22 +
1.23 +#include <d32resmanus.h>
1.24 +
1.25 +#ifdef PRM_ENABLE_EXTENDED_VERSION
1.26 +#define LDD_NAME _L("resourcecontrollerextended.ldd")
1.27 +#else
1.28 +#define LDD_NAME _L("resourcecontrol.ldd")
1.29 +#endif
1.30 +
1.31 +#ifdef PRM_ENABLE_EXTENDED_VERSION
1.32 +#define PDD_NAME _L("resourcecontrollerextended.pdd")
1.33 +#else
1.34 +#define PDD_NAME _L("resourcecontroller.pdd")
1.35 +#endif
1.36 +
1.37 +//#define PIRATE_THREAD_TESTS
1.38 +
1.39 +_LIT(testableResourceName,"SymbianSimulResource");
1.40 +
1.41 +#ifdef RESMANUS_KERN
1.42 +_LIT(testName,"t_resmanuskern");
1.43 +#else
1.44 +_LIT(testName,"t_resmanus");
1.45 +#endif
1.46 +
1.47 +TBuf<16> gTestName(testName);
1.48 +
1.49 +GLDEF_D RTest gTest(testName);
1.50 +GLDEF_D RBusDevResManUs gChannel;
1.51 +
1.52 +TUint8 KNoOfGetStateRequests = 5;
1.53 +TUint8 KNoOfSetStateRequests = 4;
1.54 +TUint8 KNoOfNotifyRequests = 7;
1.55 +#define MAX_NUM_REQUESTS 8 // Must be (at least) one greater than the largest of
1.56 + // KNoOfGetStateRequests, KNoOfSetStateRequests, KNoOfNotifyRequests
1.57 +#ifdef _DEBUG
1.58 +TUint gLongLatencyResource;
1.59 +TBool gHaveAsyncRes = EFalse;
1.60 +TInt gAsyncResStateDelta = 0;
1.61 +
1.62 +TUint gSharedResource;
1.63 +TBool gHaveSharedRes = EFalse;
1.64 +TInt gSharedResStateDelta = 0;
1.65 +#else
1.66 +// The UREL version of the driver will not implement the arrays and functionality required
1.67 +// to determine the async and shared resources to use at runtime. The values provided here
1.68 +// have been pre-determined to operate successfully with the simulated PSL.
1.69 +//
1.70 +TUint gLongLatencyResource = 6;
1.71 +TBool gHaveAsyncRes = ETrue;
1.72 +TInt gAsyncResStateDelta = -1;
1.73 +
1.74 +TUint gSharedResource = 12;
1.75 +TBool gHaveSharedRes = ETrue;
1.76 +TInt gSharedResStateDelta = -1;
1.77 +#endif
1.78 +
1.79 +TBool gUseCached = EFalse;
1.80 +
1.81 +LOCAL_C TInt OpenChannel(TDesC16& aName, RBusDevResManUs& aChannel)
1.82 + {
1.83 + TInt r = KErrNone;
1.84 + // API accepts 8-bit descriptors, only - so convert name accordingly
1.85 + TBuf8<MAX_RESOURCE_NAME_LENGTH+1>EightBitName;
1.86 + EightBitName.Copy(aName);
1.87 + r=(aChannel.Open(EightBitName));
1.88 + if (r!=KErrNone)
1.89 + gTest.Printf(_L("OpenChannel: Handle for channel %S error code =0x%x\n"),&aName,r);
1.90 + else
1.91 + gTest.Printf(_L("OpenChannel: Handle for channel %S =0x%x\n"),&aName,aChannel.Handle());
1.92 + return r;
1.93 + }
1.94 +
1.95 +LOCAL_C TInt HelperResources()
1.96 +//
1.97 +// Helper method to support OpenAndRegisterChannel
1.98 +// Invokes GetNoOfResources, GetAllResourcesInfo and GetResourceIdByName
1.99 +//
1.100 + {
1.101 + TInt r = KErrNone;
1.102 +
1.103 + __KHEAP_MARK;
1.104 +
1.105 + // Check what resources are available
1.106 + gTest.Printf(_L("**Test GetNoOfResources\n"));
1.107 + TUint numResources=0;
1.108 + if((r=gChannel.GetNoOfResources(numResources))!=KErrNone)
1.109 + {
1.110 + gTest.Printf(_L("GetNoOfResources for test channel returned %d\n"),r);
1.111 + return r;
1.112 + }
1.113 + gTest.Printf(_L("Number of resources = %d (=0x%x)\n"),numResources,numResources);
1.114 +
1.115 + // Read the resource information
1.116 + gTest.Printf(_L("**Test GetAllResourcesInfo\n"));
1.117 +
1.118 + // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects
1.119 + // and reference via an RSimplePointerArray
1.120 + TUint bufSize = numResources;
1.121 + RSimplePointerArray<TResourceInfoBuf> infoPtrs(bufSize);
1.122 + for(TUint i=0;i<bufSize;i++)
1.123 + {
1.124 + TResourceInfoBuf *info = new TResourceInfoBuf();
1.125 + if((r=infoPtrs.Insert(info, i))!=KErrNone)
1.126 + {
1.127 + gTest.Printf(_L("GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),i,r);
1.128 + }
1.129 + }
1.130 + TUint updateNumResources=numResources;
1.131 + if((r=gChannel.GetAllResourcesInfo(&infoPtrs,updateNumResources))!=KErrNone)
1.132 + {
1.133 + gTest.Printf(_L("GetAllResourcesInfo for channel returned %d\n"),r);
1.134 + return r;
1.135 + }
1.136 + gTest.Printf(_L("Updated number of resources = %d\n"),updateNumResources);
1.137 +
1.138 +#ifdef _DEBUG
1.139 + // Print resource names
1.140 + {
1.141 + TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name;
1.142 + for(TUint i=0; i<updateNumResources; i++)
1.143 + {
1.144 + TResourceInfoBuf* currRes = infoPtrs[i];
1.145 + name.Copy((*currRes)().iName);
1.146 + name.PtrZ();
1.147 + gTest.Printf(_L("Resource %d name = %S \n"),i,&name);
1.148 + };
1.149 + }
1.150 +#endif
1.151 +
1.152 + // Select a resource to use, then pass its name to GetResourceIdByName
1.153 + // to check that the corresponding resource ID is acquired.
1.154 + TResourceInfo currRes = (*infoPtrs[0])();
1.155 + if(updateNumResources>1)
1.156 + currRes=(*infoPtrs[1])();// First resource may be a dummy
1.157 + TUint resourceId;
1.158 + gTest.Printf(_L("Invoking GetResourceIdByName for last resource name extracted \n"));
1.159 + if((r=gChannel.GetResourceIdByName(currRes.iName, resourceId))!=KErrNone)
1.160 + {
1.161 + gTest.Printf(_L("GetResourceIdByName for channel returned %d \n"),r);
1.162 + return r;
1.163 + }
1.164 + gTest.Printf(_L("GetResourceIdByName gave ID = %d\n"),resourceId);
1.165 +
1.166 + infoPtrs.Close();
1.167 +
1.168 + __KHEAP_MARKEND;
1.169 +
1.170 + return r;
1.171 + }
1.172 +
1.173 +LOCAL_C TInt CheckForSimulatedResources()
1.174 +//
1.175 +// Get the name of the first resource - if it does not match the expected name
1.176 +// then the testing must not proceed, so return the relevant error code
1.177 +//
1.178 + {
1.179 + TInt r = KErrNone;
1.180 + TResourceInfoBuf buffer;
1.181 + if((r=gChannel.GetResourceInfo(1, &buffer))!=KErrNone) // first resource ID = 1
1.182 + {
1.183 + gTest.Printf(_L("CheckForSimulatedResources, candidate get resource info returned %d\n"),r);
1.184 + return r;
1.185 + }
1.186 + // Check the name of the resource
1.187 + TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name;
1.188 + name.Copy(buffer().iName);
1.189 + name.PtrZ();
1.190 + if((r=name.Compare(testableResourceName))!=KErrNone)
1.191 + {
1.192 + gTest.Printf(_L("Resource name = %S, require %S \n"),&name,&testableResourceName);
1.193 + r=KErrNotSupported;
1.194 + }
1.195 + return r;
1.196 + }
1.197 +
1.198 +//----------------------------------------------------------------------------------------------
1.199 +//! @SYMTestCaseID KBASE-T_RESMANUS-0607
1.200 +//! @SYMTestType UT
1.201 +//! @SYMPREQ PREQ1398
1.202 +//! @SYMTestCaseDesc This test case tests channel opening and initialisation APIs.
1.203 +//! @SYMTestActions 0) Call Open API with a valid name.
1.204 +//!
1.205 +//! 1) Call Open API for two more channels
1.206 +//! (to demonstrate multiple clients (channels) can be supported concurrently).
1.207 +//!
1.208 +//! 2) Call Open with an oversized name.
1.209 +//!
1.210 +//! 3) Call GetNoOfResources API
1.211 +//!
1.212 +//! 4) Call GetAllResourcesInfo API
1.213 +//!
1.214 +//! 5) Call GetResourceIdByName API for last of resource names gathered
1.215 +//! in previous step
1.216 +//!
1.217 +//! 6) Call Initialise API on the channel originally created, with non-zero arguments.
1.218 +//!
1.219 +//! @SYMTestExpectedResults 0) API should return with KErrNone, exits otherwise.
1.220 +//! 1) API should return with KErrNone, exits otherwise.
1.221 +//! 2) API should return with KErrBadName, exits otherwise.
1.222 +//! 3) API should return with KErrNone, exits otherwise.
1.223 +//! 4) API should return with KErrNone, exits otherwise.
1.224 +//! 5) API should return with KErrNone, exits otherwise.
1.225 +//! 6) API should return with KErrNone, exits otherwise.
1.226 +//!
1.227 +//! @SYMTestPriority High
1.228 +//! @SYMTestStatus Implemented
1.229 +//----------------------------------------------------------------------------------------------
1.230 +LOCAL_C TInt OpenAndRegisterChannel()
1.231 +//
1.232 +// Test Open and Initialise functionality
1.233 +// Also invokes Resource inspection methods via HelperResource
1.234 +//
1.235 + {
1.236 + TInt r;
1.237 +
1.238 + if((r=OpenChannel(gTestName, gChannel))!=KErrNone)
1.239 + return r;
1.240 +
1.241 + // Check that the simulated resources required to support this testing are present
1.242 + // If not, close the channel and return the propagated error code.
1.243 + if((r=CheckForSimulatedResources())!=KErrNone)
1.244 + {
1.245 + gChannel.Close();
1.246 + return r;
1.247 + }
1.248 +
1.249 + __KHEAP_MARK; // gTestName will remain open (allocated) when heap is checked
1.250 +
1.251 + // Open a couple of additional channels to prove that more than one
1.252 + // can exist
1.253 + _LIT(tempStr1,"temp1");
1.254 + TBufC<16> tempName1(tempStr1);
1.255 + _LIT(tempStr2,"temp2");
1.256 + TBufC<16> tempName2(tempStr2);
1.257 +
1.258 + RBusDevResManUs channelTwo;
1.259 + RBusDevResManUs channelThree;
1.260 +
1.261 + if((r=OpenChannel(tempName1, channelTwo))!=KErrNone)
1.262 + return r;
1.263 + if((r=OpenChannel(tempName2, channelThree))!=KErrNone)
1.264 + return r;
1.265 +
1.266 + // The following test requires manual enabling in resource controller of macro
1.267 + // DEBUG_VERSION - this is not done by default, so test is deactivated here.
1.268 + //
1.269 +#if 0
1.270 + // Test rejection if try a name already in use
1.271 + //
1.272 + // (For UREL builds, duplicate names are allowed; but
1.273 + // for UDEB builds, they are monitored and rejected)
1.274 + //
1.275 + RBusDevResManUs channelSameName;
1.276 + r=OpenChannel(tempName1, channelSameName);
1.277 + channelSameName.Close(); // Channel not used after here
1.278 + if (r==KErrNone)
1.279 + {
1.280 + gTest.Printf(_L("Error: Handle for re-used name channel =0x%x\n"),channelSameName.Handle());
1.281 + return KErrGeneral;
1.282 + }
1.283 + else if(r!=KErrCouldNotConnect)
1.284 + {
1.285 + gTest.Printf(_L("Error: re-used name gave unexpected error code =0x%x\n"),r);
1.286 + return r;
1.287 + }
1.288 + else // if(r==KErrCouldNotConnect)
1.289 + {
1.290 + gTest.Printf(_L("Re-used channel name rejected with correct error code\n"));
1.291 + }
1.292 +#endif // if 0
1.293 +
1.294 + // Test oversized name rejection
1.295 + _LIT(longStr,"1abcdefghijklmnopqrstuvwxyz2abcdefghijklmnopqrstuvwxyz3abcdefghijklmnopqrstuvwxyz4abcdefghijklmnopqrstuvwxyz5abcdefghijklmnopqrstuvwxyz6abcdefghijklmnopqrstuvwxyz7abcdefghijklmnopqrstuvwxyz8abcdefghijklmnopqrstuvwxyz9abcdefghijklmnopqrstuvwxyz10abcdefghijklmnopqrstuvwxyz");
1.296 + TBufC<271> longName(longStr);
1.297 +
1.298 + // API accepts 8-bit descriptors for names, only
1.299 + TBuf8<271>longName_8Bit;
1.300 + longName_8Bit.Copy(longName);
1.301 +
1.302 + RBusDevResManUs channelLong;
1.303 + r=(channelLong.Open(longName_8Bit));
1.304 + channelLong.Close(); // Channel not used after here
1.305 + if (r==KErrNone)
1.306 + {
1.307 + gTest.Printf(_L("Error: Handle for oversize name channel =0x%x\n"),channelLong.Handle());
1.308 + return KErrGeneral;
1.309 + }
1.310 + else if(r!=KErrBadName)
1.311 + {
1.312 + gTest.Printf(_L("Error: oversized name gave unexpected error code =0x%x\n"),r);
1.313 + return r;
1.314 + }
1.315 + else // if(r==KErrBadName)
1.316 + {
1.317 + gTest.Printf(_L("Oversized name for channel rejected with correct error code\n"));
1.318 + }
1.319 +
1.320 + // Invokes GetNoOfResources, GetAllResourcesInfo and GetResourceIdByName
1.321 + if((r=HelperResources())!=KErrNone)
1.322 + return r;
1.323 +
1.324 + // Close the temporary channels
1.325 + // Do this before channel registration to enable valid check of kernel heap
1.326 + channelTwo.Close();
1.327 + channelThree.Close();
1.328 +
1.329 + __KHEAP_MARKEND;
1.330 +
1.331 + // Channel registration
1.332 + gTest.Printf(_L("Invoking Initialise with values 0x%x, 0x%x, 0x%x\n"),KNoOfGetStateRequests,KNoOfSetStateRequests,KNoOfNotifyRequests);
1.333 + if ((r=gChannel.Initialise(KNoOfGetStateRequests,KNoOfSetStateRequests,KNoOfNotifyRequests))!=KErrNone)
1.334 + {
1.335 + gTest.Printf(_L("Initialise for channel returned %d\n"),r);
1.336 + return r;
1.337 + }
1.338 +
1.339 + return KErrNone;
1.340 + }
1.341 +
1.342 +
1.343 +LOCAL_C TInt HelperClients()
1.344 +//
1.345 +// Helper method to support TestGetClientGetResourceInfo
1.346 +// Invokes GetNoOfClients and GetNamesAllClients
1.347 +//
1.348 + {
1.349 + __KHEAP_MARK;
1.350 +
1.351 + TInt r = KErrNone;
1.352 + TUint numClients = 0;
1.353 + TUint numAllClients = 0;
1.354 + //
1.355 + // GetNoOfClients - with aIncludeKern=EFalse
1.356 + //
1.357 + if((r=gChannel.GetNoOfClients(numClients, EFalse)) != KErrNone)
1.358 + {
1.359 + gTest.Printf(_L("GetNoOfClients (aIncludeKern==EFalse) returned %d\n"),r);
1.360 + return r;
1.361 + }
1.362 + gTest.Printf(_L("GetNoOfClients (aIncludeKern==EFalse) gave 0x%x clients\n"),numClients);
1.363 +
1.364 + //
1.365 + // GetNoOfClients - with aIncludeKern=ETrue
1.366 + //
1.367 + r=gChannel.GetNoOfClients(numAllClients, ETrue);
1.368 +#ifdef RESMANUS_KERN
1.369 + if(r==KErrNone)
1.370 + gTest.Printf(_L("GetNoOfClients (aIncludeKern==ETrue) returned KErrNone\n"));
1.371 +#else
1.372 + if(r==KErrPermissionDenied)
1.373 + gTest.Printf(_L("GetNoOfClients (aIncludeKern==ETrue) returned KErrPermissionDenied\n"));
1.374 +#endif
1.375 + else
1.376 + {
1.377 + gTest.Printf(_L("GetNoOfClients (aIncludeKern==ETrue) returned %d"),r);
1.378 + return KErrGeneral;
1.379 + }
1.380 +
1.381 + // To support the GetNamesAllClients testing, instantiate TClientName objects
1.382 + // and reference via an RSimplePointerArray
1.383 + TUint bufSize = (numAllClients>numClients)?numAllClients:numClients;
1.384 + RSimplePointerArray<TClientName> infoPtrs(bufSize);
1.385 + for(TUint i=0;i<bufSize;i++)
1.386 + {
1.387 + TClientName *info = new TClientName();
1.388 + if((r=infoPtrs.Insert(info, i))!=KErrNone)
1.389 + {
1.390 + gTest.Printf(_L("GetNamesAllClients infoPtrs.Insert at index %d returned %d\n"),i,r);
1.391 + }
1.392 + }
1.393 +
1.394 + //
1.395 + // GetNamesAllClients - with aIncludeKern=EFalse
1.396 + //
1.397 + if((r=gChannel.GetNamesAllClients(&infoPtrs, numClients, EFalse)) != KErrNone)
1.398 + {
1.399 + gTest.Printf(_L("GetNamesAllClients (aIncludeKern==EFalse) returned %d\n"),r);
1.400 + return r;
1.401 + }
1.402 +#ifdef _DEBUG
1.403 + else
1.404 + {
1.405 + gTest.Printf(_L("GetNamesAllClients (aIncludeKern==EFalse) returned KErrNone, names follow\n"));
1.406 + for(TUint i=0;i<numClients;i++)
1.407 + {
1.408 + TClientName *currName = infoPtrs[i];
1.409 + TBuf16<sizeof(TClientName)> name;
1.410 + name.Copy(*currName);
1.411 + gTest.Printf(_L("Client name %d = %S\n"),i,&name);
1.412 + }
1.413 + }
1.414 +#endif
1.415 +
1.416 + //
1.417 + // GetNamesAllClients - with aIncludeKern=ETrue
1.418 + //
1.419 +#ifdef RESMANUS_KERN
1.420 + if((r=gChannel.GetNamesAllClients(&infoPtrs, numAllClients, ETrue)) != KErrNone)
1.421 + {
1.422 + gTest.Printf(_L("GetNamesAllClients (aIncludeKern==ETrue) returned %d\n"),r);
1.423 + return r;
1.424 + }
1.425 +#ifdef _DEBUG
1.426 + else
1.427 + {
1.428 + gTest.Printf(_L("GetNamesAllClients (aIncludeKern==ETrue) returned KErrNone, names follow\n"));
1.429 + for(TUint i=0;i<numAllClients;i++)
1.430 + {
1.431 + TClientName *currName = infoPtrs[i];
1.432 + TBuf16<sizeof(TClientName)> name;
1.433 + name.Copy(*currName);
1.434 + gTest.Printf(_L("Client name %d = %S\n"),i,&name);
1.435 + }
1.436 + }
1.437 +#endif
1.438 +#else
1.439 + if((r=gChannel.GetNamesAllClients(&infoPtrs, numClients, ETrue)) == KErrPermissionDenied)
1.440 + {
1.441 + gTest.Printf(_L("GetNamesAllClients (aIncludeKern==ETrue) returned KErrPermissionDenied\n"));
1.442 + r=KErrNone; // Ensure misleading status is not returned
1.443 + }
1.444 + else
1.445 + {
1.446 + gTest.Printf(_L("GetNamesAllClients (aIncludeKern==ETrue) returned %d"),r);
1.447 + return r;
1.448 + }
1.449 +#endif
1.450 +
1.451 + infoPtrs.Close();
1.452 + __KHEAP_MARKEND;
1.453 +
1.454 + return r;
1.455 + }
1.456 +
1.457 +LOCAL_C TInt HelperClientsUsingResource(TUint aResourceId)
1.458 +//
1.459 +// Helper method to support TestGetClientGetResourceInfo
1.460 +// Invokes GetNumClientsUsingResource and GetInfoOnClientsUsingResource
1.461 +//
1.462 + {
1.463 + __KHEAP_MARK;
1.464 +
1.465 + TInt r = KErrNone;
1.466 + //
1.467 + // GetNumClientsUsingResource - with aIncludeKern=ETrue
1.468 + //
1.469 + TUint resourceAllClients = 0;
1.470 + if((r=gChannel.GetNumClientsUsingResource(aResourceId, resourceAllClients, ETrue)) == KErrPermissionDenied)
1.471 + {
1.472 + gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==ETrue) returned KErrPermissionDenied\n"));
1.473 +#ifdef RESMANUS_KERN
1.474 + return r;
1.475 + }
1.476 + else
1.477 + {
1.478 + if(r!=KErrNone)
1.479 + {
1.480 + gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==ETrue) returned %d\n"),r);
1.481 + return r;
1.482 + }
1.483 + else
1.484 + gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==ETrue) reported 0x%x clients\n"),resourceAllClients);
1.485 + }
1.486 +#else
1.487 + }
1.488 + else
1.489 + {
1.490 + gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==ETrue) returned %d\n"),r);
1.491 + return r;
1.492 + }
1.493 +#endif
1.494 + //
1.495 + // GetNumClientsUsingResource - with aIncludeKern=EFalse
1.496 + //
1.497 + TUint resourceClients = 0;
1.498 + if((r=gChannel.GetNumClientsUsingResource(aResourceId, resourceClients, EFalse)) != KErrNone)
1.499 + {
1.500 + // If there are no clients that have requested a level then the Resource Controller will
1.501 + // the client ID as a bad argument
1.502 + if(!((resourceClients==0)&&(r==KErrArgument)))
1.503 + {
1.504 + gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==EFalse) returned %d\n"),r);
1.505 + return r;
1.506 + }
1.507 + else
1.508 + r=KErrNone; // Ensure expected error is not misinterpeted
1.509 + }
1.510 + else
1.511 + gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==EFalse) reported 0x%x clients\n"),resourceClients);
1.512 +
1.513 + // To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects
1.514 + // and reference via an RSimplePointerArray
1.515 + TUint bufSize = (resourceAllClients>resourceClients)?resourceAllClients:resourceClients;
1.516 + if(bufSize>0)
1.517 + {
1.518 + RSimplePointerArray<TClientInfoBuf> infoPtrs(bufSize);
1.519 + for(TUint i=0;i<bufSize;i++)
1.520 + {
1.521 + TClientInfoBuf *info = new TClientInfoBuf();
1.522 + if((r=infoPtrs.Insert(info, i))!=KErrNone)
1.523 + {
1.524 + gTest.Printf(_L("GetInfoOnClientsUsingResource infoPtrs.Insert at index %d returned %d\n"),i,r);
1.525 + }
1.526 + }
1.527 +
1.528 + //
1.529 + // GetInfoOnClientsUsingResource - with aIncludeKern=EFalse
1.530 + //
1.531 + if((r=gChannel.GetInfoOnClientsUsingResource(aResourceId, resourceClients, &infoPtrs, EFalse)) != KErrNone)
1.532 + {
1.533 + // If there are no clients that have requested a level then the resource will not
1.534 + // have been found
1.535 + if(!((resourceClients==0)&&(r==KErrNotFound)))
1.536 + {
1.537 + gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==EFalse) returned %d\n"),r);
1.538 + return r;
1.539 + }
1.540 + }
1.541 +#ifdef _DEBUG
1.542 + else
1.543 + {
1.544 + gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==EFalse) returned KErrNone, info follows\n"));
1.545 + for(TUint i=0;i<resourceClients;i++)
1.546 + {
1.547 + TClientInfoBuf* currInfoBuf = infoPtrs[i];
1.548 + TClientInfo currInfo=(*currInfoBuf)();
1.549 + TBuf16<sizeof(TClientName)> name;
1.550 + name.Copy(currInfo.iName);
1.551 + gTest.Printf(_L("Client name %d = %S, ID=0x%x\n"),i,&name,currInfo.iId);
1.552 + }
1.553 + }
1.554 +#endif
1.555 + //
1.556 + // GetInfoOnClientsUsingResource - with aIncludeKern=ETrue
1.557 + //
1.558 + r=gChannel.GetInfoOnClientsUsingResource(aResourceId, resourceAllClients, &infoPtrs, ETrue);
1.559 + {
1.560 +#ifdef RESMANUS_KERN
1.561 + if(r != KErrNone)
1.562 + {
1.563 + // If there are no clients that have requested a level then the Resource Controller
1.564 + // will report a request for information on 0 clients as a bad argument
1.565 + if(!((resourceClients==0)&&(r==KErrArgument)))
1.566 + {
1.567 + gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned %d\n"),r);
1.568 + return r;
1.569 + }
1.570 + else
1.571 + r=KErrNone; // Ensure misleading result is not returned
1.572 + }
1.573 +#ifdef _DEBUG
1.574 + else
1.575 + {
1.576 + gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned KErrNone, info follows\n"));
1.577 + for(TUint i=0;i<resourceClients;i++)
1.578 + {
1.579 + TClientInfoBuf* currInfoBuf = infoPtrs[i];
1.580 + TClientInfo currInfo=(*currInfoBuf)();
1.581 + TBuf16<sizeof(TClientName)> name;
1.582 + name.Copy(currInfo.iName);
1.583 + gTest.Printf(_L("Client name %d = %S, ID=0x%x\n"),i,&name,currInfo.iId);
1.584 + }
1.585 + }
1.586 +#endif
1.587 +#else
1.588 + if(r == KErrNone)
1.589 + {
1.590 + gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned KErrNone"));
1.591 + return KErrGeneral;
1.592 + }
1.593 + else if(r==KErrPermissionDenied)
1.594 + {
1.595 + gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned KErrPermissionDenied\n"));
1.596 + r=KErrNone; // Ensure that misleading result is not propagated
1.597 + }
1.598 + else
1.599 + {
1.600 + gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned %d\n"),r);
1.601 + // If there are no clients that have requested a level then the Resource Controller
1.602 + // will report a request for information on 0 clients as a bad argument
1.603 + if(!((resourceClients==0)&&(r==KErrArgument)))
1.604 + return r;
1.605 + }
1.606 +#endif
1.607 + }
1.608 + }
1.609 +
1.610 + __KHEAP_MARKEND;
1.611 +
1.612 + return r;
1.613 + }
1.614 +
1.615 +
1.616 +
1.617 +LOCAL_C TInt HelperResourcesInUseByClient()
1.618 +//
1.619 +// Helper method to supportTestGetClientGetResourceInfo
1.620 +// Invokes GetNumResourcesInUseByClient and GetInfoOnResourcesInUseByClient
1.621 +//
1.622 + {
1.623 + __KHEAP_MARK;
1.624 +
1.625 + TInt r = KErrNone;
1.626 + //
1.627 + // GetNumResourcesInUseByClient
1.628 + //
1.629 + // API accepts 8-bit descriptors, only - so convert name accordingly
1.630 + TBuf8<MAX_RESOURCE_NAME_LENGTH+1>name8Bit;
1.631 + name8Bit.Copy(gTestName);
1.632 + TClientName* clientName = (TClientName*)&name8Bit;
1.633 +#if _DEBUG
1.634 + TBuf <MAX_CLIENT_NAME_LENGTH> clientName16Bit;
1.635 + clientName16Bit.Copy(*clientName);
1.636 + clientName16Bit.SetLength(clientName->Length());
1.637 + gTest.Printf(_L("Invoking GetNumResourcesInUseByClient with %S (expect KErrPermissionDenied if no levels requested yet)\n"),&clientName16Bit);
1.638 +#endif
1.639 + TUint numResourcesForClient;
1.640 + if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResourcesForClient)) != KErrNone)
1.641 + {
1.642 + gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r);
1.643 + return r;
1.644 + }
1.645 + gTest.Printf(_L("GetNumResourcesInUseByClient gave number of resources = %d\n"),numResourcesForClient);
1.646 + //
1.647 + // In addition, check response when the name of an unknown client is passed
1.648 + //
1.649 + // Negative test - ensure that an unknown client name fails
1.650 + _LIT(dumName,"DoesNotExist");
1.651 + TBuf<16> dumNameBuf(dumName);
1.652 + TBuf8<MAX_RESOURCE_NAME_LENGTH+1>dumName8Bit;
1.653 + dumName8Bit.Copy(dumNameBuf);
1.654 + TClientName* dumClientName = (TClientName*)&dumName8Bit;
1.655 +#if _DEBUG
1.656 + gTest.Printf(_L("Invoking GetNumResourcesInUseByClient with %S\n"),&dumNameBuf);
1.657 +#endif
1.658 + TUint numResForDumClient;
1.659 + if((r=gChannel.GetNumResourcesInUseByClient(*dumClientName, numResForDumClient)) != KErrNotFound)
1.660 + {
1.661 + gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r);
1.662 + if(r==KErrNone)
1.663 + r=KErrGeneral;
1.664 + return r;
1.665 + }
1.666 + gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r);
1.667 + r=KErrNone; // Ensure misleading error code is not propagated
1.668 +
1.669 + //
1.670 + // GetInfoOnResourcesInUseByClient
1.671 + //
1.672 + // If the (TUint) number of resources in use by the client is zero skip the attempt to read the resource information
1.673 + TUint updatedNumResourcesForClient = numResourcesForClient;
1.674 + if(numResourcesForClient!=0)
1.675 + {
1.676 + TUint bufSize = numResourcesForClient;
1.677 + RSimplePointerArray<TResourceInfoBuf> infoPtrs(bufSize);
1.678 + for(TUint i=0;i<bufSize;i++)
1.679 + {
1.680 + TResourceInfoBuf *info = new TResourceInfoBuf();
1.681 + if((r=infoPtrs.Insert(info, i))!=KErrNone)
1.682 + {
1.683 + gTest.Printf(_L("GetInfoOnResourcesInUseByClient infoPtrs.Insert at index %d returned %d\n"),i,r);
1.684 + }
1.685 + }
1.686 +
1.687 + if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, updatedNumResourcesForClient, &infoPtrs)) != KErrNone)
1.688 + {
1.689 + gTest.Printf(_L("GetInfoOnResourcesInUseByClient returned %d\n"),r);
1.690 + // If there are no clients that have requested a level then the Resource Controller
1.691 + // will report a request for information on 0 clients as a bad argument
1.692 + if(!((updatedNumResourcesForClient==0)&&(r==KErrArgument)))
1.693 + return r;
1.694 + else
1.695 + r=KErrNone; // Ensure misleading value is not returned by this function
1.696 + }
1.697 + else
1.698 + {
1.699 + gTest.Printf(_L("GetInfoOnResourcesInUseByClient gave updated number of resources %d\n"),updatedNumResourcesForClient);
1.700 +#ifdef _DEBUG
1.701 + // Print resource names
1.702 + TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name;
1.703 + for(TUint i=0; i<updatedNumResourcesForClient; i++)
1.704 + {
1.705 + TResourceInfoBuf* currRes = infoPtrs[i];
1.706 + name.Copy((*currRes)().iName);
1.707 + name.PtrZ();
1.708 + gTest.Printf(_L("Resource %d name = %S \n"),i,&name);
1.709 + };
1.710 +#endif
1.711 + }
1.712 + //
1.713 + // In addition, check response when the name of an unknown client is passed
1.714 + //
1.715 + // Negative test - ensure that an unknown client name fails
1.716 + r=gChannel.GetInfoOnResourcesInUseByClient(*dumClientName, updatedNumResourcesForClient, &infoPtrs);
1.717 + gTest.Printf(_L("GetInfoOnResourcesInUseByClient for dummy client returned %d\n"),r);
1.718 + if(r==KErrNone)
1.719 + return KErrGeneral;
1.720 + else if(r!=KErrNotFound)
1.721 + return r;
1.722 + // Ensure that misleading information is not returned to the calling function
1.723 + r=KErrNone;
1.724 +
1.725 + infoPtrs.Close();
1.726 + }
1.727 +
1.728 + __KHEAP_MARKEND;
1.729 +
1.730 + return r;
1.731 + }
1.732 +
1.733 +
1.734 +LOCAL_C TInt HelperGetClientResourceInfo()
1.735 +//
1.736 +// Test methods to access information about clients and resources
1.737 +//
1.738 + {
1.739 + __KHEAP_MARK;
1.740 +
1.741 + TInt r = KErrNone;
1.742 + // Invokes GetNoOfClients and GetNamesAllClients
1.743 + if((r=HelperClients())!=KErrNone)
1.744 + return r;
1.745 +
1.746 + // Invokes GetNumClientsUsingResource and GetInfoOnClientsUsingResource
1.747 + //
1.748 + // First invoke on the Async resource
1.749 + TUint resourceId = 1; // Arbitrary
1.750 + if(gHaveAsyncRes)
1.751 + {
1.752 + resourceId = gLongLatencyResource;
1.753 + gTest.Printf(_L("Invoking HelperClientsUsinResource for Async resource ID %d\n"),resourceId);
1.754 + }
1.755 + else
1.756 + {
1.757 + gTest.Printf(_L("Invoking HelperClientsUsinResource for default resource ID %d (Async resource not yet accessed)\n"),resourceId);
1.758 + }
1.759 + if((r=HelperClientsUsingResource(resourceId))!=KErrNone)
1.760 + return r;
1.761 + //
1.762 + // Second invoke on the Shared resource - skip if not available
1.763 + if(gHaveSharedRes)
1.764 + {
1.765 + resourceId = gSharedResource;
1.766 + gTest.Printf(_L("Invoking HelperClientsUsinResource for Shared resource ID %d\n"),resourceId);
1.767 + if((r=HelperClientsUsingResource(resourceId))!=KErrNone)
1.768 + return r;
1.769 + }
1.770 +
1.771 + // Invokes GetNumResourcesInUseByClient and GetInfoOnResourcesInUseByClient
1.772 + if((r=HelperResourcesInUseByClient())!=KErrNone)
1.773 + return r;
1.774 +
1.775 + __KHEAP_MARKEND;
1.776 +
1.777 + return r;
1.778 + }
1.779 +
1.780 +#ifdef _DEBUG
1.781 +LOCAL_C TInt SetAsyncResource()
1.782 +//
1.783 +// Support function for tests of asynchronous API methods
1.784 +//
1.785 + {
1.786 + if(!gHaveAsyncRes)
1.787 + {
1.788 + gTest.Printf(_L("SetAsyncResource, Find Async resource to use\n"));
1.789 + TRequestStatus status;
1.790 + TBool cached = gUseCached;
1.791 + TInt readValue = 0;
1.792 + TInt levelOwnerId = 0;
1.793 + TUint numPotentialResources;
1.794 + TUint index=0;
1.795 + TInt r=gChannel.GetNumCandidateAsyncResources(numPotentialResources);
1.796 + if(r!=KErrNone)
1.797 + {
1.798 + gTest.Printf(_L("SetAsyncResource, GetNumCandidateAsyncResources returned %d\n"),r);
1.799 + return r;
1.800 + }
1.801 + gTest.Printf(_L("SetAsyncResource, GetNumCandidateAsyncResources found %d resources\n"),numPotentialResources);
1.802 + while((numPotentialResources>0) && !gHaveAsyncRes)
1.803 + {
1.804 + TUint tryResourceId=0;
1.805 + r=gChannel.GetCandidateAsyncResourceId(index,tryResourceId);
1.806 + if(r!=KErrNone)
1.807 + {
1.808 + gTest.Printf(_L("SetAsyncResource, GetCandidateAsyncResourceId returned %d\n"),r);
1.809 + break;
1.810 + }
1.811 + gTest.Printf(_L("SetAsyncResource, GetNumCandidateAsyncResources index %d, resource ID %d\n"),index,tryResourceId);
1.812 + // For the candidate resource to be usable, we need its current state
1.813 + // to be sufficiently less the maximum for positive sense (or sufficiently
1.814 + // more than the greater than the minimum for negative sense - but the current
1.815 + // version of the code only considers positive sense).
1.816 + gChannel.GetResourceState(status,tryResourceId,cached,&readValue,&levelOwnerId);
1.817 + User::WaitForRequest(status);
1.818 + if(status.Int() != KErrNone)
1.819 + {
1.820 + gTest.Printf(_L("SetAsyncResource, candidate get state returned %d\n"),r);
1.821 + return r;
1.822 + }
1.823 + gTest.Printf(_L("SetAsyncResource, candidate get state gave %d, levelOwnerId = %d\n"),readValue,levelOwnerId);
1.824 + TResourceInfoBuf buffer;
1.825 + if((r=gChannel.GetResourceInfo(tryResourceId, &buffer))!=KErrNone)
1.826 + {
1.827 + gTest.Printf(_L("SetAsyncResource, candidate get resource info returned %d\n"),r);
1.828 + return r;
1.829 + }
1.830 + // Print resource info
1.831 + TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name;
1.832 + TResourceInfo* infoPtr = &(buffer());
1.833 + name.Copy(infoPtr->iName);
1.834 + gTest.Printf(_L("SetAsyncResource: Resource name = %S \n"),&name);
1.835 + gTest.Printf(_L("SetAsyncResource: Resource Class =%d\n"),infoPtr->iClass);
1.836 + gTest.Printf(_L("SetAsyncResource: Resource Type =%d\n"), infoPtr->iType);
1.837 + gTest.Printf(_L("SetAsyncResource: Resource Usage =%d\n"), infoPtr->iUsage);
1.838 + gTest.Printf(_L("SetAsyncResource: Resource Sense =%d\n"), infoPtr->iSense);
1.839 + gTest.Printf(_L("SetAsyncResource: Resource MinLevel =%d\n"),infoPtr->iMinLevel);
1.840 + gTest.Printf(_L("SetAsyncResource: Resource MaxLevel =%d\n"),infoPtr->iMaxLevel);
1.841 +
1.842 + if((infoPtr->iMaxLevel - readValue) > LEVEL_GAP_REQUIRED_FOR_ASYNC_TESTING)
1.843 + {
1.844 + gLongLatencyResource = tryResourceId;
1.845 + gAsyncResStateDelta = 1; // Will change resource level in positive direction
1.846 + gHaveAsyncRes = ETrue;
1.847 + }
1.848 + else if((readValue - infoPtr->iMinLevel) > LEVEL_GAP_REQUIRED_FOR_ASYNC_TESTING)
1.849 + {
1.850 + gLongLatencyResource = tryResourceId;
1.851 + gAsyncResStateDelta = -1; // Will change resource level in negative direction
1.852 + gHaveAsyncRes = ETrue;
1.853 + }
1.854 + else
1.855 + {
1.856 + ++index;
1.857 + --numPotentialResources;
1.858 + }
1.859 + };
1.860 + }
1.861 + if(!gHaveAsyncRes)
1.862 + {
1.863 + gTest.Printf(_L("**Test SetAsyncResource - don't have suitable resource ... exiting\n"));
1.864 + return KErrNotReady;
1.865 + }
1.866 +
1.867 + return KErrNone;
1.868 + }
1.869 +
1.870 +LOCAL_C TInt SetSharedResource()
1.871 +//
1.872 +// Support function for tests of shareable resources
1.873 +//
1.874 + {
1.875 + __KHEAP_MARK;
1.876 +
1.877 + if(!gHaveSharedRes)
1.878 + {
1.879 + TRequestStatus status;
1.880 + TBool cached = gUseCached;
1.881 + TInt readValue = 0;
1.882 + TUint numPotentialResources;
1.883 + TUint index=0;
1.884 + TInt r=gChannel.GetNumCandidateSharedResources(numPotentialResources);
1.885 + if(r!=KErrNone)
1.886 + {
1.887 + gTest.Printf(_L("SetSharedResource, GetNumCandidateSharedResources returned %d\n"),r);
1.888 + return r;
1.889 + }
1.890 + gTest.Printf(_L("SetSharedResource, GetNumCandidateSharedResources found %d resources\n"),numPotentialResources);
1.891 + while((numPotentialResources>0) && !gHaveSharedRes)
1.892 + {
1.893 + TUint tryResourceId=0;
1.894 + r=gChannel.GetCandidateSharedResourceId(index,tryResourceId);
1.895 + if(r!=KErrNone)
1.896 + {
1.897 + gTest.Printf(_L("SetSharedResource, GetCandidateSharedResourceId returned %d\n"),r);
1.898 + break;
1.899 + }
1.900 + gTest.Printf(_L("SetSharedResource, GetNumCandidateSharedResources index %d, resource ID %d\n"),index,tryResourceId);
1.901 + // To support the tests, the selected shareable resource must not be the same
1.902 + // resource as that selected for asynchronous testing
1.903 + if(gHaveAsyncRes)
1.904 + if(tryResourceId==gLongLatencyResource)
1.905 + {
1.906 + gTest.Printf(_L("SetSharedResource - skipping candidate resource %d - already used for async testing\n"),tryResourceId);
1.907 + continue;
1.908 + }
1.909 + // For the candidate resource to be usable, we need its current state
1.910 + // to be sufficiently less the maximum for positive sense (or sufficiently
1.911 + // more than the greater than the minimum for negative sense - but the current
1.912 + // version of the code only considers positive sense).
1.913 + TInt levelOwnerId = 0;
1.914 + gChannel.GetResourceState(status,tryResourceId,cached,&readValue,&levelOwnerId);
1.915 + User::WaitForRequest(status);
1.916 + if(status.Int() != KErrNone)
1.917 + {
1.918 + gTest.Printf(_L("SetSharedResource, candidate get state returned %d\n"),r);
1.919 + return r;
1.920 + }
1.921 + gTest.Printf(_L("SetSharedResource, candidate get state gave %d, levelOwnerId = %d\n"),readValue,levelOwnerId);
1.922 + TResourceInfoBuf buffer;
1.923 + if((r=gChannel.GetResourceInfo(tryResourceId, &buffer))!=KErrNone)
1.924 + {
1.925 + gTest.Printf(_L("SetSharedResource, candidate get resource info returned %d\n"),r);
1.926 + return r;
1.927 + }
1.928 + // Print resource info
1.929 + TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name;
1.930 + TResourceInfo* infoPtr = &buffer();
1.931 + name.Copy(infoPtr->iName);
1.932 + gTest.Printf(_L("SetSharedResource: Resource name = %S \n"),&name);
1.933 + gTest.Printf(_L("SetSharedResource: Resource Class =%d\n"),infoPtr->iClass);
1.934 + gTest.Printf(_L("SetSharedResource: Resource Type =%d\n"), infoPtr->iType);
1.935 + gTest.Printf(_L("SetSharedResource: Resource Usage =%d\n"), infoPtr->iUsage);
1.936 + gTest.Printf(_L("SetSharedResource: Resource Sense =%d\n"), infoPtr->iSense);
1.937 + gTest.Printf(_L("SetSharedResource: Resource MinLevel =%d\n"),infoPtr->iMinLevel);
1.938 + gTest.Printf(_L("SetSharedResource: Resource MaxLevel =%d\n"),infoPtr->iMaxLevel);
1.939 +
1.940 + if((infoPtr->iMaxLevel - readValue) > LEVEL_GAP_REQUIRED_FOR_ASYNC_TESTING)
1.941 + {
1.942 + gSharedResource = tryResourceId;
1.943 + gSharedResStateDelta = 1; // Will change resource level in positive direction
1.944 + gHaveSharedRes = ETrue;
1.945 + }
1.946 + else if((readValue - infoPtr->iMinLevel) > LEVEL_GAP_REQUIRED_FOR_ASYNC_TESTING)
1.947 + {
1.948 + gSharedResource = tryResourceId;
1.949 + gSharedResStateDelta = -1; // Will change resource level in negative direction
1.950 + gHaveSharedRes = ETrue;
1.951 + }
1.952 + else
1.953 + {
1.954 + ++index;
1.955 + --numPotentialResources;
1.956 + }
1.957 + };
1.958 + }
1.959 + if(!gHaveSharedRes)
1.960 + {
1.961 + gTest.Printf(_L("**Test SetSharedResource - don't have suitable resource ... exiting\n"));
1.962 + return KErrNotReady;
1.963 + }
1.964 +
1.965 + __KHEAP_MARKEND;
1.966 + return KErrNone;
1.967 + }
1.968 +
1.969 +#endif
1.970 +
1.971 +
1.972 +//----------------------------------------------------------------------------------------------
1.973 +//! @SYMTestCaseID KBASE-T_RESMANUS-0609
1.974 +//! @SYMTestType UT
1.975 +//! @SYMPREQ PREQ1398
1.976 +//! @SYMTestCaseDesc This test case tests APIs for retrieving information about
1.977 +//! (1) clients of the channel and
1.978 +//! (2) power resources.
1.979 +//! Since the client lacks the ReadDeviceData PlatSec capability it will not
1.980 +//! be permitted to access information about kernel-side clients
1.981 +//!
1.982 +//! The tests are invoked a number of times:
1.983 +//! - first, to examine the starting state
1.984 +//! - then, to examine the effect of adding a new client (channel)
1.985 +//! - then, the examine the effect of adding a new client that requests a
1.986 +//| level on a resource
1.987 +//! - then, to test the effect of the original client requesting a level
1.988 +//! on a resource
1.989 +//!
1.990 +//! @SYMTestActions 0) Call GetNoOfClients API with default aIncludeKern=EFalse.
1.991 +//!
1.992 +//! 1) Call GetNoOfClients API with aIncludeKern=ETrue.
1.993 +//!
1.994 +//! 2) Call GetNamesAllClients API with default aIncludeKern=EFalse.
1.995 +//!
1.996 +//! 3) Call GetNamesAllClients API with aIncludeKern=ETrue.
1.997 +//!
1.998 +//! 4) Call GetNumClientsUsingResource API with aIncludeKern=ETrue.
1.999 +//!
1.1000 +//! 5) Call GetNumClientsUsingResource API with default aIncludeKern=EFalse.
1.1001 +//!
1.1002 +//! 6) Call GetInfoOnClientsUsingResource API with default aIncludeKern=EFalse.
1.1003 +//!
1.1004 +//! 7) Call GetInfoOnClientsUsingResource API with aIncludeKern=ETrue.
1.1005 +//!
1.1006 +//! 8) GetNumResourcesInUseByClient for the original client
1.1007 +//!
1.1008 +//! 9) GetNumResourcesInUseByClient for a non-existent client
1.1009 +//!
1.1010 +//! 10) GetInfoOnResourcesInUseByClient for the original client
1.1011 +//!
1.1012 +//! 11) GetInfoOnResourcesInUseByClient for a non-existent client
1.1013 +//!
1.1014 +//! @SYMTestExpectedResults 0) API should return with KErrNone, exits otherwise.
1.1015 +//!
1.1016 +//! 1) If client exhibits PlatSec capability ReadDeviceData, API should return with KErrNone, exits otherwise.
1.1017 +//! If client lacks PlatSec capability ReadDeviceData, API should return with KErrPermissionDenied, exits otherwise.
1.1018 +//!
1.1019 +//! 2) API should return with KErrNone, exits otherwise.
1.1020 +//!
1.1021 +//! 3) If client exhibits PlatSec capability ReadDeviceData, API should return with KErrNone, exits otherwise
1.1022 +//! If client lacks PlatSec capability ReadDeviceData, API should return with KErrPermissionDenied, exits otherwise
1.1023 +//!
1.1024 +//! 4) If client exhibits PlatSec capability ReadDeviceData, API should return with KErrNone, exits otherwise.
1.1025 +//! If client lacks PlatSec capability ReadDeviceData, API should return with KErrPermissionDenied, exits otherwise.
1.1026 +//!
1.1027 +//! 5) API should return with KErrNone, exits otherwise
1.1028 +//!
1.1029 +//! 6) API should return with KErrNone, exits otherwise.
1.1030 +//!
1.1031 +//! 7) If client exhibits PlatSec capability ReadDeviceData, API should return with KErrNone, exits otherwise
1.1032 +//! If client lacks PlatSec capability ReadDeviceData, API should return with KErrPermissionDenied, exits otherwise
1.1033 +//!
1.1034 +//! 8) API should return with KErrNone, exits otherwise.
1.1035 +//!
1.1036 +//! 9) API should return with KErrNotFound, exits otherwise.
1.1037 +//!
1.1038 +//! 10) API should return with KErrNone, exits otherwise.
1.1039 +//!
1.1040 +//! 11) API should return with KErrNotFound, exits otherwise.
1.1041 +//!
1.1042 +//! @SYMTestPriority High
1.1043 +//! @SYMTestStatus Implemented
1.1044 +//----------------------------------------------------------------------------------------------
1.1045 +LOCAL_C TInt TestGetClientGetResourceInfo()
1.1046 +//
1.1047 +// Test methods to access information about clients and resources
1.1048 +//
1.1049 + {
1.1050 + TInt r = KErrNone;
1.1051 +
1.1052 + // Open a couple of additional channels
1.1053 + _LIT(tempStr1,"ExtraChan1");
1.1054 + TBufC<16> tempName1(tempStr1);
1.1055 + _LIT(tempStr2,"ExtraChan2");
1.1056 + TBufC<16> tempName2(tempStr2);
1.1057 +
1.1058 + RBusDevResManUs channelTwo;
1.1059 + RBusDevResManUs channelThree;
1.1060 +
1.1061 + if((r=OpenChannel(tempName1, channelTwo))!=KErrNone)
1.1062 + return r;
1.1063 + if((r=OpenChannel(tempName2, channelThree))!=KErrNone)
1.1064 + return r;
1.1065 +
1.1066 + // Test the tracking of the client and resource info
1.1067 + //
1.1068 +
1.1069 + // First invocation to establish starting state
1.1070 +#ifdef _DEBUG
1.1071 + gTest.Printf(_L("TestGetClientGetResourceInfo: First HelperGetClientResourceInfo call (starting state):\n"));
1.1072 +#endif
1.1073 + if((r=HelperGetClientResourceInfo())!=KErrNone)
1.1074 + return r;
1.1075 +
1.1076 + // Second invocation - examine effect of adding a client
1.1077 + _LIT(tempStr3,"ExtraChan3");
1.1078 + TBufC<16> tempName3(tempStr3);
1.1079 + RBusDevResManUs channelFour;
1.1080 + if((r=OpenChannel(tempName3, channelFour))!=KErrNone)
1.1081 + return r;
1.1082 +#ifdef _DEBUG
1.1083 + gTest.Printf(_L("TestGetClientGetResourceInfo: Second HelperGetClientResourceInfo call (added client ExtraChan3):\n"));
1.1084 +#endif
1.1085 +
1.1086 + if((r=HelperGetClientResourceInfo())!=KErrNone)
1.1087 + return r;
1.1088 +
1.1089 + // Third invocation - examine effect of new client requesting a level for a resource
1.1090 + // (This relies on getting and setting the state of gSharedResource - so skip the
1.1091 + // test if this has not yet been identified
1.1092 + //
1.1093 + TUint startingLevel = 0;
1.1094 +#ifdef _DEBUG
1.1095 + if((r=SetSharedResource())!=KErrNone)
1.1096 + return r;
1.1097 +#endif
1.1098 + if(!gHaveSharedRes)
1.1099 + {
1.1100 + gTest.Printf(_L("TestGetClientGetResourceInfo: no suitable shareable resource, so skipping third call:\n"));
1.1101 + }
1.1102 + else
1.1103 + {
1.1104 + // Channel registration
1.1105 + gTest.Printf(_L("Initialise for temporary channel with arguments 1,1,0\n"));
1.1106 + if ((r=channelFour.Initialise(1,1,0))!=KErrNone) // Just need 1 get and 1 set state
1.1107 + {
1.1108 + gTest.Printf(_L("Initialise for channel returned %d\n"),r);
1.1109 + return r;
1.1110 + }
1.1111 + // Get initial state
1.1112 + TRequestStatus status;
1.1113 + TBool cached = gUseCached;
1.1114 + TInt readValue;
1.1115 + TInt levelOwnerId = 0;
1.1116 + channelFour.GetResourceState(status,gSharedResource,cached,&readValue,&levelOwnerId);
1.1117 + User::WaitForRequest(status);
1.1118 + r=status.Int();
1.1119 + if(r != KErrNone)
1.1120 + {
1.1121 + gTest.Printf(_L("TestGetClientGetResourceInfo, first get state for shareable returned %d\n"),r);
1.1122 + return r;
1.1123 + }
1.1124 + startingLevel = (TUint)readValue;
1.1125 + // Write updated state
1.1126 + TUint newLevel = (TUint)(readValue + gSharedResStateDelta);
1.1127 + gTest.Printf(_L("TestGetClientGetResourceInfo: levelOwnerId = %d\n"), levelOwnerId);
1.1128 + gTest.Printf(_L("TestGetClientGetResourceInfo: shareable resource startingLevel=0x%x, writing 0x%x\n"), startingLevel, newLevel);
1.1129 + channelFour.ChangeResourceState(status,gSharedResource,newLevel);
1.1130 + User::WaitForRequest(status);
1.1131 + r=status.Int();
1.1132 + if(r != KErrNone)
1.1133 + {
1.1134 + gTest.Printf(_L("TestGetClientGetResourceInfo, first change state for shareable resource returned %d\n"),r);
1.1135 + return r;
1.1136 + }
1.1137 +#ifdef _DEBUG
1.1138 + gTest.Printf(_L("TestGetClientGetResourceInfo: third HelperGetClientResourceInfo call (new client set level on shared resource):\n"));
1.1139 +#endif
1.1140 + if((r=HelperGetClientResourceInfo())!=KErrNone)
1.1141 + return r;
1.1142 + }
1.1143 +
1.1144 +
1.1145 + // Fourth invocation - examine effect of orignal client requesting a level for
1.1146 + // the Shared resource
1.1147 + if(gHaveSharedRes)
1.1148 + {
1.1149 + TRequestStatus status;
1.1150 + TBool cached = gUseCached;
1.1151 + TInt readValue;
1.1152 + TInt levelOwnerId;
1.1153 + gChannel.GetResourceState(status,gSharedResource,cached,&readValue,&levelOwnerId);
1.1154 + User::WaitForRequest(status);
1.1155 + r=status.Int();
1.1156 + if(r != KErrNone)
1.1157 + {
1.1158 + gTest.Printf(_L("TestGetClientGetResourceInfo, gChannel get state on Shareable resource returned %d\n"),r);
1.1159 + return r;
1.1160 + }
1.1161 + gTest.Printf(_L("TestGetClientGetResourceInfo, GetResourceState levelOwnerId = %d\n"),levelOwnerId); // Request a level on the resource
1.1162 + gChannel.ChangeResourceState(status,gSharedResource,(readValue+gSharedResStateDelta));
1.1163 + User::WaitForRequest(status);
1.1164 + if(status.Int() != KErrNone)
1.1165 + {
1.1166 + gTest.Printf(_L("TestGetClientGetResourceInfo, gChannel change state on Shareable returned %d\n"),r);
1.1167 + return r;
1.1168 + }
1.1169 +#ifdef _DEBUG
1.1170 + gTest.Printf(_L("TestGetClientGetResourceInfo: fourth HelperGetClientResourceInfo call (gChannel set level on Shareable resource):\n"));
1.1171 +#endif
1.1172 + if((r=HelperGetClientResourceInfo())!=KErrNone)
1.1173 + return r;
1.1174 + }
1.1175 +
1.1176 + // Return the resource to the state it was on function entry
1.1177 + if(gHaveSharedRes)
1.1178 + {
1.1179 + TRequestStatus status;
1.1180 + gTest.Printf(_L("TestGetClientGetResourceInfo: returning sharable resource to startingLevel=0x%x\n"), startingLevel);
1.1181 + gChannel.ChangeResourceState(status,gSharedResource,startingLevel);
1.1182 + User::WaitForRequest(status);
1.1183 + r=status.Int();
1.1184 + if(r != KErrNone)
1.1185 + {
1.1186 + gTest.Printf(_L("TestGetClientGetResourceInfo, attempt to reset shareable resource state returned %d\n"),r);
1.1187 + return r;
1.1188 + }
1.1189 + }
1.1190 +
1.1191 +
1.1192 + // Close the temporary channels
1.1193 + channelTwo.Close();
1.1194 + channelThree.Close();
1.1195 + channelFour.Close();
1.1196 +
1.1197 + return r;
1.1198 + }
1.1199 +
1.1200 +
1.1201 +
1.1202 +//----------------------------------------------------------------------------------------------
1.1203 +//! @SYMTestCaseID KBASE-T_RESMANUS-0610
1.1204 +//! @SYMTestType UT
1.1205 +//! @SYMPREQ PREQ1398
1.1206 +//! @SYMTestCaseDesc This test case tests APIs for getting and setting the state of resources;
1.1207 +//! it also tests APIs to cancel such requests.
1.1208 +//!
1.1209 +//! @SYMTestActions 0) Call API to get the initial state of a selected resource.
1.1210 +//!
1.1211 +//! 1) Call API to modify the state of the resource.
1.1212 +//!
1.1213 +//! 2) Call API to get the new state of the resource and check it exhibits
1.1214 +//! the expected value.
1.1215 +//!
1.1216 +//! 3) Call API to return the resource state to its original value.
1.1217 +//!
1.1218 +//! 4) Call API to get the state of a long latency resource then call API
1.1219 +//! with operation-type qualifier cancel the request.
1.1220 +//!
1.1221 +//! 5) Call API to modify the state of the long latency resource then call API
1.1222 +//! with operation-type qualifier to cancel the request.
1.1223 +//!
1.1224 +//! 6) Call API to get the state of a long latency resource and wait for it
1.1225 +//! to complete. Then call API with operation-type qualifier to cancel the request.
1.1226 +//!
1.1227 +//! 7) Call API to modify the state of the long latency resource and wait for
1.1228 +//! it to complete. Then call API with operation-type qualifier to cancel the request.
1.1229 +//!
1.1230 +//! 8) Call API to get the state of a long latency resource then call API
1.1231 +//! without operation-type qualifier to cancel the request.
1.1232 +//!
1.1233 +//! 9) Call API to modify the state of the long latency resource then call API
1.1234 +//! without operation-type qualifier to cancel the request.
1.1235 +//!
1.1236 +//! 10) Call API to get the state of a long latency resource and wait for it
1.1237 +//! to complete. Then call API without operation-type qualifier to cancel the request.
1.1238 +//!
1.1239 +//! 11) Call API to modify the state of the long latency resource and wait for
1.1240 +//! it to complete. Then call API without operation-type qualifier to cancel the request.
1.1241 +//!
1.1242 +//! 12) Call API to get the state of a long latency resource 'n' times. Then call API with
1.1243 +//! resource qualifier to cancel the requests.
1.1244 +//!
1.1245 +//! 13) Call API to modify the state of a long latency resource 'm' times. Then call API with
1.1246 +//! resource qualifier to cancel the requests.
1.1247 +//!
1.1248 +//! 14) Call API to get the state of a long latency resource 'n' times and wait for them to complete.
1.1249 +//! Then call API with resource qualifier to cancel the requests.
1.1250 +//!
1.1251 +//! 15) Call API to modify the state of a long latency resource 'm' times and wait for them to complete.
1.1252 +//! Then call API with resource qualifier to cancel the requests.
1.1253 +//!
1.1254 +//! 16) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
1.1255 +//! a long latency resource 'm' times. Call the API to cancel the get operations with resource qualifier.
1.1256 +//! Wait for the operations to complete. Check the state of the associated TRequestStatus objects.
1.1257 +//!
1.1258 +//! 17) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
1.1259 +//! a long latency resource 'm' times. Call the API to cancel the modify operations with resource qualifier.
1.1260 +//! Wait for the get operations to complete. Check the state of the associated TRequestStatus objects.
1.1261 +//!
1.1262 +//! 18) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
1.1263 +//! a long latency resource 'm' times. Wait for the get operations to complete. Call the API to cancel the get
1.1264 +//! operations with resource qualifier. Check the state of the associated TRequestStatus objects.
1.1265 +//!
1.1266 +//! 19) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
1.1267 +//! a long latency resource 'm' times. Wait for the modify operations to complete. Call the API to cancel the modify
1.1268 +//! operations with resource qualifier. Check the state of the associated TRequestStatus objects.
1.1269 +//!
1.1270 +//! 20) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
1.1271 +//! a long latency resource 'm' times.
1.1272 +//! Then call API with operation-type qualifier to cancel the even-numbered get request(s).
1.1273 +//! Then call API without operation-type qualifier to cancel the even-numbered modify request(s).
1.1274 +//! Check the state of the associated TRequestStatus objects.
1.1275 +//!
1.1276 +//! @SYMTestExpectedResults 0) The associated TRequestStatus object should indicate KErrNone, exits otherwise.
1.1277 +//!
1.1278 +//! 1) The associated TRequestStatus object should indicate KErrNone, exits otherwise.
1.1279 +//!
1.1280 +//! 2) The associated TRequestStatus object should indicate KErrNone, exits otherwise.
1.1281 +//! Exit if the value read back is not as expected.
1.1282 +//!
1.1283 +//! 3) The associated TRequestStatus object should indicate KErrNone, exits otherwise.
1.1284 +//!
1.1285 +//! 4) The associated TRequestStatus object should indicate KErrCancel if the cancel
1.1286 +//! request was accepted, exits otherwise.
1.1287 +//! The associated TRequestStatus object should indicate KErrNone if the cancel request
1.1288 +//! was not accepted, exits otherwise.
1.1289 +//!
1.1290 +//! 5) The associated TRequestStatus object should indicate KErrCancel if the cancel
1.1291 +//! request was accepted, exits otherwise.
1.1292 +//! The associated TRequestStatus object should indicate KErrNone if the cancel request
1.1293 +//! was not accepted, exits otherwise.
1.1294 +//!
1.1295 +//! 6) The TRequestStatus object associated with the get operation should indicate
1.1296 +//! KErrNone - exits otherwise. The TRequestStatus object associated with the cancel
1.1297 +//! operation should indicate KErrNone - exits otherwise.
1.1298 +//!
1.1299 +//! 7) The TRequestStatus object associated with the get operation should indicate
1.1300 +//! KErrNone - exits otherwise. The TRequestStatus object associated with the cancel
1.1301 +//! operation should indicate KErrNone - exits otherwise.
1.1302 +//!
1.1303 +//! 8) The associated TRequestStatus object should indicate KErrCancel, exits otherwise.
1.1304 +//!
1.1305 +//! 9) The associated TRequestStatus object should indicate KErrCancel, exits otherwise.
1.1306 +//!
1.1307 +//! 10) The TRequestStatus object associated with the get operation should indicate
1.1308 +//! KErrNone - exits otherwise. The TRequestStatus object associated with the cancel
1.1309 +//! operation should indicate KErrNone - exits otherwise.
1.1310 +//!
1.1311 +//! 11) The TRequestStatus object associated with the get operation should indicate
1.1312 +//! KErrNone - exits otherwise. The TRequestStatus object associated with the cancel
1.1313 +//! operation should indicate KErrNone - exits otherwise.
1.1314 +//!
1.1315 +//! 12) The TRequestStatus objects should all exibit KErrCancel - exits otherwise.
1.1316 +//!
1.1317 +//! 13) The TRequestStatus objects should all exibit KErrCancel - exits otherwise.
1.1318 +//!
1.1319 +//! 14) The TRequestStatus objects associated with the get operations should all exibit KErrNone - exits otherwise.
1.1320 +//! The TRequestStatus objects associated with the cancel operations should all exibit KErrNone - exits otherwise
1.1321 +//!
1.1322 +//! 15) The TRequestStatus objects associated with the modify operations should all exibit KErrNone - exits otherwise.
1.1323 +//! The TRequestStatus objects associated with the cancel operations should all exibit KErrNone - exits otherwise
1.1324 +//!
1.1325 +//! 16) The TRequestStatus objects associated with the get operations should all exibit KErrCancel - exits otherwise.
1.1326 +//! The TRequestStatus objects associated with the modify operations should all exibit KErrNone - exits otherwise
1.1327 +//!
1.1328 +//! 17) The TRequestStatus objects associated with the get operations should all exibit KErrNone - exits otherwise.
1.1329 +//! The TRequestStatus objects associated with the modify operations should all exibit KErrCancel - exits otherwise
1.1330 +//!
1.1331 +//! 18) The TRequestStatus objects associated with the get and modify operations should all exibit KErrNone - exits otherwise.
1.1332 +//!
1.1333 +//! 19) The TRequestStatus objects associated with the get and modify operations should all exibit KErrNone - exits otherwise.
1.1334 +//!
1.1335 +//! 20) The TRequestStatus objects associated with the even-numbered request should exhibit KErrCancel.
1.1336 +//! The TRequestStatus objects associated with the odd-numbered request should exhibit KErrNone.
1.1337 +//!
1.1338 +//! @SYMTestPriority High
1.1339 +//! @SYMTestStatus Implemented
1.1340 +//----------------------------------------------------------------------------------------------
1.1341 +LOCAL_C TInt TestGetSetResourceStateOps()
1.1342 +//
1.1343 +// Test resource state access methods
1.1344 +//
1.1345 + {
1.1346 + TInt r = KErrNone;
1.1347 +
1.1348 + TRequestStatus status;
1.1349 + TBool cached = gUseCached;
1.1350 + TInt readValue = 0;
1.1351 + TInt levelOwnerId = 0;
1.1352 + TInt testNo = 0;
1.1353 +
1.1354 +#ifdef _DEBUG
1.1355 + // Ensure we have a resource we can use
1.1356 + if((r=SetAsyncResource())!=KErrNone)
1.1357 + return r;
1.1358 +#endif
1.1359 +
1.1360 + // 0) Call API to get the initial state of a selected resource.
1.1361 + gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1.1362 + gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
1.1363 + User::WaitForRequest(status);
1.1364 + if(status.Int() != KErrNone)
1.1365 + {
1.1366 + gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r);
1.1367 + return r;
1.1368 + }
1.1369 + TUint startingLevel = (TUint)readValue;
1.1370 + gTest.Printf(_L("TestGetSetResourceStateOps: initial level read =0x%x, levelOwnerId = %d\n"),readValue,levelOwnerId);
1.1371 +
1.1372 + // 1) Call API to modify the state of the resource.
1.1373 + gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1.1374 + TUint newLevel = (TUint)(readValue + gAsyncResStateDelta);
1.1375 + gTest.Printf(_L("TestGetSetResourceStateOps: writing 0x%x\n"), newLevel);
1.1376 + gChannel.ChangeResourceState(status,gLongLatencyResource,newLevel);
1.1377 + User::WaitForRequest(status);
1.1378 + if(status.Int() != KErrNone)
1.1379 + {
1.1380 + gTest.Printf(_L("TestGetSetResourceStateOps, first change state returned %d\n"),r);
1.1381 + return r;
1.1382 + }
1.1383 +
1.1384 + // 2) Call API to get the new state of the resource and check it exhibits the expected value.
1.1385 + gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1.1386 + gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
1.1387 + User::WaitForRequest(status);
1.1388 + if(status.Int() != KErrNone)
1.1389 + {
1.1390 + gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r);
1.1391 + return r;
1.1392 + }
1.1393 + gTest.Printf(_L("TestGetSetResourceStateOps: level read back =0x%x, levelOwnerId=%d\n"),readValue,levelOwnerId);
1.1394 + gTest(newLevel==(TUint)readValue);
1.1395 +
1.1396 + // 3) Call API to return the resource state to its original value.
1.1397 + gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1.1398 + gTest.Printf(_L("TestGetSetResourceStateOps: write original level 0x%x\n"), startingLevel);
1.1399 + gChannel.ChangeResourceState(status,gLongLatencyResource,startingLevel);
1.1400 + User::WaitForRequest(status);
1.1401 + if(status.Int() != KErrNone)
1.1402 + {
1.1403 + gTest.Printf(_L("TestGetSetResourceStateOps, change state status = %d\n"),r);
1.1404 + return r;
1.1405 + }
1.1406 + gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
1.1407 + User::WaitForRequest(status);
1.1408 + if(status.Int() != KErrNone)
1.1409 + {
1.1410 + gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r);
1.1411 + return r;
1.1412 + }
1.1413 + gTest.Printf(_L("TestGetSetResourceStateOps: check original level read back =0x%x, levelOwnerId=%d\n"),readValue,levelOwnerId);
1.1414 +
1.1415 + // 4) Call API to get the state of a long latency resource then call API with operation-type qualifier cancel the request.
1.1416 + gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1.1417 + gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
1.1418 + r=gChannel.CancelGetResourceState(status);
1.1419 + if(r!=KErrInUse)
1.1420 + {
1.1421 + gTest.Printf(_L("TestGetSetResourceStateOps, CancelGetResourceState returned %d\n"),r);
1.1422 + }
1.1423 + if(r!=KErrCompletion) // If request had not completed before cancellation request
1.1424 + {
1.1425 + User::WaitForRequest(status);
1.1426 + if(r==KErrNone) // Cancel expected to proceed as requested
1.1427 + {
1.1428 + if(status.Int() != KErrCancel)
1.1429 + {
1.1430 + gTest.Printf(_L("TestGetSetResourceStateOps, expected KErrCancel but cancelled get state status = %d\n"),r);
1.1431 + return r;
1.1432 + }
1.1433 + }
1.1434 + else if(r==KErrInUse) // Cancel failed since request was being processed - so expect successful completion
1.1435 + {
1.1436 + if(status.Int() != KErrNone)
1.1437 + {
1.1438 + gTest.Printf(_L("TestGetSetResourceStateOps, expected KErrNone but cancelled get state status = %d\n"),r);
1.1439 + return r;
1.1440 + }
1.1441 + }
1.1442 + else if(status.Int() != KErrCancel) // Just report the error code and return
1.1443 + {
1.1444 + gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status = %d\n"),r);
1.1445 + return r;
1.1446 + }
1.1447 +
1.1448 + }
1.1449 +
1.1450 + // 5) Call API to modify the state of the long latency resource then call API with operation-type qualifier to cancel the request.
1.1451 + gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1.1452 + newLevel = (TUint)(readValue + gAsyncResStateDelta);
1.1453 + gChannel.ChangeResourceState(status,gLongLatencyResource,newLevel);
1.1454 + r=gChannel.CancelChangeResourceState(status);
1.1455 + if(r!=KErrInUse)
1.1456 + {
1.1457 + gTest.Printf(_L("TestGetSetResourceStateOps, CancelChangeResourceState returned %d\n"),r);
1.1458 + }
1.1459 + if(r!=KErrCompletion) // If request had not completed before cancellation request
1.1460 + {
1.1461 + User::WaitForRequest(status);
1.1462 + if(r==KErrNone) // Cancel expected to proceed as requested
1.1463 + {
1.1464 + if(status.Int() != KErrCancel)
1.1465 + {
1.1466 + gTest.Printf(_L("TestGetSetResourceStateOps, expected KErrCancel but cancelled get state status = %d\n"),r);
1.1467 + return r;
1.1468 + }
1.1469 + }
1.1470 + else if(r==KErrInUse) // Cancel failed since request was being processed - so expect successful completion
1.1471 + {
1.1472 + if(status.Int() != KErrNone)
1.1473 + {
1.1474 + gTest.Printf(_L("TestGetSetResourceStateOps, expected KErrNone but cancelled get state status = %d\n"),r);
1.1475 + return r;
1.1476 + }
1.1477 + }
1.1478 + else if(status.Int() != KErrCancel) // Just report the error code and return
1.1479 + {
1.1480 + gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status = %d\n"),r);
1.1481 + return r;
1.1482 + }
1.1483 + }
1.1484 +
1.1485 +
1.1486 + // 6) Call API to get the state of a long latency resource and wait for it to complete.
1.1487 + // Then call API with operation-type qualifier to cancel the request.
1.1488 + gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1.1489 + gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
1.1490 + User::WaitForRequest(status);
1.1491 + if(status.Int() != KErrNone)
1.1492 + {
1.1493 + gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r);
1.1494 + return r;
1.1495 + }
1.1496 + r=gChannel.CancelGetResourceState(status);
1.1497 + if(r!=KErrNone)
1.1498 + {
1.1499 + gTest.Printf(_L("TestGetSetResourceStateOps, CancelGetResourceState returned %d\n"),r);
1.1500 + }
1.1501 + if(status.Int() != KErrNone) // TRequestStatus should be unchanged
1.1502 + {
1.1503 + gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled get state status = %d\n"),r);
1.1504 + return r;
1.1505 + }
1.1506 +
1.1507 + // 7) Call API to modify the state of the long latency resource and wait for it to complete.
1.1508 + // Then call API with operation-type qualifier to cancel the request.
1.1509 + gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1.1510 + gChannel.ChangeResourceState(status,gLongLatencyResource,(readValue + gAsyncResStateDelta));
1.1511 + User::WaitForRequest(status);
1.1512 + if(status.Int() != KErrNone)
1.1513 + {
1.1514 + gTest.Printf(_L("TestGetSetResourceStateOps, change state status = %d\n"),r);
1.1515 + return r;
1.1516 + }
1.1517 + r=gChannel.CancelChangeResourceState(status);
1.1518 + if(r!=KErrNone)
1.1519 + {
1.1520 + gTest.Printf(_L("TestGetSetResourceStateOps, CancelChangeResourceState returned %d\n"),r);
1.1521 + }
1.1522 + if(status.Int() != KErrNone) // TRequestStatus should be unchanged
1.1523 + {
1.1524 + gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled change state status = %d\n"),r);
1.1525 + return r;
1.1526 + }
1.1527 +
1.1528 + // 8) Call API to get the state of a long latency resource then call API without operation-type qualifier to cancel the request.
1.1529 + gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1.1530 + gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
1.1531 + gChannel.CancelAsyncOperation(&status);
1.1532 + User::WaitForRequest(status);
1.1533 + if(status.Int() != KErrCancel)
1.1534 + {
1.1535 + gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status = %d\n"),r);
1.1536 + return r;
1.1537 + }
1.1538 +
1.1539 + // 9) Call API to modify the state of the long latency resource then call API without operation-type qualifier to cancel the request.
1.1540 + gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1.1541 + newLevel = (TUint)(readValue + gAsyncResStateDelta);
1.1542 + gChannel.ChangeResourceState(status,gLongLatencyResource,newLevel);
1.1543 + gChannel.CancelAsyncOperation(&status);
1.1544 + User::WaitForRequest(status);
1.1545 + if(status.Int() != KErrCancel)
1.1546 + {
1.1547 + gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status = %d\n"),r);
1.1548 + return r;
1.1549 + }
1.1550 +
1.1551 + // 10) Call API to get the state of a long latency resource and wait for it to complete.
1.1552 + // Then call API without operation-type qualifier to cancel the request.
1.1553 + gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1.1554 + gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
1.1555 + User::WaitForRequest(status);
1.1556 + if(status.Int() != KErrNone)
1.1557 + {
1.1558 + gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r);
1.1559 + return r;
1.1560 + }
1.1561 + gChannel.CancelAsyncOperation(&status);
1.1562 + if(status.Int() != KErrNone) // TRequestStatus should be unchanged
1.1563 + {
1.1564 + gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled get state status = %d\n"),r);
1.1565 + return r;
1.1566 + }
1.1567 +
1.1568 + // 11) Call API to modify the state of the long latency resource and wait for it to complete.
1.1569 + // Then call API without operation-type qualifier to cancel the request.
1.1570 + gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1.1571 + gChannel.ChangeResourceState(status,gLongLatencyResource,(readValue + gAsyncResStateDelta));
1.1572 + User::WaitForRequest(status);
1.1573 + if(status.Int() != KErrNone)
1.1574 + {
1.1575 + gTest.Printf(_L("TestGetSetResourceStateOps, change state status = %d\n"),r);
1.1576 + return r;
1.1577 + }
1.1578 + gChannel.CancelAsyncOperation(&status);
1.1579 + if(status.Int() != KErrNone) // TRequestStatus should be unchanged
1.1580 + {
1.1581 + gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled change state status = %d\n"),r);
1.1582 + return r;
1.1583 + }
1.1584 +
1.1585 + // 'n' and 'm' values and support for cancellation of multiple requests
1.1586 + const TInt KLoopVarN = 2;
1.1587 + const TInt KLoopVarM = 3;
1.1588 + TRequestStatus getReqStatus[KLoopVarN];
1.1589 + TRequestStatus setReqStatus[KLoopVarM];
1.1590 + TInt i=0;
1.1591 +
1.1592 + // 12) Call API to get the state of a long latency resource 'n' times.
1.1593 + // Then call API with resource qualifier to cancel the requests.
1.1594 + gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1.1595 + for(i=0;i<KLoopVarN;i++)
1.1596 + {
1.1597 + gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId);
1.1598 + }
1.1599 + gChannel.CancelGetResourceStateRequests(gLongLatencyResource);
1.1600 + for(i=0;i<KLoopVarN;i++)
1.1601 + {
1.1602 + User::WaitForRequest(getReqStatus[i]);
1.1603 + if((r=getReqStatus[i].Int()) != KErrCancel)
1.1604 + {
1.1605 + gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status[%d] = %d\n"),i,r);
1.1606 + return r;
1.1607 + }
1.1608 + }
1.1609 +
1.1610 + // 13) Call API to modify the state of a long latency resource 'm' times.
1.1611 + // Then call API with resource qualifier to cancel the requests.
1.1612 + gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1.1613 + for(i=0;i<KLoopVarM;i++)
1.1614 + {
1.1615 + gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta));
1.1616 + }
1.1617 + gChannel.CancelChangeResourceStateRequests(gLongLatencyResource);
1.1618 + for(i=0;i<KLoopVarM;i++)
1.1619 + {
1.1620 + User::WaitForRequest(setReqStatus[i]);
1.1621 + if((r=setReqStatus[i].Int()) != KErrCancel)
1.1622 + {
1.1623 + gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status[%d] = %d\n"),i,r);
1.1624 + return r;
1.1625 + }
1.1626 + }
1.1627 +
1.1628 + // 14) Call API to get the state of a long latency resource 'n' times and wait for them to complete.
1.1629 + // Then call API with resource qualifier to cancel the requests.
1.1630 + gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1.1631 + for(i=0;i<KLoopVarN;i++)
1.1632 + {
1.1633 + gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId);
1.1634 + }
1.1635 + for(i=0;i<KLoopVarN;i++)
1.1636 + {
1.1637 + User::WaitForRequest(getReqStatus[i]);
1.1638 + if((r=getReqStatus[i].Int()) != KErrNone)
1.1639 + {
1.1640 + gTest.Printf(_L("TestGetSetResourceStateOps, before cancel get state status[%d] = %d\n"),i,r);
1.1641 + return r;
1.1642 + }
1.1643 + }
1.1644 + gChannel.CancelGetResourceStateRequests(gLongLatencyResource);
1.1645 + for(i=0;i<KLoopVarN;i++)
1.1646 + {
1.1647 + if((r=getReqStatus[i].Int()) != KErrNone)
1.1648 + {
1.1649 + gTest.Printf(_L("TestGetSetResourceStateOps, after cancel get state status[%d] = %d\n"),i,r);
1.1650 + return r;
1.1651 + }
1.1652 + }
1.1653 +
1.1654 + // 15) Call API to modify the state of a long latency resource 'm' times and wait for them to complete.
1.1655 + // Then call API with resource qualifier to cancel the requests.
1.1656 + gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1.1657 + for(i=0;i<KLoopVarM;i++)
1.1658 + {
1.1659 + gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta));
1.1660 + }
1.1661 + for(i=0;i<KLoopVarM;i++)
1.1662 + {
1.1663 + User::WaitForRequest(setReqStatus[i]);
1.1664 + if((r=setReqStatus[i].Int()) != KErrNone)
1.1665 + {
1.1666 + gTest.Printf(_L("TestGetSetResourceStateOps, before cancel change state status[%d] = %d\n"),i,r);
1.1667 + return r;
1.1668 + }
1.1669 + }
1.1670 + gChannel.CancelChangeResourceStateRequests(gLongLatencyResource);
1.1671 + for(i=0;i<KLoopVarM;i++)
1.1672 + {
1.1673 + if((r=setReqStatus[i].Int()) != KErrNone)
1.1674 + {
1.1675 + gTest.Printf(_L("TestGetSetResourceStateOps, after cancel change state status[%d] = %d\n"),i,r);
1.1676 + return r;
1.1677 + }
1.1678 + }
1.1679 +
1.1680 + // 16) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
1.1681 + // a long latency resource 'm' times.
1.1682 + // Call the API to cancel the get operations with resource qualifier.
1.1683 + // Wait for the operations to complete. Check the state of the associated TRequestStatus objects.
1.1684 + gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1.1685 + for(i=0;i<KLoopVarN;i++)
1.1686 + {
1.1687 + gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId);
1.1688 + }
1.1689 + for(i=0;i<KLoopVarM;i++)
1.1690 + {
1.1691 + gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta));
1.1692 + }
1.1693 + gChannel.CancelGetResourceStateRequests(gLongLatencyResource);
1.1694 + for(i=0;i<KLoopVarN;i++)
1.1695 + {
1.1696 + User::WaitForRequest(getReqStatus[i]);
1.1697 + if((r=getReqStatus[i].Int()) != KErrCancel)
1.1698 + {
1.1699 + gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status[%d] = %d\n"),i,r);
1.1700 + return r;
1.1701 + }
1.1702 + }
1.1703 + for(i=0;i<KLoopVarM;i++)
1.1704 + {
1.1705 + User::WaitForRequest(setReqStatus[i]);
1.1706 + if((r=setReqStatus[i].Int()) != KErrNone)
1.1707 + {
1.1708 + gTest.Printf(_L("TestGetSetResourceStateOps, completed change state status[%d] = %d\n"),i,r);
1.1709 + return r;
1.1710 + }
1.1711 + }
1.1712 +
1.1713 + // 17) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
1.1714 + // a long latency resource 'm' times.
1.1715 + // Call the API to cancel the modify operations with resource qualifier.
1.1716 + // Wait for the get operations to complete. Check the state of the associated TRequestStatus objects.
1.1717 + gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1.1718 + for(i=0;i<KLoopVarN;i++)
1.1719 + {
1.1720 + gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId);
1.1721 + }
1.1722 + for(i=0;i<KLoopVarM;i++)
1.1723 + {
1.1724 + gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta));
1.1725 + }
1.1726 + gChannel.CancelChangeResourceStateRequests(gLongLatencyResource);
1.1727 + for(i=0;i<KLoopVarN;i++)
1.1728 + {
1.1729 + User::WaitForRequest(getReqStatus[i]);
1.1730 + if((r=getReqStatus[i].Int()) != KErrNone)
1.1731 + {
1.1732 + gTest.Printf(_L("TestGetSetResourceStateOps, completed get state status[%d] = %d\n"),i,r);
1.1733 + return r;
1.1734 + }
1.1735 + }
1.1736 + for(i=0;i<KLoopVarM;i++)
1.1737 + {
1.1738 + User::WaitForRequest(setReqStatus[i]);
1.1739 + if((r=setReqStatus[i].Int()) != KErrCancel)
1.1740 + {
1.1741 + gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status[%d] = %d\n"),i,r);
1.1742 + return r;
1.1743 + }
1.1744 + }
1.1745 +
1.1746 + // 18) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
1.1747 + // a long latency resource 'm' times. Wait for the get operations to complete.
1.1748 + // Call the API to cancel the get operations with resource qualifier. Check the state of the associated TRequestStatus objects.
1.1749 + gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1.1750 + for(i=0;i<KLoopVarN;i++)
1.1751 + {
1.1752 + gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId);
1.1753 + }
1.1754 + TInt flipper = -1;
1.1755 + for(i=0;i<KLoopVarM;i++)
1.1756 + {
1.1757 + gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + (flipper*gAsyncResStateDelta)));
1.1758 + flipper*=-1;
1.1759 + }
1.1760 + for(i=0;i<KLoopVarN;i++)
1.1761 + {
1.1762 + User::WaitForRequest(getReqStatus[i]);
1.1763 + if((r=getReqStatus[i].Int()) != KErrNone)
1.1764 + {
1.1765 + gTest.Printf(_L("TestGetSetResourceStateOps, completed get state status[%d] = %d\n"),i,r);
1.1766 + return r;
1.1767 + }
1.1768 + }
1.1769 + gChannel.CancelGetResourceStateRequests(gLongLatencyResource);
1.1770 + for(i=0;i<KLoopVarM;i++)
1.1771 + {
1.1772 + User::WaitForRequest(setReqStatus[i]);
1.1773 + if((r=setReqStatus[i].Int()) != KErrNone)
1.1774 + {
1.1775 + gTest.Printf(_L("TestGetSetResourceStateOps, completed change state status[%d]= %d\n"),i,r);
1.1776 + return r;
1.1777 + }
1.1778 + }
1.1779 + for(i=0;i<KLoopVarN;i++)
1.1780 + {
1.1781 + if((r=getReqStatus[i].Int()) != KErrNone)
1.1782 + {
1.1783 + gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled get state status[%d]= %d\n"),i,r);
1.1784 + return r;
1.1785 + }
1.1786 + }
1.1787 +
1.1788 + // 19) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
1.1789 + // a long latency resource 'm' times. Wait for the modify operations to complete. Call the API to cancel the modify
1.1790 + // operations with resource qualifier. Check the state of the associated TRequestStatus objects.
1.1791 + gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1.1792 + for(i=0;i<KLoopVarN;i++)
1.1793 + {
1.1794 + gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId);
1.1795 + }
1.1796 + for(i=0;i<KLoopVarM;i++)
1.1797 + {
1.1798 + gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta));
1.1799 + }
1.1800 + for(i=0;i<KLoopVarM;i++)
1.1801 + {
1.1802 + User::WaitForRequest(setReqStatus[i]);
1.1803 + if((r=setReqStatus[i].Int()) != KErrNone)
1.1804 + {
1.1805 + gTest.Printf(_L("TestGetSetResourceStateOps, completed change state status[%d] = %d\n"),i,r);
1.1806 + return r;
1.1807 + }
1.1808 + }
1.1809 + gChannel.CancelChangeResourceStateRequests(gLongLatencyResource);
1.1810 + for(i=0;i<KLoopVarN;i++)
1.1811 + {
1.1812 + User::WaitForRequest(getReqStatus[i]);
1.1813 + if((r=getReqStatus[i].Int()) != KErrNone)
1.1814 + {
1.1815 + gTest.Printf(_L("TestGetSetResourceStateOps, completed get state status[%d] = %d\n"),i,r);
1.1816 + return r;
1.1817 + }
1.1818 + }
1.1819 + for(i=0;i<KLoopVarM;i++)
1.1820 + {
1.1821 + if((r=setReqStatus[i].Int()) != KErrNone)
1.1822 + {
1.1823 + gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status[%d] = %d\n"),i,r);
1.1824 + return r;
1.1825 + }
1.1826 + }
1.1827 +
1.1828 + // 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.
1.1829 + // Then call API without operation-type qualifier to cancel the even-numbered modify request(s).
1.1830 + // Then call API with operation-type qualifier to cancel the even-numbered get request(s).
1.1831 + // Check the state of the associated TRequestStatus objects.
1.1832 + gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1.1833 + for(i=0;i<KLoopVarN;i++)
1.1834 + {
1.1835 + gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId);
1.1836 + }
1.1837 + for(i=0;i<KLoopVarM;i++)
1.1838 + {
1.1839 + gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta));
1.1840 + }
1.1841 + for(i=0;i<KLoopVarM;i+=2)
1.1842 + {
1.1843 + gChannel.CancelAsyncOperation(&(setReqStatus[i]));
1.1844 + }
1.1845 + for(i=0;i<KLoopVarN;i+=2)
1.1846 + {
1.1847 + r=gChannel.CancelGetResourceState(getReqStatus[i]);
1.1848 + if(r!=KErrNone)
1.1849 + {
1.1850 + gTest.Printf(_L("TestGetSetResourceStateOps, CancelGetResourceState for index %d returned %d\n"),i,r);
1.1851 + return r;
1.1852 + }
1.1853 + }
1.1854 + for(i=0;i<KLoopVarM;i++)
1.1855 + {
1.1856 + User::WaitForRequest(setReqStatus[i]);
1.1857 + if((r=setReqStatus[i].Int()) != KErrCancel)
1.1858 + {
1.1859 + gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status[%d] = %d\n"),i,r);
1.1860 + return r;
1.1861 + }
1.1862 + if(++i >= KLoopVarM)
1.1863 + break;
1.1864 + User::WaitForRequest(setReqStatus[i]);
1.1865 + if((r=setReqStatus[i].Int()) != KErrNone)
1.1866 + {
1.1867 + gTest.Printf(_L("TestGetSetResourceStateOps, completed change state status[%d] = %d\n"),i,r);
1.1868 + return r;
1.1869 + }
1.1870 + }
1.1871 + for(i=0;i<KLoopVarN;i++)
1.1872 + {
1.1873 + User::WaitForRequest(getReqStatus[i]);
1.1874 + if((r=getReqStatus[i].Int()) != KErrCancel)
1.1875 + {
1.1876 + gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status[%d] = %d\n"),i,r);
1.1877 + return r;
1.1878 + }
1.1879 + if(++i >= KLoopVarN)
1.1880 + break;
1.1881 + User::WaitForRequest(getReqStatus[i]);
1.1882 + if((r=getReqStatus[i].Int()) != KErrNone)
1.1883 + {
1.1884 + gTest.Printf(_L("TestGetSetResourceStateOps, completed get state status[%d] = %d\n"),i,r);
1.1885 + return r;
1.1886 + }
1.1887 + }
1.1888 + return KErrNone;
1.1889 + }
1.1890 +
1.1891 +
1.1892 +//----------------------------------------------------------------------------------------------
1.1893 +//! @SYMTestCaseID KBASE-T_RESMANUS-0611
1.1894 +//! @SYMTestType UT
1.1895 +//! @SYMPREQ PREQ1398
1.1896 +//! @SYMTestCaseDesc This test case tests APIs for regulating getting and setting the state of resources
1.1897 +//!
1.1898 +//! @SYMTestActions 0) Issue the maximum number (requested in the call to the Initialise API)
1.1899 +//! of requests to get the current state of a resource. Then issue one further request.
1.1900 +//!
1.1901 +//! 1) Issue the maximum number (requested in the call to the Initialise API) of
1.1902 +//! requests to set the current state of a resource. Then issue one further request.
1.1903 +//!
1.1904 +//! @SYMTestExpectedResults 0) Test that the TRequestStatus object associated with the last request
1.1905 +//! exhibits status code KErrUnderflow - exit otherwise. Test that the
1.1906 +//! TRequestStatus objects associated with the preceding requests exhibit
1.1907 +//! status code KErrNone - exit otherwise.
1.1908 +//!
1.1909 +//! 1) Test that the TRequestStatus object associated with the last request
1.1910 +//! exhibits status code KErrUnderflow - exit otherwise. Test that the
1.1911 +//! TRequestStatus objects associated with the preceding requests exhibit
1.1912 +//! status code KErrNone - exit otherwise.
1.1913 +//!
1.1914 +//! @SYMTestPriority High
1.1915 +//! @SYMTestStatus Implemented
1.1916 +//----------------------------------------------------------------------------------------------
1.1917 +LOCAL_C TInt TestGetSetResourceStateQuota()
1.1918 +//
1.1919 +// Test resource state access quota management
1.1920 +//
1.1921 + {
1.1922 + TUint resourceId;
1.1923 +
1.1924 + // To perform the quota test we need a long latency resource
1.1925 + // If one has not been defined alert the user and return
1.1926 + if(!gHaveAsyncRes)
1.1927 + {
1.1928 + gTest.Printf(_L("TestGetSetResourceStateQuota: don't have suitable asynchronous resource ... exiting\n"));
1.1929 + return KErrNone;
1.1930 + }
1.1931 + else
1.1932 + resourceId = gLongLatencyResource;
1.1933 +
1.1934 + TInt r = KErrNone;
1.1935 + TBool lastErr = KErrNone;
1.1936 +
1.1937 + TInt i = 0;
1.1938 + TRequestStatus status[MAX_NUM_REQUESTS];
1.1939 + TInt state[MAX_NUM_REQUESTS];
1.1940 + TBool cached = gUseCached;
1.1941 + TInt levelOwnerId = 0;
1.1942 +
1.1943 + //
1.1944 + // Test GetResourceState - check client can not exceed quota of requests
1.1945 + //
1.1946 + gTest.Printf(_L("**Test GetResourceState (quota management)\n"));
1.1947 +
1.1948 + // KNoOfGetStateRequests Get state requests (of the same resource, ID=1) to consume the client quota
1.1949 + for(i=0; i<KNoOfGetStateRequests; i++)
1.1950 + gChannel.GetResourceState(status[i],resourceId,cached,&(state[i]),&levelOwnerId);
1.1951 +
1.1952 + // Addition Get state request to exceed the quota - the provided TRequestStatus
1.1953 + // object should indicate KErrUnderflow
1.1954 + gChannel.GetResourceState(status[KNoOfGetStateRequests],resourceId,cached,&(state[KNoOfGetStateRequests]),&levelOwnerId);
1.1955 + User::WaitForRequest(status[KNoOfGetStateRequests]);
1.1956 + if(status[KNoOfGetStateRequests].Int() != KErrUnderflow)
1.1957 + {
1.1958 + gTest.Printf(_L("TestGetSetResourceStateQuota, extra get state returned %d\n"),r);
1.1959 + return r;
1.1960 + }
1.1961 +
1.1962 + // Need to check the TRequestStatus objects
1.1963 + for(i=0; i<KNoOfGetStateRequests; i++)
1.1964 + {
1.1965 + User::WaitForRequest(status[i]);
1.1966 + if((r=status[i].Int()) != KErrNone)
1.1967 + {
1.1968 + gTest.Printf(_L("TestGetSetResourceStateQuota, get state %d returned %d\n"),i, r);
1.1969 + lastErr = r;
1.1970 + }
1.1971 + }
1.1972 + if(lastErr != KErrNone)
1.1973 + return lastErr;
1.1974 +
1.1975 + //
1.1976 + // Test ChangeResourceState - check client can not exceed quota of requests
1.1977 + //
1.1978 + gTest.Printf(_L("**Test ChangeResourceState (quota management)\n"));
1.1979 +
1.1980 + // KNoOfSetStateRequests Set state requests (of the same resource, ID=1) to consume the client quota
1.1981 + TInt newState = (state[1])+1;
1.1982 + for(i=0; i<KNoOfSetStateRequests; i++)
1.1983 + {
1.1984 + gChannel.ChangeResourceState(status[i],resourceId,newState);
1.1985 + }
1.1986 +
1.1987 + // Addition Set state request to exceed the quota - the provided TRequestStatus
1.1988 + // object should indicate KErrUnderflow
1.1989 + gChannel.ChangeResourceState(status[KNoOfSetStateRequests],resourceId,newState);
1.1990 + User::WaitForRequest(status[KNoOfSetStateRequests]);
1.1991 + if(status[KNoOfSetStateRequests].Int() != KErrUnderflow)
1.1992 + {
1.1993 + gTest.Printf(_L("TestGetSetResourceStateQuota, extra set state returned %d\n"),r);
1.1994 + return r;
1.1995 + }
1.1996 +
1.1997 + // Need to check the TRequestStatus objects
1.1998 + for(i=0; i<KNoOfSetStateRequests; i++)
1.1999 + {
1.2000 + User::WaitForRequest(status[i]);
1.2001 + if((r=status[i].Int()) != KErrNone)
1.2002 + {
1.2003 + gTest.Printf(_L("TestGetSetResourceStateQuota, set state %d returned %d\n"),i, r);
1.2004 + lastErr = r;
1.2005 + }
1.2006 + }
1.2007 + if(lastErr != KErrNone)
1.2008 + return lastErr;
1.2009 +
1.2010 + return r;
1.2011 + }
1.2012 +
1.2013 +
1.2014 +LOCAL_C TInt TriggerNotification(TRequestStatus& aStatus, TUint aResourceId, TBool aCached, TInt aDelta)
1.2015 +//
1.2016 +// Support the notification tests - cause a notification for the specified resource
1.2017 +//
1.2018 + {
1.2019 + TInt r = KErrNone;
1.2020 + TInt readValue = 0;
1.2021 + TInt levelOwnerId = 0;
1.2022 + // Get initial state
1.2023 + gChannel.GetResourceState(aStatus,aResourceId,aCached,&readValue,&levelOwnerId);
1.2024 + User::WaitForRequest(aStatus);
1.2025 + if(aStatus.Int() != KErrNone)
1.2026 + {
1.2027 + r=aStatus.Int();
1.2028 + gTest.Printf(_L("TriggerNotification, get state returned %d\n"),r);
1.2029 + return r;
1.2030 + }
1.2031 + TUint startingLevel = (TUint)readValue;
1.2032 +
1.2033 + // Write updated state
1.2034 + TUint newLevel = (TUint)(readValue + aDelta);
1.2035 + gTest.Printf(_L("TriggerNotification: startingLevel=0x%x, writing 0x%x\n"), startingLevel, newLevel);
1.2036 + gChannel.ChangeResourceState(aStatus,aResourceId,newLevel);
1.2037 + User::WaitForRequest(aStatus);
1.2038 + if(aStatus.Int() != KErrNone)
1.2039 + {
1.2040 + r=aStatus.Int();
1.2041 + gTest.Printf(_L("TriggerNotification, change state returned %d\n"),r);
1.2042 + return r;
1.2043 + }
1.2044 +
1.2045 + return r;
1.2046 + }
1.2047 +
1.2048 +
1.2049 +LOCAL_C TInt CalcNotifyDirAndThr(TRequestStatus& aStatus, TUint aResourceId, TBool aCached, TInt& aThreshold, TBool& aDirection)
1.2050 +//
1.2051 +// Support the notification tests - determine an appropriate threshold and direction to request
1.2052 +//
1.2053 + {
1.2054 + __KHEAP_MARK;
1.2055 +
1.2056 + // Need to know current state
1.2057 + TInt r = KErrNone;
1.2058 + TInt readValue = 0;
1.2059 + TInt levelOwnerId = 0;
1.2060 + {
1.2061 + gChannel.GetResourceState(aStatus,aResourceId,aCached,&readValue,&levelOwnerId);
1.2062 + User::WaitForRequest(aStatus);
1.2063 + if(aStatus.Int() != KErrNone)
1.2064 + {
1.2065 + r=aStatus.Int();
1.2066 + gTest.Printf(_L("TestNotificationOps, pre-qualified notify get state returned %d\n"),r);
1.2067 + return r;
1.2068 + }
1.2069 + }
1.2070 + aThreshold = readValue + gAsyncResStateDelta;
1.2071 + aDirection=(gAsyncResStateDelta>0)?ETrue:EFalse;
1.2072 +
1.2073 + __KHEAP_MARKEND;
1.2074 +
1.2075 + return r;
1.2076 + }
1.2077 +
1.2078 +
1.2079 +//----------------------------------------------------------------------------------------------
1.2080 +//! @SYMTestCaseID KBASE-T_RESMANUS-0612
1.2081 +//! @SYMTestType UT
1.2082 +//! @SYMPREQ PREQ1398
1.2083 +//! @SYMTestCaseDesc This test case tests APIs for requesting both qualified and unqualified
1.2084 +//! notifications; it also tests APIs to cancel such requests.
1.2085 +//!
1.2086 +//! @SYMTestActions 0) Call API to request notification of an unqualified change in resource
1.2087 +//! state for a selected resource. Trigger a state change.
1.2088 +//!
1.2089 +//! 1) Call API to request notification of a qualified change in resource
1.2090 +//! state for a selected resource. Trigger a state change.
1.2091 +//!
1.2092 +//! 2) Call API to request notification of an unqualified change in resource
1.2093 +//! state for a selected resource. Then call API to cancel all notifications for the resource.
1.2094 +//!
1.2095 +//! 3) Call API to request notification of a qualified change in resource
1.2096 +//! state for a selected resource. Then call API to cancel all notifications for the resource.
1.2097 +//!
1.2098 +//! 4) Call API to request notification of an unqualified change in resource
1.2099 +//! state for a selected resource. Trigger a state change. Then call API to cancel all
1.2100 +//! notifications for the resource.
1.2101 +//!
1.2102 +//! 5) Call API to request notification of a qualified change in resource
1.2103 +//! state for a selected resource. Trigger a state change. Then call API to cancel all
1.2104 +//! notifications for the resource.
1.2105 +//!
1.2106 +//! 6) Call API to request notification of an unqualified change in resource
1.2107 +//! state for a selected resource. Then call API to cancel the notification request
1.2108 +//!
1.2109 +//! 7) Call API to request notification of a qualified change in resource
1.2110 +//! state for a selected resource. Then call API to cancel the notification request
1.2111 +//!
1.2112 +//! 8) Call API to request notification of an unqualified change in resource
1.2113 +//! state for a selected resource. Trigger a state change. Then call API to cancel the
1.2114 +//! notification request
1.2115 +//!
1.2116 +//! 9) Call API to request notification of a qualified change in resource
1.2117 +//! state for a selected resource. Trigger a state change. Then call API to cancel the
1.2118 +//! notification request
1.2119 +//!
1.2120 +//! 10) Call API to request notification of an unqualified change in resource
1.2121 +//! state for a selected resource. Then call API to cancel generic async request
1.2122 +//!
1.2123 +//! 11) Call API to request notification of a qualified change in resource
1.2124 +//! state for a selected resource. Then call API to cancel generic async request
1.2125 +//!
1.2126 +//! 12) Call API to request notification of an unqualified change in resource
1.2127 +//! state for a selected resource. Trigger a state change. Then call API to cancel
1.2128 +//! generic async request
1.2129 +//!
1.2130 +//! 13) Call API to request notification of a qualified change in resource
1.2131 +//! state for a selected resource. Trigger a state change. Then call API to cancel
1.2132 +//! generic async request
1.2133 +//!
1.2134 +//! @SYMTestExpectedResults 0) The associated TRequestStatus object should indicate KErrNone
1.2135 +//! - exits otherwise.
1.2136 +//!
1.2137 +//! 1) The associated TRequestStatus object should indicate KErrNone
1.2138 +//! - exits otherwise.
1.2139 +//!
1.2140 +//! 2) The associated TRequestStatus object should indicate KErrCancel
1.2141 +//! - exits otherwise.
1.2142 +//!
1.2143 +//! 3) The associated TRequestStatus object should indicate KErrCancel
1.2144 +//! - exits otherwise.
1.2145 +//!
1.2146 +//! 4) The TRequestStatus object should indicate state KRequestPending until
1.2147 +//! the state change is triggered, upon which it should exhibit state
1.2148 +//! KErrNone. After the cancellation it should still exhibit state KErrNone.
1.2149 +//! Exit for any deviation from this behaviour.
1.2150 +//!
1.2151 +//! 5) The TRequestStatus object should indicate state KRequestPending until
1.2152 +//! the state change is triggered, upon which it should exhibit state
1.2153 +//! KErrNone. After the cancellation it should still exhibit state KErrNone.
1.2154 +//! Exit for any deviation from this behaviour.
1.2155 +//!
1.2156 +//! 6) The associated TRequestStatus object should indicate KErrCancel
1.2157 +//! - exits otherwise.
1.2158 +//!
1.2159 +//! 7) The associated TRequestStatus object should indicate KErrCancel
1.2160 +//! - exits otherwise.
1.2161 +//!
1.2162 +//! 8) The TRequestStatus object should indicate state KRequestPending until
1.2163 +//! the state change is triggered, upon which it should exhibit state
1.2164 +//! KErrNone. After the cancellation it should still exhibit state KErrNone.
1.2165 +//! Exit for any deviation from this behaviour.
1.2166 +//!
1.2167 +//! 9) The TRequestStatus object should indicate state KRequestPending until
1.2168 +//! the state change is triggered, upon which it should exhibit state
1.2169 +//! KErrNone. After the cancellation it should still exhibit state KErrNone.
1.2170 +//! Exit for any deviation from this behaviour.
1.2171 +//!
1.2172 +//! 10) The associated TRequestStatus object should indicate KErrCancel
1.2173 +//! - exits otherwise.
1.2174 +//!
1.2175 +//! 11) The associated TRequestStatus object should indicate KErrCancel
1.2176 +//! - exits otherwise.
1.2177 +//!
1.2178 +//! 12) The TRequestStatus object should indicate state KRequestPending until
1.2179 +//! the state change is triggered, upon which it should exhibit state
1.2180 +//! KErrNone. After the cancellation it should still exhibit state KErrNone.
1.2181 +//! Exit for any deviation from this behaviour.
1.2182 +//!
1.2183 +//! 13) The TRequestStatus object should indicate state KRequestPending until
1.2184 +//! the state change is triggered, upon which it should exhibit state
1.2185 +//! KErrNone. After the cancellation it should still exhibit state KErrNone.
1.2186 +//! Exit for any deviation from this behaviour.
1.2187 +//!
1.2188 +//! @SYMTestPriority High
1.2189 +//! @SYMTestStatus Implemented
1.2190 +//----------------------------------------------------------------------------------------------
1.2191 +LOCAL_C TInt TestNotificationOps()
1.2192 +//
1.2193 +// Test notification methods
1.2194 +//
1.2195 + {
1.2196 + __KHEAP_MARK;
1.2197 +
1.2198 + TInt r = KErrNone;
1.2199 + TRequestStatus status;
1.2200 + TUint resourceId;
1.2201 + TInt stateDelta;
1.2202 + if(!gHaveAsyncRes)
1.2203 + {
1.2204 + resourceId = 2; // Arbitrary
1.2205 + stateDelta = 1; // Arbitrary
1.2206 + }
1.2207 + else
1.2208 + {
1.2209 + resourceId = gLongLatencyResource;
1.2210 + stateDelta = gAsyncResStateDelta;
1.2211 + }
1.2212 + TInt testIndex = 0;
1.2213 +
1.2214 + // 0) Call API to request notification of an unqualified change in resource
1.2215 + // state for a selected resource. Trigger a state change.
1.2216 + gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
1.2217 + gChannel.RequestNotification(status, resourceId);
1.2218 + if(status.Int() != KRequestPending)
1.2219 + {
1.2220 + gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
1.2221 + return KErrGeneral;
1.2222 + }
1.2223 + TBool cached = gUseCached;
1.2224 + TRequestStatus triggerStatus;
1.2225 + if((r=TriggerNotification(triggerStatus, resourceId, cached, stateDelta))!=KErrNone)
1.2226 + return r;
1.2227 + User::WaitForRequest(status);
1.2228 + if(status.Int()!=KErrNone)
1.2229 + {
1.2230 + gTest.Printf(_L("TestNotificationOps: after TriggerNotification status = %d\n"),status.Int());
1.2231 + return r;
1.2232 + }
1.2233 +
1.2234 + // 1) Call API to request notification of a qualified change in resource
1.2235 + // state for a selected resource. Trigger a state change.
1.2236 + gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
1.2237 + TInt dumThreshold=0;
1.2238 + TBool dumDirection=EFalse;
1.2239 + if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
1.2240 + return r;
1.2241 + gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection);
1.2242 + if(status.Int() != KRequestPending)
1.2243 + {
1.2244 + gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
1.2245 + return KErrGeneral;
1.2246 + }
1.2247 + // Pass gAsyncResStateDelta as this represents the delta value
1.2248 + if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
1.2249 + return r;
1.2250 + User::WaitForRequest(status);
1.2251 + if(status.Int()!=KErrNone)
1.2252 + {
1.2253 + gTest.Printf(_L("TestNotificationOps: after TriggerNotification status = %d\n"),status.Int());
1.2254 + return r;
1.2255 + }
1.2256 +
1.2257 + // 2) Call API to request notification of an unqualified change in resource
1.2258 + // state for a selected resource. Then call API to cancel all notifications for the resource.
1.2259 + gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
1.2260 + gChannel.RequestNotification(status, resourceId);
1.2261 + if(status.Int() != KRequestPending)
1.2262 + {
1.2263 + gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
1.2264 + return KErrGeneral;
1.2265 + }
1.2266 + r=gChannel.CancelNotificationRequests(resourceId);
1.2267 + if(r!=KErrNone)
1.2268 + {
1.2269 + gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests returned %d\n"),r);
1.2270 + return r;
1.2271 + }
1.2272 + User::WaitForRequest(status);
1.2273 + if(status.Int()!=KErrCancel)
1.2274 + {
1.2275 + gTest.Printf(_L("TestNotificationOps: after cancel basic request status = %d\n"),status.Int());
1.2276 + return r;
1.2277 + }
1.2278 +
1.2279 + // 3) Call API to request notification of a qualified change in resource
1.2280 + // state for a selected resource. Then call API to cancel all notifications for the resource.
1.2281 + gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
1.2282 + dumThreshold = 0; // Arbitrary
1.2283 + dumDirection = ETrue; // Arbitrary
1.2284 + if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
1.2285 + return r;
1.2286 + gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection);
1.2287 + if(status.Int() != KRequestPending)
1.2288 + {
1.2289 + gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
1.2290 + return KErrGeneral;
1.2291 + }
1.2292 + r=gChannel.CancelNotificationRequests(resourceId);
1.2293 + if(r!=KErrNone)
1.2294 + {
1.2295 + gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests (qualified) returned %d\n"),r);
1.2296 + return r;
1.2297 + }
1.2298 + User::WaitForRequest(status);
1.2299 + if(status.Int()!=KErrCancel)
1.2300 + {
1.2301 + gTest.Printf(_L("TestNotificationOps: after qualified request cancel status = %d\n"),status.Int());
1.2302 + return r;
1.2303 + }
1.2304 +
1.2305 + // 4) Call API to request notification of an unqualified change in resource
1.2306 + // state for a selected resource. Trigger a state change. Then call API to cancel all
1.2307 + // notifications for the resource.
1.2308 + gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
1.2309 + gChannel.RequestNotification(status, resourceId);
1.2310 + if(status.Int() != KRequestPending)
1.2311 + {
1.2312 + gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
1.2313 + return KErrGeneral;
1.2314 + }
1.2315 + // Pass gAsyncResStateDelta as this represents the delta value
1.2316 + if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
1.2317 + return r;
1.2318 + User::WaitForRequest(status);
1.2319 + if(status.Int()!=KErrNone)
1.2320 + {
1.2321 + gTest.Printf(_L("TestNotificationOps: trigger basic request before cancel, status = %d\n"),status.Int());
1.2322 + return r;
1.2323 + }
1.2324 + r=gChannel.CancelNotificationRequests(resourceId);
1.2325 + if(r!=KErrNone)
1.2326 + {
1.2327 + gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests returned %d\n"),r);
1.2328 + return r;
1.2329 + }
1.2330 + if(status.Int()!=KErrNone)
1.2331 + {
1.2332 + gTest.Printf(_L("TestNotificationOps: after cancel (completed) basic request status = %d\n"),status.Int());
1.2333 + return r;
1.2334 + }
1.2335 +
1.2336 + // 5) Call API to request notification of a qualified change in resource
1.2337 + // state for a selected resource. Trigger a state change. Then call API to cancel all
1.2338 + // notifications for the resource.
1.2339 + gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
1.2340 + if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
1.2341 + return r;
1.2342 + gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection);
1.2343 + if(status.Int() != KRequestPending)
1.2344 + {
1.2345 + gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
1.2346 + return KErrGeneral;
1.2347 + }
1.2348 + // Pass gAsyncResStateDelta as this represents the delta value
1.2349 + if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
1.2350 + return r;
1.2351 + User::WaitForRequest(status);
1.2352 + if(status.Int()!=KErrNone)
1.2353 + {
1.2354 + gTest.Printf(_L("TestNotificationOps: trigger qualified request before cancel, status = %d\n"),status.Int());
1.2355 + return r;
1.2356 + }
1.2357 + r=gChannel.CancelNotificationRequests(resourceId);
1.2358 + if(r!=KErrNone)
1.2359 + {
1.2360 + gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests (qualified) returned %d\n"),r);
1.2361 + return r;
1.2362 + }
1.2363 + if(status.Int()!=KErrNone)
1.2364 + {
1.2365 + gTest.Printf(_L("TestNotificationOps: after cancel (completed) qualified request status = %d\n"),status.Int());
1.2366 + return r;
1.2367 + }
1.2368 +
1.2369 + // 6) Call API to request notification of an unqualified change in resource
1.2370 + // state for a selected resource. Then call API to cancel the notification request
1.2371 + gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
1.2372 + gChannel.RequestNotification(status, resourceId);
1.2373 + if(status.Int() != KRequestPending)
1.2374 + {
1.2375 + gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
1.2376 + return KErrGeneral;
1.2377 + }
1.2378 + r=gChannel.CancelRequestNotification(status);
1.2379 + if(r!=KErrNone)
1.2380 + {
1.2381 + gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests returned %d\n"),r);
1.2382 + return r;
1.2383 + }
1.2384 + User::WaitForRequest(status);
1.2385 + if(status.Int()!=KErrCancel)
1.2386 + {
1.2387 + gTest.Printf(_L("TestNotificationOps: after cancel basic request status = %d\n"),status.Int());
1.2388 + return r;
1.2389 + }
1.2390 +
1.2391 + // 7) Call API to request notification of a qualified change in resource
1.2392 + // state for a selected resource. Then call API to cancel the notification request
1.2393 + gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
1.2394 + dumThreshold = 0; // Arbitrary
1.2395 + dumDirection = ETrue; // Arbitrary
1.2396 + if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
1.2397 + return r;
1.2398 + gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection);
1.2399 + if(status.Int() != KRequestPending)
1.2400 + {
1.2401 + gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
1.2402 + return KErrGeneral;
1.2403 + }
1.2404 + r=gChannel.CancelRequestNotification(status);
1.2405 + if(r!=KErrNone)
1.2406 + {
1.2407 + gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests (qualified) returned %d\n"),r);
1.2408 + return r;
1.2409 + }
1.2410 + User::WaitForRequest(status);
1.2411 + if(status.Int()!=KErrCancel)
1.2412 + {
1.2413 + gTest.Printf(_L("TestNotificationOps: after qualified request cancel status = %d\n"),status.Int());
1.2414 + return r;
1.2415 + }
1.2416 +
1.2417 + // 8) Call API to request notification of an unqualified change in resource
1.2418 + // state for a selected resource. Trigger a state change. Then call API to cancel the
1.2419 + // notification request
1.2420 + gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
1.2421 + gChannel.RequestNotification(status, resourceId);
1.2422 + if(status.Int() != KRequestPending)
1.2423 + {
1.2424 + gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
1.2425 + return KErrGeneral;
1.2426 + }
1.2427 + // Pass gAsyncResStateDelta as this represents the delta value
1.2428 + if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
1.2429 + return r;
1.2430 + User::WaitForRequest(status);
1.2431 + if(status.Int()!=KErrNone)
1.2432 + {
1.2433 + gTest.Printf(_L("TestNotificationOps: trigger basic request before cancel, status = %d\n"),status.Int());
1.2434 + return r;
1.2435 + }
1.2436 + r=gChannel.CancelRequestNotification(status);
1.2437 + if(r!=KErrNone)
1.2438 + {
1.2439 + gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests returned %d\n"),r);
1.2440 + return r;
1.2441 + }
1.2442 + if(status.Int()!=KErrNone)
1.2443 + {
1.2444 + gTest.Printf(_L("TestNotificationOps: after cancel (completed) basic request status = %d\n"),status.Int());
1.2445 + return r;
1.2446 + }
1.2447 +
1.2448 + // 9) Call API to request notification of a qualified change in resource
1.2449 + // state for a selected resource. Trigger a state change. Then call API to cancel the
1.2450 + // notification request
1.2451 + gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
1.2452 + if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
1.2453 + return r;
1.2454 + gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection);
1.2455 + if(status.Int() != KRequestPending)
1.2456 + {
1.2457 + gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
1.2458 + return KErrGeneral;
1.2459 + }
1.2460 + // Pass gAsyncResStateDelta as this represents the delta value
1.2461 + if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
1.2462 + return r;
1.2463 + User::WaitForRequest(status);
1.2464 + if(status.Int()!=KErrNone)
1.2465 + {
1.2466 + gTest.Printf(_L("TestNotificationOps: trigger qualified request before cancel, status = %d\n"),status.Int());
1.2467 + return r;
1.2468 + }
1.2469 + r=gChannel.CancelRequestNotification(status);
1.2470 + if(r!=KErrNone)
1.2471 + {
1.2472 + gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests (qualified) returned %d\n"),r);
1.2473 + return r;
1.2474 + }
1.2475 + if(status.Int()!=KErrNone)
1.2476 + {
1.2477 + gTest.Printf(_L("TestNotificationOps: after cancel (completed) qualified request status = %d\n"),status.Int());
1.2478 + return r;
1.2479 + }
1.2480 +
1.2481 +
1.2482 + // 10) Call API to request notification of an unqualified change in resource
1.2483 + // state for a selected resource. Then call API to cancel generic async request
1.2484 + gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
1.2485 + gChannel.RequestNotification(status, resourceId);
1.2486 + if(status.Int() != KRequestPending)
1.2487 + {
1.2488 + gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
1.2489 + return KErrGeneral;
1.2490 + }
1.2491 + gChannel.CancelAsyncOperation(&status);
1.2492 + User::WaitForRequest(status);
1.2493 + if(status.Int()!=KErrCancel)
1.2494 + {
1.2495 + gTest.Printf(_L("TestNotificationOps: after cancel basic request status = %d\n"),status.Int());
1.2496 + return r;
1.2497 + }
1.2498 +
1.2499 + // 11) Call API to request notification of a qualified change in resource
1.2500 + // state for a selected resource. Then call API to cancel generic async request
1.2501 + gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
1.2502 + dumThreshold = 0; // Arbitrary
1.2503 + dumDirection = ETrue; // Arbitrary
1.2504 + if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
1.2505 + return r;
1.2506 + gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection);
1.2507 + if(status.Int() != KRequestPending)
1.2508 + {
1.2509 + gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
1.2510 + return KErrGeneral;
1.2511 + }
1.2512 + gChannel.CancelAsyncOperation(&status);
1.2513 + User::WaitForRequest(status);
1.2514 + if(status.Int()!=KErrCancel)
1.2515 + {
1.2516 + gTest.Printf(_L("TestNotificationOps: after qualified request cancel status = %d\n"),status.Int());
1.2517 + return r;
1.2518 + }
1.2519 +
1.2520 + // 12) Call API to request notification of an unqualified change in resource
1.2521 + // state for a selected resource. Trigger a state change. Then call API to cancel
1.2522 + // generic async request
1.2523 + gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
1.2524 + gChannel.RequestNotification(status, resourceId);
1.2525 + if(status.Int() != KRequestPending)
1.2526 + {
1.2527 + gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
1.2528 + return KErrGeneral;
1.2529 + }
1.2530 + // Pass gAsyncResStateDelta as this represents the delta value
1.2531 + if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
1.2532 + return r;
1.2533 + User::WaitForRequest(status);
1.2534 + if(status.Int()!=KErrNone)
1.2535 + {
1.2536 + gTest.Printf(_L("TestNotificationOps: trigger basic request before cancel, status = %d\n"),status.Int());
1.2537 + return r;
1.2538 + }
1.2539 + gChannel.CancelAsyncOperation(&status);
1.2540 + if(status.Int()!=KErrNone)
1.2541 + {
1.2542 + gTest.Printf(_L("TestNotificationOps: after cancel (completed) basic request status = %d\n"),status.Int());
1.2543 + return r;
1.2544 + }
1.2545 +
1.2546 + // 13) Call API to request notification of a qualified change in resource
1.2547 + // state for a selected resource. Trigger a state change. Then call API to cancel
1.2548 + // generic async request
1.2549 + gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
1.2550 + if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
1.2551 + return r;
1.2552 + gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection);
1.2553 + if(status.Int() != KRequestPending)
1.2554 + {
1.2555 + gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
1.2556 + return KErrGeneral;
1.2557 + }
1.2558 + // Pass gAsyncResStateDelta as this represents the delta value
1.2559 + if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
1.2560 + return r;
1.2561 + User::WaitForRequest(status);
1.2562 + if(status.Int()!=KErrNone)
1.2563 + {
1.2564 + gTest.Printf(_L("TestNotificationOps: trigger qualified request before cancel, status = %d\n"),status.Int());
1.2565 + return r;
1.2566 + }
1.2567 + gChannel.CancelAsyncOperation(&status);
1.2568 + if(status.Int()!=KErrNone)
1.2569 + {
1.2570 + gTest.Printf(_L("TestNotificationOps: after cancel (completed) qualified request status = %d\n"),status.Int());
1.2571 + return r;
1.2572 + }
1.2573 +
1.2574 + __KHEAP_MARKEND;
1.2575 +
1.2576 + return r;
1.2577 + }
1.2578 +
1.2579 +//----------------------------------------------------------------------------------------------
1.2580 +//! @SYMTestCaseID KBASE-T_RESMANUS-0613
1.2581 +//! @SYMTestType UT
1.2582 +//! @SYMPREQ PREQ1398
1.2583 +//! @SYMTestCaseDesc This test case tests quota management for notification operations.
1.2584 +//!
1.2585 +//! @SYMTestActions 0) Issue the maximum number (requested in the call to the Initialise API)
1.2586 +//! of requests for notification of unqualified changes to the state of a
1.2587 +//! resource. Then issue one further request.
1.2588 +//!
1.2589 +//! 1) Issue the maximum number (requested in the call to the Initialise API)
1.2590 +//! of requests for notification of qualified changes to the state of a
1.2591 +//! resource. Then issue one further request.
1.2592 +//!
1.2593 +//! 2) Issue the maximum number (requested in the call to the Initialise API)
1.2594 +//! of requests for notification changes to the state of a resource, where
1.2595 +//! every odd request is for an unqualified change and every even request is
1.2596 +//! for a qualified change. Then issue one further request.
1.2597 +//!
1.2598 +//! @SYMTestExpectedResults 0) Test that the TRequestStatus object associated with the last
1.2599 +//! request exhibits status code KErrUnderflow - exit otherwise. Test
1.2600 +//! that the TRequestStatus objects associated with the preceding requests
1.2601 +//! exhibit status code KErrNone - exit otherwise.
1.2602 +//!
1.2603 +//! 1) Test that the TRequestStatus object associated with the last request
1.2604 +//! exhibits status code KErrUnderflow - exit otherwise. Test that the
1.2605 +//! TRequestStatus objects associated with the preceding requests exhibit
1.2606 +//! status code KErrNone - exit otherwise.
1.2607 +//!
1.2608 +//! 2) Test that the TRequestStatus object associated with the last request
1.2609 +//! exhibits status code KErrUnderflow - exit otherwise. Test that the
1.2610 +//! TRequestStatus objects associated with the preceding requests exhibit
1.2611 +//! status code KErrNone - exit otherwise.
1.2612 +//!
1.2613 +//! @SYMTestPriority High
1.2614 +//! @SYMTestStatus Implemented
1.2615 +//----------------------------------------------------------------------------------------------
1.2616 +LOCAL_C TInt TestNotificationQuota()
1.2617 +//
1.2618 +// Test notification request quota management
1.2619 +//
1.2620 + {
1.2621 + __KHEAP_MARK;
1.2622 +
1.2623 + TInt r = KErrNone;
1.2624 + TRequestStatus status[MAX_NUM_REQUESTS];
1.2625 + TInt loopVar=0;
1.2626 + TBool cached = gUseCached;
1.2627 + TRequestStatus triggerStatus;
1.2628 + TUint resourceId = gLongLatencyResource;
1.2629 +
1.2630 + // Test quota for basic operation
1.2631 + //
1.2632 + // Loop to perform maximum number of requests, check TRequestStatus objects are pending
1.2633 + for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++)
1.2634 + {
1.2635 + gChannel.RequestNotification(status[loopVar], resourceId);
1.2636 + if(status[loopVar].Int() != KRequestPending)
1.2637 + {
1.2638 + gTest.Printf(_L("TestNotificationQuota: status not KRequestPending, =%d\n"),
1.2639 + status[loopVar].Int());
1.2640 + return KErrGeneral;
1.2641 + }
1.2642 + }
1.2643 + // Issue one more request, check that TRequestStatus object exhibits state KErrUnderflow
1.2644 + gChannel.RequestNotification(status[KNoOfNotifyRequests], resourceId);
1.2645 + if(status[KNoOfNotifyRequests].Int() != KErrUnderflow)
1.2646 + {
1.2647 + gTest.Printf(_L("TestNotificationQuota: status[%d] not KErrUnderflow, =%d\n"),
1.2648 + KNoOfNotifyRequests,status[loopVar].Int());
1.2649 + return KErrGeneral;
1.2650 + }
1.2651 + // Loop to trigger previously-issued notifications, check TRequestStatus objects
1.2652 + for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++)
1.2653 + {
1.2654 + // Pass gAsyncResStateDelta as this represents the delta value
1.2655 + if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
1.2656 + return r;
1.2657 + User::WaitForRequest(status[loopVar]);
1.2658 + if(status[loopVar].Int()!=KErrNone)
1.2659 + {
1.2660 + gTest.Printf(_L("TestNotificationQuota: trigger basic request status[%d] = %d\n"),
1.2661 + loopVar,status[loopVar].Int());
1.2662 + return r;
1.2663 + }
1.2664 + }
1.2665 +
1.2666 +
1.2667 + // Test quota for qualified operation
1.2668 + //
1.2669 + TInt dumThreshold = -25; // Arbitrary
1.2670 + TBool dumDirection = ETrue; // Arbitrary
1.2671 + //
1.2672 + // Loop to perform maximum number of requests, check TRequestStatus objects are pending
1.2673 + for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++)
1.2674 + {
1.2675 + if((r=CalcNotifyDirAndThr(status[loopVar], resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
1.2676 + return r;
1.2677 + gChannel.RequestNotification(status[loopVar], resourceId, dumThreshold, dumDirection);
1.2678 + if(status[loopVar].Int() != KRequestPending)
1.2679 + {
1.2680 + gTest.Printf(_L("TestNotificationQuota: status[%d] not KRequestPending, =%d\n"),
1.2681 + loopVar,status[loopVar].Int());
1.2682 + return KErrGeneral;
1.2683 + }
1.2684 + }
1.2685 + // Issue one more request, check that TRequestStatus object exhibits state KErrUnderflow
1.2686 + if((r=CalcNotifyDirAndThr(status[KNoOfNotifyRequests], resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
1.2687 + return r;
1.2688 + gChannel.RequestNotification(status[KNoOfNotifyRequests], resourceId, dumThreshold, dumDirection);
1.2689 + if(status[KNoOfNotifyRequests].Int() != KErrUnderflow)
1.2690 + {
1.2691 + gTest.Printf(_L("TestNotificationQuota: status[%d] not KErrUnderflow, =%d\n"),
1.2692 + KNoOfNotifyRequests,status[loopVar].Int());
1.2693 + return KErrGeneral;
1.2694 + }
1.2695 + // Loop to trigger previously-issued notifications, check TRequestStatus objects
1.2696 + for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++)
1.2697 + {
1.2698 + // Pass gAsyncResStateDelta as this represents the delta value
1.2699 + if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
1.2700 + return r;
1.2701 + User::WaitForRequest(status[loopVar]);
1.2702 + if(status[loopVar].Int()!=KErrNone)
1.2703 + {
1.2704 + gTest.Printf(_L("TestNotificationQuota: trigger qualified request status[%d] = %d\n"),
1.2705 + loopVar,status[loopVar].Int());
1.2706 + return r;
1.2707 + }
1.2708 + }
1.2709 +
1.2710 + // Text quota with mixture of basic and qualified requests
1.2711 + //
1.2712 + TBool qualified = ETrue;
1.2713 + // Issue requests and check TRequestStatus objects are pending
1.2714 + for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++)
1.2715 + {
1.2716 + if(qualified)
1.2717 + {
1.2718 + if((r=CalcNotifyDirAndThr(status[loopVar], resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
1.2719 + return r;
1.2720 + gChannel.RequestNotification(status[loopVar], resourceId, dumThreshold, dumDirection);
1.2721 + }
1.2722 + else
1.2723 + {
1.2724 + gChannel.RequestNotification(status[loopVar], resourceId);
1.2725 + }
1.2726 + qualified=!qualified;
1.2727 + if(status[loopVar].Int() != KRequestPending)
1.2728 + {
1.2729 + gTest.Printf(_L("TestNotificationQuota: mixed loop status[%d] not KRequestPending, =%d\n"),
1.2730 + loopVar,status[loopVar].Int());
1.2731 + return KErrGeneral;
1.2732 + }
1.2733 + }
1.2734 + // Issue one more request, check that TRequestStatus object exhibits state KErrUnderflow
1.2735 + if(qualified)
1.2736 + {
1.2737 + if((r=CalcNotifyDirAndThr(status[KNoOfNotifyRequests], resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
1.2738 + return r;
1.2739 + gChannel.RequestNotification(status[KNoOfNotifyRequests], resourceId, dumThreshold, dumDirection);
1.2740 + }
1.2741 + else
1.2742 + {
1.2743 + gChannel.RequestNotification(status[KNoOfNotifyRequests], resourceId);
1.2744 + }
1.2745 + if(status[KNoOfNotifyRequests].Int() != KErrUnderflow)
1.2746 + {
1.2747 + gTest.Printf(_L("TestNotificationQuota: mixed loop status[%d] not KErrUnderflow, =%d\n"),
1.2748 + KNoOfNotifyRequests,status[loopVar].Int());
1.2749 + return KErrGeneral;
1.2750 + }
1.2751 + // Loop to trigger previously-issued notifications, check TRequestStatus objects
1.2752 + for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++)
1.2753 + {
1.2754 + // Pass gAsyncResStateDelta as this represents the delta value
1.2755 + if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
1.2756 + return r;
1.2757 + User::WaitForRequest(status[loopVar]);
1.2758 + if(status[loopVar].Int()!=KErrNone)
1.2759 + {
1.2760 + gTest.Printf(_L("TestNotificationQuota: trigger mixed request status[%d] = %d\n"),
1.2761 + loopVar,status[loopVar].Int());
1.2762 + return r;
1.2763 + }
1.2764 + }
1.2765 +
1.2766 + __KHEAP_MARKEND;
1.2767 +
1.2768 + return r;
1.2769 + }
1.2770 +
1.2771 +#ifdef PIRATE_THREAD_TESTS
1.2772 +
1.2773 +RThread PirateThread;
1.2774 +TRequestStatus PirateStatus;
1.2775 +const TInt KHeapSize=0x4000;
1.2776 +const TInt KStackSize=0x4000;
1.2777 +
1.2778 +_LIT(KPirateThreadName,"Pirate");
1.2779 +
1.2780 +TInt PirateThreadFn(TAny* /*aSrcThread*/)
1.2781 + {
1.2782 +#if 0
1.2783 + TInt r=KErrNone;
1.2784 + RBusDevResManUs pirateChannel = gChannel;
1.2785 + RThread& thread = *((RThread*)aSrcThread);
1.2786 +
1.2787 +/* 1 - pirate with current thread - Panics kernel with KErrBadHandle */
1.2788 + if((r=pirateChannel.Duplicate(RThread(),EOwnerProcess))!=KErrAccessDenied)
1.2789 + {
1.2790 + gTest.Printf(_L("TestThreadExclusiveAccess: pirateChannel.Duplicate(RThread(),EOwnerProcess) returned %d\n"),r);
1.2791 + return KErrGeneral;
1.2792 + }
1.2793 +
1.2794 +/* 2 - pirate with parent thread - Panics kernel with KErrBadHandle */
1.2795 + pirateChannel = gChannel;
1.2796 + if((r=pirateChannel.Duplicate(thread,EOwnerThread))!=KErrAccessDenied)
1.2797 + {
1.2798 + gTest.Printf(_L("TestThreadExclusiveAccess: pirateChannel.Duplicate(thread,EOwnerThread) returned %d\n"),r);
1.2799 + return KErrGeneral;
1.2800 + }
1.2801 +
1.2802 +/* 3 - gChannel with current thread - Panics kernel with KErrBadHandle */
1.2803 + if((r=gChannel.Duplicate(RThread(),EOwnerThread))!=KErrAccessDenied)
1.2804 + {
1.2805 + gTest.Printf(_L("TestThreadExclusiveAccess: gChannel.Duplicate(RThread(),EOwnerThread) returned %d\n"),r);
1.2806 + return KErrGeneral;
1.2807 + }
1.2808 +
1.2809 +/* 4 - gChannel with parent thread - Panics kernel with KErrBadHandle */
1.2810 + if((r=gChannel.Duplicate(thread,EOwnerThread))!=KErrAccessDenied)
1.2811 + {
1.2812 + gTest.Printf(_L("TestThreadExclusiveAccess: gChannel.Duplicate(thread,EOwnerThread)returned %d\n"),r);
1.2813 + return KErrGeneral;
1.2814 + }
1.2815 +#endif
1.2816 +
1.2817 +// pirateChannel.Close();
1.2818 + return KErrNone;
1.2819 + }
1.2820 +
1.2821 +TInt StartPirate(RThread& aSrcThread)
1.2822 + {
1.2823 + TAny* srcThread =(TAny*)(&aSrcThread);
1.2824 + TInt r=PirateThread.Create(KPirateThreadName,PirateThreadFn,KStackSize,KHeapSize,KHeapSize,srcThread,EOwnerThread);
1.2825 + if (r!=KErrNone)
1.2826 + return r;
1.2827 + PirateThread.Logon(PirateStatus);
1.2828 + PirateThread.Resume();
1.2829 + return KErrNone;
1.2830 + }
1.2831 +
1.2832 +TInt WaitForPirateThread()
1.2833 + {
1.2834 + User::WaitForRequest(PirateStatus);
1.2835 + TInt exitType=PirateThread.ExitType();
1.2836 + TInt exitReason=PirateThread.ExitReason();
1.2837 + TBuf<16> exitCat=PirateThread.ExitCategory();
1.2838 + if((exitType!= EExitKill)||(exitReason!=KErrNone))
1.2839 + {
1.2840 + gTest.Printf(_L("Pirate thread error: %d\n"),PirateStatus.Int());
1.2841 + gTest.Printf(_L("Thread exit reason: %d,%d,%S\n"),exitType,exitReason,&exitCat);
1.2842 + gTest(0);
1.2843 + }
1.2844 + PirateThread.Close();
1.2845 + return KErrNone;
1.2846 + }
1.2847 +
1.2848 +#endif
1.2849 +
1.2850 +//----------------------------------------------------------------------------------------------
1.2851 +//! @SYMTestCaseID KBASE-T_RESMANUS-0608
1.2852 +//! @SYMTestType UT
1.2853 +//! @SYMPREQ PREQ1398
1.2854 +//! @SYMTestCaseDesc This test case tests that channels can not be shared between threads.
1.2855 +//! @SYMTestActions 0) Attempt to Duplicate the channel handle with EOwnerProcess as the owner type.
1.2856 +//!
1.2857 +//! 1) Attempt to Duplicate the channel handle with EOwnerThread
1.2858 +//!
1.2859 +//! @SYMTestExpectedResults 0) API should return with KErrAccessDenied, exits otherwise.
1.2860 +//! 1) API should return with KErrNone, exits otherwise.
1.2861 +//!
1.2862 +//! @SYMTestPriority High
1.2863 +//! @SYMTestStatus Implemented
1.2864 +//----------------------------------------------------------------------------------------------
1.2865 +LOCAL_C TInt TestThreadExclusiveAccess()
1.2866 +//
1.2867 +// Test mechanism to prevent other threads accessing a channel
1.2868 +//
1.2869 + {
1.2870 + __KHEAP_MARK;
1.2871 +
1.2872 + TInt r;
1.2873 + RBusDevResManUs pirateChannel = gChannel;
1.2874 + if((r=pirateChannel.Duplicate(RThread(),EOwnerProcess))!=KErrAccessDenied)
1.2875 + {
1.2876 + gTest.Printf(_L("TestThreadExclusiveAccess: Duplicate with EOwnerProcess returned %d\n"),r);
1.2877 + if(r==KErrNone)
1.2878 + r=KErrGeneral;
1.2879 + return r;
1.2880 + }
1.2881 + pirateChannel = gChannel;
1.2882 + if((r=pirateChannel.Duplicate(RThread(),EOwnerThread))!=KErrNone)
1.2883 + {
1.2884 + gTest.Printf(_L("TestThreadExclusiveAccess: Duplicate with EOwnerThread returned %d\n"),r);
1.2885 + return r;
1.2886 + }
1.2887 +#ifdef PIRATE_THREAD_TESTS
1.2888 + RThread& threadRef = RThread();
1.2889 + if((r=StartPirate(threadRef))!=KErrNone)
1.2890 + {
1.2891 + gTest.Printf(_L("TestThreadExclusiveAccess: StartPirate returned %d\n"),r);
1.2892 + return KErrGeneral;
1.2893 + }
1.2894 + if((r=WaitForPirateThread())!=KErrNone)
1.2895 + {
1.2896 + gTest.Printf(_L("TestThreadExclusiveAccess: WaitForPirateThread returned %d\n"),r);
1.2897 + return KErrGeneral;
1.2898 + }
1.2899 +#endif
1.2900 + pirateChannel.Close();
1.2901 +
1.2902 + __KHEAP_MARKEND;
1.2903 +
1.2904 + return KErrNone;
1.2905 + }
1.2906 +
1.2907 +RThread Thrd2;
1.2908 +TRequestStatus Thrd2Status;
1.2909 +const TInt KHeapSize=0x4000;
1.2910 +const TInt KStackSize=0x4000;
1.2911 +
1.2912 +_LIT(KThrd2Name,"Thread2");
1.2913 +
1.2914 +
1.2915 +TInt Thread2Fn(TAny* /* */)
1.2916 +//
1.2917 +// Test that more than one thread can be supported
1.2918 +//
1.2919 + {
1.2920 + TInt r;
1.2921 +
1.2922 + // Open a channel
1.2923 + //
1.2924 + _LIT(secThrdStr,"Thrd2Channel");
1.2925 + TBufC<16> secThrdName(secThrdStr);
1.2926 + // API accepts 8-bit descriptors, only - so convert name accordingly
1.2927 + TBuf8<MAX_RESOURCE_NAME_LENGTH+1>EightBitName;
1.2928 + EightBitName.Copy(secThrdName);
1.2929 + RBusDevResManUs secThrdChannel;
1.2930 + if((r=secThrdChannel.Open(EightBitName))!=KErrNone)
1.2931 + return r;
1.2932 +
1.2933 + // Read the resource information
1.2934 + //
1.2935 + TUint numResources=0;
1.2936 + if((r=secThrdChannel.GetNoOfResources(numResources))!=KErrNone)
1.2937 + return r;
1.2938 +
1.2939 + // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects
1.2940 + // and reference via an RSimplePointerArray
1.2941 + TUint bufSize = numResources;
1.2942 + RSimplePointerArray<TResourceInfoBuf> resPtrs(bufSize);
1.2943 + for(TUint i=0;i<bufSize;i++)
1.2944 + {
1.2945 + TResourceInfoBuf *info = new TResourceInfoBuf();
1.2946 + if((r=resPtrs.Insert(info, i))!=KErrNone)
1.2947 + return r;
1.2948 + }
1.2949 +
1.2950 + TUint updateNumResources=numResources;
1.2951 + if((r=secThrdChannel.GetAllResourcesInfo(&resPtrs,updateNumResources))!=KErrNone)
1.2952 + return r;
1.2953 + resPtrs.Close();
1.2954 +
1.2955 +
1.2956 + // Read current client information
1.2957 + //
1.2958 + TUint numClients=0;
1.2959 + TUint numAllClients=0;
1.2960 + //
1.2961 + // GetNoOfClients - with default aIncludeKern=EFalse
1.2962 + //
1.2963 + if((r=secThrdChannel.GetNoOfClients(numClients,EFalse)) != KErrNone)
1.2964 + return r;
1.2965 + //
1.2966 + // GetNoOfClients - with aIncludeKern=ETrue
1.2967 + //
1.2968 + r=secThrdChannel.GetNoOfClients(numAllClients, ETrue);
1.2969 +#ifdef RESMANUS_KERN
1.2970 + if(r!=KErrNone)
1.2971 +#else
1.2972 + if(r!=KErrPermissionDenied)
1.2973 +#endif
1.2974 + return KErrGeneral;
1.2975 + //
1.2976 + // Need a buffer big enough to contain numClients instances of TClientName
1.2977 + // To support the GetNamesAllClients testing, instantiate TClientName objects
1.2978 + // and reference via an RSimplePointerArray
1.2979 + TUint resBufSize = (numAllClients>numClients)?numAllClients:numClients;
1.2980 + RSimplePointerArray<TClientName> infoPtrs(resBufSize);
1.2981 + for(TUint j=0;j<resBufSize;j++)
1.2982 + {
1.2983 + TClientName *info = new TClientName();
1.2984 + if((r=infoPtrs.Insert(info, j))!=KErrNone)
1.2985 + return r;
1.2986 + }
1.2987 + //
1.2988 + // GetNamesAllClients - with aIncludeKern=EFalse
1.2989 + //
1.2990 + if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numClients, EFalse)) != KErrNone)
1.2991 + return r;
1.2992 + //
1.2993 + // GetNamesAllClients - with aIncludeKern=ETrue
1.2994 + //
1.2995 +#ifdef RESMANUS_KERN
1.2996 + if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numAllClients, ETrue)) != KErrNone)
1.2997 + return r;
1.2998 +#else
1.2999 + if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numClients, ETrue)) != KErrPermissionDenied)
1.3000 + {
1.3001 + if(r==KErrNone)
1.3002 + r=KErrGeneral;
1.3003 + return r;
1.3004 + }
1.3005 + else
1.3006 + r=KErrNone; // Ensure misleading result is not propagated
1.3007 +#endif
1.3008 + infoPtrs.Close();
1.3009 +
1.3010 + // If we don't have a shared resource identified, skip the remaining tests
1.3011 + if(gHaveSharedRes)
1.3012 + {
1.3013 + // Register with the Resource Controller
1.3014 + //
1.3015 + if ((r=secThrdChannel.Initialise(1,1,0))!=KErrNone) // Just need 1 get and 1 set state
1.3016 + return r;
1.3017 + // Set a level on the shared resource
1.3018 + //
1.3019 + // Get initial state
1.3020 + TRequestStatus status;
1.3021 + TBool cached = gUseCached;
1.3022 + TInt readValue;
1.3023 + TInt levelOwnerId;
1.3024 + secThrdChannel.GetResourceState(status,gSharedResource,cached,&readValue,&levelOwnerId);
1.3025 + User::WaitForRequest(status);
1.3026 + r=status.Int();
1.3027 + if(r != KErrNone)
1.3028 + return r;
1.3029 + // Write updated state
1.3030 + TUint newLevel = (TUint)(readValue + gSharedResStateDelta);
1.3031 + secThrdChannel.ChangeResourceState(status,gSharedResource,newLevel);
1.3032 + User::WaitForRequest(status);
1.3033 + r=status.Int();
1.3034 + if(r != KErrNone)
1.3035 + return r;
1.3036 +
1.3037 + // Read current client information
1.3038 + //
1.3039 + numClients=0;
1.3040 + numAllClients=0;
1.3041 + //
1.3042 + // GetNoOfClients - with default aIncludeKern=EFalse
1.3043 + //
1.3044 + if((r=secThrdChannel.GetNoOfClients(numClients,EFalse)) != KErrNone)
1.3045 + return r;
1.3046 + //
1.3047 + // GetNoOfClients - with aIncludeKern=ETrue
1.3048 + //
1.3049 +#ifdef RESMANUS_KERN
1.3050 + if((r=secThrdChannel.GetNoOfClients(numAllClients, ETrue))!=KErrNone)
1.3051 +#else
1.3052 + if((r=secThrdChannel.GetNoOfClients(numAllClients, ETrue))!=KErrPermissionDenied)
1.3053 +#endif
1.3054 + return KErrGeneral;
1.3055 + //
1.3056 + // Need a buffer big enough to contain numClients instances of TClientName
1.3057 + // To support the GetNamesAllClients testing, instantiate TClientName objects
1.3058 + // and reference via an RSimplePointerArray
1.3059 + TUint bufSize = (numAllClients>numClients)?numAllClients:numClients;
1.3060 + RSimplePointerArray<TClientName> infoPtrs(bufSize);
1.3061 + for(TUint i=0;i<bufSize;i++)
1.3062 + {
1.3063 + TClientName *info = new TClientName();
1.3064 + if((r=infoPtrs.Insert(info, i))!=KErrNone)
1.3065 + return r;
1.3066 + }
1.3067 + //
1.3068 + // GetNamesAllClients - with aIncludeKern=EFalse
1.3069 + //
1.3070 + if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numClients, EFalse)) != KErrNone)
1.3071 + return r;
1.3072 + //
1.3073 + // GetNamesAllClients - with aIncludeKern=ETrue
1.3074 + //
1.3075 +#ifdef RESMANUS_KERN
1.3076 + if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numAllClients, ETrue)) != KErrNone)
1.3077 + return r;
1.3078 +#else
1.3079 + if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numClients, ETrue)) != KErrPermissionDenied)
1.3080 + {
1.3081 + if(r==KErrNone)
1.3082 + r=KErrGeneral;
1.3083 + return r;
1.3084 + }
1.3085 + else
1.3086 + r=KErrNone; // Ensure misleading result is not propagated
1.3087 +#endif
1.3088 + infoPtrs.Close();
1.3089 +
1.3090 + // Read the resource information
1.3091 + //
1.3092 + numResources=0;
1.3093 + if((r=secThrdChannel.GetNoOfResources(numResources))!=KErrNone)
1.3094 + return r;
1.3095 +
1.3096 + //
1.3097 + // Need a buffer big enough to contain numResources instances of TResourceInfoBuf
1.3098 + // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects
1.3099 + // and reference via an RSimplePointerArray
1.3100 + RSimplePointerArray<TResourceInfoBuf> resPtrs(numResources);
1.3101 + for(TUint j=0;j<numResources;j++)
1.3102 + {
1.3103 + TResourceInfoBuf *info = new TResourceInfoBuf();
1.3104 + if((r=resPtrs.Insert(info, j))!=KErrNone)
1.3105 + return r;
1.3106 + }
1.3107 +
1.3108 + if((r=secThrdChannel.GetAllResourcesInfo(&resPtrs,numResources))!=KErrNone)
1.3109 + return r;
1.3110 + resPtrs.Close();
1.3111 + }
1.3112 +
1.3113 + // Close the channel
1.3114 + secThrdChannel.Close();
1.3115 + return r;
1.3116 + }
1.3117 +
1.3118 +TInt StartThread2()
1.3119 + {
1.3120 + TInt r=Thrd2.Create(KThrd2Name,Thread2Fn,KStackSize,KHeapSize,KHeapSize,NULL,EOwnerThread);
1.3121 + if (r!=KErrNone)
1.3122 + return r;
1.3123 + Thrd2.Logon(Thrd2Status);
1.3124 + Thrd2.Resume();
1.3125 + return KErrNone;
1.3126 + }
1.3127 +
1.3128 +TInt WaitForThread2()
1.3129 + {
1.3130 + User::WaitForRequest(Thrd2Status);
1.3131 + TInt exitType=Thrd2.ExitType();
1.3132 + TInt exitReason=Thrd2.ExitReason();
1.3133 + TBuf<16> exitCat=Thrd2.ExitCategory();
1.3134 + if((exitType!= EExitKill)||(exitReason!=KErrNone))
1.3135 + {
1.3136 + gTest.Printf(_L("Thread2 error: %d\n"),Thrd2Status.Int());
1.3137 + gTest.Printf(_L("Thread exit reason: %d,%d,%S\n"),exitType,exitReason,&exitCat);
1.3138 + gTest(0);
1.3139 + }
1.3140 + Thrd2.Close();
1.3141 + return KErrNone;
1.3142 + }
1.3143 +
1.3144 +
1.3145 +//----------------------------------------------------------------------------------------------
1.3146 +//! @SYMTestCaseID KBASE-T_RESMANUS-0614
1.3147 +//! @SYMTestType UT
1.3148 +//! @SYMPREQ PREQ1398
1.3149 +//! @SYMTestCaseDesc This test case tests that an additional thread can open a channel and
1.3150 +//! exercise selected APIs.
1.3151 +//!
1.3152 +//! @SYMTestActions 0) Call API to open a channel.
1.3153 +//!
1.3154 +//! 1) Call GetNoOfResources API.
1.3155 +//!
1.3156 +//! 2) Call GetAllResourcesInfo API.
1.3157 +//!
1.3158 +//! 3) Call GetNoOfClients API with default aIncludeKern=EFalse.
1.3159 +//!
1.3160 +//! 4) Call GetNoOfClients API with aIncludeKern=ETrue
1.3161 +//!
1.3162 +//! 5) Call GetNamesAllClientsAPI with default aIncludeKern=EFalse.
1.3163 +//!
1.3164 +//! 6) Call GetNamesAllClientsAPI with aIncludeKern=ETrue
1.3165 +//!
1.3166 +//! 7) Call Initialise API.
1.3167 +//!
1.3168 +//! 8) Call GetResourceState API for selected resource.
1.3169 +//!
1.3170 +//! 9) Call GetResourceState API for selected resource.
1.3171 +//!
1.3172 +//! 10) Call GetNoOfClients API with default aIncludeKern=EFalse.
1.3173 +//!
1.3174 +//! 11) Call GetNoOfClients API with aIncludeKern=ETrue
1.3175 +//!
1.3176 +//! 12) Call GetNamesAllClientsAPI with default aIncludeKern=EFalse.
1.3177 +//!
1.3178 +//! 13) Call GetNamesAllClientsAPI with aIncludeKern=ETrue
1.3179 +//!
1.3180 +//! 14) Call GetNoOfResources API.
1.3181 +//!
1.3182 +//! 15) Call GetAllResourcesInfo API.
1.3183 +//!
1.3184 +//! @SYMTestExpectedResults 0) Test that the channel was opened - exit otherwise.
1.3185 +//!
1.3186 +//! 1) Test that the API call returned KErrNone - exit otherwise.
1.3187 +//!
1.3188 +//! 2) Test that the API call returned KErrNone - exit otherwise.
1.3189 +//!
1.3190 +//! 3) Test that the API call returned KErrNone - exit otherwise.
1.3191 +//!
1.3192 +//! 4) If client exhibits PlatSec capability ReadDeviceData, Test that the API call returned KErrNone - exit otherwise
1.3193 +//! If client lacks PlatSec capability ReadDeviceData, Test that the API call returned KErrPermissionDenied - exit otherwise
1.3194 +//!
1.3195 +//! 5) Test that the API call returned KErrNone - exit otherwise.
1.3196 +//!
1.3197 +//! 6) If client exhibits PlatSec capability ReadDeviceData, Test that the API call returned KErrNone - exit otherwise
1.3198 +//! If client lacks PlatSec capability ReadDeviceData, Test that the API call returned KErrPermissionDenied - exit otherwise
1.3199 +//!
1.3200 +//! 7) Test that the API call returned KErrNone - exit otherwise
1.3201 +//!
1.3202 +//! 8) Test that the associated TRequestStatus object exhibited state KErrNone - exit otherwise
1.3203 +//!
1.3204 +//! 9) Test that the associated TRequestStatus object exhibited state KErrNone - exit otherwise
1.3205 +//!
1.3206 +//! 10) Test that the API call returned KErrNone - exit otherwise.
1.3207 +//!
1.3208 +//! 11) If client exhibits PlatSec capability ReadDeviceData, Test that the API call returned KErrNone - exit otherwise
1.3209 +//! If client lacks PlatSec capability ReadDeviceData, Test that the API call returned KErrPermissionDenied - exit otherwise
1.3210 +//!
1.3211 +//! 12) Test that the API call returned KErrNone - exit otherwise.
1.3212 +//!
1.3213 +//! 13) If client exhibits PlatSec capability ReadDeviceData, Test that the API call returned KErrNone - exit otherwise
1.3214 +//! If client lacks PlatSec capability ReadDeviceData, Test that the API call returned KErrPermissionDenied - exit otherwise
1.3215 +//!
1.3216 +//! 14) Test that the API call returned KErrNone - exit otherwise.
1.3217 +//!
1.3218 +//! 15) Test that the API call returned KErrNone - exit otherwise.
1.3219 +//!
1.3220 +//! @SYMTestPriority High
1.3221 +//! @SYMTestStatus Implemented
1.3222 +//----------------------------------------------------------------------------------------------
1.3223 +LOCAL_C TInt TestAdditionalThread()
1.3224 +//
1.3225 +// Test that more than one thread can be supported
1.3226 +//
1.3227 + {
1.3228 + TInt r;
1.3229 + if((r=StartThread2())!=KErrNone)
1.3230 + {
1.3231 + gTest.Printf(_L("TestAdditionalThread: StartThread2 returned %d\n"),r);
1.3232 + return KErrGeneral;
1.3233 + }
1.3234 + if((r=WaitForThread2())!=KErrNone)
1.3235 + {
1.3236 + gTest.Printf(_L("TestAdditionalThread: WaitForThread2 returned %d\n"),r);
1.3237 + return KErrGeneral;
1.3238 + }
1.3239 +
1.3240 + return r;
1.3241 + }
1.3242 +
1.3243 +
1.3244 +LOCAL_C TInt LocateResourceWithDependencies(TUint &aNumResources, TUint &aResId, TUint &aNumDependents)
1.3245 +//
1.3246 +// Support function for tests of dependencies
1.3247 +//
1.3248 + {
1.3249 + __KHEAP_MARK;
1.3250 +
1.3251 + TInt r = KErrNone;
1.3252 + if((r=gChannel.GetNoOfResources(aNumResources))!=KErrNone)
1.3253 + {
1.3254 + gTest.Printf(_L("GetNoOfResources for test channel returned %d\n"),r);
1.3255 + return r;
1.3256 + }
1.3257 + TUint bufSize = aNumResources;
1.3258 + RSimplePointerArray<TResourceInfoBuf> infoPtrs(bufSize);
1.3259 + for(TUint i=0;i<bufSize;i++)
1.3260 + {
1.3261 + TResourceInfoBuf *info = new TResourceInfoBuf();
1.3262 + if((r=infoPtrs.Insert(info, i))!=KErrNone)
1.3263 + {
1.3264 + gTest.Printf(_L("GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),i,r);
1.3265 + }
1.3266 + }
1.3267 + TUint updateNumResources=aNumResources;
1.3268 + if((r=gChannel.GetAllResourcesInfo(&infoPtrs,updateNumResources))!=KErrNone)
1.3269 + {
1.3270 + gTest.Printf(_L("GetAllResourcesInfo for channel returned %d\n"),r);
1.3271 + return r;
1.3272 + }
1.3273 + for(TUint resNo=0;resNo<aNumResources;resNo++)
1.3274 + {
1.3275 + TResourceInfoBuf *info = infoPtrs[resNo];
1.3276 + TUint resId = ((*info)()).iId;
1.3277 + TUint numDependents = 0;
1.3278 + r=gChannel.GetNumDependentsForResource(resId,&numDependents, EFalse); // EFalse - don't load the dependency info
1.3279 + if((r!=KErrNone)&&(r!=KErrNotFound)&&(r!=KErrNotSupported))
1.3280 + {
1.3281 + gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource returned %d\n"),r);
1.3282 + return r;
1.3283 + }
1.3284 + if(numDependents>0)
1.3285 + {
1.3286 + aResId = resId;
1.3287 + aNumDependents = numDependents;
1.3288 + break;
1.3289 + }
1.3290 + }
1.3291 +
1.3292 + infoPtrs.Close();
1.3293 +
1.3294 + __KHEAP_MARKEND;
1.3295 +
1.3296 + return r;
1.3297 + }
1.3298 +
1.3299 +
1.3300 +
1.3301 +//----------------------------------------------------------------------------------------------
1.3302 +//! @SYMTestCaseID KBASE-T_RESMANUS-0615
1.3303 +//! @SYMTestType UT
1.3304 +//! @SYMPREQ PREQ1398
1.3305 +//! @SYMTestCaseDesc This test case tests the different options available for handling transient data.
1.3306 +//! @SYMTestActions 0) Locate a resource that has at least one dependency.
1.3307 +//!
1.3308 +//! 1) Read the number of dependencies without reading the dependency information.
1.3309 +//! Call to read the dependency information (without re-loading).
1.3310 +//!
1.3311 +//! 2) Read the number of dependencies (with default option of reading the dependency information).
1.3312 +//! Then read the dependency information (without re-loading).
1.3313 +//!
1.3314 +//! 3) Repeat the read the number of dependencies without reading the dependency information
1.3315 +//! Then read the dependency information (without re-loading).
1.3316 +//! Then read the dependency information (with re-loading).
1.3317 +//!
1.3318 +//! 4) Attempt to read the dependency information (without re-loading) with a buffer of insufficient size
1.3319 +//!
1.3320 +//! 5) Read the number of (all) resources without reading the resource information.
1.3321 +//! Call to read (all) the resource information (without re-loading).
1.3322 +//!
1.3323 +//! 6) Read the number of (all) resources (with default option of reading the resource information).
1.3324 +//! Then read (all) the resource information (without re-loading).
1.3325 +//!
1.3326 +//! 7) Repeat the read the number of (all) resources without reading the resources information
1.3327 +//! Then read (all) the resources information (without re-loading).
1.3328 +//! Then read (all) the resources information (with re-loading).
1.3329 +//!
1.3330 +//! 8) Attempt to read (all) the resource information (without re-loading) with a buffer of insufficient size
1.3331 +//!
1.3332 +//! 9) Read the number of user-side clients using a resource without reading the resource information.
1.3333 +//! Call to read the information for user-side clients using a resource (without re-loading).
1.3334 +//!
1.3335 +//! 10) Read the number of user-side clients (with loading of the client information)
1.3336 +//! Call to read the client information (without re-loading) should return be successful
1.3337 +//! Call to read the information for a resourceID with zero clients (without re-loading)
1.3338 +//! Call to read the information for the first resourceID
1.3339 +//!
1.3340 +//! 11) Repeat the read of the number of user-side clients (without re-loading)
1.3341 +//! Call to read the client information (without re-loading)
1.3342 +//! Call to read the client information (with re-loading)
1.3343 +//!
1.3344 +//! 12) Open a second channel on the User-Side API, and call initialise support for resource state access
1.3345 +//! Get the current state of a specific resource, then change the state
1.3346 +//! Call to read the number of user-side clients for the resource (with loading of the client information)
1.3347 +//! but with a buffer of insufficient size.
1.3348 +//!
1.3349 +//! 13) Read the number of resources in use by a specified client (without loading)
1.3350 +//! Call to read the information on the resources in use by the client (without loading)
1.3351 +//!
1.3352 +//! 14) Open a third channel on the User-Side API, do not call initialise.
1.3353 +//! Read the number of resources in use by a specified client (with loading)
1.3354 +//! Call to read the information for resources in use by the third channel (without re-loading)
1.3355 +//! Call to read the information for resources in use by the second channel (without re-loading)
1.3356 +//!
1.3357 +//! 15) Read the number of resources in use by a specified client (without loading)
1.3358 +//! Call to read the information on the resources in use by the client (without loading)
1.3359 +//! Call to read the information on the resources in use by the client (with loading)
1.3360 +//!
1.3361 +//! 16) Read the number of resources in use by a specified client (with loading)
1.3362 +//! Call to read the information on the resources in use by the client (without loading)
1.3363 +//! with a buffer of insufficient size.
1.3364 +//!
1.3365 +//! @SYMTestExpectedResults 0) If a suitable resource is found, the number of dependencies is reported - exit otherwise.
1.3366 +//!
1.3367 +//! 1) Test that the read of the number of dependencies returns KErrNone - exit otherwise.
1.3368 +//! Test that the read of the dependency information returned KErrNotReady - exit otherwise.
1.3369 +//!
1.3370 +//! 2) Test that the read of the number of dependencies returns KErrNone - exit otherwise.
1.3371 +//! Test that the read of the dependency information returned KErrNone - exit otherwise.
1.3372 +//!
1.3373 +//! 3) Test that the read of the number of dependencies returns KErrNone - exit otherwise.
1.3374 +//! Test that the read of the dependency information (without re-loading) returned KErrNotReady - exit otherwise.
1.3375 +//! Test that the read of the dependency information (with re-loading) returned KErrNone - exit otherwise.
1.3376 +//!
1.3377 +//! 4) Test that the read of the dependency information returns KErrArgument - exit otherwise
1.3378 +//!
1.3379 +//! 5) Test that the read of the number of resources returns KErrNone - exit otherwise.
1.3380 +//! Test that the read of the resource information returned KErrNotReady - exit otherwise.
1.3381 +//!
1.3382 +//! 6) Test that the read of the number of resources returns KErrNone - exit otherwise.
1.3383 +//! Test that the read of the resource information returned KErrNone - exit otherwise.
1.3384 +//!
1.3385 +//! 7) Test that the read of the number of resources returns KErrNone - exit otherwise.
1.3386 +//! Test that the read of the resource information (without re-loading) returned KErrNotReady - exit otherwise.
1.3387 +//! Test that the read of the resources information (with re-loading) returned KErrNone - exit otherwise.
1.3388 +//!
1.3389 +//! 8) Test that the read of the resource information returns KErrArgument - exit otherwise
1.3390 +//!
1.3391 +//! 9) Test that the read of the number of clients returns KErrNone - exit otherwise.
1.3392 +//! Test that the read of the client information returned KErrNotReady - exit otherwise.
1.3393 +//!
1.3394 +//! 10) Test that the read of the number of clients returns KErrNone - exit otherwise.
1.3395 +//! Test that the read of the client information returned KErrNone - exit otherwise.
1.3396 +//! Test that the read of the client information returned KErrNone and numClients==0 - exit otherwise.
1.3397 +//! Test that the read of the client information returned KErrNotReady - exit otherwise.
1.3398 +//!
1.3399 +//! 11) Test that the read of the number of clients returns KErrNone - exit otherwise.
1.3400 +//! Test that the read of the client information returned KErrNotReady - exit otherwise.
1.3401 +//! Test that the read of the client information returned KErrNone - exit otherwise.
1.3402 +//!
1.3403 +//! 12) Test that the opening and initialisation of the channel was successful - exit otherwise.
1.3404 +//! Test that the get and change of the resource state completed successfully - exit otherwise
1.3405 +//! Test that the read of the client information returned KErrArgument - exit otherwise.
1.3406 +//!
1.3407 +//! 13) Test that the read of the number of resources returns KErrNone - exit otherwise.
1.3408 +//! Test that the read of the resource information returned KErrNotReady - exit otherwise.
1.3409 +//!
1.3410 +//! 14) Test that the opening of the channel was successful - exit otherwise.
1.3411 +//! Test that the read of the resource information returned KErrNone - exit otherwise.
1.3412 +//! Test that the read of the client information returned KErrNone, and numResources = 0 - exit otherwise.
1.3413 +//! Test that the read of the client information returned KErrNotReady - exit otherwise.
1.3414 +//!
1.3415 +//! 15) Test that the read of the number of resources returns KErrNone - exit otherwise.
1.3416 +//! Test that the read of the resource information returned KErrNotReady - exit otherwise.
1.3417 +//! Test that the read of the resource information returned KErrNone - exit otherwise.
1.3418 +//!
1.3419 +//! 16) Test that the read of the number of resources returns KErrNone - exit otherwise.
1.3420 +//! Test that the read of the resource information returned KErrArgument - exit otherwise..
1.3421 +//!
1.3422 +//! @SYMTestPriority High
1.3423 +//! @SYMTestStatus Implemented
1.3424 +//----------------------------------------------------------------------------------------------
1.3425 +LOCAL_C TInt TestTransientHandling()
1.3426 +//
1.3427 +// Test APIs with options for handling transient data (dependencies, resources and clients)
1.3428 +//
1.3429 + {
1.3430 + TInt r = KErrNone;
1.3431 + TUint testNo = 1;
1.3432 +
1.3433 + TUint numDependents = 0;
1.3434 + TUint resNo = 0;
1.3435 +
1.3436 + //
1.3437 + // Dependency data tests
1.3438 + //
1.3439 +
1.3440 + gTest.Printf(_L("TestTransientHandling: dependency data tests ...\n"));
1.3441 +
1.3442 + // 0) Find a resource that has dependents - if none is located skip the remaining dependancy tests
1.3443 + // (this reads the number of dependencies, without loading the dependency data)
1.3444 + //
1.3445 + TUint numResources=0;
1.3446 + if((r=LocateResourceWithDependencies(numResources, resNo, numDependents))!=KErrNone)
1.3447 + {
1.3448 + gTest.Printf(_L("TestTransientHandling: no resource with dependencies found ... skipping tests\n"));
1.3449 + return KErrNone;
1.3450 + }
1.3451 + if(numDependents==0)
1.3452 + {
1.3453 + gTest.Printf(_L("TestTransientHandling: no resource with dependencies found ... skipping tests\n"));
1.3454 + }
1.3455 + else
1.3456 + {
1.3457 + // 1) Read the number of dependencies without reading the dependency information
1.3458 + // Subsequent call to read the dependency information (without re-loading) should return error KErrNotReady
1.3459 + gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
1.3460 + if((r=gChannel.GetNumDependentsForResource(resNo,&numDependents, EFalse))!=KErrNone)
1.3461 + {
1.3462 + gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource returned %d\n"),r);
1.3463 + return r;
1.3464 + }
1.3465 + gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource reported %d dependents for resource %d\n"),numDependents,resNo);
1.3466 + if(numDependents > 0)
1.3467 + {
1.3468 + RBuf8 buffer;
1.3469 + if((buffer.Create(numDependents*sizeof(SResourceDependencyInfo)))!=KErrNone)
1.3470 + return KErrGeneral;
1.3471 + buffer.SetLength(0);
1.3472 + if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents))!=KErrNotReady)
1.3473 + {
1.3474 + gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r);
1.3475 + return KErrGeneral;
1.3476 + }
1.3477 + buffer.Close();
1.3478 + }
1.3479 +
1.3480 + // 2) Read the number of dependencies (and, by default, read the dependency information)
1.3481 + // Subsequent call to read the dependency information (without re-loading) should return be successful
1.3482 + gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
1.3483 + if((r=gChannel.GetNumDependentsForResource(resNo,&numDependents))!=KErrNone)
1.3484 + {
1.3485 + gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource returned %d\n"),r);
1.3486 + return r;
1.3487 + }
1.3488 + gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource reported %d dependents for resource %d\n"),numDependents,resNo);
1.3489 + if(numDependents > 0)
1.3490 + {
1.3491 + RBuf8 buffer;
1.3492 + if((buffer.Create(numDependents*sizeof(SResourceDependencyInfo)))!=KErrNone)
1.3493 + return KErrGeneral;
1.3494 + buffer.SetLength(0);
1.3495 + if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents))!=KErrNone)
1.3496 + {
1.3497 + gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r);
1.3498 + return r;
1.3499 + }
1.3500 + SResourceDependencyInfo* tempPtr = (SResourceDependencyInfo*)(buffer.Ptr());
1.3501 + gTest.Printf(_L("TestTransientHandling: numDependents = %d\n"),numDependents);
1.3502 + for(TUint i=0; i<numDependents; i++,tempPtr++)
1.3503 + {
1.3504 + gTest.Printf(_L("TestTransientHandling: info.iResourceId = %d\n"),tempPtr->iResourceId);
1.3505 + gTest.Printf(_L("TestTransientHandling: info.iDependencyPriority= %d\n"),tempPtr->iDependencyPriority);
1.3506 + }
1.3507 + buffer.Close();
1.3508 + }
1.3509 +
1.3510 + // 3) Repeat the read the number of dependencies without reading the dependency information
1.3511 + // Subsequent call to read the dependency information (without re-loading) should return error KErrNotReady
1.3512 + // Then call to read the dependency information (with re-loading) should be successful
1.3513 + gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
1.3514 + if((r=gChannel.GetNumDependentsForResource(resNo,&numDependents, EFalse))!=KErrNone)
1.3515 + {
1.3516 + gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource returned %d\n"),r);
1.3517 + return r;
1.3518 + }
1.3519 + gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource reported %d dependents for resource %d\n"),numDependents,resNo);
1.3520 + if(numDependents > 0)
1.3521 + {
1.3522 + RBuf8 buffer;
1.3523 + if((buffer.Create(numDependents*sizeof(SResourceDependencyInfo)))!=KErrNone)
1.3524 + return KErrGeneral;
1.3525 + buffer.SetLength(0);
1.3526 +
1.3527 + if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents))!=KErrNotReady)
1.3528 + {
1.3529 + gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r);
1.3530 + return KErrGeneral;
1.3531 + }
1.3532 + if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents, ETrue))!=KErrNone)
1.3533 + {
1.3534 + gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r);
1.3535 + return KErrGeneral;
1.3536 + }
1.3537 + SResourceDependencyInfo* tempPtr = (SResourceDependencyInfo*)(buffer.Ptr());
1.3538 + for(TUint i=0; i<numDependents; i++,tempPtr++)
1.3539 + {
1.3540 + gTest.Printf(_L("TestTransientHandling: info.iResourceId = %d"),tempPtr->iResourceId);
1.3541 + gTest.Printf(_L("TestTransientHandling: info.iDependencyPriority= %d"),tempPtr->iDependencyPriority);
1.3542 + }
1.3543 + buffer.Close();
1.3544 + }
1.3545 +
1.3546 + // 4) Attempt to read the dependency information (without re-loading) with a buffer of insufficient size should
1.3547 + // return error KErrArgument
1.3548 + gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
1.3549 + if(numDependents > 0)
1.3550 + {
1.3551 + RBuf8 buffer;
1.3552 + if((buffer.Create((numDependents-1)*sizeof(SResourceDependencyInfo)))!=KErrNone)
1.3553 + return KErrGeneral;
1.3554 + buffer.SetLength(0);
1.3555 + if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents))!=KErrArgument)
1.3556 + {
1.3557 + gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r);
1.3558 + return KErrGeneral;
1.3559 + }
1.3560 + // Ensure misleading result is not returned
1.3561 + r=KErrNone;
1.3562 + buffer.Close();
1.3563 + }
1.3564 + }
1.3565 +
1.3566 +
1.3567 + //
1.3568 + // All resource data tests
1.3569 + //
1.3570 +
1.3571 + gTest.Printf(_L("TestTransientHandling: All resource data tests ...\n"));
1.3572 + testNo=1;
1.3573 +
1.3574 + // 5) Attempt to read the resource information without having previously loaded it.
1.3575 + gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
1.3576 + {
1.3577 + TUint numResources = 0;
1.3578 + r = gChannel.GetNoOfResources(numResources, EFalse); // EFalse - don't load the resource info
1.3579 + if(r!=KErrNone)
1.3580 + {
1.3581 + gTest.Printf(_L("GetNoOfResources returned %d\n"),r);
1.3582 + return r;
1.3583 + }
1.3584 + // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects
1.3585 + // and reference via an RSimplePointerArray
1.3586 + RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources);
1.3587 + for(TUint i=0;i<numResources;i++)
1.3588 + {
1.3589 + TResourceInfoBuf *info = new TResourceInfoBuf();
1.3590 + if((r=infoPtrs.Insert(info, i))!=KErrNone)
1.3591 + {
1.3592 + gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
1.3593 + }
1.3594 + }
1.3595 + if((r=gChannel.GetAllResourcesInfo(&infoPtrs, numResources))!=KErrNotReady)
1.3596 + {
1.3597 + gTest.Printf(_L("TestTransientHandling: GetAllResourcesInfo returned %d\n"),r);
1.3598 + return KErrGeneral;
1.3599 + }
1.3600 + else
1.3601 + r=KErrNone; // Ensure misleading result is not propagated
1.3602 + infoPtrs.Close();
1.3603 + }
1.3604 +
1.3605 + // 6) Read the number of resources (and, by default, read the resource information)
1.3606 + // Subsequent call to read the resource information (without re-loading) should return be successful
1.3607 + gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
1.3608 + {
1.3609 + TUint numResources = 0;
1.3610 + if((r=gChannel.GetNoOfResources(numResources))!=KErrNone)
1.3611 + {
1.3612 + gTest.Printf(_L("GetNoOfResources returned %d\n"),r);
1.3613 + return r;
1.3614 + }
1.3615 + // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects
1.3616 + // and reference via an RSimplePointerArray
1.3617 + RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources);
1.3618 + for(TUint i=0;i<numResources;i++)
1.3619 + {
1.3620 + TResourceInfoBuf *info = new TResourceInfoBuf();
1.3621 + if((r=infoPtrs.Insert(info, i))!=KErrNone)
1.3622 + {
1.3623 + gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
1.3624 + }
1.3625 + }
1.3626 + if((r=gChannel.GetAllResourcesInfo(&infoPtrs, numResources))!=KErrNone)
1.3627 + {
1.3628 + gTest.Printf(_L("TestTransientHandling: GetAllResourcesInfo returned %d\n"),r);
1.3629 + return r;
1.3630 + }
1.3631 + infoPtrs.Close();
1.3632 + }
1.3633 +
1.3634 + // 7) Repeat the read the number of resources without reading the resource information
1.3635 + // Subsequent call to read the resource information (without re-loading) should return error KErrNotReady
1.3636 + // Then call to read the resource information (with re-loading) should be successful
1.3637 + gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
1.3638 + {
1.3639 + TUint numResources = 0;
1.3640 + if((r=gChannel.GetNoOfResources(numResources, EFalse))!=KErrNone) // EFalse - don't load the resource info
1.3641 + {
1.3642 + gTest.Printf(_L("GetNoOfResources returned %d\n"),r);
1.3643 + return r;
1.3644 + }
1.3645 + // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects
1.3646 + // and reference via an RSimplePointerArray
1.3647 + RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources);
1.3648 + for(TUint i=0;i<numResources;i++)
1.3649 + {
1.3650 + TResourceInfoBuf *info = new TResourceInfoBuf();
1.3651 + if((r=infoPtrs.Insert(info, i))!=KErrNone)
1.3652 + {
1.3653 + gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
1.3654 + }
1.3655 + }
1.3656 + if((r=gChannel.GetAllResourcesInfo(&infoPtrs, numResources))!=KErrNotReady)
1.3657 + {
1.3658 + gTest.Printf(_L("TestTransientHandling: GetAllResourcesInfo returned %d\n"),r);
1.3659 + return KErrGeneral;
1.3660 + }
1.3661 + if((r=gChannel.GetAllResourcesInfo(&infoPtrs, numResources,ETrue))!=KErrNone)
1.3662 + {
1.3663 + gTest.Printf(_L("TestTransientHandling: GetAllResourcesInfo returned %d\n"),r);
1.3664 + return r;
1.3665 + }
1.3666 + else
1.3667 + infoPtrs.Close();
1.3668 + }
1.3669 +
1.3670 +
1.3671 + // 8) Attempt to read the resource information (without re-loading) with a buffer of insufficient size should
1.3672 + // return error KErrArgument
1.3673 + gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
1.3674 + {
1.3675 + TUint numResources = 0;
1.3676 + if((r=gChannel.GetNoOfResources(numResources, EFalse))!=KErrNone) // EFalse - don't load the resource info
1.3677 + {
1.3678 + gTest.Printf(_L("GetNoOfResources returned %d\n"),r);
1.3679 + return r;
1.3680 + }
1.3681 + // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects
1.3682 + // and reference via an RSimplePointerArray
1.3683 + RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources - 1);
1.3684 + for(TUint i=0;i<(numResources-1);i++)
1.3685 + {
1.3686 + TResourceInfoBuf *info = new TResourceInfoBuf();
1.3687 + if((r=infoPtrs.Insert(info, i))!=KErrNone)
1.3688 + {
1.3689 + gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
1.3690 + }
1.3691 + }
1.3692 + if((r=gChannel.GetAllResourcesInfo(&infoPtrs, numResources))!=KErrArgument)
1.3693 + {
1.3694 + gTest.Printf(_L("TestTransientHandling: GetAllResourcesInfo returned %d\n"),r);
1.3695 + return KErrGeneral;
1.3696 + }
1.3697 + // Ensure misleading result is not returned
1.3698 + r=KErrNone;
1.3699 + infoPtrs.Close();
1.3700 + }
1.3701 +
1.3702 + //
1.3703 + // Specific resource data tests
1.3704 + //
1.3705 +
1.3706 + gTest.Printf(_L("TestTransientHandling: Resource-specific data tests ...\n"));
1.3707 + testNo=1;
1.3708 +
1.3709 + // 9) Attempt to read the resource information without having previously loaded it.
1.3710 + gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
1.3711 + {
1.3712 + TUint numClients = 0;
1.3713 + if((r=gChannel.GetNumClientsUsingResource(gLongLatencyResource, numClients, EFalse, EFalse))!=KErrNone) // user-side clients, don't load the info
1.3714 + {
1.3715 + gTest.Printf(_L("GetNumClientsUsingResource returned %d\n"),r);
1.3716 + return r;
1.3717 + }
1.3718 + // To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects
1.3719 + // and reference via an RSimplePointerArray
1.3720 + RSimplePointerArray<TClientInfoBuf> infoPtrs(numClients);
1.3721 + for(TUint i=0;i<numClients;i++)
1.3722 + {
1.3723 + TClientInfoBuf *info = new TClientInfoBuf();
1.3724 + if((r=infoPtrs.Insert(info, i))!=KErrNone)
1.3725 + {
1.3726 + gTest.Printf(_L("TestTransientHandling test, GetInfoOnClientsUsingResource infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
1.3727 + }
1.3728 + }
1.3729 + if((r=gChannel.GetInfoOnClientsUsingResource(gLongLatencyResource, numClients, &infoPtrs, EFalse))!=KErrNotReady)
1.3730 + {
1.3731 + gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource returned %d\n"),r);
1.3732 + return KErrGeneral;
1.3733 + }
1.3734 + else
1.3735 + r=KErrNone; // Ensure misleading result is not propagated
1.3736 + infoPtrs.Close();
1.3737 + }
1.3738 +
1.3739 + // 10) Read the number of clients (and, by default, read the client information)
1.3740 + // Subsequent call to read the client information (without re-loading) should return be successful
1.3741 + // Call to read the information for a resourceID with zero clients (without re-loading) should return KErrNone, numClients==0
1.3742 + // Call to read the information for a resourceID with one or more clients (without re-loading) should return KErrNotReady
1.3743 + gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
1.3744 + {
1.3745 + TUint numClients = 0;
1.3746 + if((r=gChannel.GetNumClientsUsingResource(gLongLatencyResource, numClients, EFalse))!=KErrNone) // user-side clients, load the info
1.3747 + {
1.3748 + gTest.Printf(_L("GetNumClientsUsingResource returned %d\n"),r);
1.3749 + return r;
1.3750 + }
1.3751 + // To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects
1.3752 + // and reference via an RSimplePointerArray
1.3753 + RSimplePointerArray<TClientInfoBuf> infoPtrs(numClients);
1.3754 + for(TUint i=0;i<numClients;i++)
1.3755 + {
1.3756 + TClientInfoBuf *info = new TClientInfoBuf();
1.3757 + if((r=infoPtrs.Insert(info, i))!=KErrNone)
1.3758 + {
1.3759 + gTest.Printf(_L("TestTransientHandling test, GetInfoOnClientsUsingResource infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
1.3760 + }
1.3761 + }
1.3762 + if((r=gChannel.GetInfoOnClientsUsingResource(gLongLatencyResource, numClients, &infoPtrs, EFalse))!=KErrNone)
1.3763 + {
1.3764 + gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for gLongLatencyResource returned %d\n"),r);
1.3765 + return r;
1.3766 + }
1.3767 + if(((r=gChannel.GetInfoOnClientsUsingResource((gLongLatencyResource+1), numClients, &infoPtrs, EFalse))!=KErrNone) || (numClients!=0))
1.3768 + {
1.3769 + gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for (gLongLatencyResource+1) returned %d\n"),r);
1.3770 + if(numClients!=0)
1.3771 + gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for (gLongLatencyResource+1), %d clients\n"),numClients);
1.3772 + return KErrGeneral;
1.3773 + }
1.3774 + if((r=gChannel.GetInfoOnClientsUsingResource(gSharedResource, numClients, &infoPtrs, EFalse))!=KErrNotReady)
1.3775 + {
1.3776 + gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource (for gSharedResource) returned %d\n"),r);
1.3777 + return r;
1.3778 + }
1.3779 + infoPtrs.Close();
1.3780 + }
1.3781 +
1.3782 +
1.3783 + // 11) Repeat the read the number of clients without reading the client information
1.3784 + // Subsequent call to read the client information (without re-loading) should return error KErrNotReady
1.3785 + // Then call to read the client information (with re-loading) should be successful
1.3786 + gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
1.3787 + {
1.3788 + TUint numClients = 0;
1.3789 + if((r=gChannel.GetNumClientsUsingResource(gLongLatencyResource, numClients, EFalse, EFalse))!=KErrNone) // user-side clients, don't load the info
1.3790 + {
1.3791 + gTest.Printf(_L("GetNumClientsUsingResource returned %d\n"),r);
1.3792 + return r;
1.3793 + }
1.3794 + // To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects
1.3795 + // and reference via an RSimplePointerArray
1.3796 + RSimplePointerArray<TClientInfoBuf> infoPtrs(numClients);
1.3797 + for(TUint i=0;i<numClients;i++)
1.3798 + {
1.3799 + TClientInfoBuf *info = new TClientInfoBuf();
1.3800 + if((r=infoPtrs.Insert(info, i))!=KErrNone)
1.3801 + {
1.3802 + gTest.Printf(_L("TestTransientHandling test, GetInfoOnClientsUsingResource infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
1.3803 + }
1.3804 + }
1.3805 + if((r=gChannel.GetInfoOnClientsUsingResource(gLongLatencyResource, numClients, &infoPtrs, EFalse))!=KErrNotReady)
1.3806 + {
1.3807 + gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for gLongLatencyResource returned %d\n"),r);
1.3808 + return KErrGeneral;
1.3809 + }
1.3810 + if((r=gChannel.GetInfoOnClientsUsingResource(gLongLatencyResource, numClients, &infoPtrs, EFalse, ETrue))!=KErrNone)
1.3811 + {
1.3812 + gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for gLongLatencyResource returned %d\n"),r);
1.3813 + return r;
1.3814 + }
1.3815 +
1.3816 + infoPtrs.Close();
1.3817 + }
1.3818 +
1.3819 + // 12) To support the following test (and specific resource data tests, below) need a second channel to be using the resource
1.3820 + _LIT(tempStr1,"ExtraChan1");
1.3821 + TBufC<16> tempName1(tempStr1);
1.3822 + RBusDevResManUs channelTwo;
1.3823 + if((r=OpenChannel(tempName1, channelTwo))!=KErrNone)
1.3824 + {
1.3825 + gTest.Printf(_L("Failed to open channelTwo, %d\n"),r);
1.3826 + channelTwo.Close();
1.3827 + return r;
1.3828 + }
1.3829 + if ((r=channelTwo.Initialise(1,1,1))!=KErrNone)
1.3830 + {
1.3831 + gTest.Printf(_L("Failed to Initialise channelTwo, %d\n"),r);
1.3832 + channelTwo.Close();
1.3833 + return r;
1.3834 + }
1.3835 + // Attempt to change the resource level
1.3836 + // Get initial state
1.3837 + TRequestStatus status;
1.3838 + TBool cached = gUseCached;
1.3839 + TInt readValue;
1.3840 + TInt levelOwnerId = 0;
1.3841 + channelTwo.GetResourceState(status,gSharedResource,cached,&readValue,&levelOwnerId);
1.3842 + User::WaitForRequest(status);
1.3843 + r=status.Int();
1.3844 + if(r != KErrNone)
1.3845 + {
1.3846 + gTest.Printf(_L("GetResourceState for gSharedResource completed with = 0x%x\n"),r);
1.3847 + return r;
1.3848 + }
1.3849 + // Write updated state
1.3850 + TUint newLevel = (TUint)(readValue + gSharedResStateDelta);
1.3851 + channelTwo.ChangeResourceState(status,gSharedResource,newLevel);
1.3852 + User::WaitForRequest(status);
1.3853 + r=status.Int();
1.3854 + if(r != KErrNone)
1.3855 + {
1.3856 + gTest.Printf(_L("ChangeResourceState forgSharedResource completed with %d\n"),r);
1.3857 + return r;
1.3858 + }
1.3859 +
1.3860 + // Attempt to read the client information (without re-loading) with a buffer of insufficient size should
1.3861 + // return error KErrArgument
1.3862 + gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
1.3863 + {
1.3864 + TUint numClients = 0;
1.3865 + if((r=gChannel.GetNumClientsUsingResource(gSharedResource, numClients, EFalse))!=KErrNone) // user-side clients, load the info
1.3866 + {
1.3867 + gTest.Printf(_L("GetNumClientsUsingResource returned %d\n"),r);
1.3868 + channelTwo.Close();
1.3869 + return r;
1.3870 + }
1.3871 + // To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects
1.3872 + // and reference via an RSimplePointerArray
1.3873 + RSimplePointerArray<TClientInfoBuf> infoPtrs(numClients-1);
1.3874 + for(TUint i=0;i<(numClients-1);i++)
1.3875 + {
1.3876 + TClientInfoBuf *info = new TClientInfoBuf();
1.3877 + if((r=infoPtrs.Insert(info, i))!=KErrNone)
1.3878 + {
1.3879 + gTest.Printf(_L("TestTransientHandling test, GetInfoOnClientsUsingResource infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
1.3880 + channelTwo.Close();
1.3881 + }
1.3882 + }
1.3883 + if((r=gChannel.GetInfoOnClientsUsingResource(gSharedResource, numClients, &infoPtrs, EFalse))!=KErrArgument)
1.3884 + {
1.3885 + gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for gLongLatencyResource returned %d\n"),r);
1.3886 + channelTwo.Close();
1.3887 + return KErrGeneral;
1.3888 + }
1.3889 + // Ensure misleading result is not returned
1.3890 + r=KErrNone;
1.3891 + infoPtrs.Close();
1.3892 + }
1.3893 +
1.3894 +
1.3895 + //
1.3896 + // Specific resource data tests
1.3897 + //
1.3898 +
1.3899 + gTest.Printf(_L("TestTransientHandling: Client-specific data tests ...\n"));
1.3900 + testNo=1;
1.3901 +
1.3902 + // These tests require a client name
1.3903 + TBuf8<MAX_RESOURCE_NAME_LENGTH+1>name8Bit;
1.3904 + name8Bit.Copy(gTestName);
1.3905 + TClientName* clientName = (TClientName*)&name8Bit;
1.3906 +#if _DEBUG
1.3907 + TBuf <MAX_CLIENT_NAME_LENGTH> clientName16Bit;
1.3908 + clientName16Bit.Copy(*clientName);
1.3909 + clientName16Bit.SetLength(clientName->Length());
1.3910 + gTest.Printf(_L("Invoking TestTransientHandling client-specific data tests with %S \n"),&clientName16Bit);
1.3911 +#endif
1.3912 + // 13) Attempt to read the resource information without having previously loaded it.
1.3913 + gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
1.3914 + {
1.3915 + TUint numResources = 0;
1.3916 + if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResources, EFalse))!=KErrNone) // EFalse - don't load data
1.3917 + {
1.3918 + gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r);
1.3919 + return r;
1.3920 + }
1.3921 + // To support the GetInfoOnResourcesInUseByClient testing, instantiate TResourceInfoBuf objects
1.3922 + // and reference via an RSimplePointerArray
1.3923 + RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources);
1.3924 + for(TUint i=0;i<numResources;i++)
1.3925 + {
1.3926 + TResourceInfoBuf *info = new TResourceInfoBuf();
1.3927 + if((r=infoPtrs.Insert(info, i))!=KErrNone)
1.3928 + {
1.3929 + gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
1.3930 + }
1.3931 + }
1.3932 + if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, numResources, &infoPtrs))!=KErrNotReady)
1.3933 + {
1.3934 + gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource returned %d\n"),r);
1.3935 + return KErrGeneral;
1.3936 + }
1.3937 + else
1.3938 + r=KErrNone; // Ensure misleading result is not propagated
1.3939 + infoPtrs.Close();
1.3940 + }
1.3941 +
1.3942 + // 14) To support the following test need a third channel
1.3943 + _LIT(tempStr2,"ExtraChan2");
1.3944 + TBufC<16> tempName2(tempStr2);
1.3945 + RBusDevResManUs channelThree;
1.3946 + if((r=OpenChannel(tempName2, channelThree))!=KErrNone)
1.3947 + {
1.3948 + gTest.Printf(_L("Failed to open channelThree, %d\n"),r);
1.3949 + channelTwo.Close();
1.3950 + return r;
1.3951 + }
1.3952 + // Read the number of resources (and, by default, read the resource information)
1.3953 + // Subsequent call to read the resource information (without re-loading) should return be successful
1.3954 + // Call to read the information for a client name with zero resource requirements (without re-loading) should return KErrNone, numResources==0
1.3955 + // Call to read the information for a client name with one or more resource requirements (without re-loading) should return KErrNotReady
1.3956 + gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
1.3957 + {
1.3958 + TUint numResources = 0;
1.3959 + if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResources))!=KErrNone) // load data
1.3960 + {
1.3961 + gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r);
1.3962 + return r;
1.3963 + }
1.3964 + // To support the GetInfoOnResourcesInUseByClient testing, instantiate TResourceInfoBuf objects
1.3965 + // and reference via an RSimplePointerArray
1.3966 + RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources);
1.3967 + for(TUint i=0;i<numResources;i++)
1.3968 + {
1.3969 + TResourceInfoBuf *info = new TResourceInfoBuf();
1.3970 + if((r=infoPtrs.Insert(info, i))!=KErrNone)
1.3971 + {
1.3972 + gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
1.3973 + }
1.3974 + }
1.3975 + if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, numResources, &infoPtrs))!=KErrNone)
1.3976 + {
1.3977 + gTest.Printf(_L("TestTransientHandling: gChannel GetInfoOnClientsUsingResource returned %d\n"),r);
1.3978 + return KErrGeneral;
1.3979 + }
1.3980 + TUint dumResources=0;
1.3981 + TBuf8<MAX_RESOURCE_NAME_LENGTH+1>name8Bit2;
1.3982 + name8Bit2.Copy(tempName2);
1.3983 + TClientName* clientName2 = (TClientName*)&name8Bit2;
1.3984 + if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName2, dumResources, &infoPtrs))!=KErrNone)
1.3985 + {
1.3986 + gTest.Printf(_L("TestTransientHandling: tempName2 GetInfoOnClientsUsingResource returned %d\n"),r);
1.3987 + return KErrGeneral;
1.3988 + }
1.3989 + if(dumResources!=0)
1.3990 + {
1.3991 + gTest.Printf(_L("TestTransientHandling: tempName2 GetInfoOnClientsUsingResource dumResources=%d\n"),dumResources);
1.3992 + return KErrGeneral;
1.3993 + }
1.3994 + TBuf8<MAX_RESOURCE_NAME_LENGTH+1>name8Bit1;
1.3995 + name8Bit1.Copy(tempName1);
1.3996 + TClientName* clientName1 = (TClientName*)&name8Bit1;
1.3997 + if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName1, numResources, &infoPtrs))!=KErrNotReady)
1.3998 + {
1.3999 + gTest.Printf(_L("TestTransientHandling: tempName1 GetInfoOnClientsUsingResource returned %d\n"),r);
1.4000 + return KErrGeneral;
1.4001 + }
1.4002 +
1.4003 + infoPtrs.Close();
1.4004 + }
1.4005 +
1.4006 +
1.4007 + // 15) Repeat the read the number of resources without reading the resource information
1.4008 + // Subsequent call to read the resources information (without re-loading) should return error KErrNotReady
1.4009 + // Then call to read the resources information (with re-loading) should be successful
1.4010 + gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
1.4011 + {
1.4012 + TUint numResources = 0;
1.4013 + if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResources, EFalse))!=KErrNone) // don't load data
1.4014 + {
1.4015 + gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r);
1.4016 + return r;
1.4017 + }
1.4018 + // To support the GetInfoOnResourcesInUseByClient testing, instantiate TResourceInfoBuf objects
1.4019 + // and reference via an RSimplePointerArray
1.4020 + RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources);
1.4021 + for(TUint i=0;i<numResources;i++)
1.4022 + {
1.4023 + TResourceInfoBuf *info = new TResourceInfoBuf();
1.4024 + if((r=infoPtrs.Insert(info, i))!=KErrNone)
1.4025 + {
1.4026 + gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
1.4027 + }
1.4028 + }
1.4029 + if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, numResources, &infoPtrs))!=KErrNotReady)
1.4030 + {
1.4031 + gTest.Printf(_L("TestTransientHandling: GetInfoOnResourcesInUseByClient returned %d\n"),r);
1.4032 + return KErrGeneral;
1.4033 + }
1.4034 + if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, numResources, &infoPtrs, ETrue))!=KErrNone)
1.4035 + {
1.4036 + gTest.Printf(_L("TestTransientHandling: GetInfoOnResourcesInUseByClient returned %d\n"),r);
1.4037 + return r;
1.4038 + }
1.4039 + infoPtrs.Close();
1.4040 + }
1.4041 +
1.4042 +
1.4043 + // 16) Attempt to read the resource information (without re-loading) with a buffer of insufficient size should
1.4044 + // return error KErrArgument
1.4045 + gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
1.4046 + {
1.4047 + TUint numResources = 0;
1.4048 + if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResources))!=KErrNone) // load data
1.4049 + {
1.4050 + gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r);
1.4051 + return r;
1.4052 + }
1.4053 + // To support the GetInfoOnResourcesInUseByClient testing, instantiate TResourceInfoBuf objects
1.4054 + // and reference via an RSimplePointerArray
1.4055 + RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources-1);
1.4056 + for(TUint i=0;i<(numResources-1);i++)
1.4057 + {
1.4058 + TResourceInfoBuf *info = new TResourceInfoBuf();
1.4059 + if((r=infoPtrs.Insert(info, i))!=KErrNone)
1.4060 + {
1.4061 + gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
1.4062 + }
1.4063 + }
1.4064 + if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, numResources, &infoPtrs))!=KErrArgument)
1.4065 + {
1.4066 + gTest.Printf(_L("TestTransientHandling: GetInfoOnResourcesInUseByClient returned %d\n"),r);
1.4067 + return KErrGeneral;
1.4068 + }
1.4069 +
1.4070 + // Ensure misleading result is not returned
1.4071 + r=KErrNone;
1.4072 + infoPtrs.Close();
1.4073 + }
1.4074 +
1.4075 + channelTwo.Close();
1.4076 + channelThree.Close();
1.4077 +
1.4078 + return r;
1.4079 + }
1.4080 +
1.4081 +
1.4082 +EXPORT_C TInt E32Main()
1.4083 +//
1.4084 +// Main
1.4085 +//
1.4086 + {
1.4087 + gTest.Start(_L("Test Power Resource Manager user side API\n"));
1.4088 +
1.4089 + TInt r = KErrNone;
1.4090 +
1.4091 + // Test attempted load of PDD
1.4092 + gTest.Next(_L("**Load PDD\n"));
1.4093 + r=User::LoadPhysicalDevice(PDD_NAME);
1.4094 + if((r!=KErrNone)&&(r!=KErrAlreadyExists))
1.4095 + {
1.4096 + gTest.Printf(_L("User::LoadPhysicalDevice error %d\n"),r);
1.4097 + }
1.4098 + else
1.4099 + {
1.4100 + // Test attempted load of LDD
1.4101 + gTest.Next(_L("**Load LDD\n"));
1.4102 + r=User::LoadLogicalDevice(LDD_NAME);
1.4103 + if((r!=KErrNone)&&(r!=KErrAlreadyExists))
1.4104 + gTest.Printf(_L("User::LoadLogicalDevice error - expected %d, got %d\n"),KErrAlreadyExists,r);
1.4105 + }
1.4106 + if((r==KErrNone)||(r==KErrAlreadyExists))
1.4107 + {
1.4108 + r = KErrNone; // Re-initialise in case set to KErrAlreadyExists
1.4109 + //
1.4110 + // Need a channel open for the following tests
1.4111 + gTest.Next(_L("**OpenAndRegisterChannel\n"));
1.4112 + r=OpenAndRegisterChannel();
1.4113 + if (r==KErrNone)
1.4114 + {
1.4115 + // Get the version of the ResourceController
1.4116 + TUint version;
1.4117 + if((r=gChannel.GetResourceControllerVersion(version))!=KErrNone)
1.4118 + {
1.4119 + gTest.Printf(_L("TestTransientHandling: GetResourceControllerVersion returned %d\n"),r);
1.4120 + return r;
1.4121 + }
1.4122 + gTest.Printf(_L("TestTransientHandling: ResourceController version =0x%x\n"),version);
1.4123 + }
1.4124 + if (r==KErrNone)
1.4125 + {
1.4126 + gTest.Next(_L("**TestThreadExclusiveAccess\n"));
1.4127 + r=TestThreadExclusiveAccess();
1.4128 + }
1.4129 + if (r==KErrNone)
1.4130 + {
1.4131 + gTest.Next(_L("**TestGetClientGetResourceInfo - initial state\n"));
1.4132 + r=TestGetClientGetResourceInfo();
1.4133 + }
1.4134 + if (r==KErrNone)
1.4135 + {
1.4136 + gTest.Next(_L("**TestGetSetResourceStateOps\n"));
1.4137 + r=TestGetSetResourceStateOps();
1.4138 + }
1.4139 + if (r==KErrNone)
1.4140 + {
1.4141 + gTest.Next(_L("**TestGetClientGetResourceInfo - after changing stateof Async resource\n"));
1.4142 + r=TestGetClientGetResourceInfo();
1.4143 + }
1.4144 + if (r==KErrNone)
1.4145 + {
1.4146 + gTest.Next(_L("**TestGetSetResourceStateQuota\n"));
1.4147 + r=TestGetSetResourceStateQuota();
1.4148 + }
1.4149 + if (r==KErrNone)
1.4150 + {
1.4151 + gTest.Next(_L("**TestNotificationOps\n"));
1.4152 + r=TestNotificationOps();
1.4153 + }
1.4154 + if (r==KErrNone)
1.4155 + {
1.4156 + gTest.Next(_L("**TestNotificationQuota\n"));
1.4157 + r=TestNotificationQuota();
1.4158 + }
1.4159 + if (r==KErrNone)
1.4160 + {
1.4161 + // Should be no change since last invocation (assuming that
1.4162 + // no clients other than those in this test)
1.4163 + gTest.Next(_L("**TestGetClientGetResourceInfo - last invocation\n"));
1.4164 + r=TestGetClientGetResourceInfo();
1.4165 + }
1.4166 + if (r==KErrNone)
1.4167 + {
1.4168 + gTest.Next(_L("**TestAdditionalThread\n"));
1.4169 + r=TestAdditionalThread();
1.4170 + }
1.4171 + if (r==KErrNone)
1.4172 + {
1.4173 + gTest.Next(_L("**TestTransientHandling\n"));
1.4174 + r=TestTransientHandling();
1.4175 + }
1.4176 + }
1.4177 + gChannel.Close();
1.4178 +
1.4179 + User::FreeLogicalDevice(KLddRootName);
1.4180 + User::FreePhysicalDevice(PDD_NAME);
1.4181 + User::After(100000); // Allow idle thread to run for driver unloading
1.4182 +
1.4183 + gTest.End();
1.4184 + return r;
1.4185 + }
1.4186 +