Update contrib.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
18 #include <e32def_private.h>
20 #include <d32resmanus.h>
22 #ifdef PRM_ENABLE_EXTENDED_VERSION
23 #define LDD_NAME _L("resourcecontrollerextended.ldd")
25 #define LDD_NAME _L("resourcecontrol.ldd")
28 #ifdef PRM_ENABLE_EXTENDED_VERSION
29 #define PDD_NAME _L("resourcecontrollerextended.pdd")
31 #define PDD_NAME _L("resourcecontroller.pdd")
34 //#define PIRATE_THREAD_TESTS
36 _LIT(testableResourceName,"SymbianSimulResource");
39 _LIT(testName,"t_resmanuskern");
41 _LIT(testName,"t_resmanus");
44 TBuf<16> gTestName(testName);
46 GLDEF_D RTest gTest(testName);
47 GLDEF_D RBusDevResManUs gChannel;
49 TUint8 KNoOfGetStateRequests = 5;
50 TUint8 KNoOfSetStateRequests = 4;
51 TUint8 KNoOfNotifyRequests = 7;
52 #define MAX_NUM_REQUESTS 8 // Must be (at least) one greater than the largest of
53 // KNoOfGetStateRequests, KNoOfSetStateRequests, KNoOfNotifyRequests
55 TUint gLongLatencyResource;
56 TBool gHaveAsyncRes = EFalse;
57 TInt gAsyncResStateDelta = 0;
59 TUint gSharedResource;
60 TBool gHaveSharedRes = EFalse;
61 TInt gSharedResStateDelta = 0;
63 // The UREL version of the driver will not implement the arrays and functionality required
64 // to determine the async and shared resources to use at runtime. The values provided here
65 // have been pre-determined to operate successfully with the simulated PSL.
67 TUint gLongLatencyResource = 6;
68 TBool gHaveAsyncRes = ETrue;
69 TInt gAsyncResStateDelta = -1;
71 TUint gSharedResource = 12;
72 TBool gHaveSharedRes = ETrue;
73 TInt gSharedResStateDelta = -1;
76 TBool gUseCached = EFalse;
78 LOCAL_C TInt OpenChannel(TDesC16& aName, RBusDevResManUs& aChannel)
81 // API accepts 8-bit descriptors, only - so convert name accordingly
82 TBuf8<MAX_RESOURCE_NAME_LENGTH+1>EightBitName;
83 EightBitName.Copy(aName);
84 r=(aChannel.Open(EightBitName));
86 gTest.Printf(_L("OpenChannel: Handle for channel %S error code =0x%x\n"),&aName,r);
88 gTest.Printf(_L("OpenChannel: Handle for channel %S =0x%x\n"),&aName,aChannel.Handle());
92 LOCAL_C TInt HelperResources()
94 // Helper method to support OpenAndRegisterChannel
95 // Invokes GetNoOfResources, GetAllResourcesInfo and GetResourceIdByName
102 // Check what resources are available
103 gTest.Printf(_L("**Test GetNoOfResources\n"));
104 TUint numResources=0;
105 if((r=gChannel.GetNoOfResources(numResources))!=KErrNone)
107 gTest.Printf(_L("GetNoOfResources for test channel returned %d\n"),r);
110 gTest.Printf(_L("Number of resources = %d (=0x%x)\n"),numResources,numResources);
112 // Read the resource information
113 gTest.Printf(_L("**Test GetAllResourcesInfo\n"));
115 // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects
116 // and reference via an RSimplePointerArray
117 TUint bufSize = numResources;
118 RSimplePointerArray<TResourceInfoBuf> infoPtrs(bufSize);
119 for(TUint i=0;i<bufSize;i++)
121 TResourceInfoBuf *info = new TResourceInfoBuf();
122 if((r=infoPtrs.Insert(info, i))!=KErrNone)
124 gTest.Printf(_L("GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),i,r);
127 TUint updateNumResources=numResources;
128 if((r=gChannel.GetAllResourcesInfo(&infoPtrs,updateNumResources))!=KErrNone)
130 gTest.Printf(_L("GetAllResourcesInfo for channel returned %d\n"),r);
133 gTest.Printf(_L("Updated number of resources = %d\n"),updateNumResources);
136 // Print resource names
138 TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name;
139 for(TUint i=0; i<updateNumResources; i++)
141 TResourceInfoBuf* currRes = infoPtrs[i];
142 name.Copy((*currRes)().iName);
144 gTest.Printf(_L("Resource %d name = %S \n"),i,&name);
149 // Select a resource to use, then pass its name to GetResourceIdByName
150 // to check that the corresponding resource ID is acquired.
151 TResourceInfo currRes = (*infoPtrs[0])();
152 if(updateNumResources>1)
153 currRes=(*infoPtrs[1])();// First resource may be a dummy
155 gTest.Printf(_L("Invoking GetResourceIdByName for last resource name extracted \n"));
156 if((r=gChannel.GetResourceIdByName(currRes.iName, resourceId))!=KErrNone)
158 gTest.Printf(_L("GetResourceIdByName for channel returned %d \n"),r);
161 gTest.Printf(_L("GetResourceIdByName gave ID = %d\n"),resourceId);
170 LOCAL_C TInt CheckForSimulatedResources()
172 // Get the name of the first resource - if it does not match the expected name
173 // then the testing must not proceed, so return the relevant error code
177 TResourceInfoBuf buffer;
178 if((r=gChannel.GetResourceInfo(1, &buffer))!=KErrNone) // first resource ID = 1
180 gTest.Printf(_L("CheckForSimulatedResources, candidate get resource info returned %d\n"),r);
183 // Check the name of the resource
184 TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name;
185 name.Copy(buffer().iName);
187 if((r=name.Compare(testableResourceName))!=KErrNone)
189 gTest.Printf(_L("Resource name = %S, require %S \n"),&name,&testableResourceName);
195 //----------------------------------------------------------------------------------------------
196 //! @SYMTestCaseID KBASE-T_RESMANUS-0607
198 //! @SYMPREQ PREQ1398
199 //! @SYMTestCaseDesc This test case tests channel opening and initialisation APIs.
200 //! @SYMTestActions 0) Call Open API with a valid name.
202 //! 1) Call Open API for two more channels
203 //! (to demonstrate multiple clients (channels) can be supported concurrently).
205 //! 2) Call Open with an oversized name.
207 //! 3) Call GetNoOfResources API
209 //! 4) Call GetAllResourcesInfo API
211 //! 5) Call GetResourceIdByName API for last of resource names gathered
214 //! 6) Call Initialise API on the channel originally created, with non-zero arguments.
216 //! @SYMTestExpectedResults 0) API should return with KErrNone, exits otherwise.
217 //! 1) API should return with KErrNone, exits otherwise.
218 //! 2) API should return with KErrBadName, exits otherwise.
219 //! 3) API should return with KErrNone, exits otherwise.
220 //! 4) API should return with KErrNone, exits otherwise.
221 //! 5) API should return with KErrNone, exits otherwise.
222 //! 6) API should return with KErrNone, exits otherwise.
224 //! @SYMTestPriority High
225 //! @SYMTestStatus Implemented
226 //----------------------------------------------------------------------------------------------
227 LOCAL_C TInt OpenAndRegisterChannel()
229 // Test Open and Initialise functionality
230 // Also invokes Resource inspection methods via HelperResource
235 if((r=OpenChannel(gTestName, gChannel))!=KErrNone)
238 // Check that the simulated resources required to support this testing are present
239 // If not, close the channel and return the propagated error code.
240 if((r=CheckForSimulatedResources())!=KErrNone)
246 __KHEAP_MARK; // gTestName will remain open (allocated) when heap is checked
248 // Open a couple of additional channels to prove that more than one
250 _LIT(tempStr1,"temp1");
251 TBufC<16> tempName1(tempStr1);
252 _LIT(tempStr2,"temp2");
253 TBufC<16> tempName2(tempStr2);
255 RBusDevResManUs channelTwo;
256 RBusDevResManUs channelThree;
258 if((r=OpenChannel(tempName1, channelTwo))!=KErrNone)
260 if((r=OpenChannel(tempName2, channelThree))!=KErrNone)
263 // The following test requires manual enabling in resource controller of macro
264 // DEBUG_VERSION - this is not done by default, so test is deactivated here.
267 // Test rejection if try a name already in use
269 // (For UREL builds, duplicate names are allowed; but
270 // for UDEB builds, they are monitored and rejected)
272 RBusDevResManUs channelSameName;
273 r=OpenChannel(tempName1, channelSameName);
274 channelSameName.Close(); // Channel not used after here
277 gTest.Printf(_L("Error: Handle for re-used name channel =0x%x\n"),channelSameName.Handle());
280 else if(r!=KErrCouldNotConnect)
282 gTest.Printf(_L("Error: re-used name gave unexpected error code =0x%x\n"),r);
285 else // if(r==KErrCouldNotConnect)
287 gTest.Printf(_L("Re-used channel name rejected with correct error code\n"));
291 // Test oversized name rejection
292 _LIT(longStr,"1abcdefghijklmnopqrstuvwxyz2abcdefghijklmnopqrstuvwxyz3abcdefghijklmnopqrstuvwxyz4abcdefghijklmnopqrstuvwxyz5abcdefghijklmnopqrstuvwxyz6abcdefghijklmnopqrstuvwxyz7abcdefghijklmnopqrstuvwxyz8abcdefghijklmnopqrstuvwxyz9abcdefghijklmnopqrstuvwxyz10abcdefghijklmnopqrstuvwxyz");
293 TBufC<271> longName(longStr);
295 // API accepts 8-bit descriptors for names, only
296 TBuf8<271>longName_8Bit;
297 longName_8Bit.Copy(longName);
299 RBusDevResManUs channelLong;
300 r=(channelLong.Open(longName_8Bit));
301 channelLong.Close(); // Channel not used after here
304 gTest.Printf(_L("Error: Handle for oversize name channel =0x%x\n"),channelLong.Handle());
307 else if(r!=KErrBadName)
309 gTest.Printf(_L("Error: oversized name gave unexpected error code =0x%x\n"),r);
312 else // if(r==KErrBadName)
314 gTest.Printf(_L("Oversized name for channel rejected with correct error code\n"));
317 // Invokes GetNoOfResources, GetAllResourcesInfo and GetResourceIdByName
318 if((r=HelperResources())!=KErrNone)
321 // Close the temporary channels
322 // Do this before channel registration to enable valid check of kernel heap
324 channelThree.Close();
328 // Channel registration
329 gTest.Printf(_L("Invoking Initialise with values 0x%x, 0x%x, 0x%x\n"),KNoOfGetStateRequests,KNoOfSetStateRequests,KNoOfNotifyRequests);
330 if ((r=gChannel.Initialise(KNoOfGetStateRequests,KNoOfSetStateRequests,KNoOfNotifyRequests))!=KErrNone)
332 gTest.Printf(_L("Initialise for channel returned %d\n"),r);
340 LOCAL_C TInt HelperClients()
342 // Helper method to support TestGetClientGetResourceInfo
343 // Invokes GetNoOfClients and GetNamesAllClients
349 TUint numClients = 0;
350 TUint numAllClients = 0;
352 // GetNoOfClients - with aIncludeKern=EFalse
354 if((r=gChannel.GetNoOfClients(numClients, EFalse)) != KErrNone)
356 gTest.Printf(_L("GetNoOfClients (aIncludeKern==EFalse) returned %d\n"),r);
359 gTest.Printf(_L("GetNoOfClients (aIncludeKern==EFalse) gave 0x%x clients\n"),numClients);
362 // GetNoOfClients - with aIncludeKern=ETrue
364 r=gChannel.GetNoOfClients(numAllClients, ETrue);
367 gTest.Printf(_L("GetNoOfClients (aIncludeKern==ETrue) returned KErrNone\n"));
369 if(r==KErrPermissionDenied)
370 gTest.Printf(_L("GetNoOfClients (aIncludeKern==ETrue) returned KErrPermissionDenied\n"));
374 gTest.Printf(_L("GetNoOfClients (aIncludeKern==ETrue) returned %d"),r);
378 // To support the GetNamesAllClients testing, instantiate TClientName objects
379 // and reference via an RSimplePointerArray
380 TUint bufSize = (numAllClients>numClients)?numAllClients:numClients;
381 RSimplePointerArray<TClientName> infoPtrs(bufSize);
382 for(TUint i=0;i<bufSize;i++)
384 TClientName *info = new TClientName();
385 if((r=infoPtrs.Insert(info, i))!=KErrNone)
387 gTest.Printf(_L("GetNamesAllClients infoPtrs.Insert at index %d returned %d\n"),i,r);
392 // GetNamesAllClients - with aIncludeKern=EFalse
394 if((r=gChannel.GetNamesAllClients(&infoPtrs, numClients, EFalse)) != KErrNone)
396 gTest.Printf(_L("GetNamesAllClients (aIncludeKern==EFalse) returned %d\n"),r);
402 gTest.Printf(_L("GetNamesAllClients (aIncludeKern==EFalse) returned KErrNone, names follow\n"));
403 for(TUint i=0;i<numClients;i++)
405 TClientName *currName = infoPtrs[i];
406 TBuf16<sizeof(TClientName)> name;
407 name.Copy(*currName);
408 gTest.Printf(_L("Client name %d = %S\n"),i,&name);
414 // GetNamesAllClients - with aIncludeKern=ETrue
417 if((r=gChannel.GetNamesAllClients(&infoPtrs, numAllClients, ETrue)) != KErrNone)
419 gTest.Printf(_L("GetNamesAllClients (aIncludeKern==ETrue) returned %d\n"),r);
425 gTest.Printf(_L("GetNamesAllClients (aIncludeKern==ETrue) returned KErrNone, names follow\n"));
426 for(TUint i=0;i<numAllClients;i++)
428 TClientName *currName = infoPtrs[i];
429 TBuf16<sizeof(TClientName)> name;
430 name.Copy(*currName);
431 gTest.Printf(_L("Client name %d = %S\n"),i,&name);
436 if((r=gChannel.GetNamesAllClients(&infoPtrs, numClients, ETrue)) == KErrPermissionDenied)
438 gTest.Printf(_L("GetNamesAllClients (aIncludeKern==ETrue) returned KErrPermissionDenied\n"));
439 r=KErrNone; // Ensure misleading status is not returned
443 gTest.Printf(_L("GetNamesAllClients (aIncludeKern==ETrue) returned %d"),r);
454 LOCAL_C TInt HelperClientsUsingResource(TUint aResourceId)
456 // Helper method to support TestGetClientGetResourceInfo
457 // Invokes GetNumClientsUsingResource and GetInfoOnClientsUsingResource
464 // GetNumClientsUsingResource - with aIncludeKern=ETrue
466 TUint resourceAllClients = 0;
467 if((r=gChannel.GetNumClientsUsingResource(aResourceId, resourceAllClients, ETrue)) == KErrPermissionDenied)
469 gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==ETrue) returned KErrPermissionDenied\n"));
477 gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==ETrue) returned %d\n"),r);
481 gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==ETrue) reported 0x%x clients\n"),resourceAllClients);
487 gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==ETrue) returned %d\n"),r);
492 // GetNumClientsUsingResource - with aIncludeKern=EFalse
494 TUint resourceClients = 0;
495 if((r=gChannel.GetNumClientsUsingResource(aResourceId, resourceClients, EFalse)) != KErrNone)
497 // If there are no clients that have requested a level then the Resource Controller will
498 // the client ID as a bad argument
499 if(!((resourceClients==0)&&(r==KErrArgument)))
501 gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==EFalse) returned %d\n"),r);
505 r=KErrNone; // Ensure expected error is not misinterpeted
508 gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==EFalse) reported 0x%x clients\n"),resourceClients);
510 // To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects
511 // and reference via an RSimplePointerArray
512 TUint bufSize = (resourceAllClients>resourceClients)?resourceAllClients:resourceClients;
515 RSimplePointerArray<TClientInfoBuf> infoPtrs(bufSize);
516 for(TUint i=0;i<bufSize;i++)
518 TClientInfoBuf *info = new TClientInfoBuf();
519 if((r=infoPtrs.Insert(info, i))!=KErrNone)
521 gTest.Printf(_L("GetInfoOnClientsUsingResource infoPtrs.Insert at index %d returned %d\n"),i,r);
526 // GetInfoOnClientsUsingResource - with aIncludeKern=EFalse
528 if((r=gChannel.GetInfoOnClientsUsingResource(aResourceId, resourceClients, &infoPtrs, EFalse)) != KErrNone)
530 // If there are no clients that have requested a level then the resource will not
532 if(!((resourceClients==0)&&(r==KErrNotFound)))
534 gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==EFalse) returned %d\n"),r);
541 gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==EFalse) returned KErrNone, info follows\n"));
542 for(TUint i=0;i<resourceClients;i++)
544 TClientInfoBuf* currInfoBuf = infoPtrs[i];
545 TClientInfo currInfo=(*currInfoBuf)();
546 TBuf16<sizeof(TClientName)> name;
547 name.Copy(currInfo.iName);
548 gTest.Printf(_L("Client name %d = %S, ID=0x%x\n"),i,&name,currInfo.iId);
553 // GetInfoOnClientsUsingResource - with aIncludeKern=ETrue
555 r=gChannel.GetInfoOnClientsUsingResource(aResourceId, resourceAllClients, &infoPtrs, ETrue);
560 // If there are no clients that have requested a level then the Resource Controller
561 // will report a request for information on 0 clients as a bad argument
562 if(!((resourceClients==0)&&(r==KErrArgument)))
564 gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned %d\n"),r);
568 r=KErrNone; // Ensure misleading result is not returned
573 gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned KErrNone, info follows\n"));
574 for(TUint i=0;i<resourceClients;i++)
576 TClientInfoBuf* currInfoBuf = infoPtrs[i];
577 TClientInfo currInfo=(*currInfoBuf)();
578 TBuf16<sizeof(TClientName)> name;
579 name.Copy(currInfo.iName);
580 gTest.Printf(_L("Client name %d = %S, ID=0x%x\n"),i,&name,currInfo.iId);
587 gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned KErrNone"));
590 else if(r==KErrPermissionDenied)
592 gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned KErrPermissionDenied\n"));
593 r=KErrNone; // Ensure that misleading result is not propagated
597 gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned %d\n"),r);
598 // If there are no clients that have requested a level then the Resource Controller
599 // will report a request for information on 0 clients as a bad argument
600 if(!((resourceClients==0)&&(r==KErrArgument)))
614 LOCAL_C TInt HelperResourcesInUseByClient()
616 // Helper method to supportTestGetClientGetResourceInfo
617 // Invokes GetNumResourcesInUseByClient and GetInfoOnResourcesInUseByClient
624 // GetNumResourcesInUseByClient
626 // API accepts 8-bit descriptors, only - so convert name accordingly
627 TBuf8<MAX_RESOURCE_NAME_LENGTH+1>name8Bit;
628 name8Bit.Copy(gTestName);
629 TClientName* clientName = (TClientName*)&name8Bit;
631 TBuf <MAX_CLIENT_NAME_LENGTH> clientName16Bit;
632 clientName16Bit.Copy(*clientName);
633 clientName16Bit.SetLength(clientName->Length());
634 gTest.Printf(_L("Invoking GetNumResourcesInUseByClient with %S (expect KErrPermissionDenied if no levels requested yet)\n"),&clientName16Bit);
636 TUint numResourcesForClient;
637 if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResourcesForClient)) != KErrNone)
639 gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r);
642 gTest.Printf(_L("GetNumResourcesInUseByClient gave number of resources = %d\n"),numResourcesForClient);
644 // In addition, check response when the name of an unknown client is passed
646 // Negative test - ensure that an unknown client name fails
647 _LIT(dumName,"DoesNotExist");
648 TBuf<16> dumNameBuf(dumName);
649 TBuf8<MAX_RESOURCE_NAME_LENGTH+1>dumName8Bit;
650 dumName8Bit.Copy(dumNameBuf);
651 TClientName* dumClientName = (TClientName*)&dumName8Bit;
653 gTest.Printf(_L("Invoking GetNumResourcesInUseByClient with %S\n"),&dumNameBuf);
655 TUint numResForDumClient;
656 if((r=gChannel.GetNumResourcesInUseByClient(*dumClientName, numResForDumClient)) != KErrNotFound)
658 gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r);
663 gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r);
664 r=KErrNone; // Ensure misleading error code is not propagated
667 // GetInfoOnResourcesInUseByClient
669 // If the (TUint) number of resources in use by the client is zero skip the attempt to read the resource information
670 TUint updatedNumResourcesForClient = numResourcesForClient;
671 if(numResourcesForClient!=0)
673 TUint bufSize = numResourcesForClient;
674 RSimplePointerArray<TResourceInfoBuf> infoPtrs(bufSize);
675 for(TUint i=0;i<bufSize;i++)
677 TResourceInfoBuf *info = new TResourceInfoBuf();
678 if((r=infoPtrs.Insert(info, i))!=KErrNone)
680 gTest.Printf(_L("GetInfoOnResourcesInUseByClient infoPtrs.Insert at index %d returned %d\n"),i,r);
684 if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, updatedNumResourcesForClient, &infoPtrs)) != KErrNone)
686 gTest.Printf(_L("GetInfoOnResourcesInUseByClient returned %d\n"),r);
687 // If there are no clients that have requested a level then the Resource Controller
688 // will report a request for information on 0 clients as a bad argument
689 if(!((updatedNumResourcesForClient==0)&&(r==KErrArgument)))
692 r=KErrNone; // Ensure misleading value is not returned by this function
696 gTest.Printf(_L("GetInfoOnResourcesInUseByClient gave updated number of resources %d\n"),updatedNumResourcesForClient);
698 // Print resource names
699 TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name;
700 for(TUint i=0; i<updatedNumResourcesForClient; i++)
702 TResourceInfoBuf* currRes = infoPtrs[i];
703 name.Copy((*currRes)().iName);
705 gTest.Printf(_L("Resource %d name = %S \n"),i,&name);
710 // In addition, check response when the name of an unknown client is passed
712 // Negative test - ensure that an unknown client name fails
713 r=gChannel.GetInfoOnResourcesInUseByClient(*dumClientName, updatedNumResourcesForClient, &infoPtrs);
714 gTest.Printf(_L("GetInfoOnResourcesInUseByClient for dummy client returned %d\n"),r);
717 else if(r!=KErrNotFound)
719 // Ensure that misleading information is not returned to the calling function
731 LOCAL_C TInt HelperGetClientResourceInfo()
733 // Test methods to access information about clients and resources
739 // Invokes GetNoOfClients and GetNamesAllClients
740 if((r=HelperClients())!=KErrNone)
743 // Invokes GetNumClientsUsingResource and GetInfoOnClientsUsingResource
745 // First invoke on the Async resource
746 TUint resourceId = 1; // Arbitrary
749 resourceId = gLongLatencyResource;
750 gTest.Printf(_L("Invoking HelperClientsUsinResource for Async resource ID %d\n"),resourceId);
754 gTest.Printf(_L("Invoking HelperClientsUsinResource for default resource ID %d (Async resource not yet accessed)\n"),resourceId);
756 if((r=HelperClientsUsingResource(resourceId))!=KErrNone)
759 // Second invoke on the Shared resource - skip if not available
762 resourceId = gSharedResource;
763 gTest.Printf(_L("Invoking HelperClientsUsinResource for Shared resource ID %d\n"),resourceId);
764 if((r=HelperClientsUsingResource(resourceId))!=KErrNone)
768 // Invokes GetNumResourcesInUseByClient and GetInfoOnResourcesInUseByClient
769 if((r=HelperResourcesInUseByClient())!=KErrNone)
778 LOCAL_C TInt SetAsyncResource()
780 // Support function for tests of asynchronous API methods
785 gTest.Printf(_L("SetAsyncResource, Find Async resource to use\n"));
786 TRequestStatus status;
787 TBool cached = gUseCached;
789 TInt levelOwnerId = 0;
790 TUint numPotentialResources;
792 TInt r=gChannel.GetNumCandidateAsyncResources(numPotentialResources);
795 gTest.Printf(_L("SetAsyncResource, GetNumCandidateAsyncResources returned %d\n"),r);
798 gTest.Printf(_L("SetAsyncResource, GetNumCandidateAsyncResources found %d resources\n"),numPotentialResources);
799 while((numPotentialResources>0) && !gHaveAsyncRes)
801 TUint tryResourceId=0;
802 r=gChannel.GetCandidateAsyncResourceId(index,tryResourceId);
805 gTest.Printf(_L("SetAsyncResource, GetCandidateAsyncResourceId returned %d\n"),r);
808 gTest.Printf(_L("SetAsyncResource, GetNumCandidateAsyncResources index %d, resource ID %d\n"),index,tryResourceId);
809 // For the candidate resource to be usable, we need its current state
810 // to be sufficiently less the maximum for positive sense (or sufficiently
811 // more than the greater than the minimum for negative sense - but the current
812 // version of the code only considers positive sense).
813 gChannel.GetResourceState(status,tryResourceId,cached,&readValue,&levelOwnerId);
814 User::WaitForRequest(status);
815 if(status.Int() != KErrNone)
817 gTest.Printf(_L("SetAsyncResource, candidate get state returned %d\n"),r);
820 gTest.Printf(_L("SetAsyncResource, candidate get state gave %d, levelOwnerId = %d\n"),readValue,levelOwnerId);
821 TResourceInfoBuf buffer;
822 if((r=gChannel.GetResourceInfo(tryResourceId, &buffer))!=KErrNone)
824 gTest.Printf(_L("SetAsyncResource, candidate get resource info returned %d\n"),r);
827 // Print resource info
828 TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name;
829 TResourceInfo* infoPtr = &(buffer());
830 name.Copy(infoPtr->iName);
831 gTest.Printf(_L("SetAsyncResource: Resource name = %S \n"),&name);
832 gTest.Printf(_L("SetAsyncResource: Resource Class =%d\n"),infoPtr->iClass);
833 gTest.Printf(_L("SetAsyncResource: Resource Type =%d\n"), infoPtr->iType);
834 gTest.Printf(_L("SetAsyncResource: Resource Usage =%d\n"), infoPtr->iUsage);
835 gTest.Printf(_L("SetAsyncResource: Resource Sense =%d\n"), infoPtr->iSense);
836 gTest.Printf(_L("SetAsyncResource: Resource MinLevel =%d\n"),infoPtr->iMinLevel);
837 gTest.Printf(_L("SetAsyncResource: Resource MaxLevel =%d\n"),infoPtr->iMaxLevel);
839 if((infoPtr->iMaxLevel - readValue) > LEVEL_GAP_REQUIRED_FOR_ASYNC_TESTING)
841 gLongLatencyResource = tryResourceId;
842 gAsyncResStateDelta = 1; // Will change resource level in positive direction
843 gHaveAsyncRes = ETrue;
845 else if((readValue - infoPtr->iMinLevel) > LEVEL_GAP_REQUIRED_FOR_ASYNC_TESTING)
847 gLongLatencyResource = tryResourceId;
848 gAsyncResStateDelta = -1; // Will change resource level in negative direction
849 gHaveAsyncRes = ETrue;
854 --numPotentialResources;
860 gTest.Printf(_L("**Test SetAsyncResource - don't have suitable resource ... exiting\n"));
867 LOCAL_C TInt SetSharedResource()
869 // Support function for tests of shareable resources
876 TRequestStatus status;
877 TBool cached = gUseCached;
879 TUint numPotentialResources;
881 TInt r=gChannel.GetNumCandidateSharedResources(numPotentialResources);
884 gTest.Printf(_L("SetSharedResource, GetNumCandidateSharedResources returned %d\n"),r);
887 gTest.Printf(_L("SetSharedResource, GetNumCandidateSharedResources found %d resources\n"),numPotentialResources);
888 while((numPotentialResources>0) && !gHaveSharedRes)
890 TUint tryResourceId=0;
891 r=gChannel.GetCandidateSharedResourceId(index,tryResourceId);
894 gTest.Printf(_L("SetSharedResource, GetCandidateSharedResourceId returned %d\n"),r);
897 gTest.Printf(_L("SetSharedResource, GetNumCandidateSharedResources index %d, resource ID %d\n"),index,tryResourceId);
898 // To support the tests, the selected shareable resource must not be the same
899 // resource as that selected for asynchronous testing
901 if(tryResourceId==gLongLatencyResource)
903 gTest.Printf(_L("SetSharedResource - skipping candidate resource %d - already used for async testing\n"),tryResourceId);
906 // For the candidate resource to be usable, we need its current state
907 // to be sufficiently less the maximum for positive sense (or sufficiently
908 // more than the greater than the minimum for negative sense - but the current
909 // version of the code only considers positive sense).
910 TInt levelOwnerId = 0;
911 gChannel.GetResourceState(status,tryResourceId,cached,&readValue,&levelOwnerId);
912 User::WaitForRequest(status);
913 if(status.Int() != KErrNone)
915 gTest.Printf(_L("SetSharedResource, candidate get state returned %d\n"),r);
918 gTest.Printf(_L("SetSharedResource, candidate get state gave %d, levelOwnerId = %d\n"),readValue,levelOwnerId);
919 TResourceInfoBuf buffer;
920 if((r=gChannel.GetResourceInfo(tryResourceId, &buffer))!=KErrNone)
922 gTest.Printf(_L("SetSharedResource, candidate get resource info returned %d\n"),r);
925 // Print resource info
926 TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name;
927 TResourceInfo* infoPtr = &buffer();
928 name.Copy(infoPtr->iName);
929 gTest.Printf(_L("SetSharedResource: Resource name = %S \n"),&name);
930 gTest.Printf(_L("SetSharedResource: Resource Class =%d\n"),infoPtr->iClass);
931 gTest.Printf(_L("SetSharedResource: Resource Type =%d\n"), infoPtr->iType);
932 gTest.Printf(_L("SetSharedResource: Resource Usage =%d\n"), infoPtr->iUsage);
933 gTest.Printf(_L("SetSharedResource: Resource Sense =%d\n"), infoPtr->iSense);
934 gTest.Printf(_L("SetSharedResource: Resource MinLevel =%d\n"),infoPtr->iMinLevel);
935 gTest.Printf(_L("SetSharedResource: Resource MaxLevel =%d\n"),infoPtr->iMaxLevel);
937 if((infoPtr->iMaxLevel - readValue) > LEVEL_GAP_REQUIRED_FOR_ASYNC_TESTING)
939 gSharedResource = tryResourceId;
940 gSharedResStateDelta = 1; // Will change resource level in positive direction
941 gHaveSharedRes = ETrue;
943 else if((readValue - infoPtr->iMinLevel) > LEVEL_GAP_REQUIRED_FOR_ASYNC_TESTING)
945 gSharedResource = tryResourceId;
946 gSharedResStateDelta = -1; // Will change resource level in negative direction
947 gHaveSharedRes = ETrue;
952 --numPotentialResources;
958 gTest.Printf(_L("**Test SetSharedResource - don't have suitable resource ... exiting\n"));
969 //----------------------------------------------------------------------------------------------
970 //! @SYMTestCaseID KBASE-T_RESMANUS-0609
972 //! @SYMPREQ PREQ1398
973 //! @SYMTestCaseDesc This test case tests APIs for retrieving information about
974 //! (1) clients of the channel and
975 //! (2) power resources.
976 //! Since the client lacks the ReadDeviceData PlatSec capability it will not
977 //! be permitted to access information about kernel-side clients
979 //! The tests are invoked a number of times:
980 //! - first, to examine the starting state
981 //! - then, to examine the effect of adding a new client (channel)
982 //! - then, the examine the effect of adding a new client that requests a
983 //| level on a resource
984 //! - then, to test the effect of the original client requesting a level
987 //! @SYMTestActions 0) Call GetNoOfClients API with default aIncludeKern=EFalse.
989 //! 1) Call GetNoOfClients API with aIncludeKern=ETrue.
991 //! 2) Call GetNamesAllClients API with default aIncludeKern=EFalse.
993 //! 3) Call GetNamesAllClients API with aIncludeKern=ETrue.
995 //! 4) Call GetNumClientsUsingResource API with aIncludeKern=ETrue.
997 //! 5) Call GetNumClientsUsingResource API with default aIncludeKern=EFalse.
999 //! 6) Call GetInfoOnClientsUsingResource API with default aIncludeKern=EFalse.
1001 //! 7) Call GetInfoOnClientsUsingResource API with aIncludeKern=ETrue.
1003 //! 8) GetNumResourcesInUseByClient for the original client
1005 //! 9) GetNumResourcesInUseByClient for a non-existent client
1007 //! 10) GetInfoOnResourcesInUseByClient for the original client
1009 //! 11) GetInfoOnResourcesInUseByClient for a non-existent client
1011 //! @SYMTestExpectedResults 0) API should return with KErrNone, exits otherwise.
1013 //! 1) If client exhibits PlatSec capability ReadDeviceData, API should return with KErrNone, exits otherwise.
1014 //! If client lacks PlatSec capability ReadDeviceData, API should return with KErrPermissionDenied, exits otherwise.
1016 //! 2) API should return with KErrNone, exits otherwise.
1018 //! 3) If client exhibits PlatSec capability ReadDeviceData, API should return with KErrNone, exits otherwise
1019 //! If client lacks PlatSec capability ReadDeviceData, API should return with KErrPermissionDenied, exits otherwise
1021 //! 4) If client exhibits PlatSec capability ReadDeviceData, API should return with KErrNone, exits otherwise.
1022 //! If client lacks PlatSec capability ReadDeviceData, API should return with KErrPermissionDenied, exits otherwise.
1024 //! 5) API should return with KErrNone, exits otherwise
1026 //! 6) API should return with KErrNone, exits otherwise.
1028 //! 7) If client exhibits PlatSec capability ReadDeviceData, API should return with KErrNone, exits otherwise
1029 //! If client lacks PlatSec capability ReadDeviceData, API should return with KErrPermissionDenied, exits otherwise
1031 //! 8) API should return with KErrNone, exits otherwise.
1033 //! 9) API should return with KErrNotFound, exits otherwise.
1035 //! 10) API should return with KErrNone, exits otherwise.
1037 //! 11) API should return with KErrNotFound, exits otherwise.
1039 //! @SYMTestPriority High
1040 //! @SYMTestStatus Implemented
1041 //----------------------------------------------------------------------------------------------
1042 LOCAL_C TInt TestGetClientGetResourceInfo()
1044 // Test methods to access information about clients and resources
1049 // Open a couple of additional channels
1050 _LIT(tempStr1,"ExtraChan1");
1051 TBufC<16> tempName1(tempStr1);
1052 _LIT(tempStr2,"ExtraChan2");
1053 TBufC<16> tempName2(tempStr2);
1055 RBusDevResManUs channelTwo;
1056 RBusDevResManUs channelThree;
1058 if((r=OpenChannel(tempName1, channelTwo))!=KErrNone)
1060 if((r=OpenChannel(tempName2, channelThree))!=KErrNone)
1063 // Test the tracking of the client and resource info
1066 // First invocation to establish starting state
1068 gTest.Printf(_L("TestGetClientGetResourceInfo: First HelperGetClientResourceInfo call (starting state):\n"));
1070 if((r=HelperGetClientResourceInfo())!=KErrNone)
1073 // Second invocation - examine effect of adding a client
1074 _LIT(tempStr3,"ExtraChan3");
1075 TBufC<16> tempName3(tempStr3);
1076 RBusDevResManUs channelFour;
1077 if((r=OpenChannel(tempName3, channelFour))!=KErrNone)
1080 gTest.Printf(_L("TestGetClientGetResourceInfo: Second HelperGetClientResourceInfo call (added client ExtraChan3):\n"));
1083 if((r=HelperGetClientResourceInfo())!=KErrNone)
1086 // Third invocation - examine effect of new client requesting a level for a resource
1087 // (This relies on getting and setting the state of gSharedResource - so skip the
1088 // test if this has not yet been identified
1090 TUint startingLevel = 0;
1092 if((r=SetSharedResource())!=KErrNone)
1097 gTest.Printf(_L("TestGetClientGetResourceInfo: no suitable shareable resource, so skipping third call:\n"));
1101 // Channel registration
1102 gTest.Printf(_L("Initialise for temporary channel with arguments 1,1,0\n"));
1103 if ((r=channelFour.Initialise(1,1,0))!=KErrNone) // Just need 1 get and 1 set state
1105 gTest.Printf(_L("Initialise for channel returned %d\n"),r);
1108 // Get initial state
1109 TRequestStatus status;
1110 TBool cached = gUseCached;
1112 TInt levelOwnerId = 0;
1113 channelFour.GetResourceState(status,gSharedResource,cached,&readValue,&levelOwnerId);
1114 User::WaitForRequest(status);
1118 gTest.Printf(_L("TestGetClientGetResourceInfo, first get state for shareable returned %d\n"),r);
1121 startingLevel = (TUint)readValue;
1122 // Write updated state
1123 TUint newLevel = (TUint)(readValue + gSharedResStateDelta);
1124 gTest.Printf(_L("TestGetClientGetResourceInfo: levelOwnerId = %d\n"), levelOwnerId);
1125 gTest.Printf(_L("TestGetClientGetResourceInfo: shareable resource startingLevel=0x%x, writing 0x%x\n"), startingLevel, newLevel);
1126 channelFour.ChangeResourceState(status,gSharedResource,newLevel);
1127 User::WaitForRequest(status);
1131 gTest.Printf(_L("TestGetClientGetResourceInfo, first change state for shareable resource returned %d\n"),r);
1135 gTest.Printf(_L("TestGetClientGetResourceInfo: third HelperGetClientResourceInfo call (new client set level on shared resource):\n"));
1137 if((r=HelperGetClientResourceInfo())!=KErrNone)
1142 // Fourth invocation - examine effect of orignal client requesting a level for
1143 // the Shared resource
1146 TRequestStatus status;
1147 TBool cached = gUseCached;
1150 gChannel.GetResourceState(status,gSharedResource,cached,&readValue,&levelOwnerId);
1151 User::WaitForRequest(status);
1155 gTest.Printf(_L("TestGetClientGetResourceInfo, gChannel get state on Shareable resource returned %d\n"),r);
1158 gTest.Printf(_L("TestGetClientGetResourceInfo, GetResourceState levelOwnerId = %d\n"),levelOwnerId); // Request a level on the resource
1159 gChannel.ChangeResourceState(status,gSharedResource,(readValue+gSharedResStateDelta));
1160 User::WaitForRequest(status);
1161 if(status.Int() != KErrNone)
1163 gTest.Printf(_L("TestGetClientGetResourceInfo, gChannel change state on Shareable returned %d\n"),r);
1167 gTest.Printf(_L("TestGetClientGetResourceInfo: fourth HelperGetClientResourceInfo call (gChannel set level on Shareable resource):\n"));
1169 if((r=HelperGetClientResourceInfo())!=KErrNone)
1173 // Return the resource to the state it was on function entry
1176 TRequestStatus status;
1177 gTest.Printf(_L("TestGetClientGetResourceInfo: returning sharable resource to startingLevel=0x%x\n"), startingLevel);
1178 gChannel.ChangeResourceState(status,gSharedResource,startingLevel);
1179 User::WaitForRequest(status);
1183 gTest.Printf(_L("TestGetClientGetResourceInfo, attempt to reset shareable resource state returned %d\n"),r);
1189 // Close the temporary channels
1191 channelThree.Close();
1192 channelFour.Close();
1199 //----------------------------------------------------------------------------------------------
1200 //! @SYMTestCaseID KBASE-T_RESMANUS-0610
1202 //! @SYMPREQ PREQ1398
1203 //! @SYMTestCaseDesc This test case tests APIs for getting and setting the state of resources;
1204 //! it also tests APIs to cancel such requests.
1206 //! @SYMTestActions 0) Call API to get the initial state of a selected resource.
1208 //! 1) Call API to modify the state of the resource.
1210 //! 2) Call API to get the new state of the resource and check it exhibits
1211 //! the expected value.
1213 //! 3) Call API to return the resource state to its original value.
1215 //! 4) Call API to get the state of a long latency resource then call API
1216 //! with operation-type qualifier cancel the request.
1218 //! 5) Call API to modify the state of the long latency resource then call API
1219 //! with operation-type qualifier to cancel the request.
1221 //! 6) Call API to get the state of a long latency resource and wait for it
1222 //! to complete. Then call API with operation-type qualifier to cancel the request.
1224 //! 7) Call API to modify the state of the long latency resource and wait for
1225 //! it to complete. Then call API with operation-type qualifier to cancel the request.
1227 //! 8) Call API to get the state of a long latency resource then call API
1228 //! without operation-type qualifier to cancel the request.
1230 //! 9) Call API to modify the state of the long latency resource then call API
1231 //! without operation-type qualifier to cancel the request.
1233 //! 10) Call API to get the state of a long latency resource and wait for it
1234 //! to complete. Then call API without operation-type qualifier to cancel the request.
1236 //! 11) Call API to modify the state of the long latency resource and wait for
1237 //! it to complete. Then call API without operation-type qualifier to cancel the request.
1239 //! 12) Call API to get the state of a long latency resource 'n' times. Then call API with
1240 //! resource qualifier to cancel the requests.
1242 //! 13) Call API to modify the state of a long latency resource 'm' times. Then call API with
1243 //! resource qualifier to cancel the requests.
1245 //! 14) Call API to get the state of a long latency resource 'n' times and wait for them to complete.
1246 //! Then call API with resource qualifier to cancel the requests.
1248 //! 15) Call API to modify the state of a long latency resource 'm' times and wait for them to complete.
1249 //! Then call API with resource qualifier to cancel the requests.
1251 //! 16) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
1252 //! a long latency resource 'm' times. Call the API to cancel the get operations with resource qualifier.
1253 //! Wait for the operations to complete. Check the state of the associated TRequestStatus objects.
1255 //! 17) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
1256 //! a long latency resource 'm' times. Call the API to cancel the modify operations with resource qualifier.
1257 //! Wait for the get operations to complete. Check the state of the associated TRequestStatus objects.
1259 //! 18) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
1260 //! a long latency resource 'm' times. Wait for the get operations to complete. Call the API to cancel the get
1261 //! operations with resource qualifier. Check the state of the associated TRequestStatus objects.
1263 //! 19) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
1264 //! a long latency resource 'm' times. Wait for the modify operations to complete. Call the API to cancel the modify
1265 //! operations with resource qualifier. Check the state of the associated TRequestStatus objects.
1267 //! 20) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
1268 //! a long latency resource 'm' times.
1269 //! Then call API with operation-type qualifier to cancel the even-numbered get request(s).
1270 //! Then call API without operation-type qualifier to cancel the even-numbered modify request(s).
1271 //! Check the state of the associated TRequestStatus objects.
1273 //! @SYMTestExpectedResults 0) The associated TRequestStatus object should indicate KErrNone, exits otherwise.
1275 //! 1) The associated TRequestStatus object should indicate KErrNone, exits otherwise.
1277 //! 2) The associated TRequestStatus object should indicate KErrNone, exits otherwise.
1278 //! Exit if the value read back is not as expected.
1280 //! 3) The associated TRequestStatus object should indicate KErrNone, exits otherwise.
1282 //! 4) The associated TRequestStatus object should indicate KErrCancel if the cancel
1283 //! request was accepted, exits otherwise.
1284 //! The associated TRequestStatus object should indicate KErrNone if the cancel request
1285 //! was not accepted, exits otherwise.
1287 //! 5) The associated TRequestStatus object should indicate KErrCancel if the cancel
1288 //! request was accepted, exits otherwise.
1289 //! The associated TRequestStatus object should indicate KErrNone if the cancel request
1290 //! was not accepted, exits otherwise.
1292 //! 6) The TRequestStatus object associated with the get operation should indicate
1293 //! KErrNone - exits otherwise. The TRequestStatus object associated with the cancel
1294 //! operation should indicate KErrNone - exits otherwise.
1296 //! 7) The TRequestStatus object associated with the get operation should indicate
1297 //! KErrNone - exits otherwise. The TRequestStatus object associated with the cancel
1298 //! operation should indicate KErrNone - exits otherwise.
1300 //! 8) The associated TRequestStatus object should indicate KErrCancel, exits otherwise.
1302 //! 9) The associated TRequestStatus object should indicate KErrCancel, exits otherwise.
1304 //! 10) The TRequestStatus object associated with the get operation should indicate
1305 //! KErrNone - exits otherwise. The TRequestStatus object associated with the cancel
1306 //! operation should indicate KErrNone - exits otherwise.
1308 //! 11) The TRequestStatus object associated with the get operation should indicate
1309 //! KErrNone - exits otherwise. The TRequestStatus object associated with the cancel
1310 //! operation should indicate KErrNone - exits otherwise.
1312 //! 12) The TRequestStatus objects should all exibit KErrCancel - exits otherwise.
1314 //! 13) The TRequestStatus objects should all exibit KErrCancel - exits otherwise.
1316 //! 14) The TRequestStatus objects associated with the get operations should all exibit KErrNone - exits otherwise.
1317 //! The TRequestStatus objects associated with the cancel operations should all exibit KErrNone - exits otherwise
1319 //! 15) The TRequestStatus objects associated with the modify operations should all exibit KErrNone - exits otherwise.
1320 //! The TRequestStatus objects associated with the cancel operations should all exibit KErrNone - exits otherwise
1322 //! 16) The TRequestStatus objects associated with the get operations should all exibit KErrCancel - exits otherwise.
1323 //! The TRequestStatus objects associated with the modify operations should all exibit KErrNone - exits otherwise
1325 //! 17) The TRequestStatus objects associated with the get operations should all exibit KErrNone - exits otherwise.
1326 //! The TRequestStatus objects associated with the modify operations should all exibit KErrCancel - exits otherwise
1328 //! 18) The TRequestStatus objects associated with the get and modify operations should all exibit KErrNone - exits otherwise.
1330 //! 19) The TRequestStatus objects associated with the get and modify operations should all exibit KErrNone - exits otherwise.
1332 //! 20) The TRequestStatus objects associated with the even-numbered request should exhibit KErrCancel.
1333 //! The TRequestStatus objects associated with the odd-numbered request should exhibit KErrNone.
1335 //! @SYMTestPriority High
1336 //! @SYMTestStatus Implemented
1337 //----------------------------------------------------------------------------------------------
1338 LOCAL_C TInt TestGetSetResourceStateOps()
1340 // Test resource state access methods
1345 TRequestStatus status;
1346 TBool cached = gUseCached;
1348 TInt levelOwnerId = 0;
1352 // Ensure we have a resource we can use
1353 if((r=SetAsyncResource())!=KErrNone)
1357 // 0) Call API to get the initial state of a selected resource.
1358 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1359 gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
1360 User::WaitForRequest(status);
1361 if(status.Int() != KErrNone)
1363 gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r);
1366 TUint startingLevel = (TUint)readValue;
1367 gTest.Printf(_L("TestGetSetResourceStateOps: initial level read =0x%x, levelOwnerId = %d\n"),readValue,levelOwnerId);
1369 // 1) Call API to modify the state of the resource.
1370 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1371 TUint newLevel = (TUint)(readValue + gAsyncResStateDelta);
1372 gTest.Printf(_L("TestGetSetResourceStateOps: writing 0x%x\n"), newLevel);
1373 gChannel.ChangeResourceState(status,gLongLatencyResource,newLevel);
1374 User::WaitForRequest(status);
1375 if(status.Int() != KErrNone)
1377 gTest.Printf(_L("TestGetSetResourceStateOps, first change state returned %d\n"),r);
1381 // 2) Call API to get the new state of the resource and check it exhibits the expected value.
1382 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1383 gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
1384 User::WaitForRequest(status);
1385 if(status.Int() != KErrNone)
1387 gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r);
1390 gTest.Printf(_L("TestGetSetResourceStateOps: level read back =0x%x, levelOwnerId=%d\n"),readValue,levelOwnerId);
1391 gTest(newLevel==(TUint)readValue);
1393 // 3) Call API to return the resource state to its original value.
1394 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1395 gTest.Printf(_L("TestGetSetResourceStateOps: write original level 0x%x\n"), startingLevel);
1396 gChannel.ChangeResourceState(status,gLongLatencyResource,startingLevel);
1397 User::WaitForRequest(status);
1398 if(status.Int() != KErrNone)
1400 gTest.Printf(_L("TestGetSetResourceStateOps, change state status = %d\n"),r);
1403 gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
1404 User::WaitForRequest(status);
1405 if(status.Int() != KErrNone)
1407 gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r);
1410 gTest.Printf(_L("TestGetSetResourceStateOps: check original level read back =0x%x, levelOwnerId=%d\n"),readValue,levelOwnerId);
1412 // 4) Call API to get the state of a long latency resource then call API with operation-type qualifier cancel the request.
1413 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1414 gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
1415 r=gChannel.CancelGetResourceState(status);
1418 gTest.Printf(_L("TestGetSetResourceStateOps, CancelGetResourceState returned %d\n"),r);
1420 if(r!=KErrCompletion) // If request had not completed before cancellation request
1422 User::WaitForRequest(status);
1423 if(r==KErrNone) // Cancel expected to proceed as requested
1425 if(status.Int() != KErrCancel)
1427 gTest.Printf(_L("TestGetSetResourceStateOps, expected KErrCancel but cancelled get state status = %d\n"),r);
1431 else if(r==KErrInUse) // Cancel failed since request was being processed - so expect successful completion
1433 if(status.Int() != KErrNone)
1435 gTest.Printf(_L("TestGetSetResourceStateOps, expected KErrNone but cancelled get state status = %d\n"),r);
1439 else if(status.Int() != KErrCancel) // Just report the error code and return
1441 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status = %d\n"),r);
1447 // 5) Call API to modify the state of the long latency resource then call API with operation-type qualifier to cancel the request.
1448 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1449 newLevel = (TUint)(readValue + gAsyncResStateDelta);
1450 gChannel.ChangeResourceState(status,gLongLatencyResource,newLevel);
1451 r=gChannel.CancelChangeResourceState(status);
1454 gTest.Printf(_L("TestGetSetResourceStateOps, CancelChangeResourceState returned %d\n"),r);
1456 if(r!=KErrCompletion) // If request had not completed before cancellation request
1458 User::WaitForRequest(status);
1459 if(r==KErrNone) // Cancel expected to proceed as requested
1461 if(status.Int() != KErrCancel)
1463 gTest.Printf(_L("TestGetSetResourceStateOps, expected KErrCancel but cancelled get state status = %d\n"),r);
1467 else if(r==KErrInUse) // Cancel failed since request was being processed - so expect successful completion
1469 if(status.Int() != KErrNone)
1471 gTest.Printf(_L("TestGetSetResourceStateOps, expected KErrNone but cancelled get state status = %d\n"),r);
1475 else if(status.Int() != KErrCancel) // Just report the error code and return
1477 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status = %d\n"),r);
1483 // 6) Call API to get the state of a long latency resource and wait for it to complete.
1484 // Then call API with operation-type qualifier to cancel the request.
1485 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1486 gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
1487 User::WaitForRequest(status);
1488 if(status.Int() != KErrNone)
1490 gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r);
1493 r=gChannel.CancelGetResourceState(status);
1496 gTest.Printf(_L("TestGetSetResourceStateOps, CancelGetResourceState returned %d\n"),r);
1498 if(status.Int() != KErrNone) // TRequestStatus should be unchanged
1500 gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled get state status = %d\n"),r);
1504 // 7) Call API to modify the state of the long latency resource and wait for it to complete.
1505 // Then call API with operation-type qualifier to cancel the request.
1506 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1507 gChannel.ChangeResourceState(status,gLongLatencyResource,(readValue + gAsyncResStateDelta));
1508 User::WaitForRequest(status);
1509 if(status.Int() != KErrNone)
1511 gTest.Printf(_L("TestGetSetResourceStateOps, change state status = %d\n"),r);
1514 r=gChannel.CancelChangeResourceState(status);
1517 gTest.Printf(_L("TestGetSetResourceStateOps, CancelChangeResourceState returned %d\n"),r);
1519 if(status.Int() != KErrNone) // TRequestStatus should be unchanged
1521 gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled change state status = %d\n"),r);
1525 // 8) Call API to get the state of a long latency resource then call API without operation-type qualifier to cancel the request.
1526 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1527 gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
1528 gChannel.CancelAsyncOperation(&status);
1529 User::WaitForRequest(status);
1530 if(status.Int() != KErrCancel)
1532 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status = %d\n"),r);
1536 // 9) Call API to modify the state of the long latency resource then call API without operation-type qualifier to cancel the request.
1537 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1538 newLevel = (TUint)(readValue + gAsyncResStateDelta);
1539 gChannel.ChangeResourceState(status,gLongLatencyResource,newLevel);
1540 gChannel.CancelAsyncOperation(&status);
1541 User::WaitForRequest(status);
1542 if(status.Int() != KErrCancel)
1544 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status = %d\n"),r);
1548 // 10) Call API to get the state of a long latency resource and wait for it to complete.
1549 // Then call API without operation-type qualifier to cancel the request.
1550 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1551 gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
1552 User::WaitForRequest(status);
1553 if(status.Int() != KErrNone)
1555 gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r);
1558 gChannel.CancelAsyncOperation(&status);
1559 if(status.Int() != KErrNone) // TRequestStatus should be unchanged
1561 gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled get state status = %d\n"),r);
1565 // 11) Call API to modify the state of the long latency resource and wait for it to complete.
1566 // Then call API without operation-type qualifier to cancel the request.
1567 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1568 gChannel.ChangeResourceState(status,gLongLatencyResource,(readValue + gAsyncResStateDelta));
1569 User::WaitForRequest(status);
1570 if(status.Int() != KErrNone)
1572 gTest.Printf(_L("TestGetSetResourceStateOps, change state status = %d\n"),r);
1575 gChannel.CancelAsyncOperation(&status);
1576 if(status.Int() != KErrNone) // TRequestStatus should be unchanged
1578 gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled change state status = %d\n"),r);
1582 // 'n' and 'm' values and support for cancellation of multiple requests
1583 const TInt KLoopVarN = 2;
1584 const TInt KLoopVarM = 3;
1585 TRequestStatus getReqStatus[KLoopVarN];
1586 TRequestStatus setReqStatus[KLoopVarM];
1589 // 12) Call API to get the state of a long latency resource 'n' times.
1590 // Then call API with resource qualifier to cancel the requests.
1591 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1592 for(i=0;i<KLoopVarN;i++)
1594 gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId);
1596 gChannel.CancelGetResourceStateRequests(gLongLatencyResource);
1597 for(i=0;i<KLoopVarN;i++)
1599 User::WaitForRequest(getReqStatus[i]);
1600 if((r=getReqStatus[i].Int()) != KErrCancel)
1602 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status[%d] = %d\n"),i,r);
1607 // 13) Call API to modify the state of a long latency resource 'm' times.
1608 // Then call API with resource qualifier to cancel the requests.
1609 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1610 for(i=0;i<KLoopVarM;i++)
1612 gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta));
1614 gChannel.CancelChangeResourceStateRequests(gLongLatencyResource);
1615 for(i=0;i<KLoopVarM;i++)
1617 User::WaitForRequest(setReqStatus[i]);
1618 if((r=setReqStatus[i].Int()) != KErrCancel)
1620 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status[%d] = %d\n"),i,r);
1625 // 14) Call API to get the state of a long latency resource 'n' times and wait for them to complete.
1626 // Then call API with resource qualifier to cancel the requests.
1627 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1628 for(i=0;i<KLoopVarN;i++)
1630 gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId);
1632 for(i=0;i<KLoopVarN;i++)
1634 User::WaitForRequest(getReqStatus[i]);
1635 if((r=getReqStatus[i].Int()) != KErrNone)
1637 gTest.Printf(_L("TestGetSetResourceStateOps, before cancel get state status[%d] = %d\n"),i,r);
1641 gChannel.CancelGetResourceStateRequests(gLongLatencyResource);
1642 for(i=0;i<KLoopVarN;i++)
1644 if((r=getReqStatus[i].Int()) != KErrNone)
1646 gTest.Printf(_L("TestGetSetResourceStateOps, after cancel get state status[%d] = %d\n"),i,r);
1651 // 15) Call API to modify the state of a long latency resource 'm' times and wait for them to complete.
1652 // Then call API with resource qualifier to cancel the requests.
1653 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1654 for(i=0;i<KLoopVarM;i++)
1656 gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta));
1658 for(i=0;i<KLoopVarM;i++)
1660 User::WaitForRequest(setReqStatus[i]);
1661 if((r=setReqStatus[i].Int()) != KErrNone)
1663 gTest.Printf(_L("TestGetSetResourceStateOps, before cancel change state status[%d] = %d\n"),i,r);
1667 gChannel.CancelChangeResourceStateRequests(gLongLatencyResource);
1668 for(i=0;i<KLoopVarM;i++)
1670 if((r=setReqStatus[i].Int()) != KErrNone)
1672 gTest.Printf(_L("TestGetSetResourceStateOps, after cancel change state status[%d] = %d\n"),i,r);
1677 // 16) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
1678 // a long latency resource 'm' times.
1679 // Call the API to cancel the get operations with resource qualifier.
1680 // Wait for the operations to complete. Check the state of the associated TRequestStatus objects.
1681 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1682 for(i=0;i<KLoopVarN;i++)
1684 gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId);
1686 for(i=0;i<KLoopVarM;i++)
1688 gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta));
1690 gChannel.CancelGetResourceStateRequests(gLongLatencyResource);
1691 for(i=0;i<KLoopVarN;i++)
1693 User::WaitForRequest(getReqStatus[i]);
1694 if((r=getReqStatus[i].Int()) != KErrCancel)
1696 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status[%d] = %d\n"),i,r);
1700 for(i=0;i<KLoopVarM;i++)
1702 User::WaitForRequest(setReqStatus[i]);
1703 if((r=setReqStatus[i].Int()) != KErrNone)
1705 gTest.Printf(_L("TestGetSetResourceStateOps, completed change state status[%d] = %d\n"),i,r);
1710 // 17) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
1711 // a long latency resource 'm' times.
1712 // Call the API to cancel the modify operations with resource qualifier.
1713 // Wait for the get operations to complete. Check the state of the associated TRequestStatus objects.
1714 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1715 for(i=0;i<KLoopVarN;i++)
1717 gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId);
1719 for(i=0;i<KLoopVarM;i++)
1721 gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta));
1723 gChannel.CancelChangeResourceStateRequests(gLongLatencyResource);
1724 for(i=0;i<KLoopVarN;i++)
1726 User::WaitForRequest(getReqStatus[i]);
1727 if((r=getReqStatus[i].Int()) != KErrNone)
1729 gTest.Printf(_L("TestGetSetResourceStateOps, completed get state status[%d] = %d\n"),i,r);
1733 for(i=0;i<KLoopVarM;i++)
1735 User::WaitForRequest(setReqStatus[i]);
1736 if((r=setReqStatus[i].Int()) != KErrCancel)
1738 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status[%d] = %d\n"),i,r);
1743 // 18) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
1744 // a long latency resource 'm' times. Wait for the get operations to complete.
1745 // Call the API to cancel the get operations with resource qualifier. Check the state of the associated TRequestStatus objects.
1746 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1747 for(i=0;i<KLoopVarN;i++)
1749 gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId);
1752 for(i=0;i<KLoopVarM;i++)
1754 gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + (flipper*gAsyncResStateDelta)));
1757 for(i=0;i<KLoopVarN;i++)
1759 User::WaitForRequest(getReqStatus[i]);
1760 if((r=getReqStatus[i].Int()) != KErrNone)
1762 gTest.Printf(_L("TestGetSetResourceStateOps, completed get state status[%d] = %d\n"),i,r);
1766 gChannel.CancelGetResourceStateRequests(gLongLatencyResource);
1767 for(i=0;i<KLoopVarM;i++)
1769 User::WaitForRequest(setReqStatus[i]);
1770 if((r=setReqStatus[i].Int()) != KErrNone)
1772 gTest.Printf(_L("TestGetSetResourceStateOps, completed change state status[%d]= %d\n"),i,r);
1776 for(i=0;i<KLoopVarN;i++)
1778 if((r=getReqStatus[i].Int()) != KErrNone)
1780 gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled get state status[%d]= %d\n"),i,r);
1785 // 19) Call API to get the state of a long latency resource 'n' times, call API to modify the state of
1786 // a long latency resource 'm' times. Wait for the modify operations to complete. Call the API to cancel the modify
1787 // operations with resource qualifier. Check the state of the associated TRequestStatus objects.
1788 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1789 for(i=0;i<KLoopVarN;i++)
1791 gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId);
1793 for(i=0;i<KLoopVarM;i++)
1795 gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta));
1797 for(i=0;i<KLoopVarM;i++)
1799 User::WaitForRequest(setReqStatus[i]);
1800 if((r=setReqStatus[i].Int()) != KErrNone)
1802 gTest.Printf(_L("TestGetSetResourceStateOps, completed change state status[%d] = %d\n"),i,r);
1806 gChannel.CancelChangeResourceStateRequests(gLongLatencyResource);
1807 for(i=0;i<KLoopVarN;i++)
1809 User::WaitForRequest(getReqStatus[i]);
1810 if((r=getReqStatus[i].Int()) != KErrNone)
1812 gTest.Printf(_L("TestGetSetResourceStateOps, completed get state status[%d] = %d\n"),i,r);
1816 for(i=0;i<KLoopVarM;i++)
1818 if((r=setReqStatus[i].Int()) != KErrNone)
1820 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status[%d] = %d\n"),i,r);
1825 // 20) Call API to get the state of a long latency resource 'n' times, call API to modify the state of a long latency resource 'm' times.
1826 // Then call API without operation-type qualifier to cancel the even-numbered modify request(s).
1827 // Then call API with operation-type qualifier to cancel the even-numbered get request(s).
1828 // Check the state of the associated TRequestStatus objects.
1829 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
1830 for(i=0;i<KLoopVarN;i++)
1832 gChannel.GetResourceState(getReqStatus[i],gLongLatencyResource,cached,&readValue,&levelOwnerId);
1834 for(i=0;i<KLoopVarM;i++)
1836 gChannel.ChangeResourceState(setReqStatus[i],gLongLatencyResource,(readValue + gAsyncResStateDelta));
1838 for(i=0;i<KLoopVarM;i+=2)
1840 gChannel.CancelAsyncOperation(&(setReqStatus[i]));
1842 for(i=0;i<KLoopVarN;i+=2)
1844 r=gChannel.CancelGetResourceState(getReqStatus[i]);
1847 gTest.Printf(_L("TestGetSetResourceStateOps, CancelGetResourceState for index %d returned %d\n"),i,r);
1851 for(i=0;i<KLoopVarM;i++)
1853 User::WaitForRequest(setReqStatus[i]);
1854 if((r=setReqStatus[i].Int()) != KErrCancel)
1856 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status[%d] = %d\n"),i,r);
1859 if(++i >= KLoopVarM)
1861 User::WaitForRequest(setReqStatus[i]);
1862 if((r=setReqStatus[i].Int()) != KErrNone)
1864 gTest.Printf(_L("TestGetSetResourceStateOps, completed change state status[%d] = %d\n"),i,r);
1868 for(i=0;i<KLoopVarN;i++)
1870 User::WaitForRequest(getReqStatus[i]);
1871 if((r=getReqStatus[i].Int()) != KErrCancel)
1873 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status[%d] = %d\n"),i,r);
1876 if(++i >= KLoopVarN)
1878 User::WaitForRequest(getReqStatus[i]);
1879 if((r=getReqStatus[i].Int()) != KErrNone)
1881 gTest.Printf(_L("TestGetSetResourceStateOps, completed get state status[%d] = %d\n"),i,r);
1889 //----------------------------------------------------------------------------------------------
1890 //! @SYMTestCaseID KBASE-T_RESMANUS-0611
1892 //! @SYMPREQ PREQ1398
1893 //! @SYMTestCaseDesc This test case tests APIs for regulating getting and setting the state of resources
1895 //! @SYMTestActions 0) Issue the maximum number (requested in the call to the Initialise API)
1896 //! of requests to get the current state of a resource. Then issue one further request.
1898 //! 1) Issue the maximum number (requested in the call to the Initialise API) of
1899 //! requests to set the current state of a resource. Then issue one further request.
1901 //! @SYMTestExpectedResults 0) Test that the TRequestStatus object associated with the last request
1902 //! exhibits status code KErrUnderflow - exit otherwise. Test that the
1903 //! TRequestStatus objects associated with the preceding requests exhibit
1904 //! status code KErrNone - exit otherwise.
1906 //! 1) Test that the TRequestStatus object associated with the last request
1907 //! exhibits status code KErrUnderflow - exit otherwise. Test that the
1908 //! TRequestStatus objects associated with the preceding requests exhibit
1909 //! status code KErrNone - exit otherwise.
1911 //! @SYMTestPriority High
1912 //! @SYMTestStatus Implemented
1913 //----------------------------------------------------------------------------------------------
1914 LOCAL_C TInt TestGetSetResourceStateQuota()
1916 // Test resource state access quota management
1921 // To perform the quota test we need a long latency resource
1922 // If one has not been defined alert the user and return
1925 gTest.Printf(_L("TestGetSetResourceStateQuota: don't have suitable asynchronous resource ... exiting\n"));
1929 resourceId = gLongLatencyResource;
1932 TBool lastErr = KErrNone;
1935 TRequestStatus status[MAX_NUM_REQUESTS];
1936 TInt state[MAX_NUM_REQUESTS];
1937 TBool cached = gUseCached;
1938 TInt levelOwnerId = 0;
1941 // Test GetResourceState - check client can not exceed quota of requests
1943 gTest.Printf(_L("**Test GetResourceState (quota management)\n"));
1945 // KNoOfGetStateRequests Get state requests (of the same resource, ID=1) to consume the client quota
1946 for(i=0; i<KNoOfGetStateRequests; i++)
1947 gChannel.GetResourceState(status[i],resourceId,cached,&(state[i]),&levelOwnerId);
1949 // Addition Get state request to exceed the quota - the provided TRequestStatus
1950 // object should indicate KErrUnderflow
1951 gChannel.GetResourceState(status[KNoOfGetStateRequests],resourceId,cached,&(state[KNoOfGetStateRequests]),&levelOwnerId);
1952 User::WaitForRequest(status[KNoOfGetStateRequests]);
1953 if(status[KNoOfGetStateRequests].Int() != KErrUnderflow)
1955 gTest.Printf(_L("TestGetSetResourceStateQuota, extra get state returned %d\n"),r);
1959 // Need to check the TRequestStatus objects
1960 for(i=0; i<KNoOfGetStateRequests; i++)
1962 User::WaitForRequest(status[i]);
1963 if((r=status[i].Int()) != KErrNone)
1965 gTest.Printf(_L("TestGetSetResourceStateQuota, get state %d returned %d\n"),i, r);
1969 if(lastErr != KErrNone)
1973 // Test ChangeResourceState - check client can not exceed quota of requests
1975 gTest.Printf(_L("**Test ChangeResourceState (quota management)\n"));
1977 // KNoOfSetStateRequests Set state requests (of the same resource, ID=1) to consume the client quota
1978 TInt newState = (state[1])+1;
1979 for(i=0; i<KNoOfSetStateRequests; i++)
1981 gChannel.ChangeResourceState(status[i],resourceId,newState);
1984 // Addition Set state request to exceed the quota - the provided TRequestStatus
1985 // object should indicate KErrUnderflow
1986 gChannel.ChangeResourceState(status[KNoOfSetStateRequests],resourceId,newState);
1987 User::WaitForRequest(status[KNoOfSetStateRequests]);
1988 if(status[KNoOfSetStateRequests].Int() != KErrUnderflow)
1990 gTest.Printf(_L("TestGetSetResourceStateQuota, extra set state returned %d\n"),r);
1994 // Need to check the TRequestStatus objects
1995 for(i=0; i<KNoOfSetStateRequests; i++)
1997 User::WaitForRequest(status[i]);
1998 if((r=status[i].Int()) != KErrNone)
2000 gTest.Printf(_L("TestGetSetResourceStateQuota, set state %d returned %d\n"),i, r);
2004 if(lastErr != KErrNone)
2011 LOCAL_C TInt TriggerNotification(TRequestStatus& aStatus, TUint aResourceId, TBool aCached, TInt aDelta)
2013 // Support the notification tests - cause a notification for the specified resource
2018 TInt levelOwnerId = 0;
2019 // Get initial state
2020 gChannel.GetResourceState(aStatus,aResourceId,aCached,&readValue,&levelOwnerId);
2021 User::WaitForRequest(aStatus);
2022 if(aStatus.Int() != KErrNone)
2025 gTest.Printf(_L("TriggerNotification, get state returned %d\n"),r);
2028 TUint startingLevel = (TUint)readValue;
2030 // Write updated state
2031 TUint newLevel = (TUint)(readValue + aDelta);
2032 gTest.Printf(_L("TriggerNotification: startingLevel=0x%x, writing 0x%x\n"), startingLevel, newLevel);
2033 gChannel.ChangeResourceState(aStatus,aResourceId,newLevel);
2034 User::WaitForRequest(aStatus);
2035 if(aStatus.Int() != KErrNone)
2038 gTest.Printf(_L("TriggerNotification, change state returned %d\n"),r);
2046 LOCAL_C TInt CalcNotifyDirAndThr(TRequestStatus& aStatus, TUint aResourceId, TBool aCached, TInt& aThreshold, TBool& aDirection)
2048 // Support the notification tests - determine an appropriate threshold and direction to request
2053 // Need to know current state
2056 TInt levelOwnerId = 0;
2058 gChannel.GetResourceState(aStatus,aResourceId,aCached,&readValue,&levelOwnerId);
2059 User::WaitForRequest(aStatus);
2060 if(aStatus.Int() != KErrNone)
2063 gTest.Printf(_L("TestNotificationOps, pre-qualified notify get state returned %d\n"),r);
2067 aThreshold = readValue + gAsyncResStateDelta;
2068 aDirection=(gAsyncResStateDelta>0)?ETrue:EFalse;
2076 //----------------------------------------------------------------------------------------------
2077 //! @SYMTestCaseID KBASE-T_RESMANUS-0612
2079 //! @SYMPREQ PREQ1398
2080 //! @SYMTestCaseDesc This test case tests APIs for requesting both qualified and unqualified
2081 //! notifications; it also tests APIs to cancel such requests.
2083 //! @SYMTestActions 0) Call API to request notification of an unqualified change in resource
2084 //! state for a selected resource. Trigger a state change.
2086 //! 1) Call API to request notification of a qualified change in resource
2087 //! state for a selected resource. Trigger a state change.
2089 //! 2) Call API to request notification of an unqualified change in resource
2090 //! state for a selected resource. Then call API to cancel all notifications for the resource.
2092 //! 3) Call API to request notification of a qualified change in resource
2093 //! state for a selected resource. Then call API to cancel all notifications for the resource.
2095 //! 4) Call API to request notification of an unqualified change in resource
2096 //! state for a selected resource. Trigger a state change. Then call API to cancel all
2097 //! notifications for the resource.
2099 //! 5) Call API to request notification of a qualified change in resource
2100 //! state for a selected resource. Trigger a state change. Then call API to cancel all
2101 //! notifications for the resource.
2103 //! 6) Call API to request notification of an unqualified change in resource
2104 //! state for a selected resource. Then call API to cancel the notification request
2106 //! 7) Call API to request notification of a qualified change in resource
2107 //! state for a selected resource. Then call API to cancel the notification request
2109 //! 8) Call API to request notification of an unqualified change in resource
2110 //! state for a selected resource. Trigger a state change. Then call API to cancel the
2111 //! notification request
2113 //! 9) Call API to request notification of a qualified change in resource
2114 //! state for a selected resource. Trigger a state change. Then call API to cancel the
2115 //! notification request
2117 //! 10) Call API to request notification of an unqualified change in resource
2118 //! state for a selected resource. Then call API to cancel generic async request
2120 //! 11) Call API to request notification of a qualified change in resource
2121 //! state for a selected resource. Then call API to cancel generic async request
2123 //! 12) Call API to request notification of an unqualified change in resource
2124 //! state for a selected resource. Trigger a state change. Then call API to cancel
2125 //! generic async request
2127 //! 13) Call API to request notification of a qualified change in resource
2128 //! state for a selected resource. Trigger a state change. Then call API to cancel
2129 //! generic async request
2131 //! @SYMTestExpectedResults 0) The associated TRequestStatus object should indicate KErrNone
2132 //! - exits otherwise.
2134 //! 1) The associated TRequestStatus object should indicate KErrNone
2135 //! - exits otherwise.
2137 //! 2) The associated TRequestStatus object should indicate KErrCancel
2138 //! - exits otherwise.
2140 //! 3) The associated TRequestStatus object should indicate KErrCancel
2141 //! - exits otherwise.
2143 //! 4) The TRequestStatus object should indicate state KRequestPending until
2144 //! the state change is triggered, upon which it should exhibit state
2145 //! KErrNone. After the cancellation it should still exhibit state KErrNone.
2146 //! Exit for any deviation from this behaviour.
2148 //! 5) The TRequestStatus object should indicate state KRequestPending until
2149 //! the state change is triggered, upon which it should exhibit state
2150 //! KErrNone. After the cancellation it should still exhibit state KErrNone.
2151 //! Exit for any deviation from this behaviour.
2153 //! 6) The associated TRequestStatus object should indicate KErrCancel
2154 //! - exits otherwise.
2156 //! 7) The associated TRequestStatus object should indicate KErrCancel
2157 //! - exits otherwise.
2159 //! 8) The TRequestStatus object should indicate state KRequestPending until
2160 //! the state change is triggered, upon which it should exhibit state
2161 //! KErrNone. After the cancellation it should still exhibit state KErrNone.
2162 //! Exit for any deviation from this behaviour.
2164 //! 9) The TRequestStatus object should indicate state KRequestPending until
2165 //! the state change is triggered, upon which it should exhibit state
2166 //! KErrNone. After the cancellation it should still exhibit state KErrNone.
2167 //! Exit for any deviation from this behaviour.
2169 //! 10) The associated TRequestStatus object should indicate KErrCancel
2170 //! - exits otherwise.
2172 //! 11) The associated TRequestStatus object should indicate KErrCancel
2173 //! - exits otherwise.
2175 //! 12) The TRequestStatus object should indicate state KRequestPending until
2176 //! the state change is triggered, upon which it should exhibit state
2177 //! KErrNone. After the cancellation it should still exhibit state KErrNone.
2178 //! Exit for any deviation from this behaviour.
2180 //! 13) The TRequestStatus object should indicate state KRequestPending until
2181 //! the state change is triggered, upon which it should exhibit state
2182 //! KErrNone. After the cancellation it should still exhibit state KErrNone.
2183 //! Exit for any deviation from this behaviour.
2185 //! @SYMTestPriority High
2186 //! @SYMTestStatus Implemented
2187 //----------------------------------------------------------------------------------------------
2188 LOCAL_C TInt TestNotificationOps()
2190 // Test notification methods
2196 TRequestStatus status;
2201 resourceId = 2; // Arbitrary
2202 stateDelta = 1; // Arbitrary
2206 resourceId = gLongLatencyResource;
2207 stateDelta = gAsyncResStateDelta;
2211 // 0) Call API to request notification of an unqualified change in resource
2212 // state for a selected resource. Trigger a state change.
2213 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
2214 gChannel.RequestNotification(status, resourceId);
2215 if(status.Int() != KRequestPending)
2217 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
2220 TBool cached = gUseCached;
2221 TRequestStatus triggerStatus;
2222 if((r=TriggerNotification(triggerStatus, resourceId, cached, stateDelta))!=KErrNone)
2224 User::WaitForRequest(status);
2225 if(status.Int()!=KErrNone)
2227 gTest.Printf(_L("TestNotificationOps: after TriggerNotification status = %d\n"),status.Int());
2231 // 1) Call API to request notification of a qualified change in resource
2232 // state for a selected resource. Trigger a state change.
2233 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
2234 TInt dumThreshold=0;
2235 TBool dumDirection=EFalse;
2236 if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
2238 gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection);
2239 if(status.Int() != KRequestPending)
2241 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
2244 // Pass gAsyncResStateDelta as this represents the delta value
2245 if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
2247 User::WaitForRequest(status);
2248 if(status.Int()!=KErrNone)
2250 gTest.Printf(_L("TestNotificationOps: after TriggerNotification status = %d\n"),status.Int());
2254 // 2) Call API to request notification of an unqualified change in resource
2255 // state for a selected resource. Then call API to cancel all notifications for the resource.
2256 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
2257 gChannel.RequestNotification(status, resourceId);
2258 if(status.Int() != KRequestPending)
2260 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
2263 r=gChannel.CancelNotificationRequests(resourceId);
2266 gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests returned %d\n"),r);
2269 User::WaitForRequest(status);
2270 if(status.Int()!=KErrCancel)
2272 gTest.Printf(_L("TestNotificationOps: after cancel basic request status = %d\n"),status.Int());
2276 // 3) Call API to request notification of a qualified change in resource
2277 // state for a selected resource. Then call API to cancel all notifications for the resource.
2278 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
2279 dumThreshold = 0; // Arbitrary
2280 dumDirection = ETrue; // Arbitrary
2281 if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
2283 gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection);
2284 if(status.Int() != KRequestPending)
2286 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
2289 r=gChannel.CancelNotificationRequests(resourceId);
2292 gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests (qualified) returned %d\n"),r);
2295 User::WaitForRequest(status);
2296 if(status.Int()!=KErrCancel)
2298 gTest.Printf(_L("TestNotificationOps: after qualified request cancel status = %d\n"),status.Int());
2302 // 4) Call API to request notification of an unqualified change in resource
2303 // state for a selected resource. Trigger a state change. Then call API to cancel all
2304 // notifications for the resource.
2305 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
2306 gChannel.RequestNotification(status, resourceId);
2307 if(status.Int() != KRequestPending)
2309 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
2312 // Pass gAsyncResStateDelta as this represents the delta value
2313 if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
2315 User::WaitForRequest(status);
2316 if(status.Int()!=KErrNone)
2318 gTest.Printf(_L("TestNotificationOps: trigger basic request before cancel, status = %d\n"),status.Int());
2321 r=gChannel.CancelNotificationRequests(resourceId);
2324 gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests returned %d\n"),r);
2327 if(status.Int()!=KErrNone)
2329 gTest.Printf(_L("TestNotificationOps: after cancel (completed) basic request status = %d\n"),status.Int());
2333 // 5) Call API to request notification of a qualified change in resource
2334 // state for a selected resource. Trigger a state change. Then call API to cancel all
2335 // notifications for the resource.
2336 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
2337 if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
2339 gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection);
2340 if(status.Int() != KRequestPending)
2342 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
2345 // Pass gAsyncResStateDelta as this represents the delta value
2346 if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
2348 User::WaitForRequest(status);
2349 if(status.Int()!=KErrNone)
2351 gTest.Printf(_L("TestNotificationOps: trigger qualified request before cancel, status = %d\n"),status.Int());
2354 r=gChannel.CancelNotificationRequests(resourceId);
2357 gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests (qualified) returned %d\n"),r);
2360 if(status.Int()!=KErrNone)
2362 gTest.Printf(_L("TestNotificationOps: after cancel (completed) qualified request status = %d\n"),status.Int());
2366 // 6) Call API to request notification of an unqualified change in resource
2367 // state for a selected resource. Then call API to cancel the notification request
2368 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
2369 gChannel.RequestNotification(status, resourceId);
2370 if(status.Int() != KRequestPending)
2372 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
2375 r=gChannel.CancelRequestNotification(status);
2378 gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests returned %d\n"),r);
2381 User::WaitForRequest(status);
2382 if(status.Int()!=KErrCancel)
2384 gTest.Printf(_L("TestNotificationOps: after cancel basic request status = %d\n"),status.Int());
2388 // 7) Call API to request notification of a qualified change in resource
2389 // state for a selected resource. Then call API to cancel the notification request
2390 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
2391 dumThreshold = 0; // Arbitrary
2392 dumDirection = ETrue; // Arbitrary
2393 if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
2395 gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection);
2396 if(status.Int() != KRequestPending)
2398 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
2401 r=gChannel.CancelRequestNotification(status);
2404 gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests (qualified) returned %d\n"),r);
2407 User::WaitForRequest(status);
2408 if(status.Int()!=KErrCancel)
2410 gTest.Printf(_L("TestNotificationOps: after qualified request cancel status = %d\n"),status.Int());
2414 // 8) Call API to request notification of an unqualified change in resource
2415 // state for a selected resource. Trigger a state change. Then call API to cancel the
2416 // notification request
2417 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
2418 gChannel.RequestNotification(status, resourceId);
2419 if(status.Int() != KRequestPending)
2421 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
2424 // Pass gAsyncResStateDelta as this represents the delta value
2425 if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
2427 User::WaitForRequest(status);
2428 if(status.Int()!=KErrNone)
2430 gTest.Printf(_L("TestNotificationOps: trigger basic request before cancel, status = %d\n"),status.Int());
2433 r=gChannel.CancelRequestNotification(status);
2436 gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests returned %d\n"),r);
2439 if(status.Int()!=KErrNone)
2441 gTest.Printf(_L("TestNotificationOps: after cancel (completed) basic request status = %d\n"),status.Int());
2445 // 9) Call API to request notification of a qualified change in resource
2446 // state for a selected resource. Trigger a state change. Then call API to cancel the
2447 // notification request
2448 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
2449 if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
2451 gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection);
2452 if(status.Int() != KRequestPending)
2454 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
2457 // Pass gAsyncResStateDelta as this represents the delta value
2458 if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
2460 User::WaitForRequest(status);
2461 if(status.Int()!=KErrNone)
2463 gTest.Printf(_L("TestNotificationOps: trigger qualified request before cancel, status = %d\n"),status.Int());
2466 r=gChannel.CancelRequestNotification(status);
2469 gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests (qualified) returned %d\n"),r);
2472 if(status.Int()!=KErrNone)
2474 gTest.Printf(_L("TestNotificationOps: after cancel (completed) qualified request status = %d\n"),status.Int());
2479 // 10) Call API to request notification of an unqualified change in resource
2480 // state for a selected resource. Then call API to cancel generic async request
2481 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
2482 gChannel.RequestNotification(status, resourceId);
2483 if(status.Int() != KRequestPending)
2485 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
2488 gChannel.CancelAsyncOperation(&status);
2489 User::WaitForRequest(status);
2490 if(status.Int()!=KErrCancel)
2492 gTest.Printf(_L("TestNotificationOps: after cancel basic request status = %d\n"),status.Int());
2496 // 11) Call API to request notification of a qualified change in resource
2497 // state for a selected resource. Then call API to cancel generic async request
2498 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
2499 dumThreshold = 0; // Arbitrary
2500 dumDirection = ETrue; // Arbitrary
2501 if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
2503 gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection);
2504 if(status.Int() != KRequestPending)
2506 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
2509 gChannel.CancelAsyncOperation(&status);
2510 User::WaitForRequest(status);
2511 if(status.Int()!=KErrCancel)
2513 gTest.Printf(_L("TestNotificationOps: after qualified request cancel status = %d\n"),status.Int());
2517 // 12) Call API to request notification of an unqualified change in resource
2518 // state for a selected resource. Trigger a state change. Then call API to cancel
2519 // generic async request
2520 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
2521 gChannel.RequestNotification(status, resourceId);
2522 if(status.Int() != KRequestPending)
2524 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
2527 // Pass gAsyncResStateDelta as this represents the delta value
2528 if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
2530 User::WaitForRequest(status);
2531 if(status.Int()!=KErrNone)
2533 gTest.Printf(_L("TestNotificationOps: trigger basic request before cancel, status = %d\n"),status.Int());
2536 gChannel.CancelAsyncOperation(&status);
2537 if(status.Int()!=KErrNone)
2539 gTest.Printf(_L("TestNotificationOps: after cancel (completed) basic request status = %d\n"),status.Int());
2543 // 13) Call API to request notification of a qualified change in resource
2544 // state for a selected resource. Trigger a state change. Then call API to cancel
2545 // generic async request
2546 gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++);
2547 if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
2549 gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection);
2550 if(status.Int() != KRequestPending)
2552 gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int());
2555 // Pass gAsyncResStateDelta as this represents the delta value
2556 if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
2558 User::WaitForRequest(status);
2559 if(status.Int()!=KErrNone)
2561 gTest.Printf(_L("TestNotificationOps: trigger qualified request before cancel, status = %d\n"),status.Int());
2564 gChannel.CancelAsyncOperation(&status);
2565 if(status.Int()!=KErrNone)
2567 gTest.Printf(_L("TestNotificationOps: after cancel (completed) qualified request status = %d\n"),status.Int());
2576 //----------------------------------------------------------------------------------------------
2577 //! @SYMTestCaseID KBASE-T_RESMANUS-0613
2579 //! @SYMPREQ PREQ1398
2580 //! @SYMTestCaseDesc This test case tests quota management for notification operations.
2582 //! @SYMTestActions 0) Issue the maximum number (requested in the call to the Initialise API)
2583 //! of requests for notification of unqualified changes to the state of a
2584 //! resource. Then issue one further request.
2586 //! 1) Issue the maximum number (requested in the call to the Initialise API)
2587 //! of requests for notification of qualified changes to the state of a
2588 //! resource. Then issue one further request.
2590 //! 2) Issue the maximum number (requested in the call to the Initialise API)
2591 //! of requests for notification changes to the state of a resource, where
2592 //! every odd request is for an unqualified change and every even request is
2593 //! for a qualified change. Then issue one further request.
2595 //! @SYMTestExpectedResults 0) Test that the TRequestStatus object associated with the last
2596 //! request exhibits status code KErrUnderflow - exit otherwise. Test
2597 //! that the TRequestStatus objects associated with the preceding requests
2598 //! exhibit status code KErrNone - exit otherwise.
2600 //! 1) Test that the TRequestStatus object associated with the last request
2601 //! exhibits status code KErrUnderflow - exit otherwise. Test that the
2602 //! TRequestStatus objects associated with the preceding requests exhibit
2603 //! status code KErrNone - exit otherwise.
2605 //! 2) Test that the TRequestStatus object associated with the last request
2606 //! exhibits status code KErrUnderflow - exit otherwise. Test that the
2607 //! TRequestStatus objects associated with the preceding requests exhibit
2608 //! status code KErrNone - exit otherwise.
2610 //! @SYMTestPriority High
2611 //! @SYMTestStatus Implemented
2612 //----------------------------------------------------------------------------------------------
2613 LOCAL_C TInt TestNotificationQuota()
2615 // Test notification request quota management
2621 TRequestStatus status[MAX_NUM_REQUESTS];
2623 TBool cached = gUseCached;
2624 TRequestStatus triggerStatus;
2625 TUint resourceId = gLongLatencyResource;
2627 // Test quota for basic operation
2629 // Loop to perform maximum number of requests, check TRequestStatus objects are pending
2630 for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++)
2632 gChannel.RequestNotification(status[loopVar], resourceId);
2633 if(status[loopVar].Int() != KRequestPending)
2635 gTest.Printf(_L("TestNotificationQuota: status not KRequestPending, =%d\n"),
2636 status[loopVar].Int());
2640 // Issue one more request, check that TRequestStatus object exhibits state KErrUnderflow
2641 gChannel.RequestNotification(status[KNoOfNotifyRequests], resourceId);
2642 if(status[KNoOfNotifyRequests].Int() != KErrUnderflow)
2644 gTest.Printf(_L("TestNotificationQuota: status[%d] not KErrUnderflow, =%d\n"),
2645 KNoOfNotifyRequests,status[loopVar].Int());
2648 // Loop to trigger previously-issued notifications, check TRequestStatus objects
2649 for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++)
2651 // Pass gAsyncResStateDelta as this represents the delta value
2652 if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
2654 User::WaitForRequest(status[loopVar]);
2655 if(status[loopVar].Int()!=KErrNone)
2657 gTest.Printf(_L("TestNotificationQuota: trigger basic request status[%d] = %d\n"),
2658 loopVar,status[loopVar].Int());
2664 // Test quota for qualified operation
2666 TInt dumThreshold = -25; // Arbitrary
2667 TBool dumDirection = ETrue; // Arbitrary
2669 // Loop to perform maximum number of requests, check TRequestStatus objects are pending
2670 for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++)
2672 if((r=CalcNotifyDirAndThr(status[loopVar], resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
2674 gChannel.RequestNotification(status[loopVar], resourceId, dumThreshold, dumDirection);
2675 if(status[loopVar].Int() != KRequestPending)
2677 gTest.Printf(_L("TestNotificationQuota: status[%d] not KRequestPending, =%d\n"),
2678 loopVar,status[loopVar].Int());
2682 // Issue one more request, check that TRequestStatus object exhibits state KErrUnderflow
2683 if((r=CalcNotifyDirAndThr(status[KNoOfNotifyRequests], resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
2685 gChannel.RequestNotification(status[KNoOfNotifyRequests], resourceId, dumThreshold, dumDirection);
2686 if(status[KNoOfNotifyRequests].Int() != KErrUnderflow)
2688 gTest.Printf(_L("TestNotificationQuota: status[%d] not KErrUnderflow, =%d\n"),
2689 KNoOfNotifyRequests,status[loopVar].Int());
2692 // Loop to trigger previously-issued notifications, check TRequestStatus objects
2693 for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++)
2695 // Pass gAsyncResStateDelta as this represents the delta value
2696 if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
2698 User::WaitForRequest(status[loopVar]);
2699 if(status[loopVar].Int()!=KErrNone)
2701 gTest.Printf(_L("TestNotificationQuota: trigger qualified request status[%d] = %d\n"),
2702 loopVar,status[loopVar].Int());
2707 // Text quota with mixture of basic and qualified requests
2709 TBool qualified = ETrue;
2710 // Issue requests and check TRequestStatus objects are pending
2711 for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++)
2715 if((r=CalcNotifyDirAndThr(status[loopVar], resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
2717 gChannel.RequestNotification(status[loopVar], resourceId, dumThreshold, dumDirection);
2721 gChannel.RequestNotification(status[loopVar], resourceId);
2723 qualified=!qualified;
2724 if(status[loopVar].Int() != KRequestPending)
2726 gTest.Printf(_L("TestNotificationQuota: mixed loop status[%d] not KRequestPending, =%d\n"),
2727 loopVar,status[loopVar].Int());
2731 // Issue one more request, check that TRequestStatus object exhibits state KErrUnderflow
2734 if((r=CalcNotifyDirAndThr(status[KNoOfNotifyRequests], resourceId, cached, dumThreshold, dumDirection))!=KErrNone)
2736 gChannel.RequestNotification(status[KNoOfNotifyRequests], resourceId, dumThreshold, dumDirection);
2740 gChannel.RequestNotification(status[KNoOfNotifyRequests], resourceId);
2742 if(status[KNoOfNotifyRequests].Int() != KErrUnderflow)
2744 gTest.Printf(_L("TestNotificationQuota: mixed loop status[%d] not KErrUnderflow, =%d\n"),
2745 KNoOfNotifyRequests,status[loopVar].Int());
2748 // Loop to trigger previously-issued notifications, check TRequestStatus objects
2749 for(loopVar=0; loopVar<KNoOfNotifyRequests; loopVar++)
2751 // Pass gAsyncResStateDelta as this represents the delta value
2752 if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone)
2754 User::WaitForRequest(status[loopVar]);
2755 if(status[loopVar].Int()!=KErrNone)
2757 gTest.Printf(_L("TestNotificationQuota: trigger mixed request status[%d] = %d\n"),
2758 loopVar,status[loopVar].Int());
2768 #ifdef PIRATE_THREAD_TESTS
2770 RThread PirateThread;
2771 TRequestStatus PirateStatus;
2772 const TInt KHeapSize=0x4000;
2773 const TInt KStackSize=0x4000;
2775 _LIT(KPirateThreadName,"Pirate");
2777 TInt PirateThreadFn(TAny* /*aSrcThread*/)
2781 RBusDevResManUs pirateChannel = gChannel;
2782 RThread& thread = *((RThread*)aSrcThread);
2784 /* 1 - pirate with current thread - Panics kernel with KErrBadHandle */
2785 if((r=pirateChannel.Duplicate(RThread(),EOwnerProcess))!=KErrAccessDenied)
2787 gTest.Printf(_L("TestThreadExclusiveAccess: pirateChannel.Duplicate(RThread(),EOwnerProcess) returned %d\n"),r);
2791 /* 2 - pirate with parent thread - Panics kernel with KErrBadHandle */
2792 pirateChannel = gChannel;
2793 if((r=pirateChannel.Duplicate(thread,EOwnerThread))!=KErrAccessDenied)
2795 gTest.Printf(_L("TestThreadExclusiveAccess: pirateChannel.Duplicate(thread,EOwnerThread) returned %d\n"),r);
2799 /* 3 - gChannel with current thread - Panics kernel with KErrBadHandle */
2800 if((r=gChannel.Duplicate(RThread(),EOwnerThread))!=KErrAccessDenied)
2802 gTest.Printf(_L("TestThreadExclusiveAccess: gChannel.Duplicate(RThread(),EOwnerThread) returned %d\n"),r);
2806 /* 4 - gChannel with parent thread - Panics kernel with KErrBadHandle */
2807 if((r=gChannel.Duplicate(thread,EOwnerThread))!=KErrAccessDenied)
2809 gTest.Printf(_L("TestThreadExclusiveAccess: gChannel.Duplicate(thread,EOwnerThread)returned %d\n"),r);
2814 // pirateChannel.Close();
2818 TInt StartPirate(RThread& aSrcThread)
2820 TAny* srcThread =(TAny*)(&aSrcThread);
2821 TInt r=PirateThread.Create(KPirateThreadName,PirateThreadFn,KStackSize,KHeapSize,KHeapSize,srcThread,EOwnerThread);
2824 PirateThread.Logon(PirateStatus);
2825 PirateThread.Resume();
2829 TInt WaitForPirateThread()
2831 User::WaitForRequest(PirateStatus);
2832 TInt exitType=PirateThread.ExitType();
2833 TInt exitReason=PirateThread.ExitReason();
2834 TBuf<16> exitCat=PirateThread.ExitCategory();
2835 if((exitType!= EExitKill)||(exitReason!=KErrNone))
2837 gTest.Printf(_L("Pirate thread error: %d\n"),PirateStatus.Int());
2838 gTest.Printf(_L("Thread exit reason: %d,%d,%S\n"),exitType,exitReason,&exitCat);
2841 PirateThread.Close();
2847 //----------------------------------------------------------------------------------------------
2848 //! @SYMTestCaseID KBASE-T_RESMANUS-0608
2850 //! @SYMPREQ PREQ1398
2851 //! @SYMTestCaseDesc This test case tests that channels can not be shared between threads.
2852 //! @SYMTestActions 0) Attempt to Duplicate the channel handle with EOwnerProcess as the owner type.
2854 //! 1) Attempt to Duplicate the channel handle with EOwnerThread
2856 //! @SYMTestExpectedResults 0) API should return with KErrAccessDenied, exits otherwise.
2857 //! 1) API should return with KErrNone, exits otherwise.
2859 //! @SYMTestPriority High
2860 //! @SYMTestStatus Implemented
2861 //----------------------------------------------------------------------------------------------
2862 LOCAL_C TInt TestThreadExclusiveAccess()
2864 // Test mechanism to prevent other threads accessing a channel
2870 RBusDevResManUs pirateChannel = gChannel;
2871 if((r=pirateChannel.Duplicate(RThread(),EOwnerProcess))!=KErrAccessDenied)
2873 gTest.Printf(_L("TestThreadExclusiveAccess: Duplicate with EOwnerProcess returned %d\n"),r);
2878 pirateChannel = gChannel;
2879 if((r=pirateChannel.Duplicate(RThread(),EOwnerThread))!=KErrNone)
2881 gTest.Printf(_L("TestThreadExclusiveAccess: Duplicate with EOwnerThread returned %d\n"),r);
2884 #ifdef PIRATE_THREAD_TESTS
2885 RThread& threadRef = RThread();
2886 if((r=StartPirate(threadRef))!=KErrNone)
2888 gTest.Printf(_L("TestThreadExclusiveAccess: StartPirate returned %d\n"),r);
2891 if((r=WaitForPirateThread())!=KErrNone)
2893 gTest.Printf(_L("TestThreadExclusiveAccess: WaitForPirateThread returned %d\n"),r);
2897 pirateChannel.Close();
2905 TRequestStatus Thrd2Status;
2906 const TInt KHeapSize=0x4000;
2907 const TInt KStackSize=0x4000;
2909 _LIT(KThrd2Name,"Thread2");
2912 TInt Thread2Fn(TAny* /* */)
2914 // Test that more than one thread can be supported
2921 _LIT(secThrdStr,"Thrd2Channel");
2922 TBufC<16> secThrdName(secThrdStr);
2923 // API accepts 8-bit descriptors, only - so convert name accordingly
2924 TBuf8<MAX_RESOURCE_NAME_LENGTH+1>EightBitName;
2925 EightBitName.Copy(secThrdName);
2926 RBusDevResManUs secThrdChannel;
2927 if((r=secThrdChannel.Open(EightBitName))!=KErrNone)
2930 // Read the resource information
2932 TUint numResources=0;
2933 if((r=secThrdChannel.GetNoOfResources(numResources))!=KErrNone)
2936 // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects
2937 // and reference via an RSimplePointerArray
2938 TUint bufSize = numResources;
2939 RSimplePointerArray<TResourceInfoBuf> resPtrs(bufSize);
2940 for(TUint i=0;i<bufSize;i++)
2942 TResourceInfoBuf *info = new TResourceInfoBuf();
2943 if((r=resPtrs.Insert(info, i))!=KErrNone)
2947 TUint updateNumResources=numResources;
2948 if((r=secThrdChannel.GetAllResourcesInfo(&resPtrs,updateNumResources))!=KErrNone)
2953 // Read current client information
2956 TUint numAllClients=0;
2958 // GetNoOfClients - with default aIncludeKern=EFalse
2960 if((r=secThrdChannel.GetNoOfClients(numClients,EFalse)) != KErrNone)
2963 // GetNoOfClients - with aIncludeKern=ETrue
2965 r=secThrdChannel.GetNoOfClients(numAllClients, ETrue);
2966 #ifdef RESMANUS_KERN
2969 if(r!=KErrPermissionDenied)
2973 // Need a buffer big enough to contain numClients instances of TClientName
2974 // To support the GetNamesAllClients testing, instantiate TClientName objects
2975 // and reference via an RSimplePointerArray
2976 TUint resBufSize = (numAllClients>numClients)?numAllClients:numClients;
2977 RSimplePointerArray<TClientName> infoPtrs(resBufSize);
2978 for(TUint j=0;j<resBufSize;j++)
2980 TClientName *info = new TClientName();
2981 if((r=infoPtrs.Insert(info, j))!=KErrNone)
2985 // GetNamesAllClients - with aIncludeKern=EFalse
2987 if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numClients, EFalse)) != KErrNone)
2990 // GetNamesAllClients - with aIncludeKern=ETrue
2992 #ifdef RESMANUS_KERN
2993 if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numAllClients, ETrue)) != KErrNone)
2996 if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numClients, ETrue)) != KErrPermissionDenied)
3003 r=KErrNone; // Ensure misleading result is not propagated
3007 // If we don't have a shared resource identified, skip the remaining tests
3010 // Register with the Resource Controller
3012 if ((r=secThrdChannel.Initialise(1,1,0))!=KErrNone) // Just need 1 get and 1 set state
3014 // Set a level on the shared resource
3016 // Get initial state
3017 TRequestStatus status;
3018 TBool cached = gUseCached;
3021 secThrdChannel.GetResourceState(status,gSharedResource,cached,&readValue,&levelOwnerId);
3022 User::WaitForRequest(status);
3026 // Write updated state
3027 TUint newLevel = (TUint)(readValue + gSharedResStateDelta);
3028 secThrdChannel.ChangeResourceState(status,gSharedResource,newLevel);
3029 User::WaitForRequest(status);
3034 // Read current client information
3039 // GetNoOfClients - with default aIncludeKern=EFalse
3041 if((r=secThrdChannel.GetNoOfClients(numClients,EFalse)) != KErrNone)
3044 // GetNoOfClients - with aIncludeKern=ETrue
3046 #ifdef RESMANUS_KERN
3047 if((r=secThrdChannel.GetNoOfClients(numAllClients, ETrue))!=KErrNone)
3049 if((r=secThrdChannel.GetNoOfClients(numAllClients, ETrue))!=KErrPermissionDenied)
3053 // Need a buffer big enough to contain numClients instances of TClientName
3054 // To support the GetNamesAllClients testing, instantiate TClientName objects
3055 // and reference via an RSimplePointerArray
3056 TUint bufSize = (numAllClients>numClients)?numAllClients:numClients;
3057 RSimplePointerArray<TClientName> infoPtrs(bufSize);
3058 for(TUint i=0;i<bufSize;i++)
3060 TClientName *info = new TClientName();
3061 if((r=infoPtrs.Insert(info, i))!=KErrNone)
3065 // GetNamesAllClients - with aIncludeKern=EFalse
3067 if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numClients, EFalse)) != KErrNone)
3070 // GetNamesAllClients - with aIncludeKern=ETrue
3072 #ifdef RESMANUS_KERN
3073 if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numAllClients, ETrue)) != KErrNone)
3076 if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numClients, ETrue)) != KErrPermissionDenied)
3083 r=KErrNone; // Ensure misleading result is not propagated
3087 // Read the resource information
3090 if((r=secThrdChannel.GetNoOfResources(numResources))!=KErrNone)
3094 // Need a buffer big enough to contain numResources instances of TResourceInfoBuf
3095 // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects
3096 // and reference via an RSimplePointerArray
3097 RSimplePointerArray<TResourceInfoBuf> resPtrs(numResources);
3098 for(TUint j=0;j<numResources;j++)
3100 TResourceInfoBuf *info = new TResourceInfoBuf();
3101 if((r=resPtrs.Insert(info, j))!=KErrNone)
3105 if((r=secThrdChannel.GetAllResourcesInfo(&resPtrs,numResources))!=KErrNone)
3110 // Close the channel
3111 secThrdChannel.Close();
3117 TInt r=Thrd2.Create(KThrd2Name,Thread2Fn,KStackSize,KHeapSize,KHeapSize,NULL,EOwnerThread);
3120 Thrd2.Logon(Thrd2Status);
3125 TInt WaitForThread2()
3127 User::WaitForRequest(Thrd2Status);
3128 TInt exitType=Thrd2.ExitType();
3129 TInt exitReason=Thrd2.ExitReason();
3130 TBuf<16> exitCat=Thrd2.ExitCategory();
3131 if((exitType!= EExitKill)||(exitReason!=KErrNone))
3133 gTest.Printf(_L("Thread2 error: %d\n"),Thrd2Status.Int());
3134 gTest.Printf(_L("Thread exit reason: %d,%d,%S\n"),exitType,exitReason,&exitCat);
3142 //----------------------------------------------------------------------------------------------
3143 //! @SYMTestCaseID KBASE-T_RESMANUS-0614
3145 //! @SYMPREQ PREQ1398
3146 //! @SYMTestCaseDesc This test case tests that an additional thread can open a channel and
3147 //! exercise selected APIs.
3149 //! @SYMTestActions 0) Call API to open a channel.
3151 //! 1) Call GetNoOfResources API.
3153 //! 2) Call GetAllResourcesInfo API.
3155 //! 3) Call GetNoOfClients API with default aIncludeKern=EFalse.
3157 //! 4) Call GetNoOfClients API with aIncludeKern=ETrue
3159 //! 5) Call GetNamesAllClientsAPI with default aIncludeKern=EFalse.
3161 //! 6) Call GetNamesAllClientsAPI with aIncludeKern=ETrue
3163 //! 7) Call Initialise API.
3165 //! 8) Call GetResourceState API for selected resource.
3167 //! 9) Call GetResourceState API for selected resource.
3169 //! 10) Call GetNoOfClients API with default aIncludeKern=EFalse.
3171 //! 11) Call GetNoOfClients API with aIncludeKern=ETrue
3173 //! 12) Call GetNamesAllClientsAPI with default aIncludeKern=EFalse.
3175 //! 13) Call GetNamesAllClientsAPI with aIncludeKern=ETrue
3177 //! 14) Call GetNoOfResources API.
3179 //! 15) Call GetAllResourcesInfo API.
3181 //! @SYMTestExpectedResults 0) Test that the channel was opened - exit otherwise.
3183 //! 1) Test that the API call returned KErrNone - exit otherwise.
3185 //! 2) Test that the API call returned KErrNone - exit otherwise.
3187 //! 3) Test that the API call returned KErrNone - exit otherwise.
3189 //! 4) If client exhibits PlatSec capability ReadDeviceData, Test that the API call returned KErrNone - exit otherwise
3190 //! If client lacks PlatSec capability ReadDeviceData, Test that the API call returned KErrPermissionDenied - exit otherwise
3192 //! 5) Test that the API call returned KErrNone - exit otherwise.
3194 //! 6) If client exhibits PlatSec capability ReadDeviceData, Test that the API call returned KErrNone - exit otherwise
3195 //! If client lacks PlatSec capability ReadDeviceData, Test that the API call returned KErrPermissionDenied - exit otherwise
3197 //! 7) Test that the API call returned KErrNone - exit otherwise
3199 //! 8) Test that the associated TRequestStatus object exhibited state KErrNone - exit otherwise
3201 //! 9) Test that the associated TRequestStatus object exhibited state KErrNone - exit otherwise
3203 //! 10) Test that the API call returned KErrNone - exit otherwise.
3205 //! 11) If client exhibits PlatSec capability ReadDeviceData, Test that the API call returned KErrNone - exit otherwise
3206 //! If client lacks PlatSec capability ReadDeviceData, Test that the API call returned KErrPermissionDenied - exit otherwise
3208 //! 12) Test that the API call returned KErrNone - exit otherwise.
3210 //! 13) If client exhibits PlatSec capability ReadDeviceData, Test that the API call returned KErrNone - exit otherwise
3211 //! If client lacks PlatSec capability ReadDeviceData, Test that the API call returned KErrPermissionDenied - exit otherwise
3213 //! 14) Test that the API call returned KErrNone - exit otherwise.
3215 //! 15) Test that the API call returned KErrNone - exit otherwise.
3217 //! @SYMTestPriority High
3218 //! @SYMTestStatus Implemented
3219 //----------------------------------------------------------------------------------------------
3220 LOCAL_C TInt TestAdditionalThread()
3222 // Test that more than one thread can be supported
3226 if((r=StartThread2())!=KErrNone)
3228 gTest.Printf(_L("TestAdditionalThread: StartThread2 returned %d\n"),r);
3231 if((r=WaitForThread2())!=KErrNone)
3233 gTest.Printf(_L("TestAdditionalThread: WaitForThread2 returned %d\n"),r);
3241 LOCAL_C TInt LocateResourceWithDependencies(TUint &aNumResources, TUint &aResId, TUint &aNumDependents)
3243 // Support function for tests of dependencies
3249 if((r=gChannel.GetNoOfResources(aNumResources))!=KErrNone)
3251 gTest.Printf(_L("GetNoOfResources for test channel returned %d\n"),r);
3254 TUint bufSize = aNumResources;
3255 RSimplePointerArray<TResourceInfoBuf> infoPtrs(bufSize);
3256 for(TUint i=0;i<bufSize;i++)
3258 TResourceInfoBuf *info = new TResourceInfoBuf();
3259 if((r=infoPtrs.Insert(info, i))!=KErrNone)
3261 gTest.Printf(_L("GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),i,r);
3264 TUint updateNumResources=aNumResources;
3265 if((r=gChannel.GetAllResourcesInfo(&infoPtrs,updateNumResources))!=KErrNone)
3267 gTest.Printf(_L("GetAllResourcesInfo for channel returned %d\n"),r);
3270 for(TUint resNo=0;resNo<aNumResources;resNo++)
3272 TResourceInfoBuf *info = infoPtrs[resNo];
3273 TUint resId = ((*info)()).iId;
3274 TUint numDependents = 0;
3275 r=gChannel.GetNumDependentsForResource(resId,&numDependents, EFalse); // EFalse - don't load the dependency info
3276 if((r!=KErrNone)&&(r!=KErrNotFound)&&(r!=KErrNotSupported))
3278 gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource returned %d\n"),r);
3284 aNumDependents = numDependents;
3298 //----------------------------------------------------------------------------------------------
3299 //! @SYMTestCaseID KBASE-T_RESMANUS-0615
3301 //! @SYMPREQ PREQ1398
3302 //! @SYMTestCaseDesc This test case tests the different options available for handling transient data.
3303 //! @SYMTestActions 0) Locate a resource that has at least one dependency.
3305 //! 1) Read the number of dependencies without reading the dependency information.
3306 //! Call to read the dependency information (without re-loading).
3308 //! 2) Read the number of dependencies (with default option of reading the dependency information).
3309 //! Then read the dependency information (without re-loading).
3311 //! 3) Repeat the read the number of dependencies without reading the dependency information
3312 //! Then read the dependency information (without re-loading).
3313 //! Then read the dependency information (with re-loading).
3315 //! 4) Attempt to read the dependency information (without re-loading) with a buffer of insufficient size
3317 //! 5) Read the number of (all) resources without reading the resource information.
3318 //! Call to read (all) the resource information (without re-loading).
3320 //! 6) Read the number of (all) resources (with default option of reading the resource information).
3321 //! Then read (all) the resource information (without re-loading).
3323 //! 7) Repeat the read the number of (all) resources without reading the resources information
3324 //! Then read (all) the resources information (without re-loading).
3325 //! Then read (all) the resources information (with re-loading).
3327 //! 8) Attempt to read (all) the resource information (without re-loading) with a buffer of insufficient size
3329 //! 9) Read the number of user-side clients using a resource without reading the resource information.
3330 //! Call to read the information for user-side clients using a resource (without re-loading).
3332 //! 10) Read the number of user-side clients (with loading of the client information)
3333 //! Call to read the client information (without re-loading) should return be successful
3334 //! Call to read the information for a resourceID with zero clients (without re-loading)
3335 //! Call to read the information for the first resourceID
3337 //! 11) Repeat the read of the number of user-side clients (without re-loading)
3338 //! Call to read the client information (without re-loading)
3339 //! Call to read the client information (with re-loading)
3341 //! 12) Open a second channel on the User-Side API, and call initialise support for resource state access
3342 //! Get the current state of a specific resource, then change the state
3343 //! Call to read the number of user-side clients for the resource (with loading of the client information)
3344 //! but with a buffer of insufficient size.
3346 //! 13) Read the number of resources in use by a specified client (without loading)
3347 //! Call to read the information on the resources in use by the client (without loading)
3349 //! 14) Open a third channel on the User-Side API, do not call initialise.
3350 //! Read the number of resources in use by a specified client (with loading)
3351 //! Call to read the information for resources in use by the third channel (without re-loading)
3352 //! Call to read the information for resources in use by the second channel (without re-loading)
3354 //! 15) Read the number of resources in use by a specified client (without loading)
3355 //! Call to read the information on the resources in use by the client (without loading)
3356 //! Call to read the information on the resources in use by the client (with loading)
3358 //! 16) Read the number of resources in use by a specified client (with loading)
3359 //! Call to read the information on the resources in use by the client (without loading)
3360 //! with a buffer of insufficient size.
3362 //! @SYMTestExpectedResults 0) If a suitable resource is found, the number of dependencies is reported - exit otherwise.
3364 //! 1) Test that the read of the number of dependencies returns KErrNone - exit otherwise.
3365 //! Test that the read of the dependency information returned KErrNotReady - exit otherwise.
3367 //! 2) Test that the read of the number of dependencies returns KErrNone - exit otherwise.
3368 //! Test that the read of the dependency information returned KErrNone - exit otherwise.
3370 //! 3) Test that the read of the number of dependencies returns KErrNone - exit otherwise.
3371 //! Test that the read of the dependency information (without re-loading) returned KErrNotReady - exit otherwise.
3372 //! Test that the read of the dependency information (with re-loading) returned KErrNone - exit otherwise.
3374 //! 4) Test that the read of the dependency information returns KErrArgument - exit otherwise
3376 //! 5) Test that the read of the number of resources returns KErrNone - exit otherwise.
3377 //! Test that the read of the resource information returned KErrNotReady - exit otherwise.
3379 //! 6) Test that the read of the number of resources returns KErrNone - exit otherwise.
3380 //! Test that the read of the resource information returned KErrNone - exit otherwise.
3382 //! 7) Test that the read of the number of resources returns KErrNone - exit otherwise.
3383 //! Test that the read of the resource information (without re-loading) returned KErrNotReady - exit otherwise.
3384 //! Test that the read of the resources information (with re-loading) returned KErrNone - exit otherwise.
3386 //! 8) Test that the read of the resource information returns KErrArgument - exit otherwise
3388 //! 9) Test that the read of the number of clients returns KErrNone - exit otherwise.
3389 //! Test that the read of the client information returned KErrNotReady - exit otherwise.
3391 //! 10) Test that the read of the number of clients returns KErrNone - exit otherwise.
3392 //! Test that the read of the client information returned KErrNone - exit otherwise.
3393 //! Test that the read of the client information returned KErrNone and numClients==0 - exit otherwise.
3394 //! Test that the read of the client information returned KErrNotReady - exit otherwise.
3396 //! 11) Test that the read of the number of clients returns KErrNone - exit otherwise.
3397 //! Test that the read of the client information returned KErrNotReady - exit otherwise.
3398 //! Test that the read of the client information returned KErrNone - exit otherwise.
3400 //! 12) Test that the opening and initialisation of the channel was successful - exit otherwise.
3401 //! Test that the get and change of the resource state completed successfully - exit otherwise
3402 //! Test that the read of the client information returned KErrArgument - exit otherwise.
3404 //! 13) Test that the read of the number of resources returns KErrNone - exit otherwise.
3405 //! Test that the read of the resource information returned KErrNotReady - exit otherwise.
3407 //! 14) Test that the opening of the channel was successful - exit otherwise.
3408 //! Test that the read of the resource information returned KErrNone - exit otherwise.
3409 //! Test that the read of the client information returned KErrNone, and numResources = 0 - exit otherwise.
3410 //! Test that the read of the client information returned KErrNotReady - exit otherwise.
3412 //! 15) Test that the read of the number of resources returns KErrNone - exit otherwise.
3413 //! Test that the read of the resource information returned KErrNotReady - exit otherwise.
3414 //! Test that the read of the resource information returned KErrNone - exit otherwise.
3416 //! 16) Test that the read of the number of resources returns KErrNone - exit otherwise.
3417 //! Test that the read of the resource information returned KErrArgument - exit otherwise..
3419 //! @SYMTestPriority High
3420 //! @SYMTestStatus Implemented
3421 //----------------------------------------------------------------------------------------------
3422 LOCAL_C TInt TestTransientHandling()
3424 // Test APIs with options for handling transient data (dependencies, resources and clients)
3430 TUint numDependents = 0;
3434 // Dependency data tests
3437 gTest.Printf(_L("TestTransientHandling: dependency data tests ...\n"));
3439 // 0) Find a resource that has dependents - if none is located skip the remaining dependancy tests
3440 // (this reads the number of dependencies, without loading the dependency data)
3442 TUint numResources=0;
3443 if((r=LocateResourceWithDependencies(numResources, resNo, numDependents))!=KErrNone)
3445 gTest.Printf(_L("TestTransientHandling: no resource with dependencies found ... skipping tests\n"));
3448 if(numDependents==0)
3450 gTest.Printf(_L("TestTransientHandling: no resource with dependencies found ... skipping tests\n"));
3454 // 1) Read the number of dependencies without reading the dependency information
3455 // Subsequent call to read the dependency information (without re-loading) should return error KErrNotReady
3456 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
3457 if((r=gChannel.GetNumDependentsForResource(resNo,&numDependents, EFalse))!=KErrNone)
3459 gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource returned %d\n"),r);
3462 gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource reported %d dependents for resource %d\n"),numDependents,resNo);
3463 if(numDependents > 0)
3466 if((buffer.Create(numDependents*sizeof(SResourceDependencyInfo)))!=KErrNone)
3468 buffer.SetLength(0);
3469 if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents))!=KErrNotReady)
3471 gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r);
3477 // 2) Read the number of dependencies (and, by default, read the dependency information)
3478 // Subsequent call to read the dependency information (without re-loading) should return be successful
3479 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
3480 if((r=gChannel.GetNumDependentsForResource(resNo,&numDependents))!=KErrNone)
3482 gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource returned %d\n"),r);
3485 gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource reported %d dependents for resource %d\n"),numDependents,resNo);
3486 if(numDependents > 0)
3489 if((buffer.Create(numDependents*sizeof(SResourceDependencyInfo)))!=KErrNone)
3491 buffer.SetLength(0);
3492 if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents))!=KErrNone)
3494 gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r);
3497 SResourceDependencyInfo* tempPtr = (SResourceDependencyInfo*)(buffer.Ptr());
3498 gTest.Printf(_L("TestTransientHandling: numDependents = %d\n"),numDependents);
3499 for(TUint i=0; i<numDependents; i++,tempPtr++)
3501 gTest.Printf(_L("TestTransientHandling: info.iResourceId = %d\n"),tempPtr->iResourceId);
3502 gTest.Printf(_L("TestTransientHandling: info.iDependencyPriority= %d\n"),tempPtr->iDependencyPriority);
3507 // 3) Repeat the read the number of dependencies without reading the dependency information
3508 // Subsequent call to read the dependency information (without re-loading) should return error KErrNotReady
3509 // Then call to read the dependency information (with re-loading) should be successful
3510 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
3511 if((r=gChannel.GetNumDependentsForResource(resNo,&numDependents, EFalse))!=KErrNone)
3513 gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource returned %d\n"),r);
3516 gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource reported %d dependents for resource %d\n"),numDependents,resNo);
3517 if(numDependents > 0)
3520 if((buffer.Create(numDependents*sizeof(SResourceDependencyInfo)))!=KErrNone)
3522 buffer.SetLength(0);
3524 if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents))!=KErrNotReady)
3526 gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r);
3529 if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents, ETrue))!=KErrNone)
3531 gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r);
3534 SResourceDependencyInfo* tempPtr = (SResourceDependencyInfo*)(buffer.Ptr());
3535 for(TUint i=0; i<numDependents; i++,tempPtr++)
3537 gTest.Printf(_L("TestTransientHandling: info.iResourceId = %d"),tempPtr->iResourceId);
3538 gTest.Printf(_L("TestTransientHandling: info.iDependencyPriority= %d"),tempPtr->iDependencyPriority);
3543 // 4) Attempt to read the dependency information (without re-loading) with a buffer of insufficient size should
3544 // return error KErrArgument
3545 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
3546 if(numDependents > 0)
3549 if((buffer.Create((numDependents-1)*sizeof(SResourceDependencyInfo)))!=KErrNone)
3551 buffer.SetLength(0);
3552 if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents))!=KErrArgument)
3554 gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r);
3557 // Ensure misleading result is not returned
3565 // All resource data tests
3568 gTest.Printf(_L("TestTransientHandling: All resource data tests ...\n"));
3571 // 5) Attempt to read the resource information without having previously loaded it.
3572 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
3574 TUint numResources = 0;
3575 r = gChannel.GetNoOfResources(numResources, EFalse); // EFalse - don't load the resource info
3578 gTest.Printf(_L("GetNoOfResources returned %d\n"),r);
3581 // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects
3582 // and reference via an RSimplePointerArray
3583 RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources);
3584 for(TUint i=0;i<numResources;i++)
3586 TResourceInfoBuf *info = new TResourceInfoBuf();
3587 if((r=infoPtrs.Insert(info, i))!=KErrNone)
3589 gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
3592 if((r=gChannel.GetAllResourcesInfo(&infoPtrs, numResources))!=KErrNotReady)
3594 gTest.Printf(_L("TestTransientHandling: GetAllResourcesInfo returned %d\n"),r);
3598 r=KErrNone; // Ensure misleading result is not propagated
3602 // 6) Read the number of resources (and, by default, read the resource information)
3603 // Subsequent call to read the resource information (without re-loading) should return be successful
3604 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
3606 TUint numResources = 0;
3607 if((r=gChannel.GetNoOfResources(numResources))!=KErrNone)
3609 gTest.Printf(_L("GetNoOfResources returned %d\n"),r);
3612 // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects
3613 // and reference via an RSimplePointerArray
3614 RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources);
3615 for(TUint i=0;i<numResources;i++)
3617 TResourceInfoBuf *info = new TResourceInfoBuf();
3618 if((r=infoPtrs.Insert(info, i))!=KErrNone)
3620 gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
3623 if((r=gChannel.GetAllResourcesInfo(&infoPtrs, numResources))!=KErrNone)
3625 gTest.Printf(_L("TestTransientHandling: GetAllResourcesInfo returned %d\n"),r);
3631 // 7) Repeat the read the number of resources without reading the resource information
3632 // Subsequent call to read the resource information (without re-loading) should return error KErrNotReady
3633 // Then call to read the resource information (with re-loading) should be successful
3634 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
3636 TUint numResources = 0;
3637 if((r=gChannel.GetNoOfResources(numResources, EFalse))!=KErrNone) // EFalse - don't load the resource info
3639 gTest.Printf(_L("GetNoOfResources returned %d\n"),r);
3642 // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects
3643 // and reference via an RSimplePointerArray
3644 RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources);
3645 for(TUint i=0;i<numResources;i++)
3647 TResourceInfoBuf *info = new TResourceInfoBuf();
3648 if((r=infoPtrs.Insert(info, i))!=KErrNone)
3650 gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
3653 if((r=gChannel.GetAllResourcesInfo(&infoPtrs, numResources))!=KErrNotReady)
3655 gTest.Printf(_L("TestTransientHandling: GetAllResourcesInfo returned %d\n"),r);
3658 if((r=gChannel.GetAllResourcesInfo(&infoPtrs, numResources,ETrue))!=KErrNone)
3660 gTest.Printf(_L("TestTransientHandling: GetAllResourcesInfo returned %d\n"),r);
3668 // 8) Attempt to read the resource information (without re-loading) with a buffer of insufficient size should
3669 // return error KErrArgument
3670 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
3672 TUint numResources = 0;
3673 if((r=gChannel.GetNoOfResources(numResources, EFalse))!=KErrNone) // EFalse - don't load the resource info
3675 gTest.Printf(_L("GetNoOfResources returned %d\n"),r);
3678 // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects
3679 // and reference via an RSimplePointerArray
3680 RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources - 1);
3681 for(TUint i=0;i<(numResources-1);i++)
3683 TResourceInfoBuf *info = new TResourceInfoBuf();
3684 if((r=infoPtrs.Insert(info, i))!=KErrNone)
3686 gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
3689 if((r=gChannel.GetAllResourcesInfo(&infoPtrs, numResources))!=KErrArgument)
3691 gTest.Printf(_L("TestTransientHandling: GetAllResourcesInfo returned %d\n"),r);
3694 // Ensure misleading result is not returned
3700 // Specific resource data tests
3703 gTest.Printf(_L("TestTransientHandling: Resource-specific data tests ...\n"));
3706 // 9) Attempt to read the resource information without having previously loaded it.
3707 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
3709 TUint numClients = 0;
3710 if((r=gChannel.GetNumClientsUsingResource(gLongLatencyResource, numClients, EFalse, EFalse))!=KErrNone) // user-side clients, don't load the info
3712 gTest.Printf(_L("GetNumClientsUsingResource returned %d\n"),r);
3715 // To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects
3716 // and reference via an RSimplePointerArray
3717 RSimplePointerArray<TClientInfoBuf> infoPtrs(numClients);
3718 for(TUint i=0;i<numClients;i++)
3720 TClientInfoBuf *info = new TClientInfoBuf();
3721 if((r=infoPtrs.Insert(info, i))!=KErrNone)
3723 gTest.Printf(_L("TestTransientHandling test, GetInfoOnClientsUsingResource infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
3726 if((r=gChannel.GetInfoOnClientsUsingResource(gLongLatencyResource, numClients, &infoPtrs, EFalse))!=KErrNotReady)
3728 gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource returned %d\n"),r);
3732 r=KErrNone; // Ensure misleading result is not propagated
3736 // 10) Read the number of clients (and, by default, read the client information)
3737 // Subsequent call to read the client information (without re-loading) should return be successful
3738 // Call to read the information for a resourceID with zero clients (without re-loading) should return KErrNone, numClients==0
3739 // Call to read the information for a resourceID with one or more clients (without re-loading) should return KErrNotReady
3740 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
3742 TUint numClients = 0;
3743 if((r=gChannel.GetNumClientsUsingResource(gLongLatencyResource, numClients, EFalse))!=KErrNone) // user-side clients, load the info
3745 gTest.Printf(_L("GetNumClientsUsingResource returned %d\n"),r);
3748 // To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects
3749 // and reference via an RSimplePointerArray
3750 RSimplePointerArray<TClientInfoBuf> infoPtrs(numClients);
3751 for(TUint i=0;i<numClients;i++)
3753 TClientInfoBuf *info = new TClientInfoBuf();
3754 if((r=infoPtrs.Insert(info, i))!=KErrNone)
3756 gTest.Printf(_L("TestTransientHandling test, GetInfoOnClientsUsingResource infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
3759 if((r=gChannel.GetInfoOnClientsUsingResource(gLongLatencyResource, numClients, &infoPtrs, EFalse))!=KErrNone)
3761 gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for gLongLatencyResource returned %d\n"),r);
3764 if(((r=gChannel.GetInfoOnClientsUsingResource((gLongLatencyResource+1), numClients, &infoPtrs, EFalse))!=KErrNone) || (numClients!=0))
3766 gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for (gLongLatencyResource+1) returned %d\n"),r);
3768 gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for (gLongLatencyResource+1), %d clients\n"),numClients);
3771 if((r=gChannel.GetInfoOnClientsUsingResource(gSharedResource, numClients, &infoPtrs, EFalse))!=KErrNotReady)
3773 gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource (for gSharedResource) returned %d\n"),r);
3780 // 11) Repeat the read the number of clients without reading the client information
3781 // Subsequent call to read the client information (without re-loading) should return error KErrNotReady
3782 // Then call to read the client information (with re-loading) should be successful
3783 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
3785 TUint numClients = 0;
3786 if((r=gChannel.GetNumClientsUsingResource(gLongLatencyResource, numClients, EFalse, EFalse))!=KErrNone) // user-side clients, don't load the info
3788 gTest.Printf(_L("GetNumClientsUsingResource returned %d\n"),r);
3791 // To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects
3792 // and reference via an RSimplePointerArray
3793 RSimplePointerArray<TClientInfoBuf> infoPtrs(numClients);
3794 for(TUint i=0;i<numClients;i++)
3796 TClientInfoBuf *info = new TClientInfoBuf();
3797 if((r=infoPtrs.Insert(info, i))!=KErrNone)
3799 gTest.Printf(_L("TestTransientHandling test, GetInfoOnClientsUsingResource infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
3802 if((r=gChannel.GetInfoOnClientsUsingResource(gLongLatencyResource, numClients, &infoPtrs, EFalse))!=KErrNotReady)
3804 gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for gLongLatencyResource returned %d\n"),r);
3807 if((r=gChannel.GetInfoOnClientsUsingResource(gLongLatencyResource, numClients, &infoPtrs, EFalse, ETrue))!=KErrNone)
3809 gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for gLongLatencyResource returned %d\n"),r);
3816 // 12) To support the following test (and specific resource data tests, below) need a second channel to be using the resource
3817 _LIT(tempStr1,"ExtraChan1");
3818 TBufC<16> tempName1(tempStr1);
3819 RBusDevResManUs channelTwo;
3820 if((r=OpenChannel(tempName1, channelTwo))!=KErrNone)
3822 gTest.Printf(_L("Failed to open channelTwo, %d\n"),r);
3826 if ((r=channelTwo.Initialise(1,1,1))!=KErrNone)
3828 gTest.Printf(_L("Failed to Initialise channelTwo, %d\n"),r);
3832 // Attempt to change the resource level
3833 // Get initial state
3834 TRequestStatus status;
3835 TBool cached = gUseCached;
3837 TInt levelOwnerId = 0;
3838 channelTwo.GetResourceState(status,gSharedResource,cached,&readValue,&levelOwnerId);
3839 User::WaitForRequest(status);
3843 gTest.Printf(_L("GetResourceState for gSharedResource completed with = 0x%x\n"),r);
3846 // Write updated state
3847 TUint newLevel = (TUint)(readValue + gSharedResStateDelta);
3848 channelTwo.ChangeResourceState(status,gSharedResource,newLevel);
3849 User::WaitForRequest(status);
3853 gTest.Printf(_L("ChangeResourceState forgSharedResource completed with %d\n"),r);
3857 // Attempt to read the client information (without re-loading) with a buffer of insufficient size should
3858 // return error KErrArgument
3859 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
3861 TUint numClients = 0;
3862 if((r=gChannel.GetNumClientsUsingResource(gSharedResource, numClients, EFalse))!=KErrNone) // user-side clients, load the info
3864 gTest.Printf(_L("GetNumClientsUsingResource returned %d\n"),r);
3868 // To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects
3869 // and reference via an RSimplePointerArray
3870 RSimplePointerArray<TClientInfoBuf> infoPtrs(numClients-1);
3871 for(TUint i=0;i<(numClients-1);i++)
3873 TClientInfoBuf *info = new TClientInfoBuf();
3874 if((r=infoPtrs.Insert(info, i))!=KErrNone)
3876 gTest.Printf(_L("TestTransientHandling test, GetInfoOnClientsUsingResource infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
3880 if((r=gChannel.GetInfoOnClientsUsingResource(gSharedResource, numClients, &infoPtrs, EFalse))!=KErrArgument)
3882 gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for gLongLatencyResource returned %d\n"),r);
3886 // Ensure misleading result is not returned
3893 // Specific resource data tests
3896 gTest.Printf(_L("TestTransientHandling: Client-specific data tests ...\n"));
3899 // These tests require a client name
3900 TBuf8<MAX_RESOURCE_NAME_LENGTH+1>name8Bit;
3901 name8Bit.Copy(gTestName);
3902 TClientName* clientName = (TClientName*)&name8Bit;
3904 TBuf <MAX_CLIENT_NAME_LENGTH> clientName16Bit;
3905 clientName16Bit.Copy(*clientName);
3906 clientName16Bit.SetLength(clientName->Length());
3907 gTest.Printf(_L("Invoking TestTransientHandling client-specific data tests with %S \n"),&clientName16Bit);
3909 // 13) Attempt to read the resource information without having previously loaded it.
3910 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
3912 TUint numResources = 0;
3913 if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResources, EFalse))!=KErrNone) // EFalse - don't load data
3915 gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r);
3918 // To support the GetInfoOnResourcesInUseByClient testing, instantiate TResourceInfoBuf objects
3919 // and reference via an RSimplePointerArray
3920 RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources);
3921 for(TUint i=0;i<numResources;i++)
3923 TResourceInfoBuf *info = new TResourceInfoBuf();
3924 if((r=infoPtrs.Insert(info, i))!=KErrNone)
3926 gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
3929 if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, numResources, &infoPtrs))!=KErrNotReady)
3931 gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource returned %d\n"),r);
3935 r=KErrNone; // Ensure misleading result is not propagated
3939 // 14) To support the following test need a third channel
3940 _LIT(tempStr2,"ExtraChan2");
3941 TBufC<16> tempName2(tempStr2);
3942 RBusDevResManUs channelThree;
3943 if((r=OpenChannel(tempName2, channelThree))!=KErrNone)
3945 gTest.Printf(_L("Failed to open channelThree, %d\n"),r);
3949 // Read the number of resources (and, by default, read the resource information)
3950 // Subsequent call to read the resource information (without re-loading) should return be successful
3951 // Call to read the information for a client name with zero resource requirements (without re-loading) should return KErrNone, numResources==0
3952 // Call to read the information for a client name with one or more resource requirements (without re-loading) should return KErrNotReady
3953 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
3955 TUint numResources = 0;
3956 if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResources))!=KErrNone) // load data
3958 gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r);
3961 // To support the GetInfoOnResourcesInUseByClient testing, instantiate TResourceInfoBuf objects
3962 // and reference via an RSimplePointerArray
3963 RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources);
3964 for(TUint i=0;i<numResources;i++)
3966 TResourceInfoBuf *info = new TResourceInfoBuf();
3967 if((r=infoPtrs.Insert(info, i))!=KErrNone)
3969 gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
3972 if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, numResources, &infoPtrs))!=KErrNone)
3974 gTest.Printf(_L("TestTransientHandling: gChannel GetInfoOnClientsUsingResource returned %d\n"),r);
3977 TUint dumResources=0;
3978 TBuf8<MAX_RESOURCE_NAME_LENGTH+1>name8Bit2;
3979 name8Bit2.Copy(tempName2);
3980 TClientName* clientName2 = (TClientName*)&name8Bit2;
3981 if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName2, dumResources, &infoPtrs))!=KErrNone)
3983 gTest.Printf(_L("TestTransientHandling: tempName2 GetInfoOnClientsUsingResource returned %d\n"),r);
3988 gTest.Printf(_L("TestTransientHandling: tempName2 GetInfoOnClientsUsingResource dumResources=%d\n"),dumResources);
3991 TBuf8<MAX_RESOURCE_NAME_LENGTH+1>name8Bit1;
3992 name8Bit1.Copy(tempName1);
3993 TClientName* clientName1 = (TClientName*)&name8Bit1;
3994 if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName1, numResources, &infoPtrs))!=KErrNotReady)
3996 gTest.Printf(_L("TestTransientHandling: tempName1 GetInfoOnClientsUsingResource returned %d\n"),r);
4004 // 15) Repeat the read the number of resources without reading the resource information
4005 // Subsequent call to read the resources information (without re-loading) should return error KErrNotReady
4006 // Then call to read the resources information (with re-loading) should be successful
4007 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
4009 TUint numResources = 0;
4010 if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResources, EFalse))!=KErrNone) // don't load data
4012 gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r);
4015 // To support the GetInfoOnResourcesInUseByClient testing, instantiate TResourceInfoBuf objects
4016 // and reference via an RSimplePointerArray
4017 RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources);
4018 for(TUint i=0;i<numResources;i++)
4020 TResourceInfoBuf *info = new TResourceInfoBuf();
4021 if((r=infoPtrs.Insert(info, i))!=KErrNone)
4023 gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
4026 if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, numResources, &infoPtrs))!=KErrNotReady)
4028 gTest.Printf(_L("TestTransientHandling: GetInfoOnResourcesInUseByClient returned %d\n"),r);
4031 if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, numResources, &infoPtrs, ETrue))!=KErrNone)
4033 gTest.Printf(_L("TestTransientHandling: GetInfoOnResourcesInUseByClient returned %d\n"),r);
4040 // 16) Attempt to read the resource information (without re-loading) with a buffer of insufficient size should
4041 // return error KErrArgument
4042 gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++);
4044 TUint numResources = 0;
4045 if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResources))!=KErrNone) // load data
4047 gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r);
4050 // To support the GetInfoOnResourcesInUseByClient testing, instantiate TResourceInfoBuf objects
4051 // and reference via an RSimplePointerArray
4052 RSimplePointerArray<TResourceInfoBuf> infoPtrs(numResources-1);
4053 for(TUint i=0;i<(numResources-1);i++)
4055 TResourceInfoBuf *info = new TResourceInfoBuf();
4056 if((r=infoPtrs.Insert(info, i))!=KErrNone)
4058 gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r);
4061 if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, numResources, &infoPtrs))!=KErrArgument)
4063 gTest.Printf(_L("TestTransientHandling: GetInfoOnResourcesInUseByClient returned %d\n"),r);
4067 // Ensure misleading result is not returned
4073 channelThree.Close();
4079 EXPORT_C TInt E32Main()
4084 gTest.Start(_L("Test Power Resource Manager user side API\n"));
4088 // Test attempted load of PDD
4089 gTest.Next(_L("**Load PDD\n"));
4090 r=User::LoadPhysicalDevice(PDD_NAME);
4091 if((r!=KErrNone)&&(r!=KErrAlreadyExists))
4093 gTest.Printf(_L("User::LoadPhysicalDevice error %d\n"),r);
4097 // Test attempted load of LDD
4098 gTest.Next(_L("**Load LDD\n"));
4099 r=User::LoadLogicalDevice(LDD_NAME);
4100 if((r!=KErrNone)&&(r!=KErrAlreadyExists))
4101 gTest.Printf(_L("User::LoadLogicalDevice error - expected %d, got %d\n"),KErrAlreadyExists,r);
4103 if((r==KErrNone)||(r==KErrAlreadyExists))
4105 r = KErrNone; // Re-initialise in case set to KErrAlreadyExists
4107 // Need a channel open for the following tests
4108 gTest.Next(_L("**OpenAndRegisterChannel\n"));
4109 r=OpenAndRegisterChannel();
4112 // Get the version of the ResourceController
4114 if((r=gChannel.GetResourceControllerVersion(version))!=KErrNone)
4116 gTest.Printf(_L("TestTransientHandling: GetResourceControllerVersion returned %d\n"),r);
4119 gTest.Printf(_L("TestTransientHandling: ResourceController version =0x%x\n"),version);
4123 gTest.Next(_L("**TestThreadExclusiveAccess\n"));
4124 r=TestThreadExclusiveAccess();
4128 gTest.Next(_L("**TestGetClientGetResourceInfo - initial state\n"));
4129 r=TestGetClientGetResourceInfo();
4133 gTest.Next(_L("**TestGetSetResourceStateOps\n"));
4134 r=TestGetSetResourceStateOps();
4138 gTest.Next(_L("**TestGetClientGetResourceInfo - after changing stateof Async resource\n"));
4139 r=TestGetClientGetResourceInfo();
4143 gTest.Next(_L("**TestGetSetResourceStateQuota\n"));
4144 r=TestGetSetResourceStateQuota();
4148 gTest.Next(_L("**TestNotificationOps\n"));
4149 r=TestNotificationOps();
4153 gTest.Next(_L("**TestNotificationQuota\n"));
4154 r=TestNotificationQuota();
4158 // Should be no change since last invocation (assuming that
4159 // no clients other than those in this test)
4160 gTest.Next(_L("**TestGetClientGetResourceInfo - last invocation\n"));
4161 r=TestGetClientGetResourceInfo();
4165 gTest.Next(_L("**TestAdditionalThread\n"));
4166 r=TestAdditionalThread();
4170 gTest.Next(_L("**TestTransientHandling\n"));
4171 r=TestTransientHandling();
4176 User::FreeLogicalDevice(KLddRootName);
4177 User::FreePhysicalDevice(PDD_NAME);
4178 User::After(100000); // Allow idle thread to run for driver unloading