From 0e634c54460463de2c8bc1204835041d03a014e0 Mon Sep 17 00:00:00 2001 From: Christian Gruber Date: Tue, 22 Sep 2020 22:20:38 +0200 Subject: [PATCH] Relax runtime type checks Runtime type checks should only check for the mock up type, if neccessary. If objects of another class than the mocked object itself are processed, runtime type check should only check for the base-class type. It should be possible to use mockup objects and non-mockup objects within the same application. The included headers are adapted accordingly. --- libgnucash/engine/mocks/fake-qofquery.cpp | 5 +++-- libgnucash/engine/mocks/gmock-Split.cpp | 9 +++++---- libgnucash/engine/mocks/gmock-Transaction.cpp | 5 +++-- libgnucash/engine/mocks/gmock-qofbook.h | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/libgnucash/engine/mocks/fake-qofquery.cpp b/libgnucash/engine/mocks/fake-qofquery.cpp index dc8445d4d9..53dddfd804 100644 --- a/libgnucash/engine/mocks/fake-qofquery.cpp +++ b/libgnucash/engine/mocks/fake-qofquery.cpp @@ -4,10 +4,11 @@ #include +#include + #include #include "fake-qofquery.h" -#include "gmock-qofbook.h" @@ -119,7 +120,7 @@ void qof_query_set_book (QofQuery *query, QofBook *book) { ASSERT_TRUE(queryPool.query_used(query)); - ASSERT_TRUE(QOF_IS_MOCKBOOK(book)); + ASSERT_TRUE(QOF_IS_BOOK(book)); ((QofFakeQuery*)query)->set_book(book); } diff --git a/libgnucash/engine/mocks/gmock-Split.cpp b/libgnucash/engine/mocks/gmock-Split.cpp index 2cf34bc22c..1355f121da 100644 --- a/libgnucash/engine/mocks/gmock-Split.cpp +++ b/libgnucash/engine/mocks/gmock-Split.cpp @@ -1,9 +1,10 @@ #include +#include +#include + #include "gmock-Split.h" #include "gmock-qofbook.h" -#include "gmock-Account.h" -#include "gmock-Transaction.h" struct _MockSplitClass @@ -60,7 +61,7 @@ void xaccSplitSetAccount (Split *split, Account *acc) { ASSERT_TRUE(GNC_IS_MOCKSPLIT(split)); - ASSERT_TRUE(GNC_IS_MOCKACCOUNT(acc)); + ASSERT_TRUE(GNC_IS_ACCOUNT(acc)); gnc_mocksplit(split)->set_account(acc); } @@ -152,6 +153,6 @@ void xaccSplitSetParent(Split *split, Transaction *trans) { ASSERT_TRUE(GNC_IS_MOCKSPLIT(split)); - ASSERT_TRUE(GNC_IS_MOCKTRANSACTION(trans)); + ASSERT_TRUE(GNC_IS_TRANSACTION(trans)); gnc_mocksplit(split)->set_parent(trans); } diff --git a/libgnucash/engine/mocks/gmock-Transaction.cpp b/libgnucash/engine/mocks/gmock-Transaction.cpp index 597971b6e1..bde81b33c4 100644 --- a/libgnucash/engine/mocks/gmock-Transaction.cpp +++ b/libgnucash/engine/mocks/gmock-Transaction.cpp @@ -1,7 +1,8 @@ #include +#include + #include "gmock-Transaction.h" -#include "gmock-Account.h" struct _MockTransactionClass @@ -57,7 +58,7 @@ xaccTransFindSplitByAccount(const Transaction *trans, const Account *acc) { SCOPED_TRACE(""); const MockTransaction* mocktrans = gnc_mocktransaction(trans); - EXPECT_TRUE(GNC_IS_MOCKACCOUNT(acc)); + EXPECT_TRUE(GNC_IS_ACCOUNT(acc)); return mocktrans ? mocktrans->find_split_by_account(acc) : nullptr; } diff --git a/libgnucash/engine/mocks/gmock-qofbook.h b/libgnucash/engine/mocks/gmock-qofbook.h index 035eb1a9c1..7001697afc 100644 --- a/libgnucash/engine/mocks/gmock-qofbook.h +++ b/libgnucash/engine/mocks/gmock-qofbook.h @@ -5,9 +5,9 @@ #include #include +#include #include "gmock-gobject.h" -#include "gmock-Split.h" GType qof_mockbook_get_type(void);