1dca77083Schristos /* 2dca77083Schristos * Copyright (c) 2003-2017 Tim Kientzle 3dca77083Schristos * All rights reserved. 4dca77083Schristos * 5dca77083Schristos * Redistribution and use in source and binary forms, with or without 6dca77083Schristos * modification, are permitted provided that the following conditions 7dca77083Schristos * are met: 8dca77083Schristos * 1. Redistributions of source code must retain the above copyright 9dca77083Schristos * notice, this list of conditions and the following disclaimer. 10dca77083Schristos * 2. Redistributions in binary form must reproduce the above copyright 11dca77083Schristos * notice, this list of conditions and the following disclaimer in the 12dca77083Schristos * documentation and/or other materials provided with the distribution. 13dca77083Schristos * 14dca77083Schristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15dca77083Schristos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16dca77083Schristos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17dca77083Schristos * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18dca77083Schristos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19dca77083Schristos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20dca77083Schristos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21dca77083Schristos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22dca77083Schristos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23dca77083Schristos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24dca77083Schristos */ 25dca77083Schristos 26dca77083Schristos #ifndef TEST_COMMON_H 27dca77083Schristos #define TEST_COMMON_H 28dca77083Schristos 29dca77083Schristos /* 30dca77083Schristos * The goal of this file (and the matching test.c) is to 31dca77083Schristos * simplify the very repetitive test-*.c test programs. 32dca77083Schristos */ 33dca77083Schristos #if defined(HAVE_CONFIG_H) 34dca77083Schristos /* Most POSIX platforms use the 'configure' script to build config.h */ 35dca77083Schristos #include "config.h" 36dca77083Schristos #elif defined(__FreeBSD__) 37dca77083Schristos /* Building as part of FreeBSD system requires a pre-built config.h. */ 38dca77083Schristos #include "config_freebsd.h" 39dca77083Schristos #elif defined(__NetBSD__) 40dca77083Schristos /* Building as part of NetBSD system requires a pre-built config.h. */ 41dca77083Schristos #include "config_netbsd.h" 42dca77083Schristos #elif defined(_WIN32) && !defined(__CYGWIN__) 43dca77083Schristos /* Win32 can't run the 'configure' script. */ 44dca77083Schristos #include "config_windows.h" 45dca77083Schristos #else 46dca77083Schristos /* Warn if the library hasn't been (automatically or manually) configured. */ 47dca77083Schristos #error Oops: No config.h and no pre-built configuration in test.h. 48dca77083Schristos #endif 49dca77083Schristos 50dca77083Schristos #include <sys/types.h> /* Windows requires this before sys/stat.h */ 51*ed66d5dbSchristos #if !HAVE_SUSECONDS_T 52*ed66d5dbSchristos #define suseconds_t long 53*ed66d5dbSchristos #endif 54dca77083Schristos #include <sys/stat.h> 55dca77083Schristos 56dca77083Schristos #if HAVE_DIRENT_H 57dca77083Schristos #include <dirent.h> 58dca77083Schristos #endif 59dca77083Schristos #ifdef HAVE_DIRECT_H 60dca77083Schristos #include <direct.h> 61dca77083Schristos #define dirent direct 62dca77083Schristos #endif 63dca77083Schristos #include <errno.h> 64dca77083Schristos #include <fcntl.h> 65dca77083Schristos #ifdef HAVE_IO_H 66dca77083Schristos #include <io.h> 67dca77083Schristos #endif 68dca77083Schristos #ifdef HAVE_STDINT_H 69dca77083Schristos #include <stdint.h> 70dca77083Schristos #endif 71dca77083Schristos #include <stdio.h> 72dca77083Schristos #include <stdlib.h> 73dca77083Schristos #include <string.h> 74dca77083Schristos #include <ctype.h> 75dca77083Schristos #include <time.h> 76dca77083Schristos #ifdef HAVE_UNISTD_H 77dca77083Schristos #include <unistd.h> 78dca77083Schristos #endif 79dca77083Schristos #include <wchar.h> 80dca77083Schristos #ifdef HAVE_ACL_LIBACL_H 81dca77083Schristos #include <acl/libacl.h> 82dca77083Schristos #endif 83dca77083Schristos #ifdef HAVE_SYS_ACL_H 84dca77083Schristos #include <sys/acl.h> 85dca77083Schristos #endif 86dca77083Schristos #ifdef HAVE_SYS_RICHACL_H 87dca77083Schristos #include <sys/richacl.h> 88dca77083Schristos #endif 89dca77083Schristos #ifdef HAVE_WINDOWS_H 90dca77083Schristos #define NOCRYPT 91dca77083Schristos #include <windows.h> 92dca77083Schristos #include <winioctl.h> 93dca77083Schristos #endif 94dca77083Schristos 95dca77083Schristos /* 96dca77083Schristos * System-specific tweaks. We really want to minimize these 97dca77083Schristos * as much as possible, since they make it harder to understand 98dca77083Schristos * the mainline code. 99dca77083Schristos */ 100dca77083Schristos 101dca77083Schristos /* Windows (including Visual Studio and MinGW but not Cygwin) */ 102dca77083Schristos #if defined(_WIN32) && !defined(__CYGWIN__) 103dca77083Schristos #if !defined(__BORLANDC__) 104dca77083Schristos #undef chdir 105dca77083Schristos #define chdir _chdir 106dca77083Schristos #define strdup _strdup 107dca77083Schristos #endif 108dca77083Schristos #endif 109dca77083Schristos 110dca77083Schristos /* Visual Studio */ 111dca77083Schristos #if defined(_MSC_VER) && _MSC_VER < 1900 112dca77083Schristos #define snprintf sprintf_s 113dca77083Schristos #endif 114dca77083Schristos 115dca77083Schristos #if defined(__BORLANDC__) 116dca77083Schristos #pragma warn -8068 /* Constant out of range in comparison. */ 117dca77083Schristos #endif 118dca77083Schristos 11997f7d7b6Schristos 120eb896107Schristos #if defined(__GNUC__) && (__GNUC__ > 2 || \ 121eb896107Schristos (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)) 12297f7d7b6Schristos # ifdef __MINGW_PRINTF_FORMAT 12397f7d7b6Schristos # define __LA_PRINTF_FORMAT __MINGW_PRINTF_FORMAT 12497f7d7b6Schristos # else 12597f7d7b6Schristos # define __LA_PRINTF_FORMAT __printf__ 12697f7d7b6Schristos # endif 12797f7d7b6Schristos # define __LA_PRINTFLIKE(f,a) __attribute__((__format__(__LA_PRINTF_FORMAT, f, a))) 128eb896107Schristos #else 129eb896107Schristos # define __LA_PRINTFLIKE(f,a) 130eb896107Schristos #endif 131eb896107Schristos 132dca77083Schristos /* Haiku OS and QNX */ 133dca77083Schristos #if defined(__HAIKU__) || defined(__QNXNTO__) 134dca77083Schristos /* Haiku and QNX have typedefs in stdint.h (needed for int64_t) */ 135dca77083Schristos #include <stdint.h> 136dca77083Schristos #endif 137dca77083Schristos 138dca77083Schristos #ifndef O_BINARY 139dca77083Schristos #define O_BINARY 0 140dca77083Schristos #endif 141dca77083Schristos 142dca77083Schristos #ifndef __LIBARCHIVE_TEST_COMMON 143dca77083Schristos #define __LIBARCHIVE_TEST_COMMON 144dca77083Schristos #endif 145dca77083Schristos 146dca77083Schristos #include "archive_platform_acl.h" 147dca77083Schristos #define ARCHIVE_TEST_ACL_TYPE_POSIX1E 1 148dca77083Schristos #define ARCHIVE_TEST_ACL_TYPE_NFS4 2 149dca77083Schristos 150dca77083Schristos #include "archive_platform_xattr.h" 151dca77083Schristos 152dca77083Schristos /* 153dca77083Schristos * Redefine DEFINE_TEST for use in defining the test functions. 154dca77083Schristos */ 155dca77083Schristos #undef DEFINE_TEST 156dca77083Schristos #define DEFINE_TEST(name) void name(void); void name(void) 157dca77083Schristos 158dca77083Schristos /* An implementation of the standard assert() macro */ 159dca77083Schristos #define assert(e) assertion_assert(__FILE__, __LINE__, (e), #e, NULL) 160dca77083Schristos /* chdir() and error if it fails */ 161dca77083Schristos #define assertChdir(path) \ 162dca77083Schristos assertion_chdir(__FILE__, __LINE__, path) 16397f7d7b6Schristos /* change file/directory permissions and errors if it fails */ 16497f7d7b6Schristos #define assertChmod(pathname, mode) \ 16597f7d7b6Schristos assertion_chmod(__FILE__, __LINE__, pathname, mode) 166dca77083Schristos /* Assert two files have the same file flags */ 167dca77083Schristos #define assertEqualFflags(patha, pathb) \ 168dca77083Schristos assertion_compare_fflags(__FILE__, __LINE__, patha, pathb, 0) 169dca77083Schristos /* Assert two integers are the same. Reports value of each one if not. */ 170dca77083Schristos #define assertEqualInt(v1,v2) \ 171dca77083Schristos assertion_equal_int(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) 17297f7d7b6Schristos #define assertEqualAddress(v1,v2) \ 17397f7d7b6Schristos assertion_equal_address(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) 174dca77083Schristos /* Assert two strings are the same. Reports value of each one if not. */ 175dca77083Schristos #define assertEqualString(v1,v2) \ 176dca77083Schristos assertion_equal_string(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL, 0) 177dca77083Schristos #define assertEqualUTF8String(v1,v2) \ 178dca77083Schristos assertion_equal_string(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL, 1) 179dca77083Schristos /* As above, but v1 and v2 are wchar_t * */ 180dca77083Schristos #define assertEqualWString(v1,v2) \ 181dca77083Schristos assertion_equal_wstring(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) 182dca77083Schristos /* As above, but raw blocks of bytes. */ 183dca77083Schristos #define assertEqualMem(v1, v2, l) \ 184dca77083Schristos assertion_equal_mem(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (l), #l, NULL) 185dca77083Schristos /* Assert that memory is full of a specified byte */ 186dca77083Schristos #define assertMemoryFilledWith(v1, l, b) \ 187dca77083Schristos assertion_memory_filled_with(__FILE__, __LINE__, (v1), #v1, (l), #l, (b), #b, NULL) 188dca77083Schristos /* Assert two files are the same. */ 189dca77083Schristos #define assertEqualFile(f1, f2) \ 190dca77083Schristos assertion_equal_file(__FILE__, __LINE__, (f1), (f2)) 191dca77083Schristos /* Assert that a file is empty. */ 192dca77083Schristos #define assertEmptyFile(pathname) \ 193dca77083Schristos assertion_empty_file(__FILE__, __LINE__, (pathname)) 194dca77083Schristos /* Assert that a file is not empty. */ 195dca77083Schristos #define assertNonEmptyFile(pathname) \ 196dca77083Schristos assertion_non_empty_file(__FILE__, __LINE__, (pathname)) 197dca77083Schristos #define assertFileAtime(pathname, sec, nsec) \ 198dca77083Schristos assertion_file_atime(__FILE__, __LINE__, pathname, sec, nsec) 199dca77083Schristos #define assertFileAtimeRecent(pathname) \ 200dca77083Schristos assertion_file_atime_recent(__FILE__, __LINE__, pathname) 201dca77083Schristos #define assertFileBirthtime(pathname, sec, nsec) \ 202dca77083Schristos assertion_file_birthtime(__FILE__, __LINE__, pathname, sec, nsec) 203dca77083Schristos #define assertFileBirthtimeRecent(pathname) \ 204dca77083Schristos assertion_file_birthtime_recent(__FILE__, __LINE__, pathname) 205dca77083Schristos /* Assert that a file exists; supports printf-style arguments. */ 206dca77083Schristos #define assertFileExists(pathname) \ 207dca77083Schristos assertion_file_exists(__FILE__, __LINE__, pathname) 208dca77083Schristos /* Assert that a file exists. */ 209dca77083Schristos #define assertFileNotExists(pathname) \ 210dca77083Schristos assertion_file_not_exists(__FILE__, __LINE__, pathname) 211dca77083Schristos /* Assert that file contents match a string. */ 212dca77083Schristos #define assertFileContents(data, data_size, pathname) \ 213dca77083Schristos assertion_file_contents(__FILE__, __LINE__, data, data_size, pathname) 214dca77083Schristos /* Verify that a file does not contain invalid strings */ 215dca77083Schristos #define assertFileContainsNoInvalidStrings(pathname, strings) \ 216dca77083Schristos assertion_file_contains_no_invalid_strings(__FILE__, __LINE__, pathname, strings) 217dca77083Schristos #define assertFileMtime(pathname, sec, nsec) \ 218dca77083Schristos assertion_file_mtime(__FILE__, __LINE__, pathname, sec, nsec) 219dca77083Schristos #define assertFileMtimeRecent(pathname) \ 220dca77083Schristos assertion_file_mtime_recent(__FILE__, __LINE__, pathname) 221dca77083Schristos #define assertFileNLinks(pathname, nlinks) \ 222dca77083Schristos assertion_file_nlinks(__FILE__, __LINE__, pathname, nlinks) 223dca77083Schristos #define assertFileSize(pathname, size) \ 224dca77083Schristos assertion_file_size(__FILE__, __LINE__, pathname, size) 225dca77083Schristos #define assertFileMode(pathname, mode) \ 226dca77083Schristos assertion_file_mode(__FILE__, __LINE__, pathname, mode) 227dca77083Schristos #define assertTextFileContents(text, pathname) \ 228dca77083Schristos assertion_text_file_contents(__FILE__, __LINE__, text, pathname) 229dca77083Schristos #define assertFileContainsLinesAnyOrder(pathname, lines) \ 230dca77083Schristos assertion_file_contains_lines_any_order(__FILE__, __LINE__, pathname, lines) 231dca77083Schristos #define assertIsDir(pathname, mode) \ 232dca77083Schristos assertion_is_dir(__FILE__, __LINE__, pathname, mode) 233dca77083Schristos #define assertIsHardlink(path1, path2) \ 234dca77083Schristos assertion_is_hardlink(__FILE__, __LINE__, path1, path2) 235dca77083Schristos #define assertIsNotHardlink(path1, path2) \ 236dca77083Schristos assertion_is_not_hardlink(__FILE__, __LINE__, path1, path2) 237dca77083Schristos #define assertIsReg(pathname, mode) \ 238dca77083Schristos assertion_is_reg(__FILE__, __LINE__, pathname, mode) 239dca77083Schristos #define assertIsSymlink(pathname, contents, isdir) \ 240dca77083Schristos assertion_is_symlink(__FILE__, __LINE__, pathname, contents, isdir) 241dca77083Schristos /* Create a directory, report error if it fails. */ 242dca77083Schristos #define assertMakeDir(dirname, mode) \ 243dca77083Schristos assertion_make_dir(__FILE__, __LINE__, dirname, mode) 244dca77083Schristos #define assertMakeFile(path, mode, contents) \ 245dca77083Schristos assertion_make_file(__FILE__, __LINE__, path, mode, -1, contents) 246dca77083Schristos #define assertMakeBinFile(path, mode, csize, contents) \ 247dca77083Schristos assertion_make_file(__FILE__, __LINE__, path, mode, csize, contents) 248dca77083Schristos #define assertMakeHardlink(newfile, oldfile) \ 249dca77083Schristos assertion_make_hardlink(__FILE__, __LINE__, newfile, oldfile) 250dca77083Schristos #define assertMakeSymlink(newfile, linkto, targetIsDir) \ 251dca77083Schristos assertion_make_symlink(__FILE__, __LINE__, newfile, linkto, targetIsDir) 252dca77083Schristos #define assertSetNodump(path) \ 253dca77083Schristos assertion_set_nodump(__FILE__, __LINE__, path) 254dca77083Schristos #define assertUmask(mask) \ 255dca77083Schristos assertion_umask(__FILE__, __LINE__, mask) 256dca77083Schristos /* Assert that two files have unequal file flags */ 257dca77083Schristos #define assertUnequalFflags(patha, pathb) \ 258dca77083Schristos assertion_compare_fflags(__FILE__, __LINE__, patha, pathb, 1) 259dca77083Schristos #define assertUtimes(pathname, atime, atime_nsec, mtime, mtime_nsec) \ 260dca77083Schristos assertion_utimes(__FILE__, __LINE__, pathname, atime, atime_nsec, mtime, mtime_nsec) 261dca77083Schristos #ifndef PROGRAM 262dca77083Schristos #define assertEntrySetAcls(entry, acls, count) \ 263dca77083Schristos assertion_entry_set_acls(__FILE__, __LINE__, entry, acls, count) 264dca77083Schristos #define assertEntryCompareAcls(entry, acls, count, type, mode) \ 265dca77083Schristos assertion_entry_compare_acls(__FILE__, __LINE__, entry, acls, count, type, mode) 266dca77083Schristos #endif 267dca77083Schristos 268dca77083Schristos /* 269dca77083Schristos * This would be simple with C99 variadic macros, but I don't want to 270dca77083Schristos * require that. Instead, I insert a function call before each 271dca77083Schristos * skipping() call to pass the file and line information down. Crude, 272dca77083Schristos * but effective. 273dca77083Schristos */ 274dca77083Schristos #define skipping \ 275dca77083Schristos skipping_setup(__FILE__, __LINE__);test_skipping 276dca77083Schristos 277dca77083Schristos /* Function declarations. These are defined in test_utility.c. */ 278eb896107Schristos void failure(const char *fmt, ...) __LA_PRINTFLIKE(1, 2); 279dca77083Schristos int assertion_assert(const char *, int, int, const char *, void *); 280dca77083Schristos int assertion_chdir(const char *, int, const char *); 28197f7d7b6Schristos int assertion_chmod(const char *, int, const char *, int); 282dca77083Schristos int assertion_compare_fflags(const char *, int, const char *, const char *, 283dca77083Schristos int); 284dca77083Schristos int assertion_empty_file(const char *, int, const char *); 285dca77083Schristos int assertion_equal_file(const char *, int, const char *, const char *); 286dca77083Schristos int assertion_equal_int(const char *, int, long long, const char *, long long, const char *, void *); 28797f7d7b6Schristos int assertion_equal_address(const char *, int, const void *, const char *, const void *, const char *, void *); 288dca77083Schristos int assertion_equal_mem(const char *, int, const void *, const char *, const void *, const char *, size_t, const char *, void *); 289dca77083Schristos int assertion_memory_filled_with(const char *, int, const void *, const char *, size_t, const char *, char, const char *, void *); 290dca77083Schristos int assertion_equal_string(const char *, int, const char *v1, const char *, const char *v2, const char *, void *, int); 291dca77083Schristos int assertion_equal_wstring(const char *, int, const wchar_t *v1, const char *, const wchar_t *v2, const char *, void *); 292dca77083Schristos int assertion_file_atime(const char *, int, const char *, long, long); 293dca77083Schristos int assertion_file_atime_recent(const char *, int, const char *); 294dca77083Schristos int assertion_file_birthtime(const char *, int, const char *, long, long); 295dca77083Schristos int assertion_file_birthtime_recent(const char *, int, const char *); 296dca77083Schristos int assertion_file_contains_lines_any_order(const char *, int, const char *, const char **); 297dca77083Schristos int assertion_file_contains_no_invalid_strings(const char *, int, const char *, const char **); 298dca77083Schristos int assertion_file_contents(const char *, int, const void *, int, const char *); 299dca77083Schristos int assertion_file_exists(const char *, int, const char *); 300dca77083Schristos int assertion_file_mode(const char *, int, const char *, int); 301dca77083Schristos int assertion_file_mtime(const char *, int, const char *, long, long); 302dca77083Schristos int assertion_file_mtime_recent(const char *, int, const char *); 303dca77083Schristos int assertion_file_nlinks(const char *, int, const char *, int); 304dca77083Schristos int assertion_file_not_exists(const char *, int, const char *); 305dca77083Schristos int assertion_file_size(const char *, int, const char *, long); 306dca77083Schristos int assertion_is_dir(const char *, int, const char *, int); 307dca77083Schristos int assertion_is_hardlink(const char *, int, const char *, const char *); 308dca77083Schristos int assertion_is_not_hardlink(const char *, int, const char *, const char *); 309dca77083Schristos int assertion_is_reg(const char *, int, const char *, int); 310dca77083Schristos int assertion_is_symlink(const char *, int, const char *, const char *, int); 311dca77083Schristos int assertion_make_dir(const char *, int, const char *, int); 312dca77083Schristos int assertion_make_file(const char *, int, const char *, int, int, const void *); 313dca77083Schristos int assertion_make_hardlink(const char *, int, const char *newpath, const char *); 314dca77083Schristos int assertion_make_symlink(const char *, int, const char *newpath, const char *, int); 315dca77083Schristos int assertion_non_empty_file(const char *, int, const char *); 316dca77083Schristos int assertion_set_nodump(const char *, int, const char *); 317dca77083Schristos int assertion_text_file_contents(const char *, int, const char *buff, const char *f); 318dca77083Schristos int assertion_umask(const char *, int, int); 319*ed66d5dbSchristos int assertion_utimes(const char *, int, const char *, time_t, suseconds_t, time_t, suseconds_t); 320dca77083Schristos int assertion_version(const char*, int, const char *, const char *); 321dca77083Schristos 322dca77083Schristos void skipping_setup(const char *, int); 323eb896107Schristos void test_skipping(const char *fmt, ...) __LA_PRINTFLIKE(1, 2); 324dca77083Schristos 325dca77083Schristos /* Like sprintf, then system() */ 326eb896107Schristos int systemf(const char *fmt, ...) __LA_PRINTFLIKE(1, 2); 327dca77083Schristos 328dca77083Schristos /* Delay until time() returns a value after this. */ 329dca77083Schristos void sleepUntilAfter(time_t); 330dca77083Schristos 331dca77083Schristos /* Return true if this platform can create symlinks. */ 332dca77083Schristos int canSymlink(void); 333dca77083Schristos 334dca77083Schristos /* Return true if this platform can run the "bzip2" program. */ 335dca77083Schristos int canBzip2(void); 336dca77083Schristos 337dca77083Schristos /* Return true if this platform can run the "grzip" program. */ 338dca77083Schristos int canGrzip(void); 339dca77083Schristos 340dca77083Schristos /* Return true if this platform can run the "gzip" program. */ 341dca77083Schristos int canGzip(void); 342dca77083Schristos 343dca77083Schristos /* Return true if this platform can run the specified command. */ 344dca77083Schristos int canRunCommand(const char *); 345dca77083Schristos 346dca77083Schristos /* Return true if this platform can run the "lrzip" program. */ 347dca77083Schristos int canLrzip(void); 348dca77083Schristos 349dca77083Schristos /* Return true if this platform can run the "lz4" program. */ 350dca77083Schristos int canLz4(void); 351dca77083Schristos 352dca77083Schristos /* Return true if this platform can run the "zstd" program. */ 353dca77083Schristos int canZstd(void); 354dca77083Schristos 355dca77083Schristos /* Return true if this platform can run the "lzip" program. */ 356dca77083Schristos int canLzip(void); 357dca77083Schristos 358dca77083Schristos /* Return true if this platform can run the "lzma" program. */ 359dca77083Schristos int canLzma(void); 360dca77083Schristos 361dca77083Schristos /* Return true if this platform can run the "lzop" program. */ 362dca77083Schristos int canLzop(void); 363dca77083Schristos 364dca77083Schristos /* Return true if this platform can run the "xz" program. */ 365dca77083Schristos int canXz(void); 366dca77083Schristos 367dca77083Schristos /* Return true if this filesystem can handle nodump flags. */ 368dca77083Schristos int canNodump(void); 369dca77083Schristos 370dca77083Schristos /* Set test ACLs */ 371dca77083Schristos int setTestAcl(const char *path); 372dca77083Schristos 373dca77083Schristos /* Get extended attribute */ 374dca77083Schristos void *getXattr(const char *, const char *, size_t *); 375dca77083Schristos 376dca77083Schristos /* Set extended attribute */ 377dca77083Schristos int setXattr(const char *, const char *, const void *, size_t); 378dca77083Schristos 379dca77083Schristos /* Return true if the file has large i-node number(>0xffffffff). */ 380dca77083Schristos int is_LargeInode(const char *); 381dca77083Schristos 382dca77083Schristos #if ARCHIVE_ACL_SUNOS 383dca77083Schristos /* Fetch ACLs on Solaris using acl() or facl() */ 384dca77083Schristos void *sunacl_get(int cmd, int *aclcnt, int fd, const char *path); 385dca77083Schristos #endif 386dca77083Schristos 387dca77083Schristos /* Suck file into string allocated via malloc(). Call free() when done. */ 388dca77083Schristos /* Supports printf-style args: slurpfile(NULL, "%s/myfile", refdir); */ 389eb896107Schristos char *slurpfile(size_t *, const char *fmt, ...) __LA_PRINTFLIKE(2, 3); 390dca77083Schristos 391dca77083Schristos /* Dump block of bytes to a file. */ 392dca77083Schristos void dumpfile(const char *filename, void *, size_t); 393dca77083Schristos 394dca77083Schristos /* Extracts named reference file to the current directory. */ 395dca77083Schristos void extract_reference_file(const char *); 396dca77083Schristos /* Copies named reference file to the current directory. */ 397dca77083Schristos void copy_reference_file(const char *); 398dca77083Schristos 399dca77083Schristos /* Extracts a list of files to the current directory. 400dca77083Schristos * List must be NULL terminated. 401dca77083Schristos */ 402dca77083Schristos void extract_reference_files(const char **); 403dca77083Schristos 404dca77083Schristos /* Subtract umask from mode */ 405dca77083Schristos mode_t umasked(mode_t expected_mode); 406dca77083Schristos 407dca77083Schristos /* Path to working directory for current test */ 408dca77083Schristos extern const char *testworkdir; 409dca77083Schristos 410dca77083Schristos #ifndef PROGRAM 411dca77083Schristos /* 412dca77083Schristos * Special interfaces for libarchive test harness. 413dca77083Schristos */ 414dca77083Schristos 415dca77083Schristos #include "archive.h" 416dca77083Schristos #include "archive_entry.h" 417dca77083Schristos 418dca77083Schristos /* ACL structure */ 419dca77083Schristos struct archive_test_acl_t { 420dca77083Schristos int type; /* Type of ACL */ 421dca77083Schristos int permset; /* Permissions for this class of users. */ 422dca77083Schristos int tag; /* Owner, User, Owning group, group, other, etc. */ 423dca77083Schristos int qual; /* GID or UID of user/group, depending on tag. */ 424dca77083Schristos const char *name; /* Name of user/group, depending on tag. */ 425dca77083Schristos }; 426dca77083Schristos 427dca77083Schristos /* Set ACLs */ 428dca77083Schristos int assertion_entry_set_acls(const char *, int, struct archive_entry *, 429dca77083Schristos struct archive_test_acl_t *, int); 430dca77083Schristos 431dca77083Schristos /* Compare ACLs */ 432dca77083Schristos int assertion_entry_compare_acls(const char *, int, struct archive_entry *, 433dca77083Schristos struct archive_test_acl_t *, int, int, int); 434dca77083Schristos 435dca77083Schristos /* Special customized read-from-memory interface. */ 436dca77083Schristos int read_open_memory(struct archive *, const void *, size_t, size_t); 437dca77083Schristos /* _minimal version exercises a slightly different set of libarchive APIs. */ 438dca77083Schristos int read_open_memory_minimal(struct archive *, const void *, size_t, size_t); 439dca77083Schristos /* _seek version produces a seekable file. */ 440dca77083Schristos int read_open_memory_seek(struct archive *, const void *, size_t, size_t); 441dca77083Schristos 442dca77083Schristos /* Versions of above that accept an archive argument for additional info. */ 443dca77083Schristos #define assertA(e) assertion_assert(__FILE__, __LINE__, (e), #e, (a)) 444dca77083Schristos #define assertEqualIntA(a,v1,v2) \ 445dca77083Schristos assertion_equal_int(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (a)) 446dca77083Schristos #define assertEqualStringA(a,v1,v2) \ 447dca77083Schristos assertion_equal_string(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (a), 0) 448dca77083Schristos 449dca77083Schristos #else /* defined(PROGRAM) */ 450dca77083Schristos /* 451dca77083Schristos * Special interfaces for program test harness. 452dca77083Schristos */ 453dca77083Schristos 454dca77083Schristos /* Pathname of exe to be tested. */ 455dca77083Schristos extern const char *testprogfile; 456dca77083Schristos /* Name of exe to use in printf-formatted command strings. */ 457dca77083Schristos /* On Windows, this includes leading/trailing quotes. */ 458dca77083Schristos extern const char *testprog; 459dca77083Schristos 460dca77083Schristos void assertVersion(const char *prog, const char *base); 461dca77083Schristos 462dca77083Schristos #endif /* defined(PROGRAM) */ 463dca77083Schristos 464dca77083Schristos #ifdef USE_DMALLOC 465dca77083Schristos #include <dmalloc.h> 466dca77083Schristos #endif 467dca77083Schristos 46897f7d7b6Schristos #include "test_utils.h" 46997f7d7b6Schristos 470dca77083Schristos #endif /* TEST_COMMON_H */ 471