From 09983442bd8be13392876cb8cf4e1564907b07e4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 16 Oct 2015 15:45:48 +0200 Subject: [PATCH] tests: add nmtst_assert_ip4_address() and nmtst_assert_ip6_address() utility method --- include/nm-test-utils.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/include/nm-test-utils.h b/include/nm-test-utils.h index fa795b5a99..22d5fb1bf3 100644 --- a/include/nm-test-utils.h +++ b/include/nm-test-utils.h @@ -688,6 +688,37 @@ nmtst_inet6_from_string (const char *str) return &addr; } +inline static void +_nmtst_assert_ip4_address (const char *file, int line, in_addr_t addr, const char *str_expected) +{ + if (nmtst_inet4_from_string (str_expected) != addr) { + char buf[100]; + + g_error ("%s:%d: Unexpected IPv4 address: expected %s, got %s", + file, line, str_expected ? str_expected : "0.0.0.0", + inet_ntop (AF_INET, &addr, buf, sizeof (buf))); + } +} +#define nmtst_assert_ip4_address(addr, str_expected) _nmtst_assert_ip4_address (__FILE__, __LINE__, addr, str_expected) + +inline static void +_nmtst_assert_ip6_address (const char *file, int line, const struct in6_addr *addr, const char *str_expected) +{ + struct in6_addr any = in6addr_any; + + if (!addr) + addr = &any; + + if (memcmp (nmtst_inet6_from_string (str_expected), addr, sizeof (*addr)) != 0) { + char buf[100]; + + g_error ("%s:%d: Unexpected IPv6 address: expected %s, got %s", + file, line, str_expected ? str_expected : "::", + inet_ntop (AF_INET6, &addr, buf, sizeof (buf))); + } +} +#define nmtst_assert_ip6_address(addr, str_expected) _nmtst_assert_ip6_address (__FILE__, __LINE__, addr, str_expected) + inline static void FAIL(const char *test_name, const char *fmt, ...) {