2013-12-14 11:17:53 -05:00
|
|
|
/*
|
2013-12-19 16:05:39 -05:00
|
|
|
* mock_ui.c
|
2013-12-14 11:17:53 -05:00
|
|
|
*
|
|
|
|
* 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-22 17:14:15 -05:00
|
|
|
#include <string.h>
|
2013-12-14 11:17:53 -05:00
|
|
|
|
|
|
|
#include "ui/ui.h"
|
|
|
|
|
2013-12-15 14:38:23 -05:00
|
|
|
char output[256];
|
|
|
|
|
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-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
|
|
|
{
|
2013-12-22 17:14:15 -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-01-20 13:40:48 -05:00
|
|
|
static
|
|
|
|
void _stub_ui_chat_win_contact_online(PContact contact, Resource *resource, GDateTime *last_activity)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
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-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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-12-22 17:14:15 -05:00
|
|
|
void
|
|
|
|
expect_cons_show(char *output)
|
2013-12-14 11:17:53 -05:00
|
|
|
{
|
2013-12-22 17:14:15 -05:00
|
|
|
expect_string(_mock_cons_show, output, output);
|
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
|
|
|
|
expect_cons_show_error(char *output)
|
2013-12-15 17:28:22 -05:00
|
|
|
{
|
2013-12-22 17:14:15 -05:00
|
|
|
expect_string(_mock_cons_show_error, output, output);
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|