sapi_sysinfo/tsrc/testing/tsysmanualtest/src/tsysbatterynot.cpp
changeset 0 14df0fbfcc4e
equal deleted inserted replaced
-1:000000000000 0:14df0fbfcc4e
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Tests battery notifications
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "tsysmanualtest.h"
       
    21 #include "sysinfoservice.h"
       
    22 #include "entitykeys.h"
       
    23 #include "tsysbatterynot.h"
       
    24 
       
    25 using namespace SysInfo;
       
    26 
       
    27 _LIT(KBatteryLevel,"BatteryLevel");
       
    28 
       
    29 CBatteryNot* CBatteryNot::NewL(CStifLogger* aLog)
       
    30 	{
       
    31 	CBatteryNot* self = new(ELeave) CBatteryNot(aLog);
       
    32 	self->ConstructL();
       
    33 	return self;
       
    34 	}
       
    35 
       
    36 CBatteryNot::~CBatteryNot()
       
    37 	{
       
    38 	Cancel();
       
    39 	
       
    40 	if(iWaitScheduler->IsStarted())
       
    41 		iWaitScheduler->AsyncStop();
       
    42 	
       
    43 	delete iSysInfoService;
       
    44 	delete iWaitScheduler;
       
    45 	delete iTimer;
       
    46 	}
       
    47 
       
    48 void CBatteryNot::ConstructL()
       
    49 	{
       
    50 	iSysInfoService = CSysInfoService::NewL();
       
    51 	iWaitScheduler  = new(ELeave) CActiveSchedulerWait();
       
    52 	iTimer			= CWatchTimer::NewL(EPriorityNormal,this);
       
    53 	iCallBackCounter = 0 ;
       
    54 	iCount = 3 ;
       
    55 	CActiveScheduler::Add(this);
       
    56 	}
       
    57 
       
    58 CBatteryNot::CBatteryNot(CStifLogger* aLog)
       
    59 							 :CActive(EPriorityStandard),
       
    60 								iLog(aLog)
       
    61 	{
       
    62 	}
       
    63 
       
    64 void CBatteryNot::DoCancel()
       
    65 	{
       
    66 	}
       
    67 
       
    68 void CBatteryNot::RunL()
       
    69 	{
       
    70 	TestFuncL();
       
    71 //	iWaitScheduler->AsyncStop();
       
    72 	}
       
    73 
       
    74 void CBatteryNot::Start()
       
    75 	{
       
    76 	SetActive();
       
    77 	TRequestStatus* temp = &iStatus;
       
    78 	User::RequestComplete(temp, KErrNone);
       
    79 	iWaitScheduler->Start();	
       
    80 	}
       
    81 
       
    82 TInt CBatteryNot::Result()
       
    83 	{
       
    84 	if(iError || iChargingResult || iLevelResult || iStrengthResult)
       
    85 	return KErrGeneral ;
       
    86 	else
       
    87 	return KErrNone ;
       
    88 	}
       
    89 
       
    90 void CBatteryNot::TestFuncL()
       
    91 	{
       
    92 	const TTimeIntervalMicroSeconds32 threeMin(180000000);
       
    93 	CStatus* batStrength = CStatus::NewL(50) ;
       
    94 	iSysInfoService->GetInfoL(KBattery,KBatteryStrength,1,this,batStrength);
       
    95 	iSysInfoService->GetNotificationL(KBattery,KBatteryLevel,2,this);
       
    96 	iSysInfoService->GetNotificationL(KBattery,KChargingStatus,3,this);
       
    97    	iTimer->After(threeMin);
       
    98 	delete batStrength ;
       
    99 	}
       
   100 
       
   101 void CBatteryNot::HandleResponseL(const TDesC& aEntity,const TDesC& aKey,
       
   102 	 					CSysData* aOutput, TInt32 aTransID,TSysRequest::TRequestType aType, TInt aError)
       
   103 	{
       
   104 	if(iCount == iCallBackCounter)
       
   105 		{
       
   106 		delete iTimer;
       
   107 		iTimer = NULL;
       
   108 		iSysInfoService->Cancel(1) ;
       
   109 		iSysInfoService->Cancel(2) ;
       
   110 		iSysInfoService->Cancel(3) ;
       
   111 		iWaitScheduler->AsyncStop();
       
   112 		}
       
   113 		
       
   114 	else
       
   115 		{
       
   116 		iCallBackCounter++ ;
       
   117 		iLog->Log(_L("Entity: %s, Key: %s "),aEntity.Ptr(),aKey.Ptr());
       
   118 		
       
   119 		if(!aEntity.Compare(KBattery) )
       
   120 			{
       
   121 			 if(!aKey.Compare(KBatteryStrength))
       
   122 				 {
       
   123 	             iLog->Log(_L("Battery Strength read.."));
       
   124 		         if(!aError)
       
   125 					{
       
   126 					TInt32 tid = aTransID;
       
   127 					if(tid != 1)
       
   128 						{
       
   129 						iStrengthResult = KErrGeneral;
       
   130 						iLog->Log(_L("Incorrect TID Retured.. %d"),tid);
       
   131 						}
       
   132 					
       
   133 					TInt BatteryStrength = ((CStatus*)aOutput)->Status();
       
   134 					
       
   135 					iLog->Log(_L("Battery Strength: %d "),BatteryStrength);
       
   136 					
       
   137 					if( BatteryStrength > 0	&& BatteryStrength <= 100 )
       
   138 						{
       
   139 						iStrengthResult = KErrNone;
       
   140 						iLog->Log(_L("Battery strength is with in expected range"));
       
   141 						}
       
   142 					else
       
   143 						{
       
   144 						iStrengthResult = KErrGeneral;
       
   145 						iLog->Log(_L("Battery strength is out of range"));
       
   146 						}
       
   147 					delete aOutput;
       
   148 					}
       
   149 				else
       
   150 					{
       
   151 					iLog->Log(_L("ERROR SET"));
       
   152 					iStrengthResult = KErrGeneral;
       
   153 					}
       
   154 		 
       
   155 				 }
       
   156 
       
   157  			 else if(!aKey.Compare(KBatteryLevel))
       
   158  			 	{
       
   159  			     iLog->Log(_L("Battery Level read.."));
       
   160 		         
       
   161 		         if(!aError)
       
   162 					{
       
   163 					TInt32 tid = aTransID;
       
   164 					if(tid != 2)
       
   165 						{
       
   166 						iLevelResult = KErrGeneral;
       
   167 						iLog->Log(_L("Incorrect TID Retured.. %d"),tid);
       
   168 						}
       
   169 					
       
   170 					TInt batteryLevel = ((CStatus*)aOutput)->Status();
       
   171 					
       
   172 					iLog->Log(_L("Battery Level: %d "),batteryLevel);
       
   173 					
       
   174 					if( batteryLevel >= 0	&& batteryLevel <= 7 )
       
   175 						{
       
   176 						iLevelResult = KErrNone;
       
   177 						iLog->Log(_L("Battery Level is with in expected range"));
       
   178 						}
       
   179 					else
       
   180 						{
       
   181 						iLevelResult = KErrGeneral;
       
   182 						iLog->Log(_L("Battery Level is out of range"));
       
   183 						}
       
   184 					delete aOutput;
       
   185 					}
       
   186 				else
       
   187 					{
       
   188 					iLog->Log(_L("ERROR SET"));
       
   189 					iLevelResult = KErrGeneral;
       
   190 					}
       
   191 		 
       
   192 				 
       
   193  			 	}
       
   194 				
       
   195 			 else if(!aKey.Compare(KChargingStatus))
       
   196  			 	{
       
   197  			     iLog->Log(_L("Battery Charging Status read.."));
       
   198 		         
       
   199 		         if(!aError)
       
   200 					{
       
   201 					TInt32 tid = aTransID;
       
   202 					if(tid != 3)
       
   203 						{
       
   204 						iChargingResult = KErrGeneral;
       
   205 						iLog->Log(_L("Incorrect TID Retured.. %d"),tid);
       
   206 						}
       
   207 					
       
   208 					TInt chargingStatus = ((CStatus*)aOutput)->Status();
       
   209 					
       
   210 					iLog->Log(_L("ChargingStatus: %d "),chargingStatus);
       
   211 					
       
   212 					if( chargingStatus == 1 )
       
   213 						{
       
   214 						iChargingResult = KErrNone;
       
   215 						iLog->Log(_L("Charging status is as expected"));
       
   216 						}
       
   217 					else
       
   218 						{
       
   219 						iChargingResult = KErrGeneral;
       
   220 						iLog->Log(_L("Charging status is wrong"));
       
   221 						}
       
   222 					delete aOutput;
       
   223 					}
       
   224 				else
       
   225 					{
       
   226 					iLog->Log(_L("ERROR SET"));
       
   227 					iChargingResult = KErrGeneral;
       
   228 					}
       
   229 		 			 
       
   230  			 	}
       
   231 				 	
       
   232 			}
       
   233 			
       
   234 		else
       
   235 			{
       
   236 			iLog->Log(_L("Incorrect Entity,Key.."));
       
   237 			iError = KErrGeneral ;
       
   238 			}
       
   239 		}
       
   240 	
       
   241 	}
       
   242 
       
   243 void CBatteryNot::HandleTimeOut()
       
   244 {
       
   245 	iLog->Log(_L("CBatteryNot TimeOut reached..."));
       
   246 	iSysInfoService->Cancel(1) ;
       
   247 	iSysInfoService->Cancel(2) ;
       
   248 	iSysInfoService->Cancel(3) ;
       
   249 	iError = KErrGeneral;
       
   250 	iWaitScheduler->AsyncStop();
       
   251 }
       
   252 
       
   253