about summary refs log tree commit diff stats
path: root/tests/functionaltests/functionaltests.c
blob: 5e8656b714fcda3226d8cbed7b0fd23ceb909314 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#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_carbons.h"
#include "test_chat_session.h"
#include "test_receipts.h"
#include "test_roster.h"
#include "test_software.h"
#include "test_muc.h"
#include "test_disconnect.h"

#define PROF_FUNC_TEST(test) unit_test_setup_teardown(test, init_prof_test, close_prof_test)

int main(int argc, char* argv[]) {

    const UnitTest all_tests[] = {

        PROF_FUNC_TEST(connect_jid_requests_roster),
        PROF_FUNC_TEST(connect_jid_sends_presence_after_receiving_roster),
        PROF_FUNC_TEST(connect_jid_requests_bookmarks),
        PROF_FUNC_TEST(connect_bad_password),
        PROF_FUNC_TEST(connect_shows_presence_updates),

        PROF_FUNC_TEST(ping_server),
        PROF_FUNC_TEST(ping_server_not_supported),
        PROF_FUNC_TEST(ping_responds_to_server_request),
        PROF_FUNC_TEST(ping_jid),
        PROF_FUNC_TEST(ping_jid_not_supported),

        PROF_FUNC_TEST(rooms_query),

        PROF_FUNC_TEST(presence_away),
        PROF_FUNC_TEST(presence_away_with_message),
        PROF_FUNC_TEST(presence_online),
        PROF_FUNC_TEST(presence_online_with_message),
        PROF_FUNC_TEST(presence_xa),
        PROF_FUNC_TEST(presence_xa_with_message),
        PROF_FUNC_TEST(presence_dnd),
        PROF_FUNC_TEST(presence_dnd_with_message),
        PROF_FUNC_TEST(presence_chat),
        PROF_FUNC_TEST(presence_chat_with_message),
        PROF_FUNC_TEST(presence_set_priority),
        PROF_FUNC_TEST(presence_includes_priority),
        PROF_FUNC_TEST(presence_keeps_status),
        PROF_FUNC_TEST(presence_received),
        PROF_FUNC_TEST(presence_missing_resource_defaults),

        PROF_FUNC_TEST(message_send),
        PROF_FUNC_TEST(message_receive_console),
        PROF_FUNC_TEST(message_receive_chatwin),

        PROF_FUNC_TEST(sends_message_to_barejid_when_contact_offline),
        PROF_FUNC_TEST(sends_message_to_barejid_when_contact_online),
        PROF_FUNC_TEST(sends_message_to_fulljid_when_received_from_fulljid),
        PROF_FUNC_TEST(sends_subsequent_messages_to_fulljid),
        PROF_FUNC_TEST(resets_to_barejid_after_presence_received),
        PROF_FUNC_TEST(new_session_when_message_received_from_different_fulljid),

        PROF_FUNC_TEST(send_enable_carbons),
        PROF_FUNC_TEST(connect_with_carbons_enabled),
        PROF_FUNC_TEST(send_disable_carbons),
        PROF_FUNC_TEST(receive_carbon),
        PROF_FUNC_TEST(receive_self_carbon),
        PROF_FUNC_TEST(receive_private_carbon),

        PROF_FUNC_TEST(send_receipt_request),
        PROF_FUNC_TEST(send_receipt_on_request),
        PROF_FUNC_TEST(does_not_send_receipt_request_to_barejid),
        PROF_FUNC_TEST(sends_new_item),
        PROF_FUNC_TEST(sends_new_item_nick),
        PROF_FUNC_TEST(sends_remove_item),
        PROF_FUNC_TEST(sends_nick_change),

        PROF_FUNC_TEST(send_software_version_request),
        PROF_FUNC_TEST(display_software_version_result),
        PROF_FUNC_TEST(shows_message_when_software_version_error),
        PROF_FUNC_TEST(display_software_version_result_when_from_domainpart),
        PROF_FUNC_TEST(show_message_in_chat_window_when_no_resource),
        PROF_FUNC_TEST(display_software_version_result_in_chat),

        PROF_FUNC_TEST(sends_room_join),
        PROF_FUNC_TEST(sends_room_join_with_nick),
        PROF_FUNC_TEST(sends_room_join_with_password),
        PROF_FUNC_TEST(sends_room_join_with_nick_and_password),
        PROF_FUNC_TEST(shows_role_and_affiliation_on_join),
        PROF_FUNC_TEST(shows_subject_on_join),
        PROF_FUNC_TEST(shows_history_message),
        PROF_FUNC_TEST(shows_occupant_join),
        PROF_FUNC_TEST(shows_message),
        PROF_FUNC_TEST(shows_me_message_from_occupant),
        PROF_FUNC_TEST(shows_me_message_from_self),
        PROF_FUNC_TEST(shows_all_messages_in_console_when_window_not_focussed),
        PROF_FUNC_TEST(shows_first_message_in_console_when_window_not_focussed),
        PROF_FUNC_TEST(shows_no_message_in_console_when_window_not_focussed),

        PROF_FUNC_TEST(disconnect_ends_session),
    };

    return run_tests(all_tests);
}
>testpassword</password>" "</x>" "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>" "</presence>" )); } void shows_role_and_affiliation_on_join(void **state) { prof_connect(); stbbr_for_id("prof_join_4", "<presence id='prof_join_4' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>" "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>" "<x xmlns='http://jabber.org/protocol/muc#user'>" "<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>" "</x>" "<status code='110'/>" "</presence>" ); prof_input("/join testroom@conference.localhost"); assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none")); } void shows_subject_on_join(void **state) { prof_connect(); stbbr_for_id("prof_join_4", "<presence id='prof_join_4' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>" "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>" "<x xmlns='http://jabber.org/protocol/muc#user'>" "<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>" "</x>" "<status code='110'/>" "</presence>" ); prof_input("/join testroom@conference.localhost"); assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none")); stbbr_send( "<message type='groupchat' to='stabber@localhost/profanity' from='testroom@conference.localhost'>" "<subject>Test room subject</subject>" "<body>anothernick has set the subject to: Test room subject</body>" "</message>" ); assert_true(prof_output_regex("Room subject: .+Test room subject")); } void shows_history_message(void **state) { prof_connect(); stbbr_for_id("prof_join_4", "<presence id='prof_join_4' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>" "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>" "<x xmlns='http://jabber.org/protocol/muc#user'>" "<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>" "</x>" "<status code='110'/>" "</presence>" ); prof_input("/join testroom@conference.localhost"); assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none")); stbbr_send( "<message type='groupchat' to='stabber@localhost/profanity' from='testroom@conference.localhost/testoccupant'>" "<body>an old message</body>" "<delay xmlns='urn:xmpp:delay' stamp='2015-12-19T23:55:25Z' from='testroom@conference.localhost'/>" "<x xmlns='jabber:x:delay' stamp='20151219T23:55:25'/>" "</message>" ); assert_true(prof_output_regex("testoccupant: an old message")); } void shows_occupant_join(void **state) { prof_connect(); stbbr_for_id("prof_join_4", "<presence id='prof_join_4' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>" "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>" "<x xmlns='http://jabber.org/protocol/muc#user'>" "<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>" "</x>" "<status code='110'/>" "</presence>" ); prof_input("/join testroom@conference.localhost"); assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none")); stbbr_send( "<presence to='stabber@localhost/profanity' from='testroom@conference.localhost/testoccupant'>" "<x xmlns='http://jabber.org/protocol/muc#user'>" "<item role='participant' jid='someuser@someserver.org/work' affiliation='none'/>" "</x>" "</presence>" ); assert_true(prof_output_exact("-> testoccupant has joined the room, role: participant, affiliation: none")); } void shows_message(void **state) { prof_connect(); stbbr_for_id("prof_join_4", "<presence id='prof_join_4' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>" "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>" "<x xmlns='http://jabber.org/protocol/muc#user'>" "<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>" "</x>" "<status code='110'/>" "</presence>" ); prof_input("/join testroom@conference.localhost"); assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none")); stbbr_send( "<message type='groupchat' to='stabber@localhost/profanity' from='testroom@conference.localhost/testoccupant'>" "<body>a new message</body>" "</message>" ); assert_true(prof_output_regex("testoccupant: .+a new message")); } void shows_me_message_from_occupant(void **state) { prof_connect(); stbbr_for_id("prof_join_4", "<presence id='prof_join_4' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>" "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>" "<x xmlns='http://jabber.org/protocol/muc#user'>" "<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>" "</x>" "<status code='110'/>" "</presence>" ); prof_input("/join testroom@conference.localhost"); assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none")); stbbr_send( "<message type='groupchat' to='stabber@localhost/profanity' from='testroom@conference.localhost/testoccupant'>" "<body>/me did something</body>" "</message>" ); assert_true(prof_output_exact("*testoccupant did something")); } void shows_me_message_from_self(void **state) { prof_connect(); stbbr_for_id("prof_join_4", "<presence id='prof_join_4' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>" "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>" "<x xmlns='http://jabber.org/protocol/muc#user'>" "<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>" "</x>" "<status code='110'/>" "</presence>" ); prof_input("/join testroom@conference.localhost"); assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none")); stbbr_send( "<message type='groupchat' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>" "<body>/me did something</body>" "</message>" ); assert_true(prof_output_exact("*stabber did something")); } void shows_all_messages_in_console_when_window_not_focussed(void **state) { prof_connect(); stbbr_for_id("prof_join_4", "<presence id='prof_join_4' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>" "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>" "<x xmlns='http://jabber.org/protocol/muc#user'>" "<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>" "</x>" "<status code='110'/>" "</presence>" ); prof_input("/join testroom@conference.localhost"); assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none")); prof_input("/win 1"); assert_true(prof_output_exact("Profanity. Type /help for help information.")); stbbr_send( "<message type='groupchat' to='stabber@localhost/profanity' from='testroom@conference.localhost/testoccupant'>" "<body>a new message</body>" "</message>" ); assert_true(prof_output_exact("<< room message: testoccupant in testroom@conference.localhost (win 2)")); stbbr_send( "<message type='groupchat' to='stabber@localhost/profanity' from='testroom@conference.localhost/anotheroccupant'>" "<body>some other message</body>" "</message>" ); assert_true(prof_output_exact("<< room message: anotheroccupant in testroom@conference.localhost (win 2)")); } void shows_first_message_in_console_when_window_not_focussed(void **state) { prof_connect(); prof_input("/console muc first"); assert_true(prof_output_exact("Console MUC messages set: first")); stbbr_for_id("prof_join_4", "<presence id='prof_join_4' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>" "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>" "<x xmlns='http://jabber.org/protocol/muc#user'>" "<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>" "</x>" "<status code='110'/>" "</presence>" ); prof_input("/join testroom@conference.localhost"); assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none")); prof_input("/win 1"); assert_true(prof_output_exact("Profanity. Type /help for help information.")); stbbr_send( "<message type='groupchat' to='stabber@localhost/profanity' from='testroom@conference.localhost/testoccupant'>" "<body>a new message</body>" "</message>" ); assert_true(prof_output_exact("<< room message: testroom@conference.localhost (win 2)")); prof_input("/clear"); prof_input("/about"); assert_true(prof_output_exact("Type '/help' to show complete help.")); stbbr_send( "<message type='groupchat' to='stabber@localhost/profanity' from='testroom@conference.localhost/anotheroccupant'>" "<body>some other message</body>" "</message>" ); prof_timeout(2); assert_false(prof_output_exact("<< room message: testroom@conference.localhost (win 2)")); prof_timeout_reset(); } void shows_no_message_in_console_when_window_not_focussed(void **state) { prof_connect(); prof_input("/console muc none"); assert_true(prof_output_exact("Console MUC messages set: none")); stbbr_for_id("prof_join_4", "<presence id='prof_join_4' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>" "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>" "<x xmlns='http://jabber.org/protocol/muc#user'>" "<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>" "</x>" "<status code='110'/>" "</presence>" ); prof_input("/join testroom@conference.localhost"); assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none")); prof_input("/win 1"); assert_true(prof_output_exact("Profanity. Type /help for help information.")); stbbr_send( "<message type='groupchat' to='stabber@localhost/profanity' from='testroom@conference.localhost/testoccupant'>" "<body>a new message</body>" "</message>" ); prof_timeout(2); assert_false(prof_output_exact("testroom@conference.localhost (win 2)")); prof_timeout_reset(); }