wapstack/wapmessageapi/te_wapstack/src/WapBoundWDPSteps.cpp
branchRCL_3
changeset 18 50bae5c5c85f
equal deleted inserted replaced
17:3f227a47ad75 18:50bae5c5c85f
       
     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 "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 // CStepOne derived implementation
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent 
       
    21 */
       
    22 
       
    23 #include <e32base.h>
       
    24 #include <sacls.h>
       
    25 
       
    26 #include "WapBoundWDPSteps.h"
       
    27 #include "WapStackSuiteDefs.h"
       
    28 #include <etel.h>
       
    29 #include <es_wsms.h>
       
    30 #include <simtsy.h>
       
    31 #include <wapmsgerr.h>
       
    32 #include <ecom/ecom.h>
       
    33 
       
    34 CBoundWDPStepBase::CBoundWDPStepBase()
       
    35 /**
       
    36 * Constructor
       
    37 */
       
    38 	{
       
    39 	}
       
    40 
       
    41 CBoundWDPStepBase::~CBoundWDPStepBase()
       
    42 /**
       
    43 * Destructor
       
    44 */
       
    45 	{
       
    46 	if(iImp) 
       
    47 		{
       
    48 		UnloadInterface();
       
    49 		}
       
    50 	}
       
    51 
       
    52 // Load CWapBoundDatagramService Interface 
       
    53 CWapBoundDatagramService* CBoundWDPStepBase::LoadInterface()
       
    54 	{
       
    55 	TInt trapValue;
       
    56 	CWapBoundDatagramService* implementation = NULL;
       
    57 	// UID {0x101FBB37} - SWS implementation
       
    58 	TUid KInterfaceUid = {0x101FBB37}; 	
       
    59 	INFO_PRINTF2(_L("Calling new NewL(0x%08X) method"), KInterfaceUid);
       
    60 	TRAP(trapValue, implementation = CWapBoundDatagramService::NewL(KInterfaceUid));
       
    61 	if(!trapValue)
       
    62 		{
       
    63 		INFO_PRINTF2(_L("Interface is loaded: implementation.addr = 0x%08x"), implementation);
       
    64 		return implementation;
       
    65 		}
       
    66 	else return NULL;
       
    67 	}
       
    68 
       
    69 void CBoundWDPStepBase::UnloadInterface()
       
    70 	{
       
    71 	INFO_PRINTF2(_L("Interface at implementation.addr = 0x%08x is deleted"), iImp);
       
    72 	delete iImp;
       
    73 	iImp = NULL;
       
    74 	REComSession::FinalClose();	
       
    75 	}
       
    76 
       
    77 CBoundWDPStep_1::CBoundWDPStep_1()
       
    78 /**
       
    79 * Constructor
       
    80 */
       
    81 	{
       
    82 	}
       
    83 
       
    84 CBoundWDPStep_1::~CBoundWDPStep_1() 
       
    85 /**
       
    86 * Destructor
       
    87 */
       
    88 	{
       
    89 	}
       
    90 
       
    91 TVerdict CBoundWDPStep_1::doTestStepL()
       
    92 /** 
       
    93 * Load and destroy BoundDatagtamService interface implementation
       
    94 * Two different methods are used NewL() and NewL(TUid InterfaceUid)
       
    95 * @return - TVerdict code
       
    96 */
       
    97 	{
       
    98 	// CWapBoundDatagramService
       
    99 	INFO_PRINTF1(_L("CreateImplementation - CWapBoundDatagramService"));
       
   100 	INFO_PRINTF1(_L("Calling old NewL() method"));
       
   101 	
       
   102 	SetTestStepResult(EFail);
       
   103 
       
   104 	TInt trapValue(0); 
       
   105 	TRAP(trapValue, iImp = CWapBoundDatagramService::NewL());
       
   106 	if(!trapValue)
       
   107 		{
       
   108 		INFO_PRINTF2(_L("Interface is loaded: implementation.addr = 0x%08x"), iImp);
       
   109 		UnloadInterface();
       
   110 		iImp = LoadInterface();
       
   111 		if(iImp)
       
   112 			{
       
   113 			INFO_PRINTF1(_L("CreateImplementation - OK"));
       
   114 			SetTestStepResult(EPass);
       
   115 			UnloadInterface();
       
   116 			}
       
   117 		}
       
   118 	return TestStepResult();
       
   119 	}
       
   120 
       
   121 CBoundWDPStep_2::CBoundWDPStep_2()
       
   122 /**
       
   123 * Constructor
       
   124 */
       
   125 	{
       
   126 	}
       
   127 
       
   128 CBoundWDPStep_2::~CBoundWDPStep_2()
       
   129 /**
       
   130 * Destructor
       
   131 */
       
   132 	{
       
   133 	}
       
   134 
       
   135 TVerdict CBoundWDPStep_2::doTestStepL()
       
   136 /**
       
   137 * Test Connect methoths
       
   138 * @return - TVerdict code
       
   139 *
       
   140 */
       
   141 	{
       
   142 	INFO_PRINTF1(_L("BOUND-WDP: Connect"));
       
   143 	if(TestStepResult() == EPass )
       
   144 		{
       
   145 		SetTestStepResult(EFail);
       
   146 		iImp = LoadInterface();
       
   147 		if(iImp)
       
   148 			{
       
   149 			TInt bearer, port;
       
   150 			TInt error = KErrNone;
       
   151 			TBool reconnect = EFalse;
       
   152 			TBool delay = EFalse;
       
   153 
       
   154 			SetLastError(KErrNone);
       
   155 			if(GetIntFromConfig(ConfigSection(),KWapBearer, bearer)) iBearer = (Wap::TBearer)bearer;
       
   156 			if(GetIntFromConfig(ConfigSection(),KWapLocalPort, port)) iLocalPort = (Wap::TPort)port;
       
   157 			if(GetIntFromConfig(ConfigSection(),KWapExError, error)) SetExpectedError(error);
       
   158 			if(GetBoolFromConfig(ConfigSection(),KWapReconnect, reconnect)) iReconnect = reconnect;
       
   159 			if(GetBoolFromConfig(ConfigSection(),KWapDelayPortClosure, delay)) iDelayPortClosure = delay;
       
   160 			
       
   161 			TInt checkValue = 0;
       
   162 			if(UseSimTsy())
       
   163 				{
       
   164 				GetIntFromConfig(ConfigSection(), KWapSIMTSYState, iSimTsyState);
       
   165 				User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, iSimTsyState));
       
   166 				// double check that base did set it since this is the first place we try setting it in the harness
       
   167 				RProperty::Get(KUidPSSimTsyCategory, KPSSimTsyTestNumber, checkValue);
       
   168 				__ASSERT_ALWAYS(checkValue == iSimTsyState,User::Panic(KWapStackSuitePanic, EDataCorrupt));
       
   169 				} 
       
   170 			
       
   171 			User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
       
   172 			// double check
       
   173 			RProperty::Get(KUidSystemCategory, KUidPhonePwr.iUid, checkValue);
       
   174 			__ASSERT_ALWAYS(checkValue == ESAPhoneOn,User::Panic(KWapStackSuitePanic, EDataCorrupt));
       
   175 
       
   176 			SetState(EConnect);
       
   177 			iControl->ReStart();
       
   178 			ShowConnectionInfo();
       
   179 			// Start state machine
       
   180 			StartScheduler();
       
   181 			UnloadInterface();
       
   182 			}
       
   183 		}
       
   184 	return TestStepResult();
       
   185 	}
       
   186 
       
   187 TInt CBoundWDPStep_2::CallStateMachine()
       
   188 	{
       
   189 	TInt err = KErrNone;
       
   190 	INFO_PRINTF2(_L("CallStateMachine: step [%d]"), State());
       
   191 	switch(iState)
       
   192 		{
       
   193 		case EConnect:
       
   194 			INFO_PRINTF1(_L("EConnect"));
       
   195 			err = iImp->Connect(iBearer, iLocalPort);
       
   196 			INFO_PRINTF2(_L("Connection completed with code = %d"), err);
       
   197 			if( err == KErrNone)
       
   198 				{
       
   199 				if(iReconnect)
       
   200 					{
       
   201 					INFO_PRINTF1(_L("Second connect"));
       
   202 					iControl->ReStart();
       
   203 					break;
       
   204 					}
       
   205 				}
       
   206 			SetState(EFinish);
       
   207 			SetLastError(err);
       
   208 			iControl->ReStart();
       
   209 			break;
       
   210 
       
   211 		case EFinish:
       
   212 			// it's necessary to delay port closure, let the other concurrent test step
       
   213 			// can fail opening the same port with expected error EPortAlreadyBound (-5498)
       
   214 			if (iDelayPortClosure)
       
   215 				User::After(5000000);
       
   216 
       
   217 			INFO_PRINTF1(_L("EFinish"));
       
   218 			if(GetLastError() == GetExpectedError()) SetTestStepResult(EPass);
       
   219 			else SetTestStepResult(EFail);
       
   220 			SetState(EIdle);
       
   221 			// End of state machine
       
   222 			StopScheduler();
       
   223 			break;
       
   224 
       
   225 		case EIdle:
       
   226 		default:
       
   227 			INFO_PRINTF2(_L("Error: bad state EIdle or unknown [%d]"), State());
       
   228 			SetTestStepResult(EFail);
       
   229 			// End of state machine
       
   230 			StopScheduler();
       
   231 			break;
       
   232 		}
       
   233 	return (0);
       
   234 	}
       
   235 
       
   236 
       
   237 CBoundWDPStep_3::CBoundWDPStep_3() 
       
   238 /**
       
   239 * Constructor
       
   240 */
       
   241 	{
       
   242 	}
       
   243 
       
   244 CBoundWDPStep_3::~CBoundWDPStep_3() 
       
   245 /**
       
   246 * Destructor
       
   247 */
       
   248 	{
       
   249 	}
       
   250 
       
   251 TVerdict CBoundWDPStep_3::doTestStepL()
       
   252 /*
       
   253 * Test the CBoundWDP APIs in unconnected state.
       
   254 */
       
   255 	{
       
   256 	INFO_PRINTF1(_L("BoundWDP. Requests without connection"));
       
   257 	// check preamble result
       
   258 	TVerdict verdict = TestStepResult();
       
   259 	if (verdict==EPass)
       
   260 		{
       
   261 		TInt err, ret;
       
   262 		iImp = LoadInterface();
       
   263 		if (!iImp)
       
   264 			{
       
   265 			ERR_PRINTF1(_L("Unable to load BoundWDP Interface"));
       
   266 			verdict = EFail;
       
   267 			}
       
   268 		else
       
   269 			{
       
   270 			GetIntFromConfig(ConfigSection(),KWapExError,(TInt&)iExError);
       
   271 			ShowConnectionInfo();
       
   272 			TBuf8<100> buf;
       
   273 			err = iImp->SendTo(iRemoteHost, iRemotePort, buf, iBearer);
       
   274 			TRAP(ret, TEST_CHECKL(err, iExError, _L("SendTo Fails not as expected")))
       
   275 			if (ret) 
       
   276 				{
       
   277 				verdict = EFail;
       
   278 				}
       
   279 			else
       
   280 				{
       
   281 				TPckg<TUint16> aDataSizePckg(0);
       
   282 				TRequestStatus reqStatus;
       
   283 				iImp->AwaitRecvDataSize(aDataSizePckg, reqStatus);
       
   284 				User::WaitForRequest(reqStatus);
       
   285 				TRAP(ret, TEST_CHECKL(reqStatus.Int(), iExError, _L("AwaitRecvDataSize Fails not as expected")))
       
   286 				if (ret) 
       
   287 					{
       
   288 					verdict = EFail;
       
   289 					}
       
   290 				else
       
   291 					{
       
   292 					TBuf8<100> buf;
       
   293 					TBool truncated;
       
   294 					TUint32 timeout=0;
       
   295 					iImp->RecvFrom(iRecvRemoteHost, iRecvRemotePort, buf, truncated, reqStatus, timeout);
       
   296 					User::WaitForRequest(reqStatus);
       
   297 					TRAP(ret, TEST_CHECKL(reqStatus.Int(), iExError, _L("RecvFrom Fails not as expected")))
       
   298 					if (ret) 
       
   299 						{
       
   300 						verdict = EFail;
       
   301 						}
       
   302 					else
       
   303 						{
       
   304 						Wap::TPort aPort;
       
   305 						err=iImp->GetLocalPort(aPort);
       
   306 						TRAP(ret, TEST_CHECKL(err, iExError, _L("GetLocalPort Fails not as expected")))
       
   307 						if (ret) 
       
   308 							{
       
   309 							verdict = EFail;
       
   310 							}
       
   311 						else
       
   312 							{
       
   313 							HBufC8* localHost;
       
   314 							err=iImp->GetLocalAddress(localHost);
       
   315 							TRAP(ret, TEST_CHECKL(err, iExError, _L("GetLocalAddress Fails not as expected")))
       
   316 							if (ret) 
       
   317 								{
       
   318 								verdict = EFail;
       
   319 								}
       
   320 							else
       
   321 								{
       
   322 								TUint16 maxSize, nominalSize;
       
   323 								err=iImp->GetDatagramSizes(maxSize, nominalSize);
       
   324 								if (err)
       
   325 									{
       
   326 									verdict = EFail;
       
   327 									}
       
   328 								else
       
   329 									{
       
   330 									err=iImp->GetBearer(iBearer);
       
   331 									TRAP(ret, TEST_CHECKL(err, iExError, _L("GetBearer Fails not as expected")))
       
   332 									if (ret)
       
   333 										{
       
   334 										verdict = EFail;
       
   335 										}
       
   336 									}
       
   337 								}
       
   338 							}
       
   339 						}
       
   340 					}
       
   341 				}
       
   342 			UnloadInterface();
       
   343 			}
       
   344 		}
       
   345 	if (verdict==EPass)
       
   346 		{
       
   347 		INFO_PRINTF1(_L("BoundWDP. Requests Fail as expected"));
       
   348 		}
       
   349 	SetTestStepResult(verdict);
       
   350 	return TestStepResult();
       
   351 	}
       
   352 
       
   353 TInt CBoundWDPStep_3::CallStateMachine()
       
   354 	{
       
   355 	return (0);
       
   356 	}
       
   357 
       
   358 
       
   359 CBoundWDPStep_4::CBoundWDPStep_4() 
       
   360 /**
       
   361 * Constructor
       
   362 */
       
   363 	{
       
   364 	}
       
   365 
       
   366 CBoundWDPStep_4::~CBoundWDPStep_4() 
       
   367 /**
       
   368 * Destructor
       
   369 */
       
   370 	{
       
   371 	}
       
   372 
       
   373 TVerdict CBoundWDPStep_4::doTestStepL()
       
   374 /** 
       
   375 */
       
   376 	{
       
   377 	INFO_PRINTF1(_L("BOUND-WDP: Connect-Send-Await-Receive"));
       
   378 	if(TestStepResult() == EPass )
       
   379 		{
       
   380 		SetTestStepResult(EFail);
       
   381 		iImp = LoadInterface();
       
   382 		if(iImp)
       
   383 			{
       
   384 			SetLastError(KErrNone);
       
   385 
       
   386 			TInt bearer, port, bufLen;
       
   387 			TInt error = KErrNone;
       
   388 			TPtrC data, remote_host;
       
   389 			
       
   390 			if(GetIntFromConfig(ConfigSection(),KWapBearer, bearer))
       
   391 				{
       
   392 				iBearer = static_cast<Wap::TBearer>(bearer);
       
   393 				}
       
   394 			if(GetIntFromConfig(ConfigSection(),KWapLocalPort, port))
       
   395 				{
       
   396 				iLocalPort = static_cast<Wap::TPort>(port);
       
   397 				}
       
   398 			if(GetStringFromConfig(ConfigSection(), KWapRemoteHost, remote_host))
       
   399 				{
       
   400 				iRemoteHost.Copy(remote_host);
       
   401 				}
       
   402 			if(GetIntFromConfig(ConfigSection(),KWapRemotePort, port))
       
   403 				{
       
   404 				iRemotePort = static_cast<Wap::TPort>(port);
       
   405 				}
       
   406 			if(GetIntFromConfig(ConfigSection(),KWapExError, error))
       
   407 				{
       
   408 				SetExpectedError(error);
       
   409 				}
       
   410 			GetIntFromConfig(ConfigSection(), KWapExError2, iExError2);
       
   411 			GetBoolFromConfig(ConfigSection(), KAwaitLengthCancel, iAwaitLengthCancel);
       
   412 			GetBoolFromConfig(ConfigSection(), KMiddleCancel, iMiddleCancel);
       
   413 			GetBoolFromConfig(ConfigSection(), KMultiReadCancel, iMultiReadCancel);
       
   414 			GetBoolFromConfig(ConfigSection(), KAwaitLengthTwice, iAwaitLengthTwice);
       
   415 			if(GetIntFromConfig(ConfigSection(),KWapWdpBufLength, bufLen))
       
   416 				{
       
   417 				iWdpRecvBufLength=static_cast<TUint16>(bufLen);
       
   418 				iRecvBuffPtr = HBufC8::NewL(iWdpRecvBufLength);
       
   419 				}
       
   420 			error = GetStringFromConfig(ConfigSection(),KWapData, data);
       
   421 			if(!error)
       
   422 				{
       
   423 				User::Leave(error);
       
   424 				}
       
   425 			iSendBuffPtr = HBufC8::NewL(data.Length());
       
   426 			TPtr8 tmp = iSendBuffPtr->Des();
       
   427 			tmp.Copy(data);
       
   428 			
       
   429 			if(UseSimTsy())
       
   430 				{
       
   431 				GetIntFromConfig(ConfigSection(), KWapSIMTSYState, iSimTsyState);
       
   432 				User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, iSimTsyState));
       
   433 				}
       
   434 			User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
       
   435 					
       
   436 			SetState(EConnect);
       
   437 			iControl->ReStart();
       
   438 			ShowConnectionInfo();
       
   439 			// Start state machine
       
   440 			StartScheduler(); 
       
   441 			UnloadInterface();
       
   442 			}
       
   443 		}
       
   444 	return TestStepResult();
       
   445 	}
       
   446 
       
   447 TInt CBoundWDPStep_4::CallStateMachine()
       
   448 	{
       
   449 	TVerdict verdict = EFail;
       
   450 	TInt err = KErrNone;
       
   451 	TInt activate = 0;
       
   452 	
       
   453 	INFO_PRINTF2(_L("CallStateMachine: state [%d]"), State());
       
   454 	switch(iState)
       
   455 		{
       
   456 		case EConnect:
       
   457 			INFO_PRINTF1(_L("EConnect"));
       
   458 			err = iImp->Connect(iBearer, iLocalPort);
       
   459 			INFO_PRINTF2(_L("Connection completed with code = %d"), err);
       
   460 			if( err == KErrNone)
       
   461 				{
       
   462 					if(iBearer != Wap::EIP)
       
   463 						{
       
   464 						TRAP(err, WaitForInitializeL());
       
   465 						}
       
   466 					if(iSendBuffPtr->Length())
       
   467 						{
       
   468 						INFO_PRINTF1(_L("Data to send"));
       
   469 						DumpBuf(iSendBuffPtr->Des());
       
   470 						}
       
   471 				err = iImp->SendTo(iRemoteHost, iRemotePort, iSendBuffPtr->Des(), iBearer);
       
   472 				INFO_PRINTF2(_L("SendTo completed with code = %d"), err);
       
   473 				if(err == KErrNone) 
       
   474 					{	
       
   475 					SetState(EAwaitSize);
       
   476 					}
       
   477 				else 
       
   478 					{	
       
   479 					SetState(EFinish);
       
   480 					}
       
   481 				}
       
   482 			else 
       
   483 				{
       
   484 				SetState(EFinish);
       
   485 				}
       
   486 			SetLastError(err);
       
   487 			iControl->ReStart();
       
   488 			break;
       
   489 			
       
   490 		case EAwaitSize:
       
   491 			INFO_PRINTF1(_L("EAwaitSize"));
       
   492 			iImp->AwaitRecvDataSize(iLength, *iStatus);
       
   493 			activate = 1;
       
   494 			if (!iAwaitLengthCancel)
       
   495 				{
       
   496 				SetState(EReceive);
       
   497 				}
       
   498 			else
       
   499 				{
       
   500 				INFO_PRINTF1(_L("Cancel Receive in AwaitSize state"));
       
   501 				iImp->CancelRecv();
       
   502 				SetState(EFinish);
       
   503 				}
       
   504 			break;
       
   505 			
       
   506 		case EReceive:
       
   507 			INFO_PRINTF1(_L("EReceive"));
       
   508 			if(iStatus->Int()!=KErrNone) 
       
   509 				// AwaitSize failed
       
   510 				{
       
   511 				INFO_PRINTF1(_L("AwaitSize failed"));
       
   512 				SetLastError(iStatus->Int());
       
   513 				iControl->ReStart();
       
   514 				SetState(EFinish);
       
   515 				}
       
   516 			else
       
   517 				{	
       
   518 				INFO_PRINTF2(_L("AwaitSize returned - %d"),iLength());
       
   519 				if (!iAwaitLengthTwice)
       
   520 					{
       
   521 					if (iRecvBuffPtr==NULL)
       
   522 						{
       
   523 						TInt len=iLength();
       
   524 						TRAP(err, iRecvBuffPtr = HBufC8::NewL(len))
       
   525 							if (err!=KErrNone)
       
   526 								{
       
   527 								SetLastError(err);
       
   528 								iControl->ReStart();
       
   529 								SetState(EFinish);
       
   530 								break;
       
   531 								}
       
   532 						}
       
   533 					iRecvBuf.Set(iRecvBuffPtr->Des());
       
   534 					iImp->RecvFrom(iRecvRemoteHost, iRecvRemotePort, iRecvBuf, iTruncated, *iStatus, 0);
       
   535 					activate = 1;
       
   536 					if (!iMiddleCancel)
       
   537 						{
       
   538 						SetState(EMutipleReceive);
       
   539 						}
       
   540 					else
       
   541 						{
       
   542 						INFO_PRINTF1(_L("Cancel Receive in Receive state"));
       
   543 						iImp->CancelRecv();
       
   544 						SetState(EFinish);
       
   545 						}
       
   546 					}
       
   547 				else
       
   548 					{
       
   549 					iImp->AwaitRecvDataSize(iLength, *iStatus);
       
   550 					activate = 1;
       
   551 					SetState(EFinish);
       
   552 					}
       
   553 				}
       
   554 			break;
       
   555 			
       
   556 		case EMutipleReceive:
       
   557 			INFO_PRINTF1(_L("EMultipleReceive"));
       
   558 			if (iStatus->Int()!=KErrNone && iStatus->Int()!=Wap::EMoreData)
       
   559 				{
       
   560 				INFO_PRINTF1(_L("Receive failed"));
       
   561 				SetLastError(iStatus->Int());
       
   562 				iControl->ReStart();
       
   563 				SetState(EFinish);
       
   564 				}
       
   565 			else
       
   566 				{
       
   567 				iMaxWdpRecvBuffer.Append(iRecvBuf);
       
   568 				if (iTruncated)
       
   569 					{
       
   570 					iImp->RecvFrom(iRecvRemoteHost, iRecvRemotePort, iRecvBuf, iTruncated, *iStatus, 0);
       
   571 					activate = 1;
       
   572 					if (!iMultiReadCancel)
       
   573 						{
       
   574 						SetState(EMutipleReceive);
       
   575 						}
       
   576 					else
       
   577 						{
       
   578 						INFO_PRINTF1(_L("Cancel Receive in EMutipleReceive state"));
       
   579 						iImp->CancelRecv();
       
   580 						SetState(EFinish);
       
   581 						}					
       
   582 					}
       
   583 				else
       
   584 					{
       
   585 					SetLastError(iStatus->Int());
       
   586 					iControl->ReStart();
       
   587 					SetState(EFinish);
       
   588 					}
       
   589 				}	
       
   590 			break;
       
   591 			
       
   592 		case EFinish:
       
   593 			INFO_PRINTF1(_L("EFinish"));
       
   594 			if(iStatus->Int() != KErrNone) 
       
   595 				{
       
   596 				SetLastError(iStatus->Int());
       
   597 				}
       
   598 			if(iMaxWdpRecvBuffer.Length())
       
   599 				{
       
   600 				INFO_PRINTF1(_L("Data received:"));
       
   601 				DumpBuf(iMaxWdpRecvBuffer);
       
   602 				}
       
   603 			verdict = (GetLastError() == GetExpectedError())?EPass:EFail;
       
   604 			if (verdict==EPass && !iMiddleCancel && !iMultiReadCancel && !iAwaitLengthCancel && !iAwaitLengthTwice)
       
   605 				{
       
   606 				iImp->CancelRecv();
       
   607 				if (verdict==EPass)
       
   608 					{
       
   609 					verdict = (iSendBuffPtr->Match(iMaxWdpRecvBuffer)!=KErrNotFound)?EPass:EFail;
       
   610 					}
       
   611 				if (verdict==EPass)
       
   612 					{
       
   613 					verdict = (iRemoteHost.Match(iRecvRemoteHost)!=KErrNotFound)?EPass:EFail;
       
   614 					}
       
   615 				if (verdict==EPass)
       
   616 					{
       
   617 					Wap::TPort port;
       
   618 					iImp->GetLocalPort(port);
       
   619 					verdict = (port == iLocalPort)?EPass:EFail;
       
   620 					}
       
   621 				if (verdict==EPass)
       
   622 					{
       
   623 					Wap::TBearer bearer;
       
   624 					iImp->GetBearer(bearer);
       
   625 					verdict = (bearer == iBearer)?EPass:EFail;
       
   626 					}
       
   627 				if (verdict==EPass)
       
   628 					{
       
   629 					//This test can not perform in SIMTSY.
       
   630 					HBufC8* buf;
       
   631 					iImp->GetLocalAddress(buf);
       
   632 					delete buf;
       
   633 					}
       
   634 				}
       
   635 			SetTestStepResult(verdict);
       
   636 			SetState(EIdle);
       
   637 			StopScheduler();
       
   638 			break;
       
   639 			
       
   640 		case EIdle:
       
   641 		default:
       
   642 			INFO_PRINTF1(_L("EIdle or unknown"));
       
   643 			INFO_PRINTF2(_L("Error: bad state %d, State = %d"), State());
       
   644 			SetTestStepResult(verdict);
       
   645 			StopScheduler();
       
   646 			
       
   647 			break;
       
   648 		}
       
   649 		return (activate);
       
   650 	}
       
   651 	
       
   652 CBoundWDPStep_5::CBoundWDPStep_5() 
       
   653 /**
       
   654 * Constructor
       
   655 */
       
   656 	{
       
   657 	}
       
   658 	
       
   659 CBoundWDPStep_5::~CBoundWDPStep_5() 
       
   660 /**
       
   661 * Destructor
       
   662 */
       
   663 	{
       
   664 	}
       
   665 	
       
   666 TVerdict CBoundWDPStep_5::doTestStepL()
       
   667 /** 
       
   668 *	Test Cancel
       
   669 */
       
   670 	{
       
   671 	INFO_PRINTF1(_L("BOUND-WDP: Testing Cancel"));
       
   672 	
       
   673 	if(TestStepResult() == EPass )
       
   674 		{
       
   675 		SetTestStepResult(EFail);
       
   676 		iImp = LoadInterface();
       
   677 		if(iImp)
       
   678 			{	
       
   679 			TInt bearer, port;
       
   680 			TInt error	= KErrNone;
       
   681 			TBool secure= EFalse;
       
   682 			TBool reconnect= EFalse;
       
   683 			SetLastError(KErrNone);
       
   684 				
       
   685 			if(GetIntFromConfig(ConfigSection(),KWapBearer, bearer)) iBearer = (Wap::TBearer)bearer;
       
   686 			if(GetIntFromConfig(ConfigSection(),KWapLocalPort, port)) iLocalPort = (Wap::TPort)port;
       
   687 			if(GetIntFromConfig(ConfigSection(), KWapExError, error)) SetExpectedError(error);
       
   688 			if(GetBoolFromConfig(ConfigSection(), KWapSecure, secure)) iSecure = secure;
       
   689 			if(GetBoolFromConfig(ConfigSection(),_L("Reconnect"), reconnect)) iReconnect = reconnect;
       
   690 				
       
   691 			error = iImp->Connect(iBearer, (Wap::TPort)iLocalPort, iSecure);
       
   692 			INFO_PRINTF2(_L("Connection completed with code = %d"), error);
       
   693 			if( error == KErrNone)
       
   694 				{
       
   695 				TPckg<TUint16> aDataSizePckg(0);
       
   696 				TRequestStatus reqStatus;
       
   697 				iImp->AwaitRecvDataSize(aDataSizePckg, reqStatus);
       
   698 				SetState(EAwaitSize);
       
   699 				ShowConnectionInfo();
       
   700 
       
   701 				StartScheduler();
       
   702 				iControl->ReStart();
       
   703 				if(reqStatus==KErrCancel)
       
   704 					{
       
   705 					SetTestStepResult(EPass);
       
   706 					}
       
   707 				}
       
   708 			}
       
   709 		}
       
   710 	return TestStepResult();
       
   711 	}
       
   712 	
       
   713 TInt CBoundWDPStep_5::CallStateMachine()
       
   714 	{
       
   715 
       
   716 	INFO_PRINTF2(_L("CallStateMachine: step [%d]"), State());
       
   717 	switch(iState)
       
   718 		{
       
   719 		case EAwaitSize:
       
   720 			INFO_PRINTF1(_L("EAwaitSize"));
       
   721 			iImp->CancelRecv();
       
   722 			SetState(EFinish);
       
   723 			iControl->ReStart();
       
   724 			break;
       
   725 		case EFinish:
       
   726 			INFO_PRINTF1(_L("EFinish"));
       
   727 			SetState(EIdle);
       
   728 			StopScheduler();
       
   729 			break;
       
   730 		case EIdle:
       
   731 		default:
       
   732 			INFO_PRINTF2(_L("Error: EIdle or unknown state %d"), State());
       
   733 			SetTestStepResult(EFail);
       
   734 			StopScheduler();
       
   735 			break;
       
   736 		}
       
   737 	return 0;
       
   738 	}
       
   739 	
       
   740 CBoundWDPStep_6::CBoundWDPStep_6()
       
   741 	{
       
   742 	}
       
   743 	
       
   744 CBoundWDPStep_6::~CBoundWDPStep_6() 
       
   745 	{
       
   746 	}
       
   747 
       
   748 TVerdict CBoundWDPStep_6::doTestStepL()
       
   749 //
       
   750 //Test the CBoundWDP APIs Time out.
       
   751 //
       
   752 	{
       
   753 	//Not in use
       
   754 	return TestStepResult();
       
   755 	}
       
   756 	
       
   757 TInt CBoundWDPStep_6::CallStateMachine()
       
   758 	{
       
   759 	return (0);
       
   760 	}
       
   761 	
       
   762 CBoundWDPStep_7::CBoundWDPStep_7()
       
   763 	{
       
   764 	}
       
   765 
       
   766 CBoundWDPStep_7::~CBoundWDPStep_7()
       
   767 	{
       
   768 	}
       
   769 
       
   770 TVerdict CBoundWDPStep_7::doTestStepL()
       
   771 //
       
   772 // Test wrong sequenece
       
   773 //
       
   774 	{
       
   775 	INFO_PRINTF1(_L("BOUND-WDP: Connect-Receive-Await-Await"));
       
   776 	if(TestStepResult() == EPass )
       
   777 		{
       
   778 		SetTestStepResult(EFail);
       
   779 		iImp = LoadInterface();
       
   780 		if(iImp)
       
   781 			{
       
   782 			SetLastError(KErrNone);
       
   783 			TInt bearer, port, bufLen;
       
   784 			TInt error = KErrNone;
       
   785 				
       
   786 			if(GetIntFromConfig(ConfigSection(),KWapBearer, bearer))
       
   787 				{
       
   788 				iBearer = static_cast<Wap::TBearer>(bearer);
       
   789 				}
       
   790 			if(GetIntFromConfig(ConfigSection(),KWapLocalPort, port))
       
   791 				{	
       
   792 				iLocalPort = static_cast<Wap::TPort>(port);
       
   793 				}
       
   794 			if(GetIntFromConfig(ConfigSection(),KWapExError, error))
       
   795 				{
       
   796 				SetExpectedError(error);
       
   797 				}
       
   798 			if(GetIntFromConfig(ConfigSection(),KWapWdpBufLength, bufLen))
       
   799 				{
       
   800 				iWdpRecvBufLength=static_cast<TUint16>(bufLen);
       
   801 				}
       
   802 			iRecvBuffPtr = HBufC8::NewL(iWdpRecvBufLength);
       
   803 			SetState(EConnect);
       
   804 			iControl->ReStart();
       
   805 			ShowConnectionInfo();
       
   806 			// Start state machine
       
   807 			StartScheduler();
       
   808 			UnloadInterface();
       
   809 			}
       
   810 		}
       
   811 	return TestStepResult();
       
   812 	}
       
   813 	
       
   814 TInt CBoundWDPStep_7::CallStateMachine()
       
   815 	{
       
   816 	TVerdict verdict = EFail;
       
   817 	TInt err = KErrNone;
       
   818 	TInt activate = 0;
       
   819 		
       
   820 	INFO_PRINTF2(_L("CallStateMachine: state [%d]"), State());
       
   821 	switch(iState)
       
   822 		{
       
   823 		case EConnect:
       
   824 			INFO_PRINTF1(_L("EConnect"));
       
   825 			err = iImp->Connect(iBearer, iLocalPort);
       
   826 			INFO_PRINTF2(_L("Connection completed with code = %d"), err);
       
   827 			if( err == KErrNone)
       
   828 				{
       
   829 //				WaitForInitializeL();
       
   830 				if(iRecvBuffPtr == NULL)
       
   831 					{
       
   832 					err=KErrNoMemory;
       
   833 					}
       
   834 				else
       
   835 					{
       
   836 					iRecvBuf.Set(iRecvBuffPtr->Des());
       
   837 					iImp->RecvFrom(iRecvRemoteHost, iRecvRemotePort, iRecvBuf, iTruncated, *iStatus, iTimeout);
       
   838 					SetState(EReceive);
       
   839 					activate = 1;
       
   840 					}
       
   841 				}
       
   842 			SetLastError(err);
       
   843 			if (err!=KErrNone)
       
   844 				{
       
   845 				SetState(EFinish);
       
   846 				iControl->ReStart();
       
   847 				}
       
   848 			break;
       
   849 				
       
   850 		case EReceive:
       
   851 			INFO_PRINTF1(_L("EReceive"));
       
   852 			SetLastError(iStatus->Int());
       
   853 			if(iStatus->Int() != KErrNone) 
       
   854 			// Receiving fails as expect
       
   855 				{
       
   856 				verdict = (GetLastError() == GetExpectedError())?EPass:EFail;
       
   857 				if (verdict==EPass)
       
   858 					{
       
   859 					INFO_PRINTF1(_L("Receiving failed as expect"));
       
   860 					TRequestStatus reqStatus;
       
   861 					iImp->AwaitRecvDataSize(iLength, reqStatus);
       
   862 					iImp->AwaitRecvDataSize(iLength, *iStatus);
       
   863 					activate = 1;
       
   864 					SetState(EAwaitSize);
       
   865 					}
       
   866 				else
       
   867 					{
       
   868 					INFO_PRINTF1(_L("Receiving failed not as expect"));
       
   869 					iControl->ReStart();
       
   870 					SetState(EFinish);
       
   871 					}
       
   872 				}
       
   873 			else
       
   874 				{	
       
   875 				INFO_PRINTF1(_L("Receiving succeed not as expect"));
       
   876 				iControl->ReStart();
       
   877 				SetState(EFinish);
       
   878 				}
       
   879 			break;
       
   880 				
       
   881 		case EAwaitSize:
       
   882 			INFO_PRINTF1(_L("EAwaitSize"));
       
   883 			SetLastError(iStatus->Int());
       
   884 			iImp->CancelRecv();
       
   885 			SetState(EFinish);
       
   886 			iControl->ReStart();
       
   887 			break;
       
   888 				
       
   889 		case EFinish:
       
   890 			INFO_PRINTF1(_L("EFinish"));
       
   891 			if(iStatus->Int() != KErrNone) 
       
   892 				{
       
   893 				SetLastError(iStatus->Int());
       
   894 				}
       
   895 			verdict = (GetLastError() == GetExpectedError())?EPass:EFail;
       
   896 			SetTestStepResult(verdict);
       
   897 			SetState(EIdle);
       
   898 			StopScheduler();
       
   899 			break;
       
   900 				
       
   901 		case EIdle:
       
   902 		default:
       
   903 			INFO_PRINTF1(_L("EIdle or unknown"));
       
   904 			INFO_PRINTF2(_L("Error: bad state %d, State = %d"), State());
       
   905 			SetTestStepResult(verdict);
       
   906 			StopScheduler();
       
   907 			break;
       
   908 		}
       
   909 	return (activate);
       
   910 	}
       
   911 	
       
   912 CBoundWDPStep_8::CBoundWDPStep_8() 
       
   913 	{
       
   914 	}
       
   915 
       
   916 CBoundWDPStep_8::~CBoundWDPStep_8() 
       
   917 	{
       
   918 	}
       
   919 
       
   920 TVerdict CBoundWDPStep_8::doTestStepL()
       
   921 /*
       
   922 *	Using invalid values for API parameters:
       
   923 *	- Invalid TUid on construction
       
   924 *	- Setting invalid timeout for RecvFrom
       
   925 *	Note: wrong bearer value has already been implemented as part of test 2
       
   926 */
       
   927 	{
       
   928 	INFO_PRINTF1(_L("BOUND-WDP: Wrong parameter values"));
       
   929 	if(TestStepResult() == EPass )
       
   930 		{
       
   931 		TInt error;
       
   932 		if(GetIntFromConfig(ConfigSection(),KWapExError2, error))
       
   933 			{
       
   934 			iExError2=error;
       
   935 			}
       
   936 		TInt trapValue;
       
   937 		TUid invalidInterfaceUid = {0x00000000}; 	
       
   938 		INFO_PRINTF2(_L("Calling new NewL(0x%08X) method"), invalidInterfaceUid);
       
   939 		TRAP(trapValue, iImp = CWapBoundDatagramService::NewL(invalidInterfaceUid));
       
   940 		TVerdict verdict = (trapValue == iExError2)?EPass:EFail;	
       
   941 		if (verdict==EPass)
       
   942 			{
       
   943 			INFO_PRINTF2(_L("CreateImplementation with wrong Uid- Failed as expected with error %d"),trapValue);
       
   944 			}
       
   945 		SetTestStepResult(verdict);
       
   946 		}
       
   947 	return TestStepResult();
       
   948 	}
       
   949 	
       
   950 TInt CBoundWDPStep_8::CallStateMachine()
       
   951 	{
       
   952 	return 0;
       
   953 	}
       
   954 	
       
   955 CBoundWDPStep_9::CBoundWDPStep_9() 
       
   956 	{
       
   957 	}
       
   958 
       
   959 CBoundWDPStep_9::~CBoundWDPStep_9() 
       
   960 	{
       
   961 	}
       
   962 
       
   963 TVerdict CBoundWDPStep_9::doTestStepL()
       
   964 	{
       
   965 	return TestStepResult();
       
   966 	}
       
   967 	
       
   968 TInt CBoundWDPStep_9::CallStateMachine()
       
   969 	{
       
   970 	return 0;
       
   971 	}
       
   972 	
       
   973 CBoundWDPStep_OutOfMemory::CBoundWDPStep_OutOfMemory() 
       
   974 	{
       
   975 	}
       
   976 
       
   977 CBoundWDPStep_OutOfMemory::~CBoundWDPStep_OutOfMemory() 
       
   978 	{
       
   979 	}
       
   980 
       
   981 TVerdict CBoundWDPStep_OutOfMemory::doTestStepL()
       
   982 	{
       
   983 	// to test fix for DEF117706: Memory leak in CWapBoundDatagramService::Connect under OOM
       
   984 	__UHEAP_MARK;
       
   985 
       
   986 	for(TInt i=1;; i++)
       
   987 		{
       
   988 		__UHEAP_FAILNEXT(i);
       
   989 
       
   990 		CWapBoundDatagramService* datServ = NULL;
       
   991 		TRAP_IGNORE(datServ = CWapBoundDatagramService::NewL());
       
   992 		if(datServ)
       
   993 			{
       
   994 			datServ->Connect(Wap::EAll, 7576);
       
   995 			delete datServ;
       
   996 			}		 
       
   997 		REComSession::FinalClose();
       
   998 
       
   999 		TInt* marker = new TInt(0);
       
  1000 		if (!marker)
       
  1001 			{
       
  1002 			break;		
       
  1003 			}
       
  1004 		delete marker;
       
  1005 		}
       
  1006 
       
  1007 	__UHEAP_MARKEND;	
       
  1008 	return TestStepResult();
       
  1009 	}
       
  1010 	
       
  1011 TInt CBoundWDPStep_OutOfMemory::CallStateMachine()
       
  1012 	{
       
  1013 	return 0;
       
  1014 	}