]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Test refactoring to isolate Windows/Posix-specific functions.
authorTim Kientzle <kientzle@gmail.com>
Sun, 26 Jul 2009 21:41:39 +0000 (17:41 -0400)
committerTim Kientzle <kientzle@gmail.com>
Sun, 26 Jul 2009 21:41:39 +0000 (17:41 -0400)
This almost builds completely cleanly on VS9 and MinGW; a little more fidgeting is still needed.

SVN-Revision: 1279

13 files changed:
tar/test/main.c
tar/test/test.h
tar/test/test_basic.c
tar/test/test_copy.c
tar/test/test_option_T_upper.c
tar/test/test_option_q.c
tar/test/test_option_r.c
tar/test/test_option_s.c
tar/test/test_patterns.c
tar/test/test_stdio.c
tar/test/test_strip_components.c
tar/test/test_symlink_dir.c
tar/test/test_windows.c

index 48683d7f1d7a5d560ab135164451134ea485117a..c5a284e2b3bcfe1c40eb80bf38912fbd72537fe9 100644 (file)
 #if !defined(__GNUC__)
 #include <crtdbg.h>
 #endif
+#include <io.h>
 #include <windows.h>
 #include <winbase.h>
+#ifndef F_OK
+#define F_OK (0)
+#endif
+#ifndef S_ISDIR
+#define S_ISDIR(m)  ((m) & _S_IFDIR)
+#endif
+#ifndef S_ISREG
+#define S_ISREG(m)  ((m) & _S_IFREG)
+#endif
+#define access _access
+#ifndef fileno
+#define fileno _fileno
+#endif
+//#define fstat _fstat64
+#define getcwd _getcwd
+#define lstat stat
+//#define lstat _stat64
+//#define stat _stat64
+#define rmdir _rmdir
+#define strdup _strdup
+#define umask _umask
 #endif
 
 /*
@@ -293,10 +315,25 @@ test_assert(const char *file, int line, int value, const char *condition, void *
        return (value);
 }
 
+int
+test_assert_chdir(const char *file, int line, const char *pathname)
+{
+       count_assertion(file, line);
+       if (chdir(pathname) == 0)
+               return (1);
+       ++failures;
+       if (!verbose && previous_failures(file, line, 1))
+               return (0);
+       fprintf(stderr, "%s:%d: chdir(\"%s\") failed\n",
+               file, line, pathname);
+       return (0);
+
+}
+
 /* assertEqualInt() displays the values of the two integers. */
 int
 test_assert_equal_int(const char *file, int line,
-    int v1, const char *e1, int v2, const char *e2, void *extra)
+    long long v1, const char *e1, long long v2, const char *e2, void *extra)
 {
        count_assertion(file, line);
        if (v1 == v2) {
@@ -308,8 +345,8 @@ test_assert_equal_int(const char *file, int line,
                return (0);
        fprintf(stderr, "%s:%d: Assertion failed: Ints not equal\n",
            file, line);
-       fprintf(stderr, "      %s=%d\n", e1, v1);
-       fprintf(stderr, "      %s=%d\n", e2, v2);
+       fprintf(stderr, "      %s=%lld\n", e1, v1);
+       fprintf(stderr, "      %s=%lld\n", e2, v2);
        report_failure(extra);
        return (0);
 }
@@ -641,8 +678,13 @@ test_assert_file_exists(const char *fpattern, ...)
        vsprintf(f, fpattern, ap);
        va_end(ap);
 
+#if defined(_WIN32) && !defined(__CYGWIN__)
+       if (!_access(f, 0))
+               return (1);
+#else
        if (!access(f, F_OK))
                return (1);
+#endif
        if (!previous_failures(test_filename, test_line, 1)) {
                fprintf(stderr, "%s:%d: File doesn't exist\n",
                    test_filename, test_line);
@@ -662,8 +704,13 @@ test_assert_file_not_exists(const char *fpattern, ...)
        vsprintf(f, fpattern, ap);
        va_end(ap);
 
+#if defined(_WIN32) && !defined(__CYGWIN__)
+       if (_access(f, 0))
+               return (1);
+#else
        if (access(f, F_OK))
                return (1);
+#endif
        if (!previous_failures(test_filename, test_line, 1)) {
                fprintf(stderr, "%s:%d: File exists and shouldn't\n",
                    test_filename, test_line);
@@ -723,20 +770,20 @@ test_assert_file_contents(const void *buff, int s, const char *fpattern, ...)
 
 /* assertTextFileContents() asserts the contents of a text file. */
 int
-test_assert_text_file_contents(const char *buff, const char *f)
+test_assert_text_file_contents(const char *buff, const char *fn)
 {
        char *contents;
        const char *btxt, *ftxt;
-       int fd;
+       FILE *f;
        int n, s;
 
-       fd = open(f, O_RDONLY);
+       f = fopen(fn, "r");
        s = strlen(buff);
        contents = malloc(s * 2 + 128);
-       n = read(fd, contents, s * 2 + 128 -1);
+       n = fread(contents, 1, s * 2 + 128 - 1, f);
        if (n >= 0)
                contents[n] = '\0';
-       close(fd);
+       fclose(f);
        /* Compare texts. */
        btxt = buff;
        ftxt = (const char *)contents;
@@ -762,7 +809,7 @@ test_assert_text_file_contents(const char *buff, const char *f)
        if (!previous_failures(test_filename, test_line, 1)) {
                fprintf(stderr, "%s:%d: File contents don't match\n",
                    test_filename, test_line);
-               fprintf(stderr, "  file=\"%s\"\n", f);
+               fprintf(stderr, "  file=\"%s\"\n", fn);
                if (n > 0)
                        hexdump(contents, buff, n, 0);
                else {
@@ -775,6 +822,107 @@ test_assert_text_file_contents(const char *buff, const char *f)
        return (0);
 }
 
+int
+test_assert_file_hardlinks(const char *file, int line,
+                                                  const char *path1, const char *path2)
+{
+       struct stat st1, st2;
+       int r;
+
+       r = lstat(path1, &st1);
+       if (r != 0) {
+               if (!previous_failures(file, line, 1))
+                       fprintf(stderr, "%s:%d: File ``%s'' should exist\n",
+                           file, line, path1);
+               return (0);
+       }
+       r = lstat(path2, &st2);
+       if (r != 0) {
+               if (!previous_failures(file, line, 1))
+                       fprintf(stderr, "%s:%d: File ``%s'' should exist\n",
+                           file, line, path2);
+               return (0);
+       }
+       if (st1.st_ino != st2.st_ino || st1.st_dev != st2.st_dev) {
+               if (!previous_failures(file, line, 1)) {
+                       fprintf(stderr,
+                               "%s:%d: Files ``%s'' and ``%s'' are not hardlinked\n",
+                           file, line, path1, path2);
+                       report_failure(NULL);
+               }
+               return (0);
+       }
+       return (1);
+}
+
+int
+test_assert_file_nlinks(const char *file, int line, const char *pathname, int nlinks)
+{
+       struct stat st;
+       int r;
+
+       r = lstat(pathname, &st);
+       if (r == 0 && st.st_nlink == nlinks)
+                       return (1);
+       if (!previous_failures(file, line, 1)) {
+               fprintf(stderr, "%s:%d: File ``%s'' has %d links, expected %d\n",
+                   file, line, pathname, st.st_nlink, nlinks);
+               report_failure(NULL);
+       }
+       return (0);
+}
+
+int
+test_assert_file_size(const char *file, int line, const char *pathname, long size)
+{
+       struct stat st;
+       int r;
+
+       r = lstat(pathname, &st);
+       if (r == 0 && st.st_size == size)
+                       return (1);
+       if (!previous_failures(file, line, 1)) {
+               fprintf(stderr, "%s:%d: File ``%s'' has size %ld, expected %ld\n",
+                   file, line, pathname, st.st_size, size);
+               report_failure(NULL);
+       }
+       return (0);
+}
+
+int
+test_assert_is_dir(const char *file, int line, const char *pathname, int mode)
+{
+       struct stat st;
+       int r;
+
+       r = lstat(pathname, &st);
+       if (r == 0 && S_ISDIR(st.st_mode))
+                       return (1);
+       if (!previous_failures(test_filename, test_line, 1)) {
+               fprintf(stderr, "%s:%d: Dir ``%s'' doesn't exist\n",
+                   test_filename, test_line, pathname);
+               report_failure(NULL);
+       }
+       return (0);
+}
+
+int
+test_assert_is_reg(const char *file, int line, const char *pathname, int mode)
+{
+       struct stat st;
+       int r;
+
+       r = lstat(pathname, &st);
+       if (r == 0 && S_ISREG(st.st_mode))
+                       return (1);
+       if (!previous_failures(test_filename, test_line, 1)) {
+               fprintf(stderr, "%s:%d: File ``%s'' doesn't exist\n",
+                   test_filename, test_line, pathname);
+               report_failure(NULL);
+       }
+       return (0);
+}
+
 int
 test_assert_make_dir(const char *file, int line, const char *dirname, int mode)
 {
@@ -782,7 +930,7 @@ test_assert_make_dir(const char *file, int line, const char *dirname, int mode)
 
        count_assertion(file, line);
 #if defined(_WIN32) && !defined(__CYGWIN__)
-       r = mkdir(dirname);
+       r = _mkdir(dirname);
 #else
        r = mkdir(dirname, mode);
 #endif
@@ -799,6 +947,65 @@ test_assert_make_dir(const char *file, int line, const char *dirname, int mode)
        return(0);
 }
 
+int
+test_assert_make_hardlink(const char *file, int line,
+                                                 const char *newpath, const char *linkto)
+{
+       int succeeded;
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+       succeeded = CreateHardLink(newpath, linkto, NULL);
+#else
+       succeeded = !link(linkto, newpath);
+#endif
+       if (succeeded) {
+               msg[0] = '\0';
+               return (1);
+       }
+       failures++;
+       if (verbose || !previous_failures(file, line, 1)) {
+               fprintf(stderr, "%s:%d: Could not create new hardlink\n",
+                       file, line);
+               fprintf(stderr, "   New link: %s\n", newpath);
+               fprintf(stderr, "   Old name: %s\n", linkto);
+       }
+       return(0);
+}
+
+
+int
+test_assert_make_symlink(const char *file, int line,
+                                                 const char *newpath, const char *linkto)
+{
+       int succeeded;
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+       int targetIsDir = 0; /* TODO: Fix this. */
+       succeeded = CreateSymbolicLink(newpath, linkto, targetIsDir);
+#else
+       succeeded = !symlink(linkto, newpath);
+#endif
+       if (succeeded) {
+               msg[0] = '\0';
+               return (1);
+       }
+       failures++;
+       if (verbose || !previous_failures(file, line, 1)) {
+               fprintf(stderr, "%s:%d: Could not create new symlink\n",
+                       file, line);
+               fprintf(stderr, "   New link: %s\n", newpath);
+               fprintf(stderr, "   Old name: %s\n", linkto);
+       }
+       return(0);
+}
+
+int
+test_assert_umask(const char *file, int line, int mask)
+{
+       umask(mask);
+       return (1);
+}
+
 /*
  * Call standard system() call, but build up the command line using
  * sprintf() conventions.
@@ -850,13 +1057,13 @@ slurpfile(size_t * sizep, const char *fmt, ...)
                fclose(f);
                return (NULL);
        }
-       p = malloc(st.st_size + 1);
+       p = malloc((size_t)st.st_size + 1);
        if (p == NULL) {
                fprintf(stderr, "Can't allocate %ld bytes of memory to read file %s\n", (long int)st.st_size, filename);
                fclose(f);
                return (NULL);
        }
-       bytes_read = fread(p, 1, st.st_size, f);
+       bytes_read = fread(p, 1, (size_t)st.st_size, f);
        if (bytes_read < st.st_size) {
                fprintf(stderr, "Can't read file %s\n", filename);
                fclose(f);
@@ -891,6 +1098,7 @@ struct { void (*func)(void); const char *name; } tests[] = {
 static int test_run(int i, const char *tmpdir)
 {
        int failures_before = failures;
+       int oldumask;
 
        if (!quiet_flag) {
                printf("%d: %s\n", i, tests[i].name);
@@ -901,7 +1109,7 @@ static int test_run(int i, const char *tmpdir)
         * Always explicitly chdir() in case the last test moved us to
         * a strange place.
         */
-       if (chdir(tmpdir)) {
+       if (!assertChdir(tmpdir)) {
                fprintf(stderr,
                    "ERROR: Couldn't chdir to temp dir %s\n",
                    tmpdir);
@@ -915,7 +1123,7 @@ static int test_run(int i, const char *tmpdir)
                exit(1);
        }
        /* Chdir() to that work directory. */
-       if (chdir(tests[i].name)) {
+       if (!assertChdir(tests[i].name)) {
                fprintf(stderr,
                    "ERROR: Couldn't chdir to temp dir ``%s''\n",
                    tests[i].name);
@@ -923,13 +1131,17 @@ static int test_run(int i, const char *tmpdir)
        }
        /* Explicitly reset the locale before each test. */
        setlocale(LC_ALL, "C");
+       /* Record the umask before we run the test. */
+       umask(oldumask = umask(0));
        /* Run the actual test. */
        (*tests[i].func)();
+       /* Restore umask */
+       umask(oldumask);
        /* Summarize the results of this test. */
        summarize();
        /* If there were no failures, we can remove the work dir. */
        if (failures == failures_before) {
-               if (!keep_temp_files && chdir(tmpdir) == 0) {
+               if (!keep_temp_files && assertChdir(tmpdir)) {
 #if defined(_WIN32) && !defined(__CYGWIN__)
                        systemf("rmdir /S /Q %s", tests[i].name);
 #else
@@ -1337,7 +1549,7 @@ int main(int argc, char **argv)
 
        /* If the final tmpdir is empty, we can remove it. */
        /* This should be the usual case when all tests succeed. */
-       chdir("..");
+       assertChdir("..");
        rmdir(tmpdir);
 
        return (tests_failed);
index f90ef0e1513b0a064be90f831801920750d3f0d6..20cbc7d18528d249a2a6ba6564b3cb9a61ecf45c 100644 (file)
@@ -69,6 +69,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/types.h>  /* Windows requires this before sys/stat.h */
 #include <sys/stat.h>
 #if !defined(_WIN32) || defined(__CYGWIN__)
 #include <unistd.h>
 /* An implementation of the standard assert() macro */
 #define assert(e)   test_assert(__FILE__, __LINE__, (e), #e, NULL)
 
+#define assertChdir(path)      \
+       test_assert_chdir(__FILE__, __LINE__, path)
 /* Assert two integers are the same.  Reports value of each one if not. */
 #define assertEqualInt(v1,v2)   \
   test_assert_equal_int(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL)
 /* Assert that file contents match a string; supports printf-style arguments. */
 #define assertFileContents             \
   test_setup(__FILE__, __LINE__);test_assert_file_contents
+#define assertFileHardlinks(path1, path2)      \
+  test_assert_file_hardlinks(__FILE__, __LINE__, path1, path2)
+#define assertFileNLinks(pathname, nlinks)  \
+  test_assert_file_size(__FILE__, __LINE__, pathname, nlinks)
+#define assertFileSize(pathname, size)  \
+  test_assert_file_size(__FILE__, __LINE__, pathname, size)
 #define assertTextFileContents         \
   test_setup(__FILE__, __LINE__);test_assert_text_file_contents
+#define assertIsDir(pathname, mode)            \
+  test_assert_is_dir(__FILE__, __LINE__, pathname, mode)
+#define assertIsReg(pathname, mode)            \
+  test_assert_is_reg(__FILE__, __LINE__, pathname, mode)
 /* Create a directory, report error if it fails. */
 #define assertMakeDir(dirname, mode)   \
   test_assert_make_dir(__FILE__, __LINE__, dirname, mode)
+#define assertMakeHardlink(newfile, oldfile)   \
+  test_assert_make_hardlink(__FILE__, __LINE__, newfile, oldfile)
+#define assertMakeSymlink(newfile, linkto)     \
+  test_assert_make_symlink(__FILE__, __LINE__, newfile, linkto)
+#define assertUmask(mask)      \
+  test_assert_umask(__FILE__, __LINE__, mask)
 
 /*
  * This would be simple with C99 variadic macros, but I don't want to
@@ -163,18 +182,27 @@ void failure(const char *fmt, ...);
 void test_setup(const char *, int);
 void test_skipping(const char *fmt, ...);
 int test_assert(const char *, int, int, const char *, void *);
+int test_assert_chdir(const char *, int, const char *);
 int test_assert_empty_file(const char *, ...);
 int test_assert_non_empty_file(const char *, ...);
 int test_assert_equal_file(const char *, const char *, ...);
-int test_assert_equal_int(const char *, int, int, const char *, int, const char *, void *);
+int test_assert_equal_int(const char *, int, long long, const char *, long long, const char *, void *);
 int test_assert_equal_string(const char *, int, const char *v1, const char *, const char *v2, const char *, void *);
 int test_assert_equal_wstring(const char *, int, const wchar_t *v1, const char *, const wchar_t *v2, const char *, void *);
 int test_assert_equal_mem(const char *, int, const void *, const char *, const void *, const char *, size_t, const char *, void *);
 int test_assert_file_contents(const void *, int, const char *, ...);
 int test_assert_text_file_contents(const char *buff, const char *f);
 int test_assert_file_exists(const char *, ...);
+int test_assert_file_hardlinks(const char *, int, const char *, const char *);
 int test_assert_file_not_exists(const char *, ...);
+int test_assert_file_nlinks(const char *, int, const char *, int);
+int test_assert_file_size(const char *, int, const char *, long);
+int test_assert_is_dir(const char *, int, const char *, int);
+int test_assert_is_reg(const char *, int, const char *, int);
 int test_assert_make_dir(const char *, int, const char *, int);
+int test_assert_make_hardlink(const char *, int, const char *newpath, const char *);
+int test_assert_make_symlink(const char *, int, const char *newpath, const char *);
+int test_assert_umask(const char *, int, int);
 
 /* Like sprintf, then system() */
 int systemf(const char * fmt, ...);
index 34ddb666113a643b37e9f058fba5969cd30d95cf..2b02a4747ee6955c4e3dc4c28f3244f23c9e5131 100644 (file)
@@ -30,17 +30,16 @@ static void
 basic_tar(const char *target, const char *pack_options,
     const char *unpack_options, const char *flist)
 {
-       struct stat st, st2;
        int r;
 
-       assertEqualInt(0, mkdir(target, 0775));
+       assertMakeDir(target, 0775);
 
        /* Use the tar program to create an archive. */
        r = systemf("%s cf - %s %s >%s/archive 2>%s/pack.err", testprog, pack_options, flist, target, target);
        failure("Error invoking %s cf -", testprog, pack_options);
        assertEqualInt(r, 0);
 
-       chdir(target);
+       assertChdir(target);
 
        /* Verify that nothing went to stderr. */
        assertEmptyFile("pack.err");
@@ -60,30 +59,15 @@ basic_tar(const char *target, const char *pack_options,
         */
 
        /* Regular file with 2 links. */
-       r = lstat("file", &st);
-       failure("Failed to stat file %s/file, errno=%d", target, errno);
-       assertEqualInt(r, 0);
-       if (r == 0) {
-               assert(S_ISREG(st.st_mode));
-               assertEqualInt(10, st.st_size);
-               failure("file %s/file", target);
-               assertEqualInt(2, st.st_nlink);
-       }
+       assertIsReg("file", -1);
+       assertFileSize("file", 10);
+       assertFileNLinks("file", 2);
 
        /* Another name for the same file. */
-       r = lstat("linkfile", &st2);
-       failure("Failed to stat file %s/linkfile, errno=%d", target, errno);
-       assertEqualInt(r, 0);
-       if (r == 0) {
-               assert(S_ISREG(st2.st_mode));
-               assertEqualInt(10, st2.st_size);
-               failure("file %s/linkfile", target);
-               assertEqualInt(2, st2.st_nlink);
-               /* Verify that the two are really hardlinked. */
-               assertEqualInt(st.st_dev, st2.st_dev);
-               failure("%s/linkfile and %s/file aren't really hardlinks", target, target);
-               assertEqualInt(st.st_ino, st2.st_ino);
-       }
+       assertIsReg("linkfile", -1);
+       assertFileSize("linkfile", 10);
+       assertFileNLinks("linkfile", 2);
+       assertFileHardlinks("file", "linkfile");
 
 #if !defined(_WIN32) || defined(__CYGWIN__)
        /* Symlink */
@@ -105,27 +89,16 @@ basic_tar(const char *target, const char *pack_options,
 #endif
 
        /* dir */
-       r = lstat("dir", &st);
-       if (r == 0) {
-               assertEqualInt(r, 0);
-               assert(S_ISDIR(st.st_mode));
-#if !defined(_WIN32) || defined(__CYGWIN__)
-               assertEqualInt(0775, st.st_mode & 0777);
-#else
-               assertEqualInt(0700, st.st_mode & 0700);
-#endif
-       }
-
-       chdir("..");
+       assertIsDir("dir", 0775);
+       assertChdir("..");
 }
 
 DEFINE_TEST(test_basic)
 {
        FILE *f;
-       int oldumask;
        const char *flist;
 
-       oldumask = umask(0);
+       assertUmask(0);
 
        /* File with 10 bytes content. */
        f = fopen("file", "wb");
@@ -134,13 +107,13 @@ DEFINE_TEST(test_basic)
        fclose(f);
 
        /* hardlink to above file. */
-       assertEqualInt(0, link("file", "linkfile"));
+       assertMakeHardlink("linkfile", "file");
 
        /* Symlink to above file. */
-       assertEqualInt(0, symlink("file", "symlink"));
+       assertMakeSymlink("symlink", "file");
 
        /* Directory. */
-       assertEqualInt(0, mkdir("dir", 0775));
+       assertMakeDir("dir", 0775);
 
        flist = "file linkfile symlink dir";
        /* Archive/dearchive with a variety of options. */
@@ -148,6 +121,4 @@ DEFINE_TEST(test_basic)
        /* tar doesn't handle cpio symlinks correctly */
        /* basic_tar("copy_odc", "--format=odc", ""); */
        basic_tar("copy_ustar", "--format=ustar", "", flist);
-
-       umask(oldumask);
 }
index 85640e7603552b304ff44283b30ce432444e628e..d80c29ca9e68a53b8822f1bed30704f589901edc 100644 (file)
@@ -102,15 +102,15 @@ create_tree(void)
        FILE *f;
        int LOOP_MAX;
 
-       assertEqualInt(0, mkdir("original", 0775));
+       assertMakeDir("original", 0775);
        chdir("original");
        LOOP_MAX = compute_loop_max();
 
-       assertEqualInt(0, mkdir("f", 0775));
-       assertEqualInt(0, mkdir("l", 0775));
-       assertEqualInt(0, mkdir("m", 0775));
-       assertEqualInt(0, mkdir("s", 0775));
-       assertEqualInt(0, mkdir("d", 0775));
+       assertMakeDir("f", 0775);
+       assertMakeDir("l", 0775);
+       assertMakeDir("m", 0775);
+       assertMakeDir("s", 0775);
+       assertMakeDir("d", 0775);
 
        for (i = 0; i < LOOP_MAX; i++) {
                buff[0] = 'f';
@@ -127,12 +127,12 @@ create_tree(void)
                /* Create a link named "l/abcdef..." to the above. */
                strcpy(buff2, buff);
                buff2[0] = 'l';
-               assertEqualInt(0, link(buff, buff2));
+               assertMakeHardlink(buff2, buff);
 
                /* Create a link named "m/abcdef..." to the above. */
                strcpy(buff2, buff);
                buff2[0] = 'm';
-               assertEqualInt(0, link(buff, buff2));
+               assertMakeHardlink(buff2, buff);
 
 #if !defined(_WIN32) || defined(__CYGWIN__)
                /* Create a symlink named "s/abcdef..." to the above. */
@@ -142,14 +142,14 @@ create_tree(void)
                buff2[1] = '.';
                buff2[2] = '/';
                failure("buff=\"%s\" buff2=\"%s\"", buff, buff2);
-               assertEqualInt(0, symlink(buff2, buff));
+               assertMakeSymlink(buff, buff2);
 #else
                skipping("create a symlink to the above");
 #endif
                /* Create a dir named "d/abcdef...". */
                buff[0] = 'd';
                failure("buff=\"%s\"", buff);
-               assertEqualInt(0, mkdir(buff, 0775));
+               assertMakeDir(buff, 0775);
        }
 
        chdir("..");
@@ -161,17 +161,13 @@ create_tree(void)
 static void
 verify_tree(int limit)
 {
-       struct stat st, st2;
        char filename[260];
        char name1[260];
        char name2[260];
        char contents[260];
-       int i, j, r, LOOP_MAX;
+       int i, j, LOOP_MAX;
        FILE *f;
        int len;
-       const char *p, *dp;
-       DIR *d;
-       struct dirent *de;
 
        LOOP_MAX = compute_loop_max();
 
@@ -201,8 +197,6 @@ verify_tree(int limit)
                                contents[len] = '\0';
                                failure("Each test file contains its own name");
                                assertEqualString(name1, contents);
-                               /* stat() for dev/ino for next check */
-                               assertEqualInt(0, lstat(name1, &st));
                        }
                }
 
@@ -215,19 +209,10 @@ verify_tree(int limit)
                strcat(name2, filename);
                if (limit != LIMIT_USTAR || strlen(name2) <= 100) {
                        /* Verify hardlink "l/abcdef..." */
-                       assertEqualInt(0, (r = lstat(name2, &st2)));
-                       if (r == 0) {
-                               assertEqualInt(st2.st_dev, st.st_dev);
-                               assertEqualInt(st2.st_ino, st.st_ino);
-                       }
-
+                       assertFileHardlinks(name1, name2);
                        /* Verify hardlink "m_abcdef..." */
                        name2[0] = 'm';
-                       assertEqualInt(0, (r = lstat(name2, &st2)));
-                       if (r == 0) {
-                               assertEqualInt(st2.st_dev, st.st_dev);
-                               assertEqualInt(st2.st_ino, st.st_ino);
-                       }
+                       assertFileHardlinks(name1, name2);
                }
 
 #if !defined(_WIN32) || defined(__CYGWIN__)
@@ -259,65 +244,66 @@ verify_tree(int limit)
                strcpy(name1, "d/");
                strcat(name1, filename);
                if (limit != LIMIT_USTAR || strlen(filename) < 100) {
-                       /* This is a dir. */
-                       failure("Couldn't stat %s (length %d)",
-                           name1, strlen(filename));
-                       if (assertEqualInt(0, lstat(name1, &st2))) {
-                               if (assert(S_ISDIR(st2.st_mode))) {
-                                       /* TODO: opendir/readdir this
-                                        * directory and make sure
-                                        * it's empty.
-                                        */
-                               }
+                       if (assertIsDir(name1, -1)) {
+                               /* TODO: opendir/readdir this
+                                * directory and make sure
+                                * it's empty.
+                                */
                        }
                }
        }
 
-       /* Now make sure nothing is there that shouldn't be. */
-       for (dp = "dflms"; *dp != '\0'; ++dp) {
-               char dir[2];
-               dir[0] = *dp; dir[1] = '\0';
-               d = opendir(dir);
-               failure("Unable to open dir '%s'", dir);
-               if (!assert(d != NULL))
-                       continue;
-               while ((de = readdir(d)) != NULL) {
-                       p = de->d_name;
-                       switch(dp[0]) {
-                       case 'l': case 'm':
-                               if (limit == LIMIT_USTAR) {
-                                       failure("strlen(p) = %d", strlen(p));
-                                       assert(strlen(p) <= 100);
-                               }
-                       case 'd':
-                               if (limit == LIMIT_USTAR) {
-                                       failure("strlen(p)=%d", strlen(p));
-                                       assert(strlen(p) < 100);
-                               }
-                       case 'f': case 's':
-                               if (limit == LIMIT_USTAR) {
-                                       failure("strlen(p)=%d", strlen(p));
-                                       assert(strlen(p) < 101);
-                               }
-                               /* Our files have very particular filename patterns. */
-                               if (p[0] != '.' || (p[1] != '.' && p[1] != '\0')) {
-                                       for (i = 0; p[i] != '\0' && i < LOOP_MAX; i++) {
-                                               failure("i=%d, p[i]='%c' 'a'+(i%%26)='%c'", i, p[i], 'a' + (i % 26));
-                                               assertEqualInt(p[i], 'a' + (i % 26));
+#if !defined(_WIN32) || defined(__CYGWIN__)
+       {
+               char *dp;
+               /* Now make sure nothing is there that shouldn't be. */
+               for (dp = "dflms"; *dp != '\0'; ++dp) {
+                       DIR *d;
+                       char dir[2];
+                       dir[0] = *dp; dir[1] = '\0';
+                       d = opendir(dir);
+                       failure("Unable to open dir '%s'", dir);
+                       if (!assert(d != NULL))
+                               continue;
+                       while ((de = readdir(d)) != NULL) {
+                               char *p = de->d_name;
+                               switch(dp[0]) {
+                               case 'l': case 'm':
+                                       if (limit == LIMIT_USTAR) {
+                                               failure("strlen(p) = %d", strlen(p));
+                                               assert(strlen(p) <= 100);
+                                       }
+                               case 'd':
+                                       if (limit == LIMIT_USTAR) {
+                                               failure("strlen(p)=%d", strlen(p));
+                                               assert(strlen(p) < 100);
+                                       }
+                               case 'f': case 's':
+                                       if (limit == LIMIT_USTAR) {
+                                               failure("strlen(p)=%d", strlen(p));
+                                               assert(strlen(p) < 101);
+                                       }
+                                       /* Our files have very particular filename patterns. */
+                                       if (p[0] != '.' || (p[1] != '.' && p[1] != '\0')) {
+                                               for (i = 0; p[i] != '\0' && i < LOOP_MAX; i++) {
+                                                       failure("i=%d, p[i]='%c' 'a'+(i%%26)='%c'", i, p[i], 'a' + (i % 26));
+                                                       assertEqualInt(p[i], 'a' + (i % 26));
+                                               }
+                                               assert(p[i] == '\0');
                                        }
-                                       assert(p[i] == '\0');
+                                       break;
+                               case '.':
+                                       assert(p[1] == '\0' || (p[1] == '.' && p[2] == '\0'));
+                                       break;
+                               default:
+                                       failure("File %s shouldn't be here", p);
+                                       assert(0);
                                }
-                               break;
-                       case '.':
-                               assert(p[1] == '\0' || (p[1] == '.' && p[2] == '\0'));
-                               break;
-                       default:
-                               failure("File %s shouldn't be here", p);
-                               assert(0);
                        }
+                       closedir(d);
                }
-               closedir(d);
        }
+#endif
 }
 
 static void
@@ -331,7 +317,7 @@ copy_basic(void)
         * directory, "original"  This restriction derives from the
         * extremely limited pathname lengths on those platforms.
         */
-       assertEqualInt(0, mkdir("plain", 0775));
+       assertMakeDir("plain", 0775);
        assertEqualInt(0, chdir("plain"));
 
        /*
@@ -373,7 +359,7 @@ copy_ustar(void)
         * directory, "original"  This restriction derives from the
         * extremely limited pathname lengths on those platforms.
         */
-       assertEqualInt(0, mkdir(target, 0775));
+       assertMakeDir(target, 0775);
        assertEqualInt(0, chdir(target));
 
        /*
@@ -407,9 +393,7 @@ copy_ustar(void)
 
 DEFINE_TEST(test_copy)
 {
-       int oldumask;
-
-       oldumask = umask(0);
+       assertUmask(0);
 
        create_tree(); /* Create sample files in "original" dir. */
 
@@ -418,6 +402,4 @@ DEFINE_TEST(test_copy)
 
        /* Same, but constrain to ustar format. */
        copy_ustar();
-
-       umask(oldumask);
 }
index 4f544a134e59be505c93148ad7105286dfa4caa1..4e656afc8825a17038276578066953bfd216f106 100644 (file)
@@ -28,12 +28,12 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/test/test_option_T.c,v 1.3 2008/08/15 06:12:
 static int
 touch(const char *fn)
 {
-       int fd = open(fn, O_RDWR | O_CREAT, 0644);
-       failure("Couldn't create file '%s', fd=%d, errno=%d (%s)\n",
-           fn, fd, errno, strerror(errno));
-       if (!assert(fd > 0))
+       FILE *f = fopen(fn, "w");
+       failure("Couldn't create file '%s', errno=%d (%s)\n",
+           fn, errno, strerror(errno));
+       if (!assert(f != NULL))
                return (0); /* Failure. */
-       close(fd);
+       fclose(f);
        return (1); /* Success */
 }
 
@@ -44,8 +44,8 @@ DEFINE_TEST(test_option_T_upper)
        struct stat st;
 
        /* Create a simple dir heirarchy; bail if anything fails. */
-       if (!assertEqualInt(0, mkdir("d1", 0755))) return;
-       if (!assertEqualInt(0, mkdir("d1/d2", 0755)))   return;
+       if (!assertMakeDir("d1", 0755)) return;
+       if (!assertMakeDir("d1/d2", 0755))      return;
        if (!touch("d1/f1")) return;
        if (!touch("d1/f2")) return;
        if (!touch("d1/d2/f3")) return;
@@ -77,7 +77,7 @@ DEFINE_TEST(test_option_T_upper)
        assertEmptyFile("test1.err");
 
        /* Use -x -T to dearchive the files */
-       if (!assertEqualInt(0, mkdir("test1", 0755))) return;
+       if (!assertMakeDir("test1", 0755)) return;
        systemf("%s -x -f test1.tar -T filelist -C test1"
            " > test1b.out 2> test1b.err", testprog);
        assertEmptyFile("test1b.out");
@@ -97,7 +97,7 @@ DEFINE_TEST(test_option_T_upper)
        assertEmptyFile("test2.err");
 
        /* Use -x without -T to dearchive the files (ensure -r worked) */
-       if (!assertEqualInt(0, mkdir("test3", 0755))) return;
+       if (!assertMakeDir("test3", 0755)) return;
        systemf("%s -x -f test1.tar -C test3"
            " > test3.out 2> test3.err", testprog);
        assertEmptyFile("test3.out");
@@ -110,7 +110,7 @@ DEFINE_TEST(test_option_T_upper)
        assertFileExists("test3/d1/d2/f5");
 
        /* Use -x -T to dearchive the files (verify -x -T together) */
-       if (!assertEqualInt(0, mkdir("test2", 0755))) return;
+       if (!assertMakeDir("test2", 0755)) return;
        systemf("%s -x -f test1.tar -T filelist -C test2"
            " > test2b.out 2> test2b.err", testprog);
        assertEmptyFile("test2b.out");
@@ -122,10 +122,10 @@ DEFINE_TEST(test_option_T_upper)
        assertFileExists("test2/d1/d2/f4");
        assertFileNotExists("test2/d1/d2/f5");
 
-       assertEqualInt(0, mkdir("test4", 0755));
-       assertEqualInt(0, mkdir("test4_out", 0755));
-       assertEqualInt(0, mkdir("test4_out2", 0755));
-       assertEqualInt(0, mkdir("test4/d1", 0755));
+       assertMakeDir("test4", 0755);
+       assertMakeDir("test4_out", 0755);
+       assertMakeDir("test4_out2", 0755);
+       assertMakeDir("test4/d1", 0755);
        assertEqualInt(1, touch("test4/d1/foo"));
 
        /* Does bsdtar support -s option ? */
index 6f576fb818dcd70107257d0c3440a0edbd23e93c..68867b52a82ae105d18fe75fab9cf6c7779043c6 100644 (file)
@@ -81,8 +81,8 @@ DEFINE_TEST(test_option_q)
         */
 
        /* Test 1: -q foo should only extract the first foo. */
-       assertEqualInt(0, mkdir("test1", 0755));
-       assertEqualInt(0, chdir("test1"));
+       assertMakeDir("test1", 0755);
+       assertChdir("test1");
        r = systemf("%s -xf ../archive.tar -q foo >test.out 2>test.err",
            testprog);
        failure("Fatal error trying to use -q option");
@@ -92,38 +92,38 @@ DEFINE_TEST(test_option_q)
        assertFileContents("foo1", 4, "foo");
        assertEmptyFile("test.out");
        assertEmptyFile("test.err");
-       assertEqualInt(0, chdir(".."));
+       assertChdir("..");
 
        /* Test 2: -q foo bar should extract up to the first bar. */
-       assertEqualInt(0, mkdir("test2", 0755));
-       assertEqualInt(0, chdir("test2"));
+       assertMakeDir("test2", 0755);
+       assertChdir("test2");
        assertEqualInt(0,
            systemf("%s -xf ../archive.tar -q foo bar >test.out 2>test.err", testprog));
        assertFileContents("foo2", 4, "foo");
        assertFileContents("bar1", 4, "bar");
        assertEmptyFile("test.out");
        assertEmptyFile("test.err");
-       assertEqualInt(0, chdir(".."));
+       assertChdir("..");
 
        /* Test 3: Same as test 2, but use --fast-read spelling. */
-       assertEqualInt(0, mkdir("test3", 0755));
-       assertEqualInt(0, chdir("test3"));
+       assertMakeDir("test3", 0755);
+       assertChdir("test3");
        assertEqualInt(0,
            systemf("%s -xf ../archive.tar --fast-read foo bar >test.out 2>test.err", testprog));
        assertFileContents("foo2", 4, "foo");
        assertFileContents("bar1", 4, "bar");
        assertEmptyFile("test.out");
        assertEmptyFile("test.err");
-       assertEqualInt(0, chdir(".."));
+       assertChdir("..");
 
        /* Test 4: Without -q, should extract everything. */
-       assertEqualInt(0, mkdir("test4", 0755));
-       assertEqualInt(0, chdir("test4"));
+       assertMakeDir("test4", 0755);
+       assertChdir("test4");
        assertEqualInt(0,
            systemf("%s -xf ../archive.tar foo bar >test.out 2>test.err", testprog));
        assertFileContents("foo3", 4, "foo");
        assertFileContents("bar2", 4, "bar");
        assertEmptyFile("test.out");
        assertEmptyFile("test.err");
-       assertEqualInt(0, chdir(".."));
+       assertChdir("..");
 }
index 81d0f6ee1d34e1ad028b56bbf58cccb479aba8c5..373d79c93ad73909a3bf18c25ad1fe2da38a3f0b 100644 (file)
@@ -101,8 +101,8 @@ DEFINE_TEST(test_option_r)
        free(p1);
 
        /* Unpack both items */
-       assertEqualInt(0, mkdir("step3", 0775));
-       assertEqualInt(0, chdir("step3"));
+       assertMakeDir("step3", 0775);
+       assertChdir("step3");
        r = systemf("%s xf ../archive.tar", testprog);
        failure("Error invoking %s xf archive.tar", testprog);
        assertEqualInt(r, 0);
index 3a73c4d5d854a345753b736271039429b7980db5..8eb415e1cea722053edffeb0df55eda8dd5ed4a7 100644 (file)
@@ -45,8 +45,8 @@ DEFINE_TEST(test_option_s)
        struct stat st;
 
        /* Create a sample file heirarchy. */
-       assertEqualInt(0, mkdir("in", 0755));
-       assertEqualInt(0, mkdir("in/d1", 0755));
+       assertMakeDir("in", 0755);
+       assertMakeDir("in/d1", 0755);
        assertEqualInt(0, mkfile("in/d1/foo", "foo"));
        assertEqualInt(0, mkfile("in/d1/bar", "bar"));
 
@@ -63,7 +63,7 @@ DEFINE_TEST(test_option_s)
        /*
         * Test 1: Filename substitution when creating archives.
         */
-       assertEqualInt(0, mkdir("test1", 0755));
+       assertMakeDir("test1", 0755);
        systemf("%s -cf - -s /foo/bar/ in/d1/foo | %s -xf - -C test1",
            testprog, testprog);
        assertFileContents("foo", 3, "test1/in/d1/bar");
@@ -75,7 +75,7 @@ DEFINE_TEST(test_option_s)
        /*
         * Test 2: Basic substitution when extracting archive.
         */
-       assertEqualInt(0, mkdir("test2", 0755));
+       assertMakeDir("test2", 0755);
        systemf("%s -cf - in/d1/foo | %s -xf - -s /foo/bar/ -C test2",
            testprog, testprog);
        assertFileContents("foo", 3, "test2/in/d1/bar");
@@ -90,7 +90,7 @@ DEFINE_TEST(test_option_s)
        /*
         * Test 4: Multiple substitutions when extracting archive.
         */
-       assertEqualInt(0, mkdir("test4", 0755));
+       assertMakeDir("test4", 0755);
        systemf("%s -cf - in/d1/foo in/d1/bar | %s -xf - -s /foo/bar/ -s }bar}baz} -C test4",
            testprog, testprog);
        assertFileContents("foo", 3, "test4/in/d1/bar");
@@ -99,7 +99,7 @@ DEFINE_TEST(test_option_s)
        /*
         * Test 5: Name-switching substitutions when extracting archive.
         */
-       assertEqualInt(0, mkdir("test5", 0755));
+       assertMakeDir("test5", 0755);
        systemf("%s -cf - in/d1/foo in/d1/bar | %s -xf - -s /foo/bar/ -s }bar}foo} -C test5",
            testprog, testprog);
        assertFileContents("foo", 3, "test5/in/d1/bar");
index 24664fd52aaae616cbb65babdecdc57a6509a804..2ba4bd3e9f23b36b4431854ea17f6d28f4f1887a 100644 (file)
@@ -28,7 +28,8 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/test/test_patterns.c,v 1.6 2008/08/21 22:28:
 
 DEFINE_TEST(test_patterns)
 {
-       int fd, r;
+       FILE *f;
+       int r;
        const char *reffile2 = "test_patterns_2.tar";
        const char *reffile3 = "test_patterns_3.tar";
        const char *reffile4 = "test_patterns_4.tar";
@@ -44,9 +45,9 @@ DEFINE_TEST(test_patterns)
         *
         * John Baldwin reported this problem in PR bin/121598
         */
-       fd = open("foo", O_CREAT | O_WRONLY, 0644);
-       assert(fd >= 0);
-       close(fd);
+       f = fopen("foo", "w");
+       assert(f != NULL);
+       fclose(f);
        r = systemf("%s cfv tar1.tgz foo > tar1a.out 2> tar1a.err", testprog);
        assertEqualInt(r, 0);
        r = systemf("%s xv --no-same-owner -f tar1.tgz foo bar > tar1b.out 2> tar1b.err", testprog);
@@ -102,7 +103,7 @@ DEFINE_TEST(test_patterns)
        assertEqualInt(r, 0);
        assertEmptyFile("tar3d.out");
        assertEmptyFile("tar3d.err");
-       assertEqualInt(0, access("tmp/foo/baz/bar", F_OK));
+       assertFileExists("tmp/foo/baz/bar");
 
        /*
         * Test 4 archive has some entries starting with windows drive letters
@@ -167,16 +168,16 @@ DEFINE_TEST(test_patterns)
                         * c:../..\file43
                         * \/?\UnC\../file54
                         */
-                       assertEqualInt(-1, access(filex, F_OK));
+                       assertFileNotExists(filex);
                        filex = file_c;
                        xsize = sizeof(file_c);
                        filex[xsize-3] = '0' + r / 10;
                        filex[xsize-2] = '0' + r % 10;
-                       assertEqualInt(-1, access(filex, F_OK));
+                       assertFileNotExists(filex);
                        break;
                default:
                        /* Extracted patterns. */
-                       assertEqualInt(0, access(filex, F_OK));
+                       assertFileExists(filex);
                        break;
                }
        }
index 93209ea8796a3cd6ec802632d7b2e44aaeef1a95..028e7fff6537c49d635ac758daa3f51258da035a 100644 (file)
@@ -31,10 +31,9 @@ DEFINE_TEST(test_stdio)
        FILE *filelist;
        char *p;
        size_t s;
-       int oldumask;
        int r;
 
-       oldumask = umask(0);
+       assertUmask(0);
 
        /*
         * Create a couple of files on disk.
@@ -48,7 +47,7 @@ DEFINE_TEST(test_stdio)
        fclose(f);
        fprintf(filelist, "f\n");
        /* Link to above file. */
-       assertEqualInt(0, link("f", "l"));
+       assertMakeHardlink("l", "f");
        fprintf(filelist, "l\n");
        fclose(filelist);
 
@@ -126,6 +125,4 @@ DEFINE_TEST(test_stdio)
        assertEqualInt(r, 0);
        assertEmptyFile("xvf-.out");
        /* TODO: Verify xvf-.err */
-
-       umask(oldumask);
 }
index 8b386dd205132fd5e8e2e19d477958c336ba045d..2e1ebbf53c7177ef98948208bbc949a72b957aff 100644 (file)
@@ -28,50 +28,48 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/test/test_strip_components.c,v 1.2 2008/11/1
 static int
 touch(const char *fn)
 {
-       int fd = open(fn, O_RDWR | O_CREAT, 0644);
-       failure("Couldn't create file '%s', fd=%d, errno=%d (%s)\n",
-           fn, fd, errno, strerror(errno));
-       if (!assert(fd > 0))
+       FILE *f = fopen(fn, "w");
+       failure("Couldn't create file '%s', errno=%d (%s)\n",
+           fn, errno, strerror(errno));
+       if (!assert(f != NULL))
                return (0); /* Failure. */
-       close(fd);
+       fclose(f);
        return (1); /* Success */
 }
 
 DEFINE_TEST(test_strip_components)
 {
-       struct stat st;
-
-       assertEqualInt(0, mkdir("d0", 0755));
-       assertEqualInt(0, chdir("d0"));
-       assertEqualInt(0, mkdir("d1", 0755));
-       assertEqualInt(0, mkdir("d1/d2", 0755));
-       assertEqualInt(0, mkdir("d1/d2/d3", 0755));
+       assertMakeDir("d0", 0755);
+       assertChdir("d0");
+       assertMakeDir("d1", 0755);
+       assertMakeDir("d1/d2", 0755);
+       assertMakeDir("d1/d2/d3", 0755);
        assertEqualInt(1, touch("d1/d2/f1"));
-       assertEqualInt(0, link("d1/d2/f1", "l1"));
-       assertEqualInt(0, link("d1/d2/f1", "d1/l2"));
-       assertEqualInt(0, symlink("d1/d2/f1", "s1"));
-       assertEqualInt(0, symlink("d2/f1", "d1/s2"));
-       assertEqualInt(0, chdir(".."));
+       assertMakeHardlink("l1", "d1/d2/f1");
+       assertMakeHardlink("d1/l2", "d1/d2/f1");
+       assertMakeSymlink("s1", "d1/d2/f1");
+       assertMakeSymlink("d1/s2", "d2/f1");
+       assertChdir("..");
 
        assertEqualInt(0, systemf("%s -cf test.tar d0", testprog));
 
-       assertEqualInt(0, mkdir("target", 0755));
+       assertMakeDir("target", 0755);
        assertEqualInt(0, systemf("%s -x -C target --strip-components 2 "
            "-f test.tar", testprog));
 
        failure("d0/ is too short and should not get restored");
-       assertEqualInt(-1, lstat("target/d0", &st));
+       assertFileNotExists("target/d0");
        failure("d0/d1/ is too short and should not get restored");
-       assertEqualInt(-1, lstat("target/d1", &st));
+       assertFileNotExists("target/d1");
        failure("d0/d1/s2 is a symlink to something that won't be extracted");
 #if !defined(_WIN32) || defined(__CYGWIN__)
-       assertEqualInt(-1, stat("target/s2", &st));
+       assertFileNotExists("target/s2");
 #else
        skipping("symlink with stat()");
 #endif
-       assertEqualInt(0, lstat("target/s2", &st));
+       assertFileExists("target/s2", -1);
        failure("d0/d1/d2 should be extracted");
-       assertEqualInt(0, lstat("target/d2", &st));
+       assertIsDir("target/d2", -1);
 
        /*
         * This next is a complicated case.  d0/l1, d0/d1/l2, and
@@ -102,9 +100,9 @@ DEFINE_TEST(test_strip_components)
         * parallel tests for cpio and newc formats.
         */
        failure("d0/l1 is too short and should not get restored");
-       assertEqualInt(-1, lstat("target/l1", &st));
+       assertFileNotExists("target/l1");
        failure("d0/d1/l2 is a hardlink to file whose name was too short");
-       assertEqualInt(-1, lstat("target/l2", &st));
+       assertFileNotExists("target/l2");
        failure("d0/d1/d2/f1 is a hardlink to file whose name was too short");
-       assertEqualInt(-1, lstat("target/d2/f1", &st));
+       assertFileNotExists("target/d2/f1");
 }
index b54561abbca696efd03e00aca5f3a6d006ac5fcf..3a50e08cc4b645328384bb09fe60ffbb831b300b 100644 (file)
@@ -49,25 +49,23 @@ mkfile(const char *name, int mode, const char *contents, size_t size)
 
 DEFINE_TEST(test_symlink_dir)
 {
-       struct stat st;
 #if !defined(_WIN32) || defined(__CYGWIN__)
+       struct stat st;
        struct stat st2;
 #endif
-       int oldumask;
+       assertUmask(0);
 
-       oldumask = umask(0);
-
-       assertEqualInt(0, mkdir("source", 0755));
+       assertMakeDir("source", 0755);
        assertEqualInt(0, mkfile("source/file", 0755, "a", 1));
        assertEqualInt(0, mkfile("source/file2", 0755, "ab", 2));
-       assertEqualInt(0, mkdir("source/dir", 0755));
-       assertEqualInt(0, mkdir("source/dir/d", 0755));
+       assertMakeDir("source/dir", 0755);
+       assertMakeDir("source/dir/d", 0755);
        assertEqualInt(0, mkfile("source/dir/f", 0755, "abc", 3));
-       assertEqualInt(0, mkdir("source/dir2", 0755));
-       assertEqualInt(0, mkdir("source/dir2/d2", 0755));
+       assertMakeDir("source/dir2", 0755);
+       assertMakeDir("source/dir2/d2", 0755);
        assertEqualInt(0, mkfile("source/dir2/f2", 0755, "abcd", 4));
-       assertEqualInt(0, mkdir("source/dir3", 0755));
-       assertEqualInt(0, mkdir("source/dir3/d3", 0755));
+       assertMakeDir("source/dir3", 0755);
+       assertMakeDir("source/dir3/d3", 0755);
        assertEqualInt(0, mkfile("source/dir3/f3", 0755, "abcde", 5));
 
        assertEqualInt(0,
@@ -77,9 +75,9 @@ DEFINE_TEST(test_symlink_dir)
        /*
         * Extract with -x and without -P.
         */
-       assertEqualInt(0, mkdir("dest1", 0755));
+       assertMakeDir("dest1", 0755);
        /* "dir" is a symlink to an existing "real_dir" */
-       assertEqualInt(0, mkdir("dest1/real_dir", 0755));
+       assertMakeDir("dest1/real_dir", 0755);
 #if !defined(_WIN32) || defined(__CYGWIN__)
        assertEqualInt(0, symlink("real_dir", "dest1/dir"));
        /* "dir2" is a symlink to a non-existing "real_dir2" */
@@ -89,70 +87,65 @@ DEFINE_TEST(test_symlink_dir)
 #endif
        /* "dir3" is a symlink to an existing "non_dir3" */
        assertEqualInt(0, mkfile("dest1/non_dir3", 0755, "abcdef", 6));
-       assertEqualInt(0, symlink("non_dir3", "dest1/dir3"));
+       assertMakeSymlink("dest1/dir3", "non_dir3");
        /* "file" is a symlink to existing "real_file" */
        assertEqualInt(0, mkfile("dest1/real_file", 0755, "abcdefg", 7));
-       assertEqualInt(0, symlink("real_file", "dest1/file"));
+       assertMakeSymlink("dest1/file", "real_file");
 #if !defined(_WIN32) || defined(__CYGWIN__)
        /* "file2" is a symlink to non-existing "real_file2" */
-       assertEqualInt(0, symlink("real_file2", "dest1/file2"));
+       assertMakeSymlink("dest1/file2", "real_file2");
 #else
        skipping("symlink does not work on this platform");
 #endif
        assertEqualInt(0, systemf("%s -xf test.tar -C dest1", testprog));
 
-       /* dest1/dir symlink should be removed */
-       assertEqualInt(0, lstat("dest1/dir", &st));
+       /* dest1/dir symlink should be replaced */
        failure("symlink to dir was followed when it shouldn't be");
-       assert(S_ISDIR(st.st_mode));
-       /* dest1/dir2 symlink should be removed */
-       assertEqualInt(0, lstat("dest1/dir2", &st));
+       assertIsDir("dest1/dir", -1);
+       /* dest1/dir2 symlink should be replaced */
        failure("Broken symlink wasn't replaced with dir");
-       assert(S_ISDIR(st.st_mode));
-       /* dest1/dir3 symlink should be removed */
-       assertEqualInt(0, lstat("dest1/dir3", &st));
+       assertIsDir("dest1/dir2", -1);
+       /* dest1/dir3 symlink should be replaced */
        failure("Symlink to non-dir wasn't replaced with dir");
-       assert(S_ISDIR(st.st_mode));
-       /* dest1/file symlink should be removed */
-       assertEqualInt(0, lstat("dest1/file", &st));
-       failure("Symlink to existing file should be removed");
-       assert(S_ISREG(st.st_mode));
-       /* dest1/file2 symlink should be removed */
-       assertEqualInt(0, lstat("dest1/file2", &st));
-       failure("Symlink to non-existing file should be removed");
-       assert(S_ISREG(st.st_mode));
+       assertIsDir("dest1/dir3", -1);
+       /* dest1/file symlink should be replaced */
+       failure("Symlink to existing file should be replaced");
+       assertIsReg("dest1/file", -1);
+       /* dest1/file2 symlink should be replaced */
+       failure("Symlink to non-existing file should be replaced");
+       assertIsReg("dest1/file2", -1);
 
        /*
         * Extract with both -x and -P
         */
-       assertEqualInt(0, mkdir("dest2", 0755));
+       assertMakeDir("dest2", 0755);
        /* "dir" is a symlink to existing "real_dir" */
-       assertEqualInt(0, mkdir("dest2/real_dir", 0755));
+       assertMakeDir("dest2/real_dir", 0755);
 #if !defined(_WIN32) || defined(__CYGWIN__)
-       assertEqualInt(0, symlink("real_dir", "dest2/dir"));
+       assertMakeSymlink("dest2/dir", "real_dir");
        /* "dir2" is a symlink to a non-existing "real_dir2" */
-       assertEqualInt(0, symlink("real_dir2", "dest2/dir2"));
+       assertMakeSymlink("dest2/dir2", "real_dir2");
 #else
        skipping("symlink does not work on this platform");
 #endif
        /* "dir3" is a symlink to an existing "non_dir3" */
        assertEqualInt(0, mkfile("dest2/non_dir3", 0755, "abcdefgh", 8));
-       assertEqualInt(0, symlink("non_dir3", "dest2/dir3"));
+       assertMakeSymlink("dest2/dir3", "non_dir3");
        /* "file" is a symlink to existing "real_file" */
        assertEqualInt(0, mkfile("dest2/real_file", 0755, "abcdefghi", 9));
-       assertEqualInt(0, symlink("real_file", "dest2/file"));
+       assertMakeSymlink("dest2/file", "real_file");
 #if !defined(_WIN32) || defined(__CYGWIN__)
        /* "file2" is a symlink to non-existing "real_file2" */
-       assertEqualInt(0, symlink("real_file2", "dest2/file2"));
+       assertMakeSymlink("dest2/file2", "real_file2");
 #else
        skipping("symlink does not work on this platform");
 #endif
        assertEqualInt(0, systemf("%s -xPf test.tar -C dest2", testprog));
 
        /* dest2/dir symlink should be followed */
+#if !defined(_WIN32) || defined(__CYGWIN__)
        assertEqualInt(0, lstat("dest2/dir", &st));
        failure("tar -xP removed symlink instead of following it");
-#if !defined(_WIN32) || defined(__CYGWIN__)
        if (assert(S_ISLNK(st.st_mode))) {
                /* Only verify what the symlink points to if it
                 * really is a symlink. */
@@ -170,26 +163,20 @@ DEFINE_TEST(test_symlink_dir)
        skipping("symlink does not work on this platform");
 #endif
        /* Contents of 'dir' should be restored */
-       assertEqualInt(0, lstat("dest2/dir/d", &st));
-       assert(S_ISDIR(st.st_mode));
-       assertEqualInt(0, lstat("dest2/dir/f", &st));
-       assert(S_ISREG(st.st_mode));
-       assertEqualInt(3, st.st_size);
+       assertIsDir("dest2/dir/d", -1);
+       assertIsReg("dest2/dir/f", -1);
+       assertFileSize("dest2/dir/f", 3);
        /* dest2/dir2 symlink should be removed */
-       assertEqualInt(0, lstat("dest2/dir2", &st));
        failure("Broken symlink wasn't replaced with dir");
-       assert(S_ISDIR(st.st_mode));
+       assertIsDir("dest2/dir2", -1);
        /* dest2/dir3 symlink should be removed */
-       assertEqualInt(0, lstat("dest2/dir3", &st));
        failure("Symlink to non-dir wasn't replaced with dir");
-       assert(S_ISDIR(st.st_mode));
+       assertIsDir("dest2/dir3", -1);
        /* dest2/file symlink should be removed;
         * even -P shouldn't follow symlinks for files */
-       assertEqualInt(0, lstat("dest2/file", &st));
        failure("Symlink to existing file should be removed");
-       assert(S_ISREG(st.st_mode));
+       assertIsReg("dest2/file", -1);
        /* dest2/file2 symlink should be removed */
-       assertEqualInt(0, lstat("dest2/file2", &st));
        failure("Symlink to non-existing file should be removed");
-       assert(S_ISREG(st.st_mode));
+       assertIsReg("dest2/file2", -1);
 }
index 551cf35ce69076d15e50880216c6c60e22c8a591..799b385c8dda9c68c77e8743cd7cf502090ea471 100644 (file)
@@ -25,6 +25,8 @@
 #include "test.h"
 
 #if defined(_WIN32) && !defined(__CYGWIN__)
+#include <windows.h>
+
 static void
 mkfile(const char *name)
 {
@@ -136,37 +138,37 @@ DEFINE_TEST(test_windows)
         * Preparre tests.
         * Create directories and files.
         */
-       assertEqualInt(0, mkdir("tmp", 0775));
-       assertEqualInt(0, chdir("tmp"));
+       assertMakeDir("tmp", 0775);
+       assertChdir("tmp");
 
-       assertEqualInt(0, mkdir("aaa", 0775));
-       assertEqualInt(0, mkdir("aaa/xxa", 0775));
-       assertEqualInt(0, mkdir("aaa/xxb", 0775));
-       assertEqualInt(0, mkdir("aaa/zzc", 0775));
+       assertMakeDir("aaa", 0775);
+       assertMakeDir("aaa/xxa", 0775);
+       assertMakeDir("aaa/xxb", 0775);
+       assertMakeDir("aaa/zzc", 0775);
        mkfile("aaa/file1");
        mkfile("aaa/xxa/file1");
        mkfile("aaa/xxb/file1");
        mkfile("aaa/zzc/file1");
-       assertEqualInt(0, mkdir("aab", 0775));
-       assertEqualInt(0, mkdir("aac", 0775));
-       assertEqualInt(0, mkdir("abb", 0775));
-       assertEqualInt(0, mkdir("abc", 0775));
-       assertEqualInt(0, mkdir("abd", 0775));
-       assertEqualInt(0, mkdir("bbb", 0775));
-       assertEqualInt(0, mkdir("bbb/xxa", 0775));
-       assertEqualInt(0, mkdir("bbb/xxb", 0775));
-       assertEqualInt(0, mkdir("bbb/zzc", 0775));
+       assertMakeDir("aab", 0775);
+       assertMakeDir("aac", 0775);
+       assertMakeDir("abb", 0775);
+       assertMakeDir("abc", 0775);
+       assertMakeDir("abd", 0775);
+       assertMakeDir("bbb", 0775);
+       assertMakeDir("bbb/xxa", 0775);
+       assertMakeDir("bbb/xxb", 0775);
+       assertMakeDir("bbb/zzc", 0775);
        mkfile("bbb/file1");
        mkfile("bbb/xxa/file1");
        mkfile("bbb/xxb/file1");
        mkfile("bbb/zzc/file1");
-       assertEqualInt(0, mkdir("bbc", 0775));
-       assertEqualInt(0, mkdir("bbd", 0775));
-       assertEqualInt(0, mkdir("bcc", 0775));
-       assertEqualInt(0, mkdir("bcd", 0775));
-       assertEqualInt(0, mkdir("bce", 0775));
-       assertEqualInt(0, mkdir("ccc", 0775));
-       assertEqualInt(0, mkdir("fff", 0775));
+       assertMakeDir("bbc", 0775);
+       assertMakeDir("bbd", 0775);
+       assertMakeDir("bcc", 0775);
+       assertMakeDir("bcd", 0775);
+       assertEqualInt(0, _mkdir("bce"));
+       assertEqualInt(0, _mkdir("ccc"));
+       assertEqualInt(0, _mkdir("fff"));
        mkfile("fff/aaaa");
        mkfile("fff/abba");
        mkfile("fff/abca");