Fix folly conversions for Clang with GCC5's libstdc++
[folly.git] / folly / test / SocketAddressTest.cpp
index 20a4fc0f5d06103db45c39d38ea69c78f22ef831..c04d9bfcc5ae8b0cdc088b2fcdf386a14f24dfcc 100644 (file)
@@ -21,6 +21,8 @@
 #include <sstream>
 #include <system_error>
 
+#include <folly/portability/Sockets.h>
+#include <folly/portability/Stdlib.h>
 #include <folly/test/SocketAddressTestHelper.h>
 
 using namespace boost;
@@ -30,6 +32,8 @@ using std::endl;
 using folly::SocketAddress;
 using folly::SocketAddressTestHelper;
 
+namespace fsp = folly::portability::sockets;
+
 TEST(SocketAddress, Size) {
   SocketAddress addr;
   EXPECT_EQ(sizeof(addr), 32);
@@ -663,7 +667,7 @@ void testSetFromSocket(const SocketAddress *serverBindAddr,
                        SocketAddress *serverPeerAddrRet,
                        SocketAddress *clientAddrRet,
                        SocketAddress *clientPeerAddrRet) {
-  int listenSock = socket(serverBindAddr->getFamily(), SOCK_STREAM, 0);
+  int listenSock = fsp::socket(serverBindAddr->getFamily(), SOCK_STREAM, 0);
   REQUIRE_ERRNO(listenSock > 0, "failed to create listen socket");
   sockaddr_storage laddr;
   serverBindAddr->getAddress(&laddr);
@@ -681,7 +685,7 @@ void testSetFromSocket(const SocketAddress *serverBindAddr,
 
   // Note that we use the family from serverBindAddr here, since we allow
   // clientBindAddr to be nullptr.
-  int clientSock = socket(serverBindAddr->getFamily(), SOCK_STREAM, 0);
+  int clientSock = fsp::socket(serverBindAddr->getFamily(), SOCK_STREAM, 0);
   REQUIRE_ERRNO(clientSock > 0, "failed to create client socket");
   if (clientBindAddr != nullptr) {
     sockaddr_storage clientAddr;
@@ -893,3 +897,18 @@ TEST(SocketAddress, ResetUnixAddress) {
   addy.reset();
   EXPECT_EQ(addy.getFamily(), AF_UNSPEC);
 }
+
+TEST(SocketAddress, ResetIPAddress) {
+  SocketAddress addr;
+  addr.setFromIpPort("127.0.0.1", 80);
+  addr.reset();
+  EXPECT_EQ(addr.getFamily(), AF_UNSPEC);
+  EXPECT_FALSE(addr.isInitialized());
+  EXPECT_TRUE(addr.empty());
+
+  addr.setFromIpPort("2620:0:1cfe:face:b00c::3:65535");
+  addr.reset();
+  EXPECT_EQ(addr.getFamily(), AF_UNSPEC);
+  EXPECT_FALSE(addr.isInitialized());
+  EXPECT_TRUE(addr.empty());
+}