GnuCash  4.9-165-gc1c198c9f
gmock-Split.h
1 #ifndef GMOCK_SPLIT_H
2 #define GMOCK_SPLIT_H
3 
4 #include <gmock/gmock.h>
5 
6 #include <Split.h>
7 extern "C"
8 {
9 #include <SplitP.h>
10 }
11 
12 #include "gmock-qofbook.h"
13 #include "gmock-gobject.h"
14 
15 
16 GType gnc_mocksplit_get_type(void);
17 
18 #define GNC_TYPE_MOCKSPLIT (gnc_mocksplit_get_type ())
19 #define GNC_IS_MOCKSPLIT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_MOCKSPLIT))
20 
21 
22 // mock up for Split
23 class MockSplit : public Split
24 {
25 public:
26  MockSplit()
27  {
28  acc = nullptr;
29  orig_acc = nullptr;
30  parent = nullptr;
31  orig_parent = nullptr;
32  lot = nullptr;
33 
34  action = nullptr;
35  memo = nullptr;
36  reconciled = VREC;
37  amount = gnc_numeric_zero();
38  value = gnc_numeric_zero();
39 
40  date_reconciled = 0;
41 
42  balance = gnc_numeric_zero();
43  cleared_balance = gnc_numeric_zero();
44  reconciled_balance = gnc_numeric_zero();
45  noclosing_balance = gnc_numeric_zero();
46 
47  gains = GAINS_STATUS_UNKNOWN;
48  gains_split = nullptr;
49  }
50  void* operator new(size_t size)
51  {
52  return mock_g_object_new (GNC_TYPE_MOCKSPLIT, NULL, size);
53  }
54 
55  // define separate free() function since destructor is protected
56  void free()
57  {
58  delete this;
59  }
60  void operator delete(void* split, size_t size)
61  {
62  mock_g_object_unref(split, size);
63  }
64 
65  MOCK_METHOD0(init, void());
66  MOCK_CONST_METHOD0(get_book, QofBook *());
67  MOCK_CONST_METHOD0(get_account, Account *());
68  MOCK_METHOD1(set_account, void(Account*));
69  MOCK_CONST_METHOD0(get_amount, gnc_numeric());
70  MOCK_METHOD1(set_amount, void(gnc_numeric));
71  MOCK_CONST_METHOD0(get_value, gnc_numeric());
72  MOCK_METHOD1(set_value, void(gnc_numeric));
73  MOCK_CONST_METHOD0(get_memo, const char *());
74  MOCK_CONST_METHOD0(get_reconcile, char());
75  MOCK_METHOD1(set_reconcile, void(char));
76  MOCK_METHOD1(set_date_reconciled_secs, void(time64));
77  MOCK_CONST_METHOD0(get_action, const char *());
78  MOCK_CONST_METHOD0(get_other_split, Split *());
79  MOCK_CONST_METHOD0(get_parent, Transaction *());
80  MOCK_METHOD1(set_parent, void(Transaction*));
81 
82 protected:
83  // Protect destructor to avoid MockSplit objects to be created on stack. MockSplit
84  // objects can only be dynamically created, since they are derived from GObject.
85  ~MockSplit() {}
86 };
87 
88 
89 // type conversion functions
90 static inline MockSplit*
91 gnc_mocksplit (Split *split)
92 {
93  if (GNC_IS_MOCKSPLIT(split))
94  return static_cast<MockSplit*>(split);
95  ADD_FAILURE() << "Expected 'split' to be of type 'MockSplit'";
96  return nullptr;
97 }
98 
99 static inline const MockSplit*
100 gnc_mocksplit (const Split *split)
101 {
102  if (GNC_IS_MOCKSPLIT(split))
103  return static_cast<const MockSplit*>(split);
104  ADD_FAILURE() << "Expected 'split' to be of type 'MockSplit'";
105  return nullptr;
106 }
107 
108 #endif
API for Transactions and Splits (journal entries)
#define VREC
split is void
Definition: Split.h:75
Definition: init.py:1
gint64 time64
Many systems, including Microsoft Windows and BSD-derived Unixes like Darwin, are retaining the int-3...
Definition: gnc-date.h:93