]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
archive_read_support_compression_gzip() now returns ARCHIVE_WARN
authorTim Kientzle <kientzle@gmail.com>
Wed, 1 Apr 2009 04:52:48 +0000 (00:52 -0400)
committerTim Kientzle <kientzle@gmail.com>
Wed, 1 Apr 2009 04:52:48 +0000 (00:52 -0400)
if decompression is being handled via an external program.
This simplifies the many tests that need to check whether we have
full gzip support or not.  While reworking these tests, I've also
updated the style of many of them to use assertEqualFoo() instead
of plain assert() and fixed an oversight in main.c that caused it
to print an alarm if a single skip was processed multiple times.

SVN-Revision: 889

12 files changed:
libarchive/archive_read_support_compression_gzip.c
libarchive/test/main.c
libarchive/test/test_compat_gzip.c
libarchive/test/test_pax_filename_encoding.c
libarchive/test/test_read_compress_program.c
libarchive/test/test_read_format_cpio_bin_gz.c
libarchive/test/test_read_format_cpio_svr4_gzip.c
libarchive/test/test_read_format_gtar_gz.c
libarchive/test/test_read_format_iso_gz.c
libarchive/test/test_read_format_tgz.c
libarchive/test/test_write_compress_gzip.c
libarchive/test/test_write_compress_program.c

index 0e57581f54930132ffca2cfcdffe8add86239075..2222478935637c8a42a06221d208e6abac04dcf9 100644 (file)
@@ -92,7 +92,14 @@ archive_read_support_compression_gzip(struct archive *_a)
        bidder->init = gzip_bidder_init;
        bidder->options = NULL;
        bidder->free = NULL; /* No data, so no cleanup necessary. */
+       /* Signal the extent of gzip support with the return value here. */
+#if HAVE_ZLIB_H
        return (ARCHIVE_OK);
+#else
+       archive_set_error(_a, ARCHIVE_ERRNO_MISC,
+           "Using external gunzip program");
+       return (ARCHIVE_WARN);
+#endif
 }
 
 /*
index b6f84b09a1fa08bc604abe07e932b72a92658502..f208c1e005757e029ccb23a4a4babb59bffbb96a 100644 (file)
@@ -124,13 +124,14 @@ static const char *failed_filename = NULL;
 static struct line {
        int line;
        int count;
+       int critical;
 }  failed_lines[1000];
 
 /*
  * Count this failure; return the number of previous failures.
  */
 static int
-previous_failures(const char *filename, int line)
+previous_failures(const char *filename, int line, int critical)
 {
        unsigned int i;
        int count;
@@ -148,6 +149,7 @@ previous_failures(const char *filename, int line)
                if (failed_lines[i].line == 0) {
                        failed_lines[i].line = line;
                        failed_lines[i].count = 1;
+                       failed_lines[i].critical = critical;
                        return (0);
                }
        }
