Added cmd_otr tests
This commit is contained in:
@@ -80,6 +80,7 @@ test_sources = \
|
|||||||
tests/test_cmd_alias.c \
|
tests/test_cmd_alias.c \
|
||||||
tests/test_cmd_statuses.c \
|
tests/test_cmd_statuses.c \
|
||||||
tests/test_cmd_bookmark.c \
|
tests/test_cmd_bookmark.c \
|
||||||
|
tests/test_cmd_otr.c \
|
||||||
tests/test_history.c \
|
tests/test_history.c \
|
||||||
tests/test_jid.c \
|
tests/test_jid.c \
|
||||||
tests/test_parser.c \
|
tests/test_parser.c \
|
||||||
|
|||||||
@@ -2566,6 +2566,11 @@ gboolean
|
|||||||
cmd_otr(gchar **args, struct cmd_help_t help)
|
cmd_otr(gchar **args, struct cmd_help_t help)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_LIBOTR
|
#ifdef HAVE_LIBOTR
|
||||||
|
if (args[0] == NULL) {
|
||||||
|
cons_show("Usage: %s", help.usage);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
if (strcmp(args[0], "log") == 0) {
|
if (strcmp(args[0], "log") == 0) {
|
||||||
char *choice = args[1];
|
char *choice = args[1];
|
||||||
if (g_strcmp0(choice, "on") == 0) {
|
if (g_strcmp0(choice, "on") == 0) {
|
||||||
|
|||||||
45
tests/test_cmd_otr.c
Normal file
45
tests/test_cmd_otr.c
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <cmocka.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "ui/mock_ui.h"
|
||||||
|
|
||||||
|
#include "command/command.h"
|
||||||
|
#include "command/commands.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBOTR
|
||||||
|
void cmd_otr_shows_usage_when_no_args(void **state)
|
||||||
|
{
|
||||||
|
mock_cons_show();
|
||||||
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
|
help->usage = "Some usage";
|
||||||
|
gchar *args[] = { NULL };
|
||||||
|
|
||||||
|
expect_cons_show("Usage: Some usage");
|
||||||
|
|
||||||
|
gboolean result = cmd_otr(args, *help);
|
||||||
|
assert_true(result);
|
||||||
|
|
||||||
|
free(help);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
void cmd_otr_shows_message_when_otr_unsupported(void **state)
|
||||||
|
{
|
||||||
|
mock_cons_show();
|
||||||
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
|
gchar *args[] = { "gen", NULL };
|
||||||
|
|
||||||
|
expect_cons_show("This version of Profanity has not been built with OTR support enabled");
|
||||||
|
|
||||||
|
gboolean result = cmd_otr(args, *help);
|
||||||
|
assert_true(result);
|
||||||
|
|
||||||
|
free(help);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
7
tests/test_cmd_otr.h
Normal file
7
tests/test_cmd_otr.h
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBOTR
|
||||||
|
void cmd_otr_shows_usage_when_no_args(void **state);
|
||||||
|
#else
|
||||||
|
void cmd_otr_shows_message_when_otr_unsupported(void **state);
|
||||||
|
#endif
|
||||||
@@ -7,6 +7,8 @@
|
|||||||
#include <cmocka.h>
|
#include <cmocka.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "test_autocomplete.h"
|
#include "test_autocomplete.h"
|
||||||
#include "test_common.h"
|
#include "test_common.h"
|
||||||
@@ -16,6 +18,7 @@
|
|||||||
#include "test_cmd_rooms.h"
|
#include "test_cmd_rooms.h"
|
||||||
#include "test_cmd_sub.h"
|
#include "test_cmd_sub.h"
|
||||||
#include "test_cmd_statuses.h"
|
#include "test_cmd_statuses.h"
|
||||||
|
#include "test_cmd_otr.h"
|
||||||
#include "test_history.h"
|
#include "test_history.h"
|
||||||
#include "test_jid.h"
|
#include "test_jid.h"
|
||||||
#include "test_parser.h"
|
#include "test_parser.h"
|
||||||
@@ -423,6 +426,12 @@ int main(int argc, char* argv[]) {
|
|||||||
unit_test(cmd_bookmark_add_shows_message_when_upated),
|
unit_test(cmd_bookmark_add_shows_message_when_upated),
|
||||||
unit_test(cmd_bookmark_remove_shows_message_when_no_bookmark),
|
unit_test(cmd_bookmark_remove_shows_message_when_no_bookmark),
|
||||||
unit_test(cmd_bookmark_remove_autojoin_shows_message_when_no_bookmark),
|
unit_test(cmd_bookmark_remove_autojoin_shows_message_when_no_bookmark),
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBOTR
|
||||||
|
unit_test(cmd_otr_shows_usage_when_no_args),
|
||||||
|
#else
|
||||||
|
unit_test(cmd_otr_shows_message_when_otr_unsupported),
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
return run_tests(all_tests);
|
return run_tests(all_tests);
|
||||||
|
|||||||
Reference in New Issue
Block a user