diff options
-rw-r--r-- | cpio/test/test_gcpio_compat.c | 50 | ||||
-rw-r--r-- | cpio/test/test_option_B_upper.c | 6 | ||||
-rw-r--r-- | cpio/test/test_option_C_upper.c | 16 | ||||
-rw-r--r-- | cpio/test/test_option_J_upper.c | 6 | ||||
-rw-r--r-- | cpio/test/test_option_L_upper.c | 22 | ||||
-rw-r--r-- | cpio/test/test_option_Z_upper.c | 6 | ||||
-rw-r--r-- | cpio/test/test_option_c.c | 19 | ||||
-rw-r--r-- | cpio/test/test_option_d.c | 14 |
8 files changed, 35 insertions, 104 deletions
diff --git a/cpio/test/test_gcpio_compat.c b/cpio/test/test_gcpio_compat.c index c5e80575..320ca660 100644 --- a/cpio/test/test_gcpio_compat.c +++ b/cpio/test/test_gcpio_compat.c @@ -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(".."); } diff --git a/cpio/test/test_option_B_upper.c b/cpio/test/test_option_B_upper.c index 1b9260e4..b040354b 100644 --- a/cpio/test/test_option_B_upper.c +++ b/cpio/test/test_option_B_upper.c @@ -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); diff --git a/cpio/test/test_option_C_upper.c b/cpio/test/test_option_C_upper.c index b15f8870..c8e63fd3 100644 --- a/cpio/test/test_option_C_upper.c +++ b/cpio/test/test_option_C_upper.c @@ -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", diff --git a/cpio/test/test_option_J_upper.c b/cpio/test/test_option_J_upper.c index 15f26b32..532aacf3 100644 --- a/cpio/test/test_option_J_upper.c +++ b/cpio/test/test_option_J_upper.c @@ -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", diff --git a/cpio/test/test_option_L_upper.c b/cpio/test/test_option_L_upper.c index a48102f0..219f610b 100644 --- a/cpio/test/test_option_L_upper.c +++ b/cpio/test/test_option_L_upper.c @@ -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); } diff --git a/cpio/test/test_option_Z_upper.c b/cpio/test/test_option_Z_upper.c index 241f07bb..936ce0c2 100644 --- a/cpio/test/test_option_Z_upper.c +++ b/cpio/test/test_option_Z_upper.c @@ -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", diff --git a/cpio/test/test_option_c.c b/cpio/test/test_option_c.c index 7270187e..bdccd4a3 100644 --- a/cpio/test/test_option_c.c +++ b/cpio/test/test_option_c.c @@ -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" */ diff --git a/cpio/test/test_option_d.c b/cpio/test/test_option_d.c index 57497e29..9ff14539 100644 --- a/cpio/test/test_option_d.c +++ b/cpio/test/test_option_d.c @@ -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"); } |