sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include sl@0: sl@0: #ifdef PRM_ENABLE_EXTENDED_VERSION sl@0: #define LDD_NAME _L("resourcecontrollerextended.ldd") sl@0: #else sl@0: #define LDD_NAME _L("resourcecontrol.ldd") sl@0: #endif sl@0: sl@0: #ifdef PRM_ENABLE_EXTENDED_VERSION sl@0: #define PDD_NAME _L("resourcecontrollerextended.pdd") sl@0: #else sl@0: #define PDD_NAME _L("resourcecontroller.pdd") sl@0: #endif sl@0: sl@0: //#define PIRATE_THREAD_TESTS sl@0: sl@0: _LIT(testableResourceName,"SymbianSimulResource"); sl@0: sl@0: #ifdef RESMANUS_KERN sl@0: _LIT(testName,"t_resmanuskern"); sl@0: #else sl@0: _LIT(testName,"t_resmanus"); sl@0: #endif sl@0: sl@0: TBuf<16> gTestName(testName); sl@0: sl@0: GLDEF_D RTest gTest(testName); sl@0: GLDEF_D RBusDevResManUs gChannel; sl@0: sl@0: TUint8 KNoOfGetStateRequests = 5; sl@0: TUint8 KNoOfSetStateRequests = 4; sl@0: TUint8 KNoOfNotifyRequests = 7; sl@0: #define MAX_NUM_REQUESTS 8 // Must be (at least) one greater than the largest of sl@0: // KNoOfGetStateRequests, KNoOfSetStateRequests, KNoOfNotifyRequests sl@0: #ifdef _DEBUG sl@0: TUint gLongLatencyResource; sl@0: TBool gHaveAsyncRes = EFalse; sl@0: TInt gAsyncResStateDelta = 0; sl@0: sl@0: TUint gSharedResource; sl@0: TBool gHaveSharedRes = EFalse; sl@0: TInt gSharedResStateDelta = 0; sl@0: #else sl@0: // The UREL version of the driver will not implement the arrays and functionality required sl@0: // to determine the async and shared resources to use at runtime. The values provided here sl@0: // have been pre-determined to operate successfully with the simulated PSL. sl@0: // sl@0: TUint gLongLatencyResource = 6; sl@0: TBool gHaveAsyncRes = ETrue; sl@0: TInt gAsyncResStateDelta = -1; sl@0: sl@0: TUint gSharedResource = 12; sl@0: TBool gHaveSharedRes = ETrue; sl@0: TInt gSharedResStateDelta = -1; sl@0: #endif sl@0: sl@0: TBool gUseCached = EFalse; sl@0: sl@0: LOCAL_C TInt OpenChannel(TDesC16& aName, RBusDevResManUs& aChannel) sl@0: { sl@0: TInt r = KErrNone; sl@0: // API accepts 8-bit descriptors, only - so convert name accordingly sl@0: TBuf8EightBitName; sl@0: EightBitName.Copy(aName); sl@0: r=(aChannel.Open(EightBitName)); sl@0: if (r!=KErrNone) sl@0: gTest.Printf(_L("OpenChannel: Handle for channel %S error code =0x%x\n"),&aName,r); sl@0: else sl@0: gTest.Printf(_L("OpenChannel: Handle for channel %S =0x%x\n"),&aName,aChannel.Handle()); sl@0: return r; sl@0: } sl@0: sl@0: LOCAL_C TInt HelperResources() sl@0: // sl@0: // Helper method to support OpenAndRegisterChannel sl@0: // Invokes GetNoOfResources, GetAllResourcesInfo and GetResourceIdByName sl@0: // sl@0: { sl@0: TInt r = KErrNone; sl@0: sl@0: __KHEAP_MARK; sl@0: sl@0: // Check what resources are available sl@0: gTest.Printf(_L("**Test GetNoOfResources\n")); sl@0: TUint numResources=0; sl@0: if((r=gChannel.GetNoOfResources(numResources))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("GetNoOfResources for test channel returned %d\n"),r); sl@0: return r; sl@0: } sl@0: gTest.Printf(_L("Number of resources = %d (=0x%x)\n"),numResources,numResources); sl@0: sl@0: // Read the resource information sl@0: gTest.Printf(_L("**Test GetAllResourcesInfo\n")); sl@0: sl@0: // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects sl@0: // and reference via an RSimplePointerArray sl@0: TUint bufSize = numResources; sl@0: RSimplePointerArray infoPtrs(bufSize); sl@0: for(TUint i=0;iname; sl@0: for(TUint i=0; i1) sl@0: currRes=(*infoPtrs[1])();// First resource may be a dummy sl@0: TUint resourceId; sl@0: gTest.Printf(_L("Invoking GetResourceIdByName for last resource name extracted \n")); sl@0: if((r=gChannel.GetResourceIdByName(currRes.iName, resourceId))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("GetResourceIdByName for channel returned %d \n"),r); sl@0: return r; sl@0: } sl@0: gTest.Printf(_L("GetResourceIdByName gave ID = %d\n"),resourceId); sl@0: sl@0: infoPtrs.Close(); sl@0: sl@0: __KHEAP_MARKEND; sl@0: sl@0: return r; sl@0: } sl@0: sl@0: LOCAL_C TInt CheckForSimulatedResources() sl@0: // sl@0: // Get the name of the first resource - if it does not match the expected name sl@0: // then the testing must not proceed, so return the relevant error code sl@0: // sl@0: { sl@0: TInt r = KErrNone; sl@0: TResourceInfoBuf buffer; sl@0: if((r=gChannel.GetResourceInfo(1, &buffer))!=KErrNone) // first resource ID = 1 sl@0: { sl@0: gTest.Printf(_L("CheckForSimulatedResources, candidate get resource info returned %d\n"),r); sl@0: return r; sl@0: } sl@0: // Check the name of the resource sl@0: TBuf16name; sl@0: name.Copy(buffer().iName); sl@0: name.PtrZ(); sl@0: if((r=name.Compare(testableResourceName))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("Resource name = %S, require %S \n"),&name,&testableResourceName); sl@0: r=KErrNotSupported; sl@0: } sl@0: return r; sl@0: } sl@0: sl@0: //---------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-T_RESMANUS-0607 sl@0: //! @SYMTestType UT sl@0: //! @SYMPREQ PREQ1398 sl@0: //! @SYMTestCaseDesc This test case tests channel opening and initialisation APIs. sl@0: //! @SYMTestActions 0) Call Open API with a valid name. sl@0: //! sl@0: //! 1) Call Open API for two more channels sl@0: //! (to demonstrate multiple clients (channels) can be supported concurrently). sl@0: //! sl@0: //! 2) Call Open with an oversized name. sl@0: //! sl@0: //! 3) Call GetNoOfResources API sl@0: //! sl@0: //! 4) Call GetAllResourcesInfo API sl@0: //! sl@0: //! 5) Call GetResourceIdByName API for last of resource names gathered sl@0: //! in previous step sl@0: //! sl@0: //! 6) Call Initialise API on the channel originally created, with non-zero arguments. sl@0: //! sl@0: //! @SYMTestExpectedResults 0) API should return with KErrNone, exits otherwise. sl@0: //! 1) API should return with KErrNone, exits otherwise. sl@0: //! 2) API should return with KErrBadName, exits otherwise. sl@0: //! 3) API should return with KErrNone, exits otherwise. sl@0: //! 4) API should return with KErrNone, exits otherwise. sl@0: //! 5) API should return with KErrNone, exits otherwise. sl@0: //! 6) API should return with KErrNone, exits otherwise. sl@0: //! sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //---------------------------------------------------------------------------------------------- sl@0: LOCAL_C TInt OpenAndRegisterChannel() sl@0: // sl@0: // Test Open and Initialise functionality sl@0: // Also invokes Resource inspection methods via HelperResource sl@0: // sl@0: { sl@0: TInt r; sl@0: sl@0: if((r=OpenChannel(gTestName, gChannel))!=KErrNone) sl@0: return r; sl@0: sl@0: // Check that the simulated resources required to support this testing are present sl@0: // If not, close the channel and return the propagated error code. sl@0: if((r=CheckForSimulatedResources())!=KErrNone) sl@0: { sl@0: gChannel.Close(); sl@0: return r; sl@0: } sl@0: sl@0: __KHEAP_MARK; // gTestName will remain open (allocated) when heap is checked sl@0: sl@0: // Open a couple of additional channels to prove that more than one sl@0: // can exist sl@0: _LIT(tempStr1,"temp1"); sl@0: TBufC<16> tempName1(tempStr1); sl@0: _LIT(tempStr2,"temp2"); sl@0: TBufC<16> tempName2(tempStr2); sl@0: sl@0: RBusDevResManUs channelTwo; sl@0: RBusDevResManUs channelThree; sl@0: sl@0: if((r=OpenChannel(tempName1, channelTwo))!=KErrNone) sl@0: return r; sl@0: if((r=OpenChannel(tempName2, channelThree))!=KErrNone) sl@0: return r; sl@0: sl@0: // The following test requires manual enabling in resource controller of macro sl@0: // DEBUG_VERSION - this is not done by default, so test is deactivated here. sl@0: // sl@0: #if 0 sl@0: // Test rejection if try a name already in use sl@0: // sl@0: // (For UREL builds, duplicate names are allowed; but sl@0: // for UDEB builds, they are monitored and rejected) sl@0: // sl@0: RBusDevResManUs channelSameName; sl@0: r=OpenChannel(tempName1, channelSameName); sl@0: channelSameName.Close(); // Channel not used after here sl@0: if (r==KErrNone) sl@0: { sl@0: gTest.Printf(_L("Error: Handle for re-used name channel =0x%x\n"),channelSameName.Handle()); sl@0: return KErrGeneral; sl@0: } sl@0: else if(r!=KErrCouldNotConnect) sl@0: { sl@0: gTest.Printf(_L("Error: re-used name gave unexpected error code =0x%x\n"),r); sl@0: return r; sl@0: } sl@0: else // if(r==KErrCouldNotConnect) sl@0: { sl@0: gTest.Printf(_L("Re-used channel name rejected with correct error code\n")); sl@0: } sl@0: #endif // if 0 sl@0: sl@0: // Test oversized name rejection sl@0: _LIT(longStr,"1abcdefghijklmnopqrstuvwxyz2abcdefghijklmnopqrstuvwxyz3abcdefghijklmnopqrstuvwxyz4abcdefghijklmnopqrstuvwxyz5abcdefghijklmnopqrstuvwxyz6abcdefghijklmnopqrstuvwxyz7abcdefghijklmnopqrstuvwxyz8abcdefghijklmnopqrstuvwxyz9abcdefghijklmnopqrstuvwxyz10abcdefghijklmnopqrstuvwxyz"); sl@0: TBufC<271> longName(longStr); sl@0: sl@0: // API accepts 8-bit descriptors for names, only sl@0: TBuf8<271>longName_8Bit; sl@0: longName_8Bit.Copy(longName); sl@0: sl@0: RBusDevResManUs channelLong; sl@0: r=(channelLong.Open(longName_8Bit)); sl@0: channelLong.Close(); // Channel not used after here sl@0: if (r==KErrNone) sl@0: { sl@0: gTest.Printf(_L("Error: Handle for oversize name channel =0x%x\n"),channelLong.Handle()); sl@0: return KErrGeneral; sl@0: } sl@0: else if(r!=KErrBadName) sl@0: { sl@0: gTest.Printf(_L("Error: oversized name gave unexpected error code =0x%x\n"),r); sl@0: return r; sl@0: } sl@0: else // if(r==KErrBadName) sl@0: { sl@0: gTest.Printf(_L("Oversized name for channel rejected with correct error code\n")); sl@0: } sl@0: sl@0: // Invokes GetNoOfResources, GetAllResourcesInfo and GetResourceIdByName sl@0: if((r=HelperResources())!=KErrNone) sl@0: return r; sl@0: sl@0: // Close the temporary channels sl@0: // Do this before channel registration to enable valid check of kernel heap sl@0: channelTwo.Close(); sl@0: channelThree.Close(); sl@0: sl@0: __KHEAP_MARKEND; sl@0: sl@0: // Channel registration sl@0: gTest.Printf(_L("Invoking Initialise with values 0x%x, 0x%x, 0x%x\n"),KNoOfGetStateRequests,KNoOfSetStateRequests,KNoOfNotifyRequests); sl@0: if ((r=gChannel.Initialise(KNoOfGetStateRequests,KNoOfSetStateRequests,KNoOfNotifyRequests))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("Initialise for channel returned %d\n"),r); sl@0: return r; sl@0: } sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: LOCAL_C TInt HelperClients() sl@0: // sl@0: // Helper method to support TestGetClientGetResourceInfo sl@0: // Invokes GetNoOfClients and GetNamesAllClients sl@0: // sl@0: { sl@0: __KHEAP_MARK; sl@0: sl@0: TInt r = KErrNone; sl@0: TUint numClients = 0; sl@0: TUint numAllClients = 0; sl@0: // sl@0: // GetNoOfClients - with aIncludeKern=EFalse sl@0: // sl@0: if((r=gChannel.GetNoOfClients(numClients, EFalse)) != KErrNone) sl@0: { sl@0: gTest.Printf(_L("GetNoOfClients (aIncludeKern==EFalse) returned %d\n"),r); sl@0: return r; sl@0: } sl@0: gTest.Printf(_L("GetNoOfClients (aIncludeKern==EFalse) gave 0x%x clients\n"),numClients); sl@0: sl@0: // sl@0: // GetNoOfClients - with aIncludeKern=ETrue sl@0: // sl@0: r=gChannel.GetNoOfClients(numAllClients, ETrue); sl@0: #ifdef RESMANUS_KERN sl@0: if(r==KErrNone) sl@0: gTest.Printf(_L("GetNoOfClients (aIncludeKern==ETrue) returned KErrNone\n")); sl@0: #else sl@0: if(r==KErrPermissionDenied) sl@0: gTest.Printf(_L("GetNoOfClients (aIncludeKern==ETrue) returned KErrPermissionDenied\n")); sl@0: #endif sl@0: else sl@0: { sl@0: gTest.Printf(_L("GetNoOfClients (aIncludeKern==ETrue) returned %d"),r); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: // To support the GetNamesAllClients testing, instantiate TClientName objects sl@0: // and reference via an RSimplePointerArray sl@0: TUint bufSize = (numAllClients>numClients)?numAllClients:numClients; sl@0: RSimplePointerArray infoPtrs(bufSize); sl@0: for(TUint i=0;i name; sl@0: name.Copy(*currName); sl@0: gTest.Printf(_L("Client name %d = %S\n"),i,&name); sl@0: } sl@0: } sl@0: #endif sl@0: sl@0: // sl@0: // GetNamesAllClients - with aIncludeKern=ETrue sl@0: // sl@0: #ifdef RESMANUS_KERN sl@0: if((r=gChannel.GetNamesAllClients(&infoPtrs, numAllClients, ETrue)) != KErrNone) sl@0: { sl@0: gTest.Printf(_L("GetNamesAllClients (aIncludeKern==ETrue) returned %d\n"),r); sl@0: return r; sl@0: } sl@0: #ifdef _DEBUG sl@0: else sl@0: { sl@0: gTest.Printf(_L("GetNamesAllClients (aIncludeKern==ETrue) returned KErrNone, names follow\n")); sl@0: for(TUint i=0;i name; sl@0: name.Copy(*currName); sl@0: gTest.Printf(_L("Client name %d = %S\n"),i,&name); sl@0: } sl@0: } sl@0: #endif sl@0: #else sl@0: if((r=gChannel.GetNamesAllClients(&infoPtrs, numClients, ETrue)) == KErrPermissionDenied) sl@0: { sl@0: gTest.Printf(_L("GetNamesAllClients (aIncludeKern==ETrue) returned KErrPermissionDenied\n")); sl@0: r=KErrNone; // Ensure misleading status is not returned sl@0: } sl@0: else sl@0: { sl@0: gTest.Printf(_L("GetNamesAllClients (aIncludeKern==ETrue) returned %d"),r); sl@0: return r; sl@0: } sl@0: #endif sl@0: sl@0: infoPtrs.Close(); sl@0: __KHEAP_MARKEND; sl@0: sl@0: return r; sl@0: } sl@0: sl@0: LOCAL_C TInt HelperClientsUsingResource(TUint aResourceId) sl@0: // sl@0: // Helper method to support TestGetClientGetResourceInfo sl@0: // Invokes GetNumClientsUsingResource and GetInfoOnClientsUsingResource sl@0: // sl@0: { sl@0: __KHEAP_MARK; sl@0: sl@0: TInt r = KErrNone; sl@0: // sl@0: // GetNumClientsUsingResource - with aIncludeKern=ETrue sl@0: // sl@0: TUint resourceAllClients = 0; sl@0: if((r=gChannel.GetNumClientsUsingResource(aResourceId, resourceAllClients, ETrue)) == KErrPermissionDenied) sl@0: { sl@0: gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==ETrue) returned KErrPermissionDenied\n")); sl@0: #ifdef RESMANUS_KERN sl@0: return r; sl@0: } sl@0: else sl@0: { sl@0: if(r!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==ETrue) returned %d\n"),r); sl@0: return r; sl@0: } sl@0: else sl@0: gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==ETrue) reported 0x%x clients\n"),resourceAllClients); sl@0: } sl@0: #else sl@0: } sl@0: else sl@0: { sl@0: gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==ETrue) returned %d\n"),r); sl@0: return r; sl@0: } sl@0: #endif sl@0: // sl@0: // GetNumClientsUsingResource - with aIncludeKern=EFalse sl@0: // sl@0: TUint resourceClients = 0; sl@0: if((r=gChannel.GetNumClientsUsingResource(aResourceId, resourceClients, EFalse)) != KErrNone) sl@0: { sl@0: // If there are no clients that have requested a level then the Resource Controller will sl@0: // the client ID as a bad argument sl@0: if(!((resourceClients==0)&&(r==KErrArgument))) sl@0: { sl@0: gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==EFalse) returned %d\n"),r); sl@0: return r; sl@0: } sl@0: else sl@0: r=KErrNone; // Ensure expected error is not misinterpeted sl@0: } sl@0: else sl@0: gTest.Printf(_L("GetNumClientsUsingResource (aIncludeKern==EFalse) reported 0x%x clients\n"),resourceClients); sl@0: sl@0: // To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects sl@0: // and reference via an RSimplePointerArray sl@0: TUint bufSize = (resourceAllClients>resourceClients)?resourceAllClients:resourceClients; sl@0: if(bufSize>0) sl@0: { sl@0: RSimplePointerArray infoPtrs(bufSize); sl@0: for(TUint i=0;i name; sl@0: name.Copy(currInfo.iName); sl@0: gTest.Printf(_L("Client name %d = %S, ID=0x%x\n"),i,&name,currInfo.iId); sl@0: } sl@0: } sl@0: #endif sl@0: // sl@0: // GetInfoOnClientsUsingResource - with aIncludeKern=ETrue sl@0: // sl@0: r=gChannel.GetInfoOnClientsUsingResource(aResourceId, resourceAllClients, &infoPtrs, ETrue); sl@0: { sl@0: #ifdef RESMANUS_KERN sl@0: if(r != KErrNone) sl@0: { sl@0: // If there are no clients that have requested a level then the Resource Controller sl@0: // will report a request for information on 0 clients as a bad argument sl@0: if(!((resourceClients==0)&&(r==KErrArgument))) sl@0: { sl@0: gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned %d\n"),r); sl@0: return r; sl@0: } sl@0: else sl@0: r=KErrNone; // Ensure misleading result is not returned sl@0: } sl@0: #ifdef _DEBUG sl@0: else sl@0: { sl@0: gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned KErrNone, info follows\n")); sl@0: for(TUint i=0;i name; sl@0: name.Copy(currInfo.iName); sl@0: gTest.Printf(_L("Client name %d = %S, ID=0x%x\n"),i,&name,currInfo.iId); sl@0: } sl@0: } sl@0: #endif sl@0: #else sl@0: if(r == KErrNone) sl@0: { sl@0: gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned KErrNone")); sl@0: return KErrGeneral; sl@0: } sl@0: else if(r==KErrPermissionDenied) sl@0: { sl@0: gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned KErrPermissionDenied\n")); sl@0: r=KErrNone; // Ensure that misleading result is not propagated sl@0: } sl@0: else sl@0: { sl@0: gTest.Printf(_L("GetInfoOnClientsUsingResource (aIncludeKern==ETrue) returned %d\n"),r); sl@0: // If there are no clients that have requested a level then the Resource Controller sl@0: // will report a request for information on 0 clients as a bad argument sl@0: if(!((resourceClients==0)&&(r==KErrArgument))) sl@0: return r; sl@0: } sl@0: #endif sl@0: } sl@0: } sl@0: sl@0: __KHEAP_MARKEND; sl@0: sl@0: return r; sl@0: } sl@0: sl@0: sl@0: sl@0: LOCAL_C TInt HelperResourcesInUseByClient() sl@0: // sl@0: // Helper method to supportTestGetClientGetResourceInfo sl@0: // Invokes GetNumResourcesInUseByClient and GetInfoOnResourcesInUseByClient sl@0: // sl@0: { sl@0: __KHEAP_MARK; sl@0: sl@0: TInt r = KErrNone; sl@0: // sl@0: // GetNumResourcesInUseByClient sl@0: // sl@0: // API accepts 8-bit descriptors, only - so convert name accordingly sl@0: TBuf8name8Bit; sl@0: name8Bit.Copy(gTestName); sl@0: TClientName* clientName = (TClientName*)&name8Bit; sl@0: #if _DEBUG sl@0: TBuf clientName16Bit; sl@0: clientName16Bit.Copy(*clientName); sl@0: clientName16Bit.SetLength(clientName->Length()); sl@0: gTest.Printf(_L("Invoking GetNumResourcesInUseByClient with %S (expect KErrPermissionDenied if no levels requested yet)\n"),&clientName16Bit); sl@0: #endif sl@0: TUint numResourcesForClient; sl@0: if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResourcesForClient)) != KErrNone) sl@0: { sl@0: gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r); sl@0: return r; sl@0: } sl@0: gTest.Printf(_L("GetNumResourcesInUseByClient gave number of resources = %d\n"),numResourcesForClient); sl@0: // sl@0: // In addition, check response when the name of an unknown client is passed sl@0: // sl@0: // Negative test - ensure that an unknown client name fails sl@0: _LIT(dumName,"DoesNotExist"); sl@0: TBuf<16> dumNameBuf(dumName); sl@0: TBuf8dumName8Bit; sl@0: dumName8Bit.Copy(dumNameBuf); sl@0: TClientName* dumClientName = (TClientName*)&dumName8Bit; sl@0: #if _DEBUG sl@0: gTest.Printf(_L("Invoking GetNumResourcesInUseByClient with %S\n"),&dumNameBuf); sl@0: #endif sl@0: TUint numResForDumClient; sl@0: if((r=gChannel.GetNumResourcesInUseByClient(*dumClientName, numResForDumClient)) != KErrNotFound) sl@0: { sl@0: gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r); sl@0: if(r==KErrNone) sl@0: r=KErrGeneral; sl@0: return r; sl@0: } sl@0: gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r); sl@0: r=KErrNone; // Ensure misleading error code is not propagated sl@0: sl@0: // sl@0: // GetInfoOnResourcesInUseByClient sl@0: // sl@0: // If the (TUint) number of resources in use by the client is zero skip the attempt to read the resource information sl@0: TUint updatedNumResourcesForClient = numResourcesForClient; sl@0: if(numResourcesForClient!=0) sl@0: { sl@0: TUint bufSize = numResourcesForClient; sl@0: RSimplePointerArray infoPtrs(bufSize); sl@0: for(TUint i=0;iname; sl@0: for(TUint i=0; i0) && !gHaveAsyncRes) sl@0: { sl@0: TUint tryResourceId=0; sl@0: r=gChannel.GetCandidateAsyncResourceId(index,tryResourceId); sl@0: if(r!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("SetAsyncResource, GetCandidateAsyncResourceId returned %d\n"),r); sl@0: break; sl@0: } sl@0: gTest.Printf(_L("SetAsyncResource, GetNumCandidateAsyncResources index %d, resource ID %d\n"),index,tryResourceId); sl@0: // For the candidate resource to be usable, we need its current state sl@0: // to be sufficiently less the maximum for positive sense (or sufficiently sl@0: // more than the greater than the minimum for negative sense - but the current sl@0: // version of the code only considers positive sense). sl@0: gChannel.GetResourceState(status,tryResourceId,cached,&readValue,&levelOwnerId); sl@0: User::WaitForRequest(status); sl@0: if(status.Int() != KErrNone) sl@0: { sl@0: gTest.Printf(_L("SetAsyncResource, candidate get state returned %d\n"),r); sl@0: return r; sl@0: } sl@0: gTest.Printf(_L("SetAsyncResource, candidate get state gave %d, levelOwnerId = %d\n"),readValue,levelOwnerId); sl@0: TResourceInfoBuf buffer; sl@0: if((r=gChannel.GetResourceInfo(tryResourceId, &buffer))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("SetAsyncResource, candidate get resource info returned %d\n"),r); sl@0: return r; sl@0: } sl@0: // Print resource info sl@0: TBuf16name; sl@0: TResourceInfo* infoPtr = &(buffer()); sl@0: name.Copy(infoPtr->iName); sl@0: gTest.Printf(_L("SetAsyncResource: Resource name = %S \n"),&name); sl@0: gTest.Printf(_L("SetAsyncResource: Resource Class =%d\n"),infoPtr->iClass); sl@0: gTest.Printf(_L("SetAsyncResource: Resource Type =%d\n"), infoPtr->iType); sl@0: gTest.Printf(_L("SetAsyncResource: Resource Usage =%d\n"), infoPtr->iUsage); sl@0: gTest.Printf(_L("SetAsyncResource: Resource Sense =%d\n"), infoPtr->iSense); sl@0: gTest.Printf(_L("SetAsyncResource: Resource MinLevel =%d\n"),infoPtr->iMinLevel); sl@0: gTest.Printf(_L("SetAsyncResource: Resource MaxLevel =%d\n"),infoPtr->iMaxLevel); sl@0: sl@0: if((infoPtr->iMaxLevel - readValue) > LEVEL_GAP_REQUIRED_FOR_ASYNC_TESTING) sl@0: { sl@0: gLongLatencyResource = tryResourceId; sl@0: gAsyncResStateDelta = 1; // Will change resource level in positive direction sl@0: gHaveAsyncRes = ETrue; sl@0: } sl@0: else if((readValue - infoPtr->iMinLevel) > LEVEL_GAP_REQUIRED_FOR_ASYNC_TESTING) sl@0: { sl@0: gLongLatencyResource = tryResourceId; sl@0: gAsyncResStateDelta = -1; // Will change resource level in negative direction sl@0: gHaveAsyncRes = ETrue; sl@0: } sl@0: else sl@0: { sl@0: ++index; sl@0: --numPotentialResources; sl@0: } sl@0: }; sl@0: } sl@0: if(!gHaveAsyncRes) sl@0: { sl@0: gTest.Printf(_L("**Test SetAsyncResource - don't have suitable resource ... exiting\n")); sl@0: return KErrNotReady; sl@0: } sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: LOCAL_C TInt SetSharedResource() sl@0: // sl@0: // Support function for tests of shareable resources sl@0: // sl@0: { sl@0: __KHEAP_MARK; sl@0: sl@0: if(!gHaveSharedRes) sl@0: { sl@0: TRequestStatus status; sl@0: TBool cached = gUseCached; sl@0: TInt readValue = 0; sl@0: TUint numPotentialResources; sl@0: TUint index=0; sl@0: TInt r=gChannel.GetNumCandidateSharedResources(numPotentialResources); sl@0: if(r!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("SetSharedResource, GetNumCandidateSharedResources returned %d\n"),r); sl@0: return r; sl@0: } sl@0: gTest.Printf(_L("SetSharedResource, GetNumCandidateSharedResources found %d resources\n"),numPotentialResources); sl@0: while((numPotentialResources>0) && !gHaveSharedRes) sl@0: { sl@0: TUint tryResourceId=0; sl@0: r=gChannel.GetCandidateSharedResourceId(index,tryResourceId); sl@0: if(r!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("SetSharedResource, GetCandidateSharedResourceId returned %d\n"),r); sl@0: break; sl@0: } sl@0: gTest.Printf(_L("SetSharedResource, GetNumCandidateSharedResources index %d, resource ID %d\n"),index,tryResourceId); sl@0: // To support the tests, the selected shareable resource must not be the same sl@0: // resource as that selected for asynchronous testing sl@0: if(gHaveAsyncRes) sl@0: if(tryResourceId==gLongLatencyResource) sl@0: { sl@0: gTest.Printf(_L("SetSharedResource - skipping candidate resource %d - already used for async testing\n"),tryResourceId); sl@0: continue; sl@0: } sl@0: // For the candidate resource to be usable, we need its current state sl@0: // to be sufficiently less the maximum for positive sense (or sufficiently sl@0: // more than the greater than the minimum for negative sense - but the current sl@0: // version of the code only considers positive sense). sl@0: TInt levelOwnerId = 0; sl@0: gChannel.GetResourceState(status,tryResourceId,cached,&readValue,&levelOwnerId); sl@0: User::WaitForRequest(status); sl@0: if(status.Int() != KErrNone) sl@0: { sl@0: gTest.Printf(_L("SetSharedResource, candidate get state returned %d\n"),r); sl@0: return r; sl@0: } sl@0: gTest.Printf(_L("SetSharedResource, candidate get state gave %d, levelOwnerId = %d\n"),readValue,levelOwnerId); sl@0: TResourceInfoBuf buffer; sl@0: if((r=gChannel.GetResourceInfo(tryResourceId, &buffer))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("SetSharedResource, candidate get resource info returned %d\n"),r); sl@0: return r; sl@0: } sl@0: // Print resource info sl@0: TBuf16name; sl@0: TResourceInfo* infoPtr = &buffer(); sl@0: name.Copy(infoPtr->iName); sl@0: gTest.Printf(_L("SetSharedResource: Resource name = %S \n"),&name); sl@0: gTest.Printf(_L("SetSharedResource: Resource Class =%d\n"),infoPtr->iClass); sl@0: gTest.Printf(_L("SetSharedResource: Resource Type =%d\n"), infoPtr->iType); sl@0: gTest.Printf(_L("SetSharedResource: Resource Usage =%d\n"), infoPtr->iUsage); sl@0: gTest.Printf(_L("SetSharedResource: Resource Sense =%d\n"), infoPtr->iSense); sl@0: gTest.Printf(_L("SetSharedResource: Resource MinLevel =%d\n"),infoPtr->iMinLevel); sl@0: gTest.Printf(_L("SetSharedResource: Resource MaxLevel =%d\n"),infoPtr->iMaxLevel); sl@0: sl@0: if((infoPtr->iMaxLevel - readValue) > LEVEL_GAP_REQUIRED_FOR_ASYNC_TESTING) sl@0: { sl@0: gSharedResource = tryResourceId; sl@0: gSharedResStateDelta = 1; // Will change resource level in positive direction sl@0: gHaveSharedRes = ETrue; sl@0: } sl@0: else if((readValue - infoPtr->iMinLevel) > LEVEL_GAP_REQUIRED_FOR_ASYNC_TESTING) sl@0: { sl@0: gSharedResource = tryResourceId; sl@0: gSharedResStateDelta = -1; // Will change resource level in negative direction sl@0: gHaveSharedRes = ETrue; sl@0: } sl@0: else sl@0: { sl@0: ++index; sl@0: --numPotentialResources; sl@0: } sl@0: }; sl@0: } sl@0: if(!gHaveSharedRes) sl@0: { sl@0: gTest.Printf(_L("**Test SetSharedResource - don't have suitable resource ... exiting\n")); sl@0: return KErrNotReady; sl@0: } sl@0: sl@0: __KHEAP_MARKEND; sl@0: return KErrNone; sl@0: } sl@0: sl@0: #endif sl@0: sl@0: sl@0: //---------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-T_RESMANUS-0609 sl@0: //! @SYMTestType UT sl@0: //! @SYMPREQ PREQ1398 sl@0: //! @SYMTestCaseDesc This test case tests APIs for retrieving information about sl@0: //! (1) clients of the channel and sl@0: //! (2) power resources. sl@0: //! Since the client lacks the ReadDeviceData PlatSec capability it will not sl@0: //! be permitted to access information about kernel-side clients sl@0: //! sl@0: //! The tests are invoked a number of times: sl@0: //! - first, to examine the starting state sl@0: //! - then, to examine the effect of adding a new client (channel) sl@0: //! - then, the examine the effect of adding a new client that requests a sl@0: //| level on a resource sl@0: //! - then, to test the effect of the original client requesting a level sl@0: //! on a resource sl@0: //! sl@0: //! @SYMTestActions 0) Call GetNoOfClients API with default aIncludeKern=EFalse. sl@0: //! sl@0: //! 1) Call GetNoOfClients API with aIncludeKern=ETrue. sl@0: //! sl@0: //! 2) Call GetNamesAllClients API with default aIncludeKern=EFalse. sl@0: //! sl@0: //! 3) Call GetNamesAllClients API with aIncludeKern=ETrue. sl@0: //! sl@0: //! 4) Call GetNumClientsUsingResource API with aIncludeKern=ETrue. sl@0: //! sl@0: //! 5) Call GetNumClientsUsingResource API with default aIncludeKern=EFalse. sl@0: //! sl@0: //! 6) Call GetInfoOnClientsUsingResource API with default aIncludeKern=EFalse. sl@0: //! sl@0: //! 7) Call GetInfoOnClientsUsingResource API with aIncludeKern=ETrue. sl@0: //! sl@0: //! 8) GetNumResourcesInUseByClient for the original client sl@0: //! sl@0: //! 9) GetNumResourcesInUseByClient for a non-existent client sl@0: //! sl@0: //! 10) GetInfoOnResourcesInUseByClient for the original client sl@0: //! sl@0: //! 11) GetInfoOnResourcesInUseByClient for a non-existent client sl@0: //! sl@0: //! @SYMTestExpectedResults 0) API should return with KErrNone, exits otherwise. sl@0: //! sl@0: //! 1) If client exhibits PlatSec capability ReadDeviceData, API should return with KErrNone, exits otherwise. sl@0: //! If client lacks PlatSec capability ReadDeviceData, API should return with KErrPermissionDenied, exits otherwise. sl@0: //! sl@0: //! 2) API should return with KErrNone, exits otherwise. sl@0: //! sl@0: //! 3) If client exhibits PlatSec capability ReadDeviceData, API should return with KErrNone, exits otherwise sl@0: //! If client lacks PlatSec capability ReadDeviceData, API should return with KErrPermissionDenied, exits otherwise sl@0: //! sl@0: //! 4) If client exhibits PlatSec capability ReadDeviceData, API should return with KErrNone, exits otherwise. sl@0: //! If client lacks PlatSec capability ReadDeviceData, API should return with KErrPermissionDenied, exits otherwise. sl@0: //! sl@0: //! 5) API should return with KErrNone, exits otherwise sl@0: //! sl@0: //! 6) API should return with KErrNone, exits otherwise. sl@0: //! sl@0: //! 7) If client exhibits PlatSec capability ReadDeviceData, API should return with KErrNone, exits otherwise sl@0: //! If client lacks PlatSec capability ReadDeviceData, API should return with KErrPermissionDenied, exits otherwise sl@0: //! sl@0: //! 8) API should return with KErrNone, exits otherwise. sl@0: //! sl@0: //! 9) API should return with KErrNotFound, exits otherwise. sl@0: //! sl@0: //! 10) API should return with KErrNone, exits otherwise. sl@0: //! sl@0: //! 11) API should return with KErrNotFound, exits otherwise. sl@0: //! sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //---------------------------------------------------------------------------------------------- sl@0: LOCAL_C TInt TestGetClientGetResourceInfo() sl@0: // sl@0: // Test methods to access information about clients and resources sl@0: // sl@0: { sl@0: TInt r = KErrNone; sl@0: sl@0: // Open a couple of additional channels sl@0: _LIT(tempStr1,"ExtraChan1"); sl@0: TBufC<16> tempName1(tempStr1); sl@0: _LIT(tempStr2,"ExtraChan2"); sl@0: TBufC<16> tempName2(tempStr2); sl@0: sl@0: RBusDevResManUs channelTwo; sl@0: RBusDevResManUs channelThree; sl@0: sl@0: if((r=OpenChannel(tempName1, channelTwo))!=KErrNone) sl@0: return r; sl@0: if((r=OpenChannel(tempName2, channelThree))!=KErrNone) sl@0: return r; sl@0: sl@0: // Test the tracking of the client and resource info sl@0: // sl@0: sl@0: // First invocation to establish starting state sl@0: #ifdef _DEBUG sl@0: gTest.Printf(_L("TestGetClientGetResourceInfo: First HelperGetClientResourceInfo call (starting state):\n")); sl@0: #endif sl@0: if((r=HelperGetClientResourceInfo())!=KErrNone) sl@0: return r; sl@0: sl@0: // Second invocation - examine effect of adding a client sl@0: _LIT(tempStr3,"ExtraChan3"); sl@0: TBufC<16> tempName3(tempStr3); sl@0: RBusDevResManUs channelFour; sl@0: if((r=OpenChannel(tempName3, channelFour))!=KErrNone) sl@0: return r; sl@0: #ifdef _DEBUG sl@0: gTest.Printf(_L("TestGetClientGetResourceInfo: Second HelperGetClientResourceInfo call (added client ExtraChan3):\n")); sl@0: #endif sl@0: sl@0: if((r=HelperGetClientResourceInfo())!=KErrNone) sl@0: return r; sl@0: sl@0: // Third invocation - examine effect of new client requesting a level for a resource sl@0: // (This relies on getting and setting the state of gSharedResource - so skip the sl@0: // test if this has not yet been identified sl@0: // sl@0: TUint startingLevel = 0; sl@0: #ifdef _DEBUG sl@0: if((r=SetSharedResource())!=KErrNone) sl@0: return r; sl@0: #endif sl@0: if(!gHaveSharedRes) sl@0: { sl@0: gTest.Printf(_L("TestGetClientGetResourceInfo: no suitable shareable resource, so skipping third call:\n")); sl@0: } sl@0: else sl@0: { sl@0: // Channel registration sl@0: gTest.Printf(_L("Initialise for temporary channel with arguments 1,1,0\n")); sl@0: if ((r=channelFour.Initialise(1,1,0))!=KErrNone) // Just need 1 get and 1 set state sl@0: { sl@0: gTest.Printf(_L("Initialise for channel returned %d\n"),r); sl@0: return r; sl@0: } sl@0: // Get initial state sl@0: TRequestStatus status; sl@0: TBool cached = gUseCached; sl@0: TInt readValue; sl@0: TInt levelOwnerId = 0; sl@0: channelFour.GetResourceState(status,gSharedResource,cached,&readValue,&levelOwnerId); sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestGetClientGetResourceInfo, first get state for shareable returned %d\n"),r); sl@0: return r; sl@0: } sl@0: startingLevel = (TUint)readValue; sl@0: // Write updated state sl@0: TUint newLevel = (TUint)(readValue + gSharedResStateDelta); sl@0: gTest.Printf(_L("TestGetClientGetResourceInfo: levelOwnerId = %d\n"), levelOwnerId); sl@0: gTest.Printf(_L("TestGetClientGetResourceInfo: shareable resource startingLevel=0x%x, writing 0x%x\n"), startingLevel, newLevel); sl@0: channelFour.ChangeResourceState(status,gSharedResource,newLevel); sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestGetClientGetResourceInfo, first change state for shareable resource returned %d\n"),r); sl@0: return r; sl@0: } sl@0: #ifdef _DEBUG sl@0: gTest.Printf(_L("TestGetClientGetResourceInfo: third HelperGetClientResourceInfo call (new client set level on shared resource):\n")); sl@0: #endif sl@0: if((r=HelperGetClientResourceInfo())!=KErrNone) sl@0: return r; sl@0: } sl@0: sl@0: sl@0: // Fourth invocation - examine effect of orignal client requesting a level for sl@0: // the Shared resource sl@0: if(gHaveSharedRes) sl@0: { sl@0: TRequestStatus status; sl@0: TBool cached = gUseCached; sl@0: TInt readValue; sl@0: TInt levelOwnerId; sl@0: gChannel.GetResourceState(status,gSharedResource,cached,&readValue,&levelOwnerId); sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestGetClientGetResourceInfo, gChannel get state on Shareable resource returned %d\n"),r); sl@0: return r; sl@0: } sl@0: gTest.Printf(_L("TestGetClientGetResourceInfo, GetResourceState levelOwnerId = %d\n"),levelOwnerId); // Request a level on the resource sl@0: gChannel.ChangeResourceState(status,gSharedResource,(readValue+gSharedResStateDelta)); sl@0: User::WaitForRequest(status); sl@0: if(status.Int() != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestGetClientGetResourceInfo, gChannel change state on Shareable returned %d\n"),r); sl@0: return r; sl@0: } sl@0: #ifdef _DEBUG sl@0: gTest.Printf(_L("TestGetClientGetResourceInfo: fourth HelperGetClientResourceInfo call (gChannel set level on Shareable resource):\n")); sl@0: #endif sl@0: if((r=HelperGetClientResourceInfo())!=KErrNone) sl@0: return r; sl@0: } sl@0: sl@0: // Return the resource to the state it was on function entry sl@0: if(gHaveSharedRes) sl@0: { sl@0: TRequestStatus status; sl@0: gTest.Printf(_L("TestGetClientGetResourceInfo: returning sharable resource to startingLevel=0x%x\n"), startingLevel); sl@0: gChannel.ChangeResourceState(status,gSharedResource,startingLevel); sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestGetClientGetResourceInfo, attempt to reset shareable resource state returned %d\n"),r); sl@0: return r; sl@0: } sl@0: } sl@0: sl@0: sl@0: // Close the temporary channels sl@0: channelTwo.Close(); sl@0: channelThree.Close(); sl@0: channelFour.Close(); sl@0: sl@0: return r; sl@0: } sl@0: sl@0: sl@0: sl@0: //---------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-T_RESMANUS-0610 sl@0: //! @SYMTestType UT sl@0: //! @SYMPREQ PREQ1398 sl@0: //! @SYMTestCaseDesc This test case tests APIs for getting and setting the state of resources; sl@0: //! it also tests APIs to cancel such requests. sl@0: //! sl@0: //! @SYMTestActions 0) Call API to get the initial state of a selected resource. sl@0: //! sl@0: //! 1) Call API to modify the state of the resource. sl@0: //! sl@0: //! 2) Call API to get the new state of the resource and check it exhibits sl@0: //! the expected value. sl@0: //! sl@0: //! 3) Call API to return the resource state to its original value. sl@0: //! sl@0: //! 4) Call API to get the state of a long latency resource then call API sl@0: //! with operation-type qualifier cancel the request. sl@0: //! sl@0: //! 5) Call API to modify the state of the long latency resource then call API sl@0: //! with operation-type qualifier to cancel the request. sl@0: //! sl@0: //! 6) Call API to get the state of a long latency resource and wait for it sl@0: //! to complete. Then call API with operation-type qualifier to cancel the request. sl@0: //! sl@0: //! 7) Call API to modify the state of the long latency resource and wait for sl@0: //! it to complete. Then call API with operation-type qualifier to cancel the request. sl@0: //! sl@0: //! 8) Call API to get the state of a long latency resource then call API sl@0: //! without operation-type qualifier to cancel the request. sl@0: //! sl@0: //! 9) Call API to modify the state of the long latency resource then call API sl@0: //! without operation-type qualifier to cancel the request. sl@0: //! sl@0: //! 10) Call API to get the state of a long latency resource and wait for it sl@0: //! to complete. Then call API without operation-type qualifier to cancel the request. sl@0: //! sl@0: //! 11) Call API to modify the state of the long latency resource and wait for sl@0: //! it to complete. Then call API without operation-type qualifier to cancel the request. sl@0: //! sl@0: //! 12) Call API to get the state of a long latency resource 'n' times. Then call API with sl@0: //! resource qualifier to cancel the requests. sl@0: //! sl@0: //! 13) Call API to modify the state of a long latency resource 'm' times. Then call API with sl@0: //! resource qualifier to cancel the requests. sl@0: //! sl@0: //! 14) Call API to get the state of a long latency resource 'n' times and wait for them to complete. sl@0: //! Then call API with resource qualifier to cancel the requests. sl@0: //! sl@0: //! 15) Call API to modify the state of a long latency resource 'm' times and wait for them to complete. sl@0: //! Then call API with resource qualifier to cancel the requests. sl@0: //! sl@0: //! 16) Call API to get the state of a long latency resource 'n' times, call API to modify the state of sl@0: //! a long latency resource 'm' times. Call the API to cancel the get operations with resource qualifier. sl@0: //! Wait for the operations to complete. Check the state of the associated TRequestStatus objects. sl@0: //! sl@0: //! 17) Call API to get the state of a long latency resource 'n' times, call API to modify the state of sl@0: //! a long latency resource 'm' times. Call the API to cancel the modify operations with resource qualifier. sl@0: //! Wait for the get operations to complete. Check the state of the associated TRequestStatus objects. sl@0: //! sl@0: //! 18) Call API to get the state of a long latency resource 'n' times, call API to modify the state of sl@0: //! a long latency resource 'm' times. Wait for the get operations to complete. Call the API to cancel the get sl@0: //! operations with resource qualifier. Check the state of the associated TRequestStatus objects. sl@0: //! sl@0: //! 19) Call API to get the state of a long latency resource 'n' times, call API to modify the state of sl@0: //! a long latency resource 'm' times. Wait for the modify operations to complete. Call the API to cancel the modify sl@0: //! operations with resource qualifier. Check the state of the associated TRequestStatus objects. sl@0: //! sl@0: //! 20) Call API to get the state of a long latency resource 'n' times, call API to modify the state of sl@0: //! a long latency resource 'm' times. sl@0: //! Then call API with operation-type qualifier to cancel the even-numbered get request(s). sl@0: //! Then call API without operation-type qualifier to cancel the even-numbered modify request(s). sl@0: //! Check the state of the associated TRequestStatus objects. sl@0: //! sl@0: //! @SYMTestExpectedResults 0) The associated TRequestStatus object should indicate KErrNone, exits otherwise. sl@0: //! sl@0: //! 1) The associated TRequestStatus object should indicate KErrNone, exits otherwise. sl@0: //! sl@0: //! 2) The associated TRequestStatus object should indicate KErrNone, exits otherwise. sl@0: //! Exit if the value read back is not as expected. sl@0: //! sl@0: //! 3) The associated TRequestStatus object should indicate KErrNone, exits otherwise. sl@0: //! sl@0: //! 4) The associated TRequestStatus object should indicate KErrCancel if the cancel sl@0: //! request was accepted, exits otherwise. sl@0: //! The associated TRequestStatus object should indicate KErrNone if the cancel request sl@0: //! was not accepted, exits otherwise. sl@0: //! sl@0: //! 5) The associated TRequestStatus object should indicate KErrCancel if the cancel sl@0: //! request was accepted, exits otherwise. sl@0: //! The associated TRequestStatus object should indicate KErrNone if the cancel request sl@0: //! was not accepted, exits otherwise. sl@0: //! sl@0: //! 6) The TRequestStatus object associated with the get operation should indicate sl@0: //! KErrNone - exits otherwise. The TRequestStatus object associated with the cancel sl@0: //! operation should indicate KErrNone - exits otherwise. sl@0: //! sl@0: //! 7) The TRequestStatus object associated with the get operation should indicate sl@0: //! KErrNone - exits otherwise. The TRequestStatus object associated with the cancel sl@0: //! operation should indicate KErrNone - exits otherwise. sl@0: //! sl@0: //! 8) The associated TRequestStatus object should indicate KErrCancel, exits otherwise. sl@0: //! sl@0: //! 9) The associated TRequestStatus object should indicate KErrCancel, exits otherwise. sl@0: //! sl@0: //! 10) The TRequestStatus object associated with the get operation should indicate sl@0: //! KErrNone - exits otherwise. The TRequestStatus object associated with the cancel sl@0: //! operation should indicate KErrNone - exits otherwise. sl@0: //! sl@0: //! 11) The TRequestStatus object associated with the get operation should indicate sl@0: //! KErrNone - exits otherwise. The TRequestStatus object associated with the cancel sl@0: //! operation should indicate KErrNone - exits otherwise. sl@0: //! sl@0: //! 12) The TRequestStatus objects should all exibit KErrCancel - exits otherwise. sl@0: //! sl@0: //! 13) The TRequestStatus objects should all exibit KErrCancel - exits otherwise. sl@0: //! sl@0: //! 14) The TRequestStatus objects associated with the get operations should all exibit KErrNone - exits otherwise. sl@0: //! The TRequestStatus objects associated with the cancel operations should all exibit KErrNone - exits otherwise sl@0: //! sl@0: //! 15) The TRequestStatus objects associated with the modify operations should all exibit KErrNone - exits otherwise. sl@0: //! The TRequestStatus objects associated with the cancel operations should all exibit KErrNone - exits otherwise sl@0: //! sl@0: //! 16) The TRequestStatus objects associated with the get operations should all exibit KErrCancel - exits otherwise. sl@0: //! The TRequestStatus objects associated with the modify operations should all exibit KErrNone - exits otherwise sl@0: //! sl@0: //! 17) The TRequestStatus objects associated with the get operations should all exibit KErrNone - exits otherwise. sl@0: //! The TRequestStatus objects associated with the modify operations should all exibit KErrCancel - exits otherwise sl@0: //! sl@0: //! 18) The TRequestStatus objects associated with the get and modify operations should all exibit KErrNone - exits otherwise. sl@0: //! sl@0: //! 19) The TRequestStatus objects associated with the get and modify operations should all exibit KErrNone - exits otherwise. sl@0: //! sl@0: //! 20) The TRequestStatus objects associated with the even-numbered request should exhibit KErrCancel. sl@0: //! The TRequestStatus objects associated with the odd-numbered request should exhibit KErrNone. sl@0: //! sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //---------------------------------------------------------------------------------------------- sl@0: LOCAL_C TInt TestGetSetResourceStateOps() sl@0: // sl@0: // Test resource state access methods sl@0: // sl@0: { sl@0: TInt r = KErrNone; sl@0: sl@0: TRequestStatus status; sl@0: TBool cached = gUseCached; sl@0: TInt readValue = 0; sl@0: TInt levelOwnerId = 0; sl@0: TInt testNo = 0; sl@0: sl@0: #ifdef _DEBUG sl@0: // Ensure we have a resource we can use sl@0: if((r=SetAsyncResource())!=KErrNone) sl@0: return r; sl@0: #endif sl@0: sl@0: // 0) Call API to get the initial state of a selected resource. sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); sl@0: gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId); sl@0: User::WaitForRequest(status); sl@0: if(status.Int() != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r); sl@0: return r; sl@0: } sl@0: TUint startingLevel = (TUint)readValue; sl@0: gTest.Printf(_L("TestGetSetResourceStateOps: initial level read =0x%x, levelOwnerId = %d\n"),readValue,levelOwnerId); sl@0: sl@0: // 1) Call API to modify the state of the resource. sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); sl@0: TUint newLevel = (TUint)(readValue + gAsyncResStateDelta); sl@0: gTest.Printf(_L("TestGetSetResourceStateOps: writing 0x%x\n"), newLevel); sl@0: gChannel.ChangeResourceState(status,gLongLatencyResource,newLevel); sl@0: User::WaitForRequest(status); sl@0: if(status.Int() != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, first change state returned %d\n"),r); sl@0: return r; sl@0: } sl@0: sl@0: // 2) Call API to get the new state of the resource and check it exhibits the expected value. sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); sl@0: gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId); sl@0: User::WaitForRequest(status); sl@0: if(status.Int() != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r); sl@0: return r; sl@0: } sl@0: gTest.Printf(_L("TestGetSetResourceStateOps: level read back =0x%x, levelOwnerId=%d\n"),readValue,levelOwnerId); sl@0: gTest(newLevel==(TUint)readValue); sl@0: sl@0: // 3) Call API to return the resource state to its original value. sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); sl@0: gTest.Printf(_L("TestGetSetResourceStateOps: write original level 0x%x\n"), startingLevel); sl@0: gChannel.ChangeResourceState(status,gLongLatencyResource,startingLevel); sl@0: User::WaitForRequest(status); sl@0: if(status.Int() != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, change state status = %d\n"),r); sl@0: return r; sl@0: } sl@0: gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId); sl@0: User::WaitForRequest(status); sl@0: if(status.Int() != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r); sl@0: return r; sl@0: } sl@0: gTest.Printf(_L("TestGetSetResourceStateOps: check original level read back =0x%x, levelOwnerId=%d\n"),readValue,levelOwnerId); sl@0: sl@0: // 4) Call API to get the state of a long latency resource then call API with operation-type qualifier cancel the request. sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); sl@0: gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId); sl@0: r=gChannel.CancelGetResourceState(status); sl@0: if(r!=KErrInUse) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, CancelGetResourceState returned %d\n"),r); sl@0: } sl@0: if(r!=KErrCompletion) // If request had not completed before cancellation request sl@0: { sl@0: User::WaitForRequest(status); sl@0: if(r==KErrNone) // Cancel expected to proceed as requested sl@0: { sl@0: if(status.Int() != KErrCancel) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, expected KErrCancel but cancelled get state status = %d\n"),r); sl@0: return r; sl@0: } sl@0: } sl@0: else if(r==KErrInUse) // Cancel failed since request was being processed - so expect successful completion sl@0: { sl@0: if(status.Int() != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, expected KErrNone but cancelled get state status = %d\n"),r); sl@0: return r; sl@0: } sl@0: } sl@0: else if(status.Int() != KErrCancel) // Just report the error code and return sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status = %d\n"),r); sl@0: return r; sl@0: } sl@0: sl@0: } sl@0: sl@0: // 5) Call API to modify the state of the long latency resource then call API with operation-type qualifier to cancel the request. sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); sl@0: newLevel = (TUint)(readValue + gAsyncResStateDelta); sl@0: gChannel.ChangeResourceState(status,gLongLatencyResource,newLevel); sl@0: r=gChannel.CancelChangeResourceState(status); sl@0: if(r!=KErrInUse) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, CancelChangeResourceState returned %d\n"),r); sl@0: } sl@0: if(r!=KErrCompletion) // If request had not completed before cancellation request sl@0: { sl@0: User::WaitForRequest(status); sl@0: if(r==KErrNone) // Cancel expected to proceed as requested sl@0: { sl@0: if(status.Int() != KErrCancel) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, expected KErrCancel but cancelled get state status = %d\n"),r); sl@0: return r; sl@0: } sl@0: } sl@0: else if(r==KErrInUse) // Cancel failed since request was being processed - so expect successful completion sl@0: { sl@0: if(status.Int() != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, expected KErrNone but cancelled get state status = %d\n"),r); sl@0: return r; sl@0: } sl@0: } sl@0: else if(status.Int() != KErrCancel) // Just report the error code and return sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status = %d\n"),r); sl@0: return r; sl@0: } sl@0: } sl@0: sl@0: sl@0: // 6) Call API to get the state of a long latency resource and wait for it to complete. sl@0: // Then call API with operation-type qualifier to cancel the request. sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); sl@0: gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId); sl@0: User::WaitForRequest(status); sl@0: if(status.Int() != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r); sl@0: return r; sl@0: } sl@0: r=gChannel.CancelGetResourceState(status); sl@0: if(r!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, CancelGetResourceState returned %d\n"),r); sl@0: } sl@0: if(status.Int() != KErrNone) // TRequestStatus should be unchanged sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled get state status = %d\n"),r); sl@0: return r; sl@0: } sl@0: sl@0: // 7) Call API to modify the state of the long latency resource and wait for it to complete. sl@0: // Then call API with operation-type qualifier to cancel the request. sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); sl@0: gChannel.ChangeResourceState(status,gLongLatencyResource,(readValue + gAsyncResStateDelta)); sl@0: User::WaitForRequest(status); sl@0: if(status.Int() != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, change state status = %d\n"),r); sl@0: return r; sl@0: } sl@0: r=gChannel.CancelChangeResourceState(status); sl@0: if(r!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, CancelChangeResourceState returned %d\n"),r); sl@0: } sl@0: if(status.Int() != KErrNone) // TRequestStatus should be unchanged sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled change state status = %d\n"),r); sl@0: return r; sl@0: } sl@0: sl@0: // 8) Call API to get the state of a long latency resource then call API without operation-type qualifier to cancel the request. sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); sl@0: gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId); sl@0: gChannel.CancelAsyncOperation(&status); sl@0: User::WaitForRequest(status); sl@0: if(status.Int() != KErrCancel) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status = %d\n"),r); sl@0: return r; sl@0: } sl@0: sl@0: // 9) Call API to modify the state of the long latency resource then call API without operation-type qualifier to cancel the request. sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); sl@0: newLevel = (TUint)(readValue + gAsyncResStateDelta); sl@0: gChannel.ChangeResourceState(status,gLongLatencyResource,newLevel); sl@0: gChannel.CancelAsyncOperation(&status); sl@0: User::WaitForRequest(status); sl@0: if(status.Int() != KErrCancel) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status = %d\n"),r); sl@0: return r; sl@0: } sl@0: sl@0: // 10) Call API to get the state of a long latency resource and wait for it to complete. sl@0: // Then call API without operation-type qualifier to cancel the request. sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); sl@0: gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId); sl@0: User::WaitForRequest(status); sl@0: if(status.Int() != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, get state status = %d\n"),r); sl@0: return r; sl@0: } sl@0: gChannel.CancelAsyncOperation(&status); sl@0: if(status.Int() != KErrNone) // TRequestStatus should be unchanged sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled get state status = %d\n"),r); sl@0: return r; sl@0: } sl@0: sl@0: // 11) Call API to modify the state of the long latency resource and wait for it to complete. sl@0: // Then call API without operation-type qualifier to cancel the request. sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); sl@0: gChannel.ChangeResourceState(status,gLongLatencyResource,(readValue + gAsyncResStateDelta)); sl@0: User::WaitForRequest(status); sl@0: if(status.Int() != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, change state status = %d\n"),r); sl@0: return r; sl@0: } sl@0: gChannel.CancelAsyncOperation(&status); sl@0: if(status.Int() != KErrNone) // TRequestStatus should be unchanged sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, completed-then-cancelled change state status = %d\n"),r); sl@0: return r; sl@0: } sl@0: sl@0: // 'n' and 'm' values and support for cancellation of multiple requests sl@0: const TInt KLoopVarN = 2; sl@0: const TInt KLoopVarM = 3; sl@0: TRequestStatus getReqStatus[KLoopVarN]; sl@0: TRequestStatus setReqStatus[KLoopVarM]; sl@0: TInt i=0; sl@0: sl@0: // 12) Call API to get the state of a long latency resource 'n' times. sl@0: // Then call API with resource qualifier to cancel the requests. sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); sl@0: for(i=0;i= KLoopVarM) sl@0: break; sl@0: User::WaitForRequest(setReqStatus[i]); sl@0: if((r=setReqStatus[i].Int()) != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, completed change state status[%d] = %d\n"),i,r); sl@0: return r; sl@0: } sl@0: } sl@0: for(i=0;i= KLoopVarN) sl@0: break; sl@0: User::WaitForRequest(getReqStatus[i]); sl@0: if((r=getReqStatus[i].Int()) != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateOps, completed get state status[%d] = %d\n"),i,r); sl@0: return r; sl@0: } sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: //---------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-T_RESMANUS-0611 sl@0: //! @SYMTestType UT sl@0: //! @SYMPREQ PREQ1398 sl@0: //! @SYMTestCaseDesc This test case tests APIs for regulating getting and setting the state of resources sl@0: //! sl@0: //! @SYMTestActions 0) Issue the maximum number (requested in the call to the Initialise API) sl@0: //! of requests to get the current state of a resource. Then issue one further request. sl@0: //! sl@0: //! 1) Issue the maximum number (requested in the call to the Initialise API) of sl@0: //! requests to set the current state of a resource. Then issue one further request. sl@0: //! sl@0: //! @SYMTestExpectedResults 0) Test that the TRequestStatus object associated with the last request sl@0: //! exhibits status code KErrUnderflow - exit otherwise. Test that the sl@0: //! TRequestStatus objects associated with the preceding requests exhibit sl@0: //! status code KErrNone - exit otherwise. sl@0: //! sl@0: //! 1) Test that the TRequestStatus object associated with the last request sl@0: //! exhibits status code KErrUnderflow - exit otherwise. Test that the sl@0: //! TRequestStatus objects associated with the preceding requests exhibit sl@0: //! status code KErrNone - exit otherwise. sl@0: //! sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //---------------------------------------------------------------------------------------------- sl@0: LOCAL_C TInt TestGetSetResourceStateQuota() sl@0: // sl@0: // Test resource state access quota management sl@0: // sl@0: { sl@0: TUint resourceId; sl@0: sl@0: // To perform the quota test we need a long latency resource sl@0: // If one has not been defined alert the user and return sl@0: if(!gHaveAsyncRes) sl@0: { sl@0: gTest.Printf(_L("TestGetSetResourceStateQuota: don't have suitable asynchronous resource ... exiting\n")); sl@0: return KErrNone; sl@0: } sl@0: else sl@0: resourceId = gLongLatencyResource; sl@0: sl@0: TInt r = KErrNone; sl@0: TBool lastErr = KErrNone; sl@0: sl@0: TInt i = 0; sl@0: TRequestStatus status[MAX_NUM_REQUESTS]; sl@0: TInt state[MAX_NUM_REQUESTS]; sl@0: TBool cached = gUseCached; sl@0: TInt levelOwnerId = 0; sl@0: sl@0: // sl@0: // Test GetResourceState - check client can not exceed quota of requests sl@0: // sl@0: gTest.Printf(_L("**Test GetResourceState (quota management)\n")); sl@0: sl@0: // KNoOfGetStateRequests Get state requests (of the same resource, ID=1) to consume the client quota sl@0: for(i=0; i0)?ETrue:EFalse; sl@0: sl@0: __KHEAP_MARKEND; sl@0: sl@0: return r; sl@0: } sl@0: sl@0: sl@0: //---------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-T_RESMANUS-0612 sl@0: //! @SYMTestType UT sl@0: //! @SYMPREQ PREQ1398 sl@0: //! @SYMTestCaseDesc This test case tests APIs for requesting both qualified and unqualified sl@0: //! notifications; it also tests APIs to cancel such requests. sl@0: //! sl@0: //! @SYMTestActions 0) Call API to request notification of an unqualified change in resource sl@0: //! state for a selected resource. Trigger a state change. sl@0: //! sl@0: //! 1) Call API to request notification of a qualified change in resource sl@0: //! state for a selected resource. Trigger a state change. sl@0: //! sl@0: //! 2) Call API to request notification of an unqualified change in resource sl@0: //! state for a selected resource. Then call API to cancel all notifications for the resource. sl@0: //! sl@0: //! 3) Call API to request notification of a qualified change in resource sl@0: //! state for a selected resource. Then call API to cancel all notifications for the resource. sl@0: //! sl@0: //! 4) Call API to request notification of an unqualified change in resource sl@0: //! state for a selected resource. Trigger a state change. Then call API to cancel all sl@0: //! notifications for the resource. sl@0: //! sl@0: //! 5) Call API to request notification of a qualified change in resource sl@0: //! state for a selected resource. Trigger a state change. Then call API to cancel all sl@0: //! notifications for the resource. sl@0: //! sl@0: //! 6) Call API to request notification of an unqualified change in resource sl@0: //! state for a selected resource. Then call API to cancel the notification request sl@0: //! sl@0: //! 7) Call API to request notification of a qualified change in resource sl@0: //! state for a selected resource. Then call API to cancel the notification request sl@0: //! sl@0: //! 8) Call API to request notification of an unqualified change in resource sl@0: //! state for a selected resource. Trigger a state change. Then call API to cancel the sl@0: //! notification request sl@0: //! sl@0: //! 9) Call API to request notification of a qualified change in resource sl@0: //! state for a selected resource. Trigger a state change. Then call API to cancel the sl@0: //! notification request sl@0: //! sl@0: //! 10) Call API to request notification of an unqualified change in resource sl@0: //! state for a selected resource. Then call API to cancel generic async request sl@0: //! sl@0: //! 11) Call API to request notification of a qualified change in resource sl@0: //! state for a selected resource. Then call API to cancel generic async request sl@0: //! sl@0: //! 12) Call API to request notification of an unqualified change in resource sl@0: //! state for a selected resource. Trigger a state change. Then call API to cancel sl@0: //! generic async request sl@0: //! sl@0: //! 13) Call API to request notification of a qualified change in resource sl@0: //! state for a selected resource. Trigger a state change. Then call API to cancel sl@0: //! generic async request sl@0: //! sl@0: //! @SYMTestExpectedResults 0) The associated TRequestStatus object should indicate KErrNone sl@0: //! - exits otherwise. sl@0: //! sl@0: //! 1) The associated TRequestStatus object should indicate KErrNone sl@0: //! - exits otherwise. sl@0: //! sl@0: //! 2) The associated TRequestStatus object should indicate KErrCancel sl@0: //! - exits otherwise. sl@0: //! sl@0: //! 3) The associated TRequestStatus object should indicate KErrCancel sl@0: //! - exits otherwise. sl@0: //! sl@0: //! 4) The TRequestStatus object should indicate state KRequestPending until sl@0: //! the state change is triggered, upon which it should exhibit state sl@0: //! KErrNone. After the cancellation it should still exhibit state KErrNone. sl@0: //! Exit for any deviation from this behaviour. sl@0: //! sl@0: //! 5) The TRequestStatus object should indicate state KRequestPending until sl@0: //! the state change is triggered, upon which it should exhibit state sl@0: //! KErrNone. After the cancellation it should still exhibit state KErrNone. sl@0: //! Exit for any deviation from this behaviour. sl@0: //! sl@0: //! 6) The associated TRequestStatus object should indicate KErrCancel sl@0: //! - exits otherwise. sl@0: //! sl@0: //! 7) The associated TRequestStatus object should indicate KErrCancel sl@0: //! - exits otherwise. sl@0: //! sl@0: //! 8) The TRequestStatus object should indicate state KRequestPending until sl@0: //! the state change is triggered, upon which it should exhibit state sl@0: //! KErrNone. After the cancellation it should still exhibit state KErrNone. sl@0: //! Exit for any deviation from this behaviour. sl@0: //! sl@0: //! 9) The TRequestStatus object should indicate state KRequestPending until sl@0: //! the state change is triggered, upon which it should exhibit state sl@0: //! KErrNone. After the cancellation it should still exhibit state KErrNone. sl@0: //! Exit for any deviation from this behaviour. sl@0: //! sl@0: //! 10) The associated TRequestStatus object should indicate KErrCancel sl@0: //! - exits otherwise. sl@0: //! sl@0: //! 11) The associated TRequestStatus object should indicate KErrCancel sl@0: //! - exits otherwise. sl@0: //! sl@0: //! 12) The TRequestStatus object should indicate state KRequestPending until sl@0: //! the state change is triggered, upon which it should exhibit state sl@0: //! KErrNone. After the cancellation it should still exhibit state KErrNone. sl@0: //! Exit for any deviation from this behaviour. sl@0: //! sl@0: //! 13) The TRequestStatus object should indicate state KRequestPending until sl@0: //! the state change is triggered, upon which it should exhibit state sl@0: //! KErrNone. After the cancellation it should still exhibit state KErrNone. sl@0: //! Exit for any deviation from this behaviour. sl@0: //! sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //---------------------------------------------------------------------------------------------- sl@0: LOCAL_C TInt TestNotificationOps() sl@0: // sl@0: // Test notification methods sl@0: // sl@0: { sl@0: __KHEAP_MARK; sl@0: sl@0: TInt r = KErrNone; sl@0: TRequestStatus status; sl@0: TUint resourceId; sl@0: TInt stateDelta; sl@0: if(!gHaveAsyncRes) sl@0: { sl@0: resourceId = 2; // Arbitrary sl@0: stateDelta = 1; // Arbitrary sl@0: } sl@0: else sl@0: { sl@0: resourceId = gLongLatencyResource; sl@0: stateDelta = gAsyncResStateDelta; sl@0: } sl@0: TInt testIndex = 0; sl@0: sl@0: // 0) Call API to request notification of an unqualified change in resource sl@0: // state for a selected resource. Trigger a state change. sl@0: gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); sl@0: gChannel.RequestNotification(status, resourceId); sl@0: if(status.Int() != KRequestPending) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); sl@0: return KErrGeneral; sl@0: } sl@0: TBool cached = gUseCached; sl@0: TRequestStatus triggerStatus; sl@0: if((r=TriggerNotification(triggerStatus, resourceId, cached, stateDelta))!=KErrNone) sl@0: return r; sl@0: User::WaitForRequest(status); sl@0: if(status.Int()!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: after TriggerNotification status = %d\n"),status.Int()); sl@0: return r; sl@0: } sl@0: sl@0: // 1) Call API to request notification of a qualified change in resource sl@0: // state for a selected resource. Trigger a state change. sl@0: gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); sl@0: TInt dumThreshold=0; sl@0: TBool dumDirection=EFalse; sl@0: if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone) sl@0: return r; sl@0: gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection); sl@0: if(status.Int() != KRequestPending) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); sl@0: return KErrGeneral; sl@0: } sl@0: // Pass gAsyncResStateDelta as this represents the delta value sl@0: if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone) sl@0: return r; sl@0: User::WaitForRequest(status); sl@0: if(status.Int()!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: after TriggerNotification status = %d\n"),status.Int()); sl@0: return r; sl@0: } sl@0: sl@0: // 2) Call API to request notification of an unqualified change in resource sl@0: // state for a selected resource. Then call API to cancel all notifications for the resource. sl@0: gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); sl@0: gChannel.RequestNotification(status, resourceId); sl@0: if(status.Int() != KRequestPending) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); sl@0: return KErrGeneral; sl@0: } sl@0: r=gChannel.CancelNotificationRequests(resourceId); sl@0: if(r!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests returned %d\n"),r); sl@0: return r; sl@0: } sl@0: User::WaitForRequest(status); sl@0: if(status.Int()!=KErrCancel) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: after cancel basic request status = %d\n"),status.Int()); sl@0: return r; sl@0: } sl@0: sl@0: // 3) Call API to request notification of a qualified change in resource sl@0: // state for a selected resource. Then call API to cancel all notifications for the resource. sl@0: gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); sl@0: dumThreshold = 0; // Arbitrary sl@0: dumDirection = ETrue; // Arbitrary sl@0: if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone) sl@0: return r; sl@0: gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection); sl@0: if(status.Int() != KRequestPending) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); sl@0: return KErrGeneral; sl@0: } sl@0: r=gChannel.CancelNotificationRequests(resourceId); sl@0: if(r!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests (qualified) returned %d\n"),r); sl@0: return r; sl@0: } sl@0: User::WaitForRequest(status); sl@0: if(status.Int()!=KErrCancel) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: after qualified request cancel status = %d\n"),status.Int()); sl@0: return r; sl@0: } sl@0: sl@0: // 4) Call API to request notification of an unqualified change in resource sl@0: // state for a selected resource. Trigger a state change. Then call API to cancel all sl@0: // notifications for the resource. sl@0: gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); sl@0: gChannel.RequestNotification(status, resourceId); sl@0: if(status.Int() != KRequestPending) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); sl@0: return KErrGeneral; sl@0: } sl@0: // Pass gAsyncResStateDelta as this represents the delta value sl@0: if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone) sl@0: return r; sl@0: User::WaitForRequest(status); sl@0: if(status.Int()!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: trigger basic request before cancel, status = %d\n"),status.Int()); sl@0: return r; sl@0: } sl@0: r=gChannel.CancelNotificationRequests(resourceId); sl@0: if(r!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests returned %d\n"),r); sl@0: return r; sl@0: } sl@0: if(status.Int()!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: after cancel (completed) basic request status = %d\n"),status.Int()); sl@0: return r; sl@0: } sl@0: sl@0: // 5) Call API to request notification of a qualified change in resource sl@0: // state for a selected resource. Trigger a state change. Then call API to cancel all sl@0: // notifications for the resource. sl@0: gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); sl@0: if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone) sl@0: return r; sl@0: gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection); sl@0: if(status.Int() != KRequestPending) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); sl@0: return KErrGeneral; sl@0: } sl@0: // Pass gAsyncResStateDelta as this represents the delta value sl@0: if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone) sl@0: return r; sl@0: User::WaitForRequest(status); sl@0: if(status.Int()!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: trigger qualified request before cancel, status = %d\n"),status.Int()); sl@0: return r; sl@0: } sl@0: r=gChannel.CancelNotificationRequests(resourceId); sl@0: if(r!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests (qualified) returned %d\n"),r); sl@0: return r; sl@0: } sl@0: if(status.Int()!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: after cancel (completed) qualified request status = %d\n"),status.Int()); sl@0: return r; sl@0: } sl@0: sl@0: // 6) Call API to request notification of an unqualified change in resource sl@0: // state for a selected resource. Then call API to cancel the notification request sl@0: gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); sl@0: gChannel.RequestNotification(status, resourceId); sl@0: if(status.Int() != KRequestPending) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); sl@0: return KErrGeneral; sl@0: } sl@0: r=gChannel.CancelRequestNotification(status); sl@0: if(r!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests returned %d\n"),r); sl@0: return r; sl@0: } sl@0: User::WaitForRequest(status); sl@0: if(status.Int()!=KErrCancel) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: after cancel basic request status = %d\n"),status.Int()); sl@0: return r; sl@0: } sl@0: sl@0: // 7) Call API to request notification of a qualified change in resource sl@0: // state for a selected resource. Then call API to cancel the notification request sl@0: gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); sl@0: dumThreshold = 0; // Arbitrary sl@0: dumDirection = ETrue; // Arbitrary sl@0: if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone) sl@0: return r; sl@0: gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection); sl@0: if(status.Int() != KRequestPending) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); sl@0: return KErrGeneral; sl@0: } sl@0: r=gChannel.CancelRequestNotification(status); sl@0: if(r!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests (qualified) returned %d\n"),r); sl@0: return r; sl@0: } sl@0: User::WaitForRequest(status); sl@0: if(status.Int()!=KErrCancel) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: after qualified request cancel status = %d\n"),status.Int()); sl@0: return r; sl@0: } sl@0: sl@0: // 8) Call API to request notification of an unqualified change in resource sl@0: // state for a selected resource. Trigger a state change. Then call API to cancel the sl@0: // notification request sl@0: gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); sl@0: gChannel.RequestNotification(status, resourceId); sl@0: if(status.Int() != KRequestPending) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); sl@0: return KErrGeneral; sl@0: } sl@0: // Pass gAsyncResStateDelta as this represents the delta value sl@0: if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone) sl@0: return r; sl@0: User::WaitForRequest(status); sl@0: if(status.Int()!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: trigger basic request before cancel, status = %d\n"),status.Int()); sl@0: return r; sl@0: } sl@0: r=gChannel.CancelRequestNotification(status); sl@0: if(r!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests returned %d\n"),r); sl@0: return r; sl@0: } sl@0: if(status.Int()!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: after cancel (completed) basic request status = %d\n"),status.Int()); sl@0: return r; sl@0: } sl@0: sl@0: // 9) Call API to request notification of a qualified change in resource sl@0: // state for a selected resource. Trigger a state change. Then call API to cancel the sl@0: // notification request sl@0: gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); sl@0: if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone) sl@0: return r; sl@0: gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection); sl@0: if(status.Int() != KRequestPending) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); sl@0: return KErrGeneral; sl@0: } sl@0: // Pass gAsyncResStateDelta as this represents the delta value sl@0: if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone) sl@0: return r; sl@0: User::WaitForRequest(status); sl@0: if(status.Int()!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: trigger qualified request before cancel, status = %d\n"),status.Int()); sl@0: return r; sl@0: } sl@0: r=gChannel.CancelRequestNotification(status); sl@0: if(r!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps, CancelNotificationRequests (qualified) returned %d\n"),r); sl@0: return r; sl@0: } sl@0: if(status.Int()!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: after cancel (completed) qualified request status = %d\n"),status.Int()); sl@0: return r; sl@0: } sl@0: sl@0: sl@0: // 10) Call API to request notification of an unqualified change in resource sl@0: // state for a selected resource. Then call API to cancel generic async request sl@0: gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); sl@0: gChannel.RequestNotification(status, resourceId); sl@0: if(status.Int() != KRequestPending) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); sl@0: return KErrGeneral; sl@0: } sl@0: gChannel.CancelAsyncOperation(&status); sl@0: User::WaitForRequest(status); sl@0: if(status.Int()!=KErrCancel) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: after cancel basic request status = %d\n"),status.Int()); sl@0: return r; sl@0: } sl@0: sl@0: // 11) Call API to request notification of a qualified change in resource sl@0: // state for a selected resource. Then call API to cancel generic async request sl@0: gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); sl@0: dumThreshold = 0; // Arbitrary sl@0: dumDirection = ETrue; // Arbitrary sl@0: if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone) sl@0: return r; sl@0: gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection); sl@0: if(status.Int() != KRequestPending) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); sl@0: return KErrGeneral; sl@0: } sl@0: gChannel.CancelAsyncOperation(&status); sl@0: User::WaitForRequest(status); sl@0: if(status.Int()!=KErrCancel) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: after qualified request cancel status = %d\n"),status.Int()); sl@0: return r; sl@0: } sl@0: sl@0: // 12) Call API to request notification of an unqualified change in resource sl@0: // state for a selected resource. Trigger a state change. Then call API to cancel sl@0: // generic async request sl@0: gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); sl@0: gChannel.RequestNotification(status, resourceId); sl@0: if(status.Int() != KRequestPending) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); sl@0: return KErrGeneral; sl@0: } sl@0: // Pass gAsyncResStateDelta as this represents the delta value sl@0: if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone) sl@0: return r; sl@0: User::WaitForRequest(status); sl@0: if(status.Int()!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: trigger basic request before cancel, status = %d\n"),status.Int()); sl@0: return r; sl@0: } sl@0: gChannel.CancelAsyncOperation(&status); sl@0: if(status.Int()!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: after cancel (completed) basic request status = %d\n"),status.Int()); sl@0: return r; sl@0: } sl@0: sl@0: // 13) Call API to request notification of a qualified change in resource sl@0: // state for a selected resource. Trigger a state change. Then call API to cancel sl@0: // generic async request sl@0: gTest.Printf(_L("TestNotificationOps: starting test %d\n"),testIndex++); sl@0: if((r=CalcNotifyDirAndThr(status, resourceId, cached, dumThreshold, dumDirection))!=KErrNone) sl@0: return r; sl@0: gChannel.RequestNotification(status, resourceId, dumThreshold, dumDirection); sl@0: if(status.Int() != KRequestPending) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: status=%d\n"),status.Int()); sl@0: return KErrGeneral; sl@0: } sl@0: // Pass gAsyncResStateDelta as this represents the delta value sl@0: if((r=TriggerNotification(triggerStatus, resourceId, cached, gAsyncResStateDelta))!=KErrNone) sl@0: return r; sl@0: User::WaitForRequest(status); sl@0: if(status.Int()!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: trigger qualified request before cancel, status = %d\n"),status.Int()); sl@0: return r; sl@0: } sl@0: gChannel.CancelAsyncOperation(&status); sl@0: if(status.Int()!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestNotificationOps: after cancel (completed) qualified request status = %d\n"),status.Int()); sl@0: return r; sl@0: } sl@0: sl@0: __KHEAP_MARKEND; sl@0: sl@0: return r; sl@0: } sl@0: sl@0: //---------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-T_RESMANUS-0613 sl@0: //! @SYMTestType UT sl@0: //! @SYMPREQ PREQ1398 sl@0: //! @SYMTestCaseDesc This test case tests quota management for notification operations. sl@0: //! sl@0: //! @SYMTestActions 0) Issue the maximum number (requested in the call to the Initialise API) sl@0: //! of requests for notification of unqualified changes to the state of a sl@0: //! resource. Then issue one further request. sl@0: //! sl@0: //! 1) Issue the maximum number (requested in the call to the Initialise API) sl@0: //! of requests for notification of qualified changes to the state of a sl@0: //! resource. Then issue one further request. sl@0: //! sl@0: //! 2) Issue the maximum number (requested in the call to the Initialise API) sl@0: //! of requests for notification changes to the state of a resource, where sl@0: //! every odd request is for an unqualified change and every even request is sl@0: //! for a qualified change. Then issue one further request. sl@0: //! sl@0: //! @SYMTestExpectedResults 0) Test that the TRequestStatus object associated with the last sl@0: //! request exhibits status code KErrUnderflow - exit otherwise. Test sl@0: //! that the TRequestStatus objects associated with the preceding requests sl@0: //! exhibit status code KErrNone - exit otherwise. sl@0: //! sl@0: //! 1) Test that the TRequestStatus object associated with the last request sl@0: //! exhibits status code KErrUnderflow - exit otherwise. Test that the sl@0: //! TRequestStatus objects associated with the preceding requests exhibit sl@0: //! status code KErrNone - exit otherwise. sl@0: //! sl@0: //! 2) Test that the TRequestStatus object associated with the last request sl@0: //! exhibits status code KErrUnderflow - exit otherwise. Test that the sl@0: //! TRequestStatus objects associated with the preceding requests exhibit sl@0: //! status code KErrNone - exit otherwise. sl@0: //! sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //---------------------------------------------------------------------------------------------- sl@0: LOCAL_C TInt TestNotificationQuota() sl@0: // sl@0: // Test notification request quota management sl@0: // sl@0: { sl@0: __KHEAP_MARK; sl@0: sl@0: TInt r = KErrNone; sl@0: TRequestStatus status[MAX_NUM_REQUESTS]; sl@0: TInt loopVar=0; sl@0: TBool cached = gUseCached; sl@0: TRequestStatus triggerStatus; sl@0: TUint resourceId = gLongLatencyResource; sl@0: sl@0: // Test quota for basic operation sl@0: // sl@0: // Loop to perform maximum number of requests, check TRequestStatus objects are pending sl@0: for(loopVar=0; loopVar exitCat=PirateThread.ExitCategory(); sl@0: if((exitType!= EExitKill)||(exitReason!=KErrNone)) sl@0: { sl@0: gTest.Printf(_L("Pirate thread error: %d\n"),PirateStatus.Int()); sl@0: gTest.Printf(_L("Thread exit reason: %d,%d,%S\n"),exitType,exitReason,&exitCat); sl@0: gTest(0); sl@0: } sl@0: PirateThread.Close(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: #endif sl@0: sl@0: //---------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-T_RESMANUS-0608 sl@0: //! @SYMTestType UT sl@0: //! @SYMPREQ PREQ1398 sl@0: //! @SYMTestCaseDesc This test case tests that channels can not be shared between threads. sl@0: //! @SYMTestActions 0) Attempt to Duplicate the channel handle with EOwnerProcess as the owner type. sl@0: //! sl@0: //! 1) Attempt to Duplicate the channel handle with EOwnerThread sl@0: //! sl@0: //! @SYMTestExpectedResults 0) API should return with KErrAccessDenied, exits otherwise. sl@0: //! 1) API should return with KErrNone, exits otherwise. sl@0: //! sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //---------------------------------------------------------------------------------------------- sl@0: LOCAL_C TInt TestThreadExclusiveAccess() sl@0: // sl@0: // Test mechanism to prevent other threads accessing a channel sl@0: // sl@0: { sl@0: __KHEAP_MARK; sl@0: sl@0: TInt r; sl@0: RBusDevResManUs pirateChannel = gChannel; sl@0: if((r=pirateChannel.Duplicate(RThread(),EOwnerProcess))!=KErrAccessDenied) sl@0: { sl@0: gTest.Printf(_L("TestThreadExclusiveAccess: Duplicate with EOwnerProcess returned %d\n"),r); sl@0: if(r==KErrNone) sl@0: r=KErrGeneral; sl@0: return r; sl@0: } sl@0: pirateChannel = gChannel; sl@0: if((r=pirateChannel.Duplicate(RThread(),EOwnerThread))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestThreadExclusiveAccess: Duplicate with EOwnerThread returned %d\n"),r); sl@0: return r; sl@0: } sl@0: #ifdef PIRATE_THREAD_TESTS sl@0: RThread& threadRef = RThread(); sl@0: if((r=StartPirate(threadRef))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestThreadExclusiveAccess: StartPirate returned %d\n"),r); sl@0: return KErrGeneral; sl@0: } sl@0: if((r=WaitForPirateThread())!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestThreadExclusiveAccess: WaitForPirateThread returned %d\n"),r); sl@0: return KErrGeneral; sl@0: } sl@0: #endif sl@0: pirateChannel.Close(); sl@0: sl@0: __KHEAP_MARKEND; sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: RThread Thrd2; sl@0: TRequestStatus Thrd2Status; sl@0: const TInt KHeapSize=0x4000; sl@0: const TInt KStackSize=0x4000; sl@0: sl@0: _LIT(KThrd2Name,"Thread2"); sl@0: sl@0: sl@0: TInt Thread2Fn(TAny* /* */) sl@0: // sl@0: // Test that more than one thread can be supported sl@0: // sl@0: { sl@0: TInt r; sl@0: sl@0: // Open a channel sl@0: // sl@0: _LIT(secThrdStr,"Thrd2Channel"); sl@0: TBufC<16> secThrdName(secThrdStr); sl@0: // API accepts 8-bit descriptors, only - so convert name accordingly sl@0: TBuf8EightBitName; sl@0: EightBitName.Copy(secThrdName); sl@0: RBusDevResManUs secThrdChannel; sl@0: if((r=secThrdChannel.Open(EightBitName))!=KErrNone) sl@0: return r; sl@0: sl@0: // Read the resource information sl@0: // sl@0: TUint numResources=0; sl@0: if((r=secThrdChannel.GetNoOfResources(numResources))!=KErrNone) sl@0: return r; sl@0: sl@0: // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects sl@0: // and reference via an RSimplePointerArray sl@0: TUint bufSize = numResources; sl@0: RSimplePointerArray resPtrs(bufSize); sl@0: for(TUint i=0;inumClients)?numAllClients:numClients; sl@0: RSimplePointerArray infoPtrs(resBufSize); sl@0: for(TUint j=0;jnumClients)?numAllClients:numClients; sl@0: RSimplePointerArray infoPtrs(bufSize); sl@0: for(TUint i=0;i resPtrs(numResources); sl@0: for(TUint j=0;j exitCat=Thrd2.ExitCategory(); sl@0: if((exitType!= EExitKill)||(exitReason!=KErrNone)) sl@0: { sl@0: gTest.Printf(_L("Thread2 error: %d\n"),Thrd2Status.Int()); sl@0: gTest.Printf(_L("Thread exit reason: %d,%d,%S\n"),exitType,exitReason,&exitCat); sl@0: gTest(0); sl@0: } sl@0: Thrd2.Close(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: //---------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-T_RESMANUS-0614 sl@0: //! @SYMTestType UT sl@0: //! @SYMPREQ PREQ1398 sl@0: //! @SYMTestCaseDesc This test case tests that an additional thread can open a channel and sl@0: //! exercise selected APIs. sl@0: //! sl@0: //! @SYMTestActions 0) Call API to open a channel. sl@0: //! sl@0: //! 1) Call GetNoOfResources API. sl@0: //! sl@0: //! 2) Call GetAllResourcesInfo API. sl@0: //! sl@0: //! 3) Call GetNoOfClients API with default aIncludeKern=EFalse. sl@0: //! sl@0: //! 4) Call GetNoOfClients API with aIncludeKern=ETrue sl@0: //! sl@0: //! 5) Call GetNamesAllClientsAPI with default aIncludeKern=EFalse. sl@0: //! sl@0: //! 6) Call GetNamesAllClientsAPI with aIncludeKern=ETrue sl@0: //! sl@0: //! 7) Call Initialise API. sl@0: //! sl@0: //! 8) Call GetResourceState API for selected resource. sl@0: //! sl@0: //! 9) Call GetResourceState API for selected resource. sl@0: //! sl@0: //! 10) Call GetNoOfClients API with default aIncludeKern=EFalse. sl@0: //! sl@0: //! 11) Call GetNoOfClients API with aIncludeKern=ETrue sl@0: //! sl@0: //! 12) Call GetNamesAllClientsAPI with default aIncludeKern=EFalse. sl@0: //! sl@0: //! 13) Call GetNamesAllClientsAPI with aIncludeKern=ETrue sl@0: //! sl@0: //! 14) Call GetNoOfResources API. sl@0: //! sl@0: //! 15) Call GetAllResourcesInfo API. sl@0: //! sl@0: //! @SYMTestExpectedResults 0) Test that the channel was opened - exit otherwise. sl@0: //! sl@0: //! 1) Test that the API call returned KErrNone - exit otherwise. sl@0: //! sl@0: //! 2) Test that the API call returned KErrNone - exit otherwise. sl@0: //! sl@0: //! 3) Test that the API call returned KErrNone - exit otherwise. sl@0: //! sl@0: //! 4) If client exhibits PlatSec capability ReadDeviceData, Test that the API call returned KErrNone - exit otherwise sl@0: //! If client lacks PlatSec capability ReadDeviceData, Test that the API call returned KErrPermissionDenied - exit otherwise sl@0: //! sl@0: //! 5) Test that the API call returned KErrNone - exit otherwise. sl@0: //! sl@0: //! 6) If client exhibits PlatSec capability ReadDeviceData, Test that the API call returned KErrNone - exit otherwise sl@0: //! If client lacks PlatSec capability ReadDeviceData, Test that the API call returned KErrPermissionDenied - exit otherwise sl@0: //! sl@0: //! 7) Test that the API call returned KErrNone - exit otherwise sl@0: //! sl@0: //! 8) Test that the associated TRequestStatus object exhibited state KErrNone - exit otherwise sl@0: //! sl@0: //! 9) Test that the associated TRequestStatus object exhibited state KErrNone - exit otherwise sl@0: //! sl@0: //! 10) Test that the API call returned KErrNone - exit otherwise. sl@0: //! sl@0: //! 11) If client exhibits PlatSec capability ReadDeviceData, Test that the API call returned KErrNone - exit otherwise sl@0: //! If client lacks PlatSec capability ReadDeviceData, Test that the API call returned KErrPermissionDenied - exit otherwise sl@0: //! sl@0: //! 12) Test that the API call returned KErrNone - exit otherwise. sl@0: //! sl@0: //! 13) If client exhibits PlatSec capability ReadDeviceData, Test that the API call returned KErrNone - exit otherwise sl@0: //! If client lacks PlatSec capability ReadDeviceData, Test that the API call returned KErrPermissionDenied - exit otherwise sl@0: //! sl@0: //! 14) Test that the API call returned KErrNone - exit otherwise. sl@0: //! sl@0: //! 15) Test that the API call returned KErrNone - exit otherwise. sl@0: //! sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //---------------------------------------------------------------------------------------------- sl@0: LOCAL_C TInt TestAdditionalThread() sl@0: // sl@0: // Test that more than one thread can be supported sl@0: // sl@0: { sl@0: TInt r; sl@0: if((r=StartThread2())!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestAdditionalThread: StartThread2 returned %d\n"),r); sl@0: return KErrGeneral; sl@0: } sl@0: if((r=WaitForThread2())!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestAdditionalThread: WaitForThread2 returned %d\n"),r); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: return r; sl@0: } sl@0: sl@0: sl@0: LOCAL_C TInt LocateResourceWithDependencies(TUint &aNumResources, TUint &aResId, TUint &aNumDependents) sl@0: // sl@0: // Support function for tests of dependencies sl@0: // sl@0: { sl@0: __KHEAP_MARK; sl@0: sl@0: TInt r = KErrNone; sl@0: if((r=gChannel.GetNoOfResources(aNumResources))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("GetNoOfResources for test channel returned %d\n"),r); sl@0: return r; sl@0: } sl@0: TUint bufSize = aNumResources; sl@0: RSimplePointerArray infoPtrs(bufSize); sl@0: for(TUint i=0;i0) sl@0: { sl@0: aResId = resId; sl@0: aNumDependents = numDependents; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: infoPtrs.Close(); sl@0: sl@0: __KHEAP_MARKEND; sl@0: sl@0: return r; sl@0: } sl@0: sl@0: sl@0: sl@0: //---------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-T_RESMANUS-0615 sl@0: //! @SYMTestType UT sl@0: //! @SYMPREQ PREQ1398 sl@0: //! @SYMTestCaseDesc This test case tests the different options available for handling transient data. sl@0: //! @SYMTestActions 0) Locate a resource that has at least one dependency. sl@0: //! sl@0: //! 1) Read the number of dependencies without reading the dependency information. sl@0: //! Call to read the dependency information (without re-loading). sl@0: //! sl@0: //! 2) Read the number of dependencies (with default option of reading the dependency information). sl@0: //! Then read the dependency information (without re-loading). sl@0: //! sl@0: //! 3) Repeat the read the number of dependencies without reading the dependency information sl@0: //! Then read the dependency information (without re-loading). sl@0: //! Then read the dependency information (with re-loading). sl@0: //! sl@0: //! 4) Attempt to read the dependency information (without re-loading) with a buffer of insufficient size sl@0: //! sl@0: //! 5) Read the number of (all) resources without reading the resource information. sl@0: //! Call to read (all) the resource information (without re-loading). sl@0: //! sl@0: //! 6) Read the number of (all) resources (with default option of reading the resource information). sl@0: //! Then read (all) the resource information (without re-loading). sl@0: //! sl@0: //! 7) Repeat the read the number of (all) resources without reading the resources information sl@0: //! Then read (all) the resources information (without re-loading). sl@0: //! Then read (all) the resources information (with re-loading). sl@0: //! sl@0: //! 8) Attempt to read (all) the resource information (without re-loading) with a buffer of insufficient size sl@0: //! sl@0: //! 9) Read the number of user-side clients using a resource without reading the resource information. sl@0: //! Call to read the information for user-side clients using a resource (without re-loading). sl@0: //! sl@0: //! 10) Read the number of user-side clients (with loading of the client information) sl@0: //! Call to read the client information (without re-loading) should return be successful sl@0: //! Call to read the information for a resourceID with zero clients (without re-loading) sl@0: //! Call to read the information for the first resourceID sl@0: //! sl@0: //! 11) Repeat the read of the number of user-side clients (without re-loading) sl@0: //! Call to read the client information (without re-loading) sl@0: //! Call to read the client information (with re-loading) sl@0: //! sl@0: //! 12) Open a second channel on the User-Side API, and call initialise support for resource state access sl@0: //! Get the current state of a specific resource, then change the state sl@0: //! Call to read the number of user-side clients for the resource (with loading of the client information) sl@0: //! but with a buffer of insufficient size. sl@0: //! sl@0: //! 13) Read the number of resources in use by a specified client (without loading) sl@0: //! Call to read the information on the resources in use by the client (without loading) sl@0: //! sl@0: //! 14) Open a third channel on the User-Side API, do not call initialise. sl@0: //! Read the number of resources in use by a specified client (with loading) sl@0: //! Call to read the information for resources in use by the third channel (without re-loading) sl@0: //! Call to read the information for resources in use by the second channel (without re-loading) sl@0: //! sl@0: //! 15) Read the number of resources in use by a specified client (without loading) sl@0: //! Call to read the information on the resources in use by the client (without loading) sl@0: //! Call to read the information on the resources in use by the client (with loading) sl@0: //! sl@0: //! 16) Read the number of resources in use by a specified client (with loading) sl@0: //! Call to read the information on the resources in use by the client (without loading) sl@0: //! with a buffer of insufficient size. sl@0: //! sl@0: //! @SYMTestExpectedResults 0) If a suitable resource is found, the number of dependencies is reported - exit otherwise. sl@0: //! sl@0: //! 1) Test that the read of the number of dependencies returns KErrNone - exit otherwise. sl@0: //! Test that the read of the dependency information returned KErrNotReady - exit otherwise. sl@0: //! sl@0: //! 2) Test that the read of the number of dependencies returns KErrNone - exit otherwise. sl@0: //! Test that the read of the dependency information returned KErrNone - exit otherwise. sl@0: //! sl@0: //! 3) Test that the read of the number of dependencies returns KErrNone - exit otherwise. sl@0: //! Test that the read of the dependency information (without re-loading) returned KErrNotReady - exit otherwise. sl@0: //! Test that the read of the dependency information (with re-loading) returned KErrNone - exit otherwise. sl@0: //! sl@0: //! 4) Test that the read of the dependency information returns KErrArgument - exit otherwise sl@0: //! sl@0: //! 5) Test that the read of the number of resources returns KErrNone - exit otherwise. sl@0: //! Test that the read of the resource information returned KErrNotReady - exit otherwise. sl@0: //! sl@0: //! 6) Test that the read of the number of resources returns KErrNone - exit otherwise. sl@0: //! Test that the read of the resource information returned KErrNone - exit otherwise. sl@0: //! sl@0: //! 7) Test that the read of the number of resources returns KErrNone - exit otherwise. sl@0: //! Test that the read of the resource information (without re-loading) returned KErrNotReady - exit otherwise. sl@0: //! Test that the read of the resources information (with re-loading) returned KErrNone - exit otherwise. sl@0: //! sl@0: //! 8) Test that the read of the resource information returns KErrArgument - exit otherwise sl@0: //! sl@0: //! 9) Test that the read of the number of clients returns KErrNone - exit otherwise. sl@0: //! Test that the read of the client information returned KErrNotReady - exit otherwise. sl@0: //! sl@0: //! 10) Test that the read of the number of clients returns KErrNone - exit otherwise. sl@0: //! Test that the read of the client information returned KErrNone - exit otherwise. sl@0: //! Test that the read of the client information returned KErrNone and numClients==0 - exit otherwise. sl@0: //! Test that the read of the client information returned KErrNotReady - exit otherwise. sl@0: //! sl@0: //! 11) Test that the read of the number of clients returns KErrNone - exit otherwise. sl@0: //! Test that the read of the client information returned KErrNotReady - exit otherwise. sl@0: //! Test that the read of the client information returned KErrNone - exit otherwise. sl@0: //! sl@0: //! 12) Test that the opening and initialisation of the channel was successful - exit otherwise. sl@0: //! Test that the get and change of the resource state completed successfully - exit otherwise sl@0: //! Test that the read of the client information returned KErrArgument - exit otherwise. sl@0: //! sl@0: //! 13) Test that the read of the number of resources returns KErrNone - exit otherwise. sl@0: //! Test that the read of the resource information returned KErrNotReady - exit otherwise. sl@0: //! sl@0: //! 14) Test that the opening of the channel was successful - exit otherwise. sl@0: //! Test that the read of the resource information returned KErrNone - exit otherwise. sl@0: //! Test that the read of the client information returned KErrNone, and numResources = 0 - exit otherwise. sl@0: //! Test that the read of the client information returned KErrNotReady - exit otherwise. sl@0: //! sl@0: //! 15) Test that the read of the number of resources returns KErrNone - exit otherwise. sl@0: //! Test that the read of the resource information returned KErrNotReady - exit otherwise. sl@0: //! Test that the read of the resource information returned KErrNone - exit otherwise. sl@0: //! sl@0: //! 16) Test that the read of the number of resources returns KErrNone - exit otherwise. sl@0: //! Test that the read of the resource information returned KErrArgument - exit otherwise.. sl@0: //! sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //---------------------------------------------------------------------------------------------- sl@0: LOCAL_C TInt TestTransientHandling() sl@0: // sl@0: // Test APIs with options for handling transient data (dependencies, resources and clients) sl@0: // sl@0: { sl@0: TInt r = KErrNone; sl@0: TUint testNo = 1; sl@0: sl@0: TUint numDependents = 0; sl@0: TUint resNo = 0; sl@0: sl@0: // sl@0: // Dependency data tests sl@0: // sl@0: sl@0: gTest.Printf(_L("TestTransientHandling: dependency data tests ...\n")); sl@0: sl@0: // 0) Find a resource that has dependents - if none is located skip the remaining dependancy tests sl@0: // (this reads the number of dependencies, without loading the dependency data) sl@0: // sl@0: TUint numResources=0; sl@0: if((r=LocateResourceWithDependencies(numResources, resNo, numDependents))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestTransientHandling: no resource with dependencies found ... skipping tests\n")); sl@0: return KErrNone; sl@0: } sl@0: if(numDependents==0) sl@0: { sl@0: gTest.Printf(_L("TestTransientHandling: no resource with dependencies found ... skipping tests\n")); sl@0: } sl@0: else sl@0: { sl@0: // 1) Read the number of dependencies without reading the dependency information sl@0: // Subsequent call to read the dependency information (without re-loading) should return error KErrNotReady sl@0: gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); sl@0: if((r=gChannel.GetNumDependentsForResource(resNo,&numDependents, EFalse))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource returned %d\n"),r); sl@0: return r; sl@0: } sl@0: gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource reported %d dependents for resource %d\n"),numDependents,resNo); sl@0: if(numDependents > 0) sl@0: { sl@0: RBuf8 buffer; sl@0: if((buffer.Create(numDependents*sizeof(SResourceDependencyInfo)))!=KErrNone) sl@0: return KErrGeneral; sl@0: buffer.SetLength(0); sl@0: if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents))!=KErrNotReady) sl@0: { sl@0: gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r); sl@0: return KErrGeneral; sl@0: } sl@0: buffer.Close(); sl@0: } sl@0: sl@0: // 2) Read the number of dependencies (and, by default, read the dependency information) sl@0: // Subsequent call to read the dependency information (without re-loading) should return be successful sl@0: gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); sl@0: if((r=gChannel.GetNumDependentsForResource(resNo,&numDependents))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource returned %d\n"),r); sl@0: return r; sl@0: } sl@0: gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource reported %d dependents for resource %d\n"),numDependents,resNo); sl@0: if(numDependents > 0) sl@0: { sl@0: RBuf8 buffer; sl@0: if((buffer.Create(numDependents*sizeof(SResourceDependencyInfo)))!=KErrNone) sl@0: return KErrGeneral; sl@0: buffer.SetLength(0); sl@0: if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r); sl@0: return r; sl@0: } sl@0: SResourceDependencyInfo* tempPtr = (SResourceDependencyInfo*)(buffer.Ptr()); sl@0: gTest.Printf(_L("TestTransientHandling: numDependents = %d\n"),numDependents); sl@0: for(TUint i=0; iiResourceId); sl@0: gTest.Printf(_L("TestTransientHandling: info.iDependencyPriority= %d\n"),tempPtr->iDependencyPriority); sl@0: } sl@0: buffer.Close(); sl@0: } sl@0: sl@0: // 3) Repeat the read the number of dependencies without reading the dependency information sl@0: // Subsequent call to read the dependency information (without re-loading) should return error KErrNotReady sl@0: // Then call to read the dependency information (with re-loading) should be successful sl@0: gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); sl@0: if((r=gChannel.GetNumDependentsForResource(resNo,&numDependents, EFalse))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource returned %d\n"),r); sl@0: return r; sl@0: } sl@0: gTest.Printf(_L("TestTransientHandling: GetNumDependentsForResource reported %d dependents for resource %d\n"),numDependents,resNo); sl@0: if(numDependents > 0) sl@0: { sl@0: RBuf8 buffer; sl@0: if((buffer.Create(numDependents*sizeof(SResourceDependencyInfo)))!=KErrNone) sl@0: return KErrGeneral; sl@0: buffer.SetLength(0); sl@0: sl@0: if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents))!=KErrNotReady) sl@0: { sl@0: gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r); sl@0: return KErrGeneral; sl@0: } sl@0: if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents, ETrue))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r); sl@0: return KErrGeneral; sl@0: } sl@0: SResourceDependencyInfo* tempPtr = (SResourceDependencyInfo*)(buffer.Ptr()); sl@0: for(TUint i=0; iiResourceId); sl@0: gTest.Printf(_L("TestTransientHandling: info.iDependencyPriority= %d"),tempPtr->iDependencyPriority); sl@0: } sl@0: buffer.Close(); sl@0: } sl@0: sl@0: // 4) Attempt to read the dependency information (without re-loading) with a buffer of insufficient size should sl@0: // return error KErrArgument sl@0: gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); sl@0: if(numDependents > 0) sl@0: { sl@0: RBuf8 buffer; sl@0: if((buffer.Create((numDependents-1)*sizeof(SResourceDependencyInfo)))!=KErrNone) sl@0: return KErrGeneral; sl@0: buffer.SetLength(0); sl@0: if((r=gChannel.GetDependentsIdForResource(resNo, buffer, &numDependents))!=KErrArgument) sl@0: { sl@0: gTest.Printf(_L("TestTransientHandling: GetDependentsIdForResource returned %d\n"),r); sl@0: return KErrGeneral; sl@0: } sl@0: // Ensure misleading result is not returned sl@0: r=KErrNone; sl@0: buffer.Close(); sl@0: } sl@0: } sl@0: sl@0: sl@0: // sl@0: // All resource data tests sl@0: // sl@0: sl@0: gTest.Printf(_L("TestTransientHandling: All resource data tests ...\n")); sl@0: testNo=1; sl@0: sl@0: // 5) Attempt to read the resource information without having previously loaded it. sl@0: gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); sl@0: { sl@0: TUint numResources = 0; sl@0: r = gChannel.GetNoOfResources(numResources, EFalse); // EFalse - don't load the resource info sl@0: if(r!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("GetNoOfResources returned %d\n"),r); sl@0: return r; sl@0: } sl@0: // To support the GetAllResourcesInfo testing, instantiate TResourceInfoBuf objects sl@0: // and reference via an RSimplePointerArray sl@0: RSimplePointerArray infoPtrs(numResources); sl@0: for(TUint i=0;i infoPtrs(numResources); sl@0: for(TUint i=0;i infoPtrs(numResources); sl@0: for(TUint i=0;i infoPtrs(numResources - 1); sl@0: for(TUint i=0;i<(numResources-1);i++) sl@0: { sl@0: TResourceInfoBuf *info = new TResourceInfoBuf(); sl@0: if((r=infoPtrs.Insert(info, i))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r); sl@0: } sl@0: } sl@0: if((r=gChannel.GetAllResourcesInfo(&infoPtrs, numResources))!=KErrArgument) sl@0: { sl@0: gTest.Printf(_L("TestTransientHandling: GetAllResourcesInfo returned %d\n"),r); sl@0: return KErrGeneral; sl@0: } sl@0: // Ensure misleading result is not returned sl@0: r=KErrNone; sl@0: infoPtrs.Close(); sl@0: } sl@0: sl@0: // sl@0: // Specific resource data tests sl@0: // sl@0: sl@0: gTest.Printf(_L("TestTransientHandling: Resource-specific data tests ...\n")); sl@0: testNo=1; sl@0: sl@0: // 9) Attempt to read the resource information without having previously loaded it. sl@0: gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); sl@0: { sl@0: TUint numClients = 0; sl@0: if((r=gChannel.GetNumClientsUsingResource(gLongLatencyResource, numClients, EFalse, EFalse))!=KErrNone) // user-side clients, don't load the info sl@0: { sl@0: gTest.Printf(_L("GetNumClientsUsingResource returned %d\n"),r); sl@0: return r; sl@0: } sl@0: // To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects sl@0: // and reference via an RSimplePointerArray sl@0: RSimplePointerArray infoPtrs(numClients); sl@0: for(TUint i=0;i infoPtrs(numClients); sl@0: for(TUint i=0;i infoPtrs(numClients); sl@0: for(TUint i=0;i tempName1(tempStr1); sl@0: RBusDevResManUs channelTwo; sl@0: if((r=OpenChannel(tempName1, channelTwo))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("Failed to open channelTwo, %d\n"),r); sl@0: channelTwo.Close(); sl@0: return r; sl@0: } sl@0: if ((r=channelTwo.Initialise(1,1,1))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("Failed to Initialise channelTwo, %d\n"),r); sl@0: channelTwo.Close(); sl@0: return r; sl@0: } sl@0: // Attempt to change the resource level sl@0: // Get initial state sl@0: TRequestStatus status; sl@0: TBool cached = gUseCached; sl@0: TInt readValue; sl@0: TInt levelOwnerId = 0; sl@0: channelTwo.GetResourceState(status,gSharedResource,cached,&readValue,&levelOwnerId); sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("GetResourceState for gSharedResource completed with = 0x%x\n"),r); sl@0: return r; sl@0: } sl@0: // Write updated state sl@0: TUint newLevel = (TUint)(readValue + gSharedResStateDelta); sl@0: channelTwo.ChangeResourceState(status,gSharedResource,newLevel); sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("ChangeResourceState forgSharedResource completed with %d\n"),r); sl@0: return r; sl@0: } sl@0: sl@0: // Attempt to read the client information (without re-loading) with a buffer of insufficient size should sl@0: // return error KErrArgument sl@0: gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); sl@0: { sl@0: TUint numClients = 0; sl@0: if((r=gChannel.GetNumClientsUsingResource(gSharedResource, numClients, EFalse))!=KErrNone) // user-side clients, load the info sl@0: { sl@0: gTest.Printf(_L("GetNumClientsUsingResource returned %d\n"),r); sl@0: channelTwo.Close(); sl@0: return r; sl@0: } sl@0: // To support the GetInfoOnClientsUsingResource testing, instantiate TClientInfoBuf objects sl@0: // and reference via an RSimplePointerArray sl@0: RSimplePointerArray infoPtrs(numClients-1); sl@0: for(TUint i=0;i<(numClients-1);i++) sl@0: { sl@0: TClientInfoBuf *info = new TClientInfoBuf(); sl@0: if((r=infoPtrs.Insert(info, i))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestTransientHandling test, GetInfoOnClientsUsingResource infoPtrs.Insert at index %d returned %d\n"),testNo,i,r); sl@0: channelTwo.Close(); sl@0: } sl@0: } sl@0: if((r=gChannel.GetInfoOnClientsUsingResource(gSharedResource, numClients, &infoPtrs, EFalse))!=KErrArgument) sl@0: { sl@0: gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource for gLongLatencyResource returned %d\n"),r); sl@0: channelTwo.Close(); sl@0: return KErrGeneral; sl@0: } sl@0: // Ensure misleading result is not returned sl@0: r=KErrNone; sl@0: infoPtrs.Close(); sl@0: } sl@0: sl@0: sl@0: // sl@0: // Specific resource data tests sl@0: // sl@0: sl@0: gTest.Printf(_L("TestTransientHandling: Client-specific data tests ...\n")); sl@0: testNo=1; sl@0: sl@0: // These tests require a client name sl@0: TBuf8name8Bit; sl@0: name8Bit.Copy(gTestName); sl@0: TClientName* clientName = (TClientName*)&name8Bit; sl@0: #if _DEBUG sl@0: TBuf clientName16Bit; sl@0: clientName16Bit.Copy(*clientName); sl@0: clientName16Bit.SetLength(clientName->Length()); sl@0: gTest.Printf(_L("Invoking TestTransientHandling client-specific data tests with %S \n"),&clientName16Bit); sl@0: #endif sl@0: // 13) Attempt to read the resource information without having previously loaded it. sl@0: gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); sl@0: { sl@0: TUint numResources = 0; sl@0: if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResources, EFalse))!=KErrNone) // EFalse - don't load data sl@0: { sl@0: gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r); sl@0: return r; sl@0: } sl@0: // To support the GetInfoOnResourcesInUseByClient testing, instantiate TResourceInfoBuf objects sl@0: // and reference via an RSimplePointerArray sl@0: RSimplePointerArray infoPtrs(numResources); sl@0: for(TUint i=0;i tempName2(tempStr2); sl@0: RBusDevResManUs channelThree; sl@0: if((r=OpenChannel(tempName2, channelThree))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("Failed to open channelThree, %d\n"),r); sl@0: channelTwo.Close(); sl@0: return r; sl@0: } sl@0: // Read the number of resources (and, by default, read the resource information) sl@0: // Subsequent call to read the resource information (without re-loading) should return be successful sl@0: // Call to read the information for a client name with zero resource requirements (without re-loading) should return KErrNone, numResources==0 sl@0: // Call to read the information for a client name with one or more resource requirements (without re-loading) should return KErrNotReady sl@0: gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); sl@0: { sl@0: TUint numResources = 0; sl@0: if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResources))!=KErrNone) // load data sl@0: { sl@0: gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r); sl@0: return r; sl@0: } sl@0: // To support the GetInfoOnResourcesInUseByClient testing, instantiate TResourceInfoBuf objects sl@0: // and reference via an RSimplePointerArray sl@0: RSimplePointerArray infoPtrs(numResources); sl@0: for(TUint i=0;iname8Bit2; sl@0: name8Bit2.Copy(tempName2); sl@0: TClientName* clientName2 = (TClientName*)&name8Bit2; sl@0: if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName2, dumResources, &infoPtrs))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestTransientHandling: tempName2 GetInfoOnClientsUsingResource returned %d\n"),r); sl@0: return KErrGeneral; sl@0: } sl@0: if(dumResources!=0) sl@0: { sl@0: gTest.Printf(_L("TestTransientHandling: tempName2 GetInfoOnClientsUsingResource dumResources=%d\n"),dumResources); sl@0: return KErrGeneral; sl@0: } sl@0: TBuf8name8Bit1; sl@0: name8Bit1.Copy(tempName1); sl@0: TClientName* clientName1 = (TClientName*)&name8Bit1; sl@0: if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName1, numResources, &infoPtrs))!=KErrNotReady) sl@0: { sl@0: gTest.Printf(_L("TestTransientHandling: tempName1 GetInfoOnClientsUsingResource returned %d\n"),r); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: infoPtrs.Close(); sl@0: } sl@0: sl@0: sl@0: // 15) Repeat the read the number of resources without reading the resource information sl@0: // Subsequent call to read the resources information (without re-loading) should return error KErrNotReady sl@0: // Then call to read the resources information (with re-loading) should be successful sl@0: gTest.Printf(_L("TestTransientHandling: test %d\n"),testNo++); sl@0: { sl@0: TUint numResources = 0; sl@0: if((r=gChannel.GetNumResourcesInUseByClient(*clientName, numResources, EFalse))!=KErrNone) // don't load data sl@0: { sl@0: gTest.Printf(_L("GetNumResourcesInUseByClient returned %d\n"),r); sl@0: return r; sl@0: } sl@0: // To support the GetInfoOnResourcesInUseByClient testing, instantiate TResourceInfoBuf objects sl@0: // and reference via an RSimplePointerArray sl@0: RSimplePointerArray infoPtrs(numResources); sl@0: for(TUint i=0;i infoPtrs(numResources-1); sl@0: for(TUint i=0;i<(numResources-1);i++) sl@0: { sl@0: TResourceInfoBuf *info = new TResourceInfoBuf(); sl@0: if((r=infoPtrs.Insert(info, i))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestTransientHandling test, GetAllResourcesInfo infoPtrs.Insert at index %d returned %d\n"),testNo,i,r); sl@0: } sl@0: } sl@0: if((r=gChannel.GetInfoOnResourcesInUseByClient(*clientName, numResources, &infoPtrs))!=KErrArgument) sl@0: { sl@0: gTest.Printf(_L("TestTransientHandling: GetInfoOnResourcesInUseByClient returned %d\n"),r); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: // Ensure misleading result is not returned sl@0: r=KErrNone; sl@0: infoPtrs.Close(); sl@0: } sl@0: sl@0: channelTwo.Close(); sl@0: channelThree.Close(); sl@0: sl@0: return r; sl@0: } sl@0: sl@0: sl@0: EXPORT_C TInt E32Main() sl@0: // sl@0: // Main sl@0: // sl@0: { sl@0: gTest.Start(_L("Test Power Resource Manager user side API\n")); sl@0: sl@0: TInt r = KErrNone; sl@0: sl@0: // Test attempted load of PDD sl@0: gTest.Next(_L("**Load PDD\n")); sl@0: r=User::LoadPhysicalDevice(PDD_NAME); sl@0: if((r!=KErrNone)&&(r!=KErrAlreadyExists)) sl@0: { sl@0: gTest.Printf(_L("User::LoadPhysicalDevice error %d\n"),r); sl@0: } sl@0: else sl@0: { sl@0: // Test attempted load of LDD sl@0: gTest.Next(_L("**Load LDD\n")); sl@0: r=User::LoadLogicalDevice(LDD_NAME); sl@0: if((r!=KErrNone)&&(r!=KErrAlreadyExists)) sl@0: gTest.Printf(_L("User::LoadLogicalDevice error - expected %d, got %d\n"),KErrAlreadyExists,r); sl@0: } sl@0: if((r==KErrNone)||(r==KErrAlreadyExists)) sl@0: { sl@0: r = KErrNone; // Re-initialise in case set to KErrAlreadyExists sl@0: // sl@0: // Need a channel open for the following tests sl@0: gTest.Next(_L("**OpenAndRegisterChannel\n")); sl@0: r=OpenAndRegisterChannel(); sl@0: if (r==KErrNone) sl@0: { sl@0: // Get the version of the ResourceController sl@0: TUint version; sl@0: if((r=gChannel.GetResourceControllerVersion(version))!=KErrNone) sl@0: { sl@0: gTest.Printf(_L("TestTransientHandling: GetResourceControllerVersion returned %d\n"),r); sl@0: return r; sl@0: } sl@0: gTest.Printf(_L("TestTransientHandling: ResourceController version =0x%x\n"),version); sl@0: } sl@0: if (r==KErrNone) sl@0: { sl@0: gTest.Next(_L("**TestThreadExclusiveAccess\n")); sl@0: r=TestThreadExclusiveAccess(); sl@0: } sl@0: if (r==KErrNone) sl@0: { sl@0: gTest.Next(_L("**TestGetClientGetResourceInfo - initial state\n")); sl@0: r=TestGetClientGetResourceInfo(); sl@0: } sl@0: if (r==KErrNone) sl@0: { sl@0: gTest.Next(_L("**TestGetSetResourceStateOps\n")); sl@0: r=TestGetSetResourceStateOps(); sl@0: } sl@0: if (r==KErrNone) sl@0: { sl@0: gTest.Next(_L("**TestGetClientGetResourceInfo - after changing stateof Async resource\n")); sl@0: r=TestGetClientGetResourceInfo(); sl@0: } sl@0: if (r==KErrNone) sl@0: { sl@0: gTest.Next(_L("**TestGetSetResourceStateQuota\n")); sl@0: r=TestGetSetResourceStateQuota(); sl@0: } sl@0: if (r==KErrNone) sl@0: { sl@0: gTest.Next(_L("**TestNotificationOps\n")); sl@0: r=TestNotificationOps(); sl@0: } sl@0: if (r==KErrNone) sl@0: { sl@0: gTest.Next(_L("**TestNotificationQuota\n")); sl@0: r=TestNotificationQuota(); sl@0: } sl@0: if (r==KErrNone) sl@0: { sl@0: // Should be no change since last invocation (assuming that sl@0: // no clients other than those in this test) sl@0: gTest.Next(_L("**TestGetClientGetResourceInfo - last invocation\n")); sl@0: r=TestGetClientGetResourceInfo(); sl@0: } sl@0: if (r==KErrNone) sl@0: { sl@0: gTest.Next(_L("**TestAdditionalThread\n")); sl@0: r=TestAdditionalThread(); sl@0: } sl@0: if (r==KErrNone) sl@0: { sl@0: gTest.Next(_L("**TestTransientHandling\n")); sl@0: r=TestTransientHandling(); sl@0: } sl@0: } sl@0: gChannel.Close(); sl@0: sl@0: User::FreeLogicalDevice(KLddRootName); sl@0: User::FreePhysicalDevice(PDD_NAME); sl@0: User::After(100000); // Allow idle thread to run for driver unloading sl@0: sl@0: gTest.End(); sl@0: return r; sl@0: } sl@0: