1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-02 10:51:20 +03:00

tests: move path-util related tests to test-path-util.c

This commit is contained in:
Ronny Chevalier 2016-03-02 23:54:35 +01:00
parent 897891f02e
commit 6329266386
2 changed files with 46 additions and 46 deletions

View File

@ -433,6 +433,50 @@ static void test_path_is_mount_point(void) {
assert_se(rm_rf(tmp_dir, REMOVE_ROOT|REMOVE_PHYSICAL) == 0);
}
static void test_file_in_same_dir(void) {
char *t;
t = file_in_same_dir("/", "a");
assert_se(streq(t, "/a"));
free(t);
t = file_in_same_dir("/", "/a");
assert_se(streq(t, "/a"));
free(t);
t = file_in_same_dir("", "a");
assert_se(streq(t, "a"));
free(t);
t = file_in_same_dir("a/", "a");
assert_se(streq(t, "a/a"));
free(t);
t = file_in_same_dir("bar/foo", "bar");
assert_se(streq(t, "bar/bar"));
free(t);
}
static void test_filename_is_valid(void) {
char foo[FILENAME_MAX+2];
int i;
assert_se(!filename_is_valid(""));
assert_se(!filename_is_valid("/bar/foo"));
assert_se(!filename_is_valid("/"));
assert_se(!filename_is_valid("."));
assert_se(!filename_is_valid(".."));
for (i=0; i<FILENAME_MAX+1; i++)
foo[i] = 'a';
foo[FILENAME_MAX+1] = '\0';
assert_se(!filename_is_valid(foo));
assert_se(filename_is_valid("foo_bar-333"));
assert_se(filename_is_valid("o.o"));
}
int main(int argc, char **argv) {
test_path();
test_find_binary(argv[0]);
@ -444,6 +488,8 @@ int main(int argc, char **argv) {
test_path_startswith();
test_prefix_root();
test_path_is_mount_point();
test_file_in_same_dir();
test_filename_is_valid();
return 0;
}

View File

@ -300,50 +300,6 @@ static void test_log2i(void) {
assert_se(log2i(INT_MAX) == sizeof(int)*8-2);
}
static void test_filename_is_valid(void) {
char foo[FILENAME_MAX+2];
int i;
assert_se(!filename_is_valid(""));
assert_se(!filename_is_valid("/bar/foo"));
assert_se(!filename_is_valid("/"));
assert_se(!filename_is_valid("."));
assert_se(!filename_is_valid(".."));
for (i=0; i<FILENAME_MAX+1; i++)
foo[i] = 'a';
foo[FILENAME_MAX+1] = '\0';
assert_se(!filename_is_valid(foo));
assert_se(filename_is_valid("foo_bar-333"));
assert_se(filename_is_valid("o.o"));
}
static void test_file_in_same_dir(void) {
char *t;
t = file_in_same_dir("/", "a");
assert_se(streq(t, "/a"));
free(t);
t = file_in_same_dir("/", "/a");
assert_se(streq(t, "/a"));
free(t);
t = file_in_same_dir("", "a");
assert_se(streq(t, "a"));
free(t);
t = file_in_same_dir("a/", "a");
assert_se(streq(t, "a/a"));
free(t);
t = file_in_same_dir("bar/foo", "bar");
assert_se(streq(t, "bar/bar"));
free(t);
}
static void test_close_nointr(void) {
char name[] = "/tmp/test-test-close_nointr.XXXXXX";
int fd;
@ -632,8 +588,6 @@ int main(int argc, char *argv[]) {
test_get_files_in_directory();
test_in_set();
test_log2i();
test_filename_is_valid();
test_file_in_same_dir();
test_close_nointr();
test_unlink_noerrno();
test_readlink_and_make_absolute();