summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-02-09 13:56:16 +0100
committerThomas Haller <thaller@redhat.com>2021-02-10 18:23:44 +0100
commit826d4fd7a9060ca909a7e24f005933575a04124e (patch)
tree99a8e447ae27096dbef4dea477a5f9a33250a960
parentdfddab88ac47ec8a5ac808e94167e98d580c3b09 (diff)
shared/tests: add nmtst_ip_address_new() helper
-rw-r--r--shared/nm-utils/nm-test-utils.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h
index 14446562f4..98e7ba4885 100644
--- a/shared/nm-utils/nm-test-utils.h
+++ b/shared/nm-utils/nm-test-utils.h
@@ -2762,4 +2762,29 @@ nmtst_keyfile_get_num_keys(GKeyFile *keyfile, const char *group_name)
/*****************************************************************************/
+#if defined(NM_SETTING_IP_CONFIG_H) && defined(__NM_SHARED_UTILS_H__)
+
+static inline NMIPAddress *
+nmtst_ip_address_new(int addr_family, const char *str)
+{
+ NMIPAddr addr;
+ int plen;
+ GError * error = NULL;
+ NMIPAddress *a;
+
+ if (!nm_utils_parse_inaddr_prefix_bin(addr_family, str, &addr_family, &addr, &plen))
+ g_assert_not_reached();
+
+ if (plen == -1)
+ plen = addr_family == AF_INET ? 32 : 128;
+
+ a = nm_ip_address_new_binary(addr_family, &addr, plen, &error);
+ nmtst_assert_success(a, error);
+ return a;
+}
+
+#endif
+
+/*****************************************************************************/
+
#endif /* __NM_TEST_UTILS_H__ */