SocketAddressMapperTest.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-11-18
  6. * Changed: 2022-12-12
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls_std/ls_std_network.hpp>
  11. #if defined(unix) || defined(__APPLE__)
  12. #include <sys/socket.h>
  13. #endif
  14. using namespace ls::std::network;
  15. namespace
  16. {
  17. class SocketAddressMapperTest : public ::testing::Test
  18. {
  19. protected:
  20. SocketAddressMapperTest() = default;
  21. ~SocketAddressMapperTest() override = default;
  22. void SetUp() override
  23. {}
  24. void TearDown() override
  25. {}
  26. static SocketAddressMapperParameter createSocketAddressMapperParameter()
  27. {
  28. SocketAddressMapperParameter parameter{};
  29. parameter.protocolFamilyType = ProtocolFamilyType::PROTOCOL_FAMILY_TYPE_IPV4;
  30. SocketAddress socketAddress{};
  31. socketAddress.port = 8080;
  32. socketAddress.protocolType = PROTOCOL_TYPE_TCP;
  33. socketAddress.ipAddress = "127.0.0.1";
  34. parameter.socketAddress = socketAddress;
  35. return parameter;
  36. }
  37. };
  38. TEST_F(SocketAddressMapperTest, getClassName)
  39. {
  40. ASSERT_STREQ("SocketAddressMapper", SocketAddressMapper{}.getClassName().c_str());
  41. }
  42. TEST_F(SocketAddressMapperTest, from)
  43. {
  44. ConvertedSocketAddress convertedSocketAddress = SocketAddressMapper::from(createSocketAddressMapperParameter());
  45. #if defined(unix) || defined(__APPLE__)
  46. ASSERT_EQ(36895, convertedSocketAddress.socketAddressUnix.sin_port); // expected: return value of htons()
  47. ASSERT_EQ(AF_INET, convertedSocketAddress.socketAddressUnix.sin_family);
  48. ASSERT_EQ(16777343, convertedSocketAddress.socketAddressUnix.sin_addr.s_addr); // expected: return value of inet_aton()
  49. ASSERT_EQ(16, convertedSocketAddress.addressLength);
  50. #endif
  51. }
  52. }