mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added /otr myfp test
This commit is contained in:
parent
6e58d95469
commit
82ad0cd306
@ -83,7 +83,7 @@ gboolean (*ui_current_win_is_otr)(void);
|
||||
void (*ui_current_set_otr)(gboolean value);
|
||||
char* (*ui_current_recipient)(void);
|
||||
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_char, 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);
|
||||
|
@ -21,10 +21,10 @@ _mock_otr_libotr_version(void)
|
||||
return (char *)mock();
|
||||
}
|
||||
|
||||
void
|
||||
mock_otr_libotr_version(void)
|
||||
static char *
|
||||
_mock_otr_get_my_fingerprint(void)
|
||||
{
|
||||
otr_libotr_version = _mock_otr_libotr_version;
|
||||
return (char *)mock();
|
||||
}
|
||||
|
||||
void
|
||||
@ -37,5 +37,13 @@ otr_keygen_expect(ProfAccount *account)
|
||||
void
|
||||
otr_libotr_version_returns(char *version)
|
||||
{
|
||||
otr_libotr_version = _mock_otr_libotr_version;
|
||||
will_return(_mock_otr_libotr_version, version);
|
||||
}
|
||||
|
||||
void
|
||||
otr_get_my_fingerprint_returns(char *fingerprint)
|
||||
{
|
||||
otr_get_my_fingerprint = _mock_otr_get_my_fingerprint;
|
||||
will_return(_mock_otr_get_my_fingerprint, fingerprint);
|
||||
}
|
||||
|
@ -5,7 +5,8 @@
|
||||
|
||||
void otr_keygen_expect(ProfAccount *account);
|
||||
|
||||
void mock_otr_libotr_version(void);
|
||||
void otr_libotr_version_returns(char *version);
|
||||
|
||||
void otr_get_my_fingerprint_returns(char *fingerprint);
|
||||
|
||||
#endif
|
||||
|
@ -254,7 +254,6 @@ void cmd_otr_libver_shows_libotr_version(void **state)
|
||||
char *version = "9.9.9";
|
||||
GString *message = g_string_new("Using libotr version ");
|
||||
g_string_append(message, version);
|
||||
mock_otr_libotr_version();
|
||||
otr_libotr_version_returns(version);
|
||||
|
||||
expect_cons_show(message->str);
|
||||
@ -367,6 +366,27 @@ void cmd_otr_myfp_shows_message_when_disconnecting(void **state)
|
||||
test_with_command_and_connection_status("myfp", JABBER_DISCONNECTING);
|
||||
}
|
||||
|
||||
void cmd_otr_myfp_shows_my_fingerprint(void **state)
|
||||
{
|
||||
char *fingerprint = "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE";
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "myfp", NULL };
|
||||
mock_connection_status(JABBER_CONNECTED);
|
||||
otr_get_my_fingerprint_returns(strdup(fingerprint));
|
||||
mock_ui_current_print_formatted_line();
|
||||
|
||||
GString *message = g_string_new("Your OTR fingerprint: ");
|
||||
g_string_append(message, fingerprint);
|
||||
|
||||
ui_current_print_formatted_line_expect('!', 0, message->str);
|
||||
|
||||
gboolean result = cmd_otr(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
g_string_free(message, TRUE);
|
||||
free(help);
|
||||
}
|
||||
|
||||
#else
|
||||
void cmd_otr_shows_message_when_otr_unsupported(void **state)
|
||||
{
|
||||
|
@ -27,6 +27,7 @@ void cmd_otr_myfp_shows_message_when_undefined(void **state);
|
||||
void cmd_otr_myfp_shows_message_when_started(void **state);
|
||||
void cmd_otr_myfp_shows_message_when_connecting(void **state);
|
||||
void cmd_otr_myfp_shows_message_when_disconnecting(void **state);
|
||||
void cmd_otr_myfp_shows_my_fingerprint(void **state);
|
||||
#else
|
||||
void cmd_otr_shows_message_when_otr_unsupported(void **state);
|
||||
#endif
|
||||
|
@ -468,6 +468,7 @@ int main(int argc, char* argv[]) {
|
||||
unit_test(cmd_otr_myfp_shows_message_when_started),
|
||||
unit_test(cmd_otr_myfp_shows_message_when_connecting),
|
||||
unit_test(cmd_otr_myfp_shows_message_when_disconnecting),
|
||||
unit_test(cmd_otr_myfp_shows_my_fingerprint),
|
||||
#else
|
||||
unit_test(cmd_otr_shows_message_when_otr_unsupported),
|
||||
#endif
|
||||
|
@ -159,6 +159,18 @@ void _stub_ui_current_refresh(void)
|
||||
{
|
||||
}
|
||||
|
||||
static
|
||||
void _mock_ui_current_print_formatted_line(const char show_char, int attrs, const char * const msg, ...)
|
||||
{
|
||||
check_expected(show_char);
|
||||
check_expected(attrs);
|
||||
va_list args;
|
||||
va_start(args, msg);
|
||||
vsnprintf(output, sizeof(output), msg, args);
|
||||
check_expected(output);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
// bind mocks and stubs
|
||||
|
||||
void
|
||||
@ -252,6 +264,12 @@ stub_ui_current_refresh(void)
|
||||
ui_current_refresh = _stub_ui_current_refresh;
|
||||
}
|
||||
|
||||
void
|
||||
mock_ui_current_print_formatted_line(void)
|
||||
{
|
||||
ui_current_print_formatted_line = _mock_ui_current_print_formatted_line;
|
||||
}
|
||||
|
||||
// expectations
|
||||
|
||||
void
|
||||
@ -368,3 +386,11 @@ ui_current_recipient_returns(char *jid)
|
||||
{
|
||||
will_return(_mock_ui_current_recipeint, jid);
|
||||
}
|
||||
|
||||
void
|
||||
ui_current_print_formatted_line_expect(char show_char, int attrs, char *message)
|
||||
{
|
||||
expect_value(_mock_ui_current_print_formatted_line, show_char, show_char);
|
||||
expect_value(_mock_ui_current_print_formatted_line, attrs, attrs);
|
||||
expect_string(_mock_ui_current_print_formatted_line, output, message);
|
||||
}
|
||||
|
@ -51,4 +51,7 @@ void ui_current_recipient_returns(char *jid);
|
||||
|
||||
void stub_ui_current_refresh(void);
|
||||
|
||||
void mock_ui_current_print_formatted_line(void);
|
||||
void ui_current_print_formatted_line_expect(char show_char, int attrs, char *message);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user