summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-06-05 14:54:04 +0200
committerThomas Haller <thaller@redhat.com>2021-06-08 08:24:13 +0200
commit10e5f10f9d5eddbfb14075c0f35e4955c6c3ab89 (patch)
tree24492b2eee353092dd0d483cd80ab511c66e334f
parent23adeed24463bc3e383c15b1172c932ffa8074eb (diff)
downloadNetworkManager-10e5f10f9d5eddbfb14075c0f35e4955c6c3ab89.tar.gz
glib-aux/uuid: add NM_UUID_INIT() macro
-rw-r--r--src/libnm-core-impl/tests/test-general.c27
-rw-r--r--src/libnm-glib-aux/nm-uuid.h22
2 files changed, 49 insertions, 0 deletions
diff --git a/src/libnm-core-impl/tests/test-general.c b/src/libnm-core-impl/tests/test-general.c
index be0bf3b7ea..dc5780ab00 100644
--- a/src/libnm-core-impl/tests/test-general.c
+++ b/src/libnm-core-impl/tests/test-general.c
@@ -7873,6 +7873,32 @@ test_nm_utils_uuid_generate_from_strings(void)
_test_uuid("dd265bf7-c05a-3037-9939-b9629858a477", "a\0b\0", 4, "a", "b");
}
+static void
+test_nm_uuid_init(void)
+{
+ char buf[37];
+
+ {
+ NMUuid u;
+
+ u = NM_UUID_INIT(47, c4, d7, f9, 2c, 81, 4f, 7b, be, ed, 63, 0a, 7f, 65, cc, 02);
+ g_assert_cmpstr("47c4d7f9-2c81-4f7b-beed-630a7f65cc02", ==, nm_uuid_unparse(&u, buf));
+ }
+ {
+ const NMUuid u =
+ NM_UUID_INIT(47, c4, d7, f9, 2c, 81, 4f, 7b, be, ed, 63, 0a, 7f, 65, cc, 02);
+
+ g_assert_cmpstr("47c4d7f9-2c81-4f7b-beed-630a7f65cc02", ==, nm_uuid_unparse(&u, buf));
+ }
+ {
+ const struct {
+ NMUuid u;
+ } u = {NM_UUID_INIT(47, c4, d7, f9, 2c, 81, 4f, 7b, be, ed, 63, 0a, 7f, 65, cc, 02)};
+
+ g_assert_cmpstr("47c4d7f9-2c81-4f7b-beed-630a7f65cc02", ==, nm_uuid_unparse(&u.u, buf));
+ }
+}
+
/*****************************************************************************/
static void
@@ -10866,6 +10892,7 @@ main(int argc, char **argv)
test_nm_utils_uuid_generate_from_string);
g_test_add_func("/core/general/nm_uuid_generate_from_strings",
test_nm_utils_uuid_generate_from_strings);
+ g_test_add_func("/core/general/test_nm_uuid_init", test_nm_uuid_init);
g_test_add_func("/core/general/_nm_utils_ascii_str_to_int64", test_nm_utils_ascii_str_to_int64);
g_test_add_func("/core/general/nm_utils_is_power_of_two", test_nm_utils_is_power_of_two);
diff --git a/src/libnm-glib-aux/nm-uuid.h b/src/libnm-glib-aux/nm-uuid.h
index 10302bd87a..fb0f6780a2 100644
--- a/src/libnm-glib-aux/nm-uuid.h
+++ b/src/libnm-glib-aux/nm-uuid.h
@@ -7,6 +7,28 @@ typedef struct _NMUuid {
guint8 uuid[16];
} NMUuid;
+#define NM_UUID_INIT_ZERO() ((NMUuid){.uuid = {0}})
+
+#define NM_UUID_INIT(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) \
+ ((NMUuid){ \
+ .uuid = {(0x##a0), \
+ (0x##a1), \
+ (0x##a2), \
+ (0x##a3), \
+ (0x##a4), \
+ (0x##a5), \
+ (0x##a6), \
+ (0x##a7), \
+ (0x##a8), \
+ (0x##a9), \
+ (0x##a10), \
+ (0x##a11), \
+ (0x##a12), \
+ (0x##a13), \
+ (0x##a14), \
+ (0x##a15)}, \
+ })
+
char *nm_uuid_unparse_case(const NMUuid *uuid, char out_str[static 37], gboolean upper_case);
static inline char *