lbstest/lbstestproduct/lbsclient/src/ctlbsclientsteplastknownposareasources.cpp
changeset 0 9cfd9a3ee49c
child 18 54d74d217042
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 /*
       
     2 * Copyright (c) 2006-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 * @file ctlbsclientsteplastknownposareasources.cpp
       
    16 * This is the class implementation for the Last Known Position Area Data Sources Tests
       
    17 *
       
    18 */
       
    19 
       
    20  
       
    21 #include "ctlbsclientsteplastknownposareasources.h"
       
    22 
       
    23 #include <lbs.h>
       
    24 #include <lbssatellite.h>
       
    25 
       
    26 #include <lbs/test/tlbsutils.h>
       
    27 #include <lbs/test/ctlbsasyncwaiter.h>
       
    28 
       
    29 #include <etel3rdparty.h>
       
    30 #include <simtsy.h>
       
    31 
       
    32 
       
    33 // constant definitions
       
    34 _LIT(KLbsClientStepLastKnownPosAreaSources, "LbsClientStepLastKnownPosAreaSources");
       
    35 const TInt KSimTsyTransitionDelay = 4000000; // Currently it seems to take the SimTsy 3 seconds to change cell
       
    36 
       
    37 
       
    38 /**
       
    39  * Destructor
       
    40  */
       
    41 CT_LbsClientStep_LastKnownPosAreaSources::~CT_LbsClientStep_LastKnownPosAreaSources()
       
    42 	{
       
    43 	}
       
    44 
       
    45 
       
    46 /**
       
    47  * Constructor
       
    48  */
       
    49 CT_LbsClientStep_LastKnownPosAreaSources::CT_LbsClientStep_LastKnownPosAreaSources(CT_LbsClientServer& aParent) : CT_LbsClientStep(aParent)
       
    50 	{
       
    51 	SetTestStepName(KLbsClientStep_LastKnownPosAreaSources);
       
    52 	}
       
    53 
       
    54 
       
    55 /**
       
    56 Static Constructor
       
    57 */
       
    58 CT_LbsClientStep_LastKnownPosAreaSources* CT_LbsClientStep_LastKnownPosAreaSources::New(CT_LbsClientServer& aParent)
       
    59 	{
       
    60 	// Note the lack of ELeave.
       
    61 	// This means that having insufficient memory will return NULL;
       
    62 	CT_LbsClientStep_LastKnownPosAreaSources* testStep = new CT_LbsClientStep_LastKnownPosAreaSources(aParent);
       
    63 	if (testStep)
       
    64 		{
       
    65 		TInt err = KErrNone;
       
    66 		TRAP(err, testStep->ConstructL());
       
    67 		if (err)
       
    68 			{
       
    69 			delete testStep;
       
    70 			testStep = NULL;
       
    71 			}
       
    72 		}
       
    73 	return testStep;
       
    74 	}
       
    75 
       
    76 
       
    77 void CT_LbsClientStep_LastKnownPosAreaSources::ConstructL()
       
    78 	{
       
    79 	}
       
    80 
       
    81 //from MT_NotifyPosUpdateObserver:
       
    82 /**
       
    83  * 	Callback - called when NotifyPositionUpdate request completes
       
    84  */
       
    85 
       
    86 void CT_LbsClientStep_LastKnownPosAreaSources::NotifyPositionUpdateCallback(TRequestStatus& aStatus)
       
    87 	{
       
    88 	TInt err = aStatus.Int();
       
    89 	if (KErrCancel != err)	
       
    90 		{
       
    91 		SetTestStepResult(EFail); // the request always gets cancelled (see test 0122)
       
    92 		}
       
    93 	CActiveScheduler::Stop();
       
    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_LastKnownPosAreaSources::doTestStepL()
       
   103 	{
       
   104 	// Test step used to test the LBS Client Notify Position Area update API.
       
   105 	INFO_PRINTF1(_L("&gt;&gt;CT_LbsClientStep_LastKnownPosAreaSources::doTestStepL()"));
       
   106 
       
   107 	if (TestStepResult()==EPass)
       
   108 		{
       
   109 		// Connect to self locate server.	
       
   110 		TInt err = iServer.Connect();
       
   111 		User::LeaveIfError(err);
       
   112 		CleanupClosePushL(iServer);
       
   113 		//RPointerArray<TAny>& posInfoArr = iParent.iSharedData->iCurrentPosInfoArr;
       
   114 		T_LbsUtils utils;
       
   115 		//utils.ResetAndDestroy_PosInfoArr(posInfoArr);
       
   116 		//TPositionModuleId modId;
       
   117 		//modId = utils.GetAGpsModuleIdL(iServer);
       
   118 		
       
   119 		
       
   120 		// Carry out actions.
       
   121 		TInt testCaseId;
       
   122 		if (GetIntFromConfig(ConfigSection(), KTestCaseId, testCaseId))
       
   123 			{
       
   124 			switch (testCaseId)
       
   125 				{
       
   126 				// Only Clear the database
       
   127 				case 1001:
       
   128 					{
       
   129 					TRequestStatus emptyStatus;
       
   130 					iServer.EmptyLastKnownPositionStore(emptyStatus);
       
   131 					User::WaitForRequest(emptyStatus);
       
   132 					break;
       
   133 					}
       
   134 				// Verify Position and match level
       
   135 				case 1:
       
   136 				case 2:
       
   137 				case 3:
       
   138 				case 4:
       
   139 				case 5:
       
   140 					{
       
   141 					User::LeaveIfError(iPositioner.Open(iServer));
       
   142 					CleanupClosePushL(iPositioner);
       
   143 					//1. LastKnown Pos Area
       
   144 					TPositionInfo posInfo;
       
   145 					TPositionAreaExtendedInfo matchLevel, expectedMatchLevel;
       
   146 					err = DoLastKnownPosAreaL(posInfo, matchLevel);
       
   147 					if (KErrNone != err)
       
   148 						{
       
   149 						ERR_PRINTF2(_L("Incorrect err %d returned"), err);
       
   150 						SetTestStepResult(EFail);
       
   151 						}
       
   152 					expectedMatchLevel.SetMobileCountryCodeMatch(ETrue);
       
   153 					expectedMatchLevel.SetMobileNetworkCodeMatch(ETrue);
       
   154 					expectedMatchLevel.SetLocationAreaCodeMatch(ETrue);
       
   155 					expectedMatchLevel.SetCellIdMatch(ETrue);
       
   156 					VerifyMatchLevel(expectedMatchLevel, matchLevel);
       
   157 					TPosition lhsPos;
       
   158 					// MOLR TA
       
   159 					if(testCaseId == 1)
       
   160 						{
       
   161 						lhsPos.SetAccuracy(10.0,10.0);
       
   162 						lhsPos.SetCoordinate(50.2454,0.1668,1.0);	
       
   163 						}
       
   164 					// Cell
       
   165 					else if(testCaseId == 3)
       
   166 						{
       
   167 						lhsPos.SetAccuracy(2.0,3.0);
       
   168 						lhsPos.SetCoordinate(49.2,3.5,50.0);	
       
   169 						}
       
   170 					// BT
       
   171 					else if(testCaseId == 5)
       
   172 						{
       
   173 						lhsPos.SetAccuracy(10.0,30.0);
       
   174 						lhsPos.SetCoordinate(61.448,23.855,0.0);	
       
   175 						}
       
   176 					TPositionInfo lhsPosInfo;
       
   177 					lhsPosInfo.SetPosition(lhsPos);
       
   178 					if(!utils.Compare_PosInfo(lhsPosInfo, posInfo, T_LbsUtils::ERoughAccuracy))
       
   179 						{
       
   180 						ERR_PRINTF1(_L("Unexpected position returned"));
       
   181 						SetTestStepResult(EFail);
       
   182 						}
       
   183 					//2. Clear Database
       
   184 					TRequestStatus emptyStatus;
       
   185 					iServer.EmptyLastKnownPositionStore(emptyStatus);
       
   186 					User::WaitForRequest(emptyStatus);
       
   187 					CleanupStack::PopAndDestroy(&iPositioner);
       
   188 					break;
       
   189 					}
       
   190 				default:
       
   191 					User::Panic(KLbsClientStepLastKnownPosAreaSources, KErrUnknown);					
       
   192     		    }
       
   193 			}
       
   194 		// All done, clean up.
       
   195 		
       
   196 		CleanupStack::PopAndDestroy(&iServer);		
       
   197 		}
       
   198 	INFO_PRINTF1(_L("&lt;&lt;CT_LbsClientStep_LastKnownPosAreaSources::doTestStepL()"));
       
   199 	return TestStepResult();
       
   200 	}
       
   201 
       
   202 
       
   203 void CT_LbsClientStep_LastKnownPosAreaSources::Validate(TPositionInfo& aExpectedPosition, TPositionInfo& aActualPosition, 
       
   204 		TPositionAreaExtendedInfo& aActualArea, TBool aMccExpected, TBool aMncExpected, TBool aLacExpected, TBool aCidExpected)
       
   205 	{
       
   206 	TPositionAreaExtendedInfo expectedArea;
       
   207 	expectedArea.SetMobileCountryCodeMatch(aMccExpected);
       
   208 	expectedArea.SetMobileNetworkCodeMatch(aMncExpected);
       
   209 	expectedArea.SetLocationAreaCodeMatch(aLacExpected);
       
   210 	expectedArea.SetCellIdMatch(aCidExpected);	
       
   211 	VerifyMatchLevel(expectedArea, aActualArea);
       
   212 	
       
   213 	T_LbsUtils utils;
       
   214 	TBool equality = utils.Compare_PosInfo(aExpectedPosition, aActualPosition);
       
   215 	if(!equality)
       
   216 		{
       
   217 		ERR_PRINTF1(_L("Position does not match"));
       
   218 		SetTestStepResult(EFail);
       
   219 		}
       
   220 	}
       
   221 
       
   222 
       
   223 TInt CT_LbsClientStep_LastKnownPosAreaSources::VerifyMatchLevel(TPositionAreaExtendedInfo& aExpected, TPositionAreaExtendedInfo& aActual)
       
   224 	{
       
   225 	TInt err = KErrNone;
       
   226 	if (!(aExpected.MobileCountryCodeMatch() == aActual.MobileCountryCodeMatch() &&
       
   227 			aExpected.MobileNetworkCodeMatch() == aActual.MobileNetworkCodeMatch() &&
       
   228 			aExpected.LocationAreaCodeMatch() == aActual.LocationAreaCodeMatch() &&
       
   229 			aExpected.CellIdMatch() == aActual.CellIdMatch()))
       
   230 		{
       
   231 		ERR_PRINTF1(_L("Incorrect Match level"));
       
   232 		ERR_PRINTF5(_L("Expected: MCC:%d, MNC:%d, LAC:%d, CID:%d"), 
       
   233 				aExpected.MobileCountryCodeMatch(), 
       
   234 				aExpected.MobileNetworkCodeMatch(),
       
   235 				aExpected.LocationAreaCodeMatch(),
       
   236 				aExpected.CellIdMatch());
       
   237 		ERR_PRINTF5(_L("Actual: MCC:%d, MNC:%d, LAC:%d, CID:%d"), 
       
   238 				aActual.MobileCountryCodeMatch(), 
       
   239 				aActual.MobileNetworkCodeMatch(),
       
   240 				aActual.LocationAreaCodeMatch(),
       
   241 				aActual.CellIdMatch());
       
   242 		SetTestStepResult(EFail);
       
   243 		err = KErrGeneral;
       
   244 		}
       
   245 	return err;
       
   246 	}
       
   247 
       
   248 TInt CT_LbsClientStep_LastKnownPosAreaSources::DoLastKnownPosAreaL(TPositionInfoBase& aPosInfo, TPositionAreaExtendedInfo& aMatchLevel)
       
   249 {
       
   250 	// Use wrapper active object for the async call below.
       
   251 	CT_LbsAsyncWaiter*	waiter = CT_LbsAsyncWaiter::NewL();
       
   252 	CleanupStack::PushL(waiter);
       
   253 	User::LeaveIfError(iPositioner.SetRequestor(CRequestor::ERequestorService,
       
   254 												CRequestor::EFormatApplication,
       
   255 												_L("LbsClient LKPA Tests")));
       
   256 	iPositioner.GetLastKnownPositionArea(aPosInfo, aMatchLevel, waiter->iStatus);
       
   257 	// Wait for and process the result.
       
   258 	waiter->StartAndWait();
       
   259 	TInt err = waiter->Result();
       
   260 	if (KErrNone == err)
       
   261 		{
       
   262 		INFO_PRINTF1(_L("Last Known Pos Area position obtained successfully"));
       
   263 		}
       
   264 	else
       
   265 		{
       
   266 		INFO_PRINTF2(_L("Position update failed with error %d"), err);
       
   267 		}
       
   268 	CleanupStack::PopAndDestroy(waiter);
       
   269 	return err;
       
   270 }