2015-05-16 20:11:03 -04:00
|
|
|
#include <sys/stat.h>
|
2020-06-04 06:02:02 -04:00
|
|
|
#include <sys/wait.h>
|
2015-05-16 20:11:03 -04:00
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <cmocka.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
2015-05-17 18:10:30 -04:00
|
|
|
#include <errno.h>
|
2015-05-26 18:22:05 -04:00
|
|
|
#include <string.h>
|
2015-05-16 20:11:03 -04:00
|
|
|
|
2015-05-23 19:56:13 -04:00
|
|
|
#include <stabber.h>
|
2015-05-26 18:22:05 -04:00
|
|
|
#include <expect.h>
|
2015-05-16 20:11:03 -04:00
|
|
|
|
2015-05-28 14:01:49 -04:00
|
|
|
#include "proftest.h"
|
2015-05-16 20:11:03 -04:00
|
|
|
|
2015-05-23 19:56:13 -04:00
|
|
|
char *config_orig;
|
|
|
|
char *data_orig;
|
|
|
|
|
2015-05-26 20:06:17 -04:00
|
|
|
int fd = 0;
|
|
|
|
|
2015-05-16 20:11:03 -04:00
|
|
|
gboolean
|
2020-10-15 04:12:33 -04:00
|
|
|
_create_dir(const char *name)
|
2015-05-16 20:11:03 -04:00
|
|
|
{
|
|
|
|
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);
|
2015-05-26 18:22:05 -04:00
|
|
|
result = _create_dir(next_dir);
|
2015-05-16 20:11:03 -04:00
|
|
|
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)
|
|
|
|
{
|
2015-06-13 14:41:11 -04:00
|
|
|
int res = system("rm -rf ./tests/functionaltests/files");
|
2015-05-17 18:10:30 -04:00
|
|
|
if (res == -1) {
|
|
|
|
assert_true(FALSE);
|
|
|
|
}
|
2015-05-16 20:11:03 -04:00
|
|
|
}
|
|
|
|
|
2015-05-28 13:50:55 -04:00
|
|
|
void
|
|
|
|
prof_start(void)
|
|
|
|
{
|
2015-06-13 18:59:33 -04:00
|
|
|
// 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);
|
2015-05-28 13:50:55 -04:00
|
|
|
FILE *fp = fdopen(fd, "r+");
|
|
|
|
|
2015-06-13 18:59:33 -04:00
|
|
|
assert_true(fp != NULL);
|
2015-05-28 13:50:55 -04:00
|
|
|
|
|
|
|
setbuf(fp, (char *)0);
|
|
|
|
}
|
|
|
|
|
2023-11-01 20:30:08 -04:00
|
|
|
int
|
2015-05-16 20:11:03 -04:00
|
|
|
init_prof_test(void **state)
|
|
|
|
{
|
2015-06-08 15:53:41 -04:00
|
|
|
if (stbbr_start(STBBR_LOGDEBUG ,5230, 0) != 0) {
|
2015-05-23 19:56:13 -04:00
|
|
|
assert_true(FALSE);
|
2023-11-01 20:30:08 -04:00
|
|
|
return -1;
|
2015-05-23 19:56:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
config_orig = getenv("XDG_CONFIG_HOME");
|
|
|
|
data_orig = getenv("XDG_DATA_HOME");
|
|
|
|
|
2015-05-16 20:11:03 -04:00
|
|
|
setenv("XDG_CONFIG_HOME", XDG_CONFIG_HOME, 1);
|
|
|
|
setenv("XDG_DATA_HOME", XDG_DATA_HOME, 1);
|
|
|
|
|
2015-05-23 23:13:28 -04:00
|
|
|
_cleanup_dirs();
|
|
|
|
|
2015-05-16 20:11:03 -04:00
|
|
|
_create_config_dir();
|
|
|
|
_create_data_dir();
|
|
|
|
_create_chatlogs_dir();
|
|
|
|
_create_logs_dir();
|
2015-05-26 20:06:17 -04:00
|
|
|
|
|
|
|
prof_start();
|
2015-06-13 18:59:33 -04:00
|
|
|
assert_true(prof_output_exact("Profanity"));
|
2015-06-06 21:41:54 -04:00
|
|
|
|
2015-06-13 18:59:33 -04:00
|
|
|
// set UI options to make expect assertions faster and more reliable
|
2015-06-06 21:41:54 -04:00
|
|
|
prof_input("/inpblock timeout 5");
|
2015-06-13 18:59:33 -04:00
|
|
|
assert_true(prof_output_exact("Input blocking set to 5 milliseconds"));
|
2015-06-06 21:41:54 -04:00
|
|
|
prof_input("/inpblock dynamic off");
|
2015-06-13 18:59:33 -04:00
|
|
|
assert_true(prof_output_exact("Dynamic input blocking disabled"));
|
2015-11-28 19:16:00 -05:00
|
|
|
prof_input("/notify chat off");
|
|
|
|
assert_true(prof_output_exact("Chat notifications disabled"));
|
2015-12-19 21:57:01 -05:00
|
|
|
prof_input("/notify room off");
|
|
|
|
assert_true(prof_output_exact("Room notifications disabled"));
|
2015-06-13 18:59:33 -04:00
|
|
|
prof_input("/wrap off");
|
|
|
|
assert_true(prof_output_exact("Word wrap disabled"));
|
|
|
|
prof_input("/roster hide");
|
|
|
|
assert_true(prof_output_exact("Roster disabled"));
|
2016-09-25 19:39:37 -04:00
|
|
|
prof_input("/occupants default hide");
|
|
|
|
assert_true(prof_output_exact("Occupant list disabled"));
|
2015-09-30 17:42:42 -04:00
|
|
|
prof_input("/time console off");
|
|
|
|
prof_input("/time console off");
|
|
|
|
assert_true(prof_output_exact("Console time display disabled."));
|
|
|
|
prof_input("/time chat off");
|
|
|
|
assert_true(prof_output_exact("Chat time display disabled."));
|
|
|
|
prof_input("/time muc off");
|
|
|
|
assert_true(prof_output_exact("MUC time display disabled."));
|
2018-04-11 12:57:50 -04:00
|
|
|
prof_input("/time config off");
|
|
|
|
assert_true(prof_output_exact("config time display disabled."));
|
2015-09-30 17:42:42 -04:00
|
|
|
prof_input("/time private off");
|
|
|
|
assert_true(prof_output_exact("Private chat time display disabled."));
|
|
|
|
prof_input("/time xml off");
|
|
|
|
assert_true(prof_output_exact("XML Console time display disabled."));
|
2023-11-01 20:30:08 -04:00
|
|
|
return 0;
|
2015-05-16 20:11:03 -04:00
|
|
|
}
|
|
|
|
|
2023-11-01 20:30:08 -04:00
|
|
|
int
|
2015-05-16 20:11:03 -04:00
|
|
|
close_prof_test(void **state)
|
|
|
|
{
|
2015-06-06 18:07:06 -04:00
|
|
|
prof_input("/quit");
|
|
|
|
waitpid(exp_pid, NULL, 0);
|
2015-05-16 20:11:03 -04:00
|
|
|
_cleanup_dirs();
|
2015-05-23 19:56:13 -04:00
|
|
|
|
|
|
|
setenv("XDG_CONFIG_HOME", config_orig, 1);
|
|
|
|
setenv("XDG_DATA_HOME", data_orig, 1);
|
|
|
|
|
2015-06-06 21:07:09 -04:00
|
|
|
stbbr_stop();
|
2023-11-01 20:30:08 -04:00
|
|
|
return 0;
|
2015-05-16 20:11:03 -04:00
|
|
|
}
|
2015-05-26 20:06:17 -04:00
|
|
|
|
|
|
|
void
|
2020-10-15 04:12:33 -04:00
|
|
|
prof_input(const char *input)
|
2015-05-26 20:06:17 -04:00
|
|
|
{
|
|
|
|
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
|
2020-10-15 04:12:33 -04:00
|
|
|
prof_output_exact(const char *text)
|
2015-05-26 20:06:17 -04:00
|
|
|
{
|
|
|
|
return (1 == exp_expectl(fd, exp_exact, text, 1, exp_end));
|
|
|
|
}
|
2015-05-28 15:02:16 -04:00
|
|
|
|
2015-05-28 20:01:34 -04:00
|
|
|
int
|
2020-10-15 04:12:33 -04:00
|
|
|
prof_output_regex(const char *text)
|
2015-05-28 20:01:34 -04:00
|
|
|
{
|
|
|
|
return (1 == exp_expectl(fd, exp_regexp, text, 1, exp_end));
|
|
|
|
}
|
|
|
|
|
2015-05-28 15:02:16 -04:00
|
|
|
void
|
2020-10-15 04:12:33 -04:00
|
|
|
prof_connect_with_roster(const char *roster)
|
2015-05-28 15:02:16 -04:00
|
|
|
{
|
2015-07-22 19:40:08 -04:00
|
|
|
GString *roster_str = g_string_new(
|
2015-12-29 19:12:24 -05:00
|
|
|
"<iq type='result' to='stabber@localhost/profanity'>"
|
|
|
|
"<query xmlns='jabber:iq:roster' ver='362'>"
|
2015-07-22 19:40:08 -04:00
|
|
|
);
|
|
|
|
g_string_append(roster_str, roster);
|
|
|
|
g_string_append(roster_str,
|
|
|
|
"</query>"
|
|
|
|
"</iq>"
|
|
|
|
);
|
|
|
|
|
|
|
|
stbbr_for_query("jabber:iq:roster", roster_str->str);
|
|
|
|
g_string_free(roster_str, TRUE);
|
2015-07-22 17:48:37 -04:00
|
|
|
|
2015-06-13 14:41:11 -04:00
|
|
|
stbbr_for_id("prof_presence_1",
|
2015-12-29 19:12:24 -05:00
|
|
|
"<presence id='prof_presence_1' lang='en' to='stabber@localhost/profanity' from='stabber@localhost/profanity'>"
|
2015-06-13 14:41:11 -04:00
|
|
|
"<priority>0</priority>"
|
2019-05-03 04:46:41 -04:00
|
|
|
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io/' ver='f8mrtdyAmhnj8Ca+630bThSL718='/>"
|
2015-06-13 14:41:11 -04:00
|
|
|
"</presence>"
|
|
|
|
);
|
|
|
|
|
2015-10-17 22:06:23 -04:00
|
|
|
prof_input("/connect stabber@localhost server 127.0.0.1 port 5230 tls allow");
|
2015-06-13 14:41:11 -04:00
|
|
|
prof_input("password");
|
|
|
|
|
2015-06-13 14:49:26 -04:00
|
|
|
// Allow time for profanity to connect
|
2015-10-12 19:32:02 -04:00
|
|
|
exp_timeout = 30;
|
2016-11-21 19:39:52 -05:00
|
|
|
assert_true(prof_output_regex("stabber@localhost/profanity logged in successfully, .+online.+ \\(priority 0\\)\\."));
|
2015-06-13 14:49:26 -04:00
|
|
|
exp_timeout = 10;
|
2015-07-14 19:23:46 -04:00
|
|
|
stbbr_wait_for("prof_presence_*");
|
2015-05-28 15:02:16 -04:00
|
|
|
}
|
2015-07-22 17:48:37 -04:00
|
|
|
|
2015-12-29 19:32:52 -05:00
|
|
|
void
|
|
|
|
prof_timeout(int timeout)
|
|
|
|
{
|
|
|
|
exp_timeout = timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
prof_timeout_reset(void)
|
|
|
|
{
|
|
|
|
exp_timeout = 10;
|
|
|
|
}
|
|
|
|
|
2015-07-22 17:48:37 -04:00
|
|
|
void
|
|
|
|
prof_connect(void)
|
|
|
|
{
|
|
|
|
prof_connect_with_roster(
|
2015-12-29 19:12:24 -05:00
|
|
|
"<item jid='buddy1@localhost' subscription='both' name='Buddy1'/>"
|
|
|
|
"<item jid='buddy2@localhost' subscription='both' name='Buddy2'/>"
|
2015-07-22 17:48:37 -04:00
|
|
|
);
|
|
|
|
}
|