File: test_list.tcc

package info (click to toggle)
uhub 0.4.1-3.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 1,436 kB
  • ctags: 2,270
  • sloc: ansic: 18,123; xml: 575; perl: 568; sh: 368; makefile: 24
file content (137 lines) | stat: -rw-r--r-- 2,490 bytes parent folder | download | duplicates (4)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <uhub.h>

static struct linked_list* list = NULL;

static char A[2] = { 'A', 0 };
static char B[2] = { 'B', 0 };
static char C[2] = { 'C', 0 };

static void null_free(void* ptr)
{
	(void) ptr;
}


EXO_TEST(list_create_destroy, {
	int ok = 0;
	struct linked_list* alist;
	alist = list_create();
	if (alist) ok = 1;
	list_destroy(alist);
	return ok;
});

EXO_TEST(list_create, {
	list = list_create();
	return list->size == 0;
});

EXO_TEST(list_append_1, {
	list_append(list, (char*) A);
	return list->size == 1;
});

EXO_TEST(list_remove_1, {
	list_remove(list, (char*) A);
	return list->size == 0;
});


EXO_TEST(list_append_2, {
	list_append(list, A);
	list_append(list, B);
	return list->size == 2;
});

EXO_TEST(list_remove_2, {
	list_remove(list, (char*) A);
	return list->size == 1;
});

EXO_TEST(list_remove_3, {
	list_remove(list, (char*) A); /* already removed, so should have no effect */
	return list->size == 1;
});

EXO_TEST(list_remove_4, {
	list_remove(list, (char*) B); /* already removed, so should have no effect */
	return list->size == 0;
});

EXO_TEST(list_append_3, {
	list_append(list, A);
	list_append(list, B);
	list_append(list, C);
	return list->size == 3;
});

EXO_TEST(list_append_4, {
	list_append(list, A); /* OK. adding the same one *AGAIN* */
	return list->size == 4;
});

EXO_TEST(list_remove_5, {
	list_remove(list, A); /* removing the first one. */
	return list->size == 3;
});

EXO_TEST(list_get_index_1, {
	return list_get_index(list, 0) == B;
});

EXO_TEST(list_get_index_2, {
	return list_get_index(list, 1) == C;
});

EXO_TEST(list_get_index_3, {
	return list_get_index(list, 2) == A;
});

EXO_TEST(list_get_index_4, {
	return list_get_index(list, 3) == NULL;
});

EXO_TEST(list_get_first_1, {
	return list_get_first(list) == B;
});

EXO_TEST(list_get_first_next_1, {
	return list_get_next(list) == C;
});

EXO_TEST(list_get_first_next_2, {
	return list_get_next(list) == A;
});

EXO_TEST(list_get_last_1, {
	return list_get_last(list) == A;
});

EXO_TEST(list_get_last_prev_1, {
	return list_get_prev(list) == C;
});

EXO_TEST(list_get_last_prev_2, {
	return list_get_prev(list) == B;
});

EXO_TEST(list_get_last_prev_next_1, {
	return list_get_next(list) == C;
});

EXO_TEST(list_clear, {
	list_clear(list, &null_free);
	return list->size == 0 && list->first == 0 && list->last == 0 && list->iterator == 0;
});


EXO_TEST(list_destroy_1, {
	list_destroy(list);
	return 1;
});

EXO_TEST(list_destroy_2, {
	list_destroy(0);
	return 1;
});