summaryrefslogtreecommitdiff
path: root/tests.c
blob: 4277a1949d4888476bba2159933c7ba1995cec08 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <assert.h>
#include <stdio.h>
#include "pbstream.c"

void test_get_v_uint64_t()
{
  enum pbstream_status status;

  char zero[] = {0x00};
  char *zero_buf = zero;
  uint64_t zero_val = 0;
  status = get_v_uint64_t(&zero_buf, &zero_val);
  assert(status == PBSTREAM_STATUS_OK);
  assert(zero_val == 0);
  assert(zero_buf == zero + sizeof(zero));

  char one[] = {0x01};
  char *one_buf = one;
  uint64_t one_val = 0;
  status = get_v_uint64_t(&one_buf, &one_val);
  assert(status == PBSTREAM_STATUS_OK);
  assert(one_val == 1);

  char twobyte[] = {0xAC, 0x02};
  char *twobyte_buf = twobyte;
  uint64_t twobyte_val = 0;
  status = get_v_uint64_t(&twobyte_buf, &twobyte_val);
  assert(status == PBSTREAM_STATUS_OK);
  assert(twobyte_val == 300);

  char ninebyte[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x7F};
  char *ninebyte_buf = ninebyte;
  uint64_t ninebyte_val = 0;
  status = get_v_uint64_t(&ninebyte_buf, &ninebyte_val);
  assert(status == PBSTREAM_STATUS_OK);
  assert(ninebyte_val == (1LL<<63));

  char tenbyte[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01};
  char *tenbyte_buf = tenbyte;
  uint64_t tenbyte_val = 0;
  status = get_v_uint64_t(&tenbyte_buf, &tenbyte_val);
  assert(status == PBSTREAM_ERROR_UNTERMINATED_VARINT);
}

int main()
{
  test_get_v_uint64_t();
  printf("All tests passed.\n");
  return 0;
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback