mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Added tests for setting presence priorities
This commit is contained in:
parent
ba66d6b730
commit
f47bd58a1c
@ -259,11 +259,16 @@ cmd_account(gchar **args, struct cmd_help_t help)
|
||||
accounts_set_priority_dnd(account_name, intval);
|
||||
break;
|
||||
}
|
||||
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
resource_presence_t last_presence = accounts_get_last_presence(jabber_get_account_name());
|
||||
if (conn_status == JABBER_CONNECTED && presence_type == last_presence) {
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
char *connected_account = jabber_get_account_name();
|
||||
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);
|
||||
}
|
||||
}
|
||||
cons_show("Updated %s priority for account %s: %s", property, account_name, value);
|
||||
cons_show("");
|
||||
}
|
||||
|
@ -143,11 +143,36 @@ resource_presence_t accounts_get_last_presence(const char * const account_name)
|
||||
return (resource_presence_t)mock();
|
||||
}
|
||||
|
||||
void accounts_set_priority_online(const char * const account_name, const gint value) {}
|
||||
void accounts_set_priority_chat(const char * const account_name, const gint value) {}
|
||||
void accounts_set_priority_away(const char * const account_name, const gint value) {}
|
||||
void accounts_set_priority_xa(const char * const account_name, const gint value) {}
|
||||
void accounts_set_priority_dnd(const char * const account_name, const gint value) {}
|
||||
void accounts_set_priority_online(const char * const account_name, const gint value)
|
||||
{
|
||||
check_expected(account_name);
|
||||
check_expected(value);
|
||||
}
|
||||
|
||||
void accounts_set_priority_chat(const char * const account_name, const gint value)
|
||||
{
|
||||
check_expected(account_name);
|
||||
check_expected(value);
|
||||
}
|
||||
|
||||
void accounts_set_priority_away(const char * const account_name, const gint value)
|
||||
{
|
||||
check_expected(account_name);
|
||||
check_expected(value);
|
||||
}
|
||||
|
||||
void accounts_set_priority_xa(const char * const account_name, const gint value)
|
||||
{
|
||||
check_expected(account_name);
|
||||
check_expected(value);
|
||||
}
|
||||
|
||||
void accounts_set_priority_dnd(const char * const account_name, const gint value)
|
||||
{
|
||||
check_expected(account_name);
|
||||
check_expected(value);
|
||||
}
|
||||
|
||||
void accounts_set_priority_all(const char * const account_name, const gint value) {}
|
||||
|
||||
gint accounts_get_priority_for_presence_type(const char * const account_name,
|
||||
|
@ -839,3 +839,114 @@ void cmd_account_set_last_priority_shows_message(void **state)
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_account_set_online_priority_sets_preference(void **state)
|
||||
{
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "set", "a_account", "online", "10", NULL };
|
||||
|
||||
expect_any(accounts_account_exists, account_name);
|
||||
will_return(accounts_account_exists, TRUE);
|
||||
|
||||
expect_string(accounts_set_priority_online, account_name, "a_account");
|
||||
expect_value(accounts_set_priority_online, value, 10);
|
||||
|
||||
will_return(jabber_get_connection_status, JABBER_DISCONNECTED);
|
||||
|
||||
expect_any_count(cons_show, output, 2);
|
||||
|
||||
gboolean result = cmd_account(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_account_set_chat_priority_sets_preference(void **state)
|
||||
{
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "set", "a_account", "chat", "10", NULL };
|
||||
|
||||
expect_any(accounts_account_exists, account_name);
|
||||
will_return(accounts_account_exists, TRUE);
|
||||
|
||||
expect_string(accounts_set_priority_chat, account_name, "a_account");
|
||||
expect_value(accounts_set_priority_chat, value, 10);
|
||||
|
||||
will_return(jabber_get_connection_status, JABBER_DISCONNECTED);
|
||||
|
||||
expect_any_count(cons_show, output, 2);
|
||||
|
||||
gboolean result = cmd_account(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_account_set_away_priority_sets_preference(void **state)
|
||||
{
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "set", "a_account", "away", "10", NULL };
|
||||
|
||||
expect_any(accounts_account_exists, account_name);
|
||||
will_return(accounts_account_exists, TRUE);
|
||||
|
||||
expect_string(accounts_set_priority_away, account_name, "a_account");
|
||||
expect_value(accounts_set_priority_away, value, 10);
|
||||
|
||||
will_return(jabber_get_connection_status, JABBER_DISCONNECTED);
|
||||
|
||||
expect_any_count(cons_show, output, 2);
|
||||
|
||||
gboolean result = cmd_account(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_account_set_xa_priority_sets_preference(void **state)
|
||||
{
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "set", "a_account", "xa", "10", NULL };
|
||||
|
||||
expect_any(accounts_account_exists, account_name);
|
||||
will_return(accounts_account_exists, TRUE);
|
||||
|
||||
expect_string(accounts_set_priority_xa, account_name, "a_account");
|
||||
expect_value(accounts_set_priority_xa, value, 10);
|
||||
|
||||
will_return(jabber_get_connection_status, JABBER_DISCONNECTED);
|
||||
|
||||
expect_any_count(cons_show, output, 2);
|
||||
|
||||
gboolean result = cmd_account(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_account_set_dnd_priority_sets_preference(void **state)
|
||||
{
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "set", "a_account", "dnd", "10", NULL };
|
||||
|
||||
expect_any(accounts_account_exists, account_name);
|
||||
will_return(accounts_account_exists, TRUE);
|
||||
|
||||
expect_string(accounts_set_priority_dnd, account_name, "a_account");
|
||||
expect_value(accounts_set_priority_dnd, value, 10);
|
||||
|
||||
will_return(jabber_get_connection_status, JABBER_DISCONNECTED);
|
||||
|
||||
expect_any_count(cons_show, output, 2);
|
||||
|
||||
gboolean result = cmd_account(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
// test message shown when set
|
||||
// test invalid priority low
|
||||
// test invalid priority high
|
||||
// test presence updated when connected as account and current presence equals setting
|
||||
|
||||
|
@ -45,3 +45,8 @@ void cmd_account_set_status_shows_message_when_set_valid(void **state);
|
||||
void cmd_account_set_status_shows_message_when_set_last(void **state);
|
||||
void cmd_account_set_invalid_presence_string_priority_shows_message(void **state);
|
||||
void cmd_account_set_last_priority_shows_message(void **state);
|
||||
void cmd_account_set_online_priority_sets_preference(void **state);
|
||||
void cmd_account_set_chat_priority_sets_preference(void **state);
|
||||
void cmd_account_set_away_priority_sets_preference(void **state);
|
||||
void cmd_account_set_xa_priority_sets_preference(void **state);
|
||||
void cmd_account_set_dnd_priority_sets_preference(void **state);
|
||||
|
@ -236,6 +236,11 @@ int main(int argc, char* argv[]) {
|
||||
unit_test(cmd_account_set_status_shows_message_when_set_last),
|
||||
unit_test(cmd_account_set_invalid_presence_string_priority_shows_message),
|
||||
unit_test(cmd_account_set_last_priority_shows_message),
|
||||
unit_test(cmd_account_set_online_priority_sets_preference),
|
||||
unit_test(cmd_account_set_chat_priority_sets_preference),
|
||||
unit_test(cmd_account_set_away_priority_sets_preference),
|
||||
unit_test(cmd_account_set_xa_priority_sets_preference),
|
||||
unit_test(cmd_account_set_dnd_priority_sets_preference),
|
||||
};
|
||||
return run_tests(tests);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user