2013-12-14 11:17:53 -05:00
|
|
|
#include <glib.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include <cmocka.h>
|
2013-12-22 17:14:15 -05:00
|
|
|
#include <string.h>
|
2013-12-14 11:17:53 -05:00
|
|
|
|
|
|
|
#include "ui/ui.h"
|
2014-02-01 18:48:24 -05:00
|
|
|
#include "ui/window.h"
|
2014-02-01 16:18:15 -05:00
|
|
|
#include "tests/helpers.h"
|
|
|
|
|
|
|
|
#include "xmpp/bookmark.h"
|
2013-12-14 11:17:53 -05:00
|
|
|
|
2013-12-15 14:38:23 -05:00
|
|
|
char output[256];
|
|
|
|
|
2014-01-28 18:56:45 -05:00
|
|
|
// Mocks and stubs
|
|
|
|
|
2013-12-19 16:05:39 -05:00
|
|
|
static
|
|
|
|
void _mock_cons_show(const char * const msg, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, msg);
|
|
|
|
vsnprintf(output, sizeof(output), msg, args);
|
|
|
|
check_expected(output);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void _stub_cons_show(const char * const msg, ...)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-01-20 13:40:48 -05:00
|
|
|
static
|
|
|
|
void _mock_cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity)
|
|
|
|
{
|
|
|
|
check_expected(contact);
|
|
|
|
check_expected(resource);
|
|
|
|
check_expected(last_activity);
|
|
|
|
}
|
|
|
|
|
2013-12-22 17:14:15 -05:00
|
|
|
static
|
|
|
|
void _mock_cons_show_error(const char * const msg, ...)
|
2013-12-19 16:05:39 -05:00
|
|
|
{
|
2013-12-22 17:14:15 -05:00
|
|
|
va_list args;
|
|
|
|
va_start(args, msg);
|
|
|
|
vsnprintf(output, sizeof(output), msg, args);
|
|
|
|
check_expected(output);
|
|
|
|
va_end(args);
|
2013-12-19 16:05:39 -05:00
|
|
|
}
|
|
|
|
|
2013-12-22 17:14:15 -05:00
|
|
|
static
|
|
|
|
void _mock_cons_show_account(ProfAccount *account)
|
2013-12-14 11:17:53 -05:00
|
|
|
{
|
2013-12-22 17:14:15 -05:00
|
|
|
check_expected(account);
|
2013-12-14 11:17:53 -05:00
|
|
|
}
|
|
|
|
|
2014-02-01 16:18:15 -05:00
|
|
|
static
|
|
|
|
void _mock_cons_show_bookmarks(const GList *list)
|
|
|
|
{
|
|
|
|
check_expected(list);
|
|
|
|
}
|
|
|
|
|
2014-01-23 17:29:53 -05:00
|
|
|
static
|
|
|
|
void _mock_cons_show_aliases(GList *aliases)
|
|
|
|
{
|
|
|
|
check_expected(aliases);
|
|
|
|
}
|
|
|
|
|
2013-12-22 17:14:15 -05:00
|
|
|
static
|
|
|
|
void _mock_cons_show_account_list(gchar **accounts)
|
2013-12-14 11:17:53 -05:00
|
|
|
{
|
2013-12-22 17:14:15 -05:00
|
|
|
check_expected(accounts);
|
2013-12-14 11:17:53 -05:00
|
|
|
}
|
|
|
|
|
2013-12-22 17:14:15 -05:00
|
|
|
static
|
|
|
|
char * _mock_ui_ask_password(void)
|
2013-12-14 11:17:53 -05:00
|
|
|
{
|
2014-02-01 19:59:32 -05:00
|
|
|
return (char *)mock();
|
2013-12-14 11:17:53 -05:00
|
|
|
}
|
|
|
|
|
2013-12-22 17:14:15 -05:00
|
|
|
static
|
|
|
|
char * _stub_ui_ask_password(void)
|
2013-12-14 11:17:53 -05:00
|
|
|
{
|
2013-12-22 17:14:15 -05:00
|
|
|
return NULL;
|
2013-12-14 11:17:53 -05:00
|
|
|
}
|
|
|
|
|
2014-02-01 18:48:24 -05:00
|
|
|
static
|
|
|
|
win_type_t _mock_ui_current_win_type(void)
|
|
|
|
{
|
|
|
|
return (win_type_t)mock();
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
char * _mock_ui_current_recipeint(void)
|
|
|
|
{
|
|
|
|
return (char *)mock();
|
|
|
|
}
|
|
|
|
|
2014-01-28 17:37:50 -05:00
|
|
|
static
|
|
|
|
void _mock_ui_handle_error(const char * const err_msg)
|
|
|
|
{
|
|
|
|
check_expected(err_msg);
|
|
|
|
}
|
|
|
|
|
2014-01-28 18:56:45 -05:00
|
|
|
static
|
|
|
|
void _mock_ui_handle_recipient_error(const char * const recipient,
|
|
|
|
const char * const err_msg)
|
|
|
|
{
|
|
|
|
check_expected(recipient);
|
|
|
|
check_expected(err_msg);
|
|
|
|
}
|
|
|
|
|
2014-01-30 18:15:39 -05:00
|
|
|
static
|
|
|
|
void _stub_ui_handle_recipient_error(const char * const recipient,
|
|
|
|
const char * const err_msg)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-01-28 18:56:45 -05:00
|
|
|
static
|
|
|
|
void _mock_ui_handle_recipient_not_found(const char * const recipient,
|
|
|
|
const char * const err_msg)
|
|
|
|
{
|
|
|
|
check_expected(recipient);
|
|
|
|
check_expected(err_msg);
|
|
|
|
}
|
|
|
|
|
2014-01-20 13:40:48 -05:00
|
|
|
static
|
|
|
|
void _stub_ui_chat_win_contact_online(PContact contact, Resource *resource, GDateTime *last_activity)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-01-28 18:56:45 -05:00
|
|
|
static
|
|
|
|
void _stub_ui_handle_recipient_not_found(const char * const recipient, const char * const err_msg)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-15 21:22:29 -05:00
|
|
|
static
|
|
|
|
void _stub_ui_current_refresh(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-17 16:52:42 -05:00
|
|
|
static
|
|
|
|
void _mock_ui_current_print_formatted_line(const char show_char, int attrs, const char * const msg, ...)
|
|
|
|
{
|
|
|
|
check_expected(show_char);
|
|
|
|
check_expected(attrs);
|
|
|
|
va_list args;
|
|
|
|
va_start(args, msg);
|
|
|
|
vsnprintf(output, sizeof(output), msg, args);
|
|
|
|
check_expected(output);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2014-02-17 17:14:33 -05:00
|
|
|
static
|
|
|
|
void _mock_ui_current_print_line(const char * const msg, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, msg);
|
|
|
|
vsnprintf(output, sizeof(output), msg, args);
|
|
|
|
check_expected(output);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2014-02-17 17:57:36 -05:00
|
|
|
static
|
|
|
|
gboolean _mock_ui_current_win_is_otr(void)
|
|
|
|
{
|
|
|
|
return (gboolean)mock();
|
|
|
|
}
|
|
|
|
|
2014-03-08 16:10:23 -05:00
|
|
|
static
|
|
|
|
void _mock_ui_room_join(char *room)
|
|
|
|
{
|
|
|
|
check_expected(room);
|
|
|
|
}
|
|
|
|
|
2014-03-15 21:23:12 -04:00
|
|
|
static
|
|
|
|
void _mock_cons_show_roster(GSList *list)
|
|
|
|
{
|
|
|
|
check_expected(list);
|
|
|
|
}
|
|
|
|
|
2014-01-28 18:56:45 -05:00
|
|
|
// bind mocks and stubs
|
|
|
|
|
2013-12-22 17:14:15 -05:00
|
|
|
void
|
|
|
|
mock_cons_show(void)
|
2013-12-14 11:17:53 -05:00
|
|
|
{
|
2013-12-22 17:14:15 -05:00
|
|
|
cons_show = _mock_cons_show;
|
2014-02-01 19:59:32 -05:00
|
|
|
|
2013-12-14 11:17:53 -05:00
|
|
|
}
|
|
|
|
|
2014-01-20 13:40:48 -05:00
|
|
|
void
|
|
|
|
mock_cons_show_contact_online(void)
|
|
|
|
{
|
|
|
|
cons_show_contact_online = _mock_cons_show_contact_online;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
stub_ui_chat_win_contact_online(void)
|
|
|
|
{
|
|
|
|
ui_chat_win_contact_online = _stub_ui_chat_win_contact_online;
|
|
|
|
}
|
|
|
|
|
2013-12-22 17:14:15 -05:00
|
|
|
void
|
|
|
|
mock_cons_show_error(void)
|
2013-12-14 11:17:53 -05:00
|
|
|
{
|
2013-12-22 17:14:15 -05:00
|
|
|
cons_show_error = _mock_cons_show_error;
|
2013-12-14 11:17:53 -05:00
|
|
|
}
|
|
|
|
|
2013-12-22 17:14:15 -05:00
|
|
|
void
|
|
|
|
mock_cons_show_account(void)
|
2013-12-14 11:17:53 -05:00
|
|
|
{
|
2013-12-22 17:14:15 -05:00
|
|
|
cons_show_account = _mock_cons_show_account;
|
2013-12-14 11:17:53 -05:00
|
|
|
}
|
|
|
|
|
2014-02-01 16:18:15 -05:00
|
|
|
void
|
|
|
|
mock_cons_show_bookmarks(void)
|
|
|
|
{
|
|
|
|
cons_show_bookmarks = _mock_cons_show_bookmarks;
|
|
|
|
}
|
|
|
|
|
2014-01-23 17:29:53 -05:00
|
|
|
void
|
|
|
|
mock_cons_show_aliases(void)
|
|
|
|
{
|
|
|
|
cons_show_aliases = _mock_cons_show_aliases;
|
|
|
|
}
|
|
|
|
|
2013-12-22 17:14:15 -05:00
|
|
|
void
|
|
|
|
mock_cons_show_account_list(void)
|
2013-12-14 11:17:53 -05:00
|
|
|
{
|
2013-12-22 17:14:15 -05:00
|
|
|
cons_show_account_list = _mock_cons_show_account_list;
|
2013-12-14 11:17:53 -05:00
|
|
|
}
|
|
|
|
|
2013-12-22 17:14:15 -05:00
|
|
|
void
|
|
|
|
mock_ui_ask_password(void)
|
2013-12-14 11:17:53 -05:00
|
|
|
{
|
2013-12-22 17:14:15 -05:00
|
|
|
ui_ask_password = _mock_ui_ask_password;
|
2013-12-14 11:17:53 -05:00
|
|
|
}
|
|
|
|
|
2014-02-01 18:48:24 -05:00
|
|
|
void
|
|
|
|
mock_ui_current_recipient(void)
|
|
|
|
{
|
|
|
|
ui_current_recipient = _mock_ui_current_recipeint;
|
|
|
|
}
|
|
|
|
|
2013-12-22 17:14:15 -05:00
|
|
|
void
|
|
|
|
stub_ui_ask_password(void)
|
2013-12-14 11:17:53 -05:00
|
|
|
{
|
2013-12-22 17:14:15 -05:00
|
|
|
ui_ask_password = _stub_ui_ask_password;
|
2013-12-14 11:17:53 -05:00
|
|
|
}
|
|
|
|
|
2013-12-22 17:14:15 -05:00
|
|
|
void
|
|
|
|
stub_cons_show(void)
|
2013-12-14 11:17:53 -05:00
|
|
|
{
|
2013-12-22 17:14:15 -05:00
|
|
|
cons_show = _stub_cons_show;
|
2013-12-14 11:17:53 -05:00
|
|
|
}
|
|
|
|
|
2014-01-28 17:37:50 -05:00
|
|
|
void
|
2014-01-28 18:56:45 -05:00
|
|
|
stub_ui_handle_recipient_not_found(void)
|
2014-01-28 17:37:50 -05:00
|
|
|
{
|
2014-01-28 18:56:45 -05:00
|
|
|
ui_handle_recipient_not_found = _stub_ui_handle_recipient_not_found;
|
2014-01-28 17:37:50 -05:00
|
|
|
}
|
|
|
|
|
2014-01-30 18:15:39 -05:00
|
|
|
void
|
|
|
|
stub_ui_handle_recipient_error(void)
|
|
|
|
{
|
|
|
|
ui_handle_recipient_error = _stub_ui_handle_recipient_error;
|
|
|
|
}
|
|
|
|
|
2014-02-15 21:22:29 -05:00
|
|
|
void
|
|
|
|
stub_ui_current_refresh(void)
|
|
|
|
{
|
|
|
|
ui_current_refresh = _stub_ui_current_refresh;
|
|
|
|
}
|
|
|
|
|
2014-02-17 16:52:42 -05:00
|
|
|
void
|
|
|
|
mock_ui_current_print_formatted_line(void)
|
|
|
|
{
|
|
|
|
ui_current_print_formatted_line = _mock_ui_current_print_formatted_line;
|
|
|
|
}
|
|
|
|
|
2014-02-17 17:14:33 -05:00
|
|
|
void
|
|
|
|
mock_ui_current_print_line(void)
|
|
|
|
{
|
|
|
|
ui_current_print_line = _mock_ui_current_print_line;
|
|
|
|
}
|
|
|
|
|
2014-03-15 21:23:12 -04:00
|
|
|
void
|
|
|
|
mock_cons_show_roster(void)
|
|
|
|
{
|
|
|
|
cons_show_roster = _mock_cons_show_roster;
|
|
|
|
}
|
|
|
|
|
2014-01-28 18:56:45 -05:00
|
|
|
// expectations
|
|
|
|
|
2013-12-22 17:14:15 -05:00
|
|
|
void
|
2014-02-01 17:49:47 -05:00
|
|
|
expect_cons_show(char *expected)
|
2013-12-14 11:17:53 -05:00
|
|
|
{
|
2014-02-01 17:49:47 -05:00
|
|
|
expect_string(_mock_cons_show, output, expected);
|
2013-12-14 11:17:53 -05:00
|
|
|
}
|
|
|
|
|
2013-12-22 17:14:15 -05:00
|
|
|
void
|
|
|
|
expect_cons_show_calls(int n)
|
2013-12-15 14:38:23 -05:00
|
|
|
{
|
2013-12-22 17:14:15 -05:00
|
|
|
expect_any_count(_mock_cons_show, output, n);
|
2013-12-15 14:38:23 -05:00
|
|
|
}
|
|
|
|
|
2013-12-22 17:14:15 -05:00
|
|
|
void
|
2014-02-01 17:49:47 -05:00
|
|
|
expect_cons_show_error(char *expected)
|
2013-12-15 17:28:22 -05:00
|
|
|
{
|
2014-02-01 17:49:47 -05:00
|
|
|
expect_string(_mock_cons_show_error, output, expected);
|
2013-12-15 17:28:22 -05:00
|
|
|
}
|
|
|
|
|
2013-12-22 17:14:15 -05:00
|
|
|
void
|
|
|
|
expect_cons_show_account(ProfAccount *account)
|
2013-12-15 14:56:48 -05:00
|
|
|
{
|
2013-12-22 17:14:15 -05:00
|
|
|
expect_memory(_mock_cons_show_account, account, account, sizeof(ProfAccount));
|
2013-12-15 14:56:48 -05:00
|
|
|
}
|
|
|
|
|
2014-02-01 16:18:15 -05:00
|
|
|
static gboolean
|
|
|
|
_cmp_bookmark(Bookmark *bm1, Bookmark *bm2)
|
|
|
|
{
|
|
|
|
if (strcmp(bm1->jid, bm2->jid) != 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (strcmp(bm1->nick, bm2->nick) != 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (bm1->autojoin != bm2->autojoin) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
expect_cons_show_bookmarks(GList *bookmarks)
|
|
|
|
{
|
|
|
|
glist_set_cmp((GCompareFunc)_cmp_bookmark);
|
|
|
|
expect_any(_mock_cons_show_bookmarks, list);
|
|
|
|
// expect_check(_mock_cons_show_bookmarks, list, (CheckParameterValue)glist_contents_equal, bookmarks);
|
|
|
|
}
|
|
|
|
|
2013-12-22 17:14:15 -05:00
|
|
|
void
|
|
|
|
expect_cons_show_account_list(gchar **accounts)
|
2013-12-15 18:07:53 -05:00
|
|
|
{
|
2013-12-22 17:14:15 -05:00
|
|
|
expect_memory(_mock_cons_show_account_list, accounts, accounts, sizeof(accounts));
|
2013-12-15 18:07:53 -05:00
|
|
|
}
|
|
|
|
|
2014-01-20 13:40:48 -05:00
|
|
|
void
|
|
|
|
expect_cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity)
|
|
|
|
{
|
|
|
|
expect_memory(_mock_cons_show_contact_online, contact, contact, sizeof(contact));
|
|
|
|
expect_memory(_mock_cons_show_contact_online, resource, resource, sizeof(Resource));
|
|
|
|
if (last_activity == NULL) {
|
|
|
|
expect_any(_mock_cons_show_contact_online, last_activity);
|
|
|
|
} else {
|
|
|
|
expect_memory(_mock_cons_show_contact_online, last_activity, last_activity, sizeof(last_activity));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-23 17:29:53 -05:00
|
|
|
void
|
|
|
|
expect_cons_show_aliases()
|
|
|
|
{
|
|
|
|
// write a custom checker for the list
|
|
|
|
expect_any(_mock_cons_show_aliases, aliases);
|
|
|
|
}
|
|
|
|
|
2013-12-22 17:14:15 -05:00
|
|
|
void
|
|
|
|
mock_ui_ask_password_returns(char *password)
|
2013-12-14 11:17:53 -05:00
|
|
|
{
|
2013-12-22 17:14:15 -05:00
|
|
|
will_return(_mock_ui_ask_password, strdup(password));
|
2013-12-14 11:17:53 -05:00
|
|
|
}
|
2014-01-28 17:37:50 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
expect_ui_handle_error(char *err_msg)
|
|
|
|
{
|
2014-01-28 18:56:45 -05:00
|
|
|
ui_handle_error = _mock_ui_handle_error;
|
2014-01-28 17:37:50 -05:00
|
|
|
expect_string(_mock_ui_handle_error, err_msg, err_msg);
|
|
|
|
}
|
2014-01-28 18:56:45 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
expect_ui_handle_recipient_error(char *recipient, char *err_msg)
|
|
|
|
{
|
|
|
|
ui_handle_recipient_error = _mock_ui_handle_recipient_error;
|
|
|
|
expect_string(_mock_ui_handle_recipient_error, recipient, recipient);
|
|
|
|
expect_string(_mock_ui_handle_recipient_error, err_msg, err_msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
expect_ui_handle_recipient_not_found(char *recipient, char *err_msg)
|
|
|
|
{
|
|
|
|
ui_handle_recipient_not_found = _mock_ui_handle_recipient_not_found;
|
|
|
|
expect_string(_mock_ui_handle_recipient_not_found, recipient, recipient);
|
|
|
|
expect_string(_mock_ui_handle_recipient_not_found, err_msg, err_msg);
|
|
|
|
}
|
2014-02-01 18:48:24 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
mock_current_win_type(win_type_t type)
|
|
|
|
{
|
|
|
|
ui_current_win_type = _mock_ui_current_win_type;
|
|
|
|
will_return(_mock_ui_current_win_type, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ui_current_recipient_returns(char *jid)
|
|
|
|
{
|
|
|
|
will_return(_mock_ui_current_recipeint, jid);
|
|
|
|
}
|
2014-02-17 16:52:42 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
ui_current_print_formatted_line_expect(char show_char, int attrs, char *message)
|
|
|
|
{
|
|
|
|
expect_value(_mock_ui_current_print_formatted_line, show_char, show_char);
|
|
|
|
expect_value(_mock_ui_current_print_formatted_line, attrs, attrs);
|
|
|
|
expect_string(_mock_ui_current_print_formatted_line, output, message);
|
|
|
|
}
|
2014-02-17 17:14:33 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
ui_current_print_line_expect(char *message)
|
|
|
|
{
|
|
|
|
expect_string(_mock_ui_current_print_line, output, message);
|
|
|
|
}
|
2014-02-17 17:57:36 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
ui_current_win_is_otr_returns(gboolean result)
|
|
|
|
{
|
|
|
|
ui_current_win_is_otr = _mock_ui_current_win_is_otr;
|
|
|
|
will_return(_mock_ui_current_win_is_otr, result);
|
|
|
|
}
|
2014-03-08 16:10:23 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
ui_room_join_expect(char *room)
|
|
|
|
{
|
|
|
|
ui_room_join = _mock_ui_room_join;
|
|
|
|
expect_string(_mock_ui_room_join, room, room);
|
|
|
|
}
|
2014-03-15 21:23:12 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
cons_show_roster_expect(GSList *list)
|
|
|
|
{
|
|
|
|
expect_any(_mock_cons_show_roster, list);
|
|
|
|
}
|