diff options
Diffstat (limited to 'src/libmain.c')
| -rw-r--r-- | src/libmain.c | 68 |
1 files changed, 30 insertions, 38 deletions
diff --git a/src/libmain.c b/src/libmain.c index e82635d..c6d1c29 100644 --- a/src/libmain.c +++ b/src/libmain.c @@ -1,56 +1,48 @@ -#include "xxhash.h" #include <string.h> #include <stdint.h> #include <stdio.h> - -#define HT_IMPLEMENTATIONS -#define HTGEN__TEST_CONFIG -#include "htgen.h" +#include <stdlib.h> #include "nbt.h" -#if 1 -int main(int argc, char **argv) { - shash_t *hash = shash_create(4, 0.75f); - printf("%d\n", shash_put(hash, "test1", "value1")); - printf("%d\n", shash_put(hash, "testbro", "val2")); - shash__debug_table(hash); - - char *oldval = shash_pop(hash, "test1", NULL); - printf("%s:%s\n", "test1", oldval); - free(oldval); +void debug_list(nbt_tag_t *tag) { + if (!tag) { + printf("list: (null)\n"); + return; + } - shash__debug_table(hash); - printf("%d\n", shash_put(hash, "testbro", "val3")); - shash__debug_table(hash); + printf("list %p (%zu len, %zu cap)\n", tag, nbt_list_length(tag), nbt_list_capacity(tag)); - shash_free(hash); - - return 0; + 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))); + } } -#else -int main(int argc, char **argv) +void test__is_true(int i, const char *test, const char *ex, const char *file, int line, const char *func) { - ihash_t *hash = ihash_create(8, 0.75f); + if (!i) { + fprintf(stderr, "Test \"%s\" failed: %s == %d (%s:%d @ %s)\n", test, ex, i, file, line, func); + abort(); + } +} - printf("%d\n", ihash_put(hash, 1, 10)); - ihash__debug_table(hash); - printf("%d\n", ihash_put(hash, 5, 20)); - printf("%d\n", ihash_put(hash, 3, 19)); - printf("%d\n", ihash_put(hash, 56, 101)); - ihash__debug_table(hash); - printf("%d\n", ihash_put(hash, 90, 6)); - printf("%d\n", ihash_put(hash, 2000, 1)); - ihash__debug_table(hash); - printf("%d\n", ihash_put(hash, 4, 2020)); +void nbt_compound_clear(nbt_tag_t *a) { } - ihash__debug_table(hash); +#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__) - ihash_free(hash); +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; } - -#endif |
