#include "config.h" #include #include #include #include #include "asmsh_check.h" #include "shell_env.h" START_TEST(init) { asmsh_symtable_t st; ck_assert_int_eq(asmsh_symtable_init(&st,0), 0); asmsh_symtable_clean(&st); } END_TEST START_TEST(add) { asmsh_symtable_t st; ck_assert_int_eq(asmsh_symtable_init(&st,0), 0); ck_assert_int_eq(asmsh_symtable_add(&st, "b", NULL), 0); ck_assert_int_eq(st.syms_sz, 1); ck_assert_int_eq(asmsh_symtable_add(&st, "a", NULL), 0); ck_assert_int_eq(st.syms_sz, 2); ck_assert_int_eq(asmsh_symtable_add(&st, "a", NULL), 0); ck_assert_int_eq(st.syms_sz, 2); ck_assert_int_eq(asmsh_symtable_add(&st, "ab", NULL), 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), 0); ck_assert_int_eq(asmsh_symtable_del(&st, "a"), 0); ck_assert_int_eq(asmsh_symtable_add(&st, "a", NULL), 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", NULL), 0); ck_assert_int_eq(asmsh_symtable_add(&st, "b", NULL), 0); ck_assert_int_eq(asmsh_symtable_add(&st, "c", NULL), 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", NULL), 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), 0); ck_assert_ptr_null(asmsh_symtable_get(&st, "a")); ck_assert_int_eq(asmsh_symtable_add(&st, "a", NULL), 0); s = asmsh_symtable_get(&st, "a"); ck_assert_ptr_nonnull(s); ck_assert_ptr_null(s->val); ck_assert_int_eq(asmsh_symtable_add(&st, "a", (void*)42), 0); s = asmsh_symtable_get(&st, "a"); ck_assert_ptr_nonnull(s); ck_assert_ptr_eq(s->val, (void*)42); asmsh_symtable_clean(&st); } END_TEST START_TEST(_realloc) { asmsh_symtable_t st; ck_assert_int_eq(asmsh_symtable_init(&st,0), 0); for(int i=0; i