datacommsserver/esockserver/test/TS_MultiHoming/TS_TestConnection.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 TS_TestConnection echo data primitive.
       
    15 // stores this connection in C
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21 */
       
    22  
       
    23 #include "TS_TestConnection.h"
       
    24 
       
    25 
       
    26 
       
    27 /* 
       
    28  * xxx
       
    29  * Open a default / named connection
       
    30  */
       
    31 CTS_TestConnection::CTS_TestConnection()
       
    32 	{
       
    33 	iTestStepName = KTestConnection;
       
    34 	}
       
    35 
       
    36 CTS_TestConnection::~CTS_TestConnection()
       
    37 	{	
       
    38 	}
       
    39 
       
    40 enum TVerdict CTS_TestConnection::doTestStepPreambleL(void)
       
    41 /**
       
    42  * Implements OOM testing in each test
       
    43  */
       
    44 	{
       
    45 	if (!(GetBoolFromConfig(KTestConnection,KOomTest,iIsOOMTest)))
       
    46 		iIsOOMTest=EFalse;
       
    47 	return EPass;
       
    48 	}
       
    49 
       
    50 
       
    51 enum TVerdict CTS_TestConnection::doTestStepL(void)
       
    52 /**
       
    53  * Creates and starts one or more Explicit Connection(s)
       
    54  * and appends it/them to the array of
       
    55  * connections in the MultiHoming Suite 
       
    56  * @return The test step outcome.
       
    57  * 
       
    58  */
       
    59 {
       
    60 	TInt err = KErrNone;
       
    61 	TInt numOfSockets = 0;
       
    62 
       
    63 	
       
    64 	err = GetIntFromConfig(KTestConnection, KNumOfSocks, numOfSockets);
       
    65 
       
    66 
       
    67 	if ((!err) || (numOfSockets < 1))
       
    68 		{
       
    69 		return EInconclusive;
       
    70 		}
       
    71 
       
    72 	RArray<CEchoSocket*> sockArray;
       
    73 	RArray<TBool> expectSocketsToSucceedArray;
       
    74 	TConnDetails *theConn;
       
    75 
       
    76 	TInt i;
       
    77 	for (i = 0; i < numOfSockets; i++)
       
    78 		{
       
    79 		// Get some configuration data...
       
    80 		TInetAddr dest;
       
    81 		TInetAddr src;
       
    82 		//RSocketServ theSS;
       
    83         
       
    84 
       
    85 		TInt protocol = KProtocolInetUdp;
       
    86 		TInt packSize = PACKET_SIZE;
       
    87 		TInt packCount = NUM_OF_PACKETS;
       
    88 		TInt aTol = UDP_TOLERANCE;
       
    89 		TBool expectSuccess = ETrue;
       
    90 		TBool isListener = EFalse;
       
    91 		
       
    92 
       
    93 		err = GetSockConfig(i,protocol,packSize,packCount, aTol, dest, src, 
       
    94 						expectSuccess, isListener, &theConn);
       
    95 
       
    96 		
       
    97 		expectSocketsToSucceedArray.Append(expectSuccess);
       
    98 
       
    99 		if (err!=KErrNone)
       
   100 			{
       
   101 			LogExtra((TText8*)__FILE__, __LINE__, ESevrErr, KEConfigFile);
       
   102 			}
       
   103 		
       
   104 		CEchoSocket* newSocket = CEchoSocket::NewL();
       
   105 	
       
   106 		err = newSocket->Echo(dest, src, packSize,packCount,protocol,aTol, theConn, i, isListener, this);
       
   107 		if (err == KErrNone)
       
   108 			{
       
   109 			err = sockArray.Append(newSocket);
       
   110 			if (err != KErrNone)
       
   111 				{
       
   112 				newSocket->DoCancel();
       
   113 				delete newSocket;
       
   114 				newSocket = NULL;
       
   115 				}
       
   116 			}
       
   117 		else
       
   118 			{
       
   119 			TPtrC Errortxt = EpocErrorToText(err);
       
   120 			Log(KELogger, &Errortxt);
       
   121 			delete newSocket;
       
   122 			}
       
   123 		}	// for (i<numOfSockets)
       
   124 	
       
   125 	if(sockArray.Count() > 0)
       
   126 		CEnhancedScheduler::Start();	// And start them off...
       
   127 	// Wait for all to finish / time out.
       
   128 	
       
   129 	for (i = 0; i < sockArray.Count(); i++)
       
   130 		{
       
   131 		TInt err = KErrNone;
       
   132 		TBool boolResult = EFalse;
       
   133 		TInt percent = 0;
       
   134 		TInt numSent = -1;
       
   135 		err = sockArray[i]->LogReport(boolResult, numSent, percent);
       
   136 		if (expectSocketsToSucceedArray[i] &&
       
   137 			(KErrNone == err) && boolResult
       
   138 			||
       
   139 			// Failure means there was a socket error or no packets received
       
   140 			!expectSocketsToSucceedArray[i] && (KErrNone != err || !boolResult))
       
   141 			{
       
   142 			Log(KSockPassed, i, numSent, percent);
       
   143 			}
       
   144 		else
       
   145 			{
       
   146 			TPtrC errorText = EpocErrorToText(err);
       
   147 			Log(KSockFailed, i, &errorText, numSent, percent);
       
   148 			iTestStepResult = EFail;
       
   149 			}
       
   150 		delete sockArray[i];
       
   151 		}
       
   152 
       
   153 
       
   154 	expectSocketsToSucceedArray.Close();
       
   155 	sockArray.Close();
       
   156 	return iTestStepResult;
       
   157 	}
       
   158