]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Test cleanup:
authorTim Kientzle <kientzle@gmail.com>
Sat, 10 Apr 2010 21:02:55 +0000 (17:02 -0400)
committerTim Kientzle <kientzle@gmail.com>
Sat, 10 Apr 2010 21:02:55 +0000 (17:02 -0400)
 * Use assertMakeFile() instead of fopen/fwrite/fclose
 * Remove -s tests from test_option_T_upper; they just duplicate tests in test_option_s

SVN-Revision: 2221

tar/test/test_option_T_upper.c
tar/test/test_option_q.c
tar/test/test_option_r.c
tar/test/test_strip_components.c
tar/test/test_symlink_dir.c

index 94cd8cca073370d112c5cc36393909d138b88b62..f2b65d7bdc23b4c9f11a2165142577bf416a959a 100644 (file)
 __FBSDID("$FreeBSD: src/usr.bin/tar/test/test_option_T.c,v 1.3 2008/08/15 06:12:02 kientzle Exp $");
 
 static int
-touch(const char *fn, int fail)
+tryMakeFile(const char *fn)
 {
        FILE *f = fopen(fn, "w");
-       if (fail) {
-               failure("Couldn't create file '%s', errno=%d (%s)\n",
-                   fn, errno, strerror(errno));
-               if (!assert(f != NULL))
-                       return (0); /* Failure. */
-       } else {
-               if (f == NULL)
-                       return (0); /* Soft failure. */
-       }
+       if (f == NULL)
+               return (0);
        fclose(f);
-       return (1); /* Success */
+       return (1);
 }
 
 DEFINE_TEST(test_option_T_upper)
 {
        FILE *f;
        int r;
-       struct stat st;
        int gnarlyFilesSupported;
 
        /* Create a simple dir hierarchy; bail if anything fails. */
        if (!assertMakeDir("d1", 0755)) return;
        if (!assertMakeDir("d1/d2", 0755))      return;
-       if (!touch("f", 1)) return;
-       if (!touch("d1/f1", 1)) return;
-       if (!touch("d1/f2", 1)) return;
-       if (!touch("d1/d2/f3", 1)) return;
-       if (!touch("d1/d2/f4", 1)) return;
-       if (!touch("d1/d2/f5", 1)) return;
-       if (!touch("d1/d2/f6", 1)) return;
+       if (!assertMakeFile("f", 0644, "")) return;
+       if (!assertMakeFile("d1/f1", 0644, "")) return;
+       if (!assertMakeFile("d1/f2", 0644, "")) return;
+       if (!assertMakeFile("d1/d2/f3", 0644, "")) return;
+       if (!assertMakeFile("d1/d2/f4", 0644, "")) return;
+       if (!assertMakeFile("d1/d2/f5", 0644, "")) return;
+       if (!assertMakeFile("d1/d2/f6", 0644, "")) return;
        /* Some platforms don't permit such things; just skip it. */
-       gnarlyFilesSupported = touch("d1/d2/f\x0a", 0);
+       gnarlyFilesSupported = tryMakeFile("d1/d2/f\x0a");
 
        /* Populate a file list */
        f = fopen("filelist", "w+");
@@ -160,28 +152,8 @@ DEFINE_TEST(test_option_T_upper)
        assertMakeDir("test4_out", 0755);
        assertMakeDir("test4_out2", 0755);
        assertMakeDir("test4/d1", 0755);
-       assertEqualInt(1, touch("test4/d1/foo", 0));
+       assertMakeFile("test4/d1/foo", 0644, "");
 
-       /* Does bsdtar support -s option ? */
-       systemf("%s -cf - -s /foo/bar/ test4/d1/foo > check.out 2> check.err",
-           testprog);
-       assertEqualInt(0, stat("check.err", &st));
-       if (st.st_size == 0) {
-               systemf("%s -cf - -s /foo/bar/ test4/d1/foo | %s -xf - -C test4_out",
-                   testprog, testprog);
-               assertEmptyFile("test4_out/test4/d1/bar");
-               systemf("%s -cf - -s /d1/d2/ test4/d1/foo | %s -xf - -C test4_out",
-                   testprog, testprog);
-               assertEmptyFile("test4_out/test4/d2/foo");
-               systemf("%s -cf - -s ,test4/d1/foo,, test4/d1/foo | %s -tvf - > test4.lst",
-                   testprog, testprog);
-               assertEmptyFile("test4.lst");
-               systemf("%s -cf - test4/d1/foo | %s -xf - -s /foo/bar/ -C test4_out2",
-                   testprog, testprog);
-               assertEmptyFile("test4_out2/test4/d1/bar");
-       } else {
-               skipping("bsdtar does not support -s option on this platform");
-       }
 
        /* TODO: Include some use of -C directory-changing within the filelist. */
        /* I'm pretty sure -C within the filelist is broken on extract. */
index 68867b52a82ae105d18fe75fab9cf6c7779043c6..287e67afa5183963a76df1b350dd0bd1ba1ec227 100644 (file)
@@ -27,7 +27,6 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/test/test_option_q.c,v 1.3 2008/08/22 01:35:
 
 DEFINE_TEST(test_option_q)
 {
-       FILE *f;
        int r;
 
        /*
@@ -40,38 +39,23 @@ DEFINE_TEST(test_option_q)
         * what we use to build up the test archive.
         */
 
-       f = fopen("foo", "w");
-       assert(f != NULL);
-       fprintf(f, "foo1");
-       fclose(f);
+       assertMakeFile("foo", 0644, "foo1");
 
        assertEqualInt(0, systemf("%s -cf archive.tar foo", testprog));
 
-       f = fopen("foo", "w");
-       assert(f != NULL);
-       fprintf(f, "foo2");
-       fclose(f);
+       assertMakeFile("foo", 0644, "foo2");
 
        assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog));
 
