diff --git a/testsuite/buffer-test.c b/testsuite/buffer-test.c new file mode 100644 index 0000000000000000000000000000000000000000..3ac4b207ddd36b6c2125bd6cf3cb05bf66a050fd --- /dev/null +++ b/testsuite/buffer-test.c @@ -0,0 +1,29 @@ +#include "testutils.h" +#include "buffer.h" + +int +test_main(void) +{ + struct nettle_buffer buffer; + uint8_t s[5]; + + nettle_buffer_init(&buffer); + ASSERT(nettle_buffer_write(&buffer, LDATA("foo"))); + + ASSERT(NETTLE_BUFFER_PUTC(&buffer, 'x')); + + ASSERT(buffer.size == 4); + ASSERT(buffer.alloc >= 4); + ASSERT(MEMEQ(4, buffer.contents, "foox")); + + nettle_buffer_clear(&buffer); + + nettle_buffer_init_size(&buffer, sizeof(s), s); + ASSERT(buffer.alloc == sizeof(s)); + ASSERT(nettle_buffer_write(&buffer, LDATA("foo"))); + ASSERT(buffer.size == 3); + + ASSERT(!nettle_buffer_write(&buffer, LDATA("bar"))); + + SUCCESS(); +}