diff options
author | Elliott Hughes <enh@google.com> | 2017-10-23 17:38:35 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2017-10-23 17:38:35 -0700 |
commit | bb7d9fb5d438c7477c404f97e07e145d49335947 (patch) | |
tree | e1a616693dc0bf84e7451aac9dd2a21cb6997aea /tests/netdb_test.cpp | |
parent | 6f12bfece5dcc01325e0abba56a46b1bcf991c69 (diff) |
Improve glibc compatibility of gethostby*_r functions.
And add more tests.
Bug: N/A (but I'm here because a recent test broke existing tests)
Test: ran tests
Change-Id: Ib78430f179b43484a49bb50ff447ea6870c1ee3a
Diffstat (limited to 'tests/netdb_test.cpp')
-rw-r--r-- | tests/netdb_test.cpp | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/tests/netdb_test.cpp b/tests/netdb_test.cpp index e699701f3..a6241387e 100644 --- a/tests/netdb_test.cpp +++ b/tests/netdb_test.cpp @@ -271,8 +271,9 @@ TEST(netdb, gethostbyname_r_ERANGE) { char buf[4]; // Use too small buffer. int err; int result = gethostbyname_r("localhost", &hent, buf, sizeof(buf), &hp, &err); - ASSERT_EQ(ERANGE, result); - ASSERT_EQ(NULL, hp); + EXPECT_EQ(NETDB_INTERNAL, err); + EXPECT_EQ(ERANGE, result); + EXPECT_EQ(NULL, hp); } TEST(netdb, gethostbyname2_r_ERANGE) { @@ -281,8 +282,9 @@ TEST(netdb, gethostbyname2_r_ERANGE) { char buf[4]; // Use too small buffer. int err; int result = gethostbyname2_r("localhost", AF_INET, &hent, buf, sizeof(buf), &hp, &err); - ASSERT_EQ(ERANGE, result); - ASSERT_EQ(NULL, hp); + EXPECT_EQ(NETDB_INTERNAL, err); + EXPECT_EQ(ERANGE, result); + EXPECT_EQ(NULL, hp); } TEST(netdb, gethostbyaddr_r_ERANGE) { @@ -292,8 +294,43 @@ TEST(netdb, gethostbyaddr_r_ERANGE) { char buf[4]; // Use too small buffer. int err; int result = gethostbyaddr_r(&addr, sizeof(addr), AF_INET, &hent, buf, sizeof(buf), &hp, &err); - ASSERT_EQ(ERANGE, result); - ASSERT_EQ(NULL, hp); + EXPECT_EQ(NETDB_INTERNAL, err); + EXPECT_EQ(ERANGE, result); + EXPECT_EQ(NULL, hp); +} + +TEST(netdb, gethostbyname_r_HOST_NOT_FOUND) { + hostent hent; + hostent *hp; + char buf[BUFSIZ]; + int err; + int result = gethostbyname_r("does.not.exist.google.com", &hent, buf, sizeof(buf), &hp, &err); + EXPECT_EQ(HOST_NOT_FOUND, err); + EXPECT_EQ(0, result); + EXPECT_EQ(NULL, hp); +} + +TEST(netdb, gethostbyname2_r_HOST_NOT_FOUND) { + hostent hent; + hostent *hp; + char buf[BUFSIZ]; + int err; + int result = gethostbyname2_r("does.not.exist.google.com", AF_INET, &hent, buf, sizeof(buf), &hp, &err); + EXPECT_EQ(HOST_NOT_FOUND, err); + EXPECT_EQ(0, result); + EXPECT_EQ(NULL, hp); +} + +TEST(netdb, gethostbyaddr_r_HOST_NOT_FOUND) { + in_addr addr = { htonl(0xffffffff) }; + hostent hent; + hostent *hp; + char buf[BUFSIZ]; + int err; + int result = gethostbyaddr_r(&addr, sizeof(addr), AF_INET, &hent, buf, sizeof(buf), &hp, &err); + EXPECT_EQ(HOST_NOT_FOUND, err); + EXPECT_EQ(0, result); + EXPECT_EQ(NULL, hp); } TEST(netdb, getservbyname) { |