common/tools/ats/smoketest/lbs/lbsclient/src/ctlbsclientstepcellbasednpud.cpp
changeset 748 e13acd883fbe
child 872 17498133d9ad
equal deleted inserted replaced
747:76f9aaeefbab 748:e13acd883fbe
       
     1 // Copyright (c) 2006-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 the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // @file ctlbsclientstep_cellbasednpud.cpp
       
    15 // This is the class implementation for the Notify Position Update Tests
       
    16 // 
       
    17 //
       
    18  
       
    19 #include "ctlbsclientstepcellbasednpud.h"
       
    20 
       
    21 #include <lbs.h>
       
    22 #include <lbssatellite.h>
       
    23 
       
    24 #include "tlbsutils.h"
       
    25 #include "ctlbsasyncwaiter.h"
       
    26 
       
    27 
       
    28 // constant definitions
       
    29 
       
    30 _LIT(KLbsClientStepCellBasedNotifyPosUpdate, "LbsClientStepCellBasedNotifyPosUpdate");
       
    31 
       
    32 // by default, a test case will abort after this time if all callbacks not completed:
       
    33 // Note that this must be less than the TEF timeout in the script to be of any value
       
    34 TTimeIntervalMicroSeconds32 KDefaultAbortTimerPeriod = 90*1000000;	// 1.5 mins 
       
    35 
       
    36 // by default, a test case running with real gps hardware will abort after this time 
       
    37 // Note that this must be less than the TEF timeout in the script to be of any value
       
    38 TTimeIntervalMicroSeconds32 KDefaultAbortTimerPeriod_real = 100*1000000;	// 5 mins
       
    39 
       
    40 
       
    41 /**
       
    42  * Destructor
       
    43  */
       
    44 CT_LbsClientStep_CellBasedNotifyPosUpdate::~CT_LbsClientStep_CellBasedNotifyPosUpdate()
       
    45 	{
       
    46 	iDoPosUpdate->Cancel();
       
    47 	delete iDoPosUpdate;
       
    48 	}
       
    49 
       
    50 
       
    51 /**
       
    52  * Constructor
       
    53  */
       
    54 CT_LbsClientStep_CellBasedNotifyPosUpdate::CT_LbsClientStep_CellBasedNotifyPosUpdate(CT_LbsClientServer& aParent) : iParent(aParent)
       
    55 	{	
       
    56 	SetTestStepName(KLbsClientStep_CellBasedNotifyPosUpdate);
       
    57 	}
       
    58 
       
    59 
       
    60 /**
       
    61 Static Constructor
       
    62 */
       
    63 CT_LbsClientStep_CellBasedNotifyPosUpdate* CT_LbsClientStep_CellBasedNotifyPosUpdate::New(CT_LbsClientServer& aParent)
       
    64 	{
       
    65 	// Can't leave, so return NULL if insufficient memory
       
    66 	CT_LbsClientStep_CellBasedNotifyPosUpdate* testStep = new CT_LbsClientStep_CellBasedNotifyPosUpdate(aParent);
       
    67 	if (testStep)
       
    68 		{
       
    69 		TInt err = KErrNone;
       
    70 
       
    71 		TRAP(err, testStep->ConstructL());
       
    72 		if (err)
       
    73 			{
       
    74 			delete testStep;
       
    75 			testStep = NULL;
       
    76 			}
       
    77 		}
       
    78 	return testStep;
       
    79 	
       
    80 	}	
       
    81 	
       
    82 void CT_LbsClientStep_CellBasedNotifyPosUpdate::ConstructL()
       
    83 	{
       
    84 	// Create the base class object.
       
    85     CT_LbsNetSimStep::ConstructL();
       
    86 	
       
    87 	// Active object wrapper for the notify position update.
       
    88 	iDoPosUpdate = CT_LbsDoPosUpdate::NewL(this, TPositionModuleInfo::ETechnologyNetwork);
       
    89 	
       
    90 	}
       
    91 	
       
    92 /**
       
    93  * @return - TVerdict code
       
    94  * Override of base class pure virtual
       
    95  * Our implementation only gets called if the base class doTestStepPreambleL() did
       
    96  * not leave. That being the case, the current test result value will be EPass.
       
    97  */
       
    98 TVerdict CT_LbsClientStep_CellBasedNotifyPosUpdate::doTestStepL()
       
    99 	{
       
   100 	// Generic test step used to test the LBS Client Notify position update API.
       
   101 	INFO_PRINTF1(_L("&gt;&gt;CT_LbsClientStep_CellBasedNotifyPosUpdate::doTestStepL()"));
       
   102 
       
   103 	if (TestStepResult()==EPass) // TODO still don't see why we need this...
       
   104 		{
       
   105 		iNetworkUnavailable = FALSE;
       
   106 		iIsCancelTest = FALSE;
       
   107    		iCancel = FALSE;
       
   108 		iCancelOnPosUpdate = FALSE;
       
   109 		iCancelBeforePosUpdate = FALSE;
       
   110 		iMultiReq = EFalse;
       
   111 		iNumNPUDs = iParent.iSharedData->iVerifyPosInfoArr.Count(); // how many NPUDs to do
       
   112 		
       
   113 		// Expected callbacks flags
       
   114 		iFlagsToHaltOn =	KLbsCallback_NetSim_Got_Connect | 	
       
   115 							KLbsCallback_NetworkBasedLocation |
       
   116 							KLbsCallback_Got_NotifyPositionUpdate;	// notifypositionupdate completed.
       
   117 	
       
   118 		
       
   119 		TTimeIntervalMicroSeconds32 abortInterval;
       
   120 		if(iParent.iSharedData->iTestModuleInUse)
       
   121 			{
       
   122 			abortInterval = KDefaultAbortTimerPeriod;
       
   123 			}
       
   124 		else
       
   125 			{	
       
   126 			abortInterval = KDefaultAbortTimerPeriod_real;
       
   127 			}
       
   128 		
       
   129 		// Carryout unique test actions.
       
   130 		TInt testCaseId;
       
   131 		if (GetIntFromConfig(ConfigSection(), KTestCaseId, testCaseId))
       
   132 			{
       
   133 				switch (testCaseId)
       
   134 				{												
       
   135 				case 1:	// LBS-NotifyPosUpdateCellBased-0001 Request a cell-based location
       
   136 					{
       
   137 					// nothing to do 
       
   138 					}
       
   139 					break;
       
   140 				
       
   141 				case 2:	// LBS-NotifyPosUpdateCellBased-0002	Request a cell-based location and cancel before it completes
       
   142 					{
       
   143 					iCancel = ETrue;
       
   144 					iFlagsToHaltOn =	KLbsCallback_NetSim_Got_Connect |
       
   145 										KLbsCallback_Got_NotifyPositionUpdate;
       
   146 					}
       
   147 					break;
       
   148 				
       
   149 				case 3:	// LBS-NotifyPosUpdateCellBased-0003	Request a cell-based location, when network unavailable
       
   150 					{
       
   151 					iNetworkUnavailable = ETrue;
       
   152 					// TO DO - are these the right flags (get NO NetSIm callbacks while network unavailable)?
       
   153 					iFlagsToHaltOn &= ~KLbsCallback_NetworkBasedLocation;
       
   154 					}
       
   155 					break;
       
   156 					
       
   157 				case 4:	// LBS-NotifyPosUpdateCellBased-0004 multiple sequential npuds
       
   158 					{
       
   159 					iMultiReq = ETrue;
       
   160 					}
       
   161 					break;
       
   162 					
       
   163 				case 5:	// LBS-NotifyPosUpdateCellBased-0005	Request a cell-based location and attempt to cancel when the update is received
       
   164 					{
       
   165 					iCancelOnPosUpdate = ETrue;
       
   166 					iFlagsToHaltOn =	KLbsCallback_NetSim_Got_Connect |
       
   167 										KLbsCallback_Got_NotifyPositionUpdate;
       
   168 					}
       
   169 					break;
       
   170 					
       
   171 				case 6:	// LBS-NotifyPosUpdateCellBased-0006	Request a cell-based location and cancel before a position update is generated
       
   172 					{
       
   173 					iCancelBeforePosUpdate = ETrue;
       
   174 					iFlagsToHaltOn =	KLbsCallback_NetSim_Got_Connect |
       
   175 										KLbsCallback_Got_NotifyPositionUpdate;
       
   176 					}
       
   177 					
       
   178 					break;			
       
   179 	
       
   180 				default:
       
   181 					User::Panic(KLbsClientStepCellBasedNotifyPosUpdate, KErrUnknown);			
       
   182 				}
       
   183 			}
       
   184 		else
       
   185 			{
       
   186 			User::Panic(KLbsClientStepCellBasedNotifyPosUpdate, KErrUnknown);
       
   187 			}	
       
   188 			
       
   189 		iIsCancelTest = (iCancel || iCancelBeforePosUpdate || iCancelOnPosUpdate);	
       
   190 		
       
   191 		// Steps common to all tests:
       
   192 		
       
   193 		// Connect to net sim
       
   194 		iNetSim.ConnectL(this);
       
   195 
       
   196 	// Configure NetSim:	
       
   197 		// Set reference location:
       
   198 		RPointerArray<TAny>& srcPosInfoArr = iParent.iSharedData->iVerifyPosInfoArr;
       
   199 		TPositionInfo* srcPosInfo = reinterpret_cast<TPositionInfo*>(srcPosInfoArr[0]);
       
   200 		TPosition srcPos;
       
   201 		srcPosInfo->GetPosition(srcPos);
       
   202 		if (!iNetSim.SetReferenceLocation(srcPos))
       
   203 			{
       
   204 			INFO_PRINTF1(_L("CT_LbsClientStep_CellBasedNotifyPosUpdate::doTestStepL() Failed: Can't set NetSim's reference location."));
       
   205 			SetTestStepResult(EFail);
       
   206 			}	
       
   207 		
       
   208 		// Set plugin to use for getting assistance data:
       
   209 		TUid pluginUid;
       
   210 		if(iParent.iSharedData->iTestModuleInUse)
       
   211 			{
       
   212 			pluginUid = TUid::Uid(KSimpleAssistanceDataProviderPluginUidValue);
       
   213 			}
       
   214 		else
       
   215 			{
       
   216 			pluginUid = TUid::Uid(KSuplAssistanceDataProviderPluginUidValue);
       
   217 			}
       
   218 		if (!iNetSim.SetAssistanceDataProvider(pluginUid))
       
   219 			{
       
   220 			INFO_PRINTF1(_L("Can't set NetSim's assistance data plugin uid."));
       
   221 			SetTestStepResult(EFail);
       
   222 			}
       
   223 			
       
   224 		// make network unavailable if appropriate:
       
   225 		if(iNetworkUnavailable)
       
   226 			{
       
   227 			// Tell netsim to make network unavailable until further notice:
       
   228 			if(!iNetSim.SetResponseError(RLbsNetSimTest::KNetSimNetworkNotAvailable, ETrue))	//sticky
       
   229 				{
       
   230 				INFO_PRINTF1(_L("CT_LbsClientStep_CellBasedNotifyPosUpdate::doTestStepL() Failed: Can't set NetSim's response error."));
       
   231 				SetTestStepResult(EFail);
       
   232 				}
       
   233 			}			
       
   234 			
       
   235 		// Kick off the keep alive timer - do last to ensure NetSim is ready otherwise the
       
   236 		// timer callback may start a MO-LR if the NetSim connected too early.
       
   237 		TTimeIntervalMicroSeconds32 interval(KLbsKeepAlivePeriod);
       
   238 
       
   239 		iKeepAliveTimer->SetTimer(interval);
       
   240 
       
   241 		// don't wait for TEF to timeout and abort
       
   242 		iAbortTimer->SetTimer(abortInterval);
       
   243 
       
   244 		// Kick off test.
       
   245 		CActiveScheduler::Start();
       
   246 			
       
   247 		if(EDone != iState)
       
   248 			{
       
   249 			INFO_PRINTF2(_L("Failed test, finished in state %d"), iState);
       
   250 			INFO_PRINTF3(_L("Callback flags currently set = 0x%x. Expecting 0x%x"), iCallbackFlags, iFlagsToHaltOn);
       
   251 			SetTestStepResult(EFail);
       
   252 			}
       
   253 		else
       
   254 			{
       
   255 			INFO_PRINTF2(_L("Got all expected callbacks (0x%x)"), iCallbackFlags);			
       
   256 			}
       
   257 						
       
   258 		iNetSim.Close();
       
   259 			
       
   260 		}
       
   261 		
       
   262 	INFO_PRINTF1(_L("&lt;&lt;CT_LbsClientStep_CellBasedNotifyPosUpdate::doTestStepL()"));
       
   263 
       
   264 	return TestStepResult();
       
   265 	}
       
   266 
       
   267 
       
   268 void CT_LbsClientStep_CellBasedNotifyPosUpdate::Connected()
       
   269 	{
       
   270 	// Call base implementation.
       
   271 	CT_LbsNetSimStep::Connected();
       
   272 			
       
   273 	if(iCancelBeforePosUpdate)
       
   274 		{
       
   275 		TPositionInfo* posInfo = new(ELeave) TPositionInfo();
       
   276 		iDoPosUpdate->StartL(*posInfo);
       
   277 	
       
   278 		iNumNPUDs--;
       
   279 	
       
   280 		// Wait for all expected callback flags to be set:
       
   281 		iState = CT_LbsNetSimStep::EWaiting;	
       
   282 		
       
   283 		// Cancel the request for the cancel test.
       
   284 		iDoPosUpdate->CancelRequest();
       
   285 		delete posInfo;
       
   286 		}
       
   287 	else
       
   288 		{
       
   289 		T_LbsUtils utils;
       
   290 		// Create a posinfo and store in our shared array for later verification.
       
   291 		RPointerArray<TAny>& posInfoArr = iParent.iSharedData->iCurrentPosInfoArr;
       
   292 		TPositionInfo* posInfo = new(ELeave) TPositionInfo();
       
   293 		utils.ResetAndDestroy_PosInfoArr(posInfoArr);	// Clear previous entries before new entry is appended.
       
   294 		posInfoArr.Append(posInfo);
       
   295 		
       
   296 		iDoPosUpdate->StartL(*posInfo);
       
   297 	
       
   298 		iNumNPUDs--;
       
   299 	
       
   300 		// Wait for all expected callback flags to be set:
       
   301 		iState = CT_LbsNetSimStep::EWaiting;	
       
   302 		
       
   303 		// Cancel the request for the cancel test.
       
   304 		if(iCancel)				
       
   305 			{
       
   306 			User::After((TTimeIntervalMicroSeconds32)100000);   // arbitrary delay as workaround for DEF107349
       
   307 			iDoPosUpdate->CancelRequest();
       
   308 			}			
       
   309 		}
       
   310 	}
       
   311 	
       
   312 void CT_LbsClientStep_CellBasedNotifyPosUpdate::Disconnected()
       
   313 	{
       
   314 	// Call base implementation.
       
   315 	CT_LbsNetSimStep::Disconnected();
       
   316 	}
       
   317 
       
   318 void CT_LbsClientStep_CellBasedNotifyPosUpdate::NotifyRegisterLcsMoLr(const TDesC& aData)
       
   319 	{
       
   320     if (!iIsCancelTest)
       
   321     	{
       
   322     	// Call base implementation.
       
   323 		CT_LbsNetSimStep::NotifyRegisterLcsMoLr(aData);
       
   324     	}
       
   325 	}
       
   326 
       
   327 void CT_LbsClientStep_CellBasedNotifyPosUpdate::NotifyReleaseLcsMoLr(TInt aReason)
       
   328 	{
       
   329 	if (!iIsCancelTest)
       
   330     	{
       
   331 		// Call base implementation.
       
   332 		CT_LbsNetSimStep::NotifyReleaseLcsMoLr(aReason);	
       
   333     	}	
       
   334 	}
       
   335 
       
   336 // Measurement Control has been received from Network:
       
   337 void CT_LbsClientStep_CellBasedNotifyPosUpdate::NotifyMeasurementControlLocation(const TPositionInfo& aPosition, const RLbsAssistanceDataBuilderSet& aData, const TLbsNetPosRequestQuality& aQuality)
       
   338 	{
       
   339 	if (!iIsCancelTest)
       
   340     	{
       
   341 		// Call base implementation.
       
   342 		CT_LbsNetSimStep::NotifyMeasurementControlLocation(aPosition, aData, aQuality);
       
   343     	}
       
   344 	}
       
   345 
       
   346 void CT_LbsClientStep_CellBasedNotifyPosUpdate::NotifyReleaseLcsLocationNotification(const CLbsNetworkProtocolBase::TLbsPrivacyResponse& aResult)
       
   347 	{
       
   348 	if (!iIsCancelTest)
       
   349     	{
       
   350 		// Call base implementation.
       
   351 		CT_LbsNetSimStep::NotifyReleaseLcsLocationNotification(aResult);
       
   352     	}	
       
   353 	}
       
   354 
       
   355 void CT_LbsClientStep_CellBasedNotifyPosUpdate::NotifyFacilityLcsMoLrResult(TInt aReason, const TPositionInfo& aPosition)
       
   356 	{
       
   357 	if (!iIsCancelTest)
       
   358     	{
       
   359 		// Call base implementation.
       
   360 		CT_LbsNetSimStep::NotifyFacilityLcsMoLrResult(aReason, aPosition);
       
   361     	}
       
   362 	}
       
   363 
       
   364 // Our position has been reported to network
       
   365 void CT_LbsClientStep_CellBasedNotifyPosUpdate::NotifyMeasurementReportLocation(const TPositionInfo& aPosition)
       
   366 	{
       
   367 	if(iCancelOnPosUpdate)
       
   368 		{
       
   369 		iDoPosUpdate->CancelRequest();
       
   370 		}
       
   371 	if (!iIsCancelTest)
       
   372     	{
       
   373 		// Call base implementation.
       
   374 		CT_LbsNetSimStep::NotifyMeasurementReportLocation(aPosition);
       
   375     	}
       
   376 	}
       
   377 
       
   378 void CT_LbsClientStep_CellBasedNotifyPosUpdate::NotifyMeasurementReportRequestMoreAssistanceData(const TLbsAssistanceDataGroup& aFilter)
       
   379 	{
       
   380 	if (!iIsCancelTest)
       
   381     	{
       
   382 		// Call base implementation.
       
   383 		CT_LbsNetSimStep::NotifyMeasurementReportRequestMoreAssistanceData(aFilter);
       
   384     	}
       
   385 	}
       
   386 
       
   387 void CT_LbsClientStep_CellBasedNotifyPosUpdate::NotifyMeasurementReportControlFailure(TInt aReason)
       
   388 	{
       
   389 	if (!iIsCancelTest && !iMultiReq)
       
   390     	{
       
   391 		// Call base implementation.
       
   392 		CT_LbsNetSimStep::NotifyMeasurementReportControlFailure(aReason);
       
   393 		}
       
   394 	else if (iMultiReq && ! ((aReason == KErrPositionHighPriorityReceive) || (aReason == KErrServerBusy)))
       
   395 		{
       
   396 		INFO_PRINTF2(_L("FAILED: NotifyMeasurementReportControlFailure with reason = %d"), aReason);
       
   397 		SetTestStepResult(EFail);
       
   398 		}
       
   399 	}
       
   400 
       
   401 void CT_LbsClientStep_CellBasedNotifyPosUpdate::NotifyError(MLbsNetSimTestObserver::EFunction aFunction, int aError)
       
   402 	{
       
   403 	// Call base implementation.
       
   404 	CT_LbsNetSimStep::NotifyError(aFunction, aError);
       
   405 	}
       
   406 
       
   407 void CT_LbsClientStep_CellBasedNotifyPosUpdate::ProcessMeasurementControlLocationError(TInt aError)
       
   408 	{
       
   409 	// Call base implementation.
       
   410 	CT_LbsNetSimStep::ProcessMeasurementControlLocationError(aError);
       
   411 	}
       
   412 
       
   413 /**	Notify position update callback.
       
   414 */
       
   415 void CT_LbsClientStep_CellBasedNotifyPosUpdate::MT_LbsDoPosUpdateCallback(TRequestStatus& aStatus)
       
   416 	{
       
   417 	TInt err = aStatus.Int();
       
   418 	
       
   419 	INFO_PRINTF2(_L("CT_LbsClientStep_CellBasedNotifyPosUpdate::MT_LbsDoPosUpdateCallback: Got - Notify Update - Callback Event. Error = %d"), err);
       
   420 	
       
   421 	if(!iNumNPUDs)	// only set the flag when we've got them all
       
   422 		{
       
   423 		SetCallbackFlag(KLbsCallback_Got_NotifyPositionUpdate);
       
   424 		}
       
   425 		
       
   426 	if(iNetworkUnavailable)
       
   427 		{
       
   428 		if(KErrTimedOut != err && KErrDisconnected != err)
       
   429 			{
       
   430 			INFO_PRINTF2(_L("FAILED: MT_LbsDoPosUpdateCallback with error %d, expecting KErrTimedOut"), err);
       
   431 			SetTestStepResult(EFail);
       
   432 			}
       
   433 		}
       
   434 	else
       
   435 		{
       
   436 		if(iCancel)
       
   437 			{
       
   438 			if(KErrCancel != err && KErrNone != err)
       
   439 				{
       
   440 				INFO_PRINTF2(_L("FAILED: MT_LbsDoPosUpdateCallback with error = %d"), err);
       
   441 				SetTestStepResult(EFail);
       
   442 				}
       
   443 			}
       
   444 		else 
       
   445 			{
       
   446 			if(iCancelBeforePosUpdate)
       
   447 				{
       
   448 				if(KErrCancel != err)
       
   449 					{
       
   450 					INFO_PRINTF2(_L("FAILED: MT_LbsDoPosUpdateCallback with error = %d"), err);
       
   451 					SetTestStepResult(EFail);
       
   452 					}
       
   453 				}
       
   454 			else 
       
   455 				{
       
   456 				if(KErrNone != err)
       
   457 					{
       
   458 					INFO_PRINTF2(_L("FAILED: MT_LbsDoPosUpdateCallback with error = %d"), err);
       
   459 					SetTestStepResult(EFail);
       
   460 					}
       
   461 				}
       
   462 			}		
       
   463 		}
       
   464 	
       
   465 	if(iNumNPUDs--)
       
   466 		{	
       
   467 		// Create another posinfo and store in our shared array for later verification.
       
   468 		RPointerArray<TAny>& posInfoArr = iParent.iSharedData->iCurrentPosInfoArr;
       
   469 		TPositionInfo* posInfo = new(ELeave) TPositionInfo();
       
   470 		posInfoArr.Append(posInfo);
       
   471 			
       
   472 		iDoPosUpdate->StartL(*posInfo);
       
   473 		}	
       
   474 	}