diff options
-rw-r--r-- | test/navigator.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/test/navigator.c b/test/navigator.c index ca5f200..4659f80 100644 --- a/test/navigator.c +++ b/test/navigator.c @@ -1,8 +1,11 @@ #include <stdarg.h> #include <stddef.h> -#include <fcntl.h> #include <setjmp.h> +#include <unistd.h> +#include <sys/stat.h> +#include <fcntl.h> #include <cmocka.h> +#include <errno.h> #include "navigator.h" @@ -22,6 +25,45 @@ static void test_navigator_add(void **state) imv_navigator_destroy(&nav); } +static void test_navigator_file_changed(void **state) +{ + int fd; + struct imv_navigator nav; + struct timespec times[2] = { {0, 0}, {0, 0} }; + + (void)state; + imv_navigator_init(&nav); + + fd = open(FILENAME, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); + if (fd == -1) { + imv_navigator_destroy(&nav); + (void)unlink(FILENAME); + skip(); + } + assert_false(futimens(fd, times) == -1); + + imv_navigator_add(&nav, FILENAME, 0); + assert_true(imv_navigator_poll_changed(&nav, 0)); + assert_false(imv_navigator_poll_changed(&nav, 0)); + + assert_false(sleep(1)); + + fd = open(FILENAME, O_RDWR); + assert_false(fd == -1); + + times[0].tv_nsec = UTIME_NOW; + times[0].tv_sec = UTIME_NOW; + times[1].tv_nsec = UTIME_NOW; + times[1].tv_sec = UTIME_NOW; + assert_false(futimens(fd, times) == -1); + + assert_true(imv_navigator_poll_changed(&nav, 0)); + + (void)close(fd); + (void)unlink(FILENAME); + imv_navigator_destroy(&nav); +} + int main(void) { const struct CMUnitTest tests[] = { |