testexecmdw/tef/tef/workshop/demoipsuite/src/tcpstep.cpp
branchRCL_3
changeset 3 9397a16b6eb8
parent 1 6edeef394eb7
equal deleted inserted replaced
1:6edeef394eb7 3:9397a16b6eb8
     1 /*
       
     2 * Copyright (c) 2005-2009 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:  
       
    15 * Example CTestStep derived implementation
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 /**
       
    22  @file TCPStep.cpp
       
    23 */
       
    24 #include "tcpstep.h"
       
    25 #include "ipsuitedefs.h"
       
    26 
       
    27 CTCPStep::~CTCPStep()
       
    28 /**
       
    29  * Destructor
       
    30  */
       
    31 	{
       
    32 	}
       
    33 
       
    34 CTCPStep::CTCPStep()
       
    35 /**
       
    36  * Constructor
       
    37  */
       
    38 	{
       
    39 	// **MUST** call SetTestStepName in the constructor as the controlling
       
    40 	// framework uses the test step name immediately following construction to set
       
    41 	// up the step's unique logging ID.
       
    42 	SetTestStepName(KDemoTCPStep);
       
    43 	}
       
    44 
       
    45 TVerdict CTCPStep::doTestStepL()
       
    46 /**
       
    47  * @return - TVerdict code
       
    48  * Override of base class pure virtual
       
    49  * Our implementation only gets called if the base class doTestStepPreambleL() did
       
    50  * not leave. That being the case, the current test result value will be EPass.
       
    51  */
       
    52 	{
       
    53 	RSocket socket;
       
    54 	User::LeaveIfError(socket.Open(iServer, KAfInet, KSockStream, KProtocolInetTcp));
       
    55 	CleanupClosePushL(socket);
       
    56 
       
    57 	TRequestStatus status;
       
    58 	socket.Connect(iDestAddr,status);
       
    59 	User::WaitForRequest(status);
       
    60 	User::LeaveIfError(status.Int());
       
    61 	
       
    62 	TBuf<50> IPAddrBuf;
       
    63 	iDestAddr.Output(IPAddrBuf);
       
    64 	_LIT(KSendDataMessage,"Send Data to %S Port = %d Length = %d");
       
    65 	INFO_PRINTF4(KSendDataMessage,&IPAddrBuf,iDestAddr.Port(),iWriteData->Des().Length());
       
    66 	
       
    67 	TPtr8 writeDataDes(iWriteData->Des());
       
    68 	socket.Write(writeDataDes,status);
       
    69 	User::WaitForRequest(status);
       
    70 	User::LeaveIfError(status.Int());
       
    71 
       
    72 	// For TCP only. We can check to see if the server has the ACK'd the data using
       
    73 	// an Ioctl on the socket
       
    74 	socket.Ioctl(KIoctlTcpNotifyDataSent,status, 0, KSolInetTcp);
       
    75 	User::WaitForRequest(status);
       
    76 	User::LeaveIfError(status.Int());
       
    77 
       
    78 	_LIT(KSentDataMessage,"Data Sent");
       
    79 	INFO_PRINTF1(KSentDataMessage);
       
    80 
       
    81 	// Use Recv in this case
       
    82 	// The status is not completed until the descriptor is full
       
    83 	// or there is a socket error/timeout -22
       
    84 	TPtr8 readDataDes(iReadData->Des());
       
    85 	socket.Recv(readDataDes,0,status);
       
    86 	User::WaitForRequest(status);
       
    87 	User::LeaveIfError(status.Int());
       
    88 
       
    89 	_LIT(KRecvDataMessage,"Data Received Length = %d");
       
    90 	INFO_PRINTF2(KRecvDataMessage,readDataDes.Length());
       
    91 
       
    92 	// The receive data should always match the sent
       
    93 	// Try deliberately corrupting the send or receive descriptor and
       
    94 	// the panic will be picked up in the script engine
       
    95 	__ASSERT_ALWAYS(readDataDes == writeDataDes,User::Panic(KDemoIPSuitePanic,ETCPDataCorrupt));
       
    96 
       
    97 	socket.Close();
       
    98 
       
    99 	CleanupStack::Pop(1);			// Server and Socket Handles
       
   100 	
       
   101 	return TestStepResult();
       
   102 	}