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

Added /sub command test

This commit is contained in:
James Booth 2013-12-27 17:25:30 +00:00
parent c3fbaf8b2a
commit 976f3e303a
5 changed files with 38 additions and 1 deletions

View File

@ -69,6 +69,7 @@ test_sources = \
tests/test_cmd_connect.c \
tests/test_cmd_account.c \
tests/test_cmd_rooms.c \
tests/test_cmd_sub.c \
tests/test_history.c \
tests/test_jid.c \
tests/test_parser.c \

View File

@ -311,7 +311,6 @@ gboolean
cmd_sub(gchar **args, struct cmd_help_t help)
{
jabber_conn_status_t conn_status = jabber_get_connection_status();
win_type_t win_type = ui_current_win_type();
if (conn_status != JABBER_CONNECTED) {
cons_show("You are currently not connected.");
@ -337,6 +336,7 @@ cmd_sub(gchar **args, struct cmd_help_t help)
return TRUE;
}
win_type_t win_type = ui_current_win_type();
if ((win_type != WIN_CHAT) && (jid == NULL)) {
cons_show("You must specify a contact.");
return TRUE;

31
tests/test_cmd_sub.c Normal file
View File

@ -0,0 +1,31 @@
#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 "xmpp/mock_xmpp.h"
#include "ui/ui.h"
#include "ui/mock_ui.h"
#include "command/commands.h"
void cmd_sub_shows_message_when_not_connected(void **state)
{
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { NULL };
mock_connection_status(JABBER_DISCONNECTED);
expect_cons_show("You are currently not connected.");
gboolean result = cmd_sub(args, *help);
assert_true(result);
free(help);
}

1
tests/test_cmd_sub.h Normal file
View File

@ -0,0 +1 @@
void cmd_sub_shows_message_when_not_connected(void **state);

View File

@ -8,6 +8,7 @@
#include "test_cmd_connect.h"
#include "test_cmd_account.h"
#include "test_cmd_rooms.h"
#include "test_cmd_sub.h"
#include "test_history.h"
#include "test_jid.h"
#include "test_parser.h"
@ -252,6 +253,9 @@ int main(int argc, char* argv[]) {
unit_test(cmd_account_clear_checks_account_exists),
unit_test(cmd_account_clear_shows_message_when_account_doesnt_exist),
unit_test(cmd_account_clear_shows_message_when_invalid_property),
unit_test(cmd_sub_shows_message_when_not_connected),
};
return run_tests(tests);
}