]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Issue 422: Add archive_xxx_version() calls so tests can more accurately query libarc...
authorTim Kientzle <kientzle@acm.org>
Sun, 13 Mar 2016 01:38:21 +0000 (17:38 -0800)
committerTim Kientzle <kientzle@acm.org>
Sun, 13 Mar 2016 01:38:21 +0000 (17:38 -0800)
Rework some of the Zip, Cab, and LZ4 tests to use these
to determine what behavior they should expect.

libarchive/archive.h
libarchive/archive_util.c
libarchive/test/test_compat_zip.c
libarchive/test/test_read_format_cab.c
libarchive/test/test_read_format_zip.c
libarchive/test/test_read_format_zip_mac_metadata.c
libarchive/test/test_read_format_zip_traditional_encryption_data.c
libarchive/test/test_read_format_zip_winzip_aes.c
libarchive/test/test_read_format_zip_winzip_aes_large.c
libarchive/test/test_write_filter_lz4.c

index 3512a1171112a52dd4c11a7603dc28f7447b06f5..6228fc28d8a1f71f27613f37abbc88e0fef46c4f 100644 (file)
@@ -162,6 +162,16 @@ __LA_DECL const char *     archive_version_string(void);
  */
 __LA_DECL const char * archive_version_details(void);
 
+/*
+ * Returns NULL if libarchive was compiled without the associated library.
+ * Otherwise, returns the version number that libarchive was compiled
+ * against.
+ */
+__LA_DECL const char *  archive_zlib_version(void);
+__LA_DECL const char *  archive_liblzma_version(void);
+__LA_DECL const char *  archive_bzlib_version(void);
+__LA_DECL const char *  archive_liblz4_version(void);
+
 /* Declare our basic types. */
 struct archive;
 struct archive_entry;
index ea14d4d80d71b20819537949e4a71532cd7d5ea0..3aa3d8c4815bdc08f2dd2b79bea0d86e460712f8 100644 (file)
@@ -94,35 +94,79 @@ archive_version_details(void)
 {
        static struct archive_string str;
        static int init = 0;
+       const char *zlib = archive_zlib_version();
+       const char *liblzma = archive_liblzma_version();
+       const char *bzlib = archive_bzlib_version();
+       const char *liblz4 = archive_liblz4_version();
 
        if (!init) {
                archive_string_init(&str);
 
                archive_strcat(&str, ARCHIVE_VERSION_STRING);
-#ifdef HAVE_ZLIB_H
-               archive_strcat(&str, " zlib/");
-               archive_strcat(&str, ZLIB_VERSION);
-#endif
-#ifdef HAVE_LZMA_H
-               archive_strcat(&str, " liblzma/");
-               archive_strcat(&str, LZMA_VERSION_STRING);
-#endif
-#ifdef HAVE_BZLIB_H
-               {
-                       const char *p = BZ2_bzlibVersion();
+               if (zlib != NULL) {
+                       archive_strcat(&str, " zlib/");
+                       archive_strcat(&str, zlib);
+               }
+               if (liblzma) {
+                       archive_strcat(&str, " liblzma/");
+                       archive_strcat(&str, liblzma);
+               }
+               if (bzlib) {
+                       const char *p = bzlib;
                        const char *sep = strchr(p, ',');
                        if (sep == NULL)
                                sep = p + strlen(p);
                        archive_strcat(&str, " bz2lib/");
                        archive_strncat(&str, p, sep - p);
                }
+               if (liblz4) {
+                       archive_strcat(&str, " liblz4/");
+                       archive_strcat(&str, liblz4);
+               }
+       }
+       return str.s;
+}
+
+const char *
+archive_zlib_version(void)
+{
+#ifdef HAVE_ZLIB_H
+       return ZLIB_VERSION;
+#else
+       return NULL;
+#endif
+}
+
+const char *
+archive_liblzma_version(void)
+{
+#ifdef HAVE_LZMA_H
+       return LZMA_VERSION_STRING;
+#else
+       return NULL;
 #endif
+}
+
+const char *
+archive_bzlib_version(void)
+{
+#ifdef HAVE_BZLIB_H
+       return BZ2_bzlibVersion();
+#else
+       return NULL;
+#endif
+}
+
+const char *
+archive_liblz4_version(void)
+{
 #if defined(HAVE_LZ4_H) && defined(HAVE_LIBLZ4)
-               archive_string_sprintf(&str, " liblz4/%d.%d.%d",
-                   LZ4_VERSION_MAJOR, LZ4_VERSION_MINOR, LZ4_VERSION_RELEASE);
+#define NUMBER(x) #x
+       return NUMBER(LZ4_VERSION_MAJOR) "." NUMBER(LZ4_VERSION_MINOR) "." NUMBER(LZ4_VERSION_RELEASE);
+#undef NUMBER
+#else
+       return NULL;
 #endif
-       }
-       return str.s;
 }
 
 int
