Added tests for /otr warn

This commit is contained in:
James Booth
2014-02-16 02:22:29 +00:00
parent c6220e01a0
commit 7e956fb347
8 changed files with 104 additions and 2 deletions

View File

@@ -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)
{

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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