Files
gnucash/libgnucash/engine/mocks/gmock-Split.hpp
T
Noah R 3e98c5d8c8 [engine] Add first-class online_id accessors for Split and Account
Promote the OFX/HBCI online_id to named engine accessors:
  xaccSplitGetOnlineID / SetOnlineID / HasOnlineID
  xaccAccountGetOnlineID / SetOnlineID
The getters return an instance-owned const char* (mirroring
xaccTransGetDocLink / xaccTransGetNotes), so the existing
add_methods_with_prefix auto-wrapper exposes them in the Python bindings
with no .i changes and no %newobject.  They write to the same engine KVP
slot ("online_id") the desktop importer uses, so there is no data or
behavior change.

With the accessors in place the gnc_import_*_online_id wrappers in
import-utilities are redundant, so replace every call site (OFX,
AqBanking, and the generic matcher/backend) with them, delete
import-utilities.cpp, and drop the online_id declarations from
import-utilities.h (its importer preference-key macros are retained).

- The engine getters return an instance-owned const char* instead of a
  g_strdup'd copy, so callers no longer free the result; the affected
  locals are retyped const and their g_free()s dropped.
  hash_account_online_ids() g_strdups before inserting, since its hash
  table owns its keys (g_free key-destructor).
- xaccAccountSetOnlineID(acc, "") clears the slot, matching the OFX
  "delete the online_id" intent (the old wrapper stored an empty string).
- Drop the two unused wrappers: gnc_import_set_trans_online_id (marked
  "Not actually used") and gnc_import_trans_has_online_id (no callers).
- Add xaccSplitGet/SetOnlineID to the Split gmock so test-import-backend
  links without import-utilities.
2026-06-21 16:43:03 -07:00

113 lines
3.1 KiB
C++

#ifndef GMOCK_SPLIT_H
#define GMOCK_SPLIT_H
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcpp"
#include <gmock/gmock.h>
#pragma GCC diagnostic pop
#include <Split.h>
#include <SplitP.hpp>
#include "gmock-qofbook.hpp"
#include "gmock-gobject.h"
GType gnc_mocksplit_get_type(void);
#define GNC_TYPE_MOCKSPLIT (gnc_mocksplit_get_type ())
#define GNC_IS_MOCKSPLIT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_MOCKSPLIT))
// mock up for Split
class MockSplit : public Split
{
public:
MockSplit()
{
acc = nullptr;
orig_acc = nullptr;
parent = nullptr;
orig_parent = nullptr;
lot = nullptr;
action = nullptr;
memo = nullptr;
reconciled = VREC;
amount = gnc_numeric_zero();
value = gnc_numeric_zero();
date_reconciled = 0;
balance = gnc_numeric_zero();
cleared_balance = gnc_numeric_zero();
reconciled_balance = gnc_numeric_zero();
noclosing_balance = gnc_numeric_zero();
gains = GAINS_STATUS_UNKNOWN;
gains_split = nullptr;
}
void* operator new(size_t size)
{
return mock_g_object_new (GNC_TYPE_MOCKSPLIT, NULL, size);
}
// define separate free() function since destructor is protected
void free()
{
delete this;
}
void operator delete(void* split, size_t size)
{
mock_g_object_unref(split, size);
}
MOCK_METHOD0(init, void());
MOCK_CONST_METHOD0(get_book, QofBook *());
MOCK_CONST_METHOD0(get_account, Account *());
MOCK_METHOD1(set_account, void(Account*));
MOCK_CONST_METHOD0(get_amount, gnc_numeric());
MOCK_METHOD1(set_amount, void(gnc_numeric));
MOCK_CONST_METHOD0(get_value, gnc_numeric());
MOCK_METHOD1(set_value, void(gnc_numeric));
MOCK_CONST_METHOD0(get_memo, const char *());
MOCK_METHOD1(set_memo, void(const char *));
MOCK_CONST_METHOD0(get_online_id, const char *());
MOCK_METHOD1(set_online_id, void(const char *));
MOCK_CONST_METHOD0(get_reconcile, char());
MOCK_METHOD1(set_reconcile, void(char));
MOCK_METHOD1(set_date_reconciled_secs, void(time64));
MOCK_CONST_METHOD0(get_action, const char *());
MOCK_CONST_METHOD0(get_other_split, Split *());
MOCK_CONST_METHOD0(get_parent, Transaction *());
MOCK_METHOD1(set_parent, void(Transaction*));
protected:
// Protect destructor to avoid MockSplit objects to be created on stack. MockSplit
// objects can only be dynamically created, since they are derived from GObject.
~MockSplit() {}
};
// type conversion functions
static inline MockSplit*
gnc_mocksplit (Split *split)
{
if (GNC_IS_MOCKSPLIT(split))
return static_cast<MockSplit*>(split);
ADD_FAILURE() << "Expected 'split' to be of type 'MockSplit'";
return nullptr;
}
static inline const MockSplit*
gnc_mocksplit (const Split *split)
{
if (GNC_IS_MOCKSPLIT(split))
return static_cast<const MockSplit*>(split);
ADD_FAILURE() << "Expected 'split' to be of type 'MockSplit'";
return nullptr;
}
#endif