datacommsserver/esockserver/test/TE_ESock/EsockTestSection25.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 25
       
    15 // 
       
    16 //
       
    17 
       
    18 // EPOC includes
       
    19 #include <e32base.h>
       
    20 #include <in_sock.h>
       
    21 
       
    22 // Test system includes
       
    23 #include "EsockTestSection25.h"
       
    24 
       
    25 
       
    26 // Test step 25.1
       
    27 const TDesC& CEsockTest25_1::GetTestName()
       
    28 	{
       
    29 	// store the name of this test case
       
    30 	_LIT(ret,"Test25.1");
       
    31 	
       
    32 	return ret;
       
    33 	}
       
    34 
       
    35 CEsockTest25_1::~CEsockTest25_1()
       
    36 	{
       
    37 	}
       
    38 
       
    39 enum TVerdict CEsockTest25_1::easyTestStepL()
       
    40 	{
       
    41 	
       
    42 	TInetAddr addr;
       
    43 	THostName name;
       
    44 	TNameRecord hostent;
       
    45 	
       
    46 	Logger().WriteFormat(_L("TE_ESock: test 25.1"));
       
    47 	Logger().WriteFormat(_L("Lookup name in hosts file"));
       
    48 	
       
    49 	// Have to lookup a valid or invalid address to establish a csd connection so 
       
    50 	// Lookup returned address and lookup returned name below can be completed 
       
    51 	Logger().WriteFormat(_L("Lookup alias: a"));
       
    52 	GetHostByNameL(hostent, _L("a"));
       
    53 	
       
    54 	Logger().WriteFormat(_L("Lookup returned address"));
       
    55 	name = hostent.iName;
       
    56 	GetHostByNameL(hostent, name);
       
    57 	
       
    58 	Logger().WriteFormat(_L("Lookup returned name"));
       
    59 	addr = hostent.iAddr;
       
    60 	GetHostByAddrL(hostent, addr);
       
    61 	
       
    62 	return EPass;
       
    63 	}
       
    64 
       
    65 
       
    66 // Test step 25.2
       
    67 const TDesC& CEsockTest25_2::GetTestName()
       
    68 	{
       
    69 	// store the name of this test case
       
    70 	_LIT(ret,"Test25.2");
       
    71 	
       
    72 	return ret;
       
    73 	}
       
    74 
       
    75 CEsockTest25_2::~CEsockTest25_2()
       
    76 	{
       
    77 	}
       
    78 
       
    79 enum TVerdict CEsockTest25_2::easyTestStepL()
       
    80 	{
       
    81 	Logger().WriteFormat(_L("TE_ESock: test 25.2"));
       
    82 	Logger().WriteFormat(_L("Get Machine Name"));
       
    83 	
       
    84 	GetHostNameL();
       
    85 	
       
    86 	return EPass;
       
    87 	}
       
    88 
       
    89 
       
    90 // Test step 25.3
       
    91 const TDesC& CEsockTest25_3::GetTestName()
       
    92 	{
       
    93 	// store the name of this test case
       
    94 	_LIT(ret,"Test25.3");
       
    95 	
       
    96 	return ret;
       
    97 	}
       
    98 
       
    99 CEsockTest25_3::~CEsockTest25_3()
       
   100 	{
       
   101 	}
       
   102 
       
   103 enum TVerdict CEsockTest25_3::easyTestStepL()
       
   104 	{
       
   105 	TPtrC aPtrResult;
       
   106 	TInt bRet;
       
   107 	
       
   108 	Logger().WriteFormat(_L("TE_ESock: test 25.3"));
       
   109 	Logger().WriteFormat(_L("Get Machine Name"));
       
   110 	
       
   111 	bRet = GetStringFromConfig(_L("Test_25.3"), _L("sethostname"), aPtrResult);
       
   112 	if (!bRet)
       
   113 		{
       
   114 		// failed to find ipAddress
       
   115 		return EFail;
       
   116 		}
       
   117 	
       
   118 	GetHostNameL();
       
   119 	
       
   120 	// Synchronous
       
   121 	SetHostNameL(aPtrResult);
       
   122 	
       
   123 	GetHostNameL();
       
   124 	
       
   125 	return EPass;
       
   126 	}
       
   127 
       
   128 
       
   129 // Test step 25.4
       
   130 const TDesC& CEsockTest25_4::GetTestName()
       
   131 	{
       
   132 	// store the name of this test case
       
   133 	_LIT(ret,"Test25.4");
       
   134 	
       
   135 	return ret;
       
   136 	}
       
   137 
       
   138 CEsockTest25_4::~CEsockTest25_4()
       
   139 	{
       
   140 	}
       
   141 
       
   142 enum TVerdict CEsockTest25_4::easyTestStepL()
       
   143 	{
       
   144 	Logger().WriteFormat(_L("TE_ESock: test 25.4"));
       
   145 	Logger().WriteFormat(_L("Lookup name in hosts file and Cancel"));
       
   146 	
       
   147 	TNameRecord hostent;
       
   148 	TSockAddr iAddr;
       
   149 	
       
   150 	Logger().WriteFormat(_L("Lookup alias: a"));
       
   151 	GetHostByNameL(hostent, _L("a"));
       
   152 	iAddr=hostent.iAddr;
       
   153 	
       
   154 	Logger().WriteFormat(_L("Cancel Lookup returned address"));
       
   155 	GetHostByNameCancelL(hostent, _L("www.yahoo.com"));
       
   156 	
       
   157 	Logger().WriteFormat(_L("Lookup returned address"));
       
   158 	GetHostByNameL(hostent, _L("a") );
       
   159 	
       
   160 	TESTL( iAddr == hostent.iAddr );
       
   161 	
       
   162 	return EPass;
       
   163 	
       
   164 	}
       
   165 
       
   166 
       
   167 // Test step 25.5
       
   168 const TDesC& CEsockTest25_5::GetTestName()
       
   169 	{
       
   170 	// store the name of this test case
       
   171 	_LIT(ret,"Test25.5");
       
   172 	
       
   173 	return ret;
       
   174 	}
       
   175 
       
   176 CEsockTest25_5::~CEsockTest25_5()
       
   177 	{
       
   178 	}
       
   179 
       
   180 enum TVerdict CEsockTest25_5::easyTestStepL()
       
   181 	{
       
   182 	//
       
   183 	// Out Of Memory Test on open rhostresolver //
       
   184 	//
       
   185 
       
   186 	TVerdict verdict = EPass;
       
   187 
       
   188 	Logger().WriteFormat(_L("TE_ESock: test 25.5"));
       
   189 	Logger().WriteFormat(_L("RHostResolver Open"));
       
   190 
       
   191 #if defined (_DEBUG_SOCKET_FUNCTIONS)
       
   192 
       
   193 	// Open Socket Server
       
   194 	RSocketServ socketServer;
       
   195 	CleanupClosePushL(socketServer);
       
   196 	TInt ret = socketServer.Connect();
       
   197 	TESTEL(KErrNone == ret, ret);
       
   198 	
       
   199 	RHostResolver hr;
       
   200 	CleanupClosePushL(hr);
       
   201 	TInt failure=0;
       
   202 
       
   203 	verdict = EInconclusive;
       
   204 	TInt prevResult = KErrNoMemory;
       
   205 	TInt prevOccurs = 0;
       
   206 	while (EInconclusive == verdict)
       
   207 		{
       
   208 		socketServer.__DbgFailNext(failure++);
       
   209 		ret = hr.Open(socketServer, KAfInet, KProtocolInetUdp);
       
   210 		
       
   211 		if ((prevResult != ret) || (++prevOccurs >= 1000))
       
   212 			{
       
   213 			Logger().WriteFormat(_L("%d loop(s), open host resolver returned %d"), prevOccurs, prevResult);
       
   214 			if (KErrNone == ret)
       
   215 				{
       
   216 				verdict = EPass;
       
   217 				}
       
   218 			else if (KErrServerTerminated == ret)
       
   219 				{
       
   220 				verdict = EFail;
       
   221 				}
       
   222 			else if (prevResult != ret)
       
   223 				{
       
   224 				prevResult = ret;
       
   225 				prevOccurs = 1;
       
   226 				}
       
   227 			else
       
   228 				{
       
   229 				prevOccurs = 0;
       
   230 				}
       
   231 			}
       
   232 		};
       
   233 	
       
   234 	socketServer.__DbgFailNext(-1);
       
   235 	CleanupStack::PopAndDestroy(2, &socketServer);
       
   236 
       
   237 #else
       
   238 	Logger().WriteFormat(_L("Test disabled on release build."));
       
   239 #endif
       
   240 
       
   241     //-- check esock server's heap balance by shutting down the socket server
       
   242 	return verdict;
       
   243 	}
       
   244