lbstest/lbstestproduct/lbshybridmolr/src/ctlbshybridueassistedmolrpartial.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 // This is the class implementation for the Hybrid MoLr Tests
       
    15 // 
       
    16 //
       
    17 
       
    18 
       
    19 // EPOC includes.
       
    20 #include <e32math.h>
       
    21 
       
    22 // LBS includes. 
       
    23 #include <lbssatellite.h>
       
    24 #include <lbs/lbsgpsmeasurement.h>
       
    25 #include <lbs/lbsnetprotocolbase.h>
       
    26 #include <lbs/lbsassistancedatabuilderset.h>
       
    27 #include <lbs/lbsloccommon.h>
       
    28 #include <lbs/lbsx3p.h>
       
    29 #include <lbs/lbsnetprotocolbase.h>
       
    30 
       
    31 // LBS test includes.
       
    32 //#include "ctlbsuebasedmolrself.h"
       
    33 #include "ctlbshybridueassistedmolrpartial.h"
       
    34 #include <lbs/test/tlbsutils.h>
       
    35 #include "argutils.h"
       
    36 #include <lbs/test/activeyield.h>
       
    37 
       
    38 
       
    39 /**
       
    40 Static Constructor
       
    41 */
       
    42 CT_LbsHybridUEAssistedMOLRPartial* CT_LbsHybridUEAssistedMOLRPartial::New(CT_LbsHybridMOLRServer& aParent)
       
    43 	{
       
    44 	// Note the lack of ELeave.
       
    45 	// This means that having insufficient memory will return NULL;
       
    46 	CT_LbsHybridUEAssistedMOLRPartial* testStep = new CT_LbsHybridUEAssistedMOLRPartial(aParent);
       
    47 	if (testStep)
       
    48 		{
       
    49 		TInt err = KErrNone;
       
    50 
       
    51 		TRAP(err, testStep->ConstructL());
       
    52 		if (err)
       
    53 			{
       
    54 			delete testStep;
       
    55 			testStep = NULL;
       
    56 			}
       
    57 		}
       
    58 	return testStep;
       
    59 	}
       
    60 
       
    61 
       
    62 /**
       
    63  * Constructor
       
    64  */
       
    65 CT_LbsHybridUEAssistedMOLRPartial::CT_LbsHybridUEAssistedMOLRPartial(CT_LbsHybridMOLRServer& aParent) : CT_LbsHybridMOLRStep(aParent)
       
    66 	{
       
    67 	SetTestStepName(KLbsHybridUEAssistedMOLRPartial);
       
    68 	
       
    69 	iSessionId.SetSessionOwner(KRequestUid);
       
    70 	iSessionId.SetSessionNum(0x0001);
       
    71 	}
       
    72 
       
    73 
       
    74 void CT_LbsHybridUEAssistedMOLRPartial::ConstructL()
       
    75 	{
       
    76 	// Create the base class objects.
       
    77 	CT_LbsHybridMOLRStep::ConstructL();
       
    78 	}
       
    79 
       
    80 /**
       
    81  * Destructor
       
    82  */
       
    83 CT_LbsHybridUEAssistedMOLRPartial::~CT_LbsHybridUEAssistedMOLRPartial()
       
    84 	{
       
    85 	}
       
    86 
       
    87 
       
    88 TVerdict CT_LbsHybridUEAssistedMOLRPartial::doTestStepL()
       
    89 	{
       
    90 	INFO_PRINTF1(_L("CT_LbsHybridUEAssistedMOLRPartial::doTestStepL()"));	
       
    91 	// Stop the test if the preable failed
       
    92 	TESTL(TestStepResult() == EPass);
       
    93 
       
    94 	const TInt KTimeOut = 60*1000*1000;
       
    95 	
       
    96 	_LIT(KEarlyCompleteSupported, "early_complete_supported");
       
    97 	// For the S60 Loc Server the test will return KErrNone instead of KErrNotFound.
       
    98 	if(!GetIntFromConfig(ConfigSection(), KEarlyCompleteSupported, iEarlyCompleteSupported))
       
    99 		{
       
   100 		// we support early complete by default unless configured otherwise
       
   101 		iEarlyCompleteSupported = ETrue;
       
   102 		}
       
   103 	
       
   104 	// To ensure the location server does not timeout the partial update requests from the client
       
   105 	// smaller timeout values are used (new client timer added because of CR1041).
       
   106 	const TInt KAlpha2TimeOutValue = 8 * 1000 * 1000;
       
   107 	const TInt KTTimeOutvalue = 4 * 1000 * 1000;
       
   108 
       
   109 	// Create Network Protocol Proxy
       
   110 	CNetProtocolProxy* proxy = CNetProtocolProxy::NewL();
       
   111 	CleanupStack::PushL(proxy);
       
   112 
       
   113 // Recv --> GetCurrentCapabilitiesResponse.
       
   114 	// Soak up the Lbs System Status (produced by A-GPS Manager startup). 
       
   115 	TESTL(proxy->WaitForResponse(KTimeOut) == ENetMsgGetCurrentCapabilitiesResponse);
       
   116 	CLbsNetworkProtocolBase::TLbsSystemStatus status;
       
   117 	TInt cleanupCnt;
       
   118 	cleanupCnt = proxy->GetArgsLC(ENetMsgGetCurrentCapabilitiesResponse, &status);
       
   119 	TESTL(status == CLbsNetworkProtocolBase::ESystemStatusNone);
       
   120 	CleanupStack::PopAndDestroy(cleanupCnt);
       
   121 
       
   122 
       
   123 // Do the /actual/ test step!
       
   124 
       
   125 	// Setup location session and position watcher.
       
   126 	RPositionServer server;
       
   127 	TESTL(KErrNone == server.Connect());
       
   128 	CleanupClosePushL(server);	
       
   129 
       
   130 	RPositioner pos;
       
   131 	TESTL(KErrNone == pos.Open(server));
       
   132 	CleanupClosePushL(pos);
       
   133 
       
   134 	// Set the max fix time for the client request to ensure the location server does not complete the request too soon during the test.
       
   135 	
       
   136 	// Switch on partial updates.
       
   137 	TPositionUpdateOptions posOpts(TTimeIntervalMicroSeconds(0), TTimeIntervalMicroSeconds(KMOLRFixTime), TTimeIntervalMicroSeconds(0), ETrue);
       
   138 	pos.SetUpdateOptions(posOpts);	
       
   139 
       
   140 
       
   141 	CPosServerWatcher *pWatch = CPosServerWatcher::NewLC(pos, *this);
       
   142 
       
   143 // Client Send - a self-locate request, for the NaN position.
       
   144 	pWatch->IssueNotifyPositionUpdate();
       
   145 
       
   146 // Client recv - the NaN position app side.
       
   147 	CheckForObserverEventTestsL(KTimeOut, *this);
       
   148 
       
   149 
       
   150 // Client Send - a self-locate request, for the request reference position.
       
   151 	pWatch->IssueNotifyPositionUpdate();
       
   152 
       
   153 
       
   154 // Recv --> RequestSelfLocation.
       
   155 	TESTL(proxy->WaitForResponse(KTimeOut) == ENetMsgRequestSelfLocation);
       
   156 
       
   157 	// Process the response.
       
   158 	TLbsNetSessionId* 					sessionId = NULL;
       
   159 	TLbsNetPosRequestOptionsAssistance*	opts = NULL;
       
   160 	
       
   161 	cleanupCnt = proxy->GetArgsLC(ENetMsgRequestSelfLocation, &sessionId, &opts);
       
   162 	
       
   163 	TBool qualitycheck = ArgUtils::CompareQuality(	opts, 
       
   164 													ETrue, 
       
   165 													KMinHorizontalAcc, 
       
   166 													KMinVerticalAcc, 
       
   167 													KMOLRFixTime,
       
   168 													0, 
       
   169 													EAssistanceDataReferenceTime, 
       
   170 													(TPositionModuleInfo::ETechnologyTerminal 
       
   171 													| TPositionModuleInfo::ETechnologyAssisted)
       
   172 												);					
       
   173 	TESTL(qualitycheck);
       
   174 	
       
   175 	iSessionId.SetSessionNum(sessionId->SessionNum());
       
   176 	iSessionId.SetSessionOwner(sessionId->SessionOwner());
       
   177 
       
   178 	CleanupStack::PopAndDestroy(cleanupCnt);
       
   179 	sessionId = NULL;
       
   180 	opts = NULL;	
       
   181 
       
   182 		
       
   183 // Send <-- ProcessStatusUpdate.
       
   184 	MLbsNetworkProtocolObserver::TLbsNetProtocolService serviceMask = MLbsNetworkProtocolObserver::EServiceSelfLocation;
       
   185 	proxy->CallL(ENetMsgProcessStatusUpdate, &serviceMask);
       
   186 
       
   187 	
       
   188 // Send <-- ProcessLocationUpdate.
       
   189 	TPositionInfo refPosInfo = ArgUtils::MolrReferencePositionInfo();
       
   190 	proxy->CallL(ENetMsgProcessLocationUpdate, &iSessionId, &refPosInfo);
       
   191 
       
   192 
       
   193 // Client recv - the ref position app side.
       
   194 	CheckForObserverEventTestsL(KTimeOut, *this);
       
   195 
       
   196 
       
   197 // Send <-- ProcessAssistanceData.
       
   198 	TLbsAsistanceDataGroup			dataMask = EAssistanceDataReferenceTime;
       
   199 	RLbsAssistanceDataBuilderSet	data;
       
   200 	TInt							reason = KErrNone;
       
   201 	ArgUtils::PopulateLC(data);
       
   202 	proxy->CallL(ENetMsgProcessAssistanceData, &dataMask, &data, &reason);
       
   203 	CleanupStack::PopAndDestroy(); // data
       
   204 
       
   205 	// Now that the hybrid/alpha2 has been requested, record current time to verify alpha2 timer expires correctly.
       
   206 	TTime startTime;
       
   207 	startTime.HomeTime();
       
   208 
       
   209 
       
   210 //  Recv --> RequestAssistanceData, as the result of the 2nd NPUD request.
       
   211 	TESTL(proxy->WaitForResponse(KTimeOut) == ENetMsgRequestAssistanceData); 
       
   212 	cleanupCnt = proxy->GetArgsLC(ENetMsgRequestAssistanceData, &dataMask);
       
   213 	TESTL(dataMask == EAssistanceDataNone);
       
   214 	CleanupStack::PopAndDestroy(cleanupCnt);
       
   215 
       
   216 
       
   217 // Client Send - a self-locate request, for the first partial update.
       
   218 	pWatch->IssueNotifyPositionUpdate();
       
   219 
       
   220 
       
   221 // Rev --> RequestAssistanceData, as the result of the first partial update.
       
   222 	TESTL(proxy->WaitForResponse(KTimeOut) == ENetMsgRequestAssistanceData); 
       
   223 	cleanupCnt = proxy->GetArgsLC(ENetMsgRequestAssistanceData, &dataMask);
       
   224 	TESTL(dataMask == EAssistanceDataNone);
       
   225 	CleanupStack::PopAndDestroy(cleanupCnt);
       
   226 
       
   227 // Send <-- ProcessLocationRequest.
       
   228 	TBool												emergency = EFalse;
       
   229 	MLbsNetworkProtocolObserver::TLbsNetProtocolService	service = MLbsNetworkProtocolObserver::EServiceSelfLocation;
       
   230 	TLbsNetPosRequestQuality							quality = ArgUtils::Quality();
       
   231 	TLbsNetPosRequestMethod								method = ArgUtils::RequestHybridMethod();
       
   232 	quality.SetMaxFixTime(KAlpha2TimeOutValue/*MolrArgUtils::Alpha2()*/);
       
   233 	proxy->CallL(ENetMsgProcessLocationRequest, &iSessionId, &emergency, &service, &quality, &method);
       
   234 
       
   235 
       
   236 // Client recv - to get the first partial update.
       
   237 	CheckForObserverEventTestsL(KTimeOut, *this);
       
   238 
       
   239 
       
   240 
       
   241 // Recv -> RequestAssistanceData - we get an extra msg as the result of the A-GPS manager re-issueing a location request when it's
       
   242 //									max fix time timer expries.
       
   243 	TESTL(proxy->WaitForResponse(KTimeOut) == ENetMsgRequestAssistanceData); 
       
   244 	cleanupCnt = proxy->GetArgsLC(ENetMsgRequestAssistanceData, &dataMask);
       
   245 	TESTL(dataMask == EAssistanceDataNone);
       
   246 	CleanupStack::PopAndDestroy(cleanupCnt);
       
   247 
       
   248 // Recv --> RespondLocationRequest.
       
   249 
       
   250 	// Determine the value to take off the alpha2 value. This is required because we had to wait for the assistance data response.
       
   251 	TTimeIntervalMicroSeconds microseconds;
       
   252 	TTime stopTime;
       
   253 	stopTime.HomeTime();
       
   254 	microseconds = stopTime.MicroSecondsFrom(startTime); 
       
   255 	TInt64 timeElapsed = microseconds.Int64();
       
   256 
       
   257 	// First ensure we don't recv response before Alpha2.
       
   258 	TInt delta = 2 * 1000 * 1000; // 2 secs.
       
   259 	TESTL(proxy->WaitForResponse(KAlpha2TimeOutValue/*MolrArgUtils::Alpha2()*/ - timeElapsed - delta) == ENetMsgTimeoutExpired);
       
   260 	
       
   261 	// Wait for and process the response.
       
   262 	TESTL(proxy->WaitForResponse(2 * delta) == ENetMsgRespondLocationRequest);
       
   263 
       
   264 	TPositionGpsMeasurementInfo* measurementInfo = NULL;
       
   265 	cleanupCnt = proxy->GetArgsLC(ENetMsgRespondLocationRequest, &sessionId, &reason, &measurementInfo);
       
   266 	TESTL(sessionId->SessionNum() == iSessionId.SessionNum());
       
   267 	TESTL(reason == KErrNone);
       
   268 	TESTL(measurementInfo->PositionClassType() == EPositionGpsMeasurementInfoClass);
       
   269 	
       
   270 	CleanupStack::PopAndDestroy(cleanupCnt);
       
   271 	sessionId = NULL;
       
   272 	measurementInfo = NULL;
       
   273 
       
   274 
       
   275 // Recv -> RequestAssistanceData - we get an extra msg as the result of the A-GPS manager re-issueing a location request when it's
       
   276 //									max fix time timer expries.
       
   277 	TESTL(proxy->WaitForResponse(KTimeOut) == ENetMsgRequestAssistanceData); 
       
   278 	cleanupCnt = proxy->GetArgsLC(ENetMsgRequestAssistanceData, &dataMask);
       
   279 	TESTL(dataMask == EAssistanceDataNone);
       
   280 	CleanupStack::PopAndDestroy(cleanupCnt);
       
   281 
       
   282 // Send <-- ProcessLocationRequest - time t.
       
   283 	quality.SetMaxFixTime(KTTimeOutvalue/*KTTimeout*/);
       
   284 
       
   285 	proxy->CallL(ENetMsgProcessLocationRequest, &iSessionId, &emergency, &service, &quality, &method);
       
   286 
       
   287 
       
   288 // Recv --> RequestAssistanceData.
       
   289 	TESTL(proxy->WaitForResponse(KTimeOut) == ENetMsgRequestAssistanceData); 
       
   290 	cleanupCnt = proxy->GetArgsLC(ENetMsgRequestAssistanceData, &dataMask);
       
   291 	TESTL(dataMask == EAssistanceDataNone);
       
   292 	CleanupStack::PopAndDestroy(cleanupCnt);
       
   293 // Client Send - a self-locate request, for the second partial update.
       
   294 	pWatch->IssueNotifyPositionUpdate();
       
   295 
       
   296 
       
   297 // Rev --> RequestAssistanceData, as the result of the second partial update.
       
   298 	TESTL(proxy->WaitForResponse(KTimeOut) == ENetMsgRequestAssistanceData); 
       
   299 	cleanupCnt = proxy->GetArgsLC(ENetMsgRequestAssistanceData, &dataMask);
       
   300 	TESTL(dataMask == EAssistanceDataNone);
       
   301 	CleanupStack::PopAndDestroy(cleanupCnt);
       
   302 
       
   303 	if(iEarlyCompleteSupported)
       
   304 		{
       
   305 		// CompleteRequest, for the second partial request.
       
   306 			TESTL(pos.CompleteRequest(EPositionerNotifyPositionUpdate) == KErrNone);
       
   307 		
       
   308 		// Client recv - to get the second partial, cancelled by the client.
       
   309 			CheckForObserverEventTestsL(KTimeOut, *this);
       
   310 			TESTL(iState == EGpsPartialEarlyReceived);
       
   311 		
       
   312 // Recv --> RespondLocationRequest - the first partial gps position.
       
   313 		TESTL(proxy->WaitForResponse(KTimeOut) == ENetMsgRespondLocationRequest);
       
   314 	
       
   315 		sessionId = NULL;
       
   316 		TPositionInfo* positionInfo = NULL;
       
   317 				
       
   318 		cleanupCnt = proxy->GetArgsLC(ENetMsgRespondLocationRequest, &sessionId, &reason, &positionInfo);
       
   319 				
       
   320 		// Check the response.
       
   321 		TESTL(positionInfo->PositionClassType() == (EPositionInfoClass|EPositionCourseInfoClass|EPositionSatelliteInfoClass));
       
   322 		TESTL(sessionId->SessionNum() == iSessionId.SessionNum());
       
   323 		TESTL(reason == KErrNone);
       
   324 		CleanupStack::PopAndDestroy(cleanupCnt);
       
   325 		}
       
   326 	else	// if early complete not supported, just stop asking for updates.
       
   327 		{
       
   328 		// In this case the NRH will send measurements to the network again rather than a position
       
   329 // Recv --> RespondLocationRequest - the first partial gps position.
       
   330 			TESTL(proxy->WaitForResponse(KTimeOut) == ENetMsgRespondLocationRequest);
       
   331 		
       
   332 			sessionId = NULL;
       
   333 			
       
   334 			TPositionGpsMeasurementInfo* measurementInfo = NULL;
       
   335 			cleanupCnt = proxy->GetArgsLC(ENetMsgRespondLocationRequest, &sessionId, &reason, &measurementInfo);
       
   336 			TESTL(sessionId->SessionNum() == iSessionId.SessionNum());
       
   337 			TESTL(reason == KErrNone);
       
   338 			TESTL(measurementInfo->PositionClassType() == EPositionGpsMeasurementInfoClass);
       
   339 						
       
   340 			CleanupStack::PopAndDestroy(cleanupCnt);	
       
   341 		
       
   342 		}
       
   343 	
       
   344 // Send <-- ProcessLocationUpdate - return network calculated pos
       
   345 	TPositionInfo networkPosInfo = ArgUtils::MolrNetworkPositionInfo();
       
   346 	proxy->CallL(ENetMsgProcessLocationUpdate, &iSessionId, &networkPosInfo);
       
   347 
       
   348 
       
   349 // Send <-- ProcessSessionComplete.
       
   350 	reason = KErrNone;
       
   351 	proxy->CallL(ENetMsgProcessSessionComplete, &iSessionId, &reason);
       
   352 
       
   353 
       
   354 // Send <-- ProcessStatusUpdate.
       
   355 	serviceMask = MLbsNetworkProtocolObserver::EServiceNone;
       
   356 	proxy->CallL(ENetMsgProcessStatusUpdate, &serviceMask);
       
   357 
       
   358 
       
   359 // Done. Now cleanup...
       
   360 	CleanupStack::PopAndDestroy(pWatch);
       
   361 	CleanupStack::PopAndDestroy(); // pos
       
   362 	CleanupStack::PopAndDestroy(); // server	
       
   363 	CleanupStack::PopAndDestroy(proxy);
       
   364 
       
   365 		
       
   366 	return TestStepResult();
       
   367 	}
       
   368 
       
   369 
       
   370 
       
   371 
       
   372 // MPosServerObserver
       
   373 void CT_LbsHybridUEAssistedMOLRPartial::OnGetLastKnownPosition(TInt32 /*aErr*/, const TPositionInfoBase& /*aPosInfo*/)
       
   374 	{
       
   375 	TEST(EFalse); // Shouldn't see this...
       
   376 	ReturnToTestStep();
       
   377 	}
       
   378 
       
   379 
       
   380 void CT_LbsHybridUEAssistedMOLRPartial::OnNotifyPositionUpdate(TInt32 aErr, const TPositionInfoBase& aPosInfo)
       
   381 	{
       
   382 	// Verify position.
       
   383 	TEST(aPosInfo.PositionClassType() == EPositionInfoClass);
       
   384 
       
   385 	// Expecting first partial update, NaN position.
       
   386 	if (iState == EInitializing)
       
   387 		{
       
   388 		iState = EGpsPartialInitReceived;
       
   389 		
       
   390 		TEST(aErr == KPositionPartialUpdate);
       
   391 		TEST(aPosInfo.PositionMode() == (TPositionModuleInfo::ETechnologyTerminal | TPositionModuleInfo::ETechnologyAssisted));
       
   392 		
       
   393 		// check for nan in partial updates
       
   394 		const TPositionInfo posInfo = static_cast<const TPositionInfo&>(aPosInfo);
       
   395 		TESTL(ArgUtils::ComparePositionInfoToNan(posInfo));
       
   396 		}
       
   397 
       
   398 	// Expecting ref pos.
       
   399 	else if (iState == EGpsPartialInitReceived)
       
   400 		{
       
   401 		iState = ERefLocReceived;
       
   402 
       
   403 		_LIT(KExpectedRefError, "expected_ref_error");
       
   404 		TInt expected_ref_error;
       
   405 		// For the S60 Loc Server the test will return KErrNone instead of KErrNotFound.
       
   406 		if(!GetIntFromConfig(ConfigSection(), KExpectedRefError, expected_ref_error))
       
   407 			{
       
   408 			expected_ref_error = KPositionPartialUpdate;
       
   409 			}		
       
   410 		TEST(aErr == expected_ref_error);
       
   411 		TEST(aPosInfo.PositionMode() == TPositionModuleInfo::ETechnologyNetwork);
       
   412 		
       
   413 		// check for refpos details
       
   414 		const TPositionInfo posInfo = static_cast<const TPositionInfo&>(aPosInfo);
       
   415 		TESTL(ArgUtils::ComparePositionInfoToMolrRefPos(posInfo));
       
   416 		}
       
   417 
       
   418 	// Expecting first partial gps position.
       
   419 	else if (iState == ERefLocReceived)
       
   420 		{
       
   421 		iState = EGpsPartialLocReceived;
       
   422 
       
   423 		TEST(aErr == KPositionPartialUpdate);
       
   424 		TEST(aPosInfo.PositionMode() == (TPositionModuleInfo::ETechnologyTerminal | TPositionModuleInfo::ETechnologyAssisted));
       
   425 		}	
       
   426 	// Expecting early complete, of the second partial gps position.
       
   427 	else if (iState == EGpsPartialLocReceived && iEarlyCompleteSupported)
       
   428 		{			
       
   429 		iState = EGpsPartialEarlyReceived;
       
   430 		
       
   431 		TEST(aErr == KPositionEarlyComplete);
       
   432 		}
       
   433 	// Not expecting anything else.
       
   434 	else
       
   435 		{
       
   436 		TEST(EFalse);
       
   437 		}
       
   438 
       
   439 	ReturnToTestStep();
       
   440 	}
       
   441