Mercurial > hg > octave-nkf > gnulib-hg
changeset 16092:936e267d6906
tests: factor out st_ctime-comparison code (a dozen uses)
* tests/test-utimens-common.h (ctime_compare): Define.
* tests/test-futimens.h (test_futimens): Replace open-coded equivalent.
* tests/test-lutimens.h (test_lutimens): Likewise.
* tests/test-utimens.h (test_utimens): Likewise.
author | Jim Meyering <meyering@redhat.com> |
---|---|
date | Thu, 17 Nov 2011 15:28:55 +0100 |
parents | 6925d22363f2 |
children | 8c4227e2df6c |
files | ChangeLog tests/test-futimens.h tests/test-lutimens.h tests/test-utimens-common.h tests/test-utimens.h |
diffstat | 5 files changed, 35 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2011-11-17 Jim Meyering <meyering@redhat.com> + tests: factor st_ctime-comparison out of two headers + * tests/test-utimens-common.h (ctime_compare): Define. + * tests/test-futimens.h (test_futimens): Replace open-coded equivalent. + * tests/test-lutimens.h (test_lutimens): Likewise. + * tests/test-utimens.h (test_utimens): Likewise. + test-getcwd: don't leave behind a confdir3/ directory upon interrupt Invoke the test program via an init.sh-using wrapper. * tests/test-getcwd.sh: New file.
--- a/tests/test-futimens.h +++ b/tests/test-futimens.h @@ -54,9 +54,7 @@ source. */ ASSERT (0 <= utimecmp (BASE "file", &st2, &st1, UTIMECMP_TRUNCATE_SOURCE)); if (check_ctime) - ASSERT (st1.st_ctime < st2.st_ctime - || (st1.st_ctime == st2.st_ctime - && get_stat_ctime_ns (&st1) < get_stat_ctime_ns (&st2))); + ASSERT (ctime_compare (&st1, &st2) < 0); { /* On some NFS systems, the 'now' timestamp of creat or a NULL timespec is determined by the server, but the 'now' timestamp @@ -126,9 +124,7 @@ ASSERT (0 <= get_stat_mtime_ns (&st2)); ASSERT (get_stat_mtime_ns (&st2) < BILLION); if (check_ctime) - ASSERT (st1.st_ctime < st2.st_ctime - || (st1.st_ctime == st2.st_ctime - && get_stat_ctime_ns (&st1) < get_stat_ctime_ns (&st2))); + ASSERT (ctime_compare (&st1, &st2) < 0); } /* Play with UTIME_OMIT, UTIME_NOW. */ @@ -143,9 +139,7 @@ ASSERT (get_stat_atime_ns (&st3) <= BILLION / 2); ASSERT (utimecmp (BASE "file", &st1, &st3, 0) <= 0); if (check_ctime) - ASSERT (st2.st_ctime < st3.st_ctime - || (st2.st_ctime == st3.st_ctime - && get_stat_ctime_ns (&st2) < get_stat_ctime_ns (&st3))); + ASSERT (ctime_compare (&st2, &st3) < 0); nap (); ts[0].tv_nsec = 0; ts[1].tv_nsec = UTIME_OMIT; @@ -156,9 +150,7 @@ ASSERT (st3.st_mtime == st2.st_mtime); ASSERT (get_stat_mtime_ns (&st3) == get_stat_mtime_ns (&st2)); if (check_ctime) - ASSERT (st3.st_ctime < st2.st_ctime - || (st3.st_ctime == st2.st_ctime - && get_stat_ctime_ns (&st3) < get_stat_ctime_ns (&st2))); + ASSERT (ctime_compare (&st3, &st2) < 0); } /* Cleanup. */
--- a/tests/test-lutimens.h +++ b/tests/test-lutimens.h @@ -61,9 +61,7 @@ ASSERT (st2.st_atime == Y2K); ASSERT (st2.st_mtime == Y2K); if (check_ctime) - ASSERT (st1.st_ctime < st2.st_ctime - || (st1.st_ctime == st2.st_ctime - && get_stat_ctime_ns (&st1) < get_stat_ctime_ns (&st2))); + ASSERT (ctime_compare (&st1, &st2) < 0); /* Play with symlink timestamps. */ if (symlink (BASE "file", BASE "link")) @@ -143,9 +141,7 @@ ASSERT (0 <= get_stat_mtime_ns (&st2)); ASSERT (get_stat_mtime_ns (&st2) < BILLION); if (check_ctime) - ASSERT (st1.st_ctime < st2.st_ctime - || (st1.st_ctime == st2.st_ctime - && get_stat_ctime_ns (&st1) < get_stat_ctime_ns (&st2))); + ASSERT (ctime_compare (&st1, &st2) < 0); } /* Play with UTIME_OMIT, UTIME_NOW. */ @@ -163,9 +159,7 @@ } ASSERT (utimecmp (BASE "link", &st1, &st3, 0) <= 0); if (check_ctime) - ASSERT (st2.st_ctime < st3.st_ctime - || (st2.st_ctime == st3.st_ctime - && get_stat_ctime_ns (&st2) < get_stat_ctime_ns (&st3))); + ASSERT (ctime_compare (&st2, &st3) < 0); nap (); ts[0].tv_nsec = 0; ts[1].tv_nsec = UTIME_OMIT; @@ -179,9 +173,7 @@ ASSERT (st3.st_mtime == st2.st_mtime); ASSERT (get_stat_mtime_ns (&st3) == get_stat_mtime_ns (&st2)); if (check_ctime) - ASSERT (st3.st_ctime < st2.st_ctime - || (st3.st_ctime == st2.st_ctime - && get_stat_ctime_ns (&st3) < get_stat_ctime_ns (&st2))); + ASSERT (ctime_compare (&st3, &st2) < 0); } /* Symlink to directory. */
--- a/tests/test-utimens-common.h +++ b/tests/test-utimens-common.h @@ -57,4 +57,21 @@ # define check_ctime 1 # endif +/* Compare two st_ctime values. Return -1, 0 or 1, respectively + when A's st_ctime is smaller than, equal to or greater than B's. */ +static inline int +ctime_compare (struct stat const *a, struct stat const *b) +{ + if (a->st_ctime < b->st_ctime) + return -1; + else if (b->st_ctime < a->st_ctime) + return 1; + else if (get_stat_ctime_ns (a) < get_stat_ctime_ns (b)) + return -1; + else if (get_stat_ctime_ns (b) < get_stat_ctime_ns (a)) + return 1; + else + return 0; +} + #endif /* GL_TEST_UTIMENS_COMMON */
--- a/tests/test-utimens.h +++ b/tests/test-utimens.h @@ -38,9 +38,7 @@ ASSERT (stat (BASE "file", &st2) == 0); ASSERT (0 <= utimecmp (BASE "file", &st2, &st1, UTIMECMP_TRUNCATE_SOURCE)); if (check_ctime) - ASSERT (st1.st_ctime < st2.st_ctime - || (st1.st_ctime == st2.st_ctime - && get_stat_ctime_ns (&st1) < get_stat_ctime_ns (&st2))); + ASSERT (ctime_compare (&st1, &st2) < 0); { /* On some NFS systems, the 'now' timestamp of creat or a NULL timespec is determined by the server, but the 'now' timestamp @@ -102,9 +100,7 @@ ASSERT (0 <= get_stat_mtime_ns (&st2)); ASSERT (get_stat_mtime_ns (&st2) < BILLION); if (check_ctime) - ASSERT (st1.st_ctime < st2.st_ctime - || (st1.st_ctime == st2.st_ctime - && get_stat_ctime_ns (&st1) < get_stat_ctime_ns (&st2))); + ASSERT (ctime_compare (&st1, &st2) < 0); } /* Play with UTIME_OMIT, UTIME_NOW. */ @@ -120,9 +116,7 @@ /* See comment above about this utimecmp call. */ ASSERT (0 <= utimecmp (BASE "file", &st3, &st1, UTIMECMP_TRUNCATE_SOURCE)); if (check_ctime) - ASSERT (st2.st_ctime < st3.st_ctime - || (st2.st_ctime == st3.st_ctime - && get_stat_ctime_ns (&st2) < get_stat_ctime_ns (&st3))); + ASSERT (ctime_compare (&st2, &st3) < 0); nap (); ts[0].tv_nsec = 0; ts[1].tv_nsec = UTIME_OMIT; @@ -133,9 +127,7 @@ ASSERT (st3.st_mtime == st2.st_mtime); ASSERT (get_stat_mtime_ns (&st3) == get_stat_mtime_ns (&st2)); if (check_ctime) - ASSERT (st3.st_ctime < st2.st_ctime - || (st3.st_ctime == st2.st_ctime - && get_stat_ctime_ns (&st3) < get_stat_ctime_ns (&st2))); + ASSERT (ctime_compare (&st3, &st2) < 0); } /* Make sure this dereferences symlinks. */