datacommsserver/esockserver/test/TE_Socket/SocketTestSection5.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 5
       
    15 // 
       
    16 //
       
    17 
       
    18 // EPOC includes
       
    19 #include <e32base.h>
       
    20 #include <es_sock.h>
       
    21 #include <ss_std.h>
       
    22 #include <test/es_dummy.h>
       
    23 
       
    24 // Test system includes
       
    25 #include "SocketTestSection5.h"
       
    26 
       
    27 
       
    28 // Test step 5.1
       
    29 const TDesC& CSocketTest5_1::GetTestName()
       
    30 	{
       
    31 	_LIT(ret,"Test5.1");
       
    32 	return ret;
       
    33 	}
       
    34 
       
    35 enum TVerdict CSocketTest5_1::InternalDoTestStepL( void )
       
    36 	{
       
    37 	TVerdict verdict = EPass;
       
    38 	
       
    39 	Logger().WriteFormat(_L("Test Purpose: Memory Leak opening bad socket"));
       
    40 	
       
    41 #if defined(_DEBUG_SOCKET_FUNCTIONS)
       
    42 	
       
    43 	// connect to esock
       
    44 	Logger().WriteFormat(_L("Attempting to connect to socket server"));
       
    45     RSocketServ ss;
       
    46 	TInt ret = OptimalConnect(ss);
       
    47 	CleanupClosePushL(ss);
       
    48 	Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret));
       
    49 	TESTL(KErrNone == ret);
       
    50 	
       
    51 	// open a bad socket
       
    52     Logger().WriteFormat(_L("Attempting to create bad socket type with heap checking"));
       
    53 	//	ss.__DbgMarkHeap();		// in ESOCKMT leak checking is best done by shutting down the server
       
    54 	RSocket sock;
       
    55     ret = sock.Open(ss, 0, 0, 0);
       
    56 	//	ss.__DbgMarkEnd(0);
       
    57 	Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret));
       
    58 	TESTL(KErrBadName == ret);
       
    59 	
       
    60 	CleanupStack::Pop(&ss);
       
    61 	ss.Close();
       
    62 #else
       
    63 	Logger().WriteFormat(_L("TestDisabled on release build."));
       
    64 	verdict = EInconclusive;
       
    65 #endif
       
    66 	
       
    67 	SetTestStepResult(verdict);
       
    68 	return verdict;
       
    69 	}
       
    70 
       
    71 
       
    72 // Test step 5.2
       
    73 const TDesC& CSocketTest5_2::GetTestName()
       
    74 	{
       
    75 	_LIT(ret,"Test5.2");
       
    76 	return ret;
       
    77 	}
       
    78 
       
    79 enum TVerdict CSocketTest5_2::InternalDoTestStepL( void )
       
    80 	{
       
    81 	TVerdict verdict = EPass;
       
    82 	
       
    83 	Logger().WriteFormat(_L("Test Purpose: Memory Leak connecting to server and disconnecting from server"));
       
    84 	
       
    85 #if defined(_DEBUG_SOCKET_FUNCTIONS)
       
    86 	// connect to esock
       
    87 	Logger().WriteFormat(_L("Main thread : Attempting to connect to socket server"));
       
    88     RSocketServ ss;
       
    89 	TInt ret = OptimalConnect(ss);
       
    90 	CleanupClosePushL(ss);
       
    91 	Logger().WriteFormat(_L("Main Thread : Connect returned %S"), &EpocErrorToText(ret));
       
    92 	TESTL(KErrNone == ret);
       
    93 	
       
    94 	Logger().WriteFormat(_L("Main thread : Creating semaphore for threads"));
       
    95 	RSemaphore s;
       
    96 	s.CreateLocal(0);
       
    97 	RThread t;
       
    98 	
       
    99 	TSocketThreadArg tArg;
       
   100 	tArg.iHandle = this;
       
   101 	tArg.iSem  = &s;
       
   102 	tArg.iNumSockets = 0;
       
   103 	
       
   104 	// try connect and close in separate thread
       
   105 	Logger().WriteFormat(_L("Main thread : Creating sub thread to connect"));
       
   106 	//	ss.__DbgMarkHeap();		// in ESOCKMT leak checking is best done by shutting down the server
       
   107 	t.Create(_L("socketThread2"), ConnectThread, KDefaultStackSize, KDefaultHeapSize, KDefaultHeapSize, &tArg);
       
   108 	t.Resume();
       
   109 	s.Wait();
       
   110 	t.Close();
       
   111 	//	ss.__DbgMarkEnd(0);
       
   112 	Logger().WriteFormat(_L("Main thread : Connect thread completed"));
       
   113 	
       
   114 	CleanupStack::Pop(&ss);
       
   115 	ss.Close();
       
   116 #else
       
   117 	Logger().WriteFormat(_L("TestDisabled on release build."));
       
   118 	verdict = EInconclusive;
       
   119 #endif
       
   120 	
       
   121 	SetTestStepResult(verdict);
       
   122 	return verdict;
       
   123 	}
       
   124 
       
   125 // Test step 5.3
       
   126 const TDesC& CSocketTest5_3::GetTestName()
       
   127 	{
       
   128 	_LIT(ret,"Test5.3");
       
   129 	return ret;
       
   130 	}
       
   131 
       
   132 enum TVerdict CSocketTest5_3::InternalDoTestStepL( void )
       
   133 	{
       
   134 	TVerdict verdict = EPass;
       
   135 	
       
   136 	Logger().WriteFormat(_L("Test Purpose: Memory Leak killing thread with open resources"));
       
   137 	
       
   138 #if defined(_DEBUG_SOCKET_FUNCTIONS)
       
   139 	// connect to esock
       
   140 	Logger().WriteFormat(_L("Main thread : Attempting to connect to socket server"));
       
   141     RSocketServ ss;
       
   142 	TInt ret = OptimalConnect(ss);
       
   143 	CleanupClosePushL(ss);
       
   144 	Logger().WriteFormat(_L("Main Thread : Connect returned %S"), &EpocErrorToText(ret));
       
   145 	TESTL(KErrNone == ret);
       
   146 	
       
   147 	Logger().WriteFormat(_L("Main thread : Creating semaphore for threads"));
       
   148 	RSemaphore s;
       
   149 	s.CreateLocal(0);
       
   150 	
       
   151 	// try create in separate thread and kill it
       
   152 	Logger().WriteFormat(_L("Main Thread : Creating sub thread to create sockets and resolvers"));
       
   153 	//	ss.__DbgMarkHeap();		// in ESOCKMT leak checking is best done by shutting down the server
       
   154 	TSocketThreadArg a;
       
   155 	a.iHandle = this;
       
   156 	a.iSem = &s;
       
   157 	a.iNumSockets = 1;
       
   158 	RThread t2;
       
   159 	t2.Create(_L("socketThread3"), SocketThread, KDefaultStackSize, KDefaultHeapSize, KDefaultHeapSize, &a);
       
   160 	t2.Resume();
       
   161 	s.Wait();
       
   162 	Logger().WriteFormat(_L("Main Thread : Killing Create sub thread"));
       
   163 	t2.Kill(KErrNone);
       
   164 	t2.Close();
       
   165 	
       
   166 	Logger().WriteFormat(_L("Main Thread : Waiting 100ms for thread to clear up"));
       
   167 	User::After(100000);
       
   168 	//	ss.__DbgMarkEnd(0);
       
   169 	Logger().WriteFormat(_L("Main Thread : Create thread completed"));
       
   170 	
       
   171 	CleanupStack::Pop(&ss);
       
   172 	ss.Close();
       
   173 #else
       
   174 	Logger().WriteFormat(_L("TestDisabled on release build."));
       
   175 	verdict = EInconclusive;
       
   176 #endif
       
   177 	
       
   178 	SetTestStepResult(verdict);
       
   179 	return verdict;
       
   180 	}
       
   181 
       
   182 // Test step 5.4
       
   183 const TDesC& CSocketTest5_4::GetTestName()
       
   184 	{
       
   185 	_LIT(ret,"Test5.4");
       
   186 	return ret;
       
   187 	}
       
   188 
       
   189 enum TVerdict CSocketTest5_4::InternalDoTestStepL( void )
       
   190 	{
       
   191 	TVerdict verdict = EPass;
       
   192 	
       
   193 	Logger().WriteFormat(_L("Test Purpose: Memory Leak Getting Protocol Info and Opening Socket"));
       
   194 	
       
   195 #if defined(_DEBUG_SOCKET_FUNCTIONS)
       
   196 	// connect to esock
       
   197 	Logger().WriteFormat(_L("Attempting to connect to socket server"));
       
   198     RSocketServ ss;
       
   199 	TInt ret = OptimalConnect(ss);
       
   200 	CleanupClosePushL(ss);
       
   201 	Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret));
       
   202 	TESTL(KErrNone == ret);
       
   203 	
       
   204 	// NumProtocols and GetProtocolInfo
       
   205 	Logger().WriteFormat(_L("Try NumProtocols"));
       
   206 	//	ss.__DbgMarkHeap();		// in ESOCKMT leak checking is best done by shutting down the server
       
   207 	TUint numProtocols;
       
   208 	ret = ss.NumProtocols(numProtocols);
       
   209 	Logger().WriteFormat(_L("NumProtocols returned %S, number %d"), 
       
   210 		&EpocErrorToText(ret), numProtocols);
       
   211 	TESTL(KErrNone == ret);
       
   212 	//	ss.__DbgMarkEnd(0);
       
   213 	
       
   214 	Logger().WriteFormat(_L("Trying GetProtocolInfo until Dummy Protocol 1 is found"));
       
   215 	//	ss.__DbgMarkHeap();		// in ESOCKMT leak checking is best done by shutting down the server
       
   216 	TProtocolDesc protoInfo;
       
   217 	TUint aIndex;
       
   218 	TBool aFound = false;
       
   219 	for (aIndex=1;aIndex<=numProtocols;aIndex++) {
       
   220 		ret = ss.GetProtocolInfo(aIndex, protoInfo);
       
   221 		TESTL(KErrNone == ret || KErrCannotFindProtocol == ret);
       
   222 		if (protoInfo.iName ==_L("Dummy Protocol 1")){
       
   223 			aFound = true;
       
   224 			break;
       
   225 			}
       
   226 		}
       
   227 	//	ss.__DbgMarkEnd(0);
       
   228 	if (!aFound) {
       
   229 		Logger().WriteFormat(_L("Could not find Dummy Protocol 1"));
       
   230 		return EFail;
       
   231 		}
       
   232 	
       
   233 	Logger().WriteFormat(_L("Trying socket Open to load protocol"));
       
   234 	RSocket sock;
       
   235 	ret = sock.Open(ss, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol);
       
   236 	Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret));
       
   237 	TESTL(KErrNone == ret);
       
   238 	sock.Close();
       
   239 	
       
   240 	Logger().WriteFormat(_L("Trying socket Open with Heap checking"));
       
   241 	//	ss.__DbgMarkHeap();		// in ESOCKMT leak checking is best done by shutting down the server
       
   242 	RSocket sock1;
       
   243 	ret = sock1.Open(ss, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol);
       
   244 	Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret));
       
   245 	TESTL(KErrNone == ret);
       
   246 	sock1.Close();
       
   247 	//	ss.__DbgMarkEnd(0);
       
   248 	
       
   249 	CleanupStack::Pop(&ss);
       
   250 	ss.Close();
       
   251 #else
       
   252 	Logger().WriteFormat(_L("TestDisabled on release build."));
       
   253 	verdict = EInconclusive;
       
   254 #endif
       
   255 	
       
   256 	SetTestStepResult(verdict);
       
   257 	return verdict;
       
   258 	}
       
   259 
       
   260 
       
   261 // Test step 5.5
       
   262 const TDesC& CSocketTest5_5::GetTestName()
       
   263 	{
       
   264 	_LIT(ret,"Test5.5");
       
   265 	return ret;
       
   266 	}
       
   267 
       
   268 enum TVerdict CSocketTest5_5::InternalDoTestStepL( void )
       
   269 	{
       
   270 	TVerdict verdict = EPass;
       
   271 	
       
   272 	Logger().WriteFormat(_L("Test Purpose: Validating leak detection upon shutdown"));
       
   273 	
       
   274 #if defined(_DEBUG_SOCKET_FUNCTIONS)
       
   275 	// connect to esock
       
   276 	Logger().WriteFormat(_L("Attempting to connect to socket server"));
       
   277     RSocketServ ss;
       
   278 	TInt ret = OptimalConnect(ss);
       
   279 	CleanupClosePushL(ss);
       
   280 	Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret));
       
   281 	TESTL(KErrNone == ret);
       
   282 	
       
   283 	Logger().WriteFormat(_L("Open a socket on Dummy Protocol 1"));
       
   284 	RSocket sock;
       
   285 	ret = sock.Open(ss,_L("Dummy Protocol 1"));
       
   286 	Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret));
       
   287 	TESTL(KErrNone == ret);
       
   288 
       
   289 	sock.SetOpt(KDummyOptionLeakMemory, 4);
       
   290 	sock.Close();
       
   291 	
       
   292 	CleanupStack::PopAndDestroy(&ss);
       
   293 #else
       
   294 	Logger().WriteFormat(_L("TestDisabled on release build."));
       
   295 	verdict = EInconclusive;
       
   296 #endif
       
   297 	
       
   298 	SetTestStepResult(verdict);
       
   299 	return verdict;
       
   300 	}
       
   301 
       
   302 
       
   303