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