udp_endpoint_unittest.cc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <config.h>
  15. #include <string>
  16. #include <gtest/gtest.h>
  17. #include <asio.hpp>
  18. #include <asiolink/io_address.h>
  19. #include <asiolink/udp_endpoint.h>
  20. using namespace asiolink;
  21. using namespace std;
  22. // This test checks that the endpoint can manage its own internal
  23. // asio::ip::udp::endpoint object.
  24. TEST(UDPEndpointTest, v4Address) {
  25. const string test_address("192.0.2.1");
  26. const unsigned short test_port = 5301;
  27. IOAddress address(test_address);
  28. UDPEndpoint endpoint(address, test_port);
  29. EXPECT_TRUE(address == endpoint.getAddress());
  30. EXPECT_EQ(test_port, endpoint.getPort());
  31. EXPECT_EQ(IPPROTO_UDP, endpoint.getProtocol());
  32. EXPECT_EQ(AF_INET, endpoint.getFamily());
  33. }
  34. TEST(UDPEndpointTest, v6Address) {
  35. const string test_address("2001:db8::1235");
  36. const unsigned short test_port = 5302;
  37. IOAddress address(test_address);
  38. UDPEndpoint endpoint(address, test_port);
  39. EXPECT_TRUE(address == endpoint.getAddress());
  40. EXPECT_EQ(test_port, endpoint.getPort());
  41. EXPECT_EQ(IPPROTO_UDP, endpoint.getProtocol());
  42. EXPECT_EQ(AF_INET6, endpoint.getFamily());
  43. }