diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_cmd_account.c | 49 | ||||
-rw-r--r-- | tests/test_cmd_account.h | 2 | ||||
-rw-r--r-- | tests/testsuite.c | 4 | ||||
-rw-r--r-- | tests/ui/mock_ui.c | 7 |
4 files changed, 61 insertions, 1 deletions
diff --git a/tests/test_cmd_account.c b/tests/test_cmd_account.c new file mode 100644 index 00000000..a857ca1c --- /dev/null +++ b/tests/test_cmd_account.c @@ -0,0 +1,49 @@ +#include <stdarg.h> +#include <stddef.h> +#include <setjmp.h> +#include <cmocka.h> +#include <stdlib.h> +#include <string.h> +#include <glib.h> + +#include "xmpp/xmpp.h" +#include "command/commands.h" + +void cmd_account_shows_usage_when_not_connected_and_no_args(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { NULL }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_string(cons_show, output, "Usage: some usage"); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} + +void cmd_account_shows_account_when_connected_and_no_args(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + ProfAccount *account = malloc(sizeof(ProfAccount)); + gchar *args[] = { NULL }; + + will_return(jabber_get_connection_status, JABBER_CONNECTED); + + will_return(jabber_get_account_name, "account_name"); + + expect_string(accounts_get_account, name, "account_name"); + will_return(accounts_get_account, account); + + expect_memory(cons_show_account, account, account, sizeof(ProfAccount)); + + expect_any(accounts_free_account, account); + + gboolean result = cmd_account(args, *help); + assert_true(result); + + free(help); +} diff --git a/tests/test_cmd_account.h b/tests/test_cmd_account.h new file mode 100644 index 00000000..30944fe4 --- /dev/null +++ b/tests/test_cmd_account.h @@ -0,0 +1,2 @@ +void cmd_account_shows_usage_when_not_connected_and_no_args(void **state); +void cmd_account_shows_account_when_connected_and_no_args(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index ae4ab61e..73c54014 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -6,6 +6,7 @@ #include "test_autocomplete.h" #include "test_common.h" #include "test_cmd_connect.h" +#include "test_cmd_account.h" #include "test_cmd_rooms.h" #include "test_history.h" #include "test_jid.h" @@ -27,6 +28,9 @@ int main(int argc, char* argv[]) { unit_test(cmd_connect_connects_with_account), unit_test(cmd_connect_frees_account_after_connecting), + 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_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), unit_test(cmd_rooms_shows_message_when_connecting), diff --git a/tests/ui/mock_ui.c b/tests/ui/mock_ui.c index 33b6f1b8..5d83bcea 100644 --- a/tests/ui/mock_ui.c +++ b/tests/ui/mock_ui.c @@ -218,7 +218,12 @@ void cons_show_chat_prefs(void) {} void cons_show_log_prefs(void) {} void cons_show_presence_prefs(void) {} void cons_show_connection_prefs(void) {} -void cons_show_account(ProfAccount *account) {} + +void cons_show_account(ProfAccount *account) +{ + check_expected(account); +} + void cons_debug(const char * const msg, ...) {} void cons_show_time(void) {} void cons_show_word(const char * const word) {} |