PacketAndLowLevelTestsTest.cpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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 "PacketAndLowLevelTestsTest.h"
  11. /*
  12. Description:
  13. Tests out the sunctions:
  14. virtual int RakPeerInterface::GetSplitMessageProgressInterval ( void ) const "
  15. virtual void RakPeerInterface::PushBackPacket ( Packet * packet, bool pushAtHead ) "
  16. virtual bool RakPeerInterface::SendList ( char ** data, const int * lengths, const int numParameters, PacketPriority priority, PacketReliability reliability, char orderingChannel, SystemAddress systemAddress, bool broadcast ) "
  17. virtual void RakPeerInterface::SetSplitMessageProgressInterval ( int interval )
  18. virtual void RakPeerInterface::SetUnreliableTimeout ( TimeMS timeoutMS )
  19. virtual Packet* RakPeerInterface::AllocatePacket ( unsigned dataSize )
  20. AttachPlugin (PluginInterface2 *plugin)=0
  21. DetachPlugin (PluginInterface2 *plugin)=0
  22. Success conditions:
  23. Failure conditions:
  24. RakPeerInterface Functions used, tested indirectly by its use,list may not be complete:
  25. Startup
  26. SetMaximumIncomingConnections
  27. Receive
  28. DeallocatePacket
  29. Send
  30. IsConnected
  31. RakPeerInterface Functions Explicitly Tested:
  32. GetSplitMessageProgressInterval
  33. PushBackPacket
  34. SendList
  35. SetSplitMessageProgressInterval
  36. AllocatePacket
  37. GetMTUSize
  38. AttachPlugin
  39. DetachPlugin
  40. */
  41. int PacketAndLowLevelTestsTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
  42. {
  43. RakPeerInterface *server,*client;
  44. destroyList.Clear(false,_FILE_AND_LINE_);
  45. TestHelpers::StandardClientPrep(client,destroyList);
  46. TestHelpers::StandardServerPrep(server,destroyList);
  47. printf("Connecting to server\n");
  48. if (!TestHelpers::WaitAndConnectTwoPeersLocally(client,server,5000))
  49. {
  50. if (isVerbose)
  51. DebugTools::ShowError(errorList[1-1],!noPauses && isVerbose,__LINE__,__FILE__);
  52. return 1;
  53. }
  54. printf("Testing SendList\n");
  55. char* dataList2[5];
  56. char **dataList=(char **)dataList2;
  57. int lengths[5];
  58. char curString1[]="AAAA";
  59. char curString2[]="ABBB";
  60. char curString3[]="ACCC";
  61. char curString4[]="ADDD";
  62. char curString5[]="AEEE";
  63. dataList[0]=curString1;
  64. dataList[1]=curString2;
  65. dataList[2]=curString3;
  66. dataList[3]=curString4;
  67. dataList[4]=curString5;
  68. for (int i=0;i<5;i++)
  69. {
  70. dataList[i][0]=ID_USER_PACKET_ENUM+1+i;
  71. lengths[i]=5;
  72. }
  73. client->SendList((const char**)dataList,lengths,5,HIGH_PRIORITY,RELIABLE_ORDERED,0, UNASSIGNED_SYSTEM_ADDRESS, true);
  74. Packet* packet;
  75. if (!(packet=CommonFunctions::WaitAndReturnMessageWithID(server,ID_USER_PACKET_ENUM+1,1000)))
  76. {
  77. if (isVerbose)
  78. DebugTools::ShowError(errorList[9-1],!noPauses && isVerbose,__LINE__,__FILE__);
  79. return 9;
  80. }
  81. if (packet->length!=25)
  82. {
  83. if (isVerbose)
  84. DebugTools::ShowError(errorList[13],!noPauses && isVerbose,__LINE__,__FILE__);
  85. return 14;
  86. }
  87. server->DeallocatePacket(packet);
  88. PluginInterface2* myPlug=new PacketChangerPlugin();
  89. printf("Test attach detach of plugins\n");
  90. client->AttachPlugin(myPlug);
  91. TestHelpers::BroadCastTestPacket(client);
  92. if (TestHelpers::WaitForTestPacket(server,2000))
  93. {
  94. if (isVerbose)
  95. DebugTools::ShowError(errorList[2-1],!noPauses && isVerbose,__LINE__,__FILE__);
  96. return 2;
  97. }
  98. client->DetachPlugin(myPlug);
  99. TestHelpers::BroadCastTestPacket(client);
  100. if (!TestHelpers::WaitForTestPacket(server,2000))
  101. {
  102. if (isVerbose)
  103. DebugTools::ShowError(errorList[3-1],!noPauses && isVerbose,__LINE__,__FILE__);
  104. return 3;
  105. }
  106. printf("Test AllocatePacket\n");
  107. Packet * hugePacket,*hugePacket2;
  108. const int dataSize=3000000;//around 30 meg didn't want to calculate the exact
  109. hugePacket=client->AllocatePacket(dataSize);
  110. hugePacket2=client->AllocatePacket(dataSize);
  111. /*//Couldn't find a good cross platform way for allocated memory so skipped this check
  112. if (somemalloccheck<3000000)
  113. {}
  114. */
  115. printf("Assuming 3000000 allocation for splitpacket, testing setsplitpacket\n");
  116. hugePacket->data[0]=ID_USER_PACKET_ENUM+1;
  117. hugePacket2->data[0]=ID_USER_PACKET_ENUM+1;
  118. server->SetSplitMessageProgressInterval(1);
  119. if (server->GetSplitMessageProgressInterval()!=1)
  120. {
  121. if (isVerbose)
  122. DebugTools::ShowError(errorList[4-1],!noPauses && isVerbose,__LINE__,__FILE__);
  123. return 4;
  124. }
  125. if (!client->Send((const char *)hugePacket->data,dataSize,HIGH_PRIORITY,RELIABLE_ORDERED,0, UNASSIGNED_SYSTEM_ADDRESS, true))
  126. {
  127. if (isVerbose)
  128. DebugTools::ShowError(errorList[5-1],!noPauses && isVerbose,__LINE__,__FILE__);
  129. return 5;
  130. }
  131. if (!CommonFunctions::WaitForMessageWithID(server,ID_DOWNLOAD_PROGRESS,2000))
  132. {
  133. if (isVerbose)
  134. DebugTools::ShowError(errorList[6-1],!noPauses && isVerbose,__LINE__,__FILE__);
  135. return 6;
  136. }
  137. while(CommonFunctions::WaitForMessageWithID(server,ID_DOWNLOAD_PROGRESS,500))//Clear out the rest before next test
  138. {
  139. }
  140. printf("Making sure still connected, if not connect\n");
  141. if (!TestHelpers::WaitAndConnectTwoPeersLocally(client,server,5000))//Make sure connected before test
  142. {
  143. if (isVerbose)
  144. DebugTools::ShowError(errorList[11-1],!noPauses && isVerbose,__LINE__,__FILE__);
  145. return 11;
  146. }
  147. printf("Making sure standard send/recieve still functioning\n");
  148. TestHelpers::BroadCastTestPacket(client);
  149. if (!TestHelpers::WaitForTestPacket(server,5000))
  150. {
  151. if (isVerbose)
  152. DebugTools::ShowError(errorList[12],!noPauses && isVerbose,__LINE__,__FILE__);
  153. return 13;
  154. }
  155. printf("Testing PushBackPacket\n");
  156. server->PushBackPacket(hugePacket,false);
  157. if (!TestHelpers::WaitForTestPacket(server,2000))
  158. {
  159. if (isVerbose)
  160. DebugTools::ShowError(errorList[7-1],!noPauses && isVerbose,__LINE__,__FILE__);
  161. return 7;
  162. }
  163. printf("Making sure still connected, if not connect\n");
  164. if (!TestHelpers::WaitAndConnectTwoPeersLocally(client,server,5000))//Make sure connected before test
  165. {
  166. if (isVerbose)
  167. DebugTools::ShowError(errorList[11-1],!noPauses && isVerbose,__LINE__,__FILE__);
  168. return 11;
  169. }
  170. printf("Making sure standard send/recieve still functioning\n");
  171. TestHelpers::BroadCastTestPacket(client);
  172. if (!TestHelpers::WaitForTestPacket(server,2000))
  173. {
  174. if (isVerbose)
  175. DebugTools::ShowError(errorList[12-1],!noPauses && isVerbose,__LINE__,__FILE__);
  176. return 12;
  177. }
  178. printf("PushBackPacket head true test\n");
  179. server->PushBackPacket(hugePacket2,true);
  180. if (!TestHelpers::WaitForTestPacket(server,2000))
  181. {
  182. if (isVerbose)
  183. DebugTools::ShowError(errorList[10-1],!noPauses && isVerbose,__LINE__,__FILE__);
  184. return 10;
  185. }
  186. printf("Making sure still connected, if not connect\n");
  187. if (!TestHelpers::WaitAndConnectTwoPeersLocally(client,server,5000))//Make sure connected before test
  188. {
  189. if (isVerbose)
  190. DebugTools::ShowError(errorList[11-1],!noPauses && isVerbose,__LINE__,__FILE__);
  191. return 11;
  192. }
  193. printf("Run recieve test\n");
  194. TestHelpers::BroadCastTestPacket(client);
  195. if (!TestHelpers::WaitForTestPacket(server,2000))
  196. {
  197. if (isVerbose)
  198. DebugTools::ShowError(errorList[12-1],!noPauses && isVerbose,__LINE__,__FILE__);
  199. return 12;
  200. }
  201. return 0;
  202. }
  203. void PacketAndLowLevelTestsTest::FloodWithHighPriority(RakPeerInterface* client)
  204. {
  205. for (int i=0;i<60000;i++)
  206. {
  207. TestHelpers::BroadCastTestPacket(client,UNRELIABLE,HIGH_PRIORITY,ID_USER_PACKET_ENUM+2);
  208. }
  209. }
  210. RakString PacketAndLowLevelTestsTest::GetTestName()
  211. {
  212. return "PacketAndLowLevelTestsTest";
  213. }
  214. RakString PacketAndLowLevelTestsTest::ErrorCodeToString(int errorCode)
  215. {
  216. if (errorCode>0&&(unsigned int)errorCode<=errorList.Size())
  217. {
  218. return errorList[errorCode-1];
  219. }
  220. else
  221. {
  222. return "Undefined Error";
  223. }
  224. }
  225. void PacketAndLowLevelTestsTest::DestroyPeers()
  226. {
  227. int theSize=destroyList.Size();
  228. for (int i=0; i < theSize; i++)
  229. RakPeerInterface::DestroyInstance(destroyList[i]);
  230. }
  231. PacketAndLowLevelTestsTest::PacketAndLowLevelTestsTest(void)
  232. {
  233. errorList.Push("Client failed to connect to server",_FILE_AND_LINE_);
  234. errorList.Push("Attached plugin failed to modify packet",_FILE_AND_LINE_);
  235. errorList.Push("Plugin is still modifying packets after detach",_FILE_AND_LINE_);
  236. errorList.Push("GetSplitMessageProgressInterval returned wrong value",_FILE_AND_LINE_);
  237. errorList.Push("Send to server failed",_FILE_AND_LINE_);
  238. 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_);
  239. errorList.Push("Did not recieve and put on packet made with AllocatePacket and put on recieve stack with PushBackPacket",_FILE_AND_LINE_);
  240. errorList.Push("Client failed to connect to server",_FILE_AND_LINE_);
  241. errorList.Push("Did not recieve all packets from SendList",_FILE_AND_LINE_);
  242. errorList.Push("Did not recieve and put on packet made with AllocatePacket and put on recieve stack with PushBackPacket",_FILE_AND_LINE_);
  243. errorList.Push("Client failed to connect to server",_FILE_AND_LINE_);
  244. errorList.Push("PushBackPacket messed up future communication",_FILE_AND_LINE_);
  245. errorList.Push("Send/Recieve failed",_FILE_AND_LINE_);
  246. errorList.Push("Recieved size incorrect",_FILE_AND_LINE_);
  247. }
  248. PacketAndLowLevelTestsTest::~PacketAndLowLevelTestsTest(void)
  249. {
  250. }
粤ICP备19079148号