resourcemgmt/hwresourcesmgr/test/te_hwrm/hwrmtestbase.cpp
changeset 0 4e1aa6a622a0
child 70 653a8b91b95e
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     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 "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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // te_hwrm.exe
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <centralrepository.h>
       
    19 #include <hwrmvibrasdkcrkeys.h>
       
    20 #include <hwrmlightdomaincrkeys.h>
       
    21 #include <hwrmpowerdomaincrkeys.h>
       
    22 #include <hwrmfmtxdomaincrkeys.h>
       
    23 #include <hwrmfmtxaudiopolicydomainpskeys.h>
       
    24 #include "HWRMFmTxInternalCRKeys.h"
       
    25 #include "hwrmtestbase.h"
       
    26 #include "hwrmtestmacros.h"
       
    27 #include "HWRMPrivatePSKeys.h"
       
    28 
       
    29 _LIT(KVibraModeON, "EVibraModeON");
       
    30 _LIT(KVibraModeOFF, "EVibraModeOFF");
       
    31 _LIT(KVibraModeUnknown, "EVibraModeUnknown");
       
    32 
       
    33 _LIT(KVibraStatusUnknown, "EVibraStatusUnknown");
       
    34 _LIT(KVibraStatusNotAllowed, "EVibraStatusNotAllowed");
       
    35 _LIT(KVibraStatusStopped, "EVibraStatusStopped");
       
    36 _LIT(KVibraStatusOn, "EVibraStatusOn");
       
    37 
       
    38 _LIT(KLightStatusUnknown, "ELightStatusUnknown");
       
    39 _LIT(KLightOn, "ELightOn");
       
    40 _LIT(KLightOff, "ELightOff");
       
    41 _LIT(KLightBlink, "ELightBlink");
       
    42 
       
    43 _LIT(KFmTxStateOff, "EFmTxStateOff");
       
    44 _LIT(KFmTxStateActive, "EFmTxStateActive");
       
    45 _LIT(KFmTxStateInactive, "EFmTxStateInactive");
       
    46 _LIT(KFmTxStatePowerSaveInactivity, "EFmTxStatePowerSaveInactivity");
       
    47 _LIT(KFmTxStatePowerSaveAccessory, "EFmTxStatePowerSaveAccessory");
       
    48 _LIT(KFmTxStateScanning, "EFmTxStateScanning");
       
    49 _LIT(KFmTxStateUnknown, "EFmTxStateUnkown");
       
    50 
       
    51 
       
    52 void CHWRMTestBase::OpenSessionsL(TInt aNoLightSessionsToOpen, TInt aNoVibraSessionsToOpen, TInt aNoExtLightSessionsToOpen, TInt aNoFmTxSessionsToOpen, TInt aNoPowerSessionsToOpen)
       
    53 	{
       
    54 	INFO_PRINTF1(_L("--START CHWRMTestBase::OpenSessionsL"));
       
    55 	aNoLightSessionsToOpen = (aNoLightSessionsToOpen>KMaxNoOpenSessionsForResource) ? KMaxNoOpenSessionsForResource: aNoLightSessionsToOpen;
       
    56 	aNoVibraSessionsToOpen = (aNoVibraSessionsToOpen>KMaxNoOpenSessionsForResource) ? KMaxNoOpenSessionsForResource: aNoVibraSessionsToOpen;
       
    57 	aNoExtLightSessionsToOpen = (aNoExtLightSessionsToOpen>KMaxNoOpenSessionsForResource) ? KMaxNoOpenSessionsForResource: aNoExtLightSessionsToOpen;
       
    58 	aNoPowerSessionsToOpen = (aNoPowerSessionsToOpen>KMaxNoOpenSessionsForResource) ? KMaxNoOpenSessionsForResource: aNoPowerSessionsToOpen;
       
    59 	aNoFmTxSessionsToOpen = (aNoFmTxSessionsToOpen>KMaxNoOpenSessionsForResource) ? KMaxNoOpenSessionsForResource: aNoFmTxSessionsToOpen;
       
    60 	
       
    61 	for(TInt i = 0; i < aNoVibraSessionsToOpen; i++)
       
    62 		{
       
    63 		if(i==0)
       
    64 			{
       
    65 			//used first session as one listening for callbacks
       
    66 			iVibraSessions[i] = CHWRMVibra::NewL(this);
       
    67 			}
       
    68 		else
       
    69 			{
       
    70 			iVibraSessions[i] = CHWRMVibra::NewL();	
       
    71 			}		
       
    72 		}
       
    73 
       
    74 	for(TInt i = 0; i < aNoLightSessionsToOpen; i++)
       
    75 		{
       
    76 		if(i==0)
       
    77 			{
       
    78 			//used first session as one listening for callbacks
       
    79 			INFO_PRINTF1(_L("CHWRMTestBase::OpenSessionsL - BEFORE CREATING FIRST LIGHT SESSION"));
       
    80 			iLightSessions[i] = CHWRMLight::NewL(this);
       
    81 			INFO_PRINTF1(_L("CHWRMTestBase::OpenSessionsL - AFTER CREATING FIRST LIGHT SESSION"));
       
    82 			}
       
    83 		else
       
    84 			{
       
    85 			iLightSessions[i] = CHWRMLight::NewL();	
       
    86 			}		
       
    87 		}
       
    88 
       
    89 	for(TInt i = 0; i < aNoExtLightSessionsToOpen; i++)
       
    90 		{
       
    91 		if(i==0)
       
    92 			{
       
    93 			//used first session as one listening for callbacks
       
    94 			iExtLightSessions[i] = CHWRMExtendedLight::NewL(this);
       
    95 			}
       
    96 		else
       
    97 			{
       
    98 			iExtLightSessions[i] = CHWRMExtendedLight::NewL();	
       
    99 			}		
       
   100 		}
       
   101 	
       
   102 	for(TInt i = 0; i < aNoPowerSessionsToOpen; i++)
       
   103 		{
       
   104 		if(i==0)
       
   105 			{
       
   106 			//used first session as one listening for callbacks
       
   107 			iPowerSessions[i] = CHWRMPower::NewL();	
       
   108 			}
       
   109 		else
       
   110 			{
       
   111 			iPowerSessions[i] = CHWRMPower::NewL();	
       
   112 			}
       
   113 		}
       
   114 	
       
   115 	for(TInt i = 0; i <  aNoFmTxSessionsToOpen; i++)
       
   116 		{
       
   117 		if(i==0)
       
   118 			{
       
   119 			//used first session as one listening for callbacks
       
   120 			iFmTxSessions[i] = CHWRMFmTx::NewL(this);
       
   121 			}
       
   122 		else
       
   123 			{
       
   124 			iFmTxSessions[i] =  CHWRMFmTx::NewL();	
       
   125 			}		
       
   126 		}
       
   127 
       
   128 	INFO_PRINTF1(_L("CHWRMTestBase::OpenSessionsL - BEFORE OPENING MOCKSY SESSIONS"));
       
   129 	// Open sessions to MockSY	
       
   130 	if (aNoLightSessionsToOpen > 0 && !iIsMockLightSessionOpen)
       
   131 		{
       
   132 		User::LeaveIfError(iMockLight.Connect());
       
   133 		iIsMockLightSessionOpen = ETrue;
       
   134 		}
       
   135 	if (aNoVibraSessionsToOpen > 0 && !iIsMockVibraSessionOpen)
       
   136 		{
       
   137 		User::LeaveIfError(iMockVibra.Connect());
       
   138 		iIsMockVibraSessionOpen = ETrue;
       
   139 		}
       
   140 	if (aNoExtLightSessionsToOpen > 0 && !iIsMockLightSessionOpen)
       
   141 		{
       
   142 		User::LeaveIfError(iMockLight.Connect());
       
   143 		iIsMockLightSessionOpen = ETrue;
       
   144 		}
       
   145 	if (aNoPowerSessionsToOpen > 0 && !iIsMockPowerSessionOpen)
       
   146 		{
       
   147 		User::LeaveIfError(iMockPower.Connect());
       
   148 		iIsMockPowerSessionOpen = ETrue;
       
   149 		}
       
   150 	if (aNoFmTxSessionsToOpen > 0 && !iIsMockFmTxSessionOpen)
       
   151 		{
       
   152 		User::LeaveIfError(iMockFmTx.Connect());
       
   153 		iIsMockFmTxSessionOpen = ETrue;
       
   154 		}
       
   155 	
       
   156 	INFO_PRINTF1(_L("--END CHWRMTestBase::OpenSessionsL"));	
       
   157 	}
       
   158 
       
   159 void CHWRMTestBase::OpenLightSessionEnhancedL(TInt aNoEnhancedLightSessionsToOpen)
       
   160 	{
       
   161 	INFO_PRINTF1(_L("--START CHWRMTestBase::OpenEnhancedLightSessionL"));
       
   162 	aNoEnhancedLightSessionsToOpen = (aNoEnhancedLightSessionsToOpen>KMaxNoOpenSessionsForResource) ? KMaxNoOpenSessionsForResource: aNoEnhancedLightSessionsToOpen;
       
   163 	
       
   164 	for(TInt i = 0; i < aNoEnhancedLightSessionsToOpen; i++)
       
   165 		{
       
   166 		if(i==0)
       
   167 			{
       
   168 			//used first session as one listening for callbacks
       
   169 			iEnhancedLightSessions[i] = CHWRMEnhancedLight::NewL(this);
       
   170 			}
       
   171 		else
       
   172 			{
       
   173 			iEnhancedLightSessions[i] = CHWRMEnhancedLight::NewL();	
       
   174 			}		
       
   175 		}
       
   176 	
       
   177 	INFO_PRINTF1(_L("CHWRMTestBase::OpenEnhancedLightSessionL - BEFORE OPENING MOCKSY SESSIONS"));
       
   178 	// Open sessions to MockSY	
       
   179 	if (aNoEnhancedLightSessionsToOpen > 0 && !iIsMockLightSessionOpen)
       
   180 		{
       
   181 		User::LeaveIfError(iMockLight.Connect());
       
   182 		iIsMockLightSessionOpen = ETrue;
       
   183 		}
       
   184 	INFO_PRINTF1(_L("--END CHWRMTestBase::OpenSessionsL"));	
       
   185 	}
       
   186 
       
   187 void CHWRMTestBase::OpenPowerStateSessionL()
       
   188 	{
       
   189 	if (!iIsMockPowerStateSessionOpen)
       
   190 		{
       
   191 		User::LeaveIfError(iMockPowerState.Connect());
       
   192 		iIsMockPowerStateSessionOpen = ETrue;
       
   193 		}
       
   194 		
       
   195 	// P&S property observers
       
   196 	CleanupPropertyObservers();
       
   197 	
       
   198 	iBatteryLevelObserver = CPsPropertyObserver::NewL(KPSUidHWRMPowerState, KHWRMBatteryLevel,*this);
       
   199 	iBatteryStatusObserver = CPsPropertyObserver::NewL(KPSUidHWRMPowerState, KHWRMBatteryStatus,*this);
       
   200 	iChargingStatusObserver = CPsPropertyObserver::NewL(KPSUidHWRMPowerState, KHWRMChargingStatus,*this);
       
   201 	}
       
   202 
       
   203 void CHWRMTestBase::CleanupPropertyObservers()
       
   204 	{
       
   205 	delete iBatteryLevelObserver;
       
   206 	iBatteryLevelObserver = NULL;
       
   207 	delete iBatteryStatusObserver;
       
   208 	iBatteryLevelObserver = NULL;
       
   209 	delete iChargingStatusObserver;
       
   210 	iBatteryLevelObserver = NULL;	
       
   211 	}
       
   212 
       
   213 void CHWRMTestBase::GetCRVibraAttributeL(TUint32 aVibraKey, TInt &aValue)
       
   214 	{
       
   215 	CRepository* rep = CRepository::NewLC(KCRUidVibraCtrl);
       
   216     User::LeaveIfError(rep->Get(aVibraKey, aValue));
       
   217     CleanupStack::PopAndDestroy(rep);
       
   218 	}
       
   219 
       
   220 
       
   221 void CHWRMTestBase::GetVibraTimeAttributesL()
       
   222 	{
       
   223 	GetCRVibraAttributeL(KVibraMinOffTime, iVibraMinOffTime);
       
   224     if ( iVibraMinOffTime < 0 )
       
   225         {
       
   226         iVibraMinOffTime = 0;  // do not allow negative value
       
   227         }
       
   228     
       
   229     GetCRVibraAttributeL(KVibraCtrlMaxTime, iVibraMaxOnTime);
       
   230     if ( iVibraMaxOnTime < 0 )
       
   231         {
       
   232         iVibraMaxOnTime = 0;  // do not allow negative value
       
   233         }
       
   234         
       
   235     GetCRVibraAttributeL(KVibraCtrlFeedbackIntensity, iPulseMaxIntensity);
       
   236     if ( iPulseMaxIntensity < 0 )
       
   237         {
       
   238         iPulseMaxIntensity = 0;  // do not allow negative value
       
   239         }
       
   240         
       
   241     GetCRVibraAttributeL(KVibraCtrlFeedbackDuration, iPulseMaxDuration);
       
   242     if ( iPulseMaxDuration < 0 )
       
   243         {
       
   244         iPulseMaxDuration = 0;  // do not allow negative value
       
   245         }
       
   246     }
       
   247     
       
   248 	
       
   249 void CHWRMTestBase::SetCRVibraAttributeL(TUint32 aVibraKey, TInt aValue)
       
   250 	{
       
   251 	CRepository* rep = CRepository::NewLC(KCRUidVibraCtrl);
       
   252     User::LeaveIfError(rep->Set(aVibraKey, aValue));
       
   253 	CleanupStack::PopAndDestroy(rep);
       
   254 	}
       
   255 
       
   256 TInt CHWRMTestBase::SetCRVibraAttribute(TUint32 aVibraKey, TInt aValue)
       
   257 	{
       
   258 	CRepository* rep = CRepository::NewL(KCRUidVibraCtrl);
       
   259     TInt err = rep->Set(aVibraKey, aValue);
       
   260 	return err;
       
   261 	}
       
   262 
       
   263 void CHWRMTestBase::SetCRLightAttributes(TUint32 aLightKey, TInt aValue)
       
   264 	{
       
   265     
       
   266 	CRepository* rep = CRepository::NewLC(KCRUidLightSettings);
       
   267     User::LeaveIfError(rep->Set(aLightKey, aValue));
       
   268 	CleanupStack::PopAndDestroy(rep);
       
   269 	}
       
   270 
       
   271 void CHWRMTestBase::GetCRLightAttributes(TUint32 aLightKey, TInt &aValue)
       
   272 	{
       
   273 	CRepository* rep = CRepository::NewLC(KCRUidLightSettings);
       
   274     User::LeaveIfError(rep->Get(aLightKey, aValue));
       
   275     CleanupStack::PopAndDestroy(rep);
       
   276 	}
       
   277 
       
   278 void CHWRMTestBase::SetLightControlAttributes(TInt aIntensity, TInt aSensitivity, TInt aInUse)
       
   279 	{
       
   280 	iLightDefaultIntensity = aIntensity;
       
   281 	iLightDefaultSensitivity = aSensitivity;
       
   282 	iLightSensorEnabled = aInUse;
       
   283 	
       
   284 	SetCRLightAttributes(KLightIntensity, iLightDefaultIntensity);
       
   285 	SetCRLightAttributes(KLightSensorSensitivity, iLightDefaultSensitivity);
       
   286 	SetCRLightAttributes(KLightSensorInUse, iLightSensorEnabled);
       
   287 	}
       
   288 
       
   289 void CHWRMTestBase::GetLightControlAttributes()
       
   290 	{
       
   291 	GetCRVibraAttributeL(KLightIntensity, iLightDefaultIntensity);
       
   292 	GetCRVibraAttributeL(KLightSensorSensitivity, iLightDefaultSensitivity);
       
   293 	GetCRVibraAttributeL(KLightSensorInUse, iLightSensorEnabled);
       
   294 	}
       
   295 
       
   296 void CHWRMTestBase::GetCRPowerAttributeL(TUint32 aPowerKey, TInt &aValue)
       
   297 	{
       
   298 	CRepository* rep = CRepository::NewLC(KCRUidPowerSettings);
       
   299     User::LeaveIfError(rep->Get(aPowerKey, aValue));
       
   300     CleanupStack::PopAndDestroy(rep);
       
   301 	}
       
   302 
       
   303 void CHWRMTestBase::GetPowerAttributesL()
       
   304 	{
       
   305 	TInt value;
       
   306 	GetCRVibraAttributeL(KPowerBaseTimeInterval, value);
       
   307 	iPowerBaseIntervalMicroSeconds = 1000 * value; //from milli to microseconds
       
   308 	GetCRVibraAttributeL(KPowerMaxReportingPeriod, value); //from milli to microseconds
       
   309 	iPowerMaxReportingPeriodMicroSeconds = 1000 * value;
       
   310 	}
       
   311 
       
   312 void CHWRMTestBase::SetCRPowerAttributeL(TUint32 aPowerKey, TInt aValue)
       
   313 	{
       
   314 	CRepository* rep = CRepository::NewLC(KCRUidPowerSettings);
       
   315     User::LeaveIfError(rep->Set(aPowerKey, aValue));
       
   316 	CleanupStack::PopAndDestroy(rep);
       
   317 	}
       
   318 
       
   319 void CHWRMTestBase::SetCRFmTxAttributeL(TUint32 aFmTxKey, TInt aValue)
       
   320 	{
       
   321 	CRepository* rep = CRepository::NewLC(KCRUidFmTxCenRes);
       
   322     User::LeaveIfError(rep->Set(aFmTxKey, aValue));
       
   323     CleanupStack::PopAndDestroy(rep);
       
   324 	}
       
   325 
       
   326 void CHWRMTestBase::GetCRFmTxAttributeL(TUint32 aFmTxKey, TInt &aValue)
       
   327 	{
       
   328 	CRepository* rep = CRepository::NewLC(KCRUidFmTxCenRes);
       
   329     User::LeaveIfError(rep->Get(aFmTxKey, aValue));
       
   330     CleanupStack::PopAndDestroy(rep);
       
   331 	}
       
   332 
       
   333 void CHWRMTestBase::GetFmTxFrequencyStepSizeL()
       
   334 	{
       
   335 	GetCRFmTxAttributeL(KFmTxCenResKeyStepSize, iFmTxFrequencyStepSize);
       
   336 	}
       
   337 
       
   338 void CHWRMTestBase::SetFmTxFrequencyRangeEuropeL()
       
   339 	{
       
   340 	SetCRFmTxAttributeL(KFmTxCenResKeyMinFrequency, 88100);
       
   341 	SetCRFmTxAttributeL(KFmTxCenResKeyMaxFrequency, 107900);
       
   342 	SetCRFmTxAttributeL(KFmTxCenResKeyStepSize, 50);
       
   343 	}
       
   344 
       
   345 void CHWRMTestBase::SetFmTxFrequencyRangeJapanL()
       
   346 	{
       
   347 	SetCRFmTxAttributeL(KFmTxCenResKeyMinFrequency, 88100);
       
   348 	SetCRFmTxAttributeL(KFmTxCenResKeyMaxFrequency, 90000);
       
   349 	SetCRFmTxAttributeL(KFmTxCenResKeyStepSize, 50);
       
   350 	}
       
   351 
       
   352 void CHWRMTestBase::SetFmTxInactivityTimeOutL(TUint aInactivityTimeOut)
       
   353 	{
       
   354 	SetCRFmTxAttributeL(KFmTxCenResKeyPowerSaveTimerLength, aInactivityTimeOut);
       
   355 	}
       
   356 
       
   357 void CHWRMTestBase::ExpectBatteryLevelNotificationL(EPSHWRMBatteryLevel aBatteryLevel)
       
   358 	{
       
   359 	iExpectedBatteryLevelNotifications.AppendL(aBatteryLevel);
       
   360 	}
       
   361 
       
   362 void CHWRMTestBase::ExpectBatteryStatusNotificationL(EPSHWRMBatteryStatus aStatus)
       
   363 	{
       
   364 	iExpectedBatteryStatusNotifications.AppendL(aStatus);
       
   365 	}
       
   366 
       
   367 void CHWRMTestBase::ExpectedChargingStatusNotificationsL(EPSHWRMChargingStatus aStatus)
       
   368 	{
       
   369 	iExpectedChargingStatusNotifications.AppendL(aStatus);
       
   370 	}
       
   371 	
       
   372 void CHWRMTestBase::ExpectVibraStatusNotificationL(CHWRMVibra::TVibraStatus aStatus)
       
   373 	{
       
   374 	iExpectedVibraStatusNotifications.AppendL(aStatus);
       
   375 	}
       
   376 	
       
   377 void CHWRMTestBase::ExpectLightStatusNotificationL(TInt aTarget, CHWRMLight::TLightStatus aStatus)
       
   378 	{
       
   379 	if (IgnoringStatusNotifications())
       
   380 		{
       
   381 		return;
       
   382 		}
       
   383 		
       
   384 	TLightNotification notification;
       
   385 	notification.iTarget = aTarget;
       
   386 	notification.iStatus = aStatus; 	
       
   387 	iExpectedLightNotifications.AppendL(notification);
       
   388 	}
       
   389 
       
   390 void CHWRMTestBase::ExpectExtLightStatusNotificationL(TInt aTarget, CHWRMExtendedLight::TLightStatus aStatus)
       
   391 	{
       
   392 	if (IgnoringStatusNotifications())
       
   393 		{
       
   394 		return;
       
   395 		}
       
   396 		
       
   397 	TExtLightNotification notification;
       
   398 	notification.iTarget = aTarget;
       
   399 	notification.iStatus = aStatus; 	
       
   400 	iExpectedExtLightNotifications.AppendL(notification);
       
   401 	}
       
   402 
       
   403 void CHWRMTestBase::ExpectFmTxStatusNotificationL(TFmTxState aStatus1,TFmTxState aStatus2)
       
   404 	{
       
   405 	TFmTxNotification notification;
       
   406 	
       
   407 	notification.iState1=aStatus1;
       
   408 	notification.iState2=aStatus2;
       
   409 	
       
   410 	iExpectedFmTxStatusNotifications.AppendL(notification);
       
   411 	}
       
   412 
       
   413 void CHWRMTestBase::ExpectFmTxStatusNotificationL(TFmTxState aStatus)
       
   414 	{
       
   415 	ExpectFmTxStatusNotificationL(aStatus, aStatus);
       
   416 	}
       
   417 
       
   418 void CHWRMTestBase::ExpectFmTxFrequencyNotificationL(TInt aFrequency)
       
   419 	{
       
   420 	iExpectedFmTxFrequencyNotifications.AppendL(aFrequency);
       
   421 	}
       
   422 
       
   423 void CHWRMTestBase::ExpectVibraModeNotificationL()
       
   424 	{
       
   425 	TInt value(-1);
       
   426 	GetCRVibraAttributeL(KVibraCtrlProfileVibraEnabled,value);
       
   427 	
       
   428 
       
   429 	CHWRMVibra::TVibraModeState expectedVibraMode = 
       
   430 			(value == 0) ? CHWRMVibra::EVibraModeOFF : CHWRMVibra::EVibraModeON;
       
   431 		
       
   432 	
       
   433 	ExpectVibraModeNotificationL(expectedVibraMode);
       
   434 	}
       
   435 		
       
   436 void CHWRMTestBase::ExpectVibraModeNotificationL(CHWRMVibra::TVibraModeState aState)
       
   437 	{
       
   438 	iExpectedVibraModeNotifications.AppendL(aState);
       
   439 	}
       
   440 
       
   441 void CHWRMTestBase::ExpectVibraFeedbackModeNotificationL(CHWRMVibra::TVibraFeedbackModeState aState)
       
   442 	{
       
   443 	iExpectedVibraFeedbackModeNotifications.AppendL(aState);
       
   444 	}
       
   445 
       
   446 //callbacks of state change
       
   447  void CHWRMTestBase::VibraModeChanged(CHWRMVibra::TVibraModeState aStatus)
       
   448  	{
       
   449  	switch (aStatus)
       
   450         {
       
   451 	    case CHWRMVibra::EVibraModeUnknown:
       
   452 	        INFO_PRINTF1(_L("Vibra mode changed: EVibraModeUnknown"));
       
   453 	        break;
       
   454 	    case CHWRMVibra::EVibraModeON:
       
   455 	        INFO_PRINTF1(_L("Vibra mode changed: EVibraModeON"));
       
   456 	        break;
       
   457 	    case CHWRMVibra::EVibraModeOFF:
       
   458 	        INFO_PRINTF1(_L("Vibra mode changed: EVibraModeOFF"));
       
   459 	        break;
       
   460 	    default:
       
   461 	        INFO_PRINTF1(_L("Vibra mode changed: UNDEFINED ! "));
       
   462 	        break;
       
   463         }
       
   464   	
       
   465   	if (iExpectedVibraModeNotifications.Count() > 0)
       
   466   		{
       
   467   		if (aStatus != iExpectedVibraModeNotifications[0])
       
   468   			{
       
   469 	  		INFO_PRINTF3(_L("### ERROR: VibraModeChanged, expected:%d, actual:%d"),iExpectedVibraModeNotifications[0],aStatus);
       
   470 	  		SetTestFail();
       
   471   			}
       
   472         iExpectedVibraModeNotifications.Remove(0);
       
   473  		}
       
   474  	else
       
   475  		{
       
   476  	  	INFO_PRINTF2(_L("### ERROR: VibraModeChanged, expected:NONE, actual:%d"),aStatus);
       
   477 	  	SetTestFail();
       
   478  		}
       
   479     CheckForEndOfTransition();
       
   480  	}
       
   481 
       
   482 void CHWRMTestBase::VibraStatusChanged(CHWRMVibra::TVibraStatus aStatus)
       
   483 	{
       
   484 	switch (aStatus)
       
   485         {
       
   486     case CHWRMVibra::EVibraStatusUnknown:
       
   487         INFO_PRINTF1(_L("Vibra state changed: EVibraStatusUnknown"));
       
   488         break;
       
   489     case CHWRMVibra::EVibraStatusNotAllowed:
       
   490         INFO_PRINTF1(_L("Vibra state changed: EVibraStatusNotAllowed"));
       
   491         break;
       
   492     case CHWRMVibra::EVibraStatusStopped:
       
   493         INFO_PRINTF1(_L("Vibra state changed: EVibraStatusStopped"));        
       
   494         break;
       
   495     case CHWRMVibra::EVibraStatusOn:
       
   496         INFO_PRINTF1(_L("Vibra state changed: EVibraStatusOn"));
       
   497         break;
       
   498     default:
       
   499         INFO_PRINTF1(_L("Vibra state changed: UNDEFINED !"));
       
   500         break;
       
   501         }
       
   502         
       
   503    	if (iExpectedVibraStatusNotifications.Count() > 0)
       
   504   		{
       
   505   		if (aStatus != iExpectedVibraStatusNotifications[0])
       
   506   			{
       
   507 	  		INFO_PRINTF3(_L("### ERROR: VibraStatusChanged, expected:%d, actual:%d"),iExpectedVibraStatusNotifications[0],aStatus);
       
   508 	  		SetTestFail();
       
   509   			}        
       
   510         iExpectedVibraStatusNotifications.Remove(0);        
       
   511  		}
       
   512  	else
       
   513  		{
       
   514  	  	INFO_PRINTF2(_L("### ERROR: VibraStatusChanged, expected:NONE, actual:%d"),aStatus);
       
   515 	  	SetTestFail();
       
   516  		}
       
   517     CheckForEndOfTransition();
       
   518 	}
       
   519 
       
   520 void CHWRMTestBase::VibraFeedbackModeChanged(CHWRMVibra::TVibraFeedbackModeState aMode)
       
   521     {	
       
   522 	switch(aMode)
       
   523 	    {
       
   524 		case CHWRMVibra::EVibraFeedbackModeUnknown:
       
   525 			INFO_PRINTF1(_L("Vibra Feedback Mode changed to EVibraFeedbackModeUnknown"));			
       
   526 		    break;		
       
   527 		case CHWRMVibra::EVibraFeedbackModeON:
       
   528 			INFO_PRINTF1(_L("Vibra Feedback Mode changed to EVibraFeedbackModeON"));					    
       
   529 		    break;		
       
   530 		case CHWRMVibra::EVibraFeedbackModeOFF:
       
   531 			INFO_PRINTF1(_L("Vibra Feedback Mode changed to EVibraFeedbackModeOFF"));	
       
   532 		    break;							
       
   533 		default:
       
   534 			INFO_PRINTF2(_L("Vibra Feedback Mode changed to %d"), aMode);
       
   535     	}
       
   536   	if (iExpectedVibraFeedbackModeNotifications.Count() > 0)
       
   537   		{
       
   538   		if (aMode != iExpectedVibraFeedbackModeNotifications[0])
       
   539   			{
       
   540 	  		INFO_PRINTF3(_L("### ERROR: VibraFeedbackModeChanged, expected:%d, actual:%d"),iExpectedVibraModeNotifications[0],aMode);
       
   541 	  		SetTestFail();
       
   542   			}
       
   543         iExpectedVibraFeedbackModeNotifications.Remove(0);
       
   544  		}
       
   545  	else
       
   546  		{
       
   547  	  	INFO_PRINTF2(_L("### ERROR: VibraFeedbackModeChanged, expected:NONE, actual:%d"), aMode);
       
   548 	  	SetTestFail();
       
   549  		}
       
   550     CheckForEndOfTransition();    	    	
       
   551     }
       
   552     
       
   553 void CHWRMTestBase::LightStatusChanged(TInt aTarget, CHWRMLight::TLightStatus aStatus)
       
   554 	{
       
   555     switch (aStatus)
       
   556         {
       
   557 	    case CHWRMLight::ELightOn:
       
   558 	        INFO_PRINTF2(_L("Light state changed: ELightOn, target:%d"),aTarget);
       
   559 	        break;
       
   560 	    case CHWRMLight::ELightOff:
       
   561 	        INFO_PRINTF2(_L("Light state changed: ELightOff, target:%d"),aTarget);
       
   562 	        break;
       
   563 	    case CHWRMLight::ELightBlink:
       
   564 	        INFO_PRINTF2(_L("Light state changed: ELightBlink, target:%d"),aTarget);
       
   565 	        break;
       
   566 	    case CHWRMLight::ELightStatusUnknown:
       
   567 	        INFO_PRINTF2(_L("Light state changed: ELightStatusUnknown, target:%d"),aTarget);
       
   568 	        break;
       
   569 	    default:
       
   570 	        INFO_PRINTF1(_L("Light state changed: UNDEFINED !"));
       
   571 	        break;
       
   572         }
       
   573 
       
   574 	if (iExpectedLightNotifications.Count() > 0)
       
   575 		{
       
   576 		if 	( 
       
   577   				(aStatus != iExpectedLightNotifications[0].iStatus || aTarget != iExpectedLightNotifications[0].iTarget)
       
   578   			&&	(IgnoringStatusNotifications() == EFalse) && (iTearingDown == EFalse)
       
   579   		    )
       
   580   			{
       
   581 	  		INFO_PRINTF5(_L("### ERROR: LightStatusChanged, expected: target=%d, status=%d, actual: target=%d, status=%d"),
       
   582 	  			iExpectedLightNotifications[0].iTarget,iExpectedLightNotifications[0].iStatus, aTarget, aStatus);
       
   583 	  		SetTestFail();
       
   584   			}
       
   585   		else
       
   586   			{
       
   587   			INFO_PRINTF3(_L("INFO: LightStatusChanged, target=%d, status=%d"),aTarget,aStatus);
       
   588   			}
       
   589   		iExpectedLightNotifications.Remove(0);
       
   590 		}
       
   591 		
       
   592   		
       
   593 	// ignore notifications during teardown	or if we have chosen to do so
       
   594  	else if ( (iTearingDown == EFalse) && (IgnoringStatusNotifications() == EFalse) )
       
   595  		{
       
   596  	  	INFO_PRINTF3(_L("### ERROR: LightStatusChanged, expected:NONE, actual: target=%d, status=%d"),aTarget,aStatus);
       
   597 	  	SetTestFail();
       
   598  		}
       
   599  	else
       
   600  		{
       
   601  		INFO_PRINTF3(_L("INFO: LightStatusChanged, target=%d, status=%d"),aTarget,aStatus);
       
   602  		}
       
   603  		
       
   604     CheckForEndOfTransition();
       
   605 	}
       
   606 
       
   607 void CHWRMTestBase::LightStatusChanged(TInt aTarget, CHWRMExtendedLight::TLightStatus aStatus)
       
   608 	{
       
   609     switch (aStatus)
       
   610         {
       
   611 	    case CHWRMExtendedLight::ELightOn:
       
   612 	        INFO_PRINTF2(_L("Light state changed: ELightOn, target:%d"),aTarget);
       
   613 	        break;
       
   614 	    case CHWRMExtendedLight::ELightOff:
       
   615 	        INFO_PRINTF2(_L("Light state changed: ELightOff, target:%d"),aTarget);
       
   616 	        break;
       
   617 	    case CHWRMExtendedLight::ELightBlink:
       
   618 	        INFO_PRINTF2(_L("Light state changed: ELightBlink, target:%d"),aTarget);
       
   619 	        break;
       
   620 	    case CHWRMExtendedLight::ELightStatusUnknown:
       
   621 	        INFO_PRINTF2(_L("Light state changed: ELightStatusUnknown, target:%d"),aTarget);
       
   622 	        break;
       
   623 	    default:
       
   624 	        INFO_PRINTF1(_L("Light state changed: UNDEFINED !"));
       
   625 	        break;
       
   626         }
       
   627         
       
   628 	if (iExpectedExtLightNotifications.Count() > 0)
       
   629 		{
       
   630 		if 	( 
       
   631   				(aStatus != iExpectedExtLightNotifications[0].iStatus || aTarget != iExpectedExtLightNotifications[0].iTarget)
       
   632   			&&	(IgnoringStatusNotifications() == EFalse) && (iTearingDown == EFalse)
       
   633   		    )
       
   634   			{
       
   635 	  		INFO_PRINTF5(_L("### ERROR: LightStatusChanged, expected: target=%d, status=%d, actual: target=%d, status=%d"),
       
   636 	  			iExpectedLightNotifications[0].iTarget,iExpectedLightNotifications[0].iStatus, aTarget, aStatus);
       
   637 	  		SetTestFail();
       
   638   			}
       
   639   		else
       
   640   			{
       
   641   			INFO_PRINTF3(_L("INFO: LightStatusChanged, target=%d, status=%d"),aTarget,aStatus);
       
   642   			}
       
   643 		iExpectedExtLightNotifications.Remove(0);
       
   644 		}
       
   645 	// ignore notifications during teardown	or if we have chosen to do so
       
   646  	else if ( (iTearingDown == EFalse) && (IgnoringStatusNotifications() == EFalse) )
       
   647  		{
       
   648  	  	INFO_PRINTF3(_L("### ERROR: LightStatusChanged, expected:NONE, actual: target=%d, status=%d"),aTarget,aStatus);
       
   649 	  	SetTestFail();
       
   650  		}
       
   651  	else
       
   652  		{
       
   653  		INFO_PRINTF3(_L("INFO: LightStatusChanged, target=%d, status=%d"),aTarget,aStatus);
       
   654  		}
       
   655  		
       
   656     CheckForEndOfTransition();
       
   657 	}
       
   658 	
       
   659 void CHWRMTestBase::FmTxStatusChanged(TFmTxState aStatus)
       
   660 	{
       
   661 	switch (aStatus)
       
   662         {
       
   663     case EFmTxStateUnknown:
       
   664         INFO_PRINTF1(_L("FmTx state changed: EFmTxStateUnknown"));
       
   665         break;
       
   666     case EFmTxStateOff:
       
   667         INFO_PRINTF1(_L("FmTx state changed: EFmTxStateOff"));
       
   668         break;
       
   669     case EFmTxStateActive:
       
   670         INFO_PRINTF1(_L("FmTx state changed: EFmTxStateActive"));
       
   671         break;
       
   672     case EFmTxStateInactive:
       
   673         INFO_PRINTF1(_L("FmTx state changed: EFmTxStateInactive"));
       
   674         break;
       
   675     case EFmTxStatePowerSaveInactivity:
       
   676     	INFO_PRINTF1(_L("FmTx state changed: EFmTxStatePowerSaveInactivity"));
       
   677     	break;
       
   678     case EFmTxStatePowerSaveAccessory:
       
   679 		INFO_PRINTF1(_L("FmTx state changed: EFmTxStatePowerSaveAccessory"));
       
   680 		break;
       
   681     case EFmTxStateScanning:
       
   682 		INFO_PRINTF1(_L("FmTx state changed: EFmTxStateScanning"));
       
   683 		break;
       
   684     default:
       
   685         INFO_PRINTF1(_L("FmTx state changed: UNDEFINED !"));
       
   686         break;
       
   687         }
       
   688 	
       
   689    	if (iExpectedFmTxStatusNotifications.Count() > 0)
       
   690   		{
       
   691   		if (aStatus != iExpectedFmTxStatusNotifications[0].iState1 && aStatus != iExpectedFmTxStatusNotifications[0].iState2)
       
   692   			{
       
   693 	  		INFO_PRINTF4(_L("### ERROR: FmTxStatusChanged, expected:%d OR %d, actual:%d"),iExpectedFmTxStatusNotifications[0].iState1,
       
   694 	  				iExpectedFmTxStatusNotifications[0].iState2,aStatus);
       
   695 	  		SetTestFail();
       
   696   			}
       
   697         iExpectedFmTxStatusNotifications.Remove(0);
       
   698  		}
       
   699  	else
       
   700  		{
       
   701  	  	INFO_PRINTF2(_L("### ERROR: FmTxStatusChanged, expected:NONE, actual:%d"),aStatus);
       
   702 	  	SetTestFail();
       
   703  		}
       
   704     CheckForEndOfTransition();
       
   705 	}
       
   706 
       
   707 void CHWRMTestBase::FmTxFrequencyChanged(TInt aFrequency)
       
   708  	{
       
   709  	INFO_PRINTF2(_L("FmTx Frequency Changed. New Frequency = %d "),aFrequency);
       
   710 
       
   711     if (iExpectedFmTxFrequencyNotifications.Count() > 0)
       
   712     	{
       
   713   		if (aFrequency != iExpectedFmTxFrequencyNotifications[0])
       
   714   			{
       
   715 	  		INFO_PRINTF3(_L("### ERROR: FmTxFrequencyChanged, expected:%d OR %d, actual:%d"),
       
   716 	  				iExpectedFmTxFrequencyNotifications[0],aFrequency);
       
   717 	  		SetTestFail();
       
   718   			}
       
   719   		iExpectedFmTxFrequencyNotifications.Remove(0);
       
   720  		}
       
   721     	else
       
   722     		{
       
   723     		INFO_PRINTF2(_L("### ERROR: FmTxFrequencyChanged, expected:NONE, actual:%d"),aFrequency);
       
   724     		SetTestFail();
       
   725     		}
       
   726 
       
   727     CheckForEndOfTransition();
       
   728  	}
       
   729 
       
   730 	
       
   731 void CHWRMTestBase::PsPropertyChanged(TInt aKey, TInt aValue)
       
   732  	{
       
   733  	INFO_PRINTF3(_L("PsPropertyChanged: [key=%d, value=%d]"), aKey, aValue);
       
   734   	
       
   735   	switch (aKey)
       
   736   		{
       
   737   	case KHWRMBatteryLevel:
       
   738   		BatteryLevelChanged(aValue);
       
   739   		break;
       
   740 	case KHWRMBatteryStatus:
       
   741 		BatteryStatusChanged(aValue);
       
   742 		break;
       
   743 	case KHWRMChargingStatus:
       
   744 		ChargingStatusChanged(aValue);
       
   745 		break;
       
   746 	default:
       
   747 		break;
       
   748   		}
       
   749   	}	
       
   750 
       
   751 void CHWRMTestBase::BatteryLevelChanged(TInt aBatteryLevel)
       
   752 	{
       
   753   	if (iExpectedBatteryLevelNotifications.Count() > 0)
       
   754   		{
       
   755   		if (aBatteryLevel != iExpectedBatteryLevelNotifications[0])
       
   756   			{
       
   757 	  		INFO_PRINTF3(_L("### ERROR: BatteryLevelChanged, expected:%d, actual:%d"),iExpectedBatteryLevelNotifications[0],aBatteryLevel);
       
   758 	  		SetTestFail();
       
   759   			}
       
   760         iExpectedBatteryLevelNotifications.Remove(0);
       
   761  		}
       
   762  	else
       
   763  		{
       
   764  	  	INFO_PRINTF2(_L("### ERROR: BatteryLevelChanged, expected:NONE, actual:%d"),aBatteryLevel);
       
   765 	  	SetTestFail();
       
   766  		}
       
   767     CheckForEndOfTransition();
       
   768  	}
       
   769  
       
   770  void CHWRMTestBase::BatteryStatusChanged(TInt aBatteryStatus)
       
   771 	{
       
   772   	if (iExpectedBatteryStatusNotifications.Count() > 0)
       
   773   		{
       
   774   		if (aBatteryStatus != iExpectedBatteryStatusNotifications[0])
       
   775   			{
       
   776 	  		INFO_PRINTF3(_L("### ERROR: BatteryStatusChanged, expected:%d, actual:%d"),iExpectedBatteryStatusNotifications[0],aBatteryStatus);
       
   777 	  		SetTestFail();
       
   778   			}
       
   779         iExpectedBatteryStatusNotifications.Remove(0);
       
   780  		}
       
   781  	else
       
   782  		{
       
   783  	  	INFO_PRINTF2(_L("### ERROR: BatteryStatusChanged, expected:NONE, actual:%d"),aBatteryStatus);
       
   784 	  	SetTestFail();
       
   785  		}
       
   786     CheckForEndOfTransition();
       
   787  	}
       
   788  
       
   789   void CHWRMTestBase::ChargingStatusChanged(TInt aChargingStatus)
       
   790 	{
       
   791   	if (iExpectedChargingStatusNotifications.Count() > 0)
       
   792   		{
       
   793   		if (aChargingStatus != iExpectedChargingStatusNotifications[0])
       
   794   			{
       
   795 	  		INFO_PRINTF3(_L("### ERROR: BatteryStatusChanged, expected:%d, actual:%d"),iExpectedChargingStatusNotifications[0],aChargingStatus);
       
   796 	  		SetTestFail();
       
   797   			}
       
   798         iExpectedChargingStatusNotifications.Remove(0);
       
   799  		}
       
   800  	else
       
   801  		{
       
   802  	  	INFO_PRINTF2(_L("### ERROR: ChargingStatusChanged, expected:NONE, actual:%d"),aChargingStatus);
       
   803 	  	SetTestFail();
       
   804  		}
       
   805     CheckForEndOfTransition();
       
   806  	}
       
   807  	
       
   808 void CHWRMTestBase::CheckPluginInsensitivity()
       
   809 	{
       
   810 	TInt value;
       
   811 	iLightIntensityProperty.Get(value);
       
   812 	if (value != iLightDefaultIntensity)
       
   813 		{
       
   814 		INFO_PRINTF3(_L("### FAILURE: Light plugin has invalid default intensity (%d != %d)"), iLightDefaultIntensity, value);
       
   815 		User::Leave(KErrGeneral);
       
   816 		}
       
   817 	
       
   818 	iLightSensitivityProperty.Get(value);
       
   819     //if (iSensorSupported)
       
   820     //	{
       
   821     	if (value != iLightDefaultSensitivity)
       
   822     		{
       
   823     		INFO_PRINTF3(_L("### FAILURE: Light plugin has invalid default sensitivity (%d != %d)"), iLightDefaultSensitivity, value);
       
   824     		User::Leave(KErrGeneral);
       
   825     		}
       
   826     //	}
       
   827     //else
       
   828     //	{
       
   829     	// Skipped as there is no sensor enabled in features
       
   830     //	INFO_PRINTF1(_L("### Skipped sensor sensitivity check, as sensor is not supported"));
       
   831     //	}
       
   832 	}
       
   833 	
       
   834 void CHWRMTestBase::ExecuteTestL()
       
   835 	{
       
   836 	iEndStateTimer->Start(0);	//start the test with an immmediate callback
       
   837 	CActiveScheduler::Start();
       
   838 	
       
   839 	if (iTestResult)
       
   840 		{
       
   841 		TRAP_IGNORE(this->TearDownL()); // teardown is not called by TEFUnit if the test leave !!
       
   842 		User::Leave(iTestResult);
       
   843 		}
       
   844 	}
       
   845 	
       
   846 void CHWRMTestBase::CheckForEndOfTransition()
       
   847 	{
       
   848 	TBool isDone = ETrue;
       
   849 	
       
   850 	// Check SY events
       
   851 	TBool SYHasWaitingEvent;
       
   852 	TBool SYHasPendingEvent;
       
   853 	TBool SYHasError;
       
   854 	if (iIsMockLightSessionOpen)
       
   855 		{
       
   856 		iMockLight.GetStatus(SYHasWaitingEvent,SYHasPendingEvent,SYHasError);
       
   857 		if (SYHasPendingEvent)
       
   858 			isDone = EFalse;
       
   859 		}
       
   860 	if (iIsMockVibraSessionOpen)
       
   861 		{
       
   862 		iMockVibra.GetStatus(SYHasWaitingEvent,SYHasPendingEvent,SYHasError);
       
   863 		if (SYHasPendingEvent)
       
   864 			isDone = EFalse;
       
   865 		}
       
   866 	
       
   867 	if (iIsMockPowerStateSessionOpen)
       
   868 		{
       
   869 		iMockPowerState.GetStatus(SYHasWaitingEvent,SYHasPendingEvent,SYHasError);
       
   870 		if (SYHasPendingEvent)
       
   871 			isDone = EFalse;
       
   872 		}
       
   873 	
       
   874 	if (iIsMockPowerSessionOpen)
       
   875 		{
       
   876 		iMockPower.GetStatus(SYHasWaitingEvent,SYHasPendingEvent,SYHasError);
       
   877 		if (SYHasPendingEvent)
       
   878 			isDone = EFalse;
       
   879 		}
       
   880 
       
   881 	if (iIsMockFmTxSessionOpen)
       
   882 		{
       
   883 		iMockFmTx.GetStatus(SYHasWaitingEvent,SYHasPendingEvent,SYHasError);
       
   884 		if (SYHasPendingEvent)
       
   885 			isDone = EFalse;
       
   886 		}
       
   887 	
       
   888 	// Check if we are waiting for some notification
       
   889 	if(		iExpectedVibraStatusNotifications.Count() 			!=0 
       
   890 		|| 	iExpectedVibraModeNotifications.Count() 			!=0 
       
   891 		|| 	iExpectedLightNotifications.Count() 				!=0
       
   892 		|| 	iExpectedBatteryLevelNotifications.Count()			!=0
       
   893 		|| 	iExpectedBatteryStatusNotifications.Count()			!=0
       
   894 		|| 	iExpectedChargingStatusNotifications.Count()		!=0
       
   895 		||  iExpectedBatteryPowerMeasurementsError.Count()		!=0
       
   896 		||  iExpectedFmTxStatusNotifications.Count() 			!=0
       
   897 		||  iExpectedFmTxFrequencyNotifications.Count()			!=0
       
   898 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
       
   899 		||  iExpectedBatteryChargingTimeMeasurementsError.Count() !=0
       
   900 		||  iExpectedBatteryChargingCurrentMeasurementsError.Count() !=0
       
   901 #endif //SYMBIAN_HWRM_EXTPOWERINFO
       
   902 	  )
       
   903 		{
       
   904 		isDone = EFalse;
       
   905 		}
       
   906 		
       
   907 	// Stop the timer if everybody is done
       
   908 	if (isDone)
       
   909 		{
       
   910 		iEndStateTimer->DoCancel();
       
   911 		}
       
   912 	}
       
   913 	
       
   914 
       
   915 void CHWRMTestBase::SetupL()
       
   916 	{
       
   917 	__UHEAP_MARK;
       
   918 	INFO_PRINTF1(_L("HWRM - Setup."));
       
   919 	
       
   920 	//zero arrays
       
   921 	memset(&iVibraSessions, 0, KMaxNoOpenSessionsForResource*iVibraSessions.Length());
       
   922 	memset(&iLightSessions, 0, KMaxNoOpenSessionsForResource*iLightSessions.Length());
       
   923 	memset(&iPowerSessions, 0, KMaxNoOpenSessionsForResource*iPowerSessions.Length());
       
   924 	memset(&iFmTxSessions, 0, KMaxNoOpenSessionsForResource*iFmTxSessions.Length());
       
   925 	memset(&iExtLightSessions, 0, KMaxNoOpenSessionsForResource*iExtLightSessions.Length());
       
   926 	memset(&iEnhancedLightSessions, 0, KMaxNoOpenSessionsForResource*iEnhancedLightSessions.Length());
       
   927 	
       
   928 
       
   929 	ResetDefaultsL();
       
   930 	
       
   931 	//set default values
       
   932 	iLightDefaultIntensity = 50;
       
   933 	iLightDefaultSensitivity = 55;
       
   934 	iLightSensorEnabled = 0;
       
   935 	
       
   936     iLightIntensityProperty.Attach(KPSUidHWResourceNotification, KHWRMTestLightIntensityValue);
       
   937     iLightSensitivityProperty.Attach(KPSUidHWResourceNotification, KHWRMTestLightSensitivityValue);   
       
   938     	
       
   939     iPowerAttributesMeasurementProcessingTime = 0;
       
   940     
       
   941 #ifdef INSECURE_AUDIO_POLICY_KEYS
       
   942 
       
   943     // Test module mimics the behaviour of Audio Policy    
       
   944     // WARNING - HWRM must be built with INSECURE_AUDIO_POLICY_KEYS defined, else KErrPermissionDenied
       
   945     iAudioRoutedProperty.Attach(KPSUidHWRMFmTx, KHWRMFmTxAudioRoutedFlag);
       
   946 
       
   947 #endif // INSECURE_AUDIO_POLICY_KEYS
       
   948 
       
   949 	iScheduler = new CActiveScheduler;
       
   950 
       
   951     if ( iScheduler )
       
   952         {
       
   953         CActiveScheduler::Install( iScheduler );
       
   954         } 
       
   955 	iEndStateTimer = CEndStateTimer::NewL(*this);
       
   956 	}
       
   957 	
       
   958 const TDesC& CHWRMTestBase::MapVibraModeState(CHWRMVibra::TVibraModeState aState)
       
   959 	{
       
   960 	switch(aState)
       
   961 		{
       
   962 	case CHWRMVibra::EVibraModeON:
       
   963 		return KVibraModeON;
       
   964 	case CHWRMVibra::EVibraModeOFF:
       
   965 		return KVibraModeOFF;
       
   966 	default:
       
   967 		return KVibraModeUnknown;
       
   968 		}
       
   969 	}
       
   970 	
       
   971 const TDesC& CHWRMTestBase::MapVibraModeStatus(CHWRMVibra::TVibraStatus aStatus)
       
   972 	{
       
   973 	 
       
   974 	switch(aStatus)
       
   975 		{
       
   976 	case CHWRMVibra::EVibraStatusNotAllowed:
       
   977 		return KVibraStatusNotAllowed;
       
   978 	case CHWRMVibra::EVibraStatusStopped:
       
   979 		return KVibraStatusStopped;
       
   980 	case CHWRMVibra::EVibraStatusOn:
       
   981 		return KVibraStatusOn;
       
   982 	default:
       
   983 		return KVibraStatusUnknown;
       
   984 		}
       
   985 	}
       
   986 	
       
   987 	
       
   988 
       
   989 const TDesC& CHWRMTestBase::MapLightStatus(CHWRMLight::TLightStatus aStatus)
       
   990 	{
       
   991 	 
       
   992 	switch(aStatus)
       
   993 		{
       
   994 	case CHWRMLight::ELightOn:
       
   995 		return KLightOn;
       
   996 	case CHWRMLight::ELightOff:
       
   997 		return KLightOff;
       
   998 	case CHWRMLight::ELightBlink:
       
   999 		return KLightBlink;
       
  1000 	default:
       
  1001 		return KLightStatusUnknown;
       
  1002 		}
       
  1003 	}
       
  1004 		
       
  1005 const TDesC& CHWRMTestBase::MapFmTxStatus(TFmTxState aStatus)
       
  1006 	{ 
       
  1007 	switch(aStatus)
       
  1008 		{
       
  1009 	case EFmTxStateOff:
       
  1010 		return KFmTxStateOff;
       
  1011 	case EFmTxStateActive:
       
  1012 		return KFmTxStateActive;
       
  1013 	case EFmTxStateInactive:
       
  1014 		return KFmTxStateInactive;
       
  1015 	case EFmTxStatePowerSaveInactivity:
       
  1016 		return KFmTxStatePowerSaveInactivity;
       
  1017 	case EFmTxStatePowerSaveAccessory:
       
  1018 		return KFmTxStatePowerSaveAccessory;
       
  1019 	case EFmTxStateScanning:
       
  1020 		return KFmTxStateScanning;
       
  1021 	default:
       
  1022 		return KFmTxStateUnknown;
       
  1023 		}
       
  1024 	}
       
  1025 
       
  1026 void CHWRMTestBase::TearDownL()
       
  1027 	{
       
  1028 	iTearingDown = ETrue;
       
  1029 	if (iIsMockLightSessionOpen)
       
  1030 		{
       
  1031 		iMockLight.Close();
       
  1032 		iIsMockLightSessionOpen = EFalse;
       
  1033 		}
       
  1034 
       
  1035 	if (iIsMockVibraSessionOpen)
       
  1036 		{
       
  1037 		iMockVibra.Close();
       
  1038 		iIsMockVibraSessionOpen = EFalse;
       
  1039 		}
       
  1040 
       
  1041 	if (iIsMockPowerStateSessionOpen)
       
  1042 		{
       
  1043 		iMockPowerState.Close();
       
  1044 		iIsMockPowerStateSessionOpen = EFalse;
       
  1045 		}
       
  1046 		
       
  1047 	if (iIsMockPowerSessionOpen)
       
  1048 		{
       
  1049 		iMockPower.Close();
       
  1050 		iIsMockPowerSessionOpen = EFalse;
       
  1051 		}
       
  1052 
       
  1053 	if (iIsMockFmTxSessionOpen)
       
  1054 		{
       
  1055 		iMockFmTx.Close();
       
  1056 		iIsMockFmTxSessionOpen = EFalse;
       
  1057 		}
       
  1058 
       
  1059 	//log light and vibra states on tear down.
       
  1060 
       
  1061 	if(iVibraSessions[0])
       
  1062 		{
       
  1063 		CHWRMVibra& vibra = *iVibraSessions[0];
       
  1064 		CHWRMVibra::TVibraModeState state = vibra.VibraSettings();
       
  1065 		CHWRMVibra::TVibraStatus status = vibra.VibraStatus();
       
  1066 		INFO_PRINTF3(_L("Teardown - TVibraModeState=%S, TVibraStatus=%S"), &MapVibraModeState(state), &MapVibraModeStatus(status));		
       
  1067 		}
       
  1068 		
       
  1069 	if(iLightSessions[0])
       
  1070 		{
       
  1071 		CHWRMLight& light = *iLightSessions[0];
       
  1072 		TUint sup_targets = light.SupportedTargets();
       
  1073 		TUint targetsOnMask(0);
       
  1074 		INFO_PRINTF2(_L("Teardown - Light supported targets bitmask=%d"), sup_targets);		
       
  1075 		TUint target = 0x00000001;
       
  1076 		CHWRMLight::TLightStatus st;
       
  1077 		do
       
  1078 			{
       
  1079 			if(target & sup_targets)
       
  1080 				{
       
  1081 				st = light.LightStatus(target);
       
  1082 				INFO_PRINTF3(_L("Light target %d, state=%S"), target, &MapLightStatus(st));		
       
  1083 				if (st == CHWRMLight::ELightOn)
       
  1084 					{
       
  1085 					targetsOnMask |= target;
       
  1086 					}
       
  1087 				}
       
  1088 			if(target == CHWRMLight::ESystemTarget)
       
  1089 				{
       
  1090 				break;
       
  1091 				}
       
  1092 				
       
  1093 			target  = target << 1;			
       
  1094 			}
       
  1095 		while(ETrue);
       
  1096 		
       
  1097 		if (targetsOnMask != 0)
       
  1098 			{
       
  1099 			INFO_PRINTF2(_L("Teardown - Going to switch off targets bitmask=%d"), targetsOnMask);
       
  1100 			light.LightOffL(targetsOnMask);
       
  1101 			}
       
  1102 		}
       
  1103 	
       
  1104 	if(iFmTxSessions[0])
       
  1105 		{
       
  1106 		CHWRMFmTx& fmTx = *iFmTxSessions[0];
       
  1107 		TInt frequency = fmTx.Frequency();
       
  1108 		TFmTxState status = fmTx.Status();
       
  1109 		INFO_PRINTF3(_L("Teardown - TFmTxState=%S, FmTxFrequency=%d"), &MapFmTxStatus(status), frequency);		
       
  1110 		}
       
  1111 			
       
  1112 	for(TInt i = 0; i<KMaxNoOpenSessionsForResource;i++)
       
  1113 		{
       
  1114 		delete iVibraSessions[i];
       
  1115 		delete iLightSessions[i];
       
  1116 		delete iExtLightSessions[i];
       
  1117 		delete iPowerSessions[i];
       
  1118 		delete iFmTxSessions[i];
       
  1119 		delete iEnhancedLightSessions[i];
       
  1120 		}
       
  1121 		
       
  1122 	delete iScheduler;
       
  1123 	delete iEndStateTimer;
       
  1124 	for (TInt i=0; i< iStepStates.Count(); i++)
       
  1125 		{
       
  1126 		delete iStepStates[i];
       
  1127 		}
       
  1128 	iStepStates.Close();
       
  1129 	iExpectedVibraStatusNotifications.Close();
       
  1130 	iExpectedVibraModeNotifications.Close();
       
  1131 	iExpectedLightNotifications.Close();
       
  1132 	iExpectedExtLightNotifications.Close();
       
  1133 	iExpectedFmTxStatusNotifications.Close();
       
  1134 	iExpectedFmTxFrequencyNotifications.Close();
       
  1135 	iExpectedBatteryLevelNotifications.Close();
       
  1136 	iExpectedBatteryStatusNotifications.Close();
       
  1137 	iExpectedChargingStatusNotifications.Close();
       
  1138 	iExpectedVibraFeedbackModeNotifications.Close();
       
  1139 	iExpectedBatteryPowerMeasurementsError.Close();
       
  1140 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
       
  1141 	iExpectedBatteryChargingTimeMeasurementsError.Close();
       
  1142 	iExpectedBatteryChargingCurrentMeasurementsError.Close();
       
  1143 #endif //SYMBIAN_HWRM_EXTPOWERINFO
       
  1144 	iLightIntensityProperty.Close();
       
  1145 	iLightSensitivityProperty.Close();
       
  1146 	
       
  1147 #ifdef INSECURE_AUDIO_POLICY_KEYS
       
  1148 	iAudioRoutedProperty.Close();
       
  1149 #endif // INSECURE_AUDIO_POLICY_KEYS
       
  1150 	    		
       
  1151 	CleanupPropertyObservers();
       
  1152 	iTearingDown = EFalse;
       
  1153 	__UHEAP_MARKEND;
       
  1154 	}
       
  1155 
       
  1156 void CHWRMTestBase::ResetDefaultsL()
       
  1157 	{
       
  1158 	// Vibra send sync notification when the CHWRMVibra object is create
       
  1159 	// so we have to queue those expected notification before opening the session
       
  1160 	TInt value;
       
  1161 	GetCRVibraAttributeL(KVibraCtrlProfileVibraEnabled, value);
       
  1162 	INFO_PRINTF2(_L("KVibraCtrlProfileVibraEnabledvalue = %d"), value);
       
  1163 	
       
  1164 	if (value == 0)
       
  1165 		{
       
  1166 		SetCRVibraAttributeL(KVibraCtrlProfileVibraEnabled, 1);
       
  1167 		GetCRVibraAttributeL(KVibraCtrlProfileVibraEnabled, value);
       
  1168 		INFO_PRINTF2(_L("KVibraCtrlProfileVibraEnabledvalue updated = %d"), value);
       
  1169 		}
       
  1170 	}
       
  1171 
       
  1172 	
       
  1173 void CHWRMTestBase::EndStateTimerExpired(TInt /*aError*/)
       
  1174 	{
       
  1175 	
       
  1176 	//the timer has triggered for the end of a state. There are two things we have to do
       
  1177 	//1) check to see if all expected notifications were received
       
  1178 	//2) move to the next state (or end if no more states to process)
       
  1179 	
       
  1180 	INFO_PRINTF2(_L("EndStateTimerExpired. Current State = %d"), iCurrentState);	
       
  1181 	
       
  1182 	CheckMockSYResultL();
       
  1183 	CheckAllExpectedNotificationsReceived();
       
  1184 	
       
  1185 	//move to next state or finish if no more states to go to
       
  1186 	TBool bFinished = EFalse;
       
  1187 	TInt err = KErrNone;
       
  1188 	//is there another state to move to?
       
  1189 	
       
  1190 	if(iCurrentState < iStepStates.Count())
       
  1191 		{
       
  1192 		// execute the test state	
       
  1193 		TRAP(err, iStepStates[iCurrentState]->ExecuteTestState());
       
  1194 		
       
  1195 		// Expected leave are not errors
       
  1196 		if (err == iExpectedLeaveCode)
       
  1197 			{
       
  1198 			err = KErrNone;
       
  1199 			iExpectedLeaveCode = KErrNone;
       
  1200 			}
       
  1201 		else
       
  1202 			{
       
  1203 			INFO_PRINTF3(_L("### ERROR Test step left with error %d, expected error %d"), err, iExpectedLeaveCode);
       
  1204 			SetTestFail();
       
  1205 			}
       
  1206 		if(err)
       
  1207 			{	
       
  1208 			SetTestFail();
       
  1209 			}
       
  1210 		else
       
  1211 			{				
       
  1212 			//start timer to end test
       
  1213 			iEndStateTimer->Start(iStepStates[iCurrentState]->iMaxDurationInSecs);
       
  1214 			}
       
  1215 		}
       
  1216 	else
       
  1217 		{
       
  1218 		bFinished=ETrue; //no more transitions to go through, so finish step
       
  1219 		}
       
  1220 		
       
  1221 	if(bFinished || iTestResult)
       
  1222 		{
       
  1223 		//test has finished so stop scheduler
       
  1224 		CActiveScheduler::Stop();		
       
  1225 		}
       
  1226 	//move to next state
       
  1227 	iCurrentState++;
       
  1228 	
       
  1229 	}
       
  1230 
       
  1231 /**
       
  1232 This method is called by the ASSERT_LEAVE macro. previous statement is expected to leave, so if it is executed
       
  1233 it's an error.
       
  1234 */
       
  1235 void CHWRMTestBase::EndExpectLeaveL(TInt aErr, const TText8* aFile,TInt aLine)
       
  1236 	{
       
  1237 	TPtrC8 fileNamePtrC8(aFile);
       
  1238 	TBuf<100> fname;
       
  1239 	fname.Copy(fileNamePtrC8);
       
  1240 	INFO_PRINTF4(_L("### ERROR statement was expected to leave with error %d (File=%S, line=%d)"), aErr, &fname, aLine);
       
  1241 	User::Leave(KErrTEFUnitFail);	
       
  1242 	}
       
  1243 
       
  1244 	
       
  1245 void CHWRMTestBase::CheckAllExpectedNotificationsReceived()
       
  1246 	{
       
  1247 	/*
       
  1248 	if (IgnoringStatusNotifications() == ETrue)
       
  1249 		{
       
  1250 		return;
       
  1251 		}
       
  1252 	*/
       
  1253 	//if these arrays are non zero it implies that notifications were expected but not received which means a failure of the test
       
  1254 	if (iExpectedVibraStatusNotifications.Count() != 0)
       
  1255 		{
       
  1256 		SetTestFail();
       
  1257 		INFO_PRINTF1(_L("### ERROR Expected Vibra Status Notification not received"));
       
  1258 		}
       
  1259 	if (iExpectedVibraModeNotifications.Count() != 0)
       
  1260 		{
       
  1261 		SetTestFail();
       
  1262 		INFO_PRINTF1(_L("### ERROR Expected Vibra Mode Notification not received"));
       
  1263 		}
       
  1264 	if (iExpectedVibraFeedbackModeNotifications.Count() != 0)
       
  1265 		{
       
  1266 		SetTestFail();
       
  1267 		INFO_PRINTF1(_L("### ERROR Expected Vibra Feedback Mode Notification not received"));
       
  1268 		}
       
  1269 	if (iExpectedLightNotifications.Count() != 0)
       
  1270 		{
       
  1271 		SetTestFail();
       
  1272 		INFO_PRINTF1(_L("### ERROR Expected Light Status Notification not received"));
       
  1273 		}
       
  1274 	if (iExpectedBatteryLevelNotifications.Count() != 0)
       
  1275 		{
       
  1276 		SetTestFail();
       
  1277 		INFO_PRINTF1(_L("### ERROR Expected Battery Level Notification not received"));
       
  1278 		}
       
  1279 	if (iExpectedBatteryStatusNotifications.Count() != 0)
       
  1280 		{
       
  1281 		SetTestFail();
       
  1282 		INFO_PRINTF1(_L("### ERROR Expected Battery Status Notification not received"));
       
  1283 		}
       
  1284 	if (iExpectedChargingStatusNotifications.Count() != 0)
       
  1285 		{
       
  1286 		SetTestFail();
       
  1287 		INFO_PRINTF1(_L("### ERROR Expected Charging Status Notification not received"));
       
  1288 		}
       
  1289 	if (iExpectedBatteryPowerMeasurementsError.Count() != 0)
       
  1290 		{
       
  1291 		SetTestFail();
       
  1292 		INFO_PRINTF1(_L("### ERROR Expected Battery Power Measurements Error not received"));
       
  1293 		}
       
  1294 	if (iExpectedFmTxFrequencyNotifications.Count() != 0)
       
  1295 		{
       
  1296 		SetTestFail();
       
  1297 		INFO_PRINTF1(_L("### ERROR Expected FmTx Frequency Notification not received"));
       
  1298 		}
       
  1299 	if (iExpectedFmTxStatusNotifications.Count() != 0)
       
  1300 		{
       
  1301 		SetTestFail();
       
  1302 		INFO_PRINTF1(_L("### ERROR Expected FmTx Status Notification not received"));
       
  1303 		}
       
  1304 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
       
  1305 	if (iExpectedBatteryChargingTimeMeasurementsError.Count() != 0)
       
  1306 		{
       
  1307 		SetTestFail();
       
  1308 		INFO_PRINTF1(_L("### ERROR Expected Remaining charging time error notification not received"));
       
  1309 		}	
       
  1310 	if (iExpectedBatteryChargingCurrentMeasurementsError.Count() != 0)
       
  1311 		{
       
  1312 		SetTestFail();
       
  1313 		INFO_PRINTF1(_L("### ERROR Expected Charging current error notification not received"));
       
  1314 		}
       
  1315 #endif //SYMBIAN_HWRM_EXTPOWERINFO
       
  1316 	}
       
  1317 
       
  1318 void CHWRMTestBase::CheckMockSYResultL()
       
  1319 	{
       
  1320 	TBool SYHasWaitingEvent;
       
  1321 	TBool SYHasPendingEvent;
       
  1322 	TBool SYHasError;
       
  1323 	TBuf<255> log;
       
  1324 	// Light
       
  1325 	if (iIsMockLightSessionOpen)
       
  1326 		{
       
  1327 		iMockLight.GetStatus(SYHasWaitingEvent,SYHasPendingEvent,SYHasError);
       
  1328 		if (SYHasWaitingEvent)
       
  1329 			{
       
  1330 			INFO_PRINTF1(_L("### ERROR MockLight SY didn't receive all expected commands"));
       
  1331 			}
       
  1332 		if (SYHasError || SYHasWaitingEvent)
       
  1333 			{
       
  1334 			SetTestFail();
       
  1335 			do	{
       
  1336 				iMockLight.GetNextLogLine(log);
       
  1337 				INFO_PRINTF1(log);
       
  1338 				} while(log.Length() > 0);
       
  1339 			}
       
  1340 			
       
  1341 		}
       
  1342 	// Vibra	
       
  1343 	if (iIsMockVibraSessionOpen)
       
  1344 		{
       
  1345 		iMockVibra.GetStatus(SYHasWaitingEvent,SYHasPendingEvent,SYHasError);
       
  1346 		if (SYHasWaitingEvent)
       
  1347 			{
       
  1348 			INFO_PRINTF1(_L("### ERROR MockVibra SY didn't receive all expected commands"));
       
  1349 			}
       
  1350 		if (SYHasError || SYHasWaitingEvent)
       
  1351 			{
       
  1352 			SetTestFail();
       
  1353 			do	{
       
  1354 				iMockVibra.GetNextLogLine(log);
       
  1355 				INFO_PRINTF1(log);
       
  1356 				} while(log.Length() > 0);
       
  1357 			}
       
  1358 		}
       
  1359 	// Power State
       
  1360 	if (iIsMockPowerStateSessionOpen)
       
  1361 		{
       
  1362 		iMockPowerState.GetStatus(SYHasWaitingEvent,SYHasPendingEvent,SYHasError);
       
  1363 		if (SYHasWaitingEvent)
       
  1364 			{
       
  1365 			INFO_PRINTF1(_L("### ERROR MockPowerState SY didn't receive all expected commands"));
       
  1366 			}
       
  1367 		if (SYHasError || SYHasWaitingEvent)
       
  1368 			{
       
  1369 			SetTestFail();
       
  1370 			do	{
       
  1371 				iMockPowerState.GetNextLogLine(log);
       
  1372 				INFO_PRINTF1(log);
       
  1373 				} while(log.Length() > 0);
       
  1374 			}
       
  1375 		}		
       
  1376 	// Power	
       
  1377 	if (iIsMockPowerSessionOpen)
       
  1378 		{
       
  1379 		iMockPower.GetStatus(SYHasWaitingEvent,SYHasPendingEvent,SYHasError);
       
  1380 		if (SYHasWaitingEvent)
       
  1381 			{
       
  1382 			INFO_PRINTF1(_L("### ERROR MockPower SY didn't receive all expected commands"));
       
  1383 			}
       
  1384 		if (SYHasError || SYHasWaitingEvent)
       
  1385 			{
       
  1386 			SetTestFail();
       
  1387 			do	{
       
  1388 				iMockPower.GetNextLogLine(log);
       
  1389 				INFO_PRINTF1(log);
       
  1390 				} while(log.Length() > 0);
       
  1391 			}
       
  1392 		}
       
  1393 
       
  1394 	// FmTx
       
  1395 	if (iIsMockFmTxSessionOpen)
       
  1396 		{
       
  1397 		iMockFmTx.GetStatus(SYHasWaitingEvent,SYHasPendingEvent,SYHasError);
       
  1398 		if (SYHasWaitingEvent)
       
  1399 			{
       
  1400 			INFO_PRINTF1(_L("### ERROR MockFmTx SY didn't receive all expected commands"));
       
  1401 			}
       
  1402 		if (SYHasError || SYHasWaitingEvent)
       
  1403 			{
       
  1404 			SetTestFail();
       
  1405 			do	{
       
  1406 				iMockFmTx.GetNextLogLine(log);
       
  1407 				INFO_PRINTF1(log);
       
  1408 				} while(log.Length() > 0);
       
  1409 			}
       
  1410 		}
       
  1411 	}
       
  1412 
       
  1413 void CHWRMTestBase::GetTargetsOn(TInt& aTargetsOnMask) const
       
  1414 	{
       
  1415 	aTargetsOnMask = 0;
       
  1416 	if(iLightSessions[0])
       
  1417 		{
       
  1418 		CHWRMLight& light = *iLightSessions[0];
       
  1419 		TUint sup_targets = light.SupportedTargets();
       
  1420 		TUint target = 0x00000001;
       
  1421 		CHWRMLight::TLightStatus st;
       
  1422 		do
       
  1423 			{
       
  1424 			if(target & sup_targets)
       
  1425 				{
       
  1426 				st = light.LightStatus(target);
       
  1427 				if (st == CHWRMLight::ELightOn)
       
  1428 					{
       
  1429 					aTargetsOnMask |= target;
       
  1430 					}
       
  1431 				}
       
  1432 			if(target == CHWRMLight::ESystemTarget)
       
  1433 				{
       
  1434 				break;
       
  1435 				}
       
  1436 				
       
  1437 			target  = target << 1;			
       
  1438 			}
       
  1439 		while(ETrue);
       
  1440 		}
       
  1441 	}
       
  1442 
       
  1443 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
       
  1444 void CHWRMTestBase::OpenPowerStateSessionforChrgStatusL()
       
  1445 	{
       
  1446 	if (!iIsMockPowerStateSessionOpen)
       
  1447 		{
       
  1448 		User::LeaveIfError(iMockPowerState.Connect());
       
  1449 		iIsMockPowerStateSessionOpen = ETrue;
       
  1450 		}
       
  1451 	}
       
  1452 
       
  1453 void CHWRMTestBase::ChargingStatusChange(TInt aErrCode, CHWRMPower::TBatteryChargingStatus aChrgStatus)
       
  1454 	{
       
  1455 	if (aErrCode == KErrNone)
       
  1456 		{
       
  1457 		switch(aChrgStatus)
       
  1458 			{
       
  1459 			case EChargingStatusError:
       
  1460 				{
       
  1461 				INFO_PRINTF1(_L("INFO: Battery charging status changed: EChargingStatusError"));
       
  1462 				break;
       
  1463 				}
       
  1464 			case EChargingStatusNotConnected:
       
  1465 				{
       
  1466 				INFO_PRINTF1(_L("INFO: Battery charging status changed: EChargingStatusNotConnected"));
       
  1467 				break;
       
  1468 				}
       
  1469 			case EChargingStatusCharging:
       
  1470 				{
       
  1471 				INFO_PRINTF1(_L("INFO: Battery charging status changed: EChargingStatusCharging"));
       
  1472 				break;
       
  1473 				}
       
  1474 			case EChargingStatusNotCharging:
       
  1475 				{
       
  1476 				INFO_PRINTF1(_L("INFO: Battery charging status changed: EChargingStatusNotCharging"));
       
  1477 				break;
       
  1478 				}
       
  1479 			case EChargingStatusAlmostComplete:
       
  1480 				{
       
  1481 				INFO_PRINTF1(_L("INFO: Battery charging status changed: EChargingStatusAlmostComplete"));
       
  1482 				break;
       
  1483 				}
       
  1484 			case EChargingStatusChargingComplete:
       
  1485 				{
       
  1486 				INFO_PRINTF1(_L("INFO: Battery charging status changed: EChargingStatusChargingComplete"));
       
  1487 				break;
       
  1488 				}
       
  1489 			case EChargingStatusChargingContinued:
       
  1490 				{
       
  1491 				INFO_PRINTF1(_L("INFO: Battery charging status changed: EChargingStatusChargingContinued"));
       
  1492 				break;
       
  1493 				}
       
  1494 			default:
       
  1495 				{
       
  1496 				INFO_PRINTF1(_L("INFO: Battery charging status changed: UNDEFINED!"));
       
  1497 				}
       
  1498 			}
       
  1499 		
       
  1500 		if (iExpectedChargingStatusNotifications.Count() > 0)
       
  1501 			{
       
  1502 			if (aChrgStatus != iExpectedChargingStatusNotifications[0])
       
  1503 				{
       
  1504 				INFO_PRINTF3(_L("### ERROR: ChargingStatusChange, expected:%d, actual:%d"),iExpectedChargingStatusNotifications[0],aChrgStatus);
       
  1505 				SetTestFail();
       
  1506 				}
       
  1507 			iExpectedChargingStatusNotifications.Remove(0);
       
  1508 			}
       
  1509 		else
       
  1510 			{
       
  1511 			INFO_PRINTF2(_L("### ERROR: ChargingStatusChange, expected:NONE, actual:%d"),aChrgStatus);
       
  1512 			SetTestFail();
       
  1513 			}
       
  1514 		}
       
  1515 	}
       
  1516 
       
  1517 void CHWRMTestBase::ExpectBatteryChargingTimeMeasurementsErrorL(TInt aErrorCode)
       
  1518 	{
       
  1519 	iExpectedBatteryChargingTimeMeasurementsError.AppendL(aErrorCode);
       
  1520 	}
       
  1521 
       
  1522 void CHWRMTestBase::BatteryFullChargingTimeChange(TInt aErrorCode, TUint aTime)
       
  1523 	{
       
  1524 	if (aErrorCode == KErrNone)
       
  1525 		{
       
  1526 		INFO_PRINTF2(_L("INFO: Remaining charging time received, Time=%d minutes"),aTime);		
       
  1527 		}
       
  1528 	else
       
  1529 		{
       
  1530 		if (iExpectedBatteryChargingTimeMeasurementsError.Count() > 0)
       
  1531 	  		{
       
  1532 	  		if (aErrorCode != iExpectedBatteryChargingTimeMeasurementsError[0])
       
  1533 	  			{
       
  1534 		  		INFO_PRINTF3(_L("### ERROR: BatteryFullChargingTimeChange, expected error:%d, actual:%d"),iExpectedBatteryChargingTimeMeasurementsError[0],aErrorCode);
       
  1535 		  		SetTestFail();
       
  1536 	  			}
       
  1537 	  		iExpectedBatteryChargingTimeMeasurementsError.Remove(0);
       
  1538 	 		}
       
  1539 	 	else
       
  1540 	 		{
       
  1541 	 	  	INFO_PRINTF2(_L("### ERROR: BatteryFullChargingTimeChange, expected error:NONE, actual:%d"),aErrorCode);
       
  1542 		  	SetTestFail();
       
  1543 	 		}
       
  1544 		
       
  1545 		INFO_PRINTF2(_L("INFO: Remaining charging time Error, error=%d"),aErrorCode);
       
  1546 		}
       
  1547 	}
       
  1548 
       
  1549 void CHWRMTestBase::SetPowerChargingCurrentMeasurementProcessingTime(TUint aCallbackProcessingTime)
       
  1550 	{
       
  1551 	iPowerChargingCurrentMeasurementProcessingTime = aCallbackProcessingTime;
       
  1552 	}
       
  1553 
       
  1554 void CHWRMTestBase::ExpectBatteryChargingCurrentMeasurementsErrorL(TInt aErrorCode)
       
  1555 	{
       
  1556 	iExpectedBatteryChargingCurrentMeasurementsError.AppendL(aErrorCode);
       
  1557 	}
       
  1558 
       
  1559 void CHWRMTestBase::AverageChargingCurrentChange(TInt aErrorCode, TInt aMeasurement)
       
  1560 	{
       
  1561 	if (aErrorCode == KErrNone)
       
  1562 		{
       
  1563 		INFO_PRINTF2(_L("INFO: Charging current Measurement Received, measurement=%d"),aMeasurement);
       
  1564 		
       
  1565 		// Simulate time spent on processing the response
       
  1566 		if (iPowerChargingCurrentMeasurementProcessingTime > 0 )
       
  1567 			{
       
  1568 			User::After(iPowerChargingCurrentMeasurementProcessingTime * 1000);
       
  1569 			}
       
  1570 		}
       
  1571 	else
       
  1572 		{
       
  1573 		if (iExpectedBatteryChargingCurrentMeasurementsError.Count() > 0)
       
  1574 	  		{
       
  1575 	  		if (aErrorCode != iExpectedBatteryChargingCurrentMeasurementsError[0])
       
  1576 	  			{
       
  1577 		  		INFO_PRINTF3(_L("### ERROR: ChargingCurrentChange, expected error:%d, actual:%d"),iExpectedBatteryChargingCurrentMeasurementsError[0],aErrorCode);
       
  1578 		  		SetTestFail();
       
  1579 	  			}
       
  1580 	  		iExpectedBatteryChargingCurrentMeasurementsError.Remove(0);
       
  1581 	 		}
       
  1582 	 	else
       
  1583 	 		{
       
  1584 	 	  	INFO_PRINTF2(_L("### ERROR: ChargingCurrentChange, expected error:NONE, actual:%d"),aErrorCode);
       
  1585 		  	SetTestFail();
       
  1586 	 		}
       
  1587 		
       
  1588 		INFO_PRINTF2(_L("INFO: Charging current Measurement Error, error=%d"),aErrorCode);
       
  1589 		}
       
  1590 	}
       
  1591 #endif //SYMBIAN_HWRM_EXTPOWERINFO
       
  1592 
       
  1593 void CHWRMTestBase::ExpectBatteryPowerMeasurementsErrorL(TInt aErrorCode)
       
  1594 	{
       
  1595 	iExpectedBatteryPowerMeasurementsError.AppendL(aErrorCode);
       
  1596 	}
       
  1597 
       
  1598 void CHWRMTestBase::SetPowerAttributesMeasurementProcessingTime(TUint aCallbackProcessingTime)
       
  1599 	{
       
  1600 	iPowerAttributesMeasurementProcessingTime = aCallbackProcessingTime;
       
  1601 	}
       
  1602 	
       
  1603 void CHWRMTestBase::PowerMeasurement(TInt aErrorCode, CHWRMPower::TBatteryPowerMeasurementData& aMeasurement)
       
  1604 	{
       
  1605 	if (aErrorCode == KErrNone)
       
  1606 		{
       
  1607 		INFO_PRINTF3(_L("INFO: Power Attribute Measurement Received, measurement=(Voltage=%d, Current=%d)"),aMeasurement.iAverageVoltage, aMeasurement.iAverageCurrent);
       
  1608 		
       
  1609 		// Simulate time spent on processing the response
       
  1610 		if (iPowerAttributesMeasurementProcessingTime > 0 )
       
  1611 			{
       
  1612 			User::After(iPowerAttributesMeasurementProcessingTime * 1000);
       
  1613 			}
       
  1614 		if ((iExpectedBatteryPowerMeasurementsError.Count() > 0) && (iExpectedBatteryPowerMeasurementsError[0] == KErrNone))
       
  1615 	  		{
       
  1616 	  		iExpectedBatteryPowerMeasurementsError.Remove(0);
       
  1617 			}		
       
  1618 		}
       
  1619 	else
       
  1620 		{
       
  1621 		if (iExpectedBatteryPowerMeasurementsError.Count() > 0)
       
  1622 	  		{
       
  1623 	  		if (aErrorCode != iExpectedBatteryPowerMeasurementsError[0])
       
  1624 	  			{
       
  1625 		  		INFO_PRINTF3(_L("### ERROR: PowerMeasurement, expected error:%d, actual:%d"),iExpectedBatteryPowerMeasurementsError[0],aErrorCode);
       
  1626 		  		SetTestFail();
       
  1627 	  			}
       
  1628 	  		iExpectedBatteryPowerMeasurementsError.Remove(0);
       
  1629 	 		}
       
  1630 	 	else
       
  1631 	 		{
       
  1632 	 	  	INFO_PRINTF2(_L("### ERROR: PowerMeasurement, expected error:NONE, actual:%d"),aErrorCode);
       
  1633 		  	SetTestFail();
       
  1634 	 		}
       
  1635 		
       
  1636 		INFO_PRINTF2(_L("INFO: Power Attributes Measurement Error, error=%d"),aErrorCode);
       
  1637 		}
       
  1638 	}
       
  1639