lbstest/lbstestproduct/lbscalculation/src/ctlbscalculationtp236.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 "ctlbscalculationtp236.h"
       
    20 #include "tlbscalculationcheck.h"
       
    21 
       
    22 // C++ constructor 
       
    23 CT_LbsCalculationTP236::CT_LbsCalculationTP236(CT_LbsCalculationServer& aParent) : CT_LbsCalculationStepBase(aParent)
       
    24     {
       
    25     _LIT(KTestName, "Calculation TP236 - Coordinate Move");
       
    26     SetTestStepName(KTestName);
       
    27     }
       
    28 
       
    29 CT_LbsCalculationTP236::~CT_LbsCalculationTP236()
       
    30     {
       
    31     }
       
    32 
       
    33 CT_LbsCalculationTP236* CT_LbsCalculationTP236::New(CT_LbsCalculationServer& aParent)
       
    34     {
       
    35     CT_LbsCalculationTP236* testStep = new CT_LbsCalculationTP236(aParent);
       
    36     // Note the lack of ELeave.
       
    37     // This means that having insufficient memory will return NULL;
       
    38 
       
    39     if (testStep)
       
    40         {
       
    41         TInt err = KErrNone;
       
    42 
       
    43         TRAP(err, testStep->ConstructL());
       
    44         if (err)
       
    45             {
       
    46             delete testStep;
       
    47             testStep = NULL;
       
    48             }
       
    49         }
       
    50     return testStep;
       
    51     }
       
    52 
       
    53 TVerdict CT_LbsCalculationTP236::doTestStepL()
       
    54     {
       
    55     TestValuesL();
       
    56     return TestStepResult();
       
    57     }
       
    58 
       
    59 void CT_LbsCalculationTP236::TestValuesL()
       
    60     {   
       
    61     _LIT(KOpenFailed, "File open failed with %d");
       
    62     
       
    63     TInt err=0; 
       
    64     err=ReadValues();
       
    65     AssertTrueSecL(err == KErrNone, KOpenFailed, err);
       
    66 
       
    67     TInt index=5;
       
    68     for (TInt i=0; i < iCalculationChecks.Count(); i++)
       
    69         {  
       
    70         
       
    71         T_LbsCalculationCheck cc = iCalculationChecks[i];    
       
    72         
       
    73         if (index==10) 
       
    74             cc.CheckMove();
       
    75 
       
    76         err=cc.CheckMove();
       
    77         LogError(err==KErrNone, cc, err, index);
       
    78          
       
    79         ++index;
       
    80         if (index == 21 || index == 26 || index == 33 || index == 38|| index == 40 || index == 45 || 
       
    81             index == 50 || index == 73 || index == 78 || index == 85 || index == 92 || index == 96 || 
       
    82             index == 33 || index == 106 || index == 123 || index == 128 || index == 133)
       
    83             {
       
    84             ++index;
       
    85             }
       
    86         }
       
    87 
       
    88     // Checks that KErrArgumenet is returned
       
    89     
       
    90     T_LbsCalculationCheck c;
       
    91     err=c.CheckMove();
       
    92     LogError(err==KErrNone, c, err);
       
    93 
       
    94     //
       
    95     // Test error report SBUY-65KBZD TCoordinate::Move returns wrong results
       
    96     // Note that the same calculation error is found in the calculations in the excel sheet
       
    97     // Therefore we need to test it here
       
    98     TCoordinate source(0, 0);
       
    99     TCoordinate target(0, 99);
       
   100     err=source.Move(90, 11000000);
       
   101 
       
   102     
       
   103     _LIT(KInfoMsg1, "Testing SBUY-65KBZD");
       
   104     INFO_PRINTF1(KInfoMsg1);
       
   105 
       
   106     // Sert accuracy to very low
       
   107     const TReal KAccuracy = 0.5;
       
   108 
       
   109     if (!Equals(source.Latitude(), target.Latitude(), KAccuracy) ||
       
   110         !Equals(source.Longitude(), target.Longitude(), KAccuracy))
       
   111         {
       
   112         _LIT(KErrorMsg1, "Move of TC(0,0) bearing 90, 11000000 meters returned wrong coord");
       
   113         LogErrorAndLeaveL(KErrorMsg1);
       
   114         }
       
   115 
       
   116     //
       
   117     TCoordinate source2(0, 0);
       
   118     TCoordinate target2(0, -90);
       
   119     err=source2.Move(90, 30000000);
       
   120 
       
   121     if (!Equals(source2.Latitude(), target2.Latitude(), KAccuracy) ||
       
   122         !Equals(source2.Longitude(), target2.Longitude(), KAccuracy))
       
   123         {
       
   124         _LIT(KErrorMsg2, "Move of TC(0,0) bearing 90, 30000000 meters returned wrong coord");
       
   125         LogErrorAndLeaveL(KErrorMsg2);
       
   126         }        
       
   127     //
       
   128 
       
   129     }
       
   130 
       
   131 TBool CT_LbsCalculationTP236::Equals(const TReal aValue1, const TReal aValue2, const TReal aAccuracy)
       
   132     {
       
   133     TReal maxAllowedError = aAccuracy;
       
   134 
       
   135     TReal absError = Abs(aValue1-aValue2);
       
   136     
       
   137     return (absError < maxAllowedError); 
       
   138 
       
   139     }
       
   140 
       
   141 void CT_LbsCalculationTP236::TestNotSupportedL()
       
   142     {
       
   143     T_LbsCalculationCheck c;
       
   144     c.SetMoveErrorCode(KErrNotSupported);
       
   145       
       
   146     TInt err=c.CheckMove();
       
   147     LogError(err==KErrNone, c, err);     
       
   148     }
       
   149 
       
   150 void CT_LbsCalculationTP236::LogTestError(const T_LbsCalculationCheck& aCalc, 
       
   151                                      const TInt aError,
       
   152                                      const TInt aRow)
       
   153     {
       
   154     TBuf<KMaxLogLineLength> buf;
       
   155     TPosition source;
       
   156     TPosition target;
       
   157     aCalc.GetSourcePosition(source);
       
   158     aCalc.GetTargetPosition(target);
       
   159     
       
   160     if (aError==KErrCalculationCheckMove)
       
   161         {
       
   162         TCoordinate calcCoordinate;
       
   163         aCalc.GetCalcCoordinate(calcCoordinate);
       
   164 
       
   165         _LIT(KSpeedError, "Calculated coordinate is not equal to read target coordinate, values:");
       
   166         _LIT(KValues, "Read coordinate: Lat= %f, Long2= %f, calulated coordinate: Lat= %f, Long= %f, row %d"); 
       
   167             
       
   168 		buf.Format(KValues, target.Latitude(), 
       
   169                             target.Longitude(), 
       
   170                             calcCoordinate.Latitude(), 
       
   171                             calcCoordinate.Longitude(),
       
   172                             aRow);
       
   173          
       
   174         ERR_PRINTF1(KSpeedError);
       
   175         }
       
   176      else if(aError==KErrCalculationCheckErrorCode)
       
   177         {
       
   178         _LIT(KIncorrectErrorCode, "Incorrect error code returned from Speed calculation lib:");
       
   179         _LIT(KCodes, "Lat1= %f, Long1= %f, Lat2= %f, Long2= %f, Returned = %d, Expected = %d, row= %d");
       
   180         
       
   181         buf.Format(KCodes, source.Latitude(), 
       
   182                            source.Longitude(), 
       
   183                            target.Latitude(), 
       
   184                            target.Longitude(), 
       
   185                            aCalc.ReturnedErrorCode(), 
       
   186                            aCalc.SpeedErrorCode(), aRow);
       
   187 
       
   188         ERR_PRINTF1(KIncorrectErrorCode);
       
   189         }
       
   190         
       
   191     ERR_PRINTF1(buf);
       
   192     }
       
   193 
       
   194 //  End of File