summaryrefslogtreecommitdiff
path: root/testsuite/buffer-test.c
blob: fe2e22243ff4123402a49a14213be4fae129877a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "testutils.h"
#include "buffer.h"

void
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")));
}