-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-slist.c
70 lines (55 loc) · 1.26 KB
/
test-slist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "./testsuite.h"
static struct slist_head this_head;
static unsigned this_slist_id = 0;
struct this_slist {
int id;
struct slist_head sibling;
};
static struct this_slist *this_slist_alloc(void)
{
struct this_slist *_new;
_new = (struct this_slist *)malloc(sizeof(*_new));
_new->id = this_slist_id;
this_slist_id++;
return _new;
}
static void this_slist_iter(void)
{
ts_output(1, stdout, "Iterating slist\n");
struct this_slist *e;
slist_for_each_entry(e, &this_head, sibling) {
ts_output(1, stdout, "%d\n", e->id);
}
return;
}
static void this_slist_insert(struct this_slist *e, int tail)
{
ts_output(1, stdout, "Add #%d slist into head\n", e->id);
if (!tail)
slist_add(&e->sibling, &this_head);
else
slist_add_tail(&e->sibling, &this_head);
return;
}
static void this_slist_destroy(void)
{
struct this_slist *cur, *next;
slist_for_each_entry_safe(cur, next, &this_head, sibling) {
slist_del(&cur->sibling, &this_head);
free(cur);
}
}
void test_slist(void)
{
ts_output(1, stdout, "Init slist head\n");
INIT_SLIST_HEAD(&this_head);
struct this_slist *e;
e = this_slist_alloc();
this_slist_insert(e, 0);
this_slist_iter();
e = this_slist_alloc();
this_slist_insert(e, 1);
this_slist_iter();
this_slist_destroy();
return;
}