A shell that runs x86_64 assembly
c
x86-64
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

tests_shell_sym.c 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include "config.h"
  2. #include <check.h>
  3. #include <errno.h>
  4. #include <stdio.h>
  5. #include <unistd.h>
  6. #include "asmsh_check.h"
  7. #include "shell_env.h"
  8. START_TEST(init)
  9. {
  10. asmsh_symtable_t st;
  11. ck_assert_int_eq(asmsh_symtable_init(&st,0), 0);
  12. asmsh_symtable_clean(&st);
  13. }
  14. END_TEST
  15. START_TEST(add)
  16. {
  17. asmsh_symtable_t st;
  18. ck_assert_int_eq(asmsh_symtable_init(&st,0), 0);
  19. ck_assert_int_eq(asmsh_symtable_add(&st, "b", NULL), 0);
  20. ck_assert_int_eq(st.syms_sz, 1);
  21. ck_assert_int_eq(asmsh_symtable_add(&st, "a", NULL), 0);
  22. ck_assert_int_eq(st.syms_sz, 2);
  23. ck_assert_int_eq(asmsh_symtable_add(&st, "a", NULL), 0);
  24. ck_assert_int_eq(st.syms_sz, 2);
  25. ck_assert_int_eq(asmsh_symtable_add(&st, "ab", NULL), 0);
  26. ck_assert_int_eq(st.syms_sz, 3);
  27. asmsh_symtable_clean(&st);
  28. }
  29. END_TEST
  30. START_TEST(del)
  31. {
  32. asmsh_symtable_t st;
  33. ck_assert_int_eq(asmsh_symtable_init(&st,0), 0);
  34. ck_assert_int_eq(asmsh_symtable_del(&st, "a"), 0);
  35. ck_assert_int_eq(asmsh_symtable_add(&st, "a", NULL), 0);
  36. ck_assert_int_eq(asmsh_symtable_del(&st, "a"), 1);
  37. ck_assert_int_eq(asmsh_symtable_del(&st, "a"), 0);
  38. ck_assert_int_eq(asmsh_symtable_add(&st, "a", NULL), 0);
  39. ck_assert_int_eq(asmsh_symtable_add(&st, "b", NULL), 0);
  40. ck_assert_int_eq(asmsh_symtable_add(&st, "c", NULL), 0);
  41. ck_assert_int_eq(asmsh_symtable_del(&st, "d"), 0);
  42. ck_assert_int_eq(asmsh_symtable_del(&st, "b"), 1);
  43. ck_assert_int_eq(asmsh_symtable_del(&st, "b"), 0);
  44. ck_assert_int_eq(asmsh_symtable_add(&st, "b", NULL), 0);
  45. ck_assert_int_eq(asmsh_symtable_del(&st, "a"), 1);
  46. ck_assert_int_eq(asmsh_symtable_del(&st, "a"), 0);
  47. asmsh_symtable_clean(&st);
  48. }
  49. END_TEST
  50. START_TEST(get)
  51. {
  52. asmsh_symtable_t st;
  53. const asmsh_sym_t *s;
  54. ck_assert_int_eq(asmsh_symtable_init(&st,0), 0);
  55. ck_assert_ptr_null(asmsh_symtable_get(&st, "a"));
  56. ck_assert_int_eq(asmsh_symtable_add(&st, "a", NULL), 0);
  57. s = asmsh_symtable_get(&st, "a");
  58. ck_assert_ptr_nonnull(s);
  59. ck_assert_ptr_null(s->val);
  60. ck_assert_int_eq(asmsh_symtable_add(&st, "a", (void*)42), 0);
  61. s = asmsh_symtable_get(&st, "a");
  62. ck_assert_ptr_nonnull(s);
  63. ck_assert_ptr_eq(s->val, (void*)42);
  64. asmsh_symtable_clean(&st);
  65. }
  66. END_TEST
  67. START_TEST(_realloc)
  68. {
  69. asmsh_symtable_t st;
  70. ck_assert_int_eq(asmsh_symtable_init(&st,0), 0);
  71. for(int i=0; i<ASMSH_SYMALLOC*3; i++)
  72. {
  73. char buf[16];
  74. snprintf(buf, 15, "a%d", i);
  75. ck_assert_int_eq(asmsh_symtable_add(&st, buf, NULL), 0);
  76. }
  77. for(int i=0; i<ASMSH_SYMALLOC*3; i++)
  78. {
  79. char buf[16];
  80. snprintf(buf, 15, "a%d", i);
  81. ck_assert_int_eq(asmsh_symtable_del(&st, buf), 1);
  82. }
  83. asmsh_symtable_clean(&st);
  84. }
  85. END_TEST
  86. ASMSH_CHECK_START("testing completion", "Testing completion features")
  87. ASMSH_ADD_TEST(init);
  88. ASMSH_ADD_TEST(add);
  89. ASMSH_ADD_TEST(del);
  90. ASMSH_ADD_TEST(get);
  91. ASMSH_ADD_TEST(_realloc);
  92. ASMSH_CHECK_END