Debian Codegraph @

tests/agxbuf-print-nul.c

raw
1 /// \file
2 /// \brief test that `agxbprint` should not account for nor append a NUL byte
3 ///
4 /// This program accesses `agxbuf` internals in a way that is not expected from
5 /// users. This is testing the internal behavior of `agxbuf` itself.
6
7 #ifdef NDEBUG
8 #error "this program is not intended to be compiled with assertions disabled"
9 #endif
10
11 #include <assert.h>
12 #include <stdlib.h>
13 #include <util/agxbuf.h>
14
15 int main(void) {
16
17 agxbuf xb = {0};
18 assert(agxbuf_is_inline(&xb));
19
20 // construct a string that should fit in the `agxbuf` inline storage
21 char content[sizeof(xb.store) + 1] = {0};
22 for (size_t i = 0; i < sizeof(content) - 1; ++i) {
23 content[i] = 'A' + (char)i;
24 }
25
26 // now we should be able to print this to the buffer while remaining inline
27 agxbprint(&xb, "%s", content);
28 assert(agxbuf_is_inline(&xb));
29
30 return EXIT_SUCCESS;
31 }