udp_endpoint_unittest.cc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (C) 2011-2016 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #include <config.h>
  7. #include <asiolink/asio_wrapper.h>
  8. #include <asiolink/io_address.h>
  9. #include <asiolink/udp_endpoint.h>
  10. #include <gtest/gtest.h>
  11. #include <string>
  12. using namespace isc::asiolink;
  13. using namespace std;
  14. // This test checks that the endpoint can manage its own internal
  15. // boost::asio::ip::udp::endpoint object.
  16. TEST(UDPEndpointTest, v4Address) {
  17. const string test_address("192.0.2.1");
  18. const unsigned short test_port = 5301;
  19. IOAddress address(test_address);
  20. UDPEndpoint endpoint(address, test_port);
  21. EXPECT_TRUE(address == endpoint.getAddress());
  22. EXPECT_EQ(test_port, endpoint.getPort());
  23. EXPECT_EQ(static_cast<short>(IPPROTO_UDP), endpoint.getProtocol());
  24. EXPECT_EQ(AF_INET, endpoint.getFamily());
  25. }
  26. TEST(UDPEndpointTest, v6Address) {
  27. const string test_address("2001:db8::1235");
  28. const unsigned short test_port = 5302;
  29. IOAddress address(test_address);
  30. UDPEndpoint endpoint(address, test_port);
  31. EXPECT_TRUE(address == endpoint.getAddress());
  32. EXPECT_EQ(test_port, endpoint.getPort());
  33. EXPECT_EQ(static_cast<short>(IPPROTO_UDP), endpoint.getProtocol());
  34. EXPECT_EQ(AF_INET6, endpoint.getFamily());
  35. }