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.cpp131
1 files changed, 104 insertions, 27 deletions
diff --git a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
index 6f9a422820..7365fee819 100644
--- a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
+++ b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QRunnable>
@@ -44,6 +19,8 @@ public:
private slots:
void constructors();
+ void ctad();
+ void conversion();
void destructor();
void assignment_operators();
void equality_operators();
@@ -59,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()