diff options
Diffstat (limited to 'src/tests/test-systemd.c')
| -rw-r--r-- | src/tests/test-systemd.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/tests/test-systemd.c b/src/tests/test-systemd.c index ab5fed22..4660bd0d 100644 --- a/src/tests/test-systemd.c +++ b/src/tests/test-systemd.c @@ -20,6 +20,7 @@ #include "nm-default.h" #include "systemd/nm-sd.h" +#include "systemd/nm-sd-utils.h" #include "nm-test-utils-core.h" @@ -173,6 +174,50 @@ test_sd_event (void) /*****************************************************************************/ +static void +test_path_equal (void) +{ +#define _path_equal_check1(path, kill_dots, expected) \ + G_STMT_START { \ + const gboolean _kill_dots = (kill_dots); \ + const char *_path0 = (path); \ + const char *_expected = (expected); \ + gs_free char *_path = g_strdup (_path0); \ + const char *_path_result; \ + \ + if ( !_kill_dots \ + && !nm_sd_utils_path_equal (_path0, _expected)) \ + g_error ("Paths \"%s\" and \"%s\" don't compare equal", _path0, _expected); \ + \ + _path_result = nm_sd_utils_path_simplify (_path, _kill_dots); \ + g_assert (_path_result == _path); \ + g_assert_cmpstr (_path, ==, _expected); \ + } G_STMT_END + +#define _path_equal_check(path, expected_no_kill_dots, expected_kill_dots) \ + G_STMT_START { \ + _path_equal_check1 (path, FALSE, expected_no_kill_dots); \ + _path_equal_check1 (path, TRUE, expected_kill_dots ?: expected_no_kill_dots); \ + } G_STMT_END + + _path_equal_check ("", "", NULL); + _path_equal_check (".", ".", ""); + _path_equal_check ("..", "..", NULL); + _path_equal_check ("/..", "/..", NULL); + _path_equal_check ("//..", "/..", NULL); + _path_equal_check ("/.", "/.", "/"); + _path_equal_check ("./", ".", ""); + _path_equal_check ("./.", "./.", ""); + _path_equal_check (".///.", "./.", ""); + _path_equal_check (".///./", "./.", ""); + _path_equal_check (".////", ".", ""); + _path_equal_check ("//..//foo/", "/../foo", NULL); + _path_equal_check ("///foo//./bar/.", "/foo/./bar/.", "/foo/bar"); + _path_equal_check (".//./foo//./bar/.", "././foo/./bar/.", "foo/bar"); +} + +/*****************************************************************************/ + NMTST_DEFINE (); int @@ -183,6 +228,7 @@ main (int argc, char **argv) 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); return g_test_run (); } |