diff options
author | Elliott Hughes <enh@google.com> | 2014-11-17 18:26:45 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-11-17 18:26:46 +0000 |
commit | f2c882095b5747cd7f3158428208580a7ff72ed6 (patch) | |
tree | b29a812c92cc70cdc20a4cdfd8020c1287a031b0 | |
parent | 35f8910e4cdf3f7d0b877394524c7dd719084187 (diff) | |
parent | 32fea147eaac4b811440a29d362fdad7e2c5a4ec (diff) | |
download | bionic-f2c882095b5747cd7f3158428208580a7ff72ed6.zip bionic-f2c882095b5747cd7f3158428208580a7ff72ed6.tar.gz bionic-f2c882095b5747cd7f3158428208580a7ff72ed6.tar.bz2 |
Merge "Add getaddrinfo(3) tests for NULL arguments."
-rw-r--r-- | tests/netdb_test.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/netdb_test.cpp b/tests/netdb_test.cpp index ef2c8da..0cebe4e 100644 --- a/tests/netdb_test.cpp +++ b/tests/netdb_test.cpp @@ -21,6 +21,23 @@ #include <netdb.h> #include <netinet/in.h> +TEST(netdb, getaddrinfo_NULL_host) { + // It's okay for the host argument to be NULL, as long as service isn't. + addrinfo* ai = NULL; + ASSERT_EQ(0, getaddrinfo(NULL, "smtp", NULL, &ai)); + // (sockaddr_in::sin_port and sockaddr_in6::sin6_port overlap.) + ASSERT_EQ(25U, ntohs(reinterpret_cast<sockaddr_in*>(ai->ai_addr)->sin_port)); + freeaddrinfo(ai); +} + +TEST(netdb, getaddrinfo_NULL_service) { + // It's okay for the service argument to be NULL, as long as host isn't. + addrinfo* ai = NULL; + ASSERT_EQ(0, getaddrinfo("localhost", NULL, NULL, &ai)); + ASSERT_TRUE(ai != NULL); + freeaddrinfo(ai); +} + TEST(netdb, getaddrinfo_NULL_hints) { addrinfo* ai = NULL; ASSERT_EQ(0, getaddrinfo("localhost", "9999", NULL, &ai)); |