From 27d533e5c97b7d76a537cd1886e2a7447060828d Mon Sep 17 00:00:00 2001 From: Daniel Sommermann Date: Thu, 6 Nov 2014 13:44:13 -0800 Subject: [PATCH] Add some SocketAddress tests Summary: There was a bit of gap in test coverage for bracketed ipv6 Test Plan: unit tests Reviewed By: viswanath@fb.com Subscribers: doug, ps, bmatheny, njormrod, folly-diffs@ FB internal diff: D1664783 Signature: t1:1664783:1415316694:b17e0dc1fcfece06c6e04e5f65e2095c66d28cc4 --- folly/test/SocketAddressTest.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/folly/test/SocketAddressTest.cpp b/folly/test/SocketAddressTest.cpp index f875b4ad..8bfb4526 100644 --- a/folly/test/SocketAddressTest.cpp +++ b/folly/test/SocketAddressTest.cpp @@ -139,6 +139,21 @@ TEST(SocketAddress, SetFromStrings) { EXPECT_EQ(addr.getFamily(), AF_INET); EXPECT_EQ(addr.getAddressStr(), "1.2.3.4"); EXPECT_EQ(addr.getPort(), 9999); + + // Call setFromIpPort() with a bracketed IPv6 + addr.setFromIpPort("[::]:1234"); + EXPECT_EQ(addr.getFamily(), AF_INET6); + EXPECT_EQ(addr.getAddressStr(), "::"); + EXPECT_EQ(addr.getPort(), 1234); + + // Call setFromIpPort() with a bracketed IPv6 + addr.setFromIpPort("[9:8::2]:1234"); + EXPECT_EQ(addr.getFamily(), AF_INET6); + EXPECT_EQ(addr.getAddressStr(), "9:8::2"); + EXPECT_EQ(addr.getPort(), 1234); + + // Call setFromIpPort() with a bracketed IPv6 and no port + EXPECT_THROW(addr.setFromIpPort("[::]"), std::system_error); } TEST(SocketAddress, EqualityAndHash) { -- 2.34.1