Add a new module implementing a queue data structure.
Since the functions are simple make them inline functions. This provides a small code size saving.
This commit is contained in:
32
tests/app_queue_test/src/app_queue_test.xc
Normal file
32
tests/app_queue_test/src/app_queue_test.xc
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "queue.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#define VERIFY(x) do { if (!(x)) _Exit(1); } while(0)
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
|
||||
|
||||
int main()
|
||||
{
|
||||
queue_t q;
|
||||
unsigned array[4];
|
||||
const unsigned size = ARRAY_SIZE(array);
|
||||
queue_init(q, size);
|
||||
VERIFY(queue_is_empty(q));
|
||||
VERIFY(!queue_is_full(q));
|
||||
VERIFY(queue_items(q) == 0);
|
||||
VERIFY(queue_space(q) == size);
|
||||
queue_push_word(q, array, 1);
|
||||
VERIFY(!queue_is_empty(q));
|
||||
VERIFY(queue_items(q) == 1);
|
||||
VERIFY(queue_space(q) == size - 1);
|
||||
for (unsigned i = 1; i < size; i++) {
|
||||
queue_push_word(q, array, i + 1);
|
||||
}
|
||||
VERIFY(queue_is_full(q));
|
||||
VERIFY(queue_items(q) == size);
|
||||
VERIFY(queue_space(q) == 0);
|
||||
for (unsigned i = 0; i < size; i++) {
|
||||
VERIFY(queue_pop_word(q, array) == i + 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user