tst_QPointer: add checks involving multiple inheritance
Add a check that we can compare QObjects implementing interfaces to said interface. We can. Pick-to: 6.5 Task-number: QTBUG-135626 Change-Id: I0e1164b43d9112e051add2c034dea50ab5192b2d Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> (cherry picked from commit 154d175c9b7b990e5f27bd4779ae2525ec02a1e2) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 4f325cb6d51652fa7866a20b1f6ea38981bde3fa) (cherry picked from commit f3218e1f603c34f2502d8ebbbb3c8086a6ded377)
This commit is contained in:
committed by
Qt Cherry-pick Bot
parent
9b28b1940b
commit
7f95accae4
@@ -16,6 +16,23 @@
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class Interface
|
||||
{
|
||||
public:
|
||||
virtual ~Interface() = default;
|
||||
virtual void meep() const = 0;
|
||||
};
|
||||
|
||||
class ObjectImplementingInterface : public QObject, public Interface
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using QObject::QObject;
|
||||
|
||||
public Q_SLOTS:
|
||||
void meep() const override {}
|
||||
};
|
||||
|
||||
class tst_QPointer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -31,6 +48,7 @@ private slots:
|
||||
void assignment_operators();
|
||||
void compareCompiles();
|
||||
void equality_operators();
|
||||
void equality_operators_interface();
|
||||
void swap();
|
||||
void isNull();
|
||||
void dereference_operators();
|
||||
@@ -218,6 +236,7 @@ void tst_QPointer::compareCompiles()
|
||||
QTestPrivate::testEqualityOperatorsCompile<QPointer<QObject>, QWidget*>();
|
||||
QTestPrivate::testEqualityOperatorsCompile<QPointer<QObject>, QPointer<QWidget>>();
|
||||
QTestPrivate::testEqualityOperatorsCompile<QPointer<QObject>, std::nullptr_t>();
|
||||
QTestPrivate::testEqualityOperatorsCompile<QPointer<ObjectImplementingInterface>, Interface*>();
|
||||
}
|
||||
|
||||
void tst_QPointer::equality_operators()
|
||||
@@ -259,6 +278,25 @@ void tst_QPointer::equality_operators()
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QPointer::equality_operators_interface()
|
||||
{
|
||||
QObject reaper;
|
||||
QPointer<ObjectImplementingInterface> p(new ObjectImplementingInterface(&reaper));
|
||||
Interface *i = p.get();
|
||||
|
||||
ObjectImplementingInterface otherP;
|
||||
Interface *otherI = &otherP;
|
||||
|
||||
// things that are equal
|
||||
QT_TEST_EQUALITY_OPS(p, p, true);
|
||||
QT_TEST_EQUALITY_OPS(p, i, true);
|
||||
|
||||
// things that are not equal
|
||||
QT_TEST_EQUALITY_OPS(p, nullptr, false);
|
||||
QT_TEST_EQUALITY_OPS(p, &otherP, false);
|
||||
QT_TEST_EQUALITY_OPS(p, otherI, false);
|
||||
}
|
||||
|
||||
void tst_QPointer::swap()
|
||||
{
|
||||
QPointer<QObject> c1, c2;
|
||||
|
||||
Reference in New Issue
Block a user