summaryrefslogtreecommitdiff
path: root/archivers/libarchive/files/tar/test/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'archivers/libarchive/files/tar/test/main.c')
-rw-r--r--archivers/libarchive/files/tar/test/main.c91
1 files changed, 77 insertions, 14 deletions
diff --git a/archivers/libarchive/files/tar/test/main.c b/archivers/libarchive/files/tar/test/main.c
index d035e8007e9..d56f574cfb6 100644
--- a/archivers/libarchive/files/tar/test/main.c
+++ b/archivers/libarchive/files/tar/test/main.c
@@ -39,7 +39,7 @@
*
* The next few lines are the only differences.
*/
-#define PROGRAM "bsdtar" /* Name of program we're testing. */
+#define PROGRAM "bsdtar" /* Name of program being tested. */
#define ENVBASE "BSDTAR" /* Prefix for environment variables. */
#undef EXTRA_DUMP /* How to dump extra data */
/* How to generate extra version info. */
@@ -55,7 +55,7 @@ __FBSDID("$FreeBSD$");
* test functions.
*/
#undef DEFINE_TEST
-#define DEFINE_TEST(name) void name(void);
+#define DEFINE_TEST(name) void name(void);
#include "list.h"
/* Interix doesn't define these in a standard header. */
@@ -272,6 +272,30 @@ test_assert_equal_int(const char *file, int line,
return (0);
}
+static void strdump(const char *p)
+{
+ if (p == NULL) {
+ fprintf(stderr, "(null)");
+ return;
+ }
+ fprintf(stderr, "\"");
+ while (*p != '\0') {
+ unsigned int c = 0xff & *p++;
+ switch (c) {
+ case '\a': fprintf(stderr, "\a"); break;
+ case '\b': fprintf(stderr, "\b"); break;
+ case '\n': fprintf(stderr, "\n"); break;
+ case '\r': fprintf(stderr, "\r"); break;
+ default:
+ if (c >= 32 && c < 127)
+ fprintf(stderr, "%c", c);
+ else
+ fprintf(stderr, "\\x%02X", c);
+ }
+ }
+ fprintf(stderr, "\"");
+}
+
/* assertEqualString() displays the values of the two strings. */
int
test_assert_equal_string(const char *file, int line,
@@ -294,12 +318,37 @@ test_assert_equal_string(const char *file, int line,
return (0);
fprintf(stderr, "%s:%d: Assertion failed: Strings not equal\n",
file, line);
- fprintf(stderr, " %s = \"%s\"\n", e1, v1);
- fprintf(stderr, " %s = \"%s\"\n", e2, v2);
+ fprintf(stderr, " %s = ", e1);
+ strdump(v1);
+ fprintf(stderr, "\n");
+ fprintf(stderr, " %s = ", e2);
+ strdump(v2);
+ fprintf(stderr, "\n");
report_failure(extra);
return (0);
}
+static void wcsdump(const wchar_t *w)
+{
+ if (w == NULL) {
+ fprintf(stderr, "(null)");
+ return;
+ }
+ fprintf(stderr, "\"");
+ while (*w != L'\0') {
+ unsigned int c = *w++;
+ if (c >= 32 && c < 127)
+ fprintf(stderr, "%c", c);
+ else if (c < 256)
+ fprintf(stderr, "\\x%02X", c);
+ else if (c < 0x10000)
+ fprintf(stderr, "\\u%04X", c);
+ else
+ fprintf(stderr, "\\U%08X", c);
+ }
+ fprintf(stderr, "\"");
+}
+
/* assertEqualWString() displays the values of the two strings. */
int
test_assert_equal_wstring(const char *file, int line,
@@ -308,7 +357,17 @@ test_assert_equal_wstring(const char *file, int line,
void *extra)
{
++assertions;
- if (wcscmp(v1, v2) == 0) {
+ if (v1 == NULL) {
+ if (v2 == NULL) {
+ msg[0] = '\0';
+ return (1);
+ }
+ } else if (v2 == NULL) {
+ if (v1 == NULL) {
+ msg[0] = '\0';
+ return (1);
+ }
+ } else if (wcscmp(v1, v2) == 0) {
msg[0] = '\0';
return (1);
}
@@ -317,8 +376,12 @@ test_assert_equal_wstring(const char *file, int line,
return (0);
fprintf(stderr, "%s:%d: Assertion failed: Unicode strings not equal\n",
file, line);
- fwprintf(stderr, L" %s = \"%ls\"\n", e1, v1);
- fwprintf(stderr, L" %s = \"%ls\"\n", e2, v2);
+ fprintf(stderr, " %s = ", e1);
+ wcsdump(v1);
+ fprintf(stderr, "\n");
+ fprintf(stderr, " %s = ", e2);
+ wcsdump(v2);
+ fprintf(stderr, "\n");
report_failure(extra);
return (0);
}
@@ -587,7 +650,7 @@ slurpfile(size_t * sizep, const char *fmt, ...)
* We reuse it here to define a list of all tests (functions and names).
*/
#undef DEFINE_TEST
-#define DEFINE_TEST(n) { n, #n },
+#define DEFINE_TEST(n) { n, #n },
struct { void (*func)(void); const char *name; } tests[] = {
#include "list.h"
};
@@ -662,7 +725,7 @@ static void usage(const char *program)
exit(1);
}
-#define uudecode(c) (((c) - 0x20) & 0x3f)
+#define UUDECODE(c) (((c) - 0x20) & 0x3f)
void
extract_reference_file(const char *name)
@@ -695,23 +758,23 @@ extract_reference_file(const char *name)
if (memcmp(buff, "end", 3) == 0)
break;
- bytes = uudecode(*p++);
+ bytes = UUDECODE(*p++);
while (bytes > 0) {
int n = 0;
/* Write out 1-3 bytes from that. */
if (bytes > 0) {
- n = uudecode(*p++) << 18;
- n |= uudecode(*p++) << 12;
+ n = UUDECODE(*p++) << 18;
+ n |= UUDECODE(*p++) << 12;
fputc(n >> 16, out);
--bytes;
}
if (bytes > 0) {
- n |= uudecode(*p++) << 6;
+ n |= UUDECODE(*p++) << 6;
fputc((n >> 8) & 0xFF, out);
--bytes;
}
if (bytes > 0) {
- n |= uudecode(*p++);
+ n |= UUDECODE(*p++);
fputc(n & 0xFF, out);
--bytes;
}