datacommsserver/esockserver/test/TE_Socket/SocketTestSection10.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2004-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 10
       
    15 //
       
    16 //
       
    17 
       
    18 // EPOC includes
       
    19 #include <e32base.h>
       
    20 #include <test/es_dummy.h>
       
    21 
       
    22 // Test system includes
       
    23 #include "SocketTestSection10.h"
       
    24 
       
    25 
       
    26 // Test step 10.1
       
    27 const TDesC& CSocketTest10_1::GetTestName()
       
    28 	{
       
    29 	_LIT(ret,"Test10.1");
       
    30 	return ret;
       
    31 	}
       
    32 
       
    33 enum TVerdict CSocketTest10_1::InternalDoTestStepL( void )
       
    34 	{
       
    35 	TVerdict verdict = EPass;
       
    36 	
       
    37 	Logger().WriteFormat(_L("Test Purpose: Shutdown with EStopOutput"));
       
    38 	
       
    39 	// connect to esock
       
    40 	Logger().WriteFormat(_L("Attempting to connect to socket server"));
       
    41     RSocketServ ss;
       
    42 	TInt ret = OptimalConnect(ss);
       
    43 	CleanupClosePushL(ss);
       
    44 	Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret));
       
    45 	TESTL(KErrNone == ret);
       
    46 	
       
    47 	Logger().WriteFormat(_L("Opening a socket on Dummy protocol 2"));
       
    48 	RSocket sk;
       
    49 	ret = sk.Open(ss, _L("Dummy Protocol 2"));
       
    50 	Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret));
       
    51 	TESTL(KErrNone == ret);
       
    52 	
       
    53 	Logger().WriteFormat(_L("Shutting down socket with EStopOutput"));
       
    54 	TRequestStatus shutStat;
       
    55 	TRequestStatus rstat;
       
    56 	sk.Shutdown(RSocket::EStopOutput, shutStat);
       
    57 	TESTL(KRequestPending == shutStat.Int());
       
    58 	
       
    59 	// Check we can still receive
       
    60 	Logger().WriteFormat(_L("Attempting to receive data"));
       
    61 	TSockXfrLength len;
       
    62 	TBuf8<6> buf;
       
    63 	TBuf<6> buf16;
       
    64 	sk.Recv(buf, 0, rstat, len);
       
    65 	User::WaitForRequest(rstat);
       
    66 	TESTL(KErrNone == rstat.Int());
       
    67 	buf16.Copy(buf);
       
    68 	Logger().WriteFormat(_L("Recv status %S, length %d, buf '%S'"), 
       
    69 		&EpocErrorToText(rstat.Int()), len(), &buf16);
       
    70 	TESTL(KErrNone == rstat.Int());
       
    71 	TESTL(_L8("End of") == buf);
       
    72 	TESTL(6 == len());
       
    73 	
       
    74 	// Check writing fails
       
    75 	Logger().WriteFormat(_L("Attempting to Send data"));
       
    76 	buf.SetLength(1);
       
    77 	sk.Send(buf, 0, rstat);
       
    78 	User::WaitForRequest(rstat);
       
    79 	Logger().WriteFormat(_L("Send status %S"), &EpocErrorToText(rstat.Int()));
       
    80 	TESTL(KErrNotReady == rstat.Int());
       
    81 	
       
    82 	Logger().WriteFormat(_L("Attempting to receive more data"));
       
    83 	sk.Recv(buf, 0, rstat, len);
       
    84 	User::WaitForRequest(rstat);
       
    85 	buf16.Copy(buf);
       
    86 	Logger().WriteFormat(_L("Recv status %S, length %d, buf '%S'"), 
       
    87 		&EpocErrorToText(rstat.Int()), len(), &buf16);
       
    88 	TESTL(KErrEof == rstat.Int());
       
    89 	TESTL(_L8(" Data") == buf);
       
    90 	TESTL(5 == len());
       
    91 	
       
    92 	Logger().WriteFormat(_L("Attempting to receive more data"));
       
    93 	sk.Recv(buf, 0, rstat, len);
       
    94 	User::WaitForRequest(rstat);
       
    95 	buf16.Copy(buf);
       
    96 	Logger().WriteFormat(_L("Recv status %S, length %d, buf '%S'"), 
       
    97 		&EpocErrorToText(rstat.Int()), len(), &buf16);
       
    98 	TESTL(KErrEof == rstat.Int());
       
    99 	TESTL(0 == buf.Length());
       
   100 	TESTL(0 == len());
       
   101 	
       
   102 	Logger().WriteFormat(_L("Closing socket"));
       
   103 	sk.Close(); // Should cancel shutStat
       
   104 	User::WaitForRequest(shutStat);
       
   105 	Logger().WriteFormat(_L("Shutdown status %S"), &EpocErrorToText(shutStat.Int()));
       
   106 	TESTL(KErrCancel == shutStat.Int());
       
   107 	
       
   108 	ss.Close();
       
   109 	
       
   110 	CleanupStack::Pop(&ss);
       
   111 	
       
   112 	SetTestStepResult(verdict);
       
   113 	return verdict;
       
   114 	}
       
   115 
       
   116 // Test step 10.2
       
   117 const TDesC& CSocketTest10_2::GetTestName()
       
   118 	{
       
   119 	_LIT(ret,"Test10.2");
       
   120 	return ret;
       
   121 	}
       
   122 
       
   123 enum TVerdict CSocketTest10_2::InternalDoTestStepL( void )
       
   124 	{
       
   125 	TVerdict verdict = EPass;
       
   126 	
       
   127 	Logger().WriteFormat(_L("Test Purpose: Shutdown"));
       
   128 	
       
   129 	// connect to esock
       
   130 	Logger().WriteFormat(_L("Attempting to connect to socket server"));
       
   131     RSocketServ ss;
       
   132 	TInt ret = OptimalConnect(ss);
       
   133 	CleanupClosePushL(ss);
       
   134 	Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret));
       
   135 	TESTL(KErrNone == ret);
       
   136 	
       
   137 	Logger().WriteFormat(_L("Opening a socket on Dummy protocol 2"));
       
   138 	RSocket sk;
       
   139 	ret = sk.Open(ss, _L("Dummy Protocol 2"));
       
   140 	Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret));
       
   141 	TESTL(KErrNone == ret);
       
   142 	
       
   143 	Logger().WriteFormat(_L("Shutting down socket with EStopInput"));
       
   144 	TRequestStatus shutStat;
       
   145 	TRequestStatus rstat;
       
   146 	sk.Shutdown(RSocket::EStopInput, shutStat);		// Dummy doesn't complete EStopInput
       
   147 	
       
   148 	// Check we can still send
       
   149 	Logger().WriteFormat(_L("Attempting to Send data"));
       
   150 	TBuf8<6> buf;
       
   151 	buf.SetLength(1);
       
   152 	sk.Send(buf, 0, rstat);
       
   153 	sk.CancelSend();
       
   154 	User::WaitForRequest(rstat);
       
   155 	Logger().WriteFormat(_L("Send status %S"), &EpocErrorToText(rstat.Int()));
       
   156 	TESTL(KErrNotReady == rstat.Int());
       
   157 	
       
   158 	// Check receiving fails
       
   159 	Logger().WriteFormat(_L("Attempting to Receive data"));
       
   160 	TSockXfrLength len;
       
   161 	sk.Recv(buf, 0, rstat, len);
       
   162 	User::WaitForRequest(rstat);
       
   163 	Logger().WriteFormat(_L("Recv status %S, length %d"), &EpocErrorToText(rstat.Int()), len());
       
   164 	TESTL(KErrEof == rstat.Int());
       
   165 	TESTL(0 == len());
       
   166 	
       
   167 	Logger().WriteFormat(_L("Closing socket"));
       
   168 	sk.Close(); // Should cancel shutStat
       
   169 	User::WaitForRequest(shutStat);
       
   170 	Logger().WriteFormat(_L("Shutdown status %S"), &EpocErrorToText(shutStat.Int()));
       
   171 	TESTL(KErrCancel == shutStat.Int());
       
   172 	
       
   173 	CleanupStack::Pop(&ss);
       
   174 	ss.Close();
       
   175 	
       
   176 	SetTestStepResult(verdict);
       
   177 	return verdict;
       
   178 	}
       
   179 	
       
   180 	// Test step 10.2
       
   181 	const TDesC& CSocketTest10_3::GetTestName()
       
   182 	{
       
   183 	_LIT(ret,"Test10.3");
       
   184 	return ret;
       
   185 	}
       
   186 	
       
   187 	enum TVerdict CSocketTest10_3::InternalDoTestStepL( void )
       
   188 	{
       
   189 	TVerdict verdict = EPass;
       
   190 	
       
   191 	Logger().WriteFormat(_L("Testing close before completion of accept on new socket"));
       
   192 	RSocketServ ss;
       
   193 	TInt ret=OptimalConnect(ss);
       
   194 	CleanupClosePushL(ss);
       
   195     TESTL(KErrNone == ret);	
       
   196     
       
   197 	Logger().WriteFormat(_L("Opening main socket by name"));             
       
   198 	RSocket sock, sock2;                                                    
       
   199 	ret=sock.Open(ss,_L("Dummy Protocol 2")); 
       
   200 	TESTL(KErrNone == ret);	
       
   201 	
       
   202 	Logger().WriteFormat(_L("Opening null socket"));  
       
   203 	ret=sock2.Open(ss); // null socket to accept onto                         
       
   204 	TESTL(KErrNone == ret);	
       
   205 	
       
   206 	TSockAddr addr;
       
   207 	Logger().WriteFormat(_L("Binding main socket"));
       
   208 	ret=sock.Bind(addr);
       
   209 	TESTL(KErrNone == ret);	
       
   210 	
       
   211 	Logger().WriteFormat(_L("Performing Listen"));
       
   212 	Logger().WriteFormat(_L("Listen"));             
       
   213 	ret=sock.Listen(5);
       
   214 	TESTL(KErrNone == ret);	
       
   215 	
       
   216 	Logger().WriteFormat(_L("Performing Accept"));             
       
   217 	TRequestStatus rstat;
       
   218 	sock.Accept(sock2, rstat);
       
   219 	TESTL(rstat.Int() == KRequestPending);	
       
   220 	
       
   221 	User::After(2 * 1000 * 1000);	// make sure accept processing has proceeded before closing the socket, otherwise
       
   222 									// we risk incurring a BadHandle panic from it (as seen on SMP testing)
       
   223 	
       
   224 	Logger().WriteFormat(_L("Closing new socket"));
       
   225 	sock2.Close();             
       
   226 
       
   227 	Logger().WriteFormat(_L("Attempting to simulate a connect and complete the accept"));             
       
   228 	//emulate en connect complete event
       
   229 	ret=sock.SetOpt(KDummyOptionSetConnectComplete,KIoctlDummyLevel,NULL);
       
   230 	TESTL(KErrNone == ret);	
       
   231 	User::WaitForRequest(rstat); //Just a wait to allow something to possibly go wrong
       
   232 	TESTL(rstat.Int() == KErrCancel);
       
   233 	
       
   234 	Logger().WriteFormat(_L("Opening null socket"));  
       
   235 	ret=sock2.Open(ss); // null socket to accept onto                         
       
   236 	TESTL(KErrNone == ret);	
       
   237 	
       
   238 	Logger().WriteFormat(_L("Performing Accept again"));           
       
   239 	sock.Accept(sock2, rstat);
       
   240 	TESTL(rstat.Int() == KRequestPending);	
       
   241 	
       
   242 	Logger().WriteFormat(_L("Attempting to simulate a connect and complete the accept"));             
       
   243 	//emulate en connect complete event
       
   244 	ret=sock.SetOpt(KDummyOptionSetConnectComplete,KIoctlDummyLevel,NULL);
       
   245 	TESTL(KErrNone == ret);	
       
   246 	User::WaitForRequest(rstat); //Just a wait to allow something to possibly go wrong
       
   247 	TESTL(rstat.Int() == KErrNone);		
       
   248 	
       
   249 	CleanupStack::Pop(&ss);
       
   250     ss.Close();
       
   251 	
       
   252 	SetTestStepResult(verdict);
       
   253 	return verdict;
       
   254 	}
       
   255