kerneltest/e32test/resmanus/t_resmanus.cpp
branchRCL_3
changeset 43 c1f20ce4abcf
parent 0 a41df078684a
child 44 3e88ff8f41d5
equal deleted inserted replaced
42:a179b74831c9 43:c1f20ce4abcf
    41 _LIT(testName,"t_resmanus");
    41 _LIT(testName,"t_resmanus");
    42 #endif
    42 #endif
    43 
    43 
    44 TBuf<16> gTestName(testName);
    44 TBuf<16> gTestName(testName);
    45 
    45 
    46 GLDEF_D RTest gTest(testName);
       
    47 GLDEF_D RBusDevResManUs gChannel;
    46 GLDEF_D RBusDevResManUs gChannel;
    48 
    47 
    49 TUint8 KNoOfGetStateRequests = 5;
    48 TUint8 KNoOfGetStateRequests = 5;
    50 TUint8 KNoOfSetStateRequests = 4;
    49 TUint8 KNoOfSetStateRequests = 4;
    51 TUint8 KNoOfNotifyRequests = 7;
    50 TUint8 KNoOfNotifyRequests = 7;
    72 TBool gHaveSharedRes = ETrue;
    71 TBool gHaveSharedRes = ETrue;
    73 TInt gSharedResStateDelta = -1;
    72 TInt gSharedResStateDelta = -1;
    74 #endif
    73 #endif
    75 
    74 
    76 TBool gUseCached = EFalse;
    75 TBool gUseCached = EFalse;
       
    76 
       
    77 class RTestSafe: public RTest
       
    78 	{
       
    79 public:
       
    80 	RTestSafe(const TDesC &aTitle) :
       
    81 		RTest(aTitle), iCleanUpLevelMask (0), iFailHdnFunc(NULL)
       
    82 		{
       
    83 		}
       
    84 	RTestSafe(const TDesC &aTitle, void(*func)(RTestSafe &aTest)) :
       
    85 		RTest(aTitle), iFailHdnFunc(func)
       
    86 		{
       
    87 		}
       
    88 
       
    89 	// new version of operator(int), which calls our cleanup handler if check has failed
       
    90 	void operator()(TInt aResult)
       
    91 		{
       
    92 		if(!aResult && iFailHdnFunc)
       
    93 			iFailHdnFunc(*this);
       
    94 		RTest::operator ()(aResult);
       
    95 		}
       
    96 
       
    97 	void operator()(TInt aResult, TInt aLineNum)
       
    98 		{
       
    99 		if(!aResult && iFailHdnFunc)
       
   100 			iFailHdnFunc(*this);
       
   101 		RTest::operator ()(aResult, aLineNum);
       
   102 		}
       
   103 
       
   104 	void operator()(TInt aResult, TInt aLineNum, const TText* aFileName)
       
   105 		{
       
   106 		if(!aResult && iFailHdnFunc)
       
   107 			iFailHdnFunc(*this);
       
   108 		RTest::operator ()(aResult, aLineNum, aFileName);
       
   109 		}
       
   110 
       
   111 	// new version of End, which calls handler before exit..
       
   112 	void End()
       
   113 		{
       
   114 		if(iFailHdnFunc)
       
   115 			iFailHdnFunc(*this);
       
   116 		RTest::End();
       
   117 		}
       
   118 
       
   119 	void SetCleanupFlag(TUint aFlag)
       
   120 		{
       
   121 		iCleanUpLevelMask |= 1 << aFlag;
       
   122 		}
       
   123 
       
   124 	TBool CleanupNeeded(TUint aFlag)
       
   125 		{
       
   126 		return (iCleanUpLevelMask & (1 << aFlag)) >> aFlag;
       
   127 		}
       
   128 
       
   129 	TUint iCleanUpLevelMask;
       
   130 	void (*iFailHdnFunc)(RTestSafe &aTest);
       
   131 	};
       
   132 
       
   133 // cleanup handler
       
   134 enum TCleanupLevels
       
   135 	{
       
   136 	EPddLoaded = 0,
       
   137 	ELddLoaded,
       
   138 	EChannelOpened
       
   139 	};
       
   140 
       
   141 
       
   142 void TestCleanup(RTestSafe &aTest)
       
   143 	{
       
   144 	// cleanup for all 3 levels..
       
   145 	if(aTest.CleanupNeeded(EChannelOpened))
       
   146 		{
       
   147 		gChannel.Close();
       
   148 		}
       
   149 
       
   150 	if(aTest.CleanupNeeded(ELddLoaded))
       
   151 		{
       
   152 		User::FreeLogicalDevice(KLddRootName);
       
   153 		}
       
   154 
       
   155 	if(aTest.CleanupNeeded(EPddLoaded))
       
   156 		{
       
   157 		User::FreePhysicalDevice(PDD_NAME);
       
   158 		}
       
   159 	}
       
   160 
       
   161 // global gTest object..
       
   162 RTestSafe gTest(testName, &TestCleanup);
       
   163 
       
   164 LOCAL_C TInt CheckCaps()
       
   165 	{
       
   166 	TInt r = KErrNone;
       
   167 	RDevice d;
       
   168 	TPckgBuf<TCapsDevResManUs> caps;
       
   169 	r = d.Open(KLddRootName);
       
   170 	if(r == KErrNone)
       
   171 		{
       
   172 		d.GetCaps(caps);
       
   173 		d.Close();
       
   174 
       
   175 		TVersion ver = caps().version;
       
   176 		if(ver.iMajor != 1 || ver.iMinor != 0 || ver.iBuild != KE32BuildVersionNumber)
       
   177 			{
       
   178 			gTest.Printf(_L("Capabilities returned wrong version"));
       
   179 			gTest.Printf(_L("Expected(1, 0, %d), got (%d , %d, %d)"),
       
   180 			                KE32BuildVersionNumber, ver.iMajor, ver.iMinor, ver.iBuild);
       
   181 			r = KErrGeneral;
       
   182 			}
       
   183 		}
       
   184 	return r;
       
   185 	}
    77 
   186 
    78 LOCAL_C TInt OpenChannel(TDesC16& aName, RBusDevResManUs& aChannel)
   187 LOCAL_C TInt OpenChannel(TDesC16& aName, RBusDevResManUs& aChannel)
    79 	{
   188 	{
    80 	TInt r = KErrNone;
   189 	TInt r = KErrNone;
    81 	// API accepts 8-bit descriptors, only - so convert name accordingly
   190 	// API accepts 8-bit descriptors, only - so convert name accordingly
  1137 		if((r=HelperGetClientResourceInfo())!=KErrNone)
  1246 		if((r=HelperGetClientResourceInfo())!=KErrNone)
  1138 			return r;
  1247 			return r;
  1139 		}
  1248 		}
  1140 
  1249 
  1141 
  1250 
  1142 	// Fourth invocation - examine effect of orignal client requesting a level for 
  1251 	// Fourth invocation - examine effect of oryginal client requesting a level for 
  1143 	// the Shared resource
  1252 	// the Shared resource
  1144 	if(gHaveSharedRes)
  1253 	if(gHaveSharedRes)
  1145 		{
  1254 		{
  1146 		TRequestStatus status;
  1255 		TRequestStatus status;
  1147 		TBool cached = gUseCached;
  1256 		TBool cached = gUseCached;
  1183 			gTest.Printf(_L("TestGetClientGetResourceInfo, attempt to reset shareable resource state returned %d\n"),r);
  1292 			gTest.Printf(_L("TestGetClientGetResourceInfo, attempt to reset shareable resource state returned %d\n"),r);
  1184 			return r;
  1293 			return r;
  1185 			}
  1294 			}
  1186 		}
  1295 		}
  1187 
  1296 
  1188 
       
  1189 	// Close the temporary channels
  1297 	// Close the temporary channels
  1190 	channelTwo.Close();
  1298 	channelTwo.Close();
  1191 	channelThree.Close();
  1299 	channelThree.Close();
  1192 	channelFour.Close();
  1300 	channelFour.Close();
  1193 
  1301 
  1341 //
  1449 //
  1342 	{
  1450 	{
  1343 	TInt r = KErrNone;
  1451 	TInt r = KErrNone;
  1344 
  1452 
  1345 	TRequestStatus status;
  1453 	TRequestStatus status;
       
  1454 	TRequestStatus status2;
  1346 	TBool cached = gUseCached;
  1455 	TBool cached = gUseCached;
  1347 	TInt readValue = 0;
  1456 	TInt readValue = 0;
       
  1457 	TInt readValue2 = 0;
  1348 	TInt levelOwnerId = 0;
  1458 	TInt levelOwnerId = 0;
  1349 	TInt testNo = 0;
  1459 	TInt testNo = 0;
  1350 
  1460 
  1351 #ifdef _DEBUG
  1461 #ifdef _DEBUG
  1352 	// Ensure we have a resource we can use
  1462 	// Ensure we have a resource we can use
  1522 		return r;
  1632 		return r;
  1523 		}
  1633 		}
  1524 
  1634 
  1525 	// 8) Call API to get the state of a long latency resource then call API without operation-type qualifier to cancel the request.
  1635 	// 8) Call API to get the state of a long latency resource then call API without operation-type qualifier to cancel the request.
  1526 	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
  1636 	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
       
  1637 	
       
  1638 	// NOTE: Cancel operation can only remove request which is still inside the resource controller
       
  1639 	// message queue. If the queue is empty, the resource controller may process the request very quickly
       
  1640 	// after it is sent. It may cause the test fail. To solve this, two get long latency resource state 
       
  1641 	// requests are submitted. So that the second one must be inside the resource controller. 
       
  1642 	// And we will always test the second request
       
  1643 	
  1527 	gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
  1644 	gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId);
       
  1645 	gChannel.GetResourceState(status2,gLongLatencyResource,cached,&readValue2,&levelOwnerId);
  1528 	gChannel.CancelAsyncOperation(&status);
  1646 	gChannel.CancelAsyncOperation(&status);
       
  1647 	gChannel.CancelAsyncOperation(&status2);
  1529 	User::WaitForRequest(status);
  1648 	User::WaitForRequest(status);
  1530 	if(status.Int() != KErrCancel)
  1649 	User::WaitForRequest(status2);
       
  1650 	if(status2.Int() != KErrCancel)
  1531 		{
  1651 		{
  1532 		gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status = %d\n"),r);
  1652 		gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status = %d\n"),r);
  1533 		return r;
  1653 		return r;
  1534 		}
  1654 		}
  1535 
  1655 
  1536 	// 9) Call API to modify the state of the long latency resource then call API without operation-type qualifier to cancel the request.
  1656 	// 9) Call API to modify the state of the long latency resource then call API without operation-type qualifier to cancel the request.
  1537 	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
  1657 	gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++);
       
  1658 	
       
  1659 	// NOTE: Cancel operation can only remove request which is still inside the resource controller
       
  1660 	// message queue. If the queue is empty, the resource controller may process the request very quickly
       
  1661 	// after it is sent. It may cause the test fail. To solve this, two get long latency resource state 
       
  1662 	// requests are submitted. So that the second one must be inside the resource controller. 
       
  1663 	// And we will always test the second request
       
  1664 		
  1538 	newLevel = (TUint)(readValue + gAsyncResStateDelta);
  1665 	newLevel = (TUint)(readValue + gAsyncResStateDelta);
  1539 	gChannel.ChangeResourceState(status,gLongLatencyResource,newLevel);
  1666 	gChannel.ChangeResourceState(status,gLongLatencyResource,newLevel);
       
  1667 	gChannel.ChangeResourceState(status2,gLongLatencyResource,newLevel);
  1540 	gChannel.CancelAsyncOperation(&status);
  1668 	gChannel.CancelAsyncOperation(&status);
       
  1669 	gChannel.CancelAsyncOperation(&status2);
  1541 	User::WaitForRequest(status);
  1670 	User::WaitForRequest(status);
  1542 	if(status.Int() != KErrCancel)
  1671 	User::WaitForRequest(status2);
       
  1672 	if(status2.Int() != KErrCancel)
  1543 		{
  1673 		{
  1544 		gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status = %d\n"),r);
  1674 		gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status = %d\n"),r);
  1545 		return r;
  1675 		return r;
  1546 		}
  1676 		}
  1547 
  1677 
  1595 		}
  1725 		}
  1596 	gChannel.CancelGetResourceStateRequests(gLongLatencyResource);
  1726 	gChannel.CancelGetResourceStateRequests(gLongLatencyResource);
  1597 	for(i=0;i<KLoopVarN;i++)
  1727 	for(i=0;i<KLoopVarN;i++)
  1598 		{
  1728 		{
  1599 		User::WaitForRequest(getReqStatus[i]);
  1729 		User::WaitForRequest(getReqStatus[i]);
  1600 		if((r=getReqStatus[i].Int()) != KErrCancel)
  1730 
       
  1731 	// NOTE: Cancel operation can only remove request which is still inside the resource controller
       
  1732 	// message queue. If the queue is empty, the resource controller may process the request very quickly
       
  1733 	// after it is sent. It may cause the test fail. To solve this, we skip the test for request 0.
       
  1734 			
       
  1735 		if(i>0 && ((r=getReqStatus[i].Int()) != KErrCancel))
  1601 			{
  1736 			{
  1602 			gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status[%d] = %d\n"),i,r);
  1737 			gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status[%d] = %d\n"),i,r);
  1603 			return r;
  1738 			return r;
  1604 			}
  1739 			}
  1605 		}
  1740 		}
  1613 		}
  1748 		}
  1614 	gChannel.CancelChangeResourceStateRequests(gLongLatencyResource);
  1749 	gChannel.CancelChangeResourceStateRequests(gLongLatencyResource);
  1615 	for(i=0;i<KLoopVarM;i++)
  1750 	for(i=0;i<KLoopVarM;i++)
  1616 		{
  1751 		{
  1617 		User::WaitForRequest(setReqStatus[i]);
  1752 		User::WaitForRequest(setReqStatus[i]);
  1618 		if((r=setReqStatus[i].Int()) != KErrCancel)
  1753 		
       
  1754 	// NOTE: Cancel operation can only remove request which is still inside the resource controller
       
  1755 	// message queue. If the queue is empty, the resource controller may process the request very quickly 
       
  1756 	// after it is sent. It may cause the test fail. To solve this, we skip the test for request 0.
       
  1757 		
       
  1758 		if(i>0 && ((r=setReqStatus[i].Int()) != KErrCancel))
  1619 			{
  1759 			{
  1620 			gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status[%d] = %d\n"),i,r);
  1760 			gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status[%d] = %d\n"),i,r);
  1621 			return r;
  1761 			return r;
  1622 			}
  1762 			}
  1623 		}
  1763 		}
  1689 		}
  1829 		}
  1690 	gChannel.CancelGetResourceStateRequests(gLongLatencyResource);
  1830 	gChannel.CancelGetResourceStateRequests(gLongLatencyResource);
  1691 	for(i=0;i<KLoopVarN;i++)
  1831 	for(i=0;i<KLoopVarN;i++)
  1692 		{
  1832 		{
  1693 		User::WaitForRequest(getReqStatus[i]);
  1833 		User::WaitForRequest(getReqStatus[i]);
  1694 		if((r=getReqStatus[i].Int()) != KErrCancel)
  1834 
       
  1835 	// NOTE: Cancel operation can only remove request which is still inside the resource controller
       
  1836 	// message queue. If the queue is empty, the resource controller may process the request very quickly 
       
  1837 	// after it is sent. It may cause the test fail. To solve this, we skip the test for request 0.
       
  1838 		
       
  1839 		if(i>0 && ((r=getReqStatus[i].Int()) != KErrCancel))
  1695 			{
  1840 			{
  1696 			gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status[%d] = %d\n"),i,r);
  1841 			gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status[%d] = %d\n"),i,r);
  1697 			return r;
  1842 			return r;
  1698 			}
  1843 			}
  1699 		}
  1844 		}
  1842 	for(i=0;i<KLoopVarN;i+=2)
  1987 	for(i=0;i<KLoopVarN;i+=2)
  1843 		{
  1988 		{
  1844 		r=gChannel.CancelGetResourceState(getReqStatus[i]);
  1989 		r=gChannel.CancelGetResourceState(getReqStatus[i]);
  1845 		if(r!=KErrNone)
  1990 		if(r!=KErrNone)
  1846 			{
  1991 			{
  1847 			gTest.Printf(_L("TestGetSetResourceStateOps, CancelGetResourceState for index %d returned %d\n"),i,r);
  1992 
  1848 			return r;
  1993 	// NOTE: Cancel operation can only remove request which is still inside the resource controller
       
  1994 	// message queue. If the queue is empty, the resource controller may process the request very quickly 
       
  1995 	// after it is sent. It may cause the test fail. To solve this, we skip the test for request 0.
       
  1996 			
       
  1997 			if(i!=0)
       
  1998 				{
       
  1999 				gTest.Printf(_L("TestGetSetResourceStateOps, CancelGetResourceState for index %d returned %d\n"),i,r);
       
  2000 				return r;
       
  2001 				}
  1849 			}
  2002 			}
  1850 		}
  2003 		}
  1851 	for(i=0;i<KLoopVarM;i++)
  2004 	for(i=0;i<KLoopVarM;i++)
  1852 		{
  2005 		{
  1853 		User::WaitForRequest(setReqStatus[i]);
  2006 		User::WaitForRequest(setReqStatus[i]);
  1866 			}
  2019 			}
  1867 		}
  2020 		}
  1868 	for(i=0;i<KLoopVarN;i++)
  2021 	for(i=0;i<KLoopVarN;i++)
  1869 		{
  2022 		{
  1870 		User::WaitForRequest(getReqStatus[i]);
  2023 		User::WaitForRequest(getReqStatus[i]);
  1871 		if((r=getReqStatus[i].Int()) != KErrCancel)
  2024 
       
  2025 	// NOTE: Cancel operation can only remove request which is still inside the resource controller
       
  2026 	// message queue. If the queue is empty, the resource controller may process the request very quickly 
       
  2027 	// after it is sent. It may cause the test fail. To solve this, we skip the test for request 0.
       
  2028 		
       
  2029 		if(i>0 && ((r=getReqStatus[i].Int()) != KErrCancel))
  1872 			{
  2030 			{
  1873 			gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status[%d] = %d\n"),i,r);
  2031 			gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status[%d] = %d\n"),i,r);
  1874 			return r;
  2032 			return r;
  1875 			}
  2033 			}
  1876 		if(++i >= KLoopVarN)
  2034 		if(++i >= KLoopVarN)
  2871 	if((r=pirateChannel.Duplicate(RThread(),EOwnerProcess))!=KErrAccessDenied)
  3029 	if((r=pirateChannel.Duplicate(RThread(),EOwnerProcess))!=KErrAccessDenied)
  2872 		{
  3030 		{
  2873 		gTest.Printf(_L("TestThreadExclusiveAccess: Duplicate with EOwnerProcess returned %d\n"),r);
  3031 		gTest.Printf(_L("TestThreadExclusiveAccess: Duplicate with EOwnerProcess returned %d\n"),r);
  2874 		if(r==KErrNone)
  3032 		if(r==KErrNone)
  2875 			r=KErrGeneral;
  3033 			r=KErrGeneral;
  2876 		return r;
  3034 		return r; // return error which is neither KErrNone nor KErrAccessDenied
  2877 		}
  3035 		}
  2878 	pirateChannel = gChannel;
  3036 	pirateChannel = gChannel;
  2879 	if((r=pirateChannel.Duplicate(RThread(),EOwnerThread))!=KErrNone)
  3037 	if((r=pirateChannel.Duplicate(RThread(),EOwnerThread))!=KErrNone)
  2880 		{
  3038 		{
  2881 		gTest.Printf(_L("TestThreadExclusiveAccess: Duplicate with EOwnerThread returned %d\n"),r);
  3039 		gTest.Printf(_L("TestThreadExclusiveAccess: Duplicate with EOwnerThread returned %d\n"),r);
  2995 #else
  3153 #else
  2996 	if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numClients, ETrue)) != KErrPermissionDenied)
  3154 	if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numClients, ETrue)) != KErrPermissionDenied)
  2997 		{
  3155 		{
  2998 		if(r==KErrNone)
  3156 		if(r==KErrNone)
  2999 			r=KErrGeneral;
  3157 			r=KErrGeneral;
  3000 		return r;
  3158 		return r; // return error which is neither KErrPermissionDenied nor KErrGeneral
  3001 		}
  3159 		}
  3002 	else
  3160 	else
  3003 		r=KErrNone; // Ensure misleading result is not propagated
  3161 		r=KErrNone; // Ensure misleading result is not propagated
  3004 #endif
  3162 #endif
  3005 	infoPtrs.Close();
  3163 	infoPtrs.Close();
  3075 #else
  3233 #else
  3076 		if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numClients, ETrue)) != KErrPermissionDenied)
  3234 		if((r=secThrdChannel.GetNamesAllClients(&infoPtrs, numClients, ETrue)) != KErrPermissionDenied)
  3077 			{
  3235 			{
  3078 			if(r==KErrNone)
  3236 			if(r==KErrNone)
  3079 				r=KErrGeneral;
  3237 				r=KErrGeneral;
  3080 			return r;
  3238 			return r; // return error which is neither KErrPermissionDenied nor KErrGeneral
  3081 			}
  3239 			}
  3082 		else
  3240 		else
  3083 			r=KErrNone; // Ensure misleading result is not propagated
  3241 			r=KErrNone; // Ensure misleading result is not propagated
  3084 #endif
  3242 #endif
  3085 		infoPtrs.Close();
  3243 		infoPtrs.Close();
  3769 			return KErrGeneral;
  3927 			return KErrGeneral;
  3770 			}
  3928 			}
  3771 		if((r=gChannel.GetInfoOnClientsUsingResource(gSharedResource, numClients, &infoPtrs, EFalse))!=KErrNotReady)
  3929 		if((r=gChannel.GetInfoOnClientsUsingResource(gSharedResource, numClients, &infoPtrs, EFalse))!=KErrNotReady)
  3772 			{
  3930 			{
  3773 			gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource (for gSharedResource) returned %d\n"),r);
  3931 			gTest.Printf(_L("TestTransientHandling: GetInfoOnClientsUsingResource (for gSharedResource) returned %d\n"),r);
  3774 			return r;
  3932 			return KErrGeneral;
  3775 			}
  3933 			}
  3776 		infoPtrs.Close();
  3934 		infoPtrs.Close();
  3777 		}
  3935 		}
  3778 
  3936 
  3779 
  3937 
  4078 
  4236 
  4079 EXPORT_C TInt E32Main()
  4237 EXPORT_C TInt E32Main()
  4080 //
  4238 //
  4081 // Main
  4239 // Main
  4082 //
  4240 //
  4083     {
  4241 	{
       
  4242 	gTest.Title();
  4084 	gTest.Start(_L("Test Power Resource Manager user side API\n"));
  4243 	gTest.Start(_L("Test Power Resource Manager user side API\n"));
  4085   
       
  4086 	TInt r = KErrNone;
       
  4087 
  4244 
  4088 	// Test attempted load of PDD
  4245 	// Test attempted load of PDD
  4089     gTest.Next(_L("**Load PDD\n"));
  4246 	gTest.Next(_L("**Load PDD\n"));
  4090     r=User::LoadPhysicalDevice(PDD_NAME);
  4247 	TInt r = User::LoadPhysicalDevice(PDD_NAME);
  4091     if((r!=KErrNone)&&(r!=KErrAlreadyExists))
  4248 	gTest((r == KErrNone) || (r == KErrAlreadyExists));
  4092 		{
  4249 	gTest.SetCleanupFlag(EPddLoaded);
  4093 		gTest.Printf(_L("User::LoadPhysicalDevice error %d\n"),r);
  4250 
  4094 		}
  4251 	// Test attempted load of LDD
  4095 	else
  4252 	gTest.Next(_L("**Load LDD\n"));
  4096 		{
  4253 	r = User::LoadLogicalDevice(LDD_NAME);
  4097 		// Test attempted load of LDD
  4254 	gTest((r == KErrNone) || (r == KErrAlreadyExists));
  4098 		gTest.Next(_L("**Load LDD\n"));
  4255 	r = KErrNone; // Re-initialise in case set to KErrAlreadyExists
  4099 		r=User::LoadLogicalDevice(LDD_NAME);
  4256 	gTest.SetCleanupFlag(ELddLoaded);
  4100 		if((r!=KErrNone)&&(r!=KErrAlreadyExists))
  4257 
  4101 			gTest.Printf(_L("User::LoadLogicalDevice error - expected %d, got %d\n"),KErrAlreadyExists,r);
  4258 	// test caps
  4102 		}
  4259 	gTest(CheckCaps() == KErrNone);
  4103     if((r==KErrNone)||(r==KErrAlreadyExists))
  4260 
  4104 		{
  4261 	// Need a channel open for the following tests
  4105 		r = KErrNone; // Re-initialise in case set to KErrAlreadyExists
  4262 	gTest.Next(_L("**OpenAndRegisterChannel\n"));
  4106 		//
  4263 	r = OpenAndRegisterChannel();
  4107 		// Need a channel open for the following tests
  4264 	gTest(r == KErrNone);
  4108 		gTest.Next(_L("**OpenAndRegisterChannel\n"));
  4265 	gTest.SetCleanupFlag(EChannelOpened);
  4109 		r=OpenAndRegisterChannel();
  4266 
  4110 		if (r==KErrNone)
  4267 	// Get the version of the ResourceController
  4111 			{
  4268 	TUint version;
  4112 			// Get the version of the ResourceController
  4269 	r = gChannel.GetResourceControllerVersion(version);
  4113 			TUint version;
  4270 	gTest.Printf(_L("TestTransientHandling: ResourceController version =0x%x\n"), version);
  4114 			if((r=gChannel.GetResourceControllerVersion(version))!=KErrNone)
  4271 	gTest(r == KErrNone);
  4115 				{
  4272 
  4116 				gTest.Printf(_L("TestTransientHandling: GetResourceControllerVersion returned %d\n"),r);
  4273 	gTest.Next(_L("**TestThreadExclusiveAccess\n"));
  4117 				return r;
  4274 	r = TestThreadExclusiveAccess();
  4118 				}
  4275 	gTest(r == KErrNone);
  4119 			gTest.Printf(_L("TestTransientHandling: ResourceController version =0x%x\n"),version);
  4276 
  4120 			}
  4277 	gTest.Next(_L("**TestGetClientGetResourceInfo - initial state\n"));
  4121 		if (r==KErrNone)
  4278 	r = TestGetClientGetResourceInfo();
  4122 			{
  4279 	gTest(r == KErrNone);
  4123 			gTest.Next(_L("**TestThreadExclusiveAccess\n"));
  4280 
  4124 			r=TestThreadExclusiveAccess();
  4281 	gTest.Next(_L("**TestGetSetResourceStateOps\n"));
  4125 			}
  4282 	r = TestGetSetResourceStateOps();
  4126 		if (r==KErrNone)
  4283 	gTest(r == KErrNone);
  4127 			{
  4284 
  4128 			gTest.Next(_L("**TestGetClientGetResourceInfo - initial state\n"));
  4285 	gTest.Next(_L("**TestGetClientGetResourceInfo - after changing stateof Async resource\n"));
  4129 			r=TestGetClientGetResourceInfo();
  4286 	r = TestGetClientGetResourceInfo();
  4130 			}
  4287 	gTest(r == KErrNone);
  4131 		if (r==KErrNone)
  4288 
  4132 			{
  4289 	gTest.Next(_L("**TestGetSetResourceStateQuota\n"));
  4133 			gTest.Next(_L("**TestGetSetResourceStateOps\n"));
  4290 	r = TestGetSetResourceStateQuota();
  4134 			r=TestGetSetResourceStateOps();
  4291 	gTest(r == KErrNone);
  4135 			}
  4292 
  4136 		if (r==KErrNone)
  4293 	gTest.Next(_L("**TestNotificationOps\n"));
  4137 			{
  4294 	r = TestNotificationOps();
  4138 			gTest.Next(_L("**TestGetClientGetResourceInfo - after changing stateof Async resource\n"));
  4295 	gTest(r == KErrNone);
  4139 			r=TestGetClientGetResourceInfo();
  4296 
  4140 			}
  4297 	gTest.Next(_L("**TestNotificationQuota\n"));
  4141 		if (r==KErrNone)
  4298 	r = TestNotificationQuota();
  4142 			{
  4299 	gTest(r == KErrNone);
  4143 			gTest.Next(_L("**TestGetSetResourceStateQuota\n"));
  4300 
  4144 			r=TestGetSetResourceStateQuota();
  4301 	// Should be no change since last invocation (assuming that
  4145 			}
  4302 	// no clients other than those in this test)
  4146 		if (r==KErrNone)
  4303 	gTest.Next(_L("**TestGetClientGetResourceInfo - last invocation\n"));
  4147 			{
  4304 	r = TestGetClientGetResourceInfo();
  4148 			gTest.Next(_L("**TestNotificationOps\n"));
  4305 	gTest(r == KErrNone);
  4149 			r=TestNotificationOps();
  4306 
  4150 			}
  4307 	gTest.Next(_L("**TestAdditionalThread\n"));
  4151 		if (r==KErrNone)
  4308 	r = TestAdditionalThread();
  4152 			{
  4309 	gTest(r == KErrNone);
  4153 			gTest.Next(_L("**TestNotificationQuota\n"));
  4310 
  4154 			r=TestNotificationQuota();
  4311 	gTest.Next(_L("**TestTransientHandling\n"));
  4155 			}
  4312 	r = TestTransientHandling();
  4156 		if (r==KErrNone)
  4313 	gTest(r == KErrNone);
  4157 			{
       
  4158 			// Should be no change since last invocation (assuming that
       
  4159 			// no clients other than those in this test)
       
  4160 			gTest.Next(_L("**TestGetClientGetResourceInfo - last invocation\n"));
       
  4161 			r=TestGetClientGetResourceInfo();
       
  4162 			}
       
  4163 		if (r==KErrNone)
       
  4164 			{
       
  4165 			gTest.Next(_L("**TestAdditionalThread\n"));
       
  4166 			r=TestAdditionalThread();
       
  4167 			}
       
  4168 		if (r==KErrNone)
       
  4169 			{
       
  4170 			gTest.Next(_L("**TestTransientHandling\n"));
       
  4171 			r=TestTransientHandling();
       
  4172 			}
       
  4173 		}
       
  4174 	gChannel.Close();
       
  4175 
       
  4176     User::FreeLogicalDevice(KLddRootName);
       
  4177     User::FreePhysicalDevice(PDD_NAME);	
       
  4178 	User::After(100000);	// Allow idle thread to run for driver unloading
       
  4179 
  4314 
  4180 	gTest.End();
  4315 	gTest.End();
  4181 	return r;
  4316 	return KErrNone;
  4182     }
  4317 	}
  4183 
  4318 
       
  4319