Path: blob/main/contrib/libarchive/cpio/test/test_option_0.c
39536 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2003-2010 Tim Kientzle4* All rights reserved.5*/6#include "test.h"78DEFINE_TEST(test_option_0)9{10FILE *filelist;11int r;1213assertUmask(0);1415/* Create a few files. */16assertMakeFile("file1", 0644, "1234567890");17assertMakeFile("file2", 0644, "1234567890");18assertMakeFile("file3", 0644, "1234567890");19assertMakeFile("file4", 0644, "1234567890");2021/* Create a file list of filenames with varying end-of-line. */22filelist = fopen("filelist", "wb");23assertEqualInt(fwrite("file1\x0a", 1, 6, filelist), 6);24assertEqualInt(fwrite("file2\x0d", 1, 6, filelist), 6);25assertEqualInt(fwrite("file3\x0a\x0d", 1, 7, filelist), 7);26assertEqualInt(fwrite("file4", 1, 5, filelist), 5);27fclose(filelist);2829/* Create a file list of null-delimited names. */30filelist = fopen("filelistNull", "wb");31assertEqualInt(fwrite("file1\0", 1, 6, filelist), 6);32assertEqualInt(fwrite("file2\0", 1, 6, filelist), 6);33assertEqualInt(fwrite("file3\0", 1, 6, filelist), 6);34assertEqualInt(fwrite("file4", 1, 5, filelist), 5);35fclose(filelist);3637assertUmask(022);3839/* Pack up using the file list with text line endings. */40r = systemf("%s -o < filelist > archive 2> stderr1.txt", testprog);41assertEqualInt(r, 0);4243/* Extract into a new dir. */44assertMakeDir("copy", 0775);45assertChdir("copy");46r = systemf("%s -i < ../archive > stdout3.txt 2> stderr3.txt", testprog);47assertEqualInt(r, 0);4849/* Verify the files. */50assertIsReg("file1", 0644);51assertIsReg("file2", 0644);52assertIsReg("file3", 0644);53assertIsReg("file4", 0644);5455assertChdir("..");5657/* Pack up using the file list with nulls. */58r = systemf("%s -o0 < filelistNull > archiveNull 2> stderr2.txt", testprog);59assertEqualInt(r, 0);6061/* Extract into a new dir. */62assertMakeDir("copyNull", 0775);63assertChdir("copyNull");64r = systemf("%s -i < ../archiveNull > stdout4.txt 2> stderr4.txt", testprog);65assertEqualInt(r, 0);6667/* Verify the files. */68assertIsReg("file1", 0644);69assertIsReg("file2", 0644);70assertIsReg("file3", 0644);71assertIsReg("file4", 0644);72}737475