about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--.gitignore5
-rw-r--r--.travis.yml13
-rw-r--r--Makefile.am86
-rw-r--r--configure.ac3
-rw-r--r--functionaltests/functionaltests.c102
-rw-r--r--functionaltests/proftest.c202
-rw-r--r--functionaltests/proftest.h17
-rw-r--r--functionaltests/test_connect.c117
-rw-r--r--functionaltests/test_connect.h7
-rw-r--r--functionaltests/test_message.c52
-rw-r--r--functionaltests/test_message.h2
-rw-r--r--functionaltests/test_ping.c59
-rw-r--r--functionaltests/test_ping.h2
-rw-r--r--functionaltests/test_presence.c253
-rw-r--r--functionaltests/test_presence.h13
-rw-r--r--functionaltests/test_rooms.c38
-rw-r--r--functionaltests/test_rooms.h2
-rw-r--r--src/common.c9
-rw-r--r--src/common.h1
-rw-r--r--src/config/preferences.c4
-rw-r--r--src/config/theme.c5
-rw-r--r--src/event/client_events.c2
-rw-r--r--src/otr/otr.c8
-rw-r--r--src/profanity.c2
-rw-r--r--src/ui/windows.h2
-rw-r--r--src/xmpp/connection.c9
-rw-r--r--src/xmpp/xmpp.h2
-rw-r--r--unittests/config/stub_accounts.c (renamed from tests/config/stub_accounts.c)0
-rw-r--r--unittests/helpers.c (renamed from tests/helpers.c)0
-rw-r--r--unittests/helpers.h (renamed from tests/helpers.h)0
-rw-r--r--unittests/log/stub_log.c (renamed from tests/log/stub_log.c)0
-rw-r--r--unittests/otr/stub_otr.c (renamed from tests/otr/stub_otr.c)0
-rw-r--r--unittests/test_autocomplete.c (renamed from tests/test_autocomplete.c)0
-rw-r--r--unittests/test_autocomplete.h (renamed from tests/test_autocomplete.h)0
-rw-r--r--unittests/test_chat_session.c (renamed from tests/test_chat_session.c)0
-rw-r--r--unittests/test_chat_session.h (renamed from tests/test_chat_session.h)0
-rw-r--r--unittests/test_cmd_account.c (renamed from tests/test_cmd_account.c)0
-rw-r--r--unittests/test_cmd_account.h (renamed from tests/test_cmd_account.h)0
-rw-r--r--unittests/test_cmd_alias.c (renamed from tests/test_cmd_alias.c)0
-rw-r--r--unittests/test_cmd_alias.h (renamed from tests/test_cmd_alias.h)0
-rw-r--r--unittests/test_cmd_bookmark.c (renamed from tests/test_cmd_bookmark.c)0
-rw-r--r--unittests/test_cmd_bookmark.h (renamed from tests/test_cmd_bookmark.h)0
-rw-r--r--unittests/test_cmd_connect.c (renamed from tests/test_cmd_connect.c)0
-rw-r--r--unittests/test_cmd_connect.h (renamed from tests/test_cmd_connect.h)0
-rw-r--r--unittests/test_cmd_disconnect.c (renamed from tests/test_cmd_disconnect.c)0
-rw-r--r--unittests/test_cmd_disconnect.h (renamed from tests/test_cmd_disconnect.h)0
-rw-r--r--unittests/test_cmd_join.c (renamed from tests/test_cmd_join.c)0
-rw-r--r--unittests/test_cmd_join.h (renamed from tests/test_cmd_join.h)0
-rw-r--r--unittests/test_cmd_otr.c (renamed from tests/test_cmd_otr.c)0
-rw-r--r--unittests/test_cmd_otr.h (renamed from tests/test_cmd_otr.h)0
-rw-r--r--unittests/test_cmd_rooms.c (renamed from tests/test_cmd_rooms.c)0
-rw-r--r--unittests/test_cmd_rooms.h (renamed from tests/test_cmd_rooms.h)0
-rw-r--r--unittests/test_cmd_roster.c (renamed from tests/test_cmd_roster.c)0
-rw-r--r--unittests/test_cmd_roster.h (renamed from tests/test_cmd_roster.h)0
-rw-r--r--unittests/test_cmd_statuses.c (renamed from tests/test_cmd_statuses.c)0
-rw-r--r--unittests/test_cmd_statuses.h (renamed from tests/test_cmd_statuses.h)0
-rw-r--r--unittests/test_cmd_sub.c (renamed from tests/test_cmd_sub.c)0
-rw-r--r--unittests/test_cmd_sub.h (renamed from tests/test_cmd_sub.h)0
-rw-r--r--unittests/test_common.c (renamed from tests/test_common.c)0
-rw-r--r--unittests/test_common.h (renamed from tests/test_common.h)0
-rw-r--r--unittests/test_contact.c (renamed from tests/test_contact.c)0
-rw-r--r--unittests/test_contact.h (renamed from tests/test_contact.h)0
-rw-r--r--unittests/test_form.c (renamed from tests/test_form.c)0
-rw-r--r--unittests/test_form.h (renamed from tests/test_form.h)0
-rw-r--r--unittests/test_jid.c (renamed from tests/test_jid.c)0
-rw-r--r--unittests/test_jid.h (renamed from tests/test_jid.h)0
-rw-r--r--unittests/test_keyhandlers.c (renamed from tests/test_keyhandlers.c)0
-rw-r--r--unittests/test_keyhandlers.h (renamed from tests/test_keyhandlers.h)0
-rw-r--r--unittests/test_muc.c (renamed from tests/test_muc.c)0
-rw-r--r--unittests/test_muc.h (renamed from tests/test_muc.h)0
-rw-r--r--unittests/test_parser.c (renamed from tests/test_parser.c)0
-rw-r--r--unittests/test_parser.h (renamed from tests/test_parser.h)0
-rw-r--r--unittests/test_preferences.c (renamed from tests/test_preferences.c)0
-rw-r--r--unittests/test_preferences.h (renamed from tests/test_preferences.h)0
-rw-r--r--unittests/test_roster_list.c (renamed from tests/test_roster_list.c)0
-rw-r--r--unittests/test_roster_list.h (renamed from tests/test_roster_list.h)0
-rw-r--r--unittests/test_server_events.c (renamed from tests/test_server_events.c)0
-rw-r--r--unittests/test_server_events.h (renamed from tests/test_server_events.h)0
-rw-r--r--unittests/ui/stub_ui.c (renamed from tests/ui/stub_ui.c)2
-rw-r--r--unittests/ui/stub_ui.h (renamed from tests/ui/stub_ui.h)0
-rw-r--r--unittests/unittests.c (renamed from tests/testsuite.c)0
-rw-r--r--unittests/xmpp/stub_xmpp.c (renamed from tests/xmpp/stub_xmpp.c)2
82 files changed, 968 insertions, 53 deletions
diff --git a/.gitignore b/.gitignore
index ba909849..03e0adef 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
+
diff --git a/.travis.yml b/.travis.yml
index a71e321e..ccc67e6b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -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
diff --git a/Makefile.am b/Makefile.am
index 0da3aacd..dbf10ea3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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)
 
