2011-05-21 22:43:57 +02:00
|
|
|
/******************************************************************************\
|
2013-01-23 11:41:13 +01:00
|
|
|
* Copyright (c) 2004-2013
|
2011-05-21 22:43:57 +02:00
|
|
|
*
|
|
|
|
* Author(s):
|
|
|
|
* Volker Fischer
|
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation; either version 2 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
\******************************************************************************/
|
|
|
|
|
|
|
|
#if !defined ( TESTBENCH_HOIHJH8_3_43445KJIUHF1912__INCLUDED_ )
|
|
|
|
#define TESTBENCH_HOIHJH8_3_43445KJIUHF1912__INCLUDED_
|
|
|
|
|
2013-01-02 21:41:04 +01:00
|
|
|
#include <QObject>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QHostAddress>
|
2011-05-21 22:43:57 +02:00
|
|
|
#include "global.h"
|
|
|
|
#include "socket.h"
|
|
|
|
#include "protocol.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Classes ********************************************************************/
|
|
|
|
class CTestbench : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
CTestbench ( QString sNewAddress, quint16 iNewPort ) :
|
2013-08-18 20:05:28 +02:00
|
|
|
sAddress ( sNewAddress ),
|
|
|
|
iPort ( iNewPort )
|
2011-05-21 22:43:57 +02:00
|
|
|
{
|
|
|
|
// bind socket (try 100 port numbers)
|
|
|
|
quint16 iPortIncrement = 0; // start value: port nubmer plus ten
|
|
|
|
bool bSuccess = false; // initialization for while loop
|
2013-08-18 20:05:28 +02:00
|
|
|
|
2011-05-21 22:43:57 +02:00
|
|
|
while ( !bSuccess && ( iPortIncrement <= 100 ) )
|
|
|
|
{
|
2013-08-18 20:05:28 +02:00
|
|
|
bSuccess = UdpSocket.bind ( QHostAddress( QHostAddress::Any ),
|
|
|
|
22222 + iPortIncrement );
|
2011-05-21 22:43:57 +02:00
|
|
|
|
|
|
|
iPortIncrement++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// connect protocol signal
|
|
|
|
QObject::connect ( &Protocol, SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
|
|
|
|
this, SLOT ( OnSendProtMessage ( CVector<uint8_t> ) ) );
|
|
|
|
|
|
|
|
// connect and start the timer (testbench heartbeat)
|
|
|
|
QObject::connect ( &Timer, SIGNAL ( timeout() ),
|
|
|
|
this, SLOT ( OnTimer() ) );
|
|
|
|
|
|
|
|
Timer.start ( 1 ); // 1 ms
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int GenRandomIntInRange ( const int iStart, const int iEnd ) const
|
|
|
|
{
|
|
|
|
return static_cast<int> ( iStart +
|
|
|
|
( ( static_cast<double> ( iEnd - iStart + 1 ) * rand() ) / RAND_MAX ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
QString GenRandomString() const
|
|
|
|
{
|
2013-08-18 20:05:28 +02:00
|
|
|
const int iLen = GenRandomIntInRange ( 0, 111 );
|
2011-05-21 22:43:57 +02:00
|
|
|
QString strReturn = "";
|
2013-08-18 20:05:28 +02:00
|
|
|
|
2011-05-21 22:43:57 +02:00
|
|
|
for ( int i = 0; i < iLen; i++ )
|
|
|
|
{
|
|
|
|
strReturn += static_cast<char> ( GenRandomIntInRange ( 0, 255 ) );
|
|
|
|
}
|
2013-08-18 20:05:28 +02:00
|
|
|
|
2011-05-21 22:43:57 +02:00
|
|
|
return strReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString sAddress;
|
|
|
|
quint16 iPort;
|
|
|
|
QTimer Timer;
|
|
|
|
CProtocol Protocol;
|
|
|
|
QUdpSocket UdpSocket;
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void OnTimer()
|
|
|
|
{
|
2013-02-11 16:53:52 +01:00
|
|
|
CVector<CChannelInfo> vecChanInfo ( 1 );
|
|
|
|
CNetworkTransportProps NetTrProps;
|
|
|
|
CServerCoreInfo ServerInfo;
|
|
|
|
CVector<CServerInfo> vecServerInfo ( 1 );
|
|
|
|
CHostAddress CurHostAddress ( QHostAddress ( sAddress ), iPort );
|
2013-08-18 20:05:28 +02:00
|
|
|
CChannelCoreInfo ChannelCoreInfo;
|
2011-05-21 22:43:57 +02:00
|
|
|
|
|
|
|
// generate random protocol message
|
2013-09-07 22:30:08 +02:00
|
|
|
switch ( GenRandomIntInRange ( 0, 24 ) )
|
2011-05-21 22:43:57 +02:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
Protocol.CreateJitBufMes ( GenRandomIntInRange ( 0, 10 ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
Protocol.CreateReqJitBufMes();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
Protocol.CreateChanGainMes ( GenRandomIntInRange ( 0, 20 ),
|
2013-08-18 20:05:28 +02:00
|
|
|
GenRandomIntInRange ( -100, 100 ) );
|
2011-05-21 22:43:57 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
vecChanInfo[0].iChanID = GenRandomIntInRange ( -2, 20 );
|
|
|
|
vecChanInfo[0].iIpAddr = GenRandomIntInRange ( 0, 100000 );
|
|
|
|
vecChanInfo[0].strName = GenRandomString();
|
|
|
|
|
2013-02-11 16:53:52 +01:00
|
|
|
Protocol.CreateConClientListNameMes ( vecChanInfo );
|
2011-05-21 22:43:57 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
2013-08-18 20:05:28 +02:00
|
|
|
vecChanInfo[0].iChanID = GenRandomIntInRange ( -2, 20 );
|
|
|
|
vecChanInfo[0].iIpAddr = GenRandomIntInRange ( 0, 100000 );
|
|
|
|
vecChanInfo[0].strName = GenRandomString();
|
|
|
|
|
|
|
|
Protocol.CreateConClientListMes ( vecChanInfo );
|
2011-05-21 22:43:57 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
2013-08-18 20:05:28 +02:00
|
|
|
Protocol.CreateReqConnClientsList();
|
2011-05-21 22:43:57 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
2013-08-18 20:05:28 +02:00
|
|
|
Protocol.CreateChanNameMes ( GenRandomString() );
|
2011-05-21 22:43:57 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:
|
2013-08-18 20:05:28 +02:00
|
|
|
ChannelCoreInfo.eCountry =
|
|
|
|
static_cast<QLocale::Country> ( GenRandomIntInRange ( 0, 100 ) );
|
|
|
|
|
|
|
|
ChannelCoreInfo.eSkillLevel =
|
|
|
|
static_cast<ESkillLevel> ( GenRandomIntInRange ( 0, 3 ) );
|
|
|
|
|
|
|
|
ChannelCoreInfo.iInstrument = GenRandomIntInRange ( 0, 100000 );
|
|
|
|
ChannelCoreInfo.strCity = GenRandomString();
|
|
|
|
ChannelCoreInfo.strName = GenRandomString();
|
|
|
|
|
|
|
|
Protocol.CreateChanInfoMes ( ChannelCoreInfo );
|
2011-05-21 22:43:57 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:
|
2013-08-18 20:05:28 +02:00
|
|
|
Protocol.CreateReqChanInfoMes();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 9:
|
|
|
|
Protocol.CreateChatTextMes ( GenRandomString() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 10:
|
2011-05-21 22:43:57 +02:00
|
|
|
NetTrProps.eAudioCodingType =
|
|
|
|
static_cast<EAudComprType> ( GenRandomIntInRange ( 0, 2 ) );
|
|
|
|
|
|
|
|
NetTrProps.iAudioCodingArg = GenRandomIntInRange ( -100, 100 );
|
|
|
|
NetTrProps.iBaseNetworkPacketSize = GenRandomIntInRange ( -2, 1000 );
|
|
|
|
NetTrProps.iBlockSizeFact = GenRandomIntInRange ( -2, 100 );
|
|
|
|
NetTrProps.iNumAudioChannels = GenRandomIntInRange ( -2, 10 );
|
|
|
|
NetTrProps.iSampleRate = GenRandomIntInRange ( -2, 10000 );
|
|
|
|
NetTrProps.iVersion = GenRandomIntInRange ( -2, 10000 );
|
|
|
|
|
|
|
|
Protocol.CreateNetwTranspPropsMes ( NetTrProps );
|
|
|
|
break;
|
|
|
|
|
2013-09-07 22:30:08 +02:00
|
|
|
case 11:
|
2011-05-21 22:43:57 +02:00
|
|
|
Protocol.CreateReqNetwTranspPropsMes();
|
|
|
|
break;
|
|
|
|
|
2013-09-07 22:30:08 +02:00
|
|
|
case 12:
|
2013-08-18 20:05:28 +02:00
|
|
|
Protocol.CreateOpusSupportedMes();
|
|
|
|
break;
|
|
|
|
|
2013-09-07 22:30:08 +02:00
|
|
|
case 13:
|
2011-05-21 22:43:57 +02:00
|
|
|
Protocol.CreateCLPingMes ( CurHostAddress,
|
|
|
|
GenRandomIntInRange ( -2, 1000 ) );
|
|
|
|
break;
|
|
|
|
|
2013-09-07 22:30:08 +02:00
|
|
|
case 14:
|
2011-05-21 22:43:57 +02:00
|
|
|
Protocol.CreateCLPingWithNumClientsMes ( CurHostAddress,
|
|
|
|
GenRandomIntInRange ( -2, 1000 ),
|
|
|
|
GenRandomIntInRange ( -2, 1000 ) );
|
|
|
|
break;
|
|
|
|
|
2013-09-07 22:30:08 +02:00
|
|
|
case 15:
|
2011-05-21 22:43:57 +02:00
|
|
|
Protocol.CreateCLServerFullMes ( CurHostAddress );
|
|
|
|
break;
|
|
|
|
|
2013-09-07 22:30:08 +02:00
|
|
|
case 16:
|
2011-05-21 22:43:57 +02:00
|
|
|
ServerInfo.bPermanentOnline =
|
|
|
|
static_cast<bool> ( GenRandomIntInRange ( 0, 1 ) );
|
|
|
|
|
|
|
|
ServerInfo.eCountry =
|
|
|
|
static_cast<QLocale::Country> ( GenRandomIntInRange ( 0, 100 ) );
|
|
|
|
|
|
|
|
ServerInfo.iLocalPortNumber = GenRandomIntInRange ( -2, 10000 );
|
|
|
|
ServerInfo.iMaxNumClients = GenRandomIntInRange ( -2, 10000 );
|
|
|
|
ServerInfo.strCity = GenRandomString();
|
|
|
|
ServerInfo.strName = GenRandomString();
|
|
|
|
ServerInfo.strTopic = GenRandomString();
|
|
|
|
|
|
|
|
Protocol.CreateCLRegisterServerMes ( CurHostAddress,
|
|
|
|
ServerInfo );
|
|
|
|
break;
|
|
|
|
|
2013-09-07 22:30:08 +02:00
|
|
|
case 17:
|
2011-05-21 22:43:57 +02:00
|
|
|
Protocol.CreateCLUnregisterServerMes ( CurHostAddress );
|
|
|
|
break;
|
|
|
|
|
2013-09-07 22:30:08 +02:00
|
|
|
case 18:
|
2011-05-21 22:43:57 +02:00
|
|
|
vecServerInfo[0].bPermanentOnline =
|
|
|
|
static_cast<bool> ( GenRandomIntInRange ( 0, 1 ) );
|
|
|
|
|
|
|
|
vecServerInfo[0].eCountry =
|
|
|
|
static_cast<QLocale::Country> ( GenRandomIntInRange ( 0, 100 ) );
|
|
|
|
|
|
|
|
vecServerInfo[0].HostAddr = CurHostAddress;
|
|
|
|
vecServerInfo[0].iLocalPortNumber = GenRandomIntInRange ( -2, 10000 );
|
|
|
|
vecServerInfo[0].iMaxNumClients = GenRandomIntInRange ( -2, 10000 );
|
|
|
|
vecServerInfo[0].strCity = GenRandomString();
|
|
|
|
vecServerInfo[0].strName = GenRandomString();
|
|
|
|
vecServerInfo[0].strTopic = GenRandomString();
|
|
|
|
|
|
|
|
Protocol.CreateCLServerListMes ( CurHostAddress,
|
|
|
|
vecServerInfo );
|
|
|
|
break;
|
|
|
|
|
2013-09-07 22:30:08 +02:00
|
|
|
case 19:
|
2011-05-21 22:43:57 +02:00
|
|
|
Protocol.CreateCLReqServerListMes ( CurHostAddress );
|
|
|
|
break;
|
|
|
|
|
2013-09-07 22:30:08 +02:00
|
|
|
case 20:
|
2011-05-21 22:43:57 +02:00
|
|
|
Protocol.CreateCLSendEmptyMesMes ( CurHostAddress,
|
|
|
|
CurHostAddress );
|
|
|
|
break;
|
|
|
|
|
2013-09-07 22:30:08 +02:00
|
|
|
case 21:
|
2011-05-21 22:43:57 +02:00
|
|
|
Protocol.CreateCLEmptyMes ( CurHostAddress );
|
|
|
|
break;
|
|
|
|
|
2013-09-07 22:30:08 +02:00
|
|
|
case 22:
|
2011-05-22 11:47:09 +02:00
|
|
|
Protocol.CreateCLDisconnection ( CurHostAddress );
|
2011-05-21 22:43:57 +02:00
|
|
|
break;
|
|
|
|
|
2013-09-07 22:30:08 +02:00
|
|
|
case 23:
|
2011-05-22 11:47:09 +02:00
|
|
|
Protocol.CreateAndImmSendAcknMess ( GenRandomIntInRange ( -10, 100 ),
|
|
|
|
GenRandomIntInRange ( -100, 100 ) );
|
2011-05-21 22:43:57 +02:00
|
|
|
break;
|
|
|
|
|
2013-09-07 22:30:08 +02:00
|
|
|
case 24:
|
2011-05-21 22:43:57 +02:00
|
|
|
// arbitrary "audio" packet (with random sizes)
|
|
|
|
CVector<uint8_t> vecMessage ( GenRandomIntInRange ( 1, 1000 ) );
|
|
|
|
OnSendProtMessage ( vecMessage );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnSendProtMessage ( CVector<uint8_t> vecMessage )
|
|
|
|
{
|
|
|
|
UdpSocket.writeDatagram (
|
|
|
|
(const char*) &( (CVector<uint8_t>) vecMessage )[0],
|
|
|
|
vecMessage.Size(), QHostAddress ( sAddress ), iPort );
|
|
|
|
|
|
|
|
// reset protocol so that we do not have to wait for an acknowledge to
|
|
|
|
// send the next message
|
|
|
|
Protocol.Reset();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* !defined ( TESTBENCH_HOIHJH8_3_43445KJIUHF1912__INCLUDED_ ) */
|