enum TVerdict CTS_CEsockSendAndRecvData::doTestStepL( void )
	{
	TRequestStatus stat, stat2;
	TBuf8<50> Data;

	// Qos Channel(s)
	for (TInt i = 0;i < iQoSSuite->iQoSChannel.Count();i++)
		{
		// Socket(s)
		for (TInt i2 = 0;i2 < iQoSSuite->iQoSChannel[i]->GetSocketListCount() ;i2++)
			{
			// set up data buffers
			HBufC8 * writebuf = HBufC8::NewMaxLC( iQoSSuite->iQoSChannel[i]->iPacketSize[i2] );
			HBufC8 * readbuf  = HBufC8::NewMaxLC( iQoSSuite->iQoSChannel[i]->iPacketSize[i2] );
			TPtr8 ptrWritebuf = writebuf->Des();
			TPtr8 ptrReadbuf = readbuf->Des();

			TInt recvCount = 0;

			Log( _L("QoS Channel <%d>, Socket <%d>"), i+1, i2+1);

			// Send / Recv TCP
			if (iQoSSuite->iQoSChannel[i]->iProtocol[i2] == KProtocolInetTcp)
				{
				Log( _L("Sending TCP data, %d packets of %d bytes = %d"), 
				iQoSSuite->iQoSChannel[i]->iPackets[i2], iQoSSuite->iQoSChannel[i]->iPacketSize[i2], iQoSSuite->iQoSChannel[i]->iPackets[i2] * iQoSSuite->iQoSChannel[i]->iPacketSize[i2]);
				
				// Number of Packets to Send / Recv
				for (TInt i4 = 0; i4 < iQoSSuite->iQoSChannel[i]->iPackets[i2]; i4++)
					{
					// initialise data
					Data.Format(_L8("TCP-packet:%d helloworld"),i4);
					ptrWritebuf.Repeat( Data );

					// write data
					iQoSSuite->iQoSChannel[i]->GetSocketHandle(i2)->Write(ptrWritebuf, stat);
					User::WaitForRequest(stat);
					TESTL(stat==KErrNone);

					// read data
					iQoSSuite->iQoSChannel[i]->GetSocketHandle(i2)->Read(ptrReadbuf, stat);
					User::WaitForRequest(stat);
					TESTL(stat==KErrNone);

					// compare the data
					TESTL( ptrWritebuf.Compare( ptrReadbuf ) == 0);
					recvCount+=ptrReadbuf.Length();
					}
				//	writebuf and readbuf
				CleanupStack::PopAndDestroy(2);	
				} 

			// Send / Recv UDP
			if (iQoSSuite->iQoSChannel[i]->iProtocol[i2] == KProtocolInetUdp)
				{
				Log( _L("Send Udp Data, %d packets of %d bytes = %d"), 
				iQoSSuite->iQoSChannel[i]->iPackets[i2], iQoSSuite->iQoSChannel[i]->iPacketSize[i2], iQoSSuite->iQoSChannel[i]->iPackets[i2] * iQoSSuite->iQoSChannel[i]->iPacketSize[i2]);

				// Number of Packets to Send / Recv
				for (TInt i4 = 0; i4 < iQoSSuite->iQoSChannel[i]->iPackets[i2]; i4++)
					{
					// initialise data
					Data.Format(_L8("UDP-packet:%d helloworld"),i4);
					ptrWritebuf.Repeat( Data );

					// write data 
					iQoSSuite->iQoSChannel[i]->GetSocketHandle(i2)->SendTo(ptrWritebuf, iQoSSuite->iQoSChannel[i]->iDestAddr[i2], 0, stat);
					User::WaitForRequest(stat);
					TESTL(stat==KErrNone);

					iQoSSuite->iQoSChannel[i]->GetSocketHandle(i2)->RecvFrom(ptrReadbuf, iQoSSuite->iQoSChannel[i]->iDestAddr[i2], 0, stat2);
					User::WaitForRequest(stat2);
					TESTL(stat==KErrNone);

					// compare the data
				  	TESTL( ptrWritebuf.Compare( ptrReadbuf ) == 0 );
					recvCount += ptrReadbuf.Length();
					}
				//	writebuf and readbuf
				CleanupStack::PopAndDestroy(2);
				}

			// check the total received (95 per cent is allowable for us)
			TESTL(recvCount*iQoSSuite->iQoSChannel[i]->iPacketSize[i2] > (0.95*(iQoSSuite->iQoSChannel[i]->iPackets[i2]*iQoSSuite->iQoSChannel[i]->iPacketSize[i2])) );	
			}		
		}

	return EPass;
	}
