SystemAddressAndGuidTest.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. #include "SystemAddressAndGuidTest.h"
  11. /*
  12. Description:
  13. Tests:
  14. virtual unsigned short RakPeerInterface::NumberOfConnections ( void ) const
  15. virtual void RakPeerInterface::GetSystemList ( DataStructures::List< SystemAddress > & addresses, DataStructures::List< RakNetGUID > & guids )
  16. virtual bool RakPeerInterface::IsActive ( void ) const
  17. virtual SystemAddress RakPeerInterface::GetSystemAddressFromIndex ( int index )
  18. virtual SystemAddress RakPeerInterface::GetSystemAddressFromGuid ( const RakNetGUID input ) const
  19. virtual const RakNetGUID& RakPeerInterface::GetGuidFromSystemAddress ( const SystemAddress input ) const
  20. pure virtual virtual RakNetGUID RakPeerInterface::GetGUIDFromIndex ( int index )
  21. virtual SystemAddress RakPeerInterface::GetExternalID ( const SystemAddress target ) const
  22. Success conditions:
  23. All functions pass test.
  24. Failure conditions:
  25. Any function fails.
  26. Client was active but shouldn't be yet
  27. Client was not active but should be
  28. Could not connect the client
  29. Mismatch between guidList size and systemList size
  30. NumberOfConnections problem
  31. SystemList problem with GetSystemList
  32. Both SystemList and Number of connections have problems and report different results
  33. Both SystemList and Number of connections have problems and report same results
  34. Undefined Error
  35. System address from list is wrong.
  36. Guid from list is wrong
  37. GetSystemAddressFromIndex failed to return correct values
  38. GetSystemAddressFromGuid failed to return correct values
  39. GetGuidFromSystemAddress failed to return correct values
  40. GetGUIDFromIndex failed to return correct values
  41. GetExternalID failed to return correct values
  42. RakPeerInterface Functions used, tested indirectly by its use. List may not be complete:
  43. Startup
  44. SetMaximumIncomingConnections
  45. Receive
  46. DeallocatePacket
  47. Send
  48. IsConnected
  49. RakPeerInterface Functions Explicitly Tested:
  50. NumberOfConnections
  51. GetSystemList
  52. IsActive
  53. GetSystemAddressFromIndex
  54. GetSystemAddressFromGuid
  55. GetGuidFromSystemAddress
  56. GetGUIDFromIndex
  57. GetExternalID
  58. */
  59. int SystemAddressAndGuidTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
  60. {
  61. RakPeerInterface *server,*client;
  62. destroyList.Clear(false,_FILE_AND_LINE_);
  63. printf("Testing IsActive\n");
  64. client=RakPeerInterface::GetInstance();
  65. destroyList.Push( client,_FILE_AND_LINE_);
  66. if (client->IsActive())
  67. {
  68. if (isVerbose)
  69. DebugTools::ShowError(errorList[1-1],!noPauses && isVerbose,__LINE__,__FILE__);
  70. return 1;
  71. }
  72. client->Startup(1,&SocketDescriptor(60001,0),1);
  73. if (!client->IsActive())
  74. {
  75. if (isVerbose)
  76. DebugTools::ShowError(errorList[2-1],!noPauses && isVerbose,__LINE__,__FILE__);
  77. return 2;
  78. }
  79. //Passed by reference for initializations
  80. TestHelpers::StandardServerPrep(server,destroyList);
  81. if (!TestHelpers::WaitAndConnectTwoPeersLocally(client,server,5000))
  82. {
  83. if (isVerbose)
  84. DebugTools::ShowError(errorList[3-1],!noPauses && isVerbose,__LINE__,__FILE__);
  85. return 3;
  86. }
  87. DataStructures::List< SystemAddress > systemList;
  88. DataStructures::List< RakNetGUID > guidList;
  89. printf("Test GetSystemList and NumberOfConnections\n");
  90. client->GetSystemList(systemList,guidList);//Get connectionlist
  91. int len=systemList.Size();
  92. int len2=guidList.Size();
  93. int conNum=client->NumberOfConnections();
  94. printf("Test if systemList size matches guidList size \n");
  95. if (len2!=len)
  96. {
  97. printf("system list size is %i and guid size is %i ",len,len2);
  98. if (isVerbose)
  99. DebugTools::ShowError(errorList[4-1],!noPauses && isVerbose,__LINE__,__FILE__);
  100. return 4;
  101. }
  102. printf("Test returned list size against NumberofConnections return value\n");
  103. if (conNum!=len)
  104. {
  105. if (conNum==1||len==1)
  106. {
  107. if (conNum!=1)
  108. {
  109. printf("system list size is %i and NumberOfConnections return is %i ",len,conNum);
  110. if (isVerbose)
  111. DebugTools::ShowError(errorList[5-1],!noPauses && isVerbose,__LINE__,__FILE__);
  112. return 5;
  113. }
  114. if (len!=1)
  115. {
  116. printf("system list size is %i and NumberOfConnections return is %i ",len,conNum);
  117. if (isVerbose)
  118. DebugTools::ShowError(errorList[6-1],!noPauses && isVerbose,__LINE__,__FILE__);
  119. return 6;
  120. }
  121. }
  122. else
  123. {
  124. printf("system list size is %i and NumberOfConnections return is %i ",len,conNum);
  125. if (isVerbose)
  126. DebugTools::ShowError(errorList[7-1],!noPauses && isVerbose,__LINE__,__FILE__);
  127. return 7;
  128. }
  129. }
  130. else
  131. {
  132. if (conNum!=1)
  133. {
  134. printf("system list size is %i and NumberOfConnections return is %i ",len,conNum);
  135. if (isVerbose)
  136. DebugTools::ShowError(errorList[8-1],!noPauses && isVerbose,__LINE__,__FILE__);
  137. return 8;
  138. }
  139. }
  140. printf("Test GetSystemListValues of the system and guid list\n");
  141. SystemAddress serverAddress;
  142. serverAddress.SetBinaryAddress("127.0.0.1");
  143. serverAddress.port=60000;
  144. if (!compareSystemAddresses(systemList[0],serverAddress))
  145. {
  146. if (isVerbose)
  147. DebugTools::ShowError(errorList[10-1],!noPauses && isVerbose,__LINE__,__FILE__);
  148. return 10;
  149. }
  150. RakNetGUID serverGuid=server->GetGuidFromSystemAddress(UNASSIGNED_SYSTEM_ADDRESS);
  151. if (guidList[0]!=serverGuid)
  152. {
  153. if (isVerbose)
  154. DebugTools::ShowError(errorList[11-1],!noPauses && isVerbose,__LINE__,__FILE__);
  155. return 11;
  156. }
  157. printf("Test GetSystemAddressFromIndex\n");
  158. if (!compareSystemAddresses(client->GetSystemAddressFromIndex(0),serverAddress))
  159. {
  160. if (isVerbose)
  161. DebugTools::ShowError(errorList[12-1],!noPauses && isVerbose,__LINE__,__FILE__);
  162. return 12;
  163. }
  164. printf("Test GetSystemAddressFromGuid\n");
  165. if (!compareSystemAddresses(client->GetSystemAddressFromGuid(serverGuid),serverAddress))
  166. {
  167. if (isVerbose)
  168. DebugTools::ShowError(errorList[13-1],!noPauses && isVerbose,__LINE__,__FILE__);
  169. return 13;
  170. }
  171. printf("Test GetGuidFromSystemAddress\n");
  172. if (client->GetGuidFromSystemAddress(serverAddress)!=serverGuid)
  173. {
  174. if (isVerbose)
  175. DebugTools::ShowError(errorList[14-1],!noPauses && isVerbose,__LINE__,__FILE__);
  176. return 14;
  177. }
  178. printf("Test GetGUIDFromIndex\n");
  179. if (client->GetGUIDFromIndex(0)!=serverGuid)
  180. {
  181. if (isVerbose)
  182. DebugTools::ShowError(errorList[15-1],!noPauses && isVerbose,__LINE__,__FILE__);
  183. return 15;
  184. }
  185. SystemAddress clientAddress;
  186. clientAddress.SetBinaryAddress("127.0.0.1");
  187. clientAddress.port=60001;
  188. printf("Test GetExternalID, automatic testing is not only required for this\nbecause of it's nature\nShould be supplemented by internet tests\n");
  189. if (!compareSystemAddresses(client->GetExternalID(serverAddress),clientAddress))
  190. {
  191. if (isVerbose)
  192. DebugTools::ShowError(errorList[16-1],!noPauses && isVerbose,__LINE__,__FILE__);
  193. return 16;
  194. }
  195. return 0;
  196. }
  197. RakString SystemAddressAndGuidTest::GetTestName()
  198. {
  199. return "SystemAddressAndGuidTest";
  200. }
  201. RakString SystemAddressAndGuidTest::ErrorCodeToString(int errorCode)
  202. {
  203. if (errorCode>0&&(unsigned int)errorCode<=errorList.Size())
  204. {
  205. return errorList[errorCode-1];
  206. }
  207. else
  208. {
  209. return "Undefined Error";
  210. }
  211. }
  212. bool SystemAddressAndGuidTest::compareSystemAddresses(SystemAddress ad1,SystemAddress ad2)
  213. {
  214. if (ad1.binaryAddress!=ad2.binaryAddress||ad1.port!=ad2.port)
  215. {
  216. return 0;
  217. }
  218. return 1;
  219. }
  220. SystemAddressAndGuidTest::SystemAddressAndGuidTest(void)
  221. {
  222. errorList.Push("Client was active but shouldn't be yet",_FILE_AND_LINE_);
  223. errorList.Push("Client was not active but should be",_FILE_AND_LINE_);
  224. errorList.Push("Could not connect the client",_FILE_AND_LINE_);
  225. errorList.Push("Mismatch between guidList size and systemList size ",_FILE_AND_LINE_);
  226. errorList.Push("NumberOfConnections problem",_FILE_AND_LINE_);
  227. errorList.Push("SystemList problem with GetSystemList",_FILE_AND_LINE_);
  228. errorList.Push("Both SystemList and Number of connections have problems and report different results",_FILE_AND_LINE_);
  229. errorList.Push("Both SystemList and Number of connections have problems and report same results",_FILE_AND_LINE_);
  230. errorList.Push("Undefined Error",_FILE_AND_LINE_);
  231. errorList.Push("System address from list is wrong.",_FILE_AND_LINE_);
  232. errorList.Push("Guid from list is wrong",_FILE_AND_LINE_);
  233. errorList.Push("GetSystemAddressFromIndex failed to return correct values",_FILE_AND_LINE_);
  234. errorList.Push("GetSystemAddressFromGuid failed to return correct values",_FILE_AND_LINE_);
  235. errorList.Push("GetGuidFromSystemAddress failed to return correct values",_FILE_AND_LINE_);
  236. errorList.Push("GetGUIDFromIndex failed to return correct values",_FILE_AND_LINE_);
  237. errorList.Push("GetExternalID failed to return correct values",_FILE_AND_LINE_);
  238. }
  239. SystemAddressAndGuidTest::~SystemAddressAndGuidTest(void)
  240. {
  241. }
  242. void SystemAddressAndGuidTest::DestroyPeers()
  243. {
  244. int theSize=destroyList.Size();
  245. for (int i=0; i < theSize; i++)
  246. RakPeerInterface::DestroyInstance(destroyList[i]);
  247. }
粤ICP备19079148号