Portability: Eliminate the need for uudecode by incorporating
uudecode into the main test driver and invoking it just-in-time within the various tests. Also, incorporate a number of improvements to the main test support code that have proven useful on other projects where I've used this framework.
This commit is contained in:
parent
bdb5bdf0b7
commit
df4691b984
@ -7,17 +7,6 @@ LA_SRCDIR=${.CURDIR}/..
|
|||||||
# Get a list of all libarchive source files
|
# Get a list of all libarchive source files
|
||||||
LA_SRCS!=make -f ${LA_SRCDIR}/Makefile -V SRCS
|
LA_SRCS!=make -f ${LA_SRCDIR}/Makefile -V SRCS
|
||||||
|
|
||||||
TESTFILES= \
|
|
||||||
test_compat_gtar_1.tgz \
|
|
||||||
test_compat_tar_hardlink_1.tar \
|
|
||||||
test_compat_zip_1.zip \
|
|
||||||
test_read_format_gtar_sparse_1_13.tgz \
|
|
||||||
test_read_format_gtar_sparse_1_17.tgz \
|
|
||||||
test_read_format_gtar_sparse_1_17_posix00.tgz \
|
|
||||||
test_read_format_gtar_sparse_1_17_posix01.tgz \
|
|
||||||
test_read_format_gtar_sparse_1_17_posix10.tgz \
|
|
||||||
test_read_format_gtar_sparse_1_17_posix10_modified.tar
|
|
||||||
|
|
||||||
TESTS= \
|
TESTS= \
|
||||||
test_acl_basic.c \
|
test_acl_basic.c \
|
||||||
test_acl_pax.c \
|
test_acl_pax.c \
|
||||||
@ -104,13 +93,8 @@ CFLAGS+= -I/usr/local/include -DUSE_DMALLOC
|
|||||||
WARNS=6
|
WARNS=6
|
||||||
|
|
||||||
# Build libarchive_test and run it.
|
# Build libarchive_test and run it.
|
||||||
check test: libarchive_test ${TESTFILES}
|
check test: libarchive_test
|
||||||
./libarchive_test
|
./libarchive_test -k -r ${.CURDIR}
|
||||||
|
|
||||||
.for f in ${TESTFILES}
|
|
||||||
${f}: ${f}.uu
|
|
||||||
uudecode -p ${.CURDIR}/${f}.uu >${f}
|
|
||||||
.endfor
|
|
||||||
|
|
||||||
INCS=archive.h list.h
|
INCS=archive.h list.h
|
||||||
|
|
||||||
|
@ -24,22 +24,25 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This same file is used pretty much verbatim for all test harnesses.
|
* Various utility routines useful for test programs.
|
||||||
*
|
* Each test program is linked against this file.
|
||||||
* The next line is used to define various environment variables, etc.
|
|
||||||
*
|
|
||||||
* The tar and cpio test harnesses are identical except for this line;
|
|
||||||
* the libarchive test harness omits some code that is needed only for
|
|
||||||
* testing standalone executables.
|
|
||||||
*/
|
*/
|
||||||
#define PROGRAM "LIBARCHIVE"
|
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This same file is used pretty much verbatim for all test harnesses.
|
||||||
|
*
|
||||||
|
* The next few lines are the only differences.
|
||||||
|
*/
|
||||||
|
#undef PROGRAM /* Testing a library, not a program. */
|
||||||
|
#define ENVBASE "LIBARCHIVE" /* Prefix for environment variables. */
|
||||||
|
#define EXTRA_DUMP(x) archive_error_string((struct archive *)(x))
|
||||||
|
#define EXTRA_VERSION archive_version()
|
||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -51,7 +54,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
* test functions.
|
* test functions.
|
||||||
*/
|
*/
|
||||||
#undef DEFINE_TEST
|
#undef DEFINE_TEST
|
||||||
#define DEFINE_TEST(name) void name(void);
|
#define DEFINE_TEST(name) void name(void);
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
|
||||||
/* Interix doesn't define these in a standard header. */
|
/* Interix doesn't define these in a standard header. */
|
||||||
@ -71,6 +74,9 @@ static int skips = 0;
|
|||||||
/* Cumulative count of assertions. */
|
/* Cumulative count of assertions. */
|
||||||
static int assertions = 0;
|
static int assertions = 0;
|
||||||
|
|
||||||
|
/* Directory where uuencoded reference files can be found. */
|
||||||
|
static char *refdir;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* My own implementation of the standard assert() macro emits the
|
* My own implementation of the standard assert() macro emits the
|
||||||
* message in the same format as GCC (file:line: message).
|
* message in the same format as GCC (file:line: message).
|
||||||
@ -90,7 +96,7 @@ static char msg[4096];
|
|||||||
* For each test source file, we remember how many times each
|
* For each test source file, we remember how many times each
|
||||||
* failure was reported.
|
* failure was reported.
|
||||||
*/
|
*/
|
||||||
static const char *failed_filename;
|
static const char *failed_filename = NULL;
|
||||||
static struct line {
|
static struct line {
|
||||||
int line;
|
int line;
|
||||||
int count;
|
int count;
|
||||||
@ -163,9 +169,13 @@ report_failure(void *extra)
|
|||||||
fprintf(stderr, " Description: %s\n", msg);
|
fprintf(stderr, " Description: %s\n", msg);
|
||||||
msg[0] = '\0';
|
msg[0] = '\0';
|
||||||
}
|
}
|
||||||
if (extra != NULL) {
|
|
||||||
fprintf(stderr, " archive error: %s\n", archive_error_string((struct archive *)extra));
|
#ifdef EXTRA_DUMP
|
||||||
}
|
if (extra != NULL)
|
||||||
|
fprintf(stderr, " detail: %s\n", EXTRA_DUMP(extra));
|
||||||
|
#else
|
||||||
|
(void)extra; /* UNUSED */
|
||||||
|
#endif
|
||||||
|
|
||||||
if (dump_on_failure) {
|
if (dump_on_failure) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
@ -241,27 +251,28 @@ test_assert(const char *file, int line, int value, const char *condition, void *
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* assertEqualInt() displays the values of the two integers. */
|
/* assertEqualInt() displays the values of the two integers. */
|
||||||
void
|
int
|
||||||
test_assert_equal_int(const char *file, int line,
|
test_assert_equal_int(const char *file, int line,
|
||||||
int v1, const char *e1, int v2, const char *e2, void *extra)
|
int v1, const char *e1, int v2, const char *e2, void *extra)
|
||||||
{
|
{
|
||||||
++assertions;
|
++assertions;
|
||||||
if (v1 == v2) {
|
if (v1 == v2) {
|
||||||
msg[0] = '\0';
|
msg[0] = '\0';
|
||||||
return;
|
return (1);
|
||||||
}
|
}
|
||||||
failures ++;
|
failures ++;
|
||||||
if (previous_failures(file, line))
|
if (previous_failures(file, line))
|
||||||
return;
|
return (0);
|
||||||
fprintf(stderr, "%s:%d: Assertion failed: Ints not equal\n",
|
fprintf(stderr, "%s:%d: Assertion failed: Ints not equal\n",
|
||||||
file, line);
|
file, line);
|
||||||
fprintf(stderr, " %s=%d\n", e1, v1);
|
fprintf(stderr, " %s=%d\n", e1, v1);
|
||||||
fprintf(stderr, " %s=%d\n", e2, v2);
|
fprintf(stderr, " %s=%d\n", e2, v2);
|
||||||
report_failure(extra);
|
report_failure(extra);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* assertEqualString() displays the values of the two strings. */
|
/* assertEqualString() displays the values of the two strings. */
|
||||||
void
|
int
|
||||||
test_assert_equal_string(const char *file, int line,
|
test_assert_equal_string(const char *file, int line,
|
||||||
const char *v1, const char *e1,
|
const char *v1, const char *e1,
|
||||||
const char *v2, const char *e2,
|
const char *v2, const char *e2,
|
||||||
@ -271,24 +282,25 @@ test_assert_equal_string(const char *file, int line,
|
|||||||
if (v1 == NULL || v2 == NULL) {
|
if (v1 == NULL || v2 == NULL) {
|
||||||
if (v1 == v2) {
|
if (v1 == v2) {
|
||||||
msg[0] = '\0';
|
msg[0] = '\0';
|
||||||
return;
|
return (1);
|
||||||
}
|
}
|
||||||
} else if (strcmp(v1, v2) == 0) {
|
} else if (strcmp(v1, v2) == 0) {
|
||||||
msg[0] = '\0';
|
msg[0] = '\0';
|
||||||
return;
|
return (1);
|
||||||
}
|
}
|
||||||
failures ++;
|
failures ++;
|
||||||
if (previous_failures(file, line))
|
if (previous_failures(file, line))
|
||||||
return;
|
return (0);
|
||||||
fprintf(stderr, "%s:%d: Assertion failed: Strings not equal\n",
|
fprintf(stderr, "%s:%d: Assertion failed: Strings not equal\n",
|
||||||
file, line);
|
file, line);
|
||||||
fprintf(stderr, " %s = \"%s\"\n", e1, v1);
|
fprintf(stderr, " %s = \"%s\"\n", e1, v1);
|
||||||
fprintf(stderr, " %s = \"%s\"\n", e2, v2);
|
fprintf(stderr, " %s = \"%s\"\n", e2, v2);
|
||||||
report_failure(extra);
|
report_failure(extra);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* assertEqualWString() displays the values of the two strings. */
|
/* assertEqualWString() displays the values of the two strings. */
|
||||||
void
|
int
|
||||||
test_assert_equal_wstring(const char *file, int line,
|
test_assert_equal_wstring(const char *file, int line,
|
||||||
const wchar_t *v1, const char *e1,
|
const wchar_t *v1, const char *e1,
|
||||||
const wchar_t *v2, const char *e2,
|
const wchar_t *v2, const char *e2,
|
||||||
@ -297,16 +309,17 @@ test_assert_equal_wstring(const char *file, int line,
|
|||||||
++assertions;
|
++assertions;
|
||||||
if (wcscmp(v1, v2) == 0) {
|
if (wcscmp(v1, v2) == 0) {
|
||||||
msg[0] = '\0';
|
msg[0] = '\0';
|
||||||
return;
|
return (1);
|
||||||
}
|
}
|
||||||
failures ++;
|
failures ++;
|
||||||
if (previous_failures(file, line))
|
if (previous_failures(file, line))
|
||||||
return;
|
return (0);
|
||||||
fprintf(stderr, "%s:%d: Assertion failed: Unicode strings not equal\n",
|
fprintf(stderr, "%s:%d: Assertion failed: Unicode strings not equal\n",
|
||||||
file, line);
|
file, line);
|
||||||
fwprintf(stderr, L" %s = \"%ls\"\n", e1, v1);
|
fwprintf(stderr, L" %s = \"%ls\"\n", e1, v1);
|
||||||
fwprintf(stderr, L" %s = \"%ls\"\n", e2, v2);
|
fwprintf(stderr, L" %s = \"%ls\"\n", e2, v2);
|
||||||
report_failure(extra);
|
report_failure(extra);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -326,7 +339,7 @@ hexdump(const char *p, const char *ref, size_t l, size_t offset)
|
|||||||
for (j = 0; j < 16 && i + j < l; j++) {
|
for (j = 0; j < 16 && i + j < l; j++) {
|
||||||
if (ref != NULL && p[i + j] != ref[i + j])
|
if (ref != NULL && p[i + j] != ref[i + j])
|
||||||
sep = '_';
|
sep = '_';
|
||||||
fprintf(stderr, "%c%02x", sep, p[i+j]);
|
fprintf(stderr, "%c%02x", sep, 0xff & (int)p[i+j]);
|
||||||
if (ref != NULL && p[i + j] == ref[i + j])
|
if (ref != NULL && p[i + j] == ref[i + j])
|
||||||
sep = ' ';
|
sep = ' ';
|
||||||
}
|
}
|
||||||
@ -348,7 +361,7 @@ hexdump(const char *p, const char *ref, size_t l, size_t offset)
|
|||||||
|
|
||||||
/* assertEqualMem() displays the values of the two memory blocks. */
|
/* assertEqualMem() displays the values of the two memory blocks. */
|
||||||
/* TODO: For long blocks, hexdump the first bytes that actually differ. */
|
/* TODO: For long blocks, hexdump the first bytes that actually differ. */
|
||||||
void
|
int
|
||||||
test_assert_equal_mem(const char *file, int line,
|
test_assert_equal_mem(const char *file, int line,
|
||||||
const char *v1, const char *e1,
|
const char *v1, const char *e1,
|
||||||
const char *v2, const char *e2,
|
const char *v2, const char *e2,
|
||||||
@ -358,15 +371,15 @@ test_assert_equal_mem(const char *file, int line,
|
|||||||
if (v1 == NULL || v2 == NULL) {
|
if (v1 == NULL || v2 == NULL) {
|
||||||
if (v1 == v2) {
|
if (v1 == v2) {
|
||||||
msg[0] = '\0';
|
msg[0] = '\0';
|
||||||
return;
|
return (1);
|
||||||
}
|
}
|
||||||
} else if (memcmp(v1, v2, l) == 0) {
|
} else if (memcmp(v1, v2, l) == 0) {
|
||||||
msg[0] = '\0';
|
msg[0] = '\0';
|
||||||
return;
|
return (1);
|
||||||
}
|
}
|
||||||
failures ++;
|
failures ++;
|
||||||
if (previous_failures(file, line))
|
if (previous_failures(file, line))
|
||||||
return;
|
return (0);
|
||||||
fprintf(stderr, "%s:%d: Assertion failed: memory not equal\n",
|
fprintf(stderr, "%s:%d: Assertion failed: memory not equal\n",
|
||||||
file, line);
|
file, line);
|
||||||
fprintf(stderr, " size %s = %d\n", ld, (int)l);
|
fprintf(stderr, " size %s = %d\n", ld, (int)l);
|
||||||
@ -376,14 +389,19 @@ test_assert_equal_mem(const char *file, int line,
|
|||||||
hexdump(v2, v1, l < 32 ? l : 32, 0);
|
hexdump(v2, v1, l < 32 ? l : 32, 0);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
report_failure(extra);
|
report_failure(extra);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
test_assert_empty_file(const char *f1fmt, ...)
|
test_assert_empty_file(const char *f1fmt, ...)
|
||||||
{
|
{
|
||||||
|
char buff[1024];
|
||||||
char f1[1024];
|
char f1[1024];
|
||||||
struct stat st;
|
struct stat st;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
ssize_t s;
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
|
||||||
va_start(ap, f1fmt);
|
va_start(ap, f1fmt);
|
||||||
vsprintf(f1, f1fmt, ap);
|
vsprintf(f1, f1fmt, ap);
|
||||||
@ -392,16 +410,32 @@ test_assert_empty_file(const char *f1fmt, ...)
|
|||||||
if (stat(f1, &st) != 0) {
|
if (stat(f1, &st) != 0) {
|
||||||
fprintf(stderr, "%s:%d: Could not stat: %s\n", test_filename, test_line, f1);
|
fprintf(stderr, "%s:%d: Could not stat: %s\n", test_filename, test_line, f1);
|
||||||
report_failure(NULL);
|
report_failure(NULL);
|
||||||
} else if (st.st_size > 0) {
|
|
||||||
fprintf(stderr, "%s:%d: File not empty: %s\n", test_filename, test_line, f1);
|
|
||||||
fprintf(stderr, " File size: %d\n", (int)st.st_size);
|
|
||||||
report_failure(NULL);
|
|
||||||
}
|
}
|
||||||
|
if (st.st_size == 0)
|
||||||
|
return (1);
|
||||||
|
|
||||||
|
failures ++;
|
||||||
|
if (previous_failures(test_filename, test_line))
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
fprintf(stderr, "%s:%d: File not empty: %s\n", test_filename, test_line, f1);
|
||||||
|
fprintf(stderr, " File size: %d\n", (int)st.st_size);
|
||||||
|
fprintf(stderr, " Contents:\n");
|
||||||
|
fd = open(f1, O_RDONLY);
|
||||||
|
if (fd < 0) {
|
||||||
|
fprintf(stderr, " Unable to open %s\n", f1);
|
||||||
|
} else {
|
||||||
|
s = sizeof(buff) < st.st_size ? sizeof(buff) : st.st_size;
|
||||||
|
s = read(fd, buff, s);
|
||||||
|
hexdump(buff, NULL, s, 0);
|
||||||
|
}
|
||||||
|
report_failure(NULL);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* assertEqualFile() asserts that two files have the same contents. */
|
/* assertEqualFile() asserts that two files have the same contents. */
|
||||||
/* TODO: hexdump the first bytes that actually differ. */
|
/* TODO: hexdump the first bytes that actually differ. */
|
||||||
void
|
int
|
||||||
test_assert_equal_file(const char *f1, const char *f2pattern, ...)
|
test_assert_equal_file(const char *f1, const char *f2pattern, ...)
|
||||||
{
|
{
|
||||||
char f2[1024];
|
char f2[1024];
|
||||||
@ -423,16 +457,58 @@ test_assert_equal_file(const char *f1, const char *f2pattern, ...)
|
|||||||
if (n1 != n2)
|
if (n1 != n2)
|
||||||
break;
|
break;
|
||||||
if (n1 == 0 && n2 == 0)
|
if (n1 == 0 && n2 == 0)
|
||||||
return;
|
return (1);
|
||||||
if (memcmp(buff1, buff2, n1) != 0)
|
if (memcmp(buff1, buff2, n1) != 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "%s:%d: Files are not identical\n", test_filename, test_line);
|
failures ++;
|
||||||
|
if (previous_failures(test_filename, test_line))
|
||||||
|
return (0);
|
||||||
|
fprintf(stderr, "%s:%d: Files are not identical\n",
|
||||||
|
test_filename, test_line);
|
||||||
fprintf(stderr, " file1=\"%s\"\n", f1);
|
fprintf(stderr, " file1=\"%s\"\n", f1);
|
||||||
fprintf(stderr, " file2=\"%s\"\n", f2);
|
fprintf(stderr, " file2=\"%s\"\n", f2);
|
||||||
report_failure(test_extra);
|
report_failure(test_extra);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* assertFileContents() asserts the contents of a file. */
|
||||||
|
int
|
||||||
|
test_assert_file_contents(const void *buff, int s, const char *fpattern, ...)
|
||||||
|
{
|
||||||
|
char f[1024];
|
||||||
|
va_list ap;
|
||||||
|
char *contents;
|
||||||
|
int fd;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
va_start(ap, fpattern);
|
||||||
|
vsprintf(f, fpattern, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
fd = open(f, O_RDONLY);
|
||||||
|
contents = malloc(s * 2);
|
||||||
|
n = read(fd, contents, s * 2);
|
||||||
|
if (n == s && memcmp(buff, contents, s) == 0) {
|
||||||
|
free(contents);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
failures ++;
|
||||||
|
if (!previous_failures(test_filename, test_line)) {
|
||||||
|
fprintf(stderr, "%s:%d: File contents don't match\n",
|
||||||
|
test_filename, test_line);
|
||||||
|
fprintf(stderr, " file=\"%s\"\n", f);
|
||||||
|
if (n > 0)
|
||||||
|
hexdump(contents, buff, n, 0);
|
||||||
|
else {
|
||||||
|
fprintf(stderr, " File empty, contents should be:\n");
|
||||||
|
hexdump(buff, NULL, s, 0);
|
||||||
|
}
|
||||||
|
report_failure(test_extra);
|
||||||
|
}
|
||||||
|
free(contents);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Call standard system() call, but build up the command line using
|
* Call standard system() call, but build up the command line using
|
||||||
@ -510,7 +586,7 @@ slurpfile(size_t * sizep, const char *fmt, ...)
|
|||||||
* We reuse it here to define a list of all tests (functions and names).
|
* We reuse it here to define a list of all tests (functions and names).
|
||||||
*/
|
*/
|
||||||
#undef DEFINE_TEST
|
#undef DEFINE_TEST
|
||||||
#define DEFINE_TEST(n) { n, #n },
|
#define DEFINE_TEST(n) { n, #n },
|
||||||
struct { void (*func)(void); const char *name; } tests[] = {
|
struct { void (*func)(void); const char *name; } tests[] = {
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
};
|
};
|
||||||
@ -572,6 +648,10 @@ static void usage(const char *program)
|
|||||||
printf("Options:\n");
|
printf("Options:\n");
|
||||||
printf(" -k Keep running after failures.\n");
|
printf(" -k Keep running after failures.\n");
|
||||||
printf(" Default: Core dump after any failure.\n");
|
printf(" Default: Core dump after any failure.\n");
|
||||||
|
#ifdef PROGRAM
|
||||||
|
printf(" -p <path> Path to executable to be tested.\n");
|
||||||
|
printf(" Default: path taken from " ENVBASE " environment variable.\n");
|
||||||
|
#endif
|
||||||
printf(" -q Quiet.\n");
|
printf(" -q Quiet.\n");
|
||||||
printf(" -r <dir> Path to dir containing reference files.\n");
|
printf(" -r <dir> Path to dir containing reference files.\n");
|
||||||
printf(" Default: Current directory.\n");
|
printf(" Default: Current directory.\n");
|
||||||
@ -581,6 +661,66 @@ static void usage(const char *program)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define UUDECODE(c) (((c) - 0x20) & 0x3f)
|
||||||
|
|
||||||
|
void
|
||||||
|
extract_reference_file(const char *name)
|
||||||
|
{
|
||||||
|
char buff[1024];
|
||||||
|
FILE *in, *out;
|
||||||
|
|
||||||
|
sprintf(buff, "%s/%s.uu", refdir, name);
|
||||||
|
in = fopen(buff, "r");
|
||||||
|
failure("Couldn't open reference file %s", buff);
|
||||||
|
assert(in != NULL);
|
||||||
|
if (in == NULL)
|
||||||
|
return;
|
||||||
|
/* Read up to and including the 'begin' line. */
|
||||||
|
for (;;) {
|
||||||
|
if (fgets(buff, sizeof(buff), in) == NULL) {
|
||||||
|
/* TODO: This is a failure. */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (memcmp(buff, "begin ", 6) == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* Now, decode the rest and write it. */
|
||||||
|
/* Not a lot of error checking here; the input better be right. */
|
||||||
|
out = fopen(name, "w");
|
||||||
|
while (fgets(buff, sizeof(buff), in) != NULL) {
|
||||||
|
char *p = buff;
|
||||||
|
int bytes;
|
||||||
|
|
||||||
|
if (memcmp(buff, "end", 3) == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
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;
|
||||||
|
fputc(n >> 16, out);
|
||||||
|
--bytes;
|
||||||
|
}
|
||||||
|
if (bytes > 0) {
|
||||||
|
n |= UUDECODE(*p++) << 6;
|
||||||
|
fputc((n >> 8) & 0xFF, out);
|
||||||
|
--bytes;
|
||||||
|
}
|
||||||
|
if (bytes > 0) {
|
||||||
|
n |= UUDECODE(*p++);
|
||||||
|
fputc(n & 0xFF, out);
|
||||||
|
--bytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(out);
|
||||||
|
fclose(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
static const int limit = sizeof(tests) / sizeof(tests[0]);
|
static const int limit = sizeof(tests) / sizeof(tests[0]);
|
||||||
@ -602,17 +742,33 @@ int main(int argc, char **argv)
|
|||||||
++p;
|
++p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PROGRAM
|
||||||
|
/* Get the target program from environment, if available. */
|
||||||
|
testprog = getenv(ENVBASE);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Allow -k to be controlled through the environment. */
|
||||||
|
if (getenv(ENVBASE "_KEEP_GOING") != NULL)
|
||||||
|
dump_on_failure = 0;
|
||||||
|
|
||||||
/* Get the directory holding test files from environment. */
|
/* Get the directory holding test files from environment. */
|
||||||
refdir = getenv(PROGRAM "_TEST_FILES");
|
refdir = getenv(ENVBASE "_TEST_FILES");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse options.
|
* Parse options.
|
||||||
*/
|
*/
|
||||||
while ((opt = getopt(argc, argv, "kqr:")) != -1) {
|
while ((opt = getopt(argc, argv, "kp:qr:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'k':
|
case 'k':
|
||||||
dump_on_failure = 0;
|
dump_on_failure = 0;
|
||||||
break;
|
break;
|
||||||
|
case 'p':
|
||||||
|
#ifdef PROGRAM
|
||||||
|
testprog = optarg;
|
||||||
|
#else
|
||||||
|
usage(progname);
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
quiet_flag++;
|
quiet_flag++;
|
||||||
break;
|
break;
|
||||||
@ -627,6 +783,14 @@ int main(int argc, char **argv)
|
|||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sanity-check that our options make sense.
|
||||||
|
*/
|
||||||
|
#ifdef PROGRAM
|
||||||
|
if (testprog == NULL)
|
||||||
|
usage(progname);
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a temp directory for the following tests.
|
* Create a temp directory for the following tests.
|
||||||
* Include the time the tests started as part of the name,
|
* Include the time the tests started as part of the name,
|
||||||
@ -667,7 +831,12 @@ int main(int argc, char **argv)
|
|||||||
if (!quiet_flag) {
|
if (!quiet_flag) {
|
||||||
printf("Running tests in: %s\n", tmpdir);
|
printf("Running tests in: %s\n", tmpdir);
|
||||||
printf("Reference files will be read from: %s\n", refdir);
|
printf("Reference files will be read from: %s\n", refdir);
|
||||||
printf("Exercising %s\n", archive_version());
|
#ifdef PROGRAM
|
||||||
|
printf("Running tests on: %s\n", testprog);
|
||||||
|
#endif
|
||||||
|
printf("Exercising: ");
|
||||||
|
fflush(stdout);
|
||||||
|
printf("%s\n", EXTRA_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#define _FILE_OFFSET_BITS 64
|
#define _FILE_OFFSET_BITS 64
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -116,12 +117,13 @@ void failure(const char *fmt, ...);
|
|||||||
void test_setup(const char *, int);
|
void test_setup(const char *, int);
|
||||||
void test_skipping(const char *fmt, ...);
|
void test_skipping(const char *fmt, ...);
|
||||||
int test_assert(const char *, int, int, const char *, void *);
|
int test_assert(const char *, int, int, const char *, void *);
|
||||||
void test_assert_empty_file(const char *, ...);
|
int test_assert_empty_file(const char *, ...);
|
||||||
void test_assert_equal_file(const char *, const char *, ...);
|
int test_assert_equal_file(const char *, const char *, ...);
|
||||||
void test_assert_equal_int(const char *, int, int, const char *, int, const char *, void *);
|
int test_assert_equal_int(const char *, int, int, const char *, int, const char *, void *);
|
||||||
void test_assert_equal_string(const char *, int, const char *v1, const char *, const char *v2, const char *, void *);
|
int test_assert_equal_string(const char *, int, const char *v1, const char *, const char *v2, const char *, void *);
|
||||||
void test_assert_equal_wstring(const char *, int, const wchar_t *v1, const char *, const wchar_t *v2, const char *, void *);
|
int test_assert_equal_wstring(const char *, int, const wchar_t *v1, const char *, const wchar_t *v2, const char *, void *);
|
||||||
void test_assert_equal_mem(const char *, int, const char *, const char *, const char *, const char *, size_t, const char *, void *);
|
int test_assert_equal_mem(const char *, int, const char *, const char *, const char *, const char *, size_t, const char *, void *);
|
||||||
|
int test_assert_file_contents(const void *, int, const char *, ...);
|
||||||
|
|
||||||
/* Like sprintf, then system() */
|
/* Like sprintf, then system() */
|
||||||
int systemf(const char * fmt, ...);
|
int systemf(const char * fmt, ...);
|
||||||
@ -130,12 +132,8 @@ int systemf(const char * fmt, ...);
|
|||||||
/* Supports printf-style args: slurpfile(NULL, "%s/myfile", refdir); */
|
/* Supports printf-style args: slurpfile(NULL, "%s/myfile", refdir); */
|
||||||
char *slurpfile(size_t *, const char *fmt, ...);
|
char *slurpfile(size_t *, const char *fmt, ...);
|
||||||
|
|
||||||
/*
|
/* Extracts named reference file to the current directory. */
|
||||||
* Global vars
|
void extract_reference_file(const char *);
|
||||||
*/
|
|
||||||
|
|
||||||
/* Directory holding reference files. */
|
|
||||||
char *refdir;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Special interfaces for libarchive test harness.
|
* Special interfaces for libarchive test harness.
|
||||||
|
@ -40,14 +40,14 @@ __FBSDID("$FreeBSD$");
|
|||||||
static void
|
static void
|
||||||
test_compat_gtar_1(void)
|
test_compat_gtar_1(void)
|
||||||
{
|
{
|
||||||
char name[1024];
|
char name[] = "test_compat_gtar_1.tgz";
|
||||||
struct archive_entry *ae;
|
struct archive_entry *ae;
|
||||||
struct archive *a;
|
struct archive *a;
|
||||||
|
|
||||||
assert((a = archive_read_new()) != NULL);
|
assert((a = archive_read_new()) != NULL);
|
||||||
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a));
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a));
|
||||||
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
|
||||||
sprintf(name, "%s/test_compat_gtar_1.tgz", refdir);
|
extract_reference_file(name);
|
||||||
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240));
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240));
|
||||||
|
|
||||||
/* Read first entry. */
|
/* Read first entry. */
|
||||||
|
@ -46,14 +46,14 @@ __FBSDID("$FreeBSD$");
|
|||||||
static void
|
static void
|
||||||
test_compat_tar_hardlink_1(void)
|
test_compat_tar_hardlink_1(void)
|
||||||
{
|
{
|
||||||
char name[1024];
|
char name[] = "test_compat_tar_hardlink_1.tar";
|
||||||
struct archive_entry *ae;
|
struct archive_entry *ae;
|
||||||
struct archive *a;
|
struct archive *a;
|
||||||
|
|
||||||
assert((a = archive_read_new()) != NULL);
|
assert((a = archive_read_new()) != NULL);
|
||||||
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a));
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a));
|
||||||
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
|
||||||
sprintf(name, "%s/test_compat_tar_hardlink_1.tar", refdir);
|
extract_reference_file(name);
|
||||||
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240));
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240));
|
||||||
|
|
||||||
/* Read first entry, which is a regular file. */
|
/* Read first entry, which is a regular file. */
|
||||||
|
@ -29,14 +29,14 @@ __FBSDID("$FreeBSD$");
|
|||||||
static void
|
static void
|
||||||
test_compat_zip_1(void)
|
test_compat_zip_1(void)
|
||||||
{
|
{
|
||||||
char name[1024];
|
char name[] = "test_compat_zip_1.zip";
|
||||||
struct archive_entry *ae;
|
struct archive_entry *ae;
|
||||||
struct archive *a;
|
struct archive *a;
|
||||||
|
|
||||||
assert((a = archive_read_new()) != NULL);
|
assert((a = archive_read_new()) != NULL);
|
||||||
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a));
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a));
|
||||||
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
|
||||||
sprintf(name, "%s/test_compat_zip_1.zip", refdir);
|
extract_reference_file(name);
|
||||||
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240));
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240));
|
||||||
|
|
||||||
/* Read first entry. */
|
/* Read first entry. */
|
||||||
|
@ -181,7 +181,6 @@ struct archive_contents {
|
|||||||
static void
|
static void
|
||||||
verify_archive_file(const char *name, struct archive_contents *ac)
|
verify_archive_file(const char *name, struct archive_contents *ac)
|
||||||
{
|
{
|
||||||
char path[512];
|
|
||||||
struct archive_entry *ae;
|
struct archive_entry *ae;
|
||||||
int err;
|
int err;
|
||||||
/* data, size, offset of next expected block. */
|
/* data, size, offset of next expected block. */
|
||||||
@ -190,13 +189,13 @@ verify_archive_file(const char *name, struct archive_contents *ac)
|
|||||||
struct contents actual;
|
struct contents actual;
|
||||||
struct archive *a;
|
struct archive *a;
|
||||||
|
|
||||||
sprintf(path, "%s/%s", refdir, name);
|
extract_reference_file(name);
|
||||||
|
|
||||||
assert((a = archive_read_new()) != NULL);
|
assert((a = archive_read_new()) != NULL);
|
||||||
assert(0 == archive_read_support_compression_all(a));
|
assert(0 == archive_read_support_compression_all(a));
|
||||||
assert(0 == archive_read_support_format_tar(a));
|
assert(0 == archive_read_support_format_tar(a));
|
||||||
failure("Can't open %s", path);
|
failure("Can't open %s", name);
|
||||||
assert(0 == archive_read_open_filename(a, path, 3));
|
assert(0 == archive_read_open_filename(a, name, 3));
|
||||||
|
|
||||||
while (ac->filename != NULL) {
|
while (ac->filename != NULL) {
|
||||||
struct contents *cts = ac->contents;
|
struct contents *cts = ac->contents;
|
||||||
|
Loading…
Reference in New Issue
Block a user