@@ -174,7 +176,7 @@ test_skipping(const char *fmt, ...)
 {
        va_list ap;
 
-       if (previous_failures(test_filename, test_line))
+       if (previous_failures(test_filename, test_line, 0))
                return;
 
        va_start(ap, fmt);
@@ -237,7 +239,7 @@ summarize(void)
        for (i = 0; i < sizeof(failed_lines)/sizeof(failed_lines[0]); i++) {
                if (failed_lines[i].line == 0)
                        break;
-               if (failed_lines[i].count > 1)
+               if (failed_lines[i].count > 1 && failed_lines[i].critical)
                        fprintf(stderr, "%s:%d: Failed %d times\n",
                            failed_filename, failed_lines[i].line,
                            failed_lines[i].count);
@@ -266,7 +268,7 @@ test_assert(const char *file, int line, int value, const char *condition, void *
                return (value);
        }
        failures ++;
-       if (!verbose && previous_failures(file, line))
+       if (!verbose && previous_failures(file, line, 1))
                return (value);
        fprintf(stderr, "%s:%d: Assertion failed\n", file, line);
        fprintf(stderr, "   Condition: %s\n", condition);
@@ -285,7 +287,7 @@ test_assert_equal_int(const char *file, int line,
                return (1);
        }
        failures ++;
-       if (!verbose && previous_failures(file, line))
+       if (!verbose && previous_failures(file, line, 1))
                return (0);
        fprintf(stderr, "%s:%d: Assertion failed: Ints not equal\n",
            file, line);
@@ -337,7 +339,7 @@ test_assert_equal_string(const char *file, int line,
                return (1);
        }
        failures ++;
-       if (!verbose && previous_failures(file, line))
+       if (!verbose && previous_failures(file, line, 1))
                return (0);
        fprintf(stderr, "%s:%d: Assertion failed: Strings not equal\n",
            file, line);
@@ -395,7 +397,7 @@ test_assert_equal_wstring(const char *file, int line,
                return (1);
        }
        failures ++;
-       if (!verbose && previous_failures(file, line))
+       if (!verbose && previous_failures(file, line, 1))
                return (0);
        fprintf(stderr, "%s:%d: Assertion failed: Unicode strings not equal\n",
            file, line);
@@ -465,7 +467,7 @@ test_assert_equal_mem(const char *file, int line,
                return (1);
        }
        failures ++;
-       if (!verbose && previous_failures(file, line))
+       if (!verbose && previous_failures(file, line, 1))
                return (0);
        fprintf(stderr, "%s:%d: Assertion failed: memory not equal\n",
            file, line);
@@ -503,7 +505,7 @@ test_assert_empty_file(const char *f1fmt, ...)
                return (1);
 
        failures ++;
-       if (!verbose && previous_failures(test_filename, test_line))
+       if (!verbose && previous_failures(test_filename, test_line, 1))
                return (0);
 
        fprintf(stderr, "%s:%d: File not empty: %s\n", test_filename, test_line, f1);
@@ -550,7 +552,7 @@ test_assert_equal_file(const char *f1, const char *f2pattern, ...)
                        break;
        }
        failures ++;
-       if (!verbose && previous_failures(test_filename, test_line))
+       if (!verbose && previous_failures(test_filename, test_line, 1))
                return (0);
        fprintf(stderr, "%s:%d: Files are not identical\n",
            test_filename, test_line);
@@ -572,7 +574,7 @@ test_assert_file_exists(const char *fpattern, ...)
 
        if (!access(f, F_OK))
                return (1);
-       if (!previous_failures(test_filename, test_line)) {
+       if (!previous_failures(test_filename, test_line, 1)) {
                fprintf(stderr, "%s:%d: File doesn't exist\n",
                    test_filename, test_line);
                fprintf(stderr, "  file=\"%s\"\n", f);
@@ -593,7 +595,7 @@ test_assert_file_not_exists(const char *fpattern, ...)
 
        if (access(f, F_OK))
                return (1);
-       if (!previous_failures(test_filename, test_line)) {
+       if (!previous_failures(test_filename, test_line, 1)) {
                fprintf(stderr, "%s:%d: File exists and shouldn't\n",
                    test_filename, test_line);
                fprintf(stderr, "  file=\"%s\"\n", f);
@@ -624,7 +626,7 @@ test_assert_file_contents(const void *buff, int s, const char *fpattern, ...)
                return (1);
        }
        failures ++;
-       if (!previous_failures(test_filename, test_line)) {
+       if (!previous_failures(test_filename, test_line, 1)) {
                fprintf(stderr, "%s:%d: File contents don't match\n",
                    test_filename, test_line);
                fprintf(stderr, "  file=\"%s\"\n", f);
@@ -886,30 +888,34 @@ extract_reference_file(const char *name)
        fclose(in);
 }
 
-#if defined(_WIN32) && !defined(__CYGWIN__)
-#define DEV_NULL "NUL"
-#else
-#define DEV_NULL "/dev/null"
-#endif
 
+/* Since gzip is by far the most popular external compression program
+ * available, we try to use it in the read_program and write_program
+ * tests.  But if it's not available, then we can't use it.  This
+ * function just tries to run gzip/gunzip to see if they're available.
+ * If not, some of the external compression program tests will be
+ * skipped. */
 const char *
 external_gzip_program(int un)
 {
-       const char *extprog;
-
-       if (un) {
-               extprog = "gunzip";
-               if (systemf("%s -V >" DEV_NULL " 2>" DEV_NULL, extprog) == 0)
-                       return (extprog);
-               extprog = "gzip -d";
-               if (systemf("%s -V >" DEV_NULL " 2>" DEV_NULL, extprog) == 0)
-                       return (extprog);
-       } else {
-               extprog = "gzip";
-               if (systemf("%s -V >" DEV_NULL " 2>" DEV_NULL, extprog) == 0)
-                       return (extprog);
+       static int tested = 0;
+       static const char *compress_prog = NULL;
+       static const char *decompress_prog = NULL;
+       /* Args vary depending on the command interpreter we're using. */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+       static const char *args = "-V >NUL 2>NUL"; /* Win32 cmd.exe */
+#else
+       static const char *args = "-V >/dev/null 2>/dev/null"; /* POSIX 'sh' */
+#endif
+
+       if (!tested) {
+               if (systemf("gunzip %s", args) == 0)
+                       decompress_prog = "gunzip";
+               if (systemf("gzip %s", args) == 0)
+                       compress_prog = "gzip";
+               tested = 1;
        }
-       return (NULL);
+       return (un ? decompress_prog : compress_prog);
 }
 
 static char *
index 25cdc2bbe8a1d76b91ebd7a74511585aa92d12ee..9ac5a59d3d39cc728848b3ff64b7dbb51a05226f 100644 (file)
@@ -47,7 +47,12 @@ verify(const char *name)
        int i,r;
 
        assert((a = archive_read_new()) != NULL);
-       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a));
+       r = archive_read_support_compression_gzip(a);
+       if (r == ARCHIVE_WARN) {
+               skipping("gzip not fully supported");
+               return;
+       }
+       assertEqualIntA(a, ARCHIVE_OK, r);
        assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
        extract_reference_file(name);
        assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 200));
index 30717750d25abc7d1c68b56ff8f7fbbb4abf998c..1b445647c354e448d10aa40a82521bce43566a55 100644 (file)
@@ -57,7 +57,7 @@ DEFINE_TEST(test_pax_filename_encoding_1)
        extract_reference_file(testname);
        a = archive_read_new();
        assertEqualInt(ARCHIVE_OK, archive_read_support_format_tar(a));
-       assertEqualInt(ARCHIVE_OK, archive_read_support_compression_gzip(a));
+       assertEqualInt(ARCHIVE_OK, archive_read_support_compression_all(a));
        assertEqualInt(ARCHIVE_OK,
            archive_read_open_filename(a, testname, 10240));
        /*
index 9f1284e9dc968e30b58f4ab460f51a671dfa8bc2..c866e8ae80d0dfad978f92c03fb3d2301169e45b 100644 (file)
@@ -61,7 +61,7 @@ DEFINE_TEST(test_read_compress_program)
        assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
 
        /*
-        * If we have "gunzip", try using that.
+        * If we have "gzip -d", try using that.
         */
        if ((extprog = external_gzip_program(1)) == NULL) {
                skipping("There is no gzip uncompression "
index 58272c40c6aa11d497501cf60f75d1292b1ab6e3..ce282bd902910c2fdadbd7ba6270ddcfb6585d7a 100644 (file)
@@ -38,26 +38,23 @@ DEFINE_TEST(test_read_format_cpio_bin_gz)
        int r;
 
        assert((a = archive_read_new()) != NULL);
-       assert(0 == archive_read_support_compression_all(a));
-       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 (UnsupportedCompress(r, a)) {
-               skipping("Skipping GZIP compression check: "
-                   "This version of libarchive was compiled "
-                   "without gzip support");
-               goto finish;
+       assertEqualInt(ARCHIVE_OK, archive_read_support_compression_all(a));
+       r = archive_read_support_compression_gzip(a);
+       if (r == ARCHIVE_WARN) {
+               skipping("gzip not fully supported");
+       } else {
+               failure("archive_read_support_compression_gzip");
+               assertEqualInt(ARCHIVE_OK, r);
+               assertEqualInt(ARCHIVE_OK, archive_read_support_format_all(a));
+               assertEqualInt(ARCHIVE_OK,
+                   archive_read_open_memory(a, archive, sizeof(archive)));
+               assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae));
+               assertEqualInt(archive_compression(a),
+                   ARCHIVE_COMPRESSION_GZIP);
+               assertEqualInt(archive_format(a), ARCHIVE_FORMAT_CPIO_BIN_LE);
+               assertEqualInt(ARCHIVE_OK, archive_read_close(a));
        }
-       assert(0 == r);
-       assert(archive_compression(a) == ARCHIVE_COMPRESSION_GZIP);
-       assert(archive_format(a) == ARCHIVE_FORMAT_CPIO_BIN_LE);
-       assert(0 == archive_read_close(a));
-finish:
-#if ARCHIVE_VERSION_NUMBER < 2000000
-       archive_read_finish(a);
-#else
-       assert(0 == archive_read_finish(a));
-#endif
+       assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
 }
 
 
index 8c151a53a4b473b7066d069b15052d9ab3e7eb38..22aab630aed64eba60960aa50d757b08844bd4ff 100644 (file)
@@ -39,26 +39,22 @@ DEFINE_TEST(test_read_format_cpio_svr4_gzip)
        int r;
 
        assert((a = archive_read_new()) != NULL);
-       assert(0 == archive_read_support_compression_all(a));
-       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 (UnsupportedCompress(r, a)) {
-               skipping("Skipping GZIP compression check: "
-                   "This version of libarchive was compiled "
-                   "without gzip support");
-               goto finish;
+       assertEqualInt(ARCHIVE_OK, archive_read_support_compression_all(a));
+       r = archive_read_support_compression_gzip(a);
+       if (r == ARCHIVE_WARN) {
+               skipping("gzip not fully supported");
+       } else {
+               assertEqualInt(ARCHIVE_OK, archive_read_support_format_all(a));
+               assertEqualInt(ARCHIVE_OK,
+                   archive_read_open_memory(a, archive, sizeof(archive)));
+               assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae));
+               assertEqualInt(archive_compression(a),
+                   ARCHIVE_COMPRESSION_GZIP);
+               assertEqualInt(archive_format(a),
+                   ARCHIVE_FORMAT_CPIO_SVR4_NOCRC);
+               assertEqualInt(ARCHIVE_OK, archive_read_close(a));
        }
-       assert(0 == r);
-       assert(archive_compression(a) == ARCHIVE_COMPRESSION_GZIP);
-       assert(archive_format(a) == ARCHIVE_FORMAT_CPIO_SVR4_NOCRC);
-       assert(0 == archive_read_close(a));
-finish:
-#if ARCHIVE_VERSION_NUMBER < 2000000
-       archive_read_finish(a);
-#else
-       assert(0 == archive_read_finish(a));
-#endif
+       assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
 }
 
 
