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