glib-aux/uuid: add NM_UUID_INIT() macro

This commit is contained in:
Thomas Haller 2021-06-05 14:54:04 +02:00
parent 23adeed244
commit 10e5f10f9d
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 49 additions and 0 deletions

View file

@ -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);

View file

@ -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 *