]>
Commit | Line | Data |
---|---|---|
3b18ae68 JJ |
1 | /*** |
2 | This file is part of systemd | |
3 | ||
4 | Copyright 2013 Jan Janssen | |
5 | ||
6 | systemd is free software; you can redistribute it and/or modify it | |
7 | under the terms of the GNU Lesser General Public License as published by | |
8 | the Free Software Foundation; either version 2.1 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | systemd is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Lesser General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public License | |
17 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
18 | ***/ | |
19 | ||
20 | #include "list.h" | |
21 | #include "util.h" | |
22 | ||
23 | int main(int argc, const char *argv[]) { | |
24 | size_t i; | |
25 | typedef struct list_item { | |
26 | LIST_FIELDS(struct list_item, item); | |
27 | } list_item; | |
28 | LIST_HEAD(list_item, head); | |
29 | list_item items[4]; | |
30 | list_item *cursor; | |
31 | ||
32 | LIST_HEAD_INIT(list_item, head); | |
33 | assert_se(head == NULL); | |
34 | ||
35 | for (i = 0; i < ELEMENTSOF(items); i++) { | |
36 | LIST_INIT(list_item, item, &items[i]); | |
37 | assert_se(LIST_JUST_US(item, &items[i])); | |
38 | LIST_PREPEND(list_item, item, head, &items[i]); | |
39 | } | |
40 | ||
41 | assert_se(!LIST_JUST_US(item, head)); | |
42 | ||
43 | assert_se(items[0].item_next == NULL); | |
44 | assert_se(items[1].item_next == &items[0]); | |
45 | assert_se(items[2].item_next == &items[1]); | |
46 | assert_se(items[3].item_next == &items[2]); | |
47 | ||
48 | assert_se(items[0].item_prev == &items[1]); | |
49 | assert_se(items[1].item_prev == &items[2]); | |
50 | assert_se(items[2].item_prev == &items[3]); | |
51 | assert_se(items[3].item_prev == NULL); | |
52 | ||
53 | LIST_FIND_HEAD(list_item, item, &items[0], cursor); | |
54 | assert_se(cursor == &items[3]); | |
55 | ||
56 | LIST_FIND_TAIL(list_item, item, &items[3], cursor); | |
57 | assert_se(cursor == &items[0]); | |
58 | ||
59 | LIST_REMOVE(list_item, item, head, &items[1]); | |
60 | assert_se(LIST_JUST_US(item, &items[1])); | |
61 | ||
62 | assert_se(items[0].item_next == NULL); | |
63 | assert_se(items[2].item_next == &items[0]); | |
64 | assert_se(items[3].item_next == &items[2]); | |
65 | ||
66 | assert_se(items[0].item_prev == &items[2]); | |
67 | assert_se(items[2].item_prev == &items[3]); | |
68 | assert_se(items[3].item_prev == NULL); | |
69 | ||
70 | LIST_INSERT_AFTER(list_item, item, head, &items[3], &items[1]); | |
71 | assert_se(items[0].item_next == NULL); | |
72 | assert_se(items[2].item_next == &items[0]); | |
73 | assert_se(items[1].item_next == &items[2]); | |
74 | assert_se(items[3].item_next == &items[1]); | |
75 | ||
76 | assert_se(items[0].item_prev == &items[2]); | |
77 | assert_se(items[2].item_prev == &items[1]); | |
78 | assert_se(items[1].item_prev == &items[3]); | |
79 | assert_se(items[3].item_prev == NULL); | |
80 | ||
81 | LIST_REMOVE(list_item, item, head, &items[0]); | |
82 | assert_se(LIST_JUST_US(item, &items[0])); | |
83 | ||
84 | assert_se(items[2].item_next == NULL); | |
85 | assert_se(items[1].item_next == &items[2]); | |
86 | assert_se(items[3].item_next == &items[1]); | |
87 | ||
88 | assert_se(items[2].item_prev == &items[1]); | |
89 | assert_se(items[1].item_prev == &items[3]); | |
90 | assert_se(items[3].item_prev == NULL); | |
91 | ||
92 | LIST_REMOVE(list_item, item, head, &items[1]); | |
93 | assert_se(LIST_JUST_US(item, &items[1])); | |
94 | ||
95 | assert_se(items[2].item_next == NULL); | |
96 | assert_se(items[3].item_next == &items[2]); | |
97 | ||
98 | assert_se(items[2].item_prev == &items[3]); | |
99 | assert_se(items[3].item_prev == NULL); | |
100 | ||
101 | LIST_REMOVE(list_item, item, head, &items[2]); | |
102 | assert_se(LIST_JUST_US(item, &items[2])); | |
103 | assert_se(LIST_JUST_US(item, head)); | |
104 | ||
105 | LIST_REMOVE(list_item, item, head, &items[3]); | |
106 | assert_se(LIST_JUST_US(item, &items[3])); | |
107 | ||
108 | return 0; | |
109 | } |