Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add suite of ipv6 formatting tests, related to #796 #801

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,7 @@ int main(int argc, char *argv[])
x += ranges6_selftest();
x += dedup_selftest();
x += checksum_selftest();
x += ipv4address_selftest();
x += ipv6address_selftest();
x += proto_coap_selftest();
x += smack_selftest();
Expand Down
31 changes: 31 additions & 0 deletions src/massip-addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,37 @@ ipv6address_t ipv6address_add(ipv6address_t lhs, ipv6address_t rhs) {


int ipv6address_selftest(void)
{
struct test_pair {
const char *name; // Human-readable IPv6 address string
struct ipaddress ip_addr; // IP address (union)
};
/* Probably overkill, added while investigating issue #796 */
struct test_pair tests[] = {
{"2001:db8:ac10:fe01::2", {.ipv6 = {0x20010db8ac10fe01, 0x0000000000000002}, .version = 6}},
{"2607:f8b0:4000::1", {.ipv6 = {0x2607f8b040000000, 0x0000000000000001}, .version = 6}},
{"fd12:3456:7890:abcd:ef00::1", {.ipv6 = {0xfd1234567890abcd, 0xef00000000000001}, .version = 6}},
{"::1", {.ipv6 = {0x0000000000000000, 0x0000000000000001}, .version = 6}},
{"1::", {.ipv6 = {0x0001000000000000, 0x0000000000000000}, .version = 6}},
{"1::2", {.ipv6 = {0x0001000000000000, 0x0000000000000002}, .version = 6}},
{"2::1", {.ipv6 = {0x0002000000000000, 0x0000000000000001}, .version = 6}},
{"1:2::", {.ipv6 = {0x0001000200000000, 0x0000000000000000}, .version = 6}},
{NULL, {{0, 0}, 0}}
};

int x = 0;
ipaddress ip;
struct ipaddress_formatted fmt;

for (int i = 0; tests[i].name != NULL; i++) {
fmt = ipaddress_fmt(tests[i].ip_addr);
if (strcmp(fmt.string, tests[i].name) != 0)
x++;
}
return x;
}

int ipv4address_selftest(void)
{
int x = 0;
ipaddress ip;
Expand Down
1 change: 1 addition & 0 deletions src/massip-addr.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,6 @@ unsigned massint128_bitcount(massint128_t num);
* @return 0 on success, 1 on failure
*/
int ipv6address_selftest(void);
int ipv4address_selftest(void);

#endif
Loading