aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDmitrij D. Czarkoff <czarkoff@gmail.com>2016-01-06 01:07:37 +0100
committerDmitrij D. Czarkoff <czarkoff@gmail.com>2016-01-06 02:52:06 +0100
commit83e7ad52223590b44bfc25861031ff2a6373e5b7 (patch)
treea906e453c5f014f15961c6957482fa9ab39f087b /test
parent16cccb11b1217cb6d697f5b4862ad8bd2a430a89 (diff)
downloadimv-83e7ad52223590b44bfc25861031ff2a6373e5b7.tar.gz
Add test for file change detection
Diffstat (limited to 'test')
-rw-r--r--test/navigator.c44
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[] = {