mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-10 01:17:44 +03:00
tests: move stat-util related tests to test-stat-util.c
This commit is contained in:
parent
ede4edd31e
commit
f4c13ad76f
1
.gitignore
vendored
1
.gitignore
vendored
@ -258,6 +258,7 @@
|
||||
/test-siphash24
|
||||
/test-sleep
|
||||
/test-socket-util
|
||||
/test-stat-util
|
||||
/test-strbuf
|
||||
/test-string-util
|
||||
/test-strip-tab-ansi
|
||||
|
@ -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
|
||||
|
||||
|
68
src/test/test-stat-util.c
Normal file
68
src/test/test-stat-util.c
Normal file
@ -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;
|
||||
}
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user