1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-22 19:45:54 -04:00

Added cmd_otr tests

This commit is contained in:
James Booth 2014-02-16 00:04:53 +00:00
parent f010dfb004
commit 6295336284
5 changed files with 67 additions and 0 deletions

View File

@ -80,6 +80,7 @@ test_sources = \
tests/test_cmd_alias.c \
tests/test_cmd_statuses.c \
tests/test_cmd_bookmark.c \
tests/test_cmd_otr.c \
tests/test_history.c \
tests/test_jid.c \
tests/test_parser.c \

View File

@ -2566,6 +2566,11 @@ gboolean
cmd_otr(gchar **args, struct cmd_help_t help)
{
#ifdef HAVE_LIBOTR
if (args[0] == NULL) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
if (strcmp(args[0], "log") == 0) {
char *choice = args[1];
if (g_strcmp0(choice, "on") == 0) {

45
tests/test_cmd_otr.c Normal file
View 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
View 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

View File

@ -7,6 +7,8 @@
#include <cmocka.h>
#include <sys/stat.h>
#include "config.h"
#include "helpers.h"
#include "test_autocomplete.h"
#include "test_common.h"
@ -16,6 +18,7 @@
#include "test_cmd_rooms.h"
#include "test_cmd_sub.h"
#include "test_cmd_statuses.h"
#include "test_cmd_otr.h"
#include "test_history.h"
#include "test_jid.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_remove_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);