cleanup: Map test files according to structure in src

For example cmd_account() is located in src/command/cmd_funcs.c.
The unit test was located in tests/unittests/test_cmd_account.c.
Let's move it to a subdirectory like tests/unittests/command/test_cmd_account.c
to correpsond to the same structure.
This commit is contained in:
Michael Vetter
2026-02-28 11:28:24 +01:00
parent 38624f26a5
commit a7408a970e
53 changed files with 74 additions and 74 deletions

View File

@@ -0,0 +1,920 @@
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "xmpp/xmpp.h"
#include "ui/ui.h"
#include "ui/stub_ui.h"
#include "config/accounts.h"
#include "command/cmd_funcs.h"
#define CMD_ACCOUNT "/account"
void
cmd_account_shows_usage_when_not_connected_and_no_args(void** state)
{
gchar* args[] = { NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_shows_account_when_connected_and_no_args(void** state)
{
ProfAccount* account = account_new(g_strdup("jabber_org"), g_strdup("me@jabber.org"), NULL, NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
gchar* args[] = { NULL };
will_return(connection_get_status, JABBER_CONNECTED);
will_return(session_get_account_name, "account_name");
expect_any(accounts_get_account, name);
will_return(accounts_get_account, account);
expect_memory(cons_show_account, account, account, sizeof(ProfAccount));
gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_list_shows_accounts(void** state)
{
gchar* args[] = { "list", NULL };
gchar** accounts = g_new0(gchar*, 4);
accounts[0] = g_strdup("account1");
accounts[1] = g_strdup("account2");
accounts[2] = g_strdup("account3");
accounts[3] = NULL;
will_return(accounts_get_list, accounts);
expect_memory(cons_show_account_list, accounts, accounts, sizeof(accounts));
gboolean result = cmd_account_list(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_show_shows_usage_when_no_arg(void** state)
{
gchar* args[] = { "show", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
gboolean result = cmd_account_show(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_show_shows_message_when_account_does_not_exist(void** state)
{
gchar* args[] = { "show", "account_name", NULL };
expect_any(accounts_get_account, name);
will_return(accounts_get_account, NULL);
expect_cons_show("No such account.");
expect_cons_show("");
gboolean result = cmd_account_show(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_show_shows_account_when_exists(void** state)
{
gchar* args[] = { "show", "account_name", NULL };
ProfAccount* account = account_new(g_strdup("jabber_org"), g_strdup("me@jabber.org"), NULL, NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
expect_any(accounts_get_account, name);
will_return(accounts_get_account, account);
expect_memory(cons_show_account, account, account, sizeof(account));
gboolean result = cmd_account_show(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_add_shows_usage_when_no_arg(void** state)
{
gchar* args[] = { "add", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
gboolean result = cmd_account_add(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_add_adds_account(void** state)
{
gchar* args[] = { "add", "new_account", NULL };
expect_string(accounts_add, jid, "new_account");
expect_value(accounts_add, altdomain, NULL);
expect_value(accounts_add, port, 0);
expect_cons_show("Account created.");
expect_cons_show("");
gboolean result = cmd_account_add(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_enable_shows_usage_when_no_arg(void** state)
{
gchar* args[] = { "enable", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
gboolean result = cmd_account_enable(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_enable_enables_account(void** state)
{
gchar* args[] = { "enable", "account_name", NULL };
expect_string(accounts_enable, name, "account_name");
will_return(accounts_enable, TRUE);
expect_cons_show("Account enabled.");
expect_cons_show("");
gboolean result = cmd_account_enable(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_enable_shows_message_when_account_doesnt_exist(void** state)
{
gchar* args[] = { "enable", "account_name", NULL };
expect_any(accounts_enable, name);
will_return(accounts_enable, FALSE);
expect_cons_show("No such account: account_name");
expect_cons_show("");
gboolean result = cmd_account_enable(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_disable_shows_usage_when_no_arg(void** state)
{
gchar* args[] = { "disable", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
gboolean result = cmd_account_disable(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_disable_disables_account(void** state)
{
gchar* args[] = { "disable", "account_name", NULL };
expect_string(accounts_disable, name, "account_name");
will_return(accounts_disable, TRUE);
expect_cons_show("Account disabled.");
expect_cons_show("");
gboolean result = cmd_account_disable(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_disable_shows_message_when_account_doesnt_exist(void** state)
{
gchar* args[] = { "disable", "account_name", NULL };
expect_any(accounts_disable, name);
will_return(accounts_disable, FALSE);
expect_cons_show("No such account: account_name");
expect_cons_show("");
gboolean result = cmd_account_disable(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_rename_shows_usage_when_no_args(void** state)
{
gchar* args[] = { "rename", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
gboolean result = cmd_account_rename(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_rename_shows_usage_when_one_arg(void** state)
{
gchar* args[] = { "rename", "original_name", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
gboolean result = cmd_account_rename(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_rename_renames_account(void** state)
{
gchar* args[] = { "rename", "original_name", "new_name", NULL };
expect_string(accounts_rename, account_name, "original_name");
expect_string(accounts_rename, new_name, "new_name");
will_return(accounts_rename, TRUE);
expect_cons_show("Account renamed.");
expect_cons_show("");
gboolean result = cmd_account_rename(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_rename_shows_message_when_not_renamed(void** state)
{
gchar* args[] = { "rename", "original_name", "new_name", NULL };
expect_any(accounts_rename, account_name);
expect_any(accounts_rename, new_name);
will_return(accounts_rename, FALSE);
expect_cons_show("Either account original_name doesn't exist, or account new_name already exists.");
expect_cons_show("");
gboolean result = cmd_account_rename(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_shows_usage_when_no_args(void** state)
{
gchar* args[] = { "set", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_shows_usage_when_one_arg(void** state)
{
gchar* args[] = { "set", "a_account", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_shows_usage_when_two_args(void** state)
{
gchar* args[] = { "set", "a_account", "a_property", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_shows_message_when_account_doesnt_exist(void** state)
{
gchar* args[] = { "set", "a_account", "a_property", "a_value", NULL };
expect_string(accounts_account_exists, account_name, "a_account");
will_return(accounts_account_exists, FALSE);
expect_cons_show("Account a_account doesn't exist");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_jid_shows_message_for_malformed_jid(void** state)
{
gchar* args[] = { "set", "a_account", "jid", "@malformed", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_cons_show("Malformed jid: @malformed");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_jid_sets_barejid(void** state)
{
gchar* args[] = { "set", "a_account", "jid", "a_local@a_domain", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_string(accounts_set_jid, account_name, "a_account");
expect_string(accounts_set_jid, value, "a_local@a_domain");
expect_cons_show("Updated jid for account a_account: a_local@a_domain");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_jid_sets_resource(void** state)
{
gchar* args[] = { "set", "a_account", "jid", "a_local@a_domain/a_resource", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_string(accounts_set_jid, account_name, "a_account");
expect_string(accounts_set_jid, value, "a_local@a_domain");
expect_cons_show("Updated jid for account a_account: a_local@a_domain");
expect_string(accounts_set_resource, account_name, "a_account");
expect_string(accounts_set_resource, value, "a_resource");
expect_cons_show("Updated resource for account a_account: a_resource");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_server_sets_server(void** state)
{
gchar* args[] = { "set", "a_account", "server", "a_server", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_string(accounts_set_server, account_name, "a_account");
expect_string(accounts_set_server, value, "a_server");
expect_cons_show("Updated server for account a_account: a_server");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_resource_sets_resource(void** state)
{
gchar* args[] = { "set", "a_account", "resource", "a_resource", NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_string(accounts_set_resource, account_name, "a_account");
expect_string(accounts_set_resource, value, "a_resource");
expect_cons_show("Updated resource for account a_account: a_resource");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_resource_sets_resource_with_online_message(void** state)
{
gchar* args[] = { "set", "a_account", "resource", "a_resource", NULL };
will_return(connection_get_status, JABBER_CONNECTED);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_string(accounts_set_resource, account_name, "a_account");
expect_string(accounts_set_resource, value, "a_resource");
expect_cons_show("Updated resource for account a_account: a_resource, reconnect to pick up the change.");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_password_sets_password(void** state)
{
gchar* args[] = { "set", "a_account", "password", "a_password", NULL };
ProfAccount* account = account_new(g_strdup("a_account"), NULL, NULL, NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_string(accounts_get_account, name, "a_account");
will_return(accounts_get_account, account);
expect_string(accounts_set_password, account_name, "a_account");
expect_string(accounts_set_password, value, "a_password");
expect_cons_show("Updated password for account a_account");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_eval_password_sets_eval_password(void** state)
{
gchar* args[] = { "set", "a_account", "eval_password", "a_password", NULL };
ProfAccount* account = account_new(g_strdup("a_account"), NULL, NULL, NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_string(accounts_get_account, name, "a_account");
will_return(accounts_get_account, account);
expect_string(accounts_set_eval_password, account_name, "a_account");
expect_string(accounts_set_eval_password, value, "a_password");
expect_cons_show("Updated eval_password for account a_account");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_password_when_eval_password_set(void** state)
{
gchar* args[] = { "set", "a_account", "password", "a_password", NULL };
ProfAccount* account = account_new(g_strdup("a_account"), NULL, NULL, g_strdup("a_password"),
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_string(accounts_get_account, name, "a_account");
will_return(accounts_get_account, account);
expect_cons_show("Cannot set password when eval_password is set.");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_eval_password_when_password_set(void** state)
{
gchar* args[] = { "set", "a_account", "eval_password", "a_password", NULL };
ProfAccount* account = account_new(g_strdup("a_account"), NULL, g_strdup("a_password"), NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_string(accounts_get_account, name, "a_account");
will_return(accounts_get_account, account);
expect_cons_show("Cannot set eval_password when password is set.");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_muc_sets_muc(void** state)
{
gchar* args[] = { "set", "a_account", "muc", "a_muc", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_string(accounts_set_muc_service, account_name, "a_account");
expect_string(accounts_set_muc_service, value, "a_muc");
expect_cons_show("Updated muc service for account a_account: a_muc");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_nick_sets_nick(void** state)
{
gchar* args[] = { "set", "a_account", "nick", "a_nick", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_string(accounts_set_muc_nick, account_name, "a_account");
expect_string(accounts_set_muc_nick, value, "a_nick");
expect_cons_show("Updated muc nick for account a_account: a_nick");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_show_message_for_missing_otr_policy(void** state)
{
gchar* args[] = { "set", "a_account", "otr", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_show_message_for_invalid_otr_policy(void** state)
{
gchar* args[] = { "set", "a_account", "otr", "bad_otr_policy", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_cons_show("Invalid OTR policy: 'bad_otr_policy'");
expect_cons_show("OTR policy must be one of: 'manual', 'opportunistic' or 'always'.");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_otr_sets_otr(void** state)
{
gchar* args[] = { "set", "a_account", "otr", "opportunistic", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_string(accounts_set_otr_policy, account_name, "a_account");
expect_string(accounts_set_otr_policy, value, "opportunistic");
expect_cons_show("Updated OTR policy for account a_account: opportunistic");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_status_shows_message_when_invalid_status(void** state)
{
gchar* args[] = { "set", "a_account", "status", "bad_status", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_cons_show("Invalid status: bad_status");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_status_sets_status_when_valid(void** state)
{
gchar* args[] = { "set", "a_account", "status", "away", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_string(accounts_set_login_presence, account_name, "a_account");
expect_string(accounts_set_login_presence, value, "away");
expect_cons_show("Updated login status for account a_account: away");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_status_sets_status_when_last(void** state)
{
gchar* args[] = { "set", "a_account", "status", "last", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_string(accounts_set_login_presence, account_name, "a_account");
expect_string(accounts_set_login_presence, value, "last");
expect_cons_show("Updated login status for account a_account: last");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_invalid_presence_string_priority_shows_message(void** state)
{
gchar* args[] = { "set", "a_account", "blah", "10", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_cons_show("Invalid property: blah");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_last_priority_shows_message(void** state)
{
gchar* args[] = { "set", "a_account", "last", "10", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_cons_show("Invalid property: last");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_online_priority_sets_preference(void** state)
{
gchar* args[] = { "set", "a_account", "online", "10", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_string(accounts_set_priority_online, account_name, "a_account");
expect_value(accounts_set_priority_online, value, 10);
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_cons_show("Updated online priority for account a_account: 10");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_chat_priority_sets_preference(void** state)
{
gchar* args[] = { "set", "a_account", "chat", "10", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_string(accounts_set_priority_chat, account_name, "a_account");
expect_value(accounts_set_priority_chat, value, 10);
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_cons_show("Updated chat priority for account a_account: 10");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_away_priority_sets_preference(void** state)
{
gchar* args[] = { "set", "a_account", "away", "10", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_string(accounts_set_priority_away, account_name, "a_account");
expect_value(accounts_set_priority_away, value, 10);
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_cons_show("Updated away priority for account a_account: 10");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_xa_priority_sets_preference(void** state)
{
gchar* args[] = { "set", "a_account", "xa", "10", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_string(accounts_set_priority_xa, account_name, "a_account");
expect_value(accounts_set_priority_xa, value, 10);
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_cons_show("Updated xa priority for account a_account: 10");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_dnd_priority_sets_preference(void** state)
{
gchar* args[] = { "set", "a_account", "dnd", "10", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_string(accounts_set_priority_dnd, account_name, "a_account");
expect_value(accounts_set_priority_dnd, value, 10);
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_cons_show("Updated dnd priority for account a_account: 10");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_priority_too_low_shows_message(void** state)
{
gchar* args[] = { "set", "a_account", "online", "-150", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_cons_show("Value -150 out of range. Must be in -128..127.");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_priority_too_high_shows_message(void** state)
{
gchar* args[] = { "set", "a_account", "online", "150", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_cons_show("Value 150 out of range. Must be in -128..127.");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_priority_when_not_number_shows_message(void** state)
{
gchar* args[] = { "set", "a_account", "online", "abc", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_cons_show("Could not convert \"abc\" to a number.");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_priority_when_empty_shows_message(void** state)
{
gchar* args[] = { "set", "a_account", "online", "", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_cons_show("Could not convert \"\" to a number.");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_set_priority_updates_presence_when_account_connected_with_presence(void** state)
{
gchar* args[] = { "set", "a_account", "online", "10", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_any(accounts_set_priority_online, account_name);
expect_any(accounts_set_priority_online, value);
will_return(connection_get_status, JABBER_CONNECTED);
expect_any(accounts_get_last_presence, account_name);
will_return(accounts_get_last_presence, RESOURCE_ONLINE);
will_return(session_get_account_name, "a_account");
#ifdef HAVE_LIBGPGME
ProfAccount* account = account_new(g_strdup("a_account"), g_strdup("a_jid"), NULL, NULL, TRUE, NULL, 5222, g_strdup("a_resource"),
NULL, NULL, 10, 10, 10, 10, 10, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
will_return(session_get_account_name, "a_account");
expect_any(accounts_get_account, name);
will_return(accounts_get_account, account);
#endif
expect_value(presence_send, status, RESOURCE_ONLINE);
expect_value(presence_send, idle, 0);
expect_value(presence_send, signed_status, NULL);
expect_cons_show("Updated online priority for account a_account: 10");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_clear_shows_usage_when_no_args(void** state)
{
gchar* args[] = { "clear", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
gboolean result = cmd_account_clear(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_clear_shows_usage_when_one_arg(void** state)
{
gchar* args[] = { "clear", "a_account", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT);
gboolean result = cmd_account_clear(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_clear_shows_message_when_account_doesnt_exist(void** state)
{
gchar* args[] = { "clear", "a_account", "a_property", NULL };
expect_string(accounts_account_exists, account_name, "a_account");
will_return(accounts_account_exists, FALSE);
expect_cons_show("Account a_account doesn't exist");
expect_cons_show("");
gboolean result = cmd_account_clear(NULL, CMD_ACCOUNT, args);
assert_true(result);
}
void
cmd_account_clear_shows_message_when_invalid_property(void** state)
{
gchar* args[] = { "clear", "a_account", "badproperty", NULL };
expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE);
expect_cons_show("Invalid property: badproperty");
expect_cons_show("");
gboolean result = cmd_account_clear(NULL, CMD_ACCOUNT, args);
assert_true(result);
}

View File

@@ -0,0 +1,56 @@
void cmd_account_shows_usage_when_not_connected_and_no_args(void** state);
void cmd_account_shows_account_when_connected_and_no_args(void** state);
void cmd_account_list_shows_accounts(void** state);
void cmd_account_show_shows_usage_when_no_arg(void** state);
void cmd_account_show_shows_message_when_account_does_not_exist(void** state);
void cmd_account_show_shows_account_when_exists(void** state);
void cmd_account_add_shows_usage_when_no_arg(void** state);
void cmd_account_add_adds_account(void** state);
void cmd_account_enable_shows_usage_when_no_arg(void** state);
void cmd_account_enable_enables_account(void** state);
void cmd_account_enable_shows_message_when_account_doesnt_exist(void** state);
void cmd_account_disable_shows_usage_when_no_arg(void** state);
void cmd_account_disable_disables_account(void** state);
void cmd_account_disable_shows_message_when_account_doesnt_exist(void** state);
void cmd_account_rename_shows_usage_when_no_args(void** state);
void cmd_account_rename_shows_usage_when_one_arg(void** state);
void cmd_account_rename_renames_account(void** state);
void cmd_account_rename_shows_message_when_not_renamed(void** state);
void cmd_account_set_shows_usage_when_no_args(void** state);
void cmd_account_set_shows_usage_when_one_arg(void** state);
void cmd_account_set_shows_usage_when_two_args(void** state);
void cmd_account_set_shows_message_when_account_doesnt_exist(void** state);
void cmd_account_set_jid_shows_message_for_malformed_jid(void** state);
void cmd_account_set_jid_sets_barejid(void** state);
void cmd_account_set_jid_sets_resource(void** state);
void cmd_account_set_server_sets_server(void** state);
void cmd_account_set_resource_sets_resource(void** state);
void cmd_account_set_resource_sets_resource_with_online_message(void** state);
void cmd_account_set_password_sets_password(void** state);
void cmd_account_set_eval_password_sets_eval_password(void** state);
void cmd_account_set_password_when_eval_password_set(void** state);
void cmd_account_set_eval_password_when_password_set(void** state);
void cmd_account_set_muc_sets_muc(void** state);
void cmd_account_set_nick_sets_nick(void** state);
void cmd_account_show_message_for_missing_otr_policy(void** state);
void cmd_account_show_message_for_invalid_otr_policy(void** state);
void cmd_account_set_otr_sets_otr(void** state);
void cmd_account_set_status_shows_message_when_invalid_status(void** state);
void cmd_account_set_status_sets_status_when_valid(void** state);
void cmd_account_set_status_sets_status_when_last(void** state);
void cmd_account_set_invalid_presence_string_priority_shows_message(void** state);
void cmd_account_set_last_priority_shows_message(void** state);
void cmd_account_set_online_priority_sets_preference(void** state);
void cmd_account_set_chat_priority_sets_preference(void** state);
void cmd_account_set_away_priority_sets_preference(void** state);
void cmd_account_set_xa_priority_sets_preference(void** state);
void cmd_account_set_dnd_priority_sets_preference(void** state);
void cmd_account_set_priority_too_low_shows_message(void** state);
void cmd_account_set_priority_too_high_shows_message(void** state);
void cmd_account_set_priority_when_not_number_shows_message(void** state);
void cmd_account_set_priority_when_empty_shows_message(void** state);
void cmd_account_set_priority_updates_presence_when_account_connected_with_presence(void** state);
void cmd_account_clear_shows_usage_when_no_args(void** state);
void cmd_account_clear_shows_usage_when_one_arg(void** state);
void cmd_account_clear_shows_message_when_account_doesnt_exist(void** state);
void cmd_account_clear_shows_message_when_invalid_property(void** state);

View File

@@ -0,0 +1,138 @@
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "xmpp/xmpp.h"
#include "ui/ui.h"
#include "ui/stub_ui.h"
#include "config/preferences.h"
#include "command/cmd_defs.h"
#include "command/cmd_funcs.h"
#include "command/cmd_ac.h"
#define CMD_ALIAS "/alias"
void
cmd_alias_add_shows_usage_when_no_args(void** state)
{
gchar* args[] = { "add", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_ALIAS);
gboolean result = cmd_alias(NULL, CMD_ALIAS, args);
assert_true(result);
}
void
cmd_alias_add_shows_usage_when_no_value(void** state)
{
gchar* args[] = { "add", "alias", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_ALIAS);
gboolean result = cmd_alias(NULL, CMD_ALIAS, args);
assert_true(result);
}
void
cmd_alias_remove_shows_usage_when_no_args(void** state)
{
gchar* args[] = { "remove", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_ALIAS);
gboolean result = cmd_alias(NULL, CMD_ALIAS, args);
assert_true(result);
}
void
cmd_alias_show_usage_when_invalid_subcmd(void** state)
{
gchar* args[] = { "blah", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_ALIAS);
gboolean result = cmd_alias(NULL, CMD_ALIAS, args);
assert_true(result);
}
void
cmd_alias_add_adds_alias(void** state)
{
gchar* args[] = { "add", "hc", "/help commands", NULL };
expect_cons_show("Command alias added /hc -> /help commands");
gboolean result = cmd_alias(NULL, CMD_ALIAS, args);
assert_true(result);
gchar* returned_val = prefs_get_alias("hc");
assert_string_equal("/help commands", returned_val);
g_free(returned_val);
}
void
cmd_alias_add_shows_message_when_exists(void** state)
{
gchar* args[] = { "add", "hc", "/help commands", NULL };
prefs_add_alias("hc", "/help commands");
cmd_ac_add("/hc");
expect_cons_show("Command or alias '/hc' already exists.");
gboolean result = cmd_alias(NULL, CMD_ALIAS, args);
assert_true(result);
}
void
cmd_alias_remove_removes_alias(void** state)
{
gchar* args[] = { "remove", "hn", NULL };
prefs_add_alias("hn", "/help navigation");
expect_cons_show("Command alias removed -> /hn");
gboolean result = cmd_alias(NULL, CMD_ALIAS, args);
assert_true(result);
gchar* returned_val = prefs_get_alias("hn");
assert_null(returned_val);
g_free(returned_val);
}
void
cmd_alias_remove_shows_message_when_no_alias(void** state)
{
gchar* args[] = { "remove", "hn", NULL };
expect_cons_show("No such command alias /hn");
gboolean result = cmd_alias(NULL, CMD_ALIAS, args);
assert_true(result);
}
void
cmd_alias_list_shows_all_aliases(void** state)
{
gchar* args[] = { "list", NULL };
prefs_add_alias("vy", "/vercheck on");
prefs_add_alias("q", "/quit");
prefs_add_alias("hn", "/help navigation");
prefs_add_alias("hc", "/help commands");
prefs_add_alias("vn", "/vercheck off");
// write a custom checker to check the correct list is passed
expect_any(cons_show_aliases, aliases);
gboolean result = cmd_alias(NULL, CMD_ALIAS, args);
assert_true(result);
}

View File

@@ -0,0 +1,9 @@
void cmd_alias_add_shows_usage_when_no_args(void** state);
void cmd_alias_add_shows_usage_when_no_value(void** state);
void cmd_alias_remove_shows_usage_when_no_args(void** state);
void cmd_alias_show_usage_when_invalid_subcmd(void** state);
void cmd_alias_add_adds_alias(void** state);
void cmd_alias_add_shows_message_when_exists(void** state);
void cmd_alias_remove_removes_alias(void** state);
void cmd_alias_remove_shows_message_when_no_alias(void** state);
void cmd_alias_list_shows_all_aliases(void** state);

View File

@@ -0,0 +1,408 @@
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "xmpp/xmpp.h"
#include "ui/ui.h"
#include "ui/stub_ui.h"
#include "xmpp/muc.h"
#include "common.h"
#include "command/cmd_funcs.h"
#include "xmpp/bookmark.h"
#include "helpers.h"
#define CMD_BOOKMARK "/bookmark"
static void
test_with_connection_status(jabber_conn_status_t status)
{
ProfWin window;
window.type = WIN_CONSOLE;
will_return(connection_get_status, status);
expect_cons_show("You are not currently connected.");
gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, NULL);
assert_true(result);
}
void
cmd_bookmark_shows_message_when_disconnected(void** state)
{
test_with_connection_status(JABBER_DISCONNECTED);
}
void
cmd_bookmark_shows_message_when_disconnecting(void** state)
{
test_with_connection_status(JABBER_DISCONNECTING);
}
void
cmd_bookmark_shows_message_when_connecting(void** state)
{
test_with_connection_status(JABBER_CONNECTING);
}
void
cmd_bookmark_shows_usage_when_no_args(void** state)
{
gchar* args[] = { NULL };
ProfWin window;
window.type = WIN_CONSOLE;
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(cons_bad_cmd_usage, cmd, CMD_BOOKMARK);
gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, args);
assert_true(result);
}
/*
static void _free_bookmark(Bookmark *bookmark)
{
free(bookmark->barejid);
free(bookmark->nick);
free(bookmark);
}
*/
static gboolean
_cmp_bookmark(Bookmark* bm1, Bookmark* bm2)
{
if (strcmp(bm1->barejid, bm2->barejid) != 0) {
return FALSE;
}
if (strcmp(bm1->nick, bm2->nick) != 0) {
return FALSE;
}
if (bm1->autojoin != bm2->autojoin) {
return FALSE;
}
return TRUE;
}
void
cmd_bookmark_list_shows_bookmarks(void** state)
{
gchar* args[] = { "list", NULL };
GList* bookmarks = NULL;
ProfWin window;
window.type = WIN_CONSOLE;
Bookmark* bm1 = g_new0(Bookmark, 1);
bm1->barejid = strdup("room1@conf.org");
bm1->nick = strdup("bob");
bm1->autojoin = FALSE;
Bookmark* bm2 = g_new0(Bookmark, 1);
bm2->barejid = strdup("room2@conf.org");
bm2->nick = strdup("steve");
bm2->autojoin = TRUE;
Bookmark* bm3 = g_new0(Bookmark, 1);
bm3->barejid = strdup("room3@conf.org");
bm3->nick = strdup("dave");
bm3->autojoin = TRUE;
Bookmark* bm4 = g_new0(Bookmark, 1);
bm4->barejid = strdup("room4@conf.org");
bm4->nick = strdup("james");
bm4->autojoin = FALSE;
Bookmark* bm5 = g_new0(Bookmark, 1);
bm5->barejid = strdup("room5@conf.org");
bm5->nick = strdup("mike");
bm5->autojoin = FALSE;
bookmarks = g_list_append(bookmarks, bm1);
bookmarks = g_list_append(bookmarks, bm2);
bookmarks = g_list_append(bookmarks, bm3);
bookmarks = g_list_append(bookmarks, bm4);
bookmarks = g_list_append(bookmarks, bm5);
will_return(connection_get_status, JABBER_CONNECTED);
will_return(bookmark_get_list, bookmarks);
// TODO - Custom list compare
glist_set_cmp((GCompareFunc)_cmp_bookmark);
expect_any(cons_show_bookmarks, list);
gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, args);
assert_true(result);
free(bm1->barejid);
free(bm1->nick);
free(bm1);
free(bm2->barejid);
free(bm2->nick);
free(bm2);
free(bm3->barejid);
free(bm3->nick);
free(bm3);
free(bm4->barejid);
free(bm4->nick);
free(bm4);
free(bm5->barejid);
free(bm5->nick);
free(bm5);
}
void
cmd_bookmark_add_shows_message_when_invalid_jid(void** state)
{
char* jid = "room";
gchar* args[] = { "add", jid, NULL };
ProfWin window;
window.type = WIN_CONSOLE;
will_return(connection_get_status, JABBER_CONNECTED);
expect_cons_show("Invalid room, must be of the form room@domain.tld");
expect_cons_show("");
gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, args);
assert_true(result);
}
void
cmd_bookmark_add_adds_bookmark_with_jid(void** state)
{
char* jid = "room@conf.server";
gchar* args[] = { "add", jid, NULL };
ProfWin window;
window.type = WIN_CONSOLE;
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(bookmark_add, jid, jid);
expect_any(bookmark_add, nick);
expect_any(bookmark_add, password);
expect_any(bookmark_add, autojoin_str);
will_return(bookmark_add, TRUE);
expect_cons_show("Bookmark added for room@conf.server.");
gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, args);
assert_true(result);
}
void
cmd_bookmark_uses_roomjid_in_room(void** state)
{
gchar* args[] = { NULL };
ProfMucWin muc_win;
muc_win.window.type = WIN_MUC;
muc_win.memcheck = PROFMUCWIN_MEMCHECK;
muc_win.roomjid = "room@conf.server";
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(bookmark_add, jid, muc_win.roomjid);
expect_any(bookmark_add, nick);
expect_any(bookmark_add, password);
expect_any(bookmark_add, autojoin_str);
will_return(bookmark_add, TRUE);
expect_win_println("Bookmark added for room@conf.server.");
gboolean result = cmd_bookmark(&muc_win.window, CMD_BOOKMARK, args);
assert_true(result);
}
void
cmd_bookmark_add_uses_roomjid_in_room(void** state)
{
gchar* args[] = { "add", NULL };
ProfMucWin muc_win;
muc_win.window.type = WIN_MUC;
muc_win.memcheck = PROFMUCWIN_MEMCHECK;
muc_win.roomjid = "room@conf.server";
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(bookmark_add, jid, muc_win.roomjid);
expect_any(bookmark_add, nick);
expect_any(bookmark_add, password);
expect_any(bookmark_add, autojoin_str);
will_return(bookmark_add, TRUE);
expect_win_println("Bookmark added for room@conf.server.");
gboolean result = cmd_bookmark(&muc_win.window, CMD_BOOKMARK, args);
assert_true(result);
}
void
cmd_bookmark_add_uses_supplied_jid_in_room(void** state)
{
char* jid = "room1@conf.server";
gchar* args[] = { "add", jid, NULL };
ProfMucWin muc_win;
muc_win.window.type = WIN_MUC;
muc_win.memcheck = PROFMUCWIN_MEMCHECK;
muc_win.roomjid = "room2@conf.server";
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(bookmark_add, jid, jid);
expect_any(bookmark_add, nick);
expect_any(bookmark_add, password);
expect_any(bookmark_add, autojoin_str);
will_return(bookmark_add, TRUE);
expect_cons_show("Bookmark added for room1@conf.server.");
gboolean result = cmd_bookmark(&muc_win.window, CMD_BOOKMARK, args);
assert_true(result);
}
void
cmd_bookmark_add_adds_bookmark_with_jid_nick(void** state)
{
char* jid = "room@conf.server";
char* nick = "bob";
gchar* args[] = { "add", jid, "nick", nick, NULL };
ProfWin window;
window.type = WIN_CONSOLE;
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(bookmark_add, jid, jid);
expect_string(bookmark_add, nick, nick);
expect_any(bookmark_add, password);
expect_any(bookmark_add, autojoin_str);
will_return(bookmark_add, TRUE);
expect_cons_show("Bookmark added for room@conf.server.");
gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, args);
assert_true(result);
}
void
cmd_bookmark_add_adds_bookmark_with_jid_autojoin(void** state)
{
char* jid = "room@conf.server";
gchar* args[] = { "add", jid, "autojoin", "on", NULL };
ProfWin window;
window.type = WIN_CONSOLE;
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(bookmark_add, jid, jid);
expect_any(bookmark_add, nick);
expect_any(bookmark_add, password);
expect_string(bookmark_add, autojoin_str, "on");
will_return(bookmark_add, TRUE);
expect_cons_show("Bookmark added for room@conf.server.");
gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, args);
assert_true(result);
}
void
cmd_bookmark_add_adds_bookmark_with_jid_nick_autojoin(void** state)
{
char* jid = "room@conf.server";
char* nick = "bob";
gchar* args[] = { "add", jid, "nick", nick, "autojoin", "on", NULL };
ProfWin window;
window.type = WIN_CONSOLE;
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(bookmark_add, jid, jid);
expect_string(bookmark_add, nick, nick);
expect_any(bookmark_add, password);
expect_string(bookmark_add, autojoin_str, "on");
will_return(bookmark_add, TRUE);
expect_cons_show("Bookmark added for room@conf.server.");
gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, args);
assert_true(result);
}
void
cmd_bookmark_remove_removes_bookmark(void** state)
{
char* jid = "room@conf.server";
gchar* args[] = { "remove", jid, NULL };
ProfWin window;
window.type = WIN_CONSOLE;
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(bookmark_remove, jid, jid);
will_return(bookmark_remove, TRUE);
expect_cons_show("Bookmark removed for room@conf.server.");
gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, args);
assert_true(result);
}
void
cmd_bookmark_remove_shows_message_when_no_bookmark(void** state)
{
char* jid = "room@conf.server";
gchar* args[] = { "remove", jid, NULL };
ProfWin window;
window.type = WIN_CONSOLE;
will_return(connection_get_status, JABBER_CONNECTED);
expect_any(bookmark_remove, jid);
will_return(bookmark_remove, FALSE);
expect_cons_show("No bookmark exists for room@conf.server.");
gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, args);
assert_true(result);
}
void
cmd_bookmark_remove_uses_roomjid_in_room(void** state)
{
gchar* args[] = { "remove", NULL };
ProfMucWin muc_win;
muc_win.window.type = WIN_MUC;
muc_win.memcheck = PROFMUCWIN_MEMCHECK;
muc_win.roomjid = "room@conf.server";
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(bookmark_remove, jid, muc_win.roomjid);
will_return(bookmark_remove, TRUE);
expect_win_println("Bookmark removed for room@conf.server.");
gboolean result = cmd_bookmark(&muc_win.window, CMD_BOOKMARK, args);
assert_true(result);
}
void
cmd_bookmark_remove_uses_supplied_jid_in_room(void** state)
{
char* jid = "room1@conf.server";
gchar* args[] = { "remove", jid, NULL };
ProfMucWin muc_win;
muc_win.window.type = WIN_MUC;
muc_win.memcheck = PROFMUCWIN_MEMCHECK;
muc_win.roomjid = "room2@conf.server";
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(bookmark_remove, jid, jid);
will_return(bookmark_remove, TRUE);
expect_cons_show("Bookmark removed for room1@conf.server.");
gboolean result = cmd_bookmark(&muc_win.window, CMD_BOOKMARK, args);
assert_true(result);
}

View File

@@ -0,0 +1,18 @@
void cmd_bookmark_shows_message_when_disconnected(void** state);
void cmd_bookmark_shows_message_when_disconnecting(void** state);
void cmd_bookmark_shows_message_when_connecting(void** state);
void cmd_bookmark_shows_message_when_undefined(void** state);
void cmd_bookmark_shows_usage_when_no_args(void** state);
void cmd_bookmark_list_shows_bookmarks(void** state);
void cmd_bookmark_add_shows_message_when_invalid_jid(void** state);
void cmd_bookmark_add_adds_bookmark_with_jid(void** state);
void cmd_bookmark_uses_roomjid_in_room(void** state);
void cmd_bookmark_add_uses_roomjid_in_room(void** state);
void cmd_bookmark_add_uses_supplied_jid_in_room(void** state);
void cmd_bookmark_remove_uses_roomjid_in_room(void** state);
void cmd_bookmark_remove_uses_supplied_jid_in_room(void** state);
void cmd_bookmark_add_adds_bookmark_with_jid_nick(void** state);
void cmd_bookmark_add_adds_bookmark_with_jid_autojoin(void** state);
void cmd_bookmark_add_adds_bookmark_with_jid_nick_autojoin(void** state);
void cmd_bookmark_remove_removes_bookmark(void** state);
void cmd_bookmark_remove_shows_message_when_no_bookmark(void** state);

View File

@@ -0,0 +1,443 @@
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "xmpp/xmpp.h"
#include "ui/ui.h"
#include "ui/stub_ui.h"
#include "command/cmd_funcs.h"
#include "config/accounts.h"
#define CMD_CONNECT "/connect"
static void
test_with_connection_status(jabber_conn_status_t status)
{
will_return(connection_get_status, status);
expect_cons_show("You are either connected already, or a login is in process.");
gboolean result = cmd_connect(NULL, CMD_CONNECT, NULL);
assert_true(result);
}
void
cmd_connect_shows_message_when_disconnecting(void** state)
{
test_with_connection_status(JABBER_DISCONNECTING);
}
void
cmd_connect_shows_message_when_connecting(void** state)
{
test_with_connection_status(JABBER_CONNECTING);
}
void
cmd_connect_shows_message_when_connected(void** state)
{
test_with_connection_status(JABBER_CONNECTED);
}
void
cmd_connect_when_no_account(void** state)
{
gchar* args[] = { "user@server.org", NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_string(accounts_get_account, name, "user@server.org");
will_return(accounts_get_account, NULL);
will_return(ui_ask_password, g_strdup("password"));
expect_cons_show("Connecting as user@server.org");
expect_string(session_connect_with_details, jid, "user@server.org");
expect_string(session_connect_with_details, passwd, "password");
expect_value(session_connect_with_details, altdomain, NULL);
expect_value(session_connect_with_details, port, 0);
will_return(session_connect_with_details, JABBER_CONNECTING);
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}
void
cmd_connect_fail_message(void** state)
{
gchar* args[] = { "user@server.org", NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_any(accounts_get_account, name);
will_return(accounts_get_account, NULL);
will_return(ui_ask_password, g_strdup("password"));
expect_cons_show("Connecting as user@server.org");
expect_any(session_connect_with_details, jid);
expect_any(session_connect_with_details, passwd);
expect_any(session_connect_with_details, altdomain);
expect_any(session_connect_with_details, port);
will_return(session_connect_with_details, JABBER_DISCONNECTED);
expect_cons_show_error("Connection attempt for user@server.org failed.");
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}
void
cmd_connect_lowercases_argument_with_no_account(void** state)
{
gchar* args[] = { "USER@server.ORG", NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_string(accounts_get_account, name, "USER@server.ORG");
will_return(accounts_get_account, NULL);
will_return(ui_ask_password, g_strdup("password"));
expect_cons_show("Connecting as user@server.org");
expect_string(session_connect_with_details, jid, "user@server.org");
expect_string(session_connect_with_details, passwd, "password");
expect_value(session_connect_with_details, altdomain, NULL);
expect_value(session_connect_with_details, port, 0);
will_return(session_connect_with_details, JABBER_CONNECTING);
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}
void
cmd_connect_lowercases_argument_with_account(void** state)
{
gchar* args[] = { "Jabber_org", NULL };
ProfAccount* account = account_new(g_strdup("Jabber_org"), g_strdup("me@jabber.org"), g_strdup("password"), NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_any(accounts_get_account, name);
will_return(accounts_get_account, account);
expect_cons_show("Connecting with account Jabber_org as me@jabber.org");
expect_memory(session_connect_with_account, account, account, sizeof(ProfAccount));
will_return(session_connect_with_account, JABBER_CONNECTING);
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}
void
cmd_connect_asks_password_when_not_in_account(void** state)
{
gchar* args[] = { "jabber_org", NULL };
ProfAccount* account = account_new(g_strdup("jabber_org"), g_strdup("me@jabber.org"), NULL, NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_any(accounts_get_account, name);
will_return(accounts_get_account, account);
will_return(ui_ask_password, g_strdup("password"));
expect_cons_show("Connecting with account jabber_org as me@jabber.org");
expect_any(session_connect_with_account, account);
will_return(session_connect_with_account, JABBER_CONNECTING);
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}
void
cmd_connect_shows_usage_when_no_server_value(void** state)
{
gchar* args[] = { "user@server.org", "server", NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT);
expect_cons_show("");
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}
void
cmd_connect_shows_usage_when_server_no_port_value(void** state)
{
gchar* args[] = { "user@server.org", "server", "aserver", "port", NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT);
expect_cons_show("");
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}
void
cmd_connect_shows_usage_when_no_port_value(void** state)
{
gchar* args[] = { "user@server.org", "port", NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT);
expect_cons_show("");
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}
void
cmd_connect_shows_usage_when_port_no_server_value(void** state)
{
gchar* args[] = { "user@server.org", "port", "5678", "server", NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT);
expect_cons_show("");
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}
void
cmd_connect_shows_message_when_port_0(void** state)
{
gchar* args[] = { "user@server.org", "port", "0", NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_cons_show("Value 0 out of range. Must be in 1..65535.");
expect_cons_show("");
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}
void
cmd_connect_shows_message_when_port_minus1(void** state)
{
gchar* args[] = { "user@server.org", "port", "-1", NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_cons_show("Value -1 out of range. Must be in 1..65535.");
expect_cons_show("");
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}
void
cmd_connect_shows_message_when_port_65536(void** state)
{
gchar* args[] = { "user@server.org", "port", "65536", NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_cons_show("Value 65536 out of range. Must be in 1..65535.");
expect_cons_show("");
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}
void
cmd_connect_shows_message_when_port_contains_chars(void** state)
{
gchar* args[] = { "user@server.org", "port", "52f66", NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_cons_show("Could not convert \"52f66\" to a number.");
expect_cons_show("");
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}
void
cmd_connect_shows_usage_when_server_provided_twice(void** state)
{
gchar* args[] = { "user@server.org", "server", "server1", "server", "server2", NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT);
expect_cons_show("");
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}
void
cmd_connect_shows_usage_when_port_provided_twice(void** state)
{
gchar* args[] = { "user@server.org", "port", "1111", "port", "1111", NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT);
expect_cons_show("");
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}
void
cmd_connect_shows_usage_when_invalid_first_property(void** state)
{
gchar* args[] = { "user@server.org", "wrong", "server", NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT);
expect_cons_show("");
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}
void
cmd_connect_shows_usage_when_invalid_second_property(void** state)
{
gchar* args[] = { "user@server.org", "server", "aserver", "wrong", "1234", NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT);
expect_cons_show("");
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}
void
cmd_connect_with_server_when_provided(void** state)
{
gchar* args[] = { "user@server.org", "server", "aserver", NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_string(accounts_get_account, name, "user@server.org");
will_return(accounts_get_account, NULL);
will_return(ui_ask_password, g_strdup("password"));
expect_cons_show("Connecting as user@server.org");
expect_string(session_connect_with_details, jid, "user@server.org");
expect_string(session_connect_with_details, passwd, "password");
expect_string(session_connect_with_details, altdomain, "aserver");
expect_value(session_connect_with_details, port, 0);
will_return(session_connect_with_details, JABBER_CONNECTING);
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}
void
cmd_connect_with_port_when_provided(void** state)
{
gchar* args[] = { "user@server.org", "port", "5432", NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_string(accounts_get_account, name, "user@server.org");
will_return(accounts_get_account, NULL);
will_return(ui_ask_password, g_strdup("password"));
expect_cons_show("Connecting as user@server.org");
expect_string(session_connect_with_details, jid, "user@server.org");
expect_string(session_connect_with_details, passwd, "password");
expect_value(session_connect_with_details, altdomain, NULL);
expect_value(session_connect_with_details, port, 5432);
will_return(session_connect_with_details, JABBER_CONNECTING);
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}
void
cmd_connect_with_server_and_port_when_provided(void** state)
{
gchar* args[] = { "user@server.org", "port", "5432", "server", "aserver", NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_string(accounts_get_account, name, "user@server.org");
will_return(accounts_get_account, NULL);
will_return(ui_ask_password, g_strdup("password"));
expect_cons_show("Connecting as user@server.org");
expect_string(session_connect_with_details, jid, "user@server.org");
expect_string(session_connect_with_details, passwd, "password");
expect_string(session_connect_with_details, altdomain, "aserver");
expect_value(session_connect_with_details, port, 5432);
will_return(session_connect_with_details, JABBER_CONNECTING);
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}
void
cmd_connect_shows_message_when_connecting_with_account(void** state)
{
gchar* args[] = { "jabber_org", NULL };
ProfAccount* account = account_new(g_strdup("jabber_org"), g_strdup("user@jabber.org"), g_strdup("password"), NULL,
TRUE, NULL, 0, g_strdup("laptop"), NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_any(accounts_get_account, name);
will_return(accounts_get_account, account);
expect_cons_show("Connecting with account jabber_org as user@jabber.org/laptop");
expect_any(session_connect_with_account, account);
will_return(session_connect_with_account, JABBER_CONNECTING);
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}
void
cmd_connect_connects_with_account(void** state)
{
gchar* args[] = { "jabber_org", NULL };
ProfAccount* account = account_new(g_strdup("jabber_org"), g_strdup("me@jabber.org"), g_strdup("password"), NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_any(accounts_get_account, name);
will_return(accounts_get_account, account);
expect_cons_show("Connecting with account jabber_org as me@jabber.org");
expect_memory(session_connect_with_account, account, account, sizeof(ProfAccount));
will_return(session_connect_with_account, JABBER_CONNECTING);
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
assert_true(result);
}

View File

@@ -0,0 +1,27 @@
void cmd_connect_shows_message_when_disconnecting(void** state);
void cmd_connect_shows_message_when_connecting(void** state);
void cmd_connect_shows_message_when_connected(void** state);
void cmd_connect_shows_message_when_undefined(void** state);
void cmd_connect_when_no_account(void** state);
void cmd_connect_with_altdomain_when_provided(void** state);
void cmd_connect_fail_message(void** state);
void cmd_connect_lowercases_argument_with_no_account(void** state);
void cmd_connect_lowercases_argument_with_account(void** state);
void cmd_connect_asks_password_when_not_in_account(void** state);
void cmd_connect_shows_message_when_connecting_with_account(void** state);
void cmd_connect_connects_with_account(void** state);
void cmd_connect_shows_usage_when_no_server_value(void** state);
void cmd_connect_shows_usage_when_server_no_port_value(void** state);
void cmd_connect_shows_usage_when_no_port_value(void** state);
void cmd_connect_shows_usage_when_port_no_server_value(void** state);
void cmd_connect_shows_message_when_port_0(void** state);
void cmd_connect_shows_message_when_port_minus1(void** state);
void cmd_connect_shows_message_when_port_65536(void** state);
void cmd_connect_shows_message_when_port_contains_chars(void** state);
void cmd_connect_with_server_when_provided(void** state);
void cmd_connect_with_port_when_provided(void** state);
void cmd_connect_with_server_and_port_when_provided(void** state);
void cmd_connect_shows_usage_when_server_provided_twice(void** state);
void cmd_connect_shows_usage_when_port_provided_twice(void** state);
void cmd_connect_shows_usage_when_invalid_first_property(void** state);
void cmd_connect_shows_usage_when_invalid_second_property(void** state);

View File

@@ -0,0 +1,34 @@
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include "xmpp/chat_session.h"
#include "command/cmd_funcs.h"
#include "xmpp/xmpp.h"
#include "xmpp/roster_list.h"
#include "ui/stub_ui.h"
#define CMD_DISCONNECT "/disconnect"
void
clears_chat_sessions(void** state)
{
chat_sessions_init();
roster_create();
chat_session_recipient_active("bob@server.org", "laptop", FALSE);
chat_session_recipient_active("mike@server.org", "work", FALSE);
will_return(connection_get_status, JABBER_CONNECTED);
will_return(connection_get_barejid, "myjid@myserver.com");
expect_any_cons_show();
gboolean result = cmd_disconnect(NULL, CMD_DISCONNECT, NULL);
assert_true(result);
ChatSession* session1 = chat_session_get("bob@server.org");
ChatSession* session2 = chat_session_get("mike@server.org");
assert_null(session1);
assert_null(session2);
}

View File

@@ -0,0 +1 @@
void clears_chat_sessions(void** state);

View File

@@ -0,0 +1,160 @@
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "xmpp/xmpp.h"
#include "ui/ui.h"
#include "ui/stub_ui.h"
#include "config/accounts.h"
#include "command/cmd_funcs.h"
#include "xmpp/muc.h"
#define CMD_JOIN "/join"
static void
test_with_connection_status(jabber_conn_status_t status)
{
will_return(connection_get_status, status);
expect_cons_show("You are not currently connected.");
gboolean result = cmd_join(NULL, CMD_JOIN, NULL);
assert_true(result);
}
void
cmd_join_shows_message_when_disconnecting(void** state)
{
test_with_connection_status(JABBER_DISCONNECTING);
}
void
cmd_join_shows_message_when_connecting(void** state)
{
test_with_connection_status(JABBER_CONNECTING);
}
void
cmd_join_shows_message_when_disconnected(void** state)
{
test_with_connection_status(JABBER_DISCONNECTED);
}
void
cmd_join_shows_error_message_when_invalid_room_jid(void** state)
{
gchar* args[] = { "//@@/", NULL };
will_return(connection_get_status, JABBER_CONNECTED);
expect_cons_show_error("Specified room has incorrect format.");
expect_cons_show("");
gboolean result = cmd_join(NULL, CMD_JOIN, args);
assert_true(result);
}
void
cmd_join_uses_account_mucservice_when_no_service_specified(void** state)
{
gchar* account_name = g_strdup("an_account");
char* room = "room";
char* nick = "bob";
gchar* account_service = g_strdup("conference.server.org");
char* expected_room = "room@conference.server.org";
gchar* args[] = { room, "nick", nick, NULL };
ProfAccount* account = account_new(account_name, g_strdup("user@server.org"), NULL, NULL,
TRUE, NULL, 0, g_strdup("laptop"), NULL, NULL, 0, 0, 0, 0, 0, account_service, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
will_return(connection_get_status, JABBER_CONNECTED);
will_return(session_get_account_name, account_name);
expect_string(accounts_get_account, name, account_name);
will_return(accounts_get_account, account);
expect_string(presence_join_room, room, expected_room);
expect_string(presence_join_room, nick, nick);
expect_value(presence_join_room, passwd, NULL);
gboolean result = cmd_join(NULL, CMD_JOIN, args);
assert_true(result);
}
void
cmd_join_uses_supplied_nick(void** state)
{
gchar* account_name = g_strdup("an_account");
char* room = "room@conf.server.org";
char* nick = "bob";
gchar* args[] = { room, "nick", nick, NULL };
ProfAccount* account = account_new(account_name, g_strdup("user@server.org"), NULL, NULL,
TRUE, NULL, 0, g_strdup("laptop"), NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
will_return(connection_get_status, JABBER_CONNECTED);
will_return(session_get_account_name, account_name);
expect_string(accounts_get_account, name, account_name);
will_return(accounts_get_account, account);
expect_string(presence_join_room, room, room);
expect_string(presence_join_room, nick, nick);
expect_value(presence_join_room, passwd, NULL);
gboolean result = cmd_join(NULL, CMD_JOIN, args);
assert_true(result);
}
void
cmd_join_uses_account_nick_when_not_supplied(void** state)
{
gchar* account_name = g_strdup("an_account");
char* room = "room2@conf.server.org";
gchar* account_nick = g_strdup("a_nick");
gchar* args[] = { room, NULL };
ProfAccount* account = account_new(account_name, g_strdup("user@server.org"), NULL, NULL,
TRUE, NULL, 0, g_strdup("laptop"), NULL, NULL, 0, 0, 0, 0, 0, NULL, account_nick, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
will_return(connection_get_status, JABBER_CONNECTED);
will_return(session_get_account_name, account_name);
expect_string(accounts_get_account, name, account_name);
will_return(accounts_get_account, account);
expect_string(presence_join_room, room, room);
expect_string(presence_join_room, nick, account_nick);
expect_value(presence_join_room, passwd, NULL);
gboolean result = cmd_join(NULL, CMD_JOIN, args);
assert_true(result);
}
void
cmd_join_uses_password_when_supplied(void** state)
{
gchar* account_name = g_strdup("an_account");
char* room = "room";
char* password = "a_password";
gchar* account_nick = g_strdup("a_nick");
gchar* account_service = g_strdup("a_service");
char* expected_room = "room@a_service";
gchar* args[] = { room, "password", password, NULL };
ProfAccount* account = account_new(account_name, g_strdup("user@server.org"), NULL, NULL,
TRUE, NULL, 0, g_strdup("laptop"), NULL, NULL, 0, 0, 0, 0, 0, account_service, account_nick, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
will_return(connection_get_status, JABBER_CONNECTED);
will_return(session_get_account_name, account_name);
expect_string(accounts_get_account, name, account_name);
will_return(accounts_get_account, account);
expect_string(presence_join_room, room, expected_room);
expect_string(presence_join_room, nick, account_nick);
expect_value(presence_join_room, passwd, password);
gboolean result = cmd_join(NULL, CMD_JOIN, args);
assert_true(result);
}

View File

@@ -0,0 +1,9 @@
void cmd_join_shows_message_when_disconnecting(void** state);
void cmd_join_shows_message_when_connecting(void** state);
void cmd_join_shows_message_when_disconnected(void** state);
void cmd_join_shows_message_when_undefined(void** state);
void cmd_join_shows_error_message_when_invalid_room_jid(void** state);
void cmd_join_uses_account_mucservice_when_no_service_specified(void** state);
void cmd_join_uses_supplied_nick(void** state);
void cmd_join_uses_account_nick_when_not_supplied(void** state);
void cmd_join_uses_password_when_supplied(void** state);

View File

@@ -0,0 +1,487 @@
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "config.h"
#ifdef HAVE_LIBOTR
#include <libotr/proto.h>
#include "otr/otr.h"
#endif
#include "config/preferences.h"
#include "command/cmd_defs.h"
#include "command/cmd_funcs.h"
#include "ui/window_list.h"
#include "xmpp/xmpp.h"
#include "ui/ui.h"
#include "ui/stub_ui.h"
#define CMD_OTR "/otr"
#ifdef HAVE_LIBOTR
void
cmd_otr_log_shows_usage_when_no_args(void** state)
{
gchar* args[] = { "log", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_OTR);
gboolean result = cmd_otr_log(NULL, CMD_OTR, args);
assert_true(result);
}
void
cmd_otr_log_shows_usage_when_invalid_subcommand(void** state)
{
gchar* args[] = { "log", "wrong", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_OTR);
gboolean result = cmd_otr_log(NULL, CMD_OTR, args);
assert_true(result);
}
void
cmd_otr_log_on_enables_logging(void** state)
{
gchar* args[] = { "log", "on", NULL };
prefs_set_string(PREF_OTR_LOG, "off");
prefs_set_boolean(PREF_CHLOG, TRUE);
expect_cons_show("OTR messages will be logged as plaintext.");
gboolean result = cmd_otr_log(NULL, CMD_OTR, args);
auto_gchar gchar* pref_otr_log = prefs_get_string(PREF_OTR_LOG);
assert_true(result);
assert_string_equal("on", pref_otr_log);
}
void
cmd_otr_log_on_shows_warning_when_chlog_disabled(void** state)
{
gchar* args[] = { "log", "on", NULL };
prefs_set_string(PREF_OTR_LOG, "off");
prefs_set_boolean(PREF_CHLOG, FALSE);
expect_cons_show("OTR messages will be logged as plaintext.");
expect_cons_show("Chat logging is currently disabled, use '/logging chat on' to enable.");
gboolean result = cmd_otr_log(NULL, CMD_OTR, args);
assert_true(result);
}
void
cmd_otr_log_off_disables_logging(void** state)
{
gchar* args[] = { "log", "off", NULL };
prefs_set_string(PREF_OTR_LOG, "on");
prefs_set_boolean(PREF_CHLOG, TRUE);
expect_cons_show("OTR message logging disabled.");
gboolean result = cmd_otr_log(NULL, CMD_OTR, args);
auto_gchar gchar* pref_otr_log = prefs_get_string(PREF_OTR_LOG);
assert_true(result);
assert_string_equal("off", pref_otr_log);
}
void
cmd_otr_redact_redacts_logging(void** state)
{
gchar* args[] = { "log", "redact", NULL };
prefs_set_string(PREF_OTR_LOG, "on");
prefs_set_boolean(PREF_CHLOG, TRUE);
expect_cons_show("OTR messages will be logged as '[redacted]'.");
gboolean result = cmd_otr_log(NULL, CMD_OTR, args);
auto_gchar gchar* pref_otr_log = prefs_get_string(PREF_OTR_LOG);
assert_true(result);
assert_string_equal("redact", pref_otr_log);
}
void
cmd_otr_log_redact_shows_warning_when_chlog_disabled(void** state)
{
gchar* args[] = { "log", "redact", NULL };
prefs_set_string(PREF_OTR_LOG, "off");
prefs_set_boolean(PREF_CHLOG, FALSE);
expect_cons_show("OTR messages will be logged as '[redacted]'.");
expect_cons_show("Chat logging is currently disabled, use '/logging chat on' to enable.");
gboolean result = cmd_otr_log(NULL, CMD_OTR, args);
assert_true(result);
}
void
cmd_otr_libver_shows_libotr_version(void** state)
{
gchar* args[] = { "libver", NULL };
char* version = "9.9.9";
GString* message = g_string_new("Using libotr version ");
g_string_append(message, version);
will_return(otr_libotr_version, version);
expect_cons_show(message->str);
gboolean result = cmd_otr_libver(NULL, CMD_OTR, args);
assert_true(result);
g_string_free(message, TRUE);
}
void
cmd_otr_gen_shows_message_when_not_connected(void** state)
{
gchar* args[] = { "gen", NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_cons_show("You must be connected with an account to load OTR information.");
gboolean result = cmd_otr_gen(NULL, CMD_OTR, args);
assert_true(result);
}
static void
test_with_command_and_connection_status(char* command, void* cmd_func, jabber_conn_status_t status)
{
gchar* args[] = { command, NULL };
will_return(connection_get_status, status);
expect_cons_show("You must be connected with an account to load OTR information.");
gboolean (*func)(ProfWin* window, const char* const command, gchar** args) = cmd_func;
gboolean result = func(NULL, CMD_OTR, args);
assert_true(result);
}
void
cmd_otr_gen_shows_message_when_disconnected(void** state)
{
test_with_command_and_connection_status("gen", cmd_otr_gen, JABBER_DISCONNECTED);
}
void
cmd_otr_gen_shows_message_when_connecting(void** state)
{
test_with_command_and_connection_status("gen", cmd_otr_gen, JABBER_CONNECTING);
}
void
cmd_otr_gen_shows_message_when_disconnecting(void** state)
{
test_with_command_and_connection_status("gen", cmd_otr_gen, JABBER_DISCONNECTING);
}
void
cmd_otr_gen_generates_key_for_connected_account(void** state)
{
gchar* args[] = { "gen", NULL };
gchar* account_name = g_strdup("myaccount");
ProfAccount* account = account_new(account_name, g_strdup("me@jabber.org"), NULL, NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
will_return(connection_get_status, JABBER_CONNECTED);
will_return(session_get_account_name, account_name);
expect_string(accounts_get_account, name, account_name);
will_return(accounts_get_account, account);
expect_memory(otr_keygen, account, account, sizeof(ProfAccount));
gboolean result = cmd_otr_gen(NULL, CMD_OTR, args);
assert_true(result);
}
void
cmd_otr_myfp_shows_message_when_disconnected(void** state)
{
test_with_command_and_connection_status("myfp", cmd_otr_myfp, JABBER_DISCONNECTED);
}
void
cmd_otr_myfp_shows_message_when_connecting(void** state)
{
test_with_command_and_connection_status("myfp", cmd_otr_myfp, JABBER_CONNECTING);
}
void
cmd_otr_myfp_shows_message_when_disconnecting(void** state)
{
test_with_command_and_connection_status("myfp", cmd_otr_myfp, JABBER_DISCONNECTING);
}
void
cmd_otr_myfp_shows_message_when_no_key(void** state)
{
gchar* args[] = { "myfp", NULL };
will_return(connection_get_status, JABBER_CONNECTED);
will_return(otr_key_loaded, FALSE);
expect_win_println("You have not generated or loaded a private key, use '/otr gen'");
gboolean result = cmd_otr_myfp(NULL, CMD_OTR, args);
assert_true(result);
}
void
cmd_otr_myfp_shows_my_fingerprint(void** state)
{
char* fingerprint = "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE";
gchar* args[] = { "myfp", NULL };
GString* message = g_string_new("Your OTR fingerprint: ");
g_string_append(message, fingerprint);
will_return(connection_get_status, JABBER_CONNECTED);
will_return(otr_key_loaded, TRUE);
will_return(otr_get_my_fingerprint, g_strdup(fingerprint));
expect_win_println(message->str);
gboolean result = cmd_otr_myfp(NULL, CMD_OTR, args);
assert_true(result);
g_string_free(message, TRUE);
}
static void
test_cmd_otr_theirfp_from_wintype(win_type_t wintype)
{
gchar* args[] = { "theirfp", NULL };
ProfWin window;
window.type = wintype;
window.layout = NULL;
window.urls_ac = NULL;
window.quotes_ac = NULL;
will_return(connection_get_status, JABBER_CONNECTED);
expect_win_println("You must be in a regular chat window to view a recipient's fingerprint.");
gboolean result = cmd_otr_theirfp(&window, CMD_OTR, args);
assert_true(result);
}
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_non_otr_chat_window(void** state)
{
gchar* args[] = { "theirfp", NULL };
ProfWin window;
window.type = WIN_CHAT;
window.layout = NULL;
window.urls_ac = NULL;
window.quotes_ac = NULL;
ProfChatWin chatwin;
chatwin.window = window;
chatwin.memcheck = PROFCHATWIN_MEMCHECK;
chatwin.pgp_send = FALSE;
chatwin.is_otr = FALSE;
will_return(connection_get_status, JABBER_CONNECTED);
expect_win_println("You are not currently in an OTR session.");
gboolean result = cmd_otr_theirfp((ProfWin*)&chatwin, CMD_OTR, args);
assert_true(result);
}
void
cmd_otr_theirfp_shows_fingerprint(void** state)
{
char* recipient = "someone@chat.com";
char* fingerprint = "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE";
gchar* args[] = { "theirfp", NULL };
GString* message = g_string_new(recipient);
g_string_append(message, "'s OTR fingerprint: ");
g_string_append(message, fingerprint);
ProfWin window;
window.type = WIN_CHAT;
window.layout = NULL;
window.urls_ac = NULL;
window.quotes_ac = NULL;
ProfChatWin chatwin;
chatwin.window = window;
chatwin.barejid = recipient;
chatwin.memcheck = PROFCHATWIN_MEMCHECK;
chatwin.pgp_send = FALSE;
chatwin.is_otr = TRUE;
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(otr_get_their_fingerprint, recipient, recipient);
will_return(otr_get_their_fingerprint, g_strdup(fingerprint));
expect_win_println(message->str);
gboolean result = cmd_otr_theirfp((ProfWin*)&chatwin, CMD_OTR, args);
assert_true(result);
g_string_free(message, TRUE);
}
static void
test_cmd_otr_start_from_wintype(win_type_t wintype)
{
gchar* args[] = { "start", NULL };
ProfWin window;
window.type = wintype;
window.layout = NULL;
window.urls_ac = NULL;
window.quotes_ac = NULL;
will_return(connection_get_status, JABBER_CONNECTED);
expect_win_println("You must be in a regular chat window to start an OTR session.");
gboolean result = cmd_otr_start(&window, CMD_OTR, args);
assert_true(result);
}
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_already_started(void** state)
{
char* recipient = "someone@server.org";
gchar* args[] = { "start", NULL };
will_return(connection_get_status, JABBER_CONNECTED);
ProfWin window;
window.type = WIN_CHAT;
window.layout = NULL;
window.urls_ac = NULL;
window.quotes_ac = NULL;
ProfChatWin chatwin;
chatwin.window = window;
chatwin.barejid = recipient;
chatwin.memcheck = PROFCHATWIN_MEMCHECK;
chatwin.pgp_send = FALSE;
chatwin.is_otr = TRUE;
expect_win_println("You are already in an OTR session.");
gboolean result = cmd_otr_start((ProfWin*)&chatwin, CMD_OTR, args);
assert_true(result);
}
void
cmd_otr_start_shows_message_when_no_key(void** state)
{
char* recipient = "someone@server.org";
gchar* args[] = { "start", NULL };
will_return(connection_get_status, JABBER_CONNECTED);
will_return(otr_key_loaded, FALSE);
ProfWin window;
window.type = WIN_CHAT;
window.layout = NULL;
window.urls_ac = NULL;
window.quotes_ac = NULL;
ProfChatWin chatwin;
chatwin.window = window;
chatwin.barejid = recipient;
chatwin.memcheck = PROFCHATWIN_MEMCHECK;
chatwin.pgp_send = FALSE;
chatwin.is_otr = FALSE;
expect_win_println("You have not generated or loaded a private key, use '/otr gen'");
gboolean result = cmd_otr_start((ProfWin*)&chatwin, CMD_OTR, args);
assert_true(result);
}
void
cmd_otr_start_sends_otr_query_message_to_current_recipeint(void** state)
{
char* recipient = "buddy@chat.com";
char* query_message = "?OTR?";
gchar* args[] = { "start", NULL };
ProfWin window;
window.type = WIN_CHAT;
window.layout = NULL;
window.urls_ac = NULL;
window.quotes_ac = NULL;
ProfChatWin chatwin;
chatwin.window = window;
chatwin.barejid = recipient;
chatwin.memcheck = PROFCHATWIN_MEMCHECK;
chatwin.pgp_send = FALSE;
chatwin.is_otr = FALSE;
will_return(connection_get_status, JABBER_CONNECTED);
will_return(otr_key_loaded, TRUE);
will_return(otr_start_query, query_message);
expect_string(message_send_chat_otr, barejid, recipient);
expect_string(message_send_chat_otr, msg, query_message);
gboolean result = cmd_otr_start((ProfWin*)&chatwin, CMD_OTR, args);
assert_true(result);
}
#else
void
cmd_otr_shows_message_when_otr_unsupported(void** state)
{
gchar* args[] = { "gen", NULL };
expect_cons_show("This version of Profanity has not been built with OTR support enabled");
gboolean result = cmd_otr_gen(NULL, CMD_OTR, args);
assert_true(result);
}
#endif

View File

@@ -0,0 +1,37 @@
#include "config.h"
#ifdef HAVE_LIBOTR
void cmd_otr_log_shows_usage_when_no_args(void** state);
void cmd_otr_log_shows_usage_when_invalid_subcommand(void** state);
void cmd_otr_log_on_enables_logging(void** state);
void cmd_otr_log_off_disables_logging(void** state);
void cmd_otr_redact_redacts_logging(void** state);
void cmd_otr_log_on_shows_warning_when_chlog_disabled(void** state);
void cmd_otr_log_redact_shows_warning_when_chlog_disabled(void** state);
void cmd_otr_libver_shows_libotr_version(void** state);
void cmd_otr_gen_shows_message_when_not_connected(void** state);
void cmd_otr_gen_generates_key_for_connected_account(void** state);
void cmd_otr_gen_shows_message_when_disconnected(void** state);
void cmd_otr_gen_shows_message_when_undefined(void** state);
void cmd_otr_gen_shows_message_when_connecting(void** state);
void cmd_otr_gen_shows_message_when_disconnecting(void** state);
void cmd_otr_myfp_shows_message_when_disconnected(void** state);
void cmd_otr_myfp_shows_message_when_undefined(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);
void cmd_otr_theirfp_shows_message_when_in_private(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_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

@@ -0,0 +1,116 @@
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "config.h"
#include "command/cmd_funcs.h"
#include "xmpp/xmpp.h"
#include "ui/stub_ui.h"
#define CMD_PGP "/pgp"
#ifdef HAVE_LIBGPGME
void
cmd_pgp_shows_usage_when_no_args(void** state)
{
gchar* args[] = { NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_PGP);
gboolean result = cmd_pgp(NULL, CMD_PGP, args);
assert_true(result);
}
void
cmd_pgp_start_shows_message_when_connection(jabber_conn_status_t conn_status)
{
gchar* args[] = { "start", NULL };
ProfWin window;
window.type = WIN_CHAT;
will_return(connection_get_status, conn_status);
expect_cons_show("You must be connected to start PGP encryption.");
gboolean result = cmd_pgp(&window, CMD_PGP, args);
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;
will_return(connection_get_status, JABBER_CONNECTED);
expect_cons_show("You must set recipient in an argument or be in a regular chat window to start PGP encryption.");
gboolean result = cmd_pgp(&window, CMD_PGP, args);
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);
}
void
cmd_pgp_start_shows_message_when_no_arg_in_conf(void** state)
{
cmd_pgp_start_shows_message_when_no_arg_in_wintype(WIN_CONFIG);
}
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);
}
#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");
gboolean result = cmd_pgp(NULL, CMD_PGP, args);
assert_true(result);
}
#endif

View File

@@ -0,0 +1,16 @@
#include "config.h"
#ifdef HAVE_LIBGPGME
void cmd_pgp_shows_usage_when_no_args(void** state);
void cmd_pgp_start_shows_message_when_disconnected(void** state);
void cmd_pgp_start_shows_message_when_disconnecting(void** state);
void cmd_pgp_start_shows_message_when_connecting(void** state);
void cmd_pgp_start_shows_message_when_undefined(void** state);
void cmd_pgp_start_shows_message_when_no_arg_in_console(void** state);
void cmd_pgp_start_shows_message_when_no_arg_in_muc(void** state);
void cmd_pgp_start_shows_message_when_no_arg_in_conf(void** state);
void cmd_pgp_start_shows_message_when_no_arg_in_private(void** state);
void cmd_pgp_start_shows_message_when_no_arg_in_xmlconsole(void** state);
#else
void cmd_pgp_shows_message_when_pgp_unsupported(void** state);
#endif

View File

@@ -0,0 +1,192 @@
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "config/preferences.h"
#include "ui/ui.h"
#include "ui/stub_ui.h"
#include "command/cmd_funcs.h"
#define CMD_PRESENCE "/presence"
void
cmd_presence_shows_usage_when_bad_subcmd(void** state)
{
gchar* args[] = { "badcmd", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_PRESENCE);
gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);
assert_true(result);
}
void
cmd_presence_shows_usage_when_bad_console_setting(void** state)
{
gchar* args[] = { "console", "badsetting", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_PRESENCE);
gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);
assert_true(result);
}
void
cmd_presence_shows_usage_when_bad_chat_setting(void** state)
{
gchar* args[] = { "chat", "badsetting", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_PRESENCE);
gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);
assert_true(result);
}
void
cmd_presence_shows_usage_when_bad_muc_setting(void** state)
{
gchar* args[] = { "muc", "badsetting", NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_PRESENCE);
gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);
assert_true(result);
}
void
cmd_presence_console_sets_all(void** state)
{
gchar* args[] = { "console", "all", NULL };
expect_cons_show("All presence updates will appear in the console.");
gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);
auto_gchar gchar* setting = prefs_get_string(PREF_STATUSES_CONSOLE);
assert_non_null(setting);
assert_string_equal("all", setting);
assert_true(result);
}
void
cmd_presence_console_sets_online(void** state)
{
gchar* args[] = { "console", "online", NULL };
expect_cons_show("Only online/offline presence updates will appear in the console.");
gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);
auto_gchar gchar* setting = prefs_get_string(PREF_STATUSES_CONSOLE);
assert_non_null(setting);
assert_string_equal("online", setting);
assert_true(result);
}
void
cmd_presence_console_sets_none(void** state)
{
gchar* args[] = { "console", "none", NULL };
expect_cons_show("Presence updates will not appear in the console.");
gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);
auto_gchar gchar* setting = prefs_get_string(PREF_STATUSES_CONSOLE);
assert_non_null(setting);
assert_string_equal("none", setting);
assert_true(result);
}
void
cmd_presence_chat_sets_all(void** state)
{
gchar* args[] = { "chat", "all", NULL };
expect_cons_show("All presence updates will appear in chat windows.");
gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);
auto_gchar gchar* setting = prefs_get_string(PREF_STATUSES_CHAT);
assert_non_null(setting);
assert_string_equal("all", setting);
assert_true(result);
}
void
cmd_presence_chat_sets_online(void** state)
{
gchar* args[] = { "chat", "online", NULL };
expect_cons_show("Only online/offline presence updates will appear in chat windows.");
gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);
auto_gchar gchar* setting = prefs_get_string(PREF_STATUSES_CHAT);
assert_non_null(setting);
assert_string_equal("online", setting);
assert_true(result);
}
void
cmd_presence_chat_sets_none(void** state)
{
gchar* args[] = { "chat", "none", NULL };
expect_cons_show("Presence updates will not appear in chat windows.");
gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);
auto_gchar gchar* setting = prefs_get_string(PREF_STATUSES_CHAT);
assert_non_null(setting);
assert_string_equal("none", setting);
assert_true(result);
}
void
cmd_presence_room_sets_all(void** state)
{
gchar* args[] = { "room", "all", NULL };
expect_cons_show("All presence updates will appear in chat room windows.");
gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);
auto_gchar gchar* setting = prefs_get_string(PREF_STATUSES_MUC);
assert_non_null(setting);
assert_string_equal("all", setting);
assert_true(result);
}
void
cmd_presence_room_sets_online(void** state)
{
gchar* args[] = { "room", "online", NULL };
expect_cons_show("Only join/leave presence updates will appear in chat room windows.");
gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);
auto_gchar gchar* setting = prefs_get_string(PREF_STATUSES_MUC);
assert_non_null(setting);
assert_string_equal("online", setting);
assert_true(result);
}
void
cmd_presence_room_sets_none(void** state)
{
gchar* args[] = { "room", "none", NULL };
expect_cons_show("Presence updates will not appear in chat room windows.");
gboolean result = cmd_presence(NULL, CMD_PRESENCE, args);
auto_gchar gchar* setting = prefs_get_string(PREF_STATUSES_MUC);
assert_non_null(setting);
assert_string_equal("none", setting);
assert_true(result);
}

View File

@@ -0,0 +1,13 @@
void cmd_presence_shows_usage_when_bad_subcmd(void** state);
void cmd_presence_shows_usage_when_bad_console_setting(void** state);
void cmd_presence_shows_usage_when_bad_chat_setting(void** state);
void cmd_presence_shows_usage_when_bad_muc_setting(void** state);
void cmd_presence_console_sets_all(void** state);
void cmd_presence_console_sets_online(void** state);
void cmd_presence_console_sets_none(void** state);
void cmd_presence_chat_sets_all(void** state);
void cmd_presence_chat_sets_online(void** state);
void cmd_presence_chat_sets_none(void** state);
void cmd_presence_room_sets_all(void** state);
void cmd_presence_room_sets_online(void** state);
void cmd_presence_room_sets_none(void** state);

View File

@@ -0,0 +1,106 @@
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "xmpp/xmpp.h"
#include "ui/ui.h"
#include "ui/stub_ui.h"
#include "config/accounts.h"
#include "command/cmd_funcs.h"
#define CMD_ROOMS "/rooms"
static void
test_with_connection_status(jabber_conn_status_t status)
{
will_return(connection_get_status, status);
expect_cons_show("You are not currently connected.");
gboolean result = cmd_rooms(NULL, CMD_ROOMS, NULL);
assert_true(result);
}
void
cmd_rooms_shows_message_when_disconnected(void** state)
{
test_with_connection_status(JABBER_DISCONNECTED);
}
void
cmd_rooms_shows_message_when_disconnecting(void** state)
{
test_with_connection_status(JABBER_DISCONNECTING);
}
void
cmd_rooms_shows_message_when_connecting(void** state)
{
test_with_connection_status(JABBER_CONNECTING);
}
void
cmd_rooms_uses_account_default_when_no_arg(void** state)
{
gchar* args[] = { NULL };
ProfAccount* account = account_new(g_strdup("testaccount"), NULL, NULL, NULL, TRUE, NULL, 0, NULL, NULL, NULL,
0, 0, 0, 0, 0, g_strdup("default_conf_server"), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
will_return(connection_get_status, JABBER_CONNECTED);
will_return(session_get_account_name, "account_name");
expect_any(accounts_get_account, name);
will_return(accounts_get_account, account);
expect_cons_show("");
expect_cons_show("Room list request sent: default_conf_server");
expect_string(iq_room_list_request, conferencejid, "default_conf_server");
expect_any(iq_room_list_request, filter);
gboolean result = cmd_rooms(NULL, CMD_ROOMS, args);
assert_true(result);
}
void
cmd_rooms_service_arg_used_when_passed(void** state)
{
gchar* args[] = { "service", "conf_server_arg", NULL };
will_return(connection_get_status, JABBER_CONNECTED);
expect_cons_show("");
expect_cons_show("Room list request sent: conf_server_arg");
expect_string(iq_room_list_request, conferencejid, "conf_server_arg");
expect_any(iq_room_list_request, filter);
gboolean result = cmd_rooms(NULL, CMD_ROOMS, args);
assert_true(result);
}
void
cmd_rooms_filter_arg_used_when_passed(void** state)
{
gchar* args[] = { "filter", "text", NULL };
ProfAccount* account = account_new(g_strdup("testaccount"), NULL, NULL, NULL, TRUE, NULL, 0, NULL, NULL, NULL,
0, 0, 0, 0, 0, g_strdup("default_conf_server"), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
will_return(connection_get_status, JABBER_CONNECTED);
will_return(session_get_account_name, "account_name");
expect_any(accounts_get_account, name);
will_return(accounts_get_account, account);
expect_cons_show("");
expect_cons_show("Room list request sent: default_conf_server, filter: 'text'");
expect_any(iq_room_list_request, conferencejid);
expect_string(iq_room_list_request, filter, "text");
gboolean result = cmd_rooms(NULL, CMD_ROOMS, args);
assert_true(result);
}

View File

@@ -0,0 +1,7 @@
void cmd_rooms_shows_message_when_disconnected(void** state);
void cmd_rooms_shows_message_when_disconnecting(void** state);
void cmd_rooms_shows_message_when_connecting(void** state);
void cmd_rooms_shows_message_when_undefined(void** state);
void cmd_rooms_uses_account_default_when_no_arg(void** state);
void cmd_rooms_service_arg_used_when_passed(void** state);
void cmd_rooms_filter_arg_used_when_passed(void** state);

View File

@@ -0,0 +1,272 @@
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "ui/ui.h"
#include "ui/stub_ui.h"
#include "xmpp/xmpp.h"
#include "xmpp/roster_list.h"
#include "command/cmd_funcs.h"
#define CMD_ROSTER "/roster"
static void
test_with_connection_status(jabber_conn_status_t status)
{
gchar* args[] = { NULL };
will_return(connection_get_status, status);
expect_cons_show("You are not currently connected.");
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
assert_true(result);
}
void
cmd_roster_shows_message_when_disconnecting(void** state)
{
test_with_connection_status(JABBER_DISCONNECTING);
}
void
cmd_roster_shows_message_when_connecting(void** state)
{
test_with_connection_status(JABBER_CONNECTING);
}
void
cmd_roster_shows_message_when_disconnected(void** state)
{
test_with_connection_status(JABBER_DISCONNECTED);
}
void
cmd_roster_shows_roster_when_no_args(void** state)
{
gchar* args[] = { NULL };
will_return(connection_get_status, JABBER_CONNECTED);
roster_create();
roster_add("bob@server.org", "bob", NULL, "both", FALSE);
GSList* roster = roster_get_contacts(ROSTER_ORD_NAME);
expect_memory(cons_show_roster, list, roster, sizeof(roster));
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
assert_true(result);
g_slist_free(roster);
roster_destroy();
}
void
cmd_roster_add_shows_message_when_no_jid(void** state)
{
gchar* args[] = { "add", NULL };
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(cons_bad_cmd_usage, cmd, CMD_ROSTER);
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
assert_true(result);
}
void
cmd_roster_add_sends_roster_add_request(void** state)
{
char* jid = "bob@server.org";
char* nick = "bob";
gchar* args[] = { "add", jid, nick, NULL };
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(roster_send_add_new, barejid, jid);
expect_string(roster_send_add_new, name, nick);
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
assert_true(result);
}
void
cmd_roster_remove_shows_message_when_no_jid(void** state)
{
gchar* args[] = { "remove", NULL };
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(cons_bad_cmd_usage, cmd, CMD_ROSTER);
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
assert_true(result);
}
void
cmd_roster_remove_sends_roster_remove_request(void** state)
{
char* jid = "bob@server.org";
gchar* args[] = { "remove", jid, NULL };
roster_create();
roster_add("bob@server.org", "bob", NULL, "both", FALSE);
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(roster_send_remove, barejid, jid);
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
assert_true(result);
roster_destroy();
}
void
cmd_roster_remove_nickname_sends_roster_remove_request(void** state)
{
char* jid = "bob@server.org";
gchar* args[] = { "remove", "bob", NULL };
roster_create();
roster_add("bob@server.org", "bob", NULL, "both", FALSE);
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(roster_send_remove, barejid, jid);
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
assert_true(result);
roster_destroy();
}
void
cmd_roster_nick_shows_message_when_no_jid(void** state)
{
gchar* args[] = { "nick", NULL };
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(cons_bad_cmd_usage, cmd, CMD_ROSTER);
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
assert_true(result);
}
void
cmd_roster_nick_shows_message_when_no_nick(void** state)
{
gchar* args[] = { "nick", "bob@server.org", NULL };
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(cons_bad_cmd_usage, cmd, CMD_ROSTER);
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
assert_true(result);
}
void
cmd_roster_nick_shows_message_when_no_contact_exists(void** state)
{
gchar* args[] = { "nick", "bob@server.org", "bobster", NULL };
roster_create();
will_return(connection_get_status, JABBER_CONNECTED);
expect_cons_show("Contact not found in roster: bob@server.org");
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
assert_true(result);
roster_destroy();
}
void
cmd_roster_nick_sends_name_change_request(void** state)
{
char* jid = "bob@server.org";
char* nick = "bobster";
gchar* args[] = { "nick", jid, nick, NULL };
roster_create();
GSList* groups = NULL;
groups = g_slist_append(groups, g_strdup("group1"));
roster_add(jid, "bob", groups, "both", FALSE);
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(roster_send_name_change, barejid, jid);
expect_string(roster_send_name_change, new_name, nick);
expect_memory(roster_send_name_change, groups, groups, sizeof(groups));
expect_cons_show("Nickname for bob@server.org set to: bobster.");
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
assert_true(result);
PContact contact = roster_get_contact(jid);
assert_string_equal(p_contact_name(contact), nick);
roster_destroy();
}
void
cmd_roster_clearnick_shows_message_when_no_jid(void** state)
{
gchar* args[] = { "clearnick", NULL };
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(cons_bad_cmd_usage, cmd, CMD_ROSTER);
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
assert_true(result);
}
void
cmd_roster_clearnick_shows_message_when_no_contact_exists(void** state)
{
gchar* args[] = { "clearnick", "bob@server.org", NULL };
roster_create();
will_return(connection_get_status, JABBER_CONNECTED);
expect_cons_show("Contact not found in roster: bob@server.org");
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
assert_true(result);
roster_destroy();
}
void
cmd_roster_clearnick_sends_name_change_request_with_empty_nick(void** state)
{
char* jid = "bob@server.org";
gchar* args[] = { "clearnick", jid, NULL };
roster_create();
GSList* groups = NULL;
groups = g_slist_append(groups, g_strdup("group1"));
roster_add(jid, "bob", groups, "both", FALSE);
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(roster_send_name_change, barejid, jid);
expect_value(roster_send_name_change, new_name, NULL);
expect_memory(roster_send_name_change, groups, groups, sizeof(groups));
expect_cons_show("Nickname for bob@server.org removed.");
gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
assert_true(result);
PContact contact = roster_get_contact(jid);
assert_null(p_contact_name(contact));
roster_destroy();
}

View File

@@ -0,0 +1,17 @@
void cmd_roster_shows_message_when_disconnecting(void** state);
void cmd_roster_shows_message_when_connecting(void** state);
void cmd_roster_shows_message_when_disconnected(void** state);
void cmd_roster_shows_message_when_undefined(void** state);
void cmd_roster_shows_roster_when_no_args(void** state);
void cmd_roster_add_shows_message_when_no_jid(void** state);
void cmd_roster_add_sends_roster_add_request(void** state);
void cmd_roster_remove_shows_message_when_no_jid(void** state);
void cmd_roster_remove_sends_roster_remove_request(void** state);
void cmd_roster_remove_nickname_sends_roster_remove_request(void** state);
void cmd_roster_nick_shows_message_when_no_jid(void** state);
void cmd_roster_nick_shows_message_when_no_nick(void** state);
void cmd_roster_nick_shows_message_when_no_contact_exists(void** state);
void cmd_roster_nick_sends_name_change_request(void** state);
void cmd_roster_clearnick_shows_message_when_no_jid(void** state);
void cmd_roster_clearnick_shows_message_when_no_contact_exists(void** state);
void cmd_roster_clearnick_sends_name_change_request_with_empty_nick(void** state);

View File

@@ -0,0 +1,39 @@
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "xmpp/xmpp.h"
#include "ui/ui.h"
#include "ui/stub_ui.h"
#include "command/cmd_funcs.h"
#define CMD_SUB "/sub"
void
cmd_sub_shows_message_when_not_connected(void** state)
{
gchar* args[] = { NULL };
will_return(connection_get_status, JABBER_DISCONNECTED);
expect_cons_show("You are currently not connected.");
gboolean result = cmd_sub(NULL, CMD_SUB, args);
assert_true(result);
}
void
cmd_sub_shows_usage_when_no_arg(void** state)
{
gchar* args[] = { NULL };
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(cons_bad_cmd_usage, cmd, CMD_SUB);
gboolean result = cmd_sub(NULL, CMD_SUB, args);
assert_true(result);
}

View File

@@ -0,0 +1,2 @@
void cmd_sub_shows_message_when_not_connected(void** state);
void cmd_sub_shows_usage_when_no_arg(void** state);