1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-16 21:35:24 +00:00

Merge branch 'master' into openpgp

Conflicts:
	.travis.yml
This commit is contained in:
James Booth 2015-06-05 23:02:56 +01:00
commit 9aff8abd2e
82 changed files with 968 additions and 53 deletions

5
.gitignore vendored
View File

@ -69,3 +69,8 @@ callgrind.out.*
gen_docs.sh
main_fragment.html
toc_fragment.html
unittests/unittests
unittests/unittests.trs
functionaltests/functionaltests
functionaltests/functionaltests.trs

View File

@ -1,7 +1,9 @@
language: c
install:
- lsb_release -a
- uname -a
- sudo apt-get update
- sudo apt-get -y install libssl-dev libexpat1-dev libncursesw5-dev libglib2.0-dev libnotify-dev libcurl3-dev libxss-dev libotr2-dev libgpgme11-dev uuid-dev
- sudo apt-get -y install libssl-dev libexpat1-dev libncursesw5-dev libglib2.0-dev libnotify-dev libcurl3-dev libxss-dev libotr2-dev libgpgme11-dev uuid-dev expect-dev tcl-dev
- git clone git://github.com/strophe/libstrophe.git
- cd libstrophe
- mkdir m4
@ -21,5 +23,14 @@ install:
- sudo make install
- cd ../..
- rm -rf cmocka-1.0.0
- sudo apt-get install libmicrohttpd-dev
- git clone git://github.com/boothj5/stabber.git
- cd stabber
- ./bootstrap.sh
- ./configure --prefix=/usr
- make
- sudo make install
- cd ..
- rm -rf stabber
- ./bootstrap.sh
script: ./configure && make && make check

View File

