diff options
author | Graham Percival <gperciva@tarsnap.com> | 2016-09-26 12:20:25 -0700 |
---|---|---|
committer | Graham Percival <gperciva@tarsnap.com> | 2016-09-26 12:44:56 -0700 |
commit | 0f14b0816b2422bd4478e68610a4b6c67f9f68e1 (patch) | |
tree | 5e671c4a89c23933b3ee95bfed2d6ca86c900097 /tar | |
parent | 75de4e4a21d3564f1255681695672840792cb52b (diff) | |
download | libarchive-0f14b0816b2422bd4478e68610a4b6c67f9f68e1.tar.gz |
Add and use assertion_file_mode() in other tests
This adds the assertion_file_mode() function from
libarchive/test/main.c
and applies it to
cat/test/main.c
cpio/test/main.c
tar/test/main.c
Sponsored by: Tarsnap Backup Inc.
Diffstat (limited to 'tar')
-rw-r--r-- | tar/test/main.c | 30 | ||||
-rw-r--r-- | tar/test/test.h | 1 |
2 files changed, 30 insertions, 1 deletions
diff --git a/tar/test/main.c b/tar/test/main.c index 08ac6277..1855097f 100644 --- a/tar/test/main.c +++ b/tar/test/main.c @@ -1361,6 +1361,31 @@ assertion_file_birthtime_recent(const char *file, int line, return assertion_file_time(file, line, pathname, 0, 0, 'b', 1); } +/* Verify mode of 'pathname'. */ +int +assertion_file_mode(const char *file, int line, const char *pathname, int expected_mode) +{ + int mode; + int r; + + assertion_count(file, line); +#if defined(_WIN32) && !defined(__CYGWIN__) + failure_start(file, line, "assertFileMode not yet implemented for Windows"); +#else + { + struct stat st; + r = lstat(pathname, &st); + mode = (int)(st.st_mode & 0777); + } + if (r == 0 && mode == expected_mode) + return (1); + failure_start(file, line, "File %s has mode %o, expected %o", + pathname, mode, expected_mode); +#endif + failure_finish(NULL); + return (0); +} + /* Verify mtime of 'pathname'. */ int assertion_file_mtime(const char *file, int line, @@ -1579,8 +1604,10 @@ assertion_make_dir(const char *file, int line, const char *dirname, int mode) if (0 == _mkdir(dirname)) return (1); #else - if (0 == mkdir(dirname, mode)) + if (0 == mkdir(dirname, mode)) { + assertion_file_mode(file, line, dirname, mode); return (1); + } #endif failure_start(file, line, "Could not create directory %s", dirname); failure_finish(NULL); @@ -1645,6 +1672,7 @@ assertion_make_file(const char *file, int line, } } close(fd); + assertion_file_mode(file, line, path, mode); return (1); #endif } diff --git a/tar/test/test.h b/tar/test/test.h index 704a137e..35a0bc79 100644 --- a/tar/test/test.h +++ b/tar/test/test.h @@ -241,6 +241,7 @@ int assertion_file_birthtime_recent(const char *, int, const char *); int assertion_file_contains_lines_any_order(const char *, int, const char *, const char **); int assertion_file_contents(const char *, int, const void *, int, const char *); int assertion_file_exists(const char *, int, const char *); +int assertion_file_mode(const char *, int, const char *, int); int assertion_file_mtime(const char *, int, const char *, long, long); int assertion_file_mtime_recent(const char *, int, const char *); int assertion_file_nlinks(const char *, int, const char *, int); |