-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_fifo.c
144 lines (97 loc) · 4.42 KB
/
test_fifo.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
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
138
139
140
141
142
143
144
#include <criterion/criterion.h>
#include "util/fifo.h"
Test(fifo, init_and_destroy, .disabled=0) {
uint32_t size = 10;
fifo_t *fifo = fifo_create(size);
cr_assert_not_null(fifo, "FIFO should not be NULL after creation");
fifo_destroy(fifo);
}
Test(fifo, push_and_pop, .disabled=0) {
elm_t *res;
uint32_t size = 10;
fifo_t *fifo = fifo_create(size);
cr_assert_not_null(fifo, "FIFO should not be NULL after creation");
fifo_push_back(fifo, 0, 2);
cr_assert_not(fifo_empty(fifo), "FIFO should not be empty");
res = fifo_pop_front(fifo);
cr_assert_eq(res->elm, 0, "Element: Expected %d got %d", 0, res->elm);
cr_assert_eq(res->layer, 2, "Layer: Expected %d got %d", 2, res->layer);
cr_assert(fifo_empty(fifo), "FIFO should be empty");
fifo_destroy(fifo);
}
Test(fifo, realloc, .disabled=0) {
elm_t *res;
uint32_t size = 4;
fifo_t *fifo = fifo_create(size);
cr_assert_not_null(fifo, "FIFO should not be NULL after creation");
fifo_push_back(fifo, 0, 2);
fifo_push_back(fifo, 1, 3);
fifo_push_back(fifo, 2, 1);
fifo_push_back(fifo, 3, 8);
fifo_push_back(fifo, 4, 3);
cr_assert_not(fifo_empty(fifo), "FIFO should not be empty");
res = fifo_pop_front(fifo);
cr_assert_eq(res->elm, 0, "Element: Expected %d got %d", 0, res->elm);
cr_assert_eq(res->layer, 2, "Layer: Expected %d got %d", 2, res->layer);
cr_assert_not(fifo_empty(fifo), "FIFO should not be empty");
res = fifo_pop_front(fifo);
cr_assert_eq(res->elm, 1, "Element: Expected %d got %d", 1, res->elm);
cr_assert_eq(res->layer, 3, "Layer: Expected %d got %d", 3, res->layer);
cr_assert_not(fifo_empty(fifo), "FIFO should not be empty");
res = fifo_pop_front(fifo);
cr_assert_eq(res->elm, 2, "Element: Expected %d got %d", 2, res->elm);
cr_assert_eq(res->layer, 1, "Layer: Expected %d got %d", 1, res->layer);
cr_assert_not(fifo_empty(fifo), "FIFO should not be empty");
res = fifo_pop_front(fifo);
cr_assert_eq(res->elm, 3, "Element: Expected %d got %d", 3, res->elm);
cr_assert_eq(res->layer, 8, "Layer: Expected %d got %d", 8, res->layer);
cr_assert_not(fifo_empty(fifo), "FIFO should not be empty");
res = fifo_pop_front(fifo);
cr_assert_eq(res->elm, 4, "Element: Expected %d got %d", 4, res->elm);
cr_assert_eq(res->layer, 3, "Layer: Expected %d got %d", 3, res->layer);
cr_assert(fifo_empty(fifo), "FIFO should be empty");
fifo_destroy(fifo);
}
Test(fifo, realloc_middle, .disabled=0) {
elm_t *res;
uint32_t size = 4;
fifo_t *fifo = fifo_create(size);
cr_assert_not_null(fifo, "FIFO should not be NULL after creation");
fifo_push_back(fifo, 0, 2);
fifo_push_back(fifo, 1, 3);
fifo_push_back(fifo, 2, 1);
cr_assert_not(fifo_empty(fifo), "FIFO should not be empty");
res = fifo_pop_front(fifo);
cr_assert_eq(res->elm, 0, "Element: Expected %d got %d", 0, res->elm);
cr_assert_eq(res->layer, 2, "Layer: Expected %d got %d", 2, res->layer);
cr_assert_not(fifo_empty(fifo), "FIFO should not be empty");
res = fifo_pop_front(fifo);
cr_assert_eq(res->elm, 1, "Element: Expected %d got %d", 1, res->elm);
cr_assert_eq(res->layer, 3, "Layer: Expected %d got %d", 3, res->layer);
cr_assert_not(fifo_empty(fifo), "FIFO should not be empty");
fifo_push_back(fifo, 3, 8);
fifo_push_back(fifo, 4, 3);
fifo_push_back(fifo, 34, 0);
fifo_push_back(fifo, 3333, 7);
res = fifo_pop_front(fifo);
cr_assert_eq(res->elm, 2, "Element: Expected %d got %d", 2, res->elm);
cr_assert_eq(res->layer, 1, "Layer: Expected %d got %d", 1, res->layer);
cr_assert_not(fifo_empty(fifo), "FIFO should not be empty");
res = fifo_pop_front(fifo);
cr_assert_eq(res->elm, 3, "Element: Expected %d got %d", 3, res->elm);
cr_assert_eq(res->layer, 8, "Layer: Expected %d got %d", 8, res->layer);
cr_assert_not(fifo_empty(fifo), "FIFO should not be empty");
res = fifo_pop_front(fifo);
cr_assert_eq(res->elm, 4, "Element: Expected %d got %d", 4, res->elm);
cr_assert_eq(res->layer, 3, "Layer: Expected %d got %d", 3, res->layer);
cr_assert_not(fifo_empty(fifo), "FIFO should not be empty");
res = fifo_pop_front(fifo);
cr_assert_eq(res->elm, 34, "Element: Expected %d got %d", 34, res->elm);
cr_assert_eq(res->layer, 0, "Layer: Expected %d got %d", 0, res->layer);
cr_assert_not(fifo_empty(fifo), "FIFO should not be empty");
res = fifo_pop_front(fifo);
cr_assert_eq(res->elm, 3333, "Element: Expected %d got %d", 3333, res->elm);
cr_assert_eq(res->layer, 7, "Layer: Expected %d got %d", 7, res->layer);
cr_assert(fifo_empty(fifo), "FIFO should be empty");
fifo_destroy(fifo);
}