summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2025-06-24 22:00:57 +0200
committerMarc Mutz <[email protected]>2025-07-03 13:49:20 +0200
commit154d175c9b7b990e5f27bd4779ae2525ec02a1e2 (patch)
tree8a2d68078c8ee5073fbd2885cfe05025fb49618b /tests/auto
parent48e64f821ac3d6c7b3d825d6f8a94f69fa491136 (diff)
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.10 6.9 6.8 6.5 Task-number: QTBUG-135626 Change-Id: I0e1164b43d9112e051add2c034dea50ab5192b2d Reviewed-by: Ivan Solovev <[email protected]>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
index f66bea72828..d53d0d1713d 100644
--- a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
+++ b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
@@ -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;