2015-06-17 19:12:01 -04:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include <cmocka.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
|
|
|
|
2016-03-31 16:05:02 -04:00
|
|
|
#include "config.h"
|
2015-06-17 19:12:01 -04:00
|
|
|
|
2016-05-22 18:59:52 -04:00
|
|
|
#include "command/cmd_funcs.h"
|
2016-04-18 19:28:22 -04:00
|
|
|
#include "xmpp/xmpp.h"
|
2015-06-17 19:12:01 -04:00
|
|
|
|
|
|
|
#include "ui/stub_ui.h"
|
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
#define CMD_PGP "/pgp"
|
|
|
|
|
2016-03-31 16:05:02 -04:00
|
|
|
#ifdef HAVE_LIBGPGME
|
2015-06-17 19:12:01 -04:00
|
|
|
void
|
|
|
|
cmd_pgp_shows_usage_when_no_args(void** state)
|
|
|
|
{
|
|
|
|
gchar* args[] = { NULL };
|
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
expect_string(cons_bad_cmd_usage, cmd, CMD_PGP);
|
2015-06-17 19:12:01 -04:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_pgp(NULL, CMD_PGP, args);
|
2015-06-17 19:12:01 -04:00
|
|
|
assert_true(result);
|
|
|
|
}
|
|
|
|
|
2015-06-17 20:34:27 -04:00
|
|
|
void
|
|
|
|
cmd_pgp_start_shows_message_when_connection(jabber_conn_status_t conn_status)
|
|
|
|
{
|
|
|
|
gchar* args[] = { "start", NULL };
|
|
|
|
ProfWin window;
|
|
|
|
window.type = WIN_CHAT;
|
|
|
|
|
2016-05-05 18:51:49 -04:00
|
|
|
will_return(connection_get_status, conn_status);
|
2015-06-17 20:34:27 -04:00
|
|
|
|
2023-06-30 08:28:28 -04:00
|
|
|
expect_cons_show("You must be connected to start PGP encryption.");
|
2015-06-17 20:34:27 -04:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_pgp(&window, CMD_PGP, args);
|
2015-06-17 20:34:27 -04:00
|
|
|
assert_true(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmd_pgp_start_shows_message_when_disconnected(void** state)
|
|
|
|
{
|
|
|
|
cmd_pgp_start_shows_message_when_connection(JABBER_DISCONNECTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmd_pgp_start_shows_message_when_disconnecting(void** state)
|
|
|
|
{
|
|
|
|
cmd_pgp_start_shows_message_when_connection(JABBER_DISCONNECTING);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmd_pgp_start_shows_message_when_connecting(void** state)
|
|
|
|
{
|
|
|
|
cmd_pgp_start_shows_message_when_connection(JABBER_CONNECTING);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmd_pgp_start_shows_message_when_no_arg_in_wintype(win_type_t wintype)
|
|
|
|
{
|
|
|
|
gchar* args[] = { "start", NULL };
|
|
|
|
ProfWin window;
|
|
|
|
window.type = wintype;
|
|
|
|
|
2016-05-05 18:51:49 -04:00
|
|
|
will_return(connection_get_status, JABBER_CONNECTED);
|
2015-06-17 20:34:27 -04:00
|
|
|
|
2023-06-30 08:33:17 -04:00
|
|
|
expect_cons_show("You must set recipient in an argument or be in a regular chat window to start PGP encryption.");
|
2015-06-17 20:34:27 -04:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_pgp(&window, CMD_PGP, args);
|
2015-06-17 20:34:27 -04:00
|
|
|
assert_true(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmd_pgp_start_shows_message_when_no_arg_in_console(void** state)
|
|
|
|
{
|
|
|
|
cmd_pgp_start_shows_message_when_no_arg_in_wintype(WIN_CONSOLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmd_pgp_start_shows_message_when_no_arg_in_muc(void** state)
|
|
|
|
{
|
|
|
|
cmd_pgp_start_shows_message_when_no_arg_in_wintype(WIN_MUC);
|
|
|
|
}
|
|
|
|
|
2018-04-11 12:57:50 -04:00
|
|
|
void
|
|
|
|
cmd_pgp_start_shows_message_when_no_arg_in_conf(void** state)
|
2015-06-17 20:34:27 -04:00
|
|
|
{
|
2018-04-11 12:57:50 -04:00
|
|
|
cmd_pgp_start_shows_message_when_no_arg_in_wintype(WIN_CONFIG);
|
2015-06-17 20:34:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmd_pgp_start_shows_message_when_no_arg_in_private(void** state)
|
|
|
|
{
|
|
|
|
cmd_pgp_start_shows_message_when_no_arg_in_wintype(WIN_PRIVATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmd_pgp_start_shows_message_when_no_arg_in_xmlconsole(void** state)
|
|
|
|
{
|
|
|
|
cmd_pgp_start_shows_message_when_no_arg_in_wintype(WIN_XML);
|
|
|
|
}
|
|
|
|
|
2015-06-17 19:12:01 -04:00
|
|
|
#else
|
|
|
|
void
|
|
|
|
cmd_pgp_shows_message_when_pgp_unsupported(void** state)
|
|
|
|
{
|
|
|
|
gchar* args[] = { "gen", NULL };
|
|
|
|
|
|
|
|
expect_cons_show("This version of Profanity has not been built with PGP support enabled");
|
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_pgp(NULL, CMD_PGP, args);
|
2015-06-17 19:12:01 -04:00
|
|
|
assert_true(result);
|
|
|
|
}
|
|
|
|
#endif
|