mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
71 lines
1.9 KiB
C++
71 lines
1.9 KiB
C++
#ifndef GMOCK_ACCOUNT_H
|
|
#define GMOCK_ACCOUNT_H
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
#include <Account.h>
|
|
#include <AccountP.h>
|
|
|
|
#include "gmock-qofbook.h"
|
|
#include "gmock-gobject.h"
|
|
|
|
|
|
GType gnc_mock_account_get_type(void);
|
|
|
|
#define GNC_TYPE_MOCK_ACCOUNT (gnc_mock_account_get_type ())
|
|
#define GNC_IS_MOCK_ACCOUNT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_MOCK_ACCOUNT))
|
|
|
|
|
|
// mock up for Account
|
|
class MockAccount : public Account
|
|
{
|
|
public:
|
|
// note: don't use default constructor instead of empty constructor, since
|
|
// it does zero initialization, which would overwrite GObject
|
|
// initialization, which is already done in the new operator.
|
|
MockAccount() {}
|
|
void* operator new(size_t size)
|
|
{
|
|
return mock_g_object_new (GNC_TYPE_MOCK_ACCOUNT, NULL, size);
|
|
}
|
|
|
|
// define separate free() function since destructor is protected
|
|
void free()
|
|
{
|
|
delete this;
|
|
}
|
|
void operator delete(void* acc, size_t size)
|
|
{
|
|
mock_g_object_unref(acc, size);
|
|
}
|
|
|
|
MOCK_METHOD0(begin_edit, void());
|
|
MOCK_METHOD0(commit_edit, void());
|
|
MOCK_METHOD0(get_book, QofMockBook*());
|
|
MOCK_METHOD2(for_each_transaction, gint(TransactionCallback, void*));
|
|
MOCK_METHOD0(create_imap, GncImportMatchMap*());
|
|
|
|
protected:
|
|
// Protect destructor to avoid MockAccount objects to be created on stack. MockAccount
|
|
// objects can only be dynamically created, since they are derived from GObject.
|
|
~MockAccount() {}
|
|
};
|
|
|
|
|
|
class GncMockImportMatchMap : public GncImportMatchMap
|
|
{
|
|
public:
|
|
GncMockImportMatchMap(MockAccount* account)
|
|
{
|
|
acc = account;
|
|
book = account->get_book();
|
|
};
|
|
|
|
MOCK_METHOD2(find_account, Account *(const char*, const char*));
|
|
MOCK_METHOD3(add_account, void(const char*, const char*, Account*));
|
|
MOCK_METHOD1(find_account_bayes, Account *(std::vector<const char*>&));
|
|
MOCK_METHOD2(add_account_bayes, void(std::vector<const char*>&, Account*));
|
|
};
|
|
|
|
#endif
|