This commit is contained in:
2025-11-24 14:19:51 +05:30
commit f5c1412b28
6734 changed files with 1527575 additions and 0 deletions

View File

@ -0,0 +1,14 @@
#
# This file was taken from RakNet 4.082 without any modifications.
# Please see licenses/RakNet license.txt for the underlying license and related copyright.
#
cmake_minimum_required(VERSION 2.6)
GETCURRENTFOLDER()
STANDARDSUBPROJECT(${current_folder})
VSUBFOLDER(${current_folder} "Internal Tests")

View File

@ -0,0 +1,151 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "CommonFunctions.h"
CommonFunctions::CommonFunctions(void)
{
}
CommonFunctions::~CommonFunctions(void)
{
}
bool CommonFunctions::ConnectionStateMatchesOptions(RakPeerInterface *peer,SystemAddress currentSystem,bool isConnected,bool isConnecting,bool isPending,bool isDisconnecting,bool isNotConnected,bool isLoopBack , bool isSilentlyDisconnecting)
{
ConnectionState connectionState=peer->GetConnectionState(currentSystem);
switch(connectionState)
{
case IS_CONNECTED:
return isConnected;
break;
case IS_CONNECTING:
return isConnecting;
break;
case IS_PENDING:
return isPending;
break;
case IS_DISCONNECTING:
return isDisconnecting;
break;
case IS_LOOPBACK:
return isLoopBack;
break;
case IS_NOT_CONNECTED:
return isNotConnected;
break;
case IS_SILENTLY_DISCONNECTING:
return isSilentlyDisconnecting;
break;
default:
return false;
break;
}
}
bool CommonFunctions::WaitAndConnect(RakPeerInterface *peer,char* ip,unsigned short int port,int millisecondsToWait)
{
SystemAddress connectToAddress;
connectToAddress.SetBinaryAddress(ip);
connectToAddress.port=port;
TimeMS entryTime=GetTimeMS();
while(!CommonFunctions::ConnectionStateMatchesOptions (peer,connectToAddress,true)&&GetTimeMS()-entryTime<millisecondsToWait)
{
if(!CommonFunctions::ConnectionStateMatchesOptions (peer,connectToAddress,true,true,true,true))
{
peer->Connect(ip,port,0,0);
}
RakSleep(100);
}
if (ConnectionStateMatchesOptions (peer,connectToAddress,true))
{
return 1;
}
return 0;
}
void CommonFunctions::DisconnectAndWait(RakPeerInterface *peer,char* ip,unsigned short int port)
{
SystemAddress targetAddress;
targetAddress.SetBinaryAddress(ip);
targetAddress.port=port;
while(CommonFunctions::ConnectionStateMatchesOptions (peer,targetAddress,true,true,true,true))//disconnect client
{
peer->CloseConnection (targetAddress,true,0,LOW_PRIORITY);
}
}
bool CommonFunctions::WaitForMessageWithID(RakPeerInterface *reciever,int id,int millisecondsToWait)
{
RakTimer timer(millisecondsToWait);
Packet *packet;
while(!timer.IsExpired())
{
for (packet=reciever->Receive(); packet;reciever->DeallocatePacket(packet), packet=reciever->Receive())
{
//printf("Packet %i\n",packet->data[0]);
if (packet->data[0]==id)
{
reciever->DeallocatePacket(packet);
return true;
}
}
}
return false;
}
Packet *CommonFunctions::WaitAndReturnMessageWithID(RakPeerInterface *reciever,int id,int millisecondsToWait)
{
RakTimer timer(millisecondsToWait);
Packet *packet;
while(!timer.IsExpired())
{
for (packet=reciever->Receive(); packet;reciever->DeallocatePacket(packet), packet=reciever->Receive())
{
// printf("Packet %i\n",packet->data[0]);
if (packet->data[0]==id)
{
return packet;
}
}
}
return 0;
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "RakString.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include "RakPeer.h"
#include "RakSleep.h"
#include "RakNetTime.h"
#include "GetTime.h"
#include "DebugTools.h"
#include "RakTimer.h"
using namespace RakNet;
class CommonFunctions
{
public:
CommonFunctions(void);
~CommonFunctions(void);
static bool WaitAndConnect(RakPeerInterface *peer,char* ip,unsigned short int port,int millisecondsToWait);
static bool WaitForMessageWithID(RakPeerInterface *reciever,int id,int millisecondsToWait);
static Packet * WaitAndReturnMessageWithID(RakPeerInterface *reciever,int id,int millisecondsToWait);
static void DisconnectAndWait(RakPeerInterface *peer,char* ip,unsigned short int port);
static bool ConnectionStateMatchesOptions(RakPeerInterface *peer, SystemAddress currentSystem, bool isConnected, bool isConnecting=false, bool isPending=false, bool isDisconnecting=false, bool isNotConnected=false, bool isLoopBack=false, bool isSilentlyDisconnecting=false);
};

View File

@ -0,0 +1,344 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "ComprehensiveConvertTest.h"
/*
Description: Does a little bit of everything forever. This is an internal sample just to see if RakNet crashes or leaks memory over a long period of time.
Todo:
RPC replacement tests when RPC3 includes work.
Success conditions:
No failures.
Failure conditions:
Connect fails without pending ops or current connection.
*/
int ComprehensiveConvertTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
{
static const int CONNECTIONS_PER_SYSTEM =4;
SystemAddress currentSystem;
// DebugTools::ShowError("Note: The conversion of this is on hold until the original sample's problem is known.",!noPauses && isVerbose,__LINE__,__FILE__);
// return 55;
// AutoRPC autoRpcs[NUM_PEERS];
//AutoRPC autoRpcs[NUM_PEERS];
int peerIndex;
float nextAction;
int i;
int portAdd;
char data[8096];
int seed = 12345;
if (isVerbose)
printf("Using seed %i\n", seed);
seedMT(seed);
for (i=0; i < NUM_PEERS; i++)
{
//autoRpcs[i].RegisterFunction("RPC1", RPC1, false);
//autoRpcs[i].RegisterFunction("RPC2", RPC2, false);
//autoRpcs[i].RegisterFunction("RPC3", RPC3, false);
//autoRpcs[i].RegisterFunction("RPC4", RPC4, false);
peers[i]=RakPeerInterface::GetInstance();
peers[i]->SetMaximumIncomingConnections(CONNECTIONS_PER_SYSTEM);
SocketDescriptor socketDescriptor(60000+i, 0);
peers[i]->Startup(NUM_PEERS, &socketDescriptor, 1);
peers[i]->SetOfflinePingResponse("Offline Ping Data", (int)strlen("Offline Ping Data")+1);
}
for (i=0; i < NUM_PEERS; i++)
{
portAdd=randomMT()%NUM_PEERS;
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000+portAdd;
if(!CommonFunctions::ConnectionStateMatchesOptions (peers[i],currentSystem,true,true,true,true) )//Are we connected or is there a pending operation ?
{
ConnectionAttemptResult resultReturn = peers[i]->Connect("127.0.0.1", 60000+portAdd, 0, 0);
if (resultReturn!=CONNECTION_ATTEMPT_STARTED && resultReturn!=ALREADY_CONNECTED_TO_ENDPOINT)
{
DebugTools::ShowError("Problem while calling connect.\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;
}
}
}
TimeMS endTime = GetTimeMS()+10000;
while (GetTimeMS()<endTime)
{
nextAction = frandomMT();
if (nextAction < .04f)
{
// Initialize
peerIndex=randomMT()%NUM_PEERS;
SocketDescriptor socketDescriptor(60000+peerIndex, 0);
peers[peerIndex]->Startup(NUM_PEERS, &socketDescriptor, 1);
portAdd=randomMT()%NUM_PEERS;
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000+portAdd;
if(!CommonFunctions::ConnectionStateMatchesOptions (peers[peerIndex],currentSystem,true,true,true,true) )//Are we connected or is there a pending operation ?
{
ConnectionAttemptResult resultReturn = peers[peerIndex]->Connect("127.0.0.1", 60000+portAdd, 0, 0);
if (resultReturn!=CONNECTION_ATTEMPT_STARTED && resultReturn!=ALREADY_CONNECTED_TO_ENDPOINT)
{
DebugTools::ShowError("Problem while calling connect.\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;
}
}
}
else if (nextAction < .09f)
{
// Connect
peerIndex=randomMT()%NUM_PEERS;
portAdd=randomMT()%NUM_PEERS;
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000+portAdd;
if(!CommonFunctions::ConnectionStateMatchesOptions (peers[peerIndex],currentSystem,true,true,true,true) )//Are we connected or is there a pending operation ?
{
ConnectionAttemptResult resultReturn = peers[peerIndex]->Connect("127.0.0.1", 60000+portAdd, 0, 0);
if (resultReturn!=CONNECTION_ATTEMPT_STARTED && resultReturn!=ALREADY_CONNECTED_TO_ENDPOINT)
{
DebugTools::ShowError("Problem while calling connect.\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;
}
}
}
else if (nextAction < .10f)
{
// Disconnect
peerIndex=randomMT()%NUM_PEERS;
// peers[peerIndex]->Shutdown(randomMT() % 100);
}
else if (nextAction < .12f)
{
// GetConnectionList
peerIndex=randomMT()%NUM_PEERS;
SystemAddress remoteSystems[NUM_PEERS];
unsigned short numSystems=NUM_PEERS;
peers[peerIndex]->GetConnectionList(remoteSystems, &numSystems);
if (numSystems>0)
{
if (isVerbose){
printf("%i: ", 60000+numSystems);
for (i=0; i < numSystems; i++)
{
printf("%i: ", remoteSystems[i].port);
}
printf("\n");
}
}
}
else if (nextAction < .14f)
{
// Send
int dataLength;
PacketPriority priority;
PacketReliability reliability;
unsigned char orderingChannel;
SystemAddress target;
bool broadcast;
// data[0]=ID_RESERVED1+(randomMT()%10);
data[0]=ID_USER_PACKET_ENUM;
dataLength=3+(randomMT()%8000);
// dataLength=600+(randomMT()%7000);
priority=(PacketPriority)(randomMT()%(int)NUMBER_OF_PRIORITIES);
reliability=(PacketReliability)(randomMT()%((int)RELIABLE_SEQUENCED+1));
orderingChannel=randomMT()%32;
if ((randomMT()%NUM_PEERS)==0)
target=UNASSIGNED_SYSTEM_ADDRESS;
else
target=peers[peerIndex]->GetSystemAddressFromIndex(randomMT()%NUM_PEERS);
broadcast=(randomMT()%2)>0;
#ifdef _VERIFY_RECIPIENTS
broadcast=false; // Temporarily in so I can check recipients
#endif
peerIndex=randomMT()%NUM_PEERS;
sprintf(data+3, "dataLength=%i priority=%i reliability=%i orderingChannel=%i target=%i broadcast=%i\n", dataLength, priority, reliability, orderingChannel, target.port, broadcast);
//unsigned short localPort=60000+i;
#ifdef _VERIFY_RECIPIENTS
memcpy((char*)data+1, (char*)&target.port, sizeof(unsigned short));
#endif
data[dataLength-1]=0;
peers[peerIndex]->Send(data, dataLength, priority, reliability, orderingChannel, target, broadcast);
}
else if (nextAction < .18f)
{
// RPC
int dataLength;
PacketPriority priority;
PacketReliability reliability;
unsigned char orderingChannel;
SystemAddress target;
bool broadcast;
char RPCName[10];
data[0]=ID_USER_PACKET_ENUM+(randomMT()%10);
dataLength=3+(randomMT()%8000);
// dataLength=600+(randomMT()%7000);
priority=(PacketPriority)(randomMT()%(int)NUMBER_OF_PRIORITIES);
reliability=(PacketReliability)(randomMT()%((int)RELIABLE_SEQUENCED+1));
orderingChannel=randomMT()%32;
peerIndex=randomMT()%NUM_PEERS;
if ((randomMT()%NUM_PEERS)==0)
target=UNASSIGNED_SYSTEM_ADDRESS;
else
target=peers[peerIndex]->GetSystemAddressFromIndex(randomMT()%NUM_PEERS);
broadcast=(randomMT()%2)>0;
#ifdef _VERIFY_RECIPIENTS
broadcast=false; // Temporarily in so I can check recipients
#endif
sprintf(data+3, "dataLength=%i priority=%i reliability=%i orderingChannel=%i target=%i broadcast=%i\n", dataLength, priority, reliability, orderingChannel, target.port, broadcast);
#ifdef _VERIFY_RECIPIENTS
memcpy((char*)data, (char*)&target.port, sizeof(unsigned short));
#endif
data[dataLength-1]=0;
sprintf(RPCName, "RPC%i", (randomMT()%4)+1);
// autoRpc[i]->Call(RPCName);
//peers[peerIndex]->RPC(RPCName, data, dataLength*8, priority, reliability, orderingChannel, target, broadcast, 0, UNASSIGNED_NETWORK_ID,0);
}
else if (nextAction < .181f)
{
// CloseConnection
SystemAddress target;
peerIndex=randomMT()%NUM_PEERS;
target=peers[peerIndex]->GetSystemAddressFromIndex(randomMT()%NUM_PEERS);
peers[peerIndex]->CloseConnection(target, (randomMT()%2)>0, 0);
}
else if (nextAction < .20f)
{
// Offline Ping
peerIndex=randomMT()%NUM_PEERS;
peers[peerIndex]->Ping("127.0.0.1", 60000+(randomMT()%NUM_PEERS), (randomMT()%2)>0);
}
else if (nextAction < .21f)
{
// Online Ping
SystemAddress target;
target=peers[peerIndex]->GetSystemAddressFromIndex(randomMT()%NUM_PEERS);
peerIndex=randomMT()%NUM_PEERS;
peers[peerIndex]->Ping(target);
}
else if (nextAction < .24f)
{
// SetCompileFrequencyTable
peerIndex=randomMT()%NUM_PEERS;
}
else if (nextAction < .25f)
{
// GetStatistics
SystemAddress target, mySystemAddress;
RakNetStatistics *rss;
mySystemAddress=peers[peerIndex]->GetInternalID();
target=peers[peerIndex]->GetSystemAddressFromIndex(randomMT()%NUM_PEERS);
peerIndex=randomMT()%NUM_PEERS;
rss=peers[peerIndex]->GetStatistics(mySystemAddress);
if (rss)
{
StatisticsToString(rss, data, 0);
if (isVerbose)
printf("Statistics for local system %i:\n%s", mySystemAddress.port, data);
}
rss=peers[peerIndex]->GetStatistics(target);
if (rss)
{
StatisticsToString(rss, data, 0);
if (isVerbose)
printf("Statistics for target system %i:\n%s", target.port, data);
}
}
for (i=0; i < NUM_PEERS; i++)
peers[i]->DeallocatePacket(peers[i]->Receive());
RakSleep(0);
}
return 0;
}
void ComprehensiveConvertTest::DestroyPeers()
{
for (int i=0; i < NUM_PEERS; i++)
RakPeerInterface::DestroyInstance(peers[i]);
}
RakString ComprehensiveConvertTest::GetTestName()
{
return "ComprehensiveConvertTest";
}
RakString ComprehensiveConvertTest::ErrorCodeToString(int errorCode)
{
switch (errorCode)
{
case 0:
return "No error";
break;
case 1:
return "Connect function failed";
break;
default:
return "Undefined Error";
}
}
ComprehensiveConvertTest::ComprehensiveConvertTest(void)
{
}
ComprehensiveConvertTest::~ComprehensiveConvertTest(void)
{
}

View File

@ -0,0 +1,47 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "TestInterface.h"
#include "RakString.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include "RakPeer.h"
#include "RakSleep.h"
#include "RakNetTime.h"
#include "GetTime.h"
#include "DebugTools.h"
#include "CommonFunctions.h"
#include <stdlib.h> // For atoi
#include <cstring> // For strlen
#include "Rand.h"
#include <stdio.h>
using namespace RakNet;
class ComprehensiveConvertTest : public TestInterface
{
public:
ComprehensiveConvertTest(void);
~ComprehensiveConvertTest(void);
int RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses);//should return 0 if no error, or the error number
RakString GetTestName();
RakString ErrorCodeToString(int errorCode);
void DestroyPeers();
private:
static const int NUM_PEERS =10;
RakPeerInterface *peers[NUM_PEERS];
};

View File

@ -0,0 +1,208 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "ConnectWithSocketTest.h"
/*
Description:
virtual bool RakPeerInterface::ConnectWithSocket ( const char * host, unsigned short remotePort, const char * passwordData, int passwordDataLength, RakNetSmartPtr< RakNetSocket > socket, unsigned sendConnectionAttemptCount = 7, unsigned timeBetweenSendConnectionAttemptsMS = 500, TimeMS timeoutTime = 0 )
virtual void RakPeerInterface::GetSockets ( DataStructures::List< RakNetSmartPtr< RakNetSocket > > & sockets )
virtual RakNetSmartPtr<RakNetSocket> RakPeerInterface::GetSocket ( const SystemAddress target ) [pure virtual]
Success conditions:
Failure conditions:
RakPeerInterface Functions used, tested indirectly by its use:
Startup
SetMaximumIncomingConnections
Receive
DeallocatePacket
Send
IsConnected
RakPeerInterface Functions Explicitly Tested:
ConnectWithSocket
GetSockets
GetSocket
*/
int ConnectWithSocketTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
{
destroyList.Clear(false,_FILE_AND_LINE_);
RakPeerInterface *server,*client;
DataStructures::List< RakNetSmartPtr< RakNetSocket > > sockets;
TestHelpers::StandardClientPrep(client,destroyList);
TestHelpers::StandardServerPrep(server,destroyList);
SystemAddress serverAddress;
serverAddress.SetBinaryAddress("127.0.0.1");
serverAddress.port=60000;
printf("Testing normal connect before test\n");
if (!TestHelpers::WaitAndConnectTwoPeersLocally(client,server,5000))
{
if (isVerbose)
DebugTools::ShowError(errorList[1-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 1;
}
TestHelpers::BroadCastTestPacket(client);
if (!TestHelpers::WaitForTestPacket(server,5000))
{
if (isVerbose)
DebugTools::ShowError(errorList[2-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 2;
}
printf("Disconnecting client\n");
CommonFunctions::DisconnectAndWait(client,"127.0.0.1",60000);
RakNetSmartPtr<RakNetSocket> theSocket;
client->GetSockets(sockets);
theSocket=sockets[0];
RakTimer timer2(5000);
printf("Testing ConnectWithSocket using socket from GetSockets\n");
while(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true)&&!timer2.IsExpired())
{
if(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,true,true,true))
{
client->ConnectWithSocket("127.0.0.1",serverAddress.port,0,0,theSocket);
}
RakSleep(100);
}
if (!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true))
{
if (isVerbose)
DebugTools::ShowError(errorList[3-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 3;
}
TestHelpers::BroadCastTestPacket(client);
if (!TestHelpers::WaitForTestPacket(server,5000))
{
if (isVerbose)
DebugTools::ShowError(errorList[4-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 4;
}
printf("Disconnecting client\n");
CommonFunctions::DisconnectAndWait(client,"127.0.0.1",60000);
printf("Testing ConnectWithSocket using socket from GetSocket\n");
theSocket=client->GetSocket(UNASSIGNED_SYSTEM_ADDRESS);//Get open Socket
timer2.Start();
while(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true)&&!timer2.IsExpired())
{
if(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,true,true,true))
{
client->ConnectWithSocket("127.0.0.1",serverAddress.port,0,0,theSocket);
}
RakSleep(100);
}
if (!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true))
{
if (isVerbose)
DebugTools::ShowError(errorList[5-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 5;
}
TestHelpers::BroadCastTestPacket(client);
if (!TestHelpers::WaitForTestPacket(server,5000))
{
if (isVerbose)
DebugTools::ShowError(errorList[6-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 6;
}
return 0;
}
RakString ConnectWithSocketTest::GetTestName()
{
return "ConnectWithSocketTest";
}
RakString ConnectWithSocketTest::ErrorCodeToString(int errorCode)
{
if (errorCode>0&&(unsigned int)errorCode<=errorList.Size())
{
return errorList[errorCode-1];
}
else
{
return "Undefined Error";
}
}
ConnectWithSocketTest::ConnectWithSocketTest(void)
{
errorList.Push("Client did not connect after 5 seconds",_FILE_AND_LINE_);
errorList.Push("Control test send didn't work",_FILE_AND_LINE_);
errorList.Push("Client did not connect after 5 secods Using ConnectWithSocket, could be GetSockets or ConnectWithSocket problem",_FILE_AND_LINE_);
errorList.Push("Server did not recieve test packet from client",_FILE_AND_LINE_);
errorList.Push("Client did not connect after 5 secods Using ConnectWithSocket, could be GetSocket or ConnectWithSocket problem",_FILE_AND_LINE_);
errorList.Push("Server did not recieve test packet from client",_FILE_AND_LINE_);
}
ConnectWithSocketTest::~ConnectWithSocketTest(void)
{
}
void ConnectWithSocketTest::DestroyPeers()
{
int theSize=destroyList.Size();
for (int i=0; i < theSize; i++)
RakPeerInterface::DestroyInstance(destroyList[i]);
}

View File

@ -0,0 +1,45 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "TestInterface.h"
#include "RakString.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include "RakPeer.h"
#include "RakSleep.h"
#include "RakNetTime.h"
#include "GetTime.h"
#include "DebugTools.h"
#include "TestHelpers.h"
#include "CommonFunctions.h"
using namespace RakNet;
class ConnectWithSocketTest : public TestInterface
{
public:
ConnectWithSocketTest(void);
~ConnectWithSocketTest(void);
int RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses);//should return 0 if no error, or the error number
RakString GetTestName();
RakString ErrorCodeToString(int errorCode);
void DestroyPeers();
private:
DataStructures::List <RakString> errorList;
DataStructures::List <RakPeerInterface *> destroyList;
};

View File

@ -0,0 +1,262 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "CrossConnectionConvertTest.h"
/*
Description: Tests what happens if two instances of RakNet connect to each other at the same time. This has caused handshaking problems in the past.
Success conditions:
Everything connects and sends normally.
Failure conditions:
Expected values from ping/pong do not occur within expected time.
*/
int CrossConnectionConvertTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
{
static const unsigned short SERVER_PORT=1234;
// char serverMode[32];
char serverIP[64];
strcpy(serverIP,"127.0.0.1");
char clientIP[64];
RakPeerInterface *server,*client;
unsigned short clientPort;
bool gotNotification;
server=RakPeerInterface::GetInstance();
destroyList.Clear(false,_FILE_AND_LINE_);
destroyList.Push(server,_FILE_AND_LINE_);
client=RakPeerInterface::GetInstance();
destroyList.Push(client,_FILE_AND_LINE_);
server->Startup(1,&SocketDescriptor(SERVER_PORT,0), 1);
server->SetMaximumIncomingConnections(1);
client->Startup(1,&SocketDescriptor(0,0), 1);
client->Ping(serverIP,SERVER_PORT,false);
// PacketLogger pl;
// pl.LogHeader();
// rakPeer->AttachPlugin(&pl);
TimeMS connectionAttemptTime=0,connectionResultDeterminationTime=0,nextTestStartTime=0;
TimeMS entryTime=GetTimeMS();//Loop entry time
bool printedYet=false;
while(GetTimeMS()-entryTime<10000)//Run for 10 Secoonds
{
Packet *p;
printedYet=false;
for (p=server->Receive(); p; server->DeallocatePacket(p), p=server->Receive())
{
if (isVerbose&&!printedYet)
{
printf("Server:\n");
printedYet=true;
}
if (p->data[0]==ID_NEW_INCOMING_CONNECTION)
{
if (isVerbose)
printf("ID_NEW_INCOMING_CONNECTION\n");
gotNotification=true;
}
else if (p->data[0]==ID_CONNECTION_REQUEST_ACCEPTED)
{
if (isVerbose)
printf("ID_CONNECTION_REQUEST_ACCEPTED\n");
gotNotification=true;
}
else if (p->data[0]==ID_UNCONNECTED_PING)
{
if (isVerbose)
printf("ID_PING\n");
connectionAttemptTime=GetTimeMS()+1000;
p->systemAddress.ToString(false,clientIP);
clientPort=p->systemAddress.port;
gotNotification=false;
}
else if (p->data[0]==ID_UNCONNECTED_PONG)
{
if (isVerbose)
printf("ID_UNCONNECTED_PONG\n");
TimeMS sendPingTime;
BitStream bs(p->data,p->length,false);
bs.IgnoreBytes(1);
bs.Read(sendPingTime);
TimeMS rtt = GetTimeMS() - sendPingTime;
if (rtt/2<=500)
connectionAttemptTime=GetTimeMS()+1000-rtt/2;
else
connectionAttemptTime=GetTimeMS();
gotNotification=false;
}
}
printedYet=false;
for (p=client->Receive(); p; client->DeallocatePacket(p), p=client->Receive())
{
if (isVerbose&&!printedYet)
{
printf("Client:\n");
printedYet=true;
}
if (p->data[0]==ID_NEW_INCOMING_CONNECTION)
{
if (isVerbose)
printf("ID_NEW_INCOMING_CONNECTION\n");
gotNotification=true;
}
else if (p->data[0]==ID_CONNECTION_REQUEST_ACCEPTED)
{
if (isVerbose)
printf("ID_CONNECTION_REQUEST_ACCEPTED\n");
gotNotification=true;
}
else if (p->data[0]==ID_UNCONNECTED_PING)
{
if (isVerbose)
printf("ID_PING\n");
connectionAttemptTime=GetTimeMS()+1000;
p->systemAddress.ToString(false,clientIP);
clientPort=p->systemAddress.port;
gotNotification=false;
}
else if (p->data[0]==ID_UNCONNECTED_PONG)
{
if (isVerbose)
printf("ID_UNCONNECTED_PONG\n");
TimeMS sendPingTime;
BitStream bs(p->data,p->length,false);
bs.IgnoreBytes(1);
bs.Read(sendPingTime);
TimeMS rtt = GetTimeMS() - sendPingTime;
if (rtt/2<=500)
connectionAttemptTime=GetTimeMS()+1000-rtt/2;
else
connectionAttemptTime=GetTimeMS();
gotNotification=false;
}
}
if (connectionAttemptTime!=0 && GetTimeMS()>=connectionAttemptTime)
{
if (isVerbose)
printf("Attemping connection\n");
connectionAttemptTime=0;
server->Connect(clientIP,clientPort,0,0);
client->Connect(serverIP,SERVER_PORT,0,0);
connectionResultDeterminationTime=GetTimeMS()+2000;
}
if (connectionResultDeterminationTime!=0 && GetTimeMS()>=connectionResultDeterminationTime)
{
connectionResultDeterminationTime=0;
if (gotNotification==false)
{
DebugTools::ShowError("Did not recieve expected response. \n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;
}
SystemAddress sa;
sa.SetBinaryAddress(serverIP);
sa.port=SERVER_PORT;
client->CancelConnectionAttempt(sa);
sa.SetBinaryAddress(clientIP);
sa.port=clientPort;
server->CancelConnectionAttempt(sa);
server->CloseConnection(server->GetSystemAddressFromIndex(0),true,0);
client->CloseConnection(client->GetSystemAddressFromIndex(0),true,0);
//if (isServer==false)
nextTestStartTime=GetTimeMS()+1000;
}
if (nextTestStartTime!=0 && GetTimeMS()>=nextTestStartTime)
{
client->Ping(serverIP,SERVER_PORT,false);
nextTestStartTime=0;
}
RakSleep(0);
}
if (isVerbose)
printf("Test succeeded.\n");
return 0;
}
RakString CrossConnectionConvertTest::GetTestName()
{
return "CrossConnectionConvertTest";
}
RakString CrossConnectionConvertTest::ErrorCodeToString(int errorCode)
{
switch (errorCode)
{
case 0:
return "No error";
break;
case 1:
return "Did not recieve expected response";
break;
default:
return "Undefined Error";
}
}
void CrossConnectionConvertTest::DestroyPeers()
{
int theSize=destroyList.Size();
for (int i=0; i < theSize; i++)
RakPeerInterface::DestroyInstance(destroyList[i]);
}
CrossConnectionConvertTest::CrossConnectionConvertTest(void)
{
}
CrossConnectionConvertTest::~CrossConnectionConvertTest(void)
{
}

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "TestInterface.h"
#include "RakString.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include "RakPeer.h"
#include "RakSleep.h"
#include "RakNetTime.h"
#include "GetTime.h"
#include "DebugTools.h"
using namespace RakNet;
class CrossConnectionConvertTest : public TestInterface
{
public:
CrossConnectionConvertTest(void);
~CrossConnectionConvertTest(void);
int RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses);//should return 0 if no error, or the error number
RakString GetTestName();
RakString ErrorCodeToString(int errorCode);
void DestroyPeers();
private:
DataStructures::List <RakPeerInterface *> destroyList;
};

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "DebugTools.h"
DebugTools::DebugTools(void)
{
}
DebugTools::~DebugTools(void)
{
}
void DebugTools::ShowError(RakString errorString,bool pause, unsigned int lineNum,const char *fileName)
{
char pauseChar;
fflush(stdin);
printf("%s\nFile:%s \nLine: %i\n",errorString.C_String(),fileName,lineNum);
if (pause)
{
printf("Press enter to continue \n");
pauseChar=getchar();
}
}

View File

@ -0,0 +1,23 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "RakString.h"
using namespace RakNet;
class DebugTools
{
public:
DebugTools(void);
~DebugTools(void);
static void ShowError(RakString errorString,bool pause, unsigned int lineNum,const char *fileName);
};

View File

@ -0,0 +1,417 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "DroppedConnectionConvertTest.h"
/*
Description:
Tests silently dropping multiple instances of RakNet. This is used to test that lost connections are detected properly.
Randomly tests the timout detections to see if the connections are dropped.
Success conditions:
Clients connect and reconnect normally and do not have an extra connection.
Random timout detection passes.
Failure conditions:
Client has more than one connection.
Client unable to reconnect.
Connect function fails and there is no pending operation and there is no current connection with server.
Random timout detection fails.
*/
static const int NUMBER_OF_CLIENTS=9;
int DroppedConnectionConvertTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
{
RakPeerInterface *server;
RakPeerInterface *clients[NUMBER_OF_CLIENTS];
unsigned index, connectionCount;
SystemAddress serverID;
Packet *p;
unsigned short numberOfSystems;
unsigned short numberOfSystems2;
int sender;
// Buffer for input (an ugly hack to keep *nix happy)
// char buff[256];
// Used to refer to systems. We already know the IP
unsigned short serverPort = 20000;
serverID.binaryAddress=inet_addr("127.0.0.1");
serverID.port=serverPort;
server=RakPeerInterface::GetInstance();
destroyList.Clear(false,_FILE_AND_LINE_);
destroyList.Push(server,_FILE_AND_LINE_);
// server->InitializeSecurity(0,0,0,0);
SocketDescriptor socketDescriptor(serverPort,0);
server->Startup(NUMBER_OF_CLIENTS, &socketDescriptor, 1);
server->SetMaximumIncomingConnections(NUMBER_OF_CLIENTS);
server->SetTimeoutTime(2000,UNASSIGNED_SYSTEM_ADDRESS);
for (index=0; index < NUMBER_OF_CLIENTS; index++)
{
clients[index]=RakPeerInterface::GetInstance();
destroyList.Push(clients[index],_FILE_AND_LINE_);
SocketDescriptor socketDescriptor2(serverPort+1+index,0);
clients[index]->Startup(1, &socketDescriptor2, 1);
if (clients[index]->Connect("127.0.0.1", serverPort, 0, 0)!=CONNECTION_ATTEMPT_STARTED)
{
DebugTools::ShowError("Connect function failed.",!noPauses && isVerbose,__LINE__,__FILE__);
return 2;
}
clients[index]->SetTimeoutTime(5000,UNASSIGNED_SYSTEM_ADDRESS);
RakSleep(1000);
if (isVerbose)
printf("%i. ", index);
}
TimeMS entryTime=GetTimeMS();//Loop entry time
int seed = 12345;
if (isVerbose)
printf("Using seed %i\n", seed);
seedMT(seed);//specify seed to keep execution path the same.
int randomTest;
bool dropTest=false;
RakTimer timeoutWaitTimer(1000);
while (GetTimeMS()-entryTime<30000)//run for 30 seconds.
{
// User input
randomTest=randomMT() %4;
if(dropTest)
{
server->GetConnectionList(0, &numberOfSystems);
numberOfSystems2=numberOfSystems;
connectionCount=0;
for (index=0; index < NUMBER_OF_CLIENTS; index++)
{
clients[index]->GetConnectionList(0, &numberOfSystems);
if (numberOfSystems>1)
{
if (isVerbose)
{
printf("Client %i has %i connections\n", index, numberOfSystems);
DebugTools::ShowError("Client has more than one connection",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;
}
}
if (numberOfSystems==1)
{
connectionCount++;
}
}
if (connectionCount!=numberOfSystems2)
{
if (isVerbose)
DebugTools::ShowError("Timeout on dropped clients not detected",!noPauses && isVerbose,__LINE__,__FILE__);
return 3;
}
}
dropTest=false;
switch(randomTest)
{
case 0:
{
index = randomMT() % NUMBER_OF_CLIENTS;
clients[index]->GetConnectionList(0, &numberOfSystems);
clients[index]->CloseConnection(serverID, false,0);
if (numberOfSystems==0)
{
if (isVerbose)
printf("Client %i silently closing inactive connection.\n",index);
}
else
{
if (isVerbose)
printf("Client %i silently closing active connection.\n",index);
}
}
break;
case 1:
{
index = randomMT() % NUMBER_OF_CLIENTS;
clients[index]->GetConnectionList(0, &numberOfSystems);
if(!CommonFunctions::ConnectionStateMatchesOptions (clients[index],serverID,true,true,true,true) )//Are we connected or is there a pending operation ?
{
if (clients[index]->Connect("127.0.0.1", serverPort, 0, 0)!=CONNECTION_ATTEMPT_STARTED)
{
DebugTools::ShowError("Connect function failed.",!noPauses && isVerbose,__LINE__,__FILE__);
return 2;
}
}
if (numberOfSystems==0)
{
if (isVerbose)
printf("Client %i connecting to same existing connection.\n",index);
}
else
{
if (isVerbose)
printf("Client %i connecting to closed connection.\n",index);
}
}
break;
case 2:
{
if (isVerbose)
printf("Randomly connecting and disconnecting each client\n");
for (index=0; index < NUMBER_OF_CLIENTS; index++)
{
if (NUMBER_OF_CLIENTS==1 || (randomMT()%2)==0)
{
if (clients[index]->IsActive())
{
int randomTest2=randomMT() %2;
if (randomTest2)
clients[index]->CloseConnection(serverID, false, 0);
else
clients[index]->CloseConnection(serverID, true, 0);
}
}
else
{
if(!CommonFunctions::ConnectionStateMatchesOptions (clients[index],serverID,true,true,true,true) )//Are we connected or is there a pending operation ?
{
if (clients[index]->Connect("127.0.0.1", serverPort, 0, 0)!=CONNECTION_ATTEMPT_STARTED)
{
DebugTools::ShowError("Connect function failed.",!noPauses && isVerbose,__LINE__,__FILE__);
return 2;
}
}
}
}
}
break;
case 3:
{
if (isVerbose)
printf("Testing if clients dropped after timeout.\n");
timeoutWaitTimer.Start();
//Wait half the timeout time, the other half after receive so we don't drop all connections only missing ones, Active ait so the threads run on linux
while (!timeoutWaitTimer.IsExpired())
{
RakSleep(50);
}
dropTest=true;
}
break;
default:
// Ignore anything else
break;
}
server->GetConnectionList(0, &numberOfSystems);
numberOfSystems2=numberOfSystems;
if (isVerbose)
printf("The server thinks %i clients are connected.\n", numberOfSystems);
connectionCount=0;
for (index=0; index < NUMBER_OF_CLIENTS; index++)
{
clients[index]->GetConnectionList(0, &numberOfSystems);
if (numberOfSystems>1)
{
if (isVerbose)
{
printf("Client %i has %i connections\n", index, numberOfSystems);
DebugTools::ShowError("Client has more than one connection",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;
}
}
if (numberOfSystems==1)
{
connectionCount++;
}
}
if (isVerbose)
printf("%i clients are actually connected.\n", connectionCount);
if (isVerbose)
printf("server->NumberOfConnections==%i.\n", server->NumberOfConnections());
//}
// Parse messages
while (1)
{
p = server->Receive();
sender=NUMBER_OF_CLIENTS;
if (p==0)
{
for (index=0; index < NUMBER_OF_CLIENTS; index++)
{
p = clients[index]->Receive();
if (p!=0)
{
sender=index;
break;
}
}
}
if (p)
{
switch (p->data[0])
{
case ID_CONNECTION_REQUEST_ACCEPTED:
if (isVerbose)
printf("%i: %ID_CONNECTION_REQUEST_ACCEPTED from %i.\n",sender, p->systemAddress.port);
break;
case ID_DISCONNECTION_NOTIFICATION:
// Connection lost normally
if (isVerbose)
printf("%i: ID_DISCONNECTION_NOTIFICATION from %i.\n",sender, p->systemAddress.port);
break;
case ID_NEW_INCOMING_CONNECTION:
// Somebody connected. We have their IP now
if (isVerbose)
printf("%i: ID_NEW_INCOMING_CONNECTION from %i.\n",sender, p->systemAddress.port);
break;
case ID_CONNECTION_LOST:
// Couldn't deliver a reliable packet - i.e. the other system was abnormally
// terminated
if (isVerbose)
printf("%i: ID_CONNECTION_LOST from %i.\n",sender, p->systemAddress.port);
break;
case ID_NO_FREE_INCOMING_CONNECTIONS:
if (isVerbose)
printf("%i: ID_NO_FREE_INCOMING_CONNECTIONS from %i.\n",sender, p->systemAddress.port);
break;
default:
// Ignore anything else
break;
}
}
else
break;
if (sender==NUMBER_OF_CLIENTS)
server->DeallocatePacket(p);
else
clients[sender]->DeallocatePacket(p);
}
if (dropTest)
{
//Trigger the timeout if no recieve
timeoutWaitTimer.Start();
while (!timeoutWaitTimer.IsExpired())
{
RakSleep(50);
}
}
// 11/29/05 - No longer necessary since I added the keepalive
/*
// Have everyone send a reliable packet so dropped connections are noticed.
ch=255;
server->Send((char*)&ch, 1, HIGH_PRIORITY, RELIABLE, 0, UNASSIGNED_SYSTEM_ADDRESS, true);
for (index=0; index < NUMBER_OF_CLIENTS; index++)
clients[index]->Send((char*)&ch, 1, HIGH_PRIORITY, RELIABLE, 0, UNASSIGNED_SYSTEM_ADDRESS, true);
*/
// Sleep so this loop doesn't take up all the CPU time
RakSleep(10);
}
return 0;
}
RakString DroppedConnectionConvertTest::GetTestName()
{
return "DroppedConnectionConvertTest";
}
RakString DroppedConnectionConvertTest::ErrorCodeToString(int errorCode)
{
switch (errorCode)
{
case 0:
return "No error";
break;
case 1:
return "Client has more than one connection";
break;
case 2:
return "Connect failed";
break;
case 3:
return "Timeout not detected";
break;
default:
return "Undefined Error";
}
}
void DroppedConnectionConvertTest::DestroyPeers()
{
int theSize=destroyList.Size();
for (int i=0; i < theSize; i++)
RakPeerInterface::DestroyInstance(destroyList[i]);
}
DroppedConnectionConvertTest::DroppedConnectionConvertTest(void)
{
}
DroppedConnectionConvertTest::~DroppedConnectionConvertTest(void)
{
}

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "TestInterface.h"
#include "RakString.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include "RakPeer.h"
#include "RakSleep.h"
#include "RakNetTime.h"
#include "GetTime.h"
#include "DebugTools.h"
#include "Rand.h" // randomMT
#include "RakTimer.h"
#include <cstdio>
#include "CommonFunctions.h"
using namespace RakNet;
class DroppedConnectionConvertTest :
public TestInterface
{
public:
DroppedConnectionConvertTest(void);
~DroppedConnectionConvertTest(void);
int RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses);//should return 0 if no error, or the error number
RakString GetTestName();
RakString ErrorCodeToString(int errorCode);
void DestroyPeers();
private:
DataStructures::List <RakPeerInterface *> destroyList;
};

View File

@ -0,0 +1,378 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "EightPeerTest.h"
/*
What is being done here is having 8 peers all connect to eachother and be
connected. Then it check if they all connect. If so send data in ordered reliable mode for 100
loops.
Possible ideas for changes:
Possibly use rakpeerinterfaces GetSystemList() for number of
connected peers instead of manually tracking. Would be slower though,
shouldn't be significant at this number but the recieve speed it part of the test.
Success conditions:
Peers connect and receive all packets in order.
No disconnections allowed in this version of the test.
Failure conditions:
If cannot connect to all peers for 20 seconds.
All packets are not recieved.
All packets are not in order.
Disconnection.
*/
int EightPeerTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
{
const int peerNum= 8;
RakPeerInterface *peerList[peerNum];//A list of 8 peers
int connectionAmount[peerNum];//Counter for me to keep track of connection requests and accepts
int recievedFromList[peerNum][peerNum];//Counter for me to keep track of packets received
int lastNumberReceivedFromList[peerNum][peerNum];//Counter for me to keep track of last recieved sequence number
const int numPackets=100;
Packet *packet;
BitStream bitStream;
destroyList.Clear(false,_FILE_AND_LINE_);
//Initializations of the arrays
for (int i=0;i<peerNum;i++)
{
peerList[i]=RakPeerInterface::GetInstance();
destroyList.Push(peerList[i],_FILE_AND_LINE_);
connectionAmount[i]=0;
for (int j=0;j<peerNum;j++)
{
recievedFromList[i][j]=0;
lastNumberReceivedFromList[i][j]=0;
}
peerList[i]->Startup(peerNum*2, &SocketDescriptor(60000+i,0), 1);
peerList[i]->SetMaximumIncomingConnections(peerNum);
}
//Connect all the peers together
for (int i=0;i<peerNum;i++)
{
for (int j=i+1;j<peerNum;j++)//Start at i+1 so don't connect two of the same together.
{
if (peerList[i]->Connect("127.0.0.1", 60000+j, 0,0)!=CONNECTION_ATTEMPT_STARTED)
{
if (isVerbose)
{
DebugTools::ShowError("Problem while calling connect. \n",!noPauses && isVerbose,__LINE__,__FILE__);
}
return 1;//This fails the test, don't bother going on.
}
}
}
TimeMS entryTime=GetTimeMS();//Loop entry time
TimeMS finishTimer=GetTimeMS();
bool initialConnectOver=false;//Our initial connect all has been done.
for (int k=0;k<numPackets||GetTimeMS()-finishTimer<5000;)//Quit after we send 100 messages while connected, if not all connected and not failure, otherwise fail after 20 seconds and exit
{
bool allConnected=true;//Start true, only one failed case makes it all fail
for (int i=0;i<peerNum;i++)//Make sure all peers are connected to eachother
{
if (connectionAmount[i]<peerNum-1)
{
allConnected=false;
}
}
if (GetTimeMS()-entryTime>20000 &&!initialConnectOver &&!allConnected)//failed for 20 seconds
{
if (isVerbose)
DebugTools::ShowError("Failed to connect to all peers after 20 seconds",!noPauses && isVerbose,__LINE__,__FILE__);
return 2;
break;
}
if (allConnected)
{
if(!initialConnectOver)
initialConnectOver=true;
if (k<numPackets)
{
for (int i=0;i<peerNum;i++)//Have all peers send a message to all peers
{
bitStream.Reset();
bitStream.Write((unsigned char) (ID_USER_PACKET_ENUM+1));
bitStream.Write(k);
bitStream.Write(i);
peerList[i]->Send(&bitStream, HIGH_PRIORITY, RELIABLE_ORDERED ,0, UNASSIGNED_SYSTEM_ADDRESS, true);
}
}
k++;
}
if (k>=numPackets-3)//This is our last 3 packets, give it time to send packet and arrive on interface, 2 seconds is more than enough
{
RakSleep(300);
if (k==numPackets)
{
finishTimer=GetTimeMS();
}
}
for (int i=0;i<peerNum;i++)//Receive for all peers
{
if (allConnected)//If all connected try to make the data more visually appealing by bunching it in one receive
{
int waittime=0;
do
{
packet=peerList[i]->Receive();
waittime++;
if (!packet)
{
RakSleep(1);
}
if (waittime>1000)//Check for packet every millisec and if one second has passed move on, don't block execution
{
break;
}
}
while(!packet);//For testing purposes wait for packet a little while, go if not recieved
}
else//Otherwise just keep recieving quickly until connected
{
packet=peerList[i]->Receive();
}
if (isVerbose)
printf("For peer %i with %i connected peers.\n",i,connectionAmount[i]);
while(packet)
{
switch (packet->data[0])
{
case ID_REMOTE_DISCONNECTION_NOTIFICATION:
if (isVerbose)
{
printf("Another client has disconnected.\n");
DebugTools::ShowError("Test failed.\n",!noPauses && isVerbose,__LINE__,__FILE__);
}
return 3;
break;
case ID_REMOTE_CONNECTION_LOST:
if (isVerbose)
{
printf("Another client has lost the connection.\n");
DebugTools::ShowError("Test failed.\n",!noPauses && isVerbose,__LINE__,__FILE__);
}
return 3;
break;
case ID_REMOTE_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("Another client has connected.\n");
break;
case ID_CONNECTION_REQUEST_ACCEPTED:
if (isVerbose)
printf("Our connection request has been accepted.\n");
connectionAmount[i]++;
break;
case ID_CONNECTION_ATTEMPT_FAILED:
if (isVerbose)
DebugTools::ShowError("A connection has failed.\n Test failed.\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 2;
break;
case ID_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("A connection is incoming.\n");
connectionAmount[i]++;//For this test assume connection. Test will fail if connection fails.
break;
case ID_NO_FREE_INCOMING_CONNECTIONS://Should not happend
if (isVerbose)
{
printf("The server is full. This shouldn't happen in this test ever.\n");
DebugTools::ShowError("Test failed.\n",!noPauses && isVerbose,__LINE__,__FILE__);
}
return 2;
break;
case ID_ALREADY_CONNECTED:
if (isVerbose)
printf("Already connected\n");//Shouldn't happen
break;
case ID_DISCONNECTION_NOTIFICATION:
if (isVerbose)
{
printf("We have been disconnected.\n");
DebugTools::ShowError("Test failed.\n",!noPauses && isVerbose,__LINE__,__FILE__);
}
return 3;
break;
case ID_CONNECTION_LOST:
allConnected=false;
connectionAmount[i]--;
if (isVerbose)
{
printf("Connection lost.\n");
DebugTools::ShowError("Test failed.\n",!noPauses && isVerbose,__LINE__,__FILE__);
}
return 3;
break;
default:
if (packet->data[0]==ID_USER_PACKET_ENUM+1)
{
int thePeerNum;
int sequenceNum;
bitStream.Reset();
bitStream.Write((char*)packet->data, packet->length);
bitStream.IgnoreBits(8);
bitStream.Read(sequenceNum);
bitStream.Read(thePeerNum);
if (isVerbose)
printf("Message %i from %i\n",sequenceNum,thePeerNum );
if (thePeerNum>=0&&thePeerNum<peerNum)
{
if (lastNumberReceivedFromList[i][thePeerNum]==sequenceNum)
{
lastNumberReceivedFromList[i][thePeerNum]++;
}
else
{
if (isVerbose)
{
printf("Packets out of order");
DebugTools::ShowError("Test failed.\n",!noPauses && isVerbose,__LINE__,__FILE__);
}
return 4;
}
recievedFromList[i][thePeerNum]++;}
}
break;
}
peerList[i]->DeallocatePacket(packet);
// Stay in the loop as long as there are more packets.
packet = peerList[i]->Receive();
}
}
RakSleep(0);//If needed for testing
}
for (int i=0;i<peerNum;i++)
{
for (int j=0;j<peerNum;j++)
{
if (i!=j)
{
if (isVerbose)
printf("%i recieved %i packets from %i\n",i,recievedFromList[i][j],j);
if (recievedFromList[i][j]!=numPackets)
{
if (isVerbose)
{
printf("Not all packets recieved. it was in reliable ordered mode so that means test failed or wait time needs increasing\n");
DebugTools::ShowError("Test failed.\n",!noPauses && isVerbose,__LINE__,__FILE__);
}
return 5;
}
}
}
}
printf("All packets recieved in order,pass\n");
return 0;
}
RakString EightPeerTest::GetTestName()
{
return "EightPeerTest";
}
RakString EightPeerTest::ErrorCodeToString(int errorCode)
{
switch (errorCode)
{
case 0:
return "No error";
break;
case 1:
return "Connect function returned failure.";
break;
case 2:
return "Peers failed to connect.";
break;
case 3:
return "There was a disconnection.";
break;
case 4:
return "Not ordered.";
break;
case 5:
return "Not reliable.";
break;
default:
return "Undefined Error";
}
}
EightPeerTest::EightPeerTest(void)
{
}
EightPeerTest::~EightPeerTest(void)
{
}
void EightPeerTest::DestroyPeers()
{
int theSize=destroyList.Size();
for (int i=0; i < theSize; i++)
RakPeerInterface::DestroyInstance(destroyList[i]);
}

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "TestInterface.h"
#include "RakString.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include "RakPeer.h"
#include "RakSleep.h"
#include "RakNetTime.h"
#include "GetTime.h"
#include "DebugTools.h"
using namespace RakNet;
class EightPeerTest : public TestInterface
{
public:
EightPeerTest(void);
~EightPeerTest(void);
int RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses);//should return 0 if no error, or the error number
RakString GetTestName();
RakString ErrorCodeToString(int errorCode);
void DestroyPeers();
private:
DataStructures::List <RakPeerInterface *> destroyList;
};

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "EightPeerTest.h"
#include "ManyClientsOneServerBlockingTest.h"
#include "ManyClientsOneServerNonBlockingTest.h"
#include "ManyClientsOneServerDeallocateBlockingTest.h"
#include "ManyClientsOneServerDeallocateTest.h"
#include "MaximumConnectTest.h"
#include "PeerConnectDisconnectTest.h"
#include "PeerConnectDisconnectWithCancelPendingTest.h"
#include "ReliableOrderedConvertedTest.h"
#include "DroppedConnectionConvertTest.h"
#include "ComprehensiveConvertTest.h"
#include "CrossConnectionConvertTest.h"
#include "PingTestsTest.h"
#include "OfflineMessagesConvertTest.h"
#include "LocalIsConnectedTest.h"
#include "SecurityFunctionsTest.h"
#include "ConnectWithSocketTest.h"
#include "SystemAddressAndGuidTest.h"
#include "PacketAndLowLevelTestsTest.h"
#include "MiscellaneousTestsTest.h"

View File

@ -0,0 +1,282 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "LocalIsConnectedTest.h"
/*
Description:
Tests
IsLocalIP
SendLoopback
GetConnectionState
GetLocalIP
GetInternalID
Success conditions:
All tests pass
Failure conditions:
Any test fails
RakPeerInterface Functions used, tested indirectly by its use:
Startup
SetMaximumIncomingConnections
Receive
DeallocatePacket
Send
RakPeerInterface Functions Explicitly Tested:
IsLocalIP
SendLoopback
GetConnectionState
GetLocalIP
GetInternalID
*/
int LocalIsConnectedTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
{
RakPeerInterface *server,*client;
destroyList.Clear(false,_FILE_AND_LINE_);
server=RakPeerInterface::GetInstance();
destroyList.Push(server,_FILE_AND_LINE_);
client=RakPeerInterface::GetInstance();
destroyList.Push(client,_FILE_AND_LINE_);
client->Startup(1,&SocketDescriptor(),1);
server->Startup(1,&SocketDescriptor(60000,0),1);
server->SetMaximumIncomingConnections(1);
SystemAddress serverAddress;
serverAddress.SetBinaryAddress("127.0.0.1");
serverAddress.port=60000;
TimeMS entryTime=GetTimeMS();
bool lastConnect=false;
if (isVerbose)
printf("Testing GetConnectionState\n");
while(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true)&&GetTimeMS()-entryTime<5000)
{
if(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,true,true,true))
{
lastConnect=client->Connect("127.0.0.1",serverAddress.port,0,0)==CONNECTION_ATTEMPT_STARTED;
}
RakSleep(100);
}
if (!lastConnect)//Use thise method to only check if the connect function fails, detecting connected client is done next
{
if (isVerbose)
DebugTools::ShowError("Client could not connect after 5 seconds\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;
}
if(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true))
{
if (isVerbose)
DebugTools::ShowError("IsConnected did not detect connected client",!noPauses && isVerbose,__LINE__,__FILE__);
return 2;
}
client->CloseConnection (serverAddress,true,0,LOW_PRIORITY);
if(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,false,false,true))
{
DebugTools::ShowError("IsConnected did not detect disconnecting client",!noPauses && isVerbose,__LINE__,__FILE__);
return 3;
}
RakSleep(1000);
client->Connect("127.0.0.1",serverAddress.port,0,0);
if(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,true,true))
{
DebugTools::ShowError("IsConnected did not detect connecting client",!noPauses && isVerbose,__LINE__,__FILE__);
return 4;
}
entryTime=GetTimeMS();
while(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true)&&GetTimeMS()-entryTime<5000)
{
if(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,true,true,true))
{
client->Connect("127.0.0.1",serverAddress.port,0,0);
}
RakSleep(100);
}
if (!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true))
{
if (isVerbose)
DebugTools::ShowError("Client could not connect after 5 seconds\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;
}
if (isVerbose)
printf("Testing IsLocalIP\n");
if (!client->IsLocalIP("127.0.0.1"))
{
if (isVerbose)
DebugTools::ShowError("IsLocalIP failed test\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 5;
}
if (isVerbose)
printf("Testing SendLoopback\n");
char str[]="AAAAAAAAAA";
str[0]=(char)(ID_USER_PACKET_ENUM+1);
client->SendLoopback(str, (int) strlen(str)+1);
client->SendLoopback(str, (int) strlen(str)+1);
client->SendLoopback(str, (int) strlen(str)+1);
client->SendLoopback(str, (int) strlen(str)+1);
client->SendLoopback(str, (int) strlen(str)+1);
client->SendLoopback(str, (int) strlen(str)+1);
client->SendLoopback(str, (int) strlen(str)+1);
bool recievedPacket=false;
Packet *packet;
TimeMS stopWaiting = GetTimeMS() + 1000;
while (GetTimeMS()<stopWaiting)
{
for (packet=client->Receive(); packet; client->DeallocatePacket(packet), packet=client->Receive())
{
if (packet->data[0]==ID_USER_PACKET_ENUM+1)
{
recievedPacket=true;
}
}
}
if (!recievedPacket)
{
if (isVerbose)
DebugTools::ShowError("SendLoopback failed test\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 6;
}
if (isVerbose)
printf("Testing GetLocalIP\n");
const char * localIp=client->GetLocalIP(0);
if (!client->IsLocalIP(localIp))
{
if (isVerbose)
DebugTools::ShowError("GetLocalIP failed test\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 7;
}
if (isVerbose)
printf("Testing GetInternalID\n");
SystemAddress localAddress=client->GetInternalID();
char convertedIp[39];
sprintf(convertedIp,"%d.%d.%d.%d", ((localAddress.binaryAddress >> (24 - 8 * 3)) & 0xFF),((localAddress.binaryAddress >> (24 - 16)) & 0xFF),((localAddress.binaryAddress >> (24 - 8 )) & 0xFF),((localAddress.binaryAddress >> (24)) & 0xFF));
printf("GetInternalID returned %s\n",convertedIp);
if (!client->IsLocalIP(convertedIp))
{
if (isVerbose)
DebugTools::ShowError("GetInternalID failed test\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 8;
}
return 0;
}
RakString LocalIsConnectedTest::GetTestName()
{
return "LocalIsConnectedTest";
}
RakString LocalIsConnectedTest::ErrorCodeToString(int errorCode)
{
switch (errorCode)
{
case 0:
return "No error";
break;
case 1:
return "Client could not connect after 5 seconds";
break;
case 2:
return "IsConnected did not detect connected client";
break;
case 3:
return "IsConnected did not detect disconnecting client";
break;
case 4:
return "IsConnected did not detect connecting client";
break;
case 5:
return "IsLocalIP failed test";
break;
case 6:
return "Sendloopback failed test";
break;
case 7:
return "GetLocalIP failed test";
break;
case 8:
return "GetInternalID failed test";
break;
default:
return "Undefined Error";
}
}
LocalIsConnectedTest::LocalIsConnectedTest(void)
{
}
LocalIsConnectedTest::~LocalIsConnectedTest(void)
{
}
void LocalIsConnectedTest::DestroyPeers()
{
int theSize=destroyList.Size();
for (int i=0; i < theSize; i++)
RakPeerInterface::DestroyInstance(destroyList[i]);
}

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "TestInterface.h"
#include "RakString.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include "RakPeer.h"
#include "RakSleep.h"
#include "RakNetTime.h"
#include "GetTime.h"
#include "DebugTools.h"
#include "CommonFunctions.h"
using namespace RakNet;
class LocalIsConnectedTest : public TestInterface
{
public:
LocalIsConnectedTest(void);
~LocalIsConnectedTest(void);
int RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses);//should return 0 if no error, or the error number
RakString GetTestName();
RakString ErrorCodeToString(int errorCode);
void DestroyPeers();
private:
DataStructures::List <RakPeerInterface *> destroyList;
};

View File

@ -0,0 +1,424 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "ManyClientsOneServerBlockingTest.h"
void ManyClientsOneServerBlockingTest::WaitForConnectionRequestsToComplete(RakPeerInterface **clientList, int clientNum, bool isVerbose)
{
SystemAddress currentSystem;
bool msgWasPrinted=false;
for (int i=0;i<clientNum;i++)
{
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000;
while (CommonFunctions::ConnectionStateMatchesOptions (clientList[i],currentSystem,false,true,true) )
{
if (msgWasPrinted==false)
{
printf("Waiting for connection requests to complete.\n");
msgWasPrinted=true;
}
RakSleep(30);
}
}
}
void ManyClientsOneServerBlockingTest::WaitAndPrintResults(RakPeerInterface **clientList, int clientNum, bool isVerbose,RakPeerInterface *server)
{
WaitForConnectionRequestsToComplete(clientList,clientNum,isVerbose);
Packet *packet;
if (isVerbose)
printf("For server\n");
for (packet=server->Receive(); packet;server->DeallocatePacket(packet), packet=server->Receive())
{
switch (packet->data[0])
{
case ID_REMOTE_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("Another client has disconnected.\n");
break;
case ID_REMOTE_CONNECTION_LOST:
if (isVerbose)
printf("Another client has lost the connection.\n");
break;
case ID_REMOTE_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("Another client has connected.\n");
break;
case ID_CONNECTION_REQUEST_ACCEPTED:
if (isVerbose)
printf("Our connection request has been accepted.\n");
break;
case ID_CONNECTION_ATTEMPT_FAILED:
if (isVerbose)
printf("A connection has failed.\n");
break;
case ID_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("A connection is incoming.\n");
break;
case ID_NO_FREE_INCOMING_CONNECTIONS:
if (isVerbose)
printf("The server is full.\n");
break;
case ID_ALREADY_CONNECTED:
if (isVerbose)
printf("Already connected\n");
break;
case ID_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("We have been disconnected.\n");
break;
case ID_CONNECTION_LOST:
if (isVerbose)
printf("Connection lost.\n");
break;
default:
break;
}
}
// Log all events per peer
for (int i=0;i<clientNum;i++)//Receive for all peers
{
if (isVerbose)
printf("For client %i\n",i);
for (packet=clientList[i]->Receive(); packet; clientList[i]->DeallocatePacket(packet), packet=clientList[i]->Receive())
{
switch (packet->data[0])
{
case ID_REMOTE_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("Another client has disconnected.\n");
break;
case ID_REMOTE_CONNECTION_LOST:
if (isVerbose)
printf("Another client has lost the connection.\n");
break;
case ID_REMOTE_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("Another client has connected.\n");
break;
case ID_CONNECTION_REQUEST_ACCEPTED:
if (isVerbose)
printf("Our connection request has been accepted.\n");
break;
case ID_CONNECTION_ATTEMPT_FAILED:
if (isVerbose)
printf("A connection has failed.\n");
break;
case ID_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("A connection is incoming.\n");
break;
case ID_NO_FREE_INCOMING_CONNECTIONS:
if (isVerbose)
printf("The server is full.\n");
break;
case ID_ALREADY_CONNECTED:
if (isVerbose)
printf("Already connected\n");
break;
case ID_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("We have been disconnected.\n");
break;
case ID_CONNECTION_LOST:
if (isVerbose)
printf("Connection lost.\n");
break;
default:
break;
}
}
}
}
/*
What is being done here is having 256 clients connect to a server, disconnect, connect again.
Do this for about 10 seconds. Then allow them all to connect for one last time.
This version waits for connect and such in a loop, blocking execution so it is a blocking test.
Good ideas for changes:
After the last check run a eightpeers like test an add the conditions
of that test as well.
Make sure that if we initiate the connection we get a proper message
and if not we get a proper message. Add proper conditions.
Randomize sending the disconnect notes
Success conditions:
All connected normally.
Failure conditions:
Doesn't reconnect normally.
During the very first connect loop any connect returns false.
Connect function returns false and peer is not connected to anything and does not have anything pending.
*/
int ManyClientsOneServerBlockingTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
{
const int clientNum= 256;
RakPeerInterface *clientList[clientNum];//A list of clients
RakPeerInterface *server;
SystemAddress currentSystem;
destroyList.Clear(false,_FILE_AND_LINE_);
//Initializations of the arrays
for (int i=0;i<clientNum;i++)
{
clientList[i]=RakPeerInterface::GetInstance();
destroyList.Push(clientList[i],_FILE_AND_LINE_);
clientList[i]->Startup(1,&SocketDescriptor(), 1);
}
server=RakPeerInterface::GetInstance();
destroyList.Push(server,_FILE_AND_LINE_);
server->Startup(clientNum, &SocketDescriptor(60000,0), 1);
server->SetMaximumIncomingConnections(clientNum);
//Connect all the clients to the server
for (int i=0;i<clientNum;i++)
{
if (clientList[i]->Connect("127.0.0.1", 60000, 0,0)!=CONNECTION_ATTEMPT_STARTED)
{
if (isVerbose)
DebugTools::ShowError("Problem while calling connect.\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;//This fails the test, don't bother going on.
}
}
TimeMS entryTime=GetTimeMS();//Loop entry time
DataStructures::List< SystemAddress > systemList;
DataStructures::List< RakNetGUID > guidList;
printf("Entering disconnect loop \n");
while(GetTimeMS()-entryTime<10000)//Run for 10 Secoonds
{
//Disconnect all clients IF connected to any from client side
for (int i=0;i<clientNum;i++)
{
clientList[i]->GetSystemList(systemList,guidList);//Get connectionlist
int len=systemList.Size();
for (int j=0;j<len;j++)//Disconnect them all
{
clientList[i]->CloseConnection (systemList[j],true,0,LOW_PRIORITY);
}
}
RakSleep(100);
//Connect
for (int i=0;i<clientNum;i++)
{
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000;
if(!CommonFunctions::ConnectionStateMatchesOptions (clientList[i],currentSystem,true,true,true,true) )//Are we connected or is there a pending operation ?
{
if (clientList[i]->Connect("127.0.0.1", 60000, 0,0)!=CONNECTION_ATTEMPT_STARTED)
{
if (isVerbose)
DebugTools::ShowError("Problem while calling connect. \n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;//This fails the test, don't bother going on.
}
}
}
WaitAndPrintResults(clientList,clientNum,isVerbose,server);
}
WaitAndPrintResults(clientList,clientNum,isVerbose,server);
printf("Connecting clients\n");
//Connect
for (int i=0;i<clientNum;i++)
{
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000;
if(!CommonFunctions::ConnectionStateMatchesOptions (clientList[i],currentSystem,true,true,true,true) )//Are we connected or is there a pending operation ?
{
printf("Calling Connect() for client %i.\n",i);
if (clientList[i]->Connect("127.0.0.1", 60000, 0,0)!=CONNECTION_ATTEMPT_STARTED)
{
clientList[i]->GetSystemList(systemList,guidList);//Get connectionlist
int len=systemList.Size();
if (isVerbose)
DebugTools::ShowError("Problem while calling connect. \n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;//This fails the test, don't bother going on.
}
}
else
{
if (CommonFunctions::ConnectionStateMatchesOptions (clientList[i],currentSystem,false,false,false,true)==false)
printf("Not calling Connect() for client %i because it is disconnecting.\n",i);
else if (CommonFunctions::ConnectionStateMatchesOptions (clientList[i],currentSystem,false,true,true)==false)
printf("Not calling Connect() for client %i because it is connecting.\n",i);
else if (CommonFunctions::ConnectionStateMatchesOptions (clientList[i],currentSystem,true)==false)
printf("Not calling Connect() for client %i because it is connected).\n",i);
}
}
WaitAndPrintResults(clientList,clientNum,isVerbose,server);
for (int i=0;i<clientNum;i++)
{
clientList[i]->GetSystemList(systemList,guidList);
int connNum=guidList.Size();//Get the number of connections for the current peer
if (connNum!=1)//Did we connect all?
{
if (isVerbose)
{
printf("Not all clients reconnected normally.\nFailed on client number %i\n",i);
DebugTools::ShowError("",!noPauses && isVerbose,__LINE__,__FILE__);
}
return 2;
}
}
if (isVerbose)
printf("Pass\n");
return 0;
}
RakString ManyClientsOneServerBlockingTest::GetTestName()
{
return "ManyClientsOneServerBlockingTest";
}
RakString ManyClientsOneServerBlockingTest::ErrorCodeToString(int errorCode)
{
switch (errorCode)
{
case 0:
return "No error";
break;
case 1:
return "The connect function failed.";
break;
case 2:
return "Peers did not connect normally.";
break;
default:
return "Undefined Error";
}
}
ManyClientsOneServerBlockingTest::ManyClientsOneServerBlockingTest(void)
{
}
ManyClientsOneServerBlockingTest::~ManyClientsOneServerBlockingTest(void)
{
}
void ManyClientsOneServerBlockingTest::DestroyPeers()
{
int theSize=destroyList.Size();
for (int i=0; i < theSize; i++)
RakPeerInterface::DestroyInstance(destroyList[i]);
}

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "TestInterface.h"
#include "RakString.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include "RakPeer.h"
#include "RakSleep.h"
#include "RakNetTime.h"
#include "GetTime.h"
#include "DebugTools.h"
#include "CommonFunctions.h"
using namespace RakNet;
class ManyClientsOneServerBlockingTest :
public TestInterface
{
public:
ManyClientsOneServerBlockingTest(void);
~ManyClientsOneServerBlockingTest(void);
int RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses);//should return 0 if no error, or the error number
RakString GetTestName();
RakString ErrorCodeToString(int errorCode);
void DestroyPeers();
protected:
void WaitForConnectionRequestsToComplete(RakPeerInterface **peerList, int peerNum, bool isVerbose);
void WaitAndPrintResults(RakPeerInterface **peerList, int peerNum, bool isVerbose,RakPeerInterface *server);
private:
DataStructures::List <RakPeerInterface *> destroyList;
};

View File

@ -0,0 +1,466 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "ManyClientsOneServerDeallocateBlockingTest.h"
void ManyClientsOneServerDeallocateBlockingTest::WaitForConnectionRequestsToComplete(RakPeerInterface **clientList, int clientNum, bool isVerbose)
{
SystemAddress currentSystem;
bool msgWasPrinted=false;
for (int i=0;i<clientNum;i++)
{
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000;
while (CommonFunctions::ConnectionStateMatchesOptions (clientList[i],currentSystem,false,true,true) )
{
if (msgWasPrinted==false)
{
printf("Waiting for connection requests to complete.\n");
msgWasPrinted=true;
}
RakSleep(30);
}
}
}
void ManyClientsOneServerDeallocateBlockingTest::WaitAndPrintResults(RakPeerInterface **clientList, int clientNum, bool isVerbose,RakPeerInterface *server)
{
WaitForConnectionRequestsToComplete(clientList,clientNum,isVerbose);
Packet *packet;
if (isVerbose)
printf("For server\n");
for (packet=server->Receive(); packet;server->DeallocatePacket(packet), packet=server->Receive())
{
switch (packet->data[0])
{
case ID_REMOTE_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("Another client has disconnected.\n");
break;
case ID_REMOTE_CONNECTION_LOST:
if (isVerbose)
printf("Another client has lost the connection.\n");
break;
case ID_REMOTE_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("Another client has connected.\n");
break;
case ID_CONNECTION_REQUEST_ACCEPTED:
if (isVerbose)
printf("Our connection request has been accepted.\n");
break;
case ID_CONNECTION_ATTEMPT_FAILED:
if (isVerbose)
printf("A connection has failed.\n");
break;
case ID_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("A connection is incoming.\n");
break;
case ID_NO_FREE_INCOMING_CONNECTIONS:
if (isVerbose)
printf("The server is full.\n");
break;
case ID_ALREADY_CONNECTED:
if (isVerbose)
printf("Already connected\n");
break;
case ID_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("We have been disconnected.\n");
break;
case ID_CONNECTION_LOST:
if (isVerbose)
printf("Connection lost.\n");
break;
default:
break;
}
}
//RakSleep(100);
// Log all events per peer
for (int i=0;i<clientNum;i++)//Receive for all peers
{
if (isVerbose)
printf("For client %i\n",i);
for (packet=clientList[i]->Receive(); packet; clientList[i]->DeallocatePacket(packet), packet=clientList[i]->Receive())
{
switch (packet->data[0])
{
case ID_REMOTE_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("Another client has disconnected.\n");
break;
case ID_REMOTE_CONNECTION_LOST:
if (isVerbose)
printf("Another client has lost the connection.\n");
break;
case ID_REMOTE_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("Another client has connected.\n");
break;
case ID_CONNECTION_REQUEST_ACCEPTED:
if (isVerbose)
printf("Our connection request has been accepted.\n");
break;
case ID_CONNECTION_ATTEMPT_FAILED:
if (isVerbose)
printf("A connection has failed.\n");
break;
case ID_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("A connection is incoming.\n");
break;
case ID_NO_FREE_INCOMING_CONNECTIONS:
if (isVerbose)
printf("The server is full.\n");
break;
case ID_ALREADY_CONNECTED:
if (isVerbose)
printf("Already connected\n");
break;
case ID_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("We have been disconnected.\n");
break;
case ID_CONNECTION_LOST:
if (isVerbose)
printf("Connection lost.\n");
break;
default:
break;
}
}
}
}
/*
The server timeout for this test is set to one second.
What is being done here is having 256 clients connect to a server.
Then the client is deallocated.
It is put to sleep for double the timeout amount.
After that the timeout should trigger and the clients register as disconnected.
Then the connection is started again.
Do this for about 30 seconds.
It is put to sleep for double the timeout amount.
Then allow them all to connect for one last time.
This version waits for connect and such in a loop, blocking execution so it is a blocking test.
Good ideas for changes:
After the last check run a eightpeers like test an add the conditions
of that test as well.
Success conditions:
All connected normally.
Failure conditions:
Doesn't reconnect normally.
During the very first connect loop any connect returns false.
Connect function returns false and peer is not connected to anything,pending a connection, or disconnecting.
GetTimeoutTime does not match the set timeout.
RakPeerInterface Functions used, tested indirectly by its use:
Startup
Connect
SetMaximumIncomingConnections
Receive
Send
DeallocatePacket
GetSystemList
SetMaximumIncomingConnections
RakPeerInterface Functions Explicitly Tested:
GetTimeoutTime
SetTimeoutTime
Connect
IsConnected
*/
int ManyClientsOneServerDeallocateBlockingTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
{
SystemAddress currentSystem;
//Initializations of the arrays
for (int i=0;i<clientNum;i++)
{
clientList[i]=RakPeerInterface::GetInstance();
clientList[i]->Startup(1,&SocketDescriptor(), 1);
}
server=RakPeerInterface::GetInstance();
server->Startup(clientNum, &SocketDescriptor(60000,0), 1);
server->SetMaximumIncomingConnections(clientNum);
const int timeoutTime=1000;
server->SetTimeoutTime(timeoutTime,UNASSIGNED_SYSTEM_ADDRESS);
int retTimeout=(int)server->GetTimeoutTime(UNASSIGNED_SYSTEM_ADDRESS);
if (retTimeout!=timeoutTime)
{
if (isVerbose)
DebugTools::ShowError("GetTimeoutTime did not match the timeout that was set. \n",!noPauses && isVerbose,__LINE__,__FILE__);
return 3;
}
//Connect all the clients to the server
for (int i=0;i<clientNum;i++)
{
if (clientList[i]->Connect("127.0.0.1", 60000, 0,0)!=CONNECTION_ATTEMPT_STARTED)
{
if (isVerbose)
DebugTools::ShowError("Problem while calling connect.\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;//This fails the test, don't bother going on.
}
}
TimeMS entryTime=GetTimeMS();//Loop entry time
DataStructures::List< SystemAddress > systemList;
DataStructures::List< RakNetGUID > guidList;
if (isVerbose)
printf("Entering disconnect loop \n");
while(GetTimeMS()-entryTime<30000)//Run for 30 Secoonds
{
//Deallocate client IF connected
for (int i=0;i<clientNum;i++)
{
clientList[i]->GetSystemList(systemList,guidList);//Get connectionlist
int len=systemList.Size();
if(len>=1)
{
RakPeerInterface::DestroyInstance(clientList[i]);
clientList[i]=RakPeerInterface::GetInstance();
clientList[i]->Startup(1,&SocketDescriptor(), 1);
}
}
RakSleep(2000);//Allow connections to timeout.
//Connect
for (int i=0;i<clientNum;i++)
{
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000;
if(!CommonFunctions::ConnectionStateMatchesOptions (clientList[i],currentSystem,true,true,true,true) )//Are we connected or is there a pending operation ?
{
if (clientList[i]->Connect("127.0.0.1", 60000, 0,0)!=CONNECTION_ATTEMPT_STARTED)
{
if (isVerbose)
DebugTools::ShowError("Problem while calling connect. \n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;//This fails the test, don't bother going on.
}
}
}
WaitAndPrintResults(clientList,clientNum,isVerbose,server);
}
WaitAndPrintResults(clientList,clientNum,isVerbose,server);
printf("Connecting clients\n");
RakSleep(2000);//Allow connections to timeout.
//Connect
for (int i=0;i<clientNum;i++)
{
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000;
if(!CommonFunctions::ConnectionStateMatchesOptions (clientList[i],currentSystem,true,true,true,true) )//Are we connected or is there a pending operation ?
{
printf("Calling Connect() for client %i.\n",i);
if (clientList[i]->Connect("127.0.0.1", 60000, 0,0)!=CONNECTION_ATTEMPT_STARTED)
{
clientList[i]->GetSystemList(systemList,guidList);//Get connectionlist
int len=systemList.Size();
if (isVerbose)
DebugTools::ShowError("Problem while calling connect. \n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;//This fails the test, don't bother going on.
}
}
else
{
if (CommonFunctions::ConnectionStateMatchesOptions (clientList[i],currentSystem,false,false,false,true)==false)
printf("Not calling Connect() for client %i because it is disconnecting.\n",i);
else if (CommonFunctions::ConnectionStateMatchesOptions (clientList[i],currentSystem,false,true,true)==false)
printf("Not calling Connect() for client %i because it is connecting.\n",i);
else if (CommonFunctions::ConnectionStateMatchesOptions (clientList[i],currentSystem,true)==false)
printf("Not calling Connect() for client %i because it is connected).\n",i);
}
}
WaitAndPrintResults(clientList,clientNum,isVerbose,server);
for (int i=0;i<clientNum;i++)
{
clientList[i]->GetSystemList(systemList,guidList);
int connNum=guidList.Size();//Get the number of connections for the current peer
if (connNum!=1)//Did we connect all?
{
if (isVerbose)
{
printf("Not all clients reconnected normally.\nFailed on client number %i\n",i);
DebugTools::ShowError("",!noPauses && isVerbose,__LINE__,__FILE__);
}
return 2;
}
}
if (isVerbose)
printf("Pass\n");
return 0;
}
RakString ManyClientsOneServerDeallocateBlockingTest::GetTestName()
{
return "ManyClientsOneServerDeallocateBlockingTest";
}
RakString ManyClientsOneServerDeallocateBlockingTest::ErrorCodeToString(int errorCode)
{
switch (errorCode)
{
case 0:
return "No error";
break;
case 1:
return "The connect function failed";
break;
case 2:
return "Peers did not connect normally";
break;
case 3:
return "GetTimeoutTime did not match the timeout that was set";
break;
default:
return "Undefined Error";
}
}
ManyClientsOneServerDeallocateBlockingTest::ManyClientsOneServerDeallocateBlockingTest(void)
{
}
ManyClientsOneServerDeallocateBlockingTest::~ManyClientsOneServerDeallocateBlockingTest(void)
{
}
void ManyClientsOneServerDeallocateBlockingTest::DestroyPeers()
{
for (int i=0; i < clientNum; i++)
RakPeerInterface::DestroyInstance(clientList[i]);
RakPeerInterface::DestroyInstance(server);
}

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "TestInterface.h"
#include "RakString.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include "RakPeer.h"
#include "RakSleep.h"
#include "RakNetTime.h"
#include "GetTime.h"
#include "DebugTools.h"
#include "CommonFunctions.h"
using namespace RakNet;
class ManyClientsOneServerDeallocateBlockingTest :
public TestInterface
{
public:
ManyClientsOneServerDeallocateBlockingTest(void);
~ManyClientsOneServerDeallocateBlockingTest(void);
int RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses);//should return 0 if no error, or the error number
RakString GetTestName();
RakString ErrorCodeToString(int errorCode);
void DestroyPeers();
protected:
void WaitForConnectionRequestsToComplete(RakPeerInterface **peerList, int peerNum, bool isVerbose);
void WaitAndPrintResults(RakPeerInterface **peerList, int peerNum, bool isVerbose,RakPeerInterface *server);
private:
static const int clientNum= 256;
RakPeerInterface *clientList[clientNum];//A list of clients
RakPeerInterface *server;
};

View File

@ -0,0 +1,19 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "ManyClientsOneServerDeallocateTest.h"
ManyClientsOneServerDeallocateTest::ManyClientsOneServerDeallocateTest(void)
{
}
ManyClientsOneServerDeallocateTest::~ManyClientsOneServerDeallocateTest(void)
{
}

View File

@ -0,0 +1,18 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
class ManyClientsOneServerDeallocateTest
{
public:
ManyClientsOneServerDeallocateTest(void);
~ManyClientsOneServerDeallocateTest(void);
};

View File

@ -0,0 +1,706 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "ManyClientsOneServerNonBlockingTest.h"
/*
What is being done here is having 256 clients connect to one server, disconnect, connect again.
Do this for about 10 seconds. Then allow them all to connect for one last time.
This one has a nonblocking recieve so doesn't wait for connects or anything.
Just rapid connecting disconnecting.
Good ideas for changes:
After the last check run a eightpeers like test an add the conditions
of that test as well.
Make sure that if we initiate the connection we get a proper message
and if not we get a proper message. Add proper conditions.
Randomize sending the disconnect notes
Success conditions:
All connected normally.
Failure conditions:
Doesn't reconnect normally.
During the very first connect loop any connect returns false.
Connect function returns false and peer is not connected to anything.
*/
int ManyClientsOneServerNonBlockingTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
{
const int clientNum= 256;
RakPeerInterface *clientList[clientNum];//A list of clients
RakPeerInterface *server;//The server
SystemAddress currentSystem;
//SystemAddress currentSystem;
Packet *packet;
destroyList.Clear(false,_FILE_AND_LINE_);
//Initializations of the arrays
for (int i=0;i<clientNum;i++)
{
clientList[i]=RakPeerInterface::GetInstance();
destroyList.Push(clientList[i],_FILE_AND_LINE_);
clientList[i]->Startup(1,&SocketDescriptor(), 1);
}
server=RakPeerInterface::GetInstance();
destroyList.Push(server,_FILE_AND_LINE_);
server->Startup(clientNum, &SocketDescriptor(60000,0), 1);
server->SetMaximumIncomingConnections(clientNum);
//Connect all the clients to the server
for (int i=0;i<clientNum;i++)
{
if (clientList[i]->Connect("127.0.0.1", 60000, 0,0)!=CONNECTION_ATTEMPT_STARTED)
{
if (isVerbose)
DebugTools::ShowError("Problem while calling connect.\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;//This fails the test, don't bother going on.
}
}
TimeMS entryTime=GetTimeMS();//Loop entry time
DataStructures::List< SystemAddress > systemList;
DataStructures::List< RakNetGUID > guidList;
if (isVerbose)
printf("Entering disconnect loop \n");
while(GetTimeMS()-entryTime<10000)//Run for 10 Secoonds
{
//Disconnect all clients IF connected to any from client side
for (int i=0;i<clientNum;i++)
{
clientList[i]->GetSystemList(systemList,guidList);//Get connectionlist
int len=systemList.Size();
for (int j=0;j<len;j++)//Disconnect them all
{
clientList[i]->CloseConnection (systemList[j],true,0,LOW_PRIORITY);
}
}
//RakSleep(100);
//Connect
for (int i=0;i<clientNum;i++)
{
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000;
if(!CommonFunctions::ConnectionStateMatchesOptions (clientList[i],currentSystem,true,true,true,true) )//Are we connected or is there a pending operation ?
{
if (clientList[i]->Connect("127.0.0.1", 60000, 0,0)!=CONNECTION_ATTEMPT_STARTED)
{
if (isVerbose)
DebugTools::ShowError("Problem while calling connect. \n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;//This fails the test, don't bother going on.
}
}
}
//Server receive
packet=server->Receive();
if (isVerbose&&packet)
printf("For server\n");
while(packet)
{
switch (packet->data[0])
{
case ID_REMOTE_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("Another client has disconnected.\n");
break;
case ID_REMOTE_CONNECTION_LOST:
if (isVerbose)
printf("Another client has lost the connection.\n");
break;
case ID_REMOTE_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("Another client has connected.\n");
break;
case ID_CONNECTION_REQUEST_ACCEPTED:
if (isVerbose)
printf("Our connection request has been accepted.\n");
break;
case ID_CONNECTION_ATTEMPT_FAILED:
if (isVerbose)
printf("A connection has failed.\n");
break;
case ID_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("A connection is incoming.\n");
break;
case ID_NO_FREE_INCOMING_CONNECTIONS:
if (isVerbose)
printf("The server is full.\n");
break;
case ID_ALREADY_CONNECTED:
if (isVerbose)
printf("Already connected\n");
break;
case ID_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("We have been disconnected.\n");
break;
case ID_CONNECTION_LOST:
if (isVerbose)
printf("Connection lost.\n");
break;
default:
break;
}
server->DeallocatePacket(packet);
// Stay in the loop as long as there are more packets.
packet = server->Receive();
}
for (int i=0;i<clientNum;i++)//Receive for all peers
{
packet=clientList[i]->Receive();
if (isVerbose&&packet)
printf("For peer %i\n",i);
while(packet)
{
switch (packet->data[0])
{
case ID_REMOTE_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("Another client has disconnected.\n");
break;
case ID_REMOTE_CONNECTION_LOST:
if (isVerbose)
printf("Another client has lost the connection.\n");
break;
case ID_REMOTE_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("Another client has connected.\n");
break;
case ID_CONNECTION_REQUEST_ACCEPTED:
if (isVerbose)
printf("Our connection request has been accepted.\n");
break;
case ID_CONNECTION_ATTEMPT_FAILED:
if (isVerbose)
printf("A connection has failed.\n");
break;
case ID_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("A connection is incoming.\n");
break;
case ID_NO_FREE_INCOMING_CONNECTIONS:
if (isVerbose)
printf("The server is full.\n");
break;
case ID_ALREADY_CONNECTED:
if (isVerbose)
printf("Already connected\n");
break;
case ID_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("We have been disconnected.\n");
break;
case ID_CONNECTION_LOST:
if (isVerbose)
printf("Connection lost.\n");
break;
default:
break;
}
clientList[i]->DeallocatePacket(packet);
// Stay in the loop as long as there are more packets.
packet = clientList[i]->Receive();
}
}
RakSleep(0);//If needed for testing
}
entryTime=GetTimeMS();
while(GetTimeMS()-entryTime<2000)//Run for 2 Secoonds to process incoming disconnects
{
//Server receive
packet=server->Receive();
if (isVerbose&&packet)
printf("For server\n");
while(packet)
{
switch (packet->data[0])
{
case ID_REMOTE_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("Another client has disconnected.\n");
break;
case ID_REMOTE_CONNECTION_LOST:
if (isVerbose)
printf("Another client has lost the connection.\n");
break;
case ID_REMOTE_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("Another client has connected.\n");
break;
case ID_CONNECTION_REQUEST_ACCEPTED:
if (isVerbose)
printf("Our connection request has been accepted.\n");
break;
case ID_CONNECTION_ATTEMPT_FAILED:
if (isVerbose)
printf("A connection has failed.\n");
break;
case ID_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("A connection is incoming.\n");
break;
case ID_NO_FREE_INCOMING_CONNECTIONS:
if (isVerbose)
printf("The server is full.\n");
break;
case ID_ALREADY_CONNECTED:
if (isVerbose)
printf("Already connected\n");
break;
case ID_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("We have been disconnected.\n");
break;
case ID_CONNECTION_LOST:
if (isVerbose)
printf("Connection lost.\n");
break;
default:
break;
}
server->DeallocatePacket(packet);
// Stay in the loop as long as there are more packets.
packet = server->Receive();
}
for (int i=0;i<clientNum;i++)//Receive for all peers
{
packet=clientList[i]->Receive();
if (isVerbose&&packet)
printf("For peer %i\n",i);
while(packet)
{
switch (packet->data[0])
{
case ID_REMOTE_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("Another client has disconnected.\n");
break;
case ID_REMOTE_CONNECTION_LOST:
if (isVerbose)
printf("Another client has lost the connection.\n");
break;
case ID_REMOTE_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("Another client has connected.\n");
break;
case ID_CONNECTION_REQUEST_ACCEPTED:
if (isVerbose)
printf("Our connection request has been accepted.\n");
break;
case ID_CONNECTION_ATTEMPT_FAILED:
if (isVerbose)
printf("A connection has failed.\n");
break;
case ID_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("A connection is incoming.\n");
break;
case ID_NO_FREE_INCOMING_CONNECTIONS:
if (isVerbose)
printf("The server is full.\n");
break;
case ID_ALREADY_CONNECTED:
if (isVerbose)
printf("Already connected\n");
break;
case ID_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("We have been disconnected.\n");
break;
case ID_CONNECTION_LOST:
if (isVerbose)
printf("Connection lost.\n");
break;
default:
break;
}
clientList[i]->DeallocatePacket(packet);
// Stay in the loop as long as there are more packets.
packet = clientList[i]->Receive();
}
}
RakSleep(0);//If needed for testing
}
//Connect
for (int i=0;i<clientNum;i++)
{
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000;
if(!CommonFunctions::ConnectionStateMatchesOptions (clientList[i],currentSystem,true,true,true,true) )//Are we connected or is there a pending operation ?
{
if (clientList[i]->Connect("127.0.0.1", 60000, 0,0)!=CONNECTION_ATTEMPT_STARTED)
{
clientList[i]->GetSystemList(systemList,guidList);//Get connectionlist
int len=systemList.Size();
if (isVerbose)
DebugTools::ShowError("Problem while calling connect. \n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;//This fails the test, don't bother going on.
}
}
}
entryTime=GetTimeMS();
while(GetTimeMS()-entryTime<5000)//Run for 5 Secoonds
{
//Server receive
packet=server->Receive();
if (isVerbose&&packet)
printf("For server\n");
while(packet)
{
switch (packet->data[0])
{
case ID_REMOTE_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("Another client has disconnected.\n");
break;
case ID_REMOTE_CONNECTION_LOST:
if (isVerbose)
printf("Another client has lost the connection.\n");
break;
case ID_REMOTE_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("Another client has connected.\n");
break;
case ID_CONNECTION_REQUEST_ACCEPTED:
if (isVerbose)
printf("Our connection request has been accepted.\n");
break;
case ID_CONNECTION_ATTEMPT_FAILED:
if (isVerbose)
printf("A connection has failed.\n");
break;
case ID_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("A connection is incoming.\n");
break;
case ID_NO_FREE_INCOMING_CONNECTIONS:
if (isVerbose)
printf("The server is full.\n");
break;
case ID_ALREADY_CONNECTED:
if (isVerbose)
printf("Already connected\n");
break;
case ID_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("We have been disconnected.\n");
break;
case ID_CONNECTION_LOST:
if (isVerbose)
printf("Connection lost.\n");
break;
default:
break;
}
server->DeallocatePacket(packet);
// Stay in the loop as long as there are more packets.
packet = server->Receive();
}
for (int i=0;i<clientNum;i++)//Receive for all clients
{
packet=clientList[i]->Receive();
if (isVerbose&&packet)
printf("For peer %i\n",i);
while(packet)
{
switch (packet->data[0])
{
case ID_REMOTE_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("Another client has disconnected.\n");
break;
case ID_REMOTE_CONNECTION_LOST:
if (isVerbose)
printf("Another client has lost the connection.\n");
break;
case ID_REMOTE_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("Another client has connected.\n");
break;
case ID_CONNECTION_REQUEST_ACCEPTED:
if (isVerbose)
printf("Our connection request has been accepted.\n");
break;
case ID_CONNECTION_ATTEMPT_FAILED:
if (isVerbose)
printf("A connection has failed.\n");
break;
case ID_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("A connection is incoming.\n");
break;
case ID_NO_FREE_INCOMING_CONNECTIONS:
if (isVerbose)
printf("The server is full.\n");
break;
case ID_ALREADY_CONNECTED:
if (isVerbose)
printf("Already connected\n");
break;
case ID_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("We have been disconnected.\n");
break;
case ID_CONNECTION_LOST:
if (isVerbose)
printf("Connection lost.\n");
break;
default:
break;
}
clientList[i]->DeallocatePacket(packet);
// Stay in the loop as long as there are more packets.
packet = clientList[i]->Receive();
}
}
RakSleep(0);//If needed for testing
}
for (int i=0;i<clientNum;i++)
{
clientList[i]->GetSystemList(systemList,guidList);
int connNum=guidList.Size();//Get the number of connections for the current peer
if (connNum!=1)//Did we connect to all?
{
if (isVerbose)
printf("Not all clients reconnected normally.\nFailed on clients number %i\n",i);
if (isVerbose)
DebugTools::ShowError("",!noPauses && isVerbose,__LINE__,__FILE__);
return 2;
}
}
if (isVerbose)
printf("Pass\n");
return 0;
}
RakString ManyClientsOneServerNonBlockingTest::GetTestName()
{
return "ManyClientsOneServerNonBlockingTest";
}
RakString ManyClientsOneServerNonBlockingTest::ErrorCodeToString(int errorCode)
{
switch (errorCode)
{
case 0:
return "No error";
break;
case 1:
return "The connect function failed.";
break;
case 2:
return "Peers did not connect normally.";
break;
default:
return "Undefined Error";
}
}
ManyClientsOneServerNonBlockingTest::ManyClientsOneServerNonBlockingTest(void)
{
}
ManyClientsOneServerNonBlockingTest::~ManyClientsOneServerNonBlockingTest(void)
{
}
void ManyClientsOneServerNonBlockingTest::DestroyPeers()
{
int theSize=destroyList.Size();
for (int i=0; i < theSize; i++)
RakPeerInterface::DestroyInstance(destroyList[i]);
}

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "TestInterface.h"
#include "RakString.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include "RakPeer.h"
#include "RakSleep.h"
#include "RakNetTime.h"
#include "GetTime.h"
#include "DebugTools.h"
#include "CommonFunctions.h"
using namespace RakNet;
class ManyClientsOneServerNonBlockingTest : public TestInterface
{
public:
ManyClientsOneServerNonBlockingTest(void);
~ManyClientsOneServerNonBlockingTest(void);
int RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses);//should return 0 if no error, or the error number
RakString GetTestName();
RakString ErrorCodeToString(int errorCode);
void DestroyPeers();
private:
DataStructures::List <RakPeerInterface *> destroyList;
};

View File

@ -0,0 +1,260 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "MaximumConnectTest.h"
/*
What is being done here is having 8 peers all connect to eachother over the max defined connection.
It runs the connect, wait 20 seconds then see the current connections.
Success conditions:
All extra connections Refused.
Failure conditions:
There are more connected than allowed.
The connect function fails, the test is not even done.
GetMaximumIncomingConnections returns wrong value.
RakPeerInterface Functions used, tested indirectly by its use:
Startup
Connect
SetMaximumIncomingConnections
Receive
DeallocatePacket
GetSystemList
RakPeerInterface Functions Explicitly Tested:
SetMaximumIncomingConnections
GetMaximumIncomingConnections
*/
int MaximumConnectTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
{
const int peerNum= 8;
const int maxConnections=4;//Max allowed connections for test
RakPeerInterface *peerList[peerNum];//A list of 8 peers
Packet *packet;
destroyList.Clear(false,_FILE_AND_LINE_);
int connReturn;
//Initializations of the arrays
for (int i=0;i<peerNum;i++)
{
peerList[i]=RakPeerInterface::GetInstance();
destroyList.Push(peerList[i],_FILE_AND_LINE_);
peerList[i]->Startup(maxConnections, &SocketDescriptor(60000+i,0), 1);
peerList[i]->SetMaximumIncomingConnections(maxConnections);
connReturn=peerList[i]->GetMaximumIncomingConnections();
if (connReturn!=maxConnections)
{
if (isVerbose)
{
printf("Getmaxconnections wrong for peer %i, %i should be the value but the value is %i.Fail\n",i,maxConnections,connReturn);
DebugTools::ShowError("",!noPauses && isVerbose,__LINE__,__FILE__);
}
}
}
//Connect all the peers together
for (int i=0;i<peerNum;i++)
{
for (int j=i+1;j<peerNum;j++)//Start at i+1 so don't connect two of the same together.
{
if (peerList[i]->Connect("127.0.0.1", 60000+j, 0,0)!=CONNECTION_ATTEMPT_STARTED)
{
if (isVerbose)
DebugTools::ShowError("Problem while calling connect.\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;//This fails the test, don't bother going on.
}
}
}
TimeMS entryTime=GetTimeMS();//Loop entry time
while(GetTimeMS()-entryTime<20000)//Run for 20 Secoonds
{
for (int i=0;i<peerNum;i++)//Receive for all peers
{
packet=peerList[i]->Receive();
if (isVerbose&&packet)
printf("For peer %i\n",i);
while(packet)
{
switch (packet->data[0])
{
case ID_REMOTE_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("Another client has disconnected.\n");
break;
case ID_REMOTE_CONNECTION_LOST:
if (isVerbose)
printf("Another client has lost the connection.\n");
break;
case ID_REMOTE_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("Another client has connected.\n");
break;
case ID_CONNECTION_REQUEST_ACCEPTED:
if (isVerbose)
printf("Our connection request has been accepted.\n");
break;
case ID_CONNECTION_ATTEMPT_FAILED:
if (isVerbose)
printf("A connection has failed.\n");//Should happen in this test
break;
case ID_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("A connection is incoming.\n");
break;
case ID_NO_FREE_INCOMING_CONNECTIONS:
if (isVerbose)
printf("The server is full.\n");
break;
case ID_ALREADY_CONNECTED:
if (isVerbose)
printf("Already connected\n");//Shouldn't happen
break;
case ID_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("We have been disconnected.\n");
break;
case ID_CONNECTION_LOST:
if (isVerbose)
printf("Connection lost.\n");
break;
default:
break;
}
peerList[i]->DeallocatePacket(packet);
// Stay in the loop as long as there are more packets.
packet = peerList[i]->Receive();
}
}
RakSleep(0);//If needed for testing
}
DataStructures::List< SystemAddress > systemList;
DataStructures::List< RakNetGUID > guidList;
for (int i=0;i<peerNum;i++)
{
peerList[i]->GetSystemList(systemList,guidList);
int connNum=guidList.Size();//Get the number of connections for the current peer
if (connNum>maxConnections)//Did we connect to more?
{
if (isVerbose)
{
printf("More connections were allowed to peer %i, %i total.Fail\n",i,connNum);
DebugTools::ShowError("",!noPauses && isVerbose,__LINE__,__FILE__);
}
return 2;
}
}
if (isVerbose)
printf("Pass\n");
return 0;
}
RakString MaximumConnectTest::GetTestName()
{
return "MaximumConnectTest";
}
RakString MaximumConnectTest::ErrorCodeToString(int errorCode)
{
switch (errorCode)
{
case 0:
return "No error";
break;
case 1:
return "The connect function failed";
break;
case 2:
return "An extra connection was allowed";
break;
case 3:
return "GetMaximumIncomingConnectionsn returned wrong value";
break;
default:
return "Undefined Error";
}
}
MaximumConnectTest::MaximumConnectTest(void)
{
}
MaximumConnectTest::~MaximumConnectTest(void)
{
}
void MaximumConnectTest::DestroyPeers()
{
int theSize=destroyList.Size();
for (int i=0; i < theSize; i++)
RakPeerInterface::DestroyInstance(destroyList[i]);
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "TestInterface.h"
#include "RakString.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include "RakPeer.h"
#include "RakSleep.h"
#include "RakNetTime.h"
#include "GetTime.h"
#include "DebugTools.h"
using namespace RakNet;
class MaximumConnectTest : public TestInterface
{
public:
MaximumConnectTest(void);
~MaximumConnectTest(void);
int RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses);//should return 0 if no error, or the error number
RakString GetTestName();
RakString ErrorCodeToString(int errorCode);
void DestroyPeers();
private:
DataStructures::List <RakPeerInterface *> destroyList;
};

View File

@ -0,0 +1,105 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "MiscellaneousTestsTest.h"
/*
Description:
Tests:
virtual void SetRouterInterface (RouterInterface *routerInterface)=0
virtual void RemoveRouterInterface (RouterInterface *routerInterface)=0
virtual bool AdvertiseSystem (const char *host, unsigned short remotePort, const char *data, int dataLength, unsigned connectionSocketIndex=0)=0
Success conditions:
Failure conditions:
RakPeerInterface Functions used, tested indirectly by its use,list may not be complete:
Startup
SetMaximumIncomingConnections
Receive
DeallocatePacket
Send
RakPeerInterface Functions Explicitly Tested:
SetRouterInterface
RemoveRouterInterface
AdvertiseSystem
*/
int MiscellaneousTestsTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
{ destroyList.Clear(false,_FILE_AND_LINE_);
RakPeerInterface *client,*server;
TestHelpers::StandardClientPrep(client,destroyList);
TestHelpers::StandardServerPrep(server,destroyList);
printf("Testing AdvertiseSystem\n");
client->AdvertiseSystem("127.0.0.1",60000,0,0);
if (!CommonFunctions::WaitForMessageWithID(server,ID_ADVERTISE_SYSTEM,5000))
{
if (isVerbose)
DebugTools::ShowError(errorList[1-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 1;
}
return 0;
}
RakString MiscellaneousTestsTest::GetTestName()
{
return "MiscellaneousTestsTest";
}
RakString MiscellaneousTestsTest::ErrorCodeToString(int errorCode)
{
if (errorCode>0&&(unsigned int)errorCode<=errorList.Size())
{
return errorList[errorCode-1];
}
else
{
return "Undefined Error";
}
}
void MiscellaneousTestsTest::DestroyPeers()
{
int theSize=destroyList.Size();
for (int i=0; i < theSize; i++)
RakPeerInterface::DestroyInstance(destroyList[i]);
}
MiscellaneousTestsTest::MiscellaneousTestsTest(void)
{
errorList.Push("Did not recieve client advertise",_FILE_AND_LINE_);
errorList.Push("The router interface should not be called because no send has happened yet",_FILE_AND_LINE_);
errorList.Push("Router failed to trigger on failed directed send",_FILE_AND_LINE_);
errorList.Push("Router was not properly removed",_FILE_AND_LINE_);
}
MiscellaneousTestsTest::~MiscellaneousTestsTest(void)
{
}

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "TestInterface.h"
#include "RakString.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include "RakPeer.h"
#include "RakSleep.h"
#include "RakNetTime.h"
#include "GetTime.h"
#include "DebugTools.h"
#include "CommonFunctions.h"
#include "TestHelpers.h"
using namespace RakNet;
class MiscellaneousTestsTest : public TestInterface
{
public:
MiscellaneousTestsTest(void);
~MiscellaneousTestsTest(void);
int RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses);//should return 0 if no error, or the error number
RakString GetTestName();
RakString ErrorCodeToString(int errorCode);
void DestroyPeers();
private:
DataStructures::List <RakString> errorList;
DataStructures::List <RakNet::RakPeerInterface *> destroyList;
};

View File

@ -0,0 +1,253 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "OfflineMessagesConvertTest.h"
/*
Description:
Description: Tests / Demonstrates sending messages to systems you are not connected to.
Success conditions:
Proper offline response.
Proper offline ping response.
Failure conditions:
Any success conditions failed
RakPeerInterface Functions used, tested indirectly by its use:
GetGuidFromSystemAddress
Startup
SetMaximumIncomingConnections
Receive
DeallocatePacket
RakPeerInterface Functions Explicitly Tested:
SetOfflinePingResponse
GetOfflinePingResponse
AdvertiseSystem
Ping
*/
int OfflineMessagesConvertTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
{
bool recievedProperOfflineData=false;
bool recievedProperPingData=false;
int nextTest;
destroyList.Clear(false,_FILE_AND_LINE_);
RakPeerInterface *peer1=RakPeerInterface::GetInstance();
destroyList.Push( peer1,_FILE_AND_LINE_);
RakPeerInterface *peer2=RakPeerInterface::GetInstance();
destroyList.Push(peer2,_FILE_AND_LINE_);
bool sentPacket=false;
nextTest=0;
peer1->SetMaximumIncomingConnections(1);
SocketDescriptor socketDescriptor(60001, 0);
peer1->Startup(1, &socketDescriptor, 1);
socketDescriptor.port=60002;
peer2->Startup(1, &socketDescriptor, 1);
char * pingResponseData=0;
unsigned int responseLen=0;
peer1->SetOfflinePingResponse("Offline Ping Data", (int)strlen("Offline Ping Data")+1);
peer1->GetOfflinePingResponse(&pingResponseData,&responseLen);
if(strcmp(pingResponseData,"Offline Ping Data")!=0)
{
if (isVerbose)
DebugTools::ShowError("GetOfflinePingResponse failed.\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 5;
}
if (isVerbose)
printf("Peer 1 guid = %s\n", peer1->GetGuidFromSystemAddress(UNASSIGNED_SYSTEM_ADDRESS).ToString());
if (isVerbose)
printf("Peer 2 guid = %s\n", peer2->GetGuidFromSystemAddress(UNASSIGNED_SYSTEM_ADDRESS).ToString());
if (isVerbose)
printf("Systems started. Waiting for advertise system packet\n");
// Wait for connection to complete
RakSleep(300);
if (isVerbose)
printf("Sending advertise system from %s\n", peer1->GetGuidFromSystemAddress(UNASSIGNED_SYSTEM_ADDRESS).ToString());
peer1->AdvertiseSystem("127.0.0.1", 60002,"hello world", (int)strlen("hello world")+1);
TimeMS entryTime=GetTimeMS();//Loop entry time
while (nextTest!=2&&GetTimeMS()-entryTime<10000)// run for 10 seconds
{
peer1->DeallocatePacket(peer1->Receive());
Packet *packet = peer2->Receive();
if (packet)
{
if (packet->data[0]==ID_ADVERTISE_SYSTEM)
{
if (packet->length>1)
{
if (isVerbose)
printf("Got Advertise system with data: %s\n", packet->data+1);
if(strcmp((const char*)(packet->data+1),"hello world")==0)
{
recievedProperOfflineData=true;
}
else
{
if (isVerbose)
DebugTools::ShowError("Got Advertise system with unexpected data\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;
}
}
else
{
if (isVerbose)
DebugTools::ShowError("Got Advertise system with unexpected data\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;
}
if (isVerbose)
printf("Was sent from GUID %s\n", packet->guid.ToString());
if (isVerbose)
printf("Sending ping from %s\n", peer2->GetGuidFromSystemAddress(UNASSIGNED_SYSTEM_ADDRESS).ToString());
peer2->Ping("127.0.0.1", 60001, false);
nextTest++;
}
else if (packet->data[0]==ID_UNCONNECTED_PONG)
{
// Peer or client. Response from a ping for an unconnected system.
TimeMS packetTime, dataLength;
TimeMS curTime = GetTimeMS();
memcpy( ( char* ) & packetTime, packet->data + sizeof( unsigned char ), sizeof( TimeMS ) );
dataLength = packet->length - sizeof( unsigned char ) - sizeof( TimeMS );
if (peer2->IsLocalIP(packet->systemAddress.ToString(false)))
{
if (isVerbose)
printf("ID_UNCONNECTED_PONG from our own");
}
else
{
if (isVerbose)
printf( "ID_UNCONNECTED_PONG from");
}
if (isVerbose)
{
printf(" %s on %p.\nPing is %i\nData is %i bytes long.\n", packet->systemAddress.ToString(), peer2, curTime-packetTime, dataLength );
printf("Was sent from GUID %s\n", packet->guid.ToString());
}
const char * recString=(const char *)(packet->data + sizeof( unsigned char ) + sizeof( TimeMS ));
if ( dataLength > 0 )
{
printf( "Data is %s\n",recString );
if (strcmp(recString, "Offline Ping Data")!=0)
{
if (isVerbose)
DebugTools::ShowError("Received wrong offline ping response\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 2;
}
recievedProperPingData=true;
}
nextTest++;
// ProcessUnhandledPacket(packet, ID_UNCONNECTED_PONG,interfaceType);
}
peer2->DeallocatePacket(packet);
}
RakSleep(30);
}
if (!recievedProperOfflineData)
{
if (isVerbose)
DebugTools::ShowError("Never got proper offline data\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 3;
}
if (!recievedProperPingData)
{
if (isVerbose)
DebugTools::ShowError("Never got proper ping data\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 4;
}
return 0;
}
RakString OfflineMessagesConvertTest::GetTestName()
{
return "OfflineMessagesConvertTest";
}
RakString OfflineMessagesConvertTest::ErrorCodeToString(int errorCode)
{
switch (errorCode)
{
case 0:
return "No error";
break;
case 1:
return "Unexpected advertise data";
break;
case 2:
return "Wrong ping response";
break;
case 3:
return "Never got proper offline data";
break;
case 4:
return "Never got proper ping data";
break;
case 5:
return "GetOfflinePingResponse failed.";
break;
default:
return "Undefined Error";
}
}
OfflineMessagesConvertTest::OfflineMessagesConvertTest(void)
{
}
OfflineMessagesConvertTest::~OfflineMessagesConvertTest(void)
{
}
void OfflineMessagesConvertTest::DestroyPeers()
{
int theSize=destroyList.Size();
for (int i=0; i < theSize; i++)
RakPeerInterface::DestroyInstance(destroyList[i]);
}

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "TestInterface.h"
#include "RakString.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include "RakPeer.h"
#include "RakSleep.h"
#include "RakNetTime.h"
#include "GetTime.h"
#include "DebugTools.h"
using namespace RakNet;
class OfflineMessagesConvertTest : public TestInterface
{
public:
OfflineMessagesConvertTest(void);
~OfflineMessagesConvertTest(void);
int RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses);//should return 0 if no error, or the error number
RakString GetTestName();
RakString ErrorCodeToString(int errorCode);
void DestroyPeers();
private:
DataStructures::List <RakPeerInterface *> destroyList;
};

View File

@ -0,0 +1,342 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "PacketAndLowLevelTestsTest.h"
/*
Description:
Tests out the sunctions:
virtual int RakPeerInterface::GetSplitMessageProgressInterval ( void ) const "
virtual void RakPeerInterface::PushBackPacket ( Packet * packet, bool pushAtHead ) "
virtual bool RakPeerInterface::SendList ( char ** data, const int * lengths, const int numParameters, PacketPriority priority, PacketReliability reliability, char orderingChannel, SystemAddress systemAddress, bool broadcast ) "
virtual void RakPeerInterface::SetSplitMessageProgressInterval ( int interval )
virtual void RakPeerInterface::SetUnreliableTimeout ( TimeMS timeoutMS )
virtual Packet* RakPeerInterface::AllocatePacket ( unsigned dataSize )
AttachPlugin (PluginInterface2 *plugin)=0
DetachPlugin (PluginInterface2 *plugin)=0
Success conditions:
Failure conditions:
RakPeerInterface Functions used, tested indirectly by its use,list may not be complete:
Startup
SetMaximumIncomingConnections
Receive
DeallocatePacket
Send
IsConnected
RakPeerInterface Functions Explicitly Tested:
GetSplitMessageProgressInterval
PushBackPacket
SendList
SetSplitMessageProgressInterval
AllocatePacket
GetMTUSize
AttachPlugin
DetachPlugin
*/
int PacketAndLowLevelTestsTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
{
RakPeerInterface *server,*client;
destroyList.Clear(false,_FILE_AND_LINE_);
TestHelpers::StandardClientPrep(client,destroyList);
TestHelpers::StandardServerPrep(server,destroyList);
printf("Connecting to server\n");
if (!TestHelpers::WaitAndConnectTwoPeersLocally(client,server,5000))
{
if (isVerbose)
DebugTools::ShowError(errorList[1-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 1;
}
printf("Testing SendList\n");
char* dataList2[5];
char **dataList=(char **)dataList2;
int lengths[5];
char curString1[]="AAAA";
char curString2[]="ABBB";
char curString3[]="ACCC";
char curString4[]="ADDD";
char curString5[]="AEEE";
dataList[0]=curString1;
dataList[1]=curString2;
dataList[2]=curString3;
dataList[3]=curString4;
dataList[4]=curString5;
for (int i=0;i<5;i++)
{
dataList[i][0]=ID_USER_PACKET_ENUM+1+i;
lengths[i]=5;
}
client->SendList((const char**)dataList,lengths,5,HIGH_PRIORITY,RELIABLE_ORDERED,0, UNASSIGNED_SYSTEM_ADDRESS, true);
Packet* packet;
if (!(packet=CommonFunctions::WaitAndReturnMessageWithID(server,ID_USER_PACKET_ENUM+1,1000)))
{
if (isVerbose)
DebugTools::ShowError(errorList[9-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 9;
}
if (packet->length!=25)
{
if (isVerbose)
DebugTools::ShowError(errorList[13],!noPauses && isVerbose,__LINE__,__FILE__);
return 14;
}
server->DeallocatePacket(packet);
PluginInterface2* myPlug=new PacketChangerPlugin();
printf("Test attach detach of plugins\n");
client->AttachPlugin(myPlug);
TestHelpers::BroadCastTestPacket(client);
if (TestHelpers::WaitForTestPacket(server,2000))
{
if (isVerbose)
DebugTools::ShowError(errorList[2-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 2;
}
client->DetachPlugin(myPlug);
TestHelpers::BroadCastTestPacket(client);
if (!TestHelpers::WaitForTestPacket(server,2000))
{
if (isVerbose)
DebugTools::ShowError(errorList[3-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 3;
}
printf("Test AllocatePacket\n");
Packet * hugePacket,*hugePacket2;
const int dataSize=3000000;//around 30 meg didn't want to calculate the exact
hugePacket=client->AllocatePacket(dataSize);
hugePacket2=client->AllocatePacket(dataSize);
/*//Couldn't find a good cross platform way for allocated memory so skipped this check
if (somemalloccheck<3000000)
{}
*/
printf("Assuming 3000000 allocation for splitpacket, testing setsplitpacket\n");
hugePacket->data[0]=ID_USER_PACKET_ENUM+1;
hugePacket2->data[0]=ID_USER_PACKET_ENUM+1;
server->SetSplitMessageProgressInterval(1);
if (server->GetSplitMessageProgressInterval()!=1)
{
if (isVerbose)
DebugTools::ShowError(errorList[4-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 4;
}
if (!client->Send((const char *)hugePacket->data,dataSize,HIGH_PRIORITY,RELIABLE_ORDERED,0, UNASSIGNED_SYSTEM_ADDRESS, true))
{
if (isVerbose)
DebugTools::ShowError(errorList[5-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 5;
}
if (!CommonFunctions::WaitForMessageWithID(server,ID_DOWNLOAD_PROGRESS,2000))
{
if (isVerbose)
DebugTools::ShowError(errorList[6-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 6;
}
while(CommonFunctions::WaitForMessageWithID(server,ID_DOWNLOAD_PROGRESS,500))//Clear out the rest before next test
{
}
printf("Making sure still connected, if not connect\n");
if (!TestHelpers::WaitAndConnectTwoPeersLocally(client,server,5000))//Make sure connected before test
{
if (isVerbose)
DebugTools::ShowError(errorList[11-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 11;
}
printf("Making sure standard send/recieve still functioning\n");
TestHelpers::BroadCastTestPacket(client);
if (!TestHelpers::WaitForTestPacket(server,5000))
{
if (isVerbose)
DebugTools::ShowError(errorList[12],!noPauses && isVerbose,__LINE__,__FILE__);
return 13;
}
printf("Testing PushBackPacket\n");
server->PushBackPacket(hugePacket,false);
if (!TestHelpers::WaitForTestPacket(server,2000))
{
if (isVerbose)
DebugTools::ShowError(errorList[7-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 7;
}
printf("Making sure still connected, if not connect\n");
if (!TestHelpers::WaitAndConnectTwoPeersLocally(client,server,5000))//Make sure connected before test
{
if (isVerbose)
DebugTools::ShowError(errorList[11-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 11;
}
printf("Making sure standard send/recieve still functioning\n");
TestHelpers::BroadCastTestPacket(client);
if (!TestHelpers::WaitForTestPacket(server,2000))
{
if (isVerbose)
DebugTools::ShowError(errorList[12-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 12;
}
printf("PushBackPacket head true test\n");
server->PushBackPacket(hugePacket2,true);
if (!TestHelpers::WaitForTestPacket(server,2000))
{
if (isVerbose)
DebugTools::ShowError(errorList[10-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 10;
}
printf("Making sure still connected, if not connect\n");
if (!TestHelpers::WaitAndConnectTwoPeersLocally(client,server,5000))//Make sure connected before test
{
if (isVerbose)
DebugTools::ShowError(errorList[11-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 11;
}
printf("Run recieve test\n");
TestHelpers::BroadCastTestPacket(client);
if (!TestHelpers::WaitForTestPacket(server,2000))
{
if (isVerbose)
DebugTools::ShowError(errorList[12-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 12;
}
return 0;
}
void PacketAndLowLevelTestsTest::FloodWithHighPriority(RakPeerInterface* client)
{
for (int i=0;i<60000;i++)
{
TestHelpers::BroadCastTestPacket(client,UNRELIABLE,HIGH_PRIORITY,ID_USER_PACKET_ENUM+2);
}
}
RakString PacketAndLowLevelTestsTest::GetTestName()
{
return "PacketAndLowLevelTestsTest";
}
RakString PacketAndLowLevelTestsTest::ErrorCodeToString(int errorCode)
{
if (errorCode>0&&(unsigned int)errorCode<=errorList.Size())
{
return errorList[errorCode-1];
}
else
{
return "Undefined Error";
}
}
void PacketAndLowLevelTestsTest::DestroyPeers()
{
int theSize=destroyList.Size();
for (int i=0; i < theSize; i++)
RakPeerInterface::DestroyInstance(destroyList[i]);
}
PacketAndLowLevelTestsTest::PacketAndLowLevelTestsTest(void)
{
errorList.Push("Client failed to connect to server",_FILE_AND_LINE_);
errorList.Push("Attached plugin failed to modify packet",_FILE_AND_LINE_);
errorList.Push("Plugin is still modifying packets after detach",_FILE_AND_LINE_);
errorList.Push("GetSplitMessageProgressInterval returned wrong value",_FILE_AND_LINE_);
errorList.Push("Send to server failed",_FILE_AND_LINE_);
errorList.Push("Large packet did not split or did not properly get ID_DOWNLOAD_PROGRESS after SetSplitMessageProgressInterval is set to 1 millisecond",_FILE_AND_LINE_);
errorList.Push("Did not recieve and put on packet made with AllocatePacket and put on recieve stack with PushBackPacket",_FILE_AND_LINE_);
errorList.Push("Client failed to connect to server",_FILE_AND_LINE_);
errorList.Push("Did not recieve all packets from SendList",_FILE_AND_LINE_);
errorList.Push("Did not recieve and put on packet made with AllocatePacket and put on recieve stack with PushBackPacket",_FILE_AND_LINE_);
errorList.Push("Client failed to connect to server",_FILE_AND_LINE_);
errorList.Push("PushBackPacket messed up future communication",_FILE_AND_LINE_);
errorList.Push("Send/Recieve failed",_FILE_AND_LINE_);
errorList.Push("Recieved size incorrect",_FILE_AND_LINE_);
}
PacketAndLowLevelTestsTest::~PacketAndLowLevelTestsTest(void)
{
}

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "TestInterface.h"
#include "RakString.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include "RakSleep.h"
#include "RakNetTime.h"
#include "GetTime.h"
#include "DebugTools.h"
#include "CommonFunctions.h"
#include "TestHelpers.h"
#include "PacketChangerPlugin.h"
using namespace RakNet;
class PacketAndLowLevelTestsTest : public TestInterface
{
public:
PacketAndLowLevelTestsTest(void);
~PacketAndLowLevelTestsTest(void);
int RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses);//should return 0 if no error, or the error number
RakString GetTestName();
RakString ErrorCodeToString(int errorCode);
void DestroyPeers();
protected:
void FloodWithHighPriority(RakPeerInterface* client);
private:
DataStructures::List <RakString> errorList;
DataStructures::List <RakPeerInterface *> destroyList;
};

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "PacketChangerPlugin.h"
PacketChangerPlugin::PacketChangerPlugin(void)
{
}
PacketChangerPlugin::~PacketChangerPlugin(void)
{
}
void PacketChangerPlugin::OnInternalPacket(InternalPacket *internalPacket, unsigned frameNumber, SystemAddress remoteSystemAddress, TimeMS time, int isSend)
{
internalPacket->data[0]=ID_USER_PACKET_ENUM+2;
//(void) frameNumber; (void) remoteSystemAddress; (void) time; (void) isSend;
}

View File

@ -0,0 +1,96 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "RakNetTypes.h"
#include "PluginInterface2.h"
#include "PacketPriority.h"
#include "MessageIdentifiers.h"
#include "InternalPacket.h"
using namespace RakNet;
class PacketChangerPlugin: public PluginInterface2
{
public:
PacketChangerPlugin(void);
~PacketChangerPlugin(void);
/// \param[in] peer the instance of RakPeer that is calling Receive
void OnAttach(void) {}
/// Called when the interface is detached
/// \param[in] peer the instance of RakPeer that is calling Receive
void OnDetach(void) {}
/// Update is called every time a packet is checked for .
void Update(void) {}
/// OnReceive is called for every packet.
/// \param[in] packet the packet that is being returned to the user
/// \return True to allow the game and other plugins to get this message, false to absorb it
PluginReceiveResult OnReceive(Packet *packet) {(void) packet; return RR_CONTINUE_PROCESSING;}
/// Called when RakPeer is initialized
void OnStartup(void) {}
/// Called when RakPeer is shutdown
void OnShutdown(void) {}
/// Called when a connection is dropped because the user called RakPeer::CloseConnection() for a particular system
/// \param[in] systemAddress The system whose connection was closed
/// \param[in] rakNetGuid The guid of the specified system
/// \param[in] lostConnectionReason How the connection was closed: manually, connection lost, or notification of disconnection
void OnClosedConnection(SystemAddress systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason ){(void) systemAddress; (void) rakNetGUID; (void) lostConnectionReason;}
/// Called when we got a new connection
/// \param[in] systemAddress Address of the new connection
/// \param[in] rakNetGuid The guid of the specified system
/// \param[in] isIncoming If true, this is ID_NEW_INCOMING_CONNECTION, or the equivalent
void OnNewConnection(SystemAddress systemAddress, RakNetGUID rakNetGUID, bool isIncoming) {(void) systemAddress; (void) rakNetGUID; (void) isIncoming;}
/// Called when a connection attempt fails
/// \param[in] systemAddress Address of the connection
/// \param[in] failedConnectionReason Why the connection failed
void OnFailedConnectionAttempt(Packet *packet, PI2_FailedConnectionAttemptReason failedConnectionAttemptReason) {(void) failedConnectionAttemptReason;}
/// Called on a send to the socket, per datagram, that does not go through the reliability layer
/// \param[in] data The data being sent
/// \param[in] bitsUsed How many bits long \a data is
/// \param[in] remoteSystemAddress Which system this message is being sent to
void OnDirectSocketSend(const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress) {(void) data; (void) bitsUsed; (void) remoteSystemAddress;}
/// Called on a receive from the socket, per datagram, that does not go through the reliability layer
/// \param[in] data The data being sent
/// \param[in] bitsUsed How many bits long \a data is
/// \param[in] remoteSystemAddress Which system this message is being sent to
void OnDirectSocketReceive(const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress) {(void) data; (void) bitsUsed; (void) remoteSystemAddress;}
/// Called on a send or receive of a message within the reliability layer
/// \param[in] internalPacket The user message, along with all send data.
/// \param[in] frameNumber The number of frames sent or received so far for this player depending on \a isSend . Indicates the frame of this user message.
/// \param[in] remoteSystemAddress The player we sent or got this packet from
/// \param[in] time The current time as returned by GetTimeMS()
/// \param[in] isSend Is this callback representing a send event or receive event?
void OnInternalPacket(InternalPacket *internalPacket, unsigned frameNumber, SystemAddress remoteSystemAddress, TimeMS time, int isSend);// {(void) internalPacket; (void) frameNumber; (void) remoteSystemAddress; (void) time; (void) isSend;}
/// Called when we get an ack for a message we reliabily sent
/// \param[in] messageNumber The numerical identifier for which message this is
/// \param[in] remoteSystemAddress The player we sent or got this packet from
/// \param[in] time The current time as returned by GetTimeMS()
void OnAck(unsigned int messageNumber, SystemAddress remoteSystemAddress, TimeMS time) {(void) messageNumber; (void) remoteSystemAddress; (void) time;}
/// System called RakPeerInterface::PushBackPacket
/// \param[in] data The data being sent
/// \param[in] bitsUsed How many bits long \a data is
/// \param[in] remoteSystemAddress The player we sent or got this packet from
void OnPushBackPacket(const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress) {(void) data; (void) bitsUsed; (void) remoteSystemAddress;}
};

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "PacketDropPlugin.h"
PacketDropPlugin::PacketDropPlugin(void)
{
timer.SetTimerLength(500);
}
PacketDropPlugin::~PacketDropPlugin(void)
{
}
PluginReceiveResult PacketDropPlugin::OnReceive(Packet *packet)
{
if (timer.IsExpired())
{
return RR_CONTINUE_PROCESSING;
}
else
{
return RR_STOP_PROCESSING;
}
}
void PacketDropPlugin::StartTest()
{
timer.Start();
}

View File

@ -0,0 +1,102 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "RakNetTypes.h"
#include "PluginInterface2.h"
#include "PacketPriority.h"
#include "MessageIdentifiers.h"
#include "InternalPacket.h"
#include "RakTimer.h"
using namespace RakNet;
class PacketDropPlugin : public PluginInterface2
{
public:
PacketDropPlugin(void);
~PacketDropPlugin(void);
void StartTest();
/// \param[in] peer the instance of RakPeer that is calling Receive
void OnAttach(void) {}
/// Called when the interface is detached
/// \param[in] peer the instance of RakPeer that is calling Receive
void OnDetach(void) {}
/// Update is called every time a packet is checked for .
void Update(void) {}
/// OnReceive is called for every packet.
/// \param[in] packet the packet that is being returned to the user
/// \return True to allow the game and other plugins to get this message, false to absorb it
PluginReceiveResult OnReceive(Packet *packet);// {(void) packet; return RR_CONTINUE_PROCESSING;}
/// Called when RakPeer is initialized
void OnStartup(void) {}
/// Called when RakPeer is shutdown
void OnShutdown(void) {}
/// Called when a connection is dropped because the user called RakPeer::CloseConnection() for a particular system
/// \param[in] systemAddress The system whose connection was closed
/// \param[in] rakNetGuid The guid of the specified system
/// \param[in] lostConnectionReason How the connection was closed: manually, connection lost, or notification of disconnection
void OnClosedConnection(SystemAddress systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason ){(void) systemAddress; (void) rakNetGUID; (void) lostConnectionReason;}
/// Called when we got a new connection
/// \param[in] systemAddress Address of the new connection
/// \param[in] rakNetGuid The guid of the specified system
/// \param[in] isIncoming If true, this is ID_NEW_INCOMING_CONNECTION, or the equivalent
void OnNewConnection(SystemAddress systemAddress, RakNetGUID rakNetGUID, bool isIncoming) {(void) systemAddress; (void) rakNetGUID; (void) isIncoming;}
/// Called when a connection attempt fails
/// \param[in] systemAddress Address of the connection
/// \param[in] failedConnectionReason Why the connection failed
void OnFailedConnectionAttempt(Packet *packet, PI2_FailedConnectionAttemptReason failedConnectionAttemptReason) {(void) failedConnectionAttemptReason;}
/// Called on a send to the socket, per datagram, that does not go through the reliability layer
/// \param[in] data The data being sent
/// \param[in] bitsUsed How many bits long \a data is
/// \param[in] remoteSystemAddress Which system this message is being sent to
void OnDirectSocketSend(const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress) {(void) data; (void) bitsUsed; (void) remoteSystemAddress;}
/// Called on a receive from the socket, per datagram, that does not go through the reliability layer
/// \param[in] data The data being sent
/// \param[in] bitsUsed How many bits long \a data is
/// \param[in] remoteSystemAddress Which system this message is being sent to
void OnDirectSocketReceive(const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress) {(void) data; (void) bitsUsed; (void) remoteSystemAddress;}
/// Called on a send or receive of a message within the reliability layer
/// \param[in] internalPacket The user message, along with all send data.
/// \param[in] frameNumber The number of frames sent or received so far for this player depending on \a isSend . Indicates the frame of this user message.
/// \param[in] remoteSystemAddress The player we sent or got this packet from
/// \param[in] time The current time as returned by GetTimeMS()
/// \param[in] isSend Is this callback representing a send event or receive event?
void OnInternalPacket(InternalPacket *internalPacket, unsigned frameNumber, SystemAddress remoteSystemAddress, TimeMS time, int isSend) {(void) internalPacket; (void) frameNumber; (void) remoteSystemAddress; (void) time; (void) isSend;}
/// Called when we get an ack for a message we reliabily sent
/// \param[in] messageNumber The numerical identifier for which message this is
/// \param[in] remoteSystemAddress The player we sent or got this packet from
/// \param[in] time The current time as returned by GetTimeMS()
void OnAck(unsigned int messageNumber, SystemAddress remoteSystemAddress, TimeMS time) {(void) messageNumber; (void) remoteSystemAddress; (void) time;}
/// System called RakPeerInterface::PushBackPacket
/// \param[in] data The data being sent
/// \param[in] bitsUsed How many bits long \a data is
/// \param[in] remoteSystemAddress The player we sent or got this packet from
void OnPushBackPacket(const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress) {(void) data; (void) bitsUsed; (void) remoteSystemAddress;}
private:
RakTimer timer;
};

View File

@ -0,0 +1,362 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "PeerConnectDisconnectTest.h"
void PeerConnectDisconnectTest::WaitForConnectionRequestsToComplete(RakPeerInterface **peerList, int peerNum, bool isVerbose)
{
SystemAddress currentSystem;
bool msgWasPrinted=false;
for (int i=0;i<peerNum;i++)
{
for (int j=i+1;j<peerNum;j++)//Start at i+1 so don't connect two of the same together.
{
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000+j;
while (CommonFunctions::ConnectionStateMatchesOptions (peerList[i],currentSystem,false,true,true) )
{
if (msgWasPrinted==false)
{
printf("Waiting for connection requests to complete.\n");
msgWasPrinted=true;
}
RakSleep(30);
}
}
}
}
void PeerConnectDisconnectTest::WaitAndPrintResults(RakPeerInterface **peerList, int peerNum, bool isVerbose)
{
WaitForConnectionRequestsToComplete(peerList,peerNum,isVerbose);
Packet *packet;
// Log all events per peer
for (int i=0;i<peerNum;i++)//Receive for all peers
{
if (isVerbose)
printf("For peer %i\n",i);
for (packet=peerList[i]->Receive(); packet; peerList[i]->DeallocatePacket(packet), packet=peerList[i]->Receive())
{
switch (packet->data[0])
{
case ID_REMOTE_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("Another client has disconnected.\n");
break;
case ID_REMOTE_CONNECTION_LOST:
if (isVerbose)
printf("Another client has lost the connection.\n");
break;
case ID_REMOTE_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("Another client has connected.\n");
break;
case ID_CONNECTION_REQUEST_ACCEPTED:
if (isVerbose)
printf("Our connection request has been accepted.\n");
break;
case ID_CONNECTION_ATTEMPT_FAILED:
if (isVerbose)
printf("A connection has failed.\n");
break;
case ID_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("A connection is incoming.\n");
break;
case ID_NO_FREE_INCOMING_CONNECTIONS:
if (isVerbose)
printf("The server is full.\n");
break;
case ID_ALREADY_CONNECTED:
if (isVerbose)
printf("Already connected\n");
break;
case ID_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("We have been disconnected.\n");
break;
case ID_CONNECTION_LOST:
if (isVerbose)
printf("Connection lost.\n");
break;
default:
break;
}
}
}
}
/*
What is being done here is having 8 peers all connect to eachother, disconnect, connect again.
Do this for about 10 seconds. Then allow them all to connect for one last time.
Good ideas for changes:
After the last check run a eightpeers like test an add the conditions
of that test as well.
Make sure that if we initiate the connection we get a proper message
and if not we get a proper message. Add proper conditions.
Randomize sending the disconnect notes
Success conditions:
All connected normally.
Failure conditions:
Doesn't reconnect normally.
During the very first connect loop any connect returns false.
Connect function returns false and peer is not connected to anything.
*/
int PeerConnectDisconnectTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
{
const int peerNum= 8;
const int maxConnections=peerNum*3;//Max allowed connections for test set to times 3 to eliminate problem variables
RakPeerInterface *peerList[peerNum];//A list of 8 peers
SystemAddress currentSystem;
destroyList.Clear(false,_FILE_AND_LINE_);
//Initializations of the arrays
for (int i=0;i<peerNum;i++)
{
peerList[i]=RakPeerInterface::GetInstance();
destroyList.Push(peerList[i],_FILE_AND_LINE_);
peerList[i]->Startup(maxConnections, &SocketDescriptor(60000+i,0), 1);
peerList[i]->SetMaximumIncomingConnections(maxConnections);
}
//Connect all the peers together
for (int i=0;i<peerNum;i++)
{
for (int j=i+1;j<peerNum;j++)//Start at i+1 so don't connect two of the same together.
{
if (peerList[i]->Connect("127.0.0.1", 60000+j, 0,0)!=CONNECTION_ATTEMPT_STARTED)
{
if (isVerbose)
DebugTools::ShowError("Problem while calling connect.\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;//This fails the test, don't bother going on.
}
}
}
TimeMS entryTime=GetTimeMS();//Loop entry time
DataStructures::List< SystemAddress > systemList;
DataStructures::List< RakNetGUID > guidList;
printf("Entering disconnect loop \n");
while(GetTimeMS()-entryTime<10000)//Run for 10 Secoonds
{
//Disconnect all peers IF connected to any
for (int i=0;i<peerNum;i++)
{
peerList[i]->GetSystemList(systemList,guidList);//Get connectionlist
int len=systemList.Size();
for (int j=0;j<len;j++)//Disconnect them all
{
peerList[i]->CloseConnection (systemList[j],true,0,LOW_PRIORITY);
}
}
RakSleep(100);
//Connect
for (int i=0;i<peerNum;i++)
{
for (int j=i+1;j<peerNum;j++)//Start at i+1 so don't connect two of the same together.
{
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000+j;
if(!CommonFunctions::ConnectionStateMatchesOptions (peerList[i],currentSystem,true,true,true,true) )//Are we connected or is there a pending operation ?
{
if (peerList[i]->Connect("127.0.0.1", 60000+j, 0,0)!=CONNECTION_ATTEMPT_STARTED)
{
if (isVerbose)
DebugTools::ShowError("Problem while calling connect.\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;//This fails the test, don't bother going on.
}
}
}
}
WaitAndPrintResults(peerList,peerNum,isVerbose);
}
WaitAndPrintResults(peerList,peerNum,isVerbose);
printf("Connecting peers\n");
//Connect
for (int i=0;i<peerNum;i++)
{
for (int j=i+1;j<peerNum;j++)//Start at i+1 so don't connect two of the same together.
{
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000+j;
if(!CommonFunctions::ConnectionStateMatchesOptions (peerList[i],currentSystem,true,true,true,true) )//Are we connected or is there a pending operation ?
{
printf("Calling Connect() for peer %i to peer %i.\n",i,j);
if (peerList[i]->Connect("127.0.0.1", 60000+j, 0,0)!=CONNECTION_ATTEMPT_STARTED)
{
peerList[i]->GetSystemList(systemList,guidList);//Get connectionlist
int len=systemList.Size();
if (isVerbose)
DebugTools::ShowError("Problem while calling connect.\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;//This fails the test, don't bother going on.
}
}
else
{
if (CommonFunctions::ConnectionStateMatchesOptions (peerList[i],currentSystem,false,false,false,true)==false)
printf("Not calling Connect() for peer %i to peer %i because it is disconnecting.\n",i,j);
else if (CommonFunctions::ConnectionStateMatchesOptions (peerList[i],currentSystem,false,true,true)==false)
printf("Not calling Connect() for peer %i to peer %i because it is connecting.\n",i,j);
else if (CommonFunctions::ConnectionStateMatchesOptions (peerList[i],currentSystem,true)==false)
printf("Not calling Connect() for peer %i to peer %i because it is connected).\n",i,j);
}
}
}
WaitAndPrintResults(peerList,peerNum,isVerbose);
for (int i=0;i<peerNum;i++)
{
peerList[i]->GetSystemList(systemList,guidList);
int connNum=guidList.Size();//Get the number of connections for the current peer
if (connNum!=peerNum-1)//Did we connect to all?
{
if (isVerbose)
{
printf("Not all peers reconnected normally.\nFailed on peer number %i with %i peers\n",i,connNum);
DebugTools::ShowError("",!noPauses && isVerbose,__LINE__,__FILE__);
}
return 2;
}
}
if (isVerbose)
printf("Pass\n");
return 0;
}
RakString PeerConnectDisconnectTest::GetTestName()
{
return "PeerConnectDisconnectTest";
}
RakString PeerConnectDisconnectTest::ErrorCodeToString(int errorCode)
{
switch (errorCode)
{
case 0:
return "No error";
break;
case 1:
return "The connect function failed.";
break;
case 2:
return "Peers did not connect normally.";
break;
default:
return "Undefined Error";
}
}
PeerConnectDisconnectTest::PeerConnectDisconnectTest(void)
{
}
PeerConnectDisconnectTest::~PeerConnectDisconnectTest(void)
{
}
void PeerConnectDisconnectTest::DestroyPeers()
{
int theSize=destroyList.Size();
for (int i=0; i < theSize; i++)
RakPeerInterface::DestroyInstance(destroyList[i]);
}

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "TestInterface.h"
#include "RakString.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include "RakPeer.h"
#include "RakSleep.h"
#include "RakNetTime.h"
#include "GetTime.h"
#include "DebugTools.h"
#include "CommonFunctions.h"
using namespace RakNet;
class PeerConnectDisconnectTest : public TestInterface
{
public:
PeerConnectDisconnectTest(void);
~PeerConnectDisconnectTest(void);
int RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses);//should return 0 if no error, or the error number
RakString GetTestName();
RakString ErrorCodeToString(int errorCode);
void DestroyPeers();
protected:
void WaitForConnectionRequestsToComplete(RakPeerInterface **peerList, int peerNum, bool isVerbose);
void WaitAndPrintResults(RakPeerInterface **peerList, int peerNum, bool isVerbose);
private:
DataStructures::List <RakPeerInterface *> destroyList;
};

View File

@ -0,0 +1,534 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "PeerConnectDisconnectWithCancelPendingTest.h"
/*
What is being done here is having 8 peers all connect to eachother, disconnect, connect again.
Do this for about 10 seconds. Then allow them all to connect for one last time.
This test also tests the cancelpendingconnections.
Also tests nonblocking connects, the simpler one PeerConnectDisconnect tests without it
Good ideas for changes:
After the last check run a eightpeers like test an add the conditions
of that test as well.
Make sure that if we initiate the connection we get a proper message
and if not we get a proper message. Add proper conditions.
Randomize sending the disconnect notes
Success conditions:
All connected normally and pending requests get canceled normally.
Failure conditions:
Doesn't reconnect normally.
During the very first connect loop any connect returns false.
Connect function returns false and peer is not connected to anything.
Pending request is not canceled.
*/
int PeerConnectDisconnectWithCancelPendingTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
{
const int peerNum= 8;
const int maxConnections=peerNum*3;//Max allowed connections for test set to times 3 to eliminate problem variables
RakPeerInterface *peerList[peerNum];//A list of 8 peers
SystemAddress currentSystem;
Packet *packet;
destroyList.Clear(false,_FILE_AND_LINE_);
//Initializations of the arrays
for (int i=0;i<peerNum;i++)
{
peerList[i]=RakPeerInterface::GetInstance();
destroyList.Push(peerList[i],_FILE_AND_LINE_);
peerList[i]->Startup(maxConnections, &SocketDescriptor(60000+i,0), 1);
peerList[i]->SetMaximumIncomingConnections(maxConnections);
}
//Connect all the peers together
for (int i=0;i<peerNum;i++)
{
for (int j=i+1;j<peerNum;j++)//Start at i+1 so don't connect two of the same together.
{
if (peerList[i]->Connect("127.0.0.1", 60000+j, 0,0)!=CONNECTION_ATTEMPT_STARTED)
{
if (isVerbose)
DebugTools::ShowError("Problem while calling connect.",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;//This fails the test, don't bother going on.
}
}
}
TimeMS entryTime=GetTimeMS();//Loop entry time
DataStructures::List< SystemAddress > systemList;
DataStructures::List< RakNetGUID > guidList;
printf("Entering disconnect loop \n");
bool printedYet;
while(GetTimeMS()-entryTime<10000)//Run for 10 Secoonds
{
//Disconnect all peers IF connected to any
for (int i=0;i<peerNum;i++)
{
peerList[i]->GetSystemList(systemList,guidList);//Get connectionlist
int len=systemList.Size();
for (int j=0;j<len;j++)//Disconnect them all
{
peerList[i]->CloseConnection (systemList[j],true,0,LOW_PRIORITY);
}
}
RakSleep(100);
//Clear pending if not finished
for (int i=0;i<peerNum;i++)
{
for (int j=i+1;j<peerNum;j++)//Start at i+1 so don't connect two of the same together.
{
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000+j;
peerList[i]->CancelConnectionAttempt(currentSystem); //Make sure a connection is not pending before trying to connect.
}
}
RakSleep(100);
//Connect
for (int i=0;i<peerNum;i++)
{
for (int j=i+1;j<peerNum;j++)//Start at i+1 so don't connect two of the same together.
{
if (peerList[i]->Connect("127.0.0.1", 60000+j, 0,0)!=CONNECTION_ATTEMPT_STARTED)
{
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000+j;
peerList[i]->GetSystemList(systemList,guidList);//Get connectionlist
int len=systemList.Size();
if(CommonFunctions::ConnectionStateMatchesOptions (peerList[i],currentSystem,false,true,true))//Did we drop the pending connection?
{
if (isVerbose)
DebugTools::ShowError("Did not cancel the pending request \n",!noPauses && isVerbose,__LINE__,__FILE__);
return 3;
}
if (!CommonFunctions::ConnectionStateMatchesOptions (peerList[i],currentSystem,true,true,true,true))
{
if (isVerbose)
DebugTools::ShowError("Problem while calling connect. \n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;//This fails the test, don't bother going on.
}
}
}
}
for (int i=0;i<peerNum;i++)//Receive for all peers
{
printedYet=false;
packet=peerList[i]->Receive();
while(packet)
{
if (isVerbose&&!printedYet)
{
printf("For peer %i\n",i);
printedYet=true;
}
switch (packet->data[0])
{
case ID_REMOTE_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("Another client has disconnected.\n");
break;
case ID_REMOTE_CONNECTION_LOST:
if (isVerbose)
printf("Another client has lost the connection.\n");
break;
case ID_REMOTE_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("Another client has connected.\n");
break;
case ID_CONNECTION_REQUEST_ACCEPTED:
if (isVerbose)
printf("Our connection request has been accepted.\n");
break;
case ID_CONNECTION_ATTEMPT_FAILED:
if (isVerbose)
printf("A connection has failed.\n");
break;
case ID_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("A connection is incoming.\n");
break;
case ID_NO_FREE_INCOMING_CONNECTIONS:
if (isVerbose)
printf("The server is full.\n");
break;
case ID_ALREADY_CONNECTED:
if (isVerbose)
printf("Already connected\n");
break;
case ID_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("We have been disconnected.\n");
break;
case ID_CONNECTION_LOST:
if (isVerbose)
printf("Connection lost.\n");
break;
default:
break;
}
peerList[i]->DeallocatePacket(packet);
// Stay in the loop as long as there are more packets.
packet = peerList[i]->Receive();
}
}
RakSleep(0);//If needed for testing
}
while(GetTimeMS()-entryTime<2000)//Run for 2 Secoonds to process incoming disconnects
{
for (int i=0;i<peerNum;i++)//Receive for all peers
{
printedYet=false;
packet=peerList[i]->Receive();
while(packet)
{
if (isVerbose&&!printedYet)
{
printf("For peer %i\n",i);
printedYet=true;
}
switch (packet->data[0])
{
case ID_REMOTE_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("Another client has disconnected.\n");
break;
case ID_REMOTE_CONNECTION_LOST:
if (isVerbose)
printf("Another client has lost the connection.\n");
break;
case ID_REMOTE_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("Another client has connected.\n");
break;
case ID_CONNECTION_REQUEST_ACCEPTED:
if (isVerbose)
printf("Our connection request has been accepted.\n");
break;
case ID_CONNECTION_ATTEMPT_FAILED:
if (isVerbose)
printf("A connection has failed.\n");
break;
case ID_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("A connection is incoming.\n");
break;
case ID_NO_FREE_INCOMING_CONNECTIONS:
if (isVerbose)
printf("The server is full.\n");
break;
case ID_ALREADY_CONNECTED:
if (isVerbose)
printf("Already connected\n");
break;
case ID_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("We have been disconnected.\n");
break;
case ID_CONNECTION_LOST:
if (isVerbose)
printf("Connection lost.\n");
break;
default:
break;
}
peerList[i]->DeallocatePacket(packet);
// Stay in the loop as long as there are more packets.
packet = peerList[i]->Receive();
}
}
RakSleep(0);//If needed for testing
}
//Connect
for (int i=0;i<peerNum;i++)
{
for (int j=i+1;j<peerNum;j++)//Start at i+1 so don't connect two of the same together.
{
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000+j;
peerList[i]->CancelConnectionAttempt(currentSystem); //Make sure a connection is not pending before trying to connect.
if (peerList[i]->Connect("127.0.0.1", 60000+j, 0,0)!=CONNECTION_ATTEMPT_STARTED)
{
peerList[i]->GetSystemList(systemList,guidList);//Get connectionlist
int len=systemList.Size();
if (len==0)//No connections, should not fail.
{
if (isVerbose)
DebugTools::ShowError("Problem while calling connect \n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;//This fails the test, don't bother going on.
}
}
}
}
entryTime=GetTimeMS();
while(GetTimeMS()-entryTime<5000)//Run for 5 Secoonds
{
for (int i=0;i<peerNum;i++)//Receive for all peers
{
printedYet=false;
packet=peerList[i]->Receive();
while(packet)
{
if (isVerbose&&!printedYet)
{
printf("For peer %i\n",i);
printedYet=true;
}
switch (packet->data[0])
{
case ID_REMOTE_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("Another client has disconnected.\n");
break;
case ID_REMOTE_CONNECTION_LOST:
if (isVerbose)
printf("Another client has lost the connection.\n");
break;
case ID_REMOTE_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("Another client has connected.\n");
break;
case ID_CONNECTION_REQUEST_ACCEPTED:
if (isVerbose)
printf("Our connection request has been accepted.\n");
break;
case ID_CONNECTION_ATTEMPT_FAILED:
if (isVerbose)
printf("A connection has failed.\n");
break;
case ID_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("A connection is incoming.\n");
break;
case ID_NO_FREE_INCOMING_CONNECTIONS:
if (isVerbose)
printf("The server is full.\n");
break;
case ID_ALREADY_CONNECTED:
if (isVerbose)
printf("Already connected\n");
break;
case ID_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("We have been disconnected.\n");
break;
case ID_CONNECTION_LOST:
if (isVerbose)
printf("Connection lost.\n");
break;
default:
break;
}
peerList[i]->DeallocatePacket(packet);
// Stay in the loop as long as there are more packets.
packet = peerList[i]->Receive();
}
}
RakSleep(0);//If needed for testing
}
for (int i=0;i<peerNum;i++)
{
peerList[i]->GetSystemList(systemList,guidList);
int connNum=guidList.Size();//Get the number of connections for the current peer
if (connNum!=peerNum-1)//Did we connect to all?
{
if (isVerbose)
DebugTools::ShowError("Not all peers reconnected normally.\n ",!noPauses && isVerbose,__LINE__,__FILE__);
return 2;
}
}
if (isVerbose)
printf("Pass\n");
return 0;
}
RakString PeerConnectDisconnectWithCancelPendingTest::GetTestName()
{
return "PeerConnectDisconnectWithCancelPendingTest";
}
RakString PeerConnectDisconnectWithCancelPendingTest::ErrorCodeToString(int errorCode)
{
switch (errorCode)
{
case 0:
return "No error";
break;
case 1:
return "The connect function failed.";
break;
case 2:
return "Peers did not connect normally.";
break;
case 3:
return "Pending connection was not canceled.";
break;
default:
return "Undefined Error";
}
}
PeerConnectDisconnectWithCancelPendingTest::PeerConnectDisconnectWithCancelPendingTest(void)
{
}
PeerConnectDisconnectWithCancelPendingTest::~PeerConnectDisconnectWithCancelPendingTest(void)
{
}
void PeerConnectDisconnectWithCancelPendingTest::DestroyPeers()
{
int theSize=destroyList.Size();
for (int i=0; i < theSize; i++)
RakPeerInterface::DestroyInstance(destroyList[i]);
}

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "TestInterface.h"
#include "RakString.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include "RakPeer.h"
#include "RakSleep.h"
#include "RakNetTime.h"
#include "GetTime.h"
#include "DebugTools.h"
#include "CommonFunctions.h"
using namespace RakNet;
class PeerConnectDisconnectWithCancelPendingTest : public TestInterface
{
public:
PeerConnectDisconnectWithCancelPendingTest(void);
~PeerConnectDisconnectWithCancelPendingTest(void);
int RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses);//should return 0 if no error, or the error number
RakString GetTestName();
RakString ErrorCodeToString(int errorCode);
void DestroyPeers();
private:
DataStructures::List <RakPeerInterface *> destroyList;
};

View File

@ -0,0 +1,296 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "PingTestsTest.h"
/*
Description:
Tests out:
virtual int GetAveragePing (const SystemAddress systemAddress)=0
virtual int GetLastPing (const SystemAddress systemAddress) const =0
virtual int GetLowestPing (const SystemAddress systemAddress) const =0
virtual void SetOccasionalPing (bool doPing)=0
Ping is tested in CrossConnectionConvertTest,SetOfflinePingResponse and GetOfflinePingResponse tested in OfflineMessagesConvertTest
Success conditions:
Currently is that GetAveragePing and SetOccasionalPing works
Failure conditions:
RakPeerInterface Functions used, tested indirectly by its use, not all encompassing list:
Startup
SetMaximumIncomingConnections
Receive
DeallocatePacket
RakPeerInterface Functions Explicitly Tested:
GetAveragePing
GetLastPing
GetLowestPing
SetOccasionalPing
*/
int PingTestsTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
{
RakPeerInterface *sender,*sender2, *receiver;
destroyList.Clear(false,_FILE_AND_LINE_);
TestHelpers::StandardClientPrep(sender,destroyList);
TestHelpers::StandardClientPrep(sender2,destroyList);
receiver=RakPeerInterface::GetInstance();
destroyList.Push(receiver,_FILE_AND_LINE_);
receiver->Startup(2, &SocketDescriptor(60000,0), 1);
receiver->SetMaximumIncomingConnections(2);
Packet * packet;
SystemAddress currentSystem;
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000;
printf("Connecting sender2\n");
if (!TestHelpers::WaitAndConnectTwoPeersLocally(sender2,receiver,5000))
{
if (isVerbose)
DebugTools::ShowError("Could not connect after 5 seconds\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 2;
}
printf("Getting ping data for lastping and lowestping\n");
sender2->SetOccasionalPing(false);//Test the lowest ping and such without occassionalping,occasional ping comes later
RakTimer timer(1500);
int lastPing=0;
int lowestPing=0;
TimeMS nextPing=0;
while(!timer.IsExpired())
{
for (packet=receiver->Receive();packet;receiver->DeallocatePacket(packet),packet=receiver->Receive())
{
if (isVerbose)
printf("Receive packet id %i\n",packet->data[0]);
}
for (packet=sender2->Receive();packet;sender2->DeallocatePacket(packet),packet=sender2->Receive())
{
if (isVerbose)
printf("Send packet id %i\n",packet->data[0]);
}
if (GetTimeMS()>nextPing)
{
sender2->Ping(currentSystem);
nextPing=GetTimeMS()+30;
}
RakSleep(3);
}
int averagePing=sender2->GetAveragePing(currentSystem);
if (isVerbose)
printf("Average Ping time %i\n",averagePing);
lastPing=sender2->GetLastPing(currentSystem);
lowestPing=sender2->GetLowestPing(currentSystem);
if (isVerbose)
printf("Last Ping time %i\n",lastPing);
if (isVerbose)
printf("Lowest Ping time %i\n",lowestPing);
int returnVal=TestAverageValue(averagePing,__LINE__, noPauses, isVerbose);
if (returnVal!=0)
{
return returnVal;
}
if (lastPing>100)//100 MS for localhost?
{
if (isVerbose)
DebugTools::ShowError("Problem with the last ping time,greater then 100MS for localhost\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 3;
}
if (lowestPing>10)//The lowest ping for localhost should drop below 10MS at least once
{
if (isVerbose)
DebugTools::ShowError("The lowest ping for localhost should drop below 10MS at least once\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 4;
}
if (lastPing<lowestPing)
{
if (isVerbose)
DebugTools::ShowError("There is a problem if the lastping is lower than the lowestping stat\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 5;
}
CommonFunctions::DisconnectAndWait(sender2,"127.0.0.1",60000);//Eliminate variables.
printf("Connecting sender\n");
if (!TestHelpers::WaitAndConnectTwoPeersLocally(sender,receiver,5000))
{
if (isVerbose)
DebugTools::ShowError("Could not connect after 5 seconds\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 2;
}
lastPing=0;
lowestPing=0;
sender->SetOccasionalPing(true);
printf("Testing SetOccasionalPing\n");
timer.Start();
while(!timer.IsExpired())
{
for (packet=receiver->Receive();packet;receiver->DeallocatePacket(packet),packet=receiver->Receive())
{
if (isVerbose)
printf("Receive packet id %i\n",packet->data[0]);
}
for (packet=sender->Receive();packet;sender->DeallocatePacket(packet),packet=sender->Receive())
{
if (isVerbose)
printf("Send packet id %i\n",packet->data[0]);
}
RakSleep(3);
}
averagePing=sender->GetAveragePing(currentSystem);
if (isVerbose)
printf("Average Ping time %i\n",averagePing);
returnVal=TestAverageValue(averagePing,__LINE__, noPauses, isVerbose);
if (returnVal!=0)
{
return returnVal;
}
return 0;
}
int PingTestsTest::TestAverageValue(int averagePing,int line,bool noPauses,bool isVerbose)
{
if (averagePing<0)
{
if (isVerbose)
DebugTools::ShowError("Problem with the average ping time,should never be less than zero in this test\n",!noPauses && isVerbose,line,__FILE__);
return 1;
}
if (averagePing>10)//Average Ping should not be greater than 10MS for localhost. Command line pings typically give < 1ms
{
if (isVerbose)
DebugTools::ShowError("Average Ping should not be greater than 10MS for localhost. Command line pings typically give < 1ms\n",!noPauses && isVerbose,line,__FILE__);
return 5;
}
return 0;
}
RakString PingTestsTest::GetTestName()
{
return "PingTestsTest";
}
RakString PingTestsTest::ErrorCodeToString(int errorCode)
{
switch (errorCode)
{
case 0:
return "No error";
break;
case 1:
return "Problem with the average ping time,should never be less than 0 in this test";
break;
case 2:
return "Could not connect after 5 seconds";
break;
case 3:
return "Problem with the last ping time,greater then 100MS for localhost";
break;
case 4:
return "The lowest ping for localhost should drop below 10MS at least once";
break;
case 5:
return "There is a problem if the lastping is lower than the lowestping stat";
break;
case 6:
return "Average Ping should not be greater than 10MS for localhost. Command line pings typically give < 1ms";
break;
default:
return "Undefined Error";
}
}
PingTestsTest::PingTestsTest(void)
{
}
PingTestsTest::~PingTestsTest(void)
{
}
void PingTestsTest::DestroyPeers()
{
int theSize=destroyList.Size();
for (int i=0; i < theSize; i++)
RakPeerInterface::DestroyInstance(destroyList[i]);
}

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "TestInterface.h"
#include "RakString.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include "RakPeer.h"
#include "RakSleep.h"
#include "RakNetTime.h"
#include "GetTime.h"
#include "DebugTools.h"
#include "TestHelpers.h"
#include "CommonFunctions.h"
#include "RakTimer.h"
using namespace RakNet;
class PingTestsTest : public TestInterface
{
public:
PingTestsTest(void);
~PingTestsTest(void);
int RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses);//should return 0 if no error, or the error number
RakString GetTestName();
RakString ErrorCodeToString(int errorCode);
void DestroyPeers();
int TestAverageValue(int averagePing,int line,bool noPauses,bool isVerbose);
private:
DataStructures::List <RakPeerInterface *> destroyList;
};

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "RakTimer.h"
RakTimer::RakTimer(void)
{
timerLength=1000;
Start();
}
RakTimer::RakTimer(int lengthInMilliseconds)
{
timerLength=lengthInMilliseconds;
Start();
}
RakTimer::~RakTimer(void)
{
}
void RakTimer::SetTimerLength(int lengthInMilliseconds)
{
timerLength=lengthInMilliseconds;
}
void RakTimer::Start()
{
startTime=RakNet::GetTimeMS();
}
void RakTimer::Pause()
{
pauseOffset=(int)(RakNet::GetTimeMS()-startTime);
}
void RakTimer::Resume()
{
startTime=RakNet::GetTimeMS()-pauseOffset;
}
bool RakTimer::IsExpired()
{
return (RakNet::GetTimeMS()-startTime>timerLength);
}

33
Samples/Tests/RakTimer.h Normal file
View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "RakNetTime.h"
#include "GetTime.h"
using namespace RakNet;
class RakTimer
{
public:
RakTimer(void);
RakTimer(int lengthInMilliseconds);
~RakTimer(void);
void SetTimerLength(int lengthInMilliseconds);
void Start();
void Pause();
void Resume();
bool IsExpired();
private:
int timerLength;//Modified by SetTimerLength
int pauseOffset;
TimeMS startTime;
};

View File

@ -0,0 +1,402 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "ReliableOrderedConvertedTest.h"
FILE *fp;
int memoryUsage=0;
char lastError[512];
void* ReliableOrderedConvertedTest::LoggedMalloc(size_t size, const char *file, unsigned int line)
{
memoryUsage+=(int)size;
if (fp)
fprintf(fp,"Alloc %s:%i %i bytes %i total\n", file,line,size,memoryUsage);
char *p = (char*) malloc(size+sizeof(size));
memcpy(p,&size,sizeof(size));
return p+sizeof(size);
}
void ReliableOrderedConvertedTest::LoggedFree(void *p, const char *file, unsigned int line)
{
char *realP=(char*)p-sizeof(size_t);
size_t allocatedSize;
memcpy(&allocatedSize,realP,sizeof(size_t));
memoryUsage-=(int)allocatedSize;
if (fp)
fprintf(fp,"Free %s:%i %i bytes %i total\n", file,line,allocatedSize,memoryUsage);
free(realP);
}
void* ReliableOrderedConvertedTest::LoggedRealloc(void *p, size_t size, const char *file, unsigned int line)
{
char *realP=(char*)p-sizeof(size_t);
size_t allocatedSize;
memcpy(&allocatedSize,realP,sizeof(size_t));
memoryUsage-=(int)allocatedSize;
memoryUsage+=(int)size;
p = realloc(realP,size+sizeof(size));
memcpy(p,&size,sizeof(size));
if (fp)
fprintf(fp,"Realloc %s:%i %i to %i bytes %i total\n", file,line,allocatedSize,size,memoryUsage);
return (char*)p+sizeof(size);
}
/*
What is being done here is having a server connect to a client.
Packets are sent at 30 millisecond intervals for 12 seconds.
Length and sequence are checked for each packet.
Success conditions:
All packets are correctly recieved in order.
Failure conditions:
All packets are not correctly recieved.
All packets are not in order.
*/
int ReliableOrderedConvertedTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
{
RakPeerInterface *sender, *receiver;
unsigned int packetNumberSender[32],packetNumberReceiver[32], receivedPacketNumberReceiver, receivedTimeReceiver;
char str[256];
char ip[32];
TimeMS sendInterval, nextSend, currentTime, quitTime;
unsigned short remotePort, localPort;
unsigned char streamNumberSender,streamNumberReceiver;
BitStream bitStream;
Packet *packet;
bool doSend=false;
for (int i=0; i < 32; i++)
{
packetNumberSender[i]=0;
packetNumberReceiver[i]=0;
}
/*
if (argc==2)
{
fp = fopen(argv[1],"wt");
SetMalloc_Ex(LoggedMalloc);
SetRealloc_Ex(LoggedRealloc);
SetFree_Ex(LoggedFree);
}
else
*/
fp=0;
destroyList.Clear(false,_FILE_AND_LINE_);
sender =RakPeerInterface::GetInstance();
destroyList.Push( sender ,_FILE_AND_LINE_);
//sender->ApplyNetworkSimulator(.02, 100, 50);
/*
if (str[0]==0)
sendInterval=30;
else
sendInterval=atoi(str);*///possible future params
sendInterval=30;
/*
printf("Enter remote IP: ");
Gets(ip, sizeof(ip));
if (ip[0]==0)*/
strcpy(ip, "127.0.0.1");
/*
printf("Enter remote port: ");
Gets(str, sizeof(str));
if (str[0]==0)*/
strcpy(str, "60000");
remotePort=atoi(str);
/*
printf("Enter local port: ");
Gets(str, sizeof(str));
if (str[0]==0)*/
strcpy(str, "0");
localPort=atoi(str);
if (isVerbose)
printf("Connecting...\n");
sender->Startup(1, &SocketDescriptor(localPort,0), 1);
sender->Connect(ip, remotePort, 0, 0);
receiver =RakPeerInterface::GetInstance();
destroyList.Push( receiver ,_FILE_AND_LINE_);
/*
printf("Enter local port: ");
Gets(str, sizeof(str));
if (str[0]==0)*/
strcpy(str, "60000");
localPort=atoi(str);
if (isVerbose)
printf("Waiting for connections...\n");
receiver->Startup(32, &SocketDescriptor(localPort,0), 1);
receiver->SetMaximumIncomingConnections(32);
// if (sender)
// sender->ApplyNetworkSimulator(128000, 50, 100);
// if (receiver)
// receiver->ApplyNetworkSimulator(128000, 50, 100);
/*printf("How long to run this test for, in seconds?\n");
Gets(str, sizeof(str));
if (str[0]==0)*/
strcpy(str, "12");
currentTime = GetTimeMS();
quitTime = atoi(str) * 1000 + currentTime;
nextSend=currentTime;
while (currentTime < quitTime)
//while (1)
{
packet = sender->Receive();
while (packet)
{
// PARSE TYPES
switch(packet->data[0])
{
case ID_CONNECTION_REQUEST_ACCEPTED:
if (isVerbose)
printf("ID_CONNECTION_REQUEST_ACCEPTED\n");
doSend=true;
nextSend=currentTime;
break;
case ID_NO_FREE_INCOMING_CONNECTIONS:
if (isVerbose)
printf("ID_NO_FREE_INCOMING_CONNECTIONS\n");
break;
case ID_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("ID_DISCONNECTION_NOTIFICATION\n");
break;
case ID_CONNECTION_LOST:
if (isVerbose)
printf("ID_CONNECTION_LOST\n");
break;
case ID_CONNECTION_ATTEMPT_FAILED:
if (isVerbose)
printf("Connection attempt failed\n");
break;
}
sender->DeallocatePacket(packet);
packet = sender->Receive();
}
while (doSend && currentTime > nextSend)
{
streamNumberSender=0;
// streamNumber = randomMT() % 32;
// Do the send
bitStream.Reset();
bitStream.Write((unsigned char) (ID_USER_PACKET_ENUM+1));
bitStream.Write(packetNumberSender[streamNumberSender]++);
bitStream.Write(streamNumberSender);
bitStream.Write(currentTime);
char *pad;
int padLength = (randomMT() % 5000) + 1;
pad = new char [padLength];
bitStream.Write(pad, padLength);
delete [] pad;
// Send on a random priority with a random stream
// if (sender->Send(&bitStream, HIGH_PRIORITY, (PacketReliability) (RELIABLE + (randomMT() %2)) ,streamNumber, UNASSIGNED_SYSTEM_ADDRESS, true)==false)
if (sender->Send(&bitStream, HIGH_PRIORITY, RELIABLE_ORDERED ,streamNumberSender, UNASSIGNED_SYSTEM_ADDRESS, true)==false)
packetNumberSender[streamNumberSender]--; // Didn't finish connecting yet?
RakNetStatistics *rssSender;
rssSender=sender->GetStatistics(sender->GetSystemAddressFromIndex(0));
if (isVerbose)
printf("Snd: %i.\n", packetNumberSender[streamNumberSender]);
nextSend+=sendInterval;
// Test halting
// if (rand()%20==0)
// nextSend+=1000;
}
packet = receiver->Receive();
while (packet)
{
switch(packet->data[0])
{
case ID_NEW_INCOMING_CONNECTION:
if (isVerbose)
printf("ID_NEW_INCOMING_CONNECTION\n");
break;
case ID_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("ID_DISCONNECTION_NOTIFICATION\n");
break;
case ID_CONNECTION_LOST:
if (isVerbose)
printf("ID_CONNECTION_LOST\n");
break;
case ID_USER_PACKET_ENUM+1:
bitStream.Reset();
bitStream.Write((char*)packet->data, packet->length);
bitStream.IgnoreBits(8); // Ignore ID_USER_PACKET_ENUM+1
bitStream.Read(receivedPacketNumberReceiver);
bitStream.Read(streamNumberReceiver);
bitStream.Read(receivedTimeReceiver);
if (receivedPacketNumberReceiver!=packetNumberReceiver[streamNumberReceiver])
{
//WARNING: If you modify the below code make sure the whole string remains in bounds, sprintf will NOT do it for you.
//The error string is 512 in length
//Note: Removed buffer checking because chance is insignificant, left code if wanted in future. Needs limits.h ISO C standard.
/*
int maxIntWorkingCopy= INT_MAX;
int maxIntCharLen =0;
while (maxIntWorkingCopy>0)
{maxIntCharLen++;
maxIntWorkingCopy/=10;
}
if (strlen(lastError)>maxIntCharLen* 3 +27)//512 should be a good len for now
{*/
sprintf(lastError,"Expecting %i got %i (channel %i).",packetNumberReceiver[streamNumberReceiver], receivedPacketNumberReceiver, streamNumberReceiver);
/*
}
else
{
sprintf(lastError,"Did not get what was expected. More details can be given if the error string buffer size is increased.");
}*/
if (isVerbose)
{
RakNetStatistics *rssSender,*rssReceiver;
char message[2048];
rssSender=sender->GetStatistics(sender->GetSystemAddressFromIndex(0));
rssReceiver=receiver->GetStatistics(receiver->GetSystemAddressFromIndex(0));
StatisticsToString(rssSender, message, 2);
printf("Server stats %s\n", message);
StatisticsToString(rssReceiver, message, 2);
printf("Client stats%s", message);
DebugTools::ShowError(lastError,!noPauses && isVerbose,__LINE__,__FILE__);
}
return 1;
}
else
if (isVerbose)
{
printf("Got %i.Channel %i.Len %i.", packetNumberReceiver[streamNumberReceiver], streamNumberReceiver, packet->length);
printf("Sent=%u Received=%u Diff=%i.\n", receivedTimeReceiver, currentTime, (int)currentTime - (int) receivedTimeReceiver);
}
packetNumberReceiver[streamNumberReceiver]++;
break;
}
receiver->DeallocatePacket(packet);
packet = receiver->Receive();
}
RakSleep(0);
currentTime=GetTimeMS();
}
if (isVerbose)
{
RakNetStatistics *rssSender,*rssReceiver;
char message[2048];
rssSender=sender->GetStatistics(sender->GetSystemAddressFromIndex(0));
rssReceiver=receiver->GetStatistics(receiver->GetSystemAddressFromIndex(0));
StatisticsToString(rssSender, message, 2);
printf("Server stats %s\n", message);
StatisticsToString(rssReceiver, message, 2);
printf("Client stats%s", message);
}
if (fp)
fclose(fp);
return 0;
}
RakString ReliableOrderedConvertedTest::GetTestName()
{
return "ReliableOrderedConvertedTest";
}
RakString ReliableOrderedConvertedTest::ErrorCodeToString(int errorCode)
{
RakString returnString;
switch (errorCode)
{
case 0:
return "No error";
break;
case 1:
returnString= "The very last error for this object was ";
returnString+=lastError;
return returnString;
break;
default:
return "Undefined Error";
}
}
ReliableOrderedConvertedTest::ReliableOrderedConvertedTest(void)
{
}
ReliableOrderedConvertedTest::~ReliableOrderedConvertedTest(void)
{
}
void ReliableOrderedConvertedTest::DestroyPeers()
{
int theSize=destroyList.Size();
for (int i=0; i < theSize; i++)
RakPeerInterface::DestroyInstance(destroyList[i]);
}

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*
* Modified work: Copyright (c) 2017, SLikeSoft UG (haftungsbeschränkt)
*
* This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
* license found in the license.txt file in the root directory of this source tree.
*/
#pragma once
#include "TestInterface.h"
#include "slikenet/peerinterface.h"
#include "slikenet/GetTime.h"
#include "slikenet/MessageIdentifiers.h"
#include "slikenet/BitStream.h"
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <stdlib.h>
#include "slikenet/Rand.h"
#include "slikenet/statistics.h"
#include "slikenet/sleep.h"
#include "slikenet/memoryoverride.h"
#include "DebugTools.h"
using namespace RakNet;
class ReliableOrderedConvertedTest : public TestInterface
{
public:
ReliableOrderedConvertedTest(void);
~ReliableOrderedConvertedTest(void);
int RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses);//should return 0 if no error, or the error number
RakString GetTestName();
RakString ErrorCodeToString(int errorCode);
void DestroyPeers();
protected:
void *LoggedMalloc(size_t size, const char *file, unsigned int line);
void LoggedFree(void *p, const char *file, unsigned int line);
void* LoggedRealloc(void *p, size_t size, const char *file, unsigned int line);
private:
DataStructures::List <RakPeerInterface *> destroyList;
};

View File

@ -0,0 +1,601 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "SecurityFunctionsTest.h"
/*
Description:
Tests:
virtual void RakPeerInterface::AddToSecurityExceptionList ( const char * ip )
virtual void RakPeerInterface::AddToBanList ( const char * IP, TimeMS milliseconds = 0 )
virtual void RakPeerInterface::GetIncomingPassword ( char * passwordData, int * passwordDataLength )
virtual void RakPeerInterface::InitializeSecurity ( const char * pubKeyE, const char * pubKeyN, const char * privKeyP, const char * privKeyQ )
virtual bool RakPeerInterface::IsBanned ( const char * IP )
virtual bool RakPeerInterface::IsInSecurityExceptionList ( const char * ip )
virtual void RakPeerInterface::RemoveFromSecurityExceptionList ( const char * ip )
virtual void RakPeerInterface::RemoveFromBanList ( const char * IP )
virtual void RakPeerInterface::SetIncomingPassword ( const char * passwordData, int passwordDataLength )
virtual void ClearBanList (void)=0
Success conditions:
All functions pass tests.
Failure conditions:
Any function fails test.
Client connects with no password
Client connects with wrong password
Client failed to connect with correct password
Client was banned but connected anyways
GetIncomingPassword returned wrong password
IsBanned does not show localhost as banned
Localhost was not unbanned
Client failed to connect after banlist removal
Client failed to connect after banlist removal with clear function
Client did not connect encrypted
Client connected encrypted but shouldn't have
IsInSecurityExceptionList does not register localhost addition
RakPeerInterface Functions used, tested indirectly by its use:
Startup
SetMaximumIncomingConnections
Receive
DeallocatePacket
Send
IsConnected
GetStatistics
RakPeerInterface Functions Explicitly Tested:
SetIncomingPassword
GetIncomingPassword
AddToBanList
IsBanned
RemoveFromBanList
ClearBanList
InitializeSecurity //Disabled because of RakNetStatistics changes
AddToSecurityExceptionList //Disabled because of RakNetStatistics changes
IsInSecurityExceptionList //Disabled because of RakNetStatistics changes
RemoveFromSecurityExceptionList //Disabled because of RakNetStatistics changes
*/
int SecurityFunctionsTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
{
char thePassword[]="password";
server=RakPeerInterface::GetInstance();
client=RakPeerInterface::GetInstance();
client->Startup(1,&SocketDescriptor(),1);
server->Startup(1,&SocketDescriptor(60000,0),1);
server->SetMaximumIncomingConnections(1);
server->SetIncomingPassword(thePassword,(int)strlen(thePassword));
char returnedPass[22];
int returnedLen=22;
server->GetIncomingPassword(returnedPass,&returnedLen);
returnedPass[returnedLen]=0;//Password is a data block convert to null terminated string to make the test easier
if (strcmp(returnedPass,thePassword)!=0)
{
if (isVerbose)
{
printf("%s was returned but %s is the password\n",returnedPass,thePassword);
DebugTools::ShowError("GetIncomingPassword returned wrong password\n",!noPauses && isVerbose,__LINE__,__FILE__);
}
return 5;
}
SystemAddress serverAddress;
serverAddress.SetBinaryAddress("127.0.0.1");
serverAddress.port=60000;
TimeMS entryTime=GetTimeMS();
if (isVerbose)
printf("Testing if no password is rejected\n");
while(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true)&&GetTimeMS()-entryTime<5000)
{
if(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,true,true,true))
{
client->Connect("127.0.0.1",serverAddress.port,0,0);
}
RakSleep(100);
}
if (CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true))
{
if (isVerbose)
DebugTools::ShowError("Client connected with no password\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 1;
}
if (isVerbose)
printf("Testing if incorrect password is rejected\n");
char badPass[]="badpass";
entryTime=GetTimeMS();
while(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true)&&GetTimeMS()-entryTime<5000)
{
if(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,true,true,true))
{
client->Connect("127.0.0.1",serverAddress.port,badPass,(int)strlen(badPass));
}
RakSleep(100);
}
if (CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true))
{
if (isVerbose)
DebugTools::ShowError("Client connected with wrong password\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 2;
}
if (isVerbose)
printf("Testing if correct password is accepted\n");
entryTime=GetTimeMS();
while(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true)&&GetTimeMS()-entryTime<5000)
{
if(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,true,true,true))
{
client->Connect("127.0.0.1",serverAddress.port,thePassword,(int)strlen(thePassword));
}
RakSleep(100);
}
if (!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true))
{
if (isVerbose)
DebugTools::ShowError("Client failed to connect with correct password\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 3;
}
while(CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,true,true,true))//disconnect client
{
client->CloseConnection (serverAddress,true,0,LOW_PRIORITY);
}
if (isVerbose)
printf("Testing if connection is rejected after adding to ban list\n");
server->AddToBanList("127.0.0.1",0);
entryTime=GetTimeMS();
while(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true)&&GetTimeMS()-entryTime<5000)
{
if(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,true,true,true))
{
client->Connect("127.0.0.1",serverAddress.port,thePassword,(int)strlen(thePassword));
}
RakSleep(100);
}
if(!server->IsBanned("127.0.0.1"))
{
if (isVerbose)
DebugTools::ShowError("IsBanned does not show localhost as banned\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 6;
}
if (CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true))
{
if (isVerbose)
DebugTools::ShowError("Client was banned but connected anyways\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 4;
}
if (isVerbose)
printf("Testing if connection is accepted after ban removal by RemoveFromBanList\n");
server->RemoveFromBanList("127.0.0.1");
if(server->IsBanned("127.0.0.1"))
{
if (isVerbose)
DebugTools::ShowError("Localhost was not unbanned\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 7;
}
entryTime=GetTimeMS();
while(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true)&&GetTimeMS()-entryTime<5000)
{
if(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,true,true,true))
{
client->Connect("127.0.0.1",serverAddress.port,thePassword,(int)strlen(thePassword));
}
RakSleep(100);
}
if (!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true))
{
if (isVerbose)
DebugTools::ShowError("Client failed to connect after banlist removal\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 8;
}
while(CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,true,true,true))//disconnect client
{
client->CloseConnection (serverAddress,true,0,LOW_PRIORITY);
}
if (isVerbose)
printf("Testing if connection is rejected after adding to ban list\n");
server->AddToBanList("127.0.0.1",0);
entryTime=GetTimeMS();
while(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true)&&GetTimeMS()-entryTime<5000)
{
if(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,true,true,true))
{
client->Connect("127.0.0.1",serverAddress.port,thePassword,(int)strlen(thePassword));
}
RakSleep(100);
}
if(!server->IsBanned("127.0.0.1"))
{
if (isVerbose)
DebugTools::ShowError("IsBanned does not show localhost as banned\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 6;
}
if (CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true))
{
if (isVerbose)
DebugTools::ShowError("Client was banned but connected anyways\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 4;
}
if (isVerbose)
printf("Testing if connection is accepted after ban removal by ClearBanList\n");
server->ClearBanList();
if(server->IsBanned("127.0.0.1"))
{
if (isVerbose)
DebugTools::ShowError("Localhost was not unbanned\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 7;
}
entryTime=GetTimeMS();
while(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true)&&GetTimeMS()-entryTime<5000)
{
if(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,true,true,true))
{
client->Connect("127.0.0.1",serverAddress.port,thePassword,(int)strlen(thePassword));
}
RakSleep(100);
}
if (!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true))
{
if (isVerbose)
DebugTools::ShowError("Client failed to connect after banlist removal with clear function\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 9;
}
while(CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,true,true,true))//disconnect client
{
client->CloseConnection (serverAddress,true,0,LOW_PRIORITY);
}
/*//Disabled because of statistics changes
if (isVerbose)
printf("Testing InitializeSecurity on server\n");
//-----------------------------
// RSACrypt is a using namespace RakNet;
class that handles RSA encryption/decryption internally
RSACrypt rsacrypt;
uint32_t e;
uint32_t modulus[RAKNET_RSA_FACTOR_LIMBS];
uint32_t p[RAKNET_RSA_FACTOR_LIMBS/2],q[RAKNET_RSA_FACTOR_LIMBS/2];
printf("Generating %i bit key. This will take a while...\n", RAKNET_RSA_FACTOR_LIMBS*32);
rsacrypt.generatePrivateKey(RAKNET_RSA_FACTOR_LIMBS);
e=rsacrypt.getPublicExponent();
rsacrypt.getPublicModulus(modulus);
rsacrypt.getPrivateP(p);
rsacrypt.getPrivateQ(q);
RakPeerInterface::DestroyInstance(server);
server=RakPeerInterface::GetInstance();
server->InitializeSecurity(0,0,(char*)p, (char*)q);
server->Startup(1,30,&SocketDescriptor(60000,0),1);
server->SetMaximumIncomingConnections(1);
server->SetIncomingPassword(thePassword,strlen(thePassword));
if (isVerbose)
printf("Testing if client connects encrypted\n");
entryTime=GetTimeMS();
while(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true)&&GetTimeMS()-entryTime<5000)
{
if(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,true,true,true))
{
client->Connect("127.0.0.1",serverAddress.port,thePassword,strlen(thePassword));
}
RakSleep(100);
}
char str2[]="AAAAAAAAAA";
str2[0]=(char)(ID_USER_PACKET_ENUM+1);
client->Send(str2,(int) strlen(str2)+1, HIGH_PRIORITY, RELIABLE_ORDERED ,0, UNASSIGNED_SYSTEM_ADDRESS, true);
client->Send(str2,(int) strlen(str2)+1, HIGH_PRIORITY, RELIABLE_ORDERED ,0, UNASSIGNED_SYSTEM_ADDRESS, true);
Packet *packet;
entryTime=GetTimeMS();
while(GetTimeMS()-entryTime<1000)
{
for (packet=server->Receive(); packet;server->DeallocatePacket(packet), packet=server->Receive())
{
}
}
RakNetStatistics *rss;
rss=client->GetStatistics(serverAddress);
if (rss->encryptionBitsSent<=0)//If we did connect encrypted we should see encryptionBitsSent
{
if (isVerbose)
DebugTools::ShowError("Client did not connect encrypted\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 10;
}
while(CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,true,true,true))//disconnect client
{
client->CloseConnection (serverAddress,true,0,LOW_PRIORITY);
}
//Destroy to clear statistics
RakPeerInterface::DestroyInstance(client);
client=RakPeerInterface::GetInstance();
client->Startup(1,30,&SocketDescriptor(),1);
if (isVerbose)
printf("Testing AddToSecurityExceptionList client should connect without encryption\n");
server->AddToSecurityExceptionList("127.0.0.1");
if (!server->IsInSecurityExceptionList("127.0.0.1"))
{
if (isVerbose)
DebugTools::ShowError("IsInSecurityExceptionList does not register localhost addition\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 12;
}
entryTime=GetTimeMS();
while(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true)&&GetTimeMS()-entryTime<5000)
{
if(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,true,true,true))
{
client->Connect("127.0.0.1",serverAddress.port,thePassword,strlen(thePassword));
}
RakSleep(100);
}
str2[0]=(char)(ID_USER_PACKET_ENUM+1);
client->Send(str2,(int) strlen(str2)+1, HIGH_PRIORITY, RELIABLE_ORDERED ,0, UNASSIGNED_SYSTEM_ADDRESS, true);
client->Send(str2,(int) strlen(str2)+1, HIGH_PRIORITY, RELIABLE_ORDERED ,0, UNASSIGNED_SYSTEM_ADDRESS, true);
// Packet *packet;
entryTime=GetTimeMS();
while(GetTimeMS()-entryTime<1000)
{
for (packet=server->Receive(); packet;server->DeallocatePacket(packet), packet=server->Receive())
{
}
}
rss=client->GetStatistics(serverAddress);
if (rss->encryptionBitsSent>0)//If we did connect encrypted we should see encryptionBitsSent
{
if (isVerbose)
DebugTools::ShowError("Client connected encrypted but shouldn't have\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 11;
}
if (isVerbose)
printf("Testing RemoveFromSecurityExceptionList\n");
while(CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,true,true,true))//disconnect client
{
client->CloseConnection (serverAddress,true,0,LOW_PRIORITY);
}
server->RemoveFromSecurityExceptionList("127.0.0.1");
if (isVerbose)
printf("Testing if client connects encrypted\n");
entryTime=GetTimeMS();
while(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true)&&GetTimeMS()-entryTime<5000)
{
if(!CommonFunctions::ConnectionStateMatchesOptions (client,serverAddress,true,true,true,true))
{
client->Connect("127.0.0.1",serverAddress.port,thePassword,strlen(thePassword));
}
RakSleep(100);
}
str2[0]=(char)(ID_USER_PACKET_ENUM+1);
client->Send(str2,(int) strlen(str2)+1, HIGH_PRIORITY, RELIABLE_ORDERED ,0, UNASSIGNED_SYSTEM_ADDRESS, true);
client->Send(str2,(int) strlen(str2)+1, HIGH_PRIORITY, RELIABLE_ORDERED ,0, UNASSIGNED_SYSTEM_ADDRESS, true);
entryTime=GetTimeMS();
while(GetTimeMS()-entryTime<1000)
{
for (packet=server->Receive(); packet;server->DeallocatePacket(packet), packet=server->Receive())
{
}
}
rss=client->GetStatistics(serverAddress);
if (rss->encryptionBitsSent<=0)//If we did connect encrypted we should see encryptionBitsSent
{
if (isVerbose)
DebugTools::ShowError("Client did not connect encrypted\n",!noPauses && isVerbose,__LINE__,__FILE__);
return 10;
}
*/
return 0;
}
RakString SecurityFunctionsTest::GetTestName()
{
return "SecurityFunctionsTest";
}
RakString SecurityFunctionsTest::ErrorCodeToString(int errorCode)
{
switch (errorCode)
{
case 0:
return "No error";
break;
case 1:
return "Client connected with no password";
break;
case 2:
return "Client connected with wrong password";
break;
case 3:
return "Client failed to connect with correct password";
break;
case 4:
return "Client was banned but connected anyways";
break;
case 5:
return "GetIncomingPassword returned wrong password";
break;
case 6:
return "IsBanned does not show localhost as banned";
break;
case 7:
return "Localhost was not unbanned";
break;
case 8:
return "Client failed to connect after banlist removal";
break;
case 9:
return "Client failed to connect after banlist removal with clear function";
break;
case 10:
return "Client did not connect encrypted";
break;
case 11:
return "Client connected encrypted but shouldn't have";
break;
case 12:
return "IsInSecurityExceptionList does not register localhost addition";
break;
default:
return "Undefined Error";
}
}
SecurityFunctionsTest::SecurityFunctionsTest(void)
{
}
SecurityFunctionsTest::~SecurityFunctionsTest(void)
{
}
void SecurityFunctionsTest::DestroyPeers()
{
RakPeerInterface::DestroyInstance(client);
RakPeerInterface::DestroyInstance(server);
}

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "TestInterface.h"
#include "RakString.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include "RakPeer.h"
#include "RakSleep.h"
#include "RakNetTime.h"
#include "GetTime.h"
#include "DebugTools.h"
#include "CommonFunctions.h"
using namespace RakNet;
class SecurityFunctionsTest : public TestInterface
{
public:
SecurityFunctionsTest(void);
~SecurityFunctionsTest(void);
int RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses);//should return 0 if no error, or the error number
RakString GetTestName();
RakString ErrorCodeToString(int errorCode);
void DestroyPeers();
private:
RakPeerInterface *server,*client;
};

View File

@ -0,0 +1,348 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "SystemAddressAndGuidTest.h"
/*
Description:
Tests:
virtual unsigned short RakPeerInterface::NumberOfConnections ( void ) const
virtual void RakPeerInterface::GetSystemList ( DataStructures::List< SystemAddress > & addresses, DataStructures::List< RakNetGUID > & guids )
virtual bool RakPeerInterface::IsActive ( void ) const
virtual SystemAddress RakPeerInterface::GetSystemAddressFromIndex ( int index )
virtual SystemAddress RakPeerInterface::GetSystemAddressFromGuid ( const RakNetGUID input ) const
virtual const RakNetGUID& RakPeerInterface::GetGuidFromSystemAddress ( const SystemAddress input ) const
pure virtual virtual RakNetGUID RakPeerInterface::GetGUIDFromIndex ( int index )
virtual SystemAddress RakPeerInterface::GetExternalID ( const SystemAddress target ) const
Success conditions:
All functions pass test.
Failure conditions:
Any function fails.
Client was active but shouldn't be yet
Client was not active but should be
Could not connect the client
Mismatch between guidList size and systemList size
NumberOfConnections problem
SystemList problem with GetSystemList
Both SystemList and Number of connections have problems and report different results
Both SystemList and Number of connections have problems and report same results
Undefined Error
System address from list is wrong.
Guid from list is wrong
GetSystemAddressFromIndex failed to return correct values
GetSystemAddressFromGuid failed to return correct values
GetGuidFromSystemAddress failed to return correct values
GetGUIDFromIndex failed to return correct values
GetExternalID failed to return correct values
RakPeerInterface Functions used, tested indirectly by its use. List may not be complete:
Startup
SetMaximumIncomingConnections
Receive
DeallocatePacket
Send
IsConnected
RakPeerInterface Functions Explicitly Tested:
NumberOfConnections
GetSystemList
IsActive
GetSystemAddressFromIndex
GetSystemAddressFromGuid
GetGuidFromSystemAddress
GetGUIDFromIndex
GetExternalID
*/
int SystemAddressAndGuidTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
{
RakPeerInterface *server,*client;
destroyList.Clear(false,_FILE_AND_LINE_);
printf("Testing IsActive\n");
client=RakPeerInterface::GetInstance();
destroyList.Push( client,_FILE_AND_LINE_);
if (client->IsActive())
{
if (isVerbose)
DebugTools::ShowError(errorList[1-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 1;
}
client->Startup(1,&SocketDescriptor(60001,0),1);
if (!client->IsActive())
{
if (isVerbose)
DebugTools::ShowError(errorList[2-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 2;
}
//Passed by reference for initializations
TestHelpers::StandardServerPrep(server,destroyList);
if (!TestHelpers::WaitAndConnectTwoPeersLocally(client,server,5000))
{
if (isVerbose)
DebugTools::ShowError(errorList[3-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 3;
}
DataStructures::List< SystemAddress > systemList;
DataStructures::List< RakNetGUID > guidList;
printf("Test GetSystemList and NumberOfConnections\n");
client->GetSystemList(systemList,guidList);//Get connectionlist
int len=systemList.Size();
int len2=guidList.Size();
int conNum=client->NumberOfConnections();
printf("Test if systemList size matches guidList size \n");
if (len2!=len)
{
printf("system list size is %i and guid size is %i ",len,len2);
if (isVerbose)
DebugTools::ShowError(errorList[4-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 4;
}
printf("Test returned list size against NumberofConnections return value\n");
if (conNum!=len)
{
if (conNum==1||len==1)
{
if (conNum!=1)
{
printf("system list size is %i and NumberOfConnections return is %i ",len,conNum);
if (isVerbose)
DebugTools::ShowError(errorList[5-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 5;
}
if (len!=1)
{
printf("system list size is %i and NumberOfConnections return is %i ",len,conNum);
if (isVerbose)
DebugTools::ShowError(errorList[6-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 6;
}
}
else
{
printf("system list size is %i and NumberOfConnections return is %i ",len,conNum);
if (isVerbose)
DebugTools::ShowError(errorList[7-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 7;
}
}
else
{
if (conNum!=1)
{
printf("system list size is %i and NumberOfConnections return is %i ",len,conNum);
if (isVerbose)
DebugTools::ShowError(errorList[8-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 8;
}
}
printf("Test GetSystemListValues of the system and guid list\n");
SystemAddress serverAddress;
serverAddress.SetBinaryAddress("127.0.0.1");
serverAddress.port=60000;
if (!compareSystemAddresses(systemList[0],serverAddress))
{
if (isVerbose)
DebugTools::ShowError(errorList[10-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 10;
}
RakNetGUID serverGuid=server->GetGuidFromSystemAddress(UNASSIGNED_SYSTEM_ADDRESS);
if (guidList[0]!=serverGuid)
{
if (isVerbose)
DebugTools::ShowError(errorList[11-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 11;
}
printf("Test GetSystemAddressFromIndex\n");
if (!compareSystemAddresses(client->GetSystemAddressFromIndex(0),serverAddress))
{
if (isVerbose)
DebugTools::ShowError(errorList[12-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 12;
}
printf("Test GetSystemAddressFromGuid\n");
if (!compareSystemAddresses(client->GetSystemAddressFromGuid(serverGuid),serverAddress))
{
if (isVerbose)
DebugTools::ShowError(errorList[13-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 13;
}
printf("Test GetGuidFromSystemAddress\n");
if (client->GetGuidFromSystemAddress(serverAddress)!=serverGuid)
{
if (isVerbose)
DebugTools::ShowError(errorList[14-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 14;
}
printf("Test GetGUIDFromIndex\n");
if (client->GetGUIDFromIndex(0)!=serverGuid)
{
if (isVerbose)
DebugTools::ShowError(errorList[15-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 15;
}
SystemAddress clientAddress;
clientAddress.SetBinaryAddress("127.0.0.1");
clientAddress.port=60001;
printf("Test GetExternalID, automatic testing is not only required for this\nbecause of it's nature\nShould be supplemented by internet tests\n");
if (!compareSystemAddresses(client->GetExternalID(serverAddress),clientAddress))
{
if (isVerbose)
DebugTools::ShowError(errorList[16-1],!noPauses && isVerbose,__LINE__,__FILE__);
return 16;
}
return 0;
}
RakString SystemAddressAndGuidTest::GetTestName()
{
return "SystemAddressAndGuidTest";
}
RakString SystemAddressAndGuidTest::ErrorCodeToString(int errorCode)
{
if (errorCode>0&&(unsigned int)errorCode<=errorList.Size())
{
return errorList[errorCode-1];
}
else
{
return "Undefined Error";
}
}
bool SystemAddressAndGuidTest::compareSystemAddresses(SystemAddress ad1,SystemAddress ad2)
{
if (ad1.binaryAddress!=ad2.binaryAddress||ad1.port!=ad2.port)
{
return 0;
}
return 1;
}
SystemAddressAndGuidTest::SystemAddressAndGuidTest(void)
{
errorList.Push("Client was active but shouldn't be yet",_FILE_AND_LINE_);
errorList.Push("Client was not active but should be",_FILE_AND_LINE_);
errorList.Push("Could not connect the client",_FILE_AND_LINE_);
errorList.Push("Mismatch between guidList size and systemList size ",_FILE_AND_LINE_);
errorList.Push("NumberOfConnections problem",_FILE_AND_LINE_);
errorList.Push("SystemList problem with GetSystemList",_FILE_AND_LINE_);
errorList.Push("Both SystemList and Number of connections have problems and report different results",_FILE_AND_LINE_);
errorList.Push("Both SystemList and Number of connections have problems and report same results",_FILE_AND_LINE_);
errorList.Push("Undefined Error",_FILE_AND_LINE_);
errorList.Push("System address from list is wrong.",_FILE_AND_LINE_);
errorList.Push("Guid from list is wrong",_FILE_AND_LINE_);
errorList.Push("GetSystemAddressFromIndex failed to return correct values",_FILE_AND_LINE_);
errorList.Push("GetSystemAddressFromGuid failed to return correct values",_FILE_AND_LINE_);
errorList.Push("GetGuidFromSystemAddress failed to return correct values",_FILE_AND_LINE_);
errorList.Push("GetGUIDFromIndex failed to return correct values",_FILE_AND_LINE_);
errorList.Push("GetExternalID failed to return correct values",_FILE_AND_LINE_);
}
SystemAddressAndGuidTest::~SystemAddressAndGuidTest(void)
{
}
void SystemAddressAndGuidTest::DestroyPeers()
{
int theSize=destroyList.Size();
for (int i=0; i < theSize; i++)
RakPeerInterface::DestroyInstance(destroyList[i]);
}

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "TestInterface.h"
#include "RakString.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include "RakPeer.h"
#include "RakSleep.h"
#include "RakNetTime.h"
#include "GetTime.h"
#include "DebugTools.h"
#include "CommonFunctions.h"
#include "TestHelpers.h"
using namespace RakNet;
class SystemAddressAndGuidTest : public TestInterface
{
public:
SystemAddressAndGuidTest(void);
~SystemAddressAndGuidTest(void);
int RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses);//should return 0 if no error, or the error number
RakString GetTestName();
RakString ErrorCodeToString(int errorCode);
void DestroyPeers();
protected:
bool compareSystemAddresses(SystemAddress ad1,SystemAddress ad2);//true if same;
private:
DataStructures::List <RakString> errorList;
DataStructures::List <RakPeerInterface *> destroyList;
};

View File

@ -0,0 +1,132 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "TestHelpers.h"
TestHelpers::TestHelpers(void)
{
}
TestHelpers::~TestHelpers(void)
{
}
void TestHelpers::StandardServerPrep(RakPeerInterface *&server)
{
server=RakPeerInterface::GetInstance();
server->Startup(1,&SocketDescriptor(60000,0),1);
server->SetMaximumIncomingConnections(1);
}
void TestHelpers::StandardClientPrep(RakPeerInterface *&client)
{
client=RakPeerInterface::GetInstance();
client->Startup(1,&SocketDescriptor(),1);
}
void TestHelpers::StandardServerPrep(RakPeerInterface *&server,DataStructures::List <RakPeerInterface *> &destroyList)
{
StandardServerPrep(server);
destroyList.Push(server,_FILE_AND_LINE_);
}
void TestHelpers::StandardClientPrep(RakPeerInterface *&client,DataStructures::List <RakPeerInterface *> &destroyList)
{
StandardClientPrep(client);
destroyList.Push(client,_FILE_AND_LINE_);
}
//returns false if not connected
bool TestHelpers::WaitAndConnectTwoPeersLocally(RakPeerInterface *connector,RakPeerInterface *connectee,int millisecondsToWait)
{
SystemAddress connecteeAdd=connectee->GetInternalID();
return CommonFunctions::WaitAndConnect(connector,"127.0.0.1",connecteeAdd.port,millisecondsToWait);
}
//returns false if connect fails
bool TestHelpers::ConnectTwoPeersLocally(RakPeerInterface *connector,RakPeerInterface *connectee)
{
SystemAddress connecteeAdd=connectee->GetInternalID();
return connector->Connect("127.0.0.1",connecteeAdd.port,0,0);
}
bool TestHelpers::BroadCastTestPacket(RakPeerInterface *sender,PacketReliability rel,PacketPriority pr,int typeNum)//returns send return value
{
char str2[]="AAAAAAAAAA";
str2[0]=typeNum;
return sender->Send(str2,(int) strlen(str2)+1, pr, rel ,0, UNASSIGNED_SYSTEM_ADDRESS, true)>0;
}
bool TestHelpers::SendTestPacketDirected(RakPeerInterface *sender,char * ip,int port,PacketReliability rel,PacketPriority pr,int typeNum)//returns send return value
{
SystemAddress recAddress;
recAddress.SetBinaryAddress(ip);
recAddress.port=port;
char str2[]="AAAAAAAAAA";
str2[0]=typeNum;
return sender->Send(str2,(int) strlen(str2)+1, pr, rel ,0, recAddress, false)>0;
}
bool TestHelpers::WaitForTestPacket(RakPeerInterface *reciever,int millisecondsToWait)
{
RakTimer timer(millisecondsToWait);
Packet *packet;
while(!timer.IsExpired())
{
for (packet=reciever->Receive(); packet;reciever->DeallocatePacket(packet), packet=reciever->Receive())
{
if (packet->data[0]==ID_USER_PACKET_ENUM+1)
{
reciever->DeallocatePacket(packet);
return true;
}
}
}
return false;
}
void RecieveForXTime(RakPeerInterface *reciever,int millisecondsToWait)
{
RakTimer timer(millisecondsToWait);
Packet *packet;
while(!timer.IsExpired())
{
for (packet=reciever->Receive(); packet;reciever->DeallocatePacket(packet), packet=reciever->Receive())
{
}
}
}

View File

@ -0,0 +1,45 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "RakString.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include "RakPeer.h"
#include "RakSleep.h"
#include "DebugTools.h"
#include "CommonFunctions.h"
#include "RakTimer.h"
using namespace RakNet;
class TestHelpers
{
public:
TestHelpers(void);
~TestHelpers(void);
static void StandardServerPrep(RakPeerInterface *&server);
static void StandardClientPrep(RakPeerInterface *&client);
static void StandardServerPrep(RakPeerInterface *&server,DataStructures::List <RakPeerInterface *> &destroyList);
static void StandardClientPrep(RakPeerInterface *&client,DataStructures::List <RakPeerInterface *> &destroyList);
static bool WaitAndConnectTwoPeersLocally(RakPeerInterface *connector,RakPeerInterface *connectee,int millisecondsToWait);
static bool ConnectTwoPeersLocally(RakPeerInterface *connector,RakPeerInterface *connectee);
///static bool BroadCastTestPacket(RakPeerInterface *sender);
static bool BroadCastTestPacket(RakPeerInterface *sender,PacketReliability rel=RELIABLE_ORDERED,PacketPriority pr=HIGH_PRIORITY,int typeNum=ID_USER_PACKET_ENUM+1);
static bool WaitForTestPacket(RakPeerInterface *reciever,int millisecondsToWait);
static void RecieveForXTime(RakPeerInterface *reciever,int millisecondsToWait);
static bool SendTestPacketDirected(RakPeerInterface *sender,char * ip,int port,PacketReliability rel=RELIABLE_ORDERED,PacketPriority pr=HIGH_PRIORITY,int typeNum=ID_USER_PACKET_ENUM+1);
};

View File

@ -0,0 +1,19 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "TestInterface.h"
TestInterface::TestInterface(void)
{
}
TestInterface::~TestInterface(void)
{
}

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#pragma once
#include "RakString.h"
#include "DS_List.h"
using namespace RakNet;
class TestInterface
{
public:
TestInterface();
virtual ~TestInterface();
virtual int RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)=0;//should return 0 if no error, or the error number
virtual RakString GetTestName()=0;
virtual RakString ErrorCodeToString(int errorCode)=0;
virtual void DestroyPeers()=0;
};

168
Samples/Tests/Tests.cpp Normal file
View File

@ -0,0 +1,168 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "IncludeAllTests.h"
#include "RakString.h"
#include "DS_List.h"
#include "Gets.h"
using namespace RakNet;
/*
The TestInterface used in this was made to be able to be flexible
when adding new test cases. While I do not use the paramslist, it is available.
*/
int main(int argc, char *argv[])
{
int returnVal;
char str[512];
int numTests=0;
int testListSize=0;
int passedTests=0;
DataStructures::List <TestInterface*> testList;//Pointer list
DataStructures::List <int> testResultList;//A list of pass and/or fail and the error codes
DataStructures::List <RakString> testsToRun;//A list of tests to run
DataStructures::List <int> testsToRunIndexes;//A list of tests to run by index
//Add all the tests to the test list
testList.Push(new EightPeerTest(),_FILE_AND_LINE_);
testList.Push(new MaximumConnectTest(),_FILE_AND_LINE_);
testList.Push(new PeerConnectDisconnectWithCancelPendingTest(),_FILE_AND_LINE_);
testList.Push(new PeerConnectDisconnectTest(),_FILE_AND_LINE_);
testList.Push(new ManyClientsOneServerBlockingTest(),_FILE_AND_LINE_);
testList.Push(new ManyClientsOneServerNonBlockingTest(),_FILE_AND_LINE_);
testList.Push(new ManyClientsOneServerDeallocateBlockingTest(),_FILE_AND_LINE_);
testList.Push(new ReliableOrderedConvertedTest(),_FILE_AND_LINE_);
testList.Push(new DroppedConnectionConvertTest(),_FILE_AND_LINE_);
testList.Push(new ComprehensiveConvertTest(),_FILE_AND_LINE_);
testList.Push(new CrossConnectionConvertTest(),_FILE_AND_LINE_);
testList.Push(new PingTestsTest(),_FILE_AND_LINE_);
testList.Push(new OfflineMessagesConvertTest(),_FILE_AND_LINE_);
testList.Push(new LocalIsConnectedTest(),_FILE_AND_LINE_);
testList.Push(new SecurityFunctionsTest(),_FILE_AND_LINE_);
testList.Push(new ConnectWithSocketTest(),_FILE_AND_LINE_);
testList.Push(new SystemAddressAndGuidTest(),_FILE_AND_LINE_);
testList.Push(new PacketAndLowLevelTestsTest(),_FILE_AND_LINE_);
testList.Push(new MiscellaneousTestsTest(),_FILE_AND_LINE_);
testListSize=testList.Size();
bool isVerbose=true;
bool disallowTestToPause=false;
DataStructures::List<RakString> testcases;
if (argc>1)//we have command line arguments
{
for (int p=1;p<argc;p++)
{
testsToRun.Push(argv[p],_FILE_AND_LINE_);
}
}
DataStructures::List<RakString> noParamsList;
if (testsToRun.Size()==0&&testsToRunIndexes.Size()==0)
{
numTests=testListSize;
for(int i=0;i<testListSize;i++)
{
printf("\n\nRunning test %s.\n\n",testList[i]->GetTestName().C_String());
returnVal=testList[i]->RunTest(noParamsList,isVerbose,disallowTestToPause);
testList[i]->DestroyPeers();
if (returnVal==0)
{passedTests++;}
else
{
printf("Test %s returned with error %s",testList[i]->GetTestName().C_String(),testList[i]->ErrorCodeToString(returnVal).C_String());
}
}
}
if (testsToRun.Size()!=0)//If string arguments convert to indexes.Suggestion: if speed becoms an issue keep a sorted list and binary search it
{
int TestsToRunSize= testsToRun.Size();
RakString testName;
for(int i=0;i<TestsToRunSize;i++)
{
testName=testsToRun[i];
for(int j=0;j<testListSize;j++)
{
if (testList[j]->GetTestName().StrICmp(testName)==0)
{
testsToRunIndexes.Push(j,_FILE_AND_LINE_);
}
}
}
}
if (testsToRunIndexes.Size()!=0)//Run selected indexes
{
numTests=testsToRunIndexes.Size();
for(int i=0;i<numTests;i++)
{
if (testsToRunIndexes[i]<testListSize)
{
printf("\n\nRunning test %s.\n\n",testList[testsToRunIndexes[i]]->GetTestName().C_String());
returnVal=testList[testsToRunIndexes[i]]->RunTest(noParamsList,isVerbose,disallowTestToPause);
testList[i]->DestroyPeers();
if (returnVal==0)
{passedTests++;}
else
{
printf("Test %s returned with error %s",testList[testsToRunIndexes[i]]->GetTestName().C_String(),testList[testsToRunIndexes[i]]->ErrorCodeToString(returnVal).C_String());
}
}
}
}
if (numTests>0)
{
printf("\nPassed %i out of %i tests.\n",passedTests,numTests);
}
printf("Press enter to continue \n");
Gets(str, sizeof(str));
//Cleanup
int len=testList.Size();
for (int i=0;i<len;i++)
{
delete testList[i];
}
testList.Clear(false,_FILE_AND_LINE_);
return 0;
}

155
Samples/Tests/Tests.vcxproj Normal file
View File

@ -0,0 +1,155 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{8DD46676-F5C2-48D2-B08D-2D6D51637A73}</ProjectGuid>
<RootNamespace>Tests</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>NotSet</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>./../../Source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>./../../Source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalOptions>/NODEFAULTLIB:LIBCMT %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="CommonFunctions.cpp" />
<ClCompile Include="ComprehensiveConvertTest.cpp" />
<ClCompile Include="ConnectWithSocketTest.cpp" />
<ClCompile Include="CrossConnectionConvertTest.cpp" />
<ClCompile Include="DebugTools.cpp" />
<ClCompile Include="DroppedConnectionConvertTest.cpp" />
<ClCompile Include="EightPeerTest.cpp" />
<ClCompile Include="LocalIsConnectedTest.cpp" />
<ClCompile Include="ManyClientsOneServerBlockingTest.cpp" />
<ClCompile Include="ManyClientsOneServerDeallocateBlockingTest.cpp" />
<ClCompile Include="ManyClientsOneServerNonBlockingTest.cpp" />
<ClCompile Include="MaximumConnectTest.cpp" />
<ClCompile Include="MiscellaneousTestsTest.cpp" />
<ClCompile Include="OfflineMessagesConvertTest.cpp" />
<ClCompile Include="PacketAndLowLevelTestsTest.cpp" />
<ClCompile Include="PacketChangerPlugin.cpp" />
<ClCompile Include="PacketDropPlugin.cpp" />
<ClCompile Include="PeerConnectDisconnectTest.cpp" />
<ClCompile Include="PeerConnectDisconnectWithCancelPendingTest.cpp" />
<ClCompile Include="PingTestsTest.cpp" />
<ClCompile Include="RakTimer.cpp" />
<ClCompile Include="ReliableOrderedConvertedTest.cpp" />
<ClCompile Include="SecurityFunctionsTest.cpp" />
<ClCompile Include="SystemAddressAndGuidTest.cpp" />
<ClCompile Include="TestHelpers.cpp" />
<ClCompile Include="TestInterface.cpp" />
<ClCompile Include="Tests.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="CommonFunctions.h" />
<ClInclude Include="ComprehensiveConvertTest.h" />
<ClInclude Include="ConnectWithSocketTest.h" />
<ClInclude Include="CrossConnectionConvertTest.h" />
<ClInclude Include="DebugTools.h" />
<ClInclude Include="DroppedConnectionConvertTest.h" />
<ClInclude Include="EightPeerTest.h" />
<ClInclude Include="IncludeAllTests.h" />
<ClInclude Include="LocalIsConnectedTest.h" />
<ClInclude Include="ManyClientsOneServerBlockingTest.h" />
<ClInclude Include="ManyClientsOneServerDeallocateBlockingTest.h" />
<ClInclude Include="ManyClientsOneServerNonBlockingTest.h" />
<ClInclude Include="MaximumConnectTest.h" />
<ClInclude Include="MiscellaneousTestsTest.h" />
<ClInclude Include="OfflineMessagesConvertTest.h" />
<ClInclude Include="PacketAndLowLevelTestsTest.h" />
<ClInclude Include="PacketChangerPlugin.h" />
<ClInclude Include="PacketDropPlugin.h" />
<ClInclude Include="PeerConnectDisconnectTest.h" />
<ClInclude Include="PeerConnectDisconnectWithCancelPendingTest.h" />
<ClInclude Include="PingTestsTest.h" />
<ClInclude Include="RakTimer.h" />
<ClInclude Include="ReliableOrderedConvertedTest.h" />
<ClInclude Include="RouterInterfaceTester.h" />
<ClInclude Include="SecurityFunctionsTest.h" />
<ClInclude Include="SystemAddressAndGuidTest.h" />
<ClInclude Include="TestHelpers.h" />
<ClInclude Include="TestInterface.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,186 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="CommonFunctions.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ComprehensiveConvertTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ConnectWithSocketTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="CrossConnectionConvertTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DebugTools.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DroppedConnectionConvertTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="EightPeerTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="LocalIsConnectedTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ManyClientsOneServerBlockingTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ManyClientsOneServerDeallocateBlockingTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ManyClientsOneServerNonBlockingTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MaximumConnectTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MiscellaneousTestsTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="OfflineMessagesConvertTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PacketAndLowLevelTestsTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PacketChangerPlugin.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PacketDropPlugin.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PeerConnectDisconnectTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PeerConnectDisconnectWithCancelPendingTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PingTestsTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="RakTimer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ReliableOrderedConvertedTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SecurityFunctionsTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SystemAddressAndGuidTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TestHelpers.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TestInterface.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Tests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CommonFunctions.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ComprehensiveConvertTest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ConnectWithSocketTest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="CrossConnectionConvertTest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DebugTools.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DroppedConnectionConvertTest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="EightPeerTest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="IncludeAllTests.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="LocalIsConnectedTest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ManyClientsOneServerBlockingTest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ManyClientsOneServerDeallocateBlockingTest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ManyClientsOneServerNonBlockingTest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MaximumConnectTest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MiscellaneousTestsTest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="OfflineMessagesConvertTest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PacketAndLowLevelTestsTest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PacketChangerPlugin.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PacketDropPlugin.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PeerConnectDisconnectTest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PeerConnectDisconnectWithCancelPendingTest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PingTestsTest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RakTimer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ReliableOrderedConvertedTest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RouterInterfaceTester.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SecurityFunctionsTest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SystemAddressAndGuidTest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TestHelpers.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TestInterface.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>