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

index 147552469919539972fdeda178bea4514e291209..f6139960cd924ee8004cce7be3f1586b85d21518 100644 (file)
 /test-siphash24
 /test-sleep
 /test-socket-util
+/test-stat-util
 /test-strbuf
 /test-string-util
 /test-strip-tab-ansi
index 2943f51d451594ed5146a8a26da7a2836b24ca91..1212b4787395be1b9586303cd5daa8e45ea3d340 100644 (file)
@@ -1431,6 +1431,7 @@ tests += \
        test-escape \
        test-alloc-util \
        test-web-util \
+       test-stat-util \
        test-string-util \
        test-extract-word \
        test-parse-util \
@@ -1784,6 +1785,12 @@ test_cpu_set_util_SOURCES = \
 test_cpu_set_util_LDADD = \
        libbasic.la
 
+test_stat_util_SOURCES = \
+       src/test/test-stat-util.c
+
+test_stat_util_LDADD = \
+       libbasic.la
+
 test_escape_SOURCES = \
        src/test/test-escape.c
 
diff --git a/src/test/test-stat-util.c b/src/test/test-stat-util.c
new file mode 100644 (file)
index 0000000..a10227f
--- /dev/null
@@ -0,0 +1,68 @@
+/***
+  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 <fcntl.h>
+#include <unistd.h>
+
+#include "alloc-util.h"
+#include "fd-util.h"
+#include "fileio.h"
+#include "macro.h"
+#include "stat-util.h"
+
+static void test_files_same(void) {
+        _cleanup_close_ int fd = -1;
+        char name[] = "/tmp/test-files_same.XXXXXX";
+        char name_alias[] = "/tmp/test-files_same.alias";
+
+        fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
+        assert_se(fd >= 0);
+        assert_se(symlink(name, name_alias) >= 0);
+
+        assert_se(files_same(name, name));
+        assert_se(files_same(name, name_alias));
+
+        unlink(name);
+        unlink(name_alias);
+}
+
+static void test_is_symlink(void) {
+        char name[] = "/tmp/test-is_symlink.XXXXXX";
+        char name_link[] = "/tmp/test-is_symlink.link";
+        _cleanup_close_ int fd = -1;
+
+        fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
+        assert_se(fd >= 0);
+        assert_se(symlink(name, name_link) >= 0);
+
+        assert_se(is_symlink(name) == 0);
+        assert_se(is_symlink(name_link) == 1);
+        assert_se(is_symlink("/a/file/which/does/not/exist/i/guess") < 0);
+
+
+        unlink(name);
+        unlink(name_link);
+}
+
+int main(int argc, char *argv[]) {
+        test_files_same();
+        test_is_symlink();
+
+        return 0;
+}
index 60ed7f9aa0320608caa5b10f11155eaebda9611b..63ee614b2d7feeccdb31411f44ea7e3fbfd92a3a 100644 (file)
@@ -42,7 +42,6 @@
 #include "process-util.h"
 #include "rm-rf.h"
 #include "special.h"
-#include "stat-util.h"
 #include "string-util.h"
 #include "strv.h"
 #include "user-util.h"
@@ -346,22 +345,6 @@ static void test_filename_is_valid(void) {
         assert_se(filename_is_valid("o.o"));
 }
 
-static void test_files_same(void) {
-        _cleanup_close_ int fd = -1;
-        char name[] = "/tmp/test-files_same.XXXXXX";
-        char name_alias[] = "/tmp/test-files_same.alias";
-
-        fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
-        assert_se(fd >= 0);
-        assert_se(symlink(name, name_alias) >= 0);
-
-        assert_se(files_same(name, name));
-        assert_se(files_same(name, name_alias));
-
-        unlink(name);
-        unlink(name_alias);
-}
-
 static void test_file_in_same_dir(void) {
         char *t;
 
@@ -443,24 +426,6 @@ static void test_readlink_and_make_absolute(void) {
         assert_se(rm_rf(tempdir, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
 }
 
-static void test_is_symlink(void) {
-        char name[] = "/tmp/test-is_symlink.XXXXXX";
-        char name_link[] = "/tmp/test-is_symlink.link";
-        _cleanup_close_ int fd = -1;
-
-        fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
-        assert_se(fd >= 0);
-        assert_se(symlink(name, name_link) >= 0);
-
-        assert_se(is_symlink(name) == 0);
-        assert_se(is_symlink(name_link) == 1);
-        assert_se(is_symlink("/a/file/which/does/not/exist/i/guess") < 0);
-
-
-        unlink(name);
-        unlink(name_link);
-}
-
 static void test_search_and_fopen(void) {
         const char *dirs[] = {"/tmp/foo/bar", "/tmp", NULL};
         char name[] = "/tmp/test-search_and_fopen.XXXXXX";
@@ -798,12 +763,10 @@ int main(int argc, char *argv[]) {
         test_writing_tmpfile();
         test_log2i();
         test_filename_is_valid();
-        test_files_same();
         test_file_in_same_dir();
         test_close_nointr();
         test_unlink_noerrno();
         test_readlink_and_make_absolute();
-        test_is_symlink();
         test_search_and_fopen();
         test_search_and_fopen_nulstr();
         test_glob_exists();