locationmgmt/agpslocationmgr/test/te_agpsmanagersuite/src/ctestgpsmoduleobserver.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 // GPS Integration Module Observer for AGPS Manager UNIT testing
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "ctestgpsmoduleobserver.h"
       
    19 #include <lbs/lbslocdatasourceclasstypes.h>
       
    20 
       
    21 CTestGpsModuleObserver* CTestGpsModuleObserver::NewL()
       
    22 	{
       
    23 	CTestGpsModuleObserver* self = new(ELeave) CTestGpsModuleObserver();
       
    24 	CleanupStack::PushL(self);
       
    25 	self->ConstructL();
       
    26 	CleanupStack::Pop(self);
       
    27 	return self;
       
    28 	}
       
    29 
       
    30 CTestGpsModuleObserver::CTestGpsModuleObserver()
       
    31 	{
       
    32 	}
       
    33 
       
    34 CTestGpsModuleObserver::~CTestGpsModuleObserver()
       
    35 	{
       
    36 	delete iRequestedGpsOptions;
       
    37 	}
       
    38 
       
    39 void CTestGpsModuleObserver::ConstructL()
       
    40 	{
       
    41 	CTestObserverBase::ConstructL();
       
    42 	}
       
    43 
       
    44 // Callback from test GPS module to let the test know that the 
       
    45 // AGPS Manager has requested a location update.
       
    46 void CTestGpsModuleObserver::RequestLocationUpdate(const TTime& aTargetTime, const TLbsLocRequestQuality& aQuality)
       
    47 	{
       
    48 	iObservedGpsEvents |= ELocationUpdateReqCall;
       
    49 	
       
    50 	iRequestedTargetTime = aTargetTime;
       
    51 	
       
    52 	// convert from external quality to internal
       
    53 	iRequestedQuality.SetMaxFixTime(aQuality.MaxFixTime());
       
    54 	iRequestedQuality.SetMinHorizontalAccuracy(aQuality.MinHorizontalAccuracy());
       
    55 	iRequestedQuality.SetMinVerticalAccuracy(aQuality.MinVerticalAccuracy());
       
    56 	
       
    57 	SignalObserverCallBack(ECallBackErrorNone);
       
    58 	}
       
    59 
       
    60 // Callback from test GPS module to let the test know that the 
       
    61 // AGPS Manager has requested a location update to be cancelled.
       
    62 void CTestGpsModuleObserver::CancelLocationRequest()
       
    63 	{
       
    64 	iObservedGpsEvents |= ECancelLocationCall;	
       
    65 	SignalObserverCallBack(ECallBackErrorNone);
       
    66 	}
       
    67 
       
    68 // Callback from test GPS module to let the test know that the 
       
    69 // AGPS Manager has advised a new power mode
       
    70 void CTestGpsModuleObserver::AdvisePowerMode(CLbsLocationSourceGpsBase::TPowerMode aMode)
       
    71 	{
       
    72 	iObservedGpsEvents |= EAdvisePowerModeCall;
       
    73 
       
    74 	iAdvisedPowerMode = aMode;
       
    75 	
       
    76 	SignalObserverCallBack(ECallBackErrorNone);	
       
    77 	}
       
    78 
       
    79 // Callback from test GPS module to let the test know that the 
       
    80 // AGPS Manager has set new GPS options.
       
    81 void CTestGpsModuleObserver::SetGpsOptions(const TLbsGpsOptions& aGpsOptions)
       
    82 	{
       
    83 	iObservedGpsEvents |= ESetOptionsCall;
       
    84 	
       
    85 	delete iRequestedGpsOptions;
       
    86 	
       
    87 	switch(aGpsOptions.ClassType())
       
    88 		{
       
    89 		case ELbsGpsOptionsArrayClass:
       
    90 			{
       
    91 			TLbsGpsOptionsItem opsItem;
       
    92 			const TLbsGpsOptionsArray& optionsArray = static_cast<const TLbsGpsOptionsArray&>(aGpsOptions);
       
    93 			iRequestedGpsOptions = new TLbsGpsOptionsArray();
       
    94 			ASSERT(NULL != iRequestedGpsOptions);
       
    95 			iRequestedGpsOptions->SetGpsMode(optionsArray.GpsMode());
       
    96 			for (TUint i= 0; i<optionsArray.NumOptionItems(); i++)
       
    97 				{
       
    98 				optionsArray.GetOptionItem(i, opsItem);
       
    99 				__ASSERT_ALWAYS(KErrNone == (static_cast<TLbsGpsOptionsArray*>(iRequestedGpsOptions))->AppendOptionItem(opsItem), User::Invariant());
       
   100 				}
       
   101 			}
       
   102 		break;
       
   103 		
       
   104 		case ELbsGpsOptionsClass:
       
   105 			{
       
   106 			iRequestedGpsOptions = new TLbsGpsOptions();
       
   107 			ASSERT(NULL != iRequestedGpsOptions);
       
   108 			*iRequestedGpsOptions = aGpsOptions;
       
   109 			}
       
   110 		break;
       
   111 		
       
   112 		default:
       
   113 			ASSERT(EFalse);
       
   114 		break;
       
   115 		}
       
   116 	
       
   117 	SignalObserverCallBack(ECallBackErrorNone);
       
   118 	}
       
   119 
       
   120 // Callback from test GPS module to let the test know that the 
       
   121 // AGPS Manager has reported availability of assistance data.
       
   122 void CTestGpsModuleObserver::AssistanceDataEvent(TInt aError, TLbsAsistanceDataGroup aDataMask)
       
   123 	{
       
   124 	iObservedGpsEvents |= EAssistanceDataCall;
       
   125 	
       
   126 	iAssistanceDataEventError = aError;
       
   127 	iAssistanceDataMask = aDataMask;		
       
   128 	
       
   129 	SignalObserverCallBack(ECallBackErrorNone);
       
   130 	}
       
   131 
       
   132 // Method called by the test to check if the AGPS Manager has issued
       
   133 // a location update request to the GPS module. Calling this method decreases
       
   134 // the callback count in this object. When ETrue is returned, the reported
       
   135 // values of aTargetTime and aQuality are also returned.
       
   136 TBool CTestGpsModuleObserver::WasLocationUpdateRequested(TTime& aTargetTime, TLbsLocRequestQualityInt& aQuality)
       
   137 	{
       
   138 	TBool ret = EFalse;
       
   139 	if (CheckCallbackObserved(ELocationUpdateReqCall))
       
   140 		{
       
   141 		aTargetTime = iRequestedTargetTime;
       
   142 		aQuality = iRequestedQuality;
       
   143 		ret = ETrue;
       
   144 		}
       
   145 	return ret;
       
   146 	}
       
   147 
       
   148 // Method called by the test to check if the AGPS Manager has cancelled
       
   149 // a location update request with the GPS module. Calling this method decreases
       
   150 // the callback count in this object
       
   151 TBool CTestGpsModuleObserver::WasLocationUpdateCancelled()
       
   152 	{
       
   153 	TBool ret = EFalse;
       
   154 	if (CheckCallbackObserved(ECancelLocationCall))
       
   155 		{
       
   156 		ret = ETrue;
       
   157 		}
       
   158 	return ret;		
       
   159 	}
       
   160 	
       
   161 // Method called by the test to check if the AGPS Manager has issued
       
   162 // a power mode advice to the GPS module. Calling this method decreases
       
   163 // the callback count in this object. When ETrue is returned, the reported
       
   164 // value of aPowerMode is also returned.
       
   165 TBool CTestGpsModuleObserver::WasPowerModeAdvised(CLbsLocationSourceGpsBase::TPowerMode& aPowerMode)
       
   166 	{
       
   167 	TBool ret = EFalse;
       
   168 	if (CheckCallbackObserved(EAdvisePowerModeCall))
       
   169 		{
       
   170 		aPowerMode = iAdvisedPowerMode;
       
   171 		ret = ETrue;
       
   172 		}
       
   173 	return ret;		
       
   174 	}
       
   175 
       
   176 // Method called by the test to check if the AGPS Manager has sent
       
   177 // new GPS options to the GPS module. Calling this method decreases
       
   178 // the callback count in this object. When ETrue is returned, the 
       
   179 // new GPS option are also returned in aGpsOptions.
       
   180 TBool CTestGpsModuleObserver::WereGpsOptionsSet(TLbsGpsOptions& aGpsOptions)
       
   181 	{
       
   182 	TBool ret = EFalse;
       
   183 	if (CheckCallbackObserved(ESetOptionsCall))
       
   184 		{
       
   185 		// Return EFalse if the test tries to pass in a class type different from the one
       
   186 		// sent from the Manager in SetGpsOptions()
       
   187 		if ((NULL == iRequestedGpsOptions) ||
       
   188 			(aGpsOptions.ClassType() != iRequestedGpsOptions->ClassType()))
       
   189 			{
       
   190 			ret = EFalse;
       
   191 			}
       
   192 		else
       
   193 			{
       
   194 			// Panic if no options are available
       
   195 			ASSERT(NULL != iRequestedGpsOptions);
       
   196 
       
   197 			switch (aGpsOptions.ClassType())
       
   198 				{
       
   199 				case ELbsGpsOptionsArrayClass:
       
   200 					{
       
   201 					TLbsGpsOptionsItem opsItem;
       
   202 					TLbsGpsOptionsArray& optionsArray = static_cast<TLbsGpsOptionsArray&>(aGpsOptions);
       
   203 					optionsArray.SetGpsMode(iRequestedGpsOptions->GpsMode());
       
   204 					for (TUint i= 0; i<(static_cast<TLbsGpsOptionsArray*>(iRequestedGpsOptions))->NumOptionItems(); i++)
       
   205 						{
       
   206 						__ASSERT_ALWAYS(KErrNone == (static_cast<TLbsGpsOptionsArray*>(iRequestedGpsOptions))->GetOptionItem(i, opsItem), User::Invariant());
       
   207 						__ASSERT_ALWAYS(KErrNone == optionsArray.AppendOptionItem(opsItem), User::Invariant());
       
   208 						}
       
   209 					}
       
   210 				break;
       
   211 		
       
   212 				case ELbsGpsOptionsClass:
       
   213 					aGpsOptions = *iRequestedGpsOptions;
       
   214 				break;
       
   215 		
       
   216 				default:
       
   217 					ASSERT(EFalse);
       
   218 				break;
       
   219 				}
       
   220 			ret = ETrue;
       
   221 			}	
       
   222 		}
       
   223 	return ret;		
       
   224 	}
       
   225 	
       
   226 // Method called by the test to check if the AGPS Manager has reported
       
   227 // availability of new assistance data to the GPS module. Calling this
       
   228 // method decreases the callback count in this object.
       
   229 // When ETrue is returned, the new GPS option are also returned in
       
   230 // aGpsOptions.
       
   231 TBool CTestGpsModuleObserver::WereAssistanceDataReported(TInt& aError, TLbsAsistanceDataGroup& aDataMask)
       
   232 	{
       
   233 	TBool ret = EFalse;
       
   234 	if (CheckCallbackObserved(EAssistanceDataCall))
       
   235 		{
       
   236 		aError = iAssistanceDataEventError;
       
   237 		aDataMask =	iAssistanceDataMask;
       
   238 		ret = ETrue;
       
   239 		}
       
   240 	return ret;		
       
   241 	}
       
   242 
       
   243 // Returns true if aCall is among the callbacks received. If it was
       
   244 // then aCall is removed from the list of received  callbacks.
       
   245 TBool CTestGpsModuleObserver::CheckCallbackObserved(const TObservedGpsModuleCalls aCall)
       
   246 	{
       
   247 	TBool ret = EFalse;
       
   248 	if (iObservedGpsEvents & aCall)
       
   249 		{	
       
   250 		// Clear this call's flag from the list of received calls
       
   251 	 	iObservedGpsEvents = iObservedGpsEvents & ~aCall;
       
   252 	 	CallbackHandled();
       
   253 	 	ret = ETrue;
       
   254 		}
       
   255 	return ret;
       
   256 	}
       
   257 	
       
   258 	
       
   259 // Getters for the values observed in calls from AGPS Manager to GPS module
       
   260 // ========== MAY NOT BE NEEDED, COMMENT OUT FOR THE TIME BEING ============
       
   261 /*
       
   262 const TTime& CTestGpsModuleObserver::TargetTime()
       
   263 	{
       
   264 		
       
   265 	}
       
   266 
       
   267 const TLbsLocRequestQuality& CTestGpsModuleObserver::RequestQuality()
       
   268 	{
       
   269 		
       
   270 	}
       
   271 
       
   272 	
       
   273 const TPowerMode& CTestGpsModuleObserver::PowerMode()
       
   274 	{
       
   275 		
       
   276 	}
       
   277 
       
   278 const TLbsGpsOptions& CTestGpsModuleObserver::GpsOptions()
       
   279 	{
       
   280 		
       
   281 	}
       
   282 
       
   283 	
       
   284 TInt CTestGpsModuleObserver::AssistanceDataEventError()
       
   285 	{
       
   286 		
       
   287 	}
       
   288 
       
   289 TLbsAsistanceDataGroup CTestGpsModuleObserver::AssistanceDataMask()
       
   290 	{
       
   291 		
       
   292 	}
       
   293 */
       
   294