diff options
author | James Booth <boothj5@gmail.com> | 2014-02-16 02:22:29 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-02-16 02:22:29 +0000 |
commit | 7e956fb34740c691d2fc79faff864e2e9a445dab (patch) | |
tree | ca9a43829d1633fff6233f396ce0b18d1244f8a8 /tests | |
parent | c6220e01a0b51405130d9976d0331c2c99bdab4c (diff) | |
download | profani-tty-7e956fb34740c691d2fc79faff864e2e9a445dab.tar.gz |
Added tests for /otr warn
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_cmd_otr.c | 70 | ||||
-rw-r--r-- | tests/test_cmd_otr.h | 4 | ||||
-rw-r--r-- | tests/testsuite.c | 8 | ||||
-rw-r--r-- | tests/ui/mock_ui.c | 11 | ||||
-rw-r--r-- | tests/ui/mock_ui.h | 2 |
5 files changed, 95 insertions, 0 deletions
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 |