]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Simplify cheking that a compression is not supported.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Thu, 19 Feb 2009 08:42:27 +0000 (03:42 -0500)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Thu, 19 Feb 2009 08:42:27 +0000 (03:42 -0500)
SVN-Revision: 676

16 files changed:
libarchive/test/test.h
libarchive/test/test_compat_bzip2.c
libarchive/test/test_compat_gzip.c
libarchive/test/test_compat_xz.c
libarchive/test/test_fuzz.c
libarchive/test/test_read_format_cpio_bin_bz2.c
libarchive/test/test_read_format_cpio_bin_gz.c
libarchive/test/test_read_format_cpio_bin_xz.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_pax_bz2.c
libarchive/test/test_read_format_tbz.c
libarchive/test/test_read_format_tgz.c
libarchive/test/test_read_format_txz.c
libarchive/test/test_write_compress_program.c

index 9647e981109ee4d66f60b61cd8cc35ab945753b3..2e8e7b630d2272da42d73ff646022662515692d0 100644 (file)
@@ -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))
+
index 81d2ab263c370fa5e8490e85b6b97e1004e06a0b..4b2cf05136aeaac6a732a6b668bd699c49f9e6db 100644 (file)
@@ -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);
index a967979c18bd74124210565d5b533fc441d6b3ba..25cdc2bbe8a1d76b91ebd7a74511585aa92d12ee 100644 (file)
@@ -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);
index b8b42ecf6cfce3199cd3ba09f4578f8ecbeaa90e..d84326f7bee73c7c7ec91599700a89646a1f27f9 100644 (file)
@@ -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);
index a560a30441e0fb8479653362d03957af809c7046..6c7b205fbc2fa041c190e6a2dab2dfa1716fa233 100644 (file)
@@ -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));
index 176533ff18bdd0118b7b24e13e116d32a284fdfd..0efd233d7fd4c88a90474f674efcf7adf3edf402 100644 (file)
@@ -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);
index c0e65bebe9a1374fc7b93de3a98be72bb8ec8436..58272c40c6aa11d497501cf60f75d1292b1ab6e3 100644 (file)
@@ -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);
index bbf57cfc6054016328bc2ec8317de39743edbd7a..d29324c98eddebaff65eb87ee7af3e0d8ef64eea 100644 (file)
@@ -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);
index 88a7b054716737f3f2a9648d946a4516bef3d120..8c151a53a4b473b7066d069b15052d9ab3e7eb38 100644 (file)
@@ -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);
index c410757895003cc9eff2a3b562427cf9d204febf..82ddc38c80d7a26f7d0e3b9fc98946c2a8412aac 100644 (file)
@@ -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);
index 5c085170ba981a7e8790cbcd1da409f1506de701..6b3e1426be4b02963ba940201b73b3cba9574edb 100644 (file)
@@ -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);
index 9acc0db5f6cb8eb4f0030e4bde87bff313dbafba..4a767738209a2d77a87782a7922729f09f685417 100644 (file)
@@ -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);
index 995df069182415a974b36a8448f052323896b5e9..ddc4b64f230443d15a1b46a9a199bd0d36b8af94 100644 (file)
@@ -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);
index 986ab492373b61def3ae43522cb72be5058dd7e8..fe7a508b21670fe5b807ffc9c9ae62e53c949f2a 100644 (file)
@@ -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);
index 82cfc8f535202631faa743870e999c63144deeab..2325e1d1627bf47a0b2fecd1596742e860ec2998 100644 (file)
@@ -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);
index daf4aa7204b24cb3321b4eba97032cdace0cf1f7..f5eaf2a8857559f404a97a8d7d73c2fd8ba8b45a 100644 (file)
@@ -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);