]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-sd-path: basic test for the sd-path API
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 23 Mar 2020 18:12:55 +0000 (19:12 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 27 Mar 2020 19:12:44 +0000 (20:12 +0100)
src/test/meson.build
src/test/test-sd-path.c [new file with mode: 0644]

index 7c55f65be1cdeabe086175fc5ce7db1af09ab137..a8e81311f7e55301f0abd0a3e47a627431662a2e 100644 (file)
@@ -778,6 +778,10 @@ tests += [
          [],
          []],
 
+        [['src/test/test-sd-path.c'],
+         [],
+         []],
+
         [['src/test/test-local-addresses.c'],
          [],
          []],
diff --git a/src/test/test-sd-path.c b/src/test/test-sd-path.c
new file mode 100644 (file)
index 0000000..780a62a
--- /dev/null
@@ -0,0 +1,61 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include "sd-path.h"
+
+#include "alloc-util.h"
+#include "string-util.h"
+#include "strv.h"
+#include "tests.h"
+
+static void test_sd_path_home(void) {
+        log_info("/* %s */", __func__);
+
+        for (uint64_t i = 0; i < _SD_PATH_MAX; i++) {
+                _cleanup_free_ char *t, *s;
+
+                assert_se(sd_path_home(i, NULL, &t) == 0);
+                assert_se(t);
+                log_info("%02"PRIu64": \"%s\"", i, t);
+
+                assert_se(sd_path_home(i, "suffix", &s) == 0);
+                assert_se(s);
+                log_info("%02"PRIu64": \"%s\"", i, s);
+                assert_se(endswith(s, "/suffix"));
+        }
+
+        char *tt;
+        assert_se(sd_path_home(_SD_PATH_MAX, NULL, &tt) == -EOPNOTSUPP);
+}
+
+static void test_sd_path_search(void) {
+        log_info("/* %s */", __func__);
+
+        for (uint64_t i = 0; i < _SD_PATH_MAX; i++) {
+                _cleanup_strv_free_ char **t, **s;
+                char **item;
+
+                assert_se(sd_path_search(i, NULL, &t) == 0);
+                assert_se(t);
+                log_info("%02"PRIu64":", i);
+                STRV_FOREACH(item, t)
+                        log_debug("  %s", *item);
+
+                assert_se(sd_path_search(i, "suffix", &s) == 0);
+                assert_se(s);
+                log_info("%02"PRIu64":", i);
+                STRV_FOREACH(item, s) {
+                        assert_se(endswith(*item, "/suffix"));
+                        log_debug("  %s", *item);
+                }
+        }
+
+        char *tt;
+        assert_se(sd_path_home(_SD_PATH_MAX, NULL, &tt) == -EOPNOTSUPP);
+}
+
+int main(void) {
+        test_setup_logging(LOG_DEBUG);
+
+        test_sd_path_home();
+        test_sd_path_search();
+}