forked from facebookarchive/RakNet
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathConnectWithSocketTest.cpp
207 lines (141 loc) · 5.44 KB
/
ConnectWithSocketTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS 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: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.GetPort(),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.GetPort(),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]);
}