diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2011-12-01 13:35:50 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2011-12-06 18:15:14 +1000 |
commit | 6acebf9e1298939593b942ec91ae9ec9e74faa19 (patch) | |
tree | d330ae95127d2492e18d5c40d52bf21e82dac8fc /test/list.c | |
parent | fb22a408c69a84f81905147de9e82cf66ffb6eb2 (diff) |
include: add list_append()
The existing list_add() prepends to the list, but in some cases we need the
list ordered in the way we append the elements.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Chase Douglas <chase.douglas@canonical.com>
Diffstat (limited to 'test/list.c')
-rw-r--r-- | test/list.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/list.c b/test/list.c index f7d7bffce..b96182e03 100644 --- a/test/list.c +++ b/test/list.c @@ -89,6 +89,36 @@ test_list_add(void) }; static void +test_list_append(void) +{ + struct parent parent = {0}; + struct child child[3]; + struct child *c; + int i; + + list_init(&parent.children); + + list_append(&child[0].node, &parent.children); + assert(!list_is_empty(&parent.children)); + + c = list_first_entry(&parent.children, struct child, node); + assert(memcmp(c, &child[0], sizeof(struct child)) == 0); + + list_append(&child[1].node, &parent.children); + c = list_first_entry(&parent.children, struct child, node); + assert(memcmp(c, &child[0], sizeof(struct child)) == 0); + + list_append(&child[2].node, &parent.children); + c = list_first_entry(&parent.children, struct child, node); + assert(memcmp(c, &child[0], sizeof(struct child)) == 0); + + i = 0; + list_for_each_entry(c, &parent.children, node) { + assert(memcmp(c, &child[i++], sizeof(struct child)) == 0); + } +}; + +static void test_list_del(void) { struct parent parent = {0}; @@ -325,6 +355,7 @@ int main(int argc, char** argv) { test_list_init(); test_list_add(); + test_list_append(); test_list_del(); test_list_for_each(); |