mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Merge branch 'master' into osx-functional
This commit is contained in:
commit
fabfeed6da
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
||||
@ -88,6 +89,18 @@ 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(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),
|
||||
|
||||
};
|
||||
|
||||
return run_tests(all_tests);
|
||||
|
224
tests/functionaltests/test_muc.c
Normal file
224
tests/functionaltests/test_muc.c
Normal file
@ -0,0 +1,224 @@
|
||||
#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_room_join(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/join testroom@conference.localhost");
|
||||
|
||||
assert_true(stbbr_last_received(
|
||||
"<presence id=\"*\" to=\"testroom@conference.localhost/stabber\">"
|
||||
"<x xmlns=\"http://jabber.org/protocol/muc\"/>"
|
||||
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
|
||||
void
|
||||
sends_room_join_with_default_muc_service(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/join testroom");
|
||||
|
||||
assert_true(stbbr_last_received(
|
||||
"<presence id=\"*\" to=\"testroom@conference.localhost/stabber\">"
|
||||
"<x xmlns=\"http://jabber.org/protocol/muc\"/>"
|
||||
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
|
||||
void
|
||||
sends_room_join_with_nick(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/join testroom@conference.localhost nick testnick");
|
||||
|
||||
assert_true(stbbr_last_received(
|
||||
"<presence id=\"*\" to=\"testroom@conference.localhost/testnick\">"
|
||||
"<x xmlns=\"http://jabber.org/protocol/muc\"/>"
|
||||
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
|
||||
void
|
||||
sends_room_join_with_password(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/join testroom@conference.localhost password testpassword");
|
||||
|
||||
assert_true(stbbr_last_received(
|
||||
"<presence id=\"*\" to=\"testroom@conference.localhost/stabber\">"
|
||||
"<x xmlns=\"http://jabber.org/protocol/muc\">"
|
||||
"<password>testpassword</password>"
|
||||
"</x>"
|
||||
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
|
||||
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(
|
||||
"<presence id=\"*\" to=\"testroom@conference.localhost/testnick\">"
|
||||
"<x xmlns=\"http://jabber.org/protocol/muc\">"
|
||||
"<password>testpassword</password>"
|
||||
"</x>"
|
||||
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
|
||||
void
|
||||
shows_role_and_affiliation_on_join(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
stbbr_for_id("prof_join_2",
|
||||
"<presence id=\"prof_join_2\" lang=\"en\" to=\"stabber@localhost/profanity\" from=\"testroom@conference.localhost/stabber\">"
|
||||
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" node=\"http://www.profanity.im\" 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_2",
|
||||
"<presence id=\"prof_join_2\" lang=\"en\" to=\"stabber@localhost/profanity\" from=\"testroom@conference.localhost/stabber\">"
|
||||
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" node=\"http://www.profanity.im\" 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_2",
|
||||
"<presence id=\"prof_join_2\" lang=\"en\" to=\"stabber@localhost/profanity\" from=\"testroom@conference.localhost/stabber\">"
|
||||
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" node=\"http://www.profanity.im\" 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_2",
|
||||
"<presence id=\"prof_join_2\" lang=\"en\" to=\"stabber@localhost/profanity\" from=\"testroom@conference.localhost/stabber\">"
|
||||
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" node=\"http://www.profanity.im\" 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_2",
|
||||
"<presence id=\"prof_join_2\" lang=\"en\" to=\"stabber@localhost/profanity\" from=\"testroom@conference.localhost/stabber\">"
|
||||
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" node=\"http://www.profanity.im\" 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"));
|
||||
}
|
10
tests/functionaltests/test_muc.h
Normal file
10
tests/functionaltests/test_muc.h
Normal file
@ -0,0 +1,10 @@
|
||||
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 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);
|
@ -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) {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user