Skip to content

Commit

Permalink
Clean up net_util unit tests for C++.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmoinvaz committed Dec 12, 2023
1 parent b931667 commit fcf393d
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions test/test_net_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@

TEST(net_util, my_ip_address) {
char *address = my_ip_address();
EXPECT_TRUE(address != NULL);
EXPECT_NE(address, nullptr);
if (address) {
EXPECT_TRUE(strstr(address, ".") != NULL);
EXPECT_TRUE(strstr(address, ";") == NULL);
EXPECT_TRUE(strstr(address, ":") == NULL);
EXPECT_NE(strchr(address, '.'), nullptr);
EXPECT_EQ(strpbrk(address, ";:"), nullptr);
free(address);
}
}

TEST(net_util, my_ip_address_ex) {
char *addresses = my_ip_address_ex();
EXPECT_TRUE(addresses != NULL);
EXPECT_NE(addresses, nullptr);
if (addresses) {
EXPECT_TRUE(strstr(addresses, ".") != NULL || strstr(addresses, ":") != NULL);
EXPECT_NE(strpbrk(addresses, ".:"), nullptr);
free(addresses);
}
}
Expand All @@ -31,11 +30,10 @@ TEST(net_util, dns_resolve_google) {
int32_t error = 0;
char *ip = dns_resolve("google.com", &error);
EXPECT_EQ(error, 0);
EXPECT_TRUE(ip != NULL);
EXPECT_NE(ip, nullptr);
if (ip) {
EXPECT_TRUE(strstr(ip, ".") != NULL);
EXPECT_TRUE(strstr(ip, ";") == NULL);
EXPECT_TRUE(strstr(ip, ":") == NULL);
EXPECT_NE(strstr(ip, "."), nullptr);
EXPECT_EQ(strpbrk(ip, ";:"), nullptr);
free(ip);
}
}
Expand All @@ -51,9 +49,9 @@ TEST(net_util, dns_ex_resolve_google) {
int32_t error = 0;
char *ips = dns_resolve_ex("google.com", &error);
EXPECT_EQ(error, 0);
EXPECT_TRUE(ips != NULL);
EXPECT_NE(ips, nullptr);
if (ips) {
EXPECT_TRUE(strstr(ips, ".") != NULL || strstr(ips, ":") != NULL);
EXPECT_NE(strpbrk(ips, ".:"), nullptr);
free(ips);
}
}

0 comments on commit fcf393d

Please sign in to comment.