]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Update more cpio tests to new infrastructure.
authorTim Kientzle <kientzle@gmail.com>
Mon, 3 Aug 2009 02:53:22 +0000 (22:53 -0400)
committerTim Kientzle <kientzle@gmail.com>
Mon, 3 Aug 2009 02:53:22 +0000 (22:53 -0400)
SVN-Revision: 1328

cpio/test/test_gcpio_compat.c
cpio/test/test_option_B_upper.c
cpio/test/test_option_C_upper.c
cpio/test/test_option_J_upper.c
cpio/test/test_option_L_upper.c
cpio/test/test_option_Z_upper.c
cpio/test/test_option_c.c
cpio/test/test_option_d.c

index c5e80575b51d47ada454cedc7b18069fb0a82490..320ca6604bd850922faa9de3a7427aabfcdadbbb 100644 (file)
@@ -28,7 +28,6 @@ __FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_gcpio_compat.c,v 1.2 2008/08/22 0
 static void
 unpack_test(const char *from, const char *options, const char *se)
 {
-       struct stat st, st2;
        int r;
 
        /* Create a work dir named after the file we're unpacking. */
@@ -54,57 +53,18 @@ unpack_test(const char *from, const char *options, const char *se)
         */
 
        /* Regular file with 2 links. */
-       r = lstat("file", &st);
-       failure("Failed to stat file %s/file, errno=%d", from, errno);
-       assertEqualInt(r, 0);
-       if (r == 0) {
-               assert(S_ISREG(st.st_mode));
-#if defined(_WIN32) && !defined(__CYGWIN__)
-               assertEqualInt(0600, st.st_mode & 0700);
-#else
-               assertEqualInt(0644, st.st_mode & 0777);
-#endif
-               failure("file %s/file", from);
-               assertEqualInt(10, st.st_size);
-               failure("file %s/file", from);
-               assertEqualInt(2, st.st_nlink);
-       }
+       assertIsReg("file", 0644);
+       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", from, errno);
-       assertEqualInt(r, 0);
-       if (r == 0) {
-               assert(S_ISREG(st2.st_mode));
-#if defined(_WIN32) && !defined(__CYGWIN__)
-               assertEqualInt(0600, st2.st_mode & 0700);
-#else
-               assertEqualInt(0644, st2.st_mode & 0777);
-#endif
-               failure("file %s/file", from);
-               assertEqualInt(10, st2.st_size);
-               failure("file %s/file", from);
-               assertEqualInt(2, st2.st_nlink);
-               failure("file and linkfile should be hardlinked");
-               assertEqualInt(st.st_dev, st2.st_dev);
-               failure("file %s/file", from);
-               assertEqualInt(st.st_ino, st2.st_ino);
-       }
+       assertFileHardlinks("linkfile", "file");
 
        /* Symlink */
        assertIsSymlink("symlink", "file");
 
        /* dir */
-       r = lstat("dir", &st);
-       if (r == 0) {
-               assertEqualInt(r, 0);
-               assert(S_ISDIR(st.st_mode));
-#if defined(_WIN32) && !defined(__CYGWIN__)
-               assertEqualInt(0700, st.st_mode & 0700);
-#else
-               assertEqualInt(0775, st.st_mode & 0777);
-#endif
-       }
+       assertIsDir("dir", 0775);
 
        assertChdir("..");
 }
