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

160 lines
2.9 KiB
C
Raw Normal View History

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>
#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, ...)
{
}
static
void _mock_cons_show_error(const char * const msg, ...)
2013-12-19 16:05:39 -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
}
static
void _mock_cons_show_account(ProfAccount *account)
2013-12-14 11:17:53 -05:00
{
check_expected(account);
2013-12-14 11:17:53 -05:00
}
static
void _mock_cons_show_account_list(gchar **accounts)
2013-12-14 11:17:53 -05:00
{
check_expected(accounts);
2013-12-14 11:17:53 -05:00
}
static
char * _mock_ui_ask_password(void)
2013-12-14 11:17:53 -05:00
{
return (char *)mock();
2013-12-14 11:17:53 -05:00
}
static
char * _stub_ui_ask_password(void)
2013-12-14 11:17:53 -05:00
{
return NULL;
2013-12-14 11:17:53 -05:00
}
void
mock_cons_show(void)
2013-12-14 11:17:53 -05:00
{
cons_show = _mock_cons_show;
2013-12-14 11:17:53 -05:00
}
void
mock_cons_show_error(void)
2013-12-14 11:17:53 -05:00
{
cons_show_error = _mock_cons_show_error;
2013-12-14 11:17:53 -05:00
}
void
mock_cons_show_account(void)
2013-12-14 11:17:53 -05:00
{
cons_show_account = _mock_cons_show_account;
2013-12-14 11:17:53 -05:00
}
void
mock_cons_show_account_list(void)
2013-12-14 11:17:53 -05:00
{
cons_show_account_list = _mock_cons_show_account_list;
2013-12-14 11:17:53 -05:00
}
void
mock_ui_ask_password(void)
2013-12-14 11:17:53 -05:00
{
ui_ask_password = _mock_ui_ask_password;
2013-12-14 11:17:53 -05:00
}
void
stub_ui_ask_password(void)
2013-12-14 11:17:53 -05:00
{
ui_ask_password = _stub_ui_ask_password;
2013-12-14 11:17:53 -05:00
}
void
stub_cons_show(void)
2013-12-14 11:17:53 -05:00
{
cons_show = _stub_cons_show;
2013-12-14 11:17:53 -05:00
}
void
expect_cons_show(char *output)
2013-12-14 11:17:53 -05:00
{
expect_string(_mock_cons_show, output, output);
2013-12-14 11:17:53 -05:00
}
void
expect_cons_show_calls(int n)
2013-12-15 14:38:23 -05:00
{
expect_any_count(_mock_cons_show, output, n);
2013-12-15 14:38:23 -05:00
}
void
expect_cons_show_error(char *output)
2013-12-15 17:28:22 -05:00
{
expect_string(_mock_cons_show_error, output, output);
2013-12-15 17:28:22 -05:00
}
void
expect_cons_show_account(ProfAccount *account)
2013-12-15 14:56:48 -05:00
{
expect_memory(_mock_cons_show_account, account, account, sizeof(ProfAccount));
2013-12-15 14:56:48 -05:00
}
void
expect_cons_show_account_list(gchar **accounts)
2013-12-15 18:07:53 -05:00
{
expect_memory(_mock_cons_show_account_list, accounts, accounts, sizeof(accounts));
2013-12-15 18:07:53 -05:00
}
void
mock_ui_ask_password_returns(char *password)
2013-12-14 11:17:53 -05:00
{
will_return(_mock_ui_ask_password, strdup(password));
2013-12-14 11:17:53 -05:00
}