diff --git a/configure.ac b/configure.ac
index 97d99d3a..40a810d2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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], [], [])
diff --git a/functionaltests/functionaltests.c b/functionaltests/functionaltests.c
new file mode 100644
index 00000000..cb110469
--- /dev/null
+++ b/functionaltests/functionaltests.c
@@ -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);
+}
diff --git a/functionaltests/proftest.c b/functionaltests/proftest.c
new file mode 100644
index 00000000..dda1cd90
--- /dev/null
+++ b/functionaltests/proftest.c
@@ -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);
+}
diff --git a/functionaltests/proftest.h b/functionaltests/proftest.h
new file mode 100644
index 00000000..f57f6c35
--- /dev/null
+++ b/functionaltests/proftest.h
@@ -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
diff --git a/functionaltests/test_connect.c b/functionaltests/test_connect.c
new file mode 100644
index 00000000..7a42397f
--- /dev/null
+++ b/functionaltests/test_connect.c
@@ -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 :(\""));
+}
diff --git a/functionaltests/test_connect.h b/functionaltests/test_connect.h
new file mode 100644
index 00000000..c6ceb404
--- /dev/null
+++ b/functionaltests/test_connect.h
@@ -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);
+
diff --git a/functionaltests/test_message.c b/functionaltests/test_message.c
new file mode 100644
index 00000000..5cdad520
--- /dev/null
+++ b/functionaltests/test_message.c
@@ -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)"));
+}
diff --git a/functionaltests/test_message.h b/functionaltests/test_message.h
new file mode 100644
index 00000000..b8f03a7e
--- /dev/null
+++ b/functionaltests/test_message.h
@@ -0,0 +1,2 @@
+void message_send(void **state);
+void message_receive(void **state);
diff --git a/functionaltests/test_ping.c b/functionaltests/test_ping.c
new file mode 100644
index 00000000..e2ca79ca
--- /dev/null
+++ b/functionaltests/test_ping.c
@@ -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\"/>"
+    ));
+}
diff --git a/functionaltests/test_ping.h b/functionaltests/test_ping.h
new file mode 100644
index 00000000..a222a486
--- /dev/null
+++ b/functionaltests/test_ping.h
@@ -0,0 +1,2 @@
+void ping_multiple(void **state);
+void ping_responds(void **state);
diff --git a/functionaltests/test_presence.c b/functionaltests/test_presence.c
new file mode 100644
index 00000000..b26bdccb
--- /dev/null
+++ b/functionaltests/test_presence.c
@@ -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\""));
+}
diff --git a/functionaltests/test_presence.h b/functionaltests/test_presence.h
new file mode 100644
index 00000000..0603732a
--- /dev/null
+++ b/functionaltests/test_presence.h
@@ -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);
diff --git a/functionaltests/test_rooms.c b/functionaltests/test_rooms.c
new file mode 100644
index 00000000..20ed7342
--- /dev/null
+++ b/functionaltests/test_rooms.c
@@ -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)"));
+}
diff --git a/functionaltests/test_rooms.h b/functionaltests/test_rooms.h
new file mode 100644
index 00000000..a0cf5db8
--- /dev/null
+++ b/functionaltests/test_rooms.h
@@ -0,0 +1,2 @@
+void rooms_query(void **state);
+
diff --git a/src/common.c b/src/common.c
index 772e24d3..4fa45608 100644
--- a/src/common.c
+++ b/src/common.c
@@ -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)
 {
diff --git a/src/common.h b/src/common.h
index 9521a701..c1aa532d 100644
--- a/src/common.h
+++ b/src/common.h
@@ -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);
diff --git a/src/config/preferences.c b/src/config/preferences.c
index b7ca113e..e892d796 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -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;
     }
