]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: move fs-util related tests to test-fs-util.c
authorRonny Chevalier <chevalier.ronny@gmail.com>
Wed, 2 Mar 2016 23:14:18 +0000 (00:14 +0100)
committerRonny Chevalier <chevalier.ronny@gmail.com>
Thu, 3 Mar 2016 18:04:06 +0000 (19:04 +0100)
.gitignore
Makefile.am
src/test/test-fs-util.c [new file with mode: 0644]
src/test/test-util.c

index 993436fc310edea345e5d5a7263111aa6dff124a..569be9506a2053165e7332214594c23242b6a2bc 100644 (file)
 /test-fdset
 /test-fileio
 /test-firewall-util
+/test-fs-util
 /test-fstab-util
 /test-hashmap
 /test-hexdecoct
index 7b4254c16985caa85d952001635f9543d402428c..f18bc614a829e024cc36e911b419d0e755b3e1ad 100644 (file)
@@ -1430,6 +1430,7 @@ tests += \
        test-hexdecoct \
        test-escape \
        test-alloc-util \
+       test-fs-util \
        test-web-util \
        test-stat-util \
        test-fd-util \
@@ -1774,6 +1775,12 @@ test_alloc_util_SOURCES = \
 test_alloc_util_LDADD = \
        libbasic.la
 
+test_fs_util_SOURCES = \
+       src/test/test-fs-util.c
+
+test_fs_util_LDADD = \
+       libbasic.la
+
 test_fd_util_SOURCES = \
        src/test/test-fd-util.c
 
diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c
new file mode 100644 (file)
index 0000000..6db2c2b
--- /dev/null
@@ -0,0 +1,91 @@
+/***
+  This file is part of systemd.
+
+  Copyright 2010 Lennart Poettering
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <unistd.h>
+
+#include "alloc-util.h"
+#include "fileio.h"
+#include "fd-util.h"
+#include "fs-util.h"
+#include "macro.h"
+#include "mkdir.h"
+#include "rm-rf.h"
+#include "string-util.h"
+#include "strv.h"
+#include "util.h"
+
+static void test_unlink_noerrno(void) {
+        char name[] = "/tmp/test-close_nointr.XXXXXX";
+        int fd;
+
+        fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
+        assert_se(fd >= 0);
+        assert_se(close_nointr(fd) >= 0);
+
+        {
+                PROTECT_ERRNO;
+                errno = -42;
+                assert_se(unlink_noerrno(name) >= 0);
+                assert_se(errno == -42);
+                assert_se(unlink_noerrno(name) < 0);
+                assert_se(errno == -42);
+        }
+}
+
+static void test_readlink_and_make_absolute(void) {
+        char tempdir[] = "/tmp/test-readlink_and_make_absolute";
+        char name[] = "/tmp/test-readlink_and_make_absolute/original";
+        char name2[] = "test-readlink_and_make_absolute/original";
+        char name_alias[] = "/tmp/test-readlink_and_make_absolute-alias";
+        char *r = NULL;
+
+        assert_se(mkdir_safe(tempdir, 0755, getuid(), getgid()) >= 0);
+        assert_se(touch(name) >= 0);
+
+        assert_se(symlink(name, name_alias) >= 0);
+        assert_se(readlink_and_make_absolute(name_alias, &r) >= 0);
+        assert_se(streq(r, name));
+        free(r);
+        assert_se(unlink(name_alias) >= 0);
+
+        assert_se(chdir(tempdir) >= 0);
+        assert_se(symlink(name2, name_alias) >= 0);
+        assert_se(readlink_and_make_absolute(name_alias, &r) >= 0);
+        assert_se(streq(r, name));
+        free(r);
+        assert_se(unlink(name_alias) >= 0);
+
+        assert_se(rm_rf(tempdir, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
+}
+
+static void test_get_files_in_directory(void) {
+        _cleanup_strv_free_ char **l = NULL, **t = NULL;
+
+        assert_se(get_files_in_directory("/tmp", &l) >= 0);
+        assert_se(get_files_in_directory(".", &t) >= 0);
+        assert_se(get_files_in_directory(".", NULL) >= 0);
+}
+
+int main(int argc, char *argv[]) {
+        test_unlink_noerrno();
+        test_readlink_and_make_absolute();
+        test_get_files_in_directory();
+
+        return 0;
+}
index 7226e9b76f8b7a2f391b4ed928ab75d294f12581..b787a5e5f01b08b4dcd638e0dccf7c9544384cbe 100644 (file)
@@ -223,14 +223,6 @@ static void test_fstab_node_to_udev_node(void) {
         free(n);
 }
 
-static void test_get_files_in_directory(void) {
-        _cleanup_strv_free_ char **l = NULL, **t = NULL;
-
-        assert_se(get_files_in_directory("/tmp", &l) >= 0);
-        assert_se(get_files_in_directory(".", &t) >= 0);
-        assert_se(get_files_in_directory(".", NULL) >= 0);
-}
-
 static void test_in_set(void) {
         assert_se(IN_SET(1, 1));
         assert_se(IN_SET(1, 1, 2, 3, 4));
@@ -252,50 +244,6 @@ static void test_log2i(void) {
         assert_se(log2i(INT_MAX) == sizeof(int)*8-2);
 }
 
-static void test_unlink_noerrno(void) {
-        char name[] = "/tmp/test-close_nointr.XXXXXX";
-        int fd;
-
-        fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
-        assert_se(fd >= 0);
-        assert_se(close_nointr(fd) >= 0);
-
-        {
-                PROTECT_ERRNO;
-                errno = -42;
-                assert_se(unlink_noerrno(name) >= 0);
-                assert_se(errno == -42);
-                assert_se(unlink_noerrno(name) < 0);
-                assert_se(errno == -42);
-        }
-}
-
-static void test_readlink_and_make_absolute(void) {
-        char tempdir[] = "/tmp/test-readlink_and_make_absolute";
-        char name[] = "/tmp/test-readlink_and_make_absolute/original";
-        char name2[] = "test-readlink_and_make_absolute/original";
-        char name_alias[] = "/tmp/test-readlink_and_make_absolute-alias";
-        char *r = NULL;
-
-        assert_se(mkdir_safe(tempdir, 0755, getuid(), getgid()) >= 0);
-        assert_se(touch(name) >= 0);
-
-        assert_se(symlink(name, name_alias) >= 0);
-        assert_se(readlink_and_make_absolute(name_alias, &r) >= 0);
-        assert_se(streq(r, name));
-        free(r);
-        assert_se(unlink(name_alias) >= 0);
-
-        assert_se(chdir(tempdir) >= 0);
-        assert_se(symlink(name2, name_alias) >= 0);
-        assert_se(readlink_and_make_absolute(name_alias, &r) >= 0);
-        assert_se(streq(r, name));
-        free(r);
-        assert_se(unlink(name_alias) >= 0);
-
-        assert_se(rm_rf(tempdir, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
-}
-
 static void test_glob_exists(void) {
         char name[] = "/tmp/test-glob_exists.XXXXXX";
         int fd = -1;
@@ -479,11 +427,8 @@ int main(int argc, char *argv[]) {
         test_u64log2();
         test_protect_errno();
         test_fstab_node_to_udev_node();
-        test_get_files_in_directory();
         test_in_set();
         test_log2i();
-        test_unlink_noerrno();
-        test_readlink_and_make_absolute();
         test_glob_exists();
         test_execute_directory();
         test_parse_proc_cmdline();