1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Added cmd_connect tests

This commit is contained in:
James Booth 2013-12-15 18:08:26 +00:00
parent 2490f5b417
commit bf347ab9e0
6 changed files with 95 additions and 5 deletions

View File

@ -65,7 +65,8 @@ test_sources = \
tests/config/mock_accounts.c \ tests/config/mock_accounts.c \
tests/test_autocomplete.c \ tests/test_autocomplete.c \
tests/test_common.c \ tests/test_common.c \
tests/test_command.c \ tests/test_cmd_connect.c \
tests/test_cmd_rooms.c \
tests/test_history.c \ tests/test_history.c \
tests/test_jid.c \ tests/test_jid.c \
tests/test_parser.c \ tests/test_parser.c \

79
tests/test_cmd_connect.c Normal file
View File

@ -0,0 +1,79 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <glib.h>
#include "xmpp/xmpp.h"
#include "ui/ui.h"
#include "command/commands.h"
static void test_with_connection_status(jabber_conn_status_t status)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
will_return(jabber_get_connection_status, status);
expect_string(cons_show, msg, "You are either connected already, or a login is in process.");
gboolean result = cmd_connect(NULL, *help);
assert_true(result);
free(help);
}
void cmd_connect_shows_message_when_disconnecting(void **state)
{
test_with_connection_status(JABBER_DISCONNECTING);
}
void cmd_connect_shows_message_when_connecting(void **state)
{
test_with_connection_status(JABBER_CONNECTING);
}
void cmd_connect_shows_message_when_connected(void **state)
{
test_with_connection_status(JABBER_CONNECTED);
}
void cmd_connect_shows_message_when_undefined(void **state)
{
test_with_connection_status(JABBER_UNDEFINED);
}
/*
void cmd_rooms_uses_account_default_when_no_arg(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
ProfAccount *account = malloc(sizeof(ProfAccount));
account->muc_service = "default_conf_server";
gchar *args[] = { NULL };
will_return(jabber_get_connection_status, JABBER_CONNECTED);
will_return(jabber_get_account_name, "account_name");
will_return(accounts_get_account, account);
expect_string(iq_room_list_request, conferencejid, "default_conf_server");
gboolean result = cmd_rooms(args, *help);
assert_true(result);
free(help);
free(account);
}
void cmd_rooms_arg_used_when_passed(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "conf_server_arg" };
will_return(jabber_get_connection_status, JABBER_CONNECTED);
expect_string(iq_room_list_request, conferencejid, "conf_server_arg");
gboolean result = cmd_rooms(args, *help);
assert_true(result);
free(help);
}
*/

4
tests/test_cmd_connect.h Normal file
View File

@ -0,0 +1,4 @@
void cmd_connect_shows_message_when_disconnecting(void **state);
void cmd_connect_shows_message_when_connecting(void **state);
void cmd_connect_shows_message_when_connected(void **state);
void cmd_connect_shows_message_when_undefined(void **state);

View File

@ -67,7 +67,7 @@ void cmd_rooms_uses_account_default_when_no_arg(void **state)
free(account); free(account);
} }
void cmd_arg_used_when_passed(void **state) void cmd_rooms_arg_used_when_passed(void **state)
{ {
CommandHelp *help = malloc(sizeof(CommandHelp)); CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "conf_server_arg" }; gchar *args[] = { "conf_server_arg" };

View File

@ -4,4 +4,4 @@ void cmd_rooms_shows_message_when_connecting(void **state);
void cmd_rooms_shows_message_when_started(void **state); void cmd_rooms_shows_message_when_started(void **state);
void cmd_rooms_shows_message_when_undefined(void **state); void cmd_rooms_shows_message_when_undefined(void **state);
void cmd_rooms_uses_account_default_when_no_arg(void **state); void cmd_rooms_uses_account_default_when_no_arg(void **state);
void cmd_arg_used_when_passed(void **state); void cmd_rooms_arg_used_when_passed(void **state);

View File

@ -5,7 +5,8 @@
#include "test_autocomplete.h" #include "test_autocomplete.h"
#include "test_common.h" #include "test_common.h"
#include "test_command.h" #include "test_cmd_connect.h"
#include "test_cmd_rooms.h"
#include "test_history.h" #include "test_history.h"
#include "test_jid.h" #include "test_jid.h"
#include "test_parser.h" #include "test_parser.h"
@ -13,13 +14,18 @@
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
const UnitTest tests[] = { const UnitTest tests[] = {
unit_test(cmd_connect_shows_message_when_disconnecting),
unit_test(cmd_connect_shows_message_when_connecting),
unit_test(cmd_connect_shows_message_when_connected),
unit_test(cmd_connect_shows_message_when_undefined),
unit_test(cmd_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnected),
unit_test(cmd_rooms_shows_message_when_disconnecting), unit_test(cmd_rooms_shows_message_when_disconnecting),
unit_test(cmd_rooms_shows_message_when_connecting), unit_test(cmd_rooms_shows_message_when_connecting),
unit_test(cmd_rooms_shows_message_when_started), unit_test(cmd_rooms_shows_message_when_started),
unit_test(cmd_rooms_shows_message_when_undefined), unit_test(cmd_rooms_shows_message_when_undefined),
unit_test(cmd_rooms_uses_account_default_when_no_arg), unit_test(cmd_rooms_uses_account_default_when_no_arg),
unit_test(cmd_arg_used_when_passed), unit_test(cmd_rooms_arg_used_when_passed),
unit_test(replace_one_substr), unit_test(replace_one_substr),
unit_test(replace_one_substr_beginning), unit_test(replace_one_substr_beginning),