mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Merge branch 'master' into plugins
This commit is contained in:
commit
f4f1167188
@ -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,17 @@ _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();
|
||||
}
|
||||
|
||||
static char *
|
||||
_mock_otr_get_their_fingerprint(const char * const recipient)
|
||||
{
|
||||
check_expected(recipient);
|
||||
return (char *)mock();
|
||||
}
|
||||
|
||||
void
|
||||
@ -37,5 +44,21 @@ 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);
|
||||
}
|
||||
|
||||
void
|
||||
otr_get_their_fingerprint_expect_and_return(char *recipient, char *fingerprint)
|
||||
{
|
||||
otr_get_their_fingerprint = _mock_otr_get_their_fingerprint;
|
||||
expect_string(_mock_otr_get_their_fingerprint, recipient, recipient);
|
||||
will_return(_mock_otr_get_their_fingerprint, fingerprint);
|
||||
}
|
||||
|
@ -5,7 +5,9 @@
|
||||
|
||||
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);
|
||||
void otr_get_their_fingerprint_expect_and_return(char *recipient, 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,108 @@ 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);
|
||||
}
|
||||
|
||||
static void
|
||||
test_cmd_otr_theirfp_from_wintype(win_type_t wintype)
|
||||
{
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "theirfp", NULL };
|
||||
mock_connection_status(JABBER_CONNECTED);
|
||||
mock_current_win_type(wintype);
|
||||
mock_ui_current_print_line();
|
||||
|
||||
ui_current_print_line_expect("You must be in a regular chat window to view a recipient's fingerprint.");
|
||||
|
||||
gboolean result = cmd_otr(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_otr_theirfp_shows_message_when_in_console(void **state)
|
||||
{
|
||||
test_cmd_otr_theirfp_from_wintype(WIN_CONSOLE);
|
||||
}
|
||||
|
||||
void cmd_otr_theirfp_shows_message_when_in_muc(void **state)
|
||||
{
|
||||
test_cmd_otr_theirfp_from_wintype(WIN_MUC);
|
||||
}
|
||||
|
||||
void cmd_otr_theirfp_shows_message_when_in_private(void **state)
|
||||
{
|
||||
test_cmd_otr_theirfp_from_wintype(WIN_PRIVATE);
|
||||
}
|
||||
|
||||
void cmd_otr_theirfp_shows_message_when_in_duck(void **state)
|
||||
{
|
||||
test_cmd_otr_theirfp_from_wintype(WIN_DUCK);
|
||||
}
|
||||
|
||||
void cmd_otr_theirfp_shows_message_when_non_otr_chat_window(void **state)
|
||||
{
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "theirfp", NULL };
|
||||
mock_connection_status(JABBER_CONNECTED);
|
||||
mock_current_win_type(WIN_CHAT);
|
||||
ui_current_win_is_otr_returns(FALSE);
|
||||
mock_ui_current_print_formatted_line();
|
||||
|
||||
ui_current_print_formatted_line_expect('!', 0, "You are not currently in an OTR session.");
|
||||
|
||||
gboolean result = cmd_otr(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_otr_theirfp_shows_fingerprint(void **state)
|
||||
{
|
||||
char *recipient = "someone@chat.com";
|
||||
char *fingerprint = "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE";
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "theirfp", NULL };
|
||||
mock_connection_status(JABBER_CONNECTED);
|
||||
mock_current_win_type(WIN_CHAT);
|
||||
ui_current_win_is_otr_returns(TRUE);
|
||||
mock_ui_current_recipient();
|
||||
ui_current_recipient_returns(recipient);
|
||||
mock_ui_current_print_formatted_line();
|
||||
|
||||
GString *message = g_string_new(recipient);
|
||||
g_string_append(message, "'s OTR fingerprint: ");
|
||||
g_string_append(message, fingerprint);
|
||||
|
||||
otr_get_their_fingerprint_expect_and_return(recipient, strdup(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,13 @@ 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);
|
||||
void cmd_otr_theirfp_shows_message_when_in_console(void **state);
|
||||
void cmd_otr_theirfp_shows_message_when_in_muc(void **state);
|
||||
void cmd_otr_theirfp_shows_message_when_in_private(void **state);
|
||||
void cmd_otr_theirfp_shows_message_when_in_duck(void **state);
|
||||
void cmd_otr_theirfp_shows_message_when_non_otr_chat_window(void **state);
|
||||
void cmd_otr_theirfp_shows_fingerprint(void **state);
|
||||
#else
|
||||
void cmd_otr_shows_message_when_otr_unsupported(void **state);
|
||||
#endif
|
||||
|
@ -468,6 +468,13 @@ 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),
|
||||
unit_test(cmd_otr_theirfp_shows_message_when_in_console),
|
||||
unit_test(cmd_otr_theirfp_shows_message_when_in_muc),
|
||||
unit_test(cmd_otr_theirfp_shows_message_when_in_private),
|
||||
unit_test(cmd_otr_theirfp_shows_message_when_in_duck),
|
||||
unit_test(cmd_otr_theirfp_shows_message_when_non_otr_chat_window),
|
||||
unit_test(cmd_otr_theirfp_shows_fingerprint),
|
||||
#else
|
||||
unit_test(cmd_otr_shows_message_when_otr_unsupported),
|
||||
#endif
|
||||
|
@ -159,6 +159,34 @@ 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);
|
||||
}
|
||||
|
||||
static
|
||||
void _mock_ui_current_print_line(const char * const msg, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, msg);
|
||||
vsnprintf(output, sizeof(output), msg, args);
|
||||
check_expected(output);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
static
|
||||
gboolean _mock_ui_current_win_is_otr(void)
|
||||
{
|
||||
return (gboolean)mock();
|
||||
}
|
||||
|
||||
// bind mocks and stubs
|
||||
|
||||
void
|
||||
@ -252,6 +280,18 @@ 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;
|
||||
}
|
||||
|
||||
void
|
||||
mock_ui_current_print_line(void)
|
||||
{
|
||||
ui_current_print_line = _mock_ui_current_print_line;
|
||||
}
|
||||
|
||||
// expectations
|
||||
|
||||
void
|
||||
@ -368,3 +408,24 @@ 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);
|
||||
}
|
||||
|
||||
void
|
||||
ui_current_print_line_expect(char *message)
|
||||
{
|
||||
expect_string(_mock_ui_current_print_line, output, message);
|
||||
}
|
||||
|
||||
void
|
||||
ui_current_win_is_otr_returns(gboolean result)
|
||||
{
|
||||
ui_current_win_is_otr = _mock_ui_current_win_is_otr;
|
||||
will_return(_mock_ui_current_win_is_otr, result);
|
||||
}
|
||||
|
@ -51,4 +51,12 @@ 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);
|
||||
|
||||
void mock_ui_current_print_line(void);
|
||||
void ui_current_print_line_expect(char *message);
|
||||
|
||||
void ui_current_win_is_otr_returns(gboolean result);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user