#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "proftest.h" char *config_orig; char *data_orig; int fd = 0; gboolean _create_dir(const char *name) { struct stat sb; if (stat(name, &sb) != 0) { if (errno != ENOENT || mkdir(name, S_IRWXU) != 0) { return FALSE; } } else { if ((sb.st_mode & S_IFDIR) != S_IFDIR) { return FALSE; } } return TRUE; } gboolean _mkdir_recursive(const char *dir) { int i; gboolean result = TRUE; for (i = 1; i <= strlen(dir); i++) { if (dir[i] == '/' || dir[i] == '\0') { gchar *next_dir = g_strndup(dir, i); result = _create_dir(next_dir); g_free(next_dir); if (!result) { break; } } } return result; } void _create_config_dir(void) { GString *profanity_dir = g_string_new(XDG_CONFIG_HOME); g_string_append(profanity_dir, "/profanity"); if (!_mkdir_recursive(profanity_dir->str)) { assert_true(FALSE); } g_string_free(profanity_dir, TRUE); } void _create_data_dir(void) { GString *profanity_dir = g_string_new(XDG_DATA_HOME); g_string_append(profanity_dir, "/profanity"); if (!_mkdir_recursive(profanity_dir->str)) { assert_true(FALSE); } g_string_free(profanity_dir, TRUE); } void _create_chatlogs_dir(void) { GString *chatlogs_dir = g_string_new(XDG_DATA_HOME); g_string_append(chatlogs_dir, "/profanity/chatlogs"); if (!_mkdir_recursive(chatlogs_dir->str)) { assert_true(FALSE); } g_string_free(chatlogs_dir, TRUE); } void _create_logs_dir(void) { GString *logs_dir = g_string_new(XDG_DATA_HOME); g_string_append(logs_dir, "/profanity/logs"); if (!_mkdir_recursive(logs_dir->str)) { assert_true(FALSE); } g_string_free(logs_dir, TRUE); } void _cleanup_dirs(void) { int res = system("rm -rf ./tests/functionaltests/files"); if (res == -1) { assert_true(FALSE); } } void prof_start(void) { // helper script sets terminal columns, avoids assertions failing // based on the test runner terminal size fd = exp_spawnl("sh", "sh", "-c", "./tests/functionaltests/start_profanity.sh", NULL); FILE *fp = fdopen(fd, "r+"); assert_true(fp != NULL); setbuf(fp, (char *)0); } void init_prof_test(void **state) { if (stbbr_start(STBBR_LOGDEBUG ,5230, 0) != 0) { assert_true(FALSE); return; } config_orig = getenv("XDG_CONFIG_HOME"); data_orig = getenv("XDG_DATA_HOME"); setenv("XDG_CONFIG_HOME", XDG_CONFIG_HOME, 1); setenv("XDG_DATA_HOME", XDG_DATA_HOME, 1); _cleanup_dirs(); _create_config_dir(); _create_data_dir(); _create_chatlogs_dir(); _create_logs_dir(); prof_start(); assert_true(prof_output_exact("Profanity")); // set UI options to make expect assertions faster and more reliable prof_input("/inpblock timeout 5"); assert_true(prof_output_exact("Input blocking set to 5 milliseconds")); prof_input("/inpblock dynamic off"); assert_true(prof_output_exact("Dynamic input blocking disabled")); prof_input("/notify chat off"); assert_true(prof_output_exact("Chat notifications disabled")); prof_input("/notify room off"); assert_true(prof_output_exact("Room notifications disabled")); prof_input("/wrap off"); assert_true(prof_output_exact("Word wrap disabled")); prof_input("/ro