index 82ddc38c80d7a26f7d0e3b9fc98946c2a8412aac..011b53e3ea5d95d24a61a1c871c482010971da78 100644 (file)
@@ -39,26 +39,21 @@ DEFINE_TEST(test_read_format_gtar_gz)
        int r;
 
        assert((a = archive_read_new()) != NULL);
-       assert(0 == archive_read_support_compression_all(a));
-       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 (UnsupportedCompress(r, a)) {
-               skipping("Skipping GZIP compression check: "
-                   "This version of libarchive was compiled "
-                   "without gzip support");
-               goto finish;
+       assertEqualInt(ARCHIVE_OK, archive_read_support_compression_all(a));
+       r = archive_read_support_compression_gzip(a);
+       if (r == ARCHIVE_WARN) {
+               skipping("gzip not fully supported");
+       } else {
+               assertEqualInt(ARCHIVE_OK, archive_read_support_format_all(a));
+               assertEqualInt(ARCHIVE_OK,
+                   archive_read_open_memory(a, archive, sizeof(archive)));
+               assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae));
+               assertEqualInt(archive_compression(a),
+                   ARCHIVE_COMPRESSION_GZIP);
+               assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_GNUTAR);
+               assertEqualInt(ARCHIVE_OK, archive_read_close(a));
        }
