summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Kientzle <kientzle@FreeBSD.org>2008-05-21 04:14:39 +0000
committerTim Kientzle <kientzle@FreeBSD.org>2008-05-21 04:14:39 +0000
commite9709bd00d2eaffdea368f003dd459eb2cea38e6 (patch)
treec80158ffc743125cdcc5c3d8eeea8d4ea3dab92c
parent11caa33007cb522910f3d4f9297e8203e297f532 (diff)
Notes
-rw-r--r--lib/libarchive/test/Makefile24
-rw-r--r--lib/libarchive/test/main.c251
-rw-r--r--lib/libarchive/test/test.h22
-rw-r--r--lib/libarchive/test/test_archive_api_feature.c14
-rw-r--r--lib/libarchive/test/test_compat_gtar.c4
-rw-r--r--lib/libarchive/test/test_compat_tar_hardlink.c4
-rw-r--r--lib/libarchive/test/test_compat_zip.c4
-rw-r--r--lib/libarchive/test/test_empty_write.c3
-rw-r--r--lib/libarchive/test/test_entry.c88
-rw-r--r--lib/libarchive/test/test_read_format_gtar_sparse.c7
10 files changed, 338 insertions, 83 deletions
diff --git a/lib/libarchive/test/Makefile b/lib/libarchive/test/Makefile
index d55e2e6dfd4b9..c64a6ee6502a0 100644
--- a/lib/libarchive/test/Makefile
+++ b/lib/libarchive/test/Makefile
@@ -7,17 +7,6 @@ LA_SRCDIR=${.CURDIR}/..
# Get a list of all libarchive source files
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= \
test_acl_basic.c \
test_acl_pax.c \
@@ -29,6 +18,7 @@ TESTS= \
test_empty_write.c \
test_entry.c \
test_entry_strmode.c \
+ test_pax_filename_encoding.c \
test_read_compress_program.c \
test_read_data_large.c \
test_read_extract.c \
@@ -59,6 +49,7 @@ TESTS= \
test_tar_filenames.c \
test_tar_large.c \
test_write_compress_program.c \
+ test_write_compress.c \
test_write_disk.c \
test_write_disk_hardlink.c \
test_write_disk_perms.c \
@@ -104,13 +95,8 @@ CFLAGS+= -I/usr/local/include -DUSE_DMALLOC
WARNS=6
# Build libarchive_test and run it.
-check test: libarchive_test ${TESTFILES}
- ./libarchive_test
-
-.for f in ${TESTFILES}
-${f}: ${f}.uu
- uudecode -p ${.CURDIR}/${f}.uu >${f}
-.endfor
+check test: libarchive_test
+ ./libarchive_test -k -r ${.CURDIR}
INCS=archive.h list.h
@@ -123,7 +109,7 @@ archive.h: ${LA_SRCDIR}/archive.h.in ${LA_SRCDIR}/Makefile
list.h: ${TESTS} Makefile
(cd ${.CURDIR}; cat ${TESTS}) | grep DEFINE_TEST > list.h
-CLEANFILES += *.out *.o *.core *~ list.h archive.h ${TESTFILES}
+CLEANFILES += *.out *.o *.core *~ list.h archive.h
cleantest:
-chmod -R +w /tmp/libarchive_test.*
diff --git a/lib/libarchive/test/main.c b/lib/libarchive/test/main.c
index a7289ec236ef1..b72a516a4ba6d 100644
--- a/lib/libarchive/test/main.c
+++ b/lib/libarchive/test/main.c
@@ -24,22 +24,25 @@
*/
/*
- * This same file is used pretty much verbatim for all test harnesses.
- *
- * 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.
+ * Various utility routines useful for test programs.
+ * Each test program is linked against this file.
*/
-#define PROGRAM "LIBARCHIVE"
-
#include <errno.h>
#include <locale.h>
#include <stdarg.h>
#include <time.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$");
/*
@@ -51,7 +54,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. */
@@ -71,6 +74,9 @@ static int skips = 0;
/* Cumulative count of assertions. */
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
* 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
* failure was reported.
*/
-static const char *failed_filename;
+static const char *failed_filename = NULL;
static struct line {
int line;
int count;
@@ -163,9 +169,13 @@ report_failure(void *extra)
fprintf(stderr, " Description: %s\n", msg);
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) {
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. */
-void
+int
test_assert_equal_int(const char *file, int line,
int v1, const char *e1, int v2, const char *e2, void *extra)
{
++assertions;
if (v1 == v2) {
msg[0] = '\0';
- return;
+ return (1);
}
failures ++;
if (previous_failures(file, line))
- return;
+ return (0);
fprintf(stderr, "%s:%d: Assertion failed: Ints not equal\n",
file, line);
fprintf(stderr, " %s=%d\n", e1, v1);
fprintf(stderr, " %s=%d\n", e2, v2);
report_failure(extra);
+ return (0);
}
/* assertEqualString() displays the values of the two strings. */
-void
+int
test_assert_equal_string(const char *file, int line,
const char *v1, const char *e1,
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 == v2) {
msg[0] = '\0';
- return;
+ return (1);
}
} else if (strcmp(v1, v2) == 0) {
msg[0] = '\0';
- return;
+ return (1);
}
failures ++;
if (previous_failures(file, line))
- return;
+ 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);
report_failure(extra);
+ return (0);
}
/* assertEqualWString() displays the values of the two strings. */
-void
+int
test_assert_equal_wstring(const char *file, int line,
const wchar_t *v1, const char *e1,
const wchar_t *v2, const char *e2,
@@ -297,16 +309,17 @@ test_assert_equal_wstring(const char *file, int line,
++assertions;
if (wcscmp(v1, v2) == 0) {
msg[0] = '\0';
- return;
+ return (1);
}
failures ++;
if (previous_failures(file, line))
- return;
+ 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);
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++) {
if (ref != NULL && p[i + j] != ref[i + j])
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])
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. */
/* TODO: For long blocks, hexdump the first bytes that actually differ. */
-void
+int
test_assert_equal_mem(const char *file, int line,
const char *v1, const char *e1,
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 == v2) {
msg[0] = '\0';
- return;
+ return (1);
}
} else if (memcmp(v1, v2, l) == 0) {
msg[0] = '\0';
- return;
+ return (1);
}
failures ++;
if (previous_failures(file, line))
- return;
+ return (0);
fprintf(stderr, "%s:%d: Assertion failed: memory not equal\n",
file, line);
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);
fprintf(stderr, "\n");
report_failure(extra);
+ return (0);
}
-void
+int
test_assert_empty_file(const char *f1fmt, ...)
{
+ char buff[1024];
char f1[1024];
struct stat st;
va_list ap;
+ ssize_t s;
+ int fd;
+
va_start(ap, f1fmt);
vsprintf(f1, f1fmt, ap);
@@ -392,16 +410,32 @@ test_assert_empty_file(const char *f1fmt, ...)
if (stat(f1, &st) != 0) {
fprintf(stderr, "%s:%d: Could not stat: %s\n", test_filename, test_line, f1);
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. */
/* TODO: hexdump the first bytes that actually differ. */
-void
+int
test_assert_equal_file(const char *f1, const char *f2pattern, ...)
{
char f2[1024];
@@ -423,16 +457,58 @@ test_assert_equal_file(const char *f1, const char *f2pattern, ...)
if (n1 != n2)
break;
if (n1 == 0 && n2 == 0)
- return;
+ return (1);
if (memcmp(buff1, buff2, n1) != 0)
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, " file2=\"%s\"\n", f2);
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
@@ -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).
*/
#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"
};
@@ -572,6 +648,10 @@ static void usage(const char *program)
printf("Options:\n");
printf(" -k Keep running after failures.\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(" -r <dir> Path to dir containing reference files.\n");
printf(" Default: Current directory.\n");
@@ -581,6 +661,66 @@ static void usage(const char *program)
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)
{
static const int limit = sizeof(tests) / sizeof(tests[0]);
@@ -602,17 +742,33 @@ int main(int argc, char **argv)
++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. */
- refdir = getenv(PROGRAM "_TEST_FILES");
+ refdir = getenv(ENVBASE "_TEST_FILES");
/*
* Parse options.
*/
- while ((opt = getopt(argc, argv, "kqr:")) != -1) {
+ while ((opt = getopt(argc, argv, "kp:qr:")) != -1) {
switch (opt) {
case 'k':
dump_on_failure = 0;
break;
+ case 'p':
+#ifdef PROGRAM
+ testprog = optarg;
+#else
+ usage(progname);
+#endif
+ break;
case 'q':
quiet_flag++;
break;
@@ -628,6 +784,14 @@ int main(int argc, char **argv)
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.
* Include the time the tests started as part of the name,
* to make it easier to track the results of multiple tests.
@@ -667,7 +831,12 @@ int main(int argc, char **argv)
if (!quiet_flag) {
printf("Running tests in: %s\n", tmpdir);
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);
}
/*
diff --git a/lib/libarchive/test/test.h b/lib/libarchive/test/test.h
index 07de016f3219f..2284340dcb7b8 100644
--- a/lib/libarchive/test/test.h
+++ b/lib/libarchive/test/test.h
@@ -35,6 +35,7 @@
#define _FILE_OFFSET_BITS 64
#endif
+#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
@@ -116,12 +117,13 @@ void failure(const char *fmt, ...);
void test_setup(const char *, int);
void test_skipping(const char *fmt, ...);
int test_assert(const char *, int, int, const char *, void *);
-void test_assert_empty_file(const char *, ...);
-void test_assert_equal_file(const char *, const char *, ...);
-void 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 *);
-void 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_empty_file(const char *, ...);
+int test_assert_equal_file(const char *, const char *, ...);
+int test_assert_equal_int(const char *, int, int, const char *, int, const char *, void *);
+int test_assert_equal_string(const char *, int, const char *v1, const char *, const char *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 *);
+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() */
int systemf(const char * fmt, ...);
@@ -130,12 +132,8 @@ int systemf(const char * fmt, ...);
/* Supports printf-style args: slurpfile(NULL, "%s/myfile", refdir); */
char *slurpfile(size_t *, const char *fmt, ...);
-/*
- * Global vars
- */
-
-/* Directory holding reference files. */
-char *refdir;
+/* Extracts named reference file to the current directory. */
+void extract_reference_file(const char *);
/*
* Special interfaces for libarchive test harness.
diff --git a/lib/libarchive/test/test_archive_api_feature.c b/lib/libarchive/test/test_archive_api_feature.c
index 32a51fba2d12b..ba9dd44858474 100644
--- a/lib/libarchive/test/test_archive_api_feature.c
+++ b/lib/libarchive/test/test_archive_api_feature.c
@@ -27,6 +27,19 @@ __FBSDID("$FreeBSD$");
DEFINE_TEST(test_archive_api_feature)
{
+ char buff[128];
+
+ /* This is the (hopefully) final versioning API. */
+ assertEqualInt(ARCHIVE_VERSION_NUMBER, archive_version_number());
+ sprintf(buff, "libarchive %d.%d.%d",
+ archive_version_number() / 1000000,
+ (archive_version_number() / 1000) % 1000,
+ archive_version_number() % 1000);
+ assertEqualString(buff, archive_version_string());
+
+/* This is all scheduled to disappear in libarchive 3.0 */
+#if ARCHIVE_VERSION_NUMBER < 3000000
+ assertEqualInt(ARCHIVE_VERSION_STAMP, ARCHIVE_VERSION_NUMBER);
assertEqualInt(ARCHIVE_API_FEATURE, archive_api_feature());
assertEqualInt(ARCHIVE_API_VERSION, archive_api_version());
/*
@@ -48,4 +61,5 @@ DEFINE_TEST(test_archive_api_feature)
skipping("archive_version_stamp()");
#endif
assertEqualString(ARCHIVE_LIBRARY_VERSION, archive_version());
+#endif
}
diff --git a/lib/libarchive/test/test_compat_gtar.c b/lib/libarchive/test/test_compat_gtar.c
index 0f0dadffd81cb..24a294fc9cb35 100644
--- a/lib/libarchive/test/test_compat_gtar.c
+++ b/lib/libarchive/test/test_compat_gtar.c
@@ -40,14 +40,14 @@ __FBSDID("$FreeBSD$");
static void
test_compat_gtar_1(void)
{
- char name[1024];
+ char name[] = "test_compat_gtar_1.tgz";
struct archive_entry *ae;
struct archive *a;
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_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));
/* Read first entry. */
diff --git a/lib/libarchive/test/test_compat_tar_hardlink.c b/lib/libarchive/test/test_compat_tar_hardlink.c
index 3b3b34d2b9f10..6d1566fb3a8e7 100644
--- a/lib/libarchive/test/test_compat_tar_hardlink.c
+++ b/lib/libarchive/test/test_compat_tar_hardlink.c
@@ -46,14 +46,14 @@ __FBSDID("$FreeBSD$");
static void
test_compat_tar_hardlink_1(void)
{
- char name[1024];
+ char name[] = "test_compat_tar_hardlink_1.tar";
struct archive_entry *ae;
struct archive *a;
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_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));
/* Read first entry, which is a regular file. */
diff --git a/lib/libarchive/test/test_compat_zip.c b/lib/libarchive/test/test_compat_zip.c
index 082fc96654e22..f174c38b0dc03 100644
--- a/lib/libarchive/test/test_compat_zip.c
+++ b/lib/libarchive/test/test_compat_zip.c
@@ -29,14 +29,14 @@ __FBSDID("$FreeBSD$");
static void
test_compat_zip_1(void)
{
- char name[1024];
+ char name[] = "test_compat_zip_1.zip";
struct archive_entry *ae;
struct archive *a;
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_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));
/* Read first entry. */
diff --git a/lib/libarchive/test/test_empty_write.c b/lib/libarchive/test/test_empty_write.c
index ed5c650e11f36..37b14b834e88f 100644
--- a/lib/libarchive/test/test_empty_write.c
+++ b/lib/libarchive/test/test_empty_write.c
@@ -47,6 +47,7 @@ DEFINE_TEST(test_empty_write)
archive_entry_set_mode(ae, S_IFREG | 0755);
archive_entry_set_size(ae, 0);
assertA(0 == archive_write_header(a, ae));
+ archive_entry_free(ae);
/* THE TEST: write zero bytes to this entry. */
/* This used to crash. */
@@ -76,6 +77,7 @@ DEFINE_TEST(test_empty_write)
archive_entry_set_mode(ae, S_IFREG | 0755);
archive_entry_set_size(ae, 0);
assertA(0 == archive_write_header(a, ae));
+ archive_entry_free(ae);
/* THE TEST: write zero bytes to this entry. */
assertEqualIntA(a, 0, archive_write_data(a, "", 0));
@@ -104,6 +106,7 @@ DEFINE_TEST(test_empty_write)
archive_entry_set_mode(ae, S_IFREG | 0755);
archive_entry_set_size(ae, 0);
assertA(0 == archive_write_header(a, ae));
+ archive_entry_free(ae);
/* THE TEST: write zero bytes to this entry. */
assertEqualIntA(a, 0, archive_write_data(a, "", 0));
diff --git a/lib/libarchive/test/test_entry.c b/lib/libarchive/test/test_entry.c
index e829b2589906b..638af48e68f64 100644
--- a/lib/libarchive/test/test_entry.c
+++ b/lib/libarchive/test/test_entry.c
@@ -25,6 +25,8 @@
#include "test.h"
__FBSDID("$FreeBSD$");
+#include <locale.h>
+
/*
* Most of these tests are system-independent, though a few depend on
* features of the local system. Such tests are conditionalized on
@@ -120,8 +122,37 @@ DEFINE_TEST(test_entry)
#else
skipping("archive_entry_ino()");
#endif
+
/* link */
- /* TODO: implement these tests. */
+ archive_entry_set_hardlink(e, "hardlinkname");
+ archive_entry_set_symlink(e, NULL);
+ archive_entry_set_link(e, "link");
+ assertEqualString(archive_entry_hardlink(e), "link");
+ assertEqualString(archive_entry_symlink(e), NULL);
+ archive_entry_copy_link(e, "link2");
+ assertEqualString(archive_entry_hardlink(e), "link2");
+ assertEqualString(archive_entry_symlink(e), NULL);
+ archive_entry_copy_link_w(e, L"link3");
+ assertEqualString(archive_entry_hardlink(e), "link3");
+ assertEqualString(archive_entry_symlink(e), NULL);
+ archive_entry_set_hardlink(e, NULL);
+ archive_entry_set_symlink(e, "symlink");
+ archive_entry_set_link(e, "link");
+ assertEqualString(archive_entry_hardlink(e), NULL);
+ assertEqualString(archive_entry_symlink(e), "link");
+ archive_entry_copy_link(e, "link2");
+ assertEqualString(archive_entry_hardlink(e), NULL);
+ assertEqualString(archive_entry_symlink(e), "link2");
+ archive_entry_copy_link_w(e, L"link3");
+ assertEqualString(archive_entry_hardlink(e), NULL);
+ assertEqualString(archive_entry_symlink(e), "link3");
+ /* Arbitrarily override hardlink if both hardlink and symlink set. */
+ archive_entry_set_hardlink(e, "hardlink");
+ archive_entry_set_symlink(e, "symlink");
+ archive_entry_set_link(e, "link");
+ assertEqualString(archive_entry_hardlink(e), "hardlink");
+ assertEqualString(archive_entry_symlink(e), "link");
+
/* mode */
archive_entry_set_mode(e, 0123456);
assertEqualInt(archive_entry_mode(e), 0123456);
@@ -213,10 +244,16 @@ DEFINE_TEST(test_entry)
assertEqualInt(1, archive_entry_xattr_count(e));
assertEqualInt(ARCHIVE_WARN,
archive_entry_xattr_next(e, &xname, &xval, &xsize));
+ assertEqualString(xname, NULL);
+ assertEqualString(xval, NULL);
+ assertEqualInt(xsize, 0);
archive_entry_xattr_clear(e);
assertEqualInt(0, archive_entry_xattr_reset(e));
assertEqualInt(ARCHIVE_WARN,
archive_entry_xattr_next(e, &xname, &xval, &xsize));
+ assertEqualString(xname, NULL);
+ assertEqualString(xval, NULL);
+ assertEqualInt(xsize, 0);
archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue1", 12);
assertEqualInt(1, archive_entry_xattr_reset(e));
archive_entry_xattr_add_entry(e, "xattr2", "xattrvalue2", 12);
@@ -225,6 +262,9 @@ DEFINE_TEST(test_entry)
assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize));
assertEqualInt(ARCHIVE_WARN,
archive_entry_xattr_next(e, &xname, &xval, &xsize));
+ assertEqualString(xname, NULL);
+ assertEqualString(xval, NULL);
+ assertEqualInt(xsize, 0);
/*
@@ -348,6 +388,11 @@ DEFINE_TEST(test_entry)
assertEqualString(xname, "xattr1");
assertEqualString(xval, "xattrvalue");
assertEqualInt(xsize, 11);
+ assertEqualInt(ARCHIVE_WARN,
+ archive_entry_xattr_next(e2, &xname, &xval, &xsize));
+ assertEqualString(xname, NULL);
+ assertEqualString(xval, NULL);
+ assertEqualInt(xsize, 0);
#endif
/* Change the original */
@@ -453,6 +498,14 @@ DEFINE_TEST(test_entry)
assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER);
assertEqualInt(qual, 77);
assertEqualString(name, "user77");
+ assertEqualInt(1, archive_entry_acl_next(e2,
+ ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
+ &type, &permset, &tag, &qual, &name));
+ assertEqualInt(type, 0);
+ assertEqualInt(permset, 0);
+ assertEqualInt(tag, 0);
+ assertEqualInt(qual, -1);
+ assertEqualString(name, NULL);
#endif
#if ARCHIVE_VERSION_STAMP < 1009000
skipping("xattr preserved in archive_entry copy");
@@ -670,6 +723,39 @@ DEFINE_TEST(test_entry)
#endif
#endif
+ /*
+ * Exercise the character-conversion logic, if we can.
+ */
+ failure("Can't exercise charset-conversion logic.");
+ if (assert(NULL != setlocale(LC_ALL, "de_DE.UTF-8"))) {
+ /* A filename that cannot be converted to wide characters. */
+ archive_entry_copy_pathname(e, "abc\314\214mno\374xyz");
+ failure("Converting invalid chars to Unicode should fail.");
+ assert(NULL == archive_entry_pathname_w(e));
+ //failure("Converting invalid chars to UTF-8 should fail.");
+ //assert(NULL == archive_entry_pathname_utf8(e));
+
+ /* A group name that cannot be converted. */
+ archive_entry_copy_gname(e, "abc\314\214mno\374xyz");
+ failure("Converting invalid chars to Unicode should fail.");
+ assert(NULL == archive_entry_gname_w(e));
+
+ /* A user name that cannot be converted. */
+ archive_entry_copy_uname(e, "abc\314\214mno\374xyz");
+ failure("Converting invalid chars to Unicode should fail.");
+ assert(NULL == archive_entry_uname_w(e));
+
+ /* A hardlink target that cannot be converted. */
+ archive_entry_copy_hardlink(e, "abc\314\214mno\374xyz");
+ failure("Converting invalid chars to Unicode should fail.");
+ assert(NULL == archive_entry_hardlink_w(e));
+
+ /* A symlink target that cannot be converted. */
+ archive_entry_copy_symlink(e, "abc\314\214mno\374xyz");
+ failure("Converting invalid chars to Unicode should fail.");
+ assert(NULL == archive_entry_symlink_w(e));
+ }
+
/* Release the experimental entry. */
archive_entry_free(e);
}
diff --git a/lib/libarchive/test/test_read_format_gtar_sparse.c b/lib/libarchive/test/test_read_format_gtar_sparse.c
index 12bf23f6ab9c0..f3eb274b7256e 100644
--- a/lib/libarchive/test/test_read_format_gtar_sparse.c
+++ b/lib/libarchive/test/test_read_format_gtar_sparse.c
@@ -181,7 +181,6 @@ struct archive_contents {
static void
verify_archive_file(const char *name, struct archive_contents *ac)
{
- char path[512];
struct archive_entry *ae;
int err;
/* 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 archive *a;
- sprintf(path, "%s/%s", refdir, name);
+ extract_reference_file(name);
assert((a = archive_read_new()) != NULL);
assert(0 == archive_read_support_compression_all(a));
assert(0 == archive_read_support_format_tar(a));
- failure("Can't open %s", path);
- assert(0 == archive_read_open_filename(a, path, 3));
+ failure("Can't open %s", name);
+ assert(0 == archive_read_open_filename(a, name, 3));
while (ac->filename != NULL) {
struct contents *cts = ac->contents;