diff --git a/src/command/commands.c b/src/command/commands.c index 67458c79..1797c7ed 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2310,11 +2310,11 @@ _strtoi(char *str, int *saveptr, int min, int max) errno = 0; val = (int)strtol(str, &ptr, 0); - if (*str == '\0' || *ptr != '\0') { - cons_show("Illegal character. Must be a number."); + if (errno != 0 || *str == '\0' || *ptr != '\0') { + cons_show("Could not convert \"%s\" to a number.", str); return -1; - } else if (errno == ERANGE || val < min || val > max) { - cons_show("Value out of range. Must be in %d..%d.", min, max); + } else if (val < min || val > max) { + cons_show("Value %s out of range. Must be in %d..%d.", str, min, max); return -1; } diff --git a/tests/test_cmd_account.c b/tests/test_cmd_account.c index c0cceae6..da1bc0f5 100644 --- a/tests/test_cmd_account.c +++ b/tests/test_cmd_account.c @@ -966,10 +966,9 @@ void cmd_account_set_online_priority_shows_message(void **state) assert_true(result); 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(); 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); - 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); assert_true(result); 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(); 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); - 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); assert_true(result); 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 diff --git a/tests/test_cmd_account.h b/tests/test_cmd_account.h index 9377cf08..7ff9970a 100644 --- a/tests/test_cmd_account.h +++ b/tests/test_cmd_account.h @@ -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_dnd_priority_sets_preference(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_does_not_set_priority_when_too_high(void **state); +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); diff --git a/tests/testsuite.c b/tests/testsuite.c index 30d53ffa..843a5981 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -242,8 +242,10 @@ int main(int argc, char* argv[]) { unit_test(cmd_account_set_xa_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_does_not_set_priority_when_too_low), - unit_test(cmd_account_does_not_set_priority_when_too_high), + unit_test(cmd_account_set_priority_too_low_shows_message), + 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); }