datacommsserver/esockserver/test/TS_MultiHoming/TS_MultiHomingStep.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2002-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 CTS_MultiHomingStep class which is
       
    15 // the base class for all the MultiHoming test steps
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21 */
       
    22 #include "TS_MultiHomingStep.h"
       
    23 
       
    24 
       
    25 // Constructor
       
    26 CTS_MultiHomingStep::CTS_MultiHomingStep() : iIsOOMTest(EFalse)
       
    27 	{
       
    28 	}
       
    29 
       
    30 // Destructor
       
    31 CTS_MultiHomingStep::~CTS_MultiHomingStep()
       
    32 	{ 
       
    33 	}	
       
    34 
       
    35 TInt CTS_MultiHomingStep::GetConnectionType(TConnDetails *conn, TDesC& aName)
       
    36 	{
       
    37 		TPtrC ptrBuf;
       
    38 		TInt err = GetStringFromConfig(aName, KConnType, ptrBuf);
       
    39 
       
    40 		if(err != 1)
       
    41 		{
       
    42 			LogExtra((TText8*)__FILE__, __LINE__, ESevrWarn, KEConfigFile);
       
    43 			return err;
       
    44 		}
       
    45 
       
    46 
       
    47 		if(ptrBuf.Compare(KConnDefault) ==0)
       
    48 			conn->iConnectionType = TConnDetails::defaultConn;
       
    49 		else if(ptrBuf.Compare(KConnImplicit) ==0)
       
    50 			conn->iConnectionType = TConnDetails::implicitConn;
       
    51 		else if(ptrBuf.Compare(KConnExplicit) ==0)
       
    52 			conn->iConnectionType = TConnDetails::explicitConn;
       
    53 		else
       
    54 			{
       
    55 			_LIT(KTypeErr, "Connection type should be one of %S %S or %S");
       
    56 			LogExtra((TText8*)__FILE__, __LINE__, ESevrErr, KTypeErr, KConnExplicit, KConnImplicit, KConnDefault );
       
    57 			return KErrNotFound;
       
    58 			}
       
    59 		return KErrNone;			
       
    60 
       
    61 	}
       
    62 
       
    63 TInt CTS_MultiHomingStep::SetConnPrefs(TCommDbConnPref& aPrefs, TDesC& aName)
       
    64 /**
       
    65  * Fills up a CStoreableOverrideSettings* with script file configs
       
    66  * @param aPrefs A pointer to a CStoreableOverrideSettings object
       
    67  * @param aName Name of the connection to get prefs for
       
    68  * @return KErrNone if sucessful, otherwise system wide error codes
       
    69  * @exception Can leave
       
    70  */
       
    71 	{
       
    72 
       
    73 	TInt theIap = 0;
       
    74 	TInt theNet = 0;
       
    75 	// Get the IAP index and use it to complete the .ini file section name
       
    76 	if(GetIntFromConfig(aName, KConnIap, theIap))
       
    77 		{
       
    78 		aPrefs.SetIapId(theIap);		
       
    79 		}
       
    80 
       
    81 	if(GetIntFromConfig(aName, KConnNet, theNet))
       
    82 		{
       
    83 		aPrefs.SetNetId(theNet);
       
    84 		}
       
    85 	return KErrNone;
       
    86 	}
       
    87 
       
    88 
       
    89 TInt CTS_MultiHomingStep::GetSockConfig(const TInt aIndex, TInt& aProtocol,
       
    90 										TInt& aPackSize, TInt& aNumPackets,
       
    91 										TInt& aUdp, TInetAddr& aDstAddr, 
       
    92 										TInetAddr& aSrcAddr, 
       
    93 										TBool& aExpectSuccess,
       
    94 										TBool& aIsListener,
       
    95 										TConnDetails **aConnDetails)
       
    96 /**
       
    97  * Gets socket configuration from file, using defaults if necessary
       
    98  * @param aIndex The index for the socket configkey
       
    99  * @param aProtocol The protocol to be used
       
   100  * @param aPackSize The packet size in bytes
       
   101  * @param aNumPackets Number of packets to send
       
   102  * @param aUdp Percentage of UDP packets that can be dropped
       
   103  * @param aAddr The destination address for the socket
       
   104  * @param aSS The socket server sub-session to use for the socket
       
   105  * @param aNetName The network connection name in the suite
       
   106  * @return System wide error code
       
   107  */
       
   108 	{
       
   109 	TInt err=KErrNone;
       
   110 	TInt val=0;
       
   111 	TBuf<10> socketNum;		// Create the Key for the config lookup
       
   112 	socketNum= KSocket;
       
   113 	socketNum.AppendNum(aIndex);
       
   114 	
       
   115 	TPtrC ptrBuf;
       
   116 
       
   117 
       
   118 	
       
   119 
       
   120 	// Port 0 means we dont care about binding to port
       
   121 
       
   122 	err = GetStringFromConfig(socketNum, KSrcAddr, ptrBuf);
       
   123 	if (err)
       
   124 		{
       
   125 		// String found in table
       
   126 		err = aSrcAddr.Input(ptrBuf);
       
   127 		TESTE(err==KErrNone,err);
       
   128 		if (err !=KErrNone)
       
   129 			{
       
   130 			iTestStepResult= EInconclusive;
       
   131 			return KErrBadName;
       
   132 			}
       
   133 		}
       
   134 		else 
       
   135 			aSrcAddr.SetAddress(KInetAddrAny);
       
   136 
       
   137 	err = GetIntFromConfig(socketNum, KSrcPort, val);
       
   138 	if (err)
       
   139 		aSrcAddr.SetPort((TUint) val);
       
   140 	else
       
   141 		aSrcAddr.SetPort(0);		// Default to zero - ie source address NOT uses
       
   142 	
       
   143 
       
   144 	err = GetStringFromConfig(socketNum, KDestAddr, ptrBuf);
       
   145 	if (!err)
       
   146 		{
       
   147 		LogExtra((TText8*)__FILE__, __LINE__, ESevrWarn, KEConfigFile);
       
   148 		iTestStepResult= EInconclusive;
       
   149 		return KErrNotFound;
       
   150 		}
       
   151 
       
   152 
       
   153 	err = aDstAddr.Input(ptrBuf);
       
   154 	TESTE(err==KErrNone,err);
       
   155 	if (err !=KErrNone)
       
   156 		{
       
   157 		iTestStepResult= EInconclusive;
       
   158 		return KErrBadName;
       
   159 		}
       
   160 
       
   161 	err = GetIntFromConfig(socketNum, KDestPort, val);
       
   162 	if (!err)
       
   163 		aDstAddr.SetPort(ECHO_PORT);		// Default to echo port
       
   164 	aDstAddr.SetPort((TUint) val);
       
   165 	
       
   166 	err = GetStringFromConfig(socketNum, KProtocol, ptrBuf);
       
   167 	if (err && (ptrBuf.Compare(KTcp)==0))
       
   168 		aProtocol = KProtocolInetTcp;
       
   169 	else
       
   170 		aProtocol = KProtocolInetUdp;
       
   171 	
       
   172 	err = GetIntFromConfig(socketNum, KPacketSize, val);
       
   173 	if (!err)
       
   174 		aPackSize=PACKET_SIZE;
       
   175 	aPackSize=val;
       
   176 	
       
   177 	err = GetIntFromConfig(socketNum, KNumOfPackets, val);
       
   178 	if (!err)
       
   179 		aNumPackets=NUM_OF_PACKETS;
       
   180 	aNumPackets=val;
       
   181 		
       
   182 	err = GetIntFromConfig(socketNum, KUdpTol, val);
       
   183 	if (!err)
       
   184 		aUdp=UDP_TOLERANCE;
       
   185 	aUdp=val;
       
   186 
       
   187 	aExpectSuccess = ETrue;
       
   188 	GetBoolFromConfig(socketNum, KExpectSuccess, aExpectSuccess);
       
   189 	
       
   190 	aIsListener = EFalse;
       
   191 	GetBoolFromConfig(socketNum, KIsListener, aIsListener);
       
   192 
       
   193 	err = GetStringFromConfig(socketNum, KConnName, ptrBuf);
       
   194 	if (!err)
       
   195 		{
       
   196 		LogExtra((TText8*)__FILE__, __LINE__, ESevrWarn, KEConfigFile);
       
   197 		iTestStepResult= EInconclusive;
       
   198 		return KErrNotFound;
       
   199 		}
       
   200 		// Use default
       
   201 
       
   202 	*aConnDetails = iOwnerSuite->GetTConnection(ptrBuf);								
       
   203 
       
   204 	return KErrNone;
       
   205 	}
       
   206 
       
   207 void CTS_MultiHomingStep::StepLog(TRefByValue<const TDesC16> aText, ...)
       
   208 /**
       
   209  * Logging wrapper for CEchoSocket class
       
   210  * @param aText Text for the Logging, with any other parameters
       
   211  */
       
   212 	{
       
   213 	VA_LIST aList;
       
   214 	VA_START( aList, aText );
       
   215 
       
   216 	// Create a formated descriptor
       
   217 	TBuf <MAX_LOG_LINE_LENGTH> LineBuf;
       
   218 	LineBuf.AppendFormatList( aText, aList);
       
   219 
       
   220 	// Log to the suite's logger
       
   221 	iSuite->Log( _L("%S"),&LineBuf );
       
   222 
       
   223 	VA_END( aList ); 
       
   224 	}
       
   225 
       
   226 
       
   227 void CTS_MultiHomingStep::ExpLogExtra(const TText8* aFile, TInt aLine, TInt aSeverity,
       
   228 		TRefByValue<const TDesC> aFmt,...)
       
   229 	{
       
   230 	VA_LIST aList;
       
   231 	VA_START( aList, aFmt );
       
   232 
       
   233 
       
   234 	// Log to the suite's logger
       
   235 	iSuite->LogExtra( aFile, aLine, aSeverity, aFmt, aList );
       
   236 
       
   237 	VA_END( aList ); 
       
   238 
       
   239 	}
       
   240 
       
   241 
       
   242 TInt CTS_MultiHomingStep::GetResolverConfig(const TInt aIndex, TName &aHostName, TInt& aProtocol,																				 
       
   243 										TBool& aExpectSuccess, TBool& aExpectTimeout, TBool& aExpectNotReady, 
       
   244 										TBool& aExplicitResolve, TConnDetails **aConnDetails)
       
   245 /**
       
   246  * Gets resolver configuration from file, using defaults if necessary
       
   247  * @param aIndex The index for the socket configkey
       
   248  * @param aHostName The host to be resolved
       
   249  * @param aProtocol The protocol to be used
       
   250  * @param aExpectSuccess Flag indicating if name should be resolved ok
       
   251  * @param aExpectTimeout Flag indicating if name resolution should timeout
       
   252  * @param aConnDetails The connection for an explicit resolver
       
   253  * @return System wide error code
       
   254  */
       
   255 	{
       
   256 	TInt err=KErrNone;	
       
   257 	TName resolverName;		// Create the Key for the config lookup
       
   258 	resolverName = KResolver;
       
   259 	resolverName.AppendNum(aIndex);
       
   260 	
       
   261 	TPtrC ptrBuf;
       
   262 	err = GetStringFromConfig(resolverName, KDestName, ptrBuf);
       
   263 	if (!err)
       
   264 		{
       
   265 		LogExtra((TText8*)__FILE__, __LINE__, ESevrWarn, KEConfigFile);
       
   266 		iTestStepResult= EInconclusive;
       
   267 		return KErrNotFound;
       
   268 		}
       
   269 	aHostName.Copy(ptrBuf.Ptr(), ptrBuf.Length());
       
   270 		
       
   271 	
       
   272 	aExpectSuccess = ETrue;
       
   273 	GetBoolFromConfig(resolverName, KExpectSuccess, aExpectSuccess);
       
   274 	
       
   275 	aExpectTimeout = EFalse;
       
   276 	GetBoolFromConfig(resolverName, KExpectTimeout, aExpectTimeout);
       
   277 
       
   278 	aExpectNotReady = EFalse;
       
   279     GetBoolFromConfig(resolverName, KExpectNoDnsServer, aExpectNotReady);
       
   280 
       
   281 	aExplicitResolve = EFalse;
       
   282 	GetBoolFromConfig(resolverName, KExplicitResolve, aExplicitResolve);
       
   283 		
       
   284 
       
   285 	err = GetStringFromConfig(resolverName, KProtocol, ptrBuf);
       
   286 	if (err && (ptrBuf.Compare(KTcp)==0))
       
   287 		aProtocol = KProtocolInetTcp;
       
   288 	else
       
   289 		aProtocol = KProtocolInetUdp;	
       
   290 		
       
   291 	
       
   292 	err = GetStringFromConfig(resolverName, KConnName, ptrBuf);
       
   293 	if (!err)
       
   294 		{
       
   295 		return KErrNotFound;
       
   296 		}		
       
   297 
       
   298 	*aConnDetails = iOwnerSuite->GetTConnection(ptrBuf);								
       
   299 
       
   300 	return KErrNone;
       
   301 	}
       
   302 
       
   303