-       assert(0 == r);
-       assert(archive_compression(a) == ARCHIVE_COMPRESSION_GZIP);
-       assert(archive_format(a) == ARCHIVE_FORMAT_TAR_GNUTAR);
-       assert(0 == archive_read_close(a));
-finish:
-#if ARCHIVE_VERSION_NUMBER < 2000000
-       archive_read_finish(a);
-#else
-       assert(0 == archive_read_finish(a));
-#endif
+       assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
 }
 
 
index 9a1faf2cb7aac229c6d5eb5a104fecb8f3c81cd6..16fb08a2fd4871893642dbd8c215ed9542c5ce89 100644 (file)
@@ -37,22 +37,21 @@ DEFINE_TEST(test_read_format_iso_gz)
        assert((a = archive_read_new()) != NULL);
        assertEqualIntA(a, ARCHIVE_OK,
            archive_read_support_compression_all(a));
-       assertEqualIntA(a, ARCHIVE_OK,
-           archive_read_support_format_all(a));
-       assertEqualIntA(a, ARCHIVE_OK,
-           archive_read_open_filename(a, name, 512));
-       r = archive_read_next_header(a, &ae);
-       if (UnsupportedCompress(r, a)) {
-               skipping("Skipping GZIP compression check: "
-                   "This version of libarchive was compiled "
-                   "without gzip support");
-               goto finish;
+       r = archive_read_support_compression_gzip(a);
+       if (r == ARCHIVE_WARN) {
+               skipping("gzip not fully supported");
+       } else {
+               assertEqualIntA(a, ARCHIVE_OK,
+                   archive_read_support_format_all(a));
+               assertEqualIntA(a, ARCHIVE_OK,
+                   archive_read_open_filename(a, name, 512));
+               assertEqualIntA(a, ARCHIVE_OK,
+                   archive_read_next_header(a, &ae));
+               assertEqualInt(archive_compression(a),
+                   ARCHIVE_COMPRESSION_GZIP);
+               assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660);
+               assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
        }
