From 8d6bd2f6c04cccfc50cc27bbe3827486d1bb2558 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 9 Feb 2021 16:24:13 +0100 Subject: [PATCH] shared/tests: add nmtst_rand_perm_strv() helper --- shared/nm-utils/nm-test-utils.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h index 98e7ba4885..6b41c11ee9 100644 --- a/shared/nm-utils/nm-test-utils.h +++ b/shared/nm-utils/nm-test-utils.h @@ -1001,6 +1001,23 @@ nmtst_rand_perm(GRand *rand, void *dst, const void *src, gsize elmt_size, gsize return dst; } +static inline const char ** +nmtst_rand_perm_strv(const char *const *strv) +{ + const char **res; + gsize n; + + if (!strv) + return NULL; + + /* this returns a (scrambled) SHALLOW copy of the strv array! */ + + n = NM_PTRARRAY_LEN(strv); + res = (const char **) (nm_utils_strv_dup(strv, n, FALSE) ?: g_new0(char *, 1)); + nmtst_rand_perm(NULL, res, res, sizeof(char *), n); + return res; +} + static inline GSList * nmtst_rand_perm_gslist(GRand *rand, GSList *list) {