1
2 #include <stdlib.h>
3 #include <stdint.h>
4 #include <stdio.h>
5
6 #include "ringbuffer.c"
7 #include "ringbuffer-test-utils.c"
8
test_poll_force(void)9 void test_poll_force(void)
10 {
11 uint8_t in_buf[] = {
12 'a', 'b', 'c', 'd', 'e', 'f',
13 };
14 struct rb_test_ctx _ctx;
15 struct rb_test_ctx *ctx = &_ctx;
16 struct ringbuffer *rb;
17 int rc;
18
19 ringbuffer_test_context_init(ctx);
20
21 rb = ringbuffer_init(5);
22
23 ctx->rbc = ringbuffer_consumer_register(rb, ringbuffer_poll_append_all,
24 ctx);
25
26 ctx->force_only = true;
27
28 /* fill the ringbuffer */
29 rc = ringbuffer_queue(rb, in_buf, 4);
30 assert(!rc);
31
32 assert(ctx->count == 0);
33
34 /* add more data */
35 rc = ringbuffer_queue(rb, in_buf + 4, 2);
36 assert(!rc);
37
38 /* we should have had a forced poll for the initial two bytes */
39 assert(ctx->count == 1);
40 assert(ctx->len == 2);
41 assert(!memcmp(in_buf, ctx->data, 2));
42
43 ringbuffer_fini(rb);
44 ringbuffer_test_context_fini(ctx);
45 }
46
main(void)47 int main(void)
48 {
49 test_poll_force();
50 return EXIT_SUCCESS;
51 }
52