mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added tests for /otr warn
This commit is contained in:
parent
c6220e01a0
commit
7e956fb347
@ -2595,8 +2595,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
|
|||||||
} else if (strcmp(args[0], "warn") == 0) {
|
} else if (strcmp(args[0], "warn") == 0) {
|
||||||
gboolean result = _cmd_set_boolean_preference(args[1], help,
|
gboolean result = _cmd_set_boolean_preference(args[1], help,
|
||||||
"OTR warning message", PREF_OTR_WARN);
|
"OTR warning message", PREF_OTR_WARN);
|
||||||
// update the current window
|
ui_current_refresh();
|
||||||
ui_switch_win(wins_get_current_num());
|
|
||||||
return result;
|
return result;
|
||||||
} else if (strcmp(args[0], "libver") == 0) {
|
} else if (strcmp(args[0], "libver") == 0) {
|
||||||
char *version = otr_libotr_version();
|
char *version = otr_libotr_version();
|
||||||
|
@ -552,6 +552,12 @@ _ui_switch_win(const int i)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_ui_current_refresh(void)
|
||||||
|
{
|
||||||
|
ui_switch_win(wins_get_current_num());
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_ui_next_win(void)
|
_ui_next_win(void)
|
||||||
{
|
{
|
||||||
@ -1756,4 +1762,5 @@ ui_init_module(void)
|
|||||||
ui_handle_recipient_not_found = _ui_handle_recipient_not_found;
|
ui_handle_recipient_not_found = _ui_handle_recipient_not_found;
|
||||||
ui_handle_recipient_error = _ui_handle_recipient_error;
|
ui_handle_recipient_error = _ui_handle_recipient_error;
|
||||||
ui_handle_error = _ui_handle_error;
|
ui_handle_error = _ui_handle_error;
|
||||||
|
ui_current_refresh = _ui_current_refresh;
|
||||||
}
|
}
|
||||||
|
@ -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_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_error_line)(const char * const msg);
|
||||||
void (*ui_current_page_off)(void);
|
void (*ui_current_page_off)(void);
|
||||||
|
void (*ui_current_refresh)(void);
|
||||||
|
|
||||||
win_type_t (*ui_win_type)(int index);
|
win_type_t (*ui_win_type)(int index);
|
||||||
char * (*ui_recipient)(int index);
|
char * (*ui_recipient)(int index);
|
||||||
|
@ -168,6 +168,76 @@ void cmd_otr_log_redact_shows_warning_when_chlog_disabled(void **state)
|
|||||||
free(help);
|
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
|
#else
|
||||||
void cmd_otr_shows_message_when_otr_unsupported(void **state)
|
void cmd_otr_shows_message_when_otr_unsupported(void **state)
|
||||||
{
|
{
|
||||||
|
@ -10,6 +10,10 @@ void cmd_otr_log_off_disables_logging(void **state);
|
|||||||
void cmd_otr_redact_redacts_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_on_shows_warning_when_chlog_disabled(void **state);
|
||||||
void cmd_otr_log_redact_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
|
#else
|
||||||
void cmd_otr_shows_message_when_otr_unsupported(void **state);
|
void cmd_otr_shows_message_when_otr_unsupported(void **state);
|
||||||
#endif
|
#endif
|
||||||
|
@ -447,6 +447,14 @@ int main(int argc, char* argv[]) {
|
|||||||
unit_test_setup_teardown(cmd_otr_log_redact_shows_warning_when_chlog_disabled,
|
unit_test_setup_teardown(cmd_otr_log_redact_shows_warning_when_chlog_disabled,
|
||||||
init_preferences,
|
init_preferences,
|
||||||
close_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
|
#else
|
||||||
unit_test(cmd_otr_shows_message_when_otr_unsupported),
|
unit_test(cmd_otr_shows_message_when_otr_unsupported),
|
||||||
#endif
|
#endif
|
||||||
|
@ -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
|
// bind mocks and stubs
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -241,6 +246,12 @@ stub_ui_handle_recipient_error(void)
|
|||||||
ui_handle_recipient_error = _stub_ui_handle_recipient_error;
|
ui_handle_recipient_error = _stub_ui_handle_recipient_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
stub_ui_current_refresh(void)
|
||||||
|
{
|
||||||
|
ui_current_refresh = _stub_ui_current_refresh;
|
||||||
|
}
|
||||||
|
|
||||||
// expectations
|
// expectations
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -49,4 +49,6 @@ void mock_current_win_type(win_type_t type);
|
|||||||
void mock_ui_current_recipient(void);
|
void mock_ui_current_recipient(void);
|
||||||
void ui_current_recipient_returns(char *jid);
|
void ui_current_recipient_returns(char *jid);
|
||||||
|
|
||||||
|
void stub_ui_current_refresh(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user