diff options
author | Harry Jeffery <harry@exec64.co.uk> | 2016-01-07 22:02:49 +0000 |
---|---|---|
committer | Harry Jeffery <harry@exec64.co.uk> | 2016-01-07 22:02:49 +0000 |
commit | 3036f56bc6fef65a573081167ddcd417434c6d4d (patch) | |
tree | a906e453c5f014f15961c6957482fa9ab39f087b | |
parent | 35cabe381df4a3cddc29ca7805fe8b51701f4903 (diff) | |
parent | 83e7ad52223590b44bfc25861031ff2a6373e5b7 (diff) | |
download | imv-3036f56bc6fef65a573081167ddcd417434c6d4d.tar.gz |
Merge pull request #73 from czarkoff/test
Test
-rw-r--r-- | test/navigator.c | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/test/navigator.c b/test/navigator.c index 66f3a43..4659f80 100644 --- a/test/navigator.c +++ b/test/navigator.c @@ -1,21 +1,66 @@ #include <stdarg.h> #include <stddef.h> #include <setjmp.h> +#include <unistd.h> +#include <sys/stat.h> +#include <fcntl.h> #include <cmocka.h> +#include <errno.h> #include "navigator.h" +#define FILENAME "example.file" + static void test_navigator_add(void **state) { (void)state; struct imv_navigator nav; imv_navigator_init(&nav); - assert_false(imv_navigator_poll_changed(&nav)); - imv_navigator_add(&nav, "path/to/some/file", 0); - assert_true(imv_navigator_poll_changed(&nav)); - assert_string_equal(imv_navigator_selection(&nav), "path/to/some/file"); + assert_false(imv_navigator_poll_changed(&nav, 0)); + imv_navigator_add(&nav, FILENAME, 0); + assert_true(imv_navigator_poll_changed(&nav, 0)); + assert_string_equal(imv_navigator_selection(&nav), FILENAME); + + 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); } @@ -23,6 +68,7 @@ int main(void) { const struct CMUnitTest tests[] = { cmocka_unit_test(test_navigator_add), + cmocka_unit_test(test_navigator_file_changed), }; return cmocka_run_group_tests(tests, NULL, NULL); |