Path: blob/main/contrib/libarchive/tar/test/test_option_a.c
39507 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2003-2007 Tim Kientzle4* Copyright (c) 2012 Michihiro NAKAJIMA5* All rights reserved.6*/7#include "test.h"89DEFINE_TEST(test_option_a)10{11size_t s;12char *p;1314/* Create a file. */15assertMakeFile("f", 0644, "a");1617/* Test1: archive it with .tar.Z suffix. */18assertEqualInt(0,19systemf("%s -acf test1.tar.Z f 2>test1.err", testprog));20assertEmptyFile("test1.err");21/* Check that the archive file has a compress signature. */22p = slurpfile(&s, "test1.tar.Z");23assert(s > 2);24failure("The archive should be compressed");25assertEqualMem(p, "\x1f\x9d", 2);26free(p);2728/* Test2: archive it with .taZ suffix. */29assertEqualInt(0,30systemf("%s -acf test2.taZ f 2>test2.err", testprog));31assertEmptyFile("test2.err");32/* Check that the archive file has a compress signature. */33p = slurpfile(&s, "test2.taZ");34assert(s > 2);35failure("The archive should be compressed");36assertEqualMem(p, "\x1f\x9d", 2);37free(p);3839/* Test3: archive it with .tar.Z.uu suffix. */40assertEqualInt(0,41systemf("%s -acf test3.tar.Z.uu f 2>test3.err", testprog));42assertEmptyFile("test3.err");43/* Check that the archive file has a compress signature. */44p = slurpfile(&s, "test3.tar.Z.uu");45assert(s > 12);46failure("The archive should be uuencoded");47assertEqualMem(p, "begin 644 -\n", 12);48free(p);4950/* Test4: archive it with .zip suffix. */51assertEqualInt(0,52systemf("%s -acf test4.zip f 2>test4.err", testprog));53assertEmptyFile("test4.err");54/* Check that the archive file has a compress signature. */55p = slurpfile(&s, "test4.zip");56assert(s > 4);57failure("The archive should be zipped");58assertEqualMem(p, "\x50\x4b\x03\x04", 4);59free(p);6061/* Test5: archive it with .tar.Z suffix and --uuencode option. */62assertEqualInt(0,63systemf("%s -acf test5.tar.Z --uuencode f 2>test5.err",64testprog));65assertEmptyFile("test5.err");66/* Check that the archive file has a compress signature. */67p = slurpfile(&s, "test5.tar.Z");68assert(s > 2);69failure("The archive should be compressed, ignoring --uuencode option");70assertEqualMem(p, "\x1f\x9d", 2);71free(p);7273/* Test6: archive it with .xxx suffix(unknown suffix) and74* --uuencode option. */75assertEqualInt(0,76systemf("%s -acf test6.xxx --uuencode f 2>test6.err",77testprog));78assertEmptyFile("test6.err");79/* Check that the archive file has a compress signature. */80p = slurpfile(&s, "test6.xxx");81assert(s > 12);82failure("The archive should be uuencoded");83assertEqualMem(p, "begin 644 -\n", 12);84free(p);8586/* Test7: archive it with .tar.Z suffix using a long-name option. */87assertEqualInt(0,88systemf("%s --auto-compress -cf test7.tar.Z f 2>test7.err",89testprog));90assertEmptyFile("test7.err");91/* Check that the archive file has a compress signature. */92p = slurpfile(&s, "test7.tar.Z");93assert(s > 2);94failure("The archive should be compressed");95assertEqualMem(p, "\x1f\x9d", 2);96free(p);97}9899100