test_read_format_gtar_sparse_skip_entry.c revision 286082
1153816Sdougb/*-
2165071Sdougb * Copyright (c) 2014 Michihiro NAKAJIMA
3153816Sdougb * All rights reserved.
4153816Sdougb *
5153816Sdougb * Redistribution and use in source and binary forms, with or without
6153816Sdougb * modification, are permitted provided that the following conditions
7153816Sdougb * are met:
8153816Sdougb * 1. Redistributions of source code must retain the above copyright
9153816Sdougb *    notice, this list of conditions and the following disclaimer.
10153816Sdougb * 2. Redistributions in binary form must reproduce the above copyright
11153816Sdougb *    notice, this list of conditions and the following disclaimer in the
12153816Sdougb *    documentation and/or other materials provided with the distribution.
13153816Sdougb *
14153816Sdougb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15153816Sdougb * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16153816Sdougb * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17165071Sdougb * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18153816Sdougb * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19153816Sdougb * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20153816Sdougb * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21153816Sdougb * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22165071Sdougb * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23153816Sdougb * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24153816Sdougb */
25153816Sdougb#include "test.h"
26153816Sdougb__FBSDID("$FreeBSD");
27153816Sdougb
28153816Sdougb/*
29153816Sdougb * To test skip a sparse file entry, this test does not read file data.
30153816Sdougb */
31165071SdougbDEFINE_TEST(test_read_format_gtar_sparse_skip_entry)
32153816Sdougb{
33153816Sdougb#ifndef __FreeBSD__ /* Backport test. */
34153816Sdougb	const char *refname = "test_read_format_gtar_sparse_skip_entry.tar.Z.uu";
35153816Sdougb#else
36153816Sdougb	const char *refname = "test_read_format_gtar_sparse_skip_entry.tar.Z";
37153816Sdougb#endif
38153816Sdougb	struct archive *a;
39153816Sdougb	struct archive_entry *ae;
40153816Sdougb	const void *p;
41153816Sdougb	size_t s;
42153816Sdougb	int64_t o;
43153816Sdougb
44165071Sdougb#ifndef __FreeBSD__ /* Backport test. */
45153816Sdougb	copy_reference_file(refname);
46153816Sdougb#else
47153816Sdougb	extract_reference_file(refname);
48165071Sdougb#endif
49153816Sdougb	assert((a = archive_read_new()) != NULL);
50153816Sdougb	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
51153816Sdougb	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
52153816Sdougb	assertEqualIntA(a, ARCHIVE_OK,
53153816Sdougb	    archive_read_open_filename(a, refname, 10240));
54165071Sdougb
55153816Sdougb	/* Verify regular first file. */
56135446Strhodes	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
57153816Sdougb	assertEqualString("a", archive_entry_pathname(ae));
58153816Sdougb	assertEqualInt(10737418244, archive_entry_size(ae));
59135446Strhodes#ifndef __FreeBSD__ /* Backport test. */
60135446Strhodes	assertEqualInt(archive_entry_is_encrypted(ae), 0);
61135446Strhodes	assertEqualIntA(a, archive_read_has_encrypted_entries(a),
62153816Sdougb	    ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
63165071Sdougb#endif
64135446Strhodes
65135446Strhodes	/* Verify regular second file. */
66135446Strhodes	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
67153816Sdougb	assertEqualString("b", archive_entry_pathname(ae));
68153816Sdougb	assertEqualInt(4, archive_entry_size(ae));
69153816Sdougb#ifndef __FreeBSD__ /* Backport test. */
70153816Sdougb	assertEqualInt(archive_entry_is_encrypted(ae), 0);
71153816Sdougb	assertEqualIntA(a, archive_read_has_encrypted_entries(a),
72153816Sdougb	    ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
73153816Sdougb#endif
74153816Sdougb
75153816Sdougb
76135446Strhodes	/* End of archive. */
77153816Sdougb	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
78153816Sdougb
79153816Sdougb	/* Verify archive format. */
80153816Sdougb	assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
81153816Sdougb	assertEqualIntA(a, ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE,
82153816Sdougb	    archive_format(a));
83135446Strhodes
84135446Strhodes	/* Close the archive. */
85135446Strhodes	assertEqualInt(ARCHIVE_OK, archive_read_close(a));
86135446Strhodes	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
87153816Sdougb
88135446Strhodes
89153816Sdougb	/*
90153816Sdougb	 * Read just one block of a sparse file and skip it.
91153816Sdougb	 */
92153816Sdougb	assert((a = archive_read_new()) != NULL);
93135446Strhodes	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
94153816Sdougb	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
95153816Sdougb	assertEqualIntA(a, ARCHIVE_OK,
96153816Sdougb	    archive_read_open_filename(a, refname, 10240));
97153816Sdougb
98153816Sdougb	/* Verify regular first file. */
99153816Sdougb	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
100153816Sdougb	assertEqualString("a", archive_entry_pathname(ae));
101153816Sdougb	assertEqualInt(10737418244, archive_entry_size(ae));
102153816Sdougb#ifndef __FreeBSD__ /* Backport test. */
103153816Sdougb	assertEqualInt(archive_entry_is_encrypted(ae), 0);
104153816Sdougb	assertEqualIntA(a, archive_read_has_encrypted_entries(a),
105153816Sdougb	    ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
106153816Sdougb#endif
107153816Sdougb	assertEqualInt(0, archive_read_data_block(a, &p, &s, &o));
108153816Sdougb	assertEqualInt(4096, s);
109153816Sdougb	assertEqualInt(0, o);
110165071Sdougb
111153816Sdougb
112153816Sdougb	/* Verify regular second file. */
113153816Sdougb	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
114153816Sdougb	assertEqualString("b", archive_entry_pathname(ae));
115153816Sdougb	assertEqualInt(4, archive_entry_size(ae));
116#ifndef __FreeBSD__ /* Backport test. */
117	assertEqualInt(archive_entry_is_encrypted(ae), 0);
118	assertEqualIntA(a, archive_read_has_encrypted_entries(a),
119	    ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
120#endif
121
122
123	/* End of archive. */
124	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
125
126	/* Verify archive format. */
127	assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
128	assertEqualIntA(a, ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE,
129	    archive_format(a));
130
131	/* Close the archive. */
132	assertEqualInt(ARCHIVE_OK, archive_read_close(a));
133	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
134}
135
136