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