From 1f56c12377f15ac4892f7f72eb31be6bf084061e Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 20 Dec 2015 00:54:17 +0000 Subject: [PATCH 1/4] Added cons_show_incoming_room_message() --- src/event/server_events.c | 63 +++++++++++++++++++++++++++++++++--- src/ui/console.c | 15 +++++++++ src/ui/mucwin.c | 49 ---------------------------- src/ui/ui.h | 1 + tests/unittests/ui/stub_ui.c | 1 + 5 files changed, 75 insertions(+), 54 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index a519a28b..12c34d76 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -212,16 +212,69 @@ void sv_ev_room_message(const char *const room_jid, const char *const nick, const char *const message) { - ProfMucWin *mucwin = wins_get_muc(room_jid); - if (mucwin) { - mucwin_message(mucwin, nick, message); - } - if (prefs_get_boolean(PREF_GRLOG)) { Jid *jid = jid_create(jabber_get_fulljid()); groupchat_log_chat(jid->barejid, room_jid, nick, message); jid_destroy(jid); } + + ProfMucWin *mucwin = wins_get_muc(room_jid); + if (!mucwin) { + return; + } + + mucwin_message(mucwin, nick, message); + + ProfWin *window = (ProfWin*)mucwin; + gboolean is_current = wins_is_current(window); + int num = wins_get_num(window); + char *my_nick = muc_nick(mucwin->roomjid); + gboolean notify = prefs_do_room_notify(is_current, mucwin->roomjid, my_nick, message); + + // currently in groupchat window + if (wins_is_current(window)) { + status_bar_active(num); + + // not currently on groupchat window + } else { + status_bar_new(num); + cons_show_incoming_room_message(nick, mucwin->roomjid, num); + + if (prefs_get_boolean(PREF_FLASH) && (strcmp(nick, my_nick) != 0)) { + flash(); + } + + mucwin->unread++; + if (notify) { + mucwin->notify = TRUE; + } + } + + // don't notify self messages + if (strcmp(nick, my_nick) == 0) { + return; + } + + if (prefs_get_boolean(PREF_BEEP)) { + beep(); + } + + if (!notify) { + return; + } + + Jid *jidp = jid_create(mucwin->roomjid); + int ui_index = num; + if (ui_index == 10) { + ui_index = 0; + } + + if (prefs_get_boolean(PREF_NOTIFY_ROOM_TEXT)) { + notify_room_message(nick, jidp->localpart, ui_index, message); + } else { + notify_room_message(nick, jidp->localpart, ui_index, NULL); + } + jid_destroy(jidp); } void diff --git a/src/ui/console.c b/src/ui/console.c index b4083ea3..4e7077c4 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -301,6 +301,21 @@ cons_show_typing(const char *const barejid) cons_alert(); } +void +cons_show_incoming_room_message(const char *const nick, const char *const room, const int win_index) +{ + ProfWin *const console = wins_get_console(); + + int ui_index = win_index; + if (ui_index == 10) { + ui_index = 0; + } + + win_vprint(console, '-', 0, NULL, 0, THEME_INCOMING, "", "<< incoming from %s in %s (win %d)", nick, room, ui_index); + + cons_alert(); +} + void cons_show_incoming_message(const char *const short_from, const int win_index) { diff --git a/src/ui/mucwin.c b/src/ui/mucwin.c index 432256de..4674b198 100644 --- a/src/ui/mucwin.c +++ b/src/ui/mucwin.c @@ -361,7 +361,6 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes assert(mucwin != NULL); ProfWin *window = (ProfWin*)mucwin; - int num = wins_get_num(window); char *my_nick = muc_nick(mucwin->roomjid); if (g_strcmp0(nick, my_nick) != 0) { @@ -373,54 +372,6 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes } else { win_print(window, '-', 0, NULL, 0, THEME_TEXT_ME, nick, message); } - - gboolean is_current = wins_is_current(window); - gboolean notify = prefs_do_room_notify(is_current, mucwin->roomjid, my_nick, message); - - // currently in groupchat window - if (wins_is_current(window)) { - status_bar_active(num); - - // not currently on groupchat window - } else { - status_bar_new(num); - cons_show_incoming_message(nick, num); - - if (prefs_get_boolean(PREF_FLASH) && (strcmp(nick, my_nick) != 0)) { - flash(); - } - - mucwin->unread++; - if (notify) { - mucwin->notify = TRUE; - } - } - - // don't notify self messages - if (strcmp(nick, my_nick) == 0) { - return; - } - - if (prefs_get_boolean(PREF_BEEP)) { - beep(); - } - - if (!notify) { - return; - } - - Jid *jidp = jid_create(mucwin->roomjid); - int ui_index = num; - if (ui_index == 10) { - ui_index = 0; - } - - if (prefs_get_boolean(PREF_NOTIFY_ROOM_TEXT)) { - notify_room_message(nick, jidp->localpart, ui_index, message); - } else { - notify_room_message(nick, jidp->localpart, ui_index, NULL); - } - jid_destroy(jidp); } void diff --git a/src/ui/ui.h b/src/ui/ui.h index e21f2ea8..7bb15545 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -257,6 +257,7 @@ void cons_show_disco_info(const char *from, GSList *identities, GSList *features void cons_show_room_invite(const char *const invitor, const char *const room, const char *const reason); void cons_check_version(gboolean not_available_msg); void cons_show_typing(const char *const barejid); +void cons_show_incoming_room_message(const char *const nick, const char *const room, const int win_index); void cons_show_incoming_message(const char *const short_from, const int win_index); void cons_show_room_invites(GSList *invites); void cons_show_received_subs(void); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 57fe6db6..1ed6f43d 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -394,6 +394,7 @@ void cons_show_room_invite(const char * const invitor, const char * const room, const char * const reason) {} void cons_check_version(gboolean not_available_msg) {} void cons_show_typing(const char * const barejid) {} +void cons_show_incoming_room_message(const char *const nick, const char *const room, const int win_index) {} void cons_show_incoming_message(const char * const short_from, const int win_index) {} void cons_show_room_invites(GSList *invites) {} void cons_show_received_subs(void) {} From 87b4d7cbab44d30d272d87d5b59dbaad51fa90dd Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 20 Dec 2015 02:13:01 +0000 Subject: [PATCH 2/4] Added muc functional tests --- Makefile.am | 1 + tests/functionaltests/functionaltests.c | 10 ++ tests/functionaltests/test_muc.c | 139 ++++++++++++++++++++++++ tests/functionaltests/test_muc.h | 12 ++ 4 files changed, 162 insertions(+) create mode 100644 tests/functionaltests/test_muc.c create mode 100644 tests/functionaltests/test_muc.h diff --git a/Makefile.am b/Makefile.am index 1f7e0350..2452451c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -114,6 +114,7 @@ functionaltest_sources = \ tests/functionaltests/test_receipts.c tests/functionaltests/test_receipts.h \ tests/functionaltests/test_roster.c tests/functionaltests/test_roster.h \ tests/functionaltests/test_software.c tests/functionaltests/test_software.h \ + tests/functionaltests/test_muc.c tests/functionaltests/test_muc.h \ tests/functionaltests/functionaltests.c main_source = src/main.c diff --git a/tests/functionaltests/functionaltests.c b/tests/functionaltests/functionaltests.c index 6226af7f..39f43b49 100644 --- a/tests/functionaltests/functionaltests.c +++ b/tests/functionaltests/functionaltests.c @@ -20,6 +20,7 @@ #include "test_receipts.h" #include "test_roster.h" #include "test_software.h" +#include "test_muc.h" #define PROF_FUNC_TEST(test) unit_test_setup_teardown(test, init_prof_test, close_prof_test) @@ -82,6 +83,15 @@ int 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), + + PROF_FUNC_TEST(sends_room_join), + PROF_FUNC_TEST(sends_room_join_with_default_muc_service), + 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(show_role_and_affiliation_on_join), + PROF_FUNC_TEST(show_subject_on_join), + }; return run_tests(all_tests); diff --git a/tests/functionaltests/test_muc.c b/tests/functionaltests/test_muc.c new file mode 100644 index 00000000..83e383be --- /dev/null +++ b/tests/functionaltests/test_muc.c @@ -0,0 +1,139 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "proftest.h" + +void +sends_room_join(void **state) +{ + prof_connect(); + + prof_input("/join testroom@conference.localhost"); + + assert_true(stbbr_last_received( + "" + "" + "" + "" + )); +} + +void +sends_room_join_with_default_muc_service(void **state) +{ + prof_connect(); + + prof_input("/join testroom"); + + assert_true(stbbr_last_received( + "" + "" + "" + "" + )); +} + +void +sends_room_join_with_nick(void **state) +{ + prof_connect(); + + prof_input("/join testroom@conference.localhost nick testnick"); + + assert_true(stbbr_last_received( + "" + "" + "" + "" + )); +} + +void +sends_room_join_with_password(void **state) +{ + prof_connect(); + + prof_input("/join testroom@conference.localhost password testpassword"); + + assert_true(stbbr_last_received( + "" + "" + "testpassword" + "" + "" + "" + )); +} + +void +sends_room_join_with_nick_and_password(void **state) +{ + prof_connect(); + + prof_input("/join testroom@conference.localhost nick testnick password testpassword"); + + assert_true(stbbr_last_received( + "" + "" + "testpassword" + "" + "" + "" + )); +} + +void +show_role_and_affiliation_on_join(void **state) +{ + prof_connect(); + + stbbr_for_id("prof_join_2", + "" + "" + "" + "" + "" + "" + "" + ); + + prof_input("/join testroom@conference.localhost"); + + assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none")); +} + +void +show_subject_on_join(void **state) +{ + prof_connect(); + + stbbr_for_id("prof_join_2", + "" + "" + "" + "" + "" + "" + "" + ); + + prof_input("/join testroom@conference.localhost"); + assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none")); + + stbbr_send( + "" + "Test room subject" + "anothernick has set the subject to: Test room subject" + "" + ); + + assert_true(prof_output_regex("Room subject: .+Test room subject")); +} diff --git a/tests/functionaltests/test_muc.h b/tests/functionaltests/test_muc.h new file mode 100644 index 00000000..49329a36 --- /dev/null +++ b/tests/functionaltests/test_muc.h @@ -0,0 +1,12 @@ +void sends_room_join(void **state); +void sends_room_join_with_default_muc_service(void **state); +void sends_room_join_with_nick(void **state); +void sends_room_join_with_password(void **state); +void sends_room_join_with_nick_and_password(void **state); +void show_role_and_affiliation_on_join(void **state); +void show_subject_on_join(void **state); + + + + + From 46a0e6ebed23560777e1387eeb4f2a6c8c311cc5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 20 Dec 2015 02:17:17 +0000 Subject: [PATCH 3/4] Removed whitespace --- tests/functionaltests/test_muc.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/functionaltests/test_muc.h b/tests/functionaltests/test_muc.h index 49329a36..172e2adb 100644 --- a/tests/functionaltests/test_muc.h +++ b/tests/functionaltests/test_muc.h @@ -5,8 +5,3 @@ void sends_room_join_with_password(void **state); void sends_room_join_with_nick_and_password(void **state); void show_role_and_affiliation_on_join(void **state); void show_subject_on_join(void **state); - - - - - From c61e9d80ea7724c141d7dc8610b3c3ca6b46f24b Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 20 Dec 2015 02:42:11 +0000 Subject: [PATCH 4/4] Added more muc functional tests --- tests/functionaltests/functionaltests.c | 7 +- tests/functionaltests/test_muc.c | 89 ++++++++++++++++++++++++- tests/functionaltests/test_muc.h | 7 +- 3 files changed, 97 insertions(+), 6 deletions(-) diff --git a/tests/functionaltests/functionaltests.c b/tests/functionaltests/functionaltests.c index 39f43b49..b5dfa3ae 100644 --- a/tests/functionaltests/functionaltests.c +++ b/tests/functionaltests/functionaltests.c @@ -89,8 +89,11 @@ int main(int argc, char* argv[]) { 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(show_role_and_affiliation_on_join), - PROF_FUNC_TEST(show_subject_on_join), + 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), }; diff --git a/tests/functionaltests/test_muc.c b/tests/functionaltests/test_muc.c index 83e383be..5911209e 100644 --- a/tests/functionaltests/test_muc.c +++ b/tests/functionaltests/test_muc.c @@ -91,7 +91,7 @@ sends_room_join_with_nick_and_password(void **state) } void -show_role_and_affiliation_on_join(void **state) +shows_role_and_affiliation_on_join(void **state) { prof_connect(); @@ -111,7 +111,7 @@ show_role_and_affiliation_on_join(void **state) } void -show_subject_on_join(void **state) +shows_subject_on_join(void **state) { prof_connect(); @@ -137,3 +137,88 @@ show_subject_on_join(void **state) assert_true(prof_output_regex("Room subject: .+Test room subject")); } + +void +shows_history_message(void **state) +{ + prof_connect(); + + stbbr_for_id("prof_join_2", + "" + "" + "" + "" + "" + "" + "" + ); + + prof_input("/join testroom@conference.localhost"); + assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none")); + + stbbr_send( + "" + "an old message" + "" + "" + "" + ); + + assert_true(prof_output_regex("testoccupant: an old message")); +} + +void +shows_occupant_join(void **state) +{ + prof_connect(); + + stbbr_for_id("prof_join_2", + "" + "" + "" + "" + "" + "" + "" + ); + + prof_input("/join testroom@conference.localhost"); + assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none")); + + stbbr_send( + "" + "" + "" + "" + "" + ); + + 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_2", + "" + "" + "" + "" + "" + "" + "" + ); + + prof_input("/join testroom@conference.localhost"); + assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none")); + + stbbr_send( + "" + "a new message" + "" + ); + + assert_true(prof_output_regex("testoccupant: .+a new message")); +} diff --git a/tests/functionaltests/test_muc.h b/tests/functionaltests/test_muc.h index 172e2adb..5b7690cb 100644 --- a/tests/functionaltests/test_muc.h +++ b/tests/functionaltests/test_muc.h @@ -3,5 +3,8 @@ void sends_room_join_with_default_muc_service(void **state); void sends_room_join_with_nick(void **state); void sends_room_join_with_password(void **state); void sends_room_join_with_nick_and_password(void **state); -void show_role_and_affiliation_on_join(void **state); -void show_subject_on_join(void **state); +void shows_role_and_affiliation_on_join(void **state); +void shows_subject_on_join(void **state); +void shows_history_message(void **state); +void shows_occupant_join(void **state); +void shows_message(void **state);