123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- #include "config.h"
-
- #include <check.h>
- #include <errno.h>
- #include <stdio.h>
- #include <unistd.h>
-
- #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<ASMSH_SYMALLOC*3; i++)
- {
- char buf[16];
- snprintf(buf, 15, "a%d", i);
- ck_assert_int_eq(asmsh_symtable_add(&st, buf, NULL), 0);
- }
- for(int i=0; i<ASMSH_SYMALLOC*3; i++)
- {
- char buf[16];
- snprintf(buf, 15, "a%d", i);
- ck_assert_int_eq(asmsh_symtable_del(&st, buf), 1);
- }
- asmsh_symtable_clean(&st);
- }
- END_TEST
-
- ASMSH_CHECK_START("testing completion", "Testing completion features")
- ASMSH_ADD_TEST(init);
- ASMSH_ADD_TEST(add);
- ASMSH_ADD_TEST(del);
- ASMSH_ADD_TEST(get);
- ASMSH_ADD_TEST(_realloc);
- ASMSH_CHECK_END
|