From: Tim Kientzle Date: Sun, 13 Mar 2016 01:38:21 +0000 (-0800) Subject: Issue 422: Add archive_xxx_version() calls so tests can more accurately query libarc... X-Git-Tag: v3.1.901a~9^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3933e100461d2251305b2fc0db10c6adb4c762e4;p=thirdparty%2Flibarchive.git Issue 422: Add archive_xxx_version() calls so tests can more accurately query libarchive support Rework some of the Zip, Cab, and LZ4 tests to use these to determine what behavior they should expect. --- diff --git a/libarchive/archive.h b/libarchive/archive.h index 3512a1171..6228fc28d 100644 --- a/libarchive/archive.h +++ b/libarchive/archive.h @@ -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; diff --git a/libarchive/archive_util.c b/libarchive/archive_util.c index ea14d4d80..3aa3d8c48 100644 --- a/libarchive/archive_util.c +++ b/libarchive/archive_util.c @@ -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 diff --git a/libarchive/test/test_compat_zip.c b/libarchive/test/test_compat_zip.c index 5720210f2..bb6d92ef4 100644 --- a/libarchive/test/test_compat_zip.c +++ b/libarchive/test/test_compat_zip.c @@ -25,12 +25,6 @@ #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)); diff --git a/libarchive/test/test_read_format_cab.c b/libarchive/test/test_read_format_cab.c index 55e6d978b..8f6adae66 100644 --- a/libarchive/test/test_read_format_cab.c +++ b/libarchive/test/test_read_format_cab.c @@ -25,12 +25,6 @@ #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; diff --git a/libarchive/test/test_read_format_zip.c b/libarchive/test/test_read_format_zip.c index c4ba00459..da5b13787 100644 --- a/libarchive/test/test_read_format_zip.c +++ b/libarchive/test/test_read_format_zip.c @@ -26,12 +26,6 @@ #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 { diff --git a/libarchive/test/test_read_format_zip_mac_metadata.c b/libarchive/test/test_read_format_zip_mac_metadata.c index 3b5dae614..97aa427b0 100644 --- a/libarchive/test/test_read_format_zip_mac_metadata.c +++ b/libarchive/test/test_read_format_zip_mac_metadata.c @@ -25,12 +25,6 @@ #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)) { diff --git a/libarchive/test/test_read_format_zip_traditional_encryption_data.c b/libarchive/test/test_read_format_zip_traditional_encryption_data.c index a88050cfc..2700be15a 100644 --- a/libarchive/test/test_read_format_zip_traditional_encryption_data.c +++ b/libarchive/test/test_read_format_zip_traditional_encryption_data.c @@ -26,12 +26,6 @@ #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, diff --git a/libarchive/test/test_read_format_zip_winzip_aes.c b/libarchive/test/test_read_format_zip_winzip_aes.c index 6ffbc1dd0..082337d7e 100644 --- a/libarchive/test/test_read_format_zip_winzip_aes.c +++ b/libarchive/test/test_read_format_zip_winzip_aes.c @@ -26,12 +26,6 @@ #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)); diff --git a/libarchive/test/test_read_format_zip_winzip_aes_large.c b/libarchive/test/test_read_format_zip_winzip_aes_large.c index aeaca7df9..a40d5cf13 100644 --- a/libarchive/test/test_read_format_zip_winzip_aes_large.c +++ b/libarchive/test/test_read_format_zip_winzip_aes_large.c @@ -26,12 +26,6 @@ #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, diff --git a/libarchive/test/test_write_filter_lz4.c b/libarchive/test/test_write_filter_lz4.c index ae4fc67f3..46c7061ea 100644 --- a/libarchive/test/test_write_filter_lz4.c +++ b/libarchive/test/test_write_filter_lz4.c @@ -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;