aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Matuska <mm@FreeBSD.org>2013-03-21 21:51:46 +0000
committerMartin Matuska <mm@FreeBSD.org>2013-03-21 21:51:46 +0000
commit48ff71b692467e4a7e2173f1f1670ebc77116fad (patch)
tree69a8859f8bca61aba977c5201b8cf5f21b7e2f54
parent6a316f322a46b3e531726dd2a7de63b9e245878d (diff)
downloadsrc-48ff71b692467e4a7e2173f1f1670ebc77116fad.tar.gz
src-48ff71b692467e4a7e2173f1f1670ebc77116fad.zip
Delete files accidentially left over in r248590 (libarchive 3.1.2)vendor/libarchive/3.1.2
Notes
Notes: svn path=/vendor/libarchive/dist/; revision=248594 svn path=/vendor/libarchive/3.1.2/; revision=248615; tag=vendor/libarchive/3.1.2
-rw-r--r--libarchive/filter_fork.c161
-rw-r--r--libarchive/test/test_acl_freebsd.c260
-rw-r--r--libarchive/test/test_read_compress_program.c84
-rw-r--r--libarchive/test/test_read_uu.c175
-rw-r--r--libarchive/test/test_write_compress.c97
-rw-r--r--libarchive/test/test_write_compress_bzip2.c228
-rw-r--r--libarchive/test/test_write_compress_gzip.c256
-rw-r--r--libarchive/test/test_write_compress_lzip.c247
-rw-r--r--libarchive/test/test_write_compress_lzma.c251
-rw-r--r--libarchive/test/test_write_compress_program.c123
-rw-r--r--libarchive/test/test_write_compress_xz.c257
11 files changed, 0 insertions, 2139 deletions
diff --git a/libarchive/filter_fork.c b/libarchive/filter_fork.c
deleted file mode 100644
index d160524b097c..000000000000
--- a/libarchive/filter_fork.c
+++ /dev/null
@@ -1,161 +0,0 @@
-/*-
- * Copyright (c) 2007 Joerg Sonnenberger
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "archive_platform.h"
-
-/* This capability is only available on POSIX systems. */
-#if defined(HAVE_PIPE) && defined(HAVE_FCNTL) && \
- (defined(HAVE_FORK) || defined(HAVE_VFORK))
-
-__FBSDID("$FreeBSD: head/lib/libarchive/filter_fork.c 182958 2008-09-12 05:33:00Z kientzle $");
-
-#if defined(HAVE_POLL) && (defined(HAVE_POLL_H) || defined(HAVE_SYS_POLL_H))
-# if defined(HAVE_POLL_H)
-# include <poll.h>
-# elif defined(HAVE_SYS_POLL_H)
-# include <sys/poll.h>
-# endif
-#elif defined(HAVE_SELECT)
-# if defined(HAVE_SYS_SELECT_H)
-# include <sys/select.h>
-# elif defined(HAVE_UNISTD_H)
-# include <unistd.h>
-# endif
-#endif
-#ifdef HAVE_FCNTL_H
-# include <fcntl.h>
-#endif
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
-#include "filter_fork.h"
-
-pid_t
-__archive_create_child(const char *path, int *child_stdin, int *child_stdout)
-{
- pid_t child;
- int stdin_pipe[2], stdout_pipe[2], tmp;
-
- if (pipe(stdin_pipe) == -1)
- goto state_allocated;
- if (stdin_pipe[0] == 1 /* stdout */) {
- if ((tmp = dup(stdin_pipe[0])) == -1)
- goto stdin_opened;
- close(stdin_pipe[0]);
- stdin_pipe[0] = tmp;
- }
- if (pipe(stdout_pipe) == -1)
- goto stdin_opened;
- if (stdout_pipe[1] == 0 /* stdin */) {
- if ((tmp = dup(stdout_pipe[1])) == -1)
- goto stdout_opened;
- close(stdout_pipe[1]);
- stdout_pipe[1] = tmp;
- }
-
-#if HAVE_VFORK
- switch ((child = vfork())) {
-#else
- switch ((child = fork())) {
-#endif
- case -1:
- goto stdout_opened;
- case 0:
- close(stdin_pipe[1]);
- close(stdout_pipe[0]);
- if (dup2(stdin_pipe[0], 0 /* stdin */) == -1)
- _exit(254);
- if (stdin_pipe[0] != 0 /* stdin */)
- close(stdin_pipe[0]);
- if (dup2(stdout_pipe[1], 1 /* stdout */) == -1)
- _exit(254);
- if (stdout_pipe[1] != 1 /* stdout */)
- close(stdout_pipe[1]);
- execlp(path, path, (char *)NULL);
- _exit(254);
- default:
- close(stdin_pipe[0]);
- close(stdout_pipe[1]);
-
- *child_stdin = stdin_pipe[1];
- fcntl(*child_stdin, F_SETFL, O_NONBLOCK);
- *child_stdout = stdout_pipe[0];
- fcntl(*child_stdout, F_SETFL, O_NONBLOCK);
- }
-
- return child;
-
-stdout_opened:
- close(stdout_pipe[0]);
- close(stdout_pipe[1]);
-stdin_opened:
- close(stdin_pipe[0]);
- close(stdin_pipe[1]);
-state_allocated:
- return -1;
-}
-
-void
-__archive_check_child(int in, int out)
-{
-#if defined(HAVE_POLL) && (defined(HAVE_POLL_H) || defined(HAVE_SYS_POLL_H))
- struct pollfd fds[2];
- int idx;
-
- idx = 0;
- if (in != -1) {
- fds[idx].fd = in;
- fds[idx].events = POLLOUT;
- ++idx;
- }
- if (out != -1) {
- fds[idx].fd = out;
- fds[idx].events = POLLIN;
- ++idx;
- }
-
- poll(fds, idx, -1); /* -1 == INFTIM, wait forever */
-#elif defined(HAVE_SELECT)
- fd_set fds_in, fds_out, fds_error;
-
- FD_ZERO(&fds_in);
- FD_ZERO(&fds_out);
- FD_ZERO(&fds_error);
- if (out != -1) {
- FD_SET(out, &fds_in);
- FD_SET(out, &fds_error);
- }
- if (in != -1) {
- FD_SET(in, &fds_out);
- FD_SET(in, &fds_error);
- }
- select(in < out ? out + 1 : in + 1, &fds_in, &fds_out, &fds_error, NULL);
-#else
- sleep(1);
-#endif
-}
-
-#endif /* defined(HAVE_PIPE) && defined(HAVE_VFORK) && defined(HAVE_FCNTL) */
diff --git a/libarchive/test/test_acl_freebsd.c b/libarchive/test/test_acl_freebsd.c
deleted file mode 100644
index 1680f9f80e55..000000000000
--- a/libarchive/test/test_acl_freebsd.c
+++ /dev/null
@@ -1,260 +0,0 @@
-/*-
- * Copyright (c) 2003-2008 Tim Kientzle
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "test.h"
-__FBSDID("$FreeBSD: head/lib/libarchive/test/test_acl_freebsd.c 189427 2009-03-06 04:21:23Z kientzle $");
-
-#if defined(__FreeBSD__) && __FreeBSD__ > 4
-#include <sys/acl.h>
-
-struct myacl_t {
- int type; /* Type of ACL: "access" or "default" */
- int permset; /* Permissions for this class of users. */
- int tag; /* Owner, User, Owning group, group, other, etc. */
- int qual; /* GID or UID of user/group, depending on tag. */
- const char *name; /* Name of user/group, depending on tag. */
-};
-
-static struct myacl_t acls2[] = {
- { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE | ARCHIVE_ENTRY_ACL_READ,
- ARCHIVE_ENTRY_ACL_USER_OBJ, -1, "" },
- { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ,
- ARCHIVE_ENTRY_ACL_USER, 77, "user77" },
- { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0,
- ARCHIVE_ENTRY_ACL_USER, 78, "user78" },
- { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ,
- ARCHIVE_ENTRY_ACL_GROUP_OBJ, -1, "" },
- { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0007,
- ARCHIVE_ENTRY_ACL_GROUP, 78, "group78" },
- { ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
- ARCHIVE_ENTRY_ACL_WRITE | ARCHIVE_ENTRY_ACL_EXECUTE,
- ARCHIVE_ENTRY_ACL_OTHER, -1, "" },
- { ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
- ARCHIVE_ENTRY_ACL_WRITE | ARCHIVE_ENTRY_ACL_READ | ARCHIVE_ENTRY_ACL_EXECUTE,
- ARCHIVE_ENTRY_ACL_MASK, -1, "" },
- { 0, 0, 0, 0, NULL }
-};
-
-static void
-set_acls(struct archive_entry *ae, struct myacl_t *acls)
-{
- int i;
-
- archive_entry_acl_clear(ae);
- for (i = 0; acls[i].name != NULL; i++) {
- archive_entry_acl_add_entry(ae,
- acls[i].type, acls[i].permset, acls[i].tag, acls[i].qual,
- acls[i].name);
- }
-}
-
-static int
-acl_match(acl_entry_t aclent, struct myacl_t *myacl)
-{
- gid_t g, *gp;
- uid_t u, *up;
- acl_tag_t tag_type;
- acl_permset_t opaque_ps;
- int permset = 0;
-
- acl_get_tag_type(aclent, &tag_type);
-
- /* translate the silly opaque permset to a bitmap */
- acl_get_permset(aclent, &opaque_ps);
- if (acl_get_perm_np(opaque_ps, ACL_EXECUTE))
- permset |= ARCHIVE_ENTRY_ACL_EXECUTE;
- if (acl_get_perm_np(opaque_ps, ACL_WRITE))
- permset |= ARCHIVE_ENTRY_ACL_WRITE;
- if (acl_get_perm_np(opaque_ps, ACL_READ))
- permset |= ARCHIVE_ENTRY_ACL_READ;
-
- if (permset != myacl->permset)
- return (0);
-
- switch (tag_type) {
- case ACL_USER_OBJ:
- if (myacl->tag != ARCHIVE_ENTRY_ACL_USER_OBJ) return (0);
- break;
- case ACL_USER:
- if (myacl->tag != ARCHIVE_ENTRY_ACL_USER)
- return (0);
- up = acl_get_qualifier(aclent);
- u = *up;
- acl_free(up);
- if ((uid_t)myacl->qual != u)
- return (0);
- break;
- case ACL_GROUP_OBJ:
- if (myacl->tag != ARCHIVE_ENTRY_ACL_GROUP_OBJ) return (0);
- break;
- case ACL_GROUP:
- if (myacl->tag != ARCHIVE_ENTRY_ACL_GROUP)
- return (0);
- gp = acl_get_qualifier(aclent);
- g = *gp;
- acl_free(gp);
- if ((gid_t)myacl->qual != g)
- return (0);
- break;
- case ACL_MASK:
- if (myacl->tag != ARCHIVE_ENTRY_ACL_MASK) return (0);
- break;
- case ACL_OTHER:
- if (myacl->tag != ARCHIVE_ENTRY_ACL_OTHER) return (0);
- break;
- }
- return (1);
-}
-
-static void
-compare_acls(acl_t acl, struct myacl_t *myacls)
-{
- int *marker;
- int entry_id = ACL_FIRST_ENTRY;
- int matched;
- int i, n;
- acl_entry_t acl_entry;
-
- /* Count ACL entries in myacls array and allocate an indirect array. */
- for (n = 0; myacls[n].name != NULL; ++n)
- continue;
- marker = malloc(sizeof(marker[0]) * n);
- for (i = 0; i < n; i++)
- marker[i] = i;
-
- /*
- * Iterate over acls in system acl object, try to match each
- * one with an item in the myacls array.
- */
- while (1 == acl_get_entry(acl, entry_id, &acl_entry)) {
- /* After the first time... */
- entry_id = ACL_NEXT_ENTRY;
-
- /* Search for a matching entry (tag and qualifier) */
- for (i = 0, matched = 0; i < n && !matched; i++) {
- if (acl_match(acl_entry, &myacls[marker[i]])) {
- /* We found a match; remove it. */
- marker[i] = marker[n - 1];
- n--;
- matched = 1;
- }
- }
-
- /* TODO: Print out more details in this case. */
- failure("ACL entry on file that shouldn't be there");
- assert(matched == 1);
- }
-
- /* Dump entries in the myacls array that weren't in the system acl. */
- for (i = 0; i < n; ++i) {
- failure(" ACL entry missing from file: "
- "type=%d,permset=%d,tag=%d,qual=%d,name=``%s''\n",
- myacls[marker[i]].type, myacls[marker[i]].permset,
- myacls[marker[i]].tag, myacls[marker[i]].qual,
- myacls[marker[i]].name);
- assert(0); /* Record this as a failure. */
- }
- free(marker);
-}
-
-#endif
-
-
-/*
- * Verify ACL restore-to-disk. This test is FreeBSD-specific.
- */
-
-DEFINE_TEST(test_acl_freebsd)
-{
-#if !defined(__FreeBSD__)
- skipping("FreeBSD-specific ACL restore test");
-#elif __FreeBSD__ < 5
- skipping("ACL restore supported only on FreeBSD 5.0 and later");
-#else
- struct stat st;
- struct archive *a;
- struct archive_entry *ae;
- int n, fd;
- acl_t acl;
-
- /*
- * First, do a quick manual set/read of ACL data to
- * verify that the local filesystem does support ACLs.
- * If it doesn't, we'll simply skip the remaining tests.
- */
- acl = acl_from_text("u::rwx,u:1:rw,g::rwx,g:15:rx,o::rwx,m::rwx");
- assert((void *)acl != NULL);
- /* Create a test file and try to set an ACL on it. */
- fd = open("pretest", O_WRONLY | O_CREAT | O_EXCL, 0777);
- failure("Could not create test file?!");
- if (!assert(fd >= 0)) {
- acl_free(acl);
- return;
- }
-
- n = acl_set_fd(fd, acl);
- acl_free(acl);
- if (n != 0 && errno == EOPNOTSUPP) {
- close(fd);
- skipping("ACL tests require that ACL support be enabled on the filesystem");
- return;
- }
- if (n != 0 && errno == EINVAL) {
- close(fd);
- skipping("This filesystem does not support POSIX.1e ACLs");
- return;
- }
- failure("acl_set_fd(): errno = %d (%s)",
- errno, strerror(errno));
- assertEqualInt(0, n);
- close(fd);
-
- /* Create a write-to-disk object. */
- assert(NULL != (a = archive_write_disk_new()));
- archive_write_disk_set_options(a,
- ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_ACL);
-
- /* Populate an archive entry with some metadata, including ACL info */
- ae = archive_entry_new();
- assert(ae != NULL);
- archive_entry_set_pathname(ae, "test0");
- archive_entry_set_mtime(ae, 123456, 7890);
- archive_entry_set_size(ae, 0);
- set_acls(ae, acls2);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
- archive_entry_free(ae);
-
- /* Close the archive. */
- assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- /* Verify the data on disk. */
- assertEqualInt(0, stat("test0", &st));
- assertEqualInt(st.st_mtime, 123456);
- acl = acl_get_file("test0", ACL_TYPE_ACCESS);
- assert(acl != (acl_t)NULL);
- compare_acls(acl, acls2);
- acl_free(acl);
-#endif
-}
diff --git a/libarchive/test/test_read_compress_program.c b/libarchive/test/test_read_compress_program.c
deleted file mode 100644
index 751abd54fc91..000000000000
--- a/libarchive/test/test_read_compress_program.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/*-
- * Copyright (c) 2003-2007 Tim Kientzle
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "test.h"
-__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_compress_program.c 201247 2009-12-30 05:59:21Z kientzle $");
-
-static unsigned char archive[] = {
-31,139,8,0,222,'C','p','C',0,3,211,'c',160,'=','0','0','0','0','7','5','U',
-0,210,134,230,166,6,200,'4',28,'(',24,26,24,27,155,24,152,24,154,27,155,')',
-24,24,26,152,154,25,'2','(',152,210,193,'m',12,165,197,'%',137,'E','@',167,
-148,'d',230,226,'U','G','H',30,234,15,'8','=',10,'F',193,'(',24,5,131,28,
-0,0,29,172,5,240,0,6,0,0};
-
-DEFINE_TEST(test_read_compress_program)
-{
- int r;
- struct archive_entry *ae;
- struct archive *a;
-
- /*
- * First, test handling when a non-existent compression
- * program is requested.
- */
- assert((a = archive_read_new()) != NULL);
- r = archive_read_support_filter_program(a, "nonexistent");
- if (r == ARCHIVE_FATAL) {
- skipping("archive_read_support_filter_program() "
- "unsupported on this platform");
- return;
- }
- assertEqualIntA(a, ARCHIVE_OK, r);
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_support_format_all(a));
- assertEqualIntA(a, ARCHIVE_FATAL,
- archive_read_open_memory(a, archive, sizeof(archive)));
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
- /*
- * If we have "gzip -d", try using that.
- */
- if (!canGunzip()) {
- skipping("Can't run gunzip program on this platform");
- return;
- }
- assert((a = archive_read_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_support_filter_none(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_support_filter_program(a, "gunzip"));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_support_format_all(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_open_memory(a, archive, sizeof(archive)));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_next_header(a, &ae));
- assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_PROGRAM);
- assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR);
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-}
-
-
diff --git a/libarchive/test/test_read_uu.c b/libarchive/test/test_read_uu.c
deleted file mode 100644
index 648dbf01ee1a..000000000000
--- a/libarchive/test/test_read_uu.c
+++ /dev/null
@@ -1,175 +0,0 @@
-/*-
- * Copyright (c) 2003-2007 Tim Kientzle
- * Copyright (c) 2009-2011 Michihiro NAKAJIMA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "test.h"
-__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_uu.c 201248 2009-12-30 06:12:03Z kientzle $");
-
-static const char archive[] = {
-"begin 644 test_read_uu.Z\n"
-"M'YV0+@`('$BPH,&#\"!,J7,BP(4(8$&_4J`$\"`,08$F%4O)AQ(\\2/(#7&@#%C\n"
-"M!@T8-##.L`$\"QL@:-F(``%'#H<V;.'/J!%!G#ITP<BS\"H).FS<Z$1(T>/1A2\n"
-"IHU\"0%9=*G4JUJM6K6+-JW<JUJ]>O8,.*'4NVK-FS:-.J7<NVK=NW9P$`\n"
-"`\n"
-"end\n"
-};
-
-static const char archive64[] = {
-"begin-base64 644 test_read_uu.Z\n"
-"H52QLgAIHEiwoMGDCBMqXMiwIUIYEG/UqAECAMQYEmFUvJhxI8SPIDXGgDFjBg0YNDDOsAECxsga\n"
-"NmIAAFHDoc2bOHPqBFBnDp0wcizCoJOmzc6ERI0ePRhSo1CQFZdKnUq1qtWrWLNq3cq1q9evYMOK\n"
-"HUu2rNmzaNOqXcu2rdu3ZwE=\n"
-"====\n"
-};
-
-static const char extradata[] = {
-"From uudecode@libarchive Mon Jun 2 03:03:31 2008\n"
-"Return-Path: <uudecode@libarchive>\n"
-"Received: from libarchive (localhost [127.0.0.1])\n"
-" by libarchive (8.14.2/8.14.2) with ESMTP id m5233UT1006448\n"
-" for <uudecode@libarchive>; Mon, 2 Jun 2008 03:03:31 GMT\n"
-" (envelope-from uudecode@libarchive)\n"
-"Received: (from uudecode@localhost)\n"
-" by libarchive (8.14.2/8.14.2/Submit) id m5233U3e006406\n"
-" for uudecode; Mon, 2 Jun 2008 03:03:30 GMT\n"
-" (envelope-from root)\n"
-"Date: Mon, 2 Jun 2008 03:03:30 GMT\n"
-"From: Libarchive Test <uudecode@libarchive>\n"
-"Message-Id: <200806020303.m5233U3e006406@libarchive>\n"
-"To: uudecode@libarchive\n"
-"Subject: Libarchive uudecode test\n"
-"\n"
-"* Redistribution and use in source and binary forms, with or without\n"
-"* modification, are permitted provided that the following conditions\n"
-"* are met:\n"
-"\n"
-"01234567890abcdeghijklmnopqrstuvwxyz\n"
-"01234567890ABCEFGHIJKLMNOPQRSTUVWXYZ\n"
-"\n"
-};
-
-static void
-test_read_uu_sub(const char *uudata, size_t uusize, int no_nl)
-{
- struct archive_entry *ae;
- struct archive *a;
- char *buff;
- char extradata_no_nl[sizeof(extradata)];
- const char *extradata_ptr;
- int extra;
- size_t size;
-
- if (no_nl) {
- /* Remove '\n' from extra data to make a very long line. */
- char *p;
- memcpy(extradata_no_nl, extradata, sizeof(extradata));
- extradata_ptr = extradata_no_nl;
- for (p = extradata_no_nl;
- *p && (p = strchr(p, '\n')) != NULL; p++)
- *p = ' ';/* Replace '\n' with ' ' a space character. */
- } else
- extradata_ptr = extradata;
-
- assert(NULL != (buff = malloc(uusize + 1024 * 1024)));
- if (buff == NULL)
- return;
- for (extra = 0; extra <= 64; extra = extra==0?1:extra*2) {
- char *p = buff;
-
- size = extra * 1024;
- /* Add extra text size of which is from 1K bytes to
- * 64Kbytes before uuencoded data. */
- while (size) {
- if (size > sizeof(extradata)-1) {
- memcpy(p, extradata_ptr, sizeof(extradata)-1);
- p += sizeof(extradata)-1;
- size -= sizeof(extradata)-1;
- } else {
- memcpy(p, extradata_ptr, size-1);
- p += size-1;
- *p++ = '\n';/* the last of extra text must have
- * '\n' character. */
- break;
- }
- }
- memcpy(p, uudata, uusize);
- size = extra * 1024 + uusize;
-
- assert((a = archive_read_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_support_filter_all(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_support_format_all(a));
- assertEqualIntA(a, ARCHIVE_OK,
- read_open_memory(a, buff, size, 2));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_next_header(a, &ae));
- failure("archive_compression_name(a)=\"%s\""
- "extra %d, NL %d",
- archive_compression_name(a), extra, !no_nl);
- assertEqualInt(archive_compression(a),
- ARCHIVE_COMPRESSION_COMPRESS);
- failure("archive_format_name(a)=\"%s\""
- "extra %d, NL %d",
- archive_format_name(a), extra, !no_nl);
- assertEqualInt(archive_format(a),
- ARCHIVE_FORMAT_TAR_USTAR);
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
- }
-
- /* UUdecode bidder shouldn't scan too much data; make sure it
- * fails if we put 512k of data before the start. */
- size = 512 * 1024;
- for (extra = 0; (size_t)extra < size; ++extra)
- buff[extra + 1024] = buff[extra];
- buff[size - 1] = '\n';
- memcpy(buff + size, uudata, uusize);
- size += uusize;
- assert((a = archive_read_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_support_filter_all(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_support_format_all(a));
- assertEqualIntA(a, ARCHIVE_FATAL,
- read_open_memory(a, buff, size, 2));
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
- free(buff);
-}
-
-DEFINE_TEST(test_read_uu)
-{
- /* Read the traditional uuencoded data. */
- test_read_uu_sub(archive, sizeof(archive)-1, 0);
- /* Read the Base64 uuencoded data. */
- test_read_uu_sub(archive64, sizeof(archive64)-1, 0);
- /* Read the traditional uuencoded data with very long line extra
- * data in front of it. */
- test_read_uu_sub(archive, sizeof(archive)-1, 1);
- /* Read the Base64 uuencoded data with very long line extra data
- * in front of it. */
- test_read_uu_sub(archive64, sizeof(archive64)-1, 1);
-}
-
diff --git a/libarchive/test/test_write_compress.c b/libarchive/test/test_write_compress.c
deleted file mode 100644
index bb81c4f311bf..000000000000
--- a/libarchive/test/test_write_compress.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/*-
- * Copyright (c) 2007 Tim Kientzle
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer
- * in this position and unchanged.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "test.h"
-__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_compress.c 189308 2009-03-03 17:02:51Z kientzle $");
-
-/*
- * A basic exercise of compress reading and writing.
- *
- * TODO: Add a reference file and make sure we can decompress that.
- */
-
-DEFINE_TEST(test_write_compress)
-{
- struct archive_entry *ae;
- struct archive* a;
- char *buff, *data;
- size_t buffsize, datasize;
- char path[16];
- size_t used;
- int i;
-
- buffsize = 1000000;
- assert(NULL != (buff = (char *)malloc(buffsize)));
-
- datasize = 10000;
- assert(NULL != (data = (char *)malloc(datasize)));
- memset(data, 0, datasize);
-
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_compression_compress(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_open_memory(a, buff, buffsize, &used));
-
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- assert((ae = archive_entry_new()) != NULL);
- archive_entry_copy_pathname(ae, path);
- archive_entry_set_size(ae, datasize);
- archive_entry_set_filetype(ae, AE_IFREG);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
- assertEqualInt(datasize,
- archive_write_data(a, data, datasize));
- archive_entry_free(ae);
- }
-
- assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- /*
- * Now, read the data back.
- */
- assert((a = archive_read_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used));
-
-
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- if (!assertEqualInt(0, archive_read_next_header(a, &ae)))
- break;
- assertEqualString(path, archive_entry_pathname(ae));
- assertEqualInt((int)datasize, archive_entry_size(ae));
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
- free(data);
- free(buff);
-}
diff --git a/libarchive/test/test_write_compress_bzip2.c b/libarchive/test/test_write_compress_bzip2.c
deleted file mode 100644
index b9e92369a9c2..000000000000
--- a/libarchive/test/test_write_compress_bzip2.c
+++ /dev/null
@@ -1,228 +0,0 @@
-/*-
- * Copyright (c) 2007 Tim Kientzle
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer
- * in this position and unchanged.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "test.h"
-__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_compress_bzip2.c 191183 2009-04-17 01:06:31Z kientzle $");
-
-/*
- * A basic exercise of bzip2 reading and writing.
- *
- * TODO: Add a reference file and make sure we can decompress that.
- */
-
-DEFINE_TEST(test_write_compress_bzip2)
-{
- struct archive_entry *ae;
- struct archive* a;
- char *buff, *data;
- size_t buffsize, datasize;
- char path[16];
- size_t used1, used2;
- int i, r;
-
- buffsize = 2000000;
- assert(NULL != (buff = (char *)malloc(buffsize)));
-
- datasize = 10000;
- assert(NULL != (data = (char *)malloc(datasize)));
- memset(data, 0, datasize);
-
- /*
- * Write a 100 files and read them all back.
- */
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- r = archive_write_set_compression_bzip2(a);
- if (r == ARCHIVE_FATAL) {
- skipping("bzip2 writing not supported on this platform");
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
- return;
- }
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_bytes_per_block(a, 10));
- assertEqualInt(ARCHIVE_COMPRESSION_BZIP2, archive_compression(a));
- assertEqualString("bzip2", archive_compression_name(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used1));
- assertEqualInt(ARCHIVE_COMPRESSION_BZIP2, archive_compression(a));
- assertEqualString("bzip2", archive_compression_name(a));
- assert((ae = archive_entry_new()) != NULL);
- archive_entry_set_filetype(ae, AE_IFREG);
- archive_entry_set_size(ae, datasize);
- for (i = 0; i < 999; i++) {
- sprintf(path, "file%03d", i);
- archive_entry_copy_pathname(ae, path);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
- assertA(datasize
- == (size_t)archive_write_data(a, data, datasize));
- }
- archive_entry_free(ae);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- assert((a = archive_read_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used1));
- for (i = 0; i < 999; i++) {
- sprintf(path, "file%03d", i);
- if (!assertEqualInt(0, archive_read_next_header(a, &ae)))
- break;
- assertEqualString(path, archive_entry_pathname(ae));
- assertEqualInt((int)datasize, archive_entry_size(ae));
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
- /*
- * Repeat the cycle again, this time setting some compression
- * options.
- */
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_bytes_per_block(a, 10));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a));
- assertEqualIntA(a, ARCHIVE_FAILED,
- archive_write_set_filter_option(a, NULL, "nonexistent-option", "0"));
- assertEqualIntA(a, ARCHIVE_FAILED,
- archive_write_set_filter_option(a, NULL, "compression-level", "abc"));
- assertEqualIntA(a, ARCHIVE_FAILED,
- archive_write_set_filter_option(a, NULL, "compression-level", "99"));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_filter_option(a, NULL, "compression-level", "9"));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2));
- for (i = 0; i < 999; i++) {
- sprintf(path, "file%03d", i);
- assert((ae = archive_entry_new()) != NULL);
- archive_entry_copy_pathname(ae, path);
- archive_entry_set_size(ae, datasize);
- archive_entry_set_filetype(ae, AE_IFREG);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
- assertA(datasize == (size_t)archive_write_data(a, data, datasize));
- archive_entry_free(ae);
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- /* Curiously, this test fails; the test data above compresses
- * better at default compression than at level 9. */
- /*
- failure("compression-level=9 wrote %d bytes, default wrote %d bytes",
- (int)used2, (int)used1);
- assert(used2 < used1);
- */
-
- assert((a = archive_read_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used2));
- for (i = 0; i < 999; i++) {
- sprintf(path, "file%03d", i);
- if (!assertEqualInt(0, archive_read_next_header(a, &ae)))
- break;
- assertEqualString(path, archive_entry_pathname(ae));
- assertEqualInt((int)datasize, archive_entry_size(ae));
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
- /*
- * Repeat again, with much lower compression.
- */
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_bytes_per_block(a, 10));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_filter_option(a, NULL, "compression-level", "1"));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2));
- for (i = 0; i < 999; i++) {
- sprintf(path, "file%03d", i);
- assert((ae = archive_entry_new()) != NULL);
- archive_entry_copy_pathname(ae, path);
- archive_entry_set_size(ae, datasize);
- archive_entry_set_filetype(ae, AE_IFREG);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
- failure("Writing file %s", path);
- assertEqualIntA(a, datasize,
- (size_t)archive_write_data(a, data, datasize));
- archive_entry_free(ae);
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- /* Level 0 really does result in larger data. */
- failure("Compression-level=0 wrote %d bytes; default wrote %d bytes",
- (int)used2, (int)used1);
- assert(used2 > used1);
-
- assert((a = archive_read_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used2));
- for (i = 0; i < 999; i++) {
- sprintf(path, "file%03d", i);
- if (!assertEqualInt(0, archive_read_next_header(a, &ae)))
- break;
- assertEqualString(path, archive_entry_pathname(ae));
- assertEqualInt((int)datasize, archive_entry_size(ae));
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
- /*
- * Test various premature shutdown scenarios to make sure we
- * don't crash or leak memory.
- */
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a));
- assertEqualInt(ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a));
- assertEqualInt(ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2));
- assertEqualInt(ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- /*
- * Clean up.
- */
- free(data);
- free(buff);
-}
diff --git a/libarchive/test/test_write_compress_gzip.c b/libarchive/test/test_write_compress_gzip.c
deleted file mode 100644
index c8281e7b6f23..000000000000
--- a/libarchive/test/test_write_compress_gzip.c
+++ /dev/null
@@ -1,256 +0,0 @@
-/*-
- * Copyright (c) 2007 Tim Kientzle
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer
- * in this position and unchanged.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "test.h"
-__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_compress_gzip.c 191183 2009-04-17 01:06:31Z kientzle $");
-
-/*
- * A basic exercise of gzip reading and writing.
- *
- * TODO: Add a reference file and make sure we can decompress that.
- */
-
-DEFINE_TEST(test_write_compress_gzip)
-{
- struct archive_entry *ae;
- struct archive* a;
- char *buff, *data;
- size_t buffsize, datasize;
- char path[16];
- size_t used1, used2;
- int i, r;
-
- buffsize = 2000000;
- assert(NULL != (buff = (char *)malloc(buffsize)));
-
- datasize = 10000;
- assert(NULL != (data = (char *)malloc(datasize)));
- memset(data, 0, datasize);
-
- /*
- * Write a 100 files and read them all back.
- */
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_compression_compress(a));
- r = archive_write_set_compression_gzip(a);
- if (r == ARCHIVE_FATAL) {
- skipping("gzip writing not supported on this platform");
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
- return;
- }
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_bytes_per_block(a, 10));
- assertEqualInt(ARCHIVE_COMPRESSION_GZIP, archive_compression(a));
- assertEqualString("gzip", archive_compression_name(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used1));
- assertEqualInt(ARCHIVE_COMPRESSION_GZIP, archive_compression(a));
- assertEqualString("gzip", archive_compression_name(a));
- assert((ae = archive_entry_new()) != NULL);
- archive_entry_set_filetype(ae, AE_IFREG);
- archive_entry_set_size(ae, datasize);
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- archive_entry_copy_pathname(ae, path);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
- assertA(datasize
- == (size_t)archive_write_data(a, data, datasize));
- }
- archive_entry_free(ae);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- assert((a = archive_read_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
- r = archive_read_support_filter_gzip(a);
- if (r == ARCHIVE_WARN) {
- skipping("Can't verify gzip writing by reading back;"
- " gzip reading not fully supported on this platform");
- } else {
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_open_memory(a, buff, used1));
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- if (!assertEqualInt(ARCHIVE_OK,
- archive_read_next_header(a, &ae)))
- break;
- assertEqualString(path, archive_entry_pathname(ae));
- assertEqualInt((int)datasize, archive_entry_size(ae));
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- }
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
- /*
- * Repeat the cycle again, this time setting some compression
- * options.
- */
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_bytes_per_block(a, 10));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a));
- assertEqualIntA(a, ARCHIVE_FAILED,
- archive_write_set_options(a, "gzip:nonexistent-option=0"));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_options(a, "gzip:compression-level=0"));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_filter_option(a, NULL, "compression-level", "9"));
- assertEqualIntA(a, ARCHIVE_FAILED,
- archive_write_set_filter_option(a, NULL, "compression-level", "abc"));
- assertEqualIntA(a, ARCHIVE_FAILED,
- archive_write_set_filter_option(a, NULL, "compression-level", "99"));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_options(a, "gzip:compression-level=9"));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2));
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- assert((ae = archive_entry_new()) != NULL);
- archive_entry_copy_pathname(ae, path);
- archive_entry_set_size(ae, datasize);
- archive_entry_set_filetype(ae, AE_IFREG);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
- assertA(datasize == (size_t)archive_write_data(a, data, datasize));
- archive_entry_free(ae);
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- /* Curiously, this test fails; the test data above compresses
- * better at default compression than at level 9. */
- /*
- failure("compression-level=9 wrote %d bytes, default wrote %d bytes",
- (int)used2, (int)used1);
- assert(used2 < used1);
- */
-
- assert((a = archive_read_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
- r = archive_read_support_filter_gzip(a);
- if (r == ARCHIVE_WARN) {
- skipping("gzip reading not fully supported on this platform");
- } else {
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_support_filter_all(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_open_memory(a, buff, used2));
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- if (!assertEqualInt(ARCHIVE_OK,
- archive_read_next_header(a, &ae)))
- break;
- assertEqualString(path, archive_entry_pathname(ae));
- assertEqualInt((int)datasize, archive_entry_size(ae));
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- }
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
- /*
- * Repeat again, with much lower compression.
- */
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_bytes_per_block(a, 10));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_filter_option(a, NULL, "compression-level", "0"));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2));
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- assert((ae = archive_entry_new()) != NULL);
- archive_entry_copy_pathname(ae, path);
- archive_entry_set_size(ae, datasize);
- archive_entry_set_filetype(ae, AE_IFREG);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
- failure("Writing file %s", path);
- assertEqualIntA(a, datasize,
- (size_t)archive_write_data(a, data, datasize));
- archive_entry_free(ae);
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- /* Level 0 really does result in larger data. */
- failure("Compression-level=0 wrote %d bytes; default wrote %d bytes",
- (int)used2, (int)used1);
- assert(used2 > used1);
-
- assert((a = archive_read_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
- r = archive_read_support_filter_gzip(a);
- if (r == ARCHIVE_WARN) {
- skipping("gzip reading not fully supported on this platform");
- } else {
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_open_memory(a, buff, used2));
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- if (!assertEqualInt(ARCHIVE_OK,
- archive_read_next_header(a, &ae)))
- break;
- assertEqualString(path, archive_entry_pathname(ae));
- assertEqualInt((int)datasize, archive_entry_size(ae));
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- }
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
- /*
- * Test various premature shutdown scenarios to make sure we
- * don't crash or leak memory.
- */
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a));
- assertEqualInt(ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a));
- assertEqualInt(ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2));
- assertEqualInt(ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- /*
- * Clean up.
- */
- free(data);
- free(buff);
-}
diff --git a/libarchive/test/test_write_compress_lzip.c b/libarchive/test/test_write_compress_lzip.c
deleted file mode 100644
index 7dd8bcf24a25..000000000000
--- a/libarchive/test/test_write_compress_lzip.c
+++ /dev/null
@@ -1,247 +0,0 @@
-/*-
- * Copyright (c) 2010 Michihiro NAKAJIMA
- * Copyright (c) 2007-2009 Tim Kientzle
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer
- * in this position and unchanged.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "test.h"
-__FBSDID("$FreeBSD$");
-
-/*
- * A basic exercise of lzip reading and writing.
- *
- */
-
-DEFINE_TEST(test_write_compress_lzip)
-{
- struct archive_entry *ae;
- struct archive* a;
- char *buff, *data;
- size_t buffsize, datasize;
- char path[16];
- size_t used1, used2;
- int i, r;
-
- buffsize = 2000000;
- assert(NULL != (buff = (char *)malloc(buffsize)));
-
- datasize = 10000;
- assert(NULL != (data = (char *)malloc(datasize)));
- memset(data, 0, datasize);
-
- /*
- * Write a 100 files and read them all back.
- */
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- r = archive_write_set_compression_lzip(a);
- if (r == ARCHIVE_FATAL) {
- skipping("lzip writing not supported on this platform");
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
- return;
- }
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_bytes_per_block(a, 10));
- assertEqualInt(ARCHIVE_COMPRESSION_LZIP, archive_compression(a));
- assertEqualString("lzip", archive_compression_name(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_open_memory(a, buff, buffsize, &used1));
- assertEqualInt(ARCHIVE_COMPRESSION_LZIP, archive_compression(a));
- assertEqualString("lzip", archive_compression_name(a));
- assert((ae = archive_entry_new()) != NULL);
- archive_entry_set_filetype(ae, AE_IFREG);
- archive_entry_set_size(ae, datasize);
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- archive_entry_copy_pathname(ae, path);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
- assertA(datasize
- == (size_t)archive_write_data(a, data, datasize));
- }
- archive_entry_free(ae);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- assert((a = archive_read_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
- r = archive_read_support_filter_lzip(a);
- if (r == ARCHIVE_WARN) {
- skipping("Can't verify lzip writing by reading back;"
- " lzip reading not fully supported on this platform");
- } else {
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_support_filter_all(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_open_memory(a, buff, used1));
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- if (!assertEqualInt(ARCHIVE_OK,
- archive_read_next_header(a, &ae)))
- break;
- assertEqualString(path, archive_entry_pathname(ae));
- assertEqualInt((int)datasize, archive_entry_size(ae));
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- }
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
- /*
- * Repeat the cycle again, this time setting some compression
- * options.
- */
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_bytes_per_block(a, 10));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzip(a));
- assertEqualIntA(a, ARCHIVE_FAILED,
- archive_write_set_filter_option(a, NULL, "nonexistent-option", "0"));
- assertEqualIntA(a, ARCHIVE_FAILED,
- archive_write_set_filter_option(a, NULL, "compression-level", "abc"));
- assertEqualIntA(a, ARCHIVE_FAILED,
- archive_write_set_filter_option(a, NULL, "compression-level", "99"));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_filter_option(a, NULL, "compression-level", "9"));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2));
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- assert((ae = archive_entry_new()) != NULL);
- archive_entry_copy_pathname(ae, path);
- archive_entry_set_size(ae, datasize);
- archive_entry_set_filetype(ae, AE_IFREG);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
- assertA(datasize == (size_t)archive_write_data(a, data, datasize));
- archive_entry_free(ae);
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
-
- assert((a = archive_read_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
- r = archive_read_support_filter_lzip(a);
- if (r == ARCHIVE_WARN) {
- skipping("lzip reading not fully supported on this platform");
- } else {
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_support_filter_all(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_open_memory(a, buff, used2));
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- failure("Trying to read %s", path);
- if (!assertEqualIntA(a, ARCHIVE_OK,
- archive_read_next_header(a, &ae)))
- break;
- assertEqualString(path, archive_entry_pathname(ae));
- assertEqualInt((int)datasize, archive_entry_size(ae));
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- }
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
- /*
- * Repeat again, with much lower compression.
- */
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_bytes_per_block(a, 10));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzip(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_filter_option(a, NULL, "compression-level", "0"));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2));
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- assert((ae = archive_entry_new()) != NULL);
- archive_entry_copy_pathname(ae, path);
- archive_entry_set_size(ae, datasize);
- archive_entry_set_filetype(ae, AE_IFREG);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
- failure("Writing file %s", path);
- assertEqualIntA(a, datasize,
- (size_t)archive_write_data(a, data, datasize));
- archive_entry_free(ae);
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- /* Level 0 really does result in larger data. */
- failure("Compression-level=0 wrote %d bytes; default wrote %d bytes",
- (int)used2, (int)used1);
- assert(used2 > used1);
-
- assert((a = archive_read_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
- r = archive_read_support_filter_lzip(a);
- if (r == ARCHIVE_WARN) {
- skipping("lzip reading not fully supported on this platform");
- } else {
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_open_memory(a, buff, used2));
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- if (!assertEqualInt(ARCHIVE_OK,
- archive_read_next_header(a, &ae)))
- break;
- assertEqualString(path, archive_entry_pathname(ae));
- assertEqualInt((int)datasize, archive_entry_size(ae));
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- }
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
- /*
- * Test various premature shutdown scenarios to make sure we
- * don't crash or leak memory.
- */
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzip(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzip(a));
- assertEqualInt(ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzip(a));
- assertEqualInt(ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzip(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2));
- assertEqualInt(ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- /*
- * Clean up.
- */
- free(data);
- free(buff);
-}
diff --git a/libarchive/test/test_write_compress_lzma.c b/libarchive/test/test_write_compress_lzma.c
deleted file mode 100644
index f3b9de369f2b..000000000000
--- a/libarchive/test/test_write_compress_lzma.c
+++ /dev/null
@@ -1,251 +0,0 @@
-/*-
- * Copyright (c) 2007-2009 Tim Kientzle
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer
- * in this position and unchanged.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "test.h"
-__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_compress_lzma.c 191183 2009-04-17 01:06:31Z kientzle $");
-
-/*
- * A basic exercise of lzma reading and writing.
- *
- */
-
-DEFINE_TEST(test_write_compress_lzma)
-{
- struct archive_entry *ae;
- struct archive* a;
- char *buff, *data;
- size_t buffsize, datasize;
- char path[16];
- size_t used1, used2;
- int i, r;
-
- buffsize = 2000000;
- assert(NULL != (buff = (char *)malloc(buffsize)));
-
- datasize = 10000;
- assert(NULL != (data = (char *)malloc(datasize)));
- memset(data, 0, datasize);
-
- /*
- * Write a 100 files and read them all back.
- */
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- r = archive_write_set_compression_lzma(a);
- if (r == ARCHIVE_FATAL) {
- skipping("lzma writing not supported on this platform");
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
- return;
- }
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_bytes_per_block(a, 10));
- assertEqualInt(ARCHIVE_COMPRESSION_LZMA, archive_compression(a));
- assertEqualString("lzma", archive_compression_name(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_open_memory(a, buff, buffsize, &used1));
- assertEqualInt(ARCHIVE_COMPRESSION_LZMA, archive_compression(a));
- assertEqualString("lzma", archive_compression_name(a));
- assert((ae = archive_entry_new()) != NULL);
- archive_entry_set_filetype(ae, AE_IFREG);
- archive_entry_set_size(ae, datasize);
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- archive_entry_copy_pathname(ae, path);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
- assertA(datasize
- == (size_t)archive_write_data(a, data, datasize));
- }
- archive_entry_free(ae);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- assert((a = archive_read_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
- r = archive_read_support_filter_lzma(a);
- if (r == ARCHIVE_WARN) {
- skipping("Can't verify lzma writing by reading back;"
- " lzma reading not fully supported on this platform");
- } else {
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_support_filter_all(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_open_memory(a, buff, used1));
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- if (!assertEqualInt(ARCHIVE_OK,
- archive_read_next_header(a, &ae)))
- break;
- assertEqualString(path, archive_entry_pathname(ae));
- assertEqualInt((int)datasize, archive_entry_size(ae));
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- }
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
- /*
- * Repeat the cycle again, this time setting some compression
- * options.
- */
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_bytes_per_block(a, 10));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a));
- assertEqualIntA(a, ARCHIVE_FAILED,
- archive_write_set_filter_option(a, NULL, "nonexistent-option", "0"));
- assertEqualIntA(a, ARCHIVE_FAILED,
- archive_write_set_filter_option(a, NULL, "compression-level", "abc"));
- assertEqualIntA(a, ARCHIVE_FAILED,
- archive_write_set_filter_option(a, NULL, "compression-level", "99"));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_filter_option(a, NULL, "compression-level", "9"));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2));
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- assert((ae = archive_entry_new()) != NULL);
- archive_entry_copy_pathname(ae, path);
- archive_entry_set_size(ae, datasize);
- archive_entry_set_filetype(ae, AE_IFREG);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
- assertA(datasize == (size_t)archive_write_data(a, data, datasize));
- archive_entry_free(ae);
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
-
- assert((a = archive_read_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
- r = archive_read_support_filter_lzma(a);
- if (r == ARCHIVE_WARN) {
- skipping("lzma reading not fully supported on this platform");
- } else {
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_support_filter_all(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_open_memory(a, buff, used2));
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- failure("Trying to read %s", path);
- if (!assertEqualIntA(a, ARCHIVE_OK,
- archive_read_next_header(a, &ae)))
- break;
- assertEqualString(path, archive_entry_pathname(ae));
- assertEqualInt((int)datasize, archive_entry_size(ae));
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- }
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
- /*
- * Repeat again, with much lower compression.
- */
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_bytes_per_block(a, 10));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_filter_option(a, NULL, "compression-level", "0"));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2));
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- assert((ae = archive_entry_new()) != NULL);
- archive_entry_copy_pathname(ae, path);
- archive_entry_set_size(ae, datasize);
- archive_entry_set_filetype(ae, AE_IFREG);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
- failure("Writing file %s", path);
- assertEqualIntA(a, datasize,
- (size_t)archive_write_data(a, data, datasize));
- archive_entry_free(ae);
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- /* It would be nice to assert that compression-level=0 produced
- * consistently larger/smaller results than the default compression,
- * but the results here vary a lot depending on the version of liblzma
- * being used. */
- /*
- failure("Compression-level=0 wrote %d bytes; default wrote %d bytes",
- (int)used2, (int)used1);
- assert(used2 > used1);
- */
-
- assert((a = archive_read_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
- r = archive_read_support_filter_lzma(a);
- if (r == ARCHIVE_WARN) {
- skipping("lzma reading not fully supported on this platform");
- } else {
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_open_memory(a, buff, used2));
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- if (!assertEqualInt(ARCHIVE_OK,
- archive_read_next_header(a, &ae)))
- break;
- assertEqualString(path, archive_entry_pathname(ae));
- assertEqualInt((int)datasize, archive_entry_size(ae));
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- }
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
- /*
- * Test various premature shutdown scenarios to make sure we
- * don't crash or leak memory.
- */
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a));
- assertEqualInt(ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a));
- assertEqualInt(ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2));
- assertEqualInt(ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- /*
- * Clean up.
- */
- free(data);
- free(buff);
-}
diff --git a/libarchive/test/test_write_compress_program.c b/libarchive/test/test_write_compress_program.c
deleted file mode 100644
index 4956e1a6fb6a..000000000000
--- a/libarchive/test/test_write_compress_program.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/*-
- * Copyright (c) 2003-2007 Tim Kientzle
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "test.h"
-__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_compress_program.c 201247 2009-12-30 05:59:21Z kientzle $");
-
-char buff[1000000];
-char buff2[64];
-
-DEFINE_TEST(test_write_compress_program)
-{
- struct archive_entry *ae;
- struct archive *a;
- size_t used;
- int blocksize = 1024;
- int r;
-
- if (!canGzip()) {
- skipping("Cannot run 'gzip'");
- return;
- }
- /* NOTE: Setting blocksize=1024 will cause gunzip failure because
- * it add extra bytes that gunzip ignores with its warning and
- * exit code 1. So we should set blocksize=1 in order not to
- * yield the extra bytes when using gunzip. */
- assert((a = archive_read_new()) != NULL);
- r = archive_read_support_filter_gzip(a);
- if (r != ARCHIVE_OK && canGunzip())
- blocksize = 1;
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
- /* Create a new archive in memory. */
- /* Write it through an external "gzip" program. */
- assert((a = archive_write_new()) != NULL);
- assertA(0 == archive_write_set_format_ustar(a));
- r = archive_write_set_compression_program(a, "gzip");
- if (r == ARCHIVE_FATAL) {
- skipping("Write compression via external "
- "program unsupported on this platform");
- archive_write_free(a);
- return;
- }
- assertA(0 == archive_write_set_bytes_per_block(a, blocksize));
- assertA(0 == archive_write_set_bytes_in_last_block(a, blocksize));
- assertA(blocksize == archive_write_get_bytes_in_last_block(a));
- assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used));
- assertA(blocksize == archive_write_get_bytes_in_last_block(a));
-
- /*
- * Write a file to it.
- */
- assert((ae = archive_entry_new()) != NULL);
- archive_entry_set_mtime(ae, 1, 10);
- archive_entry_copy_pathname(ae, "file");
- archive_entry_set_mode(ae, S_IFREG | 0755);
- archive_entry_set_size(ae, 8);
-
- assertA(0 == archive_write_header(a, ae));
- archive_entry_free(ae);
- assertA(8 == archive_write_data(a, "12345678", 9));
-
- /* Close out the archive. */
- assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- /*
- * Now, read the data back through the built-in gzip support.
- */
- assert((a = archive_read_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
- r = archive_read_support_filter_gzip(a);
- /* The compression_gzip() handler will fall back to gunzip
- * automatically, but if we know gunzip isn't available, then
- * skip the rest. */
- if (r != ARCHIVE_OK && !canGunzip()) {
- skipping("No libz and no gunzip program, "
- "unable to verify gzip compression");
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
- return;
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used));
-
- if (!assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae))) {
- archive_read_free(a);
- return;
- }
-
- assertEqualInt(1, archive_entry_mtime(ae));
- assertEqualInt(0, archive_entry_atime(ae));
- assertEqualInt(0, archive_entry_ctime(ae));
- assertEqualString("file", archive_entry_pathname(ae));
- assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae));
- assertEqualInt(8, archive_entry_size(ae));
- assertEqualIntA(a, 8, archive_read_data(a, buff2, 10));
- assertEqualMem(buff2, "12345678", 8);
-
- /* Verify the end of the archive. */
- assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-}
diff --git a/libarchive/test/test_write_compress_xz.c b/libarchive/test/test_write_compress_xz.c
deleted file mode 100644
index 281dbcf55752..000000000000
--- a/libarchive/test/test_write_compress_xz.c
+++ /dev/null
@@ -1,257 +0,0 @@
-/*-
- * Copyright (c) 2007 Tim Kientzle
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer
- * in this position and unchanged.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "test.h"
-__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_compress_xz.c 191183 2009-04-17 01:06:31Z kientzle $");
-
-/*
- * A basic exercise of xz reading and writing.
- *
- * TODO: Add a reference file and make sure we can decompress that.
- */
-
-DEFINE_TEST(test_write_compress_xz)
-{
- struct archive_entry *ae;
- struct archive* a;
- char *buff, *data;
- size_t buffsize, datasize;
- char path[16];
- size_t used1, used2;
- int i, r;
-
- buffsize = 2000000;
- assert(NULL != (buff = (char *)malloc(buffsize)));
-
- datasize = 10000;
- assert(NULL != (data = (char *)malloc(datasize)));
- memset(data, 0, datasize);
-
- /*
- * Write a 100 files and read them all back.
- */
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- r = archive_write_set_compression_xz(a);
- if (r == ARCHIVE_FATAL) {
- skipping("xz writing not supported on this platform");
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
- return;
- }
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_bytes_per_block(a, 10));
- assertEqualInt(ARCHIVE_COMPRESSION_XZ, archive_compression(a));
- assertEqualString("xz", archive_compression_name(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used1));
- assertEqualInt(ARCHIVE_COMPRESSION_XZ, archive_compression(a));
- assertEqualString("xz", archive_compression_name(a));
- assert((ae = archive_entry_new()) != NULL);
- archive_entry_set_filetype(ae, AE_IFREG);
- archive_entry_set_size(ae, datasize);
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- archive_entry_copy_pathname(ae, path);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
- assertA(datasize
- == (size_t)archive_write_data(a, data, datasize));
- }
- archive_entry_free(ae);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- assert((a = archive_read_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
- r = archive_read_support_filter_xz(a);
- if (r == ARCHIVE_WARN) {
- skipping("Can't verify xz writing by reading back;"
- " xz reading not fully supported on this platform");
- } else {
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_support_filter_all(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_open_memory(a, buff, used1));
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- if (!assertEqualInt(ARCHIVE_OK,
- archive_read_next_header(a, &ae)))
- break;
- assertEqualString(path, archive_entry_pathname(ae));
- assertEqualInt((int)datasize, archive_entry_size(ae));
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- }
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
- /*
- * Repeat the cycle again, this time setting some compression
- * options.
- */
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_bytes_per_block(a, 10));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a));
- assertEqualIntA(a, ARCHIVE_FAILED,
- archive_write_set_filter_option(a, NULL, "nonexistent-option", "0"));
- assertEqualIntA(a, ARCHIVE_FAILED,
- archive_write_set_filter_option(a, NULL, "compression-level", "abc"));
- assertEqualIntA(a, ARCHIVE_FAILED,
- archive_write_set_filter_option(a, NULL, "compression-level", "99"));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_filter_option(a, NULL, "compression-level", "9"));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2));
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- assert((ae = archive_entry_new()) != NULL);
- archive_entry_copy_pathname(ae, path);
- archive_entry_set_size(ae, datasize);
- archive_entry_set_filetype(ae, AE_IFREG);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
- assertA(datasize == (size_t)archive_write_data(a, data, datasize));
- archive_entry_free(ae);
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- /* Curiously, this test fails; the test data above compresses
- * better at default compression than at level 9. */
- /*
- failure("compression-level=9 wrote %d bytes, default wrote %d bytes",
- (int)used2, (int)used1);
- assert(used2 < used1);
- */
-
- assert((a = archive_read_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
- r = archive_read_support_filter_xz(a);
- if (r == ARCHIVE_WARN) {
- skipping("xz reading not fully supported on this platform");
- } else {
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_support_filter_all(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_open_memory(a, buff, used2));
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- failure("Trying to read %s", path);
- if (!assertEqualIntA(a, ARCHIVE_OK,
- archive_read_next_header(a, &ae)))
- break;
- assertEqualString(path, archive_entry_pathname(ae));
- assertEqualInt((int)datasize, archive_entry_size(ae));
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- }
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
- /*
- * Repeat again, with much lower compression.
- */
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_bytes_per_block(a, 10));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_write_set_filter_option(a, NULL, "compression-level", "0"));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2));
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- assert((ae = archive_entry_new()) != NULL);
- archive_entry_copy_pathname(ae, path);
- archive_entry_set_size(ae, datasize);
- archive_entry_set_filetype(ae, AE_IFREG);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
- failure("Writing file %s", path);
- assertEqualIntA(a, datasize,
- (size_t)archive_write_data(a, data, datasize));
- archive_entry_free(ae);
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- /* I would like to assert that compression-level=0 results in
- * larger data than the default compression, but that's not true
- * for all versions of liblzma. */
- /*
- failure("Compression-level=0 wrote %d bytes; default wrote %d bytes",
- (int)used2, (int)used1);
- assert(used2 > used1);
- */
-
- assert((a = archive_read_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
- r = archive_read_support_filter_xz(a);
- if (r == ARCHIVE_WARN) {
- skipping("xz reading not fully supported on this platform");
- } else {
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_open_memory(a, buff, used2));
- for (i = 0; i < 100; i++) {
- sprintf(path, "file%03d", i);
- if (!assertEqualInt(ARCHIVE_OK,
- archive_read_next_header(a, &ae)))
- break;
- assertEqualString(path, archive_entry_pathname(ae));
- assertEqualInt((int)datasize, archive_entry_size(ae));
- }
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- }
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
- /*
- * Test various premature shutdown scenarios to make sure we
- * don't crash or leak memory.
- */
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a));
- assertEqualInt(ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a));
- assertEqualInt(ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- assert((a = archive_write_new()) != NULL);
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a));
- assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2));
- assertEqualInt(ARCHIVE_OK, archive_write_close(a));
- assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
- /*
- * Clean up.
- */
- free(data);
- free(buff);
-}