diff options
Diffstat (limited to 'archivers/libarchive/files/cpio/test/test_option_a.c')
-rw-r--r-- | archivers/libarchive/files/cpio/test/test_option_a.c | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/archivers/libarchive/files/cpio/test/test_option_a.c b/archivers/libarchive/files/cpio/test/test_option_a.c index c063280f7d7..606de606e2c 100644 --- a/archivers/libarchive/files/cpio/test/test_option_a.c +++ b/archivers/libarchive/files/cpio/test/test_option_a.c @@ -23,8 +23,12 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "test.h" +#if defined(HAVE_UTIME_H) #include <utime.h> -__FBSDID("$FreeBSD$"); +#elif defined(HAVE_SYS_UTIME_H) +#include <sys/utime.h> +#endif +__FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_option_a.c,v 1.3 2008/08/24 06:21:00 kientzle Exp $"); static struct { const char *name; @@ -53,19 +57,15 @@ test_create(void) struct utimbuf times; static const int numfiles = sizeof(files) / sizeof(files[0]); int i; - int fd; for (i = 0; i < numfiles; ++i) { - fd = open(files[i].name, O_CREAT | O_WRONLY, 0644); - assert(fd >= 0); /* * Note: Have to write at least one byte to the file. * cpio doesn't bother reading the file if it's zero length, * so the atime never gets changed in that case, which * makes the tests below rather pointless. */ - assertEqualInt(1, write(fd, "a", 1)); - close(fd); + assertMakeFile(files[i].name, 0644, "a"); /* If utime() isn't supported on your platform, just * #ifdef this section out. Most of the test below is @@ -83,26 +83,21 @@ test_create(void) } /* Wait until the atime on the last file is actually in the past. */ - /* If utime() is supported above, there's no sleep here which - * makes the test faster. */ - while (files[numfiles - 1].atime_sec >= time(NULL)) - sleep(1); + sleepUntilAfter(files[numfiles - 1].atime_sec); } DEFINE_TEST(test_option_a) { struct stat st; int r; - int f; - char buff[64]; + char *p; /* Create all of the test files. */ test_create(); /* Sanity check; verify that atimes really do get modified. */ - f = open(files[0].name, O_RDONLY); - assertEqualInt(1, read(f,buff, 1)); - assertEqualInt(0, close(f)); + assert((p = slurpfile(NULL, "f0")) != NULL); + free(p); assertEqualInt(0, stat("f0", &st)); if (st.st_atime == files[0].atime_sec) { skipping("Cannot verify -a option\n" @@ -118,7 +113,7 @@ DEFINE_TEST(test_option_a) /* Copy the file without -a; should change the atime. */ r = systemf("echo %s | %s -pd copy-no-a > copy-no-a.out 2>copy-no-a.err", files[1].name, testprog); assertEqualInt(r, 0); - assertEmptyFile("copy-no-a.err"); + assertTextFileContents("1 block\n", "copy-no-a.err"); assertEmptyFile("copy-no-a.out"); assertEqualInt(0, stat(files[1].name, &st)); failure("Copying file without -a should have changed atime."); @@ -127,7 +122,7 @@ DEFINE_TEST(test_option_a) /* Archive the file without -a; should change the atime. */ r = systemf("echo %s | %s -o > archive-no-a.out 2>archive-no-a.err", files[2].name, testprog); assertEqualInt(r, 0); - assertEmptyFile("copy-no-a.err"); + assertTextFileContents("1 block\n", "copy-no-a.err"); assertEqualInt(0, stat(files[2].name, &st)); failure("Archiving file without -a should have changed atime."); assert(st.st_atime != files[2].atime_sec); @@ -142,7 +137,7 @@ DEFINE_TEST(test_option_a) r = systemf("echo %s | %s -pad copy-a > copy-a.out 2>copy-a.err", files[3].name, testprog); assertEqualInt(r, 0); - assertEmptyFile("copy-a.err"); + assertTextFileContents("1 block\n", "copy-a.err"); assertEmptyFile("copy-a.out"); assertEqualInt(0, stat(files[3].name, &st)); failure("Copying file with -a should not have changed atime."); @@ -152,7 +147,7 @@ DEFINE_TEST(test_option_a) r = systemf("echo %s | %s -oa > archive-a.out 2>archive-a.err", files[4].name, testprog); assertEqualInt(r, 0); - assertEmptyFile("copy-a.err"); + assertTextFileContents("1 block\n", "copy-a.err"); assertEqualInt(0, stat(files[4].name, &st)); failure("Archiving file with -a should not have changed atime."); assertEqualInt(st.st_atime, files[4].atime_sec); |