From f1cb2edd1e6a306f4ddacf43135d42e46d2d30b2 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Fri, 2 Feb 2024 12:32:37 +0100 Subject: [PATCH] CMake: Add test for configuring a standalone test A standalone test is one that uses find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) in its project code. To ensure we don't accidentally regress this feature, test it as a cmake test. Also run test, this somewhat covers testing qt_internal_add_test. Pick-to: 6.6 6.5 Change-Id: Ia9f27eef2bd7bd5bb57b96e553304924db252365 Reviewed-by: Alexey Edelev Reviewed-by: Qt CI Bot (cherry picked from commit a61ac2ca58eb705021176720d481c0eb4c925c2a) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/cmake/CMakeLists.txt | 6 +++++ .../cmake/test_standalone_test/CMakeLists.txt | 14 ++++++++++++ .../tst_standalone_test.cpp | 22 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 tests/auto/cmake/test_standalone_test/CMakeLists.txt create mode 100644 tests/auto/cmake/test_standalone_test/tst_standalone_test.cpp diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index 707065f2826..c5fba0d8a7c 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -338,6 +338,12 @@ if(is_qt_build_platform) set_tests_properties(test_import_plugins PROPERTIES FIXTURES_REQUIRED build_mockplugins) endif() +if(NOT NO_GUI) + _qt_internal_test_expect_pass(test_standalone_test + BINARY "${CMAKE_CTEST_COMMAND}" + BINARY_ARGS "-V") +endif() + _qt_internal_test_expect_pass(test_versionless_targets) if(NOT NO_GUI) diff --git a/tests/auto/cmake/test_standalone_test/CMakeLists.txt b/tests/auto/cmake/test_standalone_test/CMakeLists.txt new file mode 100644 index 00000000000..169d824c887 --- /dev/null +++ b/tests/auto/cmake/test_standalone_test/CMakeLists.txt @@ -0,0 +1,14 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) +project(tststandalone_test LANGUAGES CXX) +find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) + +qt_internal_add_test(tst_standalone_test + GUI + SOURCES + tst_standalone_test.cpp + LIBRARIES + Qt::Gui +) diff --git a/tests/auto/cmake/test_standalone_test/tst_standalone_test.cpp b/tests/auto/cmake/test_standalone_test/tst_standalone_test.cpp new file mode 100644 index 00000000000..b9a7089218e --- /dev/null +++ b/tests/auto/cmake/test_standalone_test/tst_standalone_test.cpp @@ -0,0 +1,22 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include +#include + +class tst_standalone_test : public QObject +{ + Q_OBJECT + +private slots: + void testLaunched() + { + QWindow w; + w.show(); + QVERIFY(QTest::qWaitForWindowActive(&w)); + } +}; + +QTEST_MAIN(tst_standalone_test) + +#include "tst_standalone_test.moc"