summaryrefslogtreecommitdiff
path: root/cpio
diff options
context:
space:
mode:
authorTim Kientzle <kientzle@acm.org>2016-10-23 15:21:59 -0700
committerTim Kientzle <kientzle@acm.org>2016-10-23 15:21:59 -0700
commitb960225b84cf2260e3d4e819799fa1a6819ff271 (patch)
tree3b29f4e2d5fb625d3841d81d8e448cb498a632ac /cpio
parent4ad0f5d2441c6e0f3e645b3c8fe37f6d0ef9bc6c (diff)
downloadlibarchive-b960225b84cf2260e3d4e819799fa1a6819ff271.tar.gz
Sync up the test harnesses, fix an "unused var" warning on Windows
Diffstat (limited to 'cpio')
-rw-r--r--cpio/test/main.c31
-rw-r--r--cpio/test/test.h4
2 files changed, 35 insertions, 0 deletions
diff --git a/cpio/test/main.c b/cpio/test/main.c
index f3b431d0..6e6b5ab4 100644
--- a/cpio/test/main.c
+++ b/cpio/test/main.c
@@ -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;
diff --git a/cpio/test/test.h b/cpio/test/test.h
index 0a8b31e1..49fa32c9 100644
--- a/cpio/test/test.h
+++ b/cpio/test/test.h
@@ -174,6 +174,9 @@
/* 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);