diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-01-19 11:35:57 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-01-20 08:07:19 +0100 |
commit | d8a3e44a5cf8d61e0e60f4d2b84ab678c628cb89 (patch) | |
tree | 176016b90f48a9db1dc5665709781783c3ff7561 | |
parent | ptyfwd: when leaving a session with tinted background, clear to end of screen (diff) | |
download | systemd-d8a3e44a5cf8d61e0e60f4d2b84ab678c628cb89.tar.xz systemd-d8a3e44a5cf8d61e0e60f4d2b84ab678c628cb89.zip |
test-local-addresses: several modernization
- use size_t for number of addresses,
- use FOREACH_ARRAY() macro,
- use IN_ADDR_TO_STRING() macro, etc.
-rw-r--r-- | src/test/test-local-addresses.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/test/test-local-addresses.c b/src/test/test-local-addresses.c index 5a02465f23..bad47bc088 100644 --- a/src/test/test-local-addresses.c +++ b/src/test/test-local-addresses.c @@ -8,13 +8,11 @@ #include "local-addresses.h" #include "tests.h" -static void print_local_addresses(struct local_address *a, unsigned n) { - for (unsigned i = 0; i < n; i++) { - _cleanup_free_ char *b = NULL; - - assert_se(in_addr_to_string(a[i].family, &a[i].address, &b) >= 0); - log_debug("%s if%i scope=%i metric=%u address=%s", af_to_name(a[i].family), a[i].ifindex, a[i].scope, a[i].metric, b); - } +static void print_local_addresses(const struct local_address *a, size_t n) { + FOREACH_ARRAY(i, a, n) + log_debug("%s ifindex=%i scope=%u metric=%"PRIu32" address=%s", + af_to_name(i->family), i->ifindex, i->scope, i->metric, + IN_ADDR_TO_STRING(i->family, &i->address)); } TEST(local_addresses) { @@ -24,49 +22,49 @@ TEST(local_addresses) { n = local_addresses(NULL, 0, AF_INET, &a); assert_se(n >= 0); log_debug("/* Local Addresses(ifindex:0, AF_INET) */"); - print_local_addresses(a, (unsigned) n); + print_local_addresses(a, n); a = mfree(a); n = local_addresses(NULL, 0, AF_INET6, &a); assert_se(n >= 0); log_debug("/* Local Addresses(ifindex:0, AF_INET6) */"); - print_local_addresses(a, (unsigned) n); + print_local_addresses(a, n); a = mfree(a); n = local_addresses(NULL, 0, AF_UNSPEC, &a); assert_se(n >= 0); log_debug("/* Local Addresses(ifindex:0, AF_UNSPEC) */"); - print_local_addresses(a, (unsigned) n); + print_local_addresses(a, n); a = mfree(a); n = local_addresses(NULL, 1, AF_INET, &a); assert_se(n >= 0); log_debug("/* Local Addresses(ifindex:1, AF_INET) */"); - print_local_addresses(a, (unsigned) n); + print_local_addresses(a, n); a = mfree(a); n = local_addresses(NULL, 1, AF_INET6, &a); assert_se(n >= 0); log_debug("/* Local Addresses(ifindex:1, AF_INET6) */"); - print_local_addresses(a, (unsigned) n); + print_local_addresses(a, n); a = mfree(a); n = local_addresses(NULL, 1, AF_UNSPEC, &a); assert_se(n >= 0); log_debug("/* Local Addresses(ifindex:1, AF_UNSPEC) */"); - print_local_addresses(a, (unsigned) n); + print_local_addresses(a, n); a = mfree(a); n = local_gateways(NULL, 0, AF_UNSPEC, &a); assert_se(n >= 0); log_debug("/* Local Gateways */"); - print_local_addresses(a, (unsigned) n); + print_local_addresses(a, n); a = mfree(a); n = local_outbounds(NULL, 0, AF_UNSPEC, &a); assert_se(n >= 0); log_debug("/* Local Outbounds */"); - print_local_addresses(a, (unsigned) n); + print_local_addresses(a, n); free(a); } |