diff --git a/Makefile.am b/Makefile.am index d43845b7..4174e0d6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -67,9 +67,11 @@ test_sources = \ src/plugins/plugins.h src/plugins/plugins.c \ src/plugins/api.h src/plugins/api.c \ src/plugins/callbacks.h src/plugins/callbacks.c \ + src/server_events.c src/server_events.h \ tests/xmpp/mock_xmpp.h tests/xmpp/mock_xmpp.c \ tests/ui/mock_ui.h tests/ui/mock_ui.c \ tests/config/mock_accounts.h tests/config/mock_accounts.c \ + tests/config/helpers.c tests/config/helpers.h \ tests/log/mock_log.c \ tests/test_autocomplete.c \ tests/test_common.c \ @@ -78,10 +80,13 @@ test_sources = \ tests/test_cmd_account.c \ tests/test_cmd_rooms.c \ tests/test_cmd_sub.c \ + tests/test_cmd_statuses.c \ tests/test_history.c \ tests/test_jid.c \ tests/test_parser.c \ tests/test_roster_list.c \ + tests/test_preferences.c \ + tests/test_server_events.c \ tests/testsuite.c main_source = src/main.c diff --git a/src/command/command.c b/src/command/command.c index 2e70bb85..12bb3fcc 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -66,6 +66,7 @@ static char * _group_autocomplete(char *input, int *size); static char * _bookmark_autocomplete(char *input, int *size); static char * _otr_autocomplete(char *input, int *size); static char * _connect_autocomplete(char *input, int *size); +static char * _statuses_autocomplete(char *input, int *size); GHashTable *commands = NULL; @@ -762,13 +763,26 @@ static struct cmd_t command_defs[] = { "/statuses", - cmd_statuses, parse_args, 1, 1, &cons_statuses_setting, - { "/statuses on|off", "Set notifications for status messages.", - { "/statuses on|off", - "----------------", - "Show status updates from contacts, such as online/offline/away etc.", - "When disabled, status updates are not displayed.", - "The default is 'on'.", + cmd_statuses, parse_args, 2, 2, &cons_statuses_setting, + { "/statuses console|chat|muc setting", "Set preferences for presence change messages.", + { "/statuses console|chat|muc setting", + "----------------------------------", + "Configure how presence changes are displayed in various windows.", + "Settings for the console:", + " all - Show all presence changes in the console", + " online - Show only when contacts log in/out.", + " none - Don't show any presence changes in the console.", + "Settings for chat windows:", + " all - Show all presence changes in the contact's chat window if one is open.", + " online - Show only when contacts log in/out.", + " none - Don't show any presence changes in the chat windows.", + "Settings for chat room windows:", + " on - Show presence changes in chat rooms.", + " off - Do not show presence changes in chat rooms.", + "The defaults are:", + " console - all", + " chat - all", + " muc - on", NULL } } }, { "/away", @@ -852,6 +866,8 @@ static Autocomplete bookmark_ac; static Autocomplete otr_ac; static Autocomplete otr_log_ac; static Autocomplete connect_property_ac; +static Autocomplete statuses_ac; +static Autocomplete statuses_cons_chat_ac; /* * Initialise command autocompleter and history @@ -1025,6 +1041,16 @@ cmd_init(void) autocomplete_add(connect_property_ac, "server"); autocomplete_add(connect_property_ac, "port"); + statuses_ac = autocomplete_new(); + autocomplete_add(statuses_ac, "console"); + autocomplete_add(statuses_ac, "chat"); + autocomplete_add(statuses_ac, "muc"); + + statuses_cons_chat_ac = autocomplete_new(); + autocomplete_add(statuses_cons_chat_ac, "all"); + autocomplete_add(statuses_cons_chat_ac, "online"); + autocomplete_add(statuses_cons_chat_ac, "none"); + cmd_history_init(); } @@ -1064,6 +1090,8 @@ cmd_uninit(void) autocomplete_free(otr_ac); autocomplete_free(otr_log_ac); autocomplete_free(connect_property_ac); + autocomplete_free(statuses_ac); + autocomplete_free(statuses_cons_chat_ac); } // Command autocompletion functions @@ -1140,6 +1168,8 @@ cmd_reset_autocomplete() autocomplete_reset(otr_ac); autocomplete_reset(otr_log_ac); autocomplete_reset(connect_property_ac); + autocomplete_reset(statuses_ac); + autocomplete_reset(statuses_cons_chat_ac); bookmark_autocomplete_reset(); } @@ -1306,7 +1336,7 @@ _cmd_complete_parameters(char *input, int *size) // autocomplete boolean settings gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype", "/flash", "/splash", "/chlog", "/grlog", "/mouse", "/history", - "/vercheck", "/statuses" }; + "/vercheck" }; for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) { result = autocomplete_param_with_func(input, size, boolean_choices[i], @@ -1402,7 +1432,7 @@ _cmd_complete_parameters(char *input, int *size) _autoaway_autocomplete, _titlebar_autocomplete, _theme_autocomplete, _account_autocomplete, _roster_autocomplete, _group_autocomplete, _bookmark_autocomplete, _autoconnect_autocomplete, _otr_autocomplete, - _connect_autocomplete }; + _connect_autocomplete, _statuses_autocomplete }; for (i = 0; i < ARRAY_SIZE(acs); i++) { result = acs[i](input, size); @@ -1679,6 +1709,34 @@ _theme_autocomplete(char *input, int *size) return NULL; } +static char * +_statuses_autocomplete(char *input, int *size) +{ + char *result = NULL; + + result = autocomplete_param_with_ac(input, size, "/statuses console", statuses_cons_chat_ac); + if (result != NULL) { + return result; + } + + result = autocomplete_param_with_ac(input, size, "/statuses chat", statuses_cons_chat_ac); + if (result != NULL) { + return result; + } + + result = autocomplete_param_with_func(input, size, "/statuses muc", prefs_autocomplete_boolean_choice); + if (result != NULL) { + return result; + } + + result = autocomplete_param_with_ac(input, size, "/statuses", statuses_ac); + if (result != NULL) { + return result; + } + + return NULL; +} + static char * _connect_autocomplete(char *input, int *size) { diff --git a/src/command/commands.c b/src/command/commands.c index 10bc81f5..744165d6 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2256,8 +2256,56 @@ cmd_priority(gchar **args, struct cmd_help_t help) gboolean cmd_statuses(gchar **args, struct cmd_help_t help) { - return _cmd_set_boolean_preference(args[0], help, - "Status notifications", PREF_STATUSES); + if (strcmp(args[0], "console") != 0 && + strcmp(args[0], "chat") != 0 && + strcmp(args[0], "muc") != 0) { + cons_show("Usage: %s", help.usage); + } + + if (strcmp(args[0], "console") == 0 || strcmp(args[0], "chat") == 0) { + if (strcmp(args[1], "all") != 0 && + strcmp(args[1], "online") != 0 && + strcmp(args[1], "none") != 0) { + cons_show("Usage: %s", help.usage); + return TRUE; + } + + } + + if (strcmp(args[0], "muc") == 0) { + if (strcmp(args[1], "on") != 0 && strcmp(args[1], "off") != 0) { + cons_show("Usage: %s", help.usage); + return TRUE; + } + } + + if (strcmp(args[0], "console") == 0) { + prefs_set_string(PREF_STATUSES_CONSOLE, args[1]); + if (strcmp(args[1], "all") == 0) { + cons_show("All presence updates will appear in the console."); + } else if (strcmp(args[1], "online") == 0) { + cons_show("Only online/offline presence updates will appear in the console."); + } else { + cons_show("Presence updates will not appear in the console."); + } + } + + if (strcmp(args[0], "chat") == 0) { + prefs_set_string(PREF_STATUSES_CHAT, args[1]); + if (strcmp(args[1], "all") == 0) { + cons_show("All presence updates will appear in chat windows."); + } else if (strcmp(args[1], "online") == 0) { + cons_show("Only online/offline presence updates will appear in chat windows."); + } else { + cons_show("Presence updates will not appear in chat windows."); + } + } + + if (strcmp(args[0], "muc") == 0) { + _cmd_set_boolean_preference(args[1], help, + "Chat room presence updates", PREF_STATUSES_MUC); + } + return TRUE; } gboolean diff --git a/src/config/preferences.c b/src/config/preferences.c index 88020164..d4f0675b 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -23,6 +23,7 @@ #include "prof_config.h" #include +#include #include #include @@ -86,6 +87,7 @@ prefs_close(void) { autocomplete_free(boolean_choice_ac); g_key_file_free(prefs); + prefs = NULL; } char * @@ -306,6 +308,9 @@ _get_group(preference_t pref) case PREF_HISTORY: case PREF_MOUSE: case PREF_STATUSES: + case PREF_STATUSES_CONSOLE: + case PREF_STATUSES_CHAT: + case PREF_STATUSES_MUC: case PREF_OTR_WARN: return "ui"; case PREF_STATES: @@ -356,6 +361,12 @@ _get_key(preference_t pref) return "mouse"; case PREF_STATUSES: return "statuses"; + case PREF_STATUSES_CONSOLE: + return "statuses.console"; + case PREF_STATUSES_CHAT: + return "statuses.chat"; + case PREF_STATUSES_MUC: + return "statuses.muc"; case PREF_STATES: return "enabled"; case PREF_OUTTYPE: @@ -397,6 +408,7 @@ _get_default_boolean(preference_t pref) case PREF_STATUSES: case PREF_AUTOAWAY_CHECK: case PREF_OTR_WARN: + case PREF_STATUSES_MUC: return TRUE; default: return FALSE; @@ -412,6 +424,9 @@ _get_default_string(preference_t pref) return "off"; case PREF_OTR_LOG: return "redact"; + case PREF_STATUSES_CONSOLE: + case PREF_STATUSES_CHAT: + return "all"; default: return NULL; } diff --git a/src/config/preferences.h b/src/config/preferences.h index c3ef1667..86a5f504 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -46,6 +46,9 @@ typedef enum { PREF_HISTORY, PREF_MOUSE, PREF_STATUSES, + PREF_STATUSES_CONSOLE, + PREF_STATUSES_CHAT, + PREF_STATUSES_MUC, PREF_STATES, PREF_OUTTYPE, PREF_NOTIFY_TYPING, diff --git a/src/server_events.c b/src/server_events.c index d7ece623..294ad561 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -30,6 +30,9 @@ #include "roster_list.h" #include "ui/ui.h" #include "plugins/plugins.h" + +#include "ui/windows.h" + #ifdef PROF_HAVE_LIBOTR #include "otr.h" #endif @@ -336,17 +339,35 @@ handle_subscription(const char *from, jabber_subscr_t type) } void -handle_contact_offline(char *contact, char *resource, char *status) +handle_contact_offline(char *barejid, char *resource, char *status) { - gboolean updated = roster_contact_offline(contact, resource, status); + gboolean updated = roster_contact_offline(barejid, resource, status); - if (resource != NULL && updated && prefs_get_boolean(PREF_STATUSES)) { - Jid *jid = jid_create_from_bare_and_resource(contact, resource); - PContact result = roster_get_contact(contact); - if (p_contact_subscription(result) != NULL) { - if (strcmp(p_contact_subscription(result), "none") != 0) { - ui_contact_offline(jid->fulljid, "offline", status); - ui_current_page_off(); + if (resource != NULL && updated) { + char *show_console = prefs_get_string(PREF_STATUSES_CONSOLE); + char *show_chat_win = prefs_get_string(PREF_STATUSES_CHAT); + Jid *jid = jid_create_from_bare_and_resource(barejid, resource); + PContact contact = roster_get_contact(barejid); + if (p_contact_subscription(contact) != NULL) { + if (strcmp(p_contact_subscription(contact), "none") != 0) { + + // show in console if "all" + if (g_strcmp0(show_console, "all") == 0) { + cons_show_contact_offline(contact, resource, status); + + // show in console of "online" + } else if (g_strcmp0(show_console, "online") == 0) { + cons_show_contact_offline(contact, resource, status); + } + + // show in chat win if "all" + if (g_strcmp0(show_chat_win, "all") == 0) { + ui_chat_win_contact_offline(contact, resource, status); + + // show in char win if "online" and presence online + } else if (g_strcmp0(show_chat_win, "online") == 0) { + ui_chat_win_contact_offline(contact, resource, status); + } } } jid_destroy(jid); @@ -354,18 +375,38 @@ handle_contact_offline(char *contact, char *resource, char *status) } void -handle_contact_online(char *contact, Resource *resource, +handle_contact_online(char *barejid, Resource *resource, GDateTime *last_activity) { - gboolean updated = roster_update_presence(contact, resource, last_activity); + gboolean updated = roster_update_presence(barejid, resource, last_activity); - if (updated && prefs_get_boolean(PREF_STATUSES)) { - PContact result = roster_get_contact(contact); - if (p_contact_subscription(result) != NULL) { - if (strcmp(p_contact_subscription(result), "none") != 0) { - const char *show = string_from_resource_presence(resource->presence); - ui_contact_online(contact, resource->name, show, resource->status, last_activity); - ui_current_page_off(); + if (updated) { + char *show_console = prefs_get_string(PREF_STATUSES_CONSOLE); + char *show_chat_win = prefs_get_string(PREF_STATUSES_CHAT); + PContact contact = roster_get_contact(barejid); + if (p_contact_subscription(contact) != NULL) { + if (strcmp(p_contact_subscription(contact), "none") != 0) { + + // show in console if "all" + if (g_strcmp0(show_console, "all") == 0) { + cons_show_contact_online(contact, resource, last_activity); + + // show in console of "online" and presence online + } else if (g_strcmp0(show_console, "online") == 0 && + resource->presence == RESOURCE_ONLINE) { + cons_show_contact_online(contact, resource, last_activity); + + } + + // show in chat win if "all" + if (g_strcmp0(show_chat_win, "all") == 0) { + ui_chat_win_contact_online(contact, resource, last_activity); + + // show in char win if "online" and presence online + } else if (g_strcmp0(show_chat_win, "online") == 0 && + resource->presence == RESOURCE_ONLINE) { + ui_chat_win_contact_online(contact, resource, last_activity); + } } } } @@ -402,8 +443,11 @@ handle_room_member_presence(const char * const room, gboolean updated = muc_add_to_roster(room, nick, show, status, caps_str); if (updated) { - ui_room_member_presence(room, nick, show, status); - ui_current_page_off(); + gboolean show_muc = prefs_get_boolean(PREF_STATUSES_MUC); + if (show_muc) { + ui_room_member_presence(room, nick, show, status); + ui_current_page_off(); + } } } diff --git a/src/server_events.h b/src/server_events.h index ce3c3b49..64bd04a7 100644 --- a/src/server_events.h +++ b/src/server_events.h @@ -23,6 +23,8 @@ #ifndef SERVER_EVENTS_H #define SERVER_EVENTS_H +#include "xmpp/xmpp.h" + void handle_error_message(const char *from, const char *err_msg); void handle_login_account_success(char *account_name); void handle_lost_connection(void); diff --git a/src/ui/console.c b/src/ui/console.c index 7d083b14..16b545b0 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -907,9 +907,9 @@ _cons_theme_setting(void) { gchar *theme = prefs_get_string(PREF_THEME); if (theme == NULL) { - cons_show("Theme (/theme) : default"); + cons_show("Theme (/theme) : default"); } else { - cons_show("Theme (/theme) : %s", theme); + cons_show("Theme (/theme) : %s", theme); } } @@ -917,27 +917,27 @@ static void _cons_beep_setting(void) { if (prefs_get_boolean(PREF_BEEP)) - cons_show("Terminal beep (/beep) : ON"); + cons_show("Terminal beep (/beep) : ON"); else - cons_show("Terminal beep (/beep) : OFF"); + cons_show("Terminal beep (/beep) : OFF"); } static void _cons_flash_setting(void) { if (prefs_get_boolean(PREF_FLASH)) - cons_show("Terminal flash (/flash) : ON"); + cons_show("Terminal flash (/flash) : ON"); else - cons_show("Terminal flash (/flash) : OFF"); + cons_show("Terminal flash (/flash) : OFF"); } static void _cons_splash_setting(void) { if (prefs_get_boolean(PREF_SPLASH)) - cons_show("Splash screen (/splash) : ON"); + cons_show("Splash screen (/splash) : ON"); else - cons_show("Splash screen (/splash) : OFF"); + cons_show("Splash screen (/splash) : OFF"); } static void @@ -953,36 +953,44 @@ static void _cons_vercheck_setting(void) { if (prefs_get_boolean(PREF_VERCHECK)) - cons_show("Version checking (/vercheck) : ON"); + cons_show("Version checking (/vercheck) : ON"); else - cons_show("Version checking (/vercheck) : OFF"); + cons_show("Version checking (/vercheck) : OFF"); } static void _cons_mouse_setting(void) { if (prefs_get_boolean(PREF_MOUSE)) - cons_show("Mouse handling (/mouse) : ON"); + cons_show("Mouse handling (/mouse) : ON"); else - cons_show("Mouse handling (/mouse) : OFF"); + cons_show("Mouse handling (/mouse) : OFF"); } static void _cons_statuses_setting(void) { - if (prefs_get_boolean(PREF_STATUSES)) - cons_show("Status (/statuses) : ON"); - else - cons_show("Status (/statuses) : OFF"); + char *console = prefs_get_string(PREF_STATUSES_CONSOLE); + char *chat = prefs_get_string(PREF_STATUSES_CHAT); + gboolean muc = prefs_get_boolean(PREF_STATUSES_MUC); + + cons_show("Console statuses (/statuses) : %s", console); + cons_show("Chat win statuses (/statuses) : %s", chat); + + if (muc) { + cons_show("MUC statuses (/statuses) : ON"); + } else { + cons_show("MUC statuses (/statuses) : OFF"); + } } static void _cons_titlebar_setting(void) { if (prefs_get_boolean(PREF_TITLEBARVERSION)) { - cons_show("Titlebar display (/titlebar) : version"); + cons_show("Titlebar display (/titlebar) : version"); } else { - cons_show("Titlebar display (/titlebar) : NONE"); + cons_show("Titlebar display (/titlebar) : NONE"); } } @@ -990,9 +998,9 @@ static void _cons_otrwarn_setting(void) { if (prefs_get_boolean(PREF_OTR_WARN)) { - cons_show("Warn non-OTR (/otr warn) : ON"); + cons_show("Warn non-OTR (/otr warn) : ON"); } else { - cons_show("Warn non-OTR (/otr warn) : OFF"); + cons_show("Warn non-OTR (/otr warn) : OFF"); } } @@ -1369,6 +1377,40 @@ _cons_show_roster(GSList *list) cons_alert(); } +static void +_cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity) +{ + const char *show = string_from_resource_presence(resource->presence); + char *display_str = p_contact_create_display_string(contact, resource->name); + + ProfWin *console = wins_get_console(); + win_show_status_string(console, display_str, show, resource->status, last_activity, + "++", "online"); + + free(display_str); + + if (wins_is_current(console)) { + ui_current_page_off(); + } + wins_refresh_console(); +} + +static void +_cons_show_contact_offline(PContact contact, char *resource, char *status) +{ + char *display_str = p_contact_create_display_string(contact, resource); + + ProfWin *console = wins_get_console(); + win_show_status_string(console, display_str, "offline", status, NULL, "--", + "offline"); + free(display_str); + + if (wins_is_current(console)) { + ui_current_page_off(); + } + wins_refresh_console(); +} + static void _cons_show_contacts(GSList *list) { @@ -1594,4 +1636,6 @@ console_init_module(void) cons_show_roster = _cons_show_roster; cons_show_contacts = _cons_show_contacts; cons_alert = _cons_alert; + cons_show_contact_online = _cons_show_contact_online; + cons_show_contact_offline = _cons_show_contact_offline; } diff --git a/src/ui/core.c b/src/ui/core.c index 0237e3ef..aea3bebf 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -357,60 +357,6 @@ _ui_handle_error_message(const char * const from, const char * const err_msg) ui_print_error_from_recipient(from, err_msg); } -static void -_ui_contact_online(const char * const barejid, const char * const resource, - const char * const show, const char * const status, GDateTime *last_activity) -{ - PContact contact = roster_get_contact(barejid); - char *display_str = p_contact_create_display_string(contact, resource); - - ProfWin *console = wins_get_console(); - win_show_status_string(console, display_str, show, status, last_activity, - "++", "online"); - - ProfWin *window = wins_get_by_recipient(barejid); - if (window != NULL) { - win_show_status_string(window, display_str, show, status, - last_activity, "++", "online"); - } - - free(display_str); - - if (wins_is_current(console)) { - wins_refresh_current(); - } else if ((window != NULL) && (wins_is_current(window))) { - wins_refresh_current(); - } -} - -static void -_ui_contact_offline(const char * const from, const char * const show, - const char * const status) -{ - Jid *jidp = jid_create(from); - PContact contact = roster_get_contact(jidp->barejid); - char *display_str = p_contact_create_display_string(contact, jidp->resourcepart); - - ProfWin *console = wins_get_console(); - win_show_status_string(console, display_str, show, status, NULL, "--", - "offline"); - - ProfWin *window = wins_get_by_recipient(jidp->barejid); - if (window != NULL) { - win_show_status_string(window, display_str, show, status, NULL, "--", - "offline"); - } - - jid_destroy(jidp); - free(display_str); - - if (wins_is_current(console)) { - wins_refresh_current(); - } else if ((window != NULL) && (wins_is_current(window))) { - wins_refresh_current(); - } -} - static void _ui_disconnected(void) { @@ -1463,6 +1409,47 @@ _ui_ask_password(void) return passwd; } +static void +_ui_chat_win_contact_online(PContact contact, Resource *resource, GDateTime *last_activity) +{ + const char *show = string_from_resource_presence(resource->presence); + char *display_str = p_contact_create_display_string(contact, resource->name); + const char *barejid = p_contact_barejid(contact); + + ProfWin *window = wins_get_by_recipient(barejid); + if (window != NULL) { + win_show_status_string(window, display_str, show, resource->status, + last_activity, "++", "online"); + + if (wins_is_current(window)) { + wins_refresh_current(); + ui_current_page_off(); + } + } + + free(display_str); +} + +static void +_ui_chat_win_contact_offline(PContact contact, char *resource, char *status) +{ + char *display_str = p_contact_create_display_string(contact, resource); + const char *barejid = p_contact_barejid(contact); + + ProfWin *window = wins_get_by_recipient(barejid); + if (window != NULL) { + win_show_status_string(window, display_str, "offline", status, NULL, "--", + "offline"); + + if (wins_is_current(window)) { + wins_refresh_current(); + ui_current_page_off(); + } + } + + free(display_str); +} + static void _ui_draw_win_title(void) { @@ -1680,8 +1667,6 @@ ui_init_module(void) ui_group_added = _ui_group_added; ui_group_removed = _ui_group_removed; ui_handle_error_message = _ui_handle_error_message; - ui_contact_online = _ui_contact_online; - ui_contact_offline = _ui_contact_offline; ui_disconnected = _ui_disconnected; ui_handle_special_keys = _ui_handle_special_keys; ui_close_connected_win = _ui_close_connected_win; @@ -1736,4 +1721,6 @@ ui_init_module(void) ui_gone_insecure = _ui_gone_insecure; ui_trust = _ui_trust; ui_untrust = _ui_untrust; + ui_chat_win_contact_online = _ui_chat_win_contact_online; + ui_chat_win_contact_offline = _ui_chat_win_contact_offline; } diff --git a/src/ui/ui.h b/src/ui/ui.h index 83a347e6..a85ff4af 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -100,10 +100,6 @@ char * (*ui_ask_password)(void); void (*ui_contact_typing)(const char * const from); void (*ui_incoming_msg)(const char * const from, const char * const message, GTimeVal *tv_stamp, gboolean priv); -void (*ui_contact_online)(const char * const barejid, const char * const resource, - const char * const show, const char * const status, GDateTime *last_activity); -void (*ui_contact_offline)(const char * const from, const char * const show, - const char * const status); void (*ui_disconnected)(void); void (*ui_recipient_gone)(const char * const barejid); void (*ui_outgoing_msg)(const char * const from, const char * const to, @@ -132,6 +128,8 @@ void (*ui_contact_already_in_group)(const char * const contact, const char * con void (*ui_contact_not_in_group)(const char * const contact, const char * const group); void (*ui_group_added)(const char * const contact, const char * const group); void (*ui_group_removed)(const char * const contact, const char * const group); +void (*ui_chat_win_contact_online)(PContact contact, Resource *resource, GDateTime *last_activity); +void (*ui_chat_win_contact_offline)(PContact contact, char *resource, char *status); // contact status functions void (*ui_status_room)(const char * const contact); @@ -228,6 +226,8 @@ void (*cons_reconnect_setting)(void); void (*cons_autoping_setting)(void); void (*cons_priority_setting)(void); void (*cons_autoconnect_setting)(void); +void (*cons_show_contact_online)(PContact contact, Resource *resource, GDateTime *last_activity); +void (*cons_show_contact_offline)(PContact contact, char *resource, char *status); // status bar actions void (*status_bar_refresh)(void); diff --git a/tests/config/helpers.c b/tests/config/helpers.c new file mode 100644 index 00000000..9068546a --- /dev/null +++ b/tests/config/helpers.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "common.h" +#include "config/preferences.h" + +void create_config_file(void **state) +{ + setenv("XDG_CONFIG_HOME", "./tests/files/xdg_config_home", 1); + gchar *xdg_config = xdg_get_config_home(); + + GString *profanity_dir = g_string_new(xdg_config); + g_string_append(profanity_dir, "/profanity"); + + if (!mkdir_recursive(profanity_dir->str)) { + assert_true(FALSE); + } + g_string_free(profanity_dir, TRUE); + + fopen("./tests/files/xdg_config_home/profanity/profrc", "ab+"); + + g_free(xdg_config); + + prefs_load(); +} + +void delete_config_file(void **state) +{ + prefs_close(); + remove("./tests/files/xdg_config_home/profanity/profrc"); + rmdir("./tests/files/xdg_config_home/profanity"); + rmdir("./tests/files/xdg_config_home"); + rmdir("./tests/files"); +} diff --git a/tests/config/helpers.h b/tests/config/helpers.h new file mode 100644 index 00000000..4f46ad3f --- /dev/null +++ b/tests/config/helpers.h @@ -0,0 +1,2 @@ +void create_config_file(void **state); +void delete_config_file(void **state); diff --git a/tests/test_cmd_statuses.c b/tests/test_cmd_statuses.c new file mode 100644 index 00000000..04380724 --- /dev/null +++ b/tests/test_cmd_statuses.c @@ -0,0 +1,217 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "config/preferences.h" + +#include "ui/ui.h" +#include "ui/mock_ui.h" + +#include "command/commands.h" + +void cmd_statuses_shows_usage_when_bad_subcmd(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "badcmd", NULL }; + + expect_cons_show("Usage: some usage"); + + gboolean result = cmd_statuses(args, *help); + assert_true(result); + + free(help); +} + +void cmd_statuses_shows_usage_when_bad_console_setting(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "console", "badsetting", NULL }; + + expect_cons_show("Usage: some usage"); + + gboolean result = cmd_statuses(args, *help); + assert_true(result); + + free(help); +} + +void cmd_statuses_shows_usage_when_bad_chat_setting(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "chat", "badsetting", NULL }; + + expect_cons_show("Usage: some usage"); + + gboolean result = cmd_statuses(args, *help); + assert_true(result); + + free(help); +} + +void cmd_statuses_shows_usage_when_bad_muc_setting(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "muc", "badsetting", NULL }; + + expect_cons_show("Usage: some usage"); + + gboolean result = cmd_statuses(args, *help); + assert_true(result); + + free(help); +} + +void cmd_statuses_console_sets_all(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "console", "all", NULL }; + + expect_cons_show("All presence updates will appear in the console."); + + gboolean result = cmd_statuses(args, *help); + + char *setting = prefs_get_string(PREF_STATUSES_CONSOLE); + assert_non_null(setting); + assert_string_equal("all", setting); + assert_true(result); + + free(help); +} + +void cmd_statuses_console_sets_online(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "console", "online", NULL }; + + expect_cons_show("Only online/offline presence updates will appear in the console."); + + gboolean result = cmd_statuses(args, *help); + + char *setting = prefs_get_string(PREF_STATUSES_CONSOLE); + assert_non_null(setting); + assert_string_equal("online", setting); + assert_true(result); + + free(help); +} + +void cmd_statuses_console_sets_none(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "console", "none", NULL }; + + expect_cons_show("Presence updates will not appear in the console."); + + gboolean result = cmd_statuses(args, *help); + + char *setting = prefs_get_string(PREF_STATUSES_CONSOLE); + assert_non_null(setting); + assert_string_equal("none", setting); + assert_true(result); + + free(help); +} + +void cmd_statuses_chat_sets_all(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "chat", "all", NULL }; + + expect_cons_show("All presence updates will appear in chat windows."); + + gboolean result = cmd_statuses(args, *help); + + char *setting = prefs_get_string(PREF_STATUSES_CHAT); + assert_non_null(setting); + assert_string_equal("all", setting); + assert_true(result); + + free(help); +} + +void cmd_statuses_chat_sets_online(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "chat", "online", NULL }; + + expect_cons_show("Only online/offline presence updates will appear in chat windows."); + + gboolean result = cmd_statuses(args, *help); + + char *setting = prefs_get_string(PREF_STATUSES_CHAT); + assert_non_null(setting); + assert_string_equal("online", setting); + assert_true(result); + + free(help); +} + +void cmd_statuses_chat_sets_none(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "chat", "none", NULL }; + + expect_cons_show("Presence updates will not appear in chat windows."); + + gboolean result = cmd_statuses(args, *help); + + char *setting = prefs_get_string(PREF_STATUSES_CHAT); + assert_non_null(setting); + assert_string_equal("none", setting); + assert_true(result); + + free(help); +} + +void cmd_statuses_muc_sets_on(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "muc", "on", NULL }; + + expect_cons_show("Chat room presence updates enabled."); + + gboolean result = cmd_statuses(args, *help); + + gboolean setting = prefs_get_boolean(PREF_STATUSES_MUC); + assert_non_null(setting); + assert_true(setting); + assert_true(result); + + free(help); +} + +void cmd_statuses_muc_sets_off(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "muc", "off", NULL }; + + expect_cons_show("Chat room presence updates disabled."); + + gboolean result = cmd_statuses(args, *help); + + gboolean setting = prefs_get_boolean(PREF_STATUSES_MUC); + assert_false(setting); + assert_true(result); + + free(help); +} diff --git a/tests/test_cmd_statuses.h b/tests/test_cmd_statuses.h new file mode 100644 index 00000000..69f935f0 --- /dev/null +++ b/tests/test_cmd_statuses.h @@ -0,0 +1,12 @@ +void cmd_statuses_shows_usage_when_bad_subcmd(void **state); +void cmd_statuses_shows_usage_when_bad_console_setting(void **state); +void cmd_statuses_shows_usage_when_bad_chat_setting(void **state); +void cmd_statuses_shows_usage_when_bad_muc_setting(void **state); +void cmd_statuses_console_sets_all(void **state); +void cmd_statuses_console_sets_online(void **state); +void cmd_statuses_console_sets_none(void **state); +void cmd_statuses_chat_sets_all(void **state); +void cmd_statuses_chat_sets_online(void **state); +void cmd_statuses_chat_sets_none(void **state); +void cmd_statuses_muc_sets_on(void **state); +void cmd_statuses_muc_sets_off(void **state); diff --git a/tests/test_preferences.c b/tests/test_preferences.c new file mode 100644 index 00000000..41e254cc --- /dev/null +++ b/tests/test_preferences.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "config/preferences.h" + +void statuses_console_defaults_to_all(void **state) +{ + char *setting = prefs_get_string(PREF_STATUSES_CONSOLE); + + assert_non_null(setting); + assert_string_equal("all", setting); +} + +void statuses_chat_defaults_to_all(void **state) +{ + char *setting = prefs_get_string(PREF_STATUSES_CHAT); + + assert_non_null(setting); + assert_string_equal("all", setting); +} + +void statuses_muc_defaults_to_on(void **state) +{ + gboolean setting = prefs_get_boolean(PREF_STATUSES_MUC); + + assert_true(setting); +} diff --git a/tests/test_preferences.h b/tests/test_preferences.h new file mode 100644 index 00000000..577226b7 --- /dev/null +++ b/tests/test_preferences.h @@ -0,0 +1,3 @@ +void statuses_console_defaults_to_all(void **state); +void statuses_chat_defaults_to_all(void **state); +void statuses_muc_defaults_to_on(void **state); diff --git a/tests/test_server_events.c b/tests/test_server_events.c new file mode 100644 index 00000000..f800f4dc --- /dev/null +++ b/tests/test_server_events.c @@ -0,0 +1,106 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "server_events.h" +#include "roster_list.h" +#include "config/preferences.h" +#include "ui/ui.h" +#include "ui/mock_ui.h" + +void console_doesnt_show_online_presence_when_set_none(void **state) +{ + mock_cons_show_contact_online(); + stub_ui_chat_win_contact_online(); + prefs_set_string(PREF_STATUSES_CONSOLE, "none"); + roster_init(); + roster_add("test1@server", "bob", NULL, "both", FALSE); + Resource *resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10, "caps"); + + handle_contact_online("test1@server", resource, NULL); + + roster_clear(); +} + +void console_shows_online_presence_when_set_online(void **state) +{ + mock_cons_show_contact_online(); + stub_ui_chat_win_contact_online(); + prefs_set_string(PREF_STATUSES_CONSOLE, "online"); + roster_init(); + roster_add("test1@server", "bob", NULL, "both", FALSE); + Resource *resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10, "caps"); + PContact contact = roster_get_contact("test1@server"); + + expect_cons_show_contact_online(contact, resource, NULL); + + handle_contact_online("test1@server", resource, NULL); + + roster_clear(); +} + +void console_shows_online_presence_when_set_all(void **state) +{ + mock_cons_show_contact_online(); + stub_ui_chat_win_contact_online(); + prefs_set_string(PREF_STATUSES_CONSOLE, "all"); + roster_init(); + roster_add("test1@server", "bob", NULL, "both", FALSE); + Resource *resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10, "caps"); + PContact contact = roster_get_contact("test1@server"); + + expect_cons_show_contact_online(contact, resource, NULL); + + handle_contact_online("test1@server", resource, NULL); + + roster_clear(); +} + +void console_doesnt_show_dnd_presence_when_set_none(void **state) +{ + mock_cons_show_contact_online(); + stub_ui_chat_win_contact_online(); + prefs_set_string(PREF_STATUSES_CONSOLE, "none"); + roster_init(); + roster_add("test1@server", "bob", NULL, "both", FALSE); + Resource *resource = resource_new("resource", RESOURCE_DND, NULL, 10, "caps"); + + handle_contact_online("test1@server", resource, NULL); + + roster_clear(); +} + +void console_doesnt_show_dnd_presence_when_set_online(void **state) +{ + mock_cons_show_contact_online(); + stub_ui_chat_win_contact_online(); + prefs_set_string(PREF_STATUSES_CONSOLE, "online"); + roster_init(); + roster_add("test1@server", "bob", NULL, "both", FALSE); + Resource *resource = resource_new("resource", RESOURCE_DND, NULL, 10, "caps"); + + handle_contact_online("test1@server", resource, NULL); + + roster_clear(); +} + +void console_shows_dnd_presence_when_set_all(void **state) +{ + mock_cons_show_contact_online(); + stub_ui_chat_win_contact_online(); + prefs_set_string(PREF_STATUSES_CONSOLE, "all"); + roster_init(); + roster_add("test1@server", "bob", NULL, "both", FALSE); + Resource *resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10, "caps"); + PContact contact = roster_get_contact("test1@server"); + + expect_cons_show_contact_online(contact, resource, NULL); + + handle_contact_online("test1@server", resource, NULL); + + roster_clear(); +} diff --git a/tests/test_server_events.h b/tests/test_server_events.h new file mode 100644 index 00000000..b6774456 --- /dev/null +++ b/tests/test_server_events.h @@ -0,0 +1,6 @@ +void console_doesnt_show_online_presence_when_set_none(void **state); +void console_shows_online_presence_when_set_online(void **state); +void console_shows_online_presence_when_set_all(void **state); +void console_doesnt_show_dnd_presence_when_set_none(void **state); +void console_doesnt_show_dnd_presence_when_set_online(void **state); +void console_shows_dnd_presence_when_set_all(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index ade951e1..3a61e9f5 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -1,8 +1,12 @@ #include +#include +#include +#include #include #include #include +#include "config/helpers.h" #include "test_autocomplete.h" #include "test_common.h" #include "test_contact.h" @@ -10,13 +14,20 @@ #include "test_cmd_account.h" #include "test_cmd_rooms.h" #include "test_cmd_sub.h" +#include "test_cmd_statuses.h" #include "test_history.h" #include "test_jid.h" #include "test_parser.h" #include "test_roster_list.h" +#include "test_preferences.h" +#include "test_server_events.h" + +#define PROF_RUN_TESTS(name) fprintf(stderr, "\n-> Running %s\n", #name); \ + fflush(stderr); \ + result += run_tests(name); int main(int argc, char* argv[]) { - const UnitTest tests[] = { + const UnitTest common_tests[] = { unit_test(replace_one_substr), unit_test(replace_one_substr_beginning), unit_test(replace_one_substr_end), @@ -57,7 +68,9 @@ int main(int argc, char* argv[]) { unit_test(test_available_is_not_valid_resource_presence_string), unit_test(test_unavailable_is_not_valid_resource_presence_string), unit_test(test_blah_is_not_valid_resource_presence_string), + }; + const UnitTest autocomplete_tests[] = { unit_test(clear_empty), unit_test(reset_after_create), unit_test(find_after_create), @@ -68,7 +81,9 @@ int main(int argc, char* argv[]) { unit_test(add_two_adds_two), unit_test(add_two_same_adds_one), unit_test(add_two_same_updates), + }; + const UnitTest history_tests[] = { unit_test(previous_on_empty_returns_null), unit_test(next_on_empty_returns_null), unit_test(previous_once_returns_last), @@ -82,7 +97,9 @@ int main(int argc, char* argv[]) { unit_test(edit_item_mid_history), unit_test(edit_previous_and_append), unit_test(start_session_add_new_submit_previous), + }; + const UnitTest jid_tests[] = { unit_test(create_jid_from_null_returns_null), unit_test(create_jid_from_empty_string_returns_null), unit_test(create_jid_from_full_returns_full), @@ -106,7 +123,9 @@ int main(int argc, char* argv[]) { unit_test(create_with_at_in_resource), unit_test(create_with_at_and_slash_in_resource), unit_test(create_full_with_trailing_slash), + }; + const UnitTest parser_tests[] = { unit_test(parse_null_returns_null), unit_test(parse_empty_returns_null), unit_test(parse_space_returns_null), @@ -148,7 +167,9 @@ int main(int argc, char* argv[]) { unit_test(get_first_two_of_three_first_quoted), unit_test(get_first_two_of_three_second_quoted), unit_test(get_first_two_of_three_first_and_second_quoted), + }; + const UnitTest roster_list_tests[] = { unit_test(empty_list_when_none_added), unit_test(contains_one_element), unit_test(first_element_correct), @@ -167,7 +188,9 @@ int main(int argc, char* argv[]) { unit_test(find_twice_returns_second_when_two_match), unit_test(find_five_times_finds_fifth), unit_test(find_twice_returns_first_when_two_match_and_reset), + }; + const UnitTest cmd_connect_tests[] = { unit_test(cmd_connect_shows_message_when_disconnecting), unit_test(cmd_connect_shows_message_when_connecting), unit_test(cmd_connect_shows_message_when_connected), @@ -194,7 +217,9 @@ int main(int argc, char* argv[]) { unit_test(cmd_connect_shows_usage_when_port_provided_twice), unit_test(cmd_connect_shows_usage_when_invalid_first_property), unit_test(cmd_connect_shows_usage_when_invalid_second_property), + }; + const UnitTest cmd_rooms_tests[] = { unit_test(cmd_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), unit_test(cmd_rooms_shows_message_when_connecting), @@ -202,7 +227,9 @@ int main(int argc, char* argv[]) { unit_test(cmd_rooms_shows_message_when_undefined), unit_test(cmd_rooms_uses_account_default_when_no_arg), unit_test(cmd_rooms_arg_used_when_passed), + }; + const UnitTest cmd_account_tests[] = { unit_test(cmd_account_shows_usage_when_not_connected_and_no_args), unit_test(cmd_account_shows_account_when_connected_and_no_args), unit_test(cmd_account_list_shows_accounts), @@ -266,10 +293,14 @@ int main(int argc, char* argv[]) { unit_test(cmd_account_clear_checks_account_exists), unit_test(cmd_account_clear_shows_message_when_account_doesnt_exist), unit_test(cmd_account_clear_shows_message_when_invalid_property), + }; + const UnitTest cmd_sub_tests[] = { unit_test(cmd_sub_shows_message_when_not_connected), unit_test(cmd_sub_shows_usage_when_no_arg), + }; + const UnitTest contact_tests[] = { unit_test(contact_in_group), unit_test(contact_not_in_group), unit_test(contact_name_when_name_exists), @@ -294,7 +325,102 @@ int main(int argc, char* argv[]) { unit_test(contact_not_available_when_highest_priority_dnd), unit_test(contact_available_when_highest_priority_online), unit_test(contact_available_when_highest_priority_chat), - }; - return run_tests(tests); + + const UnitTest cmd_statuses_tests[] = { + unit_test(cmd_statuses_shows_usage_when_bad_subcmd), + unit_test(cmd_statuses_shows_usage_when_bad_console_setting), + unit_test(cmd_statuses_shows_usage_when_bad_chat_setting), + unit_test(cmd_statuses_shows_usage_when_bad_muc_setting), + unit_test_setup_teardown(cmd_statuses_console_sets_all, + create_config_file, + delete_config_file), + unit_test_setup_teardown(cmd_statuses_console_sets_online, + create_config_file, + delete_config_file), + unit_test_setup_teardown(cmd_statuses_console_sets_none, + create_config_file, + delete_config_file), + unit_test_setup_teardown(cmd_statuses_chat_sets_all, + create_config_file, + delete_config_file), + unit_test_setup_teardown(cmd_statuses_chat_sets_online, + create_config_file, + delete_config_file), + unit_test_setup_teardown(cmd_statuses_chat_sets_none, + create_config_file, + delete_config_file), + unit_test_setup_teardown(cmd_statuses_muc_sets_on, + create_config_file, + delete_config_file), + unit_test_setup_teardown(cmd_statuses_muc_sets_off, + create_config_file, + delete_config_file), + }; + + const UnitTest preferences_tests[] = { + unit_test_setup_teardown(statuses_console_defaults_to_all, + create_config_file, + delete_config_file), + unit_test_setup_teardown(statuses_chat_defaults_to_all, + create_config_file, + delete_config_file), + unit_test_setup_teardown(statuses_muc_defaults_to_on, + create_config_file, + delete_config_file), + }; + + const UnitTest server_events_tests[] = { + unit_test_setup_teardown(console_doesnt_show_online_presence_when_set_none, + create_config_file, + delete_config_file), + unit_test_setup_teardown(console_shows_online_presence_when_set_online, + create_config_file, + delete_config_file), + unit_test_setup_teardown(console_shows_online_presence_when_set_all, + create_config_file, + delete_config_file), + unit_test_setup_teardown(console_doesnt_show_dnd_presence_when_set_none, + create_config_file, + delete_config_file), + unit_test_setup_teardown(console_doesnt_show_dnd_presence_when_set_online, + create_config_file, + delete_config_file), +// unit_test_setup_teardown(console_shows_dnd_presence_when_set_all, +// create_config_file, +// delete_config_file), + }; + + int bak, new; + fflush(stdout); + bak = dup(1); + new = open("/dev/null", O_WRONLY); + dup2(new, 1); + close(new); + + int result = 0; + + PROF_RUN_TESTS(common_tests); + PROF_RUN_TESTS(autocomplete_tests); + PROF_RUN_TESTS(history_tests); + PROF_RUN_TESTS(jid_tests); + PROF_RUN_TESTS(parser_tests); + PROF_RUN_TESTS(roster_list_tests); + PROF_RUN_TESTS(cmd_connect_tests); + PROF_RUN_TESTS(cmd_rooms_tests); + PROF_RUN_TESTS(cmd_account_tests); + PROF_RUN_TESTS(cmd_sub_tests); + PROF_RUN_TESTS(contact_tests); + PROF_RUN_TESTS(cmd_statuses_tests); + PROF_RUN_TESTS(preferences_tests); + PROF_RUN_TESTS(server_events_tests); + + fflush(stdout); + dup2(bak, 1); + close(bak); + if (result > 0) { + return 1; + } else { + return 0; + } } diff --git a/tests/ui/mock_ui.c b/tests/ui/mock_ui.c index 83119910..cd6c62ff 100644 --- a/tests/ui/mock_ui.c +++ b/tests/ui/mock_ui.c @@ -44,6 +44,14 @@ void _stub_cons_show(const char * const msg, ...) { } +static +void _mock_cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity) +{ + check_expected(contact); + check_expected(resource); + check_expected(last_activity); +} + static void _mock_cons_show_error(const char * const msg, ...) { @@ -78,6 +86,11 @@ char * _stub_ui_ask_password(void) return NULL; } +static +void _stub_ui_chat_win_contact_online(PContact contact, Resource *resource, GDateTime *last_activity) +{ +} + void mock_cons_show(void) { @@ -85,6 +98,18 @@ mock_cons_show(void) } +void +mock_cons_show_contact_online(void) +{ + cons_show_contact_online = _mock_cons_show_contact_online; +} + +void +stub_ui_chat_win_contact_online(void) +{ + ui_chat_win_contact_online = _stub_ui_chat_win_contact_online; +} + void mock_cons_show_error(void) { @@ -152,6 +177,18 @@ expect_cons_show_account_list(gchar **accounts) expect_memory(_mock_cons_show_account_list, accounts, accounts, sizeof(accounts)); } +void +expect_cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity) +{ + expect_memory(_mock_cons_show_contact_online, contact, contact, sizeof(contact)); + expect_memory(_mock_cons_show_contact_online, resource, resource, sizeof(Resource)); + if (last_activity == NULL) { + expect_any(_mock_cons_show_contact_online, last_activity); + } else { + expect_memory(_mock_cons_show_contact_online, last_activity, last_activity, sizeof(last_activity)); + } +} + void mock_ui_ask_password_returns(char *password) { diff --git a/tests/ui/mock_ui.h b/tests/ui/mock_ui.h index 2833be29..6f6d34d7 100644 --- a/tests/ui/mock_ui.h +++ b/tests/ui/mock_ui.h @@ -11,6 +11,10 @@ void mock_cons_show(void); void expect_cons_show(char *output); void expect_cons_show_calls(int n); +void mock_cons_show_contact_online(void); +void expect_cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity); +void stub_ui_chat_win_contact_online(void); + void mock_cons_show_error(void); void expect_cons_show_error(char *output);