index 1b9260e4a90191b30771d3beea7addb6e8adc3ce..b040354b6053903174bea5cead1fb852450599cf 100644 (file)
@@ -29,14 +29,12 @@ __FBSDID("$FreeBSD$");
 DEFINE_TEST(test_option_B_upper)
 {
        struct stat st;
-       int r, fd;
+       int r;
 
        /*
         * Create a file on disk.
         */
-       fd = open("file", O_CREAT | O_WRONLY, 0644);
-       assert(fd >= 0);
-       close(fd);
+       assertMakeFile("file", 0644, NULL);
 
        /* Create an archive without -B; this should be 512 bytes. */
        r = systemf("echo file | %s -o > small.cpio 2>small.err", testprog);
index b15f8870eb2fdd49c85d10401a3dc6a200ed94ba..c8e63fd34fb519f8b24d94be2304084b711af528 100644 (file)
@@ -28,38 +28,32 @@ __FBSDID("$FreeBSD$");
 
 DEFINE_TEST(test_option_C_upper)
 {
-       struct stat st;
-       int r, fd;
+       int r;
 
        /*
         * Create a file on disk.
         */
-       fd = open("file", O_CREAT | O_WRONLY, 0644);
-       assert(fd >= 0);
-       close(fd);
+       assertMakeFile("file", 0644, NULL);
 
        /* Create an archive without -C; this should be 512 bytes. */
        r = systemf("echo file | %s -o > small.cpio 2>small.err", testprog);
        assertEqualInt(r, 0);
        assertTextFileContents("1 block\n", "small.err");
-       assertEqualInt(0, stat("small.cpio", &st));
-       assertEqualInt(512, st.st_size);
+       assertFileSize("small.cpio", 512);
 
        /* Create an archive with -C 513; this should be 513 bytes. */
        r = systemf("echo file | %s -o -C 513 > 513.cpio 2>513.err",
                    testprog);
        assertEqualInt(r, 0);
        assertTextFileContents("1 block\n", "513.err");
-       assertEqualInt(0, stat("513.cpio", &st));
-       assertEqualInt(513, st.st_size);
+       assertFileSize("513.cpio", 513);
 
        /* Create an archive with -C 12345; this should be 12345 bytes. */
        r = systemf("echo file | %s -o -C12345 > 12345.cpio 2>12345.err",
                    testprog);
        assertEqualInt(r, 0);
        assertTextFileContents("1 block\n", "12345.err");
-       assertEqualInt(0, stat("12345.cpio", &st));
-       assertEqualInt(12345, st.st_size);
+       assertFileSize("12345.cpio", 12345);
 
        /* Create an archive with invalid -C request */
        assert(0 != systemf("echo file | %s -o -C > bad.cpio 2>bad.err",
index 15f26b328371b95ed19eae6af06c24f66cb48cad..532aacf39cc2ce4ed54efc1ebf8c313564d12f5c 100644 (file)
@@ -28,15 +28,11 @@ __FBSDID("$FreeBSD$");
 DEFINE_TEST(test_option_J_upper)
 {
        char *p;
-       int fd;
        int r;
        size_t s;
 
        /* Create a file. */
-       fd = open("f", O_CREAT | O_WRONLY, 0644);
-       assert(fd >= 0);
-       assertEqualInt(1, write(fd, "a", 1));
-       close(fd);
+       assertMakeFile("f", 0644, "a");
 
        /* Archive it with xz compression. */
        r = systemf("echo f | %s -o -J >archive.out 2>archive.err",
index a48102f085f9ddc962e2bde2521c9ac2a80a2bc9..219f610b2396e15108b7b68f2c442d9b73dc8967 100644 (file)
@@ -33,24 +33,20 @@ __FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_option_L.c,v 1.2 2008/08/24 06:21
 
 DEFINE_TEST(test_option_L_upper)
 {
-       struct stat st;
-       int fd, filelist;
+       FILE *filelist;
        int r;
 
-       filelist = open("filelist", O_CREAT | O_WRONLY, 0644);
+       filelist = fopen("filelist", "w");
 
        /* Create a file and a symlink to the file. */
-       fd = open("file", O_CREAT | O_WRONLY, 0644);
-       assert(fd >= 0);
-       assertEqualInt(10, write(fd, "123456789", 10));
-       close(fd);
-       write(filelist, "file\n", 5);
+       assertMakeFile("file", 0644, "1234567890");
+       fprintf(filelist, "file\n");
 
        /* Symlink to above file. */
        assertMakeSymlink("symlink", "file");
-       write(filelist, "symlink\n", 8);
+       fprintf(filelist, "symlink\n");
 
-       close(filelist);
+       fclose(filelist);
 
        r = systemf(CAT " filelist | %s -pd copy >copy.out 2>copy.err", testprog);
        assertEqualInt(r, 0);
@@ -64,9 +60,8 @@ DEFINE_TEST(test_option_L_upper)
        assertEqualInt(r, 0);
        assertEmptyFile("copy-L.out");
        assertTextFileContents("1 block\n", "copy-L.err");
-       assertEqualInt(0, lstat("copy-L/symlink", &st));
        failure("-pdL should dereference symlinks and turn them into files.");
-       assert(!S_ISLNK(st.st_mode));
+       assertIsReg("copy-L/symlink", -1);
 
        r = systemf(CAT " filelist | %s -o >archive.out 2>archive.err", testprog);
        failure("Error invoking %s -o ", testprog);
@@ -101,6 +96,5 @@ DEFINE_TEST(test_option_L_upper)
 #endif
        failure("Error invoking %s -i < archive-L.out", testprog);
        assertEqualInt(r, 0);
-       assertEqualInt(0, lstat("unpack-L/symlink", &st));
-       assert(!S_ISLNK(st.st_mode));
+       assertIsReg("unpack-L/symlink", -1);
 }
index 241f07bba1c770a706fc1e3aaa3ec501123d0756..936ce0c2d3e6d8c984af28cbf296231e6a0f4952 100644 (file)
@@ -28,15 +28,11 @@ __FBSDID("$FreeBSD$");
 DEFINE_TEST(test_option_Z_upper)
 {
        char *p;
-       int fd;
        int r;
        size_t s;
 
        /* Create a file. */
-       fd = open("f", O_CREAT | O_WRONLY, 0644);
-       assert(fd >= 0);
-       assertEqualInt(1, write(fd, "a", 1));
-       close(fd);
+       assertMakeFile("f", 0644, "a");
 
        /* Archive it with compress compression. */
        r = systemf("echo f | %s -oZ >archive.out 2>archive.err",
index 7270187ece9f8802605c6cd9751fb89fe54b43fd..bdccd4a38328924c11df94d4f2d5a3803a740fc2 100644 (file)
@@ -53,7 +53,7 @@ from_octal(const char *p, size_t l)
 
 DEFINE_TEST(test_option_c)
 {
-       int fd, filelist;
+       FILE *filelist;
        int r;
        int dev, ino, gid;
        time_t t, now;
@@ -66,27 +66,24 @@ DEFINE_TEST(test_option_c)
         * Create an assortment of files.
         * TODO: Extend this to cover more filetypes.
         */
-       filelist = open("filelist", O_CREAT | O_WRONLY, 0644);
+       filelist = fopen("filelist", "w");
 
        /* "file" */
-       fd = open("file", O_CREAT | O_WRONLY, 0644);
-       assert(fd >= 0);
-       assertEqualInt(10, write(fd, "123456789", 10));
-       close(fd);
-       assertEqualInt(5, write(filelist, "file\n", 5));
+       assertMakeFile("file", 0644, "1234567890");
+       fprintf(filelist, "file\n");
 
        /* "symlink" */
        assertMakeSymlink("symlink", "file");
-       assertEqualInt(8, write(filelist, "symlink\n", 8));
+       fprintf(filelist, "symlink\n");
 
        /* "dir" */
        assertMakeDir("dir", 0775);
        /* Record some facts about what we just created: */
        now = time(NULL); /* They were all created w/in last two seconds. */
-       assertEqualInt(4, write(filelist, "dir\n", 4));
+       fprintf(filelist, "dir\n");
 
        /* Use the cpio program to create an archive. */
-       close(filelist);
+       fclose(filelist);
        r = systemf("%s -oc <filelist >basic.out 2>basic.err", testprog);
        /* Verify that nothing went to stderr. */
        assertTextFileContents("1 block\n", "basic.err");
@@ -132,7 +129,7 @@ DEFINE_TEST(test_option_c)
        assertEqualMem(e + 59, "000005", 6); /* Name size */
        assertEqualMem(e + 65, "00000000012", 11); /* File size */
        assertEqualMem(e + 76, "file\0", 5); /* Name contents */
-       assertEqualMem(e + 81, "123456789\0", 10); /* File contents */
+       assertEqualMem(e + 81, "1234567890", 10); /* File contents */
        e += 91;
 
        /* Second entry is "symlink" pointing to "file" */
index 57497e29112ce3f2470878abe71deaa0982614f5..9ff14539698fea055cebabe9134309d6b1bae3e5 100644 (file)
@@ -28,23 +28,19 @@ __FBSDID("$FreeBSD$");
 
 DEFINE_TEST(test_option_d)
 {
-       struct stat st;
-       int r, fd;
+       int r;
 
        /*
         * Create a file in a directory.
         */
        assertMakeDir("dir", 0755);
-       fd = open("dir/file", O_CREAT | O_WRONLY, 0644);
-       assert(fd >= 0);
-       close(fd);
+       assertMakeFile("dir/file", 0644, NULL);
 
        /* Create an archive. */
        r = systemf("echo dir/file | %s -o > archive.cpio 2>archive.err", testprog);
        assertEqualInt(r, 0);
        assertTextFileContents("1 block\n", "archive.err");
-       assertEqualInt(0, stat("archive.cpio", &st));
-       assertEqualInt(512, st.st_size);
+       assertFileSize("archive.cpio", 512);
 
        /* Dearchive without -d, this should fail. */
        assertMakeDir("without-d", 0755);
@@ -53,7 +49,7 @@ DEFINE_TEST(test_option_d)
        assertEqualInt(r, 0);
        assertEmptyFile("out");
        /* And the file should not be restored. */
-       assert(0 != stat("dir/file", &st));
+       assertFileNotExists("dir/file");
 
        /* Dearchive with -d, this should succeed. */
        assertChdir("..");
@@ -64,5 +60,5 @@ DEFINE_TEST(test_option_d)
        assertEmptyFile("out");
        assertTextFileContents("1 block\n", "err");
        /* And the file should be restored. */
-       assertEqualInt(0, stat("dir/file", &st));
+       assertFileExists("dir/file");
 }