diff options
author | James Booth <boothj5@gmail.com> | 2015-06-12 23:53:30 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-06-12 23:53:30 +0100 |
commit | 68ed20f10d2fae67b052674a42ed98c2059aa16f (patch) | |
tree | df8d1e7989282cc2e15dda3cd378b3b2895e9892 /functionaltests/proftest.c | |
parent | c182f3ecd6be5df9b9bc7757930e47b555ddd251 (diff) | |
download | profani-tty-68ed20f10d2fae67b052674a42ed98c2059aa16f.tar.gz |
Moved all tests to tests folder
Diffstat (limited to 'functionaltests/proftest.c')
-rw-r--r-- | functionaltests/proftest.c | 213 |
1 files changed, 0 insertions, 213 deletions
diff --git a/functionaltests/proftest.c b/functionaltests/proftest.c deleted file mode 100644 index 5d7b6585..00000000 --- a/functionaltests/proftest.c +++ /dev/null @@ -1,213 +0,0 @@ -#include <sys/stat.h> -#include <glib.h> - -#include <setjmp.h> -#include <stdarg.h> -#include <stddef.h> -#include <stdlib.h> -#include <cmocka.h> -#include <stdio.h> -#include <unistd.h> -#include <errno.h> -#include <string.h> - -#include <stabber.h> -#include <expect.h> - -#include "proftest.h" - -char *config_orig; -char *data_orig; - -int fd = 0; - -gboolean -_create_dir(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 ./functionaltests/files"); - if (res == -1) { - assert_true(FALSE); - } -} - -void -prof_start(void) -{ - fd = exp_spawnl("./profanity", NULL); - FILE *fp = fdopen(fd, "r+"); - - if (fp == NULL) { - assert_true(FALSE); - } - - 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(); - prof_output_exact("Profanity"); - - prof_input("/inpblock timeout 5"); - prof_output_exact("Input blocking set to 5 milliseconds"); - prof_input("/inpblock dynamic off"); - prof_output_exact("Dynamic input blocking disabled"); - - prof_input("/notify message off"); - prof_output_exact("Message notifications disabled"); -} - -void -close_prof_test(void **state) -{ - prof_input("/quit"); - waitpid(exp_pid, NULL, 0); - _cleanup_dirs(); - - setenv("XDG_CONFIG_HOME", config_orig, 1); - setenv("XDG_DATA_HOME", data_orig, 1); - - stbbr_stop(); -} - -void -prof_input(char *input) -{ - GString *inp_str = g_string_new(input); - g_string_append(inp_str, "\r"); - write(fd, inp_str->str, inp_str->len); - g_string_free(inp_str, TRUE); -} - -int -prof_output_exact(char *text) -{ - return (1 == exp_expectl(fd, exp_exact, text, 1, exp_end)); -} - -int -prof_output_regex(char *text) -{ - return (1 == exp_expectl(fd, exp_regexp, text, 1, exp_end)); -} - -void -prof_connect(char *jid, char *password) -{ - GString *connect_cmd = g_string_new("/connect "); - g_string_append(connect_cmd, jid); - g_string_append(connect_cmd, " port 5230"); - prof_input(connect_cmd->str); - g_string_free(connect_cmd, TRUE); - - prof_input(password); -} |