[vlc-devel] [PATCH 3/3] list: tests for reverse iteration

Maxime ... mmeisson at outlook.fr
Fri Sep 20 15:20:40 CEST 2019


---
 src/test/list.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/test/list.c b/src/test/list.c
index 25b1dcf162..6beb2a7483 100644
--- a/src/test/list.c
+++ b/src/test/list.c
@@ -56,6 +56,8 @@ int main (void)
     vlc_list_init(&head);
     vlc_list_foreach(elem, &head, node)
         assert(0); /* No iteration on an empty list */
+    vlc_list_reverse_foreach(elem, &head, node)
+        assert(0); /* No iteration on an empty list */
     assert(vlc_list_is_empty(&head));
 
     vlc_list_init(&head); /* List can be reinitialized */
@@ -64,6 +66,10 @@ int main (void)
     vlc_list_foreach(elem, &head, node)
         assert(elem->i == 1), count++;
     assert(count == 1);
+    count = 0;
+    vlc_list_reverse_foreach(elem, &head, node)
+        assert(elem->i == 1), count++;
+    assert(count == 1);
 
     back = make_elem(2);
     vlc_list_append(back, &head);
@@ -71,6 +77,10 @@ int main (void)
     vlc_list_foreach(elem, &head, node)
         assert(elem->i == count + 1), count++;
     assert(count == 2);
+    count = 0;
+    vlc_list_reverse_foreach(elem, &head, node)
+        assert(elem->i == 2 - count), count++;
+    assert(count == 2);
 
     vlc_list_prepend(make_elem(3), &head);
     vlc_list_remove(head.prev); /* remove number 2 */
@@ -87,6 +97,13 @@ int main (void)
     }
     assert(vlc_list_is_empty(&head));
 
+    vlc_list_prepend(make_elem(3), &head);
+    vlc_list_reverse_foreach(elem, &head, node)
+    {
+        vlc_list_remove(&elem->node);
+        free(elem);
+    }
+    assert(vlc_list_is_empty(&head));
 
     /*
      * Create a list from 10 to 30, inserting the 10 last element first
-- 
2.17.1



More information about the vlc-devel mailing list