From 83e7ad52223590b44bfc25861031ff2a6373e5b7 Mon Sep 17 00:00:00 2001 From: "Dmitrij D. Czarkoff" Date: Wed, 6 Jan 2016 01:07:37 +0100 Subject: Add test for file change detection --- test/navigator.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'test') 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 #include -#include #include +#include +#include +#include #include +#include #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[] = { -- cgit v1.2.3