xref: /freebsd/contrib/libarchive/libarchive/test/test_read_format_gtar_lzma.c (revision b9128a37faafede823eb456aa65a11ac69997284)
1 /*-
2  * Copyright (c) 2008 Miklos Vajna
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  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 #include "test.h"
26 
27 static unsigned char archive[] = {
28 0x5d, 0x0, 0x0, 0x80, 0x0, 0x0, 0x28, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
29 0x17, 0xb, 0xbc, 0x1c, 0x7d, 0x1, 0x95, 0xc0, 0x1d, 0x4a, 0x46, 0x9c,
30 0x1c, 0xc5, 0x8, 0x82, 0x10, 0xed, 0x84, 0xf6, 0xea, 0x7a, 0xfe, 0x63,
31 0x5a, 0x34, 0x5e, 0xf7, 0xc, 0x60, 0xd6, 0x8b, 0xc1, 0x47, 0xaf, 0x11,
32 0x6f, 0x18, 0x94, 0x81, 0x74, 0x8a, 0xf8, 0x47, 0xcc, 0xdd, 0xc0, 0xd9,
33 0x40, 0xa, 0xc3, 0xac, 0x43, 0x47, 0xb5, 0xac, 0x2b, 0x31, 0xd3, 0x6,
34 0xa4, 0x2c, 0x44, 0x80, 0x24, 0x4b, 0xfe, 0x43, 0x22, 0x4e, 0x14, 0x30,
35 0x7a, 0xef, 0x99, 0x6e, 0xf, 0x8b, 0xc1, 0x79, 0x93, 0x88, 0x54, 0x73,
36 0x59, 0x3f, 0xc, 0xfb, 0xee, 0x9c, 0x83, 0x49, 0x93, 0x33, 0xad, 0x44,
37 0xbe, 0x0};
38 
39 DEFINE_TEST(test_read_format_gtar_lzma)
40 {
41 	int r;
42 
43 	struct archive_entry *ae;
44 	struct archive *a;
45 	assert((a = archive_read_new()) != NULL);
46 	assertEqualIntA(a, ARCHIVE_OK,
47 	    archive_read_support_filter_all(a));
48 	r = archive_read_support_filter_lzma(a);
49 	if (r == ARCHIVE_WARN) {
50 		skipping("lzma reading not fully supported on this platform");
51 		assertEqualInt(ARCHIVE_OK, archive_read_free(a));
52 		return;
53 	}
54 
55 	assertEqualIntA(a, ARCHIVE_OK, r);
56 	assertEqualIntA(a, ARCHIVE_OK,
57 	    archive_read_support_format_all(a));
58 	r = archive_read_open_memory2(a, archive, sizeof(archive), 3);
59 	if (r != ARCHIVE_OK) {
60 		skipping("Skipping LZMA compression check: %s",
61 		    archive_error_string(a));
62 		goto finish;
63 	}
64 	assertEqualIntA(a, ARCHIVE_OK,
65 	    archive_read_next_header(a, &ae));
66 	assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_LZMA);
67 	assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_GNUTAR);
68 	assertEqualInt(archive_entry_is_encrypted(ae), 0);
69 	assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
70 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
71 finish:
72 	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
73 }
74 
75 
76