GnuCash  5.6-150-g038405b370+
gmock-Transaction.cpp
1 #include <config.h>
2 
3 #include <Account.h>
4 
5 #include "gmock-Transaction.h"
6 
7 
9 {
10  QofInstanceClass parent_class;
11 };
12 typedef struct _MockTransactionClass MockTransactionClass;
13 
14 G_DEFINE_TYPE(MockTransaction, gnc_mocktransaction, QOF_TYPE_INSTANCE)
15 
16 static void
17 gnc_mocktransaction_init (MockTransaction *inst)
18 {
19  // function is unused, initialization is done in the MockTransaction's C++ constructor
20 }
21 
22 static void
23 gnc_mocktransaction_class_init(MockTransactionClass *klass)
24 {
25  // function is unused, class functions are defined in C++ code
26 }
27 
28 
29 GType gnc_transaction_get_type(void)
30 {
31  return gnc_mocktransaction_get_type();
32 }
33 
34 void
35 xaccTransBeginEdit (Transaction *trans)
36 {
37  ASSERT_TRUE(GNC_IS_MOCKTRANSACTION(trans));
38  gnc_mocktransaction(trans)->begin_edit();
39 }
40 
41 void
42 xaccTransCommitEdit (Transaction *trans)
43 {
44  ASSERT_TRUE(GNC_IS_MOCKTRANSACTION(trans));
45  gnc_mocktransaction(trans)->commit_edit();
46 }
47 
48 Split *
49 xaccTransGetSplit (const Transaction *trans, int i)
50 {
51  SCOPED_TRACE("");
52  auto mocktrans = gnc_mocktransaction(trans);
53  return mocktrans ? mocktrans->get_split(i) : nullptr;
54 }
55 
56 SplitList *
57 xaccTransGetSplitList (const Transaction *trans)
58 {
59  g_return_val_if_fail(GNC_IS_MOCKTRANSACTION(trans), NULL);
60  return trans ? ((MockTransaction*)trans)->get_split_list() : NULL;
61 }
62 
63 Split *
64 xaccTransFindSplitByAccount(const Transaction *trans, const Account *acc)
65 {
66  SCOPED_TRACE("");
67  auto mocktrans = gnc_mocktransaction(trans);
68  EXPECT_TRUE(GNC_IS_ACCOUNT(acc));
69  return mocktrans ? mocktrans->find_split_by_account(acc) : nullptr;
70 }
71 
72 time64
73 xaccTransGetDate (const Transaction *trans)
74 {
75  SCOPED_TRACE("");
76  auto mocktrans = gnc_mocktransaction(trans);
77  return mocktrans ? mocktrans->get_date() : 0;
78 }
79 
80 void
81 xaccTransSetDatePostedSecsNormalized (Transaction *trans, time64 time)
82 {
83  ASSERT_TRUE(GNC_IS_MOCKTRANSACTION(trans));
84  gnc_mocktransaction(trans)->set_date_posted_secs_normalized(time);
85 }
86 
87 const char *
88 xaccTransGetDescription (const Transaction *trans)
89 {
90  SCOPED_TRACE("");
91  auto mocktrans = gnc_mocktransaction(trans);
92  return mocktrans ? mocktrans->get_description() : "";
93 }
94 
95 void
96 xaccTransSetDescription (Transaction *trans, const char *desc)
97 {
98  ASSERT_TRUE(GNC_IS_MOCKTRANSACTION(trans));
99  gnc_mocktransaction(trans)->set_description(desc);
100 }
101 
102 const char *
103 xaccTransGetNotes (const Transaction *trans)
104 {
105  SCOPED_TRACE("");
106  auto mocktrans = gnc_mocktransaction(trans);
107  return mocktrans ? mocktrans->get_notes() : "";
108 }
109 
110 void
111 xaccTransSetNotes (Transaction *trans, const char *notes)
112 {
113  ASSERT_TRUE(GNC_IS_MOCKTRANSACTION(trans));
114  gnc_mocktransaction(trans)->set_notes(notes);
115 }
116 
117 gnc_numeric
118 xaccTransGetImbalanceValue (const Transaction * trans)
119 {
120  SCOPED_TRACE("");
121  auto mocktrans = gnc_mocktransaction(trans);
122  return mocktrans ? mocktrans->get_imbalance_value() : gnc_numeric_zero();
123 }
124 
125 const char *
126 xaccTransGetNum (const Transaction *trans)
127 {
128  SCOPED_TRACE("");
129  auto mocktrans = gnc_mocktransaction(trans);
130  return mocktrans ? mocktrans->get_num() : "";
131 }
132 
133 gnc_commodity *
134 xaccTransGetCurrency (const Transaction *trans)
135 {
136  SCOPED_TRACE("");
137  auto mocktrans = gnc_mocktransaction(trans);
138  return mocktrans ? mocktrans->get_currency() : nullptr;
139 }
140 
141 gboolean
142 xaccTransIsOpen (const Transaction *trans)
143 {
144  SCOPED_TRACE("");
145  auto mocktrans = gnc_mocktransaction(trans);
146  return mocktrans ? mocktrans->is_open() : FALSE;
147 }
148 
149 void
150 xaccTransDestroy (Transaction *trans)
151 {
152  ASSERT_TRUE(GNC_IS_MOCKTRANSACTION(trans));
153  gnc_mocktransaction(trans)->destroy();
154 }
155 
156 void
157 xaccTransRecordPrice (Transaction *trans, PriceSource source)
158 {
159  g_return_if_fail(GNC_IS_MOCKTRANSACTION(trans));
160  ((MockTransaction*)trans)->recordPrice();
161 }
void xaccTransSetDatePostedSecsNormalized(Transaction *trans, time64 time)
This function sets the posted date of the transaction, specified by a time64 (see ctime(3))...
Split * xaccTransGetSplit(const Transaction *trans, int i)
Return a pointer to the indexed split in this transaction&#39;s split list.
time64 xaccTransGetDate(const Transaction *trans)
Retrieve the posted date of the transaction.
gboolean xaccTransIsOpen(const Transaction *trans)
The xaccTransIsOpen() method returns TRUE if the transaction is open for editing. ...
void xaccTransSetNotes(Transaction *trans, const char *notes)
Sets the transaction Notes.
STRUCTS.
void xaccTransSetDescription(Transaction *trans, const char *desc)
Sets the transaction Description.
void xaccTransRecordPrice(Transaction *trans, PriceSource source)
The xaccTransRecordPrice() method iterates through the splits and and record the non-currency equival...
const char * xaccTransGetNum(const Transaction *trans)
Gets the transaction Number (or ID) field; rather than use this function directly, see &#39;gnc_get_num_action&#39; and &#39;gnc_get_action_num&#39; in engine/engine-helpers.c & .h which takes a user-set book option for selecting the source for the num-cell (the transaction-number or the split-action field) in registers/reports into account automatically.
void xaccTransDestroy(Transaction *trans)
Destroys a transaction.
const char * xaccTransGetNotes(const Transaction *trans)
Gets the transaction Notes.
GList SplitList
GList of Split.
Definition: gnc-engine.h:207
Account handling public routines.
gnc_numeric xaccTransGetImbalanceValue(const Transaction *trans)
The xaccTransGetImbalanceValue() method returns the total value of the transaction.
const char * xaccTransGetDescription(const Transaction *trans)
Gets the transaction Description.
void xaccTransCommitEdit(Transaction *trans)
The xaccTransCommitEdit() method indicates that the changes to the transaction and its splits are com...
void xaccTransBeginEdit(Transaction *trans)
The xaccTransBeginEdit() method must be called before any changes are made to a transaction or any of...
gnc_commodity * xaccTransGetCurrency(const Transaction *trans)
Returns the valuation commodity of this transaction.
PriceSource
Price source enum.
Definition: gnc-pricedb.h:169
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition: gnc-date.h:87
SplitList * xaccTransGetSplitList(const Transaction *trans)
The xaccTransGetSplitList() method returns a GList of the splits in a transaction.