Path: blob/main/contrib/libarchive/cpio/test/test_option_L_upper.c
39507 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2003-2007 Tim Kientzle4* All rights reserved.5*/6#include "test.h"78/* This is a little pointless, as Windows doesn't support symlinks9* (except for the seriously crippled CreateSymbolicLink API) so these10* tests won't run on Windows. */11#if defined(_WIN32) && !defined(__CYGWIN__)12#define CAT "type"13#define SEP "\\"14#else15#define CAT "cat"16#define SEP "/"17#endif1819DEFINE_TEST(test_option_L_upper)20{21FILE *filelist;22int r;2324if (!canSymlink()) {25skipping("Symlink tests");26return;27}2829filelist = fopen("filelist", "w");3031/* Create a file and a symlink to the file. */32assertMakeFile("file", 0644, "1234567890");33fprintf(filelist, "file\n");3435/* Symlink to above file. */36assertMakeSymlink("symlink", "file", 0);37fprintf(filelist, "symlink\n");3839fclose(filelist);4041r = systemf(CAT " filelist | %s -pd copy >copy.out 2>copy.err", testprog);42assertEqualInt(r, 0);43assertTextFileContents("1 block\n", "copy.err");4445failure("Regular -p without -L should preserve symlinks.");46assertIsSymlink("copy/symlink", NULL, 0);4748r = systemf(CAT " filelist | %s -pd -L copy-L >copy-L.out 2>copy-L.err", testprog);49assertEqualInt(r, 0);50assertEmptyFile("copy-L.out");51assertTextFileContents("1 block\n", "copy-L.err");52failure("-pdL should dereference symlinks and turn them into files.");53assertIsReg("copy-L/symlink", -1);5455r = systemf(CAT " filelist | %s -o >archive.out 2>archive.err", testprog);56failure("Error invoking %s -o ", testprog);57assertEqualInt(r, 0);58assertTextFileContents("1 block\n", "archive.err");5960assertMakeDir("unpack", 0755);61assertChdir("unpack");62r = systemf(CAT " .." SEP "archive.out | %s -i >unpack.out 2>unpack.err", testprog);6364failure("Error invoking %s -i", testprog);65assertEqualInt(r, 0);66assertTextFileContents("1 block\n", "unpack.err");67assertChdir("..");6869assertIsSymlink("unpack/symlink", NULL, 0);7071r = systemf(CAT " filelist | %s -oL >archive-L.out 2>archive-L.err", testprog);72failure("Error invoking %s -oL", testprog);73assertEqualInt(r, 0);74assertTextFileContents("1 block\n", "archive-L.err");7576assertMakeDir("unpack-L", 0755);77assertChdir("unpack-L");78r = systemf(CAT " .." SEP "archive-L.out | %s -i >unpack-L.out 2>unpack-L.err", testprog);7980failure("Error invoking %s -i < archive-L.out", testprog);81assertEqualInt(r, 0);82assertTextFileContents("1 block\n", "unpack-L.err");83assertChdir("..");84assertIsReg("unpack-L/symlink", -1);85}868788