If zlib is not supported, do not run tests to avoid false positives.
Also adjust tests to support latest gzip versions (1.10+) which store
less information for improved reproducibility. The gzip binary is
used as a fallback if zlib is not available.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
const char *name = "test_read_filter_gzip_recursive.gz";
struct archive *a;
- if (!canGzip()) {
- skipping("gzip not available");
+ if (archive_zlib_version() == NULL) {
+ skipping("zlib not available");
return;
}
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
return;
}
- assertEqualIntA(a, ARCHIVE_OK, r);
+ if (r == ARCHIVE_WARN && canGzip())
+ assertEqualString(archive_error_string(a), "Using external gzip program");
+ else
+ assertEqualIntA(a, ARCHIVE_OK, r);
assertEqualInt(ARCHIVE_OK,
archive_read_open_memory(a, archive, sizeof(archive)));
assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae));
assertEqualInt(rbuff[0], 0x1f);
assertEqualInt(rbuff[1], 0x8b);
assertEqualInt(rbuff[2], 0x08);
- assertEqualInt(rbuff[3], 0x08);
- assertEqualInt(rbuff[8], 2); /* RFC 1952 flag for compression level 9 */
- assertEqualString((const char*)rbuff+10, "testorgfilename");
+ /* RFC 1952 flag for compression level 9 */
+ assertEqualInt(rbuff[8], 2);
+ /* External gzip program might not save filename */
+ if (!use_prog || rbuff[3] == 0x08) {
+ assertEqualInt(rbuff[3], 0x08);
+ assertEqualString((const char*)rbuff+10, "testorgfilename");
+ } else {
+ assertEqualInt(rbuff[3], 0x00);
+ }
/* Curiously, this test fails; the test data above compresses
* better at default compression than at level 9. */
archive_entry_free(ae);
assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
assertEqualInt(ARCHIVE_OK, archive_write_free(a));
- failure("Timestamp should be recorded");
- assert(memcmp(buff + 4, "\x00\x00\x00\x00", 4) != 0);
+ /* External gzip program might not save timestamp */
+ if (!use_prog) {
+ failure("Timestamp should be recorded");
+ assert(memcmp(buff + 4, "\x00\x00\x00\x00", 4) != 0);
+ }
/* Test2: set "gzip:!timestamp" option. */
assert((a = archive_write_new()) != NULL);
/* Test C arg - match case-insensitive */
DEFINE_TEST(test_C)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertEmptyFile("test.err");
assertTextFileContents("contents CAPS\n", "test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test L arg - make names lowercase */
DEFINE_TEST(test_L)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("contents b\n", "test_basic/b");
assertTextFileContents("contents c\n", "test_basic/c");
assertTextFileContents("contents CAPS\n", "test_basic/caps");
+#else
+ skipping("zlib not available");
+#endif
}
/* This test just does a basic zip decompression */
DEFINE_TEST(test_basic)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("contents b\n", "test_basic/b");
assertTextFileContents("contents c\n", "test_basic/c");
assertTextFileContents("contents CAPS\n", "test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test d arg - extract to target dir - before zipfile argument */
DEFINE_TEST(test_d_before_zipfile)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("contents b\n", "foobar/test_basic/b");
assertTextFileContents("contents c\n", "foobar/test_basic/c");
assertTextFileContents("contents CAPS\n", "foobar/test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test d arg - extract to target dir - after zipfile argument */
DEFINE_TEST(test_d_after_zipfile)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("contents b\n", "foobar/test_basic/b");
assertTextFileContents("contents c\n", "foobar/test_basic/c");
assertTextFileContents("contents CAPS\n", "foobar/test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test double dash arg - swallow "--" and use next argument as file name */
DEFINE_TEST(test_doubledash)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("contents b\n", "test_basic/b");
assertTextFileContents("contents c\n", "test_basic/c");
assertTextFileContents("contents CAPS\n", "test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test that the glob works */
DEFINE_TEST(test_glob)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("contents b\n", "test_basic/b");
assertFileNotExists("test_basic/c");
assertFileNotExists("test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test j arg - don't make directories */
DEFINE_TEST(test_j)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("contents b\n", "b");
assertTextFileContents("contents c\n", "c");
assertTextFileContents("contents CAPS\n", "CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test n arg - don't overwrite existing files */
DEFINE_TEST(test_n)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("orig b\n", "test_basic/b");
assertTextFileContents("contents c\n", "test_basic/c");
assertTextFileContents("contents CAPS\n", "test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test o arg - overwrite existing files */
DEFINE_TEST(test_o)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("contents b\n", "test_basic/b");
assertTextFileContents("contents c\n", "test_basic/c");
assertTextFileContents("contents CAPS\n", "test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test p arg - Print to stdout */
DEFINE_TEST(test_p)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertEqualInt(0, r);
assertTextFileContents("contents a\ncontents b\ncontents c\ncontents CAPS\n", "test.out");
assertEmptyFile("test.err");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test q arg - Quiet */
DEFINE_TEST(test_q)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("contents b\n", "test_basic/b");
assertTextFileContents("contents c\n", "test_basic/c");
assertTextFileContents("contents CAPS\n", "test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Ensure single-file zips work */
DEFINE_TEST(test_singlefile)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_singlefile.zip";
int r;
assertEmptyFile("test.err");
assertTextFileContents("hello\n", "file.txt");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test t arg - Test zip contents */
DEFINE_TEST(test_t)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertEqualInt(0, r);
assertNonEmptyFile("test.out");
assertEmptyFile("test.err");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test x arg with single exclude path */
DEFINE_TEST(test_x_single)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("contents b\n", "test_basic/b");
assertFileNotExists("test_basic/c");
assertTextFileContents("contents CAPS\n", "test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test x arg with multiple exclude paths */
DEFINE_TEST(test_x_multiple)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertFileNotExists("test_basic/b");
assertFileNotExists("test_basic/c");
assertTextFileContents("contents CAPS\n", "test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test x arg with multiple exclude paths and a d arg afterwards */
DEFINE_TEST(test_x_multiple_with_d)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertFileNotExists("foobar/test_basic/b");
assertFileNotExists("foobar/test_basic/c");
assertTextFileContents("contents CAPS\n", "foobar/test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}