-       assertEqualIntA(a, ARCHIVE_OK, r);
-       assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_GZIP);
-       assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660);
-       assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
-finish:
        assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
 }
 
index fe7a508b21670fe5b807ffc9c9ae62e53c949f2a..fc5bf8ce55622dd9080d7e8f00b8a1620baaeca3 100644 (file)
@@ -39,26 +39,21 @@ DEFINE_TEST(test_read_format_tgz)
        int r;
 
        assert((a = archive_read_new()) != NULL);
-       assert(0 == archive_read_support_compression_all(a));
-       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 (UnsupportedCompress(r, a)) {
-               skipping("Skipping GZIP compression check: "
-                   "This version of libarchive was compiled "
-                   "without gzip support");
-               goto finish;
+       assertEqualInt(ARCHIVE_OK, archive_read_support_compression_all(a));
+       r = archive_read_support_compression_gzip(a);
+       if (r == ARCHIVE_WARN) {
+               skipping("gzip not fully supported");
+       } else {
+               assertEqualInt(ARCHIVE_OK, archive_read_support_format_all(a));
+               assertEqualInt(ARCHIVE_OK,
+                   archive_read_open_memory(a, archive, sizeof(archive)));
+               assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae));
+               assertEqualInt(archive_compression(a),
+                   ARCHIVE_COMPRESSION_GZIP);
+               assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR);
+               assertEqualInt(ARCHIVE_OK, archive_read_close(a));
        }
-       assert(0 == r);
-       assert(archive_compression(a) == ARCHIVE_COMPRESSION_GZIP);
-       assert(archive_format(a) == ARCHIVE_FORMAT_TAR_USTAR);
-       assert(0 == archive_read_close(a));
-finish:
-#if ARCHIVE_VERSION_NUMBER < 2000000
-       archive_read_finish(a);
-#else
-       assert(0 == archive_read_finish(a));
-#endif
+       assertEqualInt(ARCHIVE_OK,archive_read_finish(a));
 }
 
 
index d8bb08564e890e481eebcd80518436218ba2f456..386b91dd5a45b6a578c6531b43904eaef2d790eb 100644 (file)
@@ -41,7 +41,7 @@ DEFINE_TEST(test_write_compress_gzip)
        size_t buffsize, datasize;
        char path[16];
        size_t used1, used2;
-       int i;
+       int i, r;
 
        buffsize = 2000000;
        assert(NULL != (buff = (char *)malloc(buffsize)));
@@ -79,17 +79,26 @@ DEFINE_TEST(test_write_compress_gzip)
 
        assert((a = archive_read_new()) != NULL);
        assertA(0 == archive_read_support_format_all(a));
-       assertA(0 == archive_read_support_compression_all(a));
-       assertA(0 == archive_read_open_memory(a, buff, used1));
-       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));
+       r = archive_read_support_compression_gzip(a);
+       if (r == ARCHIVE_WARN) {
+               skipping("Can't verify gzip writing by reading back;"
+                   " gzip reading not fully supported");
+       } else {
+               assertEqualIntA(a, ARCHIVE_OK,
+                   archive_read_support_compression_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));
        }
-       assert(0 == archive_read_close(a));
-       assert(0 == archive_read_finish(a));
+       assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
 
        /*
         * Repeat the cycle again, this time setting some compression
@@ -131,18 +140,26 @@ DEFINE_TEST(test_write_compress_gzip)
        */
 
        assert((a = archive_read_new()) != NULL);
