First public contribution.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\resourceman\t_rescontrolcli.cpp
15 // TestCase Description:
16 // This tests is intended to test the generic layer of PRM. It consists of unit testing and regression testing.
17 // Unit testing validates each of the API's. Regression testing performs random operation on random resource and
18 // currently executes 500 operations and returns.
19 // To run regression testing, test must be invoked with -R option.
20 // Testing runs only on simulated PSL.
28 #include <e32def_private.h>
29 #include "d_rescontrolcli.h"
31 #define MAX_STATIC_RESOURCE_NUM 24 //Maximum number of static resources in simulated PSL
32 #define MAX_STATIC_DEPENDENCY_RESOURCE_NUM 7 //Maximum number of static dependency resources in simulated PSL
33 #define DEPENDENCY_RESOURCE_BIT_MASK 0x00010000
34 #define DYNAMIC_RESOURCE_BIT_MASK 0x00020000
35 #define CUSTOM_RESOURCE_NUMBER 20
37 /** Macro to push the item into the specified list. Item are pushed to the head of the list. */
38 #define LIST_PUSH(list,item,link) \
40 (item)->link = (list); \
44 /** Macro to pop the item from the specified list. Item are poped from the head of the list. */
45 #define LIST_POP(list,item,link) \
50 (list) = (item)->link; \
51 (item)->link = NULL; \
55 /** Macro to remove the item from the list. */
56 #define LIST_REMOVE(list,item,link,className) \
59 className* current = (list); \
60 if (current==(item)) \
62 (list) = (item)->link; \
63 (item)->link = NULL; \
67 className* next = current->link; \
72 current->link=next->link; \
82 #ifndef PRM_ENABLE_EXTENDED_VERSION
83 _LIT(KLddFileName, "D_RESCONTROLCLI.LDD");
84 _LIT(KPddFileName, "resourcecontroller.pdd");
86 _LIT(KExtLddFileName, "D_EXTENDEDRESCONTROLCLI.LDD");
87 _LIT(KExtPddFileName, "resourcecontrollerextended.pdd");
90 LOCAL_D RTest test(_L("RESOURCE_MANAGER_TEST"));
91 TBuf8<32> SpecialResName(_L8("SymbianSimulResource"));
93 //Enum definition for resource classification.
94 enum TType {EMultiLevel = 0x1, EMultiProperty};
95 enum TUsage {ESingle, EShared};
96 enum TLatency {EInstantaneous, ELongLatency};
97 enum TClass {EPhysical, ELogical};
98 enum TSense {EPositive, ENegative, ECustom};
100 //Structure to get resource information
101 class TPowerResourceInfoV01
105 TLatency iLatencyGet;
106 TLatency iLatencySet;
110 TDesC8* iResourceName;
123 //Structure to get client information
124 struct TPowerClientInfoV01
130 //Structure for holding client information
135 TUint iResourceIds[MAX_STATIC_RESOURCE_NUM]; //Each bit corresponds to a static resource.
138 //Structure for holding notification information
148 // Structure for holding client level
149 struct SPowerResourceClientLevel
154 SPowerResourceClientLevel* iNextInList;
157 //Structure for capturing resource information to be used by Idle thread.
158 struct SIdleResourceInfo
163 TInt iReserved1; //Reserved for future use.
164 TInt iReserved2; //Reserved for future use.
165 TInt iReserved3; //Reserved for future use.
168 //Structure for holding resource information
181 TLatency iLatencyGet;
182 TLatency iLatencySet;
184 TUint iUnCondNotiCount;
186 NotiInfo *iUncondNoti;
187 SPowerResourceClientLevel *iLevel;
194 //Possible resource operation.
199 EGetAllClientName = 2,
202 EGetResourceInfo = 5,
203 EGetNumReosourceInUseByClient = 6,
204 EGetInfoOnResourceInUseByClient = 7,
205 EGetNumClientsUsingResource = 8,
206 EGetInfoOnClientsUsingResource = 9,
207 EChangeResourceStateSync = 10,
208 EChangeResourceStateAsync = 11,
209 EGetResourceStateSync = 12,
210 EGetResourceStateAsync = 13,
211 ERequestNotificationCond = 14,
212 ERequestNotificationUnCond = 15,
213 ECancelNotificationCond = 16,
214 ECancelNotificationUnCond = 17,
219 void RegisterClient();
220 void DeRegisterClient(TUint aClientId);
221 void GetClientName(TUint aClientId);
222 void GetClientId(TUint aClientId);
223 void GetResourceId(TUint aResId);
224 void GetResourceInfo(TUint aResId);
225 void GetNumResourcesInUseByClient(TInt aClientId);
226 void GetInfoOnResourcesInUseByClient(TInt aClientId, TUint aNumRes);
227 void GetNumClientsUsingResource(TUint aClientId, TUint aResId);
228 void GetInfoOnClientsUsingResource(TUint aResId, TUint aNumCli);
229 void AllocReserve(TUint aClientId);
230 void CheckNotification(TUint aResId, TInt newState);
231 void AddClientLevel(TUint aResId, TInt newState);
232 void UpdateClientInformation(TUint aResId, TInt aNewState);
233 void ChangeResourceStateSync(TUint aResId);
234 void ChangeResourceStateAsync(TUint aResId, TBool aReqCancel=EFalse);
235 void GetResourceStateSync(TUint aResId);
236 void GetResourceStateAsync(TUint aResId, TBool aReqCancel=EFalse);
237 void RequestNotification(TUint aResId);
238 void RequestNotificationCon(TUint aResId);
239 void ValidateClient(TUint aNumClients, TOwnerType aContext);
240 void CancelNotification(TUint aResId, TBool Cond);
241 void APIValidationTest();
242 void SharedBinaryPositiveResourceTesting(TUint aResId);
243 void SharedBinaryNegativeResourceTesting(TUint aResId);
244 void CustomResourceTesting(TUint aResId);
245 void DeRegisterClientLevelFromResource(TInt aClientId, TUint aResId);
246 void RegressionTest();
247 void TestStaticResourceWithDependency();
248 void GetExtendedResStateAsyncAndVerify(TUint aResId, TInt aState, TInt aLevelOwnerId, TBool aReqCancel = EFalse);
249 void GetExtendedResStateAndVerify(TUint aResId, TInt aState, TInt aLevelOwnerId);
250 void TestDynamicResource();
251 void TestDynamicResourceDependency();
252 void CheckForDependencyInformation(TUint aClientId, TUint aResourceId, TUint aNumDependents, SResourceDependencyInfo* aDepResIdArray);
253 void SharedMultilevelNegativeResourceTesting(TUint aResId);
254 void SharedMultilevelPositiveResourceTesting(TUint aResId);
256 RArray<RMClientInfo> Clients;
257 RMResInfo Resources[MAX_STATIC_RESOURCE_NUM];
258 TUint iStaticDependencyResources[MAX_STATIC_DEPENDENCY_RESOURCE_NUM];
259 TInt iCurrentClientId;
262 TUint iMaxStaticResources;
263 TUint iMaxStaticDependentResources;
264 TUint iPowerControllerId;
265 TUint iTestingExtendedVersion;
268 TBool NegativeTesting; //If true enables negative testing of API's
270 TBuf8<32> ClientName(_L8("Client?"));
275 TestRM::TestRM(): iCurrentClientId(-1),iMaxClientId(0), iMaxClients(0),iMaxStaticResources(0), iMaxStaticDependentResources(0), iTestingExtendedVersion(0)
277 test.Printf(_L("TestRM::TestRM()\n"));
280 //----------------------------------------------------------------------------------------------
281 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0573
283 //! @SYMPREQ PREQ1398
284 //! @SYMTestCaseDesc This test case tests the client registeration functionality of resource
285 //! manager.It registeres a client with resource manager and stores the relevant
286 //! information in Clients array. Currently allows only maximum of 50 client
288 //! @SYMTestActions 0 Returns if already maximum allowable clients are registered.
289 //! 1 Register a client with the resource manager with a unique name.
290 //! 2 Appends the client information to an array for futher reference.
292 //! @SYMTestExpectedResults client registration is successful, panics otherwise.
293 //! @SYMTestPriority High
294 //! @SYMTestStatus Implemented
295 //----------------------------------------------------------------------------------------------
296 void TestRM::RegisterClient()
300 if(iMaxClientId > MAX_CLIENTS)
302 test.Printf(_L("Reached maximum client allocation. Can't allocate more\n"));
305 ClientName[6] = (TUint8)('0' + iMaxClientId);
306 r = lddChan.RegisterClient(clientId, (const TDesC*)&ClientName);
308 test.Printf(_L("Register Client failed with %d\n"), r);
310 info.iClientId = clientId;
311 info.iNumResources = 0;
312 for(TUint c = 0; c< MAX_STATIC_RESOURCE_NUM; c++)
313 info.iResourceIds[c] = 0;
316 r = Clients.Append(info);
318 test.Printf(_L("Client Append failed with %d\n"), r);
322 //----------------------------------------------------------------------------------------------
323 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0574
325 //! @SYMPREQ PREQ1398
326 //! @SYMTestCaseDesc This test case tests the client deregisteration functionality of resource
327 //! manager.It deregisteres a client with the resource manager, calculates
328 //! the resource level of each resource that the client was having requirement and
329 //! checks the resource level change after client deregistration.
330 //! @SYMTestActions 0 Deregister a client from resource manager
331 //! 1 Calculates the resource level of each resource the client was having requirement.
332 //! 2 Checks the resource level change of each resource for correctness.
333 //! 3 Zeros the clientId stored internally to make sure it is not referenced again.
335 //! @SYMTestExpectedResults client deregistration is successful and also the resource level of
336 //! each resource the client was holding the resource level is checked
337 //! for correctness, panics otherwise
338 //! @SYMTestPriority High
339 //! @SYMTestStatus Implemented
340 //----------------------------------------------------------------------------------------------
341 void TestRM::DeRegisterClient(TUint aClientId)
343 r = lddChan.DeRegisterClient(Clients[aClientId].iClientId);
345 test.Printf(_L("Client deregistration of %d failed with %d\n"), Clients[aClientId].iClientId, r);
348 for(count = 0; count < iMaxStaticResources; count++)
350 RMResInfo *pR = &Resources[count];
351 NotiInfo* pI = pR->iCondNoti;
352 NotiInfo* ptr = NULL;
353 //Remove any conditional notification that this client has on resource.
356 if(pI->iClientId == aClientId)
360 LIST_REMOVE(pR->iCondNoti, ptr, iNext, NotiInfo);
367 //Remove any unconditional notification that this client has on resource.
368 pI = pR->iUncondNoti;
372 if(pI->iClientId == aClientId)
376 LIST_REMOVE(pR->iUncondNoti, ptr, iNext, NotiInfo);
383 //Remove client level
385 for(count = 0; count < Clients[aClientId].iNumResources; count++)
387 res = Clients[aClientId].iResourceIds[count];
390 for(TUint c = 0; c< iMaxStaticResources; c++)
392 if(Resources[c].iResourceId == res)
398 if(Resources[res].iCurrentClient == (TInt)aClientId)
400 if(!Resources[res].iUsage)
402 Resources[res].iCurrentLevel = Resources[res].iDefaultLevel;
403 Resources[res].iCurrentClient = -1;
404 Resources[res].iNumClients = 0;
406 else if(Resources[res].iSense == ECustom)
410 TInt maxLevel = KMinTInt;
412 for(SPowerResourceClientLevel* pCL = Resources[res].iLevel; pCL != NULL; pCL = pCL->iNextInList)
414 if(pCL->iClientId == aClientId)
416 if((maxLevel == KMinTInt) || (maxLevel == pCL->iLevel))
418 maxLevel = pCL->iLevel;
422 if(Resources[res].iSense == EPositive && pCL->iLevel > maxLevel)
424 maxLevel = pCL->iLevel;
427 else if(Resources[res].iSense == ENegative && pCL->iLevel < maxLevel)
429 maxLevel = pCL->iLevel;
435 Resources[res].iCurrentLevel = Resources[res].iDefaultLevel;
436 Resources[res].iCurrentClient = -1;
437 Resources[res].iNumClients = 0;
441 Resources[res].iCurrentLevel = maxLevel;
442 Resources[res].iCurrentClient = id;
443 Resources[res].iNumClients--;
447 //Remove client list entry from resource
448 for(SPowerResourceClientLevel* pCL = Resources[res].iLevel; pCL != NULL; pCL = pCL->iNextInList)
450 if(pCL->iClientId == aClientId)
452 LIST_REMOVE(Resources[res].iLevel, pCL, iNextInList, SPowerResourceClientLevel);
458 //Verify the resource state consistency
464 for(TUint id = 0; id < Clients[aClientId].iNumResources; id++)
466 res = Clients[aClientId].iResourceIds[id];
469 for(TUint c = 0; c< iMaxStaticResources; c++)
471 if(Resources[c].iResourceId == res)
477 r = lddChan.GetResourceStateSync(Clients[0].iClientId, Resources[res].iResourceId, ETrue, newState, levelOwnerId);
479 test.Printf(_L("GetResourceStateSync returned with %d"), r);
481 if(newState != Resources[res].iCurrentLevel)
482 test.Printf(_L("newState = %d, Resources[%d].iCurrentLevel = %d"), newState, Resources[res].iResourceId, Resources[res].iCurrentLevel);
483 test(newState == Resources[res].iCurrentLevel);
484 if(Resources[res].iCurrentClient == -1)
485 test(levelOwnerId == -1);
486 else if (levelOwnerId != (TInt)Clients[Resources[res].iCurrentClient].iClientId)
488 test.Printf(_L("levelOwnerId = 0x%x, iCurrentClient = 0x%x\n"), levelOwnerId, Resources[res].iCurrentClient);
493 Clients[aClientId].iClientId = 0;
497 //----------------------------------------------------------------------------------------------
498 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0575
500 //! @SYMPREQ PREQ1398
501 //! @SYMTestCaseDesc This test case tests the retrieval of client name functionality of resource
502 //! manager and compares for correctness. There are negative and positive tests.
503 //! @SYMTestActions If negative testing is enabled then following tests are done
504 //! 0 Call the API with invalid client Id (calling client Id).
505 //! 1 Call the API with invalid instance count of calling client Id.
506 //! 2 Call the API with invalid target client Id.
507 //! 3 Call the API with invalid instance count of target client Id.
509 //! 4 Call the API with valid client Ids (both calling and target client ID)
511 //! @SYMTestExpectedResults 0 API should return with KErrAccessDenied, panics otherwise
512 //! 1 API should return with KErrAccessDenied, panics otherwise
513 //! 2 API should return with KErrNotFound, panics otherwise
514 //! 3 API should return with KErrNotFound, panics otherwise
515 //! 4 API should return KErrNone with name updated and also name
516 //! is checked for correctness, panics otherwise
517 //! @SYMTestPriority High
518 //! @SYMTestStatus Implemented
519 //----------------------------------------------------------------------------------------------
520 void TestRM::GetClientName(TUint aClientId)
522 ClientName[6] = (TUint8)('0' + aClientId);
526 //Pass illegal client Id
527 r = lddChan.GetClientName(0, Clients[aClientId].iClientId, (TDes8*)&name);
528 test(r == KErrAccessDenied);
530 //Pass illegal instance count
531 TUint id = Clients[aClientId].iClientId;
533 r = lddChan.GetClientName(id, Clients[aClientId].iClientId, (TDes8*)&name);
534 test(r == KErrAccessDenied);
536 //Pass illegal target client id
537 r = lddChan.GetClientName(Clients[aClientId].iClientId, iMaxClients, (TDes8*)&name);
538 test(r == KErrNotFound);
540 //Pass illegal instance count of target client id
542 r = lddChan.GetClientName(Clients[aClientId].iClientId, 0 ,(TDes8*)&name);
543 test(r == KErrNotFound);
545 r = lddChan.GetClientName(Clients[aClientId].iClientId, Clients[aClientId].iClientId, (TDes8*)&name);
547 test.Printf(_L("GetClientName of ClientId 0x%x returned with %d"), Clients[aClientId].iClientId, r);
549 if(name.Compare(ClientName))
554 //----------------------------------------------------------------------------------------------
555 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0576
557 //! @SYMPREQ PREQ1398
558 //! @SYMTestCaseDesc This test case tests the retrieval of client ID functionality of resource
559 //! manager and compares for correctness. There are negative and positive tests.
560 //! @SYMTestActions If negative testing is enabled then following tests are done
561 //! 0 Call the API with invalid client Id (calling client Id).
562 //! 1 Call the API with invalid instance count of calling client Id.
563 //! 2 Call the API with client name greater than maximum allowable
564 //! client name (32 characters).
565 //! 3 Call the API with name not registered with resource manager
566 //! (non-existing name).
568 //! 4 Call the API with valid client Id.
570 //! @SYMTestExpectedResults 0 API should return with KErrAccessDenied, panics otherwise
571 //! 1 API should return with KErrAccessDenied, panics otherwise
572 //! 2 API should return with KErrTooBig, panics otherwise
573 //! 3 API should return with KErrNotFound, panics otherwise
574 //! 4 API should return KErrNone with client Id updated and also Id
575 //! is checked for correctness, panics otherwise
576 //! @SYMTestPriority High
577 //! @SYMTestStatus Implemented
578 //----------------------------------------------------------------------------------------------
579 void TestRM::GetClientId(TUint aClientId)
582 ClientName[6] = (TUint8)('0' + aClientId);
585 //Pass illegial client Id
586 r = lddChan.GetClientId(0, (TDesC8&)ClientName, Clients[aClientId].iClientId);
587 test(r == KErrAccessDenied);
589 //Pass illegal instance count
590 TUint id = Clients[aClientId].iClientId;
592 r = lddChan.GetClientId(id, (TDesC8&)ClientName, Clients[aClientId].iClientId);
593 test(r == KErrAccessDenied);
595 TBuf8<50> badName = _L8("Clientnamegreaterthan32characters");
596 r = lddChan.GetClientId(Clients[aClientId].iClientId, (TDesC8&)badName, clientId);
597 test(r == KErrTooBig);
599 ClientName[6] = (TUint8)('0' + iMaxClients + 1);
600 r = lddChan.GetClientId(Clients[aClientId].iClientId, (TDesC8&)ClientName, clientId);
601 test(r == KErrNotFound);
603 ClientName[6] = (TUint8)('0' + aClientId);
604 r = lddChan.GetClientId(Clients[aClientId].iClientId, (TDesC8&)ClientName, clientId);
606 test.Printf(_L("GetClientId returned with %d"), r);
608 if(clientId != Clients[aClientId].iClientId)
609 test.Printf(_L("ClientId = 0x%x, Expected ClientId = 0x%x"), clientId, Clients[aClientId].iClientId);
610 test(clientId == Clients[aClientId].iClientId);
613 //----------------------------------------------------------------------------------------------
614 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0577
616 //! @SYMPREQ PREQ1398
617 //! @SYMTestCaseDesc This test case tests the retrieval of resource ID functionality of resource
618 //! manager and compares for correctness. There are negative and positive tests.
619 //! @SYMTestActions If negative testing is enabled then following tests are done
620 //! 0 Call the API with invalid client Id (calling client Id).
621 //! 1 Call the API with invalid instance count of calling client Id.
622 //! 2 Call the API with resource name greater than maximum allowable
623 //! resource name (32 characters).
624 //! 3 Call the API with name not registered with resource manager
625 //! (non-existing name).
627 //! 4 Call the API with valid client Id and resource name.
629 //! @SYMTestExpectedResults 0 API should return with KErrAccessDenied, panics otherwise
630 //! 1 API should return with KErrAccessDenied, panics otherwise
631 //! 2 API should return with KErrTooBig, panics otherwise
632 //! 3 API should return with KErrNotFound, panics otherwise
633 //! 4 API should return KErrNone with resource Id updated and also Id
634 //! is checked for correctness, panics otherwise
635 //! @SYMTestPriority High
636 //! @SYMTestStatus Implemented
637 //----------------------------------------------------------------------------------------------
638 void TestRM::GetResourceId(TUint aResId)
643 r = lddChan.GetResourceId(iMaxClients, Resources[aResId].iName, resId);
644 test(r == KErrAccessDenied);
646 //Pass illegal instance count
647 TUint id = Clients[iCurrentClientId].iClientId;
649 r = lddChan.GetResourceId(id, (TDesC8&)Resources[aResId].iName, resId);
650 test(r == KErrAccessDenied);
652 TBuf8<50> badName = _L8("Resourcenamegreaterthen32characters");
653 r = lddChan.GetResourceId(Clients[iCurrentClientId].iClientId, (TDesC8&)badName, resId);
654 test(r == KErrTooBig);
655 badName = Resources[aResId].iName;
656 badName[0] = '0' + 1;
657 r = lddChan.GetResourceId(Clients[iCurrentClientId].iClientId, (TDesC8&)badName, resId);
658 test(r == KErrNotFound);
660 r = lddChan.GetResourceId(Clients[iCurrentClientId].iClientId, (TDesC8&)Resources[aResId].iName, resId);
662 test.Printf(_L("Return value of GetResourceId %d"), r);
664 if(resId != Resources[aResId].iResourceId)
665 test.Printf(_L("resId = %d ... aResId = %d"), resId, Resources[aResId].iResourceId);
666 test(resId == Resources[aResId].iResourceId);
670 //----------------------------------------------------------------------------------------------
671 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0578
673 //! @SYMPREQ PREQ1398
674 //! @SYMTestCaseDesc This test case tests the retrieval of resource information of a specified
675 //! resource functionality of resource manager and compares each info for correctness.
676 //! There are negative and positive tests.
677 //! @SYMTestActions If negative testing is enabled then following tests are done
678 //! 0 Call the API with invalid client Id (calling client Id).
679 //! 1 Call the API with invalid instance count of calling client Id.
680 //! 2 Call the API with invalid resource id.
682 //! 3 Call the API with valid client Id and resource id.
684 //! @SYMTestExpectedResults 0 API should return with KErrAccessDenied, panics otherwise
685 //! 1 API should return with KErrAccessDenied, panics otherwise
686 //! 2 API should return with KErrNotFound, panics otherwise
687 //! 3 API should return KErrNone with resource information updated and also
688 //! each information is checked for correctness, panics otherwise
689 //! @SYMTestPriority High
690 //! @SYMTestStatus Implemented
691 //----------------------------------------------------------------------------------------------
692 void TestRM::GetResourceInfo(TUint aResId)
695 infoBuf.Create(sizeof(TPowerResourceInfoV01));
698 r = lddChan.GetResourceInfo(iMaxClients-5, aResId+1, (TAny*)(TDes8*)&infoBuf);
699 test(r == KErrAccessDenied);
701 //Pass illegal instance count
702 TUint id = Clients[iCurrentClientId].iClientId;
704 r = lddChan.GetResourceInfo(id, aResId+1, (TAny*)infoBuf.Ptr());
705 test(r == KErrAccessDenied);
707 r = lddChan.GetResourceInfo(Clients[iCurrentClientId].iClientId, iMaxStaticResources + 30, (TAny*)(TDes8*)&infoBuf);
708 test(r == KErrNotFound);
709 r = lddChan.GetResourceInfo(Clients[iCurrentClientId].iClientId, 26, (TAny*)(TDes8*)&infoBuf);
710 test(r == KErrNotFound);
712 r = lddChan.GetResourceInfo(Clients[iCurrentClientId].iClientId, Resources[aResId].iResourceId, (TAny*)(TDes8*)&infoBuf);
714 test.Printf(_L("GetResourceInfo returned with %d"), r);
716 TPowerResourceInfoV01 *ptr = (TPowerResourceInfoV01*)infoBuf.Ptr();
718 test(ptr->iResourceId == Resources[aResId].iResourceId);
719 test(ptr->iLatencyGet == Resources[aResId].iLatencyGet);
720 test(ptr->iLatencySet == Resources[aResId].iLatencySet);
721 test(ptr->iType == Resources[aResId].iType);
722 test(ptr->iUsage == Resources[aResId].iUsage);
723 test(ptr->iSense == Resources[aResId].iSense);
724 test(ptr->iMaxLevel == Resources[aResId].iMaxLevel);
725 test(ptr->iMinLevel == Resources[aResId].iMinLevel);
726 test(ptr->iDefaultLevel == Resources[aResId].iDefaultLevel);
727 if(ptr->iUsage == ESingle && Resources[aResId].iNumClients >1) //Single user resource cannot have more than 1 client.
732 //----------------------------------------------------------------------------------------------
733 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0579
735 //! @SYMPREQ PREQ1398
736 //! @SYMTestCaseDesc This test case tests retrieval of number of resources the requested client has
737 //! requirement functionality of resource manager and compares with stored information
738 //! for correctness.There are negative and positive tests.
739 //! @SYMTestActions If negative testing is enabled then following tests are done
740 //! 0 Call the API with invalid client Id (calling client Id).
741 //! 1 Call the API with invalid instance count of calling client Id.
742 //! 2 Call the API with invalid target client Id.
743 //! 3 Call the API with invalid instance count of target client Id.
745 //! 4 Call the API with valid calling and target client Id.
747 //! @SYMTestExpectedResults 0 API should return with KErrAccessDenied, panics otherwise
748 //! 1 API should return with KErrAccessDenied, panics otherwise
749 //! 2 API should return with KErrNotFound, panics otherwise
750 //! 3 API should return with KErrNotFound, panics otherwise
751 //! 4 API should return KErrNone with number of resources the requested client has
752 //! requirement updated and also is checked for correctness, panics otherwise
753 //! @SYMTestPriority High
754 //! @SYMTestStatus Implemented
755 //----------------------------------------------------------------------------------------------
756 void TestRM::GetNumResourcesInUseByClient(TInt aClientId)
761 //Pass illegial client Id
762 r = lddChan.GetNumResourcesInUseByClient(23, Clients[aClientId].iClientId, numRes);
763 test(r == KErrAccessDenied);
765 //Pass illegal instance count
766 TUint id = Clients[aClientId].iClientId;
768 r = lddChan.GetNumResourcesInUseByClient(id, Clients[aClientId].iClientId, numRes);
769 test(r == KErrAccessDenied);
771 //Pass illegal target client id
772 r = lddChan.GetNumResourcesInUseByClient(Clients[aClientId].iClientId, iMaxClients, numRes);
773 test(r == KErrNotFound);
775 //Pass illegal instance count of target client id
777 r = lddChan.GetNumResourcesInUseByClient(Clients[aClientId].iClientId, id ,numRes);
778 test(r == KErrNotFound);
783 r = lddChan.GetNumResourcesInUseByClient(Clients[0].iClientId, 0, numRes);
785 test.Printf(_L("GetNumResourcesInUseByClient returned with %d"), r);
787 if((!iTestingExtendedVersion) && (numRes > MAX_STATIC_RESOURCE_NUM))
789 if(iMaxStaticResources == 0)
790 iMaxStaticResources = numRes;
792 test(numRes == (iMaxStaticResources + iMaxStaticDependentResources));
796 r = lddChan.GetNumResourcesInUseByClient(Clients[aClientId].iClientId, Clients[aClientId].iClientId, numRes);
798 test.Printf(_L("GetNumResourceInUseByClient returned with %d"), r);
800 if(numRes != Clients[aClientId].iNumResources)
801 test.Printf(_L("numRes = %d, iNumResources = %d"), numRes, Clients[aClientId].iNumResources);
802 test(numRes == Clients[aClientId].iNumResources);
806 //----------------------------------------------------------------------------------------------
807 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0580
809 //! @SYMPREQ PREQ1398
810 //! @SYMTestCaseDesc This test case tests retrieval of information about resources the requested client has
811 //! requirement functionality of resource manager and compares with stored information
812 //! for correctness.There are negative and positive tests.
813 //! @SYMTestActions If negative testing is enabled then following tests are done
814 //! 0 Call the API with invalid client Id (calling client Id).
815 //! 1 Call the API with invalid instance count of calling client Id.
816 //! 2 Call the API with invalid target client Id.
817 //! 3 Call the API with invalid instance count of target client Id.
818 //! 4 Call the API with null buffer (buffer where the resource information will be updated).
819 //! 5 Call the API with the number of resource information to be updated as 0 (specifies the
820 //! size of the buffer).
822 //! 6 Call the API with valid calling and target client Id, buffer and its size.
824 //! @SYMTestExpectedResults 0 API should return with KErrAccessDenied, panics otherwise
825 //! 1 API should return with KErrAccessDenied, panics otherwise
826 //! 2 API should return with KErrNotFound, panics otherwise
827 //! 3 API should return with KErrNotFound, panics otherwise
828 //! 4 API should return with KErrArgument, panics otherwise
829 //! 5 API should return with KErrArgument, panics otherwise
830 //! 6 API should return KErrNone with resource information about resources the requested
831 //! client has requirement updated and also is checked for correctness, panics otherwise
832 //! @SYMTestPriority High
833 //! @SYMTestStatus Implemented
834 //----------------------------------------------------------------------------------------------
835 void TestRM::GetInfoOnResourcesInUseByClient(TInt aClientId, TUint aNumRes)
838 info.Create(aNumRes * sizeof(TPowerResourceInfoV01));
841 //Pass illegial client Id
842 r = lddChan.GetInfoOnResourcesInUseByClient(32, Clients[aClientId].iClientId, aNumRes, (TAny*)(TDes8*)&info);
843 test(r == KErrAccessDenied);
845 //Pass illegal instance count
846 TUint id = Clients[aClientId].iClientId;
848 r = lddChan.GetInfoOnResourcesInUseByClient(id, Clients[aClientId].iClientId, aNumRes, (TAny*)(TDes8*)&info);
849 test(r == KErrAccessDenied);
851 //Pass illegal target client id
852 r = lddChan.GetInfoOnResourcesInUseByClient(Clients[aClientId].iClientId, iMaxClients, aNumRes, (TAny*)(TDes8*)&info);
853 test(r == KErrNotFound);
855 //Pass illegal instance count of target client id
857 r = lddChan.GetInfoOnResourcesInUseByClient(Clients[aClientId].iClientId, id ,aNumRes,(TAny*)(TDes8*)&info);
858 test(r == KErrNotFound);
861 r = lddChan.GetInfoOnResourcesInUseByClient(Clients[aClientId].iClientId, Clients[aClientId].iClientId ,aNumRes, (TAny*)NULL);
862 test(r == KErrArgument);
864 //Pass required resources as 0
866 r = lddChan.GetInfoOnResourcesInUseByClient(Clients[aClientId].iClientId, Clients[aClientId].iClientId, tempRes, (TAny*)(TDes8*)&info);
867 test(r == KErrArgument);
872 r = lddChan.GetInfoOnResourcesInUseByClient(Clients[0].iClientId, 0, aNumRes, (TAny*)(TDes8*)&info);
874 test.Printf(_L("GetInfoOnResourceInUseByClient returned with %d"), r);
876 if(aNumRes != (iMaxStaticResources + iMaxStaticDependentResources))
877 test.Printf(_L("aNumRes = %d, iMaxStaticResources = %d"), aNumRes, iMaxStaticResources);
878 test(aNumRes == (iMaxStaticResources + iMaxStaticDependentResources));
880 //Fill in the resource information
881 TInt newState, levelOwnerId;
882 TPowerResourceInfoV01 *ptr = (TPowerResourceInfoV01*)info.Ptr();
885 for(TUint count = 0; count < aNumRes; count++)
887 r = lddChan.GetResourceStateSync(Clients[0].iClientId, ptr->iResourceId, ETrue, newState, levelOwnerId);
889 test.Printf(_L("GetResourceStateSync failed for ClientId = %d, resourceId = %d with return value %d\n"), Clients[0].iClientId, count+1, r);
891 test.Printf(_L("Info of Resource %d\n"), count+1);
892 test.Printf(_L("Resource Id %d\n"), ptr->iResourceId);
893 test.Printf(_L("Resource Type %d\n"), ptr->iType);
894 test.Printf(_L("Resource Sense %d\n"), ptr->iSense);
895 test.Printf(_L("Resource Latency Get %d\n"), ptr->iLatencyGet);
896 test.Printf(_L("Resource Latency Set %d\n"), ptr->iLatencySet);
897 test.Printf(_L("Resource usage %d\n"), ptr->iUsage);
898 test.Printf(_L("Resource MinLevel %d\n"), ptr->iMinLevel);
899 test.Printf(_L("Resource MaxLevel %d\n"), ptr->iMaxLevel);
900 test.Printf(_L("Resource DefaultLevel %d\n"), ptr->iDefaultLevel);
902 if(iTestingExtendedVersion && (ptr->iResourceId & DEPENDENCY_RESOURCE_BIT_MASK))
904 iStaticDependencyResources[extCount++] = ptr->iResourceId;
908 if(iTestingExtendedVersion && (ptr->iResourceId & DYNAMIC_RESOURCE_BIT_MASK))
913 Resources[count].iName.Copy(*ptr->iResourceName);
914 Resources[count].iResourceId = ptr->iResourceId;
915 Resources[count].iMaxLevel = ptr->iMaxLevel;
916 Resources[count].iMinLevel = ptr->iMinLevel;
917 Resources[count].iDefaultLevel = ptr->iDefaultLevel;
918 Resources[count].iNumClients = 0;
919 Resources[count].iCurrentClient = -1;
920 Resources[count].iCurrentLevel = newState;
921 Resources[count].iType = ptr->iType;
922 Resources[count].iSense = ptr->iSense;
923 Resources[count].iLatencyGet = ptr->iLatencyGet;
924 Resources[count].iLatencySet = ptr->iLatencySet;
925 Resources[count].iUsage = ptr->iUsage;
926 Resources[count].iUnCondNotiCount = 0;
927 Resources[count].iCondNoti = NULL;
928 Resources[count].iUncondNoti = NULL;
929 Resources[count].iLevel = NULL;
932 iMaxStaticResources -= extCount;
933 iMaxStaticDependentResources = extCount;
937 r = lddChan.GetInfoOnResourcesInUseByClient(Clients[aClientId].iClientId, Clients[aClientId].iClientId, aNumRes, (TAny*)&info);
938 if(aNumRes != Clients[aClientId].iNumResources)
940 test.Printf(_L("Expected Resource Num = %d, Returned = %d\n"), Clients[aClientId].iNumResources, aNumRes);
945 test((r == KErrArgument) || (r == KErrNone));
951 TPowerResourceInfoV01 *ptr = (TPowerResourceInfoV01*)info.Ptr();
952 for(TUint count = 0; count < Clients[aClientId].iNumResources; count++)
954 if(Clients[aClientId].iResourceIds[count] == 0)
957 for(c = 0; c < Clients[aClientId].iNumResources; c++)
959 if(Clients[aClientId].iResourceIds[c] == ptr->iResourceId)
962 if(c == Clients[aClientId].iNumResources)
964 //Find the resource from resource list
965 for(c = 0; c < iMaxStaticResources; c++)
967 if(Resources[c].iResourceId == ptr->iResourceId)
970 if(c == iMaxStaticResources)
972 test(Resources[c].iResourceId == ptr->iResourceId);
973 test(Resources[c].iMaxLevel == ptr->iMaxLevel);
974 test(Resources[c].iMinLevel == ptr->iMinLevel);
975 test(Resources[c].iDefaultLevel == ptr->iDefaultLevel);
976 test(Resources[c].iType == ptr->iType);
977 test(Resources[c].iSense == ptr->iSense);
978 test(Resources[c].iLatencyGet == ptr->iLatencyGet);
979 test(Resources[c].iLatencySet == ptr->iLatencySet);
980 test(Resources[c].iUsage == ptr->iUsage);
981 test(!Resources[c].iName.Compare(*ptr->iResourceName));
987 //----------------------------------------------------------------------------------------------
988 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0581
990 //! @SYMPREQ PREQ1398
991 //! @SYMTestCaseDesc This test case tests retrieval of number of clients holding requirement on
992 //! the requested resource functionality of resource manager and compares with stored
993 //! information for correctness.There are negative and positive tests.
994 //! @SYMTestActions If negative testing is enabled then following tests are done
995 //! 0 Call the API with invalid client Id (calling client Id).
996 //! 1 Call the API with invalid instance count of calling client Id.
997 //! 2 Call the API with invalid resource Id.
999 //! 3 Call the API with valid calling client Id and resource Id.
1001 //! @SYMTestExpectedResults 0 API should return with KErrAccessDenied, panics otherwise
1002 //! 1 API should return with KErrAccessDenied, panics otherwise
1003 //! 2 API should return with KErrNotFound, panics otherwise
1004 //! 3 API should return KErrNone with number of clients holding requirement on
1005 //! the requested resource updated and also is checked for correctness, panics otherwise
1006 //! @SYMTestPriority High
1007 //! @SYMTestStatus Implemented
1008 //----------------------------------------------------------------------------------------------
1009 void TestRM::GetNumClientsUsingResource(TUint aClientId, TUint aResId)
1011 TUint clientNum = 0;
1014 //Pass illegial client Id
1015 r = lddChan.GetNumClientsUsingResource(32, 1, clientNum);
1016 test(r == KErrAccessDenied);
1018 //Pass illegal instance count
1019 TUint id = Clients[aClientId].iClientId;
1021 r = lddChan.GetNumClientsUsingResource(id, 1, clientNum);
1022 test(r == KErrAccessDenied);
1024 //Invalid resource id
1025 r = lddChan.GetNumClientsUsingResource(Clients[aClientId].iClientId, iMaxStaticResources+40, clientNum);
1026 test(r == KErrNotFound);
1028 if((TInt)aResId == -1)
1029 r = lddChan.GetNumClientsUsingResource(Clients[aClientId].iClientId, 0, clientNum);
1031 r = lddChan.GetNumClientsUsingResource(Clients[aClientId].iClientId, Resources[aResId].iResourceId, clientNum);
1033 test.Printf(_L("GetNumClientsUsingResource for client 0x%x failed with %d"), Clients[aClientId].iClientId, r);
1035 if((TInt)aResId == -1)
1037 if(clientNum != (TUint)(Clients.Count() + 1))
1038 test.Printf(_L("ClientNum = %d, Expected clientNum = %d"), clientNum, Clients.Count()+1);
1039 test(clientNum == (TUint)(Clients.Count() + 1));
1043 test(Resources[aResId].iNumClients == clientNum);
1044 if(!Resources[aResId].iUsage && clientNum > 1) //Single user resource cannot have more that one client
1049 //----------------------------------------------------------------------------------------------
1050 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0582
1052 //! @SYMPREQ PREQ1398
1053 //! @SYMTestCaseDesc This test case tests retrieval of information about clients holding requirement on
1054 //! the passed resource functionality of resource manager and compares with stored information
1055 //! for correctness.There are negative and positive tests.
1056 //! @SYMTestActions If negative testing is enabled then following tests are done
1057 //! 0 Call the API with invalid client Id (calling client Id).
1058 //! 1 Call the API with invalid instance count of calling client Id.
1059 //! 2 Call the API with invalid resource Id.
1060 //! 3 Call the API with null buffer (buffer where the resource information will be updated).
1061 //! 4 Call the API with the number of resource information to be updated as 0 (specifies the
1062 //! size of the buffer).
1064 //! 5 Call the API with valid calling and target client Id, buffer and its size.
1066 //! @SYMTestExpectedResults 0 API should return with KErrAccessDenied, panics otherwise
1067 //! 1 API should return with KErrAccessDenied, panics otherwise
1068 //! 2 API should return with KErrNotFound, panics otherwise
1069 //! 3 API should return with KErrArgument, panics otherwise
1070 //! 4 API should return with KErrArgument, panics otherwise
1071 //! 5 API should return KErrNone with resource information about clients holding requirement
1072 //! on the passed resource and also is checked for correctness, panics otherwise
1073 //! @SYMTestPriority High
1074 //! @SYMTestStatus Implemented
1075 //----------------------------------------------------------------------------------------------
1076 void TestRM::GetInfoOnClientsUsingResource(TUint aResId, TUint aNumCli)
1079 info.Create(aNumCli * sizeof(TPowerClientInfoV01));
1082 //Pass illegial client Id
1083 r = lddChan.GetInfoOnClientsUsingResource(2, 1, aNumCli, (TAny*)(TDes8*)&info);
1084 test(r == KErrAccessDenied);
1086 //Pass illegal instance count
1087 TUint id = Clients[iCurrentClientId].iClientId;
1089 r = lddChan.GetInfoOnClientsUsingResource(id, 1, aNumCli, (TAny*)(TDes8*)&info);
1090 test(r == KErrAccessDenied);
1092 //Invalid resource id
1093 r = lddChan.GetInfoOnClientsUsingResource(Clients[iCurrentClientId].iClientId, iMaxStaticResources+40, aNumCli, (TAny*)(TDes8*)&info);
1094 test(r == KErrNotFound);
1097 r = lddChan.GetInfoOnClientsUsingResource(Clients[iCurrentClientId].iClientId, 1 ,aNumCli, (TAny*)NULL);
1098 test(r == KErrArgument);
1100 //Pass required resources as 0
1102 r = lddChan.GetInfoOnClientsUsingResource(Clients[iCurrentClientId].iClientId, 1 ,tempCli, (TAny*)(TDes8*)&info);
1103 test(r == KErrArgument);
1105 if((TInt)aResId == -1)
1106 r = lddChan.GetInfoOnClientsUsingResource(Clients[iCurrentClientId].iClientId, 0, aNumCli, (TAny*)(TDes8*)&info);
1108 r = lddChan.GetInfoOnClientsUsingResource(Clients[iCurrentClientId].iClientId, Resources[aResId].iResourceId, aNumCli, (TAny*)(TDes8*)&info);
1109 if(r == KErrArgument)
1112 test(Resources[aResId].iNumClients == 0);
1116 test(r == KErrNone);
1117 TPowerClientInfoV01 *ptr = (TPowerClientInfoV01*)info.Ptr();
1118 if((TInt)aResId == -1)
1120 test(aNumCli == (TUint)(Clients.Count() + 1));
1122 for(TUint count = 0; count < aNumCli; count++)
1124 //Skip comparision of first client as that will be PowerController.
1125 if(ptr->iClientId == iPowerControllerId)
1130 for(c = 0; c< iMaxClients; c++)
1132 if(ptr->iClientId == Clients[c].iClientId)
1135 if(c == iMaxClients)
1142 if(aNumCli != Resources[aResId].iNumClients)
1143 test.Printf(_L("aNumCli = %d, Expected numClients = %d\n"), aNumCli, Resources[aResId].iNumClients);
1144 test(aNumCli == Resources[aResId].iNumClients);
1146 SPowerResourceClientLevel *level = Resources[aResId].iLevel;
1148 for(TUint count = 0; count < aNumCli; count++)
1150 SPowerResourceClientLevel *pL = Resources[aResId].iLevel;
1151 for(c =0;c<aNumCli;c++)
1153 if(Clients[pL->iClientId].iClientId == ptr->iClientId)
1155 pL = pL->iNextInList;
1159 test.Printf(_L("Client Id %d is not in the resource clientlevel list\n"), Clients[level->iClientId].iClientId);
1162 level = level->iNextInList;
1169 //----------------------------------------------------------------------------------------------
1170 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0583
1172 //! @SYMPREQ PREQ1398
1173 //! @SYMTestCaseDesc This test case tests preallocation of memory for resource manager internal
1174 //! structure.There are negative and positive tests.
1175 //! @SYMTestActions If negative testing is enabled then following tests are done
1176 //! 0 Call the API with invalid client Id
1177 //! 1 Call the API with invalid instance count of client Id.
1179 //! 2 Call the API with valid client Id.
1181 //! @SYMTestExpectedResults 0 API should return with KErrAccessDenied, panics otherwise
1182 //! 1 API should return with KErrAccessDenied, panics otherwise
1183 //! 2 API should return with KErrNone, panic otherwise. Really cannot
1184 //! test this for correctness.
1185 //! @SYMTestPriority High
1186 //! @SYMTestStatus Implemented
1187 //----------------------------------------------------------------------------------------------
1188 void TestRM::AllocReserve(TUint aClientId)
1192 //Pass illegial client Id
1193 r = lddChan.AllocReserve(11, 0, 3);
1194 test(r == KErrAccessDenied);
1196 //Pass illegal instance count
1197 TUint id = Clients[aClientId].iClientId;
1199 r = lddChan.AllocReserve(id, 0, 0);
1200 test(r == KErrAccessDenied);
1203 r = lddChan.AllocReserve(Clients[iCurrentClientId].iClientId, 1, 0);
1205 test.Printf(_L("Alloc Reserve failed with %d"), r);
1206 test(r == KErrNone);
1209 //This function validates the conditional and unconditional notification for the
1210 //specified resource state change.
1211 void TestRM::CheckNotification(TUint aResId, TInt newState)
1213 if(newState == Resources[aResId].iCurrentLevel)
1215 //Return if the newState is in decreasing order with respect to sense.
1216 if(Resources[aResId].iUsage == EShared && Resources[aResId].iCurrentClient != -1)
1218 if(Resources[aResId].iSense == EPositive)
1220 if(newState <= Resources[aResId].iCurrentLevel && Resources[aResId].iCurrentClient != iCurrentClientId)
1225 if(newState >= Resources[aResId].iCurrentLevel && Resources[aResId].iCurrentClient != iCurrentClientId)
1229 TUint notificationUnCon = Resources[aResId].iUnCondNotiCount;
1230 TUint notificationCon =0;
1231 for(NotiInfo* info = Resources[aResId].iCondNoti; info != NULL; info = info->iNext)
1233 if((info->iDirection && (info->iPreviousLevel < info->iThreshold) && (newState >= info->iThreshold)) ||
1234 (!info->iDirection && (info->iPreviousLevel > info->iThreshold) && (newState <= info->iThreshold)))
1236 info->iPreviousLevel = newState;
1238 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, notificationUnCon, notificationCon);
1240 test.Printf(_L("Check Notifications failed with %d"), r);
1241 test(r == KErrNone);
1244 //This function updates the client level.This will be used by other functions for validation.
1245 void TestRM::AddClientLevel(TUint aResId, TInt newState)
1247 SPowerResourceClientLevel *pCL = NULL;
1248 if(Resources[aResId].iUsage == EShared)
1250 for(pCL = Resources[aResId].iLevel;pCL != NULL; pCL = pCL->iNextInList)
1252 if((TInt)pCL->iClientId == iCurrentClientId)
1254 pCL->iLevel = newState;
1258 pCL = new SPowerResourceClientLevel;
1260 pCL->iClientId = iCurrentClientId;
1261 pCL->iResourceId = Resources[aResId].iResourceId;
1262 pCL->iLevel = newState;
1263 LIST_PUSH(Resources[aResId].iLevel, pCL, iNextInList);
1264 Resources[aResId].iNumClients++;
1268 if(Resources[aResId].iCurrentClient == -1)
1270 pCL = new SPowerResourceClientLevel;
1272 pCL->iClientId = iCurrentClientId;
1273 pCL->iResourceId = Resources[aResId].iResourceId;
1274 pCL->iLevel = newState;
1275 LIST_PUSH(Resources[aResId].iLevel, pCL, iNextInList);
1276 Resources[aResId].iNumClients++;
1280 SPowerResourceClientLevel* pCL = Resources[aResId].iLevel;
1281 pCL->iLevel = newState;
1286 //This function updates the current level and client information in corresponding resource array.
1287 void TestRM::UpdateClientInformation(TUint aResId, TInt aNewState)
1289 if(Resources[aResId].iCurrentClient == -1)
1291 Resources[aResId].iCurrentLevel = aNewState;
1292 Resources[aResId].iCurrentClient = iCurrentClientId;
1295 if(!Resources[aResId].iUsage)
1297 Resources[aResId].iCurrentLevel = aNewState;
1300 if(Resources[aResId].iSense == EPositive)
1302 if(aNewState > Resources[aResId].iCurrentLevel)
1304 Resources[aResId].iCurrentLevel = aNewState;
1305 Resources[aResId].iCurrentClient = iCurrentClientId;
1307 else if(Resources[aResId].iCurrentClient == iCurrentClientId)
1309 SPowerResourceClientLevel *pCL = NULL;
1310 for(pCL = Resources[aResId].iLevel;pCL != NULL; pCL = pCL->iNextInList)
1312 if(pCL->iLevel > aNewState)
1314 Resources[aResId].iCurrentLevel = pCL->iLevel;
1315 Resources[aResId].iCurrentClient = pCL->iClientId;
1319 Resources[aResId].iCurrentLevel = aNewState;
1320 Resources[aResId].iCurrentClient = iCurrentClientId;
1324 if(Resources[aResId].iSense == ENegative)
1326 if(aNewState < Resources[aResId].iCurrentLevel)
1328 Resources[aResId].iCurrentLevel = aNewState;
1329 Resources[aResId].iCurrentClient = iCurrentClientId;
1331 else if(Resources[aResId].iCurrentClient == iCurrentClientId)
1333 SPowerResourceClientLevel *pCL = NULL;
1334 for(pCL = Resources[aResId].iLevel;pCL != NULL; pCL = pCL->iNextInList)
1336 if(pCL->iLevel < aNewState)
1338 Resources[aResId].iCurrentLevel = pCL->iLevel;
1339 Resources[aResId].iCurrentClient = pCL->iClientId;
1343 Resources[aResId].iCurrentLevel = aNewState;
1344 Resources[aResId].iCurrentClient = iCurrentClientId;
1350 //----------------------------------------------------------------------------------------------
1351 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0584
1353 //! @SYMPREQ PREQ1398
1354 //! @SYMTestCaseDesc This test case tests change resource state functionality of resource manager
1355 //! by changing the state of the resource to random value between resource minimum
1356 //! and maximum value synchronously.This function will add the client level if required
1357 //! and update resource information and will check notification for correctness.There are
1358 //! postive and negative tests.
1359 //! @SYMTestActions If negative testing is enabled then following tests are done
1360 //! 0 Call the API with invalid client Id
1361 //! 1 Call the API with invalid instance count of client Id.
1362 //! 2 Call the API with invalid resource Id
1364 //! 3 Call the API with valid client and resource Id.
1366 //! @SYMTestExpectedResults 0 API should return with KErrAccessDenied, panics otherwise
1367 //! 1 API should return with KErrAccessDenied, panics otherwise
1368 //! 2 API should return with KErrNotFound, panic otherwise.
1369 //! 3 API should return with KErrNone, panic otherwise.
1370 //! This also checks for notifications revceived as a result of this
1371 //! resource change and checks for correctness.
1372 //! @SYMTestPriority High
1373 //! @SYMTestStatus Implemented
1374 //----------------------------------------------------------------------------------------------
1375 void TestRM::ChangeResourceStateSync(TUint aResId)
1380 //Pass illegial client Id
1381 r = lddChan.ChangeResourceStateSync(434224, Resources[aResId].iResourceId, newState);
1382 test(r == KErrAccessDenied);
1384 //Pass illegal instance count
1385 TUint id = Clients[iCurrentClientId].iClientId;
1387 r = lddChan.ChangeResourceStateSync(id, Resources[aResId].iResourceId, newState);
1388 test(r == KErrAccessDenied);
1390 //Invalid resource id
1391 r = lddChan.ChangeResourceStateSync(Clients[iCurrentClientId].iClientId, iMaxStaticResources+40, newState);
1392 test(r == KErrNotFound);
1394 r = lddChan.ChangeResourceStateSync(Clients[iCurrentClientId].iClientId, 26, newState);
1395 test(r == KErrNotFound);
1397 TInt maxLevel = Resources[aResId].iMaxLevel;
1398 TInt minLevel = Resources[aResId].iNumClients? Resources[aResId].iCurrentLevel : Resources[aResId].iMinLevel;
1399 //Toggle current state for binary resources
1400 if(!Resources[aResId].iType)
1401 newState = !Resources[aResId].iCurrentLevel;
1402 else if (Resources[aResId].iType == EMultiLevel)
1404 TInt diff = Abs(maxLevel - minLevel);
1405 if(Resources[aResId].iSense == EPositive)
1407 if(minLevel == maxLevel)
1408 newState = maxLevel - Math::Random() % diff;
1410 newState = minLevel + Math::Random() % diff;
1414 if(minLevel == maxLevel)
1415 newState = maxLevel + Math::Random() % diff;
1417 newState = minLevel - Math::Random() % diff;
1420 TInt reqState = newState;
1421 r = lddChan.ChangeResourceStateSync(Clients[iCurrentClientId].iClientId, Resources[aResId].iResourceId, newState);
1422 if(r == KErrAccessDenied)
1425 test.Printf(_L("Synchronous resource change returned with %d"), r);
1426 test(r == KErrNone);
1427 if(newState != reqState)
1428 test.Printf(_L("NewState = %d, Expected state = %d"), newState, reqState);
1429 if(!Resources[aResId].iUsage)
1430 test(newState == reqState);
1431 CheckNotification(aResId, reqState);
1432 AddClientLevel(aResId, reqState);
1433 UpdateClientInformation(aResId, reqState);
1435 for(c = 0; c< Clients[iCurrentClientId].iNumResources; c++)
1437 if(Clients[iCurrentClientId].iResourceIds[c] == Resources[aResId].iResourceId)
1440 Clients[iCurrentClientId].iResourceIds[c] = Resources[aResId].iResourceId;
1441 Clients[iCurrentClientId].iNumResources++;
1445 //----------------------------------------------------------------------------------------------
1446 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0585
1448 //! @SYMPREQ PREQ1398
1449 //! @SYMTestCaseDesc This test case tests change resource state functionality of resource manager
1450 //! by changing the state of the resource to random value between resource minimum
1451 //! and maximum value asynchronously.This function will add the client level if required
1452 //! and update resource information and will check notification for correctness.This
1453 //! also tests the cancellation of asynchronous function by immediately cancelling the
1454 //! operation after requesting resource state change. This is taken care in the driver.
1455 //! There are postive and negative tests.
1456 //! @SYMTestActions If negative testing is enabled then following tests are done
1457 //! 0 Call the API with invalid client Id
1458 //! 1 Call the API with invalid instance count of client Id.
1459 //! 2 Call the API with invalid resource Id
1461 //! 3 Call the API with valid client and resource Id.
1463 //! @SYMTestExpectedResults 0 API should return with KErrAccessDenied, panics otherwise
1464 //! 1 API should return with KErrAccessDenied, panics otherwise
1465 //! 2 API should return with KErrNotFound, panic otherwise.
1466 //! 3 API should return with KErrNone or if cancellation of this
1467 //! API is tested then will return with KErrCancel, panic otherwise.
1468 //! This also checks for notifications received as a result of this
1469 //! resource change and checks for correctness.
1470 //! @SYMTestPriority High
1471 //! @SYMTestStatus Implemented
1472 //----------------------------------------------------------------------------------------------
1473 void TestRM::ChangeResourceStateAsync(TUint aResId, TBool aReqCancel)
1475 TRequestStatus resChange;
1479 //Pass illegial client Id
1480 lddChan.ChangeResourceStateAsync(434224, Resources[aResId].iResourceId, newState, resChange);
1481 User::WaitForRequest(resChange);
1482 test(resChange.Int() == KErrAccessDenied);
1484 //Pass illegal instance count
1485 TUint id = Clients[iCurrentClientId].iClientId;
1487 lddChan.ChangeResourceStateAsync(id, Resources[aResId].iResourceId, newState, resChange);
1488 User::WaitForRequest(resChange);
1489 test(resChange.Int() == KErrAccessDenied);
1491 //Invalid resource id
1492 lddChan.ChangeResourceStateAsync(Clients[iCurrentClientId].iClientId, iMaxStaticResources+40, newState, resChange);
1493 User::WaitForRequest(resChange);
1494 test(resChange.Int() == KErrNotFound);
1496 lddChan.ChangeResourceStateAsync(Clients[iCurrentClientId].iClientId, 19, newState, resChange);
1497 User::WaitForRequest(resChange);
1498 test(resChange.Int() == KErrNotFound);
1500 TInt maxLevel = Resources[aResId].iMaxLevel;
1501 TInt minLevel = (Resources[aResId].iCurrentClient != -1)? Resources[aResId].iCurrentLevel : Resources[aResId].iMinLevel;
1502 //Check if the resource is positive
1503 if(!Resources[aResId].iType)
1504 newState = !Resources[aResId].iCurrentLevel;
1505 else if (Resources[aResId].iType == EMultiLevel)
1507 TInt diff = Abs(maxLevel - minLevel);
1509 diff = Abs(Resources[aResId].iMaxLevel - Resources[aResId].iMinLevel);
1510 if(Resources[aResId].iSense == EPositive)
1512 if(minLevel == maxLevel)
1513 newState = maxLevel - Math::Random() % diff;
1515 newState = minLevel + Math::Random() % diff;
1519 if(minLevel == maxLevel)
1520 newState = maxLevel + Math::Random() % diff;
1522 newState = minLevel - Math::Random() % diff;
1525 TInt reqState = newState;
1526 //Long latency resource
1527 lddChan.ChangeResourceStateAsync(Clients[iCurrentClientId].iClientId, Resources[aResId].iResourceId, newState, resChange, aReqCancel);
1528 User::WaitForRequest(resChange);
1529 if(aReqCancel && (resChange.Int() != KErrNone))
1531 test(resChange.Int() == KErrCancel || resChange.Int() == KErrCompletion);
1534 if(resChange.Int() == KErrAccessDenied)
1536 if(!Resources[aResId].iUsage)
1537 test(newState == reqState);
1538 CheckNotification(aResId, reqState);
1539 AddClientLevel(aResId, reqState);
1540 UpdateClientInformation(aResId, reqState);
1542 for(c = 0; c< Clients[iCurrentClientId].iNumResources; c++)
1544 if(Clients[iCurrentClientId].iResourceIds[c] == Resources[aResId].iResourceId)
1547 Clients[iCurrentClientId].iResourceIds[c] = Resources[aResId].iResourceId;
1548 Clients[iCurrentClientId].iNumResources++;
1552 //----------------------------------------------------------------------------------------------
1553 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0586
1555 //! @SYMPREQ PREQ1398
1556 //! @SYMTestCaseDesc This test case tests synchronous version of get resource state functionality of
1557 //! resource manager by getting the state of the resource checks for correctness.
1558 //! There are positive and negative tests.
1559 //! @SYMTestActions If negative testing is enabled then following tests are done
1560 //! 0 Call the API with invalid client Id
1561 //! 1 Call the API with invalid instance count of client Id.
1562 //! 2 Call the API with invalid resource Id
1564 //! 3 Call the API with valid client and resource Id.
1566 //! @SYMTestExpectedResults 0 API should return with KErrAccessDenied, panics otherwise
1567 //! 1 API should return with KErrAccessDenied, panics otherwise
1568 //! 2 API should return with KErrNotFound, panic otherwise.
1569 //! 3 API should return with KErrNone and also the state and Owner Id are checked
1570 //! for correctness, panic otherwise.
1571 //! @SYMTestPriority High
1572 //! @SYMTestStatus Implemented
1573 //----------------------------------------------------------------------------------------------
1574 void TestRM::GetResourceStateSync(TUint aResId)
1576 static TBool Cached;
1577 TInt state = 0, levelOwnerId = 0;
1580 //Pass illegial client Id
1581 r = lddChan.GetResourceStateSync(4342241, Resources[aResId].iResourceId, Cached, state, levelOwnerId);
1582 test(r == KErrAccessDenied);
1584 //Pass illegal instance count
1585 TUint id = Clients[iCurrentClientId].iClientId;
1587 r = lddChan.GetResourceStateSync(id, Resources[aResId].iResourceId, Cached, state, levelOwnerId);
1588 test(r == KErrAccessDenied);
1590 //Invalid resource id
1591 r = lddChan.GetResourceStateSync(Clients[iCurrentClientId].iClientId, iMaxStaticResources+40, Cached, state, levelOwnerId);
1592 test(r == KErrNotFound);
1594 r = lddChan.GetResourceStateSync(Clients[iCurrentClientId].iClientId, 20, Cached, state, levelOwnerId);
1595 test(r == KErrNotFound);
1597 r = lddChan.GetResourceStateSync(Clients[iCurrentClientId].iClientId, Resources[aResId].iResourceId, Cached, state, levelOwnerId);
1598 test(r == KErrNone);
1599 test(state == Resources[aResId].iCurrentLevel);
1600 if(Resources[aResId].iCurrentClient == -1)
1601 test(levelOwnerId == -1);
1602 else if (levelOwnerId != (TInt)Clients[Resources[aResId].iCurrentClient].iClientId)
1604 test.Printf(_L("Expected ClientId = 0x%x, Returned ClientId = 0x%x\n"), Resources[aResId].iCurrentClient, levelOwnerId);
1611 //----------------------------------------------------------------------------------------------
1612 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0587
1614 //! @SYMPREQ PREQ1398
1615 //! @SYMTestCaseDesc This test case tests get resource state functionality of resource manager
1616 //! by getting the state of the resource asynchronously and checking for correctness.
1617 //! This also tests the cancellation of asynchronous function by immediately cancelling the
1618 //! operation after requesting get resource state. This is taken care in the driver.
1619 //! There are positive and negative tests.
1620 //! @SYMTestActions If negative testing is enabled then following tests are done
1621 //! 0 Call the API with invalid client Id
1622 //! 1 Call the API with invalid instance count of client Id.
1623 //! 2 Call the API with invalid resource Id
1625 //! 3 Call the API with valid client and resource Id.
1627 //! @SYMTestExpectedResults 0 API should return with KErrAccessDenied, panics otherwise
1628 //! 1 API should return with KErrAccessDenied, panics otherwise
1629 //! 2 API should return with KErrNotFound, panic otherwise.
1630 //! 3 API should return with KErrNone or if cancellation of this
1631 //! API is tested then will return with KErrCancel, panic otherwise.
1632 //! This also checks the updated level and owner Id for correctness,
1633 //! panics otherwise.
1634 //! @SYMTestPriority High
1635 //! @SYMTestStatus Implemented
1636 //----------------------------------------------------------------------------------------------
1637 void TestRM::GetResourceStateAsync(TUint aResId, TBool aReqCancel)
1639 static TBool Cached;
1640 TRequestStatus resGet;
1641 TInt state, levelOwnerId;
1644 //Pass illegial client Id
1645 lddChan.GetResourceStateAsync(4342241, Resources[aResId].iResourceId, Cached, resGet, state, levelOwnerId);
1646 User::WaitForRequest(resGet);
1647 test(resGet.Int() == KErrAccessDenied);
1649 //Pass illegal instance count
1650 TUint id = Clients[iCurrentClientId].iClientId;
1652 lddChan.GetResourceStateAsync(id, Resources[aResId].iResourceId, Cached, resGet, state, levelOwnerId);
1653 User::WaitForRequest(resGet);
1654 test(resGet.Int() == KErrAccessDenied);
1656 //Invalid resource id
1657 lddChan.GetResourceStateAsync(Clients[iCurrentClientId].iClientId, iMaxStaticResources+48, Cached, resGet, state, levelOwnerId);
1658 User::WaitForRequest(resGet);
1659 test(resGet.Int() == KErrNotFound);
1661 lddChan.GetResourceStateAsync(Clients[iCurrentClientId].iClientId, 20, Cached, resGet, state, levelOwnerId);
1662 User::WaitForRequest(resGet);
1663 test(resGet.Int() == KErrNotFound);
1665 lddChan.GetResourceStateAsync(Clients[iCurrentClientId].iClientId, Resources[aResId].iResourceId, Cached, resGet, state, levelOwnerId, aReqCancel);
1666 User::WaitForRequest(resGet);
1667 if(aReqCancel && (resGet.Int() != KErrNone))
1669 test(resGet.Int() == KErrCancel || resGet.Int() == KErrCompletion);
1672 test(state == Resources[aResId].iCurrentLevel);
1673 if(Resources[aResId].iCurrentClient == -1)
1674 test(levelOwnerId == -1);
1675 else if (levelOwnerId != (TInt)Clients[Resources[aResId].iCurrentClient].iClientId)
1677 test.Printf(_L("Expected ClientId = 0x%x, Returned ClientId = 0x%x\n"), Resources[aResId].iCurrentClient, levelOwnerId);
1683 //----------------------------------------------------------------------------------------------
1684 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0588
1686 //! @SYMPREQ PREQ1398
1687 //! @SYMTestCaseDesc This test case tests unconditional notification request functionality of resource manager.
1688 //! @SYMTestActions Call the API with valid client and resource Id.
1690 //! @SYMTestExpectedResults API should return with KErrNone, panics otherwise.
1691 //! @SYMTestPriority High
1692 //! @SYMTestStatus Implemented
1693 //----------------------------------------------------------------------------------------------
1694 void TestRM::RequestNotification(TUint aResId)
1696 //If unconditional notification is already queued for this client then dont request another one.
1697 for(NotiInfo *pN = Resources[aResId].iUncondNoti; pN != NULL; pN = pN->iNext)
1699 if((TInt)pN->iClientId == iCurrentClientId)
1702 r = lddChan.RequestNotification(Clients[iCurrentClientId].iClientId, Resources[aResId].iResourceId);
1704 test.Printf(_L("Request Notification returned with %d"), r);
1705 test(r == KErrNone);
1706 //Add to resource list
1707 NotiInfo *info = new NotiInfo;
1709 info->iClientId = iCurrentClientId;
1710 LIST_PUSH(Resources[aResId].iUncondNoti, info, iNext);
1711 Resources[aResId].iUnCondNotiCount++;
1714 //----------------------------------------------------------------------------------------------
1715 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0589
1717 //! @SYMPREQ PREQ1398
1718 //! @SYMTestCaseDesc This test case tests conditional notification request functionality of resource manager.
1719 //! Threshold and direction are chosen randomly for each resource based on the resource information.
1720 //! @SYMTestActions Call the API with valid client and resource Id.
1722 //! @SYMTestExpectedResults API should return with KErrNone, panics otherwise.
1723 //! @SYMTestPriority High
1724 //! @SYMTestStatus Implemented
1725 //----------------------------------------------------------------------------------------------
1726 void TestRM::RequestNotificationCon(TUint aResId)
1728 //Allow only one notification per client.
1729 static TBool direction;
1730 TInt threshold = direction;
1731 for(NotiInfo *pN = Resources[aResId].iCondNoti; pN != NULL; pN = pN->iNext)
1733 if((TInt)pN->iClientId == iCurrentClientId)
1736 if(Resources[aResId].iType)
1738 if(Resources[aResId].iSense == EPositive)
1740 threshold = Math::Random() % Resources[aResId].iMaxLevel;
1741 if(threshold < Resources[aResId].iMinLevel)
1742 threshold += Resources[aResId].iMinLevel;
1744 else if(Resources[aResId].iSense == ENegative)
1746 threshold = Math::Random() % Resources[aResId].iMinLevel;
1747 if(threshold < Resources[aResId].iMaxLevel)
1748 threshold += Resources[aResId].iMaxLevel;
1751 r = lddChan.RequestNotification(Clients[iCurrentClientId].iClientId, Resources[aResId].iResourceId, direction, threshold);
1753 test.Printf(_L("Request Notification returned with %d for direction = %d, threshold = %d"), r, direction, threshold);
1754 test(r == KErrNone);
1755 NotiInfo *info = new NotiInfo;
1757 info->iClientId = iCurrentClientId;
1758 info->iThreshold = threshold;
1759 info->iDirection = direction;
1760 info->iPreviousLevel = Resources[aResId].iCurrentLevel;
1761 LIST_PUSH(Resources[aResId].iCondNoti, info, iNext);
1762 direction = !direction;
1765 //----------------------------------------------------------------------------------------------
1766 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0590
1768 //! @SYMPREQ PREQ1398
1769 //! @SYMTestCaseDesc This test case tests cancellation of notification functionality of resource manager.
1770 //! @SYMTestActions Call the API with valid client and resource Id.
1772 //! @SYMTestExpectedResults API should return with KErrCancel, panics otherwise.
1773 //! @SYMTestPriority High
1774 //! @SYMTestStatus Implemented
1775 //----------------------------------------------------------------------------------------------
1776 void TestRM::CancelNotification(TUint aResId, TBool Cond)
1778 RMResInfo *pR = &Resources[aResId];
1779 TBool found = EFalse;
1782 //Remove any conditional notification this client has on resource.
1783 for(NotiInfo* pI = pR->iCondNoti; pI != NULL; pI = pI->iNext)
1785 if((TInt)pI->iClientId == iCurrentClientId)
1787 LIST_REMOVE(pR->iCondNoti, pI, iNext, NotiInfo);
1796 //Remove any unconditional notification this client has on resource.
1797 for(NotiInfo* pI = pR->iUncondNoti; pI != NULL; pI = pI->iNext)
1799 if((TInt)pI->iClientId == iCurrentClientId)
1801 LIST_REMOVE(pR->iUncondNoti, pI, iNext, NotiInfo);
1802 pR->iUnCondNotiCount--;
1811 r = lddChan.CancelNotification(Clients[iCurrentClientId].iClientId, Resources[aResId].iResourceId, Cond);
1813 test.Printf(_L("CancelNotification Clients %d, return value = %d"), iCurrentClientId, r);
1814 test(r == KErrCancel);
1818 //----------------------------------------------------------------------------------------------
1819 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0591
1821 //! @SYMPREQ PREQ1398
1822 //! @SYMTestCaseDesc This test case tests client registration and deregistration API of resource manager.
1823 //! There are positive and negative tests.
1824 //! @SYMTestActions 0 Call the client registration API with valid client name to register
1825 //! 1 Call the client name updation API with valid client Id to get the client name
1826 //! 2 Call the client name updation API with invalid client id.
1827 //! 3 Call the client registration API with client name greater than maximum
1828 //! allowable name length (32 characters)
1829 //! 4 Call the client deregistration API by passing invalid client Id.
1830 //! 5 Call the client deregistration API by passing invalid instance count.
1831 //! 6 Call the client deregistration API by passing valid client Id.
1833 //! @SYMTestExpectedResults 0 API should return with KErrNone, panics otherwise.
1834 //! 1 API should return with KErrNone and updated name is checked for
1835 //! correctness, panics otherwise.
1836 //! 2 API should return with KErrAccessDenied, panics otherwise.
1837 //! 3 API should return with KErrTooBig, panics otherwise.
1838 //! 4 API should return with KErrNotFound, panics otherwise.
1839 //! 5 API should return with KErrNotFound, panics otherwise.
1840 //! 6 API should return with KErrNone, panics otherwise.
1841 //! @SYMTestPriority High
1842 //! @SYMTestStatus Implemented
1843 //----------------------------------------------------------------------------------------------
1844 void TestRM::ValidateClient(TUint aNumClients, TOwnerType aContext)
1847 TBuf8<32> ClientName;
1849 ClientName.Append(_L8("Clients?"));
1850 TUint clientId[MAX_CLIENTS];
1851 if(aNumClients > MAX_CLIENTS)
1854 for(c = 0; c < aNumClients; c++)
1856 ClientName[7] = (TUint8)('0' + c);
1857 r = lddChan.RegisterClient(clientId[c], (const TDesC*)&ClientName, aContext);
1860 test.Printf(_L("Client registration failed with %d"), r);
1868 for(c = 0; c < aNumClients; c++)
1870 ClientName[7] = (TUint8)('0' + c);
1871 r = lddChan.GetClientName(clientId[c], clientId[c], (TDes8*)&aName);
1874 test.Printf(_L("GetClientName API failed with error %d"), r);
1877 r = aName.Compare(ClientName);
1880 test.Printf(_L("Client Name is not as expected"));
1885 ClientName[7] = (TUint8)('0' + aNumClients+1);
1886 r = lddChan.GetClientName(aNumClients, clientId[0], &aName);
1887 if(r != KErrAccessDenied)
1889 test.Printf(_L("RM allows illegal clients"));
1896 name.Append(_L8("RegisteringClientNameGreaterThan32Characters"));
1898 r = lddChan.RegisterClient(id, (const TDesC*)&name, aContext);
1901 test.Printf(_L("RM allows big names !!!"));
1904 test.Printf(_L("Client Deregistration"));
1905 //Deregistration of non-existing client
1907 r = lddChan.DeRegisterClient(id);
1908 if(r != KErrNotFound)
1910 test.Printf(_L("RM allows invalid client ID deregistration!!!"));
1914 //Get client Name by passing invalid client Id (changing a bit in instance count)
1915 id = clientId[0] ^ (1<<16);
1916 r = lddChan.DeRegisterClient(id);
1917 if(r != KErrNotFound)
1919 test.Printf(_L("RM allows invalid client ID deregistation!!!"));
1923 //Deregister the client registered at the start of this function
1924 for(c = 0; c < aNumClients; c++)
1926 r = lddChan.DeRegisterClient(clientId[c]);
1929 test.Printf(_L("Deregistration of client id 0x%x failed"), clientId[c]);
1936 #ifdef PRM_ENABLE_EXTENDED_VERSION
1937 //----------------------------------------------------------------------------------------------
1938 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0597
1940 //! @SYMPREQ PREQ1398
1941 //! @SYMTestCaseDesc This test case tests dynamic resources with dependency.
1942 //! @SYMTestActions 0 Register clients
1943 //! 1 Register dynamic resource with dependency
1944 //! 2 Establish dependency between resources
1945 //! 3 Register notifications
1946 //! 4 Check dependency information for correctness
1947 //! 5 Change Resource State of each resource
1948 //! 6 Get state of the resources and verify them for correctness
1949 //! 7 Check notification count for correctness
1950 //! 8 Deregister dependency between resources
1951 //! 9 Deregister client level
1952 //! 10 Deregister dynamic resource with dependency
1953 //! 11 Deregister clients
1955 //! @SYMTestExpectedResults 0 API should return with KErrNone, panics otherwise.
1956 //! 1 API should return with KErrNone, panics otherwise.
1957 //! 2 API should return with KErrNone, panics otherwise.
1958 //! 3 API should return with KErrNone, panics otherwise.
1959 //! 4 API should return with KErrNone, panics otherwise.
1960 //! 5 API should return with KErrNone, panics otherwise.
1961 //! 6 API should return with KErrNone, panics otherwise.
1962 //! 7 API should return with KErrNone, panics otherwise.
1963 //! 8 API should return with KErrNone, panics otherwise.
1964 //! 9 API should return with KErrNone, panics otherwise.
1965 //! 10 API should return with KErrNone, panics otherwise.
1966 //! 11 API should return with KErrNone, panics otherwise.
1967 //! @SYMTestPriority High
1968 //! @SYMTestStatus Implemented
1969 //----------------------------------------------------------------------------------------------
1970 /*This tests dynamic dependency resource. It also creates a dependency between static resource.
1971 Below is the dependency tree
1972 ResourceA <----------------> ResourceD <------------->ResourceE <--------------> ResourceC
1979 ResourceF ResourceG <-------------> Resource H <------->Resource I
1980 ¦ (Dynamic) (Dynamic)
1984 Resource J <-------->Resource K
1987 void TestRM::TestDynamicResourceDependency()
1991 SResourceDependencyInfo info1, info2;
1992 SResourceDependencyInfo sResDepInfo;
1993 RArray<SResourceDependencyInfo>depResArray;
1995 TUint dynamicDepResId[4];
1997 test.Next(_L("Testing Dynamic + static resource dependency"));
1998 RmTest.RegisterClient(); /* Register Client 1 */
2000 //Register dependency resource
2001 dynamicDepResId[0] = 5;
2002 r = lddChan.RegisterDynamicResource(Clients[0].iClientId, dynamicDepResId[0]);
2003 test(r == KErrNone);
2005 info1.iResourceId = iStaticDependencyResources[5];
2006 info1.iDependencyPriority = 3;
2008 info2.iResourceId = dynamicDepResId[0];
2009 info2.iDependencyPriority = 2;
2011 r = lddChan.RegisterResourceDependency(Clients[0].iClientId, info1, info2);
2012 test(r == KErrNone);
2014 //Check for correctness of dependency resource information
2015 sResDepInfo.iResourceId = iStaticDependencyResources[3];
2016 sResDepInfo.iDependencyPriority = 1;
2017 depResArray.Append(sResDepInfo);
2018 sResDepInfo.iResourceId = dynamicDepResId[0];
2019 sResDepInfo.iDependencyPriority = 2;
2020 depResArray.Append(sResDepInfo);
2021 RmTest.CheckForDependencyInformation(Clients[0].iClientId, iStaticDependencyResources[5], 2, &depResArray[0]);
2023 depResArray[0].iResourceId = iStaticDependencyResources[5];
2024 depResArray[0].iDependencyPriority = 3;
2025 RmTest.CheckForDependencyInformation(Clients[0].iClientId, dynamicDepResId[0], 1, &depResArray[0]);
2027 //Change Static dependency resource to -50
2028 RmTest.RegisterClient(); /* Register Client 2 */
2030 lddChan.ChangeResourceStateAsync(Clients[1].iClientId, iStaticDependencyResources[0], state, req);
2031 User::WaitForRequest(req);
2032 test(req.Int() == KErrNone);
2034 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[0], -50, Clients[1].iClientId, EFalse);
2035 GetExtendedResStateAndVerify(iStaticDependencyResources[1], -11, iStaticDependencyResources[0]);
2036 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[2], 1, iStaticDependencyResources[0], EFalse);
2037 GetExtendedResStateAndVerify(iStaticDependencyResources[3], 13, iStaticDependencyResources[0]);
2038 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 0, iStaticDependencyResources[3], EFalse);
2039 GetExtendedResStateAndVerify(iStaticDependencyResources[5], 73, iStaticDependencyResources[3]);
2040 GetExtendedResStateAndVerify(dynamicDepResId[0], 80, iStaticDependencyResources[5]);
2042 //Register dynamic dependency resource I
2043 dynamicDepResId[1] = 6;
2044 r = lddChan.RegisterDynamicResource(Clients[0].iClientId, dynamicDepResId[1]);
2045 test(r == KErrNone);
2047 //Register dynamic dependency resource J
2048 dynamicDepResId[2] = 7;
2049 r = lddChan.RegisterDynamicResource(Clients[0].iClientId, dynamicDepResId[2]);
2050 test(r == KErrNone);
2052 //Register dynamic dependency resource K
2053 dynamicDepResId[3] = 8;
2054 r = lddChan.RegisterDynamicResource(Clients[0].iClientId, dynamicDepResId[3]);
2055 test(r == KErrNone);
2057 RmTest.RegisterClient(); /* Register Client3 */
2058 RmTest.RegisterClient(); /* Register Client4 */
2060 //Register notifications
2061 r = lddChan.RequestNotification(Clients[1].iClientId, iStaticDependencyResources[5]);
2062 test(r == KErrNone);
2063 r = lddChan.RequestNotification(Clients[2].iClientId, dynamicDepResId[0]);
2064 test(r == KErrNone);
2065 r = lddChan.RequestNotification(Clients[1].iClientId, dynamicDepResId[1]);
2066 test(r == KErrNone);
2067 r = lddChan.RequestNotification(Clients[2].iClientId, dynamicDepResId[2]);
2068 test(r == KErrNone);
2069 r = lddChan.RequestNotification(Clients[1].iClientId, dynamicDepResId[3]);
2070 test(r == KErrNone);
2072 //Create depedency between H and I
2073 info1.iResourceId = dynamicDepResId[0];
2074 info1.iDependencyPriority = 1;
2076 info2.iResourceId = dynamicDepResId[1];
2077 info2.iDependencyPriority = 1;
2079 //Register dependency between resource H and I
2080 r = lddChan.RegisterResourceDependency(Clients[0].iClientId, info1, info2);
2081 test(r == KErrNone);
2082 //Validate dependency information
2083 depResArray[0].iResourceId = dynamicDepResId[1];
2084 depResArray[0].iDependencyPriority = 1;
2085 depResArray[1].iResourceId = iStaticDependencyResources[5];
2086 depResArray[1].iDependencyPriority = 3;
2087 RmTest.CheckForDependencyInformation(Clients[0].iClientId, dynamicDepResId[0], 2, &depResArray[0]);
2089 depResArray[0].iResourceId = dynamicDepResId[0];
2090 depResArray[0].iDependencyPriority = 1;
2091 RmTest.CheckForDependencyInformation(Clients[0].iClientId, dynamicDepResId[1], 1, &depResArray[0]);
2093 //Create depedency between H and J
2094 info1.iResourceId = dynamicDepResId[0];
2095 info1.iDependencyPriority = 1;
2097 info2.iResourceId = dynamicDepResId[2];
2098 info2.iDependencyPriority = 2;
2100 //Register dependency between resource H and J
2101 r = lddChan.RegisterResourceDependency(Clients[0].iClientId, info1, info2);
2102 test(r == KErrNone);
2104 depResArray[0].iResourceId = dynamicDepResId[1];
2105 depResArray[0].iDependencyPriority = 1;
2106 depResArray[1].iResourceId = dynamicDepResId[2];
2107 depResArray[1].iDependencyPriority = 2;
2108 sResDepInfo.iResourceId = iStaticDependencyResources[5];
2109 sResDepInfo.iDependencyPriority = 3;
2110 depResArray.Append(sResDepInfo);
2111 RmTest.CheckForDependencyInformation(Clients[0].iClientId, dynamicDepResId[0], 3, &depResArray[0]);
2113 depResArray[0].iResourceId = dynamicDepResId[0];
2114 depResArray[0].iDependencyPriority = 1;
2115 RmTest.CheckForDependencyInformation(Clients[0].iClientId, dynamicDepResId[2], 1, &depResArray[0]);
2117 // Check if the priority for a new dependency is already existing.
2118 //Create dependency between J and K
2119 info1.iResourceId = dynamicDepResId[2];
2120 info1.iDependencyPriority = 1;
2122 info2.iResourceId = dynamicDepResId[3];
2123 info2.iDependencyPriority = 1;
2125 //Register dependency between resource J and K
2126 r = lddChan.RegisterResourceDependency(Clients[0].iClientId, info1, info2);
2127 test(r == KErrAlreadyExists);
2129 //Create depedency between J and K
2130 info1.iResourceId = dynamicDepResId[2];
2131 info1.iDependencyPriority = 1;
2133 info2.iResourceId = dynamicDepResId[3];
2134 info2.iDependencyPriority = 2;
2136 //Register dependency between resource J and K
2137 r = lddChan.RegisterResourceDependency(Clients[0].iClientId, info1, info2);
2138 test(r == KErrNone);
2140 depResArray[0].iResourceId = dynamicDepResId[2];
2141 depResArray[0].iDependencyPriority = 1;
2142 RmTest.CheckForDependencyInformation(Clients[0].iClientId, dynamicDepResId[3], 1, &depResArray[0]);
2144 depResArray[0].iResourceId = dynamicDepResId[0];
2145 depResArray[0].iDependencyPriority = 1;
2146 depResArray[1].iResourceId = dynamicDepResId[3];
2147 depResArray[1].iDependencyPriority = 2;
2148 RmTest.CheckForDependencyInformation(Clients[0].iClientId, dynamicDepResId[2], 2, &depResArray[0]);
2150 RmTest.RegisterClient(); /* Client5 registration */
2152 r = lddChan.ChangeResourceStateSync(Clients[2].iClientId, dynamicDepResId[0], 85);
2153 test(r == KErrNone);
2155 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[0], -50, Clients[1].iClientId, EFalse);
2156 GetExtendedResStateAndVerify(iStaticDependencyResources[1], -11, iStaticDependencyResources[0]);
2157 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[2], 1, iStaticDependencyResources[0], EFalse);
2158 GetExtendedResStateAndVerify(iStaticDependencyResources[3], 13, iStaticDependencyResources[0]);
2159 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 0, iStaticDependencyResources[3], EFalse);
2160 GetExtendedResStateAndVerify(iStaticDependencyResources[5], 71, dynamicDepResId[0]);
2161 GetExtendedResStateAndVerify(dynamicDepResId[0], 85, Clients[2].iClientId);
2162 GetExtendedResStateAsyncAndVerify(dynamicDepResId[1], 1, dynamicDepResId[0]);
2163 GetExtendedResStateAsyncAndVerify(dynamicDepResId[2], 18, dynamicDepResId[0], EFalse);
2164 GetExtendedResStateAndVerify(dynamicDepResId[3], 1, dynamicDepResId[2]);
2166 //Check notifications
2167 r = lddChan.CheckNotifications(iStaticDependencyResources[5], 1, 0);
2168 test(r == KErrNone);
2169 r = lddChan.CheckNotifications(dynamicDepResId[0], 1, 0);
2170 test(r == KErrNone);
2171 r = lddChan.CheckNotifications(dynamicDepResId[1], 1, 0);
2172 test(r == KErrNone);
2173 r = lddChan.CheckNotifications(dynamicDepResId[2], 1, 0);
2174 test(r == KErrNone);
2178 lddChan.ChangeResourceStateAsync(Clients[2].iClientId, dynamicDepResId[3], state, req);
2179 User::WaitForRequest(req);
2180 test(req.Int() == KErrNone);
2182 GetExtendedResStateAsyncAndVerify(dynamicDepResId[2], 18, dynamicDepResId[0], EFalse);
2183 GetExtendedResStateAsyncAndVerify(dynamicDepResId[3], 1, Clients[2].iClientId, EFalse);
2185 //Check notifications
2186 r = lddChan.CheckNotifications(dynamicDepResId[2], 0, 0);
2187 test(r == KErrNone);
2188 r = lddChan.CheckNotifications(dynamicDepResId[3], 0, 0);
2189 test(r == KErrNone);
2192 r = lddChan.ChangeResourceStateSync(Clients[2].iClientId, dynamicDepResId[2],12);
2193 test(r == KErrNone);
2195 GetExtendedResStateAsyncAndVerify(dynamicDepResId[2], 12, Clients[2].iClientId, EFalse);
2197 //Check notifications
2198 r = lddChan.CheckNotifications(dynamicDepResId[0], 0, 0);
2199 test(r == KErrNone);
2200 r = lddChan.CheckNotifications(dynamicDepResId[2], 1, 0);
2201 test(r == KErrNone);
2202 r = lddChan.CheckNotifications(dynamicDepResId[3], 0, 0);
2203 test(r == KErrNone);
2206 TRequestStatus reqSet;
2208 lddChan.CheckParallelExecutionForChangeResState(Clients[2].iClientId,
2209 dynamicDepResId[0],state,
2211 User::WaitForRequest(reqSet);
2212 test(reqSet.Int() == KErrNone);
2214 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[0], -50, Clients[1].iClientId, EFalse);
2215 GetExtendedResStateAndVerify(iStaticDependencyResources[1], -11, iStaticDependencyResources[0]);
2216 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[2], 1, iStaticDependencyResources[0], EFalse);
2217 GetExtendedResStateAndVerify(iStaticDependencyResources[3], 13, iStaticDependencyResources[0]);
2218 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 0, iStaticDependencyResources[3], EFalse);
2219 GetExtendedResStateAndVerify(iStaticDependencyResources[5], 69, dynamicDepResId[0]);
2220 GetExtendedResStateAndVerify(dynamicDepResId[0], 90, Clients[2].iClientId);
2221 GetExtendedResStateAsyncAndVerify(dynamicDepResId[1], 1, dynamicDepResId[0]);
2222 GetExtendedResStateAsyncAndVerify(dynamicDepResId[2], 11, dynamicDepResId[0], EFalse);
2223 GetExtendedResStateAndVerify(dynamicDepResId[3], 1, Clients[2].iClientId);
2225 //Check notifications
2226 r = lddChan.CheckNotifications(iStaticDependencyResources[5], 1, 0);
2227 test(r == KErrNone);
2228 r = lddChan.CheckNotifications(dynamicDepResId[0], 1, 0);
2229 test(r == KErrNone);
2230 r = lddChan.CheckNotifications(dynamicDepResId[1], 0, 0);
2231 test(r == KErrNone);
2232 r = lddChan.CheckNotifications(dynamicDepResId[2], 1, 0);
2233 test(r == KErrNone);
2234 r = lddChan.CheckNotifications(dynamicDepResId[3], 0, 0);
2235 test(r == KErrNone);
2238 lddChan.ChangeResourceStateAsync(Clients[1].iClientId, dynamicDepResId[2], state, req);
2239 User::WaitForRequest(req);
2240 test(req.Int() == KErrNone);
2242 GetExtendedResStateAndVerify(dynamicDepResId[0], 90, Clients[2].iClientId);
2243 GetExtendedResStateAsyncAndVerify(dynamicDepResId[1], 1, dynamicDepResId[0]);
2244 GetExtendedResStateAsyncAndVerify(dynamicDepResId[2], 9, Clients[1].iClientId, EFalse);
2245 GetExtendedResStateAndVerify(dynamicDepResId[3], 1, Clients[2].iClientId);
2247 //Check notifications
2248 r = lddChan.CheckNotifications(dynamicDepResId[0], 0, 0);
2249 test(r == KErrNone);
2250 r = lddChan.CheckNotifications(dynamicDepResId[1], 0, 0);
2251 test(r == KErrNone);
2252 r = lddChan.CheckNotifications(dynamicDepResId[2], 1, 0);
2253 test(r == KErrNone);
2254 r = lddChan.CheckNotifications(dynamicDepResId[3], 0, 0);
2255 test(r == KErrNone);
2259 lddChan.ChangeResourceStateAsync(Clients[1].iClientId, iStaticDependencyResources[0], state, req);
2260 User::WaitForRequest(req);
2261 test(req.Int() == KErrNone);
2263 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[0], 50, Clients[1].iClientId, EFalse);
2264 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[1], -12, iStaticDependencyResources[0], EFalse);
2265 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[2], 1, iStaticDependencyResources[0], EFalse);
2266 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[3], 16, iStaticDependencyResources[0], EFalse);
2267 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 0, iStaticDependencyResources[3], EFalse);
2268 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[5], 67, iStaticDependencyResources[3], EFalse);
2269 GetExtendedResStateAndVerify(dynamicDepResId[0], 90, Clients[2].iClientId);
2270 GetExtendedResStateAsyncAndVerify(dynamicDepResId[1], 1, dynamicDepResId[0]);
2271 GetExtendedResStateAsyncAndVerify(dynamicDepResId[2], 9, Clients[1].iClientId, EFalse);
2272 GetExtendedResStateAndVerify(dynamicDepResId[3], 1, Clients[2].iClientId);
2274 //Check notifications
2275 r = lddChan.CheckNotifications(iStaticDependencyResources[5], 1, 0);
2276 test(r == KErrNone);
2277 //DeRegister dependency between J and K
2278 r = lddChan.DeRegisterResourceDependency(Clients[0].iClientId, dynamicDepResId[3], dynamicDepResId[2]);
2279 test(r == KErrNone);
2281 RmTest.CheckForDependencyInformation(Clients[0].iClientId, dynamicDepResId[3], 0, &depResArray[0]);
2283 depResArray[0].iResourceId = dynamicDepResId[0];
2284 depResArray[0].iDependencyPriority = 1;
2285 RmTest.CheckForDependencyInformation(Clients[0].iClientId, dynamicDepResId[2], 1, &depResArray[0]);
2288 r = lddChan.ChangeResourceStateSync(Clients[1].iClientId, dynamicDepResId[2], 13);
2289 test(r == KErrNone);
2291 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[0], 50, Clients[1].iClientId, EFalse);
2292 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[1], -12, iStaticDependencyResources[0], EFalse);
2293 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[2], 1, iStaticDependencyResources[0], EFalse);
2294 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[3], 16, iStaticDependencyResources[0], EFalse);
2295 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 0, iStaticDependencyResources[3], EFalse);
2296 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[5], 67, iStaticDependencyResources[3], EFalse);
2297 GetExtendedResStateAndVerify(dynamicDepResId[0], 90, Clients[2].iClientId);
2298 GetExtendedResStateAsyncAndVerify(dynamicDepResId[1], 1, dynamicDepResId[0]);
2299 GetExtendedResStateAsyncAndVerify(dynamicDepResId[2], 12, Clients[2].iClientId, EFalse);
2300 GetExtendedResStateAndVerify(dynamicDepResId[3], 1, Clients[2].iClientId);
2301 //Check notifications
2302 r = lddChan.CheckNotifications(dynamicDepResId[2], 1, 0);
2303 test(r == KErrNone);
2304 /* Remove client level from resource 7 */
2305 r = lddChan.DeRegisterClientLevelFromResource(Clients[2].iClientId, dynamicDepResId[3]);
2306 test(r == KErrNone);
2308 GetExtendedResStateAndVerify(dynamicDepResId[3], 0, -1);
2309 //Check notifications
2310 r = lddChan.CheckNotifications(dynamicDepResId[3], 1, 0);
2311 test(r == KErrNone);
2313 r = lddChan.DeRegisterDynamicResource(Clients[0].iClientId, dynamicDepResId[3], NULL);
2314 test(r == KErrNone);
2315 //Check notifications
2316 r = lddChan.CheckNotifications(dynamicDepResId[3], 1, 0);
2317 test(r == KErrNone);
2319 //Deregister dependency between H and J
2320 r = lddChan.DeRegisterResourceDependency(Clients[0].iClientId, dynamicDepResId[2], dynamicDepResId[0]);
2321 test(r == KErrNone);
2323 RmTest.CheckForDependencyInformation(Clients[0].iClientId, dynamicDepResId[2], 0, &depResArray[0]);
2325 depResArray[0].iResourceId = dynamicDepResId[1];
2326 depResArray[0].iDependencyPriority = 1;
2327 depResArray[1].iResourceId = iStaticDependencyResources[5];
2328 depResArray[1].iDependencyPriority = 3;
2329 RmTest.CheckForDependencyInformation(Clients[0].iClientId, dynamicDepResId[0], 2, &depResArray[0]);
2331 /* Remove client level from resource 7 */
2332 r = lddChan.DeRegisterClientLevelFromResource(Clients[1].iClientId, dynamicDepResId[2]);
2333 test(r == KErrNone);
2335 GetExtendedResStateAndVerify(dynamicDepResId[2], 12, Clients[2].iClientId);
2336 //Check notifications
2337 r = lddChan.CheckNotifications(dynamicDepResId[2], 0, 0);
2338 test(r == KErrNone);
2340 r = lddChan.DeRegisterClient(Clients[2].iClientId);
2341 test(r == KErrNone);
2343 GetExtendedResStateAsyncAndVerify(dynamicDepResId[2], 19, -1, EFalse);
2345 //Deregister dependency between G and H
2346 r = lddChan.DeRegisterResourceDependency(Clients[1].iClientId, iStaticDependencyResources[5], dynamicDepResId[0]);
2347 test(r == KErrNone);
2349 depResArray[0].iResourceId = dynamicDepResId[1];
2350 depResArray[0].iDependencyPriority = 1;
2351 RmTest.CheckForDependencyInformation(Clients[0].iClientId, dynamicDepResId[0], 1, &depResArray[0]);
2353 depResArray[0].iResourceId = iStaticDependencyResources[3];
2354 depResArray[0].iDependencyPriority = 1;
2355 RmTest.CheckForDependencyInformation(Clients[0].iClientId, iStaticDependencyResources[5], 1, &depResArray[0]);
2357 GetExtendedResStateAndVerify(dynamicDepResId[0], 75, -1);
2358 GetExtendedResStateAsyncAndVerify(dynamicDepResId[1], 0, dynamicDepResId[0]);
2359 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[5], 67, iStaticDependencyResources[3], EFalse);
2361 //Deregister dependency between I and H
2362 r = lddChan.DeRegisterResourceDependency(Clients[1].iClientId, dynamicDepResId[1], dynamicDepResId[0]);
2363 test(r == KErrNone);
2365 RmTest.CheckForDependencyInformation(Clients[0].iClientId, dynamicDepResId[0], 0, &depResArray[0]);
2367 RmTest.CheckForDependencyInformation(Clients[0].iClientId, dynamicDepResId[1], 0, &depResArray[0]);
2369 GetExtendedResStateAndVerify(dynamicDepResId[0], 75, -1);
2370 GetExtendedResStateAsyncAndVerify(dynamicDepResId[1], 0, -1);
2371 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[5], 67, iStaticDependencyResources[3], EFalse);
2372 //Check notifications
2373 r = lddChan.CheckNotifications(iStaticDependencyResources[5], 0, 0);
2374 test(r == KErrNone);
2375 r = lddChan.CheckNotifications(dynamicDepResId[1], 1, 0);
2376 test(r == KErrNone);
2378 r = lddChan.DeRegisterDynamicResource(Clients[0].iClientId, dynamicDepResId[2], NULL);
2379 test(r == KErrNone);
2380 r = lddChan.DeRegisterDynamicResource(Clients[0].iClientId, dynamicDepResId[1], NULL);
2381 test(r == KErrNone);
2382 //Check notifications
2383 r = lddChan.CheckNotifications(dynamicDepResId[1], 1, 0);
2384 test(r == KErrNone);
2385 r = lddChan.DeRegisterDynamicResource(Clients[0].iClientId, dynamicDepResId[0], NULL);
2386 test(r == KErrNone);
2387 r = lddChan.DeRegisterClient(Clients[1].iClientId);
2388 test(r == KErrNone);
2389 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[0], -100, -1, EFalse);
2390 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[1], -10, iStaticDependencyResources[0], EFalse);
2391 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[2], 0, iStaticDependencyResources[0], EFalse);
2392 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[3], 10, iStaticDependencyResources[0], EFalse);
2393 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 1, iStaticDependencyResources[3], EFalse);
2394 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[5], 75, iStaticDependencyResources[3], EFalse);
2395 r = lddChan.DeRegisterClient(Clients[3].iClientId);
2396 test(r == KErrNone);
2398 r = lddChan.DeRegisterClient(Clients[0].iClientId);
2399 test(r == KErrNone);
2401 r = lddChan.DeRegisterClient(Clients[4].iClientId);
2402 test(r == KErrNone);
2404 depResArray.Close();
2408 //----------------------------------------------------------------------------------------------
2409 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0596
2411 //! @SYMPREQ PREQ1398
2412 //! @SYMTestCaseDesc This test case tests dynamic resources which does not support dependency
2413 //! @SYMTestActions 0 Register clients
2414 //! 1 Register dynamic resource
2415 //! 2 Register notifications
2416 //! 3 Change Resource State of each static resource with dependency
2417 //! 4 Get state of the resource and check for correctness
2418 //! 5 Check notification count for correctness
2419 //! 6 Deregister client level
2420 //! 7 Deregister dynamic resource
2421 //! 8 Deregister clients
2423 //! @SYMTestExpectedResults 0 API should return with KErrNone, panics otherwise.
2424 //! 1 API should return with KErrNone, panics otherwise.
2425 //! 2 API should return with KErrNone, panics otherwise.
2426 //! 3 API should return with KErrNone, panics otherwise.
2427 //! 4 API should return with KErrNone, panics otherwise.
2428 //! 5 API should return with KErrNone, panics otherwise.
2429 //! 6 API should return with KErrNone, panics otherwise.
2430 //! 7 API should return with KErrNone, panics otherwise.
2431 //! 8 API should return with KErrNone, panics otherwise.
2432 //! @SYMTestPriority High
2433 //! @SYMTestStatus Implemented
2434 //----------------------------------------------------------------------------------------------
2435 void TestRM::TestDynamicResource()
2439 TUint dynamicResId[4];
2441 test.Next(_L("Testing dynamic resource"));
2443 RmTest.RegisterClient();
2445 RmTest.RegisterClient();
2447 RmTest.RegisterClient();
2449 NegativeTesting = EFalse;
2450 dynamicResId[0] = 1;
2451 //Register dynamic resource 1
2452 r = lddChan.RegisterDynamicResource(Clients[0].iClientId, dynamicResId[0]);
2453 test(r == KErrNone);
2454 //Deregister dynamic resource with different client id
2455 r = lddChan.DeRegisterDynamicResource(Clients[1].iClientId, dynamicResId[0], NULL);
2456 test(r == KErrAccessDenied);
2457 dynamicResId[1] = 2;
2458 //Register dynamic resource 2
2459 r = lddChan.RegisterDynamicResource(Clients[1].iClientId, dynamicResId[1]);
2460 test(r == KErrNone);
2461 RmTest.GetNumResourcesInUseByClient(iCurrentClientId);
2462 RmTest.GetInfoOnResourcesInUseByClient(iCurrentClientId, iMaxStaticResources);
2465 r = lddChan.GetNumClientsUsingResource(Clients[0].iClientId, dynamicResId[0], numClients);
2466 test(r == KErrNone);
2467 test(numClients == 0);
2469 r = lddChan.RequestNotification(Clients[1].iClientId, dynamicResId[0]);
2470 test(r == KErrNone);
2472 RmTest.RegisterClient();
2473 r = lddChan.RequestNotification(Clients[2].iClientId, dynamicResId[0], 1, 1);
2474 test(r == KErrNone);
2475 //Change state of dynamic resource 1 and verify
2477 lddChan.ChangeResourceStateAsync(Clients[0].iClientId, dynamicResId[0], state, req);
2478 User::WaitForRequest(req);
2479 test(req.Int() == KErrNone);
2481 r = lddChan.CheckNotifications(dynamicResId[0], 1, 1);
2482 test(r == KErrNone);
2484 GetExtendedResStateAsyncAndVerify(dynamicResId[0], 1, Clients[0].iClientId, EFalse);
2486 r = lddChan.GetNumClientsUsingResource(Clients[0].iClientId, dynamicResId[0], numClients);
2487 test(r == KErrNone);
2488 test(numClients == 1);
2489 //Change state of dynamic resource 1.
2490 r = lddChan.ChangeResourceStateSync(Clients[1].iClientId, dynamicResId[0], 0);
2491 test(r == KErrAccessDenied);
2492 //Deregister dynamic resource 1 and set the resource to 1.
2494 r = lddChan.DeRegisterDynamicResource(Clients[0].iClientId, dynamicResId[0], &state);
2495 test(r == KErrNone);
2497 r = lddChan.CheckNotifications(dynamicResId[0], 1, 1);
2498 test(r == KErrNone);
2500 r = lddChan.GetNumClientsUsingResource(Clients[0].iClientId, dynamicResId[0], numClients);
2501 test(r == KErrNotFound);
2503 RmTest.RegisterClient();
2505 GetExtendedResStateAndVerify(dynamicResId[1], -5, -1);
2507 r = lddChan.RequestNotification(Clients[1].iClientId, dynamicResId[1]);
2508 test(r == KErrNone);
2510 r = lddChan.RequestNotification(Clients[2].iClientId, dynamicResId[1], 0, -8);
2511 test(r == KErrNone);
2512 //Change state of dynamic resource 1 and verify
2514 lddChan.ChangeResourceStateAsync(Clients[2].iClientId, dynamicResId[1], state, req);
2515 User::WaitForRequest(req);
2516 test(req.Int() == KErrNone);
2518 r = lddChan.CheckNotifications(dynamicResId[1], 1, 0);
2519 test(r == KErrNone);
2521 GetExtendedResStateAndVerify(dynamicResId[1], -7, Clients[2].iClientId);
2523 RmTest.RegisterClient();
2525 RmTest.RegisterClient();
2526 //Change state of dynamic resource 2 and verify
2528 lddChan.ChangeResourceStateAsync(Clients[3].iClientId, dynamicResId[1], state, req);
2529 User::WaitForRequest(req);
2530 test(req.Int() == KErrNone);
2532 r = lddChan.CheckNotifications(dynamicResId[1], 1, 1);
2533 test(r == KErrNone);
2535 GetExtendedResStateAsyncAndVerify(dynamicResId[1], -9, Clients[3].iClientId, EFalse);
2536 //Change state of dynamic resource 1 and verify
2538 lddChan.ChangeResourceStateAsync(Clients[4].iClientId, dynamicResId[1], state, req);
2539 User::WaitForRequest(req);
2540 test(req.Int() == KErrNone);
2542 r = lddChan.CheckNotifications(dynamicResId[1], 1, 0);
2543 test(r == KErrNone);
2545 GetExtendedResStateAsyncAndVerify(dynamicResId[1], -10, Clients[4].iClientId, EFalse);
2547 lddChan.ChangeResourceStateSync(Clients[5].iClientId, dynamicResId[1], state);
2548 test(r == KErrNone);
2550 r = lddChan.CheckNotifications(dynamicResId[1], 0, 0);
2551 test(r == KErrNone);
2553 GetExtendedResStateAsyncAndVerify(dynamicResId[1], -10, Clients[4].iClientId, EFalse);
2554 //Change state of dynamic resource 1 and verify
2556 lddChan.ChangeResourceStateSync(Clients[6].iClientId, dynamicResId[1], state);
2557 test(r == KErrNone);
2559 r = lddChan.CheckNotifications(dynamicResId[1], 0, 0);
2560 test(r == KErrNone);
2562 GetExtendedResStateAsyncAndVerify(dynamicResId[1], -10, Clients[4].iClientId, EFalse);
2564 r = lddChan.DeRegisterClientLevelFromResource(Clients[4].iClientId, dynamicResId[1]);
2565 test(r == KErrNone);
2567 GetExtendedResStateAsyncAndVerify(dynamicResId[1], -10, Clients[5].iClientId, EFalse);
2569 r = lddChan.DeRegisterClientLevelFromResource(Clients[5].iClientId, dynamicResId[1]);
2570 test(r == KErrNone);
2572 r = lddChan.CheckNotifications(dynamicResId[1], 1, 0);
2573 test(r == KErrNone);
2574 GetExtendedResStateAsyncAndVerify(dynamicResId[1], -9, Clients[3].iClientId, EFalse);
2575 //Deregister client 4
2576 r = lddChan.DeRegisterClient(Clients[3].iClientId);
2577 test(r == KErrNone);
2579 r = lddChan.CheckNotifications(dynamicResId[1], 1, 0);
2580 test(r == KErrNone);
2581 GetExtendedResStateAsyncAndVerify(dynamicResId[1], -7, Clients[2].iClientId, EFalse);
2583 r = lddChan.DeRegisterClientLevelFromResource(Clients[2].iClientId, dynamicResId[1]);
2584 test(r == KErrNone);
2586 r = lddChan.CheckNotifications(dynamicResId[1], 1, 0);
2587 test(r == KErrNone);
2588 GetExtendedResStateAsyncAndVerify(dynamicResId[1], -6, Clients[6].iClientId, EFalse);
2590 r = lddChan.DeRegisterClientLevelFromResource(Clients[6].iClientId, dynamicResId[1]);
2591 test(r == KErrNone);
2593 r = lddChan.CheckNotifications(dynamicResId[1], 1, 0);
2594 test(r == KErrNone);
2595 GetExtendedResStateAsyncAndVerify(dynamicResId[1], -5, -1, EFalse);
2596 //Deregister dynamic resource 2
2597 r = lddChan.DeRegisterDynamicResource(Clients[1].iClientId, dynamicResId[1], NULL);
2598 test(r == KErrNone);
2600 r = lddChan.CheckNotifications(dynamicResId[1], 1, 1);
2601 test(r == KErrNone);
2602 //Register dynamic resource 3
2603 dynamicResId[2] = 3;
2604 r = lddChan.RegisterDynamicResource(Clients[2].iClientId, dynamicResId[2]);
2605 test(r == KErrNone);
2606 //Register dynamic resource 4
2607 dynamicResId[3] = 4;
2608 r = lddChan.RegisterDynamicResource(Clients[6].iClientId, dynamicResId[3]);
2609 test(r == KErrNone);
2610 //Change state of dynamic resource 3 to 0
2611 r = lddChan.ChangeResourceStateSync(Clients[4].iClientId, dynamicResId[2], 0);
2612 test(r == KErrNone);
2613 GetExtendedResStateAndVerify(dynamicResId[2], 0, Clients[4].iClientId);
2614 //Change state of dynamic resource 3 to 1
2615 r = lddChan.ChangeResourceStateSync(Clients[5].iClientId, dynamicResId[2], 1);
2616 test(r == KErrNone);
2617 GetExtendedResStateAndVerify(dynamicResId[2], 0, Clients[4].iClientId);
2618 //Deregister client 5
2619 r = lddChan.DeRegisterClient(Clients[4].iClientId);
2620 test(r == KErrNone);
2621 GetExtendedResStateAndVerify(dynamicResId[2], 1, Clients[5].iClientId);
2622 //Deregister dynamic resource 3
2623 r = lddChan.DeRegisterDynamicResource(Clients[2].iClientId, dynamicResId[2], NULL);
2624 test(r == KErrInUse);
2625 //Deregister client 6
2626 r = lddChan.DeRegisterClient(Clients[5].iClientId);
2627 test(r == KErrNone);
2628 GetExtendedResStateAndVerify(dynamicResId[2], 1, -1);
2629 //Deregister dynamic resource 3
2630 r = lddChan.DeRegisterDynamicResource(Clients[2].iClientId, dynamicResId[2], NULL);
2631 test(r == KErrNone);
2632 //Change state of dynamic resource 4 to 15
2633 r = lddChan.ChangeResourceStateSync(Clients[6].iClientId, dynamicResId[3], 15);
2634 test(r == KErrNone);
2635 GetExtendedResStateAndVerify(dynamicResId[3], 15, Clients[6].iClientId);
2636 //Change state of resource and try to deregister the resource while the change is taking place
2638 lddChan.ChangeResStateAndDeRegisterDynamicRes(Clients[6].iClientId, dynamicResId[3], state, req);
2639 User::WaitForRequest(req);
2640 test(req.Int() == KErrNone);
2642 GetExtendedResStateAndVerify(dynamicResId[3], 17, Clients[6].iClientId);
2643 //Deregister dynamic resource 4 with some other client which is not owner
2644 r = lddChan.DeRegisterDynamicResource(Clients[2].iClientId, dynamicResId[3], NULL);
2645 test(r == KErrAccessDenied);
2646 //Deregister dynamic resource 4
2647 r = lddChan.DeRegisterDynamicResource(Clients[6].iClientId, dynamicResId[3], NULL);
2648 test(r == KErrNone);
2649 //Deregister client 7
2650 r = lddChan.DeRegisterClient(Clients[6].iClientId);
2651 test(r == KErrNone);
2652 //Deregister client 3
2653 r = lddChan.DeRegisterClient(Clients[2].iClientId);
2654 test(r == KErrNone);
2655 //Deregister client 2
2656 r = lddChan.DeRegisterClient(Clients[1].iClientId);
2657 test(r == KErrNone);
2658 //Deregister client 1
2659 r = lddChan.DeRegisterClient(Clients[0].iClientId);
2660 test(r == KErrNone);
2664 //This function gets extended resource state synchronously and verifies for correctness
2665 void TestRM::GetExtendedResStateAndVerify(TUint aResId, TInt aState, TInt aLevelOwnerId)
2667 static TBool cached = ETrue;
2670 r = lddChan.GetResourceStateSync(Clients[0].iClientId, aResId, cached, state, levelOwnerId);
2671 test(r == KErrNone);
2672 test(state == aState);
2673 test(levelOwnerId == aLevelOwnerId);
2677 //This function gets extended resource state asynchronously and verifies for correctness
2678 void TestRM::GetExtendedResStateAsyncAndVerify(TUint aResId, TInt aState, TInt aLevelOwnerId, TBool aReqCancel)
2680 static TBool cached = ETrue;
2681 TRequestStatus resGet;
2684 lddChan.GetResourceStateAsync(Clients[0].iClientId, aResId, cached, resGet, state, levelOwnerId, aReqCancel);
2685 User::WaitForRequest(resGet);
2686 if(aReqCancel && (resGet.Int() != KErrNone))
2688 test((resGet.Int() == KErrCompletion) || (resGet.Int() == KErrCancel));
2691 test(resGet.Int() == KErrNone);
2692 test(state == aState);
2693 test(levelOwnerId == aLevelOwnerId);
2696 //This function validates number of dependency resource and their id's for correctness
2697 void TestRM::CheckForDependencyInformation(TUint aClientId, TUint aResourceId, TUint aNumDependents, SResourceDependencyInfo* aDepResIdArray)
2699 TUint numDepResources;
2701 //Get the number of dependent's for the resource
2702 r = lddChan.GetNumDependentsForResource(aClientId, aResourceId, numDepResources);
2704 test.Printf(_L("GetNumDependentsForResource returned with %d\n"), r);
2705 test(r == KErrNone);
2706 if(aNumDependents != numDepResources)
2707 test.Printf(_L("aNumDependents = %d, numDepResource = %d\n"), aNumDependents, numDepResources);
2708 test(aNumDependents == numDepResources);
2709 if(numDepResources == 0)
2711 //Get the dependent's id
2713 info.Create(aNumDependents * sizeof(SResourceDependencyInfo));
2714 r = lddChan.GetDependentsIdForResource(aClientId, aResourceId, (TAny*)&info, numDepResources);
2717 test.Printf(_L("GetDependentsIdForResource returned with %d\n"), r);
2720 test(r == KErrNone);
2721 if(aNumDependents != numDepResources)
2723 test.Printf(_L("aNumDependents = %d, numDepResource = %d\n"), aNumDependents, numDepResources);
2726 test(aNumDependents == numDepResources);
2727 SResourceDependencyInfo* sResDepInfoPtr = (SResourceDependencyInfo*)info.Ptr();
2728 for(TUint count = 0; count < aNumDependents; count++, sResDepInfoPtr++)
2730 if(sResDepInfoPtr->iResourceId != aDepResIdArray[count].iResourceId)
2732 test.Printf(_L("Expected resourceId : %d, Returned ResourceId = %d\n"),sResDepInfoPtr->iResourceId,
2733 aDepResIdArray[count].iResourceId);
2737 if(sResDepInfoPtr->iDependencyPriority != aDepResIdArray[count].iDependencyPriority)
2739 test.Printf(_L("Expected resource priority : %d, Returned resource priority = %d\n"),sResDepInfoPtr->iDependencyPriority,
2740 aDepResIdArray[count].iDependencyPriority);
2749 //----------------------------------------------------------------------------------------------
2750 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0595
2752 //! @SYMPREQ PREQ1398
2753 //! @SYMTestCaseDesc This test case tests static resources with dependency.
2754 //! @SYMTestActions 0 Register clients
2755 //! 1 Check dependency information of each resource
2756 //! 2 Register notifications
2757 //! 3 Change Resource State of each static resource with dependency
2758 //! 4 Get state of the resources and verify them for correctness
2759 //! 5 Check notification count for correctness
2760 //! 6 Deregister client level
2761 //! 7 Deregister clients
2763 //! @SYMTestExpectedResults 0 API should return with KErrNone, panics otherwise.
2764 //! 1 API should return with KErrNone, panics otherwise.
2765 //! 2 API should return with KErrNone, panics otherwise.
2766 //! 3 API should return with KErrNone, panics otherwise.
2767 //! 4 API should return with KErrNone, panics otherwise.
2768 //! 5 API should return with KErrNone, panics otherwise.
2769 //! 6 API should return with KErrNone, panics otherwise.
2770 //! 7 API should return with KErrNone, panics otherwise.
2771 //! @SYMTestPriority High
2772 //! @SYMTestStatus Implemented
2773 //----------------------------------------------------------------------------------------------
2774 void TestRM::TestStaticResourceWithDependency()
2777 RArray<SResourceDependencyInfo>depResArray;
2778 SResourceDependencyInfo sResDepInfo;
2779 TUint numClients; // The maximum no. of dependents in the dependency tree.
2782 //Register client 1.
2783 RmTest.RegisterClient();
2784 iCurrentClientId = -1;
2786 TRequestStatus reqSet;
2788 NegativeTesting = EFalse;
2789 test.Next(_L("\nTesting static resource with dependency...."));
2791 //Check for resource dependency information of Resource D
2792 sResDepInfo.iResourceId = iStaticDependencyResources[1];
2793 sResDepInfo.iDependencyPriority = 1;
2794 depResArray.Append(sResDepInfo);
2795 sResDepInfo.iResourceId = iStaticDependencyResources[3];
2796 sResDepInfo.iDependencyPriority = 2;
2797 depResArray.Append(sResDepInfo);
2798 sResDepInfo.iResourceId = iStaticDependencyResources[2];
2799 sResDepInfo.iDependencyPriority = 3;
2800 depResArray.Append(sResDepInfo);
2801 RmTest.CheckForDependencyInformation(Clients[0].iClientId, iStaticDependencyResources[0], 3, &depResArray[0]);
2803 //Check for resource dependency information of Resource E
2804 depResArray[0].iResourceId = iStaticDependencyResources[4];
2805 depResArray[0].iDependencyPriority = 1;
2806 depResArray[1].iResourceId = iStaticDependencyResources[5];
2807 depResArray[1].iDependencyPriority = 2;
2808 depResArray[2].iResourceId = iStaticDependencyResources[0];
2809 depResArray[2].iDependencyPriority = 3;
2810 RmTest.CheckForDependencyInformation(Clients[0].iClientId, iStaticDependencyResources[3], 3, &depResArray[0]);
2812 //Check for resource dependency information of Resource C
2813 depResArray[0].iResourceId = iStaticDependencyResources[3];
2814 depResArray[0].iDependencyPriority = 1;
2815 RmTest.CheckForDependencyInformation(Clients[0].iClientId, iStaticDependencyResources[4], 1, &depResArray[0]);
2817 //Check for resource dependency information of Resource G
2818 RmTest.CheckForDependencyInformation(Clients[0].iClientId, iStaticDependencyResources[5], 1, &depResArray[0]);
2820 //Check for resource dependency information of Resource F
2821 depResArray[0].iResourceId = iStaticDependencyResources[0];
2822 depResArray[0].iDependencyPriority = 1;
2823 RmTest.CheckForDependencyInformation(Clients[0].iClientId, iStaticDependencyResources[2], 1, &depResArray[0]);
2825 //Check for resource dependency information of Resource A
2826 RmTest.CheckForDependencyInformation(Clients[0].iClientId, iStaticDependencyResources[1], 1, &depResArray[0]);
2828 RmTest.GetNumResourcesInUseByClient(iCurrentClientId);
2829 RmTest.GetInfoOnResourcesInUseByClient(iCurrentClientId, iMaxStaticResources + iMaxStaticDependentResources);
2830 iCurrentClientId = 0;
2831 //Get resource state of all dependent resource and verify
2832 GetExtendedResStateAndVerify(iStaticDependencyResources[0], -50, -1);
2833 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[1], -11, iStaticDependencyResources[0]);
2834 GetExtendedResStateAndVerify(iStaticDependencyResources[2], 1, iStaticDependencyResources[0]);
2835 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[3], 13, iStaticDependencyResources[0]);
2836 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 0, iStaticDependencyResources[3]);
2837 GetExtendedResStateAndVerify(iStaticDependencyResources[5], 73, iStaticDependencyResources[3]);
2839 r = lddChan.GetNumClientsUsingResource(Clients[0].iClientId, iStaticDependencyResources[3], numClients);
2840 test(r == KErrNone);
2841 test(numClients == 0);
2842 //Request notification
2843 for(count = 0; count < iMaxStaticDependentResources; count++)
2845 r = lddChan.RequestNotification(Clients[0].iClientId, iStaticDependencyResources[count]);
2846 test(r == KErrNone);
2848 //Change state of resource A to -11 and verify
2849 r = lddChan.ChangeResourceStateSync(Clients[0].iClientId, iStaticDependencyResources[1], -11);
2850 test(r == KErrNone);
2851 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[1], -11, Clients[0].iClientId);
2852 //Change state of resource A to -12 and verify
2854 lddChan.ChangeResourceStateAsync(Clients[0].iClientId, iStaticDependencyResources[1], state, reqSet);
2855 User::WaitForRequest(reqSet);
2856 test(reqSet.Int() == KErrNone);
2857 r = lddChan.CheckNotifications(iStaticDependencyResources[1], 1, 0);
2858 test(r == KErrNone);
2860 RmTest.RegisterClient();
2861 //Change state of resource D to -49 and verify
2863 lddChan.ChangeResourceStateAsync(Clients[1].iClientId, iStaticDependencyResources[0], state, reqSet);
2864 User::WaitForRequest(reqSet);
2865 test(reqSet.Int() == KErrNone);
2866 //Check for notifications
2867 r = lddChan.CheckNotifications(iStaticDependencyResources[0], 1, 0);
2868 test(r == KErrNone);
2869 r = lddChan.CheckNotifications(iStaticDependencyResources[1], 1, 0);
2870 test(r == KErrNone);
2871 r = lddChan.CheckNotifications(iStaticDependencyResources[3], 1, 0);
2872 test(r == KErrNone);
2873 r = lddChan.CheckNotifications(iStaticDependencyResources[5], 1, 0);
2874 test(r == KErrNone);
2875 //Get the state and verify for correctness
2876 GetExtendedResStateAndVerify(iStaticDependencyResources[0], -49, Clients[1].iClientId);
2877 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[1], -13, iStaticDependencyResources[0]);
2878 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[2], 1, iStaticDependencyResources[0]);
2879 GetExtendedResStateAndVerify(iStaticDependencyResources[3], 16, iStaticDependencyResources[0]);
2880 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 0, iStaticDependencyResources[3]);
2881 GetExtendedResStateAndVerify(iStaticDependencyResources[5], 71, iStaticDependencyResources[3]);
2882 //Change state of resource F to 1 and verify
2883 r = lddChan.ChangeResourceStateSync(Clients[1].iClientId, iStaticDependencyResources[2], 1);
2884 test(r == KErrNone);
2885 r = lddChan.CheckNotifications(iStaticDependencyResources[2], 0, 0);
2886 test(r == KErrNone);
2887 GetExtendedResStateAndVerify(iStaticDependencyResources[2], 1, Clients[1].iClientId);
2889 RmTest.RegisterClient();
2890 //Change state of resource E to 19 and verify
2891 r = lddChan.ChangeResourceStateSync(Clients[2].iClientId, iStaticDependencyResources[3], 19);
2892 test(r == KErrNone);
2893 r = lddChan.CheckNotifications(iStaticDependencyResources[3], 1, 0);
2894 test(r == KErrNone);
2895 r = lddChan.CheckNotifications(iStaticDependencyResources[5], 1, 0);
2896 test(r == KErrNone);
2897 GetExtendedResStateAndVerify(iStaticDependencyResources[0], -49, Clients[1].iClientId);
2898 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[1], -13, iStaticDependencyResources[0]);
2899 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[2], 1, Clients[1].iClientId);
2900 GetExtendedResStateAndVerify(iStaticDependencyResources[3], 19, Clients[2].iClientId);
2901 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 0, iStaticDependencyResources[3]);
2902 GetExtendedResStateAndVerify(iStaticDependencyResources[5], 69, iStaticDependencyResources[3]);
2904 RmTest.RegisterClient();
2905 //Change state of resource C to 0 and verify
2906 r = lddChan.ChangeResourceStateSync(Clients[3].iClientId, iStaticDependencyResources[4], 0);
2907 test(r == KErrNone);
2908 r = lddChan.CheckNotifications(iStaticDependencyResources[4], 0, 0);
2909 test(r == KErrNone);
2910 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 0, iStaticDependencyResources[3]);
2911 //Change state of resource C to 1 and verify
2912 r = lddChan.ChangeResourceStateSync(Clients[2].iClientId, iStaticDependencyResources[4], 1);
2913 test(r == KErrNone);
2914 r = lddChan.CheckNotifications(iStaticDependencyResources[4], 0, 0);
2915 test(r == KErrNone);
2916 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 0, iStaticDependencyResources[3]);
2917 //Change state of resource G to 67 and verify
2918 r = lddChan.ChangeResourceStateSync(Clients[2].iClientId, iStaticDependencyResources[5], 67);
2919 test(r == KErrNone);
2920 r = lddChan.CheckNotifications(iStaticDependencyResources[5], 1, 0);
2921 test(r == KErrNone);
2922 GetExtendedResStateAndVerify(iStaticDependencyResources[0], -49, Clients[1].iClientId);
2923 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[1], -13, iStaticDependencyResources[0]);
2924 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[2], 1, Clients[1].iClientId);
2925 GetExtendedResStateAndVerify(iStaticDependencyResources[3], 19, Clients[2].iClientId);
2926 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 0, iStaticDependencyResources[3]);
2927 GetExtendedResStateAndVerify(iStaticDependencyResources[5], 67, Clients[2].iClientId);
2928 //Change state of resource G to 67 and verify
2929 r = lddChan.ChangeResourceStateSync(Clients[3].iClientId, iStaticDependencyResources[5], 67);
2930 test(r == KErrNone);
2931 r = lddChan.CheckNotifications(iStaticDependencyResources[5], 0, 0);
2932 test(r == KErrNone);
2933 GetExtendedResStateAndVerify(iStaticDependencyResources[0], -49, Clients[1].iClientId);
2934 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[1], -13, iStaticDependencyResources[0]);
2935 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[2], 1, Clients[1].iClientId);
2936 GetExtendedResStateAndVerify(iStaticDependencyResources[3], 19, Clients[2].iClientId);
2937 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 0, iStaticDependencyResources[3]);
2938 GetExtendedResStateAndVerify(iStaticDependencyResources[5], 67, Clients[2].iClientId);
2940 //Change the state of the resource E to 24
2943 RmTest.RegisterClient();
2944 lddChan.ChangeResourceStateAsync(Clients[4].iClientId, iStaticDependencyResources[3], state, reqSet);
2945 User::WaitForRequest(reqSet);
2946 test(reqSet.Int() == KErrNone);
2947 r = lddChan.CheckNotifications(iStaticDependencyResources[3], 1, 0);
2948 test(r == KErrNone);
2949 r = lddChan.CheckNotifications(iStaticDependencyResources[5], 1, 0);
2950 test(r == KErrNone);
2951 GetExtendedResStateAndVerify(iStaticDependencyResources[0], -49, Clients[1].iClientId);
2952 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[1], -13, iStaticDependencyResources[0]);
2953 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[2], 1, Clients[1].iClientId);
2954 GetExtendedResStateAndVerify(iStaticDependencyResources[3], 24, Clients[4].iClientId);
2955 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 0, iStaticDependencyResources[3]);
2956 GetExtendedResStateAndVerify(iStaticDependencyResources[5], 65, iStaticDependencyResources[3]);
2958 //Change resource state of Resource D to -51
2959 r = lddChan.ChangeResourceStateSync(Clients[2].iClientId, iStaticDependencyResources[0], -51);
2960 test(r == KErrAccessDenied);
2961 GetExtendedResStateAndVerify(iStaticDependencyResources[0], -49, Clients[1].iClientId);
2963 //DeregisterClient 5
2964 r = lddChan.DeRegisterClient(Clients[4].iClientId);
2965 test(r == KErrNone);
2967 r = lddChan.CheckNotifications(iStaticDependencyResources[3], 1, 0);
2968 test(r == KErrNone);
2969 r = lddChan.CheckNotifications(iStaticDependencyResources[5], 1, 0);
2970 test(r == KErrNone);
2972 GetExtendedResStateAndVerify(iStaticDependencyResources[3], 19, Clients[2].iClientId);
2973 GetExtendedResStateAndVerify(iStaticDependencyResources[5], 63, iStaticDependencyResources[3]);
2975 //Change resource state of resource D to 50
2977 lddChan.ChangeResourceStateAsync(Clients[1].iClientId, iStaticDependencyResources[0], state, reqSet);
2978 User::WaitForRequest(reqSet);
2979 test(reqSet.Int() == KErrNone);
2980 r = lddChan.CheckNotifications(iStaticDependencyResources[0], 1, 0);
2981 test(r == KErrNone);
2982 r = lddChan.CheckNotifications(iStaticDependencyResources[1], 1, 0);
2983 test(r == KErrNone);
2984 r = lddChan.CheckNotifications(iStaticDependencyResources[3], 1, 0);
2985 test(r == KErrNone);
2986 r = lddChan.CheckNotifications(iStaticDependencyResources[5], 1, 0);
2987 test(r == KErrNone);
2989 GetExtendedResStateAndVerify(iStaticDependencyResources[0], 50, Clients[1].iClientId);
2990 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[1], -14, iStaticDependencyResources[0]);
2991 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[2], 1, Clients[1].iClientId);
2992 GetExtendedResStateAndVerify(iStaticDependencyResources[3], 22, iStaticDependencyResources[0]);
2993 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 0, iStaticDependencyResources[3]);
2994 GetExtendedResStateAndVerify(iStaticDependencyResources[5], 61, iStaticDependencyResources[3]);
2996 //Change resource state of resource G to 61
2997 r = lddChan.ChangeResourceStateSync(Clients[3].iClientId, iStaticDependencyResources[5], 61);
2998 test(r == KErrNone);
3000 r = lddChan.CheckNotifications(iStaticDependencyResources[5], 0, 0);
3001 test(r == KErrNone);
3003 GetExtendedResStateAndVerify(iStaticDependencyResources[0], 50, Clients[1].iClientId);
3004 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[1], -14, iStaticDependencyResources[0]);
3005 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[2], 1, Clients[1].iClientId);
3006 GetExtendedResStateAndVerify(iStaticDependencyResources[3], 22, iStaticDependencyResources[0]);
3007 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 0, iStaticDependencyResources[3]);
3008 GetExtendedResStateAndVerify(iStaticDependencyResources[5], 61, iStaticDependencyResources[3]);
3010 //Deregister client 4;
3011 r = lddChan.DeRegisterClient(Clients[3].iClientId);
3012 test(r == KErrNone);
3014 r = lddChan.CheckNotifications(iStaticDependencyResources[5], 0, 0);
3015 test(r == KErrNone);
3017 GetExtendedResStateAndVerify(iStaticDependencyResources[0], 50, Clients[1].iClientId);
3018 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[1], -14, iStaticDependencyResources[0]);
3019 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[2], 1, Clients[1].iClientId);
3020 GetExtendedResStateAndVerify(iStaticDependencyResources[3], 22, iStaticDependencyResources[0]);
3021 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 0, iStaticDependencyResources[3]);
3022 GetExtendedResStateAndVerify(iStaticDependencyResources[5], 61, iStaticDependencyResources[3]);
3024 //Deregister client 3.
3025 r = lddChan.DeRegisterClient(Clients[2].iClientId);
3026 test(r == KErrNone);
3028 GetExtendedResStateAndVerify(iStaticDependencyResources[0], 50, Clients[1].iClientId);
3029 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[1], -14, iStaticDependencyResources[0]);
3030 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[2], 1, Clients[1].iClientId);
3031 GetExtendedResStateAndVerify(iStaticDependencyResources[3], 22, iStaticDependencyResources[0]);
3032 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 0, iStaticDependencyResources[3]);
3033 GetExtendedResStateAndVerify(iStaticDependencyResources[5], 61, iStaticDependencyResources[3]);
3035 //Deregister client 0 from Resource A
3036 r = lddChan.DeRegisterClientLevelFromResource(Clients[0].iClientId, iStaticDependencyResources[1]);
3037 test(r == KErrNone);
3039 r = lddChan.CheckNotifications(iStaticDependencyResources[1], 0, 0);
3040 test(r == KErrNone);
3042 GetExtendedResStateAndVerify(iStaticDependencyResources[0], 50, Clients[1].iClientId);
3043 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[1], -14, iStaticDependencyResources[0]);
3044 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[2], 1, Clients[1].iClientId);
3045 GetExtendedResStateAndVerify(iStaticDependencyResources[3], 22, iStaticDependencyResources[0]);
3046 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 0, iStaticDependencyResources[3]);
3047 GetExtendedResStateAndVerify(iStaticDependencyResources[5], 61, iStaticDependencyResources[3]);
3049 //Move Resource D to default
3050 r = lddChan.ChangeResourceStateSync(Clients[1].iClientId, iStaticDependencyResources[0], -100);
3051 test(r == KErrPermissionDenied);
3053 //Deregister client 1 from Resource F
3054 r = lddChan.DeRegisterClientLevelFromResource(Clients[1].iClientId, iStaticDependencyResources[2]);
3055 test(r == KErrNone);
3057 r = lddChan.CheckNotifications(iStaticDependencyResources[1], 0, 0);
3058 test(r == KErrNone);
3060 GetExtendedResStateAndVerify(iStaticDependencyResources[0], 50, Clients[1].iClientId);
3061 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[1], -14, iStaticDependencyResources[0]);
3062 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[2], 1, iStaticDependencyResources[0]);
3063 GetExtendedResStateAndVerify(iStaticDependencyResources[3], 22, iStaticDependencyResources[0]);
3064 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 0, iStaticDependencyResources[3]);
3065 GetExtendedResStateAndVerify(iStaticDependencyResources[5], 61, iStaticDependencyResources[3]);
3067 //Deregister client 2
3068 r = lddChan.DeRegisterClient(Clients[1].iClientId);
3069 test(r == KErrNone);
3071 GetExtendedResStateAndVerify(iStaticDependencyResources[0], -100, -1);
3072 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[1], -10, iStaticDependencyResources[0]);
3073 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[2], 0, iStaticDependencyResources[0]);
3074 GetExtendedResStateAndVerify(iStaticDependencyResources[3], 10, iStaticDependencyResources[0]);
3075 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 1, iStaticDependencyResources[3]);
3076 GetExtendedResStateAndVerify(iStaticDependencyResources[5], 75, iStaticDependencyResources[3]);
3077 //Deregister client 1
3078 r = lddChan.DeRegisterClient(Clients[0].iClientId);
3079 test(r == KErrNone);
3080 Clients.Close(); //Close the array and release memory
3082 //Test parallel execution of RC and Dependency resource DFC's
3084 RmTest.RegisterClient();
3086 RmTest.RegisterClient();
3089 /* CheckParallelExecutionForResChageStateWithDependency */
3090 lddChan.CheckParallelExecutionForChangeResState(Clients[1].iClientId,
3091 iStaticDependencyResources[0],state,5,0,reqSet);
3093 User::WaitForRequest(reqSet);
3094 test(reqSet.Int() == KErrNone);
3096 GetExtendedResStateAndVerify(iStaticDependencyResources[0], 50, Clients[1].iClientId);
3097 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[1], -11, iStaticDependencyResources[0]);
3098 GetExtendedResStateAndVerify(iStaticDependencyResources[2], 1, iStaticDependencyResources[0]);
3099 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[3], 13, iStaticDependencyResources[0]);
3100 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 0, iStaticDependencyResources[3]);
3101 GetExtendedResStateAndVerify(iStaticDependencyResources[5], 73, iStaticDependencyResources[3]);
3104 TBool cached = ETrue;
3105 r = lddChan.GetResourceStateSync(Clients[1].iClientId, 4, cached, state, owner);
3106 test(r == KErrNone);
3110 r = lddChan.DeRegisterClient(Clients[1].iClientId);
3111 test(r == KErrNone);
3113 GetExtendedResStateAndVerify(iStaticDependencyResources[0], -100, -1);
3114 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[1], -10, iStaticDependencyResources[0]);
3115 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[2], 0, iStaticDependencyResources[0]);
3116 GetExtendedResStateAndVerify(iStaticDependencyResources[3], 10, iStaticDependencyResources[0]);
3117 GetExtendedResStateAsyncAndVerify(iStaticDependencyResources[4], 1, iStaticDependencyResources[3]);
3118 GetExtendedResStateAndVerify(iStaticDependencyResources[5], 75, iStaticDependencyResources[3]);
3120 r = lddChan.GetResourceStateSync(Clients[0].iClientId, 4, cached, state, owner);
3121 test(r == KErrNone);
3125 r = lddChan.DeRegisterClient(Clients[0].iClientId);
3126 test(r == KErrNone);
3128 Clients.Close(); //Close the array and release memory
3129 depResArray.Close(); //Close the array and release memory
3133 //This function validates each of the resource manager API's
3134 void TestRM::APIValidationTest()
3136 test.Next(_L("\nStarting API validation Test...."));
3137 RmTest.RegisterClient();
3138 r = lddChan.GetResourceControllerVersion(Clients[0].iClientId, iTestingExtendedVersion);
3139 test(r == KErrNone);
3140 if(!iTestingExtendedVersion)
3141 test.Printf(_L("Testing Basic Version only...."));
3143 test.Printf(_L("Testing basic & extended version...."));
3144 RmTest.ValidateClient(5, EOwnerProcess);
3145 iCurrentClientId = -1;
3146 RmTest.GetNumResourcesInUseByClient(iCurrentClientId);
3147 RmTest.GetInfoOnResourcesInUseByClient(iCurrentClientId, iMaxStaticResources);
3148 iCurrentClientId = 0;
3149 NegativeTesting = ETrue;
3150 if(Resources[0].iName.Compare(*(const TDesC8*)&SpecialResName))
3152 test.Printf(_L("Test runs only on simulated PSL\n"));
3153 RmTest.DeRegisterClient(Clients[0].iClientId);
3156 TBuf8<32> PowerController = _L8("PowerController");
3157 r = lddChan.GetClientId(Clients[0].iClientId, (TDesC8&)PowerController, iPowerControllerId);
3158 test(r == KErrNone);
3162 r = info.Create((iMaxStaticResources) * sizeof(SIdleResourceInfo));
3163 test(r == KErrNone);
3164 SIdleResourceInfo* pI = (SIdleResourceInfo*)info.Ptr();
3165 for(c = 0; c < iMaxStaticResources; c++)
3167 pI->iResourceId = Resources[c].iResourceId;
3170 pI = (SIdleResourceInfo*)info.Ptr();
3172 r = lddChan.RegisterForIdleResourcesInfo(iPowerControllerId, iMaxStaticResources, (TAny*)info.Ptr());
3174 test(r == KErrNone);
3175 RmTest.GetClientName(iCurrentClientId);
3176 RmTest.GetClientId(iCurrentClientId);
3177 RmTest.GetResourceId(2);
3178 RmTest.GetResourceInfo(19);
3179 RmTest.GetNumResourcesInUseByClient(iCurrentClientId);
3180 RmTest.GetInfoOnResourcesInUseByClient(iCurrentClientId, 3);
3181 RmTest.GetNumClientsUsingResource(iCurrentClientId, (TUint)-1);
3182 RmTest.GetNumClientsUsingResource(iCurrentClientId, 10);
3183 RmTest.GetInfoOnClientsUsingResource((TUint)-1, 4);
3184 RmTest.GetInfoOnClientsUsingResource(5, 3);
3186 for(c = 0; c < iMaxStaticResources; c++)
3188 if(Resources[c].iSense == ECustom)
3190 RmTest.GetResourceStateAsync(c, ETrue);
3192 User::After(2000000); //Add delay to make sure that the asynchronous request is processed in controller thread
3194 for(c = 0; c < iMaxStaticResources; c++)
3196 if(Resources[c].iSense == ECustom)
3198 iCurrentClientId = c;
3199 RmTest.RegisterClient();
3200 RmTest.AllocReserve(c);
3201 RmTest.GetResourceStateAsync(c);
3202 RmTest.RequestNotification(c);
3203 RmTest.RequestNotificationCon(c);
3206 for(c=0; c< iMaxStaticResources; c++)
3208 if(Resources[c].iSense == ECustom)
3210 iCurrentClientId = c;
3211 RmTest.ChangeResourceStateAsync(c);
3212 RmTest.GetResourceStateAsync(c);
3213 RmTest.GetResourceStateSync(c);
3214 RmTest.ChangeResourceStateSync(c);
3216 for(c = 0; c < iMaxStaticResources; c++)
3218 if(Resources[c].iSense == ECustom)
3220 iCurrentClientId = c;
3221 RmTest.GetClientName(c);
3222 RmTest.GetClientId(c);
3223 RmTest.GetResourceId(c);
3224 RmTest.GetResourceInfo(c);
3225 RmTest.GetNumResourcesInUseByClient(c);
3226 RmTest.GetInfoOnResourcesInUseByClient(c, Clients[c].iNumResources);
3227 RmTest.GetNumClientsUsingResource(c, c);
3228 RmTest.GetInfoOnClientsUsingResource(c, Resources[c].iNumClients);
3229 RmTest.CancelNotification(c, ETrue);
3230 RmTest.CancelNotification(c, EFalse);
3233 TInt clientCount = Clients.Count();
3234 for(c = clientCount-1; ((TInt)c) >=0; c--)
3236 test.Printf(_L("DeRegister ClientId %d\n"), Clients[c].iClientId);
3237 RmTest.DeRegisterClient(c);
3240 //Find any shared binary resource
3241 for(c = 0; c < iMaxStaticResources; c++)
3243 if(Resources[c].iSense == ECustom)
3245 if((Resources[c].iUsage == EShared) && (Resources[c].iSense == ENegative))
3247 if(Resources[c].iType == 0x0) //Binary Resource
3248 RmTest.SharedBinaryNegativeResourceTesting(c);
3250 RmTest.SharedMultilevelNegativeResourceTesting(c);
3252 else if((Resources[c].iUsage == EShared) && (Resources[c].iSense == EPositive))
3254 if(Resources[c].iType == 0x0) //Binary Resource
3255 RmTest.SharedBinaryPositiveResourceTesting(c);
3257 RmTest.SharedMultilevelPositiveResourceTesting(c);
3261 RmTest.CustomResourceTesting(CUSTOM_RESOURCE_NUMBER);
3263 //Testing of Deregistration of client level for binary resource
3264 RmTest.RegisterClient();
3265 for(c = 0; c < iMaxStaticResources; c++)
3267 if(Resources[c].iSense == ECustom)
3269 RmTest.DeRegisterClientLevelFromResource(-1, c);
3271 for(c = 0; c < iMaxStaticResources; c++)
3273 iCurrentClientId = 0;
3274 RmTest.ChangeResourceStateSync(c);
3275 RmTest.DeRegisterClientLevelFromResource(0, c);
3277 RmTest.RegisterClient();
3278 for(c = 0; c < iMaxStaticResources; c++) //Test valid only for shared resources.
3280 if((Resources[c].iSense == ECustom) || (Resources[c].iUsage == ESingle))
3282 iCurrentClientId = 0;
3283 RmTest.ChangeResourceStateSync(c);
3284 iCurrentClientId = 1;
3285 RmTest.ChangeResourceStateSync(c);
3286 if(Resources[c].iCurrentClient == 0)
3288 RmTest.DeRegisterClientLevelFromResource(0, c);
3289 RmTest.DeRegisterClientLevelFromResource(1, c);
3293 RmTest.DeRegisterClientLevelFromResource(1, c);
3294 RmTest.DeRegisterClientLevelFromResource(0, c);
3297 //Testing of Deregistration of client level for shared resource
3298 for(c = 0; c < iMaxStaticResources; c++)
3300 if((Resources[c].iSense == ECustom) || (!Resources[c].iUsage))
3302 RmTest.DeRegisterClientLevelFromResource(-1, c);
3305 RmTest.DeRegisterClient(1);
3306 RmTest.DeRegisterClient(0);
3307 info.Create(15 * sizeof(SIdleResourceInfo));
3308 r = lddChan.GetIdleResourcesInfo(15, (TAny*)(TDes8*)&info);
3309 test(r == KErrNone);
3310 pI = (SIdleResourceInfo*)info.Ptr();
3311 for(c = 0; c< 15; c++)
3313 test(Resources[c].iCurrentClient == pI->iLevelOwnerId);
3314 test(Resources[c].iCurrentLevel == pI->iCurrentLevel);
3315 test(Resources[c].iResourceId == pI->iResourceId);
3320 #ifdef PRM_ENABLE_EXTENDED_VERSION
3321 if(iTestingExtendedVersion)
3323 TestStaticResourceWithDependency();
3324 TestDynamicResource();
3325 TestDynamicResourceDependency();
3332 //----------------------------------------------------------------------------------------------
3333 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0592
3335 //! @SYMPREQ PREQ1398
3336 //! @SYMTestCaseDesc This test case tests deregistration of client level functionality.
3337 //! @SYMTestActions 0 Register client
3338 //! 1 Change Resource State
3339 //! 2 Deregister client level
3340 //! 3 Deregister client
3342 //! @SYMTestExpectedResults 0 API should return with KErrNone, panics otherwise.
3343 //! 1 API should return with KErrNone, panics otherwise.
3344 //! 2 API should return with KErrNone, panics otherwise.
3345 //! 3 API should return with KErrNone, panics otherwise.
3346 //! @SYMTestPriority High
3347 //! @SYMTestStatus Implemented
3348 //----------------------------------------------------------------------------------------------
3349 void TestRM::DeRegisterClientLevelFromResource(TInt aClientId, TUint aResId)
3354 r = lddChan.GetResourceStateSync(Clients[0].iClientId, Resources[aResId].iResourceId, ETrue, newState, levelOwnerId);
3355 test(r == KErrNone);
3356 if((levelOwnerId != -1) && (levelOwnerId != (TInt)Clients[aClientId].iClientId))
3358 test.Printf(_L("Client Id does not match so not testing Deregistration of client level\n"));
3361 if(Resources[aResId].iUsage == ESingle) //Single user resource
3363 if(levelOwnerId == -1)
3366 ClientName[6] = (TUint8)('0' + iMaxClientId+1);
3367 r = lddChan.RegisterClient(ClientId, (const TDesC*)&ClientName);
3368 test(r == KErrNone);
3369 newState = Resources[aResId].iMaxLevel;
3370 r = lddChan.ChangeResourceStateSync(ClientId, Resources[aResId].iResourceId, newState);
3371 test(r == KErrNone);
3372 r = lddChan.GetResourceStateSync(ClientId, Resources[aResId].iResourceId, ETrue, state, levelOwnerId);
3373 test(r == KErrNone);
3374 test(state == newState);
3375 test(levelOwnerId == (TInt)ClientId);
3376 r = lddChan.DeRegisterClientLevelFromResource(ClientId, Resources[aResId].iResourceId);
3377 test(r == KErrNone);
3378 r = lddChan.GetResourceStateSync(ClientId, Resources[aResId].iResourceId, ETrue, state, levelOwnerId);
3379 test(r == KErrNone);
3380 test(levelOwnerId == -1);
3381 r = lddChan.DeRegisterClient(ClientId);
3382 test(r == KErrNone);
3385 r = lddChan.DeRegisterClientLevelFromResource(Clients[aClientId].iClientId, Resources[aResId].iResourceId);
3386 test(r == KErrNone);
3387 r = lddChan.GetResourceStateSync(Clients[aClientId].iClientId, Resources[aResId].iResourceId, ETrue, state, levelOwnerId);
3388 test(r == KErrNone);
3389 test(levelOwnerId == -1);
3391 Resources[aResId].iCurrentClient = -1;
3392 Resources[aResId].iCurrentLevel = state;
3393 Resources[aResId].iNumClients = 0;
3394 delete Resources[aResId].iLevel;
3395 Resources[aResId].iLevel = NULL;
3398 //Handle for Shared resources
3399 if(levelOwnerId == -1)
3402 ClientName[6] = (TUint8)('0' + iMaxClientId+1);
3403 r = lddChan.RegisterClient(ClientId[0], (const TDesC*)&ClientName);
3404 test(r == KErrNone);
3405 ClientName[6] = (TUint8)('0' + iMaxClientId+2);
3406 r = lddChan.RegisterClient(ClientId[1], (const TDesC*)&ClientName);
3407 test(r == KErrNone);
3408 newState = Resources[aResId].iMinLevel;
3409 r = lddChan.ChangeResourceStateSync(ClientId[0], Resources[aResId].iResourceId, newState);
3410 test(r == KErrNone);
3411 r = lddChan.GetResourceStateSync(ClientId[0], Resources[aResId].iResourceId, ETrue, state, levelOwnerId);
3412 test(r == KErrNone);
3413 test(levelOwnerId == (TInt)ClientId[0]);
3414 r = lddChan.ChangeResourceStateSync(ClientId[1], Resources[aResId].iResourceId, newState);
3415 test(r == KErrNone);
3416 r = lddChan.DeRegisterClientLevelFromResource(ClientId[0], Resources[aResId].iResourceId);
3417 test(r == KErrNone);
3418 r = lddChan.GetResourceStateSync(ClientId[0], Resources[aResId].iResourceId, ETrue, state, levelOwnerId);
3419 test(r == KErrNone);
3420 test(levelOwnerId == (TInt)ClientId[1]);
3421 r = lddChan.DeRegisterClientLevelFromResource(ClientId[1], Resources[aResId].iResourceId);
3422 test(r == KErrNone);
3423 r = lddChan.GetResourceStateSync(ClientId[0], Resources[aResId].iResourceId, ETrue, state, levelOwnerId);
3424 test(r == KErrNone);
3425 test(levelOwnerId == -1);
3426 r = lddChan.DeRegisterClient(ClientId[0]);
3427 test(r == KErrNone);
3428 r = lddChan.DeRegisterClient(ClientId[1]);
3429 test(r == KErrNone);
3432 r = lddChan.DeRegisterClientLevelFromResource(Clients[aClientId].iClientId, Resources[aResId].iResourceId);
3433 test(r == KErrNone);
3434 r = lddChan.GetResourceStateSync(Clients[aClientId].iClientId, Resources[aResId].iResourceId, ETrue, state, levelOwnerId);
3435 test(r == KErrNone);
3436 test(levelOwnerId != (TInt)Clients[aClientId].iClientId);
3437 if(Resources[aResId].iNumClients == 1)
3439 Resources[aResId].iNumClients--;
3440 Resources[aResId].iCurrentClient = -1;
3441 r = lddChan.GetResourceStateSync(Clients[aClientId].iClientId, Resources[aResId].iResourceId, ETrue, state, levelOwnerId);
3442 test(r == KErrNone);
3443 Resources[aResId].iCurrentLevel = state;
3444 delete Resources[aResId].iLevel;
3445 Resources[aResId].iLevel = NULL;
3449 Resources[aResId].iNumClients--;
3450 SPowerResourceClientLevel *pCL = NULL;
3451 TInt level = KMinTInt;
3453 for(SPowerResourceClientLevel* pL = Resources[aResId].iLevel; pL != NULL; pL = pL->iNextInList)
3455 if(pL->iClientId == Clients[aClientId].iClientId)
3460 if(level == KMinTInt)
3463 clientId = pL->iClientId;
3466 if(((Resources[aResId].iSense == EPositive) && (pL->iLevel > level)) || ((Resources[aResId].iSense == ENegative) && (pL->iLevel < level)))
3469 clientId = pL->iClientId;
3473 Resources[aResId].iCurrentClient = clientId;
3474 Resources[aResId].iCurrentLevel = level;
3479 //----------------------------------------------------------------------------------------------
3480 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0593
3482 //! @SYMPREQ PREQ1398
3483 //! @SYMTestCaseDesc This test case tests changing resource state of shared positive resource.
3484 //! @SYMTestActions 0 Register client1
3485 //! 1 Register client2
3486 //! 2 Register client3
3487 //! 3 Register client4
3488 //! 4 Client1 change resource state.
3489 //! 5 Client2 change resource state.
3490 //! 6 Client3 change resource state.
3491 //! 7 Client4 change resource state.
3492 //! 8 Client1 change resource state.
3493 //! 9 Client2 change resource state.
3494 //! 10 Deregister client2
3495 //! 11 Client3 change resource state.
3496 //! 12 Deregister client1
3497 //! 13 Deregister client3
3498 //! 14 Deregister client4
3500 //! @SYMTestExpectedResults 0 Client registered
3501 //! 1 Client registered
3502 //! 2 Client registered
3503 //! 3 Client registered
3504 //! 4 Resource state changed
3505 //! 5 Resource state changed
3506 //! 6 Resource state changed
3507 //! 7 Resource state changed
3508 //! 8 Resource state changed
3509 //! 9 Resource state changed
3510 //! 10 Client2 deregistered
3511 //! 11 Resource state changed
3512 //! 12 Client1 deregistered
3513 //! 13 Client3 deregistered
3514 //! 14 Client4 deregistered
3515 //! @SYMTestPriority High
3516 //! @SYMTestStatus Implemented
3517 //----------------------------------------------------------------------------------------------
3518 void TestRM::SharedBinaryPositiveResourceTesting(TUint aResId)
3520 TInt newState, levelOwnerId;
3524 ClientName[6] = (TUint8)('0' + iMaxClientId+1);
3525 r = lddChan.RegisterClient(ClientId[0], (const TDesC*)&ClientName);
3526 test(r == KErrNone);
3528 r = lddChan.GetResourceStateSync(ClientId[0], Resources[aResId].iResourceId, ETrue, newState, levelOwnerId);
3529 test(r == KErrNone);
3530 if(levelOwnerId != -1)
3532 test.Printf(_L("Not testing the shared resource as some other client is currently holding the resource\n"));
3533 r = lddChan.DeRegisterClient(ClientId[0]);
3534 test(r == KErrNone);
3538 ClientName[6] = (TUint8)('0' + iMaxClientId +2);
3539 r = lddChan.RegisterClient(ClientId[1], (const TDesC*)&ClientName);
3540 test(r == KErrNone);
3541 ClientName[6] = (TUint8)('0' + iMaxClientId +3);
3542 r = lddChan.RegisterClient(ClientId[2], (const TDesC*)&ClientName);
3543 test(r == KErrNone);
3544 ClientName[6] = (TUint8)('0' + iMaxClientId +4);
3545 r = lddChan.RegisterClient(ClientId[3], (const TDesC*)&ClientName);
3546 test(r == KErrNone);
3547 ClientName[6] = (TUint8)('0' + iMaxClientId +5);
3548 r = lddChan.RegisterClient(ClientId[4], (const TDesC*)&ClientName);
3549 test(r == KErrNone);
3552 r = lddChan.ChangeResourceStateSync(ClientId[0], Resources[aResId].iResourceId, newState);
3553 test(r == KErrNone);
3554 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 0, 0);
3555 test(r == KErrNone);
3556 r = lddChan.RequestNotification(ClientId[1], Resources[aResId].iResourceId);
3557 test(r == KErrNone);
3558 r = lddChan.RequestNotification(ClientId[2], Resources[aResId].iResourceId);
3559 test(r == KErrNone);
3560 r = lddChan.RequestNotification(ClientId[3], Resources[aResId].iResourceId, 1, ETrue);
3561 test(r == KErrNone);
3562 r = lddChan.RequestNotification(ClientId[2], Resources[aResId].iResourceId, 0, EFalse);
3563 test(r == KErrNone);
3564 newState = !newState; //State 0
3565 r = lddChan.ChangeResourceStateSync(ClientId[0], Resources[aResId].iResourceId, newState);
3566 test(r == KErrNone);
3567 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 2, 1);
3568 test(r == KErrNone);
3569 newState = !newState; //State 1
3570 r = lddChan.ChangeResourceStateSync(ClientId[1], Resources[aResId].iResourceId, newState);
3571 test(r == KErrNone);
3572 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 2, 1);
3573 test(r == KErrNone);
3574 lddChan.ChangeResourceStateAsync(ClientId[2], Resources[aResId].iResourceId, newState, req);
3575 User::WaitForRequest(req); //State 1
3576 test(req.Int() == KErrNone);
3577 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 0, 0);
3578 test(r == KErrNone);
3579 newState = !newState; //State 0
3580 r = lddChan.ChangeResourceStateSync(ClientId[3], Resources[aResId].iResourceId, newState);
3581 test(r == KErrNone);
3582 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 0, 0);
3583 test(r == KErrNone);
3584 newState = !newState; //state 1
3585 r = lddChan.ChangeResourceStateSync(ClientId[0], Resources[aResId].iResourceId, newState);
3586 test(r == KErrNone);
3587 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 0, 0);
3588 newState = !newState; //state 0
3589 r = lddChan.ChangeResourceStateSync(ClientId[1], Resources[aResId].iResourceId, newState);
3590 test(r == KErrNone);
3591 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 0,0);
3592 test(r == KErrNone);
3593 r = lddChan.DeRegisterClient(ClientId[1]);
3594 test(r == KErrNone);
3596 r = lddChan.ChangeResourceStateSync(ClientId[2], Resources[aResId].iResourceId, newState);
3597 test(r == KErrNone);
3598 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 0,0);
3599 test(r == KErrNone);
3600 r = lddChan.ChangeResourceStateSync(ClientId[0], Resources[aResId].iResourceId, newState);
3601 test(r == KErrNone);
3602 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 1,1);
3603 test(r == KErrNone);
3604 r = lddChan.CancelNotification(ClientId[2], Resources[aResId].iResourceId, EFalse);
3605 test(r == KErrCancel);
3606 r = lddChan.CancelNotification(ClientId[3], Resources[aResId].iResourceId, ETrue);
3607 test(r == KErrCancel);
3609 r = lddChan.ChangeResourceStateSync(ClientId[0], Resources[aResId].iResourceId, newState);
3610 test(r == KErrNone);
3611 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 0, 0);
3612 test(r == KErrNone);
3613 r = lddChan.CancelNotification(ClientId[2], Resources[aResId].iResourceId, ETrue);
3614 test(r == KErrCancel);
3616 r = lddChan.ChangeResourceStateSync(ClientId[0], Resources[aResId].iResourceId, newState);
3617 test(r == KErrNone);
3618 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 0, 0);
3619 test(r == KErrNone);
3620 r = lddChan.DeRegisterClient(ClientId[0]);
3621 test(r == KErrNone);
3622 r = lddChan.DeRegisterClient(ClientId[2]);
3623 test(r == KErrNone);
3624 r = lddChan.DeRegisterClient(ClientId[3]);
3625 test(r == KErrNone);
3626 r = lddChan.GetResourceStateSync(ClientId[4], Resources[aResId].iResourceId, ETrue, newState, levelOwnerId);
3627 test(r == KErrNone);
3628 test(levelOwnerId == -1);
3629 r = lddChan.DeRegisterClient(ClientId[4]);
3630 test(r == KErrNone);
3634 //----------------------------------------------------------------------------------------------
3635 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0594
3637 //! @SYMPREQ PREQ1398
3638 //! @SYMTestCaseDesc This test case tests changing resource state of shared negative resource.
3639 //! @SYMTestActions 0 Register client1
3640 //! 1 Register client2
3641 //! 2 Register client3
3642 //! 3 Register client4
3643 //! 4 Client1 change resource state.
3644 //! 5 Client2 change resource state.
3645 //! 6 Client3 change resource state.
3646 //! 7 Client4 change resource state.
3647 //! 8 Client1 change resource state.
3648 //! 9 Client2 change resource state.
3649 //! 10 Deregister client2
3650 //! 11 Client3 change resource state.
3651 //! 12 Deregister client1
3652 //! 13 Deregister client3
3653 //! 14 Deregister client4
3655 //! @SYMTestExpectedResults 0 Client registered
3656 //! 1 Client registered
3657 //! 2 Client registered
3658 //! 3 Client registered
3659 //! 4 Resource state changed
3660 //! 5 Resource state changed
3661 //! 6 Resource state changed
3662 //! 7 Resource state changed
3663 //! 8 Resource state changed
3664 //! 9 Resource state changed
3665 //! 10 Client2 deregistered
3666 //! 11 Resource state changed
3667 //! 12 Client1 deregistered
3668 //! 13 Client3 deregistered
3669 //! 14 Client4 deregistered
3670 //! @SYMTestPriority High
3671 //! @SYMTestStatus Implemented
3672 //----------------------------------------------------------------------------------------------
3673 void TestRM::SharedBinaryNegativeResourceTesting(TUint aResId)
3680 ClientName[6] = (TUint8)('0' + iMaxClientId+1);
3681 r = lddChan.RegisterClient(ClientId[0], (const TDesC*)&ClientName);
3682 test(r == KErrNone);
3684 r = lddChan.GetResourceStateSync(ClientId[0], Resources[aResId].iResourceId, ETrue, newState, levelOwnerId);
3685 test(r == KErrNone);
3686 if(levelOwnerId != -1)
3688 test.Printf(_L("Not testing the shared resource as some other client is currently holding the resource\n"));
3689 r = lddChan.DeRegisterClient(ClientId[0]);
3690 test(r == KErrNone);
3694 ClientName[6] = (TUint8)('0' + iMaxClientId +2);
3695 r = lddChan.RegisterClient(ClientId[1], (const TDesC*)&ClientName);
3696 test(r == KErrNone);
3697 ClientName[6] = (TUint8)('0' + iMaxClientId +3);
3698 r = lddChan.RegisterClient(ClientId[2], (const TDesC*)&ClientName);
3699 test(r == KErrNone);
3700 ClientName[6] = (TUint8)('0' + iMaxClientId +4);
3701 r = lddChan.RegisterClient(ClientId[3], (const TDesC*)&ClientName);
3702 test(r == KErrNone);
3703 ClientName[6] = (TUint8)('0' + iMaxClientId +5);
3704 r = lddChan.RegisterClient(ClientId[4], (const TDesC*)&ClientName);
3705 test(r == KErrNone);
3708 r = lddChan.ChangeResourceStateSync(ClientId[0], Resources[aResId].iResourceId, newState);
3709 test(r == KErrNone);
3710 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 0, 0);
3711 test(r == KErrNone);
3712 r = lddChan.RequestNotification(ClientId[1], Resources[aResId].iResourceId);
3713 test(r == KErrNone);
3714 r = lddChan.RequestNotification(ClientId[2], Resources[aResId].iResourceId);
3715 test(r == KErrNone);
3716 r = lddChan.RequestNotification(ClientId[3], Resources[aResId].iResourceId, 1, ETrue);
3717 test(r == KErrNone);
3718 r = lddChan.RequestNotification(ClientId[2], Resources[aResId].iResourceId, 0, EFalse);
3719 test(r == KErrNone);
3720 newState = !newState; //State 1
3721 r = lddChan.ChangeResourceStateSync(ClientId[0], Resources[aResId].iResourceId, newState);
3722 test(r == KErrNone);
3723 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 2, 1);
3724 test(r == KErrNone);
3725 newState = !newState; //State 0
3726 r = lddChan.ChangeResourceStateSync(ClientId[1], Resources[aResId].iResourceId, newState);
3727 test(r == KErrNone);
3728 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 2, 1);
3729 test(r == KErrNone);
3730 lddChan.ChangeResourceStateAsync(ClientId[2], Resources[aResId].iResourceId, newState, req);
3731 User::WaitForRequest(req); //State 0
3732 test(req.Int() == KErrNone);
3733 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 0, 0);
3734 test(r == KErrNone);
3735 newState = !newState; //State 1
3736 r = lddChan.ChangeResourceStateSync(ClientId[3], Resources[aResId].iResourceId, newState);
3737 test(r == KErrNone);
3738 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 0, 0);
3739 test(r == KErrNone);
3740 newState = !newState; //state 0
3741 r = lddChan.ChangeResourceStateSync(ClientId[0], Resources[aResId].iResourceId, newState);
3742 test(r == KErrNone);
3743 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 0, 0);
3744 newState = !newState; //state 1
3745 r = lddChan.ChangeResourceStateSync(ClientId[1], Resources[aResId].iResourceId, newState);
3746 test(r == KErrNone);
3747 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 0,0);
3748 test(r == KErrNone);
3749 r = lddChan.DeRegisterClient(ClientId[1]);
3750 test(r == KErrNone);
3752 r = lddChan.ChangeResourceStateSync(ClientId[2], Resources[aResId].iResourceId, newState);
3753 test(r == KErrNone);
3754 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 0,0);
3755 test(r == KErrNone);
3756 r = lddChan.ChangeResourceStateSync(ClientId[0], Resources[aResId].iResourceId, newState);
3757 test(r == KErrNone);
3758 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 1,1);
3759 test(r == KErrNone);
3760 r = lddChan.CancelNotification(ClientId[2], Resources[aResId].iResourceId, EFalse);
3761 test(r == KErrCancel);
3762 r = lddChan.CancelNotification(ClientId[3], Resources[aResId].iResourceId, ETrue);
3763 test(r == KErrCancel);
3765 r = lddChan.ChangeResourceStateSync(ClientId[0], Resources[aResId].iResourceId, newState);
3766 test(r == KErrNone);
3767 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 0, 0);
3768 test(r == KErrNone);
3769 r = lddChan.CancelNotification(ClientId[2], Resources[aResId].iResourceId, ETrue);
3770 test(r == KErrCancel);
3772 r = lddChan.ChangeResourceStateSync(ClientId[0], Resources[aResId].iResourceId, newState);
3773 test(r == KErrNone);
3774 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 0, 0);
3775 test(r == KErrNone);
3776 r = lddChan.DeRegisterClient(ClientId[0]);
3777 test(r == KErrNone);
3778 r = lddChan.DeRegisterClient(ClientId[2]);
3779 test(r == KErrNone);
3780 r = lddChan.DeRegisterClient(ClientId[3]);
3781 test(r == KErrNone);
3782 r = lddChan.GetResourceStateSync(ClientId[4], Resources[aResId].iResourceId, ETrue, newState, levelOwnerId);
3783 test(r == KErrNone);
3784 test(levelOwnerId == -1);
3785 r = lddChan.DeRegisterClient(ClientId[4]);
3786 test(r == KErrNone);
3790 //Test cases to test the shared multilevel negative resources
3791 void TestRM::SharedMultilevelNegativeResourceTesting(TUint aResId)
3798 //Register 1st client
3799 ClientName[6] = (TUint8)('0' + iMaxClientId+1);
3800 r = lddChan.RegisterClient(ClientId[0], (const TDesC*)&ClientName);
3801 test(r == KErrNone);
3803 r = lddChan.GetResourceStateSync(ClientId[0], Resources[aResId].iResourceId, ETrue, newState, levelOwnerId);
3804 test(r == KErrNone);
3805 if(levelOwnerId != -1)
3807 test.Printf(_L("Not testing the shared resource as some other client is currently holding the resource\n"));
3808 r = lddChan.DeRegisterClient(ClientId[0]);
3809 test(r == KErrNone);
3813 test.Printf(_L("Testing %d Shared Multilevel Negative Resource\n"), Resources[aResId].iResourceId);
3815 //Register 2nd client
3816 ClientName[6] = (TUint8)('0' + iMaxClientId+2);
3817 r = lddChan.RegisterClient(ClientId[1], (const TDesC*)&ClientName);
3818 test(r == KErrNone);
3820 //Change the resource and ClientId[0] becomes the owner of the resource
3821 newState = Resources[aResId].iMaxLevel + 10;
3823 r = lddChan.ChangeResourceStateSync(ClientId[0], Resources[aResId].iResourceId, newState);
3824 test(r == KErrNone);
3827 r = lddChan.GetResourceStateSync(ClientId[0], Resources[aResId].iResourceId, ETrue, state, levelOwnerId);
3828 test(r == KErrNone);
3829 test(state == newState);
3830 test(levelOwnerId = (TInt)ClientId[0]);
3832 //Second client(clientId[1]) trying to change the resource, but still
3833 newState = state +5;
3834 lddChan.ChangeResourceStateAsync(ClientId[1], Resources[aResId].iResourceId, newState, req);
3835 User::WaitForRequest(req);
3836 test(req.Int() == KErrNone);
3838 lddChan.GetResourceStateAsync(ClientId[0], Resources[aResId].iResourceId, EFalse, req, newState, levelOwnerId);
3839 User::WaitForRequest(req);
3840 test(req.Int() == KErrNone);
3841 test(state = newState);
3842 test(levelOwnerId == (TInt)ClientId[0]);
3844 newState = state + 10;
3845 r = lddChan.ChangeResourceStateSync(ClientId[0], Resources[aResId].iResourceId, newState);
3846 test(r == KErrNone);
3848 r = lddChan.GetResourceStateSync(ClientId[0], Resources[aResId].iResourceId, EFalse, state, levelOwnerId);
3849 test(r == KErrNone);
3850 newState = Resources[aResId].iMaxLevel + 15;
3851 test(state == newState);
3852 test(levelOwnerId == (TInt)ClientId[1]);
3854 r = lddChan.DeRegisterClientLevelFromResource(ClientId[1], Resources[aResId].iResourceId);
3855 test(r == KErrNone);
3857 state = Resources[aResId].iMaxLevel + 20;
3858 lddChan.GetResourceStateAsync(ClientId[1], Resources[aResId].iResourceId, ETrue, req, newState, levelOwnerId);
3859 User::WaitForRequest(req);
3860 test(req.Int() == KErrNone);
3861 test(state == newState);
3862 test(levelOwnerId == (TInt)ClientId[0]);
3864 newState = Resources[aResId].iMaxLevel + 10;
3865 lddChan.ChangeResourceStateAsync(ClientId[1], Resources[aResId].iResourceId, newState, req);
3866 User::WaitForRequest(req);
3867 test(req.Int() == KErrNone);
3870 lddChan.GetResourceStateAsync(ClientId[0], Resources[aResId].iResourceId, EFalse, req, state, levelOwnerId);
3871 User::WaitForRequest(req);
3872 test(req.Int() == KErrNone);
3873 test(state == newState);
3874 test(levelOwnerId == (TInt)ClientId[1]);
3876 r = lddChan.DeRegisterClient(ClientId[1]);
3877 test(r == KErrNone);
3879 r = lddChan.DeRegisterClientLevelFromResource(ClientId[0], Resources[aResId].iResourceId);
3880 test(r == KErrNone);
3882 r = lddChan.GetResourceStateSync(ClientId[0], Resources[aResId].iResourceId, EFalse, state, levelOwnerId);
3883 test(r == KErrNone);
3884 test(state == Resources[aResId].iDefaultLevel);
3885 test(levelOwnerId == -1);
3887 r = lddChan.DeRegisterClient(ClientId[0]);
3888 test(r == KErrNone);
3893 //Test cases to test the shared multilevel positive resources
3894 void TestRM::SharedMultilevelPositiveResourceTesting(TUint aResId)
3901 //Register 1st client
3902 ClientName[6] = (TUint8)('0' + iMaxClientId+1);
3903 r = lddChan.RegisterClient(ClientId[0], (const TDesC*)&ClientName);
3904 test(r == KErrNone);
3906 r = lddChan.GetResourceStateSync(ClientId[0], Resources[aResId].iResourceId, ETrue, newState, levelOwnerId);
3907 test(r == KErrNone);
3908 if(levelOwnerId != -1)
3910 test.Printf(_L("Not testing the shared resource as some other client is currently holding the resource\n"));
3911 r = lddChan.DeRegisterClient(ClientId[0]);
3912 test(r == KErrNone);
3916 test.Printf(_L("Testing %d Shared Multilevel positive Resource\n"), Resources[aResId].iResourceId);
3918 //Register 2nd client
3919 ClientName[6] = (TUint8)('0' + iMaxClientId+2);
3920 r = lddChan.RegisterClient(ClientId[1], (const TDesC*)&ClientName);
3921 test(r == KErrNone);
3923 //Change the resource and ClientId[0] becomes the owner of the resource
3924 newState = Resources[aResId].iMinLevel + 20;
3926 r = lddChan.ChangeResourceStateSync(ClientId[0], Resources[aResId].iResourceId, newState);
3927 test(r == KErrNone);
3930 r = lddChan.GetResourceStateSync(ClientId[0], Resources[aResId].iResourceId, ETrue, state, levelOwnerId);
3931 test(r == KErrNone);
3932 test(state == newState);
3933 test(levelOwnerId = (TInt)ClientId[0]);
3935 //Second client(clientId[1]) trying to change the resource, but still
3936 newState = Resources[aResId].iMinLevel +10;
3937 lddChan.ChangeResourceStateAsync(ClientId[1], Resources[aResId].iResourceId, newState, req);
3938 User::WaitForRequest(req);
3939 test(req.Int() == KErrNone);
3941 lddChan.GetResourceStateAsync(ClientId[0], Resources[aResId].iResourceId, EFalse, req, newState, levelOwnerId);
3942 User::WaitForRequest(req);
3943 test(req.Int() == KErrNone);
3944 test(state = newState);
3945 test(levelOwnerId == (TInt)ClientId[0]);
3947 newState = Resources[aResId].iMinLevel + 5;
3948 r = lddChan.ChangeResourceStateSync(ClientId[0], Resources[aResId].iResourceId, newState);
3949 test(r == KErrNone);
3951 r = lddChan.GetResourceStateSync(ClientId[0], Resources[aResId].iResourceId, EFalse, state, levelOwnerId);
3952 test(r == KErrNone);
3953 test(state == Resources[aResId].iMinLevel+10);
3954 test(levelOwnerId == (TInt)ClientId[1]);
3956 r = lddChan.DeRegisterClientLevelFromResource(ClientId[1], Resources[aResId].iResourceId);
3957 test(r == KErrNone);
3959 newState = Resources[aResId].iMinLevel + 5;
3960 lddChan.GetResourceStateAsync(ClientId[1], Resources[aResId].iResourceId, ETrue, req, state, levelOwnerId);
3961 User::WaitForRequest(req);
3962 test(req.Int() == KErrNone);
3963 test(state == newState);
3964 test(levelOwnerId == (TInt)ClientId[0]);
3966 newState = Resources[aResId].iMinLevel + 10;
3967 lddChan.ChangeResourceStateAsync(ClientId[1], Resources[aResId].iResourceId, newState, req);
3968 User::WaitForRequest(req);
3969 test(req.Int() == KErrNone);
3972 lddChan.GetResourceStateAsync(ClientId[0], Resources[aResId].iResourceId, EFalse, req, state, levelOwnerId);
3973 User::WaitForRequest(req);
3974 test(req.Int() == KErrNone);
3975 test(state == newState);
3976 test(levelOwnerId == (TInt)ClientId[1]);
3978 r = lddChan.DeRegisterClient(ClientId[1]);
3979 test(r == KErrNone);
3981 r = lddChan.DeRegisterClientLevelFromResource(ClientId[0], Resources[aResId].iResourceId);
3982 test(r == KErrNone);
3984 r = lddChan.GetResourceStateSync(ClientId[0], Resources[aResId].iResourceId, EFalse, state, levelOwnerId);
3985 test(r == KErrNone);
3986 test(state == Resources[aResId].iDefaultLevel);
3987 test(levelOwnerId == -1);
3989 r = lddChan.DeRegisterClient(ClientId[0]);
3990 test(r == KErrNone);
3995 //Custom resource testing. This testing is done only with simulated resources.
3996 //Testing of shared binary positive resource.
3997 //----------------------------------------------------------------------------------------------
3998 //! @SYMTestCaseID KBASE-T_RESCONTROLCLI-0593
4000 //! @SYMPREQ PREQ1398
4001 //! @SYMTestCaseDesc This test case tests changing resource state of shared positive resource.
4002 //! @SYMTestActions 0 Register client1
4003 //! 1 Register client2
4004 //! 2 Register client3
4005 //! 3 Register client4
4006 //! 4 Client1 change resource state.
4007 //! 5 Client2 change resource state.
4008 //! 6 Client3 get resource state.
4009 //! 7 Client4 get resource state.
4010 //! 8 Client1 change resource state.
4011 //! 9 Client2 get resource state.
4012 //! 10 Deregister client2
4013 //! 11 Deregister client1
4014 //! 12 Deregister client3
4015 //! 13 Deregister client4
4017 //! @SYMTestExpectedResults 0 Client registered
4018 //! 1 Client registered
4019 //! 2 Client registered
4020 //! 3 Client registered
4021 //! 4 Resource state changed
4022 //! 5 Resource state changed
4023 //! 6 Resource state read and compared for correctness
4024 //! 7 Resource state read and compared for correctness
4025 //! 8 Resource state changed
4026 //! 9 Resource state read and compared for correctness
4027 //! 10 Client2 deregistered
4028 //! 11 Client1 deregistered
4029 //! 12 Client3 deregistered
4030 //! 13 Client4 deregistered
4031 //! @SYMTestPriority High
4032 //! @SYMTestStatus Implemented
4033 //----------------------------------------------------------------------------------------------
4034 void TestRM::CustomResourceTesting(TUint aResId)
4036 test.Printf(_L("Testing custom function\n"));
4043 ClientName[6] = (TUint8)('0' + iMaxClientId +1);
4044 r = lddChan.RegisterClient(ClientId[0], (const TDesC*)&ClientName);
4045 test(r == KErrNone);
4046 ClientName[6] = (TUint8)('0' + iMaxClientId +2);
4047 r = lddChan.RegisterClient(ClientId[1], (const TDesC*)&ClientName);
4048 test(r == KErrNone);
4049 ClientName[6] = (TUint8)('0' + iMaxClientId +3);
4050 r = lddChan.RegisterClient(ClientId[2], (const TDesC*)&ClientName);
4051 test(r == KErrNone);
4052 ClientName[6] = (TUint8)('0' + iMaxClientId +4);
4053 r = lddChan.RegisterClient(ClientId[3], (const TDesC*)&ClientName);
4054 test(r == KErrNone);
4055 r = lddChan.RequestNotification(ClientId[0], Resources[aResId].iResourceId);
4056 test(r == KErrNone);
4057 r = lddChan.RequestNotification(ClientId[1], Resources[aResId].iResourceId);
4058 test(r == KErrNone);
4061 lddChan.ChangeResourceStateAsync(ClientId[2], Resources[aResId].iResourceId, state, req);
4062 User::WaitForRequest(req); //State 1
4063 test(req.Int() == KErrNone);
4064 test(state == newState);
4065 test(r == KErrNone);
4066 r = lddChan.CheckNotifications(Resources[aResId].iResourceId, 2, 0);
4067 test(r == KErrNone);
4069 lddChan.ChangeResourceStateAsync(ClientId[1], Resources[aResId].iResourceId, state, req);
4070 User::WaitForRequest(req);
4071 test(req.Int() == KErrNone);
4072 test(state == newState);
4073 r = lddChan.GetResourceStateSync(ClientId[0], Resources[aResId].iResourceId, EFalse, state, levelOwnerId);
4074 test(r == KErrNone);
4076 lddChan.ChangeResourceStateAsync(ClientId[0], Resources[aResId].iResourceId, state, req);
4077 User::WaitForRequest(req);
4078 test(req.Int() == KErrNone);
4079 test(state == newState);
4080 r = lddChan.GetResourceStateSync(ClientId[0], Resources[aResId].iResourceId, ETrue, state, levelOwnerId);
4081 test(r == KErrNone);
4082 test((TUint)levelOwnerId == ClientId[2]);
4083 r = lddChan.ChangeResourceStateSync(ClientId[2], Resources[aResId].iResourceId, 0);
4084 test(r == KErrNone);
4085 r = lddChan.GetResourceStateSync(ClientId[0], Resources[aResId].iResourceId, EFalse, state, levelOwnerId);
4086 test(r == KErrNone);
4088 test((TUint)levelOwnerId == ClientId[0]);
4089 r = lddChan.DeRegisterClient(ClientId[0]);
4090 test(r == KErrNone);
4091 r = lddChan.DeRegisterClientLevelFromResource(ClientId[1], Resources[aResId].iResourceId);
4092 test(r == KErrNone);
4093 r= lddChan.DeRegisterClient(ClientId[2]);
4094 test(r == KErrNone);
4095 r = lddChan.GetResourceStateSync(ClientId[3], Resources[aResId].iResourceId, ETrue, state, levelOwnerId);
4096 test(r == KErrNone);
4097 test(levelOwnerId == -1);
4098 r = lddChan.DeRegisterClient(ClientId[3]);
4099 test(r == KErrNone);
4100 r = lddChan.DeRegisterClient(ClientId[1]);
4101 test(r == KErrNone);
4105 //Resource manager operations are chosen randomly and tested for correctness. This is done only in
4106 //simulated resources. Currently this runs for 500 iteration.
4107 //NOTE: Increasing the iteration to more than 500 may fail due to insufficient internal buffers.
4108 void TestRM::RegressionTest()
4110 TUint operation = 0;
4113 NegativeTesting = 0;
4115 iMaxStaticResources = 0;
4116 iMaxStaticDependentResources = 0;
4118 RmTest.RegisterClient();
4119 iCurrentClientId = -1;
4120 r = lddChan.GetResourceControllerVersion(Clients[0].iClientId, iTestingExtendedVersion);
4122 test.Printf(_L("Return value of GetResourceControllerVersion %d\n"), r);
4123 test(r == KErrNone);
4124 if(!iTestingExtendedVersion)
4125 test.Printf(_L("Testing Basic Version only...."));
4127 test.Printf(_L("Testing basic & extended version...."));
4128 RmTest.GetNumResourcesInUseByClient(iCurrentClientId);
4129 RmTest.GetInfoOnResourcesInUseByClient(iCurrentClientId, iMaxStaticResources);
4130 if(!(Resources[0].iName.Compare(*(const TDesC8*)&SpecialResName)))
4132 TBuf8<32> PowerController = _L8("PowerController");
4133 r = lddChan.GetClientId(Clients[0].iClientId, (TDesC8&)PowerController, iPowerControllerId);
4134 test(r == KErrNone);
4138 test.Printf(_L("Regression testing is run only on simulator"));
4142 for(count = 0; count < 500; count++)
4144 operation = Math::Random() % EOperationEnd;
4145 iCurrentClientId = Math::Random() % iMaxClients;
4146 resourceId = Math::Random() % iMaxStaticResources;
4147 if(operation != ERegisterClient)
4149 if(Clients[iCurrentClientId].iClientId == 0) //Not a valid client
4152 if(Resources[resourceId].iSense == ECustom)
4154 test.Printf(_L("\nOperation = %d, ClientId = %d, ResourceId = %d\n"), operation, iCurrentClientId, resourceId);
4157 case ERegisterClient:
4158 RmTest.RegisterClient();
4160 case EGetClientName:
4161 RmTest.GetClientName(iCurrentClientId);
4163 case EGetAllClientName:
4164 RmTest.GetClientName(0);
4167 RmTest.GetClientId(iCurrentClientId);
4169 case EGetResourceId:
4170 RmTest.GetResourceId(resourceId);
4172 case EGetResourceInfo:
4173 RmTest.GetResourceInfo(resourceId);
4175 case EGetNumReosourceInUseByClient:
4176 RmTest.GetNumResourcesInUseByClient(iCurrentClientId);
4178 case EGetInfoOnResourceInUseByClient:
4179 test.Printf(_L("NumResources = %d\n"), Clients[iCurrentClientId].iNumResources);
4180 RmTest.GetInfoOnResourcesInUseByClient(iCurrentClientId, Clients[iCurrentClientId].iNumResources);
4182 case EGetNumClientsUsingResource:
4185 RmTest.GetNumClientsUsingResource(iCurrentClientId, (TUint)-1);
4189 RmTest.GetNumClientsUsingResource(iCurrentClientId, resourceId);
4192 case EGetInfoOnClientsUsingResource:
4194 RmTest.GetInfoOnClientsUsingResource((TUint)-1, iMaxClients+1);
4197 test.Printf(_L("NumResources = %d\n"), Resources[resourceId].iNumClients);
4198 RmTest.GetInfoOnClientsUsingResource(resourceId, Resources[resourceId].iNumClients);
4201 case EChangeResourceStateSync:
4202 RmTest.ChangeResourceStateSync(resourceId);
4204 case EChangeResourceStateAsync:
4205 RmTest.ChangeResourceStateAsync(resourceId);
4207 case EGetResourceStateSync:
4208 RmTest.GetResourceStateSync(resourceId);
4210 case EGetResourceStateAsync:
4211 RmTest.GetResourceStateAsync(resourceId);
4213 case ERequestNotificationCond:
4214 RmTest.RequestNotificationCon(resourceId);
4216 case ERequestNotificationUnCond:
4217 RmTest.RequestNotification(resourceId);
4219 case ECancelNotificationCond:
4220 RmTest.CancelNotification(resourceId, ETrue);
4222 case ECancelNotificationUnCond:
4223 RmTest.CancelNotification(resourceId, EFalse);
4228 test.Printf(_L("Cleanup of all Clients\n"));
4229 TInt clientCount = Clients.Count();
4230 for(count = clientCount-1; ((TInt)count) >=0; count--)
4232 if(Clients[count].iClientId == 0)
4234 test.Printf(_L("ClientId deregistration of %d\n"), Clients[count].iClientId);
4235 RmTest.DeRegisterClient(count);
4240 GLDEF_C TInt E32Main()
4243 test.Start(_L("Testing Resource Manager...\n"));
4244 test.Next(_L("Load Physical device"));
4245 #ifndef PRM_ENABLE_EXTENDED_VERSION
4246 r = User::LoadPhysicalDevice(KPddFileName);
4247 test(r==KErrNone || r==KErrAlreadyExists);
4248 test.Next(_L("Load Logical Device"));
4249 r=User::LoadLogicalDevice(KLddFileName);
4250 test(r==KErrNone || r==KErrAlreadyExists);
4251 __KHEAP_MARK; //Heap testing is done only for basic version
4253 r = User::LoadPhysicalDevice(KExtPddFileName);
4254 test(r==KErrNone || r==KErrAlreadyExists);
4255 test.Next(_L("Load Logical Device"));
4256 r=User::LoadLogicalDevice(KExtLddFileName);
4257 test(r==KErrNone || r==KErrAlreadyExists);
4260 test(r==KErrNone || r==KErrAlreadyExists);
4261 //Check whether the notifications recieved as a result of postboot level setting is as expected.
4262 r = lddChan.CheckPostBootLevelNotifications();
4263 test(r == KErrNone);
4264 TBool regressionTesting = EFalse;
4265 //Parse the command line arguments.
4267 User::CommandLine(cmd);
4270 if(lex.Get() == '-')
4272 TChar letter = lex.Get();
4273 if((letter == 'R') || (letter == 'r'))
4274 regressionTesting = ETrue;
4276 if(regressionTesting)
4277 RmTest.RegressionTest();
4279 RmTest.APIValidationTest();
4280 test.Printf(_L("Closing the channel\n"));
4282 test.Printf(_L("Freeing logical device\n"));
4283 #ifndef PRM_ENABLE_EXTENDED_VERSION
4285 r = User::FreeLogicalDevice(KLddFileName);
4287 r = User::FreePhysicalDevice(KPddFileName);
4290 r = User::FreeLogicalDevice(KExtLddFileName);
4292 r = User::FreePhysicalDevice(KExtPddFileName);
4295 User::After(100000);