@ -35,7 +35,7 @@ core_sources = \
src/config/preferences.c src/config/preferences.h \
src/config/theme.c src/config/theme.h
tests_sources = \
unittest_sources = \
src/contact.c src/contact.h src/common.c \
src/log.h src/profanity.c src/common.h \
src/profanity.h src/chat_session.c \
@ -66,34 +66,43 @@ tests_sources = \
src/event/server_events.c src/event/server_events.h \
src/event/client_events.c src/event/client_events.h \
src/event/ui_events.c src/event/ui_events.h \
tests/xmpp/stub_xmpp.c \
tests/ui/stub_ui.c \
tests/log/stub_log.c \
tests/config/stub_accounts.c \
tests/helpers.c tests/helpers.h \
tests/test_cmd_account.c tests/test_cmd_account.h \
tests/test_cmd_alias.c tests/test_cmd_alias.h \
tests/test_cmd_bookmark.c tests/test_cmd_bookmark.h \
tests/test_cmd_connect.c tests/test_cmd_connect.h \
tests/test_cmd_join.c tests/test_cmd_join.h \
tests/test_cmd_otr.c tests/test_cmd_otr.h \
tests/test_cmd_rooms.c tests/test_cmd_rooms.h \
tests/test_cmd_roster.c tests/test_cmd_roster.h \
tests/test_cmd_statuses.c tests/test_cmd_statuses.h \
tests/test_cmd_sub.c tests/test_cmd_sub.h \
tests/test_cmd_disconnect.c tests/test_cmd_disconnect.h \
tests/test_common.c tests/test_common.h \
tests/test_contact.c tests/test_contact.h \
tests/test_form.c tests/test_form.h \
tests/test_jid.c tests/test_jid.h \
tests/test_muc.c tests/test_muc.h \
tests/test_parser.c tests/test_parser.h \
tests/test_preferences.c tests/test_preferences.h \
tests/test_roster_list.c tests/test_roster_list.h \
tests/test_server_events.c tests/test_server_events.h \
tests/test_autocomplete.c tests/test_autocomplete.h \
tests/test_chat_session.c tests/test_chat_session.h \
tests/testsuite.c
unittests/xmpp/stub_xmpp.c \
unittests/ui/stub_ui.c \
unittests/log/stub_log.c \
unittests/config/stub_accounts.c \
unittests/helpers.c unittests/helpers.h \
unittests/test_cmd_account.c unittests/test_cmd_account.h \
unittests/test_cmd_alias.c unittests/test_cmd_alias.h \
unittests/test_cmd_bookmark.c unittests/test_cmd_bookmark.h \
unittests/test_cmd_connect.c unittests/test_cmd_connect.h \
unittests/test_cmd_join.c unittests/test_cmd_join.h \
unittests/test_cmd_otr.c unittests/test_cmd_otr.h \
unittests/test_cmd_rooms.c unittests/test_cmd_rooms.h \
unittests/test_cmd_roster.c unittests/test_cmd_roster.h \
unittests/test_cmd_statuses.c unittests/test_cmd_statuses.h \
unittests/test_cmd_sub.c unittests/test_cmd_sub.h \
unittests/test_cmd_disconnect.c unittests/test_cmd_disconnect.h \
unittests/test_common.c unittests/test_common.h \
unittests/test_contact.c unittests/test_contact.h \
unittests/test_form.c unittests/test_form.h \
unittests/test_jid.c unittests/test_jid.h \
unittests/test_muc.c unittests/test_muc.h \
unittests/test_parser.c unittests/test_parser.h \
unittests/test_preferences.c unittests/test_preferences.h \
unittests/test_roster_list.c unittests/test_roster_list.h \
unittests/test_server_events.c unittests/test_server_events.h \
unittests/test_autocomplete.c unittests/test_autocomplete.h \
unittests/test_chat_session.c unittests/test_chat_session.h \
unittests/unittests.c
functionaltest_sources = \
functionaltests/proftest.c functionaltests/proftest.h \
functionaltests/test_connect.c functionaltests/test_connect.h \
functionaltests/test_ping.c functionaltests/test_ping.h \
functionaltests/test_rooms.c functionaltests/test_rooms.h \
functionaltests/test_presence.c functionaltests/test_presence.h \
functionaltests/test_message.c functionaltests/test_message.h \
functionaltests/functionaltests.c
main_source = src/main.c
@ -111,8 +120,8 @@ otr3_sources = \
otr4_sources = \
src/otr/otrlib.h src/otr/otrlibv4.c src/otr/otr.h src/otr/otr.c
otr_test_sources = \
tests/otr/stub_otr.c
otr_unittest_sources = \
unittests/otr/stub_otr.c
themes_sources = themes/*
@ -122,11 +131,11 @@ man_sources = docs/profanity.1
if BUILD_PGP
core_sources += $(pgp_sources)
tests_sources += $(pgp_test_sources)
unittest_sources += $(pgp_test_sources)
endif
if BUILD_OTR
tests_sources += $(otr_test_sources)
unittest_sources += $(otr_unittest_sources)
if BUILD_OTR3
core_sources += $(otr3_sources)
endif
@ -145,10 +154,13 @@ if INCLUDE_GIT_VERSION
BUILT_SOURCES = $(git_include)
endif
TESTS = tests/testsuite
check_PROGRAMS = tests/testsuite
tests_testsuite_SOURCES = $(tests_sources)
tests_testsuite_LDADD = -lcmocka
TESTS = unittests/unittests functionaltests/functionaltests
check_PROGRAMS = unittests/unittests functionaltests/functionaltests
unittests_unittests_SOURCES = $(unittest_sources)
unittests_unittests_LDADD = -lcmocka
functionaltests_functionaltests_SOURCES = $(functionaltest_sources)
functionaltests_functionaltests_CFLAGS = -I/usr/include/tcl8.6 -I/usr/include/tcl8.5
functionaltests_functionaltests_LDADD = -lcmocka -lstabber -lexpect -ltcl
man_MANS = $(man_sources)

View File

@ -248,6 +248,9 @@ AM_CONDITIONAL([THEMES_INSTALL], "$THEMES_INSTALL")
PKG_CHECK_MODULES([cmocka], [cmocka], [],
[AC_MSG_NOTICE([cmocka is not found, will not be able to run tests])])
AC_CHECK_LIB([stabber], [stbbr_start], [],
[AC_MSG_NOTICE([stabber not found, will not be able to run functional tests])])
### Check for ncursesw/ncurses.h first, Arch linux uses ncurses.h for ncursesw
AC_CHECK_HEADERS([ncursesw/ncurses.h], [], [])
AC_CHECK_HEADERS([ncurses.h], [], [])

View File

@ -0,0 +1,102 @@
#include <stdarg.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <sys/stat.h>
#include "config.h"
#include "proftest.h"
#include "test_connect.h"
#include "test_ping.h"
#include "test_rooms.h"
#include "test_presence.h"
#include "test_message.h"
int main(int argc, char* argv[]) {
const UnitTest all_tests[] = {
unit_test_setup_teardown(connect_jid,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(connect_jid_requests_roster,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(connect_jid_sends_presence_after_receiving_roster,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(connect_jid_requests_bookmarks,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(connect_bad_password,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(connect_shows_presence_updates,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(ping_multiple,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(ping_responds,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(rooms_query,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(presence_away,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(presence_away_with_message,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(presence_online,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(presence_online_with_message,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(presence_xa,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(presence_xa_with_message,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(presence_dnd,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(presence_dnd_with_message,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(presence_chat,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(presence_chat_with_message,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(presence_set_priority,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(presence_includes_priority,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(presence_received,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(message_send,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(message_receive,
init_prof_test,
close_prof_test)
};
return run_tests(all_tests);
}

202
functionaltests/proftest.c Normal file
View File

@ -0,0 +1,202 @@
#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(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();
}
void
close_prof_test(void **state)
{
_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);
}

View File

@ -0,0 +1,17 @@
#ifndef __H_PROFTEST
#define __H_PROFTEST
#define XDG_CONFIG_HOME "./functionaltests/files/xdg_config_home"
#define XDG_DATA_HOME "./functionaltests/files/xdg_data_home"
void init_prof_test(void **state);
void close_prof_test(void **state);
void prof_start(void);
void prof_connect(char *jid, char *password);
void prof_input(char *input);
int prof_output_exact(char *text);
int prof_output_regex(char *text);
#endif

View File

@ -0,0 +1,117 @@
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>
#include <stabber.h>
#include <expect.h>
#include "proftest.h"
void
connect_jid(void **state)
{
prof_connect("stabber@localhost", "password");
assert_true(prof_output_exact("Connecting as stabber@localhost"));
assert_true(prof_output_regex("stabber@localhost logged in successfully, .+online.+ \\(priority 0\\)\\."));
}
void
connect_jid_requests_roster(void **state)
{
prof_connect("stabber@localhost", "password");
assert_true(stbbr_received(
"<iq id=\"*\" type=\"get\"><query xmlns=\"jabber:iq:roster\"/></iq>"
));
}
void
connect_jid_sends_presence_after_receiving_roster(void **state)
{
stbbr_for_query("jabber:iq:roster",
"<iq type=\"result\" to=\"stabber@localhost/profanity\">"
"<query xmlns=\"jabber:iq:roster\" ver=\"362\">"
"<item jid=\"buddy1@localhost\" subscription=\"both\" name=\"Buddy1\"/>"
"<item jid=\"buddy2@localhost\" subscription=\"both\" name=\"Buddy2\"/>"
"</query>"
"</iq>"
);
prof_connect("stabber@localhost", "password");
assert_true(stbbr_received(
"<presence id=\"*\">"
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
"</presence>"
));
}
void
connect_jid_requests_bookmarks(void **state)
{
prof_connect("stabber@localhost", "password");
assert_true(stbbr_received(
"<iq id=\"*\" type=\"get\">"
"<query xmlns=\"jabber:iq:private\">"
"<storage xmlns=\"storage:bookmarks\"/>"
"</query>"
"</iq>"
));
}
void
connect_bad_password(void **state)
{
prof_connect("stabber@localhost", "badpassword");
assert_true(prof_output_exact("Login failed."));
}
void
connect_shows_presence_updates(void **state)
{
stbbr_for_query("jabber:iq:roster",
"<iq type=\"result\" to=\"stabber@localhost/profanity\">"
"<query xmlns=\"jabber:iq:roster\" ver=\"362\">"
"<item jid=\"buddy1@localhost\" subscription=\"both\" name=\"Buddy1\"/>"
"<item jid=\"buddy2@localhost\" subscription=\"both\" name=\"Buddy2\"/>"
"</query>"
"</iq>"
);
stbbr_for_id("prof_presence_1",
"<presence to=\"stabber@localhost\" from=\"buddy1@localhost/mobile\">"
"<show>dnd</show>"
"<status>busy!</status>"
"</presence>"
"<presence to=\"stabber@localhost\" from=\"buddy1@localhost/laptop\">"
"<show>chat</show>"
"<status>Talk to me!</status>"
"</presence>"
"<presence to=\"stabber@localhost\" from=\"buddy2@localhost/work\">"
"<show>away</show>"
"<status>Out of office</status>"
"</presence>"
);
prof_connect("stabber@localhost", "password");
assert_true(prof_output_exact("Buddy1 (mobile) is dnd, \"busy!\""));
assert_true(prof_output_exact("Buddy1 (laptop) is chat, \"Talk to me!\""));
assert_true(prof_output_exact("Buddy2 (work) is away, \"Out of office\""));
stbbr_send(
"<presence to=\"stabber@localhost\" from=\"buddy1@localhost/mobile\">"
"<show>xa</show>"
"<status>Gone :(</status>"
"</presence>"
);
assert_true(prof_output_exact("Buddy1 (mobile) is xa, \"Gone :(\""));
}

View File

@ -0,0 +1,7 @@
void connect_jid(void **state);
void connect_jid_requests_roster(void **state);
void connect_jid_sends_presence_after_receiving_roster(void **state);
void connect_jid_requests_bookmarks(void **state);
void connect_bad_password(void **state);
void connect_shows_presence_updates(void **state);

View File

@ -0,0 +1,52 @@
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>
#include <stabber.h>
#include <expect.h>
#include "proftest.h"
void
message_send(void **state)
{
prof_connect("stabber@localhost", "password");
prof_input("/msg somejid@someserver.com Hi there");
assert_true(stbbr_received(
"<message id=\"*\" to=\"somejid@someserver.com\" type=\"chat\">"
"<body>Hi there</body>"
"</message>"
));
assert_true(prof_output_regex("me: .+Hi there"));
}
void
message_receive(void **state)
{
stbbr_for_id("roster",
"<iq id=\"roster\" type=\"result\" to=\"stabber@localhost/profanity\">"
"<query xmlns=\"jabber:iq:roster\" ver=\"362\">"
"<item jid=\"buddy1@localhost\" subscription=\"both\" name=\"Buddy1\"/>"
"<item jid=\"buddy2@localhost\" subscription=\"both\" name=\"Buddy2\"/>"
"</query>"
"</iq>"
);
prof_connect("stabber@localhost", "password");
stbbr_wait_for("prof_presence_1");
stbbr_send(
"<message id=\"message1\" to=\"stabber@localhost\" from=\"someuser@chatserv.org/laptop\" type=\"chat\">"
"<body>How are you?</body>"
"</message>"
);
assert_true(prof_output_exact("<< incoming from someuser@chatserv.org/laptop (2)"));
}

View File

@ -0,0 +1,2 @@
void message_send(void **state);
void message_receive(void **state);

View File

@ -0,0 +1,59 @@
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>
#include <stabber.h>
#include <expect.h>
#include "proftest.h"
void
ping_multiple(void **state)
{
stbbr_for_id("prof_ping_1",
"<iq id=\"prof_ping_1\" type=\"result\" to=\"stabber@localhost/profanity\"/>"
);
stbbr_for_id("prof_ping_2",
"<iq id=\"prof_ping_2\" type=\"result\" to=\"stabber@localhost/profanity\"/>"
);
prof_connect("stabber@localhost", "password");
prof_input("/ping");
assert_true(stbbr_received(
"<iq id=\"prof_ping_1\" type=\"get\">"
"<ping xmlns=\"urn:xmpp:ping\"/>"
"</iq>"
));
assert_true(prof_output_exact("Ping response from server"));
prof_input("/ping");
assert_true(stbbr_received(
"<iq id=\"prof_ping_2\" type=\"get\">"
"<ping xmlns=\"urn:xmpp:ping\"/>"
"</iq>"
));
assert_true(prof_output_exact("Ping response from server"));
}
void
ping_responds(void **state)
{
prof_connect("stabber@localhost", "password");
assert_true(prof_output_exact("stabber@localhost logged in successfully"));
stbbr_send(
"<iq id=\"pingtest1\" type=\"get\" to=\"stabber@localhost/profanity\" from=\"localhost\">"
"<ping xmlns=\"urn:xmpp:ping\"/>"
"</iq>"
);
assert_true(stbbr_received(
"<iq id=\"pingtest1\" type=\"result\" from=\"stabber@localhost/profanity\" to=\"localhost\"/>"
));
}

View File

@ -0,0 +1,2 @@
void ping_multiple(void **state);
void ping_responds(void **state);

View File

@ -0,0 +1,253 @@
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>
#include <stabber.h>
#include <expect.h>
#include "proftest.h"
void
presence_online(void **state)
{
prof_connect("stabber@localhost", "password");
prof_input("/online");
assert_true(stbbr_received(
"<presence id=\"*\">"
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
"</presence>"
));
assert_true(prof_output_exact("Status set to online (priority 0)"));
}
void
presence_online_with_message(void **state)
{
prof_connect("stabber@localhost", "password");
prof_input("/online \"Hi there\"");
assert_true(stbbr_received(
"<presence id=\"*\">"
"<status>Hi there</status>"
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
"</presence>"
));
assert_true(prof_output_exact("Status set to online (priority 0), \"Hi there\"."));
}
void
presence_away(void **state)
{
prof_connect("stabber@localhost", "password");
prof_input("/away");
assert_true(stbbr_received(
"<presence id=\"*\">"
"<show>away</show>"
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
"</presence>"
));
assert_true(prof_output_exact("Status set to away (priority 0)"));
}
void
presence_away_with_message(void **state)
{
prof_connect("stabber@localhost", "password");
prof_input("/away \"I'm not here for a bit\"");
assert_true(stbbr_received(
"<presence id=\"*\">"
"<show>away</show>"
"<status>I'm not here for a bit</status>"
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
"</presence>"
));
assert_true(prof_output_exact("Status set to away (priority 0), \"I'm not here for a bit\"."));
}
void
presence_xa(void **state)
{
prof_connect("stabber@localhost", "password");
prof_input("/xa");
assert_true(stbbr_received(
"<presence id=\"*\">"
"<show>xa</show>"
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
"</presence>"
));
assert_true(prof_output_exact("Status set to xa (priority 0)"));
}
void
presence_xa_with_message(void **state)
{
prof_connect("stabber@localhost", "password");
prof_input("/xa \"Gone to the shops\"");
assert_true(stbbr_received(
"<presence id=\"*\">"
"<show>xa</show>"
"<status>Gone to the shops</status>"
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
"</presence>"
));
assert_true(prof_output_exact("Status set to xa (priority 0), \"Gone to the shops\"."));
}
void
presence_dnd(void **state)
{
prof_connect("stabber@localhost", "password");
prof_input("/dnd");
assert_true(stbbr_received(
"<presence id=\"*\">"
"<show>dnd</show>"
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
"</presence>"
));
assert_true(prof_output_exact("Status set to dnd (priority 0)"));
}
void
presence_dnd_with_message(void **state)
{
prof_connect("stabber@localhost", "password");
prof_input("/dnd \"Working\"");
assert_true(stbbr_received(
"<presence id=\"*\">"
"<show>dnd</show>"
"<status>Working</status>"
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
"</presence>"
));
assert_true(prof_output_exact("Status set to dnd (priority 0), \"Working\"."));
}
void
presence_chat(void **state)
{
prof_connect("stabber@localhost", "password");
prof_input("/chat");
assert_true(stbbr_received(
"<presence id=\"*\">"
"<show>chat</show>"
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
"</presence>"
));
assert_true(prof_output_exact("Status set to chat (priority 0)"));
}
void
presence_chat_with_message(void **state)
{
prof_connect("stabber@localhost", "password");
prof_input("/chat \"Free to talk\"");
assert_true(stbbr_received(
"<presence id=\"*\">"
"<show>chat</show>"
"<status>Free to talk</status>"
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
"</presence>"
));
assert_true(prof_output_exact("Status set to chat (priority 0), \"Free to talk\"."));
}
void
presence_set_priority(void **state)
{
prof_connect("stabber@localhost", "password");
prof_input("/priority 25");
assert_true(stbbr_received(
"<presence id=\"*\">"
"<priority>25</priority>"
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
"</presence>"
));
assert_true(prof_output_exact("Priority set to 25."));
}
void
presence_includes_priority(void **state)
{
prof_connect("stabber@localhost", "password");
prof_input("/priority 25");
assert_true(stbbr_received(
"<presence id=\"*\">"
"<priority>25</priority>"
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
"</presence>"
));
assert_true(prof_output_exact("Priority set to 25."));
prof_input("/chat \"Free to talk\"");
assert_true(stbbr_received(
"<presence id=\"*\">"
"<priority>25</priority>"
"<show>chat</show>"
"<status>Free to talk</status>"
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
"</presence>"
));
assert_true(prof_output_exact("Status set to chat (priority 25), \"Free to talk\"."));
}
void
presence_received(void **state)
{
stbbr_for_id("roster",
"<iq id=\"roster\" type=\"result\" to=\"stabber@localhost/profanity\">"
"<query xmlns=\"jabber:iq:roster\" ver=\"362\">"
"<item jid=\"buddy1@localhost\" subscription=\"both\" name=\"Buddy1\"/>"
"<item jid=\"buddy2@localhost\" subscription=\"both\" name=\"Buddy2\"/>"
"</query>"
"</iq>"
);
prof_connect("stabber@localhost", "password");
stbbr_wait_for("prof_presence_1");
stbbr_send(
"<presence to=\"stabber@localhost\" from=\"buddy1@localhost/mobile\">"
"<priority>10</priority>"
"<status>I'm here</status>"
"</presence>"
);
assert_true(prof_output_exact("Buddy1 (mobile) is online, \"I'm here\""));
}

View File

@ -0,0 +1,13 @@
void presence_away(void **state);
void presence_away_with_message(void **state);
void presence_online(void **state);
void presence_online_with_message(void **state);
void presence_xa(void **state);
void presence_xa_with_message(void **state);
void presence_dnd(void **state);
void presence_dnd_with_message(void **state);
void presence_chat(void **state);
void presence_chat_with_message(void **state);
void presence_set_priority(void **state);
void presence_includes_priority(void **state);
void presence_received(void **state);

View File

@ -0,0 +1,38 @@
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>
#include <stabber.h>
#include <expect.h>
#include "proftest.h"
void
rooms_query(void **state)
{
stbbr_for_id("confreq",
"<iq id=\"confreq\" type=\"result\" to=\"stabber@localhost/profanity\" from=\"conference.localhost\">"
"<query xmlns=\"http://jabber.org/protocol/disco#items\">"
"<item jid=\"chatroom@conference.localhost\" name=\"A chat room\"/>"
"<item jid=\"hangout@conference.localhost\" name=\"Another chat room\"/>"
"</query>"
"</iq>"
);
prof_connect("stabber@localhost", "password");
prof_input("/rooms");
assert_true(stbbr_last_received(
"<iq id=\"confreq\" to=\"conference.localhost\" type=\"get\">"
"<query xmlns=\"http://jabber.org/protocol/disco#items\"/>"
"</iq>"
));
assert_true(prof_output_exact("chatroom@conference.localhost, (A chat room)"));
assert_true(prof_output_exact("hangout@conference.localhost, (Another chat room)"));
}

View File

@ -0,0 +1,2 @@
void rooms_query(void **state);

View File

@ -57,6 +57,8 @@ struct curl_data_t
size_t size;
};
static unsigned long unique_id = 0;
static size_t _data_callback(void *ptr, size_t size, size_t nmemb, void *data);
// taken from glib 2.30.3
@ -469,7 +471,6 @@ xdg_get_data_home(void)
char *
create_unique_id(char *prefix)
{
static unsigned long unique_id;
char *result = NULL;
GString *result_str = g_string_new("");
@ -485,6 +486,12 @@ create_unique_id(char *prefix)
return result;
}
void
reset_unique_id(void)
{
unique_id = 0;
}
char *
p_sha1_hash(char *str)
{

View File

@ -127,6 +127,7 @@ contact_presence_t contact_presence_from_resource_presence(resource_presence_t r
char * p_sha1_hash(char *str);
char * create_unique_id(char *prefix);
void reset_unique_id(void);
int cmp_win_num(gconstpointer a, gconstpointer b);
int get_next_available_win_num(GList *used);

View File

@ -82,7 +82,7 @@ prefs_load(void)
{
GError *err;
log_info("Loading preferences");
// log_info("Loading preferences");
prefs_loc = _get_preferences_file();
if (g_file_test(prefs_loc, G_FILE_TEST_EXISTS)) {
@ -743,4 +743,4 @@ _get_default_string(preference_t pref)
default:
return NULL;
}
}
}

View File

@ -207,12 +207,15 @@ theme_close(void)
{
if (theme) {
g_key_file_free(theme);
theme = NULL;
}
if (theme_loc) {
g_string_free(theme_loc, TRUE);
theme_loc = NULL;
}
if (bold_items) {
g_hash_table_destroy(bold_items);
bold_items = NULL;
}
}
@ -614,4 +617,4 @@ theme_attrs(theme_item_t attrs)
return result;
}
}
}

View File

@ -107,4 +107,4 @@ cl_ev_send_priv_msg(ProfPrivateWin *privwin, const char * const msg)
{
message_send_private(privwin->fulljid, msg);
ui_outgoing_private_msg(privwin, msg);
}
}

View File

@ -163,6 +163,8 @@ otr_init(void)
log_info("Initialising OTR");
OTRL_INIT;
jid = NULL;
ops.policy = cb_policy;
ops.is_logged_in = cb_is_logged_in;
ops.inject_message = cb_inject_message;
@ -181,6 +183,7 @@ otr_shutdown(void)
{
if (jid) {
free(jid);
jid = NULL;
}
}
@ -642,7 +645,8 @@ otr_get_their_fingerprint(const char * const recipient)
prof_otrpolicy_t
otr_get_policy(const char * const recipient)
{
ProfAccount *account = accounts_get_account(jabber_get_account_name());
char *account_name = jabber_get_account_name();
ProfAccount *account = accounts_get_account(account_name);
// check contact specific setting
if (g_list_find_custom(account->otr_manual, recipient, (GCompareFunc)g_strcmp0)) {
account_free(account);
@ -747,4 +751,4 @@ void
otr_free_message(char *message)
{
otrl_message_free(message);
}
}

View File

@ -103,7 +103,7 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
otr_poll();
#endif
notify_remind();
jabber_process_events();
jabber_process_events(10);
ui_update();
}
}

View File

@ -35,6 +35,8 @@
#ifndef UI_WINDOWS_H
#define UI_WINDOWS_H
#include "ui/window.h"
void wins_init(void);
ProfWin * wins_new_xmlconsole(void);

View File

@ -194,7 +194,7 @@ jabber_disconnect(void)
xmpp_disconnect(jabber_conn.conn);
while (jabber_get_connection_status() == JABBER_DISCONNECTING) {
jabber_process_events();
jabber_process_events(10);
}
_connection_free_saved_account();
_connection_free_saved_details();
@ -222,10 +222,11 @@ jabber_shutdown(void)
_connection_free_session_data();
xmpp_shutdown();
free(jabber_conn.log);
jabber_conn.log = NULL;
}
void
jabber_process_events(void)
jabber_process_events(int millis)
{
int reconnect_sec;
@ -234,7 +235,7 @@ jabber_process_events(void)
case JABBER_CONNECTED:
case JABBER_CONNECTING:
case JABBER_DISCONNECTING:
xmpp_run_once(jabber_conn.ctx, 10);
xmpp_run_once(jabber_conn.ctx, millis);
break;
case JABBER_DISCONNECTED:
reconnect_sec = prefs_get_reconnect();
@ -577,4 +578,4 @@ _xmpp_get_file_logger()
file_log->userdata = &level;
return file_log;
}
}

View File

@ -136,7 +136,7 @@ jabber_conn_status_t jabber_connect_with_details(const char * const jid,
jabber_conn_status_t jabber_connect_with_account(const ProfAccount * const account);
void jabber_disconnect(void);
void jabber_shutdown(void);
void jabber_process_events(void);
void jabber_process_events(int millis);
const char * jabber_get_fulljid(void);
const char * jabber_get_domain(void);
jabber_conn_status_t jabber_get_connection_status(void);

View File

@ -7,7 +7,7 @@
#include "ui/window.h"
#include "ui/ui.h"
#include "tests/ui/stub_ui.h"
#include "unittests/ui/stub_ui.h"
// mock state

View File

@ -26,7 +26,7 @@ jabber_conn_status_t jabber_connect_with_account(const ProfAccount * const accou
void jabber_disconnect(void) {}
void jabber_shutdown(void) {}
void jabber_process_events(void) {}
void jabber_process_events(int millis) {}
const char * jabber_get_fulljid(void)
{
return (char *)mock();