1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Merge branch 'master' into plugins

This commit is contained in:
James Booth 2014-02-23 21:22:01 +00:00
commit 56bbc7e664
8 changed files with 180 additions and 3 deletions

View File

@ -2642,9 +2642,13 @@ cmd_otr(gchar **args, struct cmd_help_t help)
otr_keygen(account);
return TRUE;
} else if (strcmp(args[0], "myfp") == 0) {
char *fingerprint = otr_get_my_fingerprint();
ui_current_print_formatted_line('!', 0, "Your OTR fingerprint: %s", fingerprint);
free(fingerprint);
if (!otr_key_loaded()) {
ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
} else {
char *fingerprint = otr_get_my_fingerprint();
ui_current_print_formatted_line('!', 0, "Your OTR fingerprint: %s", fingerprint);
free(fingerprint);
}
return TRUE;
} else if (strcmp(args[0], "theirfp") == 0) {
win_type_t win_type = ui_current_win_type();

View File

@ -34,6 +34,18 @@ _mock_otr_get_their_fingerprint(const char * const recipient)
return (char *)mock();
}
static gboolean
_mock_otr_key_loaded(void)
{
return (gboolean)mock();
}
static char *
_mock_otr_start_query(void)
{
return (char *)mock();
}
void
otr_keygen_expect(ProfAccount *account)
{
@ -62,3 +74,17 @@ otr_get_their_fingerprint_expect_and_return(char *recipient, char *fingerprint)
expect_string(_mock_otr_get_their_fingerprint, recipient, recipient);
will_return(_mock_otr_get_their_fingerprint, fingerprint);
}
void
otr_key_loaded_returns(gboolean loaded)
{
otr_key_loaded = _mock_otr_key_loaded;
will_return(_mock_otr_key_loaded, loaded);
}
void
otr_start_query_returns(char *query)
{
otr_start_query = _mock_otr_start_query;
will_return(_mock_otr_start_query, query);
}

View File

@ -4,10 +4,13 @@
#include "config/account.h"
void otr_keygen_expect(ProfAccount *account);
void otr_key_loaded_returns(gboolean loaded);
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);
void otr_start_query_returns(char *query);
#endif

View File

@ -366,12 +366,29 @@ void cmd_otr_myfp_shows_message_when_disconnecting(void **state)
test_with_command_and_connection_status("myfp", JABBER_DISCONNECTING);
}
void cmd_otr_myfp_shows_message_when_no_key(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "myfp", NULL };
mock_connection_status(JABBER_CONNECTED);
otr_key_loaded_returns(FALSE);
mock_ui_current_print_formatted_line();
ui_current_print_formatted_line_expect('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
gboolean result = cmd_otr(args, *help);
assert_true(result);
free(help);
}
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_key_loaded_returns(TRUE);
otr_get_my_fingerprint_returns(strdup(fingerprint));
mock_ui_current_print_formatted_line();
@ -468,6 +485,100 @@ void cmd_otr_theirfp_shows_fingerprint(void **state)
free(help);
}
static void
test_cmd_otr_start_from_wintype(win_type_t wintype)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "start", 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 start an OTR session.");
gboolean result = cmd_otr(args, *help);
assert_true(result);
free(help);
}
void cmd_otr_start_shows_message_when_in_console(void **state)
{
test_cmd_otr_start_from_wintype(WIN_CONSOLE);
}
void cmd_otr_start_shows_message_when_in_muc(void **state)
{
test_cmd_otr_start_from_wintype(WIN_MUC);
}
void cmd_otr_start_shows_message_when_in_private(void **state)
{
test_cmd_otr_start_from_wintype(WIN_PRIVATE);
}
void cmd_otr_start_shows_message_when_in_duck(void **state)
{
test_cmd_otr_start_from_wintype(WIN_DUCK);
}
void cmd_otr_start_shows_message_when_already_started(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "start", NULL };
mock_connection_status(JABBER_CONNECTED);
mock_current_win_type(WIN_CHAT);
ui_current_win_is_otr_returns(TRUE);
mock_ui_current_print_formatted_line();
ui_current_print_formatted_line_expect('!', 0, "You are already in an OTR session.");
gboolean result = cmd_otr(args, *help);
assert_true(result);
free(help);
}
void cmd_otr_start_shows_message_when_no_key(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "start", NULL };
mock_connection_status(JABBER_CONNECTED);
mock_current_win_type(WIN_CHAT);
ui_current_win_is_otr_returns(FALSE);
otr_key_loaded_returns(FALSE);
mock_ui_current_print_formatted_line();
ui_current_print_formatted_line_expect('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
gboolean result = cmd_otr(args, *help);
assert_true(result);
free(help);
}
void
cmd_otr_start_sends_otr_query_message_to_current_recipeint(void **state)
{
char *recipient = "buddy@chat.com";
char *query_message = "?OTR?";
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "start", NULL };
mock_connection_status(JABBER_CONNECTED);
mock_current_win_type(WIN_CHAT);
ui_current_win_is_otr_returns(FALSE);
otr_key_loaded_returns(TRUE);
ui_current_recipient_returns(recipient);
otr_start_query_returns(query_message);
message_send_expect(query_message, recipient);
gboolean result = cmd_otr(args, *help);
assert_true(result);
free(help);
}
#else
void cmd_otr_shows_message_when_otr_unsupported(void **state)
{

View File

@ -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_message_when_no_key(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);
@ -34,6 +35,13 @@ 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);
void cmd_otr_start_shows_message_when_in_console(void **state);
void cmd_otr_start_shows_message_when_in_muc(void **state);
void cmd_otr_start_shows_message_when_in_private(void **state);
void cmd_otr_start_shows_message_when_in_duck(void **state);
void cmd_otr_start_shows_message_when_already_started(void **state);
void cmd_otr_start_shows_message_when_no_key(void **state);
void cmd_otr_start_sends_otr_query_message_to_current_recipeint(void **state);
#else
void cmd_otr_shows_message_when_otr_unsupported(void **state);
#endif

View File

@ -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_message_when_no_key),
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),
@ -475,6 +476,13 @@ int main(int argc, char* argv[]) {
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),
unit_test(cmd_otr_start_shows_message_when_in_console),
unit_test(cmd_otr_start_shows_message_when_in_muc),
unit_test(cmd_otr_start_shows_message_when_in_private),
unit_test(cmd_otr_start_shows_message_when_in_duck),
unit_test(cmd_otr_start_shows_message_when_already_started),
unit_test(cmd_otr_start_shows_message_when_no_key),
unit_test(cmd_otr_start_sends_otr_query_message_to_current_recipeint),
#else
unit_test(cmd_otr_shows_message_when_otr_unsupported),
#endif

View File

@ -81,6 +81,13 @@ _mock_bookmark_remove(const char *jid, gboolean autojoin)
return (gboolean)mock();
}
static void
_mock_message_send(const char * const msg, const char * const recipient)
{
check_expected(msg);
check_expected(recipient);
}
void
mock_jabber_connect_with_details(void)
{
@ -219,3 +226,11 @@ expect_and_return_bookmark_remove(char *expected_jid, gboolean expected_autojoin
will_return(_mock_bookmark_remove, removed);
}
void
message_send_expect(char *message, char *recipient)
{
message_send = _mock_message_send;
expect_string(_mock_message_send, msg, message);
expect_string(_mock_message_send, recipient, recipient);
}

View File

@ -31,4 +31,6 @@ void mock_bookmark_remove(void);
void expect_and_return_bookmark_remove(char *expected_jid, gboolean expected_autojoin,
gboolean removed);
void message_send_expect(char *message, char *recipient);
#endif