]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Sync up the test harnesses, fix an "unused var" warning on Windows
authorTim Kientzle <kientzle@acm.org>
Sun, 23 Oct 2016 22:21:59 +0000 (15:21 -0700)
committerTim Kientzle <kientzle@acm.org>
Sun, 23 Oct 2016 22:21:59 +0000 (15:21 -0700)
cat/test/main.c
cat/test/test.h
cpio/test/main.c
cpio/test/test.h
libarchive/test/main.c
libarchive/test/test.h
tar/test/main.c
tar/test/test.h

index 29f7b14b1849746a490b669c6513fcbb957a128c..a57984294fe4d9bd8c3913599d37ac5cfcc5cb54 100644 (file)
 # include <crtdbg.h>
 #endif
 
+mode_t umasked(mode_t expected_mode)
+{
+       mode_t mode = umask(0);
+       umask(mode);
+       return expected_mode & ~mode;
+}
+
 /* Path to working directory for current test */
 const char *testworkdir;
 #ifdef PROGRAM
@@ -1156,6 +1163,35 @@ assertion_file_contains_lines_any_order(const char *file, int line,
        return (0);
 }
 
+/* Verify that a text file does not contains the specified strings */
+int
+assertion_file_contains_no_invalid_strings(const char *file, int line,
+    const char *pathname, const char *strings[])
+{
+       char *buff;
+       int i;
+
+       buff = slurpfile(NULL, "%s", pathname);
+       if (buff == NULL) {
+               failure_start(file, line, "Can't read file: %s", pathname);
+               failure_finish(NULL);
+               return (0);
+       }
+
+       for (i = 0; strings[i] != NULL; ++i) {
+               if (strstr(buff, strings[i]) != NULL) {
+                       failure_start(file, line, "Invalid string in %s: %s", pathname,
+                           strings[i]);
+                       failure_finish(NULL);
+                       free(buff);
+                       return(0);
+               }
+       }
+
+       free(buff);
+       return (0);
+}
+
 /* Test that two paths point to the same file. */
 /* As a side-effect, asserts that both files exist. */
 static int
