GnuCash  5.6-150-g038405b370+
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 #include <TransactionP.hpp>
8 
9 #include "gmock-gobject.h"
10 
11 
12 GType gnc_mocktransaction_get_type(void);
13 
14 #define GNC_TYPE_MOCKTRANSACTION (gnc_mocktransaction_get_type ())
15 #define GNC_IS_MOCKTRANSACTION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_MOCKTRANSACTION))
16 
17 
18 // mock up for Transaction
19 class MockTransaction : public Transaction
20 {
21 public:
23  {
24  num = nullptr;
25  description = nullptr;
26  common_currency = nullptr;
27  splits = nullptr;
28  date_entered = 0;
29  date_posted = 0;
30  marker = 0;
31  orig = nullptr;
32  }
33  void* operator new(size_t size)
34  {
35  return mock_g_object_new (GNC_TYPE_MOCKTRANSACTION, NULL, size);
36  }
37 
38  // define separate free() function since destructor is protected
39  void free()
40  {
41  delete this;
42  }
43  void operator delete(void* trans, size_t size)
44  {
45  mock_g_object_unref(trans, size);
46  }
47 
48  MOCK_METHOD0(begin_edit, void());
49  MOCK_METHOD0(commit_edit, void());
50  MOCK_CONST_METHOD1(get_split, Split *(int));
51  MOCK_CONST_METHOD0(get_split_list, GList*());
52  MOCK_CONST_METHOD1(find_split_by_account, Split *(const Account*));
53  MOCK_CONST_METHOD0(get_date, time64());
54  MOCK_METHOD1(set_date_posted_secs_normalized, void(time64));
55  MOCK_CONST_METHOD0(get_description, const char *());
56  MOCK_METHOD1(set_description, void(const char*));
57  MOCK_CONST_METHOD0(get_currency, gnc_commodity *());
58  MOCK_CONST_METHOD0(get_notes, const char *());
59  MOCK_METHOD1(set_notes, void(const char*));
60  MOCK_CONST_METHOD0(get_imbalance_value, gnc_numeric());
61  MOCK_CONST_METHOD0(get_num, const char *());
62  MOCK_CONST_METHOD0(is_open, gboolean());
63  MOCK_METHOD0(destroy, void());
64  MOCK_METHOD0(recordPrice, void());
65 
66 protected:
67  // Protect destructor to avoid MockTransaction objects to be created on stack. MockTransaction
68  // objects can only be dynamically created, since they are derived from GObject.
69  ~MockTransaction() {}
70 };
71 
72 
73 // type conversion functions
74 static inline MockTransaction*
75 gnc_mocktransaction (Transaction *trans)
76 {
77  if (GNC_IS_MOCKTRANSACTION(trans))
78  return static_cast<MockTransaction*>(trans);
79  ADD_FAILURE() << "Expected 'trans' to be of type 'MockTransaction'";
80  return nullptr;
81 }
82 
83 static inline const MockTransaction*
84 gnc_mocktransaction (const Transaction *trans)
85 {
86  if (GNC_IS_MOCKTRANSACTION(trans))
87  return static_cast<const MockTransaction*>(trans);
88  ADD_FAILURE() << "Expected 'trans' to be of type 'MockTransaction'";
89  return nullptr;
90 }
91 
92 #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)