GnuCash c935c2f+
Loading...
Searching...
No Matches
gmock-Account.h
1#ifndef GMOCK_ACCOUNT_H
2#define GMOCK_ACCOUNT_H
3
4#pragma GCC diagnostic push
5#pragma GCC diagnostic ignored "-Wcpp"
6#include <gmock/gmock.h>
7#pragma GCC diagnostic pop
8
9
10#include <Account.h>
11#include <Account.hpp>
12#include <AccountP.hpp>
13#include <qofbook.h>
14
15#include "gmock-gobject.h"
16
17
18GType gnc_mockaccount_get_type(void);
19
20#define GNC_TYPE_MOCKACCOUNT (gnc_mockaccount_get_type ())
21#define GNC_IS_MOCKACCOUNT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_MOCKACCOUNT))
22
23
24// mock up for Account
25class MockAccount : public Account
26{
27public:
28 /* note: don't use default constructor instead of empty constructor, since
29 * it does zero initialization, which would overwrite GObject
30 * initialization, which is already done in the new operator. */
31 MockAccount() {}
32 void* operator new(size_t size)
33 {
34 return mock_g_object_new (GNC_TYPE_MOCKACCOUNT, NULL, size);
35 }
36
37 // define separate free() function since destructor is protected
38 void free()
39 {
40 delete this;
41 }
42 void operator delete(void* acc, size_t size)
43 {
44 mock_g_object_unref(acc, size);
45 }
46
47 MOCK_METHOD0(begin_edit, void());
48 MOCK_METHOD0(commit_edit, void());
49 MOCK_CONST_METHOD0(get_book, QofBook*());
50 MOCK_CONST_METHOD0(get_commodity, gnc_commodity*());
51 MOCK_CONST_METHOD2(for_each_transaction, gint(TransactionCallback, void*));
52 MOCK_CONST_METHOD0(xaccAccountGetSplitList, SplitList*());
53 MOCK_CONST_METHOD0(xaccAccountGetSplits, std::vector<Split*>&());
54 MOCK_METHOD2(find_account, Account *(const char*, const char*));
55 MOCK_METHOD3(add_account, void(const char*, const char*, Account*));
56 MOCK_METHOD1(find_account_bayes, Account *(std::vector<const char*>&));
57 MOCK_METHOD2(add_account_bayes, void(std::vector<const char*>&, Account*));
58
59protected:
60 /* Protect destructor to avoid MockAccount objects to be created on stack. MockAccount
61 * objects can only be dynamically created, since they are derived from GObject. */
62 ~MockAccount() {}
63};
64
65
66// type conversion functions
67static inline MockAccount*
68gnc_mockaccount (Account *account)
69{
70 if (GNC_IS_MOCKACCOUNT(account))
71 return static_cast<MockAccount*>(account);
72 ADD_FAILURE() << "Expected 'account' to be of type 'MockAccount'";
73 return nullptr;
74}
75
76static inline const MockAccount*
77gnc_mockaccount (const Account *account)
78{
79 if (GNC_IS_MOCKACCOUNT(account))
80 return static_cast<const MockAccount*>(account);
81 ADD_FAILURE() << "Expected 'account' to be of type 'MockAccount'";
82 return nullptr;
83}
84
85#endif
This is the private header for the account structure.
Account handling public routines.
Account public routines (C++ api)
GList SplitList
GList of Split.
Definition gnc-engine.h:207
SplitList * xaccAccountGetSplitList(const Account *acc)
The xaccAccountGetSplitList() routine returns a pointer to a GList of the splits in the account.
Definition Account.cpp:3949
Encapsulate all the information about a dataset.
STRUCTS.
QofBook reference.
Definition qofbook-p.hpp:47