diff options
| author | Michael Biebl <biebl@debian.org> | 2022-01-13 22:30:39 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2022-01-13 22:30:39 +0100 |
| commit | 88c227d90a6b7b388c5c85d72802a0ca8f05ed5c (patch) | |
| tree | 71f32df6617802270e8a78574bd8e1637dc532f4 /src/libnm-core-impl/tests | |
| parent | e74c568b07b50b97873fb4ee1d776dedefbd54d6 (diff) | |
New upstream version 1.34.0 upstream/1.34.0
Diffstat (limited to 'src/libnm-core-impl/tests')
| -rw-r--r-- | src/libnm-core-impl/tests/test-crypto.c | 2 | ||||
| -rw-r--r-- | src/libnm-core-impl/tests/test-general.c | 618 | ||||
| -rw-r--r-- | src/libnm-core-impl/tests/test-keyfile.c | 4 | ||||
| -rw-r--r-- | src/libnm-core-impl/tests/test-setting.c | 504 |
4 files changed, 808 insertions, 320 deletions
diff --git a/src/libnm-core-impl/tests/test-crypto.c b/src/libnm-core-impl/tests/test-crypto.c index bdbcd0f3..1c072f71 100644 --- a/src/libnm-core-impl/tests/test-crypto.c +++ b/src/libnm-core-impl/tests/test-crypto.c @@ -135,7 +135,7 @@ test_load_private_key(const char *path, /* Compare the crypto decrypted key against a known-good decryption */ if (!g_file_get_contents(decrypted_path, &contents, &length, NULL)) g_assert_not_reached(); - g_assert(nm_utils_gbytes_equal_mem(array, contents, length)); + g_assert(nm_g_bytes_equal_mem(array, contents, length)); } } diff --git a/src/libnm-core-impl/tests/test-general.c b/src/libnm-core-impl/tests/test-general.c index 57864948..5c831cb7 100644 --- a/src/libnm-core-impl/tests/test-general.c +++ b/src/libnm-core-impl/tests/test-general.c @@ -478,6 +478,38 @@ test_nm_hash(void) g_assert_cmpint(NM_HASH_COMBINE_BOOLS(guint16, 0, 0, 1, 1, 0, 0, 0, 1), ==, 0x031); g_assert_cmpint(NM_HASH_COMBINE_BOOLS(guint16, 0, 0, 0, 1, 1, 0, 0, 0, 1), ==, 0x031); g_assert_cmpint(NM_HASH_COMBINE_BOOLS(guint16, 1, 0, 0, 1, 1, 0, 0, 0, 1), ==, 0x131); + g_assert_cmpint(NM_HASH_COMBINE_BOOLS(guint16, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1), + ==, + 0x131); + g_assert_cmpint(NM_HASH_COMBINE_BOOLS(guint16, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1), + ==, + 0x8131); + g_assert_cmpint( + NM_HASH_COMBINE_BOOLS(guint32, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1), + ==, + 0x8131); + g_assert_cmpint( + NM_HASH_COMBINE_BOOLS(guint32, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1), + ==, + 0x28131); + +#if _NM_CC_SUPPORT_AUTO_TYPE + { + _nm_auto_type x = NM_HASH_COMBINE_BOOLS(guint8, 0, 0, 1, 1, 0, 0, 0, 1); + + G_STATIC_ASSERT(sizeof(x) == 1); + g_assert(((typeof(x)) -1) > 0); + } + + { + _nm_auto_type x = NM_HASH_COMBINE_BOOLS(guint16, 0, 0, 1, 1, 0, 0, 0, 1); + + G_STATIC_ASSERT(sizeof(x) == 2); + g_assert(((typeof(x)) -1) > 0); + } +#endif + + NM_STATIC_ASSERT_EXPR_VOID(NM_HASH_COMBINE_BOOLS(int, 1, 0, 1) == 5); } /*****************************************************************************/ @@ -510,27 +542,25 @@ test_nm_g_slice_free_fcn(void) /*****************************************************************************/ static void -_do_test_nm_utils_strsplit_set_f_one(NMUtilsStrsplitSetFlags flags, - const char * str, - gsize words_len, - const char *const * exp_words) +_do_test_nm_strsplit_set_f_one(NMUtilsStrsplitSetFlags flags, + const char * str, + gsize words_len, + const char *const * exp_words) { #define DELIMITERS " \n" #define DELIMITERS_C ' ', '\n' gs_free const char **words = NULL; gsize i, j, k; - const gboolean f_allow_escaping = - NM_FLAGS_HAS(flags, NM_UTILS_STRSPLIT_SET_FLAGS_ALLOW_ESCAPING); - const gboolean f_preserve_empty = - NM_FLAGS_HAS(flags, NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY); + const gboolean f_allow_escaping = NM_FLAGS_HAS(flags, NM_STRSPLIT_SET_FLAGS_ALLOW_ESCAPING); + const gboolean f_preserve_empty = NM_FLAGS_HAS(flags, NM_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY); const char * s1; gsize initial_offset; gs_strfreev char **words_g = NULL; - g_assert(!NM_FLAGS_ANY(flags, - ~(NM_UTILS_STRSPLIT_SET_FLAGS_ALLOW_ESCAPING - | NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY))); + g_assert(!NM_FLAGS_ANY( + flags, + ~(NM_STRSPLIT_SET_FLAGS_ALLOW_ESCAPING | NM_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY))); /* assert that the expected words are valid (and don't contain unescaped delimiters). */ for (i = 0; i < words_len; i++) { @@ -587,16 +617,16 @@ _do_test_nm_utils_strsplit_set_f_one(NMUtilsStrsplitSetFlags flags, } g_assert(words_g[words_len] == NULL); g_assert_cmpint(NM_PTRARRAY_LEN(words_g), ==, words_len); - g_assert(nm_utils_strv_cmp_n(exp_words, words_len, words_g, -1) == 0); + g_assert(nm_strv_cmp_n(exp_words, words_len, words_g, -1) == 0); } } - if (flags == NM_UTILS_STRSPLIT_SET_FLAGS_NONE && nmtst_get_rand_bool()) - words = nm_utils_strsplit_set(str, DELIMITERS); - else if (flags == NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY && nmtst_get_rand_bool()) - words = nm_utils_strsplit_set_with_empty(str, DELIMITERS); + if (flags == NM_STRSPLIT_SET_FLAGS_NONE && nmtst_get_rand_bool()) + words = nm_strsplit_set(str, DELIMITERS); + else if (flags == NM_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY && nmtst_get_rand_bool()) + words = nm_strsplit_set_with_empty(str, DELIMITERS); else - words = nm_utils_strsplit_set_full(str, DELIMITERS, flags); + words = nm_strsplit_set_full(str, DELIMITERS, flags); g_assert_cmpint(NM_PTRARRAY_LEN(words), ==, words_len); @@ -611,7 +641,7 @@ _do_test_nm_utils_strsplit_set_f_one(NMUtilsStrsplitSetFlags flags, g_assert_cmpstr(exp_words[i], ==, words[i]); g_assert(words[words_len] == NULL); - g_assert(nm_utils_strv_cmp_n(exp_words, words_len, words, -1) == 0); + g_assert(nm_strv_cmp_n(exp_words, words_len, words, -1) == 0); s1 = words[0]; g_assert(s1 >= (char *) &words[words_len + 1]); @@ -719,14 +749,14 @@ _do_test_nm_utils_strsplit_set_f_one(NMUtilsStrsplitSetFlags flags, } static void -_do_test_nm_utils_strsplit_set_f(NMUtilsStrsplitSetFlags flags, - const char * str, - gsize words_len, - const char *const * exp_words) +_do_test_nm_strsplit_set_f(NMUtilsStrsplitSetFlags flags, + const char * str, + gsize words_len, + const char *const * exp_words) { - _do_test_nm_utils_strsplit_set_f_one(flags, str, words_len, exp_words); + _do_test_nm_strsplit_set_f_one(flags, str, words_len, exp_words); - if (NM_FLAGS_HAS(flags, NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY)) { + if (NM_FLAGS_HAS(flags, NM_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY)) { gs_unref_ptrarray GPtrArray *exp_words2 = NULL; gsize k; @@ -736,32 +766,32 @@ _do_test_nm_utils_strsplit_set_f(NMUtilsStrsplitSetFlags flags, g_ptr_array_add(exp_words2, (gpointer) exp_words[k]); } - _do_test_nm_utils_strsplit_set_f_one(flags & (~NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY), - str, - exp_words2->len, - (const char *const *) exp_words2->pdata); + _do_test_nm_strsplit_set_f_one(flags & (~NM_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY), + str, + exp_words2->len, + (const char *const *) exp_words2->pdata); } } -#define do_test_nm_utils_strsplit_set_f(flags, str, ...) \ - _do_test_nm_utils_strsplit_set_f(flags, str, NM_NARG(__VA_ARGS__), NM_MAKE_STRV(__VA_ARGS__)) +#define do_test_nm_strsplit_set_f(flags, str, ...) \ + _do_test_nm_strsplit_set_f(flags, str, NM_NARG(__VA_ARGS__), NM_MAKE_STRV(__VA_ARGS__)) -#define do_test_nm_utils_strsplit_set(allow_escaping, str, ...) \ - do_test_nm_utils_strsplit_set_f((allow_escaping) ? NM_UTILS_STRSPLIT_SET_FLAGS_ALLOW_ESCAPING \ - : NM_UTILS_STRSPLIT_SET_FLAGS_NONE, \ - str, \ - ##__VA_ARGS__) +#define do_test_nm_strsplit_set(allow_escaping, str, ...) \ + do_test_nm_strsplit_set_f((allow_escaping) ? NM_STRSPLIT_SET_FLAGS_ALLOW_ESCAPING \ + : NM_STRSPLIT_SET_FLAGS_NONE, \ + str, \ + ##__VA_ARGS__) static void -_do_test_nm_utils_strsplit_set_simple(NMUtilsStrsplitSetFlags flags, - const char * str, - gsize words_len, - const char *const * exp_words) +_do_test_nm_strsplit_set_simple(NMUtilsStrsplitSetFlags flags, + const char * str, + gsize words_len, + const char *const * exp_words) { gs_free const char **tokens = NULL; gsize n_tokens; - tokens = nm_utils_strsplit_set_full(str, DELIMITERS, flags); + tokens = nm_strsplit_set_full(str, DELIMITERS, flags); if (!tokens) { g_assert_cmpint(words_len, ==, 0); @@ -772,7 +802,7 @@ _do_test_nm_utils_strsplit_set_simple(NMUtilsStrsplitSetFlags flags, g_assert_cmpint(words_len, >, 0); n_tokens = NM_PTRARRAY_LEN(tokens); - if (nm_utils_strv_cmp_n(exp_words, words_len, tokens, -1) != 0) { + if (nm_strv_cmp_n(exp_words, words_len, tokens, -1) != 0) { gsize i; g_print(">>> split \"%s\" (flags %x) got %zu tokens (%zu expected)\n", @@ -794,107 +824,87 @@ _do_test_nm_utils_strsplit_set_simple(NMUtilsStrsplitSetFlags flags, } g_assert_cmpint(words_len, ==, NM_PTRARRAY_LEN(tokens)); } -#define do_test_nm_utils_strsplit_set_simple(flags, str, ...) \ - _do_test_nm_utils_strsplit_set_simple((flags), \ - (str), \ - NM_NARG(__VA_ARGS__), \ - NM_MAKE_STRV(__VA_ARGS__)) +#define do_test_nm_strsplit_set_simple(flags, str, ...) \ + _do_test_nm_strsplit_set_simple((flags), (str), NM_NARG(__VA_ARGS__), NM_MAKE_STRV(__VA_ARGS__)) static void -test_nm_utils_strsplit_set(void) +test_nm_strsplit_set(void) { gs_unref_ptrarray GPtrArray *words_exp = NULL; guint test_run; - do_test_nm_utils_strsplit_set_f(NM_UTILS_STRSPLIT_SET_FLAGS_NONE, NULL); - do_test_nm_utils_strsplit_set_f(NM_UTILS_STRSPLIT_SET_FLAGS_NONE, ""); - do_test_nm_utils_strsplit_set_f(NM_UTILS_STRSPLIT_SET_FLAGS_NONE, " "); - do_test_nm_utils_strsplit_set_f(NM_UTILS_STRSPLIT_SET_FLAGS_NONE, "a b", "a", "b"); - - do_test_nm_utils_strsplit_set_f(NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, NULL); - do_test_nm_utils_strsplit_set_f(NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, ""); - do_test_nm_utils_strsplit_set_f(NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, " ", "", ""); - do_test_nm_utils_strsplit_set_f(NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, " ", "", "", ""); - do_test_nm_utils_strsplit_set_f(NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, "a ", "a", "", ""); - do_test_nm_utils_strsplit_set_f(NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, - "a b", - "a", - "", - "b"); - do_test_nm_utils_strsplit_set_f(NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, - " ab b", - "", - "ab", - "", - "b"); - do_test_nm_utils_strsplit_set_f(NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, - "ab b", - "ab", - "", - "b"); - do_test_nm_utils_strsplit_set_f(NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, "abb", "abb"); - do_test_nm_utils_strsplit_set_f(NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, - "abb bb ", - "abb", - "", - "bb", - ""); - do_test_nm_utils_strsplit_set_f(NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, - "abb bcb ", - "abb", - "bcb", - ""); - - do_test_nm_utils_strsplit_set(FALSE, NULL); - do_test_nm_utils_strsplit_set(FALSE, ""); - do_test_nm_utils_strsplit_set(FALSE, "\n"); - do_test_nm_utils_strsplit_set(TRUE, " \t\n", "\t"); - do_test_nm_utils_strsplit_set(FALSE, "a", "a"); - do_test_nm_utils_strsplit_set(FALSE, "a b", "a", "b"); - do_test_nm_utils_strsplit_set(FALSE, "a\rb", "a\rb"); - do_test_nm_utils_strsplit_set(FALSE, " a\rb ", "a\rb"); - do_test_nm_utils_strsplit_set(FALSE, " a bbbd afds ere", "a", "bbbd", "afds", "ere"); - do_test_nm_utils_strsplit_set(FALSE, - "1 2 3 4 5 6 7 8 9 0 " - "1 2 3 4 5 6 7 8 9 0 " - "1 2 3 4 5 6 7 8 9 0", - "1", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9", - "0", - "1", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9", - "0", - "1", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9", - "0"); - do_test_nm_utils_strsplit_set(TRUE, "\\", "\\"); - do_test_nm_utils_strsplit_set(TRUE, "\\ ", "\\ "); - do_test_nm_utils_strsplit_set(TRUE, "\\\\", "\\\\"); - do_test_nm_utils_strsplit_set(TRUE, "\\\t", "\\\t"); - do_test_nm_utils_strsplit_set(TRUE, "foo\\", "foo\\"); - do_test_nm_utils_strsplit_set(TRUE, "bar foo\\", "bar", "foo\\"); - do_test_nm_utils_strsplit_set(TRUE, "\\ a b\\ \\ c", "\\ a", "b\\ \\ ", "c"); + do_test_nm_strsplit_set_f(NM_STRSPLIT_SET_FLAGS_NONE, NULL); + do_test_nm_strsplit_set_f(NM_STRSPLIT_SET_FLAGS_NONE, ""); + do_test_nm_strsplit_set_f(NM_STRSPLIT_SET_FLAGS_NONE, " "); + do_test_nm_strsplit_set_f(NM_STRSPLIT_SET_FLAGS_NONE, "a b", "a", "b"); + + do_test_nm_strsplit_set_f(NM_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, NULL); + do_test_nm_strsplit_set_f(NM_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, ""); + do_test_nm_strsplit_set_f(NM_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, " ", "", ""); + do_test_nm_strsplit_set_f(NM_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, " ", "", "", ""); + do_test_nm_strsplit_set_f(NM_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, "a ", "a", "", ""); + do_test_nm_strsplit_set_f(NM_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, "a b", "a", "", "b"); + do_test_nm_strsplit_set_f(NM_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, " ab b", "", "ab", "", "b"); + do_test_nm_strsplit_set_f(NM_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, "ab b", "ab", "", "b"); + do_test_nm_strsplit_set_f(NM_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, "abb", "abb"); + do_test_nm_strsplit_set_f(NM_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, + "abb bb ", + "abb", + "", + "bb", + ""); + do_test_nm_strsplit_set_f(NM_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, "abb bcb ", "abb", "bcb", ""); + + do_test_nm_strsplit_set(FALSE, NULL); + do_test_nm_strsplit_set(FALSE, ""); + do_test_nm_strsplit_set(FALSE, "\n"); + do_test_nm_strsplit_set(TRUE, " \t\n", "\t"); + do_test_nm_strsplit_set(FALSE, "a", "a"); + do_test_nm_strsplit_set(FALSE, "a b", "a", "b"); + do_test_nm_strsplit_set(FALSE, "a\rb", "a\rb"); + do_test_nm_strsplit_set(FALSE, " a\rb ", "a\rb"); + do_test_nm_strsplit_set(FALSE, " a bbbd afds ere", "a", "bbbd", "afds", "ere"); + do_test_nm_strsplit_set(FALSE, + "1 2 3 4 5 6 7 8 9 0 " + "1 2 3 4 5 6 7 8 9 0 " + "1 2 3 4 5 6 7 8 9 0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "0"); + do_test_nm_strsplit_set(TRUE, "\\", "\\"); + do_test_nm_strsplit_set(TRUE, "\\ ", "\\ "); + do_test_nm_strsplit_set(TRUE, "\\\\", "\\\\"); + do_test_nm_strsplit_set(TRUE, "\\\t", "\\\t"); + do_test_nm_strsplit_set(TRUE, "foo\\", "foo\\"); + do_test_nm_strsplit_set(TRUE, "bar foo\\", "bar", "foo\\"); + do_test_nm_strsplit_set(TRUE, "\\ a b\\ \\ c", "\\ a", "b\\ \\ ", "c"); words_exp = g_ptr_array_new_with_free_func(g_free); for (test_run = 0; test_run < 100; test_run++) { @@ -942,52 +952,40 @@ test_nm_utils_strsplit_set(void) words_len = 0; } - _do_test_nm_utils_strsplit_set_f((f_allow_escaping - ? NM_UTILS_STRSPLIT_SET_FLAGS_ALLOW_ESCAPING - : NM_UTILS_STRSPLIT_SET_FLAGS_NONE) - | NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, - str, - words_len, - (const char *const *) words_exp->pdata); + _do_test_nm_strsplit_set_f( + (f_allow_escaping ? NM_STRSPLIT_SET_FLAGS_ALLOW_ESCAPING : NM_STRSPLIT_SET_FLAGS_NONE) + | NM_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, + str, + words_len, + (const char *const *) words_exp->pdata); } - do_test_nm_utils_strsplit_set_simple(NM_UTILS_STRSPLIT_SET_FLAGS_ESCAPED, "\t", "\t"); - do_test_nm_utils_strsplit_set_simple(NM_UTILS_STRSPLIT_SET_FLAGS_ESCAPED - | NM_UTILS_STRSPLIT_SET_FLAGS_STRSTRIP, - "\t"); - do_test_nm_utils_strsplit_set_simple(NM_UTILS_STRSPLIT_SET_FLAGS_ESCAPED - | NM_UTILS_STRSPLIT_SET_FLAGS_STRSTRIP - | NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, - "\t", - ""); - do_test_nm_utils_strsplit_set_simple(NM_UTILS_STRSPLIT_SET_FLAGS_ESCAPED - | NM_UTILS_STRSPLIT_SET_FLAGS_STRSTRIP - | NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, - "\t\\\t\t\t\\\t", - "\t\t\t\t"); - - do_test_nm_utils_strsplit_set_simple(NM_UTILS_STRSPLIT_SET_FLAGS_ESCAPED, "\ta", "\ta"); - do_test_nm_utils_strsplit_set_simple(NM_UTILS_STRSPLIT_SET_FLAGS_ESCAPED - | NM_UTILS_STRSPLIT_SET_FLAGS_STRSTRIP, - "\ta", - "a"); - do_test_nm_utils_strsplit_set_simple(NM_UTILS_STRSPLIT_SET_FLAGS_ESCAPED, - "\ta\\ b\t\\ ", - "\ta b\t "); - do_test_nm_utils_strsplit_set_simple(NM_UTILS_STRSPLIT_SET_FLAGS_ESCAPED - | NM_UTILS_STRSPLIT_SET_FLAGS_STRSTRIP, - "\ta\\ b\t\\ \t", - "a b\t "); - do_test_nm_utils_strsplit_set_simple(NM_UTILS_STRSPLIT_SET_FLAGS_ESCAPED, "a\\ b", "a ", "b"); - do_test_nm_utils_strsplit_set_simple(NM_UTILS_STRSPLIT_SET_FLAGS_ESCAPED, - "\ta\\ b", - "\ta ", - "b"); - do_test_nm_utils_strsplit_set_simple(NM_UTILS_STRSPLIT_SET_FLAGS_ESCAPED - | NM_UTILS_STRSPLIT_SET_FLAGS_STRSTRIP, - "\ta\\ b", - "a ", - "b"); + do_test_nm_strsplit_set_simple(NM_STRSPLIT_SET_FLAGS_ESCAPED, "\t", "\t"); + do_test_nm_strsplit_set_simple(NM_STRSPLIT_SET_FLAGS_ESCAPED | NM_STRSPLIT_SET_FLAGS_STRSTRIP, + "\t"); + do_test_nm_strsplit_set_simple(NM_STRSPLIT_SET_FLAGS_ESCAPED | NM_STRSPLIT_SET_FLAGS_STRSTRIP + | NM_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, + "\t", + ""); + do_test_nm_strsplit_set_simple(NM_STRSPLIT_SET_FLAGS_ESCAPED | NM_STRSPLIT_SET_FLAGS_STRSTRIP + | NM_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, + "\t\\\t\t\t\\\t", + "\t\t\t\t"); + + do_test_nm_strsplit_set_simple(NM_STRSPLIT_SET_FLAGS_ESCAPED, "\ta", "\ta"); + do_test_nm_strsplit_set_simple(NM_STRSPLIT_SET_FLAGS_ESCAPED | NM_STRSPLIT_SET_FLAGS_STRSTRIP, + "\ta", + "a"); + do_test_nm_strsplit_set_simple(NM_STRSPLIT_SET_FLAGS_ESCAPED, "\ta\\ b\t\\ ", "\ta b\t "); + do_test_nm_strsplit_set_simple(NM_STRSPLIT_SET_FLAGS_ESCAPED | NM_STRSPLIT_SET_FLAGS_STRSTRIP, + "\ta\\ b\t\\ \t", + "a b\t "); + do_test_nm_strsplit_set_simple(NM_STRSPLIT_SET_FLAGS_ESCAPED, "a\\ b", "a ", "b"); + do_test_nm_strsplit_set_simple(NM_STRSPLIT_SET_FLAGS_ESCAPED, "\ta\\ b", "\ta ", "b"); + do_test_nm_strsplit_set_simple(NM_STRSPLIT_SET_FLAGS_ESCAPED | NM_STRSPLIT_SET_FLAGS_STRSTRIP, + "\ta\\ b", + "a ", + "b"); } /*****************************************************************************/ @@ -3062,8 +3060,7 @@ test_setting_new_from_dbus_bad(void) "i", 10);); conn = _connection_new_from_dbus(dict, &error); - g_assert(conn); - g_assert_no_error(error); + nmtst_assert_success(conn, error); setting = nm_connection_get_setting(conn, NM_TYPE_SETTING_WIRELESS); g_assert(setting); g_assert_cmpint(nm_setting_wireless_get_rate(NM_SETTING_WIRELESS(setting)), ==, 10); @@ -3823,6 +3820,7 @@ test_connection_diff_a_only(void) {NM_SETTING_CONNECTION_AUTH_RETRIES, NM_SETTING_DIFF_RESULT_IN_A}, {NM_SETTING_CONNECTION_MDNS, NM_SETTING_DIFF_RESULT_IN_A}, {NM_SETTING_CONNECTION_LLMNR, NM_SETTING_DIFF_RESULT_IN_A}, + {NM_SETTING_CONNECTION_DNS_OVER_TLS, NM_SETTING_DIFF_RESULT_IN_A}, {NM_SETTING_CONNECTION_MUD_URL, NM_SETTING_DIFF_RESULT_IN_A}, {NM_SETTING_CONNECTION_WAIT_DEVICE_TIMEOUT, NM_SETTING_DIFF_RESULT_IN_A}, {NULL, NM_SETTING_DIFF_RESULT_UNKNOWN}}}, @@ -5016,7 +5014,7 @@ test_connection_changed_signal(void) connection = new_test_connection(); g_signal_connect(connection, NM_CONNECTION_CHANGED, - (GCallback) test_connection_changed_cb, + G_CALLBACK(test_connection_changed_cb), &changed); /* Add new setting */ @@ -5042,7 +5040,7 @@ test_setting_connection_changed_signal(void) connection = nm_simple_connection_new(); g_signal_connect(connection, NM_CONNECTION_CHANGED, - (GCallback) test_connection_changed_cb, + G_CALLBACK(test_connection_changed_cb), &changed); s_con = (NMSettingConnection *) nm_setting_connection_new(); @@ -5078,7 +5076,7 @@ test_setting_bond_changed_signal(void) connection = nm_simple_connection_new(); g_signal_connect(connection, NM_CONNECTION_CHANGED, - (GCallback) test_connection_changed_cb, + G_CALLBACK(test_connection_changed_cb), &changed); s_bond = (NMSettingBond *) nm_setting_bond_new(); @@ -5104,7 +5102,7 @@ test_setting_ip4_changed_signal(void) connection = nm_simple_connection_new(); g_signal_connect(connection, NM_CONNECTION_CHANGED, - (GCallback) test_connection_changed_cb, + G_CALLBACK(test_connection_changed_cb), &changed); s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); @@ -5180,7 +5178,7 @@ test_setting_ip6_changed_signal(void) connection = nm_simple_connection_new(); g_signal_connect(connection, NM_CONNECTION_CHANGED, - (GCallback) test_connection_changed_cb, + G_CALLBACK(test_connection_changed_cb), &changed); s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); @@ -5247,7 +5245,7 @@ test_setting_vlan_changed_signal(void) connection = nm_simple_connection_new(); g_signal_connect(connection, NM_CONNECTION_CHANGED, - (GCallback) test_connection_changed_cb, + G_CALLBACK(test_connection_changed_cb), &changed); s_vlan = (NMSettingVlan *) nm_setting_vlan_new(); @@ -5282,7 +5280,7 @@ test_setting_vpn_changed_signal(void) connection = nm_simple_connection_new(); g_signal_connect(connection, NM_CONNECTION_CHANGED, - (GCallback) test_connection_changed_cb, + G_CALLBACK(test_connection_changed_cb), &changed); s_vpn = (NMSettingVpn *) nm_setting_vpn_new(); @@ -5309,7 +5307,7 @@ test_setting_wired_changed_signal(void) connection = nm_simple_connection_new(); g_signal_connect(connection, NM_CONNECTION_CHANGED, - (GCallback) test_connection_changed_cb, + G_CALLBACK(test_connection_changed_cb), &changed); s_wired = (NMSettingWired *) nm_setting_wired_new(); @@ -5332,7 +5330,7 @@ test_setting_wireless_changed_signal(void) connection = nm_simple_connection_new(); g_signal_connect(connection, NM_CONNECTION_CHANGED, - (GCallback) test_connection_changed_cb, + G_CALLBACK(test_connection_changed_cb), &changed); s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); @@ -5353,7 +5351,7 @@ test_setting_wireless_security_changed_signal(void) connection = nm_simple_connection_new(); g_signal_connect(connection, NM_CONNECTION_CHANGED, - (GCallback) test_connection_changed_cb, + G_CALLBACK(test_connection_changed_cb), &changed); s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); @@ -5420,7 +5418,7 @@ test_setting_802_1x_changed_signal(void) connection = nm_simple_connection_new(); g_signal_connect(connection, NM_CONNECTION_CHANGED, - (GCallback) test_connection_changed_cb, + G_CALLBACK(test_connection_changed_cb), &changed); s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); @@ -7121,7 +7119,7 @@ test_hexstr2bin(void) g_assert(b); else g_assert(!b); - g_assert(nm_utils_gbytes_equal_mem(b, items[i].expected, items[i].expected_len)); + g_assert(nm_g_bytes_equal_mem(b, items[i].expected, items[i].expected_len)); } } @@ -7209,11 +7207,10 @@ test_nm_strquote(void) /*****************************************************************************/ -#define UUID_NS_ZERO "00000000-0000-0000-0000-000000000000" -#define UUID_NS_DNS "6ba7b810-9dad-11d1-80b4-00c04fd430c8" -#define UUID_NS_URL "6ba7b811-9dad-11d1-80b4-00c04fd430c8" -#define UUID_NS_OID "6ba7b812-9dad-11d1-80b4-00c04fd430c8" -#define UUID_NS_X500 "6ba7b814-9dad-11d1-80b4-00c04fd430c8" +#define NM_UUID_NS_DNS "6ba7b810-9dad-11d1-80b4-00c04fd430c8" +#define NM_UUID_NS_URL "6ba7b811-9dad-11d1-80b4-00c04fd430c8" +#define NM_UUID_NS_OID "6ba7b812-9dad-11d1-80b4-00c04fd430c8" +#define NM_UUID_NS_X500 "6ba7b814-9dad-11d1-80b4-00c04fd430c8" static const NMUuid * _uuid(const char *str) @@ -7230,11 +7227,18 @@ _test_uuid(int uuid_type, const char *expected_uuid, const char *str, gssize slen, - gpointer type_args) + const char *type_args) { - gs_free char *uuid_test = NULL; + gs_free char *uuid_test = NULL; + NMUuid type_args_u = NM_UUID_INIT_ZERO(); - uuid_test = nm_uuid_generate_from_string_str(str, slen, uuid_type, type_args); + if (type_args) { + if (!nm_uuid_parse(type_args, &type_args_u)) + g_assert_not_reached(); + } + + uuid_test = + nm_uuid_generate_from_string_str(str, slen, uuid_type, type_args ? &type_args_u : NULL); g_assert(uuid_test); g_assert(nm_utils_is_uuid(uuid_test)); @@ -7245,7 +7249,7 @@ _test_uuid(int uuid_type, str, (long long) slen, NM_IN_SET(uuid_type, NM_UUID_TYPE_VERSION3, NM_UUID_TYPE_VERSION5) - ? (((const char *) type_args) ?: "(all-zero)") + ? (type_args ?: "(all-zero)") : (type_args ? "(unknown)" : "(null)"), uuid_test, expected_uuid); @@ -7260,8 +7264,8 @@ _test_uuid(int uuid_type, } if (NM_IN_SET(uuid_type, NM_UUID_TYPE_VERSION3, NM_UUID_TYPE_VERSION5) && !type_args) { - /* For version3 and version5, a missing @type_args is equal to UUID_NS_ZERO */ - _test_uuid(uuid_type, expected_uuid, str, slen, UUID_NS_ZERO); + /* For version3 and version5, a missing @type_args is equal to NM_UUID_NS_ZERO */ + _test_uuid(uuid_type, expected_uuid, str, slen, NM_UUID_NS_ZERO); } } @@ -7695,33 +7699,53 @@ test_nm_utils_uuid_generate_from_string(void) _test_uuid(NM_UUID_TYPE_VERSION3, "96e17d7a-ac89-38cf-95e1-bf5098da34e1", "test", -1, NULL); _test_uuid(NM_UUID_TYPE_VERSION3, "8156568e-4ae6-3f34-a93e-18e2c6cbbf78", "a\0b", 3, NULL); - _test_uuid(NM_UUID_TYPE_VERSION3, "c87ee674-4ddc-3efe-a74e-dfe25da5d7b3", "", -1, UUID_NS_DNS); - _test_uuid(NM_UUID_TYPE_VERSION3, "4c104dd0-4821-30d5-9ce3-0e7a1f8b7c0d", "a", -1, UUID_NS_DNS); + _test_uuid(NM_UUID_TYPE_VERSION3, + "c87ee674-4ddc-3efe-a74e-dfe25da5d7b3", + "", + -1, + NM_UUID_NS_DNS); + _test_uuid(NM_UUID_TYPE_VERSION3, + "4c104dd0-4821-30d5-9ce3-0e7a1f8b7c0d", + "a", + -1, + NM_UUID_NS_DNS); _test_uuid(NM_UUID_TYPE_VERSION3, "45a113ac-c7f2-30b0-90a5-a399ab912716", "test", -1, - UUID_NS_DNS); + NM_UUID_NS_DNS); _test_uuid(NM_UUID_TYPE_VERSION3, "002a0ada-f547-375a-bab5-896a11d1927e", "a\0b", 3, - UUID_NS_DNS); + NM_UUID_NS_DNS); _test_uuid(NM_UUID_TYPE_VERSION3, "9a75f5f2-195e-31a9-9d07-8c18b5d3b285", "test123", -1, - UUID_NS_DNS); - _test_uuid(NM_UUID_TYPE_VERSION3, "ec794efe-a384-3b11-a0b6-ec8995bc6acc", "x", -1, UUID_NS_DNS); + NM_UUID_NS_DNS); + _test_uuid(NM_UUID_TYPE_VERSION3, + "ec794efe-a384-3b11-a0b6-ec8995bc6acc", + "x", + -1, + NM_UUID_NS_DNS); _test_uuid(NM_UUID_TYPE_VERSION5, "a7650b9f-f19f-5300-8a13-91160ea8de2c", "a\0b", 3, NULL); - _test_uuid(NM_UUID_TYPE_VERSION5, "4f3f2898-69e3-5a0d-820a-c4e87987dbce", "a", -1, UUID_NS_DNS); - _test_uuid(NM_UUID_TYPE_VERSION5, "05b16a01-46c6-56dd-bd6e-c6dfb4a1427a", "x", -1, UUID_NS_DNS); + _test_uuid(NM_UUID_TYPE_VERSION5, + "4f3f2898-69e3-5a0d-820a-c4e87987dbce", + "a", + -1, + NM_UUID_NS_DNS); + _test_uuid(NM_UUID_TYPE_VERSION5, + "05b16a01-46c6-56dd-bd6e-c6dfb4a1427a", + "x", + -1, + NM_UUID_NS_DNS); _test_uuid(NM_UUID_TYPE_VERSION5, "c9ed566a-6b79-5d3a-b2b7-96a936b48cf3", "test123", -1, - UUID_NS_DNS); + NM_UUID_NS_DNS); for (i = 0; i < G_N_ELEMENTS(zero_uuids); i++) { nm_sprintf_buf(i_str, "%u", i), @@ -7730,8 +7754,8 @@ test_nm_utils_uuid_generate_from_string(void) } for (i = 0; i < G_N_ELEMENTS(dns_uuids); i++) { nm_sprintf_buf(i_str, "%u", i), - _test_uuid(NM_UUID_TYPE_VERSION3, dns_uuids[i].uuid3, i_str, -1, UUID_NS_DNS); - _test_uuid(NM_UUID_TYPE_VERSION5, dns_uuids[i].uuid5, i_str, -1, UUID_NS_DNS); + _test_uuid(NM_UUID_TYPE_VERSION3, dns_uuids[i].uuid3, i_str, -1, NM_UUID_NS_DNS); + _test_uuid(NM_UUID_TYPE_VERSION5, dns_uuids[i].uuid5, i_str, -1, NM_UUID_NS_DNS); } /* examples from cpython unit tests: */ @@ -7739,48 +7763,48 @@ test_nm_utils_uuid_generate_from_string(void) "6fa459ea-ee8a-3ca4-894e-db77e160355e", "python.org", -1, - UUID_NS_DNS); + NM_UUID_NS_DNS); _test_uuid(NM_UUID_TYPE_VERSION5, "886313e1-3b8a-5372-9b90-0c9aee199e5d", "python.org", -1, - UUID_NS_DNS); + NM_UUID_NS_DNS); _test_uuid(NM_UUID_TYPE_VERSION3, "9fe8e8c4-aaa8-32a9-a55c-4535a88b748d", "http://python.org/", -1, - UUID_NS_URL); + NM_UUID_NS_URL); _test_uuid(NM_UUID_TYPE_VERSION5, "4c565f0d-3f5a-5890-b41b-20cf47701c5e", "http://python.org/", -1, - UUID_NS_URL); + NM_UUID_NS_URL); _test_uuid(NM_UUID_TYPE_VERSION3, "dd1a1cef-13d5-368a-ad82-eca71acd4cd1", "1.3.6.1", -1, - UUID_NS_OID); + NM_UUID_NS_OID); _test_uuid(NM_UUID_TYPE_VERSION5, "1447fa61-5277-5fef-a9b3-fbc6e44f4af3", "1.3.6.1", -1, - UUID_NS_OID); + NM_UUID_NS_OID); _test_uuid(NM_UUID_TYPE_VERSION3, "658d3002-db6b-3040-a1d1-8ddd7d189a4d", "c=ca", -1, - UUID_NS_X500); + NM_UUID_NS_X500); _test_uuid(NM_UUID_TYPE_VERSION5, "cc957dd1-a972-5349-98cd-874190002798", "c=ca", -1, - UUID_NS_X500); + NM_UUID_NS_X500); _test_uuid(NM_UUID_TYPE_VERSION5, "74738ff5-5367-5958-9aee-98fffdcd1876", "www.example.org", -1, - UUID_NS_DNS); + NM_UUID_NS_DNS); } /*****************************************************************************/ @@ -7800,7 +7824,7 @@ __test_uuid(const char *expected_uuid, const char *str, gssize slen, char *uuid_ } g_free(uuid_test); - uuid_test = nm_uuid_generate_from_string_str(str, slen, NM_UUID_TYPE_VERSION3, NM_UUID_NS1); + uuid_test = nm_uuid_generate_from_string_str(str, slen, NM_UUID_TYPE_VERSION3, &nm_uuid_ns_1); g_assert(uuid_test); g_assert(nm_utils_is_uuid(uuid_test)); @@ -7821,15 +7845,23 @@ __test_uuid(const char *expected_uuid, const char *str, gssize slen, char *uuid_ static void test_nm_utils_uuid_generate_from_strings(void) { - const NMUuid uuid0 = {}; + const NMUuid uuid0 = NM_UUID_INIT_ZERO(); + const NMUuid uuid1 = {}; + char buf[37]; g_assert_cmpmem(&uuid0, sizeof(uuid0), _uuid("00000000-0000-0000-0000-000000000000"), 16); + g_assert_cmpmem(&uuid0, sizeof(NMUuid), &uuid1, sizeof(NMUuid)); + g_assert(nm_uuid_is_null(NULL)); g_assert(nm_uuid_is_null(&uuid0)); + g_assert(nm_uuid_is_null(&nm_uuid_ns_zero)); g_assert(nm_uuid_is_null(_uuid("00000000-0000-0000-0000-000000000000"))); g_assert(!nm_uuid_is_null(_uuid("10000000-0000-0000-0000-000000000000"))); + g_assert_cmpstr(NM_UUID_NS_1, ==, nm_uuid_unparse(&nm_uuid_ns_1, buf)); + g_assert_cmpstr(NM_UUID_NS_ZERO, ==, nm_uuid_unparse(&nm_uuid_ns_zero, buf)); + _test_uuid("b07c334a-399b-32de-8d50-58e4e08f98e3", "", 0, NULL); _test_uuid("b8a426cb-bcb5-30a3-bd8f-6786fea72df9", "\0", 1, ""); _test_uuid("12a4a982-7aae-39e1-951e-41aeb1250959", "a\0", 2, "a"); @@ -7846,6 +7878,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 @@ -9787,11 +9845,53 @@ test_nm_va_args_macros(void) g_assert_cmpint(7, ==, GET_NARG_1(x, x, x, x, x, x, x)); g_assert_cmpint(8, ==, GET_NARG_1(x, x, x, x, x, x, x, x)); g_assert_cmpint(9, ==, GET_NARG_1(x, x, x, x, x, x, x, x, x)); - g_assert_cmpint(10, ==, GET_NARG_1(x, x, x, x, x, x, x, x, x, x)); + g_assert_cmpint(10, ==, NM_NARG(x, x, x, x, x, x, x, x, x, x)); G_STATIC_ASSERT_EXPR(0 == GET_NARG_1()); G_STATIC_ASSERT_EXPR(1 == GET_NARG_1(x)); G_STATIC_ASSERT_EXPR(2 == GET_NARG_1(x, x)); + + /* clang-format off */ + G_STATIC_ASSERT_EXPR(NM_NARG( + 1,2,3,4,5,6,7,8,9,10, + 1,2,3,4,5,6,7,8,9,20, + 1,2,3,4,5,6,7,8,9,30 + ) == 30); + G_STATIC_ASSERT_EXPR(NM_NARG( + 1,2,3,4,5,6,7,8,9,10, + 1,2,3,4,5,6,7,8,9,20, + 1,2,3,4,5,6,7,8,9,30, + 1,2,3,4,5,6,7,8,9,40, + 1,2,3,4,5,6,7,8,9,50, + 1,2,3,4,5,6,7,8,9,60, + 1,2,3,4,5,6,7,8,9,70, + 1,2,3,4,5,6,7,8,9,80 + ) == 80); + G_STATIC_ASSERT_EXPR(NM_NARG( + 1,2,3,4,5,6,7,8,9,10, + 1,2,3,4,5,6,7,8,9,20, + 1,2,3,4,5,6,7,8,9,30, + 1,2,3,4,5,6,7,8,9,40, + 1,2,3,4,5,6,7,8,9,50, + 1,2,3,4,5,6,7,8,9,60, + 1,2,3,4,5,6,7,8,9,70, + 1,2,3,4,5,6,7,8,9,80, + 1,2,3,4,5,6,7,8,9,90, + 1,2,3,4,5,6,7,8,9,100, + 1,2,3,4,5,6,7,8,9,110, + 1,2,3,4,5,6,7,8,9,120 + ) == 120); + /* clang-format on */ + + G_STATIC_ASSERT_EXPR(NM_NARG_MAX1() == 0); + G_STATIC_ASSERT_EXPR(NM_NARG_MAX1(1) == 1); + G_STATIC_ASSERT_EXPR(NM_NARG_MAX1(1, 2) == 1); + G_STATIC_ASSERT_EXPR(NM_NARG_MAX1(1, 2, 3) == 1); + + G_STATIC_ASSERT_EXPR(NM_NARG_MAX2() == 0); + G_STATIC_ASSERT_EXPR(NM_NARG_MAX2(1) == 1); + G_STATIC_ASSERT_EXPR(NM_NARG_MAX2(1, 2) == 2); + G_STATIC_ASSERT_EXPR(NM_NARG_MAX2(1, 2, 3) == 2); } /*****************************************************************************/ @@ -10333,7 +10433,7 @@ _strsplit_quoted_assert_strv(const char * topic, g_assert(strv1); g_assert(strv2); - if (nm_utils_strv_equal(strv1, strv2)) + if (nm_strv_equal(strv1, strv2)) return; for (i = 0; strv1[i]; i++) { @@ -10425,6 +10525,60 @@ test_strsplit_quoted(void) /*****************************************************************************/ static void +test_nm_property_variant_to_gvalue(void) +{ +#define _test_variant_to_gvalue_bad(variant, gtype) \ + G_STMT_START \ + { \ + gs_unref_variant GVariant * _variant = (variant); \ + GType _gtype = (gtype); \ + nm_auto_unset_gvalue GValue _gvalue = G_VALUE_INIT; \ + \ + g_value_init(&_gvalue, _gtype); \ + g_assert_cmpint(_nm_property_variant_to_gvalue(_variant, &_gvalue), ==, FALSE); \ + } \ + G_STMT_END + +#define _test_variant_to_gvalue(variant, gtype, check) \ + G_STMT_START \ + { \ + gs_unref_variant GVariant * _variant = (variant); \ + GType _gtype = (gtype); \ + nm_auto_unset_gvalue GValue _gvalue = G_VALUE_INIT; \ + _nm_unused GValue *const gg = &_gvalue; \ + \ + g_value_init(&_gvalue, _gtype); \ + g_assert_cmpint(_nm_property_variant_to_gvalue(_variant, &_gvalue), ==, TRUE); \ + check; \ + } \ + G_STMT_END + +#define _test_variant_to_gvalue_int(variant, gtype, gvalue_get, expected) \ + _test_variant_to_gvalue((variant), (gtype), g_assert_cmpint(gvalue_get(gg), ==, (expected))) + + _test_variant_to_gvalue_bad(g_variant_new_string(""), G_TYPE_BOOLEAN); + _test_variant_to_gvalue(g_variant_new_string(""), + G_TYPE_STRING, + g_assert_cmpstr(g_value_get_string(gg), ==, "")); + _test_variant_to_gvalue_int(g_variant_new_boolean(FALSE), + G_TYPE_BOOLEAN, + g_value_get_boolean, + FALSE); + _test_variant_to_gvalue_int(g_variant_new_boolean(TRUE), + G_TYPE_BOOLEAN, + g_value_get_boolean, + TRUE); + _test_variant_to_gvalue_int(g_variant_new_int32(0), G_TYPE_BOOLEAN, g_value_get_boolean, FALSE); + _test_variant_to_gvalue_int(g_variant_new_int32(1), G_TYPE_BOOLEAN, g_value_get_boolean, 1); + _test_variant_to_gvalue_int(g_variant_new_int32(2), G_TYPE_BOOLEAN, g_value_get_boolean, 1); + _test_variant_to_gvalue_int(g_variant_new_byte(0), G_TYPE_BOOLEAN, g_value_get_boolean, 0); + _test_variant_to_gvalue_int(g_variant_new_byte(1), G_TYPE_BOOLEAN, g_value_get_boolean, 1); + _test_variant_to_gvalue_int(g_variant_new_byte(2), G_TYPE_BOOLEAN, g_value_get_boolean, 1); +} + +/*****************************************************************************/ + +static void _do_wifi_ghz_freqs(const guint *freqs, const char *band) { int len; @@ -10531,7 +10685,7 @@ main(int argc, char **argv) g_test_add_func("/core/general/test_c_list_sort", test_c_list_sort); g_test_add_func("/core/general/test_dedup_multi", test_dedup_multi); g_test_add_func("/core/general/test_utils_str_utf8safe", test_utils_str_utf8safe); - g_test_add_func("/core/general/test_nm_utils_strsplit_set", test_nm_utils_strsplit_set); + g_test_add_func("/core/general/test_nm_strsplit_set", test_nm_strsplit_set); g_test_add_func("/core/general/test_nm_utils_escaped_tokens", test_nm_utils_escaped_tokens); g_test_add_func("/core/general/test_nm_in_set", test_nm_in_set); g_test_add_func("/core/general/test_nm_in_strset", test_nm_in_strset); @@ -10743,6 +10897,9 @@ main(int argc, char **argv) g_test_add_func("/core/general/test_setting_connection_permissions_property", test_setting_connection_permissions_property); + g_test_add_func("/core/general/test_nm_property_variant_to_gvalue", + test_nm_property_variant_to_gvalue); + g_test_add_func("/core/general/test_connection_compare_same", test_connection_compare_same); g_test_add_func("/core/general/test_connection_compare_key_only_in_a", test_connection_compare_key_only_in_a); @@ -10810,6 +10967,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-core-impl/tests/test-keyfile.c b/src/libnm-core-impl/tests/test-keyfile.c index ba7d783b..db193379 100644 --- a/src/libnm-core-impl/tests/test-keyfile.c +++ b/src/libnm-core-impl/tests/test-keyfile.c @@ -123,7 +123,7 @@ _assert_gbytes(GBytes *bytes, gconstpointer data, gssize len) if (!len) g_assert(!bytes); - g_assert(nm_utils_gbytes_equal_mem(bytes, data, len)); + g_assert(nm_g_bytes_equal_mem(bytes, data, len)); } static GKeyFile * @@ -350,7 +350,7 @@ _test_8021x_cert_check(NMConnection * con, } g_assert(blob); - g_assert(nm_utils_gbytes_equal_mem(blob, value, val_len)); + g_assert(nm_g_bytes_equal_mem(blob, value, val_len)); kval = g_key_file_get_string(keyfile, "802-1x", "ca-cert", NULL); g_assert(kval); diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 6b65e98d..7444f2c1 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -7,6 +7,8 @@ #include <linux/pkt_sched.h> #include <net/if.h> +#include <linux/if_ether.h> +#include <linux/if_infiniband.h> #include "libnm-glib-aux/nm-uuid.h" #include "libnm-glib-aux/nm-json-aux.h" @@ -119,7 +121,7 @@ test_nm_meta_setting_types_by_priority(void) G_STATIC_ASSERT_EXPR(_NM_META_SETTING_TYPE_NUM == G_N_ELEMENTS(nm_meta_setting_types_by_priority)); - G_STATIC_ASSERT_EXPR(_NM_META_SETTING_TYPE_NUM == 51); + G_STATIC_ASSERT_EXPR(_NM_META_SETTING_TYPE_NUM == 52); arr = g_ptr_array_new_with_free_func(g_object_unref); @@ -150,7 +152,7 @@ test_nm_meta_setting_types_by_priority(void) for (j = 0; j < i; j++) { NMSetting *other = arr->pdata[j]; - if (_nmtst_nm_setting_sort(other, setting) >= 0) { + if (_nm_setting_sort_for_nm_assert(other, setting) >= 0) { g_error("sort order for nm_meta_setting_types_by_priority[%d vs %d] is wrong: %s " "should be before %s", j, @@ -874,6 +876,34 @@ test_bond_normalize(void) /*****************************************************************************/ +static void +test_dummy_normalize(void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + + connection = nm_simple_connection_new(); + s_con = NM_SETTING_CONNECTION(nm_setting_connection_new()); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "dummy-test", + NM_SETTING_CONNECTION_UUID, + nm_uuid_generate_random_str_a(), + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_DUMMY_SETTING_NAME, + NULL); + + nmtst_assert_connection_unnormalizable(connection, 0, 0); + + g_object_set(s_con, NM_SETTING_CONNECTION_INTERFACE_NAME, "dummy1", NULL); + + nmtst_connection_normalize(connection); +} + +/*****************************************************************************/ + #define DCB_FLAGS_ALL \ (NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_ADVERTISE | NM_SETTING_DCB_FLAG_WILLING) @@ -1183,7 +1213,7 @@ test_nm_json(void) #endif #if WITH_JANSSON != defined(JANSSON_SONAME) - #error "WITH_JANSON and JANSSON_SONAME are defined inconsistently." +#error "WITH_JANSON and JANSSON_SONAME are defined inconsistently." #endif } @@ -3219,7 +3249,7 @@ _rndt_wired_add_s390_options(NMSettingWired *s_wired, char **out_keyfile_entries g_assert(k); g_assert(v); - idx = nm_utils_strv_find_first((char **) opt_keys, n_opts, k); + idx = nm_strv_find_first(opt_keys, n_opts, k); g_assert(idx >= 0); g_assert(!opt_found[idx]); opt_found[idx] = TRUE; @@ -3619,6 +3649,12 @@ test_roundtrip_conversion(gconstpointer test_data) s_wg = NM_SETTING_WIREGUARD(nm_connection_get_setting(con, NM_TYPE_SETTING_WIREGUARD)); + s_ip.s_4 = NM_SETTING_IP_CONFIG(nm_connection_get_setting(con, NM_TYPE_SETTING_IP4_CONFIG)); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip.s_4), ==, "disabled"); + + s_ip.s_6 = NM_SETTING_IP_CONFIG(nm_connection_get_setting(con, NM_TYPE_SETTING_IP6_CONFIG)); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip.s_6), ==, "disabled"); + g_ptr_array_add(kf_data_arr, g_strdup_printf("[connection]\n" "id=%s\n" @@ -3636,7 +3672,7 @@ test_roundtrip_conversion(gconstpointer test_data) "[ipv6]\n" "addr-gen-mode=stable-privacy\n" "dns-search=\n" - "method=ignore\n" + "method=disabled\n" "\n" "[proxy]\n" "", @@ -3693,7 +3729,7 @@ test_roundtrip_conversion(gconstpointer test_data) "[ipv6]\n" "addr-gen-mode=stable-privacy\n" "dns-search=\n" - "method=ignore\n" + "method=disabled\n" "\n" "[proxy]\n" "", @@ -4354,6 +4390,9 @@ test_setting_metadata(void) guint prop_idx; gs_free GParamSpec **property_specs = NULL; guint n_property_specs; + guint n_param_spec; + guint i; + guint j; g_assert(sis); @@ -4370,8 +4409,22 @@ test_setting_metadata(void) g_assert_cmpint(sis->property_infos_len, >, 0); g_assert(sis->property_infos); + { + int offset; + + if (sis->private_offset < 0) { + offset = g_type_class_get_instance_private_offset(sis->setting_class); + g_assert_cmpint(sis->private_offset, ==, offset); + } else { + /* it would be nice to assert that this class has no private data. + * But we cannot. */ + } + } + h_properties = g_hash_table_new(nm_str_hash, g_str_equal); + n_param_spec = 0; + for (prop_idx = 0; prop_idx < sis->property_infos_len; prop_idx++) { const NMSettInfoProperty *sip = &sis->property_infos[prop_idx]; GArray * property_types_data; @@ -4380,6 +4433,9 @@ test_setting_metadata(void) g_assert(sip->name); + if (sip->param_spec) + n_param_spec++; + if (prop_idx > 0) g_assert_cmpint(strcmp(sis->property_infos[prop_idx - 1].name, sip->name), <, 0); @@ -4387,17 +4443,152 @@ test_setting_metadata(void) g_assert(sip->property_type->dbus_type); g_assert(g_variant_type_string_is_valid((const char *) sip->property_type->dbus_type)); + if (sip->property_type->direct_type == NM_VALUE_TYPE_NONE) { + g_assert_cmpint(sip->direct_offset, ==, 0); + } else if (sip->property_type->direct_type == NM_VALUE_TYPE_BOOL) { + g_assert(sip->property_type == &nm_sett_info_propert_type_direct_boolean); + g_assert(g_variant_type_equal(sip->property_type->dbus_type, "b")); + g_assert(sip->property_type->to_dbus_fcn + == _nm_setting_property_to_dbus_fcn_direct); + g_assert(sip->param_spec); + g_assert(sip->param_spec->value_type == G_TYPE_BOOLEAN); + can_set_including_default = TRUE; + } else if (sip->property_type->direct_type == NM_VALUE_TYPE_INT32) { + const GParamSpecInt *pspec; + + g_assert(sip->property_type == &nm_sett_info_propert_type_direct_int32); + g_assert(g_variant_type_equal(sip->property_type->dbus_type, "i")); + g_assert(sip->property_type->to_dbus_fcn + == _nm_setting_property_to_dbus_fcn_direct); + g_assert(sip->param_spec); + g_assert(sip->param_spec->value_type == G_TYPE_INT); + + pspec = NM_G_PARAM_SPEC_CAST_INT(sip->param_spec); + g_assert_cmpint(pspec->minimum, <=, pspec->maximum); + g_assert_cmpint(pspec->default_value, >=, pspec->minimum); + g_assert_cmpint(pspec->default_value, <=, pspec->maximum); + + g_assert_cmpint(pspec->minimum, >=, (gint64) G_MININT32); + g_assert_cmpint(pspec->maximum, <=, (gint64) G_MAXINT32); + + can_set_including_default = TRUE; + } else if (sip->property_type->direct_type == NM_VALUE_TYPE_UINT32) { + const GParamSpecUInt *pspec; + + g_assert(sip->property_type == &nm_sett_info_propert_type_direct_uint32); + g_assert(g_variant_type_equal(sip->property_type->dbus_type, "u")); + g_assert(sip->property_type->to_dbus_fcn + == _nm_setting_property_to_dbus_fcn_direct); + g_assert(sip->param_spec); + g_assert(sip->param_spec->value_type == G_TYPE_UINT); + + pspec = NM_G_PARAM_SPEC_CAST_UINT(sip->param_spec); + g_assert_cmpint(pspec->minimum, <=, pspec->maximum); + g_assert_cmpint(pspec->default_value, >=, pspec->minimum); + g_assert_cmpint(pspec->default_value, <=, pspec->maximum); + + g_assert_cmpint(pspec->maximum, <=, (guint64) G_MAXUINT32); + + can_set_including_default = TRUE; + } else if (sip->property_type->direct_type == NM_VALUE_TYPE_UINT64) { + const GParamSpecUInt64 *pspec; + + g_assert(sip->property_type == &nm_sett_info_propert_type_direct_uint64); + g_assert(g_variant_type_equal(sip->property_type->dbus_type, "t")); + g_assert(sip->property_type->to_dbus_fcn + == _nm_setting_property_to_dbus_fcn_direct); + g_assert(sip->param_spec); + g_assert(sip->param_spec->value_type == G_TYPE_UINT64); + + pspec = NM_G_PARAM_SPEC_CAST_UINT64(sip->param_spec); + g_assert_cmpuint(pspec->minimum, <=, pspec->maximum); + g_assert_cmpuint(pspec->default_value, >=, pspec->minimum); + g_assert_cmpuint(pspec->default_value, <=, pspec->maximum); + + g_assert_cmpuint(pspec->maximum, <=, G_MAXUINT64); + + can_set_including_default = TRUE; + } else if (sip->property_type->direct_type == NM_VALUE_TYPE_ENUM) { + const GParamSpecEnum *pspec; + + g_assert(sip->property_type == &nm_sett_info_propert_type_direct_enum); + g_assert(g_variant_type_equal(sip->property_type->dbus_type, "i")); + g_assert(sip->property_type->to_dbus_fcn + == _nm_setting_property_to_dbus_fcn_direct); + g_assert(sip->param_spec); + g_assert(g_type_is_a(sip->param_spec->value_type, G_TYPE_ENUM)); + g_assert(sip->param_spec->value_type != G_TYPE_ENUM); + + pspec = NM_G_PARAM_SPEC_CAST_ENUM(sip->param_spec); + g_assert(G_TYPE_FROM_CLASS(pspec->enum_class) == sip->param_spec->value_type); + g_assert(g_enum_get_value(pspec->enum_class, pspec->default_value)); + + can_set_including_default = TRUE; + } else if (sip->property_type->direct_type == NM_VALUE_TYPE_FLAGS) { + const GParamSpecFlags *pspec; + + g_assert(sip->property_type == &nm_sett_info_propert_type_direct_flags); + g_assert(g_variant_type_equal(sip->property_type->dbus_type, "u")); + g_assert(sip->property_type->to_dbus_fcn + == _nm_setting_property_to_dbus_fcn_direct); + g_assert(sip->param_spec); + g_assert(g_type_is_a(sip->param_spec->value_type, G_TYPE_FLAGS)); + g_assert(sip->param_spec->value_type != G_TYPE_FLAGS); + + pspec = NM_G_PARAM_SPEC_CAST_FLAGS(sip->param_spec); + g_assert_cmpint(pspec->flags_class->mask, !=, 0); + g_assert_cmpint(pspec->default_value, + ==, + pspec->flags_class->mask & pspec->default_value); + + can_set_including_default = TRUE; + } else if (sip->property_type->direct_type == NM_VALUE_TYPE_STRING) { + if (sip->property_type == &nm_sett_info_propert_type_direct_mac_address) { + g_assert(g_variant_type_equal(sip->property_type->dbus_type, "ay")); + g_assert(sip->property_type->to_dbus_fcn + == _nm_setting_property_to_dbus_fcn_direct_mac_address); + g_assert(NM_IN_SET((guint) sip->direct_set_string_mac_address_len, + ETH_ALEN, + 8, + INFINIBAND_ALEN)); + } else { + g_assert(g_variant_type_equal(sip->property_type->dbus_type, "s")); + g_assert(sip->property_type->to_dbus_fcn + == _nm_setting_property_to_dbus_fcn_direct); + } + g_assert(sip->param_spec); + g_assert(sip->param_spec->value_type == G_TYPE_STRING); + } else if (sip->property_type->direct_type == NM_VALUE_TYPE_BYTES) { + g_assert(g_variant_type_equal(sip->property_type->dbus_type, "ay")); + g_assert(sip->property_type->to_dbus_fcn + == _nm_setting_property_to_dbus_fcn_direct); + g_assert(sip->param_spec); + g_assert(sip->param_spec->value_type == G_TYPE_BYTES); + } else + g_assert_not_reached(); + + if (sip->direct_set_string_ascii_strdown) + g_assert(sip->property_type->direct_type == NM_VALUE_TYPE_STRING); + + if (sip->direct_set_string_mac_address_len != 0) { + g_assert(NM_IN_SET(sip->property_type, + &nm_sett_info_propert_type_direct_string, + &nm_sett_info_propert_type_direct_mac_address)); + g_assert(sip->property_type->direct_type == NM_VALUE_TYPE_STRING); + } + + g_assert(((sip->direct_set_string_mac_address_len != 0) + + (!!sip->direct_set_string_ascii_strdown) + + (sip->direct_set_string_ip_address_addr_family != 0)) + <= 1); + if (!sip->property_type->to_dbus_fcn) { /* it's allowed to have no to_dbus_fcn(), to ignore a property. But such - * properties must not have a param_spec and no gprop_to_dbus_fcn. */ + * properties must not have a param_spec. */ g_assert(!sip->param_spec); - g_assert(!sip->to_dbus_data.none); } else if (sip->property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_gprop) { g_assert(sip->param_spec); switch (sip->property_type->typdata_to_dbus.gprop_type) { - case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_BYTES: - g_assert(sip->param_spec->value_type == G_TYPE_BYTES); - goto check_done; case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_ENUM: g_assert(g_type_is_a(sip->param_spec->value_type, G_TYPE_ENUM)); goto check_done; @@ -4410,40 +4601,82 @@ test_setting_metadata(void) case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_STRDICT: g_assert(sip->param_spec->value_type == G_TYPE_HASH_TABLE); goto check_done; - case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_MAC_ADDRESS: - g_assert(sip->param_spec->value_type == G_TYPE_STRING); - goto check_done; case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT: goto check_done; } g_assert_not_reached(); check_done:; - if (sip->property_type->typdata_to_dbus.gprop_type - != NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT) - g_assert(!sip->to_dbus_data.gprop_to_dbus_fcn); can_set_including_default = TRUE; - } else if (sip->property_type->to_dbus_fcn - == _nm_setting_property_to_dbus_fcn_get_boolean) { - g_assert(sip->param_spec); - g_assert(sip->param_spec->value_type == G_TYPE_BOOLEAN); - g_assert(sip->to_dbus_data.get_boolean); - can_set_including_default = TRUE; - } else if (sip->property_type->to_dbus_fcn - == _nm_setting_property_to_dbus_fcn_get_string) { - g_assert(sip->param_spec); - g_assert(sip->param_spec->value_type == G_TYPE_STRING); - g_assert(sip->to_dbus_data.get_string); } if (!can_set_including_default) - g_assert(!sip->to_dbus_data.including_default); + g_assert(!sip->to_dbus_including_default); - g_assert(!sip->property_type->from_dbus_fcn - || !sip->property_type->gprop_from_dbus_fcn); + g_assert(sip->property_type->from_dbus_fcn || !sip->param_spec); + if (sip->property_type->typdata_from_dbus.gprop_fcn) { + g_assert(sip->property_type->from_dbus_fcn + == _nm_setting_property_from_dbus_fcn_gprop); + } + if (sip->property_type->from_dbus_direct_allow_transform) { + g_assert(sip->property_type->from_dbus_fcn + == _nm_setting_property_from_dbus_fcn_direct); + } + if (sip->property_type->from_dbus_fcn == _nm_setting_property_from_dbus_fcn_direct) { + /* for the moment, all direct properties allow transformation. */ + g_assert(sip->property_type->from_dbus_direct_allow_transform); + } + + if (sip->property_type->from_dbus_fcn == _nm_setting_property_from_dbus_fcn_gprop) + g_assert(sip->param_spec); + if (sip->property_type->from_dbus_fcn) { + if (sip->property_type->direct_type != NM_VALUE_TYPE_NONE) { + g_assert(NM_IN_SET(sip->property_type->from_dbus_fcn, + _nm_setting_property_from_dbus_fcn_direct_ip_config_gateway, + _nm_setting_property_from_dbus_fcn_direct_mac_address, + _nm_setting_property_from_dbus_fcn_direct)); + } + } + + g_assert(sip->property_type->from_dbus_is_full + == NM_IN_SET(sip->property_type->from_dbus_fcn, + _nm_setting_property_from_dbus_fcn_direct, + _nm_setting_property_from_dbus_fcn_gprop, + _nm_setting_property_from_dbus_fcn_ignore)); if (!g_hash_table_insert(h_properties, (char *) sip->name, sip->param_spec)) g_assert_not_reached(); + if (sip->property_type->compare_fcn == _nm_setting_property_compare_fcn_default) { + g_assert(sip->param_spec); + g_assert_cmpstr(sip->name, !=, NM_SETTING_NAME); + } else if (sip->property_type->compare_fcn == _nm_setting_property_compare_fcn_direct) { + g_assert(sip->param_spec); + g_assert(sip->property_type->direct_type != NM_VALUE_TYPE_NONE); + g_assert(NM_IN_SET(sip->property_type->to_dbus_fcn, + _nm_setting_property_to_dbus_fcn_direct, + _nm_setting_property_to_dbus_fcn_direct_mac_address)); + } else if (sip->property_type->compare_fcn == _nm_setting_property_compare_fcn_ignore) { + if (NM_IN_SET(sip->property_type, + &nm_sett_info_propert_type_deprecated_ignore_i, + &nm_sett_info_propert_type_deprecated_ignore_u, + &nm_sett_info_propert_type_assigned_mac_address)) { + /* pass */ + } else if (!sip->param_spec) { + /* pass */ + } else if (nm_streq(sip->name, NM_SETTING_NAME)) { + /* pass */ + } else { + /* ignoring a property for comparison make only sense in very specific cases. */ + g_assert_not_reached(); + } + } else if (sip->property_type->compare_fcn) { + /* pass */ + } else { + g_assert_not_reached(); + } + g_assert((sip->property_type->compare_fcn != _nm_setting_property_compare_fcn_direct) + || (sip->property_type->direct_type != NM_VALUE_TYPE_NONE)); + property_types_data = g_hash_table_lookup(h_property_types, sip->property_type); if (!property_types_data) { property_types_data = g_array_new(FALSE, FALSE, sizeof(guint)); @@ -4460,32 +4693,51 @@ check_done:; g_assert_cmpstr(sip->name, ==, sip->param_spec->name); + g_assert(NM_FLAGS_HAS(sip->param_spec->flags, G_PARAM_WRITABLE) + != nm_streq(sip->name, NM_SETTING_NAME)); + g_assert((sip->property_type == &nm_sett_info_propert_type_setting_name) + == nm_streq(sip->name, NM_SETTING_NAME)); + g_value_init(&val, sip->param_spec->value_type); g_object_get_property(G_OBJECT(setting), sip->name, &val); if (sip->param_spec->value_type == G_TYPE_STRING) { - const char *default_value; - - default_value = ((const GParamSpecString *) sip->param_spec)->default_value; - if (default_value) { - /* having a string property with a default != NULL is really ugly. They - * should be best avoided... */ - if (meta_type == NM_META_SETTING_TYPE_DCB - && nm_streq(sip->name, NM_SETTING_DCB_APP_FCOE_MODE)) { - /* Whitelist the properties that have a non-NULL default value. */ - g_assert_cmpstr(default_value, ==, NM_SETTING_DCB_FCOE_MODE_FABRIC); - } else - g_assert_not_reached(); - } + /* String properties should all have a default value of NULL. Otherwise, + * it's ugly. */ + g_assert_cmpstr(((const GParamSpecString *) sip->param_spec)->default_value, + ==, + NULL); + g_assert(!NM_G_PARAM_SPEC_GET_DEFAULT_STRING(sip->param_spec)); if (nm_streq(sip->name, NM_SETTING_NAME)) g_assert_cmpstr(g_value_get_string(&val), ==, msi->setting_name); else - g_assert_cmpstr(g_value_get_string(&val), ==, default_value); + g_assert_cmpstr(g_value_get_string(&val), ==, NULL); } if (NM_FLAGS_HAS(sip->param_spec->flags, NM_SETTING_PARAM_TO_DBUS_IGNORE_FLAGS)) g_assert(sip->property_type->to_dbus_fcn); + + g_assert(!NM_FLAGS_HAS(sip->param_spec->flags, G_PARAM_CONSTRUCT)); + g_assert(!NM_FLAGS_HAS(sip->param_spec->flags, G_PARAM_CONSTRUCT_ONLY)); + + if (NM_FLAGS_HAS(sip->param_spec->flags, NM_SETTING_PARAM_SECRET)) { + if (sip->param_spec->value_type == G_TYPE_STRING) { + g_assert_cmpstr(NM_G_PARAM_SPEC_GET_DEFAULT_STRING(sip->param_spec), + ==, + NULL); + } else if (sip->param_spec->value_type == G_TYPE_BYTES) { + /* pass */ + } else if (sip->param_spec->value_type == G_TYPE_HASH_TABLE) { + g_assert(NM_IS_SETTING_VPN(setting)); + g_assert_cmpstr(sip->name, ==, NM_SETTING_VPN_SECRETS); + } else { + g_error("secret %s.%s is of unexpected property type %s", + nm_setting_get_name(setting), + sip->name, + g_type_name(sip->param_spec->value_type)); + } + } } } @@ -4533,6 +4785,44 @@ check_done:; g_assert_cmpstr(sis->property_infos[0].name, ==, NM_SETTING_NAME); } else g_assert_cmpint(meta_type, !=, NM_META_SETTING_TYPE_ETHTOOL); + + g_assert_cmpint(n_param_spec, >, 0); + g_assert_cmpint(n_param_spec, ==, sis->property_lookup_by_param_spec_len); + g_assert(sis->property_lookup_by_param_spec); + for (i = 0; i < sis->property_lookup_by_param_spec_len; i++) { + const NMSettInfoPropertLookupByParamSpec *p = &sis->property_lookup_by_param_spec[i]; + guint n_found; + + if (i > 0) { + g_assert_cmpint(sis->property_lookup_by_param_spec[i - 1].param_spec_as_uint, + <, + p->param_spec_as_uint); + } + g_assert(p->property_info); + g_assert(p->property_info >= sis->property_infos); + g_assert(p->property_info < &sis->property_infos[sis->property_infos_len]); + g_assert(p->property_info + == &sis->property_infos[p->property_info - sis->property_infos]); + + g_assert(p->property_info->param_spec); + g_assert(p->param_spec_as_uint + == ((uintptr_t) ((gpointer) p->property_info->param_spec))); + + g_assert(_nm_sett_info_property_lookup_by_param_spec(sis, p->property_info->param_spec) + == p->property_info); + + n_found = 0; + for (j = 0; j < sis->property_infos_len; j++) { + const NMSettInfoProperty *pip2 = &sis->property_infos[j]; + + if (pip2->param_spec + && p->param_spec_as_uint == ((uintptr_t) ((gpointer) pip2->param_spec))) { + g_assert(pip2 == p->property_info); + n_found++; + } + } + g_assert(n_found == 1); + } } { @@ -4552,10 +4842,14 @@ check_done:; const NMSettInfoPropertType *pt_2 = a_property_types[prop_idx_2]; if (!g_variant_type_equal(pt->dbus_type, pt_2->dbus_type) - || pt->to_dbus_fcn != pt_2->to_dbus_fcn + || pt->direct_type != pt_2->direct_type || pt->to_dbus_fcn != pt_2->to_dbus_fcn || pt->from_dbus_fcn != pt_2->from_dbus_fcn + || pt->compare_fcn != pt_2->compare_fcn || pt->missing_from_dbus_fcn != pt_2->missing_from_dbus_fcn - || pt->gprop_from_dbus_fcn != pt_2->gprop_from_dbus_fcn + || memcmp(&pt->typdata_from_dbus, + &pt_2->typdata_from_dbus, + sizeof(pt->typdata_from_dbus)) + != 0 || memcmp(&pt->typdata_to_dbus, &pt_2->typdata_to_dbus, sizeof(pt->typdata_to_dbus)) @@ -4632,44 +4926,44 @@ test_setting_connection_secondaries_verify(void) g_object_set(s_con, NM_SETTING_CONNECTION_SECONDARIES, arr->pdata, NULL); -#define _assert_secondaries(s_con, expected) \ - G_STMT_START \ - { \ - NMSettingConnection *const _s_con = (s_con); \ - const char *const * _expected = (expected); \ - GArray * _secondaries; \ - const guint _expected_len = NM_PTRARRAY_LEN(_expected); \ - gs_strfreev char ** _sec_strv = NULL; \ - guint _i; \ - \ - g_assert(_expected); \ - \ - if (nmtst_get_rand_bool()) { \ - _secondaries = _nm_setting_connection_get_secondaries(_s_con); \ - g_assert_cmpint(_expected_len, ==, nm_g_array_len(_secondaries)); \ - g_assert((_expected_len == 0) == (!_secondaries)); \ - g_assert(nm_utils_strv_equal(_expected, \ - _secondaries ? nm_strvarray_get_strv(&_secondaries, NULL) \ - : NM_PTRARRAY_EMPTY(const char *))); \ - } \ - \ - if (nmtst_get_rand_bool()) { \ - g_object_get(_s_con, NM_SETTING_CONNECTION_SECONDARIES, &_sec_strv, NULL); \ - g_assert_cmpint(_expected_len, ==, NM_PTRARRAY_LEN(_sec_strv)); \ - g_assert((_expected_len == 0) == (!_sec_strv)); \ - g_assert(nm_utils_strv_equal(_expected, _sec_strv ?: NM_STRV_EMPTY())); \ - } \ - \ - g_assert_cmpint(nm_setting_connection_get_num_secondaries(_s_con), ==, _expected_len); \ - if (nmtst_get_rand_bool()) { \ - for (_i = 0; _i < _expected_len; _i++) { \ - g_assert_cmpstr(nm_setting_connection_get_secondary(_s_con, _i), \ - ==, \ - _expected[_i]); \ - } \ - g_assert_null(nm_setting_connection_get_secondary(_s_con, _expected_len)); \ - } \ - } \ +#define _assert_secondaries(s_con, expected) \ + G_STMT_START \ + { \ + NMSettingConnection *const _s_con = (s_con); \ + const char *const * _expected = (expected); \ + GArray * _secondaries; \ + const guint _expected_len = NM_PTRARRAY_LEN(_expected); \ + gs_strfreev char ** _sec_strv = NULL; \ + guint _i; \ + \ + g_assert(_expected); \ + \ + if (nmtst_get_rand_bool()) { \ + _secondaries = _nm_setting_connection_get_secondaries(_s_con); \ + g_assert_cmpint(_expected_len, ==, nm_g_array_len(_secondaries)); \ + g_assert((_expected_len == 0) == (!_secondaries)); \ + g_assert(nm_strv_equal(_expected, \ + _secondaries ? nm_strvarray_get_strv(&_secondaries, NULL) \ + : NM_PTRARRAY_EMPTY(const char *))); \ + } \ + \ + if (nmtst_get_rand_bool()) { \ + g_object_get(_s_con, NM_SETTING_CONNECTION_SECONDARIES, &_sec_strv, NULL); \ + g_assert_cmpint(_expected_len, ==, NM_PTRARRAY_LEN(_sec_strv)); \ + g_assert((_expected_len == 0) == (!_sec_strv)); \ + g_assert(nm_strv_equal(_expected, _sec_strv ?: NM_STRV_EMPTY())); \ + } \ + \ + g_assert_cmpint(nm_setting_connection_get_num_secondaries(_s_con), ==, _expected_len); \ + if (nmtst_get_rand_bool()) { \ + for (_i = 0; _i < _expected_len; _i++) { \ + g_assert_cmpstr(nm_setting_connection_get_secondary(_s_con, _i), \ + ==, \ + _expected[_i]); \ + } \ + g_assert_null(nm_setting_connection_get_secondary(_s_con, _expected_len)); \ + } \ + } \ G_STMT_END _assert_secondaries(s_con, (const char *const *) arr->pdata); @@ -4688,14 +4982,14 @@ test_setting_connection_secondaries_verify(void) if (is_normalized) s = uuid_normalized; - if (nm_utils_strv_find_first((char **) arr_norm->pdata, arr_norm->len, s) >= 0) + if (nm_strv_ptrarray_find_first(arr_norm, s) >= 0) continue; g_ptr_array_add(arr_norm, g_strdup(s)); } g_ptr_array_add(arr_norm, NULL); - was_normalized = !nm_utils_strv_equal((char **) arr->pdata, (char **) arr_norm->pdata); + was_normalized = !nm_strv_equal((char **) arr->pdata, (char **) arr_norm->pdata); if (was_normalized) nmtst_assert_connection_verifies_and_normalizable(con); @@ -4713,6 +5007,38 @@ test_setting_connection_secondaries_verify(void) /*****************************************************************************/ +static void +test_6lowpan_1(void) +{ + gs_unref_object NMConnection *con = NULL; + NMSetting6Lowpan * s_6low; + gs_free char * value = NULL; + + con = nmtst_create_minimal_connection("test-sec", NULL, NM_SETTING_6LOWPAN_SETTING_NAME, NULL); + + s_6low = NM_SETTING_6LOWPAN(nm_connection_get_setting(con, NM_TYPE_SETTING_6LOWPAN)); + g_assert(s_6low); + + g_assert_cmpstr(nm_setting_6lowpan_get_parent(s_6low), ==, NULL); + g_object_get(s_6low, NM_SETTING_6LOWPAN_PARENT, &value, NULL); + g_assert_cmpstr(value, ==, NULL); + nm_clear_g_free(&value); + + g_object_set(s_6low, NM_SETTING_6LOWPAN_PARENT, "hello", NULL); + g_assert_cmpstr(nm_setting_6lowpan_get_parent(s_6low), ==, "hello"); + g_object_get(s_6low, NM_SETTING_6LOWPAN_PARENT, &value, NULL); + g_assert_cmpstr(value, ==, "hello"); + nm_clear_g_free(&value); + + g_object_set(s_6low, NM_SETTING_6LOWPAN_PARENT, "world", NULL); + g_assert_cmpstr(nm_setting_6lowpan_get_parent(s_6low), ==, "world"); + g_object_get(s_6low, NM_SETTING_6LOWPAN_PARENT, &value, NULL); + g_assert_cmpstr(value, ==, "world"); + nm_clear_g_free(&value); +} + +/*****************************************************************************/ + NMTST_DEFINE(); int @@ -4741,6 +5067,8 @@ main(int argc, char **argv) g_test_add_func("/libnm/settings/bond/compare", test_bond_compare); g_test_add_func("/libnm/settings/bond/normalize", test_bond_normalize); + g_test_add_func("/libnm/settings/dummy/normalize", test_dummy_normalize); + g_test_add_func("/libnm/settings/dcb/flags-valid", test_dcb_flags_valid); g_test_add_func("/libnm/settings/dcb/flags-invalid", test_dcb_flags_invalid); g_test_add_func("/libnm/settings/dcb/app-priorities", test_dcb_app_priorities); @@ -4752,6 +5080,8 @@ main(int argc, char **argv) g_test_add_func("/libnm/settings/ethtool/ring", test_ethtool_ring); g_test_add_func("/libnm/settings/ethtool/pause", test_ethtool_pause); + g_test_add_func("/libnm/settings/6lowpan/1", test_6lowpan_1); + g_test_add_func("/libnm/settings/sriov/vf", test_sriov_vf); g_test_add_func("/libnm/settings/sriov/vf-dup", test_sriov_vf_dup); g_test_add_func("/libnm/settings/sriov/vf-vlan", test_sriov_vf_vlan); |