diff --git a/Makefile.am b/Makefile.am index 1735d1ea..60ff0f33 100644 --- a/Makefile.am +++ b/Makefile.am @@ -185,6 +185,7 @@ functionaltest_sources = \ tests/functionaltests/test_software.c tests/functionaltests/test_software.h \ tests/functionaltests/test_muc.c tests/functionaltests/test_muc.h \ tests/functionaltests/test_disconnect.c tests/functionaltests/test_disconnect.h \ + tests/functionaltests/test_lastactivity.c tests/functionaltests/test_lastactivity.h \ tests/functionaltests/functionaltests.c main_source = src/main.c diff --git a/tests/functionaltests/functionaltests.c b/tests/functionaltests/functionaltests.c index cd89c58f..46d1a7d2 100644 --- a/tests/functionaltests/functionaltests.c +++ b/tests/functionaltests/functionaltests.c @@ -52,6 +52,7 @@ #include "test_software.h" #include "test_muc.h" #include "test_disconnect.h" +#include "test_lastactivity.h" /* Macro to wrap each test with setup/teardown functions */ #define PROF_FUNC_TEST(test) cmocka_unit_test_setup_teardown(test, init_prof_test, close_prof_test) @@ -104,6 +105,10 @@ main(int argc, char* argv[]) 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), + + /* Last Activity - XEP-0012 */ + PROF_FUNC_TEST(responds_to_last_activity_request), + PROF_FUNC_TEST(last_activity_request_to_contact), }; /* ============================================================ @@ -188,6 +193,10 @@ main(int argc, char* argv[]) PROF_FUNC_TEST(shows_first_message_in_console_when_window_not_focussed), PROF_FUNC_TEST(shows_no_message_in_console_when_window_not_focussed), + /* MUC moderation - XEP-0045 room admin */ + PROF_FUNC_TEST(sends_affiliation_list_request), + PROF_FUNC_TEST(sends_kick_request), + /* Message Carbons - XEP-0280 (message sync across devices) */ PROF_FUNC_TEST(send_enable_carbons), PROF_FUNC_TEST(connect_with_carbons_enabled), diff --git a/tests/functionaltests/test_lastactivity.c b/tests/functionaltests/test_lastactivity.c new file mode 100644 index 00000000..e4ba89db --- /dev/null +++ b/tests/functionaltests/test_lastactivity.c @@ -0,0 +1,63 @@ +/* + * test_lastactivity.c + * Functional tests for Last Activity (XEP-0012) + */ +#include +#include "prof_cmocka.h" +#include +#include + +#include + +#include "proftest.h" + +void +responds_to_last_activity_request(void **state) +{ + prof_connect(); + + // Send incoming last activity request + stbbr_send( + "" + "" + "" + ); + + // Verify profanity responds with last activity info + // The 'seconds' attribute indicates idle time + assert_true(stbbr_received( + "" + "" + "" + )); +} + +void +last_activity_request_to_contact(void **state) +{ + prof_connect(); + + stbbr_send( + "" + "10" + "I'm here" + "" + ); + assert_true(prof_output_exact("Buddy1 (mobile) is online, \"I'm here\"")); + + // Register response for last activity query + stbbr_for_query("jabber:iq:last", + "" + "" + "" + ); + + prof_input("/lastactivity get buddy1@localhost/mobile"); + + // Verify the request was sent + assert_true(stbbr_received( + "" + "" + "" + )); +} diff --git a/tests/functionaltests/test_lastactivity.h b/tests/functionaltests/test_lastactivity.h new file mode 100644 index 00000000..a159a600 --- /dev/null +++ b/tests/functionaltests/test_lastactivity.h @@ -0,0 +1,7 @@ +/* + * test_lastactivity.h + * Header for Last Activity tests (XEP-0012) + */ + +void responds_to_last_activity_request(void **state); +void last_activity_request_to_contact(void **state); diff --git a/tests/functionaltests/test_muc.c b/tests/functionaltests/test_muc.c index 3df179d2..0b618ab3 100644 --- a/tests/functionaltests/test_muc.c +++ b/tests/functionaltests/test_muc.c @@ -393,3 +393,83 @@ shows_no_message_in_console_when_window_not_focussed(void **state) assert_false(prof_output_regex("testroom@conference\\.localhost \\(win 2\\)")); prof_timeout_reset(); } + +void +sends_affiliation_list_request(void **state) +{ + prof_connect(); + + stbbr_for_presence_to("testroom@conference.localhost/stabber", + "" + "" + "" + "" + "" + "" + "" + ); + + prof_input("/join testroom@conference.localhost"); + assert_true(prof_output_regex("-> You have joined the room as stabber, role: moderator, affiliation: owner")); + + prof_input("/affiliation owner list"); + + assert_true(stbbr_received( + "" + "" + "" + "" + "" + )); +} + +void +sends_kick_request(void **state) +{ + prof_connect(); + + // Enable MUC presence messages to see occupant join/leave + prof_input("/presence room all"); + assert_true(prof_output_regex("All presence updates will appear")); + + stbbr_for_presence_to("testroom@conference.localhost/stabber", + "" + "" + "" + "" + "" + "" + "" + ); + + prof_input("/join testroom@conference.localhost"); + assert_true(prof_output_regex("-> You have joined the room as stabber, role: moderator, affiliation: admin")); + + // Simulate another user in the room + stbbr_send( + "" + "" + "" + "" + "" + ); + sleep(1); + assert_true(prof_output_regex("baduser has joined")); + + // Register success response for kick + stbbr_for_query("http://jabber.org/protocol/muc#admin", + "" + ); + + prof_input("/kick baduser \"spamming\""); + + assert_true(stbbr_received( + "" + "" + "" + "spamming" + "" + "" + "" + )); +} diff --git a/tests/functionaltests/test_muc.h b/tests/functionaltests/test_muc.h index 1636bd05..7be3ee1f 100644 --- a/tests/functionaltests/test_muc.h +++ b/tests/functionaltests/test_muc.h @@ -12,3 +12,5 @@ void shows_me_message_from_self(void **state); void shows_all_messages_in_console_when_window_not_focussed(void **state); void shows_first_message_in_console_when_window_not_focussed(void **state); void shows_no_message_in_console_when_window_not_focussed(void **state); +void sends_affiliation_list_request(void **state); +void sends_kick_request(void **state);