1 /*- 2 * Copyright (c) 2014 Sebastian Freundt 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer 10 * in this position and unchanged. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #include "test.h" 28 __FBSDID("$FreeBSD$"); 29 30 31 DEFINE_TEST(test_read_format_warc) 32 { 33 char buff[256U]; 34 const char reffile[] = "test_read_format_warc.warc"; 35 struct archive_entry *ae; 36 struct archive *a; 37 38 extract_reference_file(reffile); 39 assert((a = archive_read_new()) != NULL); 40 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); 41 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); 42 assertEqualIntA(a, ARCHIVE_OK, 43 archive_read_open_filename(a, reffile, 10240)); 44 45 /* First Entry */ 46 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 47 assertEqualString("sometest.txt", archive_entry_pathname(ae)); 48 assertEqualInt(1402399833, archive_entry_mtime(ae)); 49 assertEqualInt(0, archive_entry_uid(ae)); 50 assertEqualInt(0, archive_entry_gid(ae)); 51 assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 52 assertEqualInt(65, archive_entry_size(ae)); 53 assertEqualInt(65, archive_read_data(a, buff, sizeof(buff))); 54 assertEqualMem(buff, "This is a sample text file for libarchive's WARC reader/writer.\n\n", 65); 55 assertEqualInt(archive_entry_is_encrypted(ae), 0); 56 assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 57 58 /* Second Entry */ 59 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 60 assertEqualString("moretest.txt", archive_entry_pathname(ae)); 61 assertEqualInt(1402399884, archive_entry_mtime(ae)); 62 assertEqualInt(0, archive_entry_uid(ae)); 63 assertEqualInt(0, archive_entry_gid(ae)); 64 assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 65 assertEqualInt(76, archive_entry_size(ae)); 66 assertA(76 == archive_read_data(a, buff, sizeof(buff))); 67 assertEqualMem(buff, "The beauty is that WARC remains ASCII only iff all contents are ASCII only.\n", 76); 68 assertEqualInt(archive_entry_is_encrypted(ae), 0); 69 assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 70 71 /* Test EOF */ 72 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); 73 assertEqualInt(2, archive_file_count(a)); 74 75 /* Verify archive format. */ 76 assertEqualIntA(a, ARCHIVE_FILTER_NONE, archive_filter_code(a, 0)); 77 assertEqualIntA(a, ARCHIVE_FORMAT_WARC, archive_format(a)); 78 79 /* Verify closing and resource freeing */ 80 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); 81 assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 82 } 83