A shell that runs x86_64 assembly
c
x86-64
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tests_history.c 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "config.h"
  2. #include <check.h>
  3. #include <errno.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. #include "asmsh_check.h"
  9. #include "history.h"
  10. START_TEST(test_filename)
  11. {
  12. char *fname;
  13. char expt_path[4096];
  14. fname = history_filename_init("/foo");
  15. ck_assert_ptr_nonnull(fname);
  16. snprintf(expt_path, sizeof(expt_path), "/foo/.local/share/asmsh/%s",
  17. ASMSH_HISTORY_FILE);
  18. ck_assert_str_eq(expt_path, fname);
  19. fname = history_filename_init(NULL);
  20. if(getenv("HOME"))
  21. {
  22. snprintf(expt_path, sizeof(expt_path), "%s/.local/share/asmsh/%s",
  23. getenv("HOME"),
  24. ASMSH_HISTORY_FILE);
  25. ck_assert_ptr_nonnull(fname);
  26. ck_assert_str_eq(expt_path, fname);
  27. }
  28. else
  29. {
  30. ck_assert_ptr_null(fname);
  31. }
  32. }
  33. END_TEST
  34. START_TEST(test_save)
  35. {
  36. // Do not test the written content, only check for segfaults
  37. const char * const hist[]={"foo", "bar", "super history", NULL};
  38. save_history("/dev/null", hist);
  39. }
  40. END_TEST
  41. #define SAMPLE_HISTORY "samples/sample.history"
  42. static const char * const samples[] = {
  43. "hello world!",
  44. "mov $1312, %rax",
  45. "syscall",
  46. };
  47. static int mock_add_calls = 0;
  48. static void mock_add_history(const char *str)
  49. {
  50. int sz = sizeof(samples)/sizeof(*samples);
  51. ck_assert(mock_add_calls < sz);
  52. ck_assert_str_eq(samples[mock_add_calls], str);
  53. mock_add_calls++;
  54. }
  55. START_TEST(test_load)
  56. {
  57. load_history(SAMPLE_HISTORY, mock_add_history);
  58. }
  59. ASMSH_CHECK_START("history utils", "testing history store/load functions")
  60. ASMSH_ADD_TEST(test_filename);
  61. ASMSH_ADD_TEST(test_save);
  62. ASMSH_ADD_TEST(test_load);
  63. ASMSH_CHECK_END