diff options
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | tests/log/mock_log.c | 59 | ||||
-rw-r--r-- | tests/test_cmd_connect.c | 52 | ||||
-rw-r--r-- | tests/test_cmd_connect.h | 2 | ||||
-rw-r--r-- | tests/testsuite.c | 2 | ||||
-rw-r--r-- | tests/ui/mock_ui.c | 11 |
6 files changed, 127 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am index cb717a15..a4cc2df8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -42,7 +42,7 @@ core_sources = \ src/config/theme.c src/config/theme.h test_sources = \ - src/contact.c src/contact.h src/log.c src/common.c \ + src/contact.c src/contact.h src/common.c \ src/log.h src/profanity.c src/common.h \ src/profanity.h src/chat_session.c \ src/chat_session.h src/muc.c src/muc.h src/jid.h src/jid.c \ @@ -62,6 +62,7 @@ test_sources = \ src/config/theme.c src/config/theme.h \ tests/ui/mock_ui.c \ tests/xmpp/mock_xmpp.c \ + tests/log/mock_log.c \ tests/config/mock_accounts.c \ tests/test_autocomplete.c \ tests/test_common.c \ diff --git a/tests/log/mock_log.c b/tests/log/mock_log.c new file mode 100644 index 00000000..a5e6a950 --- /dev/null +++ b/tests/log/mock_log.c @@ -0,0 +1,59 @@ +/* + * mock_log.c + * + * Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com> + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <glib.h> +#include <setjmp.h> +#include <cmocka.h> + +#include "log.h" + +void log_init(log_level_t filter) {} +log_level_t log_get_filter(void) +{ + return (log_level_t)mock(); +} +void log_close(void) {} +void log_debug(const char * const msg, ...) {} +void log_info(const char * const msg, ...) {} +void log_warning(const char * const msg, ...) {} +void log_error(const char * const msg, ...) {} +void log_msg(log_level_t level, const char * const area, + const char * const msg) {} + +log_level_t log_level_from_string(char *log_level) +{ + return (log_level_t)mock(); +} + +void chat_log_init(void) {} +void chat_log_chat(const gchar * const login, gchar *other, + const gchar * const msg, chat_log_direction_t direction, GTimeVal *tv_stamp) {} +void chat_log_close(void) {} +GSList * chat_log_get_previous(const gchar * const login, + const gchar * const recipient, GSList *history) +{ + return (GSList *)mock(); +} + +void groupchat_log_init(void) {} +void groupchat_log_chat(const gchar * const login, const gchar * const room, + const gchar * const nick, const gchar * const msg) {} diff --git a/tests/test_cmd_connect.c b/tests/test_cmd_connect.c index 2a09815f..0092d5e4 100644 --- a/tests/test_cmd_connect.c +++ b/tests/test_cmd_connect.c @@ -67,3 +67,55 @@ void cmd_connect_when_no_account(void **state) free(help); } + +void cmd_connect_with_altdomain_when_provided(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "user@server.org", "altdomain" }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_string(accounts_get_account, name, "user@server.org"); + will_return(accounts_get_account, NULL); + + will_return(ui_ask_password, strdup("password")); + + expect_string(cons_show, output, "Connecting as user@server.org"); + + expect_string(jabber_connect_with_details, jid, "user@server.org"); + expect_string(jabber_connect_with_details, passwd, "password"); + expect_string(jabber_connect_with_details, altdomain, "altdomain"); + will_return(jabber_connect_with_details, JABBER_CONNECTING); + + gboolean result = cmd_connect(args, *help); + assert_true(result); + + free(help); +} + +void cmd_connect_fail_message(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "user@server.org", "altdomain" }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_string(accounts_get_account, name, "user@server.org"); + will_return(accounts_get_account, NULL); + + will_return(ui_ask_password, strdup("password")); + + expect_string(cons_show, output, "Connecting as user@server.org"); + + expect_string(jabber_connect_with_details, jid, "user@server.org"); + expect_string(jabber_connect_with_details, passwd, "password"); + expect_string(jabber_connect_with_details, altdomain, "altdomain"); + will_return(jabber_connect_with_details, JABBER_DISCONNECTED); + + expect_string(cons_show_error, output, "Connection attempt for user@server.org failed."); + + gboolean result = cmd_connect(args, *help); + assert_true(result); + + free(help); +} diff --git a/tests/test_cmd_connect.h b/tests/test_cmd_connect.h index be8eba23..c351f11b 100644 --- a/tests/test_cmd_connect.h +++ b/tests/test_cmd_connect.h @@ -3,3 +3,5 @@ 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); void cmd_connect_when_no_account(void **state); +void cmd_connect_with_altdomain_when_provided(void **state); +void cmd_connect_fail_message(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 8a29e0fd..148ccf90 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -19,6 +19,8 @@ int main(int argc, char* argv[]) { unit_test(cmd_connect_shows_message_when_connected), unit_test(cmd_connect_shows_message_when_undefined), unit_test(cmd_connect_when_no_account), + unit_test(cmd_connect_with_altdomain_when_provided), + unit_test(cmd_connect_fail_message), unit_test(cmd_rooms_shows_message_when_disconnected), unit_test(cmd_rooms_shows_message_when_disconnecting), diff --git a/tests/ui/mock_ui.c b/tests/ui/mock_ui.c index a361e90e..33b6f1b8 100644 --- a/tests/ui/mock_ui.c +++ b/tests/ui/mock_ui.c @@ -222,7 +222,16 @@ void cons_show_account(ProfAccount *account) {} void cons_debug(const char * const msg, ...) {} void cons_show_time(void) {} void cons_show_word(const char * const word) {} -void cons_show_error(const char * const cmd, ...) {} + +void cons_show_error(const char * const cmd, ...) +{ + va_list args; + va_start(args, cmd); + vsnprintf(output, sizeof(output), cmd, args); + check_expected(output); + va_end(args); +} + void cons_highlight_show(const char * const cmd) {} void cons_show_contacts(GSList * list) {} void cons_show_roster(GSList * list) {} |