|
18 | 18 | #include "tests.h" |
19 | 19 | #include "tmpfile-util.h" |
20 | 20 |
|
| 21 | +TEST(null_or_empty_path) { |
| 22 | + assert_se(null_or_empty_path("/dev/null") == 1); |
| 23 | + assert_se(null_or_empty_path("/dev/tty") == 1); /* We assume that any character device is "empty", bleh. */ |
| 24 | + assert_se(null_or_empty_path("../../../../../../../../../../../../../../../../../../../../dev/null") == 1); |
| 25 | + assert_se(null_or_empty_path("/proc/self/exe") == 0); |
| 26 | + assert_se(null_or_empty_path("/nosuchfileordir") == -ENOENT); |
| 27 | +} |
| 28 | + |
| 29 | +TEST(null_or_empty_path_with_root) { |
| 30 | + assert_se(null_or_empty_path_with_root("/dev/null", NULL) == 1); |
| 31 | + assert_se(null_or_empty_path_with_root("/dev/null", "/") == 1); |
| 32 | + assert_se(null_or_empty_path_with_root("/dev/null", "/.././../") == 1); |
| 33 | + assert_se(null_or_empty_path_with_root("/dev/null", "/.././..") == 1); |
| 34 | + assert_se(null_or_empty_path_with_root("../../../../../../../../../../../../../../../../../../../../dev/null", NULL) == 1); |
| 35 | + assert_se(null_or_empty_path_with_root("../../../../../../../../../../../../../../../../../../../../dev/null", "/") == 1); |
| 36 | + assert_se(null_or_empty_path_with_root("/proc/self/exe", NULL) == 0); |
| 37 | + assert_se(null_or_empty_path_with_root("/proc/self/exe", "/") == 0); |
| 38 | + assert_se(null_or_empty_path_with_root("/nosuchfileordir", NULL) == -ENOENT); |
| 39 | + assert_se(null_or_empty_path_with_root("/nosuchfileordir", "/.././../") == -ENOENT); |
| 40 | + assert_se(null_or_empty_path_with_root("/nosuchfileordir", "/.././..") == -ENOENT); |
| 41 | + assert_se(null_or_empty_path_with_root("/foobar/barbar/dev/null", "/foobar/barbar") == 1); |
| 42 | + assert_se(null_or_empty_path_with_root("/foobar/barbar/dev/null", "/foobar/barbar/") == 1); |
| 43 | +} |
| 44 | + |
21 | 45 | TEST(files_same) { |
22 | 46 | _cleanup_close_ int fd = -1; |
23 | 47 | char name[] = "/tmp/test-files_same.XXXXXX"; |
|
0 commit comments