lbstest/lbstestproduct/lbssimulationpsy/src/ctlbssimulationpsypostp254.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 // Copyright (c) 2001-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 //
       
    15 
       
    16 
       
    17 
       
    18 //  INCLUDES
       
    19 #include "ctlbssimulationpsypostp254.h"
       
    20 #include "ctlbssimulationpsypostp242constants.h"
       
    21 
       
    22 // CONSTANTS
       
    23 _LIT(KServiceName, "TP254");
       
    24 
       
    25 #ifdef __WINS__
       
    26     _LIT(KNmeaFile,         "z:\\system\\test\\testdata\\tp242.nme");           // Full fix
       
    27     _LIT(KPartialNmeaFile,  "z:\\system\\test\\testdata\\TP254Partial.nme");    // Missing longitude
       
    28     _LIT(KPartialNmeaFile2, "z:\\system\\test\\testdata\\TP254Partial2.nme");   // Missing latitude
       
    29     _LIT(KPartialNmeaFile3, "z:\\system\\test\\testdata\\TP254Partial3.nme");   // Full fix
       
    30     _LIT(KPartialNmeaFile4, "z:\\system\\test\\testdata\\TP254Partial4.nme");   // Missing longitude and latitude 
       
    31     _LIT(KPartialNmeaFile5, "z:\\system\\test\\testdata\\TP254Partial5.nme");   // Missing longitude, latitude 
       
    32     // Contains 8 locations fixes: 
       
    33     // 1-full, 2-partial, 3-full, 4-partial, 5-partial(missing GGA), 6-full, 7-partial(missing GGA), 8-full 
       
    34     _LIT(KPartialNmeaFile6, "z:\\system\\test\\testdata\\TP254Partial6.nme");   
       
    35     
       
    36 #else
       
    37     _LIT(KNmeaFile,         "c:\\system\\test\\testdata\\tp242.nme");           
       
    38     _LIT(KPartialNmeaFile,  "c:\\system\\test\\testdata\\TP254Partial.nme");    
       
    39     _LIT(KPartialNmeaFile2, "c:\\system\\test\\testdata\\TP254Partial2.nme");   
       
    40     _LIT(KPartialNmeaFile3, "c:\\system\\test\\testdata\\TP254Partial3.nme");   
       
    41     _LIT(KPartialNmeaFile4, "c:\\system\\test\\testdata\\TP254Partial4.nme");   
       
    42     _LIT(KPartialNmeaFile5, "c:\\system\\test\\testdata\\TP254Partial5.nme");
       
    43     _LIT(KPartialNmeaFile6, "c:\\system\\test\\testdata\\TP254Partial6.nme");
       
    44     
       
    45 #endif
       
    46 
       
    47 const TInt KTimeOut = 3000000;
       
    48 
       
    49 // ================= MEMBER FUNCTIONS =======================
       
    50 
       
    51 // ---------------------------------------------------------
       
    52 // Constructor.
       
    53 // ---------------------------------------------------------
       
    54 CT_LbsSimulationPSYPosTp254::CT_LbsSimulationPSYPosTp254(CT_LbsServer& aParent): CT_LbsPortedStepBase(aParent)
       
    55 	{
       
    56 	_LIT(KTestName, "TP254 - Partial update");
       
    57 	SetTestStepName(KTestName);
       
    58 	}
       
    59 
       
    60 // ---------------------------------------------------------
       
    61 // Destructor.
       
    62 // ---------------------------------------------------------
       
    63 CT_LbsSimulationPSYPosTp254::~CT_LbsSimulationPSYPosTp254()
       
    64 	{
       
    65 	}
       
    66 
       
    67 // ---------------------------------------------------------
       
    68 // CT_LbsSimulationPSYPosTp254::StartL
       
    69 //
       
    70 // (other items were commented in a header).
       
    71 // ---------------------------------------------------------
       
    72 //
       
    73 void CT_LbsSimulationPSYPosTp254::StartL()
       
    74     {    	
       
    75 	_LIT(KConnectErr, "Error when connecting to Position Server,  %d");
       
    76     _LIT(KNotifyErr, "NotifyPositionUpdate returns err %d when expected KErrNone");
       
    77     _LIT(KPartialErr, "NotifyPositionUpdate returns err %d when expected KPositionPartialUpdate");
       
    78     _LIT(KTimedOutErr, "NotifyPositionUpdate returns err %d when expected KErrTimedOut");   
       
    79     
       
    80     TInt err = iPosServer.Connect();
       
    81 	AssertTrueL(err == KErrNone, KConnectErr, err); 
       
    82 
       
    83     SetupPsyL(iUidSimulationPsy);
       
    84     TPositionInfo posInfo;
       
    85     
       
    86     
       
    87     SetFileInUseL(KPartialNmeaFile, EFalse);
       
    88     SetUpdateTimeOutL(KTimeOut);
       
    89     
       
    90     err = Request(posInfo);
       
    91     AssertTrueL(err == KErrTimedOut, KTimedOutErr, err); // Since partial not accepted
       
    92     
       
    93     SetFileInUseL(KNmeaFile);
       
    94     posInfo = TPositionInfo();
       
    95     err = Request(posInfo);
       
    96     AssertTrueL(err == KErrNone, KNotifyErr, err);    
       
    97     CheckTPositionInfoL(posInfo, ENone);
       
    98     
       
    99     SetFileInUseL(KPartialNmeaFile);
       
   100     posInfo = TPositionInfo();
       
   101     err = Request(posInfo);
       
   102     AssertTrueL(err == KPositionPartialUpdate, KPartialErr, err);
       
   103     CheckTPositionInfoL(posInfo, ELongitude);
       
   104     
       
   105     SetFileInUseL(KPartialNmeaFile2);
       
   106     posInfo = TPositionInfo();
       
   107     err = Request(posInfo);
       
   108     AssertTrueL(err == KPositionPartialUpdate, KPartialErr, err);
       
   109     CheckTPositionInfoL(posInfo, ELatitude);
       
   110     
       
   111     SetFileInUseL(KPartialNmeaFile3);
       
   112     posInfo = TPositionInfo();
       
   113     err = Request(posInfo);
       
   114     AssertTrueL(err == KErrNone, KNotifyErr, err);
       
   115     CheckTPositionInfoL(posInfo, ENone);
       
   116     
       
   117     SetFileInUseL(KPartialNmeaFile4);
       
   118     posInfo = TPositionInfo();
       
   119     err = Request(posInfo);
       
   120     AssertTrueL(err == KPositionPartialUpdate, KPartialErr, err);
       
   121     CheckTPositionInfoL(posInfo, ELongitude | ELatitude | ETimeStamp);
       
   122     
       
   123     SetFileInUseL(KPartialNmeaFile5);
       
   124     posInfo = TPositionInfo();
       
   125     err = Request(posInfo);
       
   126     AssertTrueL(err == KPositionPartialUpdate, KPartialErr, err);
       
   127     CheckTPositionInfoL(posInfo, ELongitude | ELatitude | ETimeStamp);
       
   128     
       
   129     SetFileInUseL(KPartialNmeaFile6);
       
   130     SetUpdateTimeOutL(KTimeOut);
       
   131     posInfo = TPositionInfo();
       
   132     
       
   133     // 1
       
   134     err = Request(posInfo);
       
   135     AssertTrueL(err == KErrNone, KNotifyErr, err);
       
   136     CheckTPositionInfoL(posInfo, ENone);
       
   137     
       
   138     // 2
       
   139     err = Request(posInfo);
       
   140     AssertTrueL(err == KPositionPartialUpdate, KPartialErr, err);
       
   141     CheckTPositionInfoL(posInfo, ELongitude);
       
   142     
       
   143     // 3
       
   144     err = Request(posInfo);
       
   145     AssertTrueL(err == KErrNone, KNotifyErr, err);
       
   146     CheckTPositionInfoL(posInfo, ENone);
       
   147     
       
   148     // 4
       
   149     err = Request(posInfo);
       
   150     AssertTrueL(err == KPositionPartialUpdate, KPartialErr, err);
       
   151     CheckTPositionInfoL(posInfo, ELatitude);
       
   152      
       
   153     // 5
       
   154     err = Request(posInfo);
       
   155     AssertTrueL(err == KPositionPartialUpdate, KPartialErr, err);
       
   156     CheckTPositionInfoL(posInfo, ELatitude | ELongitude | ETimeStamp | EAltitude);
       
   157     
       
   158     // 6
       
   159     err = Request(posInfo);
       
   160     AssertTrueL(err == KErrNone, KNotifyErr, err);
       
   161     CheckTPositionInfoL(posInfo, ENone);
       
   162     
       
   163     // 7
       
   164     err = Request(posInfo);
       
   165     AssertTrueL(err == KPositionPartialUpdate, KPartialErr, err);
       
   166     CheckTPositionInfoL(posInfo, ELatitude | ELongitude | ETimeStamp | EAltitude);
       
   167     
       
   168     // 8
       
   169     err = Request(posInfo);
       
   170     AssertTrueL(err == KErrNone, KNotifyErr, err);
       
   171     CheckTPositionInfoL(posInfo, ENone);
       
   172      
       
   173     // 9 The NMEA file is parsed from the beginning 
       
   174     SetPartialUpdateL(EFalse);
       
   175     
       
   176     err = Request(posInfo);
       
   177     AssertTrueL(err == KErrNone, KNotifyErr, err);
       
   178     CheckTPositionInfoL(posInfo, ENone);
       
   179 
       
   180     // 10 - skipped by PSY since partial and partial not allowed
       
   181     // 11
       
   182     err = Request(posInfo);
       
   183     AssertTrueL(err == KErrNone,KNotifyErr, err); // Since partial not accepted
       
   184     CheckTPositionInfoL(posInfo, ENone);
       
   185         
       
   186     // 12
       
   187     SetPartialUpdateL(ETrue);
       
   188     err = Request(posInfo);
       
   189     AssertTrueL(err == KPositionPartialUpdate, KPartialErr, err);
       
   190     CheckTPositionInfoL(posInfo, ELatitude);
       
   191 
       
   192     // 13
       
   193     err = Request(posInfo);
       
   194     AssertTrueL(err == KPositionPartialUpdate, KPartialErr, err);
       
   195     CheckTPositionInfoL(posInfo, ELatitude | ELongitude | ETimeStamp | EAltitude);
       
   196 
       
   197     }
       
   198 
       
   199 // ---------------------------------------------------------
       
   200 // CT_LbsSimulationPSYPosTp254::CloseTest()
       
   201 //
       
   202 // (other items were commented in a header).
       
   203 // ---------------------------------------------------------
       
   204 //
       
   205 void CT_LbsSimulationPSYPosTp254::CloseTest()
       
   206 	{
       
   207     iPositioner.Close();
       
   208 	iPosServer.Close();
       
   209 	}
       
   210 
       
   211 // ---------------------------------------------------------
       
   212 // CT_LbsSimulationPSYPosTp254::RequestL()
       
   213 // 
       
   214 // (other items were commented in a header).
       
   215 // ---------------------------------------------------------
       
   216 //
       
   217 TInt CT_LbsSimulationPSYPosTp254::Request(TPositionInfoBase& aPositionInfo)
       
   218 	{
       
   219 	_LIT(KFunctionName, "We are inside Request()");
       
   220 	INFO_PRINTF1(KFunctionName);
       
   221     iPositioner.NotifyPositionUpdate(aPositionInfo, iStatus);
       
   222     User::WaitForRequest(iStatus);
       
   223     
       
   224     return iStatus.Int();
       
   225     }
       
   226     
       
   227 // ---------------------------------------------------------
       
   228 // CT_LbsSimulationPSYPosTp254::CheckTPositionInfo()
       
   229 //
       
   230 // (other items were commented in a header).
       
   231 // ---------------------------------------------------------
       
   232 //
       
   233 void CT_LbsSimulationPSYPosTp254::CheckTPositionInfoL(const TPositionInfo& aPosInfo, TMissingPositionData aMissingData)
       
   234     {
       
   235     _LIT(KLongitudeErr, "Longitude is incorrect in TPositionInfo");
       
   236     _LIT(KLatitudeErr, "Latitude is incorrect in TPositionInfo");
       
   237     _LIT(KHorizontalErr, "Horizontal Accuracy is incorrect in TPositionInfo");
       
   238     _LIT(KVerticalErr, "Vertical Accuracy is incorrect in TPositionInfo");
       
   239     _LIT(KAltitudeErr, "Altitude is incorrect in TPositionInfo");
       
   240     _LIT(KTimeErr, "Time is incorrect in TPositionInfo");
       
   241 
       
   242     TPosition pos;
       
   243 	aPosInfo.GetPosition(pos);
       
   244 	TBool fullFix = ETrue;
       
   245 
       
   246     if (aMissingData & ELongitude)
       
   247         {
       
   248         AssertTrueL(Math::IsNaN(pos.Longitude()), KLongitudeErr, KErrGeneral);
       
   249         fullFix = EFalse;
       
   250         }
       
   251     else
       
   252         {
       
   253         AssertTrueL(pos.Longitude() == KLongitude, KLongitudeErr, KErrGeneral);
       
   254         }
       
   255     if (aMissingData & ELatitude)
       
   256         {
       
   257         AssertTrueL(Math::IsNaN(pos.Latitude()), KLatitudeErr, KErrGeneral);
       
   258         fullFix = EFalse;
       
   259         }
       
   260     else
       
   261         {
       
   262         AssertTrueL(pos.Latitude() == KLatitude, KLatitudeErr, KErrGeneral);
       
   263         }
       
   264     if (aMissingData & ETimeStamp)
       
   265         {
       
   266         AssertTrueL(pos.Time().Int64() == 0, KTimeErr, KErrGeneral); 
       
   267         fullFix = EFalse;
       
   268         }
       
   269 
       
   270 	if (aMissingData & EAltitude)
       
   271         {
       
   272         AssertTrueL(Math::IsNaN(pos.Altitude()), KAltitudeErr, KErrGeneral);
       
   273         _LIT(KIsNaN, "Altitude IsNaN");
       
   274         INFO_PRINTF1(KIsNaN);
       
   275         fullFix = EFalse;
       
   276         }
       
   277     else
       
   278         {
       
   279         AssertTrueL(pos.Altitude() == KAltitude, KAltitudeErr, KErrGeneral);
       
   280         }
       
   281         	    
       
   282     AssertTrueL(pos.HorizontalAccuracy() == KHorizontalAcc, KHorizontalErr, KErrGeneral);
       
   283     AssertTrueL(pos.VerticalAccuracy() == KVerticalAcc, KVerticalErr, KErrGeneral);
       
   284     
       
   285    	if (fullFix) 
       
   286    		{
       
   287    		_LIT(KFullFix, "Read fullFix");
       
   288    		INFO_PRINTF1(KFullFix);
       
   289    		}
       
   290 	else 
       
   291 		{
       
   292 		_LIT(KPartialUpdate, "Read partial update");
       
   293 		INFO_PRINTF1(KPartialUpdate);
       
   294 		}
       
   295     
       
   296     }
       
   297 
       
   298 // ---------------------------------------------------------
       
   299 // CT_LbsSimulationPSYPosTp254::SetFileInUse()
       
   300 // 
       
   301 // (other items were commented in a header).
       
   302 // ---------------------------------------------------------
       
   303 //
       
   304 void CT_LbsSimulationPSYPosTp254::SetFileInUseL(const TDesC& aFileName, TBool aPartial)
       
   305     {
       
   306     _LIT(KOpenErr, "Error when opening positioner,  %d");
       
   307     _LIT(KSetUpdateOptionsErr, "Error %d when setting update options");
       
   308     
       
   309     iPositioner.Close();
       
   310     SetSimDataFileL(aFileName); 
       
   311 
       
   312     TInt err;
       
   313     err = iPositioner.Open(iPosServer, iUidSimulationPsy);
       
   314     AssertTrueL(err == KErrNone, KOpenErr, err);
       
   315     
       
   316     iPositioner.SetRequestor(CRequestor::ERequestorService,
       
   317 							CRequestor::EFormatApplication, KServiceName);
       
   318 
       
   319     TPositionUpdateOptions posOption;
       
   320 	posOption.SetAcceptPartialUpdates(aPartial);
       
   321 	        
       
   322 	err = iPositioner.SetUpdateOptions(posOption);    
       
   323     AssertTrueL(err == KErrNone, KSetUpdateOptionsErr, err);
       
   324     
       
   325     }
       
   326 
       
   327 // ---------------------------------------------------------
       
   328 // CT_LbsSimulationPSYPosTp254::SetPartialUpdateL()
       
   329 // 
       
   330 // (other items were commented in a header).
       
   331 // ---------------------------------------------------------
       
   332 //
       
   333 void CT_LbsSimulationPSYPosTp254::SetPartialUpdateL(TBool aPartial)
       
   334     {
       
   335     _LIT(KSetUpdateOptionsErr, "Error %d when setting update options");
       
   336 
       
   337     TPositionUpdateOptions posOption;
       
   338     iPositioner.GetUpdateOptions(posOption);
       
   339 
       
   340 	posOption.SetAcceptPartialUpdates(aPartial);
       
   341 	        
       
   342 	TInt err = iPositioner.SetUpdateOptions(posOption);    
       
   343     AssertTrueL(err == KErrNone, KSetUpdateOptionsErr, err);
       
   344     }
       
   345 
       
   346 // ---------------------------------------------------------
       
   347 // CT_LbsSimulationPSYPosTp254::SetUpdateTimeOutL()
       
   348 // 
       
   349 // (other items were commented in a header).
       
   350 // ---------------------------------------------------------
       
   351 //
       
   352 void CT_LbsSimulationPSYPosTp254::SetUpdateTimeOutL(const TInt& aInterval)
       
   353     {
       
   354     _LIT(KSetUpdateOptionsErr, "Error %d when setting update options");
       
   355 
       
   356     TPositionUpdateOptions posOption;
       
   357     iPositioner.GetUpdateOptions(posOption);
       
   358     
       
   359 	posOption.SetUpdateTimeOut(TTimeIntervalMicroSeconds(aInterval));
       
   360 	        
       
   361 	TInt err = iPositioner.SetUpdateOptions(posOption);    
       
   362     AssertTrueL(err == KErrNone, KSetUpdateOptionsErr, err);
       
   363     }
       
   364     
       
   365 // ---------------------------------------------------------
       
   366 // TNmeaSentenceParser::PrintChecksum
       
   367 //
       
   368 // (other items were commented in a header).
       
   369 // ---------------------------------------------------------
       
   370 //
       
   371 void CT_LbsSimulationPSYPosTp254::PrintChecksum(const TDesC8& aSentence)
       
   372     {
       
   373     TUint8 checksum = 0;
       
   374     
       
   375     TInt i;
       
   376     for (i = 1; i < aSentence.Length() && aSentence[i] != '*'; i++)
       
   377         {
       
   378         checksum ^= aSentence[i];
       
   379         }
       
   380 
       
   381     TUint8 lsb = (TUint8)(checksum & 0x0f);
       
   382     TUint8 msb = (TUint8)(checksum >> 4); 
       
   383    
       
   384     _LIT(KStatus, "Checksum field  = %x%x");
       
   385     TBuf<32> info;
       
   386     info.Format(KStatus, msb, lsb);
       
   387 	RDebug::Print(info);
       
   388     }
       
   389 
       
   390 //  End of File