From 8d005e7565b80f161a51bebb26cf62c700b39dd6 Mon Sep 17 00:00:00 2001 From: Johannes Lorenz Date: Sat, 27 Apr 2019 10:48:37 +0200 Subject: [PATCH] AutomatableModelTest: Improve tests Check whether returned pointers from the cast are equal to the original pointers, rather than just checking wether they are not `nullptr`. --- tests/src/core/AutomatableModelTest.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/src/core/AutomatableModelTest.cpp b/tests/src/core/AutomatableModelTest.cpp index 9bc19d7e8..6717da12d 100644 --- a/tests/src/core/AutomatableModelTest.cpp +++ b/tests/src/core/AutomatableModelTest.cpp @@ -32,21 +32,23 @@ class AutomatableModelTest : QTestSuite Q_OBJECT private slots: + //! Test that upcast and exact casts work, + //! but no downcast or any other casts void CastTests() { ComboBoxModel comboModel; AutomatableModel* amPtr = &comboModel; - QCOMPARE(nullptr, amPtr->dynamicCast()); - QVERIFY(nullptr != amPtr->dynamicCast()); - QVERIFY(nullptr != amPtr->dynamicCast()); - QVERIFY(nullptr != amPtr->dynamicCast()); + QCOMPARE(nullptr, amPtr->dynamicCast()); // not a parent class + QCOMPARE(&comboModel, amPtr->dynamicCast()); // parent class + QCOMPARE(&comboModel, amPtr->dynamicCast()); // parent class + QCOMPARE(&comboModel, amPtr->dynamicCast()); // same class IntModel intModel; IntModel* imPtr = &intModel; - QCOMPARE(nullptr, imPtr->dynamicCast()); - QVERIFY(nullptr != imPtr->dynamicCast()); - QVERIFY(nullptr != imPtr->dynamicCast()); - QCOMPARE(nullptr, imPtr->dynamicCast()); + QCOMPARE(nullptr, imPtr->dynamicCast()); // not a parent class + QCOMPARE(&intModel, imPtr->dynamicCast()); // parent class + QCOMPARE(&intModel, imPtr->dynamicCast()); // same class + QCOMPARE(nullptr, imPtr->dynamicCast()); // child class } } AutomatableModelTests;