about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/command/commands.c3
-rw-r--r--src/ui/core.c7
-rw-r--r--src/ui/ui.h1
-rw-r--r--tests/test_cmd_otr.c70
-rw-r--r--tests/test_cmd_otr.h4
-rw-r--r--tests/testsuite.c8
-rw-r--r--tests/ui/mock_ui.c11
-rw-r--r--tests/ui/mock_ui.h2
8 files changed, 104 insertions, 2 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index 397c6a54..53a2b1a3 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -2595,8 +2595,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
     } else if (strcmp(args[0], "warn") == 0) {
         gboolean result =  _cmd_set_boolean_preference(args[1], help,
             "OTR warning message", PREF_OTR_WARN);
-        // update the current window
-        ui_switch_win(wins_get_current_num());
+        ui_current_refresh();
         return result;
     } else if (strcmp(args[0], "libver") == 0) {
         char *version = otr_libotr_version();
diff --git a/src/ui/core.c b/src/ui/core.c
index 783b369e..cf2b4961 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -553,6 +553,12 @@ _ui_switch_win(const int i)
 }
 
 static void
+_ui_current_refresh(void)
+{
+    ui_switch_win(wins_get_current_num());
+}
+
+static void
 _ui_next_win(void)
 {
     ui_current_page_off();
@@ -1756,4 +1762,5 @@ ui_init_module(void)
     ui_handle_recipient_not_found = _ui_handle_recipient_not_found;
     ui_handle_recipient_error = _ui_handle_recipient_error;
     ui_handle_error = _ui_handle_error;
+    ui_current_refresh = _ui_current_refresh;
 }
diff --git a/src/ui/ui.h b/src/ui/ui.h
index c30bbb12..af254ae6 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -86,6 +86,7 @@ void (*ui_current_print_line)(const char * const msg, ...);
 void (*ui_current_print_formatted_line)(const char show_chat, int attrs, const char * const msg, ...);
 void (*ui_current_error_line)(const char * const msg);
 void (*ui_current_page_off)(void);
+void (*ui_current_refresh)(void);
 
 win_type_t (*ui_win_type)(int index);
 char * (*ui_recipient)(int index);
diff --git a/tests/test_cmd_otr.c b/tests/test_cmd_otr.c
index 22342751..124f52f9 100644
--- a/tests/test_cmd_otr.c
+++ b/tests/test_cmd_otr.c
@@ -168,6 +168,76 @@ void cmd_otr_log_redact_shows_warning_when_chlog_disabled(void **state)
     free(help);
 }
 
+void cmd_otr_warn_shows_usage_when_no_args(void **state)
+{
+    mock_cons_show();
+    stub_ui_current_refresh();
+    CommandHelp *help = malloc(sizeof(CommandHelp));
+    help->usage = "Some usage";
+    gchar *args[] = { "warn", NULL };
+
+    expect_cons_show("Usage: Some usage");
+
+    gboolean result = cmd_otr(args, *help);
+    assert_true(result);
+
+    free(help);
+}
+
+void cmd_otr_warn_shows_usage_when_invalid_arg(void **state)
+{
+    mock_cons_show();
+    stub_ui_current_refresh();
+    CommandHelp *help = malloc(sizeof(CommandHelp));
+    help->usage = "Some usage";
+    gchar *args[] = { "warn", "badarg", NULL };
+
+    expect_cons_show("Usage: Some usage");
+
+    gboolean result = cmd_otr(args, *help);
+    assert_true(result);
+
+    free(help);
+}
+
+void cmd_otr_warn_on_enables_unencrypted_warning(void **state)
+{
+    mock_cons_show();
+    stub_ui_current_refresh();
+    CommandHelp *help = malloc(sizeof(CommandHelp));
+    gchar *args[] = { "warn", "on", NULL };
+
+    prefs_set_boolean(PREF_OTR_WARN, FALSE);
+    expect_cons_show("OTR warning message enabled.");
+
+    gboolean result = cmd_otr(args, *help);
+    gboolean otr_warn_enabled = prefs_get_boolean(PREF_OTR_WARN);
+
+    assert_true(result);
+    assert_true(otr_warn_enabled);
+
+    free(help);
+}
+
+void cmd_otr_warn_off_disables_unencrypted_warning(void **state)
+{
+    mock_cons_show();
+    stub_ui_current_refresh();
+    CommandHelp *help = malloc(sizeof(CommandHelp));
+    gchar *args[] = { "warn", "off", NULL };
+
+    prefs_set_boolean(PREF_OTR_WARN, TRUE);
+    expect_cons_show("OTR warning message disabled.");
+
+    gboolean result = cmd_otr(args, *help);
+    gboolean otr_warn_enabled = prefs_get_boolean(PREF_OTR_WARN);
+
+    assert_true(result);
+    assert_false(otr_warn_enabled);
+
+    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 21830e81..bfb39a2d 100644
--- a/tests/test_cmd_otr.h
+++ b/tests/test_cmd_otr.h
@@ -10,6 +10,10 @@ 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);
+void cmd_otr_warn_shows_usage_when_no_args(void **state);
+void cmd_otr_warn_shows_usage_when_invalid_arg(void **state);
+void cmd_otr_warn_on_enables_unencrypted_warning(void **state);
+void cmd_otr_warn_off_disables_unencrypted_warning(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 8d9209b1..0a34bad2 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -447,6 +447,14 @@ int main(int argc, char* argv[]) {
         unit_test_setup_teardown(cmd_otr_log_redact_shows_warning_when_chlog_disabled,
             init_preferences,
             close_preferences),
+        unit_test(cmd_otr_warn_shows_usage_when_no_args),
+        unit_test(cmd_otr_warn_shows_usage_when_invalid_arg),
+        unit_test_setup_teardown(cmd_otr_warn_on_enables_unencrypted_warning,
+            init_preferences,
+            close_preferences),
+        unit_test_setup_teardown(cmd_otr_warn_off_disables_unencrypted_warning,
+            init_preferences,
+            close_preferences),
 #else
         unit_test(cmd_otr_shows_message_when_otr_unsupported),
 #endif
diff --git a/tests/ui/mock_ui.c b/tests/ui/mock_ui.c
index 4fdd0a99..7175d2b9 100644
--- a/tests/ui/mock_ui.c
+++ b/tests/ui/mock_ui.c
@@ -154,6 +154,11 @@ void _stub_ui_handle_recipient_not_found(const char * const recipient, const cha
 {
 }
 
+static
+void _stub_ui_current_refresh(void)
+{
+}
+
 // bind mocks and stubs
 
 void
@@ -241,6 +246,12 @@ stub_ui_handle_recipient_error(void)
     ui_handle_recipient_error = _stub_ui_handle_recipient_error;
 }
 
+void
+stub_ui_current_refresh(void)
+{
+    ui_current_refresh = _stub_ui_current_refresh;
+}
+
 // expectations
 
 void
diff --git a/tests/ui/mock_ui.h b/tests/ui/mock_ui.h
index fc6ff19a..3d264970 100644
--- a/tests/ui/mock_ui.h
+++ b/tests/ui/mock_ui.h
@@ -49,4 +49,6 @@ void mock_current_win_type(win_type_t type);
 void mock_ui_current_recipient(void);
 void ui_current_recipient_returns(char *jid);
 
+void stub_ui_current_refresh(void);
+
 #endif