common/tools/ats/smoketest/lbs/lbsclient/src/ctlbsclientpostp173.cpp
changeset 748 e13acd883fbe
child 872 17498133d9ad
equal deleted inserted replaced
747:76f9aaeefbab 748:e13acd883fbe
       
     1 // Copyright (c) 2002-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 the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 
       
    19 //  INCLUDES
       
    20 #include "ctlbsclientpostp173.h"
       
    21 #include <badesca.h>
       
    22 #include <EPos_CPosModules.h>
       
    23 #include <EPos_CPosModuleUpdate.h>
       
    24 #include <EPos_CPosModuleIdList.h>
       
    25 #include <LbsCommon.h>
       
    26 #include <LbsPositionInfo.h>
       
    27 #include "tctlbsclientmodulesobserver.h"
       
    28 
       
    29 
       
    30 void MyStopActive(TAny* /*aAny*/)
       
    31     {
       
    32     CActiveScheduler::Stop();
       
    33     }
       
    34 
       
    35 // ================= MEMBER FUNCTIONS =======================
       
    36 
       
    37 // ---------------------------------------------------------
       
    38 // Constructor.
       
    39 // ---------------------------------------------------------
       
    40 CT_LbsClientPosTp173::CT_LbsClientPosTp173(CT_LbsServer& aParent): CT_LbsPortedStepBase(aParent)
       
    41 	{
       
    42 	_LIT(KTestName, "TP173 - Notify Module Events");
       
    43 	SetTestStepName(KTestName); 
       
    44 	}
       
    45 
       
    46 
       
    47 // ---------------------------------------------------------
       
    48 // Destructor.
       
    49 // ---------------------------------------------------------
       
    50 CT_LbsClientPosTp173::~CT_LbsClientPosTp173()
       
    51 	{
       
    52 	}
       
    53 
       
    54 // ---------------------------------------------------------
       
    55 // CT_LbsClientPosTp173::StartL
       
    56 //
       
    57 // (other items were commented in a header).
       
    58 // ---------------------------------------------------------
       
    59 //
       
    60 void CT_LbsClientPosTp173::StartL()
       
    61     {
       
    62     iNoEvents = EFalse;
       
    63     iError = EFalse;
       
    64     // This test listens for events.
       
    65     // There is no data in the event, so all that is needed to be done is
       
    66     // to see that an event is generated. This test doesn't fail if unsuccessful,
       
    67     // it hangs.
       
    68 
       
    69     CPosModules* db = CPosModules::OpenL();
       
    70     CleanupStack::PushL(db);
       
    71 
       
    72     db->SetObserverL(*this);
       
    73 
       
    74     TInt prio = db->PriorityL(iUidTestPsy2);
       
    75     if (prio > 0)
       
    76         {
       
    77         prio = 0;
       
    78         }
       
    79     else
       
    80         {
       
    81         prio = 1; // this assumes that more that one PSY is installed
       
    82         }
       
    83 
       
    84     CPosModuleUpdate* visibileUpdate = CPosModuleUpdate::NewLC();
       
    85     visibileUpdate->SetUpdateVisibility(ETrue);
       
    86     db->UpdateModuleL(iUidTestPsy2, *visibileUpdate);
       
    87     
       
    88     db->SetModulePriorityL(iUidTestPsy2, prio);
       
    89     CleanupStack::PopAndDestroy(visibileUpdate);
       
    90     
       
    91 
       
    92     // Wait for event
       
    93     DoEventHandlingL();
       
    94 
       
    95     CPosModuleUpdate* availUpdate = CPosModuleUpdate::NewLC();
       
    96 
       
    97 
       
    98 	TPositionModuleInfo info;
       
    99 	db -> GetModuleInfoL(iUidTestPsy2, info);
       
   100 	TBool available = info.IsAvailable();
       
   101 
       
   102     availUpdate->SetUpdateAvailability(/*ETrue*/ !available);
       
   103     db->UpdateModuleL(iUidTestPsy2, *availUpdate);
       
   104     
       
   105     CleanupStack::PopAndDestroy(availUpdate);
       
   106 
       
   107     // Wait for event
       
   108     DoEventHandlingL();
       
   109 
       
   110     CPosModuleUpdate* costUpdate = CPosModuleUpdate::NewLC();
       
   111 	
       
   112 	TPositionQuality quality;
       
   113 	info.GetPositionQuality(quality);
       
   114 	TPositionQuality::TCostIndicator indicator = quality.CostIndicator();
       
   115     switch (indicator)
       
   116     {
       
   117         case TPositionQuality::ECostUnknown:
       
   118             indicator = TPositionQuality::ECostZero;
       
   119             break;
       
   120         case TPositionQuality::ECostZero:
       
   121             indicator = TPositionQuality::ECostPossible;
       
   122             break;
       
   123         case TPositionQuality::ECostPossible:
       
   124             indicator = TPositionQuality::ECostCharge;
       
   125             break;
       
   126         case TPositionQuality::ECostCharge:
       
   127             indicator = TPositionQuality::ECostPossible;
       
   128             break;
       
   129         default:
       
   130         	_LIT(KErrorAndLeave, "quality indicator does not exist");
       
   131             LogErrorAndLeaveL(KErrorAndLeave);
       
   132     }
       
   133 
       
   134     costUpdate->SetUpdateCost(/*TPositionQuality::ECostCharge*/ indicator);
       
   135     db->UpdateModuleL(iUidTestPsy2, *costUpdate);
       
   136     
       
   137     CleanupStack::PopAndDestroy(costUpdate);
       
   138 
       
   139     // Wait for event
       
   140     DoEventHandlingL();
       
   141 
       
   142     ////////////////////////////////////
       
   143 
       
   144     CPosModuleUpdate* visibilityUpdate = CPosModuleUpdate::NewLC();
       
   145     visibilityUpdate->SetUpdateVisibility(EFalse);
       
   146     db->UpdateModuleL(iUidTestPsy2, *visibilityUpdate);
       
   147     CleanupStack::PopAndDestroy(visibilityUpdate);
       
   148     
       
   149     DoEventHandlingL();
       
   150     
       
   151     ////////////////////////////////////
       
   152     
       
   153     CMyNotificationTimer* timer = CMyNotificationTimer::NewLC(this);
       
   154 	
       
   155     TTimeIntervalMicroSeconds ttfUpdate(1000000);
       
   156     TPositionQuality dynQualityUpdate;
       
   157     dynQualityUpdate.SetHorizontalAccuracy(30.0);
       
   158     dynQualityUpdate.SetTimeToNextFix(ttfUpdate);
       
   159 
       
   160     timer->StartNotificationTimer();
       
   161     iNoEvents = ETrue;
       
   162     // Wait for event
       
   163     DoEventHandlingL();
       
   164     
       
   165 ////////////////////////////////////
       
   166    
       
   167    
       
   168     
       
   169     
       
   170     db->RemoveObserver();
       
   171     CleanupStack::PopAndDestroy(2, db);
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------
       
   175 // CT_LbsClientPosTp173::DoEventHandlingL
       
   176 //
       
   177 // (other items were commented in a header).
       
   178 // ---------------------------------------------------------
       
   179 //
       
   180 void CT_LbsClientPosTp173::DoEventHandlingL()
       
   181     {
       
   182 	//User::After(20);
       
   183 	CActiveScheduler::Start();
       
   184     CheckErrorL();
       
   185     }
       
   186 
       
   187 // ---------------------------------------------------------
       
   188 // CT_LbsClientPosTp173::CheckErrorL
       
   189 //
       
   190 // (other items were commented in a header).
       
   191 // ---------------------------------------------------------
       
   192 //
       
   193 void CT_LbsClientPosTp173::CheckErrorL()
       
   194     {
       
   195     if (iError)
       
   196         {
       
   197         LogErrorAndLeaveL(iErrorText);
       
   198         }
       
   199     }
       
   200 
       
   201 // ---------------------------------------------------------
       
   202 // CT_LbsClientPosTp173::HandleDatabaseChangeL
       
   203 //
       
   204 // (other items were commented in a header).
       
   205 // ---------------------------------------------------------
       
   206 void CT_LbsClientPosTp173::HandleSettingsChangeL(TPosModulesEvent /*aModuleEvent*/)
       
   207     {
       
   208        
       
   209     CleanupStack::PushL(TCleanupItem(MyStopActive));
       
   210     if (iNoEvents)
       
   211         {
       
   212         _LIT(KErrorText, "Event received when no event should have been received");
       
   213         iErrorText = KErrorText;
       
   214         iError = ETrue;
       
   215         }
       
   216 
       
   217     CleanupStack::PopAndDestroy();
       
   218     }
       
   219 
       
   220 // ---------------------------------------------------------
       
   221 // CT_LbsClientPosTp173::AssertTrueSecL
       
   222 //
       
   223 // (other items were commented in a header).
       
   224 // ---------------------------------------------------------
       
   225 //
       
   226 void CT_LbsClientPosTp173::AssertTrueSecL(TBool aCondition, const TDesC& aErrorMsg, TInt aErrorCode)
       
   227     {
       
   228     if (!aCondition)
       
   229         {
       
   230         TBuf<100> buf;
       
   231         buf.Format(aErrorMsg, aErrorCode);
       
   232         LogErrorAndLeaveL(buf);
       
   233         }
       
   234     }
       
   235 
       
   236 // ---------------------------------------------------------
       
   237 // CT_LbsClientPosTp173::NotifyTimeout
       
   238 //
       
   239 // (other items were commented in a header).
       
   240 // ---------------------------------------------------------
       
   241 //
       
   242 void CT_LbsClientPosTp173::NotifyTimeout()
       
   243 	{
       
   244     CleanupStack::PushL(TCleanupItem(MyStopActive));
       
   245     if (!iNoEvents)
       
   246         {
       
   247         _LIT(KErrorText, "No event received when event should have been received");
       
   248         iErrorText = KErrorText;
       
   249         iError = ETrue;
       
   250         }
       
   251 
       
   252     CleanupStack::PopAndDestroy();
       
   253 	}
       
   254 
       
   255 // ---------------------------------------------------------
       
   256 // CNotificationTimer::~CNotificationTimer
       
   257 //
       
   258 // (other items were commented in a header).
       
   259 // ---------------------------------------------------------
       
   260 //
       
   261 //Implementation of a CNotificationTimer
       
   262 
       
   263 // destructor
       
   264 CMyNotificationTimer::~CMyNotificationTimer()
       
   265 	{
       
   266 	Cancel();
       
   267 	iMainControl = NULL;
       
   268 	}
       
   269 
       
   270 // ---------------------------------------------------------
       
   271 // CNotificationTimer::NewLC
       
   272 //
       
   273 // (other items were commented in a header).
       
   274 // ---------------------------------------------------------
       
   275 //
       
   276 // Two-phased constructor.
       
   277 CMyNotificationTimer* CMyNotificationTimer::NewLC(CT_LbsClientPosTp173* aMainControl)
       
   278 	{
       
   279 	CMyNotificationTimer* self=new (ELeave) CMyNotificationTimer(aMainControl);
       
   280 	CleanupStack::PushL(self);
       
   281 	self->ConstructL();
       
   282 	return self;
       
   283 	}
       
   284 
       
   285 // ---------------------------------------------------------
       
   286 // CNotificationTimer::NewL
       
   287 //
       
   288 // (other items were commented in a header).
       
   289 // ---------------------------------------------------------
       
   290 //
       
   291 // Two-phased constructor.
       
   292 CMyNotificationTimer* CMyNotificationTimer::NewL(CT_LbsClientPosTp173* aMainControl)
       
   293 	{
       
   294 	CMyNotificationTimer* self = NewLC(aMainControl);
       
   295 	CleanupStack::Pop();
       
   296 	return self;
       
   297 	}
       
   298 	
       
   299 // ---------------------------------------------------------
       
   300 // CNotificationTimer::StartNotificationTimer
       
   301 //
       
   302 // (other items were commented in a header).
       
   303 // ---------------------------------------------------------
       
   304 void CMyNotificationTimer::StartNotificationTimer()
       
   305 	{
       
   306 	CTimer::After(iNotificationTimout);
       
   307 	}
       
   308 
       
   309 // ---------------------------------------------------------
       
   310 // CNotificationTimer::DoCancel
       
   311 //
       
   312 // (other items were commented in a header).
       
   313 // ---------------------------------------------------------
       
   314 //
       
   315 void CMyNotificationTimer::DoCancel()
       
   316 	{
       
   317 	CTimer::DoCancel();
       
   318 	}
       
   319 
       
   320 // ---------------------------------------------------------
       
   321 // CNotificationTimer::ConstructL
       
   322 //
       
   323 // (other items were commented in a header).
       
   324 // ---------------------------------------------------------
       
   325 //
       
   326 void CMyNotificationTimer::ConstructL()
       
   327 	{
       
   328 	CTimer::ConstructL();
       
   329 	iNotificationTimout = 5000000;
       
   330 	//add this object to the active scheduler
       
   331 	CActiveScheduler::Add(this); 
       
   332 	}
       
   333 
       
   334 // ---------------------------------------------------------
       
   335 // CNotificationTimer::CNotificationTimer
       
   336 //
       
   337 // (other items were commented in a header).
       
   338 // ---------------------------------------------------------
       
   339 //
       
   340 //c++ default constructor
       
   341 CMyNotificationTimer::CMyNotificationTimer(CT_LbsClientPosTp173* aMainControl)
       
   342 :CTimer(CActive::EPriorityStandard)
       
   343 	{
       
   344 	iMainControl = aMainControl;
       
   345 	}
       
   346         
       
   347 // ---------------------------------------------------------
       
   348 // CNotificationTimer::RunL
       
   349 //
       
   350 // (other items were commented in a header).
       
   351 // ---------------------------------------------------------
       
   352 //
       
   353 void CMyNotificationTimer::RunL()
       
   354 	{
       
   355 	iMainControl->NotifyTimeout();
       
   356 	}
       
   357 
       
   358