]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Add test case for issue #794
authorMartin Matuska <martin@matuska.org>
Tue, 11 Oct 2016 22:29:07 +0000 (00:29 +0200)
committerMartin Matuška <martin@matuska.org>
Wed, 12 Oct 2016 10:19:44 +0000 (12:19 +0200)
tar/test/main.c
tar/test/test.h
tar/test/test_missing_file.c

index d4a3cce7a4d2d1d6f3e10ceb1732e91291bb971e..d847964f75e9392f37732268164c486bdadb594b 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
index 73c0668ee67ed5739c541bbe9e5bce90ff392b06..98415f8538d8872f68ab90d934a809f6666af36c 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 e2e5da5bddf76ac95ef8848d5c4f3be78e8b2480..808e384e10b0a3b4dc156a7c8c5a005bd1c40e1d 100644 (file)
@@ -27,11 +27,15 @@ __FBSDID("$FreeBSD$");
 
 DEFINE_TEST(test_missing_file)
 {
+       const char * invalid_stderr[] = { "INTERNAL ERROR", NULL };
        assertMakeFile("file1", 0644, "file1");
        assertMakeFile("file2", 0644, "file2");
        assert(0 == systemf("%s -cf archive.tar file1 file2 2>stderr1", testprog));
        assertEmptyFile("stderr1");
        assert(0 != systemf("%s -cf archive.tar file1 file2 file3 2>stderr2", testprog));
+       assertFileContainsNoInvalidStrings("stderr2", invalid_stderr);
        assert(0 != systemf("%s -cf archive.tar 2>stderr3", testprog));
-       assert(0 != systemf("%s -cf archive.tar file3 2>stderr4", testprog));
+       assertFileContainsNoInvalidStrings("stderr3", invalid_stderr);
+       assert(0 != systemf("%s -cf archive.tar file3 file4 2>stderr4", testprog));
+       assertFileContainsNoInvalidStrings("stderr4", invalid_stderr);
 }