-}
\ No newline at end of file
+}
diff --git a/src/config/theme.c b/src/config/theme.c
index 537771b1..640b7298 100644
--- a/src/config/theme.c
+++ b/src/config/theme.c
@@ -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;
 
     }
-}
\ No newline at end of file
+}
diff --git a/src/event/client_events.c b/src/event/client_events.c
index 3465d5ee..3feeeca1 100644
--- a/src/event/client_events.c
+++ b/src/event/client_events.c
@@ -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);
-}
\ No newline at end of file
+}
diff --git a/src/otr/otr.c b/src/otr/otr.c
index e568af56..1f63c8f9 100644
--- a/src/otr/otr.c
+++ b/src/otr/otr.c
@@ -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);
-}
\ No newline at end of file
+}
diff --git a/src/profanity.c b/src/profanity.c
index 277fe4ad..7aee7a67 100644
--- a/src/profanity.c
+++ b/src/profanity.c
@@ -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();
     }
 }
diff --git a/src/ui/windows.h b/src/ui/windows.h
index 97183d51..4cc527ca 100644
--- a/src/ui/windows.h
+++ b/src/ui/windows.h
@@ -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);
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index 70d49b7c..8fa83144 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -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;
-}
\ No newline at end of file
+}
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 80b680b0..26122d51 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -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);
diff --git a/tests/config/stub_accounts.c b/unittests/config/stub_accounts.c
index c046be86..c046be86 100644
--- a/tests/config/stub_accounts.c
+++ b/unittests/config/stub_accounts.c
diff --git a/tests/helpers.c b/unittests/helpers.c
index 564b2716..564b2716 100644
--- a/tests/helpers.c
+++ b/unittests/helpers.c
diff --git a/tests/helpers.h b/unittests/helpers.h
index 75d446d0..75d446d0 100644
--- a/tests/helpers.h
+++ b/unittests/helpers.h
diff --git a/tests/log/stub_log.c b/unittests/log/stub_log.c
index f88871a7..f88871a7 100644
--- a/tests/log/stub_log.c
+++ b/unittests/log/stub_log.c
diff --git a/tests/otr/stub_otr.c b/unittests/otr/stub_otr.c
index 482f0a7f..482f0a7f 100644
--- a/tests/otr/stub_otr.c
+++ b/unittests/otr/stub_otr.c
diff --git a/tests/test_autocomplete.c b/unittests/test_autocomplete.c
index f6ef8653..f6ef8653 100644
--- a/tests/test_autocomplete.c
+++ b/unittests/test_autocomplete.c
diff --git a/tests/test_autocomplete.h b/unittests/test_autocomplete.h
index 4ad327c0..4ad327c0 100644
--- a/tests/test_autocomplete.h
+++ b/unittests/test_autocomplete.h
diff --git a/tests/test_chat_session.c b/unittests/test_chat_session.c
index b5e1f7b6..b5e1f7b6 100644
--- a/tests/test_chat_session.c
+++ b/unittests/test_chat_session.c
diff --git a/tests/test_chat_session.h b/unittests/test_chat_session.h
index 4ce03fd5..4ce03fd5 100644
--- a/tests/test_chat_session.h
+++ b/unittests/test_chat_session.h
diff --git a/tests/test_cmd_account.c b/unittests/test_cmd_account.c
index 887f635e..887f635e 100644
--- a/tests/test_cmd_account.c
+++ b/unittests/test_cmd_account.c
diff --git a/tests/test_cmd_account.h b/unittests/test_cmd_account.h
index 91bd1e70..91bd1e70 100644
--- a/tests/test_cmd_account.h
+++ b/unittests/test_cmd_account.h
diff --git a/tests/test_cmd_alias.c b/unittests/test_cmd_alias.c
index 10ab7f53..10ab7f53 100644
--- a/tests/test_cmd_alias.c
+++ b/unittests/test_cmd_alias.c
diff --git a/tests/test_cmd_alias.h b/unittests/test_cmd_alias.h
index bd93ef1a..bd93ef1a 100644
--- a/tests/test_cmd_alias.h
+++ b/unittests/test_cmd_alias.h
diff --git a/tests/test_cmd_bookmark.c b/unittests/test_cmd_bookmark.c
index 695e7362..695e7362 100644
--- a/tests/test_cmd_bookmark.c
+++ b/unittests/test_cmd_bookmark.c
diff --git a/tests/test_cmd_bookmark.h b/unittests/test_cmd_bookmark.h
index 9505e105..9505e105 100644
--- a/tests/test_cmd_bookmark.h
+++ b/unittests/test_cmd_bookmark.h
diff --git a/tests/test_cmd_connect.c b/unittests/test_cmd_connect.c
index 90b154d5..90b154d5 100644
--- a/tests/test_cmd_connect.c
+++ b/unittests/test_cmd_connect.c
diff --git a/tests/test_cmd_connect.h b/unittests/test_cmd_connect.h
index ad27a0a5..ad27a0a5 100644
--- a/tests/test_cmd_connect.h
+++ b/unittests/test_cmd_connect.h
diff --git a/tests/test_cmd_disconnect.c b/unittests/test_cmd_disconnect.c
index 68253820..68253820 100644
--- a/tests/test_cmd_disconnect.c
+++ b/unittests/test_cmd_disconnect.c
diff --git a/tests/test_cmd_disconnect.h b/unittests/test_cmd_disconnect.h
index 856b501e..856b501e 100644
--- a/tests/test_cmd_disconnect.h
+++ b/unittests/test_cmd_disconnect.h
diff --git a/tests/test_cmd_join.c b/unittests/test_cmd_join.c
index 8dc6cf02..8dc6cf02 100644
--- a/tests/test_cmd_join.c
+++ b/unittests/test_cmd_join.c
diff --git a/tests/test_cmd_join.h b/unittests/test_cmd_join.h
index a96fa435..a96fa435 100644
--- a/tests/test_cmd_join.h
+++ b/unittests/test_cmd_join.h
diff --git a/tests/test_cmd_otr.c b/unittests/test_cmd_otr.c
index 8841be86..8841be86 100644
--- a/tests/test_cmd_otr.c
+++ b/unittests/test_cmd_otr.c
diff --git a/tests/test_cmd_otr.h b/unittests/test_cmd_otr.h
index 8ef182e9..8ef182e9 100644
--- a/tests/test_cmd_otr.h
+++ b/unittests/test_cmd_otr.h
diff --git a/tests/test_cmd_rooms.c b/unittests/test_cmd_rooms.c
index 5114bfbf..5114bfbf 100644
--- a/tests/test_cmd_rooms.c
+++ b/unittests/test_cmd_rooms.c
diff --git a/tests/test_cmd_rooms.h b/unittests/test_cmd_rooms.h
index a9a7af83..a9a7af83 100644
--- a/tests/test_cmd_rooms.h
+++ b/unittests/test_cmd_rooms.h
diff --git a/tests/test_cmd_roster.c b/unittests/test_cmd_roster.c
index a7160cf5..a7160cf5 100644
--- a/tests/test_cmd_roster.c
+++ b/unittests/test_cmd_roster.c
diff --git a/tests/test_cmd_roster.h b/unittests/test_cmd_roster.h
index 79f69ec8..79f69ec8 100644
--- a/tests/test_cmd_roster.h
+++ b/unittests/test_cmd_roster.h
diff --git a/tests/test_cmd_statuses.c b/unittests/test_cmd_statuses.c
index ed37021a..ed37021a 100644
--- a/tests/test_cmd_statuses.c
+++ b/unittests/test_cmd_statuses.c
diff --git a/tests/test_cmd_statuses.h b/unittests/test_cmd_statuses.h
index 306a6fc7..306a6fc7 100644
--- a/tests/test_cmd_statuses.h
+++ b/unittests/test_cmd_statuses.h
diff --git a/tests/test_cmd_sub.c b/unittests/test_cmd_sub.c
index 80b85f15..80b85f15 100644
--- a/tests/test_cmd_sub.c
+++ b/unittests/test_cmd_sub.c
diff --git a/tests/test_cmd_sub.h b/unittests/test_cmd_sub.h
index 6e8addd3..6e8addd3 100644
--- a/tests/test_cmd_sub.h
+++ b/unittests/test_cmd_sub.h
diff --git a/tests/test_common.c b/unittests/test_common.c
index 980f2198..980f2198 100644
--- a/tests/test_common.c
+++ b/unittests/test_common.c
diff --git a/tests/test_common.h b/unittests/test_common.h
index b4b98e5a..b4b98e5a 100644
--- a/tests/test_common.h
+++ b/unittests/test_common.h
diff --git a/tests/test_contact.c b/unittests/test_contact.c
index cad88907..cad88907 100644
--- a/tests/test_contact.c
+++ b/unittests/test_contact.c
diff --git a/tests/test_contact.h b/unittests/test_contact.h
index c9d8c1fd..c9d8c1fd 100644
--- a/tests/test_contact.h
+++ b/unittests/test_contact.h
diff --git a/tests/test_form.c b/unittests/test_form.c
index b3158a83..b3158a83 100644
--- a/tests/test_form.c
+++ b/unittests/test_form.c
diff --git a/tests/test_form.h b/unittests/test_form.h
index 65911d0a..65911d0a 100644
--- a/tests/test_form.h
+++ b/unittests/test_form.h
diff --git a/tests/test_jid.c b/unittests/test_jid.c
index ff5f4c9a..ff5f4c9a 100644
--- a/tests/test_jid.c
+++ b/unittests/test_jid.c
diff --git a/tests/test_jid.h b/unittests/test_jid.h
index 9b96d0b8..9b96d0b8 100644
--- a/tests/test_jid.h
+++ b/unittests/test_jid.h
diff --git a/tests/test_keyhandlers.c b/unittests/test_keyhandlers.c
index a6d39143..a6d39143 100644
--- a/tests/test_keyhandlers.c
+++ b/unittests/test_keyhandlers.c
diff --git a/tests/test_keyhandlers.h b/unittests/test_keyhandlers.h
index 4be429a9..4be429a9 100644
--- a/tests/test_keyhandlers.h
+++ b/unittests/test_keyhandlers.h
diff --git a/tests/test_muc.c b/unittests/test_muc.c
index e3b7f9b0..e3b7f9b0 100644
--- a/tests/test_muc.c
+++ b/unittests/test_muc.c
diff --git a/tests/test_muc.h b/unittests/test_muc.h
index 8df54a5d..8df54a5d 100644
--- a/tests/test_muc.h
+++ b/unittests/test_muc.h
diff --git a/tests/test_parser.c b/unittests/test_parser.c
index faefc9c7..faefc9c7 100644
--- a/tests/test_parser.c
+++ b/unittests/test_parser.c
diff --git a/tests/test_parser.h b/unittests/test_parser.h
index 51d768fe..51d768fe 100644
--- a/tests/test_parser.h
+++ b/unittests/test_parser.h
diff --git a/tests/test_preferences.c b/unittests/test_preferences.c
index c4bcbf77..c4bcbf77 100644
--- a/tests/test_preferences.c
+++ b/unittests/test_preferences.c
diff --git a/tests/test_preferences.h b/unittests/test_preferences.h
index 5bf79a6a..5bf79a6a 100644
--- a/tests/test_preferences.h
+++ b/unittests/test_preferences.h
diff --git a/tests/test_roster_list.c b/unittests/test_roster_list.c
index 41ccb8cf..41ccb8cf 100644
--- a/tests/test_roster_list.c
+++ b/unittests/test_roster_list.c
diff --git a/tests/test_roster_list.h b/unittests/test_roster_list.h
index 080bca9f..080bca9f 100644
--- a/tests/test_roster_list.h
+++ b/unittests/test_roster_list.h
diff --git a/tests/test_server_events.c b/unittests/test_server_events.c
index fac1ac38..fac1ac38 100644
--- a/tests/test_server_events.c
+++ b/unittests/test_server_events.c
diff --git a/tests/test_server_events.h b/unittests/test_server_events.h
index 81a436f4..81a436f4 100644
--- a/tests/test_server_events.h
+++ b/unittests/test_server_events.h
diff --git a/tests/ui/stub_ui.c b/unittests/ui/stub_ui.c
index 13820645..0052bfc8 100644
--- a/tests/ui/stub_ui.c
+++ b/unittests/ui/stub_ui.c
@@ -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
 
diff --git a/tests/ui/stub_ui.h b/unittests/ui/stub_ui.h
index 81357a86..81357a86 100644
--- a/tests/ui/stub_ui.h
+++ b/unittests/ui/stub_ui.h
diff --git a/tests/testsuite.c b/unittests/unittests.c
index 3f860178..3f860178 100644
--- a/tests/testsuite.c
+++ b/unittests/unittests.c
diff --git a/tests/xmpp/stub_xmpp.c b/unittests/xmpp/stub_xmpp.c
index d134b901..7fd9cf98 100644
--- a/tests/xmpp/stub_xmpp.c
+++ b/unittests/xmpp/stub_xmpp.c
@@ -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();