1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Changed messages on invalid priorities

This commit is contained in:
James Booth 2013-12-27 00:29:20 +00:00
parent 9d1b05a896
commit 7a63cf2e22
4 changed files with 46 additions and 15 deletions

View File

@ -2310,11 +2310,11 @@ _strtoi(char *str, int *saveptr, int min, int max)
errno = 0; errno = 0;
val = (int)strtol(str, &ptr, 0); val = (int)strtol(str, &ptr, 0);
if (*str == '\0' || *ptr != '\0') { if (errno != 0 || *str == '\0' || *ptr != '\0') {
cons_show("Illegal character. Must be a number."); cons_show("Could not convert \"%s\" to a number.", str);
return -1; return -1;
} else if (errno == ERANGE || val < min || val > max) { } else if (val < min || val > max) {
cons_show("Value out of range. Must be in %d..%d.", min, max); cons_show("Value %s out of range. Must be in %d..%d.", str, min, max);
return -1; return -1;
} }

View File

@ -966,10 +966,9 @@ void cmd_account_set_online_priority_shows_message(void **state)
assert_true(result); assert_true(result);
free(help); free(help);
} }
void cmd_account_does_not_set_priority_when_too_low(void **state) void cmd_account_set_priority_too_low_shows_message(void **state)
{ {
mock_cons_show(); mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp)); CommandHelp *help = malloc(sizeof(CommandHelp));
@ -977,17 +976,15 @@ void cmd_account_does_not_set_priority_when_too_low(void **state)
accounts_account_exists_return(TRUE); accounts_account_exists_return(TRUE);
expect_cons_show("Value out of range. Must be in -128..127."); expect_cons_show("Value -150 out of range. Must be in -128..127.");
gboolean result = cmd_account(args, *help); gboolean result = cmd_account(args, *help);
assert_true(result); assert_true(result);
free(help); free(help);
} }
void cmd_account_does_not_set_priority_when_too_high(void **state) void cmd_account_set_priority_too_high_shows_message(void **state)
{ {
mock_cons_show(); mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp)); CommandHelp *help = malloc(sizeof(CommandHelp));
@ -995,14 +992,44 @@ void cmd_account_does_not_set_priority_when_too_high(void **state)
accounts_account_exists_return(TRUE); accounts_account_exists_return(TRUE);
expect_cons_show("Value out of range. Must be in -128..127."); expect_cons_show("Value 150 out of range. Must be in -128..127.");
gboolean result = cmd_account(args, *help); gboolean result = cmd_account(args, *help);
assert_true(result); assert_true(result);
free(help); free(help);
}
void cmd_account_set_priority_when_not_number_shows_message(void **state)
{
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "set", "a_account", "online", "abc", NULL };
accounts_account_exists_return(TRUE);
expect_cons_show("Could not convert \"abc\" to a number.");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
}
void cmd_account_set_priority_when_empty_shows_message(void **state)
{
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "set", "a_account", "online", "", NULL };
accounts_account_exists_return(TRUE);
expect_cons_show("Could not convert \"\" to a number.");
gboolean result = cmd_account(args, *help);
assert_true(result);
free(help);
} }
// test presence updated when connected as account and current presence equals setting // test presence updated when connected as account and current presence equals setting

View File

@ -51,5 +51,7 @@ void cmd_account_set_away_priority_sets_preference(void **state);
void cmd_account_set_xa_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); void cmd_account_set_dnd_priority_sets_preference(void **state);
void cmd_account_set_online_priority_shows_message(void **state); void cmd_account_set_online_priority_shows_message(void **state);
void cmd_account_does_not_set_priority_when_too_low(void **state); void cmd_account_set_priority_too_low_shows_message(void **state);
void cmd_account_does_not_set_priority_when_too_high(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);

View File

@ -242,8 +242,10 @@ int main(int argc, char* argv[]) {
unit_test(cmd_account_set_xa_priority_sets_preference), unit_test(cmd_account_set_xa_priority_sets_preference),
unit_test(cmd_account_set_dnd_priority_sets_preference), unit_test(cmd_account_set_dnd_priority_sets_preference),
unit_test(cmd_account_set_online_priority_shows_message), unit_test(cmd_account_set_online_priority_shows_message),
unit_test(cmd_account_does_not_set_priority_when_too_low), unit_test(cmd_account_set_priority_too_low_shows_message),
unit_test(cmd_account_does_not_set_priority_when_too_high), 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),
}; };
return run_tests(tests); return run_tests(tests);
} }