summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp')
-rw-r--r--tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp104
1 files changed, 103 insertions, 1 deletions
diff --git a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
index 9886ab84f2..7365fee819 100644
--- a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
+++ b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QRunnable>
@@ -19,6 +19,8 @@ public:
private slots:
void constructors();
+ void ctad();
+ void conversion();
void destructor();
void assignment_operators();
void equality_operators();
@@ -34,14 +36,114 @@ private slots:
void constQPointer();
};
+// check that nullptr QPointer construction is Q_CONSTINIT:
+[[maybe_unused]] Q_CONSTINIT static QPointer<QFile> s_file1;
+[[maybe_unused]] Q_CONSTINIT static QPointer<QFile> s_file2 = {};
+[[maybe_unused]] Q_CONSTINIT static QPointer<QFile> s_file3 = nullptr;
+[[maybe_unused]] Q_CONSTINIT static QPointer<QFile> s_file4 = 0; // legacy nullptr
+
void tst_QPointer::constructors()
{
+ struct Derived : QObject {};
+ Derived derived;
+
QPointer<QObject> p1;
QPointer<QObject> p2(this);
QPointer<QObject> p3(p2);
+ QPointer<QObject> p4 = &derived;
QCOMPARE(p1, QPointer<QObject>(0));
QCOMPARE(p2, QPointer<QObject>(this));
QCOMPARE(p3, QPointer<QObject>(this));
+ QCOMPARE(p4, &derived);
+}
+
+void tst_QPointer::ctad()
+{
+
+ {
+ QObject o;
+ QPointer po = &o;
+ static_assert(std::is_same_v<decltype(po), QPointer<QObject>>);
+ QPointer poc = po;
+ static_assert(std::is_same_v<decltype(poc), QPointer<QObject>>);
+ QPointer pom = std::move(po);
+ static_assert(std::is_same_v<decltype(pom), QPointer<QObject>>);
+ }
+ {
+ const QObject co;
+ QPointer pco = &co;
+ static_assert(std::is_same_v<decltype(pco), QPointer<const QObject>>);
+ QPointer pcoc = pco;
+ static_assert(std::is_same_v<decltype(pcoc), QPointer<const QObject>>);
+ QPointer pcom = std::move(pco);
+ static_assert(std::is_same_v<decltype(pcom), QPointer<const QObject>>);
+ }
+ {
+ QFile f;
+ QPointer pf = &f;
+ static_assert(std::is_same_v<decltype(pf), QPointer<QFile>>);
+ QPointer pfc = pf;
+ static_assert(std::is_same_v<decltype(pfc), QPointer<QFile>>);
+ QPointer pfm = std::move(pf);
+ static_assert(std::is_same_v<decltype(pfm), QPointer<QFile>>);
+ }
+ {
+ const QFile cf;
+ QPointer pcf = &cf;
+ static_assert(std::is_same_v<decltype(pcf), QPointer<const QFile>>);
+ QPointer pcfc = pcf;
+ static_assert(std::is_same_v<decltype(pcfc), QPointer<const QFile>>);
+ QPointer pcfm = std::move(pcf);
+ static_assert(std::is_same_v<decltype(pcfm), QPointer<const QFile>>);
+ }
+}
+
+void tst_QPointer::conversion()
+{
+ // copy-conversion:
+ {
+ QFile file;
+ QPointer<QFile> pf = &file;
+ QCOMPARE_EQ(pf, &file);
+ QPointer<const QIODevice> pio = pf;
+ QCOMPARE_EQ(pio, &file);
+ QCOMPARE_EQ(pio.get(), &file);
+ QCOMPARE_EQ(pio, pf);
+ QCOMPARE_EQ(pio.get(), pf.get());
+
+ // reset
+ pio = nullptr;
+ QCOMPARE_EQ(pio, nullptr);
+ QCOMPARE_EQ(pio.get(), nullptr);
+
+ // copy-assignment
+ QCOMPARE_EQ(pf, &file);
+ pio = pf;
+ QCOMPARE_EQ(pio, &file);
+ QCOMPARE_EQ(pio.get(), &file);
+ QCOMPARE_EQ(pio, pf);
+ QCOMPARE_EQ(pio.get(), pf.get());
+ }
+ // move-conversion:
+ {
+ QFile file;
+ QPointer<QFile> pf = &file;
+ QCOMPARE_EQ(pf, &file);
+ QPointer<const QIODevice> pio = std::move(pf);
+ QCOMPARE_EQ(pf, nullptr);
+ QCOMPARE_EQ(pio, &file);
+ QCOMPARE_EQ(pio.get(), &file);
+
+ // reset
+ pio = nullptr;
+ QCOMPARE_EQ(pio, nullptr);
+ QCOMPARE_EQ(pio.get(), nullptr);
+
+ // move-assignment
+ pio = QPointer<QFile>(&file);
+ QCOMPARE_EQ(pio, &file);
+ QCOMPARE_EQ(pio.get(), &file);
+ }
}
void tst_QPointer::destructor()