summaryrefslogtreecommitdiffstats
path: root/src/libmain.c
blob: c6d1c29b4dd1d4b9df398ad16e621593afe81607 (plain) (blame)
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
#include <string.h>

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#include "nbt.h"

void debug_list(nbt_tag_t *tag) {
  if (!tag) {
    printf("list: (null)\n");
    return;
  }

  printf("list %p (%zu len, %zu cap)\n", tag, nbt_list_length(tag), nbt_list_capacity(tag));

  for (size_t n = 0; n < nbt_list_length(tag); ++n) {
    nbt_tag_t *t = nbt_list_get(tag, n);
    printf("%zu %p: tag %p(%s)\n", n, tag, t, nbt_typestr(nbt_tag_type(tag)));
  }
}

void test__is_true(int i, const char *test, const char *ex, const char *file, int line, const char *func)
{
  if (!i) {
    fprintf(stderr, "Test \"%s\" failed: %s == %d (%s:%d @ %s)\n", test, ex, i, file, line, func);
    abort();
  }
}

void nbt_compound_clear(nbt_tag_t *a) { }

#define TEST_TRUE(_e) test__is_true(_e, "is true", #_e, __FILE__, __LINE__, __func__)
#define TEST_NONNULL(_e) test__is_true(!!(_e), "is nonnull", #_e, __FILE__, __LINE__, __func__)

int main(int argc, char **argv) {
  nbt_tag_t *list = nbt_list();
  debug_list(list);

  TEST_TRUE(nbt_list_append_move(list, nbt_byte(5)) >= 0);
  TEST_TRUE(nbt_list_append_move(list, nbt_string("somestr")) >= 0);

  debug_list(list);

  nbt_decref(list);

  return 0;
}