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

Added cmd_account test

This commit is contained in:
James Booth 2013-12-15 22:28:22 +00:00
parent 6d75ebb8e9
commit 683da12c3a
5 changed files with 62 additions and 1 deletions

View File

@ -67,6 +67,7 @@ test_sources = \
tests/test_autocomplete.c \
tests/test_common.c \
tests/test_cmd_connect.c \
tests/test_cmd_account.c \
tests/test_cmd_rooms.c \
tests/test_history.c \
tests/test_jid.c \

49
tests/test_cmd_account.c Normal file
View File

@ -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);
}

2
tests/test_cmd_account.h Normal file
View File

@ -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);

View File

@ -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),

View File

@ -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) {}