xref: /freebsd/contrib/libarchive/tar/test/test_option_xz.c (revision bd66c1b43e33540205dbc1187c2f2a15c58b57ba)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2003-2007 Tim Kientzle
5  * Copyright (c) 2012 Michihiro NAKAJIMA
6  * All rights reserved.
7  */
8 #include "test.h"
9 
DEFINE_TEST(test_option_xz)10 DEFINE_TEST(test_option_xz)
11 {
12 	char *p;
13 	int r;
14 	size_t s;
15 
16 	/* Create a file. */
17 	assertMakeFile("f", 0644, "a");
18 
19 	/* Archive it with xz compression. */
20 	r = systemf("%s -cf - --xz f >archive.out 2>archive.err",
21 	    testprog);
22 	p = slurpfile(&s, "archive.err");
23 	p[s] = '\0';
24 	if (r != 0) {
25 		if (strstr(p, "Unsupported compression") != NULL) {
26 			skipping("This version of bsdtar was compiled "
27 			    "without xz support");
28 			goto done;
29 		}
30 		failure("--xz option is broken");
31 		assertEqualInt(r, 0);
32 		goto done;
33 	}
34 	free(p);
35 	/* Check that the archive file has an xz signature. */
36 	p = slurpfile(&s, "archive.out");
37 	assert(s > 2);
38 	assertEqualMem(p, "\xFD\x37\x7A\x58\x5A\x00", 6);
39 done:
40 	free(p);
41 }
42