GnuCash  5.6-150-g038405b370+
gmock-Transaction.h
1 #ifndef GMOCK_TRANSACTION_H
2 #define GMOCK_TRANSACTION_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 <Transaction.h>
11 #include <TransactionP.hpp>
12 
13 #include "gmock-gobject.h"
14 
15 
16 GType gnc_mocktransaction_get_type(void);
17 
18 #define GNC_TYPE_MOCKTRANSACTION (gnc_mocktransaction_get_type ())
19 #define GNC_IS_MOCKTRANSACTION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_MOCKTRANSACTION))
20 
21 
22 // mock up for Transaction
23 class MockTransaction : public Transaction
24 {
25 public:
27  {
28  num = nullptr;
29  description = nullptr;
30  common_currency = nullptr;
31  splits = nullptr;
32  date_entered = 0;
33  date_posted = 0;
34  marker = 0;
35  orig = nullptr;
36  }
37  void* operator new(size_t size)
38  {
39  return mock_g_object_new (GNC_TYPE_MOCKTRANSACTION, NULL, size);
40  }
41 
42  // define separate free() function since destructor is protected
43  void free()
44  {
45  delete this;
46  }
47  void operator delete(void* trans, size_t size)
48  {
49  mock_g_object_unref(trans, size);
50  }
51 
52  MOCK_METHOD0(begin_edit, void());
53  MOCK_METHOD0(commit_edit, void());
54  MOCK_CONST_METHOD1(get_split, Split *(int));
55  MOCK_CONST_METHOD0(get_split_list, GList*());
56  MOCK_CONST_METHOD1(find_split_by_account, Split *(const Account*));
57  MOCK_CONST_METHOD0(get_date, time64());
58  MOCK_METHOD1(set_date_posted_secs_normalized, void(time64));
59  MOCK_CONST_METHOD0(get_description, const char *());
60  MOCK_METHOD1(set_description, void(const char*));
61  MOCK_CONST_METHOD0(get_currency, gnc_commodity *());
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
STRUCTS.
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition: gnc-date.h:87
API for Transactions and Splits (journal entries)