aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitrij D. Czarkoff <czarkoff@gmail.com>2016-04-26 19:27:18 +0200
committerDmitrij D. Czarkoff <czarkoff@gmail.com>2016-04-26 19:27:18 +0200
commit42fe047e7343b42369244d1d6e73f884af777c01 (patch)
treebf819008d88b7429091641e35ea6e744d5285409
parent34a37303bfc41a6553afafc690a7fd744a8fd775 (diff)
downloadimv-42fe047e7343b42369244d1d6e73f884af777c01.tar.gz
Testcase for removal from navigator
Test that removing items leads to predictable results. Right now test is fairly incomplete, because it does not cover moving in reversed direction.
-rw-r--r--test/navigator.c50
1 files changed, 42 insertions, 8 deletions
diff --git a/test/navigator.c b/test/navigator.c
index 2c29ea2..9b756e9 100644
--- a/test/navigator.c
+++ b/test/navigator.c
@@ -9,7 +9,9 @@
#include "navigator.h"
-#define FILENAME "example.file"
+#define FILENAME1 "example.file.1"
+#define FILENAME2 "example.file.2"
+#define FILENAME3 "example.file.3"
static void test_navigator_add(void **state)
{
@@ -18,9 +20,40 @@ static void test_navigator_add(void **state)
imv_navigator_init(&nav);
assert_false(imv_navigator_poll_changed(&nav, 0));
- imv_navigator_add(&nav, FILENAME, 0);
+ imv_navigator_add(&nav, FILENAME1, 0);
assert_true(imv_navigator_poll_changed(&nav, 0));
- assert_string_equal(imv_navigator_selection(&nav), FILENAME);
+ assert_string_equal(imv_navigator_selection(&nav), FILENAME1);
+
+ imv_navigator_destroy(&nav);
+}
+
+static void test_navigator_remove(void **state)
+{
+ (void)state;
+ struct imv_navigator nav;
+ imv_navigator_init(&nav);
+
+ /* Add 3 paths */
+ imv_navigator_add(&nav, FILENAME1, 0);
+ imv_navigator_add(&nav, FILENAME2, 0);
+ imv_navigator_add(&nav, FILENAME3, 0);
+ assert_int_equal(nav.num_paths, 3);
+
+ assert_string_equal(imv_navigator_selection(&nav), FILENAME1);
+ assert_true(imv_navigator_select_rel(&nav, 1, 0));
+ assert_string_equal(imv_navigator_selection(&nav), FILENAME2);
+ imv_navigator_remove(&nav, FILENAME2);
+ assert_int_equal(nav.num_paths, 2);
+ assert_string_equal(imv_navigator_selection(&nav), FILENAME3);
+ assert_false(imv_navigator_select_rel(&nav, 1, 0));
+
+ assert_string_equal(imv_navigator_selection(&nav), FILENAME3);
+ imv_navigator_remove(&nav, FILENAME3);
+ assert_int_equal(nav.num_paths, 1);
+ assert_string_equal(imv_navigator_selection(&nav), FILENAME1);
+ imv_navigator_remove(&nav, FILENAME1);
+ assert_int_equal(nav.num_paths, 0);
+ assert_false(imv_navigator_selection(&nav));
imv_navigator_destroy(&nav);
}
@@ -34,21 +67,21 @@ static void test_navigator_file_changed(void **state)
(void)state;
imv_navigator_init(&nav);
- fd = open(FILENAME, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
+ fd = open(FILENAME1, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
if (fd == -1) {
imv_navigator_destroy(&nav);
- (void)unlink(FILENAME);
+ (void)unlink(FILENAME1);
skip();
}
assert_false(futimens(fd, times) == -1);
- imv_navigator_add(&nav, FILENAME, 0);
+ imv_navigator_add(&nav, FILENAME1, 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);
+ fd = open(FILENAME1, O_RDWR);
assert_false(fd == -1);
times[0].tv_nsec = UTIME_NOW;
@@ -60,7 +93,7 @@ static void test_navigator_file_changed(void **state)
assert_true(imv_navigator_poll_changed(&nav, 0));
(void)close(fd);
- (void)unlink(FILENAME);
+ (void)unlink(FILENAME1);
imv_navigator_destroy(&nav);
}
@@ -68,6 +101,7 @@ int main(void)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_navigator_add),
+ cmocka_unit_test(test_navigator_remove),
cmocka_unit_test(test_navigator_file_changed),
};