-       assertA(0 == archive_read_support_format_all(a));
-       assertA(0 == archive_read_support_compression_all(a));
-       assertA(0 == archive_read_open_memory(a, buff, used2));
-       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_support_format_all(a));
+       r = archive_read_support_compression_gzip(a);
+       if (r == ARCHIVE_WARN) {
+               skipping("gzip decompression not fully supported");
+       } else {
+               assertEqualIntA(a, ARCHIVE_OK,
+                   archive_read_support_compression_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));
        }
-       assert(0 == archive_read_close(a));
-       assert(0 == archive_read_finish(a));
+       assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
 
        /*
         * Repeat again, with much lower compression.
@@ -178,16 +195,23 @@ DEFINE_TEST(test_write_compress_gzip)
        assert((a = archive_read_new()) != NULL);
        assertA(0 == archive_read_support_format_all(a));
        assertA(0 == archive_read_support_compression_all(a));
-       assertA(0 == archive_read_open_memory(a, buff, used2));
-       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));
+       r = archive_read_support_compression_gzip(a);
+       if (r == ARCHIVE_WARN) {
+               skipping("gzip decompression not fully supported");
+       } 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));
        }
-       assert(0 == archive_read_close(a));
-       assert(0 == archive_read_finish(a));
+       assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
 
        /*
         * Clean up.
index f5eaf2a8857559f404a97a8d7d73c2fd8ba8b45a..c67c57749b661cc4fda41e9587360653af882c43 100644 (file)
@@ -38,18 +38,20 @@ DEFINE_TEST(test_write_compress_program)
        size_t used;
        int blocksize = 1024;
        int r;
-       const char *extprog;
+       const char *compprog, *decompprog;
 
-       if ((extprog = external_gzip_program(0)) == NULL) {
+       decompprog = external_gzip_program(1);
+       if ((compprog = external_gzip_program(0)) == NULL) {
                skipping("There is no gzip compression "
                    "program in this platform");
                return;
        }
+
        /* 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, extprog);
+       r = archive_write_set_compression_program(a, compprog);
        if (r == ARCHIVE_FATAL) {
                skipping("Write compression via external "
                    "program unsupported on this platform");
@@ -77,60 +79,43 @@ DEFINE_TEST(test_write_compress_program)
 
        /* Close out the archive. */
        assertA(0 == archive_write_close(a));
-#if ARCHIVE_VERSION_NUMBER < 2000000
-       archive_write_finish(a);
-#else
        assertA(0 == archive_write_finish(a));
-#endif
 
        /*
         * Now, read the data back through the built-in gzip support.
         */
        assert((a = archive_read_new()) != NULL);
-       assertA(0 == archive_read_support_format_all(a));
-       assertA(0 == archive_read_support_compression_all(a));
-       assertA(0 == archive_read_open_memory(a, buff, used));
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a));
+       r = archive_read_support_compression_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 && decompprog == NULL) {
+               skipping("No gzip decompression is available; "
+                   "unable to verify gzip compression");
+               assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
+               return;
+       }
+       assertEqualIntA(a, ARCHIVE_OK, 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);
+       if (!assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae))) {
+               archive_read_finish(a);
+               return;
        }
-       assertA(0 == r);
 
-       assert(1 == archive_entry_mtime(ae));
-       assert(0 == archive_entry_atime(ae));
-       assert(0 == archive_entry_ctime(ae));
+       assertEqualInt(1, archive_entry_mtime(ae));
+       assertEqualInt(0, archive_entry_atime(ae));
+       assertEqualInt(0, archive_entry_ctime(ae));
        assertEqualString("file", archive_entry_pathname(ae));
-       assert((S_IFREG | 0755) == archive_entry_mode(ae));
-       assert(8 == archive_entry_size(ae));
-       assertA(8 == archive_read_data(a, buff2, 10));
-       assert(0 == memcmp(buff2, "12345678", 8));
+       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. */
-       assert(1 == archive_read_next_header(a, &ae));
-       assert(0 == archive_read_close(a));
-#if ARCHIVE_VERSION_NUMBER < 2000000
-       archive_read_finish(a);
-#else
-       assert(0 == archive_read_finish(a));
-#endif
+       assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+       assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
 #endif
 }