blob: e1e42454ddd9a475ccd6485d19ba4c7b3bc71fc3 [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 };
Jeremy Kerrc9775ce2017-02-07 16:25:34 +080014 struct rb_test_ctx _ctx, *ctx = &_ctx;
15 struct ringbuffer *rb;
16 int rc;
17
18 ringbuffer_test_context_init(ctx);
19
20 rb = ringbuffer_init(5);
21
Andrew Jefferya72711a2023-04-18 18:19:41 +093022 ctx->rbc = ringbuffer_consumer_register(rb, ringbuffer_poll_append_all,
23 ctx);
Jeremy Kerrc9775ce2017-02-07 16:25:34 +080024
25 ctx->force_only = true;
26
27 /* fill the ringbuffer */
28 rc = ringbuffer_queue(rb, in_buf, 4);
29 assert(!rc);
30
31 assert(ctx->count == 0);
32
33 /* add more data */
34 rc = ringbuffer_queue(rb, in_buf + 4, 2);
35 assert(!rc);
36
37 /* we should have had a forced poll for the initial two bytes */
38 assert(ctx->count == 1);
39 assert(ctx->len == 2);
40 assert(!memcmp(in_buf, ctx->data, 2));
41
42 ringbuffer_fini(rb);
43 ringbuffer_test_context_fini(ctx);
44}
45
46int main(void)
47{
48 test_poll_force();
49 return EXIT_SUCCESS;
50}