diff options
author | James Booth <boothj5@gmail.com> | 2015-06-12 23:53:30 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-06-12 23:53:30 +0100 |
commit | 68ed20f10d2fae67b052674a42ed98c2059aa16f (patch) | |
tree | df8d1e7989282cc2e15dda3cd378b3b2895e9892 /tests/functionaltests | |
parent | c182f3ecd6be5df9b9bc7757930e47b555ddd251 (diff) | |
download | profani-tty-68ed20f10d2fae67b052674a42ed98c2059aa16f.tar.gz |
Moved all tests to tests folder
Diffstat (limited to 'tests/functionaltests')
-rw-r--r-- | tests/functionaltests/functionaltests.c | 122 | ||||
-rw-r--r-- | tests/functionaltests/proftest.c | 213 | ||||
-rw-r--r-- | tests/functionaltests/proftest.h | 17 | ||||
-rw-r--r-- | tests/functionaltests/test_chat_session.c | 264 | ||||
-rw-r--r-- | tests/functionaltests/test_chat_session.h | 7 | ||||
-rw-r--r-- | tests/functionaltests/test_connect.c | 117 | ||||
-rw-r--r-- | tests/functionaltests/test_connect.h | 7 | ||||
-rw-r--r-- | tests/functionaltests/test_message.c | 52 | ||||
-rw-r--r-- | tests/functionaltests/test_message.h | 2 | ||||
-rw-r--r-- | tests/functionaltests/test_ping.c | 59 | ||||
-rw-r--r-- | tests/functionaltests/test_ping.h | 2 | ||||
-rw-r--r-- | tests/functionaltests/test_presence.c | 253 | ||||
-rw-r--r-- | tests/functionaltests/test_presence.h | 13 | ||||
-rw-r--r-- | tests/functionaltests/test_rooms.c | 38 | ||||
-rw-r--r-- | tests/functionaltests/test_rooms.h | 2 |
15 files changed, 1168 insertions, 0 deletions
diff --git a/tests/functionaltests/functionaltests.c b/tests/functionaltests/functionaltests.c new file mode 100644 index 00000000..a1550842 --- /dev/null +++ b/tests/functionaltests/functionaltests.c @@ -0,0 +1,122 @@ +#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" +#include "test_chat_session.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), + + unit_test_setup_teardown(sends_message_to_barejid_when_contact_offline, + init_prof_test, + close_prof_test), + unit_test_setup_teardown(sends_message_to_barejid_when_contact_online, + init_prof_test, + close_prof_test), + unit_test_setup_teardown(sends_message_to_fulljid_when_received_from_fulljid, + init_prof_test, + close_prof_test), + unit_test_setup_teardown(sends_subsequent_messages_to_fulljid, + init_prof_test, + close_prof_test), + unit_test_setup_teardown(resets_to_barejid_after_presence_received, + init_prof_test, + close_prof_test), + unit_test_setup_teardown(new_session_when_message_received_from_different_fulljid, + init_prof_test, + close_prof_test), + }; + + return run_tests(all_tests); +} diff --git a/tests/functionaltests/proftest.c b/tests/functionaltests/proftest.c new file mode 100644 index 00000000..5d7b6585 --- /dev/null +++ b/tests/functionaltests/proftest.c @@ -0,0 +1,213 @@ +#include <sys/stat.h> +#include <glib.h> + +#include <setjmp.h> +#include <stdarg.h> +#include <stddef.h> +#include <stdlib.h> +#include <cmocka.h> +#include <stdio.h> +#include <unistd.h> +#include <errno.h> +#include <string.h> + +#include <stabber.h> +#include <expect.h> + +#include "proftest.h" + +char *config_orig; +char *data_orig; + +int fd = 0; + +gboolean +_create_dir(char *name) +{ + struct stat sb; + + if (stat(name, &sb) != 0) { + if (errno != ENOENT || mkdir(name, S_IRWXU) != 0) { + return FALSE; + } + } else { + if ((sb.st_mode & S_IFDIR) != S_IFDIR) { + return FALSE; + } + } + + return TRUE; +} + +gboolean +_mkdir_recursive(const char *dir) +{ + int i; + gboolean result = TRUE; + + for (i = 1; i <= strlen(dir); i++) { + if (dir[i] == '/' || dir[i] == '\0') { + gchar *next_dir = g_strndup(dir, i); + result = _create_dir(next_dir); + g_free(next_dir); + if (!result) { + break; + } + } + } + + return result; +} + +void +_create_config_dir(void) +{ + GString *profanity_dir = g_string_new(XDG_CONFIG_HOME); + g_string_append(profanity_dir, "/profanity"); + + if (!_mkdir_recursive(profanity_dir->str)) { + assert_true(FALSE); + } + + g_string_free(profanity_dir, TRUE); +} + +void +_create_data_dir(void) +{ + GString *profanity_dir = g_string_new(XDG_DATA_HOME); + g_string_append(profanity_dir, "/profanity"); + + if (!_mkdir_recursive(profanity_dir->str)) { + assert_true(FALSE); + } + + g_string_free(profanity_dir, TRUE); +} + +void +_create_chatlogs_dir(void) +{ + GString *chatlogs_dir = g_string_new(XDG_DATA_HOME); + g_string_append(chatlogs_dir, "/profanity/chatlogs"); + + if (!_mkdir_recursive(chatlogs_dir->str)) { + assert_true(FALSE); + } + + g_string_free(chatlogs_dir, TRUE); +} + +void +_create_logs_dir(void) +{ + GString *logs_dir = g_string_new(XDG_DATA_HOME); + g_string_append(logs_dir, "/profanity/logs"); + + if (!_mkdir_recursive(logs_dir->str)) { + assert_true(FALSE); + } + + g_string_free(logs_dir, TRUE); +} + +void +_cleanup_dirs(void) +{ + int res = system("rm -rf ./functionaltests/files"); + if (res == -1) { + assert_true(FALSE); + } +} + +void +prof_start(void) +{ + fd = exp_spawnl("./profanity", NULL); + FILE *fp = fdopen(fd, "r+"); + + if (fp == NULL) { + assert_true(FALSE); + } + + setbuf(fp, (char *)0); +} + +void +init_prof_test(void **state) +{ + if (stbbr_start(STBBR_LOGDEBUG ,5230, 0) != 0) { + assert_true(FALSE); + return; + } + + config_orig = getenv("XDG_CONFIG_HOME"); + data_orig = getenv("XDG_DATA_HOME"); + + setenv("XDG_CONFIG_HOME", XDG_CONFIG_HOME, 1); + setenv("XDG_DATA_HOME", XDG_DATA_HOME, 1); + + _cleanup_dirs(); + + _create_config_dir(); + _create_data_dir(); + _create_chatlogs_dir(); + _create_logs_dir(); + + prof_start(); + prof_output_exact("Profanity"); + + prof_input("/inpblock timeout 5"); + prof_output_exact("Input blocking set to 5 milliseconds"); + prof_input("/inpblock dynamic off"); + prof_output_exact("Dynamic input blocking disabled"); + + prof_input("/notify message off"); + prof_output_exact("Message notifications disabled"); +} + +void +close_prof_test(void **state) +{ + prof_input("/quit"); + waitpid(exp_pid, NULL, 0); + _cleanup_dirs(); + + setenv("XDG_CONFIG_HOME", config_orig, 1); + setenv("XDG_DATA_HOME", data_orig, 1); + + stbbr_stop(); +} + +void +prof_input(char *input) +{ + GString *inp_str = g_string_new(input); + g_string_append(inp_str, "\r"); + write(fd, inp_str->str, inp_str->len); + g_string_free(inp_str, TRUE); +} + +int +prof_output_exact(char *text) +{ + return (1 == exp_expectl(fd, exp_exact, text, 1, exp_end)); +} + +int +prof_output_regex(char *text) +{ + return (1 == exp_expectl(fd, exp_regexp, text, 1, exp_end)); +} + +void +prof_connect(char *jid, char *password) +{ + GString *connect_cmd = g_string_new("/connect "); + g_string_append(connect_cmd, jid); + g_string_append(connect_cmd, " port 5230"); + prof_input(connect_cmd->str); + g_string_free(connect_cmd, TRUE); + + prof_input(password); +} diff --git a/tests/functionaltests/proftest.h b/tests/functionaltests/proftest.h new file mode 100644 index 00000000..f57f6c35 --- /dev/null +++ b/tests/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/tests/functionaltests/test_chat_session.c b/tests/functionaltests/test_chat_session.c new file mode 100644 index 00000000..11df4e76 --- /dev/null +++ b/tests/functionaltests/test_chat_session.c @@ -0,0 +1,264 @@ +#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 +sends_message_to_barejid_when_contact_offline(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\"/>" + "</query>" + "</iq>" + ); + + prof_connect("stabber@localhost", "password"); + stbbr_wait_for("prof_presence_1"); + + prof_input("/msg buddy1@localhost Hi there"); + + assert_true(stbbr_received( + "<message id=\"*\" to=\"buddy1@localhost\" type=\"chat\">" + "<body>Hi there</body>" + "</message>" + )); +} + +void +sends_message_to_barejid_when_contact_online(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\"/>" + "</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>" + "</presence>" + ); + prof_output_exact("buddy1@localhost (mobile) is online"); + + prof_input("/msg buddy1@localhost Hi there"); + + assert_true(stbbr_received( + "<message id=\"*\" to=\"buddy1@localhost\" type=\"chat\">" + "<body>Hi there</body>" + "</message>" + )); +} + +void +sends_message_to_fulljid_when_received_from_fulljid(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\"/>" + "</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>" + "</presence>" + ); + prof_output_exact("buddy1@localhost (mobile) is online"); + + stbbr_send( + "<message id=\"message1\" to=\"stabber@localhost\" from=\"buddy1@localhost/mobile\" type=\"chat\">" + "<body>First message</body>" + "</message>" + ); + prof_output_exact("<< incoming from buddy1@localhost/mobile (2)"); + + prof_input("/msg buddy1@localhost Hi there"); + + assert_true(stbbr_received( + "<message id=\"*\" to=\"buddy1@localhost/mobile\" type=\"chat\">" + "<body>Hi there</body>" + "</message>" + )); +} + +void +sends_subsequent_messages_to_fulljid(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\"/>" + "</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>" + "</presence>" + ); + prof_output_exact("buddy1@localhost (mobile) is online"); + + stbbr_send( + "<message id=\"message1\" to=\"stabber@localhost\" from=\"buddy1@localhost/mobile\" type=\"chat\">" + "<body>First message</body>" + "</message>" + ); + prof_output_exact("<< incoming from buddy1@localhost/mobile (2)"); + + prof_input("/msg buddy1@localhost Outgoing 1"); + prof_input("/msg buddy1@localhost Outgoing 2"); + prof_input("/msg buddy1@localhost Outgoing 3"); + + assert_true(stbbr_received( + "<message id=\"*\" to=\"buddy1@localhost/mobile\" type=\"chat\">" + "<body>Outgoing 1</body>" + "</message>" + )); + assert_true(stbbr_received( + "<message id=\"*\" to=\"buddy1@localhost/mobile\" type=\"chat\">" + "<body>Outgoing 2</body>" + "</message>" + )); + assert_true(stbbr_received( + "<message id=\"*\" to=\"buddy1@localhost/mobile\" type=\"chat\">" + "<body>Outgoing 3</body>" + "</message>" + )); +} + +void +resets_to_barejid_after_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\"/>" + "</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>" + "</presence>" + ); + prof_output_exact("buddy1@localhost (mobile) is online"); + + stbbr_send( + "<message id=\"message1\" to=\"stabber@localhost\" from=\"buddy1@localhost/mobile\" type=\"chat\">" + "<body>First message</body>" + "</message>" + ); + prof_output_exact("<< incoming from buddy1@localhost/mobile (2)"); + + prof_input("/msg buddy1@localhost Outgoing 1"); + + assert_true(stbbr_received( + "<message id=\"*\" to=\"buddy1@localhost/mobile\" type=\"chat\">" + "<body>Outgoing 1</body>" + "</message>" + )); + + stbbr_send( + "<presence to=\"stabber@localhost\" from=\"buddy1@localhost/laptop\">" + "<priority>5</priority>" + "<show>dnd</show>" + "</presence>" + ); + prof_output_exact("buddy1@localhost (laptop) is dnd"); + + prof_input("/msg buddy1@localhost Outgoing 2"); + + assert_true(stbbr_received( + "<message id=\"*\" to=\"buddy1@localhost\" type=\"chat\">" + "<body>Outgoing 2</body>" + "</message>" + )); +} + +void +new_session_when_message_received_from_different_fulljid(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\"/>" + "</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>" + "</presence>" + ); + prof_output_exact("buddy1@localhost (mobile) is online"); + + stbbr_send( + "<presence to=\"stabber@localhost\" from=\"buddy1@localhost/laptop\">" + "<priority>8</priority>" + "<show>away</show>" + "</presence>" + ); + prof_output_exact("buddy1@localhost (laptop) is away"); + + stbbr_send( + "<message id=\"message1\" to=\"stabber@localhost\" from=\"buddy1@localhost/mobile\" type=\"chat\">" + "<body>From first resource</body>" + "</message>" + ); + prof_output_exact("<< incoming from buddy1@localhost/mobile (2)"); + + prof_input("/msg buddy1@localhost Outgoing 1"); + + assert_true(stbbr_received( + "<message id=\"*\" to=\"buddy1@localhost/mobile\" type=\"chat\">" + "<body>Outgoing 1</body>" + "</message>" + )); + + stbbr_send( + "<message id=\"message1\" to=\"stabber@localhost\" from=\"buddy1@localhost/laptop\" type=\"chat\">" + "<body>From second resource</body>" + "</message>" + ); + prof_output_regex("buddy1@localhost/laptop:.+From second resource"); + + prof_input("/msg buddy1@localhost Outgoing 2"); + + assert_true(stbbr_received( + "<message id=\"*\" to=\"buddy1@localhost/laptop\" type=\"chat\">" + "<body>Outgoing 2</body>" + "</message>" + )); +} diff --git a/tests/functionaltests/test_chat_session.h b/tests/functionaltests/test_chat_session.h new file mode 100644 index 00000000..2ba75e05 --- /dev/null +++ b/tests/functionaltests/test_chat_session.h @@ -0,0 +1,7 @@ +void sends_message_to_barejid_when_contact_offline(void **state); +void sends_message_to_barejid_when_contact_online(void **state); +void sends_message_to_fulljid_when_received_from_fulljid(void **state); +void sends_subsequent_messages_to_fulljid(void **state); +void resets_to_barejid_after_presence_received(void **state); +void new_session_when_message_received_from_different_fulljid(void **state); + diff --git a/tests/functionaltests/test_connect.c b/tests/functionaltests/test_connect.c new file mode 100644 index 00000000..7a42397f --- /dev/null +++ b/tests/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/tests/functionaltests/test_connect.h b/tests/functionaltests/test_connect.h new file mode 100644 index 00000000..c6ceb404 --- /dev/null +++ b/tests/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/tests/functionaltests/test_message.c b/tests/functionaltests/test_message.c new file mode 100644 index 00000000..5cdad520 --- /dev/null +++ b/tests/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/tests/functionaltests/test_message.h b/tests/functionaltests/test_message.h new file mode 100644 index 00000000..b8f03a7e --- /dev/null +++ b/tests/functionaltests/test_message.h @@ -0,0 +1,2 @@ +void message_send(void **state); +void message_receive(void **state); diff --git a/tests/functionaltests/test_ping.c b/tests/functionaltests/test_ping.c new file mode 100644 index 00000000..e2ca79ca --- /dev/null +++ b/tests/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/tests/functionaltests/test_ping.h b/tests/functionaltests/test_ping.h new file mode 100644 index 00000000..a222a486 --- /dev/null +++ b/tests/functionaltests/test_ping.h @@ -0,0 +1,2 @@ +void ping_multiple(void **state); +void ping_responds(void **state); diff --git a/tests/functionaltests/test_presence.c b/tests/functionaltests/test_presence.c new file mode 100644 index 00000000..b26bdccb --- /dev/null +++ b/tests/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/tests/functionaltests/test_presence.h b/tests/functionaltests/test_presence.h new file mode 100644 index 00000000..0603732a --- /dev/null +++ b/tests/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/tests/functionaltests/test_rooms.c b/tests/functionaltests/test_rooms.c new file mode 100644 index 00000000..20ed7342 --- /dev/null +++ b/tests/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/tests/functionaltests/test_rooms.h b/tests/functionaltests/test_rooms.h new file mode 100644 index 00000000..a0cf5db8 --- /dev/null +++ b/tests/functionaltests/test_rooms.h @@ -0,0 +1,2 @@ +void rooms_query(void **state); + |