Merge branch 'test-qof-plug-leaks' into stable #1773

This commit is contained in:
Christopher Lam 2023-09-18 08:50:33 +08:00
commit b7cac5c301
2 changed files with 16 additions and 1 deletions

View File

@ -64,6 +64,9 @@ setup( Fixture *fixture, gconstpointer pData )
static void
teardown( Fixture *fixture, gconstpointer pData )
{
Account *root = gnc_book_get_root_account (fixture->book);
xaccAccountBeginEdit (root);
xaccAccountDestroy (root);
qof_book_destroy( fixture->book );
}

View File

@ -36,8 +36,20 @@ static bool sync_called {false};
static bool load_error {true};
static bool data_loaded {false};
struct DestroyAccount
{
void operator()(Account *acct)
{
xaccAccountBeginEdit (acct);
xaccAccountDestroy (acct);
}
};
using AccountPtr = std::unique_ptr<Account, DestroyAccount>;
class QofSessionMockBackend : public QofBackend
{
AccountPtr m_root;
public:
QofSessionMockBackend() = default;
QofSessionMockBackend(const QofSessionMockBackend&) = delete;
@ -56,7 +68,7 @@ void QofSessionMockBackend::load (QofBook *book, QofBackendLoadType)
if (load_error)
set_error(ERR_BACKEND_NO_BACKEND);
else
gnc_account_create_root (book);
m_root = AccountPtr{gnc_account_create_root (book)};
data_loaded = true;
}