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