Skip to content

Commit c81efb9

Browse files
committed
Tests, provide known-good archive read test.
1 parent adc91b6 commit c81efb9

4 files changed

Lines changed: 107 additions & 0 deletions

File tree

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ libarchive_test_SOURCES= \
441441
libarchive/test/test_read_format_txz.c \
442442
libarchive/test/test_read_format_tz.c \
443443
libarchive/test/test_read_format_ustar_filename.c \
444+
libarchive/test/test_read_format_warc.c \
444445
libarchive/test/test_read_format_xar.c \
445446
libarchive/test/test_read_format_zip.c \
446447
libarchive/test/test_read_format_zip_comment_stored.c \

libarchive/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ IF(ENABLE_TEST)
145145
test_read_format_txz.c
146146
test_read_format_tz.c
147147
test_read_format_ustar_filename.c
148+
test_read_format_warc.c
148149
test_read_format_xar.c
149150
test_read_format_zip.c
150151
test_read_format_zip_comment_stored.c
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
begin 644 test_read_format_warc.warc
2+
M5T%20R\Q+C`-"E=!4D,M5'EP93H@=V%R8VEN9F\-"E=!4D,M1&%T93H@,C`Q
3+
M-"TP-BTQ,%0Q,3HS,3HS.%H-"DQA<W0M36]D:69I960Z(#(P,30M,#8M,3!4
4+
M,3$Z,S$Z,SA:#0I705)#+5)E8V]R9"U)1#H@/'5R;CIU=6ED.C,U-68Y-V)B
5+
M+35C,C@M-&-D9"UB,3=A+6(P.#@W9F(Q8S(X8SX-"D-O;G1E;G0M5'EP93H@
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