mirror of
https://frontier.innolan.net/rainlance/c-ares.git
synced 2025-10-06 12:49:29 +00:00
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:
@ -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);
|
||||
|
@ -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_);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user