1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Test for presence update when changing priority

This commit is contained in:
James Booth 2013-12-27 14:17:24 +00:00
parent 7a63cf2e22
commit 6d6bc67d5c
8 changed files with 91 additions and 2 deletions

View File

@ -266,7 +266,8 @@ cmd_account(gchar **args, struct cmd_help_t help)
resource_presence_t last_presence = accounts_get_last_presence(connected_account);
if (presence_type == last_presence) {
presence_update(last_presence, jabber_get_presence_message(), 0);
char *message = jabber_get_presence_message();
presence_update(last_presence, message, 0);
}
}
cons_show("Updated %s priority for account %s: %s", property, account_name, value);

View File

@ -256,6 +256,14 @@ _mock_accounts_set_login_presence(const char * const account_name, const char *
static void
_stub_accounts_set_login_presence(const char * const account_name, const char * const value)
{
// do nothing
}
static resource_presence_t
_mock_accounts_get_last_presence(const char * const account_name)
{
check_expected(account_name);
return (resource_presence_t)mock();
}
// set up functions
@ -430,6 +438,12 @@ stub_accounts_set_login_presence(void)
accounts_set_login_presence = _stub_accounts_set_login_presence;
}
void
mock_accounts_get_last_presence(void)
{
accounts_get_last_presence = _mock_accounts_get_last_presence;
}
// mock behaviours
void
@ -617,3 +631,10 @@ accounts_set_login_presence_expect(char *account_name, char *presence)
expect_string(_mock_accounts_set_login_presence, account_name, account_name);
expect_string(_mock_accounts_set_login_presence, value, presence);
}
void
accounts_get_last_presence_return(resource_presence_t presence)
{
expect_any(_mock_accounts_get_last_presence, account_name);
will_return(_mock_accounts_get_last_presence, presence);
}

View File

@ -89,3 +89,6 @@ void accounts_set_priority_dnd_expect(char *account_name, gint priority);
void mock_accounts_set_login_presence(void);
void stub_accounts_set_login_presence(void);
void accounts_set_login_presence_expect(char *account_name, char *presence);
void mock_accounts_get_last_presence(void);
void accounts_get_last_presence_return(resource_presence_t presence);

View File

@ -1032,5 +1032,28 @@ void cmd_account_set_priority_when_empty_shows_message(void **state)
free(help);
}
// test presence updated when connected as account and current presence equals setting
void cmd_account_set_priority_updates_presence_when_account_connected_with_presence(void **state)
{
stub_cons_show();
stub_accounts_set_priorities();
mock_accounts_get_last_presence();
mock_presence_update();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "set", "a_account", "online", "10", NULL };
accounts_account_exists_return(TRUE);
mock_connection_status(JABBER_CONNECTED);
mock_connection_account_name("a_account");
accounts_get_last_presence_return(RESOURCE_ONLINE);
mock_connection_presence_message("Free to chat");
presence_update_expect(RESOURCE_ONLINE, "Free to chat", 0);
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}

View File

@ -55,3 +55,4 @@ void cmd_account_set_priority_too_low_shows_message(void **state);
void cmd_account_set_priority_too_high_shows_message(void **state);
void cmd_account_set_priority_when_not_number_shows_message(void **state);
void cmd_account_set_priority_when_empty_shows_message(void **state);
void cmd_account_set_priority_updates_presence_when_account_connected_with_presence(void **state);

View File

@ -246,6 +246,7 @@ int main(int argc, char* argv[]) {
unit_test(cmd_account_set_priority_too_high_shows_message),
unit_test(cmd_account_set_priority_when_not_number_shows_message),
unit_test(cmd_account_set_priority_when_empty_shows_message),
unit_test(cmd_account_set_priority_updates_presence_when_account_connected_with_presence),
};
return run_tests(tests);
}

View File

@ -43,6 +43,20 @@ _mock_jabber_connect_with_account(const ProfAccount * const account)
return (jabber_conn_status_t)mock();
}
static char *
_mock_jabber_get_presence_message(void)
{
return (char *)mock();
}
static void
_mock_presence_update(resource_presence_t status, const char * const msg, int idle)
{
check_expected(status);
check_expected(msg);
check_expected(idle);
}
void
mock_jabber_connect_with_details(void)
{
@ -55,6 +69,12 @@ mock_jabber_connect_with_account(void)
jabber_connect_with_account = _mock_jabber_connect_with_account;
}
void
mock_presence_update(void)
{
presence_update = _mock_presence_update;
}
void
mock_connection_status(jabber_conn_status_t status)
{
@ -69,6 +89,13 @@ mock_connection_account_name(char *name)
will_return(_mock_jabber_get_account_name, name);
}
void
mock_connection_presence_message(char *message)
{
jabber_get_presence_message = _mock_jabber_get_presence_message;
will_return(_mock_jabber_get_presence_message, message);
}
void
expect_room_list_request(char *conf_server)
{
@ -120,3 +147,11 @@ jabber_connect_with_account_return(ProfAccount *account,
expect_any(_mock_jabber_connect_with_account, account);
will_return(_mock_jabber_connect_with_account, result);
}
void
presence_update_expect(resource_presence_t presence, char *msg, int idle)
{
expect_value(_mock_presence_update, status, presence);
expect_string(_mock_presence_update, msg, msg);
expect_value(_mock_presence_update, idle, idle);
}

View File

@ -5,6 +5,7 @@
void mock_connection_status(jabber_conn_status_t status);
void mock_connection_account_name(char *name);
void mock_connection_presence_message(char *message);
void expect_room_list_request(char *conf_server);
void mock_jabber_connect_with_details(void);
@ -19,4 +20,7 @@ void jabber_connect_with_account_expect_and_return(ProfAccount *account,
jabber_conn_status_t result);
void jabber_connect_with_account_return(jabber_conn_status_t result);
void mock_presence_update(void);
void presence_update_expect(resource_presence_t presence, char *msg, int idle);
#endif