]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Add and use assertion_file_mode() in other tests
authorGraham Percival <gperciva@tarsnap.com>
Mon, 26 Sep 2016 19:20:25 +0000 (12:20 -0700)
committerGraham Percival <gperciva@tarsnap.com>
Mon, 26 Sep 2016 19:44:56 +0000 (12:44 -0700)
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.

cat/test/main.c
cat/test/test.h
cpio/test/main.c
cpio/test/test.h
tar/test/main.c
tar/test/test.h

index 0aa1deb572b361caf67132553e5d43f839455515..24071baf18e3f46d166471ef8e50817965f99b99 100644 (file)
@@ -1360,6 +1360,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,
@@ -1578,8 +1603,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);
@@ -1644,6 +1671,7 @@ assertion_make_file(const char *file, int line,
                }
        }
        close(fd);
+       assertion_file_mode(file, line, path, mode);
        return (1);
 #endif
 }
index 704a137ed3fb82a9fd953a6291c91dc8edb3352b..35a0bc790378cce5440096011573c12083a4b602 100644 (file)
@@ -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);
index 1c9ae6e2be5437e0371dd5761ebf14cd40d435f4..985a959b510bec93861d45b237cfe8388f1560cb 100644 (file)
@@ -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
 }
index 606b121bba6e14872d8069e7c749eee0c1e64308..ecc6f27911b27b6676f2e96263f75f886aea20fc 100644 (file)
@@ -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);
index 08ac6277370a2351fe07337e3eb61300e971e409..1855097f552bc9ce6993cb528d3fd2958c9b4cc3 100644 (file)
@@ -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
 }
index 704a137ed3fb82a9fd953a6291c91dc8edb3352b..35a0bc790378cce5440096011573c12083a4b602 100644 (file)
@@ -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);