1 #include "SystemAddressAndGuidTest.h"
2
3 /*
4 Description:
5 Tests:
6 virtual unsigned short RakPeerInterface::NumberOfConnections ( void ) const
7 virtual void RakPeerInterface::GetSystemList ( DataStructures::List< SystemAddress > & addresses, DataStructures::List< RakNetGUID > & guids )
8 virtual bool RakPeerInterface::IsActive ( void ) const
9 virtual SystemAddress RakPeerInterface::GetSystemAddressFromIndex ( int index )
10 virtual SystemAddress RakPeerInterface::GetSystemAddressFromGuid ( const RakNetGUID input ) const
11 virtual const RakNetGUID& RakPeerInterface::GetGuidFromSystemAddress ( const SystemAddress input ) const
12 pure virtual virtual RakNetGUID RakPeerInterface::GetGUIDFromIndex ( int index )
13 virtual SystemAddress RakPeerInterface::GetExternalID ( const SystemAddress target ) const
14
15 Success conditions:
16 All functions pass test.
17
18 Failure conditions:
19 Any function fails.
20
21 Client was active but shouldn't be yet
22 Client was not active but should be
23 Could not connect the client
24 Mismatch between guidList size and systemList size
25 NumberOfConnections problem
26 SystemList problem with GetSystemList
27 Both SystemList and Number of connections have problems and report different results
28 Both SystemList and Number of connections have problems and report same results
29 Undefined Error
30 System address from list is wrong.
31 Guid from list is wrong
32 GetSystemAddressFromIndex failed to return correct values
33 GetSystemAddressFromGuid failed to return correct values
34 GetGuidFromSystemAddress failed to return correct values
35 GetGUIDFromIndex failed to return correct values
36 GetExternalID failed to return correct values
37
38 RakPeerInterface Functions used, tested indirectly by its use. List may not be complete:
39 Startup
40 SetMaximumIncomingConnections
41 Receive
42 DeallocatePacket
43 Send
44 IsConnected
45
46 RakPeerInterface Functions Explicitly Tested:
47
48 NumberOfConnections
49 GetSystemList
50 IsActive
51 GetSystemAddressFromIndex
52 GetSystemAddressFromGuid
53 GetGuidFromSystemAddress
54 GetGUIDFromIndex
55 GetExternalID
56
57 */
RunTest(DataStructures::List<RakNet::RakString> params,bool isVerbose,bool noPauses)58 int SystemAddressAndGuidTest::RunTest(DataStructures::List<RakNet::RakString> params,bool isVerbose,bool noPauses)
59 {
60
61 RakPeerInterface *server,*client;
62 destroyList.Clear(false,__FILE__,__LINE__);
63
64 printf("Testing IsActive\n");
65 client=RakNetworkFactory::GetRakPeerInterface();
66 destroyList.Push( client,__FILE__,__LINE__);
67 if (client->IsActive())
68 {
69
70 if (isVerbose)
71 DebugTools::ShowError(errorList[1-1],!noPauses && isVerbose,__LINE__,__FILE__);
72
73 return 1;
74 }
75
76 client->Startup(1,30,&SocketDescriptor(60001,0),1);
77
78 if (!client->IsActive())
79 {
80
81 if (isVerbose)
82 DebugTools::ShowError(errorList[2-1],!noPauses && isVerbose,__LINE__,__FILE__);
83
84 return 2;
85 }
86
87 //Passed by reference for initializations
88 TestHelpers::StandardServerPrep(server,destroyList);
89
90 if (!TestHelpers::WaitAndConnectTwoPeersLocally(client,server,5000))
91 {
92
93 if (isVerbose)
94 DebugTools::ShowError(errorList[3-1],!noPauses && isVerbose,__LINE__,__FILE__);
95
96 return 3;
97 }
98
99 DataStructures::List< SystemAddress > systemList;
100 DataStructures::List< RakNetGUID > guidList;
101
102 printf("Test GetSystemList and NumberOfConnections\n");
103
104 client->GetSystemList(systemList,guidList);//Get connectionlist
105 int len=systemList.Size();
106 int len2=guidList.Size();
107
108 int conNum=client->NumberOfConnections();
109
110 printf("Test if systemList size matches guidList size \n");
111
112 if (len2!=len)
113 {
114
115 printf("system list size is %i and guid size is %i ",len,len2);
116
117 if (isVerbose)
118 DebugTools::ShowError(errorList[4-1],!noPauses && isVerbose,__LINE__,__FILE__);
119
120 return 4;
121 }
122
123 printf("Test returned list size against NumberofConnections return value\n");
124 if (conNum!=len)
125 {
126
127 if (conNum==1||len==1)
128 {
129
130 if (conNum!=1)
131 {
132 printf("system list size is %i and NumberOfConnections return is %i ",len,conNum);
133
134 if (isVerbose)
135 DebugTools::ShowError(errorList[5-1],!noPauses && isVerbose,__LINE__,__FILE__);
136
137 return 5;
138
139 }
140
141 if (len!=1)
142 {
143
144 printf("system list size is %i and NumberOfConnections return is %i ",len,conNum);
145
146 if (isVerbose)
147 DebugTools::ShowError(errorList[6-1],!noPauses && isVerbose,__LINE__,__FILE__);
148
149 return 6;
150
151 }
152 }
153 else
154 {
155 printf("system list size is %i and NumberOfConnections return is %i ",len,conNum);
156
157 if (isVerbose)
158 DebugTools::ShowError(errorList[7-1],!noPauses && isVerbose,__LINE__,__FILE__);
159
160 return 7;
161
162 }
163
164 }
165 else
166 {
167
168 if (conNum!=1)
169 {
170 printf("system list size is %i and NumberOfConnections return is %i ",len,conNum);
171
172 if (isVerbose)
173 DebugTools::ShowError(errorList[8-1],!noPauses && isVerbose,__LINE__,__FILE__);
174
175 return 8;
176
177 }
178
179 }
180
181 printf("Test GetSystemListValues of the system and guid list\n");
182 SystemAddress serverAddress;
183 serverAddress.SetBinaryAddress("127.0.0.1");
184 serverAddress.port=60000;
185
186 if (!compareSystemAddresses(systemList[0],serverAddress))
187 {
188
189 if (isVerbose)
190 DebugTools::ShowError(errorList[10-1],!noPauses && isVerbose,__LINE__,__FILE__);
191
192 return 10;
193
194 }
195
196 RakNetGUID serverGuid=server->GetGuidFromSystemAddress(UNASSIGNED_SYSTEM_ADDRESS);
197
198 if (guidList[0]!=serverGuid)
199 {
200
201 if (isVerbose)
202 DebugTools::ShowError(errorList[11-1],!noPauses && isVerbose,__LINE__,__FILE__);
203
204 return 11;
205
206 }
207
208 printf("Test GetSystemAddressFromIndex\n");
209 if (!compareSystemAddresses(client->GetSystemAddressFromIndex(0),serverAddress))
210 {
211
212 if (isVerbose)
213 DebugTools::ShowError(errorList[12-1],!noPauses && isVerbose,__LINE__,__FILE__);
214
215 return 12;
216 }
217
218 printf("Test GetSystemAddressFromGuid\n");
219 if (!compareSystemAddresses(client->GetSystemAddressFromGuid(serverGuid),serverAddress))
220 {
221
222 if (isVerbose)
223 DebugTools::ShowError(errorList[13-1],!noPauses && isVerbose,__LINE__,__FILE__);
224
225 return 13;
226 }
227
228 printf("Test GetGuidFromSystemAddress\n");
229 if (client->GetGuidFromSystemAddress(serverAddress)!=serverGuid)
230 {
231
232 if (isVerbose)
233 DebugTools::ShowError(errorList[14-1],!noPauses && isVerbose,__LINE__,__FILE__);
234
235 return 14;
236
237 }
238
239 printf("Test GetGUIDFromIndex\n");
240 if (client->GetGUIDFromIndex(0)!=serverGuid)
241 {
242
243 if (isVerbose)
244 DebugTools::ShowError(errorList[15-1],!noPauses && isVerbose,__LINE__,__FILE__);
245
246 return 15;
247
248 }
249
250 SystemAddress clientAddress;
251 clientAddress.SetBinaryAddress("127.0.0.1");
252 clientAddress.port=60001;
253
254 printf("Test GetExternalID, automatic testing is not only required for this\nbecause of it's nature\nShould be supplemented by internet tests\n");
255
256 if (!compareSystemAddresses(client->GetExternalID(serverAddress),clientAddress))
257 {
258
259 if (isVerbose)
260 DebugTools::ShowError(errorList[16-1],!noPauses && isVerbose,__LINE__,__FILE__);
261
262 return 16;
263 }
264
265
266
267
268 return 0;
269
270 }
271
GetTestName()272 RakNet::RakString SystemAddressAndGuidTest::GetTestName()
273 {
274
275 return "SystemAddressAndGuidTest";
276
277 }
278
ErrorCodeToString(int errorCode)279 RakNet::RakString SystemAddressAndGuidTest::ErrorCodeToString(int errorCode)
280 {
281
282 if (errorCode>0&&(unsigned int)errorCode<=errorList.Size())
283 {
284 return errorList[errorCode-1];
285 }
286 else
287 {
288 return "Undefined Error";
289 }
290
291 }
292
compareSystemAddresses(SystemAddress ad1,SystemAddress ad2)293 bool SystemAddressAndGuidTest::compareSystemAddresses(SystemAddress ad1,SystemAddress ad2)
294 {
295 if (ad1.binaryAddress!=ad2.binaryAddress||ad1.port!=ad2.port)
296 {
297 return 0;
298 }
299
300 return 1;
301
302 }
303
SystemAddressAndGuidTest(void)304 SystemAddressAndGuidTest::SystemAddressAndGuidTest(void)
305 {
306
307 errorList.Push("Client was active but shouldn't be yet",__FILE__,__LINE__);
308 errorList.Push("Client was not active but should be",__FILE__,__LINE__);
309 errorList.Push("Could not connect the client",__FILE__,__LINE__);
310 errorList.Push("Mismatch between guidList size and systemList size ",__FILE__,__LINE__);
311 errorList.Push("NumberOfConnections problem",__FILE__,__LINE__);
312 errorList.Push("SystemList problem with GetSystemList",__FILE__,__LINE__);
313 errorList.Push("Both SystemList and Number of connections have problems and report different results",__FILE__,__LINE__);
314 errorList.Push("Both SystemList and Number of connections have problems and report same results",__FILE__,__LINE__);
315 errorList.Push("Undefined Error",__FILE__,__LINE__);
316 errorList.Push("System address from list is wrong.",__FILE__,__LINE__);
317 errorList.Push("Guid from list is wrong",__FILE__,__LINE__);
318 errorList.Push("GetSystemAddressFromIndex failed to return correct values",__FILE__,__LINE__);
319 errorList.Push("GetSystemAddressFromGuid failed to return correct values",__FILE__,__LINE__);
320 errorList.Push("GetGuidFromSystemAddress failed to return correct values",__FILE__,__LINE__);
321 errorList.Push("GetGUIDFromIndex failed to return correct values",__FILE__,__LINE__);
322 errorList.Push("GetExternalID failed to return correct values",__FILE__,__LINE__);
323
324 }
325
~SystemAddressAndGuidTest(void)326 SystemAddressAndGuidTest::~SystemAddressAndGuidTest(void)
327 {
328 }
329
DestroyPeers()330 void SystemAddressAndGuidTest::DestroyPeers()
331 {
332
333 int theSize=destroyList.Size();
334
335 for (int i=0; i < theSize; i++)
336 RakNetworkFactory::DestroyRakPeerInterface(destroyList[i]);
337
338 }