@@ -1293,6 +1329,11 @@ assertion_file_time(const char *file, int line,
        switch (type) {
        case 'a': filet_nsec = st.st_atimespec.tv_nsec; break;
        case 'b': filet = st.st_birthtime;
+               /* FreeBSD filesystems that don't support birthtime
+                * (e.g., UFS1) always return -1 here. */
+               if (filet == -1) {
+                       return (1);
+               }
                filet_nsec = st.st_birthtimespec.tv_nsec; break;
        case 'm': filet_nsec = st.st_mtimespec.tv_nsec; break;
        default: fprintf(stderr, "INTERNAL: Bad type %c for file time", type);
@@ -1370,6 +1411,8 @@ assertion_file_mode(const char *file, int line, const char *pathname, int expect
        assertion_count(file, line);
 #if defined(_WIN32) && !defined(__CYGWIN__)
        failure_start(file, line, "assertFileMode not yet implemented for Windows");
+       (void)mode; /* UNUSED */
+       (void)r; /* UNUSED */
 #else
        {
                struct stat st;
@@ -1424,7 +1467,7 @@ assertion_file_nlinks(const char *file, int line,
        assertion_count(file, line);
        r = lstat(pathname, &st);
        if (r == 0 && (int)st.st_nlink == nlinks)
-                       return (1);
+               return (1);
        failure_start(file, line, "File %s has %d links, expected %d",
            pathname, st.st_nlink, nlinks);
        failure_finish(NULL);
@@ -1660,6 +1703,7 @@ assertion_make_file(const char *file, int line,
        if (0 != chmod(path, mode)) {
                failure_start(file, line, "Could not chmod %s", path);
                failure_finish(NULL);
+               close(fd);
                return (0);
        }
        if (contents != NULL) {
@@ -1674,6 +1718,7 @@ assertion_make_file(const char *file, int line,
                        failure_start(file, line,
                            "Could not write to %s", path);
                        failure_finish(NULL);
+                       close(fd);
                        return (0);
                }
        }
index 35a0bc790378cce5440096011573c12083a4b602..3a23a05a67ec30bcc59d2358455954752140757e 100644 (file)
 /* Assert that file contents match a string. */
 #define assertFileContents(data, data_size, pathname) \
   assertion_file_contents(__FILE__, __LINE__, data, data_size, pathname)
+/* Verify that a file does not contain invalid strings */
+#define assertFileContainsNoInvalidStrings(pathname, strings) \
+  assertion_file_contains_no_invalid_strings(__FILE__, __LINE__, pathname, strings)
 #define assertFileMtime(pathname, sec, nsec)   \
   assertion_file_mtime(__FILE__, __LINE__, pathname, sec, nsec)
 #define assertFileMtimeRecent(pathname) \
   assertion_file_nlinks(__FILE__, __LINE__, pathname, nlinks)
 #define assertFileSize(pathname, size)  \
   assertion_file_size(__FILE__, __LINE__, pathname, size)
+#define assertFileMode(pathname, mode)  \
+  assertion_file_mode(__FILE__, __LINE__, pathname, mode)
 #define assertTextFileContents(text, pathname) \
   assertion_text_file_contents(__FILE__, __LINE__, text, pathname)
 #define assertFileContainsLinesAnyOrder(pathname, lines)       \
@@ -239,6 +244,7 @@ int assertion_file_atime_recent(const char *, int, const char *);
 int assertion_file_birthtime(const char *, int, const char *, long, long);
 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_contains_no_invalid_strings(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);
@@ -327,6 +333,9 @@ void copy_reference_file(const char *);
  */
 void extract_reference_files(const char **);
 
+/* Subtract umask from mode */
+mode_t umasked(mode_t expected_mode);
+
 /* Path to working directory for current test */
 extern const char *testworkdir;
 
index f3b431d0a6dff5f4232a757268182e6bbd11e7ae..6e6b5ab435d0124db36e84b64545d918ff85bf72 100644 (file)
@@ -1164,6 +1164,35 @@ assertion_file_contains_lines_any_order(const char *file, int line,
        return (0);
 }
 
+/* Verify that a text file does not contains the specified strings */
+int
+assertion_file_contains_no_invalid_strings(const char *file, int line,
+    const char *pathname, const char *strings[])
+{
+       char *buff;
+       int i;
+
+       buff = slurpfile(NULL, "%s", pathname);
+       if (buff == NULL) {
+               failure_start(file, line, "Can't read file: %s", pathname);
+               failure_finish(NULL);
+               return (0);
+       }
+
+       for (i = 0; strings[i] != NULL; ++i) {
+               if (strstr(buff, strings[i]) != NULL) {
+                       failure_start(file, line, "Invalid string in %s: %s", pathname,
+                           strings[i]);
+                       failure_finish(NULL);
+                       free(buff);
+                       return(0);
+               }
+       }
+
+       free(buff);
+       return (0);
+}
+
 /* Test that two paths point to the same file. */
 /* As a side-effect, asserts that both files exist. */
 static int
@@ -1383,6 +1412,8 @@ assertion_file_mode(const char *file, int line, const char *pathname, int expect
        assertion_count(file, line);
 #if defined(_WIN32) && !defined(__CYGWIN__)
        failure_start(file, line, "assertFileMode not yet implemented for Windows");
+       (void)mode; /* UNUSED */
+       (void)r; /* UNUSED */
 #else
        {
                struct stat st;
index 0a8b31e1c8648828d3800b30d3e049f9c40e7e7a..49fa32c99e2527eae9fc5dfb1ef6a1d8af029598 100644 (file)
 /* Assert that file contents match a string. */
 #define assertFileContents(data, data_size, pathname) \
   assertion_file_contents(__FILE__, __LINE__, data, data_size, pathname)
+/* Verify that a file does not contain invalid strings */
+#define assertFileContainsNoInvalidStrings(pathname, strings) \
+  assertion_file_contains_no_invalid_strings(__FILE__, __LINE__, pathname, strings)
 #define assertFileMtime(pathname, sec, nsec)   \
   assertion_file_mtime(__FILE__, __LINE__, pathname, sec, nsec)
 #define assertFileMtimeRecent(pathname) \
@@ -241,6 +244,7 @@ int assertion_file_atime_recent(const char *, int, const char *);
 int assertion_file_birthtime(const char *, int, const char *, long, long);
 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_contains_no_invalid_strings(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);
index aaa5cfa5d4b6bd5a9630623a0d0675e995607f3b..32a1f78b9cf2ef53d63ffb77afead78fcad23ae2 100644 (file)
@@ -1162,6 +1162,35 @@ assertion_file_contains_lines_any_order(const char *file, int line,
        return (0);
 }
 
+/* Verify that a text file does not contains the specified strings */
+int
+assertion_file_contains_no_invalid_strings(const char *file, int line,
+    const char *pathname, const char *strings[])
+{
+       char *buff;
+       int i;
+
+       buff = slurpfile(NULL, "%s", pathname);
+       if (buff == NULL) {
+               failure_start(file, line, "Can't read file: %s", pathname);
+               failure_finish(NULL);
+               return (0);
+       }
+
+       for (i = 0; strings[i] != NULL; ++i) {
+               if (strstr(buff, strings[i]) != NULL) {
+                       failure_start(file, line, "Invalid string in %s: %s", pathname,
+                           strings[i]);
+                       failure_finish(NULL);
+                       free(buff);
+                       return(0);
+               }
+       }
+
+       free(buff);
+       return (0);
+}
+
 /* Test that two paths point to the same file. */
 /* As a side-effect, asserts that both files exist. */
 static int
@@ -1381,6 +1410,8 @@ assertion_file_mode(const char *file, int line, const char *pathname, int expect
        assertion_count(file, line);
 #if defined(_WIN32) && !defined(__CYGWIN__)
        failure_start(file, line, "assertFileMode not yet implemented for Windows");
+       (void)mode; /* UNUSED */
+       (void)r; /* UNUSED */
 #else
        {
                struct stat st;
index 4d5030329d53ad90bd5cf6f6d45de549fc1f939d..a48c42641e89ba82be0a7e31398474a5794a1aba 100644 (file)
 /* Assert that file contents match a string. */
 #define assertFileContents(data, data_size, pathname) \
   assertion_file_contents(__FILE__, __LINE__, data, data_size, pathname)
+/* Verify that a file does not contain invalid strings */
+#define assertFileContainsNoInvalidStrings(pathname, strings) \
+  assertion_file_contains_no_invalid_strings(__FILE__, __LINE__, pathname, strings)
 #define assertFileMtime(pathname, sec, nsec)   \
   assertion_file_mtime(__FILE__, __LINE__, pathname, sec, nsec)
 #define assertFileMtimeRecent(pathname) \
@@ -241,6 +244,7 @@ int assertion_file_atime_recent(const char *, int, const char *);
 int assertion_file_birthtime(const char *, int, const char *, long, long);
 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_contains_no_invalid_strings(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);
index d847964f75e9392f37732268164c486bdadb594b..d35d3356544975e02cdb1545f28deb62671bb752 100644 (file)
@@ -1188,7 +1188,7 @@ assertion_file_contains_no_invalid_strings(const char *file, int line,
                        return(0);
                }
        }
-       
+
        free(buff);
        return (0);
 }
@@ -1412,6 +1412,8 @@ assertion_file_mode(const char *file, int line, const char *pathname, int expect
        assertion_count(file, line);
 #if defined(_WIN32) && !defined(__CYGWIN__)
        failure_start(file, line, "assertFileMode not yet implemented for Windows");
+       (void)mode; /* UNUSED */
+       (void)r; /* UNUSED */
 #else
        {
                struct stat st;
index 98415f8538d8872f68ab90d934a809f6666af36c..3a23a05a67ec30bcc59d2358455954752140757e 100644 (file)
@@ -244,7 +244,7 @@ int assertion_file_atime_recent(const char *, int, const char *);
 int assertion_file_birthtime(const char *, int, const char *, long, long);
 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_contains_no_invalid_strings(const char *, int, const char *, const char **); 
+int assertion_file_contains_no_invalid_strings(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);