datasourcemodules/defaultpositioningmodule/test/te_defproxy/src/basicusagestep.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 // Copyright (c) 2008-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 // Example CTestStep derived implementation
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file BasicUsageStep.cpp
       
    20  @internalTechnology
       
    21 */
       
    22 #include "basicusagestep.h"
       
    23 #include "te_defproxysuitedefs.h"
       
    24 
       
    25 CBasicUsageStep::~CBasicUsageStep()
       
    26 /**
       
    27  * Destructor
       
    28  */
       
    29 	{
       
    30 	}
       
    31 
       
    32 CBasicUsageStep::CBasicUsageStep()
       
    33 /**
       
    34  * Constructor
       
    35  */
       
    36 	{
       
    37 	SetTestStepName(KBasicUsageStep);
       
    38 	}
       
    39 
       
    40 TVerdict CBasicUsageStep::doTestStepPreambleL()
       
    41 /**
       
    42  * @return - TVerdict code
       
    43  * Override of base class virtual
       
    44  */
       
    45 	{
       
    46 	CTe_defproxySuiteStepBase::doTestStepPreambleL();
       
    47 	SetTestStepResult(EPass);
       
    48 	return TestStepResult();
       
    49 	}
       
    50 
       
    51 TVerdict CBasicUsageStep::doTestStepL()
       
    52 /**
       
    53  * @return - TVerdict code
       
    54  * Override of base class pure virtual
       
    55  * Our implementation only gets called if the base class doTestStepPreambleL() did
       
    56  * not leave. That being the case, the current test result value will be EPass.
       
    57  */
       
    58 	{
       
    59     StandardPrepareL();
       
    60     TPositionInfo posInfo;
       
    61     TPositionUpdateOptions options;
       
    62     // psy6 will be instructed
       
    63     HPositionGenericInfo* genInfo = HPositionGenericInfo::NewLC();
       
    64 
       
    65     DisableAllModulesL();
       
    66 
       
    67     // 0. No PSYs
       
    68     PositionRequestWithCheck(posInfo, KErrNotFound, KNullUid);
       
    69     
       
    70     // only PSY6 from now on
       
    71     ToggleModuleL(KUidLcfPsy6, ETrue);
       
    72 
       
    73     // 1. Request and Cancel
       
    74     genInfo->SetRequestedField(KPSY6FieldDelayProcessing);
       
    75     genInfo->SetValue(KPSY6FieldDelayProcessing,
       
    76         TTimeIntervalMicroSeconds(KDelay));
       
    77 
       
    78     iPositioner.NotifyPositionUpdate(*genInfo, iStatus);
       
    79     User::After(KSmallDelay);
       
    80     iPositioner.CancelRequest(EPositionerNotifyPositionUpdate);
       
    81     User::WaitForRequest(iStatus);
       
    82     CheckExpectedResult(iStatus.Int(), KErrCancel, KRequestNotCancelled);
       
    83 
       
    84     // check events
       
    85     genInfo->ClearRequestedFields();
       
    86     genInfo->SetRequestedField(KPSY6FieldEventLog);
       
    87     PositionRequestWithCheck(*genInfo, KErrNone, KUidLcfPsy6);
       
    88 
       
    89     TInt32 logSize;
       
    90     if(KErrNone != genInfo->GetValue(KPSY6FieldEventLogSize, logSize))
       
    91         {
       
    92         ERR_PRINTF1(KFailedReadLogsize);
       
    93         CleanupStack::PopAndDestroy(genInfo);
       
    94         SetTestStepResult(EFail);
       
    95         return TestStepResult();
       
    96         }
       
    97     if (3 == logSize) // update, cancel, update
       
    98     {
       
    99         TQueryEvent* eventArray = GetPsy6EventLogL(*genInfo);
       
   100         CheckExpectedResult((eventArray)->iEventType, EUpdate, KBadFirstEventPSY6);
       
   101         CheckExpectedResult((eventArray + 1)->iEventType, ECancel, KBadSecondEventPSY6);
       
   102         CheckExpectedResult((eventArray + 2)->iEventType, EUpdate, KBadThirdEventPSY6);
       
   103     }
       
   104     else
       
   105     {
       
   106         CheckExpectedResult(logSize, 3, KWrongEventNumberPSY6);
       
   107     }
       
   108 
       
   109     // 2. Check bad Uid
       
   110      const  TInt32 wrongUid = 0x12345678;
       
   111     genInfo->ClearRequestedFields();
       
   112     {
       
   113         genInfo->SetRequestedField(KPSY6FieldRequestedUid);
       
   114         genInfo->SetValue(KPSY6FieldRequestedUid, wrongUid);
       
   115         iPositioner.NotifyPositionUpdate(*genInfo, iStatus);
       
   116         User::WaitForRequest(iStatus);
       
   117         CheckExpectedResult(iStatus.Int(), KErrGeneral, KWrongUidAccepted);
       
   118 
       
   119         genInfo->SetRequestedField(KPSY6FieldRequestedUid);
       
   120         genInfo->SetValue(KPSY6FieldRequestedUid, (TInt32) KNullUid.iUid);
       
   121         iPositioner.NotifyPositionUpdate(*genInfo, iStatus);
       
   122         User::WaitForRequest(iStatus);
       
   123         CheckExpectedResult(iStatus.Int(), KErrGeneral, KWrongNullUidAccepted);
       
   124     }
       
   125     genInfo->ClearRequestedFields();
       
   126 
       
   127     // 3. Check specific results
       
   128 
       
   129     // KErrPositionBufferOverflow
       
   130     TInt32 result = KErrPositionBufferOverflow;
       
   131     SetPsy6Result(*genInfo, result);
       
   132     PositionRequestWithCheck(*genInfo, result, KUidLcfPsy6);
       
   133 
       
   134     // KErrPositionPartialUpdate
       
   135     result = KPositionPartialUpdate;
       
   136 
       
   137     // if allowed
       
   138     options.SetAcceptPartialUpdates(ETrue);
       
   139     iPositioner.SetUpdateOptions(options);
       
   140     SetPsy6Result(*genInfo, result);
       
   141     PositionRequestWithCheck(*genInfo, result, KUidLcfPsy6);
       
   142 
       
   143     // if not allowed
       
   144     options.SetAcceptPartialUpdates(EFalse);
       
   145     iPositioner.SetUpdateOptions(options);
       
   146     SetPsy6Result(*genInfo, result);
       
   147     PositionRequestWithCheck(*genInfo, result, KUidLcfPsy6);
       
   148 
       
   149     // 4. This is very special case:
       
   150     // If a PSY is unloaded due to settings changes and loaded again
       
   151     // within tracking session, it should be informed about tracking session
       
   152     // via StartTrackingL method.
       
   153     // Test also what happens if this method leaves - leave is ignored
       
   154 
       
   155     // order : Psy6, Dummy3
       
   156     SetupModuleL(KUidLcfPsy6, ETrue, 0);
       
   157     SetupModuleL(KUidLcfPsy3, ETrue, 1);
       
   158 
       
   159     const TTimeIntervalMicroSeconds KInterval = 1 * KSecondsToMicro;
       
   160     options.SetUpdateInterval(KInterval);
       
   161     iPositioner.SetUpdateOptions(options);
       
   162 
       
   163     // 4.1 StartTrackingL may leave
       
   164 
       
   165     genInfo->ClearRequestedFields();
       
   166 
       
   167     // 2 requests to "warm up" tracking session
       
   168     PositionRequestWithCheck(*genInfo, KErrNone, KUidLcfPsy6);
       
   169     PositionRequestWithCheck(*genInfo, KErrNone, KUidLcfPsy6);
       
   170 
       
   171     // disable PSY6
       
   172     ToggleModuleL(KUidLcfPsy6, EFalse);
       
   173     PositionRequestWithCheck(*genInfo, KErrNone, KUidLcfPsy3);
       
   174     PositionRequestWithCheck(*genInfo, KErrNone, KUidLcfPsy3);
       
   175 
       
   176     // reenable PSY6
       
   177     ToggleModuleL(KUidLcfPsy6, ETrue);
       
   178     PositionRequestWithCheck(*genInfo, KErrNone, KUidLcfPsy6); // tracking is informed here just before request
       
   179 
       
   180     options.SetUpdateInterval(0);
       
   181     iPositioner.SetUpdateOptions(options); // stop tracking is called here
       
   182 
       
   183     // get event log
       
   184     genInfo->SetRequestedField(KPSY6FieldEventLog);
       
   185     PositionRequestWithCheck(*genInfo, KErrNone, KUidLcfPsy6);
       
   186 
       
   187     // check log
       
   188     TQueryEvent* events = GetPsy6EventLogL(*genInfo);
       
   189     if(KErrNone != genInfo->GetValue(KPSY6FieldEventLogSize, logSize))
       
   190         {
       
   191         ERR_PRINTF1(KFailedReadLogsize);
       
   192         CleanupStack::PopAndDestroy(genInfo);
       
   193         SetTestStepResult(EFail);
       
   194         return TestStepResult();
       
   195         }
       
   196     
       
   197     CheckExpectedResult(events->iEventType, ETrackingStart, KWrongEventType);
       
   198     CheckExpectedResult((events + 1)->iEventType, EUpdate, KWrongEventType);
       
   199     CheckExpectedResult((events + 2)->iEventType, ETrackingStop, KWrongEventType);
       
   200     CheckExpectedResult((events + 3)->iEventType, EUpdate, KWrongEventType);
       
   201 
       
   202     CheckExpectedResult(logSize, 4, KWrongAmountOfEvent);
       
   203 	
       
   204 
       
   205     // 4.2 disable and renable PSY6 again, and program to leave on StartTrackingL,
       
   206     // request should still succeed, StartTrackingL/StopTracking not called
       
   207 /* This part does not work, because StartTrackingL will be called by DefProxy
       
   208    before issuing location request
       
   209 
       
   210     ToggleModuleL(KUidLcfPsy6, EFalse);
       
   211     PositionRequestWithCheck(*genInfo, KErrNone, KUidLcfPsy3)
       
   212 
       
   213     options.SetUpdateInterval(KInterval);
       
   214     iPositioner.SetUpdateOptions(options);
       
   215 
       
   216     // 1 requests to "warm up" tracking session
       
   217     PositionRequestWithCheck(*genInfo, KErrNone, KUidLcfPsy3)
       
   218 
       
   219     ToggleModuleL(KUidLcfPsy6, ETrue);
       
   220 
       
   221     genInfo->ClearRequestedFields();
       
   222     genInfo->SetRequestedField(KPSY6FieldLeaveOnStartTracking);
       
   223     PositionRequestWithCheck(*genInfo, KErrNone, KUidLcfPsy6) // starttracking called before request and leaves
       
   224 
       
   225     // stop tracking and check log, StopTracking is not called
       
   226     options.SetUpdateInterval(0);
       
   227     iPositioner.SetUpdateOptions(options);
       
   228 
       
   229     genInfo->ClearRequestedFields();
       
   230     genInfo->SetRequestedField(KPSY6FieldEventLog);
       
   231     PositionRequestWithCheck(*genInfo, KErrNone, KUidLcfPsy6)
       
   232 
       
   233     // check log
       
   234     events = GetPsy6EventLogL(*genInfo);
       
   235     LEAVE(KErrNone != genInfo->GetValue(KPSY6FieldEventLogSize, logSize), "Failed to read logsize");
       
   236 
       
   237     CHECK_EQUAL(events->iEventType, ETrackingStart, KWrongEventType);
       
   238     CHECK_EQUAL((events + 1)->iEventType, EUpdate, KWrongEventType);
       
   239     CHECK_EQUAL((events + 2)->iEventType, EUpdate, KWrongEventType);
       
   240 
       
   241     CHECK_EQUAL(logSize, 3, KWrongAmountOfEvent);
       
   242 */
       
   243 
       
   244 	
       
   245     // 5. Check Leaving PSY
       
   246     // KLeavingPsy leaves on construction, DefProxy should switch to another PSY
       
   247     DisableAllModulesL();
       
   248     SetupModuleL(KLeavingPsy, ETrue, 0);
       
   249     PositionRequestWithCheck(posInfo, KErrGeneral, KNullUid);
       
   250 
       
   251     SetupModuleL(KUidLcfPsy6, ETrue, 1);
       
   252     PositionRequestWithCheck(posInfo, KErrNone, KUidLcfPsy6);
       
   253 
       
   254     // cleanup
       
   255     CleanupStack::PopAndDestroy(genInfo);
       
   256     StandardCleanup();
       
   257     return TestStepResult();
       
   258 	}
       
   259 
       
   260 
       
   261 
       
   262 TVerdict CBasicUsageStep::doTestStepPostambleL()
       
   263 /**
       
   264  * @return - TVerdict code
       
   265  * Override of base class virtual
       
   266  */
       
   267 	{
       
   268 	CTe_defproxySuiteStepBase::doTestStepPostambleL();
       
   269 	return TestStepResult();
       
   270 	}