Mock otr module for cmd_otr tests

This commit is contained in:
James Booth
2014-02-16 19:14:15 +00:00
parent 6ef1174bf4
commit a21ab6d4c8
9 changed files with 144 additions and 49 deletions

View File

@@ -20,6 +20,9 @@
*
*/
#ifndef MOCK_ACCOUNTS_H
#define MOCK_ACCOUNTS_H
void mock_accounts_get_account(void);
void accounts_get_account_expect_and_return(const char * const name, ProfAccount *account);
void accounts_get_account_return(ProfAccount *account);
@@ -85,3 +88,5 @@ void accounts_set_login_presence_expect(char *account_name, char *presence);
void mock_accounts_get_last_presence(void);
void accounts_get_last_presence_return(resource_presence_t presence);
#endif

46
tests/otr/mock_otr.c Normal file
View File

@@ -0,0 +1,46 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "otr/otr.h"
#include "config/account.h"
static void
_mock_otr_keygen(ProfAccount *account)
{
check_expected(account);
}
static char *
_mock_otr_libotr_version(void)
{
return (char *)mock();
}
void
mock_otr_keygen(void)
{
otr_keygen = _mock_otr_keygen;
}
void
mock_otr_libotr_version(void)
{
otr_libotr_version = _mock_otr_libotr_version;
}
void
otr_keygen_expect(ProfAccount *account)
{
expect_memory(_mock_otr_keygen, account, account, sizeof(ProfAccount));
}
void
otr_libotr_version_returns(char *version)
{
will_return(_mock_otr_libotr_version, version);
}

12
tests/otr/mock_otr.h Normal file
View File

@@ -0,0 +1,12 @@
#ifndef MOCK_OTR_H
#define MOCK_OTR_H
#include "config/account.h"
void mock_otr_keygen(void);
void otr_keygen_expect(ProfAccount *account);
void mock_otr_libotr_version(void);
void otr_libotr_version_returns(char *version);
#endif

View File

@@ -10,6 +10,8 @@
#ifdef HAVE_LIBOTR
#include <libotr/proto.h>
#include "otr/otr.h"
#include "otr/mock_otr.h"
#endif
#include "config/preferences.h"
@@ -248,10 +250,11 @@ void cmd_otr_libver_shows_libotr_version(void **state)
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "libver", NULL };
char *version = OTRL_VERSION;
char *version = "9.9.9";
GString *message = g_string_new("Using libotr version ");
g_string_append(message, version);
mock_otr_libotr_version();
otr_libotr_version_returns(version);
expect_cons_show(message->str);
gboolean result = cmd_otr(args, *help);

View File

@@ -1,5 +1,5 @@
#ifndef COMMON_MOCKS_H
#define COMMON_MOCKS_H
#ifndef MOCK_XMPP_H
#define MOCK_XMPP_H
#include "xmpp/xmpp.h"