Skip to content

Commit

Permalink
Relax runtime type checks
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Christian Gruber committed Sep 22, 2020
1 parent 99256c3 commit 0e634c5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
5 changes: 3 additions & 2 deletions libgnucash/engine/mocks/fake-qofquery.cpp
Expand Up @@ -4,10 +4,11 @@

#include <config.h>

#include <qofbook.h>

#include <list>

#include "fake-qofquery.h"
#include "gmock-qofbook.h"



Expand Down Expand Up @@ -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);
}

Expand Down
9 changes: 5 additions & 4 deletions libgnucash/engine/mocks/gmock-Split.cpp
@@ -1,9 +1,10 @@
#include <config.h>

#include <Transaction.h>
#include <Account.h>

#include "gmock-Split.h"
#include "gmock-qofbook.h"
#include "gmock-Account.h"
#include "gmock-Transaction.h"


struct _MockSplitClass
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
5 changes: 3 additions & 2 deletions libgnucash/engine/mocks/gmock-Transaction.cpp
@@ -1,7 +1,8 @@
#include <config.h>

#include <Account.h>

#include "gmock-Transaction.h"
#include "gmock-Account.h"


struct _MockTransactionClass
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion libgnucash/engine/mocks/gmock-qofbook.h
Expand Up @@ -5,9 +5,9 @@

#include <qofbook.h>
#include <qofbook-p.h>
#include <Split.h>

#include "gmock-gobject.h"
#include "gmock-Split.h"


GType qof_mockbook_get_type(void);
Expand Down

0 comments on commit 0e634c5

Please sign in to comment.