summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2018-05-23 15:21:56 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2018-06-08 13:47:33 +1000
commite05fa8444a01c87395dae77844ac7e1352bd75b9 (patch)
tree6ad0b508ad471568194d3f5e2a97fa35c753a6a5 /test
parentc81809d0aa3c454d48862c28be2ac032fc5bf1ec (diff)
downloadlibinput-e05fa8444a01c87395dae77844ac7e1352bd75b9.tar.gz
util: add a list_append()
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'test')
-rw-r--r--test/test-misc.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/test/test-misc.c b/test/test-misc.c
index ea262f65..779baf31 100644
--- a/test/test-misc.c
+++ b/test/test-misc.c
@@ -1580,6 +1580,67 @@ START_TEST(timer_flush)
}
END_TEST
+START_TEST(list_test_insert)
+{
+ struct list_test {
+ int val;
+ struct list node;
+ } tests[] = {
+ { .val = 1 },
+ { .val = 2 },
+ { .val = 3 },
+ { .val = 4 },
+ };
+ struct list_test *t;
+ struct list head;
+ int val;
+
+ list_init(&head);
+
+ ARRAY_FOR_EACH(tests, t) {
+ list_insert(&head, &t->node);
+ }
+
+ val = 4;
+ list_for_each(t, &head, node) {
+ ck_assert_int_eq(t->val, val);
+ val--;
+ }
+
+ ck_assert_int_eq(val, 0);
+}
+END_TEST
+
+START_TEST(list_test_append)
+{
+ struct list_test {
+ int val;
+ struct list node;
+ } tests[] = {
+ { .val = 1 },
+ { .val = 2 },
+ { .val = 3 },
+ { .val = 4 },
+ };
+ struct list_test *t;
+ struct list head;
+ int val;
+
+ list_init(&head);
+
+ ARRAY_FOR_EACH(tests, t) {
+ list_append(&head, &t->node);
+ }
+
+ val = 1;
+ list_for_each(t, &head, node) {
+ ck_assert_int_eq(t->val, val);
+ val++;
+ }
+ ck_assert_int_eq(val, 5);
+}
+END_TEST
+
TEST_COLLECTION(misc)
{
litest_add_no_device("events:conversion", event_conversion_device_notify);
@@ -1623,4 +1684,7 @@ TEST_COLLECTION(misc)
litest_add_no_device("misc:fd", fd_no_event_leak);
litest_add_no_device("misc:library_version", library_version);
+
+ litest_add_no_device("misc:list", list_test_insert);
+ litest_add_no_device("misc:list", list_test_append);
}