From: Michihiro NAKAJIMA Date: Thu, 19 Feb 2009 08:42:27 +0000 (-0500) Subject: Simplify cheking that a compression is not supported. X-Git-Tag: v2.7.0~241 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0fb3c72a2f09e214cf6aa2034349cdc8d4144fbb;p=thirdparty%2Flibarchive.git Simplify cheking that a compression is not supported. SVN-Revision: 676 --- diff --git a/libarchive/test/test.h b/libarchive/test/test.h index 9647e9811..2e8e7b630 100644 --- a/libarchive/test/test.h +++ b/libarchive/test/test.h @@ -187,3 +187,14 @@ int read_open_memory(struct archive *, void *, size_t, size_t); test_assert_equal_int(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (a)) #define assertEqualStringA(a,v1,v2) \ test_assert_equal_string(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (a)) + +/* + * A compression is not supported + * Use this define after archive_read_next_header() is called + */ +#define UnsupportedCompress(r, a) \ + (r != ARCHIVE_OK && \ + (strcmp(archive_error_string(a), \ + "Unrecognized archive format") == 0 && \ + archive_compression(a) == ARCHIVE_COMPRESSION_NONE)) + diff --git a/libarchive/test/test_compat_bzip2.c b/libarchive/test/test_compat_bzip2.c index 81d2ab263..4b2cf0513 100644 --- a/libarchive/test/test_compat_bzip2.c +++ b/libarchive/test/test_compat_bzip2.c @@ -55,14 +55,11 @@ compat_bzip2(const char *name) /* Read entries, match up names with list above. */ for (i = 0; i < 6; ++i) { r = archive_read_next_header(a, &ae); - if (r != ARCHIVE_OK) { - if (strcmp(archive_error_string(a), - "Unrecognized archive format") == 0) { - skipping("Skipping BZIP2 compression check: " - "This version of libarchive was compiled " - "without bzip2 support"); - goto finish; - } + if (UnsupportedCompress(r, a)) { + skipping("Skipping BZIP2 compression check: " + "This version of libarchive was compiled " + "without bzip2 support"); + goto finish; } failure("Could not read file %d (%s) from %s", i, n[i], name); assertEqualIntA(a, ARCHIVE_OK, r); diff --git a/libarchive/test/test_compat_gzip.c b/libarchive/test/test_compat_gzip.c index a967979c1..25cdc2bbe 100644 --- a/libarchive/test/test_compat_gzip.c +++ b/libarchive/test/test_compat_gzip.c @@ -55,14 +55,11 @@ verify(const char *name) /* Read entries, match up names with list above. */ for (i = 0; i < 6; ++i) { r = archive_read_next_header(a, &ae); - if (r != ARCHIVE_OK) { - if (strcmp(archive_error_string(a), - "Unrecognized archive format") == 0) { - skipping("Skipping GZIP compression check: " - "This version of libarchive was compiled " - "without gzip support"); - goto finish; - } + if (UnsupportedCompress(r, a)) { + skipping("Skipping GZIP compression check: " + "This version of libarchive was compiled " + "without gzip support"); + goto finish; } failure("Could not read file %d (%s) from %s", i, n[i], name); assertEqualIntA(a, ARCHIVE_OK, r); diff --git a/libarchive/test/test_compat_xz.c b/libarchive/test/test_compat_xz.c index b8b42ecf6..d84326f7b 100644 --- a/libarchive/test/test_compat_xz.c +++ b/libarchive/test/test_compat_xz.c @@ -54,14 +54,11 @@ compat_xz(const char *name) /* Read entries, match up names with list above. */ for (i = 0; i < 6; ++i) { r = archive_read_next_header(a, &ae); - if (r != ARCHIVE_OK) { - if (strcmp(archive_error_string(a), - "Unrecognized archive format") == 0) { - skipping("Skipping XZ compression check: " - "This version of libarchive was compiled " - "without xz support"); - goto finish; - } + if (UnsupportedCompress(r, a)) { + skipping("Skipping XZ compression check: " + "This version of libarchive was compiled " + "without xz support"); + goto finish; } failure("Could not read file %d (%s) from %s", i, n[i], name); assertEqualIntA(a, ARCHIVE_OK, r); diff --git a/libarchive/test/test_fuzz.c b/libarchive/test/test_fuzz.c index a560a3044..6c7b205fb 100644 --- a/libarchive/test/test_fuzz.c +++ b/libarchive/test/test_fuzz.c @@ -84,29 +84,26 @@ DEFINE_TEST(test_fuzz) assert(0 == archive_read_support_format_all(a)); assert(0 == archive_read_open_memory(a, rawimage, size)); r = archive_read_next_header(a, &ae); - if (r != ARCHIVE_OK) { - if (strcmp(archive_error_string(a), - "Unrecognized archive format") == 0) { - skipping("Skipping GZIP/BZIP2 compression check: " - "This version of libarchive was compiled " - "without gzip/bzip2 support"); - assert(0 == archive_read_close(a)); - assert(0 == archive_read_finish(a)); - continue; - } - } else { + if (UnsupportedCompress(r, a)) { + skipping("Skipping GZIP/BZIP2 compression check: " + "This version of libarchive was compiled " + "without gzip/bzip2 support"); + assert(0 == archive_read_close(a)); + assert(0 == archive_read_finish(a)); + continue; + } + assert(0 == r); + if (r == ARCHIVE_OK) { char buff[20]; 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)); - assert(0 == archive_read_close(a)); - assert(0 == archive_read_finish(a)); - continue; - } + if (r < ARCHIVE_OK && strcmp(archive_error_string(a), + "libarchive compiled without deflate support (no libz)") == 0) { + skipping("Skipping ZIP compression check: %s", + archive_error_string(a)); + assert(0 == archive_read_close(a)); + assert(0 == archive_read_finish(a)); + continue; } } assert(0 == archive_read_close(a)); diff --git a/libarchive/test/test_read_format_cpio_bin_bz2.c b/libarchive/test/test_read_format_cpio_bin_bz2.c index 176533ff1..0efd233d7 100644 --- a/libarchive/test/test_read_format_cpio_bin_bz2.c +++ b/libarchive/test/test_read_format_cpio_bin_bz2.c @@ -45,14 +45,11 @@ DEFINE_TEST(test_read_format_cpio_bin_bz2) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, archive, sizeof(archive))); r = archive_read_next_header(a, &ae); - if (r != ARCHIVE_OK) { - if (strcmp(archive_error_string(a), - "Unrecognized archive format") == 0) { - skipping("Skipping BZ2 compression check: " - "This version of libarchive was compiled " - "without bz2 support"); - goto finish; - } + if (UnsupportedCompress(r, a)) { + skipping("Skipping BZ2 compression check: " + "This version of libarchive was compiled " + "without bz2 support"); + goto finish; } assertEqualIntA(a, ARCHIVE_OK, r); assert(archive_compression(a) == ARCHIVE_COMPRESSION_BZIP2); diff --git a/libarchive/test/test_read_format_cpio_bin_gz.c b/libarchive/test/test_read_format_cpio_bin_gz.c index c0e65bebe..58272c40c 100644 --- a/libarchive/test/test_read_format_cpio_bin_gz.c +++ b/libarchive/test/test_read_format_cpio_bin_gz.c @@ -42,15 +42,11 @@ DEFINE_TEST(test_read_format_cpio_bin_gz) assert(0 == archive_read_support_format_all(a)); assert(0 == archive_read_open_memory(a, archive, sizeof(archive))); r = archive_read_next_header(a, &ae); - if (r != ARCHIVE_OK) { - /* TODO: when cpio really broken */ - if (strcmp(archive_error_string(a), - "Unrecognized archive format") == 0) { - skipping("Skipping GZIP compression check: " - "This version of libarchive was compiled " - "without gzip support"); - goto finish; - } + if (UnsupportedCompress(r, a)) { + skipping("Skipping GZIP compression check: " + "This version of libarchive was compiled " + "without gzip support"); + goto finish; } assert(0 == r); assert(archive_compression(a) == ARCHIVE_COMPRESSION_GZIP); diff --git a/libarchive/test/test_read_format_cpio_bin_xz.c b/libarchive/test/test_read_format_cpio_bin_xz.c index bbf57cfc6..d29324c98 100644 --- a/libarchive/test/test_read_format_cpio_bin_xz.c +++ b/libarchive/test/test_read_format_cpio_bin_xz.c @@ -55,15 +55,11 @@ DEFINE_TEST(test_read_format_cpio_bin_xz) assert(0 == archive_read_support_format_all(a)); assert(0 == archive_read_open_memory(a, archive, sizeof(archive))); r = archive_read_next_header(a, &ae); - if (r != ARCHIVE_OK) { - /* TODO: when cpio really broken */ - if (strcmp(archive_error_string(a), - "Unrecognized archive format") == 0) { - skipping("Skipping XZ compression check: " - "This version of libarchive was compiled " - "without xz support"); - goto finish; - } + if (UnsupportedCompress(r, a)) { + skipping("Skipping XZ compression check: " + "This version of libarchive was compiled " + "without xz support"); + goto finish; } assert(0 == r); assert(archive_compression(a) == ARCHIVE_COMPRESSION_XZ); diff --git a/libarchive/test/test_read_format_cpio_svr4_gzip.c b/libarchive/test/test_read_format_cpio_svr4_gzip.c index 88a7b0547..8c151a53a 100644 --- a/libarchive/test/test_read_format_cpio_svr4_gzip.c +++ b/libarchive/test/test_read_format_cpio_svr4_gzip.c @@ -43,14 +43,11 @@ DEFINE_TEST(test_read_format_cpio_svr4_gzip) assert(0 == archive_read_support_format_all(a)); assert(0 == archive_read_open_memory(a, archive, sizeof(archive))); r = archive_read_next_header(a, &ae); - if (r != ARCHIVE_OK) { - if (strcmp(archive_error_string(a), - "Unrecognized archive format") == 0) { - skipping("Skipping GZIP compression check: " - "This version of libarchive was compiled " - "without gzip support"); - goto finish; - } + if (UnsupportedCompress(r, a)) { + skipping("Skipping GZIP compression check: " + "This version of libarchive was compiled " + "without gzip support"); + goto finish; } assert(0 == r); assert(archive_compression(a) == ARCHIVE_COMPRESSION_GZIP); diff --git a/libarchive/test/test_read_format_gtar_gz.c b/libarchive/test/test_read_format_gtar_gz.c index c41075789..82ddc38c8 100644 --- a/libarchive/test/test_read_format_gtar_gz.c +++ b/libarchive/test/test_read_format_gtar_gz.c @@ -43,14 +43,11 @@ DEFINE_TEST(test_read_format_gtar_gz) assert(0 == archive_read_support_format_all(a)); assert(0 == archive_read_open_memory(a, archive, sizeof(archive))); r = archive_read_next_header(a, &ae); - if (r != ARCHIVE_OK) { - if (strcmp(archive_error_string(a), - "Unrecognized archive format") == 0) { - skipping("Skipping GZIP compression check: " - "This version of libarchive was compiled " - "without gzip support"); - goto finish; - } + if (UnsupportedCompress(r, a)) { + skipping("Skipping GZIP compression check: " + "This version of libarchive was compiled " + "without gzip support"); + goto finish; } assert(0 == r); assert(archive_compression(a) == ARCHIVE_COMPRESSION_GZIP); diff --git a/libarchive/test/test_read_format_iso_gz.c b/libarchive/test/test_read_format_iso_gz.c index 5c085170b..6b3e1426b 100644 --- a/libarchive/test/test_read_format_iso_gz.c +++ b/libarchive/test/test_read_format_iso_gz.c @@ -65,14 +65,11 @@ DEFINE_TEST(test_read_format_iso_gz) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, archive, sizeof(archive))); r = archive_read_next_header(a, &ae); - if (r != ARCHIVE_OK) { - if (strcmp(archive_error_string(a), - "Unrecognized archive format") == 0) { - skipping("Skipping GZIP compression check: " - "This version of libarchive was compiled " - "without gzip support"); - goto finish; - } + if (UnsupportedCompress(r, a)) { + skipping("Skipping GZIP compression check: " + "This version of libarchive was compiled " + "without gzip support"); + goto finish; } assertEqualIntA(a, ARCHIVE_OK, r); assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_GZIP); diff --git a/libarchive/test/test_read_format_pax_bz2.c b/libarchive/test/test_read_format_pax_bz2.c index 9acc0db5f..4a7677382 100644 --- a/libarchive/test/test_read_format_pax_bz2.c +++ b/libarchive/test/test_read_format_pax_bz2.c @@ -51,14 +51,11 @@ DEFINE_TEST(test_read_format_pax_bz2) assert(0 == archive_read_support_format_all(a)); assert(0 == archive_read_open_memory(a, archive, sizeof(archive))); r = archive_read_next_header(a, &ae); - if (r != ARCHIVE_OK) { - if (strcmp(archive_error_string(a), - "Unrecognized archive format") == 0) { - skipping("Skipping BZIP2 compression check: " - "This version of libarchive was compiled " - "without bzip2 support"); - goto finish; - } + if (UnsupportedCompress(r, a)) { + skipping("Skipping BZIP2 compression check: " + "This version of libarchive was compiled " + "without bzip2 support"); + goto finish; } assert(0 == r); assert(archive_compression(a) == ARCHIVE_COMPRESSION_BZIP2); diff --git a/libarchive/test/test_read_format_tbz.c b/libarchive/test/test_read_format_tbz.c index 995df0691..ddc4b64f2 100644 --- a/libarchive/test/test_read_format_tbz.c +++ b/libarchive/test/test_read_format_tbz.c @@ -44,14 +44,11 @@ DEFINE_TEST(test_read_format_tbz) assert(0 == archive_read_support_format_all(a)); assert(0 == archive_read_open_memory(a, archive, sizeof(archive))); r = archive_read_next_header(a, &ae); - if (r != ARCHIVE_OK) { - if (strcmp(archive_error_string(a), - "Unrecognized archive format") == 0) { - skipping("Skipping BZIP2 compression check: " - "This version of libarchive was compiled " - "without bzip2 support"); - goto finish; - } + if (UnsupportedCompress(r, a)) { + skipping("Skipping BZIP2 compression check: " + "This version of libarchive was compiled " + "without bzip2 support"); + goto finish; } assert(0 == r); assert(archive_compression(a) == ARCHIVE_COMPRESSION_BZIP2); diff --git a/libarchive/test/test_read_format_tgz.c b/libarchive/test/test_read_format_tgz.c index 986ab4923..fe7a508b2 100644 --- a/libarchive/test/test_read_format_tgz.c +++ b/libarchive/test/test_read_format_tgz.c @@ -43,14 +43,11 @@ DEFINE_TEST(test_read_format_tgz) assert(0 == archive_read_support_format_all(a)); assert(0 == archive_read_open_memory(a, archive, sizeof(archive))); r = archive_read_next_header(a, &ae); - if (r != ARCHIVE_OK) { - if (strcmp(archive_error_string(a), - "Unrecognized archive format") == 0) { - skipping("Skipping GZIP compression check: " - "This version of libarchive was compiled " - "without gzip support"); - goto finish; - } + if (UnsupportedCompress(r, a)) { + skipping("Skipping GZIP compression check: " + "This version of libarchive was compiled " + "without gzip support"); + goto finish; } assert(0 == r); assert(archive_compression(a) == ARCHIVE_COMPRESSION_GZIP); diff --git a/libarchive/test/test_read_format_txz.c b/libarchive/test/test_read_format_txz.c index 82cfc8f53..2325e1d16 100644 --- a/libarchive/test/test_read_format_txz.c +++ b/libarchive/test/test_read_format_txz.c @@ -49,15 +49,11 @@ DEFINE_TEST(test_read_format_txz) assert(0 == archive_read_support_format_all(a)); assert(0 == archive_read_open_memory(a, archive, sizeof(archive))); r = archive_read_next_header(a, &ae); - if (r != ARCHIVE_OK) { - if (strcmp(archive_error_string(a), - "Unrecognized archive format") == 0) { - skipping("Skipping XZ compression check: " - "This version of libarchive was compiled " - "without xz support", - archive_error_string(a)); - goto finish; - } + if (UnsupportedCompress(r, a)) { + skipping("Skipping XZ compression check: " + "This version of libarchive was compiled " + "without xz support"); + goto finish; } assert(0 == r); assert(archive_compression(a) == ARCHIVE_COMPRESSION_XZ); diff --git a/libarchive/test/test_write_compress_program.c b/libarchive/test/test_write_compress_program.c index daf4aa720..f5eaf2a88 100644 --- a/libarchive/test/test_write_compress_program.c +++ b/libarchive/test/test_write_compress_program.c @@ -92,29 +92,26 @@ DEFINE_TEST(test_write_compress_program) assertA(0 == archive_read_open_memory(a, buff, used)); r = archive_read_next_header(a, &ae); - if (r != ARCHIVE_OK) { - if (strcmp(archive_error_string(a), - "Unrecognized archive format") == 0) { - skipping("This version of libarchive was compiled " - "without gzip support"); - assert(0 == archive_read_finish(a)); - /* - * Try using an external "gunzip","gzip -d" program - */ - if ((extprog = external_gzip_program(1)) == NULL) { - skipping("There is no gzip uncompression " - "program in this platform"); - return; - } - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_none(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_program(a, extprog)); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_open_memory(a, buff, used)); - r = archive_read_next_header(a, &ae); + if (UnsupportedCompress(r, a)) { + skipping("This version of libarchive was compiled " + "without gzip support"); + assert(0 == archive_read_finish(a)); + /* + * Try using an external "gunzip","gzip -d" program + */ + if ((extprog = external_gzip_program(1)) == NULL) { + skipping("There is no gzip uncompression " + "program in this platform"); + return; } + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_none(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_program(a, extprog)); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_open_memory(a, buff, used)); + r = archive_read_next_header(a, &ae); } assertA(0 == r);