locationmgmt/agpslocationmgr/test/te_man/src/man20Step.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     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 // Example CTestStep derived implementation
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file man20Step.cpp
       
    20 */
       
    21 #include "man20step.h"
       
    22 #include "Te_manSuiteDefs.h"
       
    23 #include "LbsInternalInterface.h"
       
    24 #include <lbs/lbslocdatasourcegpsbase.h>
       
    25 #include <lbs/lbsextendedsatellite.h>
       
    26 #include <lbs/lbsgpsmeasurement.h>
       
    27 
       
    28 
       
    29 Cman20Step::~Cman20Step()
       
    30 /**
       
    31  * Destructor
       
    32  */
       
    33 	{
       
    34 	iUpdateCodeProperty.Close();
       
    35 	}
       
    36 
       
    37 Cman20Step::Cman20Step()
       
    38 /**
       
    39  * Constructor
       
    40  */
       
    41 	{
       
    42 	SetTestStepName(Kman20Step);
       
    43 	}
       
    44 
       
    45 TVerdict Cman20Step::doTestStepPreambleL()
       
    46 /*
       
    47  * @return - TVerdict code
       
    48  * Override of base class virtual
       
    49  */
       
    50 	{
       
    51 	SetTestStepResult(EPass);
       
    52 	return TestStepResult();
       
    53 	}
       
    54 
       
    55 
       
    56 TVerdict Cman20Step::doTestStepL()
       
    57 /**
       
    58  * @return - TVerdict code
       
    59   The Location Server requests a location update. The Molr starts and at some point the AGPS Manager has a request from
       
    60   the Location Server and a request from the NRH. The GPS Module produces an update with error code KPositionCalculationFutile.
       
    61   The test checks that the position is published again, with different attributes, when the session is completed.
       
    62  */
       
    63 	{
       
    64 	
       
    65 	if (TestStepResult()==EPass)
       
    66 		{
       
    67 
       
    68 		// Subscribe to the property where the test GPS module reads the desired error code for
       
    69 		// the location update
       
    70     	const TInt KTestLocSourceVal= 0x1028226E;// Secure ID of the test AGPS Manager
       
    71     	const TUid KTestLocSourceUid= {KTestLocSourceVal};
       
    72     	const TInt KUpdateCodePropertyKey = 0x11110100;
       
    73     	User::LeaveIfError(iUpdateCodeProperty.Attach(KTestLocSourceUid, 
       
    74 	                                             KUpdateCodePropertyKey));
       
    75 		
       
    76 		// This test wants to receive a location update with error code KPositionCalculationFutile
       
    77 		iUpdateCodeProperty.Set(KPositionCalculationFutile);
       
    78 		
       
    79 		const RLbsPositionUpdateRequests::TChannelIdentifer KChannelIdentifierNRH = 
       
    80 			{
       
    81 				{KLbsGpsLocManagerUidValue},{KLbsNetRequestHandlerUidValue}
       
    82 			};
       
    83 			
       
    84 		const RLbsPositionUpdateRequests::TChannelIdentifer KChannelIdentifierLocServer = 
       
    85 			{
       
    86 				{KLbsGpsLocManagerUidValue},{KLbsLocServerUidValue}
       
    87 			};
       
    88 			
       
    89 		RLbsPositionUpdateRequests posUpdateReqLocSrv;
       
    90 		posUpdateReqLocSrv.OpenL(KChannelIdentifierLocServer);
       
    91 		CleanupClosePushL(posUpdateReqLocSrv);
       
    92 	
       
    93 		RLbsPositionUpdateRequests posUpdateReqNRH;
       
    94 		posUpdateReqNRH.OpenL(KChannelIdentifierNRH);
       
    95 		CleanupClosePushL(posUpdateReqNRH);
       
    96 		
       
    97 		RLbsPositionUpdates posUpdates;
       
    98 		posUpdates.OpenL(KLbsGpsLocManagerUid);
       
    99 		CleanupClosePushL(posUpdates);
       
   100 	
       
   101 		RLbsGpsMeasurementUpdates measurementUpdates;
       
   102 		measurementUpdates.OpenL();
       
   103 		CleanupClosePushL(measurementUpdates);
       
   104 		TRequestStatus measurementStat;
       
   105 		measurementUpdates.NotifyGpsMeasurementUpdate(measurementStat);
       
   106 		
       
   107 		RLbsModuleStatus modStatus;
       
   108 		modStatus.OpenL(KLbsGpsLocManagerUid);
       
   109 		CleanupClosePushL(modStatus);
       
   110 
       
   111 		TLbsPositionUpdateRequestCancel cancel;
       
   112 		
       
   113 		// simulate what is done by Location Server when it wants a location update
       
   114 		TLbsPositionUpdateRequest locRequest;
       
   115 		TLbsLocRequestQualityInt quality;
       
   116 		quality.SetMaxFixTime(10000000);// 10 seconds
       
   117 		quality.SetMinHorizontalAccuracy(0.1);
       
   118 		quality.SetMinVerticalAccuracy(0.1);
       
   119 		TTime targetTime;
       
   120 		targetTime.UniversalTime(); // target time is now and try for 10 seconds!
       
   121     	locRequest.RequestQuality() = quality;
       
   122 		locRequest.TargetTime() = targetTime;
       
   123 		
       
   124 		TLbsNetPosRequestMethodInt methods;
       
   125 		TLbsNetPosMethodInt posMethods[1];
       
   126 		posMethods[0].SetPosMethod(KLbsRootUid, (TPositionModuleInfo::ETechnologyTerminal|TPositionModuleInfo::ETechnologyAssisted));
       
   127 		methods.SetPosMethods(posMethods, 1);
       
   128 		locRequest.RequestMethod() = methods;
       
   129 		
       
   130 		INFO_PRINTF1(_L("Loc server sends a location request to integration module"));
       
   131 		User::LeaveIfError(posUpdateReqLocSrv.SetPositionUpdateRequest(locRequest));
       
   132 		
       
   133 		User::After(1000000); //Allow a second for the request to sink in
       
   134 
       
   135 
       
   136 		// Simulate what is done by NRH when it wants a hybrid location update
       
   137 		TLbsPositionUpdateRequest locRequestNRH;
       
   138 		TLbsLocRequestQualityInt qualityNRH;
       
   139 		qualityNRH.SetMaxFixTime(5000000);// five seconds -shorter than LocServers's-
       
   140 		qualityNRH.SetMinHorizontalAccuracy(0.5);
       
   141 		qualityNRH.SetMinVerticalAccuracy(0.5);
       
   142     	locRequestNRH.RequestQuality() = qualityNRH;    	
       
   143 		locRequestNRH.TargetTime() = targetTime; // Target time is now and try for 5 seconds
       
   144 		// Make the request a 'hybrid' one
       
   145 		TLbsNetPosRequestMethodInt nrhmethods;
       
   146 		TLbsNetPosMethodInt nrhposMethods[2];
       
   147 		nrhposMethods[0].SetPosMethod(KLbsRootUid, (TPositionModuleInfo::ETechnologyTerminal|TPositionModuleInfo::ETechnologyAssisted));
       
   148 		nrhposMethods[1].SetPosMethod(KLbsRootUid, (TPositionModuleInfo::ETechnologyNetwork | TPositionModuleInfo::ETechnologyAssisted));
       
   149 		nrhmethods.SetPosMethods(nrhposMethods, 2);
       
   150 		locRequestNRH.RequestMethod() = nrhmethods;
       
   151 		
       
   152 		
       
   153 		TRequestStatus locState;
       
   154 		posUpdates.NotifyPositionUpdate(locState);
       
   155 		INFO_PRINTF1(_L("NRH sends a location request to integration module"));
       
   156 		User::LeaveIfError(posUpdateReqNRH.SetPositionUpdateRequest(locRequestNRH));
       
   157 		
       
   158 		// Check first that the GPS Manager publishes a position update as provided
       
   159 		// by the test integration module (the test version of the integration module
       
   160 		// is hardwired to send a test TPositionExtendedSatelliteInfo)
       
   161 		// Check also that the error code is KPositionCalculationFutile
       
   162 		//
       
   163 		User::WaitForRequest(locState);
       
   164 		
       
   165 		if(locState.Int()!=KErrNone)
       
   166 			User::Leave(KErrGeneral);
       
   167 		
       
   168 		TInt error = 1; // something other than KErrNone
       
   169 		TTime actualTime = 0;
       
   170 		targetTime = 0;
       
   171 
       
   172 		TPositionExtendedSatelliteInfo satInfo;
       
   173 		TBool conflictControl;
       
   174 		TUint attributes;
       
   175 		TUint gpsMode;
       
   176 		error = posUpdates.GetPositionInfo(conflictControl, &satInfo, 
       
   177 												   sizeof(satInfo), targetTime, 
       
   178 												   actualTime, attributes, gpsMode);
       
   179 		if(KPositionCalculationFutile != error)
       
   180 			User::Leave(KErrGeneral);
       
   181 
       
   182 		INFO_PRINTF1(_L("Test integration module correctly responds with KPositionCalculationFutile"));
       
   183 
       
   184 		if(RLbsPositionUpdates::ESelfLocateSessionInProgress != attributes)
       
   185 				User::Leave(KErrGeneral);
       
   186 		INFO_PRINTF1(_L("Attribute obtained are correct (ESelfLocateSessionInProgress)"));
       
   187 
       
   188 		if(targetTime!=locRequestNRH.TargetTime())
       
   189 			User::Leave(KErrGeneral);
       
   190 
       
   191 		if(satInfo.SatelliteTime()!=locRequestNRH.TargetTime())
       
   192 			User::Leave(KErrGeneral);
       
   193 
       
   194 		INFO_PRINTF1(_L("Test integration module has correctly responded with a position as expected"));
       
   195 
       
   196 		// Check that the GPS Manager publishes a measurement update as provided
       
   197 		// by the test integration module (the test version of the integration module
       
   198 		// is hardwired to send a measurement update with 1 measured data)
       
   199 		//
       
   200 		User::WaitForRequest(measurementStat);
       
   201 		
       
   202 		if(measurementStat.Int()!=KErrNone)
       
   203 			User::Leave(KErrGeneral);
       
   204 		
       
   205 		error = 1; // something other than KErrNone
       
   206 		actualTime = 0;
       
   207 
       
   208 		TPositionGpsMeasurementInfo measurementUpdate;
       
   209 		error = measurementUpdates.GetGpsMeasurementInfo(&measurementUpdate, sizeof(measurementUpdate), actualTime);
       
   210 		
       
   211 		if(error!=KPositionCalculationFutile)
       
   212 			User::Leave(KErrGeneral);
       
   213 		
       
   214 		INFO_PRINTF1(_L("Measurement update error code is correct"));
       
   215 
       
   216 		// The last part of the test consists of cancelling the request and check the results
       
   217 		// The test GPS Module will show those results by changes to the module status (this wouldn't
       
   218 		// happen in production code, it is just for testing). Set the module status to some initial values
       
   219 		// before cancelling.
       
   220 		TPositionModuleStatus moduleStatus;
       
   221 		moduleStatus.SetDeviceStatus(TPositionModuleStatus::EDeviceReady);
       
   222 		moduleStatus.SetDataQualityStatus(TPositionModuleStatus::EDataQualityNormal);
       
   223 
       
   224         TPositionModuleStatusEventBase::TModuleEvent occurredEvents = 
       
   225 						TPositionModuleStatusEventBase::EEventDeviceStatus | TPositionModuleStatusEventBase::EEventDataQualityStatus;
       
   226 		User::LeaveIfError(modStatus.SetModuleStatus(&moduleStatus,sizeof(moduleStatus),occurredEvents));
       
   227 		User::After(1000000);
       
   228 	    
       
   229 		// now we expect to see the ESelfLocationRequest and also a 
       
   230 		// EAssistanceDataRequest (as a result of the integration module
       
   231 		// asking for assisatance data when it receives the location request
       
   232 		// from the NRH
       
   233    		WaitAndValidateNgMsg(TLbsNetInternalMsgBase::ESelfLocationRequest);
       
   234 		WaitAndValidateNgMsg(TLbsNetInternalMsgBase::EAssistanceDataRequest);
       
   235 	
       
   236 		// Cancel NRH's location update request.
       
   237 		// The AGPS Manager should ask the Integration Module to
       
   238 		// configure the GPS Mode as per Admin setting; but it should not
       
   239 		// cancel the location request in the GPS module.
       
   240 		//
       
   241 		User::LeaveIfError(posUpdateReqNRH.SetPositionUpdateRequest(cancel));
       
   242 		
       
   243 		//...let the cancel message do its thing for a second
       
   244 		User::After(1000000);
       
   245 		
       
   246 	    User::LeaveIfError(modStatus.GetModuleStatus(&moduleStatus, sizeof(moduleStatus), occurredEvents));
       
   247 
       
   248 		// Check that the cancellation has NOT resulted in a call to CancelLocationRequest of the
       
   249 		// integration module (hack: the test integration module switches the Data Quality Status
       
   250 		// when CancelLocationRequest is called while in 'hybrid'mode)
       
   251 		//
       
   252 		//if (moduleStatus.DataQualityStatus() == TPositionModuleStatus::EDataQualityPartial)
       
   253 		//	{
       
   254 		//	User::Leave(KErrNotFound);
       
   255 		//	}
       
   256 		
       
   257 		// Check that the AGPS manager has reconfigured the Integration Module' GPS mode with the 
       
   258 		// Admin setting after leaving the hybrid mode. (NOTE: for testing purposes, the test integration 
       
   259 		// module switches state to EDeviceInitialising when it is configured with a new admin setting)
       
   260 		//
       
   261 		if(moduleStatus.DeviceStatus() == TPositionModuleStatus::EDeviceReady)
       
   262 			{
       
   263 			INFO_PRINTF1(_L("Error in DeviceStatus: GPS mode not changed."));
       
   264 			User::Leave(KErrNotFound);
       
   265 			}
       
   266 		
       
   267 		
       
   268 		// Re-set property
       
   269 		iUpdateCodeProperty.Set(KErrNone);
       
   270 
       
   271 		// Clean up
       
   272 		User::LeaveIfError(posUpdateReqLocSrv.SetPositionUpdateRequest(cancel));
       
   273 		User::After(1000000);
       
   274 
       
   275 		// and now the NetworkGateway should recieve a cancel as a result of the cancellation of the 
       
   276 		// request from location server 
       
   277 		WaitAndValidateNgMsg(TLbsNetInternalMsgBase::ESelfLocationCancel);
       
   278 		
       
   279 		SendNgMsg(KSessionCompleteKErrNone);
       
   280 
       
   281 		CleanupStack::PopAndDestroy(&modStatus);
       
   282 		CleanupStack::PopAndDestroy(&measurementUpdates);
       
   283 		CleanupStack::PopAndDestroy(&posUpdates);
       
   284 		CleanupStack::PopAndDestroy(&posUpdateReqNRH);
       
   285 		CleanupStack::PopAndDestroy(&posUpdateReqLocSrv);
       
   286 
       
   287 	 		//  **************   Block end ****************
       
   288 
       
   289 		SetTestStepResult(EPass);
       
   290 		}
       
   291 	  return TestStepResult();
       
   292 	}
       
   293 
       
   294 
       
   295 
       
   296 
       
   297 TVerdict Cman20Step::doTestStepPostambleL()
       
   298 /**
       
   299  * @return - TVerdict code
       
   300  * Override of base class virtual
       
   301  */
       
   302 	{
       
   303 	return TestStepResult();
       
   304 	}