-       f = fopen("bar", "w");
-       assert(f != NULL);
-       fprintf(f, "bar1");
-       fclose(f);
+       assertMakeFile("bar", 0644, "bar1");
 
        assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog));
 
-       f = fopen("foo", "w");
-       assert(f != NULL);
-       fprintf(f, "foo3");
-       fclose(f);
+       assertMakeFile("foo", 0644, "foo3");
 
        assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog));
 
-       f = fopen("bar", "w");
-       assert(f != NULL);
-       fprintf(f, "bar2");
-       fclose(f);
+       assertMakeFile("bar", 0644, "bar2");
 
        assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog));
 
index 516a8307936cd628a0d25595bf1af26d1016f776..2bfcacea54467769d21f4bad7e9685188ce377ac 100644 (file)
@@ -30,18 +30,12 @@ __FBSDID("$FreeBSD$");
  */
 DEFINE_TEST(test_option_r)
 {
-       char buff[15];
        char *p0, *p1;
        size_t s;
-       FILE *f;
        int r;
 
        /* Create a file */
-       f = fopen("f1", "w");
-       if (!assert(f != NULL))
-               return;
-       assertEqualInt(3, fwrite("abc", 1, 3, f));
-       fclose(f);
+       assertMakeFile("f1", 0644, "abc");
 
        /* Archive that one file. */
        r = systemf("%s cf archive.tar --format=ustar f1 >step1.out 2>step1.err", testprog);
@@ -67,11 +61,7 @@ DEFINE_TEST(test_option_r)
        assertEqualMem(p0 + 1536, "\0\0\0\0\0\0\0\0", 8);
 
        /* Edit that file */
-       f = fopen("f1", "w");
-       if (!assert(f != NULL))
-               return;
-       assertEqualInt(3, fwrite("123", 1, 3, f));
-       fclose(f);
+       assertMakeFile("f1", 0644, "123");
 
        /* Update the archive. */
        r = systemf("%s rf archive.tar --format=ustar f1 >step2.out 2>step2.err", testprog);
@@ -108,10 +98,5 @@ DEFINE_TEST(test_option_r)
        assertEqualInt(r, 0);
 
        /* Verify that the second one overwrote the first. */
-       f = fopen("f1", "r");
-       if (assert(f != NULL)) {
-               assertEqualInt(3, fread(buff, 1, 3, f));
-               assertEqualMem(buff, "123", 3);
-               fclose(f);
-       }
+       assertFileContents("123", 3, "f1");
 }
index c9028a4d766170338ad16f1dc425af1217215c5d..2db07d61999bf4b2fe7bf7f9a059ef794095a977 100644 (file)
 #include "test.h"
 __FBSDID("$FreeBSD: src/usr.bin/tar/test/test_strip_components.c,v 1.2 2008/11/10 05:24:13 kientzle Exp $");
 
