lbs/lbsclient/src/ctlbsclientstepmultireq.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     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 ctlbsclientstepmultireq.cpp
       
    15 // This is the class implementation for the Multi-Request Tests
       
    16 // 
       
    17 //
       
    18  
       
    19 #include "ctlbsclientstepmultireq.h"
       
    20 
       
    21 #include <lbs.h>
       
    22 #include <lbscommon.h>
       
    23 #include <lbspositioninfo.h>
       
    24 #include <lbsipc.h>
       
    25 
       
    26 #include "tlbsutils.h"
       
    27 
       
    28 // constant definitions
       
    29 _LIT(KLbsClientStepMultiReq, "LbsClientStepMultiReq");
       
    30 
       
    31 
       
    32 /**
       
    33  * Destructor
       
    34  */
       
    35 CT_LbsClientStep_MultiReq::~CT_LbsClientStep_MultiReq()
       
    36 	{
       
    37 	delete	iGetLastKnownPosAO;
       
    38 	delete	iNotifyPosUpdateAO;	
       
    39 	delete  iTimer;
       
    40 	delete 	iTempPosInfo;
       
    41 	}
       
    42 
       
    43 
       
    44 /**
       
    45  * Constructor
       
    46  */
       
    47 CT_LbsClientStep_MultiReq::CT_LbsClientStep_MultiReq(CT_LbsClientServer& aParent) : CT_LbsClientStep(aParent), iState(EStateUnknown), iTempPosInfo(NULL)
       
    48 	{
       
    49 	SetTestStepName(KLbsClientStep_MultiReq);
       
    50 	}
       
    51 
       
    52 
       
    53 /**
       
    54 Static Constructor
       
    55 */
       
    56 CT_LbsClientStep_MultiReq* CT_LbsClientStep_MultiReq::NewL(CT_LbsClientServer& aParent)
       
    57 	{
       
    58 	return new(ELeave) CT_LbsClientStep_MultiReq(aParent);
       
    59 	}
       
    60 
       
    61 
       
    62 /**
       
    63 Static Constructor
       
    64 */
       
    65 CT_LbsClientStep_MultiReq* CT_LbsClientStep_MultiReq::New(CT_LbsClientServer& aParent)
       
    66 	{
       
    67 	return new CT_LbsClientStep_MultiReq(aParent);
       
    68 	// Note the lack of ELeave.
       
    69 	// This means that having insufficient memory will return NULL;
       
    70 	}
       
    71 	
       
    72 
       
    73 /**
       
    74  * 	Callback - called when NotifyPositionUpdate request completes
       
    75  */
       
    76 void CT_LbsClientStep_MultiReq::NotifyPositionUpdateCallback(TRequestStatus& aStatus)
       
    77 /**
       
    78  *	Called when async NotifyPositionUpdate completes
       
    79  */
       
    80 	{
       
    81 	TInt testCaseId;
       
    82 
       
    83 	if (GetIntFromConfig(ConfigSection(), KTestCaseId, testCaseId))
       
    84 		{
       
    85 		switch (testCaseId)
       
    86 			{
       
    87 			case 01:		// multiple requests of different types
       
    88 				{
       
    89 				if(KErrNone == aStatus.Int())
       
    90 					{
       
    91 					switch(iState)
       
    92 						{
       
    93 						case EStateUnknown:					
       
    94 							{
       
    95 							iState = EStateLastNotifyPositionUpdateComplete;
       
    96 							}
       
    97 							break;
       
    98 							
       
    99 						case EStateLastKnownPositionComplete:
       
   100 							{ 
       
   101 							iState = EStateDone;
       
   102 							AsyncTidyUp();
       
   103 							// note: we'll now drop back into the main test step
       
   104 							}
       
   105 							break;			
       
   106 							
       
   107 						case EStateLastNotifyPositionUpdateComplete:
       
   108 						case EStateDone :								
       
   109 						// fall through
       
   110 						default:
       
   111 							{
       
   112 							User::Panic(KLbsClientStepMultiReq, KErrUnknown);
       
   113 							}
       
   114 							break;	
       
   115 						}	
       
   116 					}
       
   117 				else
       
   118 					{
       
   119 					INFO_PRINTF2(_L("NotifyModuleStatusEvent completed. Status = %d"), aStatus.Int());	
       
   120 					SetTestStepResult(EFail);
       
   121 					AsyncTidyUp();
       
   122 					}
       
   123 				}// end case 01
       
   124 				break;
       
   125 			case 02:	// 
       
   126 				{
       
   127 				switch(iState)
       
   128 					{
       
   129 					case EStateUnknown:					
       
   130 						{
       
   131 						iState = EStateLastNotifyPositionUpdateComplete;
       
   132 						}
       
   133 						break;						
       
   134 
       
   135 					case EStateLastKnownPositionComplete:
       
   136 						{
       
   137 						iState = EStateDone;
       
   138 						AsyncTidyUp();
       
   139 						}
       
   140 						break;
       
   141 	
       
   142 					case EStateLastNotifyPositionUpdateComplete:											
       
   143 					case EStateDone :								
       
   144 					// fall through
       
   145 					default:
       
   146 						{
       
   147 						User::Panic(KLbsClientStepMultiReq, KErrUnknown);
       
   148 						}
       
   149 						break;	
       
   150 					}	
       
   151 				}
       
   152 				break;
       
   153 			default:
       
   154 				{
       
   155 				User::Panic(KLbsClientStepMultiReq, KErrUnknown);
       
   156 				}
       
   157 			
       
   158 			}// end switch testCaseId
       
   159 		}// end if GetIntFromConfig
       
   160 	}
       
   161 
       
   162  
       
   163  
       
   164 /**
       
   165  * 	Callback - called when GetLastKnownPosition request completes
       
   166  */
       
   167 void CT_LbsClientStep_MultiReq::GetLastKnownPositionCallback(TRequestStatus& aStatus)
       
   168 /**
       
   169  *	Called when NotifyModuleStatusEvent completes
       
   170  */
       
   171 	{
       
   172 	TInt testCaseId;
       
   173 
       
   174 	if (GetIntFromConfig(ConfigSection(), KTestCaseId, testCaseId))
       
   175 		{
       
   176 		switch (testCaseId)
       
   177 			{
       
   178 			case 01:		// multiple requests of different types
       
   179 				{
       
   180 				if(KErrNone == aStatus.Int())
       
   181 					{
       
   182 					switch(iState)
       
   183 						{
       
   184 						case EStateUnknown:					
       
   185 							{
       
   186 							iState = EStateLastKnownPositionComplete;
       
   187 							}
       
   188 							break;
       
   189 							
       
   190 						case EStateLastNotifyPositionUpdateComplete:				
       
   191 							{ 
       
   192 							iState = EStateDone;
       
   193 							AsyncTidyUp();
       
   194 							// note: we'll now drop back into the main test step
       
   195 							}
       
   196 							break;			
       
   197 							
       
   198 						case EStateLastKnownPositionComplete:
       
   199 						case EStateDone :								
       
   200 						// fall through
       
   201 						default:
       
   202 							{
       
   203 							User::Panic(KLbsClientStepMultiReq, KErrUnknown);
       
   204 							}
       
   205 						break;
       
   206 						
       
   207 						}	
       
   208 					}
       
   209 				else
       
   210 					{
       
   211 					INFO_PRINTF2(_L("NotifyModuleStatusEvent completed. Status =%d"), aStatus.Int());	
       
   212 					SetTestStepResult(EFail);
       
   213 					AsyncTidyUp();
       
   214 					}
       
   215 					
       
   216 				}// end case 01
       
   217 				break;
       
   218 			case 02: // NotifyPositionUpdate then GetLKP, latter cancelled
       
   219 				{
       
   220 				switch(iState)
       
   221 					{
       
   222 					case EStateUnknown:
       
   223 						{
       
   224 						iState = EStateLastKnownPositionComplete;
       
   225 						TInt err = aStatus.Int();
       
   226 						switch(err)
       
   227 							{
       
   228 							case KErrNone:
       
   229 								{
       
   230 								INFO_PRINTF1(_L("MultiReq test: Last Known Position request completed successfully"));
       
   231 								}
       
   232 								break;
       
   233 							case KErrCancel:
       
   234 								{
       
   235 								INFO_PRINTF1(_L("MultiReq test: Last Known Position request completed with KErrCancel"));
       
   236 								}
       
   237 								break;
       
   238 							case KErrUnknown:
       
   239 								{
       
   240 								INFO_PRINTF1(_L("MultiReq test: Last Known Position request completed with KErrUnknown"));
       
   241 								}
       
   242 								break;
       
   243 							default:
       
   244 								{
       
   245 		
       
   246 								SetTestStepResult(EFail);
       
   247 								AsyncTidyUp();								
       
   248 								}
       
   249 								break;
       
   250 							}
       
   251 						}
       
   252 						break;
       
   253 																	
       
   254 					case EStateLastNotifyPositionUpdateComplete:	
       
   255 						{
       
   256 						iState = EStateDone;
       
   257 						TInt err = aStatus.Int();
       
   258 						if(KErrNone != err)
       
   259 							{
       
   260 							SetTestStepResult(EFail);
       
   261 							}
       
   262 						AsyncTidyUp();
       
   263 						}
       
   264 						break;
       
   265 						
       
   266 					case EStateLastKnownPositionComplete:						
       
   267 					case EStateDone :								
       
   268 					// fall through
       
   269 					default:
       
   270 						{
       
   271 						User::Panic(KLbsClientStepMultiReq, KErrUnknown);
       
   272 						}					
       
   273 					}// end switch(iState)
       
   274 				}// end case 2
       
   275 				break;
       
   276 				
       
   277 			default:
       
   278 				{
       
   279 				User::Panic(KLbsClientStepMultiReq, KErrUnknown);
       
   280 				}
       
   281 			break;				
       
   282 			}
       
   283 		}			
       
   284 	}
       
   285 	
       
   286 	
       
   287 /**
       
   288  *	tidy up everything
       
   289  */
       
   290 void CT_LbsClientStep_MultiReq::AsyncTidyUp()
       
   291 	{
       
   292 	if ( iTimer->IsActive() )
       
   293 		{
       
   294 		iTimer->Cancel();
       
   295 		}	
       
   296 	// Cancel any outstanding requests (to be tested):
       
   297 	if(iNotifyPosUpdateAO->IsActive())
       
   298 		{
       
   299 		iNotifyPosUpdateAO->Cancel();
       
   300 		}
       
   301 	if(iGetLastKnownPosAO->IsActive())
       
   302 		{
       
   303 		iGetLastKnownPosAO->Cancel();
       
   304 		}
       
   305 	CActiveScheduler::Stop();
       
   306 	}
       
   307 	
       
   308 	
       
   309 /**
       
   310  *	Callback function - called if timer fires (requests did not all complete in time)
       
   311  */
       
   312 static TInt TimerCallback(TAny* aPointer)
       
   313 	{
       
   314 	//the timer expired and we have not got the responses to our lbs requests
       
   315 	static_cast<CT_LbsClientStep_MultiReq*>(aPointer)->INFO_PRINTF1(_L(">>TEST FAILED: timer fired"));
       
   316 	static_cast<CT_LbsClientStep_MultiReq*>(aPointer)->AsyncTidyUp();
       
   317 	static_cast<CT_LbsClientStep_MultiReq*>(aPointer)->SetTestStepResult(EFail);
       
   318 
       
   319 	return KErrNone;	
       
   320 	}
       
   321 	
       
   322 /**
       
   323  * @return - TVerdict code
       
   324  * Override of base class pure virtual
       
   325  * Our implementation only gets called if the base class doTestStepPreambleL() did
       
   326  * not leave. That being the case, the current test result value will be EPass.
       
   327  */
       
   328 TVerdict CT_LbsClientStep_MultiReq::doTestStepL()
       
   329 	{
       
   330 	// Generic test step used to test the LBS Client Notify position update API.
       
   331 	INFO_PRINTF1(_L("&gt;&gt;CT_LbsClientStep_MultiReq::doTestStepL()"));
       
   332 		
       
   333 	if (TestStepResult()==EPass)
       
   334 		{		
       
   335 		// Connect to self locate server.
       
   336 		User::LeaveIfError(iServer.Connect());
       
   337 		CleanupClosePushL(iServer);
       
   338 		
       
   339 		TInt testCaseId;
       
   340 		if (GetIntFromConfig(ConfigSection(), KTestCaseId, testCaseId))
       
   341 			{
       
   342 			switch (testCaseId)
       
   343 				{
       
   344 				case 01:		// multiple requests of different types
       
   345 					{
       
   346 					// Open positioner.
       
   347 					User::LeaveIfError(iPositioner.Open(iServer));
       
   348 					CleanupClosePushL(iPositioner);
       
   349 
       
   350 					// Carry out a notify update to ensure last known cache is filled (note: this blocks!)
       
   351 					TPositionInfo notifyPosInfo;
       
   352 					User::LeaveIfError(DoNotifyUpdateL(notifyPosInfo));
       
   353 
       
   354 					// Create 2 posinfos and store in our shared array for later verification.
       
   355 					RPointerArray<TAny>& posInfoArr = iParent.iSharedData->iCurrentPosInfoArr;
       
   356 					TPositionInfo* posInfoLastKnown = new(ELeave) TPositionInfo();
       
   357 					TPositionInfo* posInfoNotifyUpd = new(ELeave) TPositionInfo();
       
   358 							
       
   359 					T_LbsUtils utils;
       
   360 					utils.ResetAndDestroy_PosInfoArr(posInfoArr);	// Clear previous entries before new entry is appended.
       
   361 
       
   362 					// these get deleted by the base class destructor
       
   363 					posInfoArr.Append(posInfoLastKnown);
       
   364 					posInfoArr.Append(posInfoNotifyUpd);
       
   365 
       
   366 					// Start GetLastKnownPosition request:
       
   367 					iGetLastKnownPosAO = CT_LbsClientGetLastKnownPosAO::NewL(*this);					
       
   368 				
       
   369 					iGetLastKnownPosAO->GetLastKnownPosL(iPositioner, *posInfoLastKnown);
       
   370 					
       
   371 					// Start NotifyPositionUpdate request:
       
   372 					iNotifyPosUpdateAO = CT_LbsClientNotifyPosUpdAO::NewL(*this);
       
   373 					
       
   374 					iNotifyPosUpdateAO->NotifyPosUpdateL(iPositioner, *posInfoNotifyUpd);
       
   375 					
       
   376 					// Start a timer to make sure neither of above times out:
       
   377 					iTimer = CPeriodic::New(CActive::EPriorityStandard);						
       
   378 					TCallBack callbackFunction = TCallBack(TimerCallback, this);
       
   379 					iTimer->Start( delay10Seconds, 0, callbackFunction);
       
   380 					
       
   381 					// can start the scheduler now as there are async requests issued
       
   382 					CActiveScheduler::Start();
       
   383 					
       
   384 					// All requests have now completed (and scheduler stopped)
       
   385 					
       
   386 					CleanupStack::PopAndDestroy(&iPositioner);					
       
   387 					} // end case 1
       
   388 					break;
       
   389 					
       
   390 				case 02:	// cancel one of two outstanding requests
       
   391 					{
       
   392 					// Open positioner.
       
   393 					User::LeaveIfError(iPositioner.Open(iServer));
       
   394 					CleanupClosePushL(iPositioner);
       
   395 
       
   396 					// Create a posinfo and store in our shared array for later verification.
       
   397 					RPointerArray<TAny>& posInfoArr = iParent.iSharedData->iCurrentPosInfoArr;
       
   398 					TPositionInfo* posInfoNotifyUpd = new(ELeave) TPositionInfo();
       
   399 							
       
   400 					T_LbsUtils utils;
       
   401 					utils.ResetAndDestroy_PosInfoArr(posInfoArr);	// Clear previous entries before new entry is appended.
       
   402 
       
   403 					// this gets deleted by the base class destructor:
       
   404 					posInfoArr.Append(posInfoNotifyUpd);
       
   405 					
       
   406 					// Start NotifyPositionUpdate request:
       
   407 					iNotifyPosUpdateAO = CT_LbsClientNotifyPosUpdAO::NewL(*this);
       
   408 					
       
   409 					iNotifyPosUpdateAO->NotifyPosUpdateL(iPositioner, *posInfoNotifyUpd);
       
   410 											
       
   411 					// Start a GetLastKnownPosition:
       
   412 					// don't put in verify array as this may be cancelled:
       
   413 					iTempPosInfo = new(ELeave) TPositionInfo();
       
   414 					
       
   415 					iGetLastKnownPosAO = CT_LbsClientGetLastKnownPosAO::NewL(*this);					
       
   416 				
       
   417 					iGetLastKnownPosAO->GetLastKnownPosL(iPositioner, *iTempPosInfo);
       
   418 					
       
   419 					// cancel the last known position. Note that we do this directly, NOT by calling the AO's cancel()
       
   420 					// so that the AO's RunL(), and therefore our callback, will be called and we can check the result
       
   421 					TInt err;
       
   422 					err = iPositioner.CancelRequest(EPositionerGetLastKnownPosition);
       
   423 					if(KErrNotFound != err)
       
   424 						{
       
   425 						SetTestStepResult(EFail);
       
   426 						}
       
   427 					
       
   428 					// Start a timer to make sure neither of above times out:
       
   429 					iTimer = CPeriodic::New(CActive::EPriorityStandard);						
       
   430 					TCallBack callbackFunction = TCallBack(TimerCallback, this);
       
   431 					
       
   432 					//
       
   433 					// 
       
   434 					// NB - THIS VALUE WAS 10 SEC AND THE TIMER EXPIRED, CAUSING THE TEST
       
   435 					// TO FAIL. NEED TO FIND OUT WHY THIS VALUE IS OK BUT THAT ONE WAS NOT.
       
   436 					// PUT BACK TEMPORARILY TO GET RID OF REGRESSION FAILURE
       
   437 					//
       
   438 					iTimer->Start( 22000000, 0, callbackFunction);
       
   439 					
       
   440 					// can start the scheduler now as there are async requests issued
       
   441 					CActiveScheduler::Start();
       
   442 					
       
   443 					// All requests have now completed
       
   444 					
       
   445 					CleanupStack::PopAndDestroy(&iPositioner);					
       
   446 					}
       
   447 					break;
       
   448 					
       
   449 				default:
       
   450 					{
       
   451 					User::Leave(KErrArgument);
       
   452 					}
       
   453 				}// end switch
       
   454 			}//end if GetIntFromConfig
       
   455 					
       
   456 		CleanupStack::PopAndDestroy(&iServer);	
       
   457 
       
   458 		} // end if TestStepResult
       
   459 		
       
   460 	INFO_PRINTF1(_L("&lt;&lt;CT_LbsClientStep_MultiReq::doTestStepL()"));
       
   461 
       
   462 	return TestStepResult();
       
   463 	}