test: Make failure tests more robust

Different platforms will do different numbers of allocations
in the processing of a given API call; just check that the
return code is either success or ENOMEM, and free off any
returned state in the former case.

Also cope with ECONNREFUSED as well as ENOTFOUND.
This commit is contained in:
David Drysdale 2015-12-30 15:04:08 +00:00
parent 3478963873
commit 78f9ec5515
3 changed files with 18 additions and 6 deletions

View File

@ -44,7 +44,7 @@ TEST(LibraryInit, Nested) {
EXPECT_EQ(EXPECTED_NONINIT, ares_library_initialized());
}
TEST_F(LibraryTest, BasicChannelInit) {
TEST(LibraryInit, BasicChannelInit) {
EXPECT_EQ(ARES_SUCCESS, ares_library_init(ARES_LIB_INIT_ALL));
ares_channel channel = nullptr;
EXPECT_EQ(ARES_SUCCESS, ares_init(&channel));
@ -175,9 +175,16 @@ TEST_F(LibraryTest, OptionsChannelAllocFail) {
for (int ii = 1; ii <= 8; ii++) {
ClearFails();
SetAllocFail(ii);
EXPECT_EQ(ARES_ENOMEM, ares_init_options(&channel, &opts, optmask)) << ii;
EXPECT_EQ(nullptr, channel);
int rc = ares_init_options(&channel, &opts, optmask);
if (rc == ARES_ENOMEM) {
EXPECT_EQ(nullptr, channel);
} else {
EXPECT_EQ(ARES_SUCCESS, rc);
ares_destroy(channel);
channel = nullptr;
}
}
ClearFails();
EXPECT_EQ(ARES_SUCCESS, ares_init_options(&channel, &opts, optmask));
EXPECT_NE(nullptr, channel);

View File

@ -81,7 +81,7 @@ TEST_P(DefaultChannelModeTest, LiveGetLocalhostByNameV4) {
ares_gethostbyname(channel_, "localhost", AF_INET, HostCallback, &result);
Process();
EXPECT_TRUE(result.done_);
if (result.status_ != ARES_ENOTFOUND) {
if ((result.status_ != ARES_ENOTFOUND) && (result.status_ != ARES_ECONNREFUSED)) {
EXPECT_EQ(ARES_SUCCESS, result.status_);
EXPECT_EQ(1, (int)result.host_.addrs_.size());
EXPECT_EQ(AF_INET, result.host_.addrtype_);

View File

@ -234,8 +234,13 @@ TEST_F(LibraryTest, ParsePtrReplyAllocFailMany) {
for (int ii = 1; ii <= 63; ii++) {
ClearFails();
SetAllocFail(ii);
EXPECT_EQ(ARES_ENOMEM, ares_parse_ptr_reply(data.data(), data.size(),
addrv4, sizeof(addrv4), AF_INET, &host)) << ii;
int rc = ares_parse_ptr_reply(data.data(), data.size(),
addrv4, sizeof(addrv4), AF_INET, &host);
if (rc != ARES_ENOMEM) {
EXPECT_EQ(ARES_SUCCESS, rc);
ares_free_hostent(host);
host = nullptr;
}
}
}