diff options
Diffstat (limited to 'src/core/tests')
| -rw-r--r-- | src/core/tests/config/test-config.c | 6 | ||||
| -rw-r--r-- | src/core/tests/test-core-with-expect.c | 10 | ||||
| -rw-r--r-- | src/core/tests/test-core.c | 30 | ||||
| -rw-r--r-- | src/core/tests/test-l3cfg.c | 2 | ||||
| -rw-r--r-- | src/core/tests/test-systemd.c | 159 | ||||
| -rw-r--r-- | src/core/tests/test-utils.c | 4 |
6 files changed, 27 insertions, 184 deletions
diff --git a/src/core/tests/config/test-config.c b/src/core/tests/config/test-config.c index fa7fae07..17a66b06 100644 --- a/src/core/tests/config/test-config.c +++ b/src/core/tests/config/test-config.c @@ -1103,9 +1103,9 @@ test_config_set_values(void) const char *CONFIG_USER = BUILD_DIR "/test-set-values-user.conf"; const char *CONFIG_INTERN = BUILD_DIR "/test-set-values-intern.conf"; const char *atomic_section_prefixes[] = { - "atomic-prefix-1.", - "atomic-prefix-2.", - NULL, + "atomic-prefix-1.", + "atomic-prefix-2.", + NULL, }; g_assert(g_file_set_contents(CONFIG_USER, "", 0, NULL)); diff --git a/src/core/tests/test-core-with-expect.c b/src/core/tests/test-core-with-expect.c index eca098c4..de510c76 100644 --- a/src/core/tests/test-core-with-expect.c +++ b/src/core/tests/test-core-with-expect.c @@ -227,11 +227,11 @@ do_test_nm_utils_kill_child(void) { GLogLevelFlags fatal_mask; char *argv_watchdog[] = { - "bash", - "-c", - "sleep 4; " - "kill -KILL 0; #watchdog for #" TEST_TOKEN, - NULL, + "bash", + "-c", + "sleep 4; " + "kill -KILL 0; #watchdog for #" TEST_TOKEN, + NULL, }; char *argv1[] = { "bash", diff --git a/src/core/tests/test-core.c b/src/core/tests/test-core.c index 11a7f323..c260788e 100644 --- a/src/core/tests/test-core.c +++ b/src/core/tests/test-core.c @@ -2353,21 +2353,21 @@ test_nm_utils_dhcp_client_id_systemd_node_specific(gconstpointer test_data) { const int TEST_IDX = GPOINTER_TO_INT(test_data); const guint8 HASH_KEY[16] = {0x80, - 0x11, - 0x8c, - 0xc2, - 0xfe, - 0x4a, - 0x03, - 0xee, - 0x3e, - 0xd6, - 0x0c, - 0x6f, - 0x36, - 0x39, - 0x14, - 0x09}; + 0x11, + 0x8c, + 0xc2, + 0xfe, + 0x4a, + 0x03, + 0xee, + 0x3e, + 0xd6, + 0x0c, + 0x6f, + 0x36, + 0x39, + 0x14, + 0x09}; const guint16 duid_type_en = htons(2); const guint32 systemd_pen = htonl(43793); const struct { diff --git a/src/core/tests/test-l3cfg.c b/src/core/tests/test-l3cfg.c index 924d98f1..a9ac4004 100644 --- a/src/core/tests/test-l3cfg.c +++ b/src/core/tests/test-l3cfg.c @@ -821,7 +821,7 @@ _test_l3_ipv6ll_find_lladdr(TestL3IPv6LLData *tdata, int ifindex) g_assert(tdata); - nmp_lookup_init_object(&lookup, NMP_OBJECT_TYPE_IP6_ADDRESS, ifindex); + nmp_lookup_init_object_by_ifindex(&lookup, NMP_OBJECT_TYPE_IP6_ADDRESS, ifindex); nm_platform_iter_obj_for_each (&iter, tdata->f->platform, &lookup, &obj) { const NMPlatformIP6Address *a = NMP_OBJECT_CAST_IP6_ADDRESS(obj); diff --git a/src/core/tests/test-systemd.c b/src/core/tests/test-systemd.c index 71a6a60d..cf31ec33 100644 --- a/src/core/tests/test-systemd.c +++ b/src/core/tests/test-systemd.c @@ -13,27 +13,6 @@ /*****************************************************************************/ static void -test_dhcp_create(void) -{ - sd_dhcp_client *client4 = NULL; - int r; - - r = sd_dhcp_client_new(&client4, FALSE); - g_assert(r == 0); - g_assert(client4); - - if (/* never true */ client4 == (gpointer) &r) { - /* we don't want to call this, but ensure that the linker - * includes all these symbols. */ - sd_dhcp_client_start(client4); - } - - sd_dhcp_client_unref(client4); -} - -/*****************************************************************************/ - -static void test_lldp_create(void) { sd_lldp_rx *lldp = NULL; @@ -119,141 +98,6 @@ test_sd_event(void) /*****************************************************************************/ -static void -test_path_equal(void) -{ -#define _path_equal_check(path, expected) \ - G_STMT_START \ - { \ - const char *_path0 = (path); \ - const char *_expected = (expected); \ - gs_free char *_path = g_strdup(_path0); \ - const char *_path_result; \ - \ - _path_result = nm_sd_utils_path_simplify(_path); \ - g_assert(_path_result == _path); \ - g_assert_cmpstr(_path, ==, _expected); \ - } \ - G_STMT_END - - _path_equal_check("", ""); - _path_equal_check(".", "."); - _path_equal_check("..", ".."); - _path_equal_check("/..", "/.."); - _path_equal_check("//..", "/.."); - _path_equal_check("/.", "/"); - _path_equal_check("./", "."); - _path_equal_check("./.", "."); - _path_equal_check(".///.", "."); - _path_equal_check(".///./", "."); - _path_equal_check(".////", "."); - _path_equal_check("//..//foo/", "/../foo"); - _path_equal_check("///foo//./bar/.", "/foo/bar"); - _path_equal_check(".//./foo//./bar/.", "foo/bar"); -} - -/*****************************************************************************/ - -static void -_test_unbase64char(char ch, gboolean maybe_invalid) -{ - int r; - - r = nm_sd_utils_unbase64char(ch, FALSE); - - if (ch == '=') { - g_assert(!maybe_invalid); - g_assert_cmpint(r, <, 0); - g_assert_cmpint(nm_sd_utils_unbase64char(ch, TRUE), ==, G_MAXINT); - } else { - g_assert_cmpint(r, ==, nm_sd_utils_unbase64char(ch, TRUE)); - if (r >= 0) - g_assert_cmpint(r, <=, 255); - if (!maybe_invalid) - g_assert_cmpint(r, >=, 0); - } -} - -static void -_test_unbase64mem_mem(const char *base64, const guint8 *expected_arr, gsize expected_len) -{ - gs_free char *expected_base64 = NULL; - int r; - nm_auto_free guint8 *exp2_arr = NULL; - nm_auto_free guint8 *exp3_arr = NULL; - gsize exp2_len; - gsize exp3_len; - gsize i; - - expected_base64 = g_base64_encode(expected_arr, expected_len); - - for (i = 0; expected_base64[i]; i++) - _test_unbase64char(expected_base64[i], FALSE); - - r = nm_sd_utils_unbase64mem(expected_base64, - strlen(expected_base64), - TRUE, - &exp2_arr, - &exp2_len); - g_assert_cmpint(r, ==, 0); - g_assert_cmpmem(expected_arr, expected_len, exp2_arr, exp2_len); - - if (!nm_streq(base64, expected_base64)) { - r = nm_sd_utils_unbase64mem(base64, strlen(base64), TRUE, &exp3_arr, &exp3_len); - g_assert_cmpint(r, ==, 0); - g_assert_cmpmem(expected_arr, expected_len, exp3_arr, exp3_len); - } -} - -#define _test_unbase64mem(base64, expected_str) \ - _test_unbase64mem_mem(base64, (const guint8 *) "" expected_str "", NM_STRLEN(expected_str)) - -static void -_test_unbase64mem_inval(const char *base64) -{ - gs_free guint8 *exp_arr = NULL; - gsize exp_len = 0; - int r; - - r = nm_sd_utils_unbase64mem(base64, strlen(base64), TRUE, &exp_arr, &exp_len); - g_assert_cmpint(r, <, 0); - g_assert(!exp_arr); - g_assert(exp_len == 0); -} - -static void -test_nm_sd_utils_unbase64mem(void) -{ - gs_free char *rnd_base64 = NULL; - guint8 rnd_buf[30]; - guint i, rnd_len; - - _test_unbase64mem("", ""); - _test_unbase64mem(" ", ""); - _test_unbase64mem(" Y Q == ", "a"); - _test_unbase64mem(" Y WJjZGV mZ 2g = ", "abcdefgh"); - _test_unbase64mem_inval(" Y %WJjZGV mZ 2g = "); - _test_unbase64mem_inval(" Y %WJjZGV mZ 2g = a"); - _test_unbase64mem("YQ==", "a"); - _test_unbase64mem_inval("YQ==a"); - - rnd_len = nmtst_get_rand_uint32() % sizeof(rnd_buf); - for (i = 0; i < rnd_len; i++) - rnd_buf[i] = nmtst_get_rand_uint32() % 256; - rnd_base64 = g_base64_encode(rnd_buf, rnd_len); - _test_unbase64mem_mem(rnd_base64, rnd_buf, rnd_len); - - _test_unbase64char('=', FALSE); - for (i = 0; i < 10; i++) { - char ch = nmtst_get_rand_uint32() % 256; - - if (ch != '=') - _test_unbase64char(ch, TRUE); - } -} - -/*****************************************************************************/ - NMTST_DEFINE(); int @@ -261,11 +105,8 @@ main(int argc, char **argv) { nmtst_init(&argc, &argv, TRUE); - g_test_add_func("/systemd/dhcp/create", test_dhcp_create); g_test_add_func("/systemd/lldp/create", test_lldp_create); g_test_add_func("/systemd/sd-event", test_sd_event); - g_test_add_func("/systemd/test_path_equal", test_path_equal); - g_test_add_func("/systemd/test_nm_sd_utils_unbase64mem", test_nm_sd_utils_unbase64mem); return g_test_run(); } diff --git a/src/core/tests/test-utils.c b/src/core/tests/test-utils.c index ad9950dd..2bcb6f69 100644 --- a/src/core/tests/test-utils.c +++ b/src/core/tests/test-utils.c @@ -234,8 +234,10 @@ test_shorten_hostname(void) * system configuration (`getconf HOST_NAME_MAX`). On Linux * it's typically 64 characters, but POSIX allows up to * 255 characters. + * + * We use our own define NM_HOST_NAME_MAX, which is always 64. */ - maxhost = g_strnfill(HOST_NAME_MAX, 'a'); + maxhost = g_strnfill(NM_HOST_NAME_MAX, 'a'); do_test_shorten_hostname("name1", TRUE, NULL); |