diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile.am | 7 | ||||
-rw-r--r-- | src/test/test-stat-util.c | 68 | ||||
-rw-r--r-- | src/test/test-util.c | 37 |
4 files changed, 76 insertions, 37 deletions
diff --git a/.gitignore b/.gitignore index 1475524699..f6139960cd 100644 --- a/.gitignore +++ b/.gitignore @@ -258,6 +258,7 @@ /test-siphash24 /test-sleep /test-socket-util +/test-stat-util /test-strbuf /test-string-util /test-strip-tab-ansi diff --git a/Makefile.am b/Makefile.am index 2943f51d45..1212b47873 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 0000000000..a10227f823 --- /dev/null +++ b/src/test/test-stat-util.c @@ -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; +} diff --git a/src/test/test-util.c b/src/test/test-util.c index 60ed7f9aa0..63ee614b2d 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -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(); |