mirror of https://github.com/tailix/libshmemq.git
Add test "cons_reaches_queue_end"
This commit is contained in:
parent
81b4a0a488
commit
ce608407d1
|
@ -38,5 +38,6 @@
|
|||
/examples/raw_sender
|
||||
/tests/test_main
|
||||
/tests/test_cons_pops_buffer_start
|
||||
/tests/test_cons_reaches_queue_end
|
||||
/tests/test_prod_jumps_to_buffer_start_and_reaches_cons
|
||||
/tests/test_prod_reaches_buffer_end
|
||||
|
|
|
@ -11,6 +11,7 @@ lib_LIBRARIES = libshmemq.a
|
|||
TESTS = \
|
||||
tests/test_main \
|
||||
tests/test_cons_pops_buffer_start \
|
||||
tests/test_cons_reaches_queue_end \
|
||||
tests/test_prod_jumps_to_buffer_start_and_reaches_cons \
|
||||
tests/test_prod_reaches_buffer_end
|
||||
|
||||
|
@ -37,6 +38,10 @@ tests_test_cons_pops_buffer_start_SOURCES = \
|
|||
$(libshmemq_a_SOURCES) \
|
||||
tests/test_cons_pops_buffer_start.c
|
||||
|
||||
tests_test_cons_reaches_queue_end_SOURCES = \
|
||||
$(libshmemq_a_SOURCES) \
|
||||
tests/test_cons_reaches_queue_end.c
|
||||
|
||||
tests_test_prod_jumps_to_buffer_start_and_reaches_cons_SOURCES = \
|
||||
$(libshmemq_a_SOURCES) \
|
||||
tests/test_prod_jumps_to_buffer_start_and_reaches_cons.c
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
#include <shmemq.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
static const char name[] = "/foobar";
|
||||
|
||||
int main()
|
||||
{
|
||||
ShmemqError error;
|
||||
|
||||
const Shmemq consumer = shmemq_new(name, true, &error);
|
||||
assert(error == SHMEMQ_ERROR_NONE);
|
||||
|
||||
const Shmemq producer = shmemq_new(name, false, &error);
|
||||
assert(error == SHMEMQ_ERROR_NONE);
|
||||
|
||||
for (unsigned i = 0; i < 25; ++i) {
|
||||
const ShmemqFrame frame = shmemq_push_start(producer);
|
||||
assert(frame != NULL);
|
||||
|
||||
*(unsigned*)frame->data = i;
|
||||
|
||||
shmemq_push_end(producer, sizeof(unsigned), &error);
|
||||
assert(error == SHMEMQ_ERROR_NONE);
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < 25; ++i) {
|
||||
const ShmemqFrame frame = shmemq_pop_start(consumer);
|
||||
assert(frame != NULL);
|
||||
|
||||
assert(*(unsigned*)frame->data == i);
|
||||
|
||||
shmemq_pop_end(consumer, &error);
|
||||
assert(error == SHMEMQ_ERROR_NONE);
|
||||
}
|
||||
|
||||
assert(shmemq_pop_start(consumer) == NULL);
|
||||
|
||||
shmemq_pop_end(consumer, &error);
|
||||
assert(error == SHMEMQ_ERROR_BUG_POP_END_ON_EMPTY_QUEUE);
|
||||
|
||||
shmemq_delete(consumer, &error);
|
||||
assert(error == SHMEMQ_ERROR_NONE);
|
||||
|
||||
shmemq_delete(producer, &error);
|
||||
assert(error == SHMEMQ_ERROR_NONE);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue