diff options
author | Elliott Hughes | 2014-11-17 12:26:45 -0600 |
---|---|---|
committer | Gerrit Code Review | 2014-11-17 12:26:46 -0600 |
commit | f2c882095b5747cd7f3158428208580a7ff72ed6 (patch) | |
tree | b29a812c92cc70cdc20a4cdfd8020c1287a031b0 /tests | |
parent | 35f8910e4cdf3f7d0b877394524c7dd719084187 (diff) | |
parent | 32fea147eaac4b811440a29d362fdad7e2c5a4ec (diff) | |
download | platform-bionic-f2c882095b5747cd7f3158428208580a7ff72ed6.tar.gz platform-bionic-f2c882095b5747cd7f3158428208580a7ff72ed6.tar.xz platform-bionic-f2c882095b5747cd7f3158428208580a7ff72ed6.zip |
Merge "Add getaddrinfo(3) tests for NULL arguments."
Diffstat (limited to 'tests')
-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 ef2c8dac..0cebe4e8 100644 --- a/tests/netdb_test.cpp +++ b/tests/netdb_test.cpp | |||
@@ -21,6 +21,23 @@ | |||
21 | #include <netdb.h> | 21 | #include <netdb.h> |
22 | #include <netinet/in.h> | 22 | #include <netinet/in.h> |
23 | 23 | ||
24 | TEST(netdb, getaddrinfo_NULL_host) { | ||
25 | // It's okay for the host argument to be NULL, as long as service isn't. | ||
26 | addrinfo* ai = NULL; | ||
27 | ASSERT_EQ(0, getaddrinfo(NULL, "smtp", NULL, &ai)); | ||
28 | // (sockaddr_in::sin_port and sockaddr_in6::sin6_port overlap.) | ||
29 | ASSERT_EQ(25U, ntohs(reinterpret_cast<sockaddr_in*>(ai->ai_addr)->sin_port)); | ||
30 | freeaddrinfo(ai); | ||
31 | } | ||
32 | |||
33 | TEST(netdb, getaddrinfo_NULL_service) { | ||
34 | // It's okay for the service argument to be NULL, as long as host isn't. | ||
35 | addrinfo* ai = NULL; | ||
36 | ASSERT_EQ(0, getaddrinfo("localhost", NULL, NULL, &ai)); | ||
37 | ASSERT_TRUE(ai != NULL); | ||
38 | freeaddrinfo(ai); | ||
39 | } | ||
40 | |||
24 | TEST(netdb, getaddrinfo_NULL_hints) { | 41 | TEST(netdb, getaddrinfo_NULL_hints) { |
25 | addrinfo* ai = NULL; | 42 | addrinfo* ai = NULL; |
26 | ASSERT_EQ(0, getaddrinfo("localhost", "9999", NULL, &ai)); | 43 | ASSERT_EQ(0, getaddrinfo("localhost", "9999", NULL, &ai)); |