GnuCash  4.8a-176-g88ecf8dd1
gmock-Transaction.h
1 #ifndef GMOCK_TRANSACTION_H
2 #define GMOCK_TRANSACTION_H
3 
4 #include <gmock/gmock.h>
5 
6 #include <Transaction.h>
7 extern "C"
8 {
9 #include <TransactionP.h>
10 }
11 
12 #include "gmock-gobject.h"
13 
14 
15 GType gnc_mocktransaction_get_type(void);
16 
17 #define GNC_TYPE_MOCKTRANSACTION (gnc_mocktransaction_get_type ())
18 #define GNC_IS_MOCKTRANSACTION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_MOCKTRANSACTION))
19 
20 
21 // mock up for Transaction
22 class MockTransaction : public Transaction
23 {
24 public:
26  {
27  num = nullptr;
28  description = nullptr;
29  common_currency = nullptr;
30  splits = nullptr;
31  date_entered = 0;
32  date_posted = 0;
33  marker = 0;
34  orig = nullptr;
35  readonly_reason = nullptr;
36  isClosingTxn_cached = -1;
37  }
38  void* operator new(size_t size)
39  {
40  return mock_g_object_new (GNC_TYPE_MOCKTRANSACTION, NULL, size);
41  }
42 
43  // define separate free() function since destructor is protected
44  void free()
45  {
46  delete this;
47  }
48  void operator delete(void* trans, size_t size)
49  {
50  mock_g_object_unref(trans, size);
51  }
52 
53  MOCK_METHOD0(begin_edit, void());
54  MOCK_METHOD0(commit_edit, void());
55  MOCK_CONST_METHOD1(get_split, Split *(int));
56  MOCK_CONST_METHOD0(get_split_list, GList*());
57  MOCK_CONST_METHOD1(find_split_by_account, Split *(const Account*));
58  MOCK_CONST_METHOD0(get_date, time64());
59  MOCK_METHOD1(set_date_posted_secs_normalized, void(time64));
60  MOCK_CONST_METHOD0(get_description, const char *());
61  MOCK_METHOD1(set_description, void(const char*));
62  MOCK_CONST_METHOD0(get_notes, const char *());
63  MOCK_METHOD1(set_notes, void(const char*));
64  MOCK_CONST_METHOD0(get_imbalance_value, gnc_numeric());
65  MOCK_CONST_METHOD0(get_num, const char *());
66  MOCK_CONST_METHOD0(is_open, gboolean());
67  MOCK_METHOD0(destroy, void());
68  MOCK_METHOD0(recordPrice, void());
69 
70 protected:
71  // Protect destructor to avoid MockTransaction objects to be created on stack. MockTransaction
72  // objects can only be dynamically created, since they are derived from GObject.
73  ~MockTransaction() {}
74 };
75 
76 
77 // type conversion functions
78 static inline MockTransaction*
79 gnc_mocktransaction (Transaction *trans)
80 {
81  if (GNC_IS_MOCKTRANSACTION(trans))
82  return static_cast<MockTransaction*>(trans);
83  ADD_FAILURE() << "Expected 'trans' to be of type 'MockTransaction'";
84  return nullptr;
85 }
86 
87 static inline const MockTransaction*
88 gnc_mocktransaction (const Transaction *trans)
89 {
90  if (GNC_IS_MOCKTRANSACTION(trans))
91  return static_cast<const MockTransaction*>(trans);
92  ADD_FAILURE() << "Expected 'trans' to be of type 'MockTransaction'";
93  return nullptr;
94 }
95 
96 #endif
gint64 time64
Many systems, including Microsoft Windows and BSD-derived Unixes like Darwin, are retaining the int-3...
Definition: gnc-date.h:93
API for Transactions and Splits (journal entries)