#include "test.h"
__FBSDID("$FreeBSD: head/lib/libarchive/test/test_compat_zip.c 196962 2009-09-08 05:02:41Z kientzle $");
+#ifdef HAVE_LIBZ
+static const int libz_enabled = 1;
+#else
+static const int libz_enabled = 0;
+#endif
+
/* Copy this function for each test file and adjust it accordingly. */
static void
test_compat_zip_1(void)
/* Read second entry. */
r = archive_read_next_header(a, &ae);
- if (r != ARCHIVE_OK) {
- if (strcmp(archive_error_string(a),
- "libarchive compiled without deflate support (no libz)") == 0) {
- skipping("Skipping ZIP compression check: %s",
- archive_error_string(a));
- goto finish;
- }
+ if (r == ARCHIVE_FATAL && !libz_enabled) {
+ skipping("Skipping ZIP compression check: %s",
+ archive_error_string(a));
+ goto finish;
}
assertEqualIntA(a, ARCHIVE_OK, r);
assertEqualString("tmp.class", archive_entry_pathname(ae));
assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_NONE);
assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ZIP);
- assertEqualInt(ARCHIVE_OK, archive_read_close(a));
finish:
+ assertEqualInt(ARCHIVE_OK, archive_read_close(a));
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
}
const char *refname = "test_compat_zip_3.zip";
struct archive_entry *ae;
struct archive *a;
- char *p;
- size_t s;
extract_reference_file(refname);
assert((a = archive_read_new()) != NULL);
/* Extract under a different name. */
archive_entry_set_pathname(ae, "test_3.txt");
- assertEqualIntA(a, ARCHIVE_OK, archive_read_extract(a, ae, 0));
- /* Verify the first 12 bytes actually got written to disk correctly. */
- p = slurpfile(&s, "test_3.txt");
- assertEqualInt(s, 1030);
- assertEqualMem(p, "<?xml versio", 12);
- free(p);
+ if(libz_enabled) {
+ char *p;
+ size_t s;
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_extract(a, ae, 0));
+ /* Verify the first 12 bytes actually got written to disk correctly. */
+ p = slurpfile(&s, "test_3.txt");
+ assertEqualInt(s, 1030);
+ assertEqualMem(p, "<?xml versio", 12);
+ free(p);
+ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
+ } else {
+ skipping("Skipping ZIP compression check, no libz support");
+ assertEqualIntA(a, ARCHIVE_FATAL, archive_read_next_header(a, &ae));
+ }
- assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
}
#include "test.h"
__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_zip.c 189482 2009-03-07 03:30:35Z kientzle $");
+#ifdef HAVE_LIBZ
+static const int libz_enabled = 1;
+#else
+static const int libz_enabled = 0;
+#endif
+
/*
* The reference file for this has been manually tweaked so that:
* * file2 has length-at-end but file1 does not
const void *pv;
size_t s;
int64_t o;
- int r;
extract_reference_file(refname);
assert((a = archive_read_new()) != NULL);
assertEqualInt(1179604289, archive_entry_mtime(ae));
assertEqualInt(18, archive_entry_size(ae));
failure("archive_read_data() returns number of bytes read");
- r = archive_read_data(a, buff, 19);
- if (r < ARCHIVE_OK) {
- if (strcmp(archive_error_string(a),
- "libarchive compiled without deflate support (no libz)") == 0) {
- skipping("Skipping ZIP compression check: %s",
- archive_error_string(a));
- goto finish;
- }
+ if (libz_enabled) {
+ assertEqualInt(18, archive_read_data(a, buff, 19));
+ assertEqualMem(buff, "hello\nhello\nhello\n", 18);
+ } else {
+ assertEqualInt(ARCHIVE_FATAL, archive_read_data(a, buff, 19));
+ assertEqualString(archive_error_string(a),
+ "libarchive compiled without deflate support (no libz)");
+ assert(archive_errno(a) != 0);
}
- assertEqualInt(18, r);
- assertEqualMem(buff, "hello\nhello\nhello\n", 18);
assertA(0 == archive_read_next_header(a, &ae));
assertEqualString("file2", archive_entry_pathname(ae));
assertEqualInt(1179605932, archive_entry_mtime(ae));
failure("file2 has length-at-end, so we shouldn't see a valid size");
assertEqualInt(0, archive_entry_size_is_set(ae));
- failure("file2 has a bad CRC, so reading to end should fail");
- assertEqualInt(ARCHIVE_WARN, archive_read_data(a, buff, 19));
- assertEqualMem(buff, "hello\nhello\nhello\n", 18);
- /* Verify the number of files read. */
+ if (libz_enabled) {
+ failure("file2 has a bad CRC, so read should fail and not change buff");
+ memset(buff, 'a', 19);
+ assertEqualInt(ARCHIVE_WARN, archive_read_data(a, buff, 19));
+ assertEqualMem(buff, "aaaaaaaaaaaaaaaaaaa", 19);
+ } else {
+ assertEqualInt(ARCHIVE_FATAL, archive_read_data(a, buff, 19));
+ assertEqualString(archive_error_string(a),
+ "libarchive compiled without deflate support (no libz)");
+ assert(archive_errno(a) != 0);
+ }
+ /* Verify the number of files read. */
failure("the archive file has three files");
assertEqualInt(3, archive_file_count(a));
assertA(archive_compression(a) == ARCHIVE_COMPRESSION_NONE);
assertA(archive_format(a) == ARCHIVE_FORMAT_ZIP);
assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
-finish:
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
}
/*
* Read Info-ZIP New Unix Extra Field 0x7875 "ux".
- * Currently sotres Unix UID/GID up to 32 bits.
+ * Currently stores Unix UID/GID up to 32 bits.
*/
static void
test_info_zip_ux(void)
struct archive_entry *ae;
struct archive *a;
char *buff[128];
- int r;
extract_reference_file(refname);
assert((a = archive_read_new()) != NULL);
assertEqualInt(1001, archive_entry_uid(ae));
assertEqualInt(1001, archive_entry_gid(ae));
failure("archive_read_data() returns number of bytes read");
- r = archive_read_data(a, buff, 19);
- if (r < ARCHIVE_OK) {
- if (strcmp(archive_error_string(a),
- "libarchive compiled without deflate support (no libz)") == 0) {
- skipping("Skipping ZIP compression check: %s",
- archive_error_string(a));
- goto finish;
- }
+ if (libz_enabled) {
+ assertEqualInt(18, archive_read_data(a, buff, 19));
+ assertEqualMem(buff, "hello\nhello\nhello\n", 18);
+ } else {
+ assertEqualInt(ARCHIVE_FATAL, archive_read_data(a, buff, 19));
+ assertEqualString(archive_error_string(a),
+ "libarchive compiled without deflate support (no libz)");
+ assert(archive_errno(a) != 0);
}
- assertEqualInt(18, r);
- assertEqualMem(buff, "hello\nhello\nhello\n", 18);
assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
- /* Verify the number of files read. */
+ /* Verify the number of files read. */
failure("the archive file has just one file");
assertEqualInt(1, archive_file_count(a));
assertA(archive_compression(a) == ARCHIVE_COMPRESSION_NONE);
assertA(archive_format(a) == ARCHIVE_FORMAT_ZIP);
assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
-finish:
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
}
assert(!archive_entry_size_is_set(ae));
assertEqualInt(0, archive_entry_size(ae));
- assertEqualIntA(a, ARCHIVE_OK, archive_read_extract(a, ae, 0));
-
- assertFileContents("hello\x0A", 6, "hello.txt");
+ if (libz_enabled) {
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_extract(a, ae, 0));
+ assertFileContents("hello\x0A", 6, "hello.txt");
+ } else {
+ assertEqualIntA(a, ARCHIVE_FATAL, archive_read_extract(a, ae, 0));
+ assertEqualString(archive_error_string(a),
+ "libarchive compiled without deflate support (no libz)");
+ assert(archive_errno(a) != 0);
+ }
assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));