#include "config.h" #include #include #include #include #include #include #include "asmsh_check.h" #include "history.h" START_TEST(test_filename) { char *fname; char expt_path[4096]; fname = history_filename_init("/foo"); ck_assert_ptr_nonnull(fname); snprintf(expt_path, sizeof(expt_path), "/foo/.local/share/asmsh/%s", ASMSH_HISTORY_FILE); ck_assert_str_eq(expt_path, fname); fname = history_filename_init(NULL); if(getenv("HOME")) { snprintf(expt_path, sizeof(expt_path), "%s/.local/share/asmsh/%s", getenv("HOME"), ASMSH_HISTORY_FILE); ck_assert_ptr_nonnull(fname); ck_assert_str_eq(expt_path, fname); } else { ck_assert_ptr_null(fname); } } END_TEST START_TEST(test_save) { // Do not test the written content, only check for segfaults const char * const hist[]={"foo", "bar", "super history", NULL}; save_history("/dev/null", hist); } END_TEST #define SAMPLE_HISTORY "samples/sample.history" static const char * const samples[] = { "hello world!", "mov $1312, %rax", "syscall", }; static int mock_add_calls = 0; static void mock_add_history(const char *str) { int sz = sizeof(samples)/sizeof(*samples); ck_assert(mock_add_calls < sz); ck_assert_str_eq(samples[mock_add_calls], str); mock_add_calls++; } START_TEST(test_load) { load_history(SAMPLE_HISTORY, mock_add_history); } ASMSH_CHECK_START("history utils", "testing history store/load functions") ASMSH_ADD_TEST(test_filename); ASMSH_ADD_TEST(test_save); ASMSH_ADD_TEST(test_load); ASMSH_CHECK_END