Alien-cares
view release on metacpan or search on metacpan
libcares/test/ares-test-misc.cc view on Meta::CPAN
EXPECT_EQ(ARES_ENODATA, ares_set_servers_csv(nullptr, "256.1.2.3"));
EXPECT_EQ(ARES_ENODATA, ares_set_servers_csv(nullptr, "1.2.3.4.5"));
EXPECT_EQ(ARES_ENODATA, ares_set_servers_csv(nullptr, "1:2:3:4:5"));
EXPECT_EQ(ARES_SUCCESS,
ares_set_servers_csv(channel_, "1.2.3.4,0102:0304:0506:0708:0910:1112:1314:1516,2.3.4.5"));
std::vector<std::string> expected = {"1.2.3.4", "0102:0304:0506:0708:0910:1112:1314:1516", "2.3.4.5"};
EXPECT_EQ(expected, GetNameServers(channel_));
// Same, with spaces
EXPECT_EQ(ARES_EBADSTR,
ares_set_servers_csv(channel_, "1.2.3.4 , 0102:0304:0506:0708:0910:1112:1314:1516, 2.3.4.5"));
// Same, with ports
EXPECT_EQ(ARES_SUCCESS,
ares_set_servers_csv(channel_, "1.2.3.4:54,[0102:0304:0506:0708:0910:1112:1314:1516]:80,2.3.4.5:55"));
EXPECT_EQ(expected, GetNameServers(channel_));
EXPECT_EQ(ARES_SUCCESS,
ares_set_servers_ports_csv(channel_, "1.2.3.4:54,[0102:0304:0506:0708:0910:1112:1314:1516]:80,2.3.4.5:55"));
std::vector<std::string> expected2 = {"1.2.3.4:54", "[0102:0304:0506:0708:0910:1112:1314:1516]:80", "2.3.4.5:55"};
EXPECT_EQ(expected2, GetNameServers(channel_));
// Change not allowed while request is pending
HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
EXPECT_EQ(ARES_ENOTIMP, ares_set_servers_csv(channel_, "1.2.3.4,2.3.4.5"));
EXPECT_EQ(ARES_ENOTIMP, ares_set_servers_ports_csv(channel_, "1.2.3.4:56,2.3.4.5:67"));
ares_cancel(channel_);
// Should survive duplication
ares_channel channel2;
EXPECT_EQ(ARES_SUCCESS, ares_dup(&channel2, channel_));
EXPECT_EQ(expected2, GetNameServers(channel2));
ares_destroy(channel2);
// Allocation failure cases
for (int fail = 1; fail <= 5; fail++) {
SetAllocFail(fail);
EXPECT_EQ(ARES_ENOMEM,
ares_set_servers_csv(channel_, "1.2.3.4,0102:0304:0506:0708:0910:1112:1314:1516,2.3.4.5"));
}
// Blank servers
EXPECT_EQ(ARES_SUCCESS, ares_set_servers_csv(channel_, ""));
std::vector<std::string> none;
EXPECT_EQ(none, GetNameServers(channel_));
EXPECT_EQ(ARES_EBADSTR, ares_set_servers_csv(channel_, "2.3.4.5,1.2.3.4:,3.4.5.6"));
EXPECT_EQ(ARES_EBADSTR, ares_set_servers_csv(channel_, "2.3.4.5,1.2.3.4:Z,3.4.5.6"));
}
TEST_F(DefaultChannelTest, TimeoutValue) {
struct timeval tinfo;
tinfo.tv_sec = 0;
tinfo.tv_usec = 0;
struct timeval tmax;
tmax.tv_sec = 0;
tmax.tv_usec = 10;
struct timeval* pt;
// No timers => get max back.
pt = ares_timeout(channel_, &tmax, &tinfo);
EXPECT_EQ(&tmax, pt);
EXPECT_EQ(0, pt->tv_sec);
EXPECT_EQ(10, pt->tv_usec);
pt = ares_timeout(channel_, nullptr, &tinfo);
EXPECT_EQ(nullptr, pt);
HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
// Now there's a timer running.
pt = ares_timeout(channel_, &tmax, &tinfo);
EXPECT_EQ(&tmax, pt);
EXPECT_EQ(0, pt->tv_sec);
EXPECT_EQ(10, pt->tv_usec);
tmax.tv_sec = 100;
pt = ares_timeout(channel_, &tmax, &tinfo);
EXPECT_EQ(&tinfo, pt);
pt = ares_timeout(channel_, nullptr, &tinfo);
EXPECT_EQ(&tinfo, pt);
Process();
}
TEST_F(LibraryTest, InetNtoP) {
struct in_addr addr;
addr.s_addr = htonl(0x01020304);
char buffer[256];
EXPECT_EQ(buffer, ares_inet_ntop(AF_INET, &addr, buffer, sizeof(buffer)));
EXPECT_EQ("1.2.3.4", std::string(buffer));
}
TEST_F(LibraryTest, Mkquery) {
byte* p;
int len;
ares_mkquery("example.com", ns_c_in, ns_t_a, 0x1234, 0, &p, &len);
std::vector<byte> data(p, p + len);
ares_free_string(p);
std::string actual = PacketToString(data);
DNSPacket pkt;
pkt.set_qid(0x1234).add_question(new DNSQuestion("example.com", ns_t_a));
std::string expected = PacketToString(pkt.data());
EXPECT_EQ(expected, actual);
}
TEST_F(LibraryTest, CreateQuery) {
byte* p;
int len;
EXPECT_EQ(ARES_SUCCESS,
ares_create_query("exam\\@le.com", ns_c_in, ns_t_a, 0x1234, 0,
&p, &len, 0));
std::vector<byte> data(p, p + len);
ares_free_string(p);
std::string actual = PacketToString(data);
DNSPacket pkt;
pkt.set_qid(0x1234).add_question(new DNSQuestion("exam@le.com", ns_t_a));
std::string expected = PacketToString(pkt.data());
EXPECT_EQ(expected, actual);
}
TEST_F(LibraryTest, CreateQueryTrailingEscapedDot) {
byte* p;
int len;
EXPECT_EQ(ARES_SUCCESS,
ares_create_query("example.com\\.", ns_c_in, ns_t_a, 0x1234, 0,
&p, &len, 0));
std::vector<byte> data(p, p + len);
( run in 0.657 second using v1.01-cache-2.11-cpan-02777c243ea )