From c81efb9912cb83bec7e0c93c8c241be174eed8d2 Mon Sep 17 00:00:00 2001 From: Sebastian Freundt Date: Tue, 10 Jun 2014 12:24:00 +0000 Subject: [PATCH] Tests, provide known-good archive read test. --- Makefile.am | 1 + libarchive/test/CMakeLists.txt | 1 + libarchive/test/test_read_format_warc.c | 82 +++++++++++++++++++ libarchive/test/test_read_format_warc.warc.uu | 23 ++++++ 4 files changed, 107 insertions(+) create mode 100644 libarchive/test/test_read_format_warc.c create mode 100644 libarchive/test/test_read_format_warc.warc.uu diff --git a/Makefile.am b/Makefile.am index f22fb3038..7a8ce4bbc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -441,6 +441,7 @@ libarchive_test_SOURCES= \ libarchive/test/test_read_format_txz.c \ libarchive/test/test_read_format_tz.c \ libarchive/test/test_read_format_ustar_filename.c \ + libarchive/test/test_read_format_warc.c \ libarchive/test/test_read_format_xar.c \ libarchive/test/test_read_format_zip.c \ libarchive/test/test_read_format_zip_comment_stored.c \ diff --git a/libarchive/test/CMakeLists.txt b/libarchive/test/CMakeLists.txt index c5f10c351..42cbf7802 100644 --- a/libarchive/test/CMakeLists.txt +++ b/libarchive/test/CMakeLists.txt @@ -145,6 +145,7 @@ IF(ENABLE_TEST) test_read_format_txz.c test_read_format_tz.c test_read_format_ustar_filename.c + test_read_format_warc.c test_read_format_xar.c test_read_format_zip.c test_read_format_zip_comment_stored.c diff --git a/libarchive/test/test_read_format_warc.c b/libarchive/test/test_read_format_warc.c new file mode 100644 index 000000000..658ab8a6e --- /dev/null +++ b/libarchive/test/test_read_format_warc.c @@ -0,0 +1,82 @@ +/*- + * Copyright (c) 2014 Sebastian Freundt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "test.h" +__FBSDID("$FreeBSD$"); + + +DEFINE_TEST(test_read_format_warc) +{ + char buff[256U]; + const char reffile[] = "test_read_format_warc.warc"; + struct archive_entry *ae; + struct archive *a; + + extract_reference_file(reffile); + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_filename(a, reffile, 10240)); + + /* First Entry */ + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("sometest.txt", archive_entry_pathname(ae)); + assertEqualInt(1402399833, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_uid(ae)); + assertEqualInt(0, archive_entry_gid(ae)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); + assertEqualInt(65, archive_entry_size(ae)); + assertEqualInt(65, archive_read_data(a, buff, sizeof(buff))); + assertEqualMem(buff, "This is a sample text file for libarchive's WARC reader/writer.\n\n", 65); + assertEqualInt(archive_entry_is_encrypted(ae), 0); + assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); + + /* Second Entry */ + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("moretest.txt", archive_entry_pathname(ae)); + assertEqualInt(1402399884, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_uid(ae)); + assertEqualInt(0, archive_entry_gid(ae)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); + assertEqualInt(76, archive_entry_size(ae)); + assertA(76 == archive_read_data(a, buff, sizeof(buff))); + assertEqualMem(buff, "The beauty is that WARC remains ASCII only iff all contents are ASCII only.\n", 76); + assertEqualInt(archive_entry_is_encrypted(ae), 0); + assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); + + /* Test EOF */ + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + assertEqualInt(2, archive_file_count(a)); + + /* Verify archive format. */ + assertEqualIntA(a, ARCHIVE_FILTER_NONE, archive_filter_code(a, 0)); + assertEqualIntA(a, ARCHIVE_FORMAT_WARC, archive_format(a)); + + /* Verify closing and resource freeing */ + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_free(a)); +} diff --git a/libarchive/test/test_read_format_warc.warc.uu b/libarchive/test/test_read_format_warc.warc.uu new file mode 100644 index 000000000..f89592b9b --- /dev/null +++ b/libarchive/test/test_read_format_warc.warc.uu @@ -0,0 +1,23 @@ +begin 644 test_read_format_warc.warc +M5T%20R\Q+C`-"E=!4D,M5'EP93H@=V%R8VEN9F\-"E=!4D,M1&%T93H@,C`Q +M-"TP-BTQ,%0Q,3HS,3HS.%H-"DQA7!E.B!R97-O +M=7)C90T*5T%20RU487)G970M55)).B!F:6QE.B\O2!I +D9F8@86QL(&-O;G1E;G1S(&%R92!!4T-)22!O;FQY+@H-"@T* +` +end -- 2.47.2