blob: 34cc3480f312d9cbc0216c836c22352ffbc9dea2 [file] [log] [blame]
Jeremy Kerrc9775ce2017-02-07 16:25:34 +08001
2#include <stdlib.h>
3#include <stdint.h>
4#include <stdio.h>
5
6#include "ringbuffer.c"
7#include "ringbuffer-test-utils.c"
8
9void test_poll_force(void)
10{
Andrew Jefferya72711a2023-04-18 18:19:41 +093011 uint8_t in_buf[] = {
12 'a', 'b', 'c', 'd', 'e', 'f',
13 };
Andrew Jefferyb70f8712023-04-19 12:53:34 +093014 struct rb_test_ctx _ctx;
15 struct rb_test_ctx *ctx = &_ctx;
Jeremy Kerrc9775ce2017-02-07 16:25:34 +080016 struct ringbuffer *rb;
17 int rc;
18
19 ringbuffer_test_context_init(ctx);
20
21 rb = ringbuffer_init(5);
22
Andrew Jefferya72711a2023-04-18 18:19:41 +093023 ctx->rbc = ringbuffer_consumer_register(rb, ringbuffer_poll_append_all,
24 ctx);
Jeremy Kerrc9775ce2017-02-07 16:25:34 +080025
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
47int main(void)
48{
49 test_poll_force();
50 return EXIT_SUCCESS;
51}