Пример #2
0
void CMultipleArray::SendAndRecvL(TInt aExtraSocksToJoin)
	{
	TRequestStatus stat;
	TBuf8<50> Data;

	// set up data buffers
	HBufC8 * writebuf = HBufC8::NewMaxLC( iPacketSize[aExtraSocksToJoin] );
	HBufC8 * readbuf  = HBufC8::NewMaxLC( iPacketSize[aExtraSocksToJoin] );
	TPtr8 ptrWritebuf = writebuf->Des();
	TPtr8 ptrReadbuf = readbuf->Des();

	TInt recvCount = 0;

	// Send / Recv TCP
	if (iProtocol[aExtraSocksToJoin] == KProtocolInetTcp)
		{
		for (TInt i = 0; i < iPackets[aExtraSocksToJoin]; i++)
			{
			iQoSStep->iQoSSuite->Log( _L("Sending TCP data, %d packets of %d bytes = %d"), 
			iPackets[aExtraSocksToJoin], iPacketSize[aExtraSocksToJoin], iPackets[aExtraSocksToJoin] * iPacketSize[aExtraSocksToJoin]);

			// initialise data
			Data.Format(_L8("TCP-packet:%d helloworld"),i);
			ptrWritebuf.Repeat( Data );

			// write data
			GetSocketHandle(aExtraSocksToJoin)->Write(ptrWritebuf, stat);
			User::WaitForRequest(stat);
			if (stat!=KErrNone)
				{
				iQoSStep->iQoSSuite->Log(_L("Failed to write tcp data to destination: return value = <%d>"), stat);
				User::Leave(stat.Int());
				}

			// read data
			GetSocketHandle(aExtraSocksToJoin)->Read(ptrReadbuf, stat);
			User::WaitForRequest(stat); //, TimerStatus);
			if (stat!=KErrNone)
				{
				iQoSStep->iQoSSuite->Log(_L("Failed to read tcp data from destination: return value = <%d>"), stat);
				User::Leave(stat.Int());
				}

			// compare the data
			if (ptrWritebuf.Compare( ptrReadbuf ) != 0)
				{
				iQoSStep->iQoSSuite->Log(_L("Data written to and read from destination address do not match in size"));
//				return Fail;
				}

			recvCount+=ptrReadbuf.Length();
			}

		CleanupStack::PopAndDestroy(2);	//	writebuf and readbuf
		} 

	// Send / Recv UDP 
	if (iProtocol[aExtraSocksToJoin] == KProtocolInetUdp)
		{
		iQoSStep->iQoSSuite->Log( _L("Send Udp Data, %d packets of %d bytes = %d"), 
		iPackets[aExtraSocksToJoin], iPacketSize[aExtraSocksToJoin], iPackets[aExtraSocksToJoin] * iPacketSize[aExtraSocksToJoin]);
	
		for (TInt i = 0; i < iPackets[aExtraSocksToJoin]; i++)
			{
			// initialise data
			Data.Format(_L8("UDP-packet:%d helloworld"),i);
			ptrWritebuf.Repeat( Data );	

			// write data
			GetSocketHandle(aExtraSocksToJoin)->Send(ptrWritebuf, 0, stat);
			User::WaitForRequest(stat);
			if (stat!=KErrNone)
				{
				iQoSStep->iQoSSuite->Log(_L("Failed to write udp data to destination: return value = <%d>"), stat);
				User::Leave(stat.Int());
				}

			GetSocketHandle(aExtraSocksToJoin)->Recv(ptrReadbuf, 0, stat);
			User::WaitForRequest(stat);
			if (stat!=KErrNone)
				{
				iQoSStep->iQoSSuite->Log(_L("Failed to read udp data from destination: return value = <%d>"), stat);
				User::Leave(stat.Int());
				}

			// compare the data
			if (ptrWritebuf.Compare( ptrReadbuf ) != 0 )
				{
				iQoSStep->iQoSSuite->Log(_L("Data written to and read from destination address do not match in sizevalue"));
//				return Fail;
				}
			recvCount += ptrReadbuf.Length();
			}

		// get rid of the old buffers 
		CleanupStack::PopAndDestroy(2);	//	writebuf and readbuf
		}


	// check the total received (95 per cent is allowable for us)
	if (recvCount*iPacketSize[aExtraSocksToJoin] < (0.95*(iPackets[aExtraSocksToJoin]*iPacketSize[aExtraSocksToJoin])))
		{
		iQoSStep->iQoSSuite->Log(_L("The total packets received is less than 95 per cent of the overall packets sent"));
//		return Fail;
		}
	}