lbstest/lbstestproduct/lbsclient/src/ctlbsclientstepconcurrent.cpp
changeset 0 9cfd9a3ee49c
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 ctlbsclientstepconcurrent.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 // LBS includes.
       
    19 #include <lbspositioninfo.h>
       
    20 #include <lbsareainfo.h>
       
    21 #include <e32base.h>
       
    22 #include <lbs.h>
       
    23 
       
    24 #include <lbssatellite.h>
       
    25 
       
    26 #include <lbs/test/tlbsutils.h>
       
    27 
       
    28 #include <etel3rdparty.h>
       
    29 #include <simtsy.h>
       
    30 
       
    31 
       
    32 // LBS test includes.
       
    33 #include "ctlbsclientstepconcurrent.h"
       
    34 
       
    35 const TInt KSimTsyTransitionDelay = 4000000; // Currently it seems to take the SimTsy 3 seconds to change cell
       
    36 
       
    37 //Literals Used
       
    38 _LIT(KTestCaseId, "tc_id");
       
    39 _LIT(KPosInfosFile, "pos_infos_file");
       
    40 _LIT(KLbsModuleType, "module_type");
       
    41 _LIT(KLbsModuleType_Real, "real");
       
    42 
       
    43 /**
       
    44  * Destructor
       
    45  */
       
    46 CT_LbsClientStep_Concurrent::~CT_LbsClientStep_Concurrent()
       
    47 	{
       
    48 	// Delete this active scheduler
       
    49 	if (iScheduler)
       
    50 		delete iScheduler;
       
    51 
       
    52 	// Clear arrays.
       
    53 	for (TInt i = 0; i < iVerifyPosInfoArr.Count(); ++i)
       
    54 		delete iVerifyPosInfoArr[i];
       
    55 	iVerifyPosInfoArr.Close();
       
    56 
       
    57 	for (TInt i = 0; i < iCurrentPosInfoArr.Count(); ++i)
       
    58 		delete iCurrentPosInfoArr[i];
       
    59 	iCurrentPosInfoArr.Close();
       
    60 	}
       
    61 
       
    62 /**
       
    63  * Constructor
       
    64  */
       
    65 CT_LbsClientStep_Concurrent::CT_LbsClientStep_Concurrent()
       
    66 	{
       
    67 	iTestModuleInUse = ETrue;
       
    68 	SetTestStepName(KLbsClientStepConcurrent);
       
    69 	}
       
    70 
       
    71 /**
       
    72 Static Constructor
       
    73 */
       
    74 CT_LbsClientStep_Concurrent* CT_LbsClientStep_Concurrent::New()
       
    75 	{
       
    76 	CT_LbsClientStep_Concurrent* testStep = new CT_LbsClientStep_Concurrent();
       
    77 	// Note the lack of ELeave.
       
    78 	// This means that having insufficient memory will return NULL;
       
    79 	if (testStep)
       
    80 		{
       
    81 		TInt err = KErrNone;
       
    82 
       
    83 		TRAP(err, testStep->ConstructL());
       
    84 		if (err)
       
    85 			{
       
    86 			delete testStep;
       
    87 			testStep = NULL;
       
    88 			}
       
    89 		}
       
    90 
       
    91 	return testStep;
       
    92 	}
       
    93 
       
    94 void CT_LbsClientStep_Concurrent::ConstructL()
       
    95 	{
       
    96 	
       
    97 	// Create this objects active scheduler in 
       
    98 	// case some tests needs it.
       
    99 	iScheduler = new (ELeave) CActiveScheduler();
       
   100 
       
   101 	CActiveScheduler::Install(iScheduler);
       
   102 	}
       
   103 
       
   104 /**
       
   105  * @return - TVerdict code
       
   106  */
       
   107 TVerdict CT_LbsClientStep_Concurrent::doTestStepL()
       
   108 	{
       
   109 	// Generic test step used to test the LBS Client Notify position update API.
       
   110 	INFO_PRINTF1(_L("   CT_LbsClientStep_Concurrent::doTestStepL()"));
       
   111 
       
   112 	if (TestStepResult() == EPass)
       
   113 		{
       
   114 		TPositionAreaExtendedInfo matchLevel, expectedMatchLevel;
       
   115 		// Connect to self locate server.
       
   116 		TInt err = iServer.Connect();
       
   117 		User::LeaveIfError(err);
       
   118 		CleanupClosePushL(iServer);
       
   119 		TPositionModuleId modId;
       
   120 		T_LbsUtils utils;
       
   121 		modId = utils.GetAGpsModuleIdL(iServer);
       
   122 		User::LeaveIfError(iPositioner.Open(iServer, modId));
       
   123 		CleanupClosePushL(iPositioner);
       
   124 		
       
   125 		
       
   126 		// Create the verifiable position info
       
   127 		// CreateVerifyPositionInfoL();
       
   128 
       
   129 		// Carry out actions required by each specific test (id).
       
   130 		if (GetIntFromConfig(ConfigSection(), KTestCaseId, iTestCaseId))
       
   131 			{
       
   132 			switch (iTestCaseId)
       
   133 				{
       
   134 				case 0:
       
   135 					{
       
   136 					// This test is for setting up the database. It is sometimes
       
   137 					// run sequentially before starting other concurrent tests.
       
   138 					
       
   139 					// First clear the DB.
       
   140 					TRequestStatus emptyStatus;
       
   141 					iServer.EmptyLastKnownPositionStore(emptyStatus);
       
   142 					User::WaitForRequest(emptyStatus);
       
   143 					
       
   144 					TPositionInfo* posInfo = new (ELeave) TPositionInfo();
       
   145 					//Move to next cell in sim tsy config file to ensure
       
   146 					// the Location Monitor DB has at least information about
       
   147 					// one area/cell Id.
       
   148 					RProperty::Set(KUidPSSimTsyCategory,
       
   149 							KPSSimTsyTimersReduceTime, KReduceSimTsyTimers);
       
   150 					User::After(KSimTsyTransitionDelay);
       
   151 
       
   152 					// Issue NPUD waiting for result to make sure a position
       
   153 					// has gone into the Location Monitor database before
       
   154 					// the real test starts
       
   155 					TRequestStatus status;
       
   156 					iPositioner.NotifyPositionUpdate(*posInfo, status);
       
   157 					User::WaitForRequest(status);
       
   158 					delete posInfo;
       
   159 					break;
       
   160 					}
       
   161 				case 1:
       
   162 					{
       
   163 					//
       
   164 					// This test requests an NPUD and a GLKPA from the
       
   165 					// same subsession
       
   166 					//
       
   167 					TPositionInfo* posInfo1 = new (ELeave) TPositionInfo();
       
   168 					TPositionInfo* posInfo2 = new (ELeave) TPositionInfo();
       
   169 					iCurrentPosInfoArr.Append(posInfo1);
       
   170 					iCurrentPosInfoArr.Append(posInfo2);
       
   171 					
       
   172 					//1. Move to next cell in sim tsy config file
       
   173 					//RProperty::Set(KUidPSSimTsyCategory,
       
   174 					//		KPSSimTsyTimersReduceTime, KReduceSimTsyTimers);
       
   175 					//User::After(KSimTsyTransitionDelay);
       
   176 
       
   177 					//2. NPUD waiting for result to make sure a position
       
   178 					// has gone into the Location Monitor database before
       
   179 					// the real test starts
       
   180 					TRequestStatus status1;
       
   181 					//iPositioner.NotifyPositionUpdate(*posInfo1, status1);
       
   182 					//User::WaitForRequest(status1);
       
   183 					
       
   184 					//3. NPUD that will be simultaneous to a GLKPA (step 4)
       
   185 					iPositioner.NotifyPositionUpdate(*posInfo1, status1);
       
   186 
       
   187 					//4. GLKPA that is simultaneous to the NPUD at step 3
       
   188 					TRequestStatus status2;
       
   189 					iPositioner.GetLastKnownPositionArea(*posInfo2 , matchLevel, status2);					
       
   190 
       
   191 					User::WaitForRequest(status1);
       
   192 					User::WaitForRequest(status2);
       
   193 					
       
   194 					// NOTE: in concurrent mode, this validation only makes sense when
       
   195 					// the integration module has been asked to reply always with the same
       
   196 					// position. This is because at this point there's no way to know if the
       
   197 					// posInfo2 will contain the position that went into the Location Monitor's
       
   198 					// Database after step 3 above or the value returned by the integration
       
   199 					// module after a concurrent step got its response
       
   200 					// to the NPUD in step 3 above. If the position returned by the integration
       
   201 					// module is always the same, then the validation should pass.
       
   202 					TESTL(KErrNone == status2.Int());
       
   203 					Validate(*posInfo1, *posInfo2, matchLevel, ETrue, ETrue, ETrue, ETrue);
       
   204 					break;
       
   205 					}
       
   206 					
       
   207 				case 2:
       
   208 					{
       
   209 					//
       
   210 					// This test requests an GLKP and a GLKPA from the
       
   211 					// same subsession
       
   212 					//
       
   213 					TPositionInfo* posInfo3 = new (ELeave) TPositionInfo();
       
   214 					TPositionInfo* posInfo4 = new (ELeave) TPositionInfo();
       
   215 					iCurrentPosInfoArr.Append(posInfo3);
       
   216 					iCurrentPosInfoArr.Append(posInfo4);
       
   217 
       
   218 					
       
   219 					
       
   220 					//1. Move to next cell in sim tsy config file
       
   221 					//RProperty::Set(KUidPSSimTsyCategory,
       
   222 					//		KPSSimTsyTimersReduceTime, KReduceSimTsyTimers);
       
   223 					//User::After(KSimTsyTransitionDelay);
       
   224 
       
   225 					//2. NPUD waiting for result to make sure a position
       
   226 					// has gone into the Location Monitor database before
       
   227 					// the real test starts
       
   228 					TRequestStatus status3;
       
   229 					//iPositioner.NotifyPositionUpdate(*posInfo3, status3);
       
   230 					//User::WaitForRequest(status3);
       
   231 					
       
   232 					//3. GLKP that will be simultaneous to a GLKPA (step 4)
       
   233 					iPositioner.GetLastKnownPosition(*posInfo3, status3);
       
   234 
       
   235 					//4. GLKPA that is simultaneous to the NPUD at step 3
       
   236 					TRequestStatus status4;
       
   237 					iPositioner.GetLastKnownPositionArea(*posInfo4 , matchLevel, status4);					
       
   238 
       
   239 					User::WaitForRequest(status3);
       
   240 					User::WaitForRequest(status4);
       
   241 					
       
   242 					// NOTE: in concurrent mode, this validation only makes sense when
       
   243 					// the integration module has been asked to reply always with the same
       
   244 					// position. This is because at this point there's no way to know if the
       
   245 					// posInfo2 will contain the position that went into the Location Monitor's
       
   246 					// Database after step 3 above or the value returned by the integration
       
   247 					// module after a concurrent step got its response
       
   248 					// to the NPUD in step 3 above. If the position returned by the integration
       
   249 					// module is always the same, then the validation should pass.
       
   250 					TESTL(KErrNone == status4.Int());
       
   251 					Validate(*posInfo3, *posInfo4, matchLevel, ETrue, ETrue, ETrue, ETrue);
       
   252 					break;
       
   253 					}
       
   254 					
       
   255 				case 3:
       
   256 					{
       
   257 					//
       
   258 					// This test only requests GLKPA (meant to be used 
       
   259 					// concurrently with other test cases in this file)
       
   260 					//
       
   261 					TPositionInfo* posInfo5 = new (ELeave) TPositionInfo();
       
   262 					TPositionInfo* posInfo6 = new (ELeave) TPositionInfo();
       
   263 					iCurrentPosInfoArr.Append(posInfo5);
       
   264 					iCurrentPosInfoArr.Append(posInfo6);
       
   265 
       
   266 					TRequestStatus status5;
       
   267 
       
   268 					iPositioner.GetLastKnownPositionArea(*posInfo6 , matchLevel, status5);					
       
   269 
       
   270 					User::WaitForRequest(status5);
       
   271 					
       
   272 					TESTL(KErrNone == status5.Int());
       
   273 					
       
   274 					break;
       
   275 					}
       
   276 					
       
   277 				case 31: 
       
   278 					{
       
   279 					//
       
   280 					// This test requests GLKPA then cancels it (meant to be used 
       
   281 					// concurrently with other test cases in this file)
       
   282 					//
       
   283 					TRequestStatus status6;
       
   284 
       
   285 					TPositionInfo* posInfo7 = new (ELeave) TPositionInfo();
       
   286 					TPositionInfo* posInfo8 = new (ELeave) TPositionInfo();
       
   287 					iCurrentPosInfoArr.Append(posInfo7);
       
   288 					iCurrentPosInfoArr.Append(posInfo8);
       
   289 					
       
   290 					//3. GLKPA 
       
   291 					iPositioner.GetLastKnownPositionArea(*posInfo8 , matchLevel, status6);
       
   292 					
       
   293 					//4. Cancel the above request
       
   294 					err = iPositioner.CancelRequest(RPositioner::EReqGetLastKnownPositionArea);
       
   295 
       
   296 					User::WaitForRequest(status6);
       
   297 					
       
   298 					// The cancel may either return KErrNone, in which case the GLKPA
       
   299 					// must complete with KErrCancel or the cancel may complete with
       
   300 					// KErrNotFound, in which case the GLKPA should complete normally
       
   301 					// with KErrNone
       
   302 					INFO_PRINTF2(_L("GLKPA completed with completion code %d"), status6.Int());
       
   303 					if(err != KErrNone && err != KErrNotFound)
       
   304 						{
       
   305 						ERR_PRINTF2(_L("Incorrect Cancel error: %d"), err);
       
   306 						SetTestStepResult(EFail);
       
   307 						}
       
   308 					else if ((err == KErrNone) && (status6.Int() != KErrCancel))
       
   309 						{
       
   310 						ERR_PRINTF2(_L("Incorrect GLKPA completion code: %d"), status6.Int());
       
   311 						SetTestStepResult(EFail);	
       
   312 						}
       
   313 					else if ((err == KErrNotFound) && (status6.Int() != KErrNone))
       
   314 						{
       
   315 						ERR_PRINTF2(_L("Incorrect GLKPA completion code: %d"), status6.Int());
       
   316 						SetTestStepResult(EFail);	
       
   317 						}
       
   318 					
       
   319 					break;
       
   320 					}
       
   321 
       
   322 				case 4:
       
   323 					{
       
   324 					TRequestStatus emptyStatus;
       
   325 					iServer.EmptyLastKnownPositionStore(emptyStatus);
       
   326 					User::WaitForRequest(emptyStatus);
       
   327 					if(emptyStatus.Int() != KErrNone)
       
   328 						{
       
   329 						ERR_PRINTF2(_L("Incorrect err %d returned"), emptyStatus.Int());
       
   330 						SetTestStepResult(EFail);
       
   331 						}
       
   332 					break;
       
   333 					}
       
   334 					
       
   335 				case 41: 
       
   336 					{
       
   337 					TRequestStatus emptyStatus;
       
   338 					iServer.EmptyLastKnownPositionStore(emptyStatus);
       
   339 					//5. Cancel Clear Database
       
   340 					iServer.CancelRequest(RPositionServer::EReqEmptyLastKnownPositionStore);
       
   341 					User::WaitForRequest(emptyStatus);
       
   342 					if(emptyStatus.Int() != KErrNone && emptyStatus.Int() != KErrCancel)
       
   343 						{
       
   344 						ERR_PRINTF2(_L("Incorrect err %d returned"), emptyStatus.Int());
       
   345 						SetTestStepResult(EFail);
       
   346 						}
       
   347 					break;
       
   348 					}
       
   349 				default:
       
   350 					{
       
   351 					INFO_PRINTF2(_L("<FONT><B>   Case number %d did not match any expected value</B></FONT>"),iTestCaseId);
       
   352 					User::Panic(KLbsClientStepConcurrent, KErrUnknown);
       
   353 					}
       
   354     		    }	
       
   355 			}
       
   356 						
       
   357 			// Unless the testcase has been testcase 0000, whose only purpose is
       
   358 			// setting up the Location Monitor DB, delete the database after each
       
   359 			// test. Waiting two seconds before deleting the database gives
       
   360 			// concurrent testcases terminating later a chance to use the database.
       
   361 			// 
       
   362 			//if (iTestCaseId != 0)
       
   363 			//	{
       
   364 			//	User::After(2000000); // 2 seconds
       
   365 			//	TRequestStatus emptyStatus;
       
   366 			//	iServer.EmptyLastKnownPositionStore(emptyStatus);
       
   367 			//	User::WaitForRequest(emptyStatus);
       
   368 			//	}
       
   369 
       
   370 			
       
   371 			// All done, clean up.
       
   372 			CleanupStack::PopAndDestroy(&iPositioner);
       
   373 			CleanupStack::PopAndDestroy(&iServer);	
       
   374 		}
       
   375 	INFO_PRINTF1(_L("&lt;&lt;CT_LbsClientStep_Concurrent::doTestStepL()"));
       
   376 	return TestStepResult();
       
   377 	}
       
   378 
       
   379 
       
   380 void CT_LbsClientStep_Concurrent::CreateVerifyPositionInfoL()
       
   381 {
       
   382 		INFO_PRINTF1(_L("   CreateVerifyPositionInfoL"));
       
   383 
       
   384 		TPtrC configFileName;
       
   385 		GetStringFromConfig(ConfigSection(), KPosInfosFile, configFileName);
       
   386 
       
   387 		T_LbsUtils utils;
       
   388 
       
   389 		utils.GetConfigured_PosInfosL(configFileName, ConfigSection(), iVerifyPosInfoArr); // Note previous entries will be cleared.
       
   390 
       
   391 		// Notify the test module that it's required to update it's test data.
       
   392 		TPtrC modType;
       
   393 		GetStringFromConfig(ConfigSection(), KLbsModuleType, modType);
       
   394 		if (modType != KLbsModuleType_Real)
       
   395 			{
       
   396 
       
   397 			TModuleDataIn modDataIn;
       
   398 
       
   399 			modDataIn.iRequestType = TModuleDataIn::EModuleRequestConfig;
       
   400 			modDataIn.iConfigFileName = configFileName;
       
   401 			modDataIn.iConfigSection = ConfigSection();
       
   402 
       
   403 			// Now publish the ini file and section name to the test module - will block.
       
   404 			utils.NotifyModuleOfConfigChangeL(modDataIn);
       
   405 			}
       
   406 		else
       
   407 			{
       
   408 			iTestModuleInUse = EFalse;	// Indicate to test harness the real A-GPS integration module is being used.
       
   409 			}
       
   410 }
       
   411 
       
   412 void CT_LbsClientStep_Concurrent::VerifyPosInfo()
       
   413 {
       
   414 	INFO_PRINTF1(_L("   VerifyPosInfo"));
       
   415 
       
   416 	T_LbsUtils utils;
       
   417 	TBool res;
       
   418 	// Verify arrays are equal.
       
   419 	if(iTestModuleInUse)
       
   420 		res = utils.Compare_PosInfoArr(iVerifyPosInfoArr, iCurrentPosInfoArr, T_LbsUtils::EExactAccuracy);
       
   421 	else
       
   422 		res = utils.Compare_PosInfoArr(iVerifyPosInfoArr, iCurrentPosInfoArr, T_LbsUtils::ERoughAccuracy);
       
   423 
       
   424 	// Fail test if arrays do not match.
       
   425 	if (!res)
       
   426     	{
       
   427     	INFO_PRINTF1(_L("   Positions didnt match"));
       
   428 		SetTestStepResult(EFail);
       
   429 	    }
       
   430 }
       
   431 
       
   432 void CT_LbsClientStep_Concurrent::Validate(TPositionInfo& aExpectedPosition, TPositionInfo& aActualPosition, 
       
   433 		TPositionAreaExtendedInfo& aActualArea, TBool aMccExpected, TBool aMncExpected, TBool aLacExpected, TBool aCidExpected)
       
   434 	{
       
   435 	TPositionAreaExtendedInfo expectedArea;
       
   436 	expectedArea.SetMobileCountryCodeMatch(aMccExpected);
       
   437 	expectedArea.SetMobileNetworkCodeMatch(aMncExpected);
       
   438 	expectedArea.SetLocationAreaCodeMatch(aLacExpected);
       
   439 	expectedArea.SetCellIdMatch(aCidExpected);	
       
   440 	VerifyMatchLevel(expectedArea, aActualArea);
       
   441 	
       
   442 	T_LbsUtils utils;
       
   443 	TBool equality = utils.Compare_PosInfo(aExpectedPosition, aActualPosition);
       
   444 	if(!equality)
       
   445 		{
       
   446 		ERR_PRINTF1(_L("Position does not match"));
       
   447 		SetTestStepResult(EFail);
       
   448 		}
       
   449 	}
       
   450 
       
   451 
       
   452 TInt CT_LbsClientStep_Concurrent::VerifyMatchLevel(TPositionAreaExtendedInfo& aExpected, TPositionAreaExtendedInfo& aActual)
       
   453 	{
       
   454 	TInt err = KErrNone;
       
   455 	if (!(aExpected.MobileCountryCodeMatch() == aActual.MobileCountryCodeMatch() &&
       
   456 			aExpected.MobileNetworkCodeMatch() == aActual.MobileNetworkCodeMatch() &&
       
   457 			aExpected.LocationAreaCodeMatch() == aActual.LocationAreaCodeMatch() &&
       
   458 			aExpected.CellIdMatch() == aActual.CellIdMatch()))
       
   459 		{
       
   460 		ERR_PRINTF1(_L("Incorrect Match level"));
       
   461 		ERR_PRINTF5(_L("Expected: MCC:%d, MNC:%d, LAC:%d, CID:%d"), 
       
   462 				aExpected.MobileCountryCodeMatch(), 
       
   463 				aExpected.MobileNetworkCodeMatch(),
       
   464 				aExpected.LocationAreaCodeMatch(),
       
   465 				aExpected.CellIdMatch());
       
   466 		ERR_PRINTF5(_L("Actual: MCC:%d, MNC:%d, LAC:%d, CID:%d"), 
       
   467 				aActual.MobileCountryCodeMatch(), 
       
   468 				aActual.MobileNetworkCodeMatch(),
       
   469 				aActual.LocationAreaCodeMatch(),
       
   470 				aActual.CellIdMatch());
       
   471 		SetTestStepResult(EFail);
       
   472 		err = KErrGeneral;
       
   473 		}
       
   474 	return err;
       
   475 	}
       
   476 
       
   477