diff options
Diffstat (limited to 'tests/auto/corelib/kernel/qapplicationstatic')
-rw-r--r-- | tests/auto/corelib/kernel/qapplicationstatic/CMakeLists.txt | 17 | ||||
-rw-r--r-- | tests/auto/corelib/kernel/qapplicationstatic/tst_qapplicationstatic.cpp | 40 |
2 files changed, 57 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qapplicationstatic/CMakeLists.txt b/tests/auto/corelib/kernel/qapplicationstatic/CMakeLists.txt new file mode 100644 index 0000000000..9332b6ecd0 --- /dev/null +++ b/tests/auto/corelib/kernel/qapplicationstatic/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## tst_qapplicationstatic Test: +##################################################################### + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qapplicationstatic LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qapplicationstatic + SOURCES + tst_qapplicationstatic.cpp + ) diff --git a/tests/auto/corelib/kernel/qapplicationstatic/tst_qapplicationstatic.cpp b/tests/auto/corelib/kernel/qapplicationstatic/tst_qapplicationstatic.cpp new file mode 100644 index 0000000000..dd9a415a52 --- /dev/null +++ b/tests/auto/corelib/kernel/qapplicationstatic/tst_qapplicationstatic.cpp @@ -0,0 +1,40 @@ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QTest> +#include <QPointer> +#include "QtCore/qapplicationstatic.h" + +Q_APPLICATION_STATIC(QObject, tstObject) + +class tst_qapplicationstatic : public QObject +{ + Q_OBJECT + +private slots: + void testCreateMultipleApplications() const; +}; + +void tst_qapplicationstatic::testCreateMultipleApplications() const +{ + for (int i = 0; i < 5; i++) { + int argc = 1; + char *argv[] = { (char *)"tst_qapplicationstatic" }; + auto app = new QCoreApplication(argc, argv); + + QVERIFY(tstObject); + + QPointer<QObject> tstObjectPointer(tstObject); + QVERIFY(tstObjectPointer.get()); + + QVERIFY2(tstObject->objectName().isEmpty(), "Got QObject from previous iteration, not correctly recreated"); + tstObject->setObjectName(QStringLiteral("tstObject")); + QVERIFY(!tstObject->objectName().isEmpty()); + + delete app; + QVERIFY2(!tstObjectPointer.get(), "QObject wasn't destroyed on QCoreApplication destruction"); + } +} + +QTEST_APPLESS_MAIN(tst_qapplicationstatic) +#include "tst_qapplicationstatic.moc" |