]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Issue 192: Fix tests that fail when libarchive is deliberately
authorTim Kientzle <kientzle@gmail.com>
Sat, 12 Nov 2011 04:57:35 +0000 (23:57 -0500)
committerTim Kientzle <kientzle@gmail.com>
Sat, 12 Nov 2011 04:57:35 +0000 (23:57 -0500)
built without libz.
Thanks to dpmcgee.

SVN-Revision: 3765

libarchive/test/test_compat_zip.c
libarchive/test/test_read_format_cab.c
libarchive/test/test_read_format_zip.c

index f036a7049354b6978b3987abe405a4add5d68339..24a4c5a0f947e4aa465b17fffb890b5f1ceaf7b9 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. */
 static void
 test_compat_zip_1(void)
@@ -46,13 +52,10 @@ test_compat_zip_1(void)
 
        /* Read second entry. */
        r = archive_read_next_header(a, &ae);
-       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));
-                       goto finish;
-               }
+       if (r == ARCHIVE_FATAL && !libz_enabled) {
+               skipping("Skipping ZIP compression check: %s",
+                       archive_error_string(a));
+               goto finish;
        }
        assertEqualIntA(a, ARCHIVE_OK, r);
        assertEqualString("tmp.class", archive_entry_pathname(ae));
@@ -62,8 +65,8 @@ test_compat_zip_1(void)
        assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_NONE);
        assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ZIP);
 
-       assertEqualInt(ARCHIVE_OK, archive_read_close(a));
 finish:
+       assertEqualInt(ARCHIVE_OK, archive_read_close(a));
        assertEqualInt(ARCHIVE_OK, archive_read_free(a));
 }
 
@@ -109,8 +112,6 @@ test_compat_zip_3(void)
        const char *refname = "test_compat_zip_3.zip";
        struct archive_entry *ae;
        struct archive *a;
-       char *p;
-       size_t s;
 
        extract_reference_file(refname);
        assert((a = archive_read_new()) != NULL);
@@ -134,14 +135,21 @@ test_compat_zip_3(void)
 
        /* Extract under a different name. */
        archive_entry_set_pathname(ae, "test_3.txt");
-       assertEqualIntA(a, ARCHIVE_OK, archive_read_extract(a, ae, 0));
-       /* Verify the first 12 bytes actually got written to disk correctly. */
-       p = slurpfile(&s, "test_3.txt");
-       assertEqualInt(s, 1030);
-       assertEqualMem(p, "<?xml versio", 12);
-       free(p);
+       if(libz_enabled) {
+               char *p;
+               size_t s;
+               assertEqualIntA(a, ARCHIVE_OK, archive_read_extract(a, ae, 0));
+               /* Verify the first 12 bytes actually got written to disk correctly. */
+               p = slurpfile(&s, "test_3.txt");
+               assertEqualInt(s, 1030);
+               assertEqualMem(p, "<?xml versio", 12);
+               free(p);
+               assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
+       } else {
+               skipping("Skipping ZIP compression check, no libz support");
+               assertEqualIntA(a, ARCHIVE_FATAL, archive_read_next_header(a, &ae));
+       }
 
-       assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
        assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
        assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
 }
index e3d162ef03e6523211beb5549ad98115f3c648b7..0a94865d6a494d4beb617b66d08d9b5738852fcf 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
@@ -212,10 +218,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 < 0 &&
-                           strcmp(archive_error_string(a),
-                           "libarchive compiled without deflate support (no libz)")
-                           == 0) {
+                       if (comp == MSZIP && rsize == ARCHIVE_FATAL && !libz_enabled) {
                                skipping("Skipping CAB format(MSZIP) check: %s",
                                    archive_error_string(a));
                                goto finish;
@@ -261,8 +264,8 @@ verify(const char *refname, enum comp_type comp)
        assertEqualIntA(a, ARCHIVE_FORMAT_CAB, archive_format(a));
 
        /* Close the archive. */
-       assertEqualInt(ARCHIVE_OK, archive_read_close(a));
 finish:
+       assertEqualInt(ARCHIVE_OK, archive_read_close(a));
        assertEqualInt(ARCHIVE_OK, archive_read_free(a));
 }
 
index 96473135f0b1f1d3593e54c4ff1664682590c869..fce8de98f4be6934327691033f6bf5b82c7a276a 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
@@ -42,7 +48,6 @@ test_basic(void)
        const void *pv;
        size_t s;
        int64_t o;
-       int r;
 
        extract_reference_file(refname);
        assert((a = archive_read_new()) != NULL);
@@ -61,38 +66,43 @@ test_basic(void)
        assertEqualInt(1179604289, archive_entry_mtime(ae));
        assertEqualInt(18, archive_entry_size(ae));
        failure("archive_read_data() returns number of bytes read");
-       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));
-                       goto finish;
-               }
+       if (libz_enabled) {
+               assertEqualInt(18, archive_read_data(a, buff, 19));
+               assertEqualMem(buff, "hello\nhello\nhello\n", 18);
+       } else {
+               assertEqualInt(ARCHIVE_FATAL, archive_read_data(a, buff, 19));
+               assertEqualString(archive_error_string(a),
+                   "libarchive compiled without deflate support (no libz)");
+               assert(archive_errno(a) != 0);
        }
