SocketIT.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-12-27
  6. * Changed: 2022-12-28
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls_std/ls_std_network.hpp>
  11. using namespace ls::std::network;
  12. namespace
  13. {
  14. class SocketIT : public ::testing::Test
  15. {
  16. protected:
  17. SocketIT() = default;
  18. ~SocketIT() override = default;
  19. void SetUp() override
  20. {}
  21. void TearDown() override
  22. {}
  23. };
  24. TEST_F(SocketIT, local_server_client)
  25. {
  26. // create server parameter
  27. SocketParameter serverParameter{};
  28. serverParameter.protocolFamilyType = LS_STD_PROTOCOL_FAMILY_TYPE_IPV4;
  29. serverParameter.socketAddress.protocolType = LS_STD_PROTOCOL_TYPE_TCP;
  30. serverParameter.socketAddress.port = 5099;
  31. serverParameter.queueSize = 5;
  32. // create client parameter
  33. SocketParameter clientParameter{};
  34. clientParameter.protocolFamilyType = LS_STD_PROTOCOL_FAMILY_TYPE_IPV4;
  35. clientParameter.socketAddress.protocolType = LS_STD_PROTOCOL_TYPE_TCP;
  36. clientParameter.socketAddress.ipAddress = "127.0.0.1";
  37. clientParameter.socketAddress.port = 5099;
  38. // start server
  39. Socket serverSocket{serverParameter};
  40. ASSERT_TRUE(serverSocket.bind());
  41. ASSERT_TRUE(serverSocket.listen());
  42. // start client
  43. Socket clientSocket{clientParameter};
  44. ASSERT_TRUE(clientSocket.connect());
  45. // close sockets
  46. ASSERT_TRUE(clientSocket.close());
  47. ASSERT_TRUE(serverSocket.close());
  48. }
  49. }