diff options
Diffstat (limited to 'src/tests')
| -rw-r--r-- | src/tests/config/meson.build | 1 | ||||
| -rw-r--r-- | src/tests/test-general-with-expect.c | 4 | ||||
| -rw-r--r-- | src/tests/test-general.c | 118 | ||||
| -rw-r--r-- | src/tests/test-wired-defname.c | 17 |
4 files changed, 16 insertions, 124 deletions
diff --git a/src/tests/config/meson.build b/src/tests/config/meson.build index fd6c89b7..f542c453 100644 --- a/src/tests/config/meson.build +++ b/src/tests/config/meson.build @@ -11,6 +11,7 @@ exe = executable( test_unit, sources, dependencies: test_nm_dep, + c_args: nm_build_cflags, ) test( diff --git a/src/tests/test-general-with-expect.c b/src/tests/test-general-with-expect.c index ba8e3ce4..a78b5311 100644 --- a/src/tests/test-general-with-expect.c +++ b/src/tests/test-general-with-expect.c @@ -32,6 +32,10 @@ #include "nm-test-utils-core.h" +#ifndef CLOCK_BOOTTIME +#define CLOCK_BOOTTIME 7 +#endif + /*****************************************************************************/ static void diff --git a/src/tests/test-general.c b/src/tests/test-general.c index 1e7329d1..4db05ac8 100644 --- a/src/tests/test-general.c +++ b/src/tests/test-general.c @@ -907,79 +907,6 @@ test_connection_match_ip6_routes (void) g_assert (matched == copy); } -#define do_test_wildcard_match(str, result, ...) \ - g_assert (nm_wildcard_match_check (str, \ - (const char *const[]) { __VA_ARGS__ }, \ - NM_NARG (__VA_ARGS__)) \ - == result); - -static void -test_wildcard_match (void) -{ - do_test_wildcard_match ("foobar", TRUE); - - do_test_wildcard_match ("foo", TRUE, "foo", "bar", "baz"); - do_test_wildcard_match ("bar", TRUE, "foo", "bar", "baz"); - do_test_wildcard_match ("baz", TRUE, "foo", "bar", "baz"); - do_test_wildcard_match ("aaa", FALSE, "foo", "bar", "baz"); - do_test_wildcard_match ("", FALSE, "foo", "bar", "baz"); - - do_test_wildcard_match ("ens1", TRUE, "ens1*"); - do_test_wildcard_match ("ens10", TRUE, "ens1*"); - do_test_wildcard_match ("ens11", TRUE, "ens1*"); - do_test_wildcard_match ("ens12", TRUE, "ens1*"); - do_test_wildcard_match ("eth0", FALSE, "ens1*"); - do_test_wildcard_match ("ens", FALSE, "ens1*"); - - do_test_wildcard_match ("ens1*", TRUE, "ens1\\*"); - do_test_wildcard_match ("ens1" , FALSE, "ens1\\*"); - do_test_wildcard_match ("ens10", FALSE, "ens1\\*"); - - do_test_wildcard_match ("abcd", TRUE, "ab??"); - do_test_wildcard_match ("ab", FALSE, "ab??"); - - do_test_wildcard_match ("ab??", TRUE, "ab\\?\\?"); - do_test_wildcard_match ("abcd", FALSE, "ab\\?\\?"); - - do_test_wildcard_match ("ens10", TRUE, "ens1*", "!ens11"); - do_test_wildcard_match ("ens11", FALSE, "ens1*", "!ens11"); - do_test_wildcard_match ("ens12", TRUE, "ens1*", "!ens11"); - - do_test_wildcard_match ("a", FALSE, "!a", "!b"); - do_test_wildcard_match ("b", FALSE, "!a", "!b"); - do_test_wildcard_match ("c", TRUE, "!a", "!b"); - do_test_wildcard_match ("!a", TRUE, "!a", "!b"); - - do_test_wildcard_match ("!net", TRUE, "\\!net"); - do_test_wildcard_match ("net", FALSE, "\\!net"); - do_test_wildcard_match ("ens10", FALSE, "\\!net"); - do_test_wildcard_match ("\\!net", FALSE, "\\!net"); - - do_test_wildcard_match ("eth0", FALSE, "*eth?", "!veth*", "!*0"); - do_test_wildcard_match ("eth1", TRUE, "*eth?", "!veth*", "!*0"); - do_test_wildcard_match ("myeth0", FALSE, "*eth?", "!veth*", "!*0"); - do_test_wildcard_match ("myeth2", TRUE, "*eth?", "!veth*", "!*0"); - do_test_wildcard_match ("veth0", FALSE, "*eth?", "!veth*", "!*0"); - do_test_wildcard_match ("veth1", FALSE, "*eth?", "!veth*", "!*0"); - do_test_wildcard_match ("dummy1", FALSE, "*eth?", "!veth*", "!*0"); - - do_test_wildcard_match ("a", TRUE, "!!a"); - do_test_wildcard_match ("b", TRUE, "!!a"); - do_test_wildcard_match ("!a", FALSE, "!!a"); - - do_test_wildcard_match ("\\", TRUE, "\\\\"); - do_test_wildcard_match ("\\\\", FALSE, "\\\\"); - do_test_wildcard_match ("", FALSE, "\\\\"); - - do_test_wildcard_match ("name", FALSE, "name[123]"); - do_test_wildcard_match ("name1", TRUE, "name[123]"); - do_test_wildcard_match ("name2", TRUE, "name[123]"); - do_test_wildcard_match ("name3", TRUE, "name[123]"); - do_test_wildcard_match ("name4", FALSE, "name[123]"); - - do_test_wildcard_match ("[a]", TRUE, "\\[a\\]"); -} - static NMConnection * _create_connection_autoconnect (const char *id, gboolean autoconnect, int autoconnect_priority) { @@ -1278,7 +1205,7 @@ test_match_spec_device (void) /*****************************************************************************/ static void -_do_test_match_spec_config (const char *file, int line, const char *spec_str, guint version, guint v_maj, guint v_min, guint v_mic, NMMatchSpecMatchType expected) +_do_test_match_spec_config (const char *file, gint line, const char *spec_str, guint version, guint v_maj, guint v_min, guint v_mic, NMMatchSpecMatchType expected) { GSList *specs; NMMatchSpecMatchType match_result; @@ -1445,7 +1372,7 @@ test_nm_utils_strbuf_append (void) t_buf = buf; t_len = buf_len; - test_mode = nmtst_get_rand_int () % 5; + test_mode = nmtst_get_rand_int () % 4; switch (test_mode) { case 0: @@ -1466,45 +1393,6 @@ test_nm_utils_strbuf_append (void) case 3: nm_utils_strbuf_append (&t_buf, &t_len, "%s", str); break; - case 4: - g_snprintf (t_buf, t_len, "%s", str); - if ( t_len > 0 - && strlen (str) >= buf_len - && (nmtst_get_rand_int () % 2)) { - /* the string was truncated by g_snprintf(). That means, at the last position in the - * buffer is now NUL. - * Replace the NUL by the actual character, and check that nm_utils_strbuf_seek_end() - * does the right thing: NUL terminate the buffer and seek past the end of the buffer. */ - g_assert_cmpmem (t_buf, t_len - 1, str, t_len - 1); - g_assert (t_buf[t_len - 1] == '\0'); - g_assert (str[t_len - 1] != '\0'); - t_buf[t_len - 1] = str[t_len - 1]; - nm_utils_strbuf_seek_end (&t_buf, &t_len); - g_assert (t_len == 0); - g_assert (t_buf == &buf[buf_len]); - g_assert (t_buf[-1] == '\0'); - } else { - nm_utils_strbuf_seek_end (&t_buf, &t_len); - if ( buf_len > 0 - && strlen (str) + 1 > buf_len) { - /* the buffer was truncated by g_snprintf() above. - * - * But nm_utils_strbuf_seek_end() does not recognize that and returns - * a remaining length of 1. - * - * Note that other nm_utils_strbuf_append*() functions recognize - * truncation, and properly set the remaining length to zero. - * As the assertions below check for the behavior of nm_utils_strbuf_append*(), - * we assert here that nm_utils_strbuf_seek_end() behaved as expected, and then - * adjust t_buf/t_len according to the "is-truncated" case. */ - g_assert (t_len == 1); - g_assert (t_buf == &buf[buf_len - 1]); - g_assert (t_buf[0] == '\0'); - t_len = 0; - t_buf++; - } - } - break; } /* Assert that the source-buffer is unmodified. */ @@ -1877,8 +1765,6 @@ main (int argc, char **argv) g_test_add_func ("/general/connection-match/routes/ip4/2", test_connection_match_ip4_routes2); g_test_add_func ("/general/connection-match/routes/ip6", test_connection_match_ip6_routes); - g_test_add_func ("/general/wildcard-match", test_wildcard_match); - g_test_add_func ("/general/connection-sort/autoconnect-priority", test_connection_sort_autoconnect_priority); g_test_add_func ("/general/match-spec/device", test_match_spec_device); diff --git a/src/tests/test-wired-defname.c b/src/tests/test-wired-defname.c index 97a6c319..a966ed21 100644 --- a/src/tests/test-wired-defname.c +++ b/src/tests/test-wired-defname.c @@ -44,14 +44,15 @@ _new_connection (const char *id) static char * _get_default_wired_name (GSList *list) { - gs_unref_hashtable GHashTable *existing_ids = NULL; - - if (list) { - existing_ids = g_hash_table_new (nm_str_hash, g_str_equal); - for (; list; list = list->next) - g_hash_table_add (existing_ids, (char *) nm_connection_get_id (list->data)); - } - return nm_device_ethernet_utils_get_default_wired_name (existing_ids); + gs_free NMConnection **v = NULL; + guint l, i; + + l = g_slist_length (list); + v = g_new0 (NMConnection *, l + 1); + for (i = 0; list; list = list->next, i++) + v[i] = NM_CONNECTION (list->data); + g_assert (i == l); + return nm_device_ethernet_utils_get_default_wired_name (v); } /*****************************************************************************/ |