lbstest/lbstestproduct/lbssimulationpsy/src/ctlbssimulationpsypostp400.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <lbs.h>
       
    20 #include <lbsposition.h>
       
    21 #include "ctlbssimulationpsypostp400.h"
       
    22 #include "simulationpsyinternalcrkeys.h"
       
    23 
       
    24 //Number of tests in this file, increment when a new test is added
       
    25 const TInt KNrOfTests = 6;
       
    26 const TInt K30seconds = 30000000;
       
    27 const TInt K10seconds = 10000000;
       
    28 const TInt K5seconds = 5000000;
       
    29 const TInt K0seconds = 0;
       
    30 // Value for Common Data Set to enable Time Relative Playback
       
    31 const TInt KTrpModeEnable= 1;
       
    32 
       
    33 _LIT(KName0, "TP400-0 - TrpMultiClientNmeaStoredFixExist");
       
    34 _LIT(KName1, "TP400-1 - TrpMultiClientNmeaStoredFixNotExist");
       
    35 _LIT(KName2, "TP400-2 - TrpMultiClientNmeaNoUpdateAge");
       
    36 _LIT(KName3, "TP400-3 - TrpMultiClientSpsStoredFixExist");
       
    37 _LIT(KName4, "TP400-4 - TrpMultiClientSpsStoredFixNotExist");
       
    38 _LIT(KName5, "TP400-5 - TrpMultiClientSpsNoUpdateAge");
       
    39 
       
    40 CT_LbsSimulationPsyPosTp400::CT_LbsSimulationPsyPosTp400(CT_LbsServer& aParent,
       
    41 		TInt aIndex) :
       
    42 	CT_LbsPortedStepBase(aParent)
       
    43 	{
       
    44 	SetTestStepName(GetIndexName(aIndex));
       
    45 	iIndex = aIndex;
       
    46 	}
       
    47 
       
    48 void CT_LbsSimulationPsyPosTp400::StartL()
       
    49 	{
       
    50 	// Setup test environment
       
    51 	iNrOfRequests = 0;
       
    52 	ConnectL();
       
    53 	SetupPsyL(iUidSimulationPsy);
       
    54 	RunTestsL(iIndex);
       
    55 	}
       
    56 
       
    57 TVerdict CT_LbsSimulationPsyPosTp400::doTestStepPostambleL()
       
    58 	{
       
    59 	SetTrpModeL(iOldTrpMode);
       
    60 	return CT_LbsPortedStepBase::doTestStepPostambleL();
       
    61 	}
       
    62 
       
    63 void CT_LbsSimulationPsyPosTp400::CloseTest()
       
    64 	{
       
    65 	Disconnect();
       
    66 	}
       
    67 
       
    68 /*
       
    69  * Gets the name of an individual test index
       
    70  * @param aIndex Indicates which test index name that is asked for.
       
    71  */
       
    72 TPtrC CT_LbsSimulationPsyPosTp400::GetIndexName(TInt aIndex) const
       
    73 	{
       
    74 	if (aIndex > KNrOfTests)
       
    75 		{
       
    76 		User::Panic(_L("Wrong Test Argument Index"), KErrGeneral);
       
    77 		}
       
    78 
       
    79 	const TDesC* names[KNrOfTests] =
       
    80 		{
       
    81 		&KName0, &KName1, &KName2, &KName3, &KName4, &KName5
       
    82 		};
       
    83 	return *names[aIndex];
       
    84 	}
       
    85 
       
    86 /*
       
    87  * Contains calls to tests itself. 
       
    88  * @param aIndex test number
       
    89  */
       
    90 void CT_LbsSimulationPsyPosTp400::RunTestsL(TInt aIndex)
       
    91 	{
       
    92 	_LIT(KStart0, "Testing TrpMultiClientNmeaStoredFixExist() PSY ");
       
    93 	_LIT(KStart1, "Testing TrpMultiClientNmeaStoredFixNotExist() PSY ");
       
    94 	_LIT(KStart2, "Testing TrpMultiClientNmeaNoUpdateAge() PSY ");
       
    95 	_LIT(KStart3, "Testing TrpMultiClientSpsStoredFixExist() PSY ");
       
    96 	_LIT(KStart4, "Testing TrpMultiClientSpsStoredFixNotExist() PSY ");
       
    97 	_LIT(KStart5, "Testing TrpMultiClientSpsNoUpdateAge() PSY ");
       
    98 	_LIT(KEnd0, "TrpMultiClientNmeaStoredFixExist() passed");
       
    99 	_LIT(KEnd1, "TrpMultiClientNmeaStoredFixNotExist() passed");
       
   100 	_LIT(KEnd2, "TrpMultiClientNmeaNoUpdateAge() passed");
       
   101 	_LIT(KEnd3, "TrpMultiClientSpsStoredFixExist() passed");
       
   102 	_LIT(KEnd4, "TrpMultiClientSpsStoredFixNotExist() passed");
       
   103 	_LIT(KEnd5, "TrpMultiClientSpsNoUpdateAge() passed");
       
   104 
       
   105 	switch (aIndex)
       
   106 		{
       
   107 		case 0:
       
   108 			INFO_PRINTF1(KStart0);
       
   109 			TestTrpMultiClientNmeaStoredFixExistL();
       
   110 			INFO_PRINTF1(KEnd0);
       
   111 			break;
       
   112 		case 1:
       
   113 			INFO_PRINTF1(KStart1);
       
   114 			TestTrpMultiClientNmeaStoredFixNotExistL();
       
   115 			INFO_PRINTF1(KEnd1);
       
   116 			break;
       
   117 		case 2:
       
   118 			INFO_PRINTF1(KStart2);
       
   119 			TestTrpMultiClientNmeaNoUpdateAgeL();
       
   120 			INFO_PRINTF1(KEnd2);
       
   121 			break;
       
   122 		case 3:
       
   123 			INFO_PRINTF1(KStart3);
       
   124 			TestTrpMultiClientSpsStoredFixExistL();
       
   125 			INFO_PRINTF1(KEnd3);
       
   126 			break;
       
   127 		case 4:
       
   128 			INFO_PRINTF1(KStart4);
       
   129 			TestTrpMultiClientSpsStoredFixNotExistL();
       
   130 			INFO_PRINTF1(KEnd4);
       
   131 			break;
       
   132 		case 5:
       
   133 			INFO_PRINTF1(KStart5);
       
   134 			TestTrpMultiClientSpsNoUpdateAgeL();
       
   135 			INFO_PRINTF1(KEnd5);
       
   136 			break;
       
   137 		default:
       
   138 			User::Leave(KErrArgument);
       
   139 		}
       
   140 	}
       
   141 
       
   142 void CT_LbsSimulationPsyPosTp400::TestTrpMultiClientNmeaStoredFixExistL()
       
   143 	{
       
   144 	_LIT(KTrpMultiClientRequestError, "Error, the fixes are different.");
       
   145 	
       
   146 	if (!TwoClientRequestL(EFalse, K0seconds, K30seconds))
       
   147 		{
       
   148 		LogErrorAndLeaveL(KTrpMultiClientRequestError);
       
   149 		}
       
   150 	
       
   151 	INFO_PRINTF1(_L("The fixes are identical."));
       
   152 	}
       
   153 
       
   154 void CT_LbsSimulationPsyPosTp400::TestTrpMultiClientNmeaStoredFixNotExistL()
       
   155 	{
       
   156 	_LIT(KTrpMultiClientRequestError, "Error, The fixes are identical.");
       
   157 	
       
   158 	if (TwoClientRequestL(EFalse, K10seconds, K5seconds))
       
   159 		{
       
   160 		LogErrorAndLeaveL(KTrpMultiClientRequestError);
       
   161 		}
       
   162 	
       
   163 	INFO_PRINTF1(_L("The fixes are different."));
       
   164 	}
       
   165 
       
   166 void CT_LbsSimulationPsyPosTp400::TestTrpMultiClientNmeaNoUpdateAgeL()
       
   167 	{
       
   168 	_LIT(KTrpMultiClientRequestError, "Error, The fixes are identical.");
       
   169 	
       
   170 	if (TwoClientRequestL(EFalse, K0seconds, K0seconds))
       
   171 		{
       
   172 		LogErrorAndLeaveL(KTrpMultiClientRequestError);
       
   173 		}
       
   174 	
       
   175 	INFO_PRINTF1(_L("The fixes are different."));
       
   176 	}
       
   177 
       
   178 void CT_LbsSimulationPsyPosTp400::TestTrpMultiClientSpsStoredFixExistL()
       
   179 	{
       
   180 	_LIT(KTrpMultiClientRequestError, "Error, the fixes are different.");
       
   181 	
       
   182 	if (!TwoClientRequestL(ETrue, K0seconds, K30seconds))
       
   183 		{
       
   184 		LogErrorAndLeaveL(KTrpMultiClientRequestError);
       
   185 		}
       
   186 	
       
   187 	INFO_PRINTF1(_L("The fixes are identical."));
       
   188 	}
       
   189 
       
   190 void CT_LbsSimulationPsyPosTp400::TestTrpMultiClientSpsStoredFixNotExistL()
       
   191 	{
       
   192 	_LIT(KTrpMultiClientRequestError, "Error, The fixes are identical.");
       
   193 	_LIT(KTrpMultiClientDirectionError, "Error, the position differences do not correspond to direction of movement.");
       
   194 
       
   195 	TReal latitudeDifference;
       
   196 	TReal longitudeDifference;
       
   197 
       
   198 	if (TwoClientRequestL(ETrue, K10seconds, K5seconds, &latitudeDifference,
       
   199 			&longitudeDifference))
       
   200 		{
       
   201 		LogErrorAndLeaveL(KTrpMultiClientRequestError);
       
   202 		}
       
   203 	//The latitude and longitude difference should be not as bellow 
       
   204 	//to correspond movement direction specified in SPS file.
       
   205 	if (latitudeDifference >= 0 || longitudeDifference <= 0)
       
   206 		{
       
   207 		LogErrorAndLeaveL(KTrpMultiClientDirectionError);
       
   208 		}
       
   209 	
       
   210 	INFO_PRINTF3(_L("The fixes are different and Client 2 is further than Client 1.: %d, %d"), longitudeDifference, latitudeDifference);
       
   211 	}
       
   212 
       
   213 void CT_LbsSimulationPsyPosTp400::TestTrpMultiClientSpsNoUpdateAgeL()
       
   214 	{
       
   215 	_LIT(KTrpMultiClientRequestError, "Error, The fixes are identical.");
       
   216 	_LIT(KTrpMultiClientDirectionError, "Error, the position differences doesn't correspond direction of movement.");
       
   217 
       
   218 	TReal latitudeDifference;
       
   219 	TReal longitudeDifference;
       
   220 
       
   221 	if (TwoClientRequestL(ETrue, K0seconds, K0seconds, &latitudeDifference,
       
   222 			&longitudeDifference))
       
   223 		{
       
   224 		LogErrorAndLeaveL(KTrpMultiClientRequestError);
       
   225 		}
       
   226 	//The latitude and longitude difference should be positive 
       
   227 	//to correspond movement direction specified in SPS file.
       
   228 	if (latitudeDifference >= 0 || longitudeDifference <= 0)
       
   229 		{
       
   230 		LogErrorAndLeaveL(KTrpMultiClientDirectionError);
       
   231 		}
       
   232 	
       
   233 	INFO_PRINTF3(_L("The fixes are different and Client 2 is further than Client 1.: %d/%d"), longitudeDifference, latitudeDifference);
       
   234 	}
       
   235 
       
   236 /*
       
   237  * Make two client sessions. First client request position and waits for time of aDelay. 
       
   238  * Next set Max Update Age of second client and issue position request of second client. 
       
   239  * If aLatitudeDiff and aLongitudeDiff parameters are set method will use them to
       
   240  * return calculated difference of client positions.
       
   241  * @param aIsSps set to ETrue if function should use SPS simulation mode, EFalse for NMEA simulation mode.
       
   242  * @param aSecondClientDelay is delay in milliseconds of second positioner request.
       
   243  * @param aMaxUpdateAge value in milliseconds that will be set to Max Update Age option of second positioner.
       
   244  * @param aLatitudeDiff this parameter will store difference of latitude between clients position.
       
   245  * @param aLongitudeDiff this parameter will store difference of longitude between clients position.
       
   246  * @return ETrue if clients positions are equal. Otherwise EFalse.
       
   247  */
       
   248 TBool CT_LbsSimulationPsyPosTp400::TwoClientRequestL(TBool aIsSps,
       
   249 		TInt aSecondClientDelay, TInt aMaxUpdateAge, TReal* aLatitudeDiff,
       
   250 		TReal* aLongitudeDiff)
       
   251 	{
       
   252 	_LIT(KErrorRequestingPosition, "Position Request Error.");
       
   253 	_LIT(KGetUpdateOptionsErr, "Error %d when getting update options.");
       
   254 	_LIT(KSetUpdateOptionsErr, "Error %d when setting Max Update Age option.");
       
   255 
       
   256 #ifdef __WINS__
       
   257 	_LIT(KTrpNmeaFile, "z:\\system\\test\\testdata\\trpnmeadatafile.nme");
       
   258 	_LIT(KTrpSpsFile, "z:\\system\\test\\testdata\\trpspsdatafile.sps");
       
   259 #else
       
   260 	_LIT(KTrpNmeaFile, "c:\\system\\test\\testdata\\trpnmeadatafile.nme");
       
   261 	_LIT(KTrpSpsFile, "c:\\system\\test\\testdata\\trpspsdatafile.sps");
       
   262 #endif
       
   263 	
       
   264 	iOldTrpMode = TrpModeL();
       
   265 	SetTrpModeL(KTrpModeEnable);
       
   266 	
       
   267 	//Creating client subsessions to position server.
       
   268 	RPositioner positioner1;
       
   269 	RPositioner positioner2;
       
   270 	if (aIsSps)
       
   271 		{
       
   272 		OpenNewSourceFileLC(KTrpSpsFile, positioner1);
       
   273 		OpenNewSourceFileLC(KTrpSpsFile, positioner2);
       
   274 		}
       
   275 	else
       
   276 		{
       
   277 		OpenNewSourceFileLC(KTrpNmeaFile, positioner1);
       
   278 		OpenNewSourceFileLC(KTrpNmeaFile, positioner2);
       
   279 		}
       
   280 	
       
   281 	//Seting Max Update Age option for second Positioner.
       
   282 	TPositionUpdateOptions posOption;
       
   283 	TInt err = positioner2.GetUpdateOptions(posOption);
       
   284 	AssertTrueL(err == KErrNone, KGetUpdateOptionsErr, err);
       
   285 
       
   286 	posOption.SetMaxUpdateAge(aMaxUpdateAge);
       
   287 	err = positioner2.SetUpdateOptions(posOption);
       
   288 	AssertTrueL(err == KErrNone, KSetUpdateOptionsErr, err);
       
   289 
       
   290 	TPositionInfo fix1;
       
   291 	TPositionInfo fix2;
       
   292 	
       
   293 	//Position request of First client.
       
   294 	err = PerformSyncRequest(fix1, positioner1);
       
   295 	AssertTrueL(err == KErrNone, KErrorRequestingPosition, err);
       
   296 	
       
   297 	//Delay of second positioner.
       
   298 	User::After(aSecondClientDelay);
       
   299 	
       
   300 	//Position request of Second client.
       
   301 	err = PerformSyncRequest(fix2, positioner2);
       
   302 	AssertTrueL(err == KErrNone, KErrorRequestingPosition, err);
       
   303 	
       
   304 	//Getting fixed positions.
       
   305 	TPosition pos1;
       
   306 	fix1.GetPosition(pos1);
       
   307 	TPosition pos2;
       
   308 	fix2.GetPosition(pos2);
       
   309 
       
   310 	//Closing positioners
       
   311 	CleanupStack::PopAndDestroy(&positioner2);
       
   312 	CleanupStack::PopAndDestroy(&positioner1);
       
   313 	
       
   314 	//Seting longitude and latitude difference.
       
   315 	if (aLatitudeDiff != NULL)
       
   316 		{
       
   317 		*aLatitudeDiff = pos2.Latitude() - pos1.Latitude();
       
   318 		}
       
   319 	if (aLongitudeDiff != NULL)
       
   320 		{
       
   321 		*aLongitudeDiff = pos2.Longitude() - pos1.Longitude();
       
   322 		}
       
   323 	
       
   324 	return pos1.Latitude() == pos2.Latitude() && pos1.Longitude() == pos2.Longitude();
       
   325 	}
       
   326 
       
   327 /*
       
   328  * Set new source file in central repository and open new RPositioner session.
       
   329  * Opened session will be left on cleanup stack. 
       
   330  * @param aName Name of file to set in central repository.
       
   331  * @param aPositioner reference to constructed but unopened RPositioner that will use data from this particular file.
       
   332  * 		This parameter will opened and the session will be left on cleanup stack.	
       
   333  */
       
   334 void CT_LbsSimulationPsyPosTp400::OpenNewSourceFileLC(const TDesC& aName,
       
   335 		RPositioner& aPositioner)
       
   336 	{
       
   337 	_LIT(KOpenPositionerErr, "Error when opening positioner,  %d");
       
   338 	_LIT(KSettingRequestorErr, "Error when setting requester,  %d");
       
   339 	TInt err = KErrNone;
       
   340 	SetSimDataFileL(aName);
       
   341 	err = aPositioner.Open(iPosServer, iUidSimulationPsy);
       
   342 	AssertTrueL(err == KErrNone, KOpenPositionerErr, err);
       
   343 	CleanupClosePushL(aPositioner);
       
   344 	_LIT(KService, "service");
       
   345 	err = aPositioner.SetRequestor(CRequestor::ERequestorService,
       
   346 			CRequestor::EFormatApplication, KService);
       
   347 	AssertTrueL(err == KErrNone, KSettingRequestorErr, err);
       
   348 	}
       
   349 
       
   350 /*
       
   351  * @return value of Common Data Set in Central Repository.
       
   352  */
       
   353 TInt CT_LbsSimulationPsyPosTp400::TrpModeL() const
       
   354 	{
       
   355 	// Get the Common Data Set setting from Central Repository
       
   356 	CRepository* repository = CRepository::NewLC(KCRUidSimulationPSY);
       
   357 	TInt commonDataSet = 0;
       
   358 	User::LeaveIfError(repository->Get(KCRKeySimPSYCommonDataSet, commonDataSet));
       
   359 	CleanupStack::PopAndDestroy(repository);
       
   360 	return commonDataSet;
       
   361 	}
       
   362 
       
   363 /*
       
   364  * This method sets Common Data Set in Central Repository.
       
   365  * @param aNewValue new value for Common Data Set.
       
   366  */
       
   367 void CT_LbsSimulationPsyPosTp400::SetTrpModeL(TInt aNewValue)
       
   368 	{
       
   369 	// Set Time Related Playback behaviour in the Central Repository.
       
   370 	CRepository* repository = CRepository::NewLC(KCRUidSimulationPSY);
       
   371 	User::LeaveIfError(repository->Set(KCRKeySimPSYCommonDataSet, aNewValue));
       
   372 	CleanupStack::PopAndDestroy(repository);
       
   373 	}
       
   374 
       
   375 /*
       
   376  * Perform a synchronous position request and return error code.
       
   377  * @param aModuleInfo position information is returned in this object.
       
   378  * @param aPositioner reference to RPositioner that will be used to obtain position request.
       
   379  * @return Symbian system error code.
       
   380  */
       
   381 TInt CT_LbsSimulationPsyPosTp400::PerformSyncRequest(TPositionInfoBase& aModuleInfo, const RPositioner& aPositioner) const
       
   382 	{
       
   383 	TRequestStatus status = KRequestPending;
       
   384 	aPositioner.NotifyPositionUpdate(aModuleInfo, status);
       
   385 	User::WaitForRequest(status);
       
   386 	return status.Int();
       
   387 	}
       
   388