index 5720210f2abb1e113501a1c774ceea19b751a5af..bb6d92ef498c67bf2909e83876bd7fea4d7fc06e 100644 (file)
 #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. */
 DEFINE_TEST(test_compat_zip_1)
 {
@@ -51,7 +45,7 @@ DEFINE_TEST(test_compat_zip_1)
 
        /* Read second entry. */
        r = archive_read_next_header(a, &ae);
-       if (r == ARCHIVE_FATAL && !libz_enabled) {
+       if (r == ARCHIVE_FATAL && archive_zlib_version() == NULL) {
                skipping("Skipping ZIP compression check: %s",
                        archive_error_string(a));
                goto finish;
@@ -132,7 +126,7 @@ DEFINE_TEST(test_compat_zip_3)
 
        /* Extract under a different name. */
        archive_entry_set_pathname(ae, "test_3.txt");
-       if(libz_enabled) {
+       if(archive_zlib_version() != NULL) {
                char *p;
                size_t s;
                assertEqualIntA(a, ARCHIVE_OK, archive_read_extract(a, ae, 0));
index 55e6d978b8d5fd51cf05f7c71d6dbf0b0081a1e1..8f6adae66a4a7689b0ad526e6363bb7e0ec92da9 100644 (file)
 #include "test.h"
 __FBSDID("$FreeBSD");
 
-#ifdef HAVE_LIBZ
-static const int libz_enabled = 1;
-#else
-static const int libz_enabled = 0;
-#endif
-
 /*
 Execute the following command to rebuild the data for this program:
    tail -n +44 test_read_format_cab.c | /bin/sh
@@ -222,7 +216,7 @@ verify(const char *refname, enum comp_type comp)
                assertEqualInt(33000, archive_entry_size(ae));
                for (s = 0; s + sizeof(buff) < 33000; s+= sizeof(buff)) {
                        ssize_t rsize = archive_read_data(a, buff, sizeof(buff));
-                       if (comp == MSZIP && rsize == ARCHIVE_FATAL && !libz_enabled) {
+                       if (comp == MSZIP && rsize == ARCHIVE_FATAL && archive_zlib_version() == NULL) {
                                skipping("Skipping CAB format(MSZIP) check: %s",
                                    archive_error_string(a));
                                goto finish;
@@ -288,7 +282,7 @@ verify2(const char *refname, enum comp_type comp)
        char buff[128];
        char zero[128];
 
-       if (comp == MSZIP && !libz_enabled) {
+       if (comp == MSZIP && archive_zlib_version() == NULL) {
                skipping("Skipping CAB format(MSZIP) check for %s",
                  refname);
                return;
index c4ba0045990c6f3c5787341d2804900a9dc622e6..da5b13787ed5780200761b602dc2f8aad69e938d 100644 (file)
 #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
@@ -67,7 +61,7 @@ verify_basic(struct archive *a, int seek_checks)
        assertEqualInt(archive_entry_is_encrypted(ae), 0);
        assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
        failure("archive_read_data() returns number of bytes read");
-       if (libz_enabled) {
+       if (archive_zlib_version() != NULL) {
                assertEqualInt(18, archive_read_data(a, buff, 19));
                assertEqualMem(buff, "hello\nhello\nhello\n", 18);
        } else {
@@ -87,7 +81,7 @@ verify_basic(struct archive *a, int seek_checks)
        }
        assert(archive_entry_size_is_set(ae));
        assertEqualInt(18, archive_entry_size(ae));
-       if (libz_enabled) {
+       if (archive_zlib_version() != NULL) {
                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));
@@ -155,7 +149,7 @@ verify_info_zip_ux(struct archive *a, int seek_checks)
        failure("zip reader should read Info-ZIP New Unix Extra Field");
        assertEqualInt(1001, archive_entry_uid(ae));
        assertEqualInt(1001, archive_entry_gid(ae));
-       if (libz_enabled) {
+       if (archive_zlib_version() != NULL) {
                failure("archive_read_data() returns number of bytes read");
                assertEqualInt(18, archive_read_data(a, buff, 19));
                assertEqualMem(buff, "hello\nhello\nhello\n", 18);
@@ -226,7 +220,7 @@ verify_extract_length_at_end(struct archive *a, int seek_checks)
                assertEqualInt(0, archive_entry_size(ae));
        }
 
-       if (libz_enabled) {
+       if (archive_zlib_version() != NULL) {
                assertEqualIntA(a, ARCHIVE_OK, archive_read_extract(a, ae, 0));
                assertFileContents("hello\x0A", 6, "hello.txt");
        } else {
index 3b5dae614ce09c8ca4a350a52af9d6e49af01445..97aa427b0348201d293a9b828708965a4d2e30b2 100644 (file)
 #include "test.h"
 __FBSDID("$FreeBSD$");
 
-#ifdef HAVE_LIBZ
-static const int libz_enabled = 1;
-#else
-static const int libz_enabled = 0;
-#endif
-
 /*
  * Read a zip file that has a zip comment in the end of the central
  * directory record.
@@ -90,7 +84,7 @@ DEFINE_TEST(test_read_format_zip_mac_metadata)
        assertEqualIntA(a, ARCHIVE_OK, archive_read_set_option(a, "zip", "mac-ext", "1"));
        assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, p, s, 1));
 
-       if (libz_enabled) {
+       if (archive_zlib_version() != NULL) {
                assertEqualIntA(a, ARCHIVE_OK,
                    archive_read_next_header(a, &ae));
        } else {
@@ -105,7 +99,7 @@ DEFINE_TEST(test_read_format_zip_mac_metadata)
        assertEqualString("file3", archive_entry_pathname(ae));
        assertEqualInt(AE_IFREG | 0644, archive_entry_mode(ae));
        failure("Mac metadata should be set");
-       if (libz_enabled) {
+       if (archive_zlib_version() != NULL) {
                const void *metadata;
                if (assert((metadata = archive_entry_mac_metadata(ae, &s))
                    != NULL)) {
index a88050cfc2778eae9ec71ddde8b368b22ef1a1f5..2700be15ac7cfd4048bfa5ac4b65e146d6d210c4 100644 (file)
 #include "test.h"
 __FBSDID("$FreeBSD$");
 
-#ifdef HAVE_LIBZ
-static const int libz_enabled = 1;
-#else
-static const int libz_enabled = 0;
-#endif
-
 DEFINE_TEST(test_read_format_zip_traditional_encryption_data)
 {
        /* This file is password protected (Traditional PKWARE Enctypted).
@@ -130,7 +124,7 @@ DEFINE_TEST(test_read_format_zip_traditional_encryption_data)
        assertEqualInt(1, archive_entry_is_data_encrypted(ae));
        assertEqualInt(0, archive_entry_is_metadata_encrypted(ae));
        assertEqualIntA(a, 1, archive_read_has_encrypted_entries(a));
-       if (libz_enabled) {
+       if (archive_zlib_version() != NULL) {
                assertEqualInt(495, archive_read_data(a, buff, sizeof(buff)));
        } else {
                assertEqualInt(ARCHIVE_FAILED,
@@ -148,7 +142,7 @@ DEFINE_TEST(test_read_format_zip_traditional_encryption_data)
        assertEqualInt(1, archive_entry_is_data_encrypted(ae));
        assertEqualInt(0, archive_entry_is_metadata_encrypted(ae));
        assertEqualIntA(a, 1, archive_read_has_encrypted_entries(a));
-       if (libz_enabled) {
+       if (archive_zlib_version() != NULL) {
                assertEqualInt(495, archive_read_data(a, buff, sizeof(buff)));
        } else {
                assertEqualInt(ARCHIVE_FAILED,
index 6ffbc1dd0cb502f00984fcb1814cd1807e617cd8..082337d7eabffaa2bbfe617bbdaebb6267bede41 100644 (file)
 #include "test.h"
 __FBSDID("$FreeBSD$");
 
-#ifdef HAVE_LIBZ
-static const int libz_enabled = 1;
-#else
-static const int libz_enabled = 0;
-#endif
-
 static void
 test_winzip_aes(const char *refname, int need_libz)
 {
@@ -116,7 +110,7 @@ test_winzip_aes(const char *refname, int need_libz)
        assertEqualInt(1, archive_entry_is_data_encrypted(ae));
        assertEqualInt(0, archive_entry_is_metadata_encrypted(ae));
        assertEqualIntA(a, 1, archive_read_has_encrypted_entries(a));
-       if (!need_libz || libz_enabled) {
+       if (!need_libz || archive_zlib_version() != NULL) {
                assertEqualInt(512, archive_read_data(a, buff, sizeof(buff)));
        } else {
                assertEqualInt(ARCHIVE_FAILED, archive_read_data(a, buff, 19));
index aeaca7df9cc36a724b735b472c41ca02abcf154c..a40d5cf1329a86dbce47ab218b1f6bfa6afaccd1 100644 (file)
 #include "test.h"
 __FBSDID("$FreeBSD$");
 
-#ifdef HAVE_LIBZ
-static const int libz_enabled = 1;
-#else
-static const int libz_enabled = 0;
-#endif
-
 DEFINE_TEST(test_read_format_zip_winzip_aes256_large)
 {
        const char *refname = "test_read_format_zip_winzip_aes256_large.zip";
@@ -143,7 +137,7 @@ DEFINE_TEST(test_read_format_zip_winzip_aes256_large)
        assertEqualInt(1, archive_entry_is_data_encrypted(ae));
        assertEqualInt(0, archive_entry_is_metadata_encrypted(ae));
        assertEqualIntA(a, 1, archive_read_has_encrypted_entries(a));
-       if (libz_enabled) {
+       if (archive_zlib_version() != NULL) {
                assertEqualInt(512, archive_read_data(a, buff, sizeof(buff)));
        } else {
                assertEqualInt(ARCHIVE_FAILED,
@@ -161,7 +155,7 @@ DEFINE_TEST(test_read_format_zip_winzip_aes256_large)
        assertEqualInt(1, archive_entry_is_data_encrypted(ae));
        assertEqualInt(0, archive_entry_is_metadata_encrypted(ae));
        assertEqualIntA(a, 1, archive_read_has_encrypted_entries(a));
-       if (libz_enabled) {
+       if (archive_zlib_version() != NULL) {
                assertEqualInt(512, archive_read_data(a, buff, sizeof(buff)));
        } else {
                assertEqualInt(ARCHIVE_FAILED,
@@ -179,7 +173,7 @@ DEFINE_TEST(test_read_format_zip_winzip_aes256_large)
        assertEqualInt(1, archive_entry_is_data_encrypted(ae));
        assertEqualInt(0, archive_entry_is_metadata_encrypted(ae));
        assertEqualIntA(a, 1, archive_read_has_encrypted_entries(a));
-       if (libz_enabled) {
+       if (archive_zlib_version() != NULL) {
                assertEqualInt(512, archive_read_data(a, buff, sizeof(buff)));
        } else {
                assertEqualInt(ARCHIVE_FAILED,
@@ -197,7 +191,7 @@ DEFINE_TEST(test_read_format_zip_winzip_aes256_large)
        assertEqualInt(1, archive_entry_is_data_encrypted(ae));
        assertEqualInt(0, archive_entry_is_metadata_encrypted(ae));
        assertEqualIntA(a, 1, archive_read_has_encrypted_entries(a));
-       if (libz_enabled) {
+       if (archive_zlib_version() != NULL) {
                assertEqualInt(512, archive_read_data(a, buff, sizeof(buff)));
        } else {
                assertEqualInt(ARCHIVE_FAILED,
index ae4fc67f38ff9e6d46c35ca303a7646d3eb5ff93..46c7061eae15f7709b148e265567d30a9b51f172 100644 (file)
@@ -43,14 +43,18 @@ DEFINE_TEST(test_write_filter_lz4)
 
        assert((a = archive_write_new()) != NULL);
        r = archive_write_add_filter_lz4(a);
-       if (r != ARCHIVE_OK) {
-               if (canLz4() && r == ARCHIVE_WARN)
-                       use_prog = 1;
-               else {
+       if (archive_liblz4_version() == NULL) {
+               if (!canLz4()) {
                        skipping("lz4 writing not supported on this platform");
+                       assertEqualInt(ARCHIVE_WARN, r);
                        assertEqualInt(ARCHIVE_OK, archive_write_free(a));
                        return;
+               } else {
+                       assertEqualInt(ARCHIVE_WARN, r);
+                       use_prog = 1;
                }
+       } else {
+               assertEqualInt(ARCHIVE_OK, r);
        }
 
        buffsize = 2000000;
@@ -280,14 +284,18 @@ test_options(const char *options)
 
        assert((a = archive_write_new()) != NULL);
        r = archive_write_add_filter_lz4(a);
-       if (r != ARCHIVE_OK) {
-               if (canLz4() && r == ARCHIVE_WARN)
-                       use_prog = 1;
-               else {
+       if (archive_liblz4_version() == NULL) {
+               if (!canLz4()) {
                        skipping("lz4 writing not supported on this platform");
+                       assertEqualInt(ARCHIVE_WARN, r);
                        assertEqualInt(ARCHIVE_OK, archive_write_free(a));
                        return;
+               } else {
+                       assertEqualInt(ARCHIVE_WARN, r);
+                       use_prog = 1;
                }
+       } else {
+               assertEqualInt(ARCHIVE_OK, r);
        }
 
        buffsize = 2000000;