]> git.ozlabs.org Git - ccan/blobdiff - ccan/list/test/run.c
list: implement list_for_each_rev()
[ccan] / ccan / list / test / run.c
index f80e364a276c1dd466737a80186db60f99cc57f3..4ac2dcda34e3eb5ebdc50aca20ea8ac1e379505a 100644 (file)
@@ -22,7 +22,7 @@ int main(int argc, char *argv[])
        unsigned int i;
        struct list_head list = LIST_HEAD_INIT(list);
 
-       plan_tests(49);
+       plan_tests(53);
        /* Test LIST_HEAD, LIST_HEAD_INIT, list_empty and check_list */
        ok1(list_empty(&static_list));
        ok1(list_check(&static_list, NULL));
@@ -104,6 +104,25 @@ int main(int argc, char *argv[])
        }
        ok1(i == 3);
 
+       /* Test list_for_each_rev. */
+       i = 0;
+       list_for_each_rev(&parent.children, c, list) {
+               switch (i++) {
+               case 0:
+                       ok1(c == &c3);
+                       break;
+               case 1:
+                       ok1(c == &c2);
+                       break;
+               case 2:
+                       ok1(c == &c1);
+                       break;
+               }
+               if (i > 2)
+                       break;
+       }
+       ok1(i == 3);
+
        /* Test list_for_each_safe, list_del and list_del_from. */
        i = 0;
        list_for_each_safe(&parent.children, c, n, list) {