supl/locationomasuplpostester/epos_comasuplpostestermodulecfg/src/epos_comasuplgetsuplinfotest.cpp
changeset 0 667063e416a2
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     1 /*
       
     2 * Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Tests GetSuplInfoL in various scenarios.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <epos_comasuplposhandlerbase.h>
       
    19 #include <epos_comasuplpossessionbase.h>
       
    20 #include <epos_comasuplinforequestlist.h>
       
    21 #include <epos_comasuplinforequestlist.h>
       
    22 #include <epos_comasuplreqasstdata.h>
       
    23 #include <epos_comasuplsetcapabilities.h>
       
    24 #include <epos_comasuplposition.h>
       
    25 #include <epos_comasuplpospayload.h>
       
    26 #include <epos_comasuplvelocity.h>
       
    27 #include <epos_eomasuplposerrors.h>
       
    28 #include <ecom/ecom.h>
       
    29 #include "epos_comasuplpostesterlogger.h"
       
    30 #include "epos_comasupltesthandler.h"
       
    31 #include "epos_comasuplgetsuplinfotest.h"
       
    32 #include "epos_comasuplpostestercategory.h"
       
    33 #include "epos_comasuplpossessioncreationtest.h"
       
    34 #include "epos_comasuplgetsuplinfomanager.h"
       
    35 
       
    36 /** Constant used for logging information about test*/
       
    37 _LIT8(KGetSuplInfoTestComplete, "Info: GetSuplInfoL Test Complete.");
       
    38 
       
    39 /** Constant used for logging information about test*/
       
    40 _LIT8(KGetSuplInfoTestAborted, "Error: GetSuplInfoL Test Aborted");
       
    41 
       
    42 _LIT8(KReqBeforeSessionInitialize, "Info: Requesting GetSuplInfo before \
       
    43 Initializing POS session.");
       
    44 
       
    45 _LIT8(KEndSessionRequest, "Info: GetSuplInfoL requested after \
       
    46 Session End.");
       
    47 
       
    48 _LIT8(KPosInactiveWarning, "Warning: POS session is not initialized.\
       
    49 GetSuplInfoL() completed with error code: ");
       
    50 
       
    51 _LIT8(KEndSessionWarning, "Warning: After End of POS session \
       
    52 GetSuplInfoL() completed with error code: ");
       
    53 
       
    54 _LIT8(KPosInactiveInfo, "Info: GetSuplInfoL() completed with status \
       
    55 KErrOMASuplPosInActive");
       
    56 
       
    57 _LIT8(KGetSuplInfoInfo, "Info: GetSuplInfoL() completed with status \
       
    58 KErrNone.");
       
    59 
       
    60 _LIT8(KRequestAfterSessionInit, "Info: Requesting GetSuplInfo after \
       
    61 Initializing POS session.");
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // Named constructor
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 COMASuplGetSuplInfoTest* COMASuplGetSuplInfoTest::NewL(
       
    68 								COMASuplPosHandlerBase& aPosHandler
       
    69 								, COMASuplPosTesterCategory* aCallBack )
       
    70 	{
       
    71 	COMASuplGetSuplInfoTest* self = new( ELeave )COMASuplGetSuplInfoTest(
       
    72 												 aPosHandler, aCallBack );
       
    73 	CleanupStack::PushL( self );
       
    74 	self->ConstructL();
       
    75 	CleanupStack::Pop( self );
       
    76 	return self;
       
    77 	}
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // Constructor
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 COMASuplGetSuplInfoTest::COMASuplGetSuplInfoTest(
       
    84 							COMASuplPosHandlerBase& aPosHandler 
       
    85 						, COMASuplPosTesterCategory* aCallBack)
       
    86 						:COMASuplGetSuplInfoManager(aPosHandler, aCallBack)
       
    87 	{
       
    88 	CActiveScheduler::Add( this );
       
    89 	}
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // Second phase constructor
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 void COMASuplGetSuplInfoTest::ConstructL()
       
    96 	{
       
    97 	iRequestList = COMASuplInfoRequestList::NewL();
       
    98 	}
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // Destructor
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 COMASuplGetSuplInfoTest::~COMASuplGetSuplInfoTest()
       
   105 	{
       
   106 	}
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // Ends a POS Session.
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 void COMASuplGetSuplInfoTest::EndSession()
       
   113 	{
       
   114 	iInfo++;
       
   115 	iLogger->WriteLine(KSessionEnd, iTestNo);
       
   116 	iSessionBase->SessionEnd();
       
   117 	}
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // This function is called by test handler. It is entry point of execution
       
   121 // of a test case.
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 void COMASuplGetSuplInfoTest::StartTestingL()
       
   125 	{
       
   126 	if(iCallBack)
       
   127 		{
       
   128 		iLogger->WriteTestHeader(KGetSuplInfoTest, iTestNo);
       
   129 		}
       
   130 	iNextInSeq = EStartTest;
       
   131 	__ASSERT_ALWAYS(!IsActive(),User::Panic(KPanicSetActive, KErrAlreadyExists));
       
   132 	DummyRequest(iStatus);
       
   133 	SetActive();
       
   134 	}
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // Handles an active object's request completion event.
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 void COMASuplGetSuplInfoTest::RunL()
       
   141 	{
       
   142 	switch( iNextInSeq )
       
   143 		{
       
   144 		case EStartTest:
       
   145 			{
       
   146 			iLogger->GetRequestStartTime();
       
   147 			TRAPD( err, iSessionBase = iPosHandler.CreateNewSessionL( this ) );
       
   148 			if( KErrNone != err )
       
   149 				{
       
   150 				iError++;
       
   151 				iLogger->WriteLine(KCreatingSessionFail, iTestNo);
       
   152 				User::Leave(err);
       
   153 				}
       
   154 			iInfo++;
       
   155 			iLogger->LogExecutionTime(KExecCreateNewSessionL);
       
   156 			iInfo++;
       
   157 			iLogger->WriteLine(KSessionCreated, iTestNo);
       
   158 			__ASSERT_ALWAYS(!IsActive(),User::Panic(KPanicSetActive, KErrAlreadyExists));
       
   159 			iNextInSeq = ERequestBeforeInitialize;
       
   160 			DummyRequest(iStatus);
       
   161 			SetActive();
       
   162 			break;
       
   163 			}
       
   164 		case ERequestBeforeInitialize:
       
   165 			{
       
   166 			ProcessRequestBeforeInitializeL();
       
   167 			break;
       
   168 			}
       
   169 		case ERequestBeforeInitializeComplete:
       
   170 			{
       
   171 			ProcessRequestBeforeInitializeCompleteL();
       
   172 			break;
       
   173 			}
       
   174 		case EInitializeSession:
       
   175 			{
       
   176 			ProcessInitializeSessionL();
       
   177 			break;
       
   178 			}
       
   179 		case EInitializationComplete:
       
   180 			{
       
   181 			ProcessInitializationCompleteL();
       
   182 			break;
       
   183 			}
       
   184 		case ERequestGetSuplInfo:
       
   185 			{
       
   186 			ProcessRequestGetSuplInfoL();
       
   187 			break;
       
   188 			}
       
   189 		case EGetSuplInfoLRequestComplete:
       
   190 			{
       
   191 			ProcessGetSuplInfoComplete();
       
   192 			break;
       
   193 			}
       
   194 		case EEndSessionAndRequestGetsuplInfo:
       
   195 			{
       
   196 			ProcessEndSessionAndRequestGetsuplInfoL();
       
   197 			break;
       
   198 			}
       
   199 		case EEndSessionRequestComplete:
       
   200 			{
       
   201 			ProcessEndSessionRequestComplete();
       
   202 			break;
       
   203 			}
       
   204 		case ETestingComplete:
       
   205 			{
       
   206 			TestingComplete(KGetSuplInfoTestComplete);
       
   207 			break;
       
   208 			}
       
   209 		default: 
       
   210 			{
       
   211 			User::Leave(KErrNotFound);
       
   212 			}
       
   213 		}
       
   214 	}
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // Implements cancellation of an outstanding request.
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 void COMASuplGetSuplInfoTest::DoCancel()
       
   221 	{
       
   222 	if(iNextInSeq == ERequestBeforeInitializeComplete
       
   223 		|| iNextInSeq == EGetSuplInfoLRequestComplete
       
   224 		|| iNextInSeq == EEndSessionRequestComplete)
       
   225 		{
       
   226 		iSessionBase->CancelSuplInfoRequest();
       
   227 		}
       
   228 	else if(iNextInSeq == EInitializationComplete )
       
   229 		{
       
   230 		iSessionBase->CancelInitialize();
       
   231 		}
       
   232 	}
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // Handles a leave occurring in the request completion event handler RunL().
       
   236 // ---------------------------------------------------------------------------
       
   237 //
       
   238 TInt  COMASuplGetSuplInfoTest::RunError( TInt aError )
       
   239 	{
       
   240 	
       
   241 	if(iNextInSeq == EInitializationComplete )
       
   242 		{
       
   243 		iError++;
       
   244 		iLogger->WriteStatus(KLeaveInSessionInit, aError, iTestNo);
       
   245 		}
       
   246 	else if(iNextInSeq == EStartTest)
       
   247 		{
       
   248 		iError++;
       
   249 		iLogger->WriteStatus(KLeaveInCreateNewSession, aError, iTestNo);
       
   250 		}
       
   251 	else
       
   252 		{
       
   253 		iError++;
       
   254 		iLogger->WriteStatus(KLeaveOccured, aError, iTestNo);
       
   255 		}
       
   256 	TestingAborted(KGetSuplInfoTestAborted);
       
   257 	return KErrNone;
       
   258 	}
       
   259 	
       
   260 // ---------------------------------------------------------------------------
       
   261 // Requests for GetSuplInfoL before initializing session.
       
   262 // ---------------------------------------------------------------------------
       
   263 //
       
   264 void COMASuplGetSuplInfoTest::ProcessRequestBeforeInitializeL()
       
   265 	{
       
   266 	iNextInSeq = ERequestBeforeInitializeComplete;
       
   267 	iInfo++;
       
   268 	iLogger->WriteLine(KReqBeforeSessionInitialize, iTestNo);
       
   269 	__ASSERT_ALWAYS( !IsActive(), User::Panic(KPanicSetActive, 1));
       
   270 	iSessionBase->GetSuplInfoL(iRequestList, iStatus);
       
   271 	SetActive();
       
   272 	}
       
   273 
       
   274 // ---------------------------------------------------------------------------
       
   275 // Logs the completion status of GetsuplinfoL.
       
   276 // ---------------------------------------------------------------------------
       
   277 //
       
   278 void COMASuplGetSuplInfoTest::ProcessRequestBeforeInitializeCompleteL()
       
   279 	{
       
   280 	iNextInSeq = EInitializeSession;
       
   281 	TInt diff = -1;
       
   282 	if(!MatchLists(diff))
       
   283 		{
       
   284 		iError++;
       
   285 		iLogger->WriteStatus(KMatchError, diff, iTestNo, &KNULL());
       
   286 		}
       
   287 	if(iStatus != KErrOMASuplPosInActive)
       
   288 		{
       
   289 		iWarning++;
       
   290 		iLogger->WriteStatus(KPosInactiveWarning, iStatus.Int(), iTestNo
       
   291 																, &KNULL());
       
   292 		iLogger->LogRequestList(*iRequestList);
       
   293 		}
       
   294 	else
       
   295 		{
       
   296 		iInfo++;
       
   297 		iLogger->WriteLine(KPosInactiveInfo, iTestNo);
       
   298 		}
       
   299 	__ASSERT_ALWAYS( !IsActive(), User::Panic(KPanicSetActive, 1));
       
   300 	DummyRequest(iStatus);
       
   301 	SetActive();
       
   302 	}
       
   303 
       
   304 // ---------------------------------------------------------------------------
       
   305 // Initializes the POS session.
       
   306 // ---------------------------------------------------------------------------
       
   307 //
       
   308 void COMASuplGetSuplInfoTest::ProcessInitializeSessionL()
       
   309 	{
       
   310 	iNextInSeq = EInitializationComplete;
       
   311 	iInfo++;
       
   312 	iLogger->WriteLine(KInitializingSession, iTestNo);
       
   313 	__ASSERT_ALWAYS( !IsActive(), User::Panic(KPanicSetActive, 1));
       
   314 	iSessionBase->InitializeL(iRequestID, iStatus);
       
   315 	SetActive();
       
   316 	}
       
   317 
       
   318 // ---------------------------------------------------------------------------
       
   319 // Logs the completion status of session initialization.
       
   320 // Leaves if session initialization is not complete with KErrNone.
       
   321 // ---------------------------------------------------------------------------
       
   322 //
       
   323 void COMASuplGetSuplInfoTest::ProcessInitializationCompleteL()
       
   324 	{
       
   325 	if(iStatus != KErrNone)
       
   326 		{
       
   327 		iError++;
       
   328 		iLogger->WriteStatus(KError, iStatus.Int(), iTestNo, &KReqCompWith());
       
   329 		TestingAborted(KGetSuplInfoTestAborted);
       
   330 		return;
       
   331 		}
       
   332 	iNextInSeq = ERequestGetSuplInfo;
       
   333 	iInfo++;
       
   334 	iLogger->WriteLine(KSessionInitialized, iTestNo);
       
   335 	__ASSERT_ALWAYS(!IsActive(), User::Panic(KPanicSetActive, 1));
       
   336 	DummyRequest(iStatus);
       
   337 	SetActive();
       
   338 	}
       
   339 
       
   340 // ---------------------------------------------------------------------------
       
   341 // Requests for GetSuplInfoL().
       
   342 // ---------------------------------------------------------------------------
       
   343 //
       
   344 void COMASuplGetSuplInfoTest::ProcessRequestGetSuplInfoL()
       
   345 	{
       
   346 	iNextInSeq = EGetSuplInfoLRequestComplete;
       
   347 	TRAPD(err, CreateRequestListL());
       
   348 	if(KErrNone != err)
       
   349 		{
       
   350 		iError++;
       
   351 		iLogger->WriteStatus(KLeaveRequestListCreation(), err, iTestNo);
       
   352 		TestingAborted(KGetSuplInfoTestAborted);
       
   353 		return;
       
   354 		}
       
   355 	__ASSERT_ALWAYS(!IsActive(), User::Panic(KPanicSetActive, 1));
       
   356 	iInfo++;
       
   357 	iLogger->WriteLine(KRequestAfterSessionInit, iTestNo);
       
   358 	iSessionBase->GetSuplInfoL(iRequestList, iStatus);
       
   359 	SetActive();
       
   360 	}
       
   361 
       
   362 // ---------------------------------------------------------------------------
       
   363 // Logs the completion status of GetSplInfoL().
       
   364 // ---------------------------------------------------------------------------
       
   365 //
       
   366 void COMASuplGetSuplInfoTest::ProcessGetSuplInfoComplete()
       
   367 	{
       
   368 	TInt diff = -1;
       
   369 	if(!MatchLists(diff))
       
   370 		{
       
   371 		iError++;
       
   372 		iLogger->WriteStatus(KMatchError, diff, iTestNo, &KNULL());
       
   373 		}
       
   374 	iNextInSeq = EEndSessionAndRequestGetsuplInfo;
       
   375 	if(iStatus != KErrNone)
       
   376 		{
       
   377 		iWarning++;
       
   378 		iLogger->WriteStatus(KPosInactiveWarning, iStatus.Int(), iTestNo
       
   379 															, &KNULL());
       
   380 		}
       
   381 	else
       
   382 		{
       
   383 		iInfo++;
       
   384 		iLogger->WriteLine(KGetSuplInfoInfo, iTestNo);
       
   385 		}
       
   386 	iLogger->LogRequestList(*iRequestList);
       
   387 	__ASSERT_ALWAYS(!IsActive(), User::Panic(KPanicSetActive, 1));
       
   388 	DummyRequest(iStatus);
       
   389 	SetActive();
       
   390 	}
       
   391 
       
   392 // ---------------------------------------------------------------------------
       
   393 // Ends session and requests for GetSuplInfoL().
       
   394 // ---------------------------------------------------------------------------
       
   395 //
       
   396 void COMASuplGetSuplInfoTest::ProcessEndSessionAndRequestGetsuplInfoL()
       
   397 	{
       
   398 	EndSession();
       
   399 	//Recreate request list
       
   400 	TRAPD(err, CreateRequestListL());
       
   401 	if(KErrNone != err)
       
   402 		{
       
   403 		iError++;
       
   404 		iLogger->WriteStatus(KLeaveRequestListCreation(), err, iTestNo);
       
   405 		TestingAborted(KGetSuplInfoTestAborted);
       
   406 		return;
       
   407 		}
       
   408 	iNextInSeq = EEndSessionRequestComplete;
       
   409 	__ASSERT_ALWAYS(!IsActive(), User::Panic(KPanicSetActive, 1));
       
   410 	iInfo++;
       
   411 	iLogger->WriteLine(KEndSessionRequest, iTestNo);
       
   412 	iSessionBase->GetSuplInfoL( iRequestList, iStatus );
       
   413 	SetActive();
       
   414 	}
       
   415 
       
   416 // ---------------------------------------------------------------------------
       
   417 // Logs completion status of GetSuplInfoL requested after 
       
   418 // ending the session.
       
   419 // ---------------------------------------------------------------------------
       
   420 //
       
   421 void COMASuplGetSuplInfoTest::ProcessEndSessionRequestComplete()
       
   422 	{
       
   423 	TInt diff = -1;
       
   424 	if(!MatchLists(diff))
       
   425 		{
       
   426 		iError++;
       
   427 		iLogger->WriteStatus(KMatchError, diff, iTestNo, &KNULL());
       
   428 		}
       
   429 	iNextInSeq = ETestingComplete;
       
   430 	if(iStatus != KErrOMASuplPosInActive)
       
   431 		{
       
   432 		iWarning++;
       
   433 		iLogger->WriteStatus(KEndSessionWarning, iStatus.Int(), iTestNo
       
   434 														, &KNULL());
       
   435 		}
       
   436 	else
       
   437 		{
       
   438 		iInfo++;
       
   439 		iLogger->WriteLine(KPosInactiveInfo, iTestNo);
       
   440 		}
       
   441 	//Logging the request list.
       
   442 	iLogger->LogRequestList(*iRequestList);
       
   443 	__ASSERT_ALWAYS(!IsActive(), User::Panic(KPanicSetActive, 1));
       
   444 	DummyRequest(iStatus);
       
   445 	SetActive();
       
   446 	}