datacommsserver/esockserver/test/TE_ESock/EsockTestSection4.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2001-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 // This contains ESock Test cases from section 4
       
    15 // 
       
    16 //
       
    17 
       
    18 // EPOC includes
       
    19 #include <e32base.h>
       
    20 #include <in_sock.h>
       
    21 
       
    22 // Test system includes
       
    23 #include "EsockTestSection4.h"
       
    24 
       
    25 
       
    26 // Test step 4.1
       
    27 const TDesC& CEsockTest4_1::GetTestName()
       
    28 	{
       
    29 	// store the name of this test case
       
    30 	_LIT(ret,"Test4.1");
       
    31 	
       
    32 	return ret;
       
    33 	}
       
    34 
       
    35 CEsockTest4_1::~CEsockTest4_1()
       
    36 	{
       
    37 	}
       
    38 
       
    39 enum TVerdict CEsockTest4_1::easyTestStepPreambleL()
       
    40 	{
       
    41 	if (iEsockSuite->GetSocketListCount() > 1)
       
    42 		{
       
    43 		CloseSockets();
       
    44 		}
       
    45 	
       
    46 	if (iEsockSuite->GetSocketListCount() < 1)
       
    47 		{
       
    48 		const TPtrC &sectName = SectionName(_L("Test_4.1"));
       
    49 		
       
    50 		// get size of listening queue
       
    51 		if (!GetIntFromConfig(sectName, _L("qSize"), iSize))
       
    52 			{
       
    53 			return EFail;
       
    54 			}
       
    55 		
       
    56 		// get local ip address
       
    57 		TInetAddr addrLocal;
       
    58 		if (!GetIpAddressFromConfig(sectName, _L("ipAddressLocal"), addrLocal))
       
    59 			{
       
    60 			return EFail;
       
    61 			}
       
    62 		
       
    63 		// get remote ip address
       
    64 		if (!GetIpAddressFromConfig(sectName, _L("ipAddressRemote"), iAddrRemote))
       
    65 			{
       
    66 			return EFail;
       
    67 			}
       
    68 
       
    69 		// get port number
       
    70 		if (!GetIntFromConfig(sectName, _L("port"), iPort))
       
    71 			{
       
    72 			return EFail;
       
    73 			}
       
    74 		
       
    75 		// set port number
       
    76 		iAddrRemote.SetPort(iPort);
       
    77 		
       
    78 		// open socket and listen for connect requests
       
    79 		TInt nRet = OpenListeningSocketL(addrLocal, iSockIndex, iPort, iSize);
       
    80 		if (KErrNone != nRet)
       
    81 			{
       
    82 			if (KErrServerTerminated == nRet)
       
    83 				{
       
    84 				User::Leave(EFail);
       
    85 				}
       
    86 			return EFail;
       
    87 			}
       
    88 		}
       
    89 	
       
    90 	return EPass;
       
    91 	}
       
    92 
       
    93 enum TVerdict CEsockTest4_1::easyTestStepL()
       
    94 	{
       
    95 	TESTL(EPass == TestStepResult());
       
    96 
       
    97 	// open <nSize> active sockets
       
    98 	TInt sockIndexIgnore;  // socket index - returned value we can ignore
       
    99 	for (TInt n = 0; n < iSize; n++)
       
   100 		{
       
   101 		TESTL(KErrNone == OpenActiveSocketL(iAddrRemote, sockIndexIgnore, iPort));
       
   102 		}
       
   103 	
       
   104 	// open another active socket
       
   105 	RSocket sock1;
       
   106 	CleanupClosePushL(sock1);
       
   107 	TInt nRet = sock1.Open(iEsockSuite->iSocketServer, KAfInet,KSockStream, KProtocolInetTcp);
       
   108 	TESTEL(KErrNone == nRet, nRet);
       
   109 	
       
   110 	// add socket to list
       
   111 	sockIndexIgnore=iEsockSuite->AddSocketToListL(sock1);
       
   112 	CleanupStack::Pop();
       
   113 	
       
   114 	// make connect request
       
   115 	TRequestStatus stat;
       
   116 	sock1.Connect(iAddrRemote, stat);
       
   117 	User::WaitForRequest(stat);
       
   118 	nRet = stat.Int();
       
   119 	TESTEL(KErrTimedOut == nRet, nRet);
       
   120 	
       
   121 	// accept one of the outstanding requests
       
   122 	TESTL(KErrNone == AcceptConnectionL(sockIndexIgnore, iSockIndex));
       
   123 	
       
   124 	// make another connect request
       
   125 	TESTL(KErrNone == OpenActiveSocketL(iAddrRemote, sockIndexIgnore, iPort));
       
   126 	
       
   127 	// accept one of the outstanding requests
       
   128 	TESTL(KErrNone == AcceptConnectionL(sockIndexIgnore, iSockIndex));
       
   129 	
       
   130 	return EPass;
       
   131 	}
       
   132 
       
   133 
       
   134 // Test step 4.2
       
   135 const TDesC& CEsockTest4_2::GetTestName()
       
   136 	{
       
   137 	// store the name of this test case
       
   138 	_LIT(ret,"Test4.2");
       
   139 	
       
   140 	return ret;
       
   141 	}
       
   142 
       
   143 CEsockTest4_2::~CEsockTest4_2()
       
   144 	{
       
   145 	}
       
   146 
       
   147 enum TVerdict CEsockTest4_2::easyTestStepPreambleL()
       
   148 	{
       
   149 	if (iEsockSuite->GetSocketListCount() < 1)
       
   150 		{
       
   151 		const TPtrC &sectName = SectionName(_L("Test_4.2"));
       
   152 		// get local ip address
       
   153 		TInetAddr addrLocal, addrRemote;
       
   154 		if (!GetIpAddressFromConfig(sectName, _L("ipAddressLocal"), addrLocal))
       
   155 			{
       
   156 			return EFail;
       
   157 			}
       
   158 		
       
   159 		// get ip address to connect to (usually loopback)
       
   160 		if (!GetIpAddressFromConfig(sectName, _L("ipAddressRemote"), addrRemote))
       
   161 			{
       
   162 			return EFail;
       
   163 			}
       
   164 		
       
   165 		// get port number
       
   166 		TInt port;
       
   167 		if (!GetIntFromConfig(sectName, _L("port"), port))
       
   168 			{
       
   169 			return EFail;
       
   170 			}
       
   171 		
       
   172 		// open socket and listen for connect requests
       
   173 		TInt nRet = OpenListeningSocketL(addrLocal, iSockIndex, port);
       
   174 		if (KErrNone != nRet)
       
   175 			{
       
   176 			if (KErrServerTerminated == nRet)
       
   177 				{
       
   178 				User::Leave(EFail);
       
   179 				}
       
   180 			return EFail;
       
   181 			}
       
   182 		}
       
   183 
       
   184 	return EPass;
       
   185 	}
       
   186 
       
   187 enum TVerdict CEsockTest4_2::easyTestStepL()
       
   188 	{
       
   189 	TESTL(EPass == TestStepResult());
       
   190 	
       
   191 	// open active socket and make connect request
       
   192 	// by not doing this allow time for the CancelAccept() after the Accept() below
       
   193 	// TESTL(OpenActiveSocketL(addrRemote, sockIndexIgnore, port));
       
   194 
       
   195 	// open a blank socket
       
   196 	RSocket sock;
       
   197 	CleanupClosePushL(sock);
       
   198 	TInt nRet = sock.Open(iEsockSuite->iSocketServer);
       
   199 	TESTEL(KErrNone == nRet, nRet);
       
   200 	
       
   201 	// accept a connection on the listening socket
       
   202 	TRequestStatus stat;
       
   203 	iEsockSuite->GetSocketHandle(iSockIndex).Accept(sock, stat);
       
   204 	
       
   205 	// cancel the accept before completion
       
   206 	iEsockSuite->GetSocketHandle(iSockIndex).CancelAccept();
       
   207 	
       
   208 	User::WaitForRequest(stat);
       
   209 	nRet = stat.Int();
       
   210 	TESTEL(KErrCancel == nRet, nRet);
       
   211 
       
   212 	CleanupStack::PopAndDestroy();
       
   213 	return EPass;
       
   214 	}
       
   215