1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-08 19:34:14 -04:00
profanity/tests/xmpp/mock_xmpp.c

123 lines
3.1 KiB
C
Raw Normal View History

2013-12-18 18:06:43 -05:00
#include <stdarg.h>
#include <stddef.h>
2013-12-14 11:17:53 -05:00
#include <setjmp.h>
#include <cmocka.h>
2013-12-18 18:06:43 -05:00
#include <stdlib.h>
#include <string.h>
#include <glib.h>
2013-12-14 11:17:53 -05:00
#include "xmpp/xmpp.h"
2013-12-18 18:06:43 -05:00
static jabber_conn_status_t
_mock_jabber_get_connection_status(void)
2013-12-14 11:17:53 -05:00
{
2013-12-18 18:06:43 -05:00
return (jabber_conn_status_t)mock();
2013-12-14 11:17:53 -05:00
}
2013-12-18 18:06:43 -05:00
static char *
_mock_jabber_get_account_name(void)
2013-12-14 11:17:53 -05:00
{
2013-12-18 18:06:43 -05:00
return (char *)mock();
2013-12-14 11:17:53 -05:00
}
2013-12-18 18:06:43 -05:00
static void
_mock_iq_room_list_request(gchar *conf_server)
2013-12-14 11:17:53 -05:00
{
2013-12-18 18:06:43 -05:00
check_expected(conf_server);
2013-12-14 11:17:53 -05:00
}
2013-12-26 09:48:25 -05:00
static jabber_conn_status_t
_mock_jabber_connect_with_details(const char * const jid,
const char * const passwd, const char * const altdomain)
{
check_expected(jid);
check_expected(passwd);
check_expected(altdomain);
return (jabber_conn_status_t)mock();
}
static jabber_conn_status_t
_mock_jabber_connect_with_account(const ProfAccount * const account)
{
check_expected(account);
return (jabber_conn_status_t)mock();
}
void
mock_jabber_connect_with_details(void)
{
jabber_connect_with_details = _mock_jabber_connect_with_details;
}
void
mock_jabber_connect_with_account(void)
{
jabber_connect_with_account = _mock_jabber_connect_with_account;
}
2013-12-18 18:06:43 -05:00
void
mock_connection_status(jabber_conn_status_t status)
2013-12-14 11:17:53 -05:00
{
2013-12-18 18:06:43 -05:00
jabber_get_connection_status = _mock_jabber_get_connection_status;
will_return(_mock_jabber_get_connection_status, status);
2013-12-14 11:17:53 -05:00
}
2013-12-18 18:06:43 -05:00
void
mock_connection_account_name(char *name)
2013-12-14 11:17:53 -05:00
{
2013-12-18 18:06:43 -05:00
jabber_get_account_name = _mock_jabber_get_account_name;
will_return(_mock_jabber_get_account_name, name);
2013-12-14 11:17:53 -05:00
}
2013-12-18 18:06:43 -05:00
void
expect_room_list_request(char *conf_server)
2013-12-14 11:17:53 -05:00
{
2013-12-18 18:06:43 -05:00
iq_room_list_request = _mock_iq_room_list_request;
expect_string(_mock_iq_room_list_request, conf_server, conf_server);
2013-12-14 11:17:53 -05:00
}
2013-12-26 09:48:25 -05:00
void
jabber_connect_with_username_password_expect_and_return(char *jid,
char *password, jabber_conn_status_t result)
{
expect_string(_mock_jabber_connect_with_details, jid, jid);
expect_string(_mock_jabber_connect_with_details, passwd, password);
expect_any(_mock_jabber_connect_with_details, altdomain);
will_return(_mock_jabber_connect_with_details, result);
}
void
jabber_connect_with_altdomain_expect_and_return(char *altdomain,
jabber_conn_status_t result)
{
expect_any(_mock_jabber_connect_with_details, jid);
expect_any(_mock_jabber_connect_with_details, passwd);
expect_string(_mock_jabber_connect_with_details, altdomain, altdomain);
will_return(_mock_jabber_connect_with_details, result);
}
void
jabber_connect_with_details_return(jabber_conn_status_t result)
{
expect_any(_mock_jabber_connect_with_details, jid);
expect_any(_mock_jabber_connect_with_details, passwd);
expect_any(_mock_jabber_connect_with_details, altdomain);
will_return(_mock_jabber_connect_with_details, result);
}
void
jabber_connect_with_account_expect_and_return(ProfAccount *account,
jabber_conn_status_t result)
{
expect_memory(_mock_jabber_connect_with_account, account, account, sizeof(ProfAccount));
will_return(_mock_jabber_connect_with_account, result);
}
void
jabber_connect_with_account_return(ProfAccount *account,
jabber_conn_status_t result)
{
expect_any(_mock_jabber_connect_with_account, account);
will_return(_mock_jabber_connect_with_account, result);
}