#include "config.h" #include #include #include #include #include "asmsh_check.h" #include "shell_sym.h" START_TEST(init) { asmsh_symtable_t st; ck_assert_int_eq(asmsh_symtable_init(&st), 0); asmsh_symtable_clean(&st); } END_TEST START_TEST(add) { asmsh_symtable_t st; ck_assert_int_eq(asmsh_symtable_init(&st), 0); ck_assert_int_eq(asmsh_symtable_add(&st, "b", 0), 0); ck_assert_int_eq(st.syms_sz, 1); ck_assert_int_eq(asmsh_symtable_add(&st, "a", 0), 0); ck_assert_int_eq(st.syms_sz, 2); ck_assert_int_eq(asmsh_symtable_add(&st, "a", 0), 0); ck_assert_int_eq(st.syms_sz, 2); ck_assert_int_eq(asmsh_symtable_add(&st, "ab", 0), 0); ck_assert_int_eq(st.syms_sz, 3); asmsh_symtable_clean(&st); } END_TEST START_TEST(del) { asmsh_symtable_t st; ck_assert_int_eq(asmsh_symtable_init(&st), 0); ck_assert_int_eq(asmsh_symtable_del(&st, "a"), 0); ck_assert_int_eq(asmsh_symtable_add(&st, "a", 0), 0); ck_assert_int_eq(asmsh_symtable_del(&st, "a"), 1); ck_assert_int_eq(asmsh_symtable_del(&st, "a"), 0); ck_assert_int_eq(asmsh_symtable_add(&st, "a", 0), 0); ck_assert_int_eq(asmsh_symtable_add(&st, "b", 0), 0); ck_assert_int_eq(asmsh_symtable_add(&st, "c", 0), 0); ck_assert_int_eq(asmsh_symtable_del(&st, "d"), 0); ck_assert_int_eq(asmsh_symtable_del(&st, "b"), 1); ck_assert_int_eq(asmsh_symtable_del(&st, "b"), 0); ck_assert_int_eq(asmsh_symtable_add(&st, "b", 0), 0); ck_assert_int_eq(asmsh_symtable_del(&st, "a"), 1); ck_assert_int_eq(asmsh_symtable_del(&st, "a"), 0); asmsh_symtable_clean(&st); } END_TEST START_TEST(get) { asmsh_symtable_t st; const asmsh_sym_t *s; ck_assert_int_eq(asmsh_symtable_init(&st), 0); ck_assert_ptr_null(asmsh_symtable_get(&st, "a")); ck_assert_int_eq(asmsh_symtable_add(&st, "a", 0), 0); s = asmsh_symtable_get(&st, "a"); ck_assert_ptr_nonnull(s); ck_assert_int_eq(s->addr, 0); ck_assert_int_eq(asmsh_symtable_add(&st, "a", 42), 0); s = asmsh_symtable_get(&st, "a"); ck_assert_ptr_nonnull(s); ck_assert_int_eq(s->addr, 42); asmsh_symtable_clean(&st); } END_TEST START_TEST(_realloc) { asmsh_symtable_t st; ck_assert_int_eq(asmsh_symtable_init(&st), 0); for(int i=0; i