netTest.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. ////-----------------------------------------------------------------------------
  2. //// Copyright (c) 2014 GarageGames, LLC
  3. ////
  4. //// Permission is hereby granted, free of charge, to any person obtaining a copy
  5. //// of this software and associated documentation files (the "Software"), to
  6. //// deal in the Software without restriction, including without limitation the
  7. //// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. //// sell copies of the Software, and to permit persons to whom the Software is
  9. //// furnished to do so, subject to the following conditions:
  10. ////
  11. //// The above copyright notice and this permission notice shall be included in
  12. //// all copies or substantial portions of the Software.
  13. ////
  14. //// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. //// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. //// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. //// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. //// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. //// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. //// IN THE SOFTWARE.
  21. ////-----------------------------------------------------------------------------
  22. //
  23. //#ifdef TORQUE_TESTS_ENABLED
  24. //#include "testing/unitTesting.h"
  25. //#include "platform/platformNet.h"
  26. //#include "core/util/journal/process.h"
  27. //
  28. //struct TcpHandle
  29. //{
  30. // NetSocket mSocket;
  31. // S32 mDataReceived;
  32. //
  33. // void notify(NetSocket sock, U32 state)
  34. // {
  35. // // Only consider our own socket.
  36. // if(mSocket != sock)
  37. // return;
  38. //
  39. // // Ok - what's the state? We do some dumb responses to given states
  40. // // in order to fulfill the request.
  41. // if(state == Net::Connected)
  42. // {
  43. // U8 reqBuffer[] = {
  44. // "GET / HTTP/1.0\nUser-Agent: Torque/1.0\n\n"
  45. // };
  46. //
  47. // Net::Error e = Net::sendtoSocket(mSocket, reqBuffer, sizeof(reqBuffer));
  48. //
  49. // ASSERT_EQ(Net::NoError, e)
  50. // << "Got an error sending our HTTP request!";
  51. // }
  52. // else
  53. // {
  54. // Process::requestShutdown();
  55. // mSocket = NetSocket::INVALID;
  56. // ASSERT_EQ(Net::Disconnected, state)
  57. // << "Ended with a network error!";
  58. // }
  59. // }
  60. //
  61. // void receive(NetSocket sock, RawData incomingData)
  62. // {
  63. // // Only consider our own socket.
  64. // if(mSocket != sock)
  65. // return;
  66. //
  67. // mDataReceived += incomingData.size;
  68. // }
  69. //};
  70. //
  71. //TEST(Net, TCPRequest)
  72. //{
  73. // TcpHandle handler;
  74. //
  75. // handler.mSocket = NetSocket::INVALID;
  76. // handler.mDataReceived = 0;
  77. //
  78. // // Hook into the signals.
  79. // Net::smConnectionNotify ->notify(&handler, &TcpHandle::notify);
  80. // Net::smConnectionReceive->notify(&handler, &TcpHandle::receive);
  81. //
  82. // // Open a TCP connection to torque3d.org
  83. // handler.mSocket = Net::openConnectTo("108.61.193.195:80");
  84. // const U32 limit = Platform::getRealMilliseconds() + (5*1000);
  85. // while(Process::processEvents() && (Platform::getRealMilliseconds() < limit) ) {}
  86. //
  87. // // Unhook from the signals.
  88. // Net::smConnectionNotify ->remove(&handler, &TcpHandle::notify);
  89. // Net::smConnectionReceive->remove(&handler, &TcpHandle::receive);
  90. //
  91. // EXPECT_GT(handler.mDataReceived, 0)
  92. // << "Didn't get any data back!";
  93. //}
  94. //
  95. //struct JournalHandle
  96. //{
  97. // NetSocket mSocket;
  98. // S32 mDataReceived;
  99. //
  100. // void notify(NetSocket sock, U32 state)
  101. // {
  102. // // Only consider our own socket.
  103. // if(mSocket != sock)
  104. // return;
  105. //
  106. // // Ok - what's the state? We do some dumb responses to given states
  107. // // in order to fulfill the request.
  108. // if(state == Net::Connected)
  109. // {
  110. // U8 reqBuffer[] = {
  111. // "GET / HTTP/1.0\nUser-Agent: Torque/1.0\n\n"
  112. // };
  113. //
  114. // Net::Error e = Net::sendtoSocket(mSocket, reqBuffer, sizeof(reqBuffer));
  115. //
  116. // ASSERT_EQ(Net::NoError, e)
  117. // << "Got an error sending our HTTP request!";
  118. // }
  119. // else
  120. // {
  121. // Process::requestShutdown();
  122. // mSocket = NetSocket::INVALID;
  123. // ASSERT_EQ(Net::Disconnected, state)
  124. // << "Ended with a network error!";
  125. // }
  126. // }
  127. //
  128. // void receive(NetSocket sock, RawData incomingData)
  129. // {
  130. // // Only consider our own socket.
  131. // if(mSocket != sock)
  132. // return;
  133. // mDataReceived += incomingData.size;
  134. // }
  135. //
  136. // void makeRequest()
  137. // {
  138. // mSocket = NetSocket::INVALID;
  139. // mDataReceived = 0;
  140. //
  141. // // Hook into the signals.
  142. // Net::smConnectionNotify ->notify(this, &JournalHandle::notify);
  143. // Net::smConnectionReceive->notify(this, &JournalHandle::receive);
  144. //
  145. // // Open a TCP connection to torque3d.org
  146. // mSocket = Net::openConnectTo("108.61.193.195:80");
  147. //
  148. // // Let the callbacks enable things to process.
  149. // while(Process::processEvents()) {}
  150. //
  151. // // Unhook from the signals.
  152. // Net::smConnectionNotify ->remove(this, &JournalHandle::notify);
  153. // Net::smConnectionReceive->remove(this, &JournalHandle::receive);
  154. //
  155. // EXPECT_GT(mDataReceived, 0)
  156. // << "Didn't get any data back!";
  157. // }
  158. //};
  159. //
  160. //TEST(Net, JournalTCPRequest)
  161. //{
  162. // JournalHandle handler;
  163. //
  164. // Journal::Record("journalTCP.jrn");
  165. // ASSERT_TRUE(Journal::IsRecording());
  166. // handler.makeRequest();
  167. // S32 bytesRead = handler.mDataReceived;
  168. // Journal::Stop();
  169. //
  170. // Journal::Play("journalTCP.jrn");
  171. // handler.makeRequest();
  172. // Journal::Stop();
  173. //
  174. // EXPECT_EQ(bytesRead, handler.mDataReceived)
  175. // << "Didn't get same data back from journal playback.";
  176. //}
  177. //
  178. //#endif