mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Added tests for /otr log
This commit is contained in:
parent
6295336284
commit
c6220e01a0
@ -7,8 +7,10 @@
|
||||
#include <glib.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "config/preferences.h"
|
||||
|
||||
#include "ui/mock_ui.h"
|
||||
#include "xmpp/mock_xmpp.h"
|
||||
|
||||
#include "command/command.h"
|
||||
#include "command/commands.h"
|
||||
@ -28,6 +30,144 @@ void cmd_otr_shows_usage_when_no_args(void **state)
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_otr_shows_usage_when_invalid_subcommand(void **state)
|
||||
{
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "Some usage";
|
||||
gchar *args[] = { "unknown", NULL };
|
||||
|
||||
mock_connection_status(JABBER_CONNECTED);
|
||||
expect_cons_show("Usage: Some usage");
|
||||
|
||||
gboolean result = cmd_otr(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_otr_log_shows_usage_when_no_args(void **state)
|
||||
{
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "Some usage";
|
||||
gchar *args[] = { "log", NULL };
|
||||
|
||||
expect_cons_show("Usage: Some usage");
|
||||
|
||||
gboolean result = cmd_otr(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_otr_log_shows_usage_when_invalid_subcommand(void **state)
|
||||
{
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
help->usage = "Some usage";
|
||||
gchar *args[] = { "log", "wrong", NULL };
|
||||
|
||||
expect_cons_show("Usage: Some usage");
|
||||
|
||||
gboolean result = cmd_otr(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_otr_log_on_enables_logging(void **state)
|
||||
{
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "log", "on", NULL };
|
||||
|
||||
prefs_set_string(PREF_OTR_LOG, "off");
|
||||
prefs_set_boolean(PREF_CHLOG, TRUE);
|
||||
expect_cons_show("OTR messages will be logged as plaintext.");
|
||||
|
||||
gboolean result = cmd_otr(args, *help);
|
||||
char *pref_otr_log = prefs_get_string(PREF_OTR_LOG);
|
||||
|
||||
assert_true(result);
|
||||
assert_string_equal("on", pref_otr_log);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_otr_log_on_shows_warning_when_chlog_disabled(void **state)
|
||||
{
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "log", "on", NULL };
|
||||
|
||||
prefs_set_string(PREF_OTR_LOG, "off");
|
||||
prefs_set_boolean(PREF_CHLOG, FALSE);
|
||||
expect_cons_show("OTR messages will be logged as plaintext.");
|
||||
expect_cons_show("Chat logging is currently disabled, use '/chlog on' to enable.");
|
||||
|
||||
gboolean result = cmd_otr(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_otr_log_off_disables_logging(void **state)
|
||||
{
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "log", "off", NULL };
|
||||
|
||||
prefs_set_string(PREF_OTR_LOG, "on");
|
||||
prefs_set_boolean(PREF_CHLOG, TRUE);
|
||||
expect_cons_show("OTR message logging disabled.");
|
||||
|
||||
gboolean result = cmd_otr(args, *help);
|
||||
char *pref_otr_log = prefs_get_string(PREF_OTR_LOG);
|
||||
|
||||
assert_true(result);
|
||||
assert_string_equal("off", pref_otr_log);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_otr_redact_redacts_logging(void **state)
|
||||
{
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "log", "redact", NULL };
|
||||
|
||||
prefs_set_string(PREF_OTR_LOG, "on");
|
||||
prefs_set_boolean(PREF_CHLOG, TRUE);
|
||||
expect_cons_show("OTR messages will be logged as '[redacted]'.");
|
||||
|
||||
gboolean result = cmd_otr(args, *help);
|
||||
char *pref_otr_log = prefs_get_string(PREF_OTR_LOG);
|
||||
|
||||
assert_true(result);
|
||||
assert_string_equal("redact", pref_otr_log);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_otr_log_redact_shows_warning_when_chlog_disabled(void **state)
|
||||
{
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "log", "redact", NULL };
|
||||
|
||||
prefs_set_string(PREF_OTR_LOG, "off");
|
||||
prefs_set_boolean(PREF_CHLOG, FALSE);
|
||||
expect_cons_show("OTR messages will be logged as '[redacted]'.");
|
||||
expect_cons_show("Chat logging is currently disabled, use '/chlog on' to enable.");
|
||||
|
||||
gboolean result = cmd_otr(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
#else
|
||||
void cmd_otr_shows_message_when_otr_unsupported(void **state)
|
||||
{
|
||||
|
@ -2,6 +2,14 @@
|
||||
|
||||
#ifdef HAVE_LIBOTR
|
||||
void cmd_otr_shows_usage_when_no_args(void **state);
|
||||
void cmd_otr_shows_usage_when_invalid_subcommand(void **state);
|
||||
void cmd_otr_log_shows_usage_when_no_args(void **state);
|
||||
void cmd_otr_log_shows_usage_when_invalid_subcommand(void **state);
|
||||
void cmd_otr_log_on_enables_logging(void **state);
|
||||
void cmd_otr_log_off_disables_logging(void **state);
|
||||
void cmd_otr_redact_redacts_logging(void **state);
|
||||
void cmd_otr_log_on_shows_warning_when_chlog_disabled(void **state);
|
||||
void cmd_otr_log_redact_shows_warning_when_chlog_disabled(void **state);
|
||||
#else
|
||||
void cmd_otr_shows_message_when_otr_unsupported(void **state);
|
||||
#endif
|
||||
|
@ -429,6 +429,24 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
#ifdef HAVE_LIBOTR
|
||||
unit_test(cmd_otr_shows_usage_when_no_args),
|
||||
unit_test(cmd_otr_shows_usage_when_invalid_subcommand),
|
||||
unit_test(cmd_otr_log_shows_usage_when_no_args),
|
||||
unit_test(cmd_otr_log_shows_usage_when_invalid_subcommand),
|
||||
unit_test_setup_teardown(cmd_otr_log_on_enables_logging,
|
||||
init_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(cmd_otr_log_off_disables_logging,
|
||||
init_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(cmd_otr_redact_redacts_logging,
|
||||
init_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(cmd_otr_log_on_shows_warning_when_chlog_disabled,
|
||||
init_preferences,
|
||||
close_preferences),
|
||||
unit_test_setup_teardown(cmd_otr_log_redact_shows_warning_when_chlog_disabled,
|
||||
init_preferences,
|
||||
close_preferences),
|
||||
#else
|
||||
unit_test(cmd_otr_shows_message_when_otr_unsupported),
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user