Skip to content

Commit 7fb7fb6

Browse files
committed
Add test for csp_queue_empty
libcsp now get a new function, csp_queue_empty(). Test it. Signed-off-by: Yasushi SHOJI <[email protected]>
1 parent 6b0c3e3 commit 7fb7fb6

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/queue.c

+44
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,48 @@ ZTEST(queue, test_queue_free)
197197
zassert_equal(csp_queue_free(qh), qlength);
198198
}
199199

200+
ZTEST(queue, test_queue_emtpy)
201+
{
202+
char item1[] = "abc";
203+
204+
int qlength = 10;
205+
int buf_size = qlength * sizeof(item1);
206+
char buf[buf_size];
207+
208+
csp_queue_handle_t qh;
209+
csp_static_queue_t q;
210+
211+
/* zero clear */
212+
memset(buf, 0, buf_size);
213+
214+
csp_init();
215+
216+
/* create */
217+
qh = csp_queue_create_static(qlength, sizeof(item1), buf, &q);
218+
219+
csp_queue_enqueue(qh, item1, 1000);
220+
csp_queue_enqueue(qh, item1, 1000);
221+
csp_queue_enqueue(qh, item1, 1000);
222+
csp_queue_enqueue(qh, item1, 1000);
223+
224+
/* After enqueue, check the size */
225+
zassert_equal(4, csp_queue_size(qh));
226+
227+
/* After empty, check the size */
228+
csp_queue_empty(qh);
229+
zassert_equal(0, csp_queue_size(qh));
230+
231+
/* It's ok to call queue_empty on an empty queue */
232+
csp_queue_empty(qh);
233+
zassert_equal(0, csp_queue_size(qh));
234+
235+
/* make it full */
236+
for (int i = 0; i < qlength; i++) {
237+
csp_queue_enqueue(qh, item1, 1000);
238+
}
239+
/* then empty it */
240+
csp_queue_empty(qh);
241+
zassert_equal(0, csp_queue_size(qh));
242+
}
243+
200244
ZTEST_SUITE(queue, NULL, NULL, NULL, NULL, NULL);

0 commit comments

Comments
 (0)