-       assertEqualInt(18, r);
-       assertEqualMem(buff, "hello\nhello\nhello\n", 18);
        assertA(0 == archive_read_next_header(a, &ae));
        assertEqualString("file2", archive_entry_pathname(ae));
        assertEqualInt(1179605932, archive_entry_mtime(ae));
        failure("file2 has length-at-end, so we shouldn't see a valid size");
        assertEqualInt(0, archive_entry_size_is_set(ae));
-       failure("file2 has a bad CRC, so reading to end should fail");
-       assertEqualInt(ARCHIVE_WARN, archive_read_data(a, buff, 19));
-       assertEqualMem(buff, "hello\nhello\nhello\n", 18);
-        /* Verify the number of files read. */
+       if (libz_enabled) {
+               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));
+               assertEqualMem(buff, "aaaaaaaaaaaaaaaaaaa", 19);
+       } else {
+               assertEqualInt(ARCHIVE_FATAL, archive_read_data(a, buff, 19));
+               assertEqualString(archive_error_string(a),
+                   "libarchive compiled without deflate support (no libz)");
+               assert(archive_errno(a) != 0);
+       }
+       /* Verify the number of files read. */
        failure("the archive file has three files");
        assertEqualInt(3, archive_file_count(a));
        assertA(archive_compression(a) == ARCHIVE_COMPRESSION_NONE);
        assertA(archive_format(a) == ARCHIVE_FORMAT_ZIP);
        assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
-finish:
        assertEqualInt(ARCHIVE_OK, archive_read_free(a));
 }
 
 /*
  * Read Info-ZIP New Unix Extra Field 0x7875 "ux".
- *  Currently sotres Unix UID/GID up to 32 bits.
+ *  Currently stores Unix UID/GID up to 32 bits.
  */
 static void
 test_info_zip_ux(void)
@@ -101,7 +111,6 @@ test_info_zip_ux(void)
        struct archive_entry *ae;
        struct archive *a;
        char *buff[128];
-       int r;
 
        extract_reference_file(refname);
        assert((a = archive_read_new()) != NULL);
@@ -117,27 +126,24 @@ test_info_zip_ux(void)
        assertEqualInt(1001, archive_entry_uid(ae));
        assertEqualInt(1001, archive_entry_gid(ae));
        failure("archive_read_data() returns number of bytes read");
-       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));
-                       goto finish;
-               }
+       if (libz_enabled) {
+               assertEqualInt(18, archive_read_data(a, buff, 19));
+               assertEqualMem(buff, "hello\nhello\nhello\n", 18);
+       } else {
+               assertEqualInt(ARCHIVE_FATAL, archive_read_data(a, buff, 19));
+               assertEqualString(archive_error_string(a),
+                   "libarchive compiled without deflate support (no libz)");
+               assert(archive_errno(a) != 0);
        }
-       assertEqualInt(18, r);
-       assertEqualMem(buff, "hello\nhello\nhello\n", 18);
        assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
 
-        /* Verify the number of files read. */
+       /* Verify the number of files read. */
        failure("the archive file has just one file");
        assertEqualInt(1, archive_file_count(a));
 
        assertA(archive_compression(a) == ARCHIVE_COMPRESSION_NONE);
        assertA(archive_format(a) == ARCHIVE_FORMAT_ZIP);
        assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
-finish:
        assertEqualInt(ARCHIVE_OK, archive_read_free(a));
 }
 
@@ -164,9 +170,15 @@ test_extract_length_at_end(void)
        assert(!archive_entry_size_is_set(ae));
        assertEqualInt(0, archive_entry_size(ae));
 
-       assertEqualIntA(a, ARCHIVE_OK, archive_read_extract(a, ae, 0));
-
-       assertFileContents("hello\x0A", 6, "hello.txt");
+       if (libz_enabled) {
+               assertEqualIntA(a, ARCHIVE_OK, archive_read_extract(a, ae, 0));
+               assertFileContents("hello\x0A", 6, "hello.txt");
+       } else {
+               assertEqualIntA(a, ARCHIVE_FATAL, archive_read_extract(a, ae, 0));
+               assertEqualString(archive_error_string(a),
+                   "libarchive compiled without deflate support (no libz)");
+               assert(archive_errno(a) != 0);
+       }
 
        assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
        assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));