summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorAlex Crawford <alex.crawford@coreos.com>2015-08-03 23:11:53 -0700
committerAlex Crawford <alex.crawford@coreos.com>2015-08-04 03:23:43 -0700
commitdbe465c93ea8a87da95919d3f0ee802865802cfa (patch)
tree1cc0d50e2a026e988a85672d531383f97776af7c /src/test
parent58a2e9acd8216f55b004e5432f76a851f7b233c0 (diff)
basic: add LIST_INSERT_BEFORE
Similar in function to LIST_INSERT_AFTER, this will insert a new element into the list before the specified position. If the specified position is NULL, the element is added as the tail of the list.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-list.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/test/test-list.c b/src/test/test-list.c
index f6da1a7053..160064d06a 100644
--- a/src/test/test-list.c
+++ b/src/test/test-list.c
@@ -99,6 +99,50 @@ int main(int argc, const char *argv[]) {
assert_se(items[1].item_prev == &items[3]);
assert_se(items[3].item_prev == NULL);
+ LIST_REMOVE(item, head, &items[1]);
+ assert_se(LIST_JUST_US(item, &items[1]));
+
+ assert_se(items[0].item_next == NULL);
+ assert_se(items[2].item_next == &items[0]);
+ assert_se(items[3].item_next == &items[2]);
+
+ assert_se(items[0].item_prev == &items[2]);
+ assert_se(items[2].item_prev == &items[3]);
+ assert_se(items[3].item_prev == NULL);
+
+ LIST_INSERT_BEFORE(item, head, &items[2], &items[1]);
+ assert_se(items[0].item_next == NULL);
+ assert_se(items[2].item_next == &items[0]);
+ assert_se(items[1].item_next == &items[2]);
+ assert_se(items[3].item_next == &items[1]);
+
+ assert_se(items[0].item_prev == &items[2]);
+ assert_se(items[2].item_prev == &items[1]);
+ assert_se(items[1].item_prev == &items[3]);
+ assert_se(items[3].item_prev == NULL);
+
+ LIST_REMOVE(item, head, &items[0]);
+ assert_se(LIST_JUST_US(item, &items[0]));
+
+ assert_se(items[2].item_next == NULL);
+ assert_se(items[1].item_next == &items[2]);
+ assert_se(items[3].item_next == &items[1]);
+
+ assert_se(items[2].item_prev == &items[1]);
+ assert_se(items[1].item_prev == &items[3]);
+ assert_se(items[3].item_prev == NULL);
+
+ LIST_INSERT_BEFORE(item, head, NULL, &items[0]);
+ assert_se(items[0].item_next == NULL);
+ assert_se(items[2].item_next == &items[0]);
+ assert_se(items[1].item_next == &items[2]);
+ assert_se(items[3].item_next == &items[1]);
+
+ assert_se(items[0].item_prev == &items[2]);
+ assert_se(items[2].item_prev == &items[1]);
+ assert_se(items[1].item_prev == &items[3]);
+ assert_se(items[3].item_prev == NULL);
+
LIST_REMOVE(item, head, &items[0]);
assert_se(LIST_JUST_US(item, &items[0]));