lbstest/lbstestproduct/lbsclient/src/ctlbsclientsteplastknownpos.cpp
changeset 0 9cfd9a3ee49c
child 52 29dbbeac905d
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     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 "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 // @file ctlbsclientstep_lastknownpos.cpp
       
    15 // This is the class implementation for the Last Known Position Tests
       
    16 // 
       
    17 //
       
    18  
       
    19 #include "ctlbsclientsteplastknownpos.h"
       
    20 
       
    21 #include <lbs.h>
       
    22 #include <lbs/lbsadmin.h>
       
    23 #include "lbssatellite.h"
       
    24 #include <lbs/EPos_CPosModules.h>
       
    25 #include <lbs/EPos_CPosModuleUpdate.h>
       
    26 #include <lbs/test/tlbsutils.h>
       
    27 #include <lbs/test/ctlbsasyncwaiter.h>
       
    28 #include "netpsy.hrh"
       
    29 
       
    30 /**
       
    31  * Destructor
       
    32  */
       
    33 CT_LbsClientStep_LastKnownPos::~CT_LbsClientStep_LastKnownPos()
       
    34 	{
       
    35 	}
       
    36 
       
    37 
       
    38 /**
       
    39  * Constructor
       
    40  */
       
    41 CT_LbsClientStep_LastKnownPos::CT_LbsClientStep_LastKnownPos(CT_LbsClientServer& aParent) : CT_LbsClientStep(aParent)
       
    42 	{
       
    43 	SetTestStepName(KLbsClientStep_LastKnownPos);
       
    44 	}
       
    45 
       
    46 
       
    47 /**
       
    48 Static Constructor
       
    49 */
       
    50 CT_LbsClientStep_LastKnownPos* CT_LbsClientStep_LastKnownPos::New(CT_LbsClientServer& aParent)
       
    51 	{
       
    52     // Note the lack of ELeave.
       
    53     // This means that having insufficient memory will return NULL;
       
    54 	CT_LbsClientStep_LastKnownPos* testStep =  new CT_LbsClientStep_LastKnownPos(aParent);
       
    55 
       
    56     if (testStep)
       
    57         {
       
    58         TInt err = KErrNone;
       
    59 
       
    60         TRAP(err, testStep->ConstructL());
       
    61         if (err)
       
    62             {
       
    63             delete testStep;
       
    64             testStep = NULL;
       
    65             }
       
    66         }
       
    67     return testStep;
       
    68 	}
       
    69 
       
    70 void CT_LbsClientStep_LastKnownPos::ConstructL()
       
    71     {
       
    72     // Re-enable the network PSY
       
    73     CPosModules* db = CPosModules::OpenL();
       
    74     CleanupStack::PushL(db);
       
    75 
       
    76     CPosModuleUpdate* moduleUpdate = CPosModuleUpdate::NewLC();
       
    77     
       
    78     moduleUpdate->SetUpdateAvailability(ETrue);
       
    79     moduleUpdate->SetUpdateVisibility(ETrue);
       
    80     TUid uid = TUid::Uid(KPosNETPSYImplUid);
       
    81     db->UpdateModuleL(uid, *moduleUpdate);
       
    82     
       
    83     CleanupStack::PopAndDestroy(moduleUpdate);
       
    84     CleanupStack::PopAndDestroy(db);
       
    85     }
       
    86 
       
    87 void CT_LbsClientStep_LastKnownPos::SwitchOnselfLocateAPIL()
       
    88 	{
       
    89 	CLbsAdmin* adminApi = CLbsAdmin::NewL();
       
    90 	CleanupStack::PushL(adminApi);
       
    91 	adminApi->Set(KLbsSettingHomeSelfLocate, CLbsAdmin::ESelfLocateOn);	
       
    92 	CleanupStack::PopAndDestroy(adminApi);
       
    93 	}
       
    94 
       
    95 
       
    96 /**
       
    97  * @return - TVerdict code
       
    98  * Override of base class pure virtual
       
    99  * Our implementation only gets called if the base class doTestStepPreambleL() did
       
   100  * not leave. That being the case, the current test result value will be EPass.
       
   101  */
       
   102 TVerdict CT_LbsClientStep_LastKnownPos::doTestStepL()
       
   103 	{
       
   104 	// Generic test step used to test the LBS Client Notify position update API.
       
   105 	INFO_PRINTF1(_L("&gt;&gt;CT_LbsClientStep_LastKnownPos::doTestStepL()"));
       
   106 
       
   107     if (TestStepResult() == EPass)
       
   108 		{
       
   109 		TInt err = KErrNone;
       
   110 		
       
   111 		// Wait for server to cease to be - thus ensuring cache is empty
       
   112 		//User::After(10000000);   //Not needed
       
   113 		
       
   114 		// Carryout unique test actions.
       
   115 		TInt testCaseId;
       
   116 		if (GetIntFromConfig(ConfigSection(), KTestCaseId, testCaseId))
       
   117 			{
       
   118 			if(testCaseId == 2)
       
   119 				{
       
   120 				//The delay below is to make sure that there is no request to server for at least 200 seconds
       
   121 				//so that it will shutdown and clear cache.
       
   122 
       
   123 				User::After(3*1000*1000);
       
   124 				}
       
   125 
       
   126 			// Connect to self locate server.
       
   127 			User::LeaveIfError(iServer.Connect());
       
   128 			CleanupClosePushL(iServer);
       
   129 				
       
   130 			switch (testCaseId)
       
   131 				{
       
   132 				// Test case LBS-LastKnownPos-0001
       
   133 				case 1:
       
   134 				// Test case LBS-LastKnownPos-0101
       
   135 				case 101:
       
   136 				    {
       
   137 					T_LbsUtils utils;
       
   138 					// Open positioner.
       
   139 					User::LeaveIfError(iPositioner.Open(iServer));
       
   140 					CleanupClosePushL(iPositioner);
       
   141                     if(testCaseId==101)
       
   142 	                    {
       
   143 	                    // For this test an additional reference position will be returned.
       
   144 					
       
   145 						// Setup netsim.
       
   146 						User::LeaveIfError(OpenNetSim());
       
   147 							
       
   148 						// Request notify for the expected reference position.
       
   149 						TPositionInfo actualRefPosInfo;
       
   150 							
       
   151 						err = DoNotifyUpdateL(actualRefPosInfo);
       
   152 						if (err)
       
   153 							{
       
   154 							INFO_PRINTF2(_L("Failed test, reference position request returned err %d."), err);
       
   155 							SetTestStepResult(EFail);							
       
   156 							}
       
   157 								
       
   158 						// Verify reference position.
       
   159 						TPositionInfo verifyRefPosInfo;
       
   160 							
       
   161 						verifyRefPosInfo.SetPosition(iRefPos);
       
   162 						if (!utils.Compare_PosInfo(verifyRefPosInfo, actualRefPosInfo))
       
   163 							{
       
   164 							INFO_PRINTF1(_L("Failed test, reference position incorrect."));
       
   165 							SetTestStepResult(EFail);
       
   166 							}	
       
   167 	                    }
       
   168 					
       
   169 					
       
   170 				    TPosition pos;		// original position
       
   171 					TTime timeStamp;	// timestamp inside original received position
       
   172 					
       
   173 				    // Carry out a notify update to ensure last known cache is filled.
       
   174 					TPositionInfo notifyPosInfo;
       
   175 					User::LeaveIfError(DoNotifyUpdateL(notifyPosInfo));
       
   176 
       
   177 					// get the position data:
       
   178 					notifyPosInfo.GetPosition(pos);
       
   179 					
       
   180 					timeStamp = pos.Time();
       
   181 					INFO_PRINTF1(_L("Original position timeStamp: "));
       
   182 					INFO_PRINTF4(_L("%d/%d/%d"), timeStamp.DateTime().Day() + 1, timeStamp.DateTime().Month() + 1, timeStamp.DateTime().Year());
       
   183 					INFO_PRINTF5(_L("at %d :%d :%d :%d"), timeStamp.DateTime().Hour(), timeStamp.DateTime().Minute(), timeStamp.DateTime().Second(), timeStamp.DateTime().Second());
       
   184 						
       
   185 					// Create a posinfo and store in our shared array for later verification.
       
   186 					RPointerArray<TAny>& posInfoArr = iParent.iSharedData->iCurrentPosInfoArr;
       
   187 					TPositionInfo* posInfo = new(ELeave) TPositionInfo();
       
   188 	
       
   189 					utils.ResetAndDestroy_PosInfoArr(posInfoArr);	// Clear previous entries before new entry is appended.
       
   190 
       
   191 					posInfoArr.Append(posInfo);
       
   192 
       
   193 					// Get the last known position
       
   194 					err = DoLastKnownPosL(*posInfo);
       
   195 					if (KErrNone != err)
       
   196 						{
       
   197 						SetTestStepResult(EFail);
       
   198 						}
       
   199 					else
       
   200 						{								
       
   201 						TTime timeStamp_cached;		
       
   202 						posInfo->GetPosition(pos);	
       
   203 						timeStamp_cached = pos.Time();
       
   204 						
       
   205 						timeStamp = pos.Time();
       
   206 						INFO_PRINTF1(_L("Cached position timeStamp: "));
       
   207 						INFO_PRINTF4(_L("%d/%d/%d"), timeStamp_cached.DateTime().Day() + 1, timeStamp_cached.DateTime().Month() + 1, timeStamp_cached.DateTime().Year());
       
   208 						INFO_PRINTF5(_L("at %d :%d :%d :%d"), timeStamp_cached.DateTime().Hour(), timeStamp_cached.DateTime().Minute(), timeStamp_cached.DateTime().Second(), timeStamp_cached.DateTime().Second());
       
   209 													
       
   210 						// verify that the timestamp matches the original one:
       
   211 						if(timeStamp_cached != timeStamp)
       
   212 							{
       
   213 							SetTestStepResult(EFail);
       
   214 							}
       
   215 						
       
   216 						}
       
   217 					CleanupStack::PopAndDestroy(&iPositioner);
       
   218 					if (testCaseId == 101)
       
   219 						{
       
   220 						CloseNetSim();
       
   221 						}
       
   222 					break;
       
   223 					}
       
   224 				
       
   225 				// NEGATIVE TEST
       
   226 				// Test case LBS-LastKnownPos-0002
       
   227 				case 2:
       
   228 					{
       
   229 					// Open positioner.
       
   230 					User::LeaveIfError(iPositioner.Open(iServer));
       
   231 					CleanupClosePushL(iPositioner);
       
   232 
       
   233 					// DONT carry out a notify update to ensure last known cache is filled.
       
   234 
       
   235 					// Create a posinfo to store position info from LastKnownPosition method.
       
   236 					TPositionInfo posInfo;
       
   237 
       
   238 					// Get the last known position
       
   239 					err = DoLastKnownPosL(posInfo);
       
   240 					if (KErrUnknown != err)
       
   241 						{
       
   242 						INFO_PRINTF2(_L("Failed with error %d when expecting error KErrUnknown, indicating no position in cache"), err);
       
   243 						SetTestStepResult(EFail);
       
   244 						}
       
   245 						
       
   246 					// Wait for a time period and verify that location info is not published.
       
   247 					// 10seconds
       
   248 					User::After(10000000);
       
   249 					
       
   250 					// Get the last known position
       
   251 					err = DoLastKnownPosL(posInfo);
       
   252 					if (KErrUnknown != err)
       
   253 						{
       
   254 						INFO_PRINTF2(_L("Failed with error %d when expecting error KErrUnknown, indicating no position in cache"), err);
       
   255 						SetTestStepResult(EFail);
       
   256 						}
       
   257 						
       
   258 					CleanupStack::PopAndDestroy(&iPositioner);
       
   259 					break;
       
   260 					}
       
   261 					
       
   262 
       
   263 				// NEGATIVE TEST	
       
   264 				// Test case LBS-LastKnownPos-0004
       
   265 				case 4:
       
   266 					{
       
   267 					T_LbsUtils utils;
       
   268 					TPositionModuleId networkModuleId = utils.GetNetworkModuleIdL(iServer);
       
   269 					// Open positioner.
       
   270 					User::LeaveIfError(iPositioner.Open(iServer, networkModuleId));
       
   271 					CleanupClosePushL(iPositioner);
       
   272 
       
   273 					// Setup netsim.
       
   274 					User::LeaveIfError(OpenNetSim());
       
   275 						
       
   276 					// Carry out a notify update to ensure last known cache is filled.
       
   277 					TPositionInfo actualRefPosInfo;
       
   278 						
       
   279 					err = DoNotifyUpdateL(actualRefPosInfo);
       
   280 										
       
   281 					if (err)
       
   282 						{
       
   283 						INFO_PRINTF2(_L("Failed test, reference position request returned err %d."), err);
       
   284 						SetTestStepResult(EFail);							
       
   285 						}
       
   286 							
       
   287 					// Verify reference position.
       
   288 					TPositionInfo verifyRefPosInfo;
       
   289 					verifyRefPosInfo.SetPosition(iRefPos);
       
   290 					if (!utils.Compare_PosInfo(verifyRefPosInfo, actualRefPosInfo))
       
   291 						{
       
   292 						INFO_PRINTF1(_L("Failed test, reference position incorrect."));
       
   293 						SetTestStepResult(EFail);
       
   294 						}
       
   295 				    
       
   296 				    // ** Create a position info which is not supported by the network module **
       
   297 					TPositionSatelliteInfo positionSatelliteInfo;
       
   298 
       
   299 					// Get the last known position
       
   300 					err = DoLastKnownPosL(positionSatelliteInfo);
       
   301 					if (KErrArgument != err)
       
   302 						{
       
   303 						SetTestStepResult(EFail);
       
   304 						}
       
   305 												
       
   306 					CleanupStack::PopAndDestroy(&iPositioner);
       
   307 					// Close netsim.
       
   308 					CloseNetSim();
       
   309 					break;
       
   310 					}
       
   311 									
       
   312 				// Test case LBS-LastKnownPos-0006
       
   313 				case 6:
       
   314 					{
       
   315 					// Open positioner.
       
   316 					User::LeaveIfError(iPositioner.Open(iServer));
       
   317 					CleanupClosePushL(iPositioner);
       
   318 											
       
   319 					CLbsAdmin* adminApi = CLbsAdmin::NewL();
       
   320 					CleanupStack::PushL(adminApi);
       
   321 					
       
   322 					adminApi->Set(KLbsSettingHomeSelfLocate, CLbsAdmin::ESelfLocateOff);
       
   323 					
       
   324 					TPositionInfo posInfo;
       
   325 
       
   326 					// Get the last known position
       
   327 					err = DoLastKnownPosL(posInfo);
       
   328 					if (KErrAccessDenied != err)
       
   329 						{
       
   330 						SetTestStepResult(EFail);
       
   331 						}
       
   332 
       
   333 					CleanupStack::PopAndDestroy(adminApi);
       
   334 					CleanupStack::PopAndDestroy(&iPositioner);
       
   335 
       
   336 					SwitchOnselfLocateAPIL();
       
   337 
       
   338 					break;		
       
   339 					}
       
   340 
       
   341 				// Test case LBS-LastKnownPos-0007
       
   342 				case 7:
       
   343 				// Test case LBS-LastKnownPos-0102
       
   344 				case 102:
       
   345 					{
       
   346 					T_LbsUtils utils;
       
   347 					// Open positioner.
       
   348 					User::LeaveIfError(iPositioner.Open(iServer));
       
   349 					CleanupClosePushL(iPositioner);
       
   350                     if(testCaseId==102)
       
   351 	                    {
       
   352 	                    // For this test an additional reference position will be returned.
       
   353 					
       
   354 						// Setup netsim.
       
   355 						User::LeaveIfError(OpenNetSim());
       
   356 							
       
   357 						// Request notify for the expected reference position.
       
   358 						TPositionInfo actualRefPosInfo;
       
   359 							
       
   360 						err = DoNotifyUpdateL(actualRefPosInfo);
       
   361 						if (err)
       
   362 							{
       
   363 							INFO_PRINTF2(_L("Failed test, reference position request returned err %d."), err);
       
   364 							SetTestStepResult(EFail);							
       
   365 							}
       
   366 								
       
   367 						// Verify reference position.
       
   368 						TPositionInfo verifyRefPosInfo;
       
   369 							
       
   370 						verifyRefPosInfo.SetPosition(iRefPos);
       
   371 						if (!utils.Compare_PosInfo(verifyRefPosInfo, actualRefPosInfo))
       
   372 							{
       
   373 							INFO_PRINTF1(_L("Failed test, reference position incorrect."));
       
   374 							SetTestStepResult(EFail);
       
   375 							}	
       
   376 	                    }
       
   377 														
       
   378 					// Carry out a notify update to ensure last known cache is filled.
       
   379 					TPositionInfo notifyPosInfo;
       
   380 					TInt err = DoNotifyUpdateL(notifyPosInfo);
       
   381 					User::LeaveIfError(err);
       
   382 
       
   383 					// Create a posinfo and store in our shared array for later verification.
       
   384 					RPointerArray<TAny>& posInfoArr = iParent.iSharedData->iCurrentPosInfoArr;
       
   385 					TPositionInfo* posInfo = new(ELeave) TPositionInfo();
       
   386 
       
   387 				
       
   388 					utils.ResetAndDestroy_PosInfoArr(posInfoArr);	// Clear previous entries before new entry is appended.
       
   389 
       
   390 					posInfoArr.Append(posInfo);
       
   391 
       
   392 					// Get the last known position
       
   393 					CT_LbsAsyncWaiter*	waiter = CT_LbsAsyncWaiter::NewL();
       
   394 					CleanupStack::PushL(waiter);
       
   395 
       
   396 					User::LeaveIfError(iPositioner.SetRequestor(	CRequestor::ERequestorService,
       
   397 																	CRequestor::EFormatApplication,
       
   398 																	_L("Tom Tom")));
       
   399 																	
       
   400 					iPositioner.GetLastKnownPosition(*posInfo, waiter->iStatus);
       
   401 									
       
   402 					TInt errCancel = iPositioner.CancelRequest(EPositionerGetLastKnownPosition);
       
   403 						
       
   404 					waiter->StartAndWait();
       
   405 
       
   406 					TInt errLkp = waiter->Result();
       
   407 
       
   408 					CleanupStack::PopAndDestroy(waiter);
       
   409 					
       
   410 					// Sync Cancel() call returns either KErrNone or KErrNotFound. 
       
   411 					if ( errCancel != KErrNone && errCancel != KErrNotFound )
       
   412 						{
       
   413 						INFO_PRINTF1(_L("<FONT><B>Cancel must return KErrNone or KErrNotFound</B></FONT>"));
       
   414 						SetTestStepResult(EFail);									
       
   415 						}
       
   416 					// If Cancel() returns KErrNone, then the original request may complete with KErrCancel.
       
   417 					if (errCancel != KErrNone &&  (errLkp != KErrCancel && errLkp != KErrNone )  )
       
   418 						{
       
   419 						INFO_PRINTF1(_L("<FONT><B>Cancel must return KErrCancel or KErrNone</B></FONT>"));
       
   420 						SetTestStepResult(EFail);									
       
   421 						}
       
   422 						
       
   423 						
       
   424 					CleanupStack::PopAndDestroy(&iPositioner);
       
   425 					if (testCaseId == 102)
       
   426 						{
       
   427 						CloseNetSim();
       
   428 						}			
       
   429 					break;		
       
   430 					}		
       
   431 					
       
   432 				// Test case LBS-LastKnownPos-0008
       
   433 				case 8:
       
   434 					{
       
   435 					// Open positioner.
       
   436 					User::LeaveIfError(iPositioner.Open(iServer));
       
   437 					CleanupClosePushL(iPositioner);
       
   438 
       
   439 					// DONT get the last known position, but DO cancel
       
   440 					err = iPositioner.CancelRequest(EPositionerNotifyPositionUpdate);
       
   441 					
       
   442 					if (KErrNotFound != err)
       
   443 						{
       
   444 						//Didnt cancel or complete successfully.
       
   445 						SetTestStepResult(EFail);
       
   446 						}
       
   447 
       
   448 					CleanupStack::PopAndDestroy(&iPositioner);
       
   449 									
       
   450 					break;		
       
   451 					}	
       
   452 					
       
   453 
       
   454 				// Test case LBS-LastKnownPos-0009
       
   455 				case 9:
       
   456 					{
       
   457 					//DONT open connection to Position Server
       
   458 
       
   459 					TPositionInfo posInfo;
       
   460 
       
   461 					// Get the last known position, THIS SHOULD PANIC WITH EPositionServerBadHandle
       
   462 					TRequestStatus status;
       
   463 					iPositioner.GetLastKnownPosition(posInfo, status);
       
   464 					err = iPositioner.CancelRequest(EPositionerNotifyPositionUpdate);
       
   465 
       
   466 					if (KErrNone == err)
       
   467 						{
       
   468 						//Completed Successfully.
       
   469 						SetTestStepResult(EFail);
       
   470 						}
       
   471 
       
   472 					CleanupStack::PopAndDestroy(&iPositioner);
       
   473 					
       
   474 					SwitchOnselfLocateAPIL();
       
   475 					
       
   476 					break;		
       
   477 					}	
       
   478 					
       
   479 
       
   480 				// Test case LBS-LastKnownPos-0012
       
   481 				case 12:
       
   482 					{
       
   483 					// Open positioner.
       
   484 					User::LeaveIfError(iPositioner.Open(iServer));
       
   485 					CleanupClosePushL(iPositioner);
       
   486 
       
   487 					// Carry out a notify update to ensure last known cache is filled.
       
   488 					TPositionInfo notifyPosInfo;
       
   489 					User::LeaveIfError(DoNotifyUpdateL(notifyPosInfo));
       
   490 
       
   491 					TPositionInfo posInfo;
       
   492 
       
   493 					// Get the last known position while self Locate Server is busy
       
   494 					err = DoLastKnownPosL(posInfo);
       
   495 
       
   496 					if (KErrServerBusy != err)
       
   497 						{
       
   498 						// Completed successfully.
       
   499 						INFO_PRINTF1(_L("<FONT><B>**Test should pass if GetLastKnownPosition() fails with KErrServerBusy **</B></FONT>"));
       
   500 						SetTestStepResult(EFail);
       
   501 						}
       
   502 					CleanupStack::PopAndDestroy(&iPositioner);
       
   503 					break;	
       
   504 					}
       
   505 			
       
   506 			
       
   507 				// Test case LBS-LastKnownPos-0014
       
   508 				case 14:
       
   509 					{
       
   510 					// Testcase placeholder
       
   511 					// Request multiples LKPs from different clients concurrently 
       
   512 					SetTestStepResult(EFail);						
       
   513 					break;
       
   514 					}
       
   515 			
       
   516 			
       
   517 				// Test case LBS-LastKnownPos-0015
       
   518 				case 15:
       
   519 				// Test case LBS-LastKnownPos-0103
       
   520 				case 103:
       
   521 					{
       
   522 					T_LbsUtils utils;
       
   523 					// Open positioner.
       
   524 					User::LeaveIfError(iPositioner.Open(iServer));
       
   525 					CleanupClosePushL(iPositioner);		
       
   526 					if(testCaseId==103)
       
   527 	                    {
       
   528 	                    // For this test an additional reference position will be returned.
       
   529 					
       
   530 						// Setup netsim.
       
   531 						User::LeaveIfError(OpenNetSim());
       
   532 							
       
   533 						// Request notify for the expected reference position.
       
   534 						TPositionInfo actualRefPosInfo;
       
   535 							
       
   536 						err = DoNotifyUpdateL(actualRefPosInfo);
       
   537 						if (err)
       
   538 							{
       
   539 							INFO_PRINTF2(_L("Failed test, reference position request returned err %d."), err);
       
   540 							SetTestStepResult(EFail);							
       
   541 							}
       
   542 								
       
   543 						// Verify reference position.
       
   544 						TPositionInfo verifyRefPosInfo;
       
   545 							
       
   546 						verifyRefPosInfo.SetPosition(iRefPos);
       
   547 						if (!utils.Compare_PosInfo(verifyRefPosInfo, actualRefPosInfo))
       
   548 							{
       
   549 							INFO_PRINTF1(_L("Failed test, reference position incorrect."));
       
   550 							SetTestStepResult(EFail);
       
   551 							}	
       
   552 	                    }
       
   553 																				
       
   554 					// Carry out a notify update to ensure last known cache is filled.
       
   555 					TPositionInfo notifyPosInfo;
       
   556 					TInt err = DoNotifyUpdateL(notifyPosInfo);
       
   557 					User::LeaveIfError(err);
       
   558 					
       
   559 					// Create a posinfo and store in our shared array for later verification.
       
   560 					RPointerArray<TAny>& posInfoArr = iParent.iSharedData->iCurrentPosInfoArr;
       
   561 					
       
   562 					
       
   563 					utils.ResetAndDestroy_PosInfoArr(posInfoArr);	// Clear previous entries before new entry is appended.
       
   564 					
       
   565 					CT_LbsAsyncWaiter*	waiter = CT_LbsAsyncWaiter::NewL();
       
   566 					CleanupStack::PushL(waiter);
       
   567 					
       
   568 					TInt numpositions = iParent.iSharedData->iVerifyPosInfoArr.Count();
       
   569 					while(numpositions--)
       
   570 						{
       
   571 						RPositioner positioner;
       
   572 						// Open positioner.
       
   573 						User::LeaveIfError(positioner.Open(iServer));
       
   574 						CleanupClosePushL(positioner);		
       
   575 												
       
   576 						TPositionInfo* posInfo = new(ELeave) TPositionInfo();
       
   577 						posInfoArr.Append(posInfo);
       
   578 
       
   579 						// LastKnownPosition from multiple sub sessions
       
   580 
       
   581 						User::LeaveIfError(positioner.SetRequestor(	CRequestor::ERequestorService,
       
   582 																		CRequestor::EFormatApplication,
       
   583 																		_L("Tom Tom")));
       
   584 																		
       
   585 						positioner.GetLastKnownPosition(*posInfo, waiter->iStatus);
       
   586 						waiter->StartAndWait();
       
   587 						TInt res = waiter->Result();
       
   588 						
       
   589 						if(KErrNone != res)
       
   590 							{
       
   591 							//One of the LKPs failed, so test fails.
       
   592 							SetTestStepResult(EFail);
       
   593 							}
       
   594 						CleanupStack::PopAndDestroy(&positioner);
       
   595 						}
       
   596 
       
   597 						CleanupStack::PopAndDestroy(waiter);
       
   598 						CleanupStack::PopAndDestroy(&iPositioner);
       
   599 					    if (testCaseId == 103)
       
   600 							{
       
   601 							CloseNetSim();
       
   602 							}
       
   603 					break;	
       
   604 					}
       
   605 				// Test case LBS-LastKnownPos-0016
       
   606 				case 16:
       
   607 				// Test case LBS-LastKnownPos-0104
       
   608 				case 104:
       
   609 					{
       
   610 					T_LbsUtils utils;
       
   611 					// Open positioner.
       
   612 					User::LeaveIfError(iPositioner.Open(iServer));
       
   613 					CleanupClosePushL(iPositioner);
       
   614                     if(testCaseId==104)
       
   615 	                    {
       
   616 	                    // For this test an additional reference position will be returned.
       
   617 					
       
   618 						// Setup netsim.
       
   619 						User::LeaveIfError(OpenNetSim());
       
   620 							
       
   621 						// Request notify for the expected reference position.
       
   622 						TPositionInfo actualRefPosInfo;
       
   623 							
       
   624 						err = DoNotifyUpdateL(actualRefPosInfo);
       
   625 						if (err)
       
   626 							{
       
   627 							INFO_PRINTF2(_L("Failed test, reference position request returned err %d."), err);
       
   628 							SetTestStepResult(EFail);							
       
   629 							}
       
   630 								
       
   631 						// Verify reference position.
       
   632 						TPositionInfo verifyRefPosInfo;
       
   633 							
       
   634 						verifyRefPosInfo.SetPosition(iRefPos);
       
   635 						if (!utils.Compare_PosInfo(verifyRefPosInfo, actualRefPosInfo))
       
   636 							{
       
   637 							INFO_PRINTF1(_L("Failed test, reference position incorrect."));
       
   638 							SetTestStepResult(EFail);
       
   639 							}	
       
   640 	                    }
       
   641 		
       
   642 					// Carry out a notify update to ensure last known cache is filled.
       
   643 					TPositionInfo notifyPosInfo;
       
   644 					User::LeaveIfError(DoNotifyUpdateL(notifyPosInfo));
       
   645 
       
   646 					// Create a posinfo and store in our shared array for later verification.
       
   647 					RPointerArray<TAny>& posInfoArr = iParent.iSharedData->iCurrentPosInfoArr;
       
   648 
       
   649 				
       
   650 					utils.ResetAndDestroy_PosInfoArr(posInfoArr);	// Clear previous entries before new entry is appended.
       
   651 
       
   652 					TInt numPositions = iParent.iSharedData->iVerifyPosInfoArr.Count();
       
   653 					while(numPositions--)
       
   654 						{
       
   655 						TPositionInfo* posInfo = new(ELeave) TPositionInfo();
       
   656 						posInfoArr.Append(posInfo);
       
   657 						
       
   658 						err = DoLastKnownPosL(*posInfo);
       
   659 						if (KErrNone != err)
       
   660 							{
       
   661 							SetTestStepResult(EFail);
       
   662 							}
       
   663 						}
       
   664 					
       
   665 					CleanupStack::PopAndDestroy(&iPositioner);
       
   666 					if (testCaseId == 104)
       
   667 						{
       
   668 						CloseNetSim();
       
   669 						}
       
   670 					break;	
       
   671 					}
       
   672 				// Test case LBS-LastKnownPos-0105	
       
   673 				case 105:
       
   674 			    	{
       
   675 			    	T_LbsUtils utils;
       
   676 			    	TPositionModuleId networkModuleId = utils.GetNetworkModuleIdL(iServer);
       
   677 					// Open positioner.
       
   678 					User::LeaveIfError(iPositioner.Open(iServer, networkModuleId));
       
   679 					CleanupClosePushL(iPositioner);
       
   680 
       
   681 					// Setup netsim.
       
   682 					User::LeaveIfError(OpenNetSim());
       
   683 						
       
   684 					TPosition pos;		// original position
       
   685 					TTime timeStamp;	// timestamp inside original received position
       
   686 					
       
   687 					// Carry out a notify update to ensure last known cache is filled.
       
   688 					TPositionInfo actualRefPosInfo;
       
   689 						
       
   690 					err = DoNotifyUpdateL(actualRefPosInfo);
       
   691 										
       
   692 					if (err)
       
   693 						{
       
   694 						INFO_PRINTF2(_L("Failed test, reference position request returned err %d."), err);
       
   695 						SetTestStepResult(EFail);							
       
   696 						}
       
   697 												
       
   698 					// get the position data:
       
   699 					actualRefPosInfo.GetPosition(pos);
       
   700 					
       
   701 					timeStamp = pos.Time();
       
   702 					INFO_PRINTF1(_L("Original position timeStamp: "));
       
   703 					INFO_PRINTF4(_L("%d/%d/%d"), timeStamp.DateTime().Day() + 1, timeStamp.DateTime().Month() + 1, timeStamp.DateTime().Year());
       
   704 					INFO_PRINTF5(_L("at %d :%d :%d :%d"), timeStamp.DateTime().Hour(), timeStamp.DateTime().Minute(), timeStamp.DateTime().Second(), timeStamp.DateTime().Second());
       
   705 						
       
   706 					// Create a posinfo and store in our shared array for later verification.
       
   707 					RPointerArray<TAny>& posInfoArr = iParent.iSharedData->iCurrentPosInfoArr;
       
   708 					TPositionInfo* posInfo = new(ELeave) TPositionInfo();
       
   709 	
       
   710 					utils.ResetAndDestroy_PosInfoArr(posInfoArr);	// Clear previous entries before new entry is appended.
       
   711 
       
   712 					posInfoArr.Append(posInfo);
       
   713 
       
   714 					// Get the last known position
       
   715 					err = DoLastKnownPosL(*posInfo);
       
   716 					if (KErrNone != err)
       
   717 						{
       
   718 						SetTestStepResult(EFail);
       
   719 						}
       
   720 					else
       
   721 						{								
       
   722 						TTime timeStamp_cached;		
       
   723 						posInfo->GetPosition(pos);	
       
   724 						timeStamp_cached = pos.Time();
       
   725 						
       
   726 						timeStamp = pos.Time();
       
   727 						INFO_PRINTF1(_L("Cached position timeStamp: "));
       
   728 						INFO_PRINTF4(_L("%d/%d/%d"), timeStamp_cached.DateTime().Day() + 1, timeStamp_cached.DateTime().Month() + 1, timeStamp_cached.DateTime().Year());
       
   729 						INFO_PRINTF5(_L("at %d :%d :%d :%d"), timeStamp_cached.DateTime().Hour(), timeStamp_cached.DateTime().Minute(), timeStamp_cached.DateTime().Second(), timeStamp_cached.DateTime().Second());
       
   730 													
       
   731 						// verify that the timestamp matches the original one:
       
   732 						if(timeStamp_cached != timeStamp)
       
   733 							{
       
   734 							SetTestStepResult(EFail);
       
   735 							}
       
   736 						
       
   737 						}
       
   738 														
       
   739 					CleanupStack::PopAndDestroy(&iPositioner);
       
   740 					// Close netsim.
       
   741 					CloseNetSim();
       
   742 					break;
       
   743 					}
       
   744 				
       
   745 				default:
       
   746 					{
       
   747 					User::Leave(KErrArgument);
       
   748 					}
       
   749 				}
       
   750 			}
       
   751 
       
   752 		// All done, clean up.
       
   753 
       
   754 		CleanupStack::PopAndDestroy(&iServer);		
       
   755 		}
       
   756 
       
   757 	INFO_PRINTF1(_L("&lt;&lt;CT_LbsClientStep_LastKnownPos::doTestStepL()"));
       
   758 
       
   759 	return TestStepResult();
       
   760 	}
       
   761