-static int
-touch(const char *fn)
-{
-       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. */
-       fclose(f);
-       return (1); /* Success */
-}
-
 DEFINE_TEST(test_strip_components)
 {
        assertMakeDir("d0", 0755);
@@ -44,7 +32,7 @@ DEFINE_TEST(test_strip_components)
        assertMakeDir("d1", 0755);
        assertMakeDir("d1/d2", 0755);
        assertMakeDir("d1/d2/d3", 0755);
-       assertEqualInt(1, touch("d1/d2/f1"));
+       assertMakeFile("d1/d2/f1", 0644, "");
        assertMakeHardlink("l1", "d1/d2/f1");
        assertMakeHardlink("d1/l2", "d1/d2/f1");
        if (canSymlink()) {
index aa80ba68e31536d375a5a6d7ee7a158b4c0b611e..f6e99662bf110d5a95ccd582c1e737e34771c0a3 100644 (file)
@@ -31,38 +31,22 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/test/test_symlink_dir.c,v 1.1 2008/09/14 02:
  * way of a dir extraction.
  */
 
-static int
-mkfile(const char *name, int mode, const char *contents, size_t size)
-{
-       FILE *f = fopen(name, "wb");
-       size_t written;
-
-       (void)mode; /* UNUSED */
-       if (f == NULL)
-               return (-1);
-       written = fwrite(contents, 1, size, f);
-       fclose(f);
-       if (size != written)
-               return (-1);
-       return (0);
-}
-
 DEFINE_TEST(test_symlink_dir)
 {
        assertUmask(0);
 
        assertMakeDir("source", 0755);
-       assertEqualInt(0, mkfile("source/file", 0755, "a", 1));
-       assertEqualInt(0, mkfile("source/file2", 0755, "ab", 2));
+       assertMakeFile("source/file", 0755, "a");
+       assertMakeFile("source/file2", 0755, "ab");
        assertMakeDir("source/dir", 0755);
        assertMakeDir("source/dir/d", 0755);
-       assertEqualInt(0, mkfile("source/dir/f", 0755, "abc", 3));
+       assertMakeFile("source/dir/f", 0755, "abc");
        assertMakeDir("source/dir2", 0755);
        assertMakeDir("source/dir2/d2", 0755);
-       assertEqualInt(0, mkfile("source/dir2/f2", 0755, "abcd", 4));
+       assertMakeFile("source/dir2/f2", 0755, "abcd");
        assertMakeDir("source/dir3", 0755);
        assertMakeDir("source/dir3/d3", 0755);
-       assertEqualInt(0, mkfile("source/dir3/f3", 0755, "abcde", 5));
+       assertMakeFile("source/dir3/f3", 0755, "abcde");
 
        assertEqualInt(0,
            systemf("%s -cf test.tar -C source dir dir2 dir3 file file2",
@@ -82,11 +66,11 @@ DEFINE_TEST(test_symlink_dir)
                skipping("some symlink checks");
        }
        /* "dir3" is a symlink to an existing "non_dir3" */
-       assertEqualInt(0, mkfile("dest1/non_dir3", 0755, "abcdef", 6));
+       assertMakeFile("dest1/non_dir3", 0755, "abcdef");
        if (canSymlink())
                assertMakeSymlink("dest1/dir3", "non_dir3");
        /* "file" is a symlink to existing "real_file" */
-       assertEqualInt(0, mkfile("dest1/real_file", 0755, "abcdefg", 7));
+       assertMakeFile("dest1/real_file", 0755, "abcdefg");
        if (canSymlink()) {
                assertMakeSymlink("dest1/file", "real_file");
                /* "file2" is a symlink to non-existing "real_file2" */
@@ -122,11 +106,11 @@ DEFINE_TEST(test_symlink_dir)
        if (canSymlink())
                assertMakeSymlink("dest2/dir2", "real_dir2");
        /* "dir3" is a symlink to an existing "non_dir3" */
-       assertEqualInt(0, mkfile("dest2/non_dir3", 0755, "abcdefgh", 8));
+       assertMakeFile("dest2/non_dir3", 0755, "abcdefgh");
        if (canSymlink())
                assertMakeSymlink("dest2/dir3", "non_dir3");
        /* "file" is a symlink to existing "real_file" */
-       assertEqualInt(0, mkfile("dest2/real_file", 0755, "abcdefghi", 9));
+       assertMakeFile("dest2/real_file", 0755, "abcdefghi");
        if (canSymlink())
                assertMakeSymlink("dest2/file", "real_file");
        /* "file2" is a symlink to non-existing "real_file2" */