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

641 lines
14 KiB
C
Raw Normal View History

/*
* mock_accounts.c
*
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY {} without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <glib.h>
#include <setjmp.h>
#include <cmocka.h>
2013-12-26 08:37:22 -05:00
#include <string.h>
#include "config/accounts.h"
2013-12-26 08:37:22 -05:00
// mocks and stubs
2013-12-26 08:37:22 -05:00
static ProfAccount *
_mock_accounts_get_account(const char * const name)
{
2013-12-26 08:37:22 -05:00
check_expected(name);
return (ProfAccount *)mock();
}
2013-12-26 08:37:22 -05:00
static char *
_mock_accounts_create_full_jid(ProfAccount *account)
{
2013-12-26 08:37:22 -05:00
check_expected(account);
return (char *)mock();
}
2013-12-26 08:37:22 -05:00
void
_stub_accounts_free_account(ProfAccount *account)
{
// do nothing
}
2013-12-26 08:37:22 -05:00
void
_mock_accounts_free_account(ProfAccount *account)
{
2013-12-26 08:37:22 -05:00
check_expected(account);
}
2013-12-26 08:37:22 -05:00
gchar **
_mock_accounts_get_list(void)
{
return (gchar **)mock();
}
2013-12-26 08:37:22 -05:00
void
2014-01-18 15:34:46 -05:00
_mock_accounts_add(const char *account_name, const char *altdomain, const int port)
{
2013-12-26 08:37:22 -05:00
check_expected(account_name);
check_expected(altdomain);
}
2013-12-26 08:37:22 -05:00
void
2014-01-18 15:34:46 -05:00
_stub_accounts_add(const char *account_name, const char *altdomain, const int port)
2013-12-15 17:00:42 -05:00
{
2013-12-26 08:37:22 -05:00
// do nothing
2013-12-15 17:00:42 -05:00
}
2013-12-26 08:37:22 -05:00
static gboolean
_mock_accounts_enable(const char * const name)
{
2013-12-15 18:51:29 -05:00
check_expected(name);
return (gboolean)mock();
}
2013-12-26 08:37:22 -05:00
static gboolean
_mock_accounts_disable(const char * const name)
{
2013-12-15 18:55:59 -05:00
check_expected(name);
return (gboolean)mock();
}
2013-12-26 08:37:22 -05:00
static gboolean
_mock_accounts_rename(const char * const account_name, const char * const new_name)
{
2013-12-15 19:12:07 -05:00
check_expected(account_name);
check_expected(new_name);
return (gboolean)mock();
}
2013-12-26 08:37:22 -05:00
static gboolean
_mock_accounts_account_exists(const char * const account_name)
{
check_expected(account_name);
return (gboolean)mock();
}
2013-12-26 08:37:22 -05:00
static void
_mock_accounts_set_jid(const char * const account_name, const char * const value)
{
check_expected(account_name);
check_expected(value);
}
2013-12-26 08:37:22 -05:00
static void
_stub_accounts_set_jid(const char * const account_name, const char * const value)
2013-12-17 17:33:49 -05:00
{
2013-12-26 08:37:22 -05:00
// do nothing
2013-12-17 17:33:49 -05:00
}
2013-12-26 08:37:22 -05:00
static void
_mock_accounts_set_resource(const char * const account_name, const char * const value)
{
check_expected(account_name);
check_expected(value);
}
2013-12-26 08:37:22 -05:00
static void
_stub_accounts_set_resource(const char * const account_name, const char * const value)
{
// do nothing
}
static void
_mock_accounts_set_server(const char * const account_name, const char * const value)
{
check_expected(account_name);
check_expected(value);
}
2013-12-26 08:37:22 -05:00
static void
_stub_accounts_set_server(const char * const account_name, const char * const value)
{
// do nothing
}
static void
_mock_accounts_set_password(const char * const account_name, const char * const value)
{
check_expected(account_name);
check_expected(value);
}
2013-12-26 08:37:22 -05:00
static void
_stub_accounts_set_password(const char * const account_name, const char * const value)
{
// do nothing
}
static void
_mock_accounts_set_muc_service(const char * const account_name, const char * const value)
{
check_expected(account_name);
check_expected(value);
}
2013-12-26 08:37:22 -05:00
static void
_stub_accounts_set_muc_service(const char * const account_name, const char * const value)
{
// do nothing
}
2013-12-17 18:17:02 -05:00
2013-12-26 08:37:22 -05:00
static void
_mock_accounts_set_muc_nick(const char * const account_name, const char * const value)
2013-12-17 18:17:02 -05:00
{
check_expected(account_name);
check_expected(value);
}
2013-12-26 08:37:22 -05:00
static void
_stub_accounts_set_muc_nick(const char * const account_name, const char * const value)
{
2013-12-26 08:37:22 -05:00
// do nothing
}
2013-12-26 08:37:22 -05:00
static void
_mock_accounts_set_priority_online(const char * const account_name, const gint value)
{
2013-12-26 08:37:22 -05:00
check_expected(account_name);
check_expected(value);
}
static void
_stub_accounts_set_priority_online(const char * const account_name, const gint value)
{
// do nothing
}
2013-12-26 08:37:22 -05:00
static void
_mock_accounts_set_priority_chat(const char * const account_name, const gint value)
{
check_expected(account_name);
check_expected(value);
}
static void
_stub_accounts_set_priority_chat(const char * const account_name, const gint value)
{
// do nothing
}
2013-12-26 08:37:22 -05:00
static void
_mock_accounts_set_priority_away(const char * const account_name, const gint value)
{
check_expected(account_name);
check_expected(value);
}
static void
_stub_accounts_set_priority_away(const char * const account_name, const gint value)
{
// do nothing
}
2013-12-26 08:37:22 -05:00
static void
_mock_accounts_set_priority_xa(const char * const account_name, const gint value)
{
check_expected(account_name);
check_expected(value);
}
static void
_stub_accounts_set_priority_xa(const char * const account_name, const gint value)
{
// do nothing
}
2013-12-26 08:37:22 -05:00
static void
_mock_accounts_set_priority_dnd(const char * const account_name, const gint value)
{
check_expected(account_name);
check_expected(value);
}
static void
_stub_accounts_set_priority_dnd(const char * const account_name, const gint value)
{
// do nothing
}
2013-12-26 08:37:22 -05:00
static void
_mock_accounts_set_login_presence(const char * const account_name, const char * const value)
{
check_expected(account_name);
check_expected(value);
}
2013-12-26 08:37:22 -05:00
static void
_stub_accounts_set_login_presence(const char * const account_name, const char * const value)
{
// do nothing
}
static resource_presence_t
_mock_accounts_get_last_presence(const char * const account_name)
{
check_expected(account_name);
return (resource_presence_t)mock();
2013-12-26 08:37:22 -05:00
}
2013-12-26 08:37:22 -05:00
// set up functions
void
mock_accounts_get_account(void)
{
2013-12-26 08:37:22 -05:00
accounts_get_account = _mock_accounts_get_account;
}
2013-12-26 08:37:22 -05:00
void
mock_accounts_create_full_jid(void)
{
accounts_create_full_jid = _mock_accounts_create_full_jid;
}
2013-12-26 08:37:22 -05:00
void
stub_accounts_free_account(void)
2013-12-15 15:32:30 -05:00
{
2013-12-26 08:37:22 -05:00
accounts_free_account = _stub_accounts_free_account;
}
void
mock_accounts_free_account(void)
{
accounts_free_account = _mock_accounts_free_account;
}
void
mock_accounts_get_list(void)
{
accounts_get_list = _mock_accounts_get_list;
}
void
mock_accounts_add(void)
{
accounts_add = _mock_accounts_add;
}
void
stub_accounts_add(void)
{
accounts_add = _stub_accounts_add;
}
void
mock_accounts_enable(void)
{
accounts_enable = _mock_accounts_enable;
}
void
mock_accounts_disable(void)
{
accounts_disable = _mock_accounts_disable;
}
void
mock_accounts_rename(void)
{
accounts_rename = _mock_accounts_rename;
}
void
mock_accounts_account_exists(void)
{
accounts_account_exists = _mock_accounts_account_exists;
}
void
mock_accounts_set_jid(void)
{
accounts_set_jid = _mock_accounts_set_jid;
}
void
stub_accounts_set_jid(void)
{
accounts_set_jid = _stub_accounts_set_jid;
}
void
mock_accounts_set_resource(void)
{
accounts_set_resource = _mock_accounts_set_resource;
}
void
stub_accounts_set_resource(void)
{
accounts_set_resource = _stub_accounts_set_resource;
}
void
mock_accounts_set_server(void)
{
accounts_set_server = _mock_accounts_set_server;
}
void
stub_accounts_set_server(void)
{
accounts_set_server = _stub_accounts_set_server;
}
void
mock_accounts_set_password(void)
{
accounts_set_password = _mock_accounts_set_password;
}
void
stub_accounts_set_password(void)
{
accounts_set_password = _stub_accounts_set_password;
}
void
mock_accounts_set_muc_service(void)
{
accounts_set_muc_service = _mock_accounts_set_muc_service;
}
void
stub_accounts_set_muc_service(void)
{
accounts_set_muc_service = _stub_accounts_set_muc_service;
}
void
mock_accounts_set_muc_nick(void)
{
accounts_set_muc_nick = _mock_accounts_set_muc_nick;
2013-12-15 15:32:30 -05:00
}
2013-12-26 08:37:22 -05:00
void
stub_accounts_set_muc_nick(void)
{
accounts_set_muc_nick = _stub_accounts_set_muc_nick;
}
void
mock_accounts_set_priorities(void)
{
accounts_set_priority_online = _mock_accounts_set_priority_online;
accounts_set_priority_chat = _mock_accounts_set_priority_chat;
accounts_set_priority_away = _mock_accounts_set_priority_away;
accounts_set_priority_xa = _mock_accounts_set_priority_xa;
accounts_set_priority_dnd = _mock_accounts_set_priority_dnd;
}
void
stub_accounts_set_priorities(void)
{
accounts_set_priority_online = _stub_accounts_set_priority_online;
accounts_set_priority_chat = _stub_accounts_set_priority_chat;
accounts_set_priority_away = _stub_accounts_set_priority_away;
accounts_set_priority_xa = _stub_accounts_set_priority_xa;
accounts_set_priority_dnd = _stub_accounts_set_priority_dnd;
}
2013-12-26 08:37:22 -05:00
void
mock_accounts_set_login_presence(void)
{
accounts_set_login_presence = _mock_accounts_set_login_presence;
}
void
stub_accounts_set_login_presence(void)
{
accounts_set_login_presence = _stub_accounts_set_login_presence;
}
void
mock_accounts_get_last_presence(void)
{
accounts_get_last_presence = _mock_accounts_get_last_presence;
}
2013-12-26 08:37:22 -05:00
// mock behaviours
void
accounts_get_account_expect_and_return(const char * const name, ProfAccount *account)
{
expect_string(_mock_accounts_get_account, name, name);
will_return(_mock_accounts_get_account, account);
}
void
accounts_get_account_return(ProfAccount *account)
{
expect_any(_mock_accounts_get_account, name);
will_return(_mock_accounts_get_account, account);
}
void
accounts_create_full_jid_return(char *fulljid)
{
expect_any(_mock_accounts_create_full_jid, account);
if (fulljid != NULL) {
will_return(_mock_accounts_create_full_jid, strdup(fulljid));
} else {
will_return(_mock_accounts_create_full_jid, NULL);
}
}
void
accounts_free_account_expect(ProfAccount *account)
{
expect_memory(_mock_accounts_free_account, account, account, sizeof(ProfAccount));
}
void
accounts_get_list_return(gchar **accounts)
{
will_return(_mock_accounts_get_list, accounts);
}
void
accounts_add_expect_account_name(char *account_name)
{
expect_any(_mock_accounts_add, altdomain);
expect_string(_mock_accounts_add, account_name, account_name);
}
void
accounts_enable_expect(char *name)
{
expect_string(_mock_accounts_enable, name, name);
will_return(_mock_accounts_enable, TRUE);
}
void
accounts_enable_return(gboolean result)
{
expect_any(_mock_accounts_enable, name);
will_return(_mock_accounts_enable, result);
}
void
accounts_disable_expect(char *name)
{
expect_string(_mock_accounts_disable, name, name);
will_return(_mock_accounts_disable, TRUE);
}
void
accounts_disable_return(gboolean result)
{
expect_any(_mock_accounts_disable, name);
will_return(_mock_accounts_disable, result);
}
void
accounts_rename_expect(char *account_name, char *new_name)
{
expect_string(_mock_accounts_rename, account_name, account_name);
expect_string(_mock_accounts_rename, new_name, new_name);
will_return(_mock_accounts_rename, TRUE);
}
void
accounts_rename_return(gboolean result)
{
expect_any(_mock_accounts_rename, account_name);
expect_any(_mock_accounts_rename, new_name);
will_return(_mock_accounts_rename, result);
}
void
accounts_account_exists_expect(char *account_name)
{
expect_string(_mock_accounts_account_exists, account_name, account_name);
will_return(_mock_accounts_account_exists, TRUE);
}
void
accounts_account_exists_return(gboolean result)
{
expect_any(_mock_accounts_account_exists, account_name);
will_return(_mock_accounts_account_exists, result);
}
void
accounts_set_jid_expect(char *account_name, char *jid)
{
expect_string(_mock_accounts_set_jid, account_name, account_name);
expect_string(_mock_accounts_set_jid, value, jid);
}
void
accounts_set_resource_expect(char *account_name, char *resource)
{
expect_string(_mock_accounts_set_resource, account_name, account_name);
expect_string(_mock_accounts_set_resource, value, resource);
}
void
accounts_set_server_expect(char *account_name, char *server)
{
expect_string(_mock_accounts_set_server, account_name, account_name);
expect_string(_mock_accounts_set_server, value, server);
}
void
accounts_set_password_expect(char *account_name, char *password)
{
expect_string(_mock_accounts_set_password, account_name, account_name);
expect_string(_mock_accounts_set_password, value, password);
}
void
accounts_set_muc_service_expect(char *account_name, char *service)
{
expect_string(_mock_accounts_set_muc_service, account_name, account_name);
expect_string(_mock_accounts_set_muc_service, value, service);
}
void
accounts_set_muc_nick_expect(char *account_name, char *nick)
{
expect_string(_mock_accounts_set_muc_nick, account_name, account_name);
expect_string(_mock_accounts_set_muc_nick, value, nick);
}
void
accounts_set_priority_online_expect(char *account_name, gint priority)
{
expect_string(_mock_accounts_set_priority_online, account_name, account_name);
expect_value(_mock_accounts_set_priority_online, value, priority);
}
void
accounts_set_priority_chat_expect(char *account_name, gint priority)
{
expect_string(_mock_accounts_set_priority_chat, account_name, account_name);
expect_value(_mock_accounts_set_priority_chat, value, priority);
}
void
accounts_set_priority_away_expect(char *account_name, gint priority)
{
expect_string(_mock_accounts_set_priority_away, account_name, account_name);
expect_value(_mock_accounts_set_priority_away, value, priority);
}
void
accounts_set_priority_xa_expect(char *account_name, gint priority)
{
expect_string(_mock_accounts_set_priority_xa, account_name, account_name);
expect_value(_mock_accounts_set_priority_xa, value, priority);
}
void
accounts_set_priority_dnd_expect(char *account_name, gint priority)
{
expect_string(_mock_accounts_set_priority_dnd, account_name, account_name);
expect_value(_mock_accounts_set_priority_dnd, value, priority);
}
void
accounts_set_login_presence_expect(char *account_name, char *presence)
{
expect_string(_mock_accounts_set_login_presence, account_name, account_name);
expect_string(_mock_accounts_set_login_presence, value, presence);
}
void
accounts_get_last_presence_return(resource_presence_t presence)
{
expect_any(_mock_accounts_get_last_presence, account_name);
will_return(_mock_accounts_get_last_presence, presence);
}