diff options
-rw-r--r-- | tests/test_cmd_otr.c | 140 | ||||
-rw-r--r-- | tests/test_cmd_otr.h | 8 | ||||
-rw-r--r-- | tests/testsuite.c | 18 |
3 files changed, 166 insertions, 0 deletions
diff --git a/tests/test_cmd_otr.c b/tests/test_cmd_otr.c index 940614a2..22342751 100644 --- a/tests/test_cmd_otr.c +++ b/tests/test_cmd_otr.c @@ -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) { diff --git a/tests/test_cmd_otr.h b/tests/test_cmd_otr.h index e4a84281..21830e81 100644 --- a/tests/test_cmd_otr.h +++ b/tests/test_cmd_otr.h @@ -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 diff --git a/tests/testsuite.c b/tests/testsuite.c index fd7a6524..8d9209b1 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -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 |