mirror of
https://github.com/profanity-im/profanity.git
synced 2025-07-25 11:24:19 -04:00
Added mock log module
This commit is contained in:
parent
079ea5304b
commit
7842b0d1fc
@ -42,7 +42,7 @@ core_sources = \
|
|||||||
src/config/theme.c src/config/theme.h
|
src/config/theme.c src/config/theme.h
|
||||||
|
|
||||||
test_sources = \
|
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/log.h src/profanity.c src/common.h \
|
||||||
src/profanity.h src/chat_session.c \
|
src/profanity.h src/chat_session.c \
|
||||||
src/chat_session.h src/muc.c src/muc.h src/jid.h src/jid.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 \
|
src/config/theme.c src/config/theme.h \
|
||||||
tests/ui/mock_ui.c \
|
tests/ui/mock_ui.c \
|
||||||
tests/xmpp/mock_xmpp.c \
|
tests/xmpp/mock_xmpp.c \
|
||||||
|
tests/log/mock_log.c \
|
||||||
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 \
|
||||||
|
59
tests/log/mock_log.c
Normal file
59
tests/log/mock_log.c
Normal file
@ -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) {}
|
@ -67,3 +67,55 @@ void cmd_connect_when_no_account(void **state)
|
|||||||
|
|
||||||
free(help);
|
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);
|
||||||
|
}
|
||||||
|
@ -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_connected(void **state);
|
||||||
void cmd_connect_shows_message_when_undefined(void **state);
|
void cmd_connect_shows_message_when_undefined(void **state);
|
||||||
void cmd_connect_when_no_account(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);
|
||||||
|
@ -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_connected),
|
||||||
unit_test(cmd_connect_shows_message_when_undefined),
|
unit_test(cmd_connect_shows_message_when_undefined),
|
||||||
unit_test(cmd_connect_when_no_account),
|
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_disconnected),
|
||||||
unit_test(cmd_rooms_shows_message_when_disconnecting),
|
unit_test(cmd_rooms_shows_message_when_disconnecting),
|
||||||
|
@ -222,7 +222,16 @@ void cons_show_account(ProfAccount *account) {}
|
|||||||
void cons_debug(const char * const msg, ...) {}
|
void cons_debug(const char * const msg, ...) {}
|
||||||
void cons_show_time(void) {}
|
void cons_show_time(void) {}
|
||||||
void cons_show_word(const char * const word) {}
|
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_highlight_show(const char * const cmd) {}
|
||||||
void cons_show_contacts(GSList * list) {}
|
void cons_show_contacts(GSList * list) {}
|
||||||
void cons_show_roster(GSList * list) {}
|
void cons_show_roster(GSList * list) {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user