Add some SocketAddress tests
authorDaniel Sommermann <dcsommer@fb.com>
Thu, 6 Nov 2014 21:44:13 +0000 (13:44 -0800)
committerPavlo Kushnir <pavlo@fb.com>
Sat, 8 Nov 2014 02:40:19 +0000 (18:40 -0800)
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

index f875b4ad17d59a8a6750845df6cb767c67c9ef0a..8bfb45263464c63d3e8213a2f9bf5eab899cd6e7 100644 (file)
@@ -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) {