datacommsserver/esockserver/test/TE_EsockTestSteps/src/Sockets.TestSteps.cpp
changeset 0 dfb7c4ff071f
child 1 21d2ab05f085
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2006-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 //
       
    15 
       
    16 /**
       
    17  @file Sockets.TestSteps.cpp
       
    18 */
       
    19 
       
    20 #include "Sockets.TestSteps.h"
       
    21 #include "SocketServer.TestSteps.h"
       
    22 #include "Connections.TestSteps.h"
       
    23 #include "SubConnections.TestSteps.h"
       
    24 
       
    25 #include <utf.h>
       
    26 
       
    27 
       
    28 // Open Socket
       
    29 //------------
       
    30 
       
    31 COpenRSocketStep::COpenRSocketStep(CCEsockTestBase*& aEsockTest)
       
    32 :   CTe_EsockStepBase(aEsockTest)
       
    33 	{
       
    34 	SetTestStepName(KOpenRSocketStep);
       
    35 	}
       
    36 
       
    37 TInt COpenRSocketStep::ConfigureFromIni()
       
    38 	{
       
    39 	iParams.Reset();
       
    40 	
       
    41 	// Read in appropriate fields
       
    42 	if((GetStringFromConfig(iSection, KTe_SocketName, iParams.iSocketName) != 1)
       
    43 		|| (iParams.iSocketName.Length() == 0))
       
    44 		{
       
    45 		INFO_PRINTF1(_L("Couldn't find appropriate field in config file"));
       
    46 		return KErrNotFound;
       
    47 		}
       
    48 		
       
    49     if (GetStringFromConfig(iSection,KTe_SocketServName,iParams.iSockServName)!=1)
       
    50         {
       
    51         INFO_PRINTF2(_L("%S: Socket server name missing."),&iParams.iSocketName);
       
    52         return KErrNotFound;
       
    53         }
       
    54 
       
    55     if ((GetStringFromConfig(iSection,KTe_ConnectionName,iParams.iConnectionName)==1)
       
    56     	&& iParams.iConnectionName.Length()>0)
       
    57         {
       
    58         INFO_PRINTF2(_L("%S: connection name found - opening with RConnection."),&iParams.iSocketName);
       
    59         }
       
    60     else if ((GetStringFromConfig(iSection,KTe_SubConnectionName,iParams.iSubconnectionName)==1)
       
    61     	&& iParams.iSubconnectionName.Length()>0)
       
    62         {
       
    63         INFO_PRINTF2(_L("%S: subconnection name found - opening with RSubConnection."),&iParams.iSocketName);
       
    64         }
       
    65     else
       
    66         {
       
    67         INFO_PRINTF2(_L("%S: connection or subconnection names missing - opening implicit."),&iParams.iSocketName);
       
    68         }
       
    69 
       
    70 	if (GetStringFromConfig(iSection,KTe_ProtocolName,iParams.iProtocolName)==1)
       
    71         {
       
    72         INFO_PRINTF2(_L("%S: Protocol name found."),&iParams.iProtocolName);
       
    73         }
       
    74 	else
       
    75 		{
       
    76 	    TPtrC protocol;
       
    77 	    if (GetStringFromConfig(iSection,KTe_Protocol,protocol)!=1)
       
    78         {
       
    79 	        INFO_PRINTF2(_L("%S: Protocol missing."),&iParams.iSocketName);
       
    80         	return KErrNotFound;
       
    81         }
       
    82 
       
    83 	    if (protocol.Compare(KTe_TCPName)==0)
       
    84 		    { iParams.iProtocol = KProtocolInetTcp; iParams.iSocketType = KSockStream; }
       
    85 	    else if (protocol.Compare(KTe_UDPName)==0)
       
    86 		    { iParams.iProtocol = KProtocolInetUdp; iParams.iSocketType = KSockDatagram; }
       
    87 	    else if (protocol.Compare(KDummyProtocolName)==0)
       
    88 		    {
       
    89 			iParams.iProtocol = KProtocolInetDummy;
       
    90 			iParams.iSocketType = KSockDatagram;
       
    91 			}
       
    92 	    else
       
    93 	        {
       
    94 	        INFO_PRINTF3(_L("%S: Protocol (%S) not recognised."),&iParams.iSocketName,&protocol);
       
    95 	        return KErrNotFound;
       
    96 	        }
       
    97         }
       
    98 
       
    99     // All ok if we got this far
       
   100     return KErrNone;
       
   101 	}
       
   102 
       
   103 TVerdict COpenRSocketStep::doSingleTestStep()
       
   104 	{
       
   105     TInt error = iEsockTest->OpenSocket(iParams);
       
   106     if (error!=KErrNone)
       
   107         {
       
   108         INFO_PRINTF2(_L("Could not open socket (%S)."),&iParams.iSocketName);
       
   109         INFO_PRINTF2(_L("Error: %d."),error);
       
   110 		SetTestStepError(error); 
       
   111 		return EFail;
       
   112         }
       
   113 	return EPass;
       
   114 	}
       
   115 
       
   116 
       
   117 // Close Socket
       
   118 //-------------
       
   119 
       
   120 CCloseRSocketStep::CCloseRSocketStep(CCEsockTestBase*& aEsockTest)
       
   121 :   CTe_EsockStepBase(aEsockTest)
       
   122 	{
       
   123 	SetTestStepName(KCloseRSocketStep);
       
   124 	}
       
   125 
       
   126 TInt CCloseRSocketStep::ConfigureFromIni()
       
   127 	{
       
   128 	iSocketName.Set(KNullDesC);
       
   129 
       
   130 	if((GetStringFromConfig(iSection, KTe_SocketName, iSocketName) != 1)
       
   131 		|| (iSocketName.Length() == 0))
       
   132 		{
       
   133 		INFO_PRINTF1(_L("Couldn't find appropriate field in config file"));
       
   134 		return KErrNotFound;
       
   135 		}
       
   136 		
       
   137     // All ok if we got this far
       
   138     return KErrNone;
       
   139 	}
       
   140 
       
   141 TVerdict CCloseRSocketStep::doSingleTestStep()
       
   142 	{
       
   143     TInt error = iEsockTest->CloseSocket(iSocketName);
       
   144     if (error!=KErrNone)
       
   145         {
       
   146         INFO_PRINTF2(_L("Could not close socket (%S)."),&iSocketName);
       
   147         INFO_PRINTF2(_L("Error: %d."),error);
       
   148         return EFail;
       
   149         }
       
   150 	return EPass;
       
   151 	}
       
   152 
       
   153 
       
   154 // Create Socket
       
   155 //--------------
       
   156 
       
   157 CCreateRSocketStep::CCreateRSocketStep(CCEsockTestBase*& aEsockTest)
       
   158 :   CTe_EsockStepBase(aEsockTest)
       
   159 	{
       
   160 	SetTestStepName(KCreateRSocketStep);
       
   161 	}
       
   162 
       
   163 TVerdict CCreateRSocketStep::doTestStepPreambleL()
       
   164 	{
       
   165 	SetTestStepResult(EFail);
       
   166 
       
   167 	if (iEsockTest==NULL)
       
   168 	    iEsockTest = new (ELeave) CCEsockTestBase;
       
   169 
       
   170 	SetTestStepResult(EPass);
       
   171 	return TestStepResult();
       
   172 	}
       
   173 
       
   174 TInt CCreateRSocketStep::ConfigureFromIni()
       
   175 	{
       
   176 	iParams.Reset();
       
   177 	
       
   178 	// Read in appropriate fields
       
   179 	if((GetStringFromConfig(iSection, KTe_SocketName, iParams.iSocketName) != 1)
       
   180 		|| (iParams.iSocketName.Length() == 0))
       
   181 		{
       
   182 		INFO_PRINTF1(_L("Couldn't find appropriate field in config file"));
       
   183 		return KErrNotFound;
       
   184 		}
       
   185 		
       
   186     // All ok if we got this far
       
   187     return KErrNone;
       
   188 	}
       
   189 
       
   190 TVerdict CCreateRSocketStep::doSingleTestStep()
       
   191 	{
       
   192     TInt error = iEsockTest->CreateSocket(iParams.iSocketName);
       
   193     if (error!=KErrNone)
       
   194         {
       
   195         INFO_PRINTF2(_L("Could not create socket (%S)."),&iParams.iSocketName);
       
   196         INFO_PRINTF2(_L("Error: %d."),error);
       
   197         return EFail;
       
   198         }
       
   199 	return EPass;
       
   200     }
       
   201 
       
   202 
       
   203 // Connect Socket
       
   204 //---------------
       
   205 
       
   206 CConnectRSocketStep::CConnectRSocketStep(CCEsockTestBase*& aEsockTest)
       
   207 :   CTe_EsockStepBase(aEsockTest)
       
   208 	{
       
   209 	SetTestStepName(KConnectRSocketStep);
       
   210 	}
       
   211 
       
   212 TInt CConnectRSocketStep::ConfigureFromIni()
       
   213 	{
       
   214 	iParams.Reset();
       
   215 	
       
   216 	// Read in appropriate fields
       
   217 	if((GetStringFromConfig(iSection, KTe_SocketName, iParams.iSocketName) != 1)
       
   218 		|| (iParams.iSocketName.Length() == 0))
       
   219 		{
       
   220 		INFO_PRINTF1(_L("Couldn't find appropriate field in config file"));
       
   221 		return KErrNotFound;
       
   222 		}
       
   223 		
       
   224     TPtrC protocol;
       
   225 	if (GetStringFromConfig(iSection,KTe_Protocol,protocol)!=1)
       
   226         {
       
   227         INFO_PRINTF2(_L("%S: Protocol missing."),&iParams.iSocketName);
       
   228         return KErrNotFound;
       
   229         }
       
   230 
       
   231     if (protocol.Compare(KTe_TCPName)==0)
       
   232 	    { iParams.iProtocol = KProtocolInetTcp; }
       
   233     else if (protocol.Compare(KTe_UDPName)==0)
       
   234 	    { iParams.iProtocol = KProtocolInetUdp; }
       
   235 	else if (protocol.Compare(KDummyProtocolName)==0)
       
   236 		{
       
   237 		iParams.iProtocol = KProtocolInetDummy;
       
   238 		}
       
   239     else
       
   240         {
       
   241         INFO_PRINTF3(_L("%S: Protocol (%S) not recognised."),&iParams.iSocketName,&protocol);
       
   242         return KErrNotFound;
       
   243         }
       
   244 
       
   245 	// IP Address Local
       
   246 	if (GetIpAddressFromConfig(iSection,KTe_SourceAddressName,iParams.iLocalIP)!=1)
       
   247         {
       
   248         INFO_PRINTF2(_L("%S: Local address missing."),&iParams.iSocketName);
       
   249         //return KErrNotFound;  // Source Address is not mandatory always.
       
   250         }
       
   251 
       
   252 	// IP Address Remote
       
   253 	if (GetIpAddressFromConfig(iSection,KTe_DestinationAddressName,iParams.iRemoteIP)!=1)
       
   254         {
       
   255         INFO_PRINTF2(_L("%S: Remote address missing."),&iParams.iSocketName);
       
   256         return KErrNotFound;
       
   257         }
       
   258 
       
   259 	// Port Number Local
       
   260     TInt portLocal;
       
   261 	if (GetIntFromConfig(iSection,KTe_SourcePortName,portLocal)!=1)
       
   262         {
       
   263         portLocal = 0;
       
   264         INFO_PRINTF2(_L("%S: Source port missing. Defaulting to unassigned (port=0)."), &iParams.iSocketName);
       
   265         }
       
   266     iParams.iLocalIP.SetPort(portLocal);
       
   267 
       
   268 	// Port Number
       
   269 	// Port Number Remote
       
   270     TInt port;
       
   271 	if (GetIntFromConfig(iSection,KTe_DestinationPortName,port)!=1)
       
   272         {
       
   273         INFO_PRINTF2(_L("%S: Remote port missing."),&iParams.iSocketName);
       
   274         return KErrNotFound;
       
   275         }
       
   276 
       
   277 	// Attach the port number to remote IP
       
   278 	iParams.iRemoteIP.SetPort(port);
       
   279 	
       
   280     iCancelFlag = EFalse;
       
   281     GetBoolFromConfig(iSection,KTe_ImmediateCancelFlagName,iCancelFlag);
       
   282 
       
   283     // All ok if we got this far
       
   284     return KErrNone;
       
   285 	}
       
   286 
       
   287 TVerdict CConnectRSocketStep::doSingleTestStep()
       
   288 	{
       
   289     TRequestStatus reqStat;
       
   290     TInt error = iEsockTest->ConnectSocket(iParams,reqStat);
       
   291     if (error!=KErrNone)
       
   292         {
       
   293         INFO_PRINTF2(_L("Could not connect socket (%S)."),&iParams.iSocketName);
       
   294         INFO_PRINTF2(_L("Error: %d."),error);
       
   295         SetTestStepResult(EFail);
       
   296         }
       
   297 	else
       
   298 		{
       
   299 		if (iCancelFlag)
       
   300 			{
       
   301 	        error = iEsockTest->CancelConnectSocket(iParams);
       
   302 	        if (error!=KErrNone)
       
   303 		        {
       
   304                 INFO_PRINTF2(_L("Could not cancel connecting socket (%S)."),&iParams.iSocketName);
       
   305                 INFO_PRINTF2(_L("Error: %d."),error);
       
   306 				SetTestStepResult(EFail);
       
   307 				}
       
   308 			}
       
   309 		User::WaitForRequest(reqStat);
       
   310 	    if (reqStat.Int()!=KErrNone)
       
   311 		    {
       
   312             INFO_PRINTF2(_L("Could not connect socket (%S)."),&iParams.iSocketName);
       
   313             INFO_PRINTF2(_L("Error: %d."),error);
       
   314 	        SetTestStepResult(EFail);
       
   315 	        }
       
   316 		}
       
   317 	return TestStepResult();
       
   318 	}
       
   319 
       
   320 
       
   321 // Send Receive on Socket
       
   322 //-----------------------
       
   323 _LIT(KPayloadColour, "PayloadColour");
       
   324 
       
   325 CSendReceiveRSocketStep::CSendReceiveRSocketStep(CCEsockTestBase*& aEsockTest)
       
   326 :   CTe_EsockStepBase(aEsockTest)
       
   327 	{
       
   328 	SetTestStepName(KSendReceiveRSocketStep);
       
   329 	}
       
   330 
       
   331 TInt CSendReceiveRSocketStep::ConfigureFromIni()
       
   332 	{
       
   333 	iParams.Reset();
       
   334 	
       
   335 	// Read in appropriate fields
       
   336 	if((GetStringFromConfig(iSection, KTe_SocketName, iParams.iSocketName) != 1)
       
   337 		|| (iParams.iSocketName.Length() == 0))
       
   338 		{
       
   339 		INFO_PRINTF1(_L("Couldn't find appropriate field in config file"));
       
   340 		return KErrNotFound;
       
   341 		}
       
   342 		
       
   343 	if (GetIntFromConfig(iSection,KTe_PacketSizeName,iParams.iPacketSize)!=1)
       
   344         {
       
   345         INFO_PRINTF2(_L("%S: Packet size missing."),&iParams.iSocketName);
       
   346         return KErrNotFound;
       
   347         }
       
   348 
       
   349     if (GetIntFromConfig(iSection,KTe_NrOfPacketsName,iParams.iNrOfPackets)!=1)
       
   350         {
       
   351         INFO_PRINTF2(_L("%S: Nr of packets missing."),&iParams.iSocketName);
       
   352         return KErrNotFound;
       
   353         }
       
   354 
       
   355     TPtrC protocol;
       
   356 	if (GetStringFromConfig(iSection,KTe_Protocol,protocol)!=1)
       
   357         {
       
   358         INFO_PRINTF2(_L("%S: Protocol missing."),&iParams.iSocketName);
       
   359         return KErrNotFound;
       
   360         }
       
   361 
       
   362     if (protocol.Compare(KTe_TCPName)==0)
       
   363 	    { iParams.iProtocol = KProtocolInetTcp; }
       
   364     else if (protocol.Compare(KTe_UDPName)==0)
       
   365 	    { iParams.iProtocol = KProtocolInetUdp; }
       
   366 	else if (protocol.Compare(KDummyProtocolName)==0)
       
   367 		{
       
   368 		iParams.iProtocol = KProtocolInetDummy;
       
   369 		}
       
   370     else
       
   371         {
       
   372         INFO_PRINTF3(_L("%S: Protocol (%S) not recognised."),&iParams.iSocketName,&protocol);
       
   373         return KErrNotFound;
       
   374         }
       
   375 
       
   376 	// OPTIONAL: colouring data by access point Id
       
   377 	iParams.iPayloadColouringIsEnabled = EFalse;
       
   378 	if (GetIntFromConfig(iSection, KPayloadColour, iParams.iPayloadColour) == 1)
       
   379 		{
       
   380 		if((iParams.iPayloadColour < 0) || (iParams.iPayloadColour > 255))
       
   381 			{
       
   382 			INFO_PRINTF2(_L("Payload colour out of range. Must be (0 <= x <= 255)."), iParams.iPayloadColour);
       
   383 	        return KErrArgument;
       
   384 			}
       
   385 		else if (iParams.iProtocol != KProtocolInetUdp)
       
   386 			{
       
   387 			INFO_PRINTF2(_L("Payload colouring only available on UDP sockets."), iParams.iPayloadColour);
       
   388 	        return KErrArgument;
       
   389 			}
       
   390 		else
       
   391 			{
       
   392 			// All good
       
   393 			iParams.iPayloadColouringIsEnabled = ETrue;
       
   394 			INFO_PRINTF2(_L("Payload colouring enabled. payloadColour:%d"), iParams.iPayloadColour);
       
   395 			}
       
   396 		}
       
   397 
       
   398     // All ok if we got this far
       
   399     return KErrNone;
       
   400 	}
       
   401 
       
   402 TVerdict CSendReceiveRSocketStep::doSingleTestStep()
       
   403 	{
       
   404     TRAPD(error,iEsockTest->SendAndReceiveDataL(iParams));
       
   405     SetTestStepError(error);
       
   406 
       
   407     if (error!=KErrNone)
       
   408         {
       
   409         INFO_PRINTF2(_L("Could not send/receive on socket (%S)."),&iParams.iSocketName);
       
   410         INFO_PRINTF2(_L("Error: %d."),error);
       
   411         return EFail;
       
   412         }
       
   413 	return EPass;
       
   414 	}
       
   415 
       
   416 
       
   417 
       
   418 // Add Socket to SubConnection
       
   419 //----------------------------
       
   420 
       
   421 CAddRSocketToRSubConnectionStep::CAddRSocketToRSubConnectionStep(CCEsockTestBase*& aEsockTest)
       
   422 :   CTe_EsockStepBase(aEsockTest)
       
   423 	{
       
   424 	SetTestStepName(KAddRSocketToRSubConnectionStep);
       
   425 	}
       
   426 
       
   427 TInt CAddRSocketToRSubConnectionStep::ConfigureFromIni()
       
   428 	{
       
   429 	iParams.Reset();
       
   430 
       
   431 	// Read in appropriate fields
       
   432 	if((GetStringFromConfig(iSection, KTe_SocketName, iParams.iSocketName) != 1)
       
   433 		|| (iParams.iSocketName.Length() == 0))
       
   434 		{
       
   435 		INFO_PRINTF1(_L("Couldn't find appropriate field in config file"));
       
   436 		return KErrNotFound;
       
   437 		}
       
   438 
       
   439     if (GetStringFromConfig(iSection,KTe_SubConnectionName,iParams.iSubConnectionName)!=1
       
   440         || iParams.iSubConnectionName.Length()==0)
       
   441             {
       
   442             INFO_PRINTF2(_L("%S: SubConnection name missing."),&iParams.iSocketName);
       
   443             return KErrNotFound;
       
   444             }
       
   445 
       
   446     // All ok if we got this far
       
   447     return KErrNone;
       
   448 	}
       
   449 
       
   450 TVerdict CAddRSocketToRSubConnectionStep::doSingleTestStep()
       
   451 	{
       
   452     TRequestStatus reqStat;
       
   453     TInt error = iEsockTest->AddSocketToSubConnection(iParams,reqStat);
       
   454     if (error!=KErrNone)
       
   455         {
       
   456         INFO_PRINTF3(_L("Could not add socket (%S) to subconnection (%S)."),&iParams.iSocketName,&iParams.iSubConnectionName);
       
   457         INFO_PRINTF2(_L("Error: %d."),error);
       
   458         return EFail;
       
   459         }
       
   460 
       
   461 	User::WaitForRequest(reqStat);
       
   462 	error = reqStat.Int();
       
   463 	if (error!=KErrNone)
       
   464 		{
       
   465 		INFO_PRINTF3(_L("Could not add socket (%S) to subconnection (%S)."),&iParams.iSocketName,&iParams.iSubConnectionName);
       
   466         INFO_PRINTF2(_L("Error: %d."),error);
       
   467 	    return EFail;
       
   468 		}
       
   469 	return EPass;
       
   470 	}
       
   471 
       
   472 
       
   473 // Add Socket to SubConnection without calling User::WaitForRequest
       
   474 // Tests PDEF134595
       
   475 //----------------------------
       
   476 
       
   477 CAddRSocketToRSubConNoWaitStep::CAddRSocketToRSubConNoWaitStep(CCEsockTestBase*& aEsockTest)
       
   478 :   CTe_EsockStepBase(aEsockTest)
       
   479     {
       
   480     SetTestStepName(KAddRSocketToRSubConNoWaitStep);
       
   481     }
       
   482 
       
   483 TInt CAddRSocketToRSubConNoWaitStep::ConfigureFromIni()
       
   484     {
       
   485     //clean parameters from previous runs
       
   486     iParams.Reset();
       
   487 
       
   488     if (GetStringFromConfig(iSection, KTe_SocketName, iParams.iSocketName) != 1
       
   489         || iParams.iSocketName.Length()==0)
       
   490             return KErrNotFound;
       
   491     
       
   492     if (GetStringFromConfig(iSection,KTe_SubConnectionName,iParams.iSubConnectionName)!=1
       
   493         || iParams.iSubConnectionName.Length()==0)
       
   494             {
       
   495             INFO_PRINTF2(_L("%S: SubConnection name missing."),&iParams.iSocketName);
       
   496             return KErrNotFound;
       
   497             }
       
   498 
       
   499     return KErrNone;
       
   500     }
       
   501 
       
   502 TVerdict CAddRSocketToRSubConNoWaitStep::doSingleTestStep()
       
   503     {
       
   504         TRequestStatus reqStat,reqStat2;
       
   505         TInt error;
       
   506         error = iEsockTest->AddSocketToSubConnection(iParams, reqStat);
       
   507         if (error != KErrNone)
       
   508             {
       
   509             INFO_PRINTF2(_L("Could not add socket (%d)!"), error);
       
   510             SetTestStepResult(EFail);
       
   511             }
       
   512         return TestStepResult();
       
   513     }
       
   514 
       
   515 
       
   516 // Add Socket to SubConnection (OOM)
       
   517 //----------------------------------
       
   518 
       
   519 CAddRSocketToRSubConnectionOOMStep::CAddRSocketToRSubConnectionOOMStep(CCEsockTestBase*& aEsockTest)
       
   520 :   CTe_EsockStepBase(aEsockTest)
       
   521 	{
       
   522 	SetTestStepName(KAddRSocketToRSubConnectionOOMStep);
       
   523 	}
       
   524 
       
   525 TInt CAddRSocketToRSubConnectionOOMStep::ConfigureFromIni()
       
   526 	{
       
   527 	iParams.Reset();
       
   528 
       
   529 	// Read in appropriate fields
       
   530 	if((GetStringFromConfig(iSection, KTe_SocketName, iParams.iSocketName) != 1)
       
   531 		|| (iParams.iSocketName.Length() == 0))
       
   532 		{
       
   533 		INFO_PRINTF1(_L("Couldn't find appropriate field in config file"));
       
   534 		return KErrNotFound;
       
   535 		}
       
   536 
       
   537     if (GetStringFromConfig(iSection, KTe_SubConnectionName, iParams.iSubConnectionName)!=1
       
   538         || iParams.iSubConnectionName.Length()==0)
       
   539 		{
       
   540 		INFO_PRINTF2(_L("%S: SubConnection name missing."), &iParams.iSocketName);
       
   541 		return KErrNotFound;
       
   542 		}
       
   543 		
       
   544     if (GetStringFromConfig(iSection,KTe_SocketServName,iParams.iSockServName)!=1
       
   545         || iParams.iSockServName.Length()==0)
       
   546         {
       
   547         INFO_PRINTF2(_L("%S: Socket server name missing."),&iParams.iSockServName);
       
   548         return KErrNotFound;
       
   549         }
       
   550 		
       
   551 
       
   552     // All ok if we got this far
       
   553     return KErrNone;
       
   554 	}
       
   555 
       
   556 TInt CAddRSocketToRSubConnectionOOMStep::AddSocketToSubConnectionOOM()
       
   557 	{
       
   558 	TInt errorAddingSocket = KErrNoMemory;
       
   559 	TInt errorRemovingSocket;
       
   560 	TBool errorNextWillFail = iEsockTest->__DbgCheckFailNext(iParams.iSockServName);
       
   561 	TRequestStatus reqStatus;
       
   562 
       
   563 	for (TInt j = 1; !errorNextWillFail; ++j)
       
   564 		{		
       
   565 		INFO_PRINTF3(_L("CCEsockTestBase::__DbgCheckFailNext() returned (%d) in  OOM Loop (%d)..."), errorNextWillFail, j);	
       
   566 		iEsockTest->__DbgFailNext(iParams.iSockServName, j);
       
   567 
       
   568 		iEsockTest->AddSocketToSubConnection(iParams, reqStatus);
       
   569 		User::WaitForRequest(reqStatus);
       
   570 		errorAddingSocket = reqStatus.Int();
       
   571 		INFO_PRINTF3(_L("RSubConnection::AddSocket() returned (%d) in OOM loop (%d)..."), errorAddingSocket, j);  
       
   572 		
       
   573 		if (errorAddingSocket == KErrNone)
       
   574 			{
       
   575 			iEsockTest->RemoveSocketFromSubConnection(iParams, reqStatus);
       
   576 			User::WaitForRequest(reqStatus);
       
   577 			errorRemovingSocket = reqStatus.Int();
       
   578 			INFO_PRINTF3(_L("RSubConnection::RemoveSocket() returned (%d) in OOM loop (%d)..."), errorRemovingSocket, j);  
       
   579 			
       
   580 			// Reset the "FailNext" flag in iEsockTest
       
   581 			iEsockTest->__DbgFailNext(iParams.iSockServName, -1);
       
   582 			return KErrNone;
       
   583 			}
       
   584 
       
   585 		errorNextWillFail = iEsockTest->__DbgCheckFailNext(iParams.iSockServName);
       
   586 		}
       
   587 
       
   588 	INFO_PRINTF2(_L("CCEsockTestBase::__DbgCheckFailNext() returned (%d). OOM Loop Finished."), errorNextWillFail);	
       
   589 
       
   590 	// Reset the "FailNext" flag in iEsockTest
       
   591 	iEsockTest->__DbgFailNext(iParams.iSockServName, -1);
       
   592 
       
   593 	return errorAddingSocket;
       
   594 	}
       
   595 
       
   596 TVerdict CAddRSocketToRSubConnectionOOMStep::doSingleTestStep()
       
   597 	{
       
   598     TInt error = AddSocketToSubConnectionOOM();
       
   599     if (error != KErrNoMemory && error != KErrNone)
       
   600         {
       
   601         INFO_PRINTF3(_L("Could not add socket (%S) to subconnectiont (%S)."),&iParams.iSocketName,&iParams.iSubConnectionName);
       
   602         INFO_PRINTF2(_L("Error: %d."),error);
       
   603         return EFail;
       
   604         }
       
   605 	return EPass;
       
   606 	}
       
   607 
       
   608 
       
   609 // Remove Socket from SubConnection
       
   610 //---------------------------------
       
   611 
       
   612 CRemoveRSocketFromRSubConnectionStep::CRemoveRSocketFromRSubConnectionStep(CCEsockTestBase*& aEsockTest)
       
   613 :   CTe_EsockStepBase(aEsockTest)
       
   614 	{
       
   615 	SetTestStepName(KRemoveRSocketFromRSubConnectionStep);
       
   616 	}
       
   617 
       
   618 TInt CRemoveRSocketFromRSubConnectionStep::ConfigureFromIni()
       
   619     {
       
   620 	//clean parameters from previous runs
       
   621 	iParams.Reset();
       
   622 
       
   623     if (GetStringFromConfig(iSection,KTe_SocketName,iParams.iSocketName)!=1
       
   624         || iParams.iSocketName.Length()==0)
       
   625             return KErrNotFound;
       
   626 
       
   627     if (GetStringFromConfig(iSection,KTe_SubConnectionName,iParams.iSubConnectionName)!=1
       
   628         || iParams.iSubConnectionName.Length()==0)
       
   629             {
       
   630             INFO_PRINTF2(_L("%S: SubConnection name missing."),&iParams.iSocketName);
       
   631             return KErrNotFound;
       
   632             }
       
   633 
       
   634     return KErrNone;
       
   635     }
       
   636 
       
   637 TVerdict CRemoveRSocketFromRSubConnectionStep::doSingleTestStep()
       
   638 	{
       
   639     TRequestStatus reqStat;
       
   640     TInt error = iEsockTest->RemoveSocketFromSubConnection(iParams,reqStat);
       
   641     if (error!=KErrNone)
       
   642         {
       
   643         INFO_PRINTF3(_L("Could not remove socket (%S) from subconnection (%S)."),&iParams.iSocketName,&iParams.iSubConnectionName);
       
   644         INFO_PRINTF2(_L("Error: %d."),error);
       
   645         return EFail;
       
   646         }
       
   647 
       
   648 	User::WaitForRequest(reqStat);
       
   649 	error = reqStat.Int();
       
   650 	if (error!=KErrNone)
       
   651 		{
       
   652         INFO_PRINTF3(_L("Could not remove socket (%S) from subconnection (%S)."),&iParams.iSocketName,&iParams.iSubConnectionName);
       
   653         INFO_PRINTF2(_L("Error: %d."),error);
       
   654 	    return EFail;
       
   655 		}
       
   656 	return EPass;
       
   657 	}
       
   658 
       
   659 
       
   660 // Remove Socket from SubConnection (OOM)
       
   661 //---------------------------------------
       
   662 
       
   663 CRemoveRSocketFromRSubConnectionOOMStep::CRemoveRSocketFromRSubConnectionOOMStep(CCEsockTestBase*& aEsockTest)
       
   664 :   CTe_EsockStepBase(aEsockTest)
       
   665 	{
       
   666 	SetTestStepName(KRemoveRSocketFromRSubConnectionOOMStep);
       
   667 	}
       
   668 
       
   669 TInt CRemoveRSocketFromRSubConnectionOOMStep::ConfigureFromIni()
       
   670     {
       
   671 	//clean parameters from previous runs
       
   672 	iParams.Reset();
       
   673 
       
   674     if (GetStringFromConfig(iSection, KTe_SocketName, iParams.iSocketName)!=1
       
   675         || iParams.iSocketName.Length()==0)
       
   676             return KErrNotFound;
       
   677 
       
   678     if (GetStringFromConfig(iSection,KTe_SubConnectionName,iParams.iSubConnectionName)!=1
       
   679         || iParams.iSubConnectionName.Length()==0)
       
   680             {
       
   681             INFO_PRINTF2(_L("%S: SubConnection name missing."),&iParams.iSocketName);
       
   682             return KErrNotFound;
       
   683             }
       
   684 
       
   685     return KErrNone;
       
   686     }
       
   687 
       
   688 
       
   689 TInt CRemoveRSocketFromRSubConnectionOOMStep::RemoveSocketFromSubConnectionOOM()
       
   690 	{
       
   691 	TInt error = KErrNoMemory;
       
   692 	for (TInt j = 1; error == KErrNoMemory; j++)
       
   693 		{
       
   694 		TRequestStatus status;
       
   695 #ifdef _DEBUG
       
   696 		iEsockTest->__DbgFailNext(iParams.iSockServName, j);
       
   697 #endif
       
   698 		iEsockTest->RemoveSocketFromSubConnection(iParams,status);
       
   699 		User::WaitForRequest(status);
       
   700 		error = status.Int();
       
   701 		INFO_PRINTF2(_L("Error = (%d)!."),error);
       
   702 
       
   703 		if (error != KErrNoMemory && error != KErrNone)
       
   704 			{
       
   705 			INFO_PRINTF2(_L("RSubConnection::RemoveSocket() failed in OOM (%d)!.."),error);
       
   706 			SetTestStepResult(EFail);
       
   707 			}
       
   708 		}
       
   709 #ifdef _DEBUG
       
   710 	iEsockTest->__DbgFailNext(iParams.iSockServName, -1);
       
   711 #endif
       
   712 	return error;
       
   713 	}
       
   714 
       
   715 TVerdict CRemoveRSocketFromRSubConnectionOOMStep::doSingleTestStep()
       
   716 	{
       
   717     TInt error = RemoveSocketFromSubConnectionOOM();
       
   718     if (error!=KErrNone)
       
   719         {
       
   720         INFO_PRINTF2(_L("Could not remove socket from subconnection (%S)."),&iParams.iSubConnectionName);
       
   721         INFO_PRINTF2(_L("Error: %d."),error);
       
   722         return EFail;
       
   723         }
       
   724 	return EPass;
       
   725 	}
       
   726 
       
   727 
       
   728 // Move Connected Socket
       
   729 //----------------------
       
   730 
       
   731 CmoveConnectedSocketToSubconnectionStep::CmoveConnectedSocketToSubconnectionStep(CCEsockTestBase*& aEsockTest)
       
   732 :   CTe_EsockStepBase(aEsockTest)
       
   733 	{
       
   734 	SetTestStepName(KmoveConnectedSocketToSubconnectionStep);
       
   735 	}
       
   736 
       
   737 TVerdict CmoveConnectedSocketToSubconnectionStep::doTestStepPreambleL()
       
   738 	{
       
   739 	SetTestStepResult(EFail);
       
   740 
       
   741 	if (iEsockTest==NULL)
       
   742 		{
       
   743 		iEsockTest = new (ELeave) CCEsockTestBase;
       
   744 		}
       
   745 	SetTestStepResult(EPass);
       
   746 	return TestStepResult();
       
   747 	}
       
   748 
       
   749 TInt CmoveConnectedSocketToSubconnectionStep::ConfigureFromIni()
       
   750  	{
       
   751  	// This test configures itself
       
   752  	return KErrNone;
       
   753     }
       
   754 
       
   755 TVerdict CmoveConnectedSocketToSubconnectionStep::doSingleTestStep()
       
   756 	{
       
   757 	
       
   758 	RSocket			socket;
       
   759 	TInetAddr		dstAddr;
       
   760 	RSocketServ		socketServer;
       
   761 	RConnection		conn;
       
   762 	RSubConnection	subconn;
       
   763 	TRequestStatus	status;
       
   764 	TRequestStatus 	eventStatus;
       
   765 	TNotificationEventBuf	subconnNotifBuf;
       
   766 	TInt				ret;
       
   767 	
       
   768 	CleanupClosePushL(socketServer);
       
   769    	CleanupClosePushL(conn);
       
   770     	CleanupClosePushL(socket);
       
   771     	CleanupClosePushL(subconn);
       
   772 
       
   773     	// Connect to ESOCK
       
   774     	ret = socketServer.Connect();
       
   775     	if (ret != KErrNone)
       
   776     		{
       
   777     		INFO_PRINTF2(_L("Failed to connect toEsock due to Error: %d."),ret);
       
   778     		return EFail;
       
   779     		}
       
   780   
       
   781         	// Open a connection
       
   782     	ret = conn.Open(socketServer);
       
   783 	if (ret != KErrNone)
       
   784     		{
       
   785     		INFO_PRINTF2(_L("Failed to open connection due to Error: %d."),ret);
       
   786     		return EFail;
       
   787     		}
       
   788 
       
   789 	// Start the connection
       
   790 	conn.Start(status);
       
   791 	User::WaitForRequest(status);
       
   792 	
       
   793 	if (status != KErrNone)
       
   794     		{
       
   795     		INFO_PRINTF2(_L("Failed to start connection due to Error: %d."),status.Int());
       
   796     		return EFail;
       
   797     		}
       
   798 
       
   799 
       
   800 	// Open UDP socket
       
   801 	ret = socket.Open(socketServer,
       
   802 			KAfInet,
       
   803 	                      KSockDatagram,
       
   804 	                      KProtocolInetUdp,
       
   805 	                      conn);
       
   806 	if (ret != KErrNone)
       
   807     		{
       
   808     		INFO_PRINTF2(_L("Failure to open socket due to Error: %d."),ret);
       
   809     		return EFail;
       
   810     		}
       
   811 	
       
   812 	
       
   813 	dstAddr.SetPort(3441);
       
   814 	_LIT(KText50, "127.0.0.1");
       
   815 	dstAddr.Input( KText50 );
       
   816 
       
   817 	ret = socket.SetLocalPort(3442);
       
   818 	if (ret != KErrNone)
       
   819     		{
       
   820     		INFO_PRINTF2(_L("Failed to set port on socket due to Error: %d."),ret);
       
   821     		return EFail;
       
   822     		}
       
   823     		
       
   824 	socket.Connect(dstAddr, status);
       
   825 	User::WaitForRequest(status);
       
   826 
       
   827 	if (status != KErrNone)
       
   828     		{
       
   829     		INFO_PRINTF2(_L("Socket failed to connect to dst addr due to Error: %d."),status.Int());
       
   830     		return EFail;
       
   831     		}
       
   832 
       
   833 	// Create a new sub-connection
       
   834 	ret = subconn.Open(socketServer,
       
   835 	                   RSubConnection::ECreateNew,
       
   836 	                   conn);
       
   837 	if (ret != KErrNone)
       
   838     		{
       
   839     		INFO_PRINTF2(_L("Failed to create new sub-connection due to Error: %d."),ret);
       
   840     		return EFail;
       
   841     		}
       
   842     		
       
   843 	 // Move the connected socket onto the new sub-connection
       
   844 	subconn.Add(socket, status);
       
   845 	User::WaitForRequest(status);
       
   846 
       
   847 	if (status != KErrNotReady)
       
   848     		{
       
   849     		INFO_PRINTF2(_L("Socket could not be added to subconn due to  Error: %d."),status.Int());
       
   850     		return EFail;
       
   851     		}
       
   852 
       
   853 	 // close and destroy
       
   854 	CleanupStack::PopAndDestroy(&subconn);
       
   855 	CleanupStack::PopAndDestroy(&socket);
       
   856 	CleanupStack::PopAndDestroy(&conn);
       
   857 	CleanupStack::PopAndDestroy(&socketServer);
       
   858 	
       
   859  	return EPass;
       
   860 	}
       
   861 
       
   862 
       
   863 // Shutdown Socket
       
   864 //----------------
       
   865 
       
   866 CShutdownRSocketStep::CShutdownRSocketStep(CCEsockTestBase*& aEsockTest)
       
   867 :   CTe_EsockStepBase(aEsockTest)
       
   868 	{
       
   869 	SetTestStepName(KShutdownRSocketStep);
       
   870 	}
       
   871 
       
   872 TInt CShutdownRSocketStep::ConfigureFromIni()
       
   873 	{
       
   874 	iParams.Reset();
       
   875 
       
   876 	// Read in appropriate fields
       
   877 	if((GetStringFromConfig(iSection, KTe_SocketName, iParams.iSocketName) != 1)
       
   878 		|| (iParams.iSocketName.Length() == 0))
       
   879 		{
       
   880 		INFO_PRINTF1(_L("Couldn't find appropriate field in config file"));
       
   881 		return KErrNotFound;
       
   882 		}
       
   883 
       
   884     TPtrC shutdownType;
       
   885     if (GetStringFromConfig(iSection,KTe_ShutdownTypeName,shutdownType)!=1)
       
   886         {
       
   887         INFO_PRINTF2(_L("%S: Shutdown type missing."),&iParams.iSocketName);
       
   888         return KErrNotFound;
       
   889         }
       
   890 
       
   891     if (shutdownType.Compare(KTe_ShutdownNormal)==0)
       
   892 	    { iParams.iShutdownType = RSocket::ENormal; }
       
   893     else if (shutdownType.Compare(KTe_ShutdownStopInput)==0)
       
   894 	    { iParams.iShutdownType = RSocket::EStopInput; }
       
   895     else if (shutdownType.Compare(KTe_ShutdownStopOutput)==0)
       
   896 	    { iParams.iShutdownType = RSocket::EStopOutput; }
       
   897     else if (shutdownType.Compare(KTe_ShutdownImmediate)==0)
       
   898 	    { iParams.iShutdownType = RSocket::EImmediate; }
       
   899     else
       
   900         {
       
   901         INFO_PRINTF3(_L("%S: Shutdown type (%S) not recognised."),&iParams.iSocketName,&shutdownType);
       
   902         return KErrNotFound;
       
   903         }
       
   904 
       
   905     // All ok if we got this far
       
   906     return KErrNone;
       
   907 	}
       
   908 
       
   909 TVerdict CShutdownRSocketStep::doSingleTestStep()
       
   910 	{
       
   911     TRequestStatus reqStat;
       
   912 	TInt error = iEsockTest->ShutdownSocket(iParams,reqStat);
       
   913     if (error!=KErrNone)
       
   914         {
       
   915         INFO_PRINTF2(_L("Could not connect socket (%S)."),&iParams.iSocketName);
       
   916         INFO_PRINTF2(_L("Error: %d."),error);
       
   917         return EFail;
       
   918         }
       
   919 
       
   920 	User::WaitForRequest(reqStat);
       
   921 	error = reqStat.Int();
       
   922 	if (error!=KErrNone)
       
   923 		{
       
   924         INFO_PRINTF2(_L("Could not connect socket (%S)."),&iParams.iSocketName);
       
   925         INFO_PRINTF2(_L("Error: %d."),error);
       
   926 		return EFail;
       
   927 		}
       
   928 	return EPass;
       
   929 	}
       
   930 
       
   931 
       
   932 // Ioctls
       
   933 //-------
       
   934 
       
   935 CSendReceiveIoctlStep::CSendReceiveIoctlStep(CCEsockTestBase*& aEsockTest)
       
   936 :   CTe_EsockStepBase(aEsockTest)
       
   937 	{
       
   938 	SetTestStepName(KSendReceiveIoctlStep);
       
   939 	}
       
   940 
       
   941 _LIT(KIoctlCommand, "IoctlCommand");
       
   942 _LIT(KIoctlLevel, "IoctlLevel");
       
   943 _LIT(KExpectedIoctlOutput, "ExpectedOutput");
       
   944 
       
   945 TInt CSendReceiveIoctlStep::ConfigureFromIni()
       
   946 	{
       
   947 	// Reset the parameters and read in necessary fields
       
   948 	iParams.Reset();
       
   949 
       
   950 	// Socket to apply it to
       
   951 	if((GetStringFromConfig(iSection, KTe_SocketName, iParams.iSocketName) != 1)
       
   952 		|| (iParams.iSocketName.Length() == 0))
       
   953 		{
       
   954 		INFO_PRINTF3(KErrString_MissingConfigFileField, &iSection, &KTe_SocketName);
       
   955 		return KErrNotFound;
       
   956 		}
       
   957 
       
   958     // Ioctl command
       
   959 	if (GetIntFromConfig(iSection, KIoctlCommand, iParams.iIoctlCommand) != 1)
       
   960         {
       
   961 		INFO_PRINTF3(KErrString_MissingConfigFileField, &iSection, &KIoctlCommand);
       
   962 		return KErrNotFound;
       
   963         }
       
   964 
       
   965     // Ioctl level
       
   966     // Default to 
       
   967 	if (GetIntFromConfig(iSection, KIoctlLevel, iParams.iIoctlLevel) != 1)
       
   968         {
       
   969 		INFO_PRINTF1(_L("Ioctl level not specified: defaulting"));
       
   970 		iParams.iIoctlLevel = KLevelUnspecified;
       
   971         }
       
   972 
       
   973 	// Output to compare it with
       
   974 	if(GetStringFromConfig(iSection, KExpectedIoctlOutput, iParams.iExpectedIoctlOutput) != 1)
       
   975 		{
       
   976 		INFO_PRINTF3(KErrString_MissingConfigFileField, &iSection, &KExpectedIoctlOutput);
       
   977 		return KErrNotFound;
       
   978 		}
       
   979 
       
   980     // All ok if we got this far
       
   981     return KErrNone;
       
   982 	}
       
   983 
       
   984 TVerdict CSendReceiveIoctlStep::doSingleTestStep()
       
   985 	{
       
   986     TRequestStatus requestStatus;
       
   987 
       
   988 	TBuf8<256> outputBuffer;
       
   989 	TInt error = iEsockTest->IoctlSocket(iParams, outputBuffer, requestStatus);
       
   990 
       
   991     if (error != KErrNone)
       
   992         {
       
   993         INFO_PRINTF2(_L("Could not find socket (%S)."),&iParams.iSocketName);
       
   994         INFO_PRINTF2(_L("Error: %d."),error);
       
   995         return EFail;
       
   996         }
       
   997 
       
   998 	User::WaitForRequest(requestStatus);
       
   999 
       
  1000 	error = requestStatus.Int();
       
  1001 
       
  1002 	if (error!=KErrNone)
       
  1003 		{
       
  1004         INFO_PRINTF2(_L("Could not complete ioctl (%S)."),&iParams.iSocketName);
       
  1005         INFO_PRINTF2(_L("Error: %d."),error);
       
  1006 		return EFail;
       
  1007 		}
       
  1008 
       
  1009 	// Convert the output to wide chars
       
  1010 	TBuf<256> outputConvertedToWideChars;
       
  1011 	CnvUtfConverter::ConvertToUnicodeFromUtf8(outputConvertedToWideChars, outputBuffer);
       
  1012 
       
  1013 	// Validate the output with that expected
       
  1014 	return (outputConvertedToWideChars == iParams.iExpectedIoctlOutput) ?
       
  1015 		EPass :
       
  1016 		EFail;
       
  1017 	}
       
  1018 
       
  1019 
       
  1020 // Get options
       
  1021 //------------
       
  1022 
       
  1023 CSocketGetOptionStep::CSocketGetOptionStep(CCEsockTestBase*& aEsockTest)
       
  1024 :   CTe_EsockStepBase(aEsockTest)
       
  1025 	{
       
  1026 	SetTestStepName(KSocketGetOptionStep);
       
  1027 	}
       
  1028 
       
  1029 _LIT(KOptionName, "OptionName");
       
  1030 _LIT(KOptionLevel, "OptionLevel");
       
  1031 _LIT(KExpectedOptionText, "ExpectedOptionText");
       
  1032 _LIT(KExpectedOptionValue, "ExpectedOptionValue");
       
  1033 
       
  1034 TInt CSocketGetOptionStep::ConfigureFromIni()
       
  1035 	{
       
  1036 	// Reset the parameters and read in necessary fields
       
  1037 	iParams.Reset();
       
  1038 
       
  1039 	// Socket to apply it to
       
  1040 	if((GetStringFromConfig(iSection, KTe_SocketName, iParams.iSocketName) != 1)
       
  1041 		|| (iParams.iSocketName.Length() == 0))
       
  1042 		{
       
  1043 		INFO_PRINTF3(KErrString_MissingConfigFileField, &iSection, &KTe_SocketName);
       
  1044 		return KErrNotFound;
       
  1045 		}
       
  1046 
       
  1047     // Option "name"
       
  1048 	if (GetIntFromConfig(iSection, KOptionName, iParams.iOptionName) != 1)
       
  1049         {
       
  1050 		INFO_PRINTF3(KErrString_MissingConfigFileField, &iSection, &KOptionName);
       
  1051 		return KErrNotFound;
       
  1052         }
       
  1053 
       
  1054     // Option level
       
  1055 	if (GetIntFromConfig(iSection, KOptionLevel, iParams.iOptionLevel) != 1)
       
  1056         {
       
  1057 		INFO_PRINTF1(_L("Option level not specified: defaulting to KLevelUnspecified"));
       
  1058 		iParams.iOptionLevel = KLevelUnspecified;
       
  1059         }
       
  1060 
       
  1061 	// Output string to compare it with
       
  1062 	if(GetStringFromConfig(iSection, KExpectedOptionText, iParams.iExpectedOptionOutputText) == 1)
       
  1063 		{
       
  1064 		iParams.iTextExpected = ETrue;
       
  1065 		}
       
  1066 
       
  1067 	// Output value to compare it with
       
  1068 	if(GetIntFromConfig(iSection, KExpectedOptionValue, iParams.iExpectedOptionOutputValue) == 1)
       
  1069 		{
       
  1070 		iParams.iValueExpected = ETrue;
       
  1071 		}
       
  1072 
       
  1073     // Checks on config values
       
  1074     if(iParams.iValueExpected && iParams.iTextExpected)
       
  1075     	{
       
  1076 		INFO_PRINTF1(_L("Can be only value of text expected. Not both"));
       
  1077 		return KErrCorrupt;
       
  1078 		}
       
  1079 		
       
  1080     if(!iParams.iValueExpected && !iParams.iTextExpected)
       
  1081     	{
       
  1082 		INFO_PRINTF1(_L("Must have value or text expected."));
       
  1083 		return KErrCorrupt;
       
  1084 		}
       
  1085 		
       
  1086     
       
  1087     // All ok if we got this far
       
  1088     return KErrNone;
       
  1089 	}
       
  1090 
       
  1091 TVerdict CSocketGetOptionStep::doSingleTestStep()
       
  1092 	{
       
  1093     TRequestStatus requestStatus;
       
  1094 
       
  1095 	TBuf8<256> outputBuffer;
       
  1096 	TInt outputValue;
       
  1097 	TInt error;
       
  1098 	if(iParams.iTextExpected)
       
  1099 		{
       
  1100 		error = iEsockTest->GetOptSocket(iParams, outputBuffer);
       
  1101 		}
       
  1102 	else
       
  1103 		{
       
  1104 		error = iEsockTest->GetOptSocket(iParams, outputValue);
       
  1105 		}
       
  1106 
       
  1107     if (error != KErrNone)
       
  1108         {
       
  1109         INFO_PRINTF3(_L("Socket get option error. socket:%S, error:%d"), &iParams.iSocketName, error);
       
  1110         SetTestStepError(error);
       
  1111         return EFail;
       
  1112         }
       
  1113 
       
  1114 	if(iParams.iTextExpected)
       
  1115 		{
       
  1116 		// Convert the output to wide chars
       
  1117 		TBuf<256> outputConvertedToWideChars;
       
  1118 		CnvUtfConverter::ConvertToUnicodeFromUtf8(outputConvertedToWideChars, outputBuffer);
       
  1119 
       
  1120 		// Log what was returned
       
  1121 		INFO_PRINTF2(_L("Socket returned get opt value. value:%S"), &outputConvertedToWideChars);
       
  1122 		INFO_PRINTF2(_L("Expected get opt value.        value:%S"), &iParams.iExpectedOptionOutputText);
       
  1123 
       
  1124 		// Validate the output with that expected
       
  1125 		TVerdict verdict = (outputConvertedToWideChars == iParams.iExpectedOptionOutputText) ? EPass : EFail;
       
  1126 		SetTestStepResult(verdict);
       
  1127 		}
       
  1128 	else
       
  1129 		{
       
  1130 		// Log what was returned
       
  1131 		INFO_PRINTF2(_L("Socket returned get opt value. value:%d"), outputValue);
       
  1132 		INFO_PRINTF2(_L("Expected get opt value.        value:%d"), iParams.iExpectedOptionOutputValue);
       
  1133 
       
  1134 		// Validate the output with that expected
       
  1135 		TVerdict verdict = (outputValue == iParams.iExpectedOptionOutputValue) ? EPass : EFail;
       
  1136 		SetTestStepResult(verdict);
       
  1137 		}
       
  1138 
       
  1139 	// Return the result
       
  1140 	return TestStepResult();
       
  1141 	}
       
  1142 
       
  1143 
       
  1144 
       
  1145 // Socket protocol description
       
  1146 //----------------------------
       
  1147 CSocketProtocolDescriptionStep::CSocketProtocolDescriptionStep(CCEsockTestBase*& aEsockTest)
       
  1148 :   CTe_EsockStepBase(aEsockTest)
       
  1149 	{
       
  1150 	SetTestStepName(KSocketProtocolDescriptionStep);
       
  1151 	}
       
  1152 
       
  1153 TInt CSocketProtocolDescriptionStep::ConfigureFromIni()
       
  1154 	{
       
  1155 	// Reset the parameters and read in necessary fields
       
  1156 	iParams.Reset();
       
  1157 
       
  1158 	// Socket to apply it to
       
  1159 	if((GetStringFromConfig(iSection, KTe_SocketName, iParams.iSocketName) != 1)
       
  1160 		|| (iParams.iSocketName.Length() == 0))
       
  1161 		{
       
  1162 		INFO_PRINTF3(KErrString_MissingConfigFileField, &iSection, &KTe_SocketName);
       
  1163 		return KErrNotFound;
       
  1164 		}
       
  1165 
       
  1166 	TInt descStatus = TProtocolDescriptionParams::FetchDescription(iParams.iProtocolDescParams, *this);
       
  1167 	return descStatus;
       
  1168 	}
       
  1169 
       
  1170 
       
  1171 TVerdict CSocketProtocolDescriptionStep::doSingleTestStep()
       
  1172 	{
       
  1173 	TProtocolDesc desc;
       
  1174 	TInt error = iEsockTest->ProtocolDescription(iParams, desc);
       
  1175 
       
  1176     if (error != KErrNone)
       
  1177         {
       
  1178         INFO_PRINTF3(_L("Could not fetch protocol description from socket. socket:%S, error:%d"), &iParams.iSocketName, error);
       
  1179         return EFail;
       
  1180         }
       
  1181 
       
  1182 	// Validate the output with that expected
       
  1183 	if(iParams.iProtocolDescParams.MatchesExpected(desc))
       
  1184 		{
       
  1185 		return EPass;
       
  1186 		}
       
  1187 	else
       
  1188 		{
       
  1189         INFO_PRINTF1(_L("Protocol description does not match that expected"));
       
  1190         return EFail;
       
  1191 		}
       
  1192 	}
       
  1193 
       
  1194 
       
  1195