diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/cmake/CMakeLists.txt | 19 | ||||
-rw-r--r-- | tests/auto/cmake/test_widgets_app_deployment/CMakeLists.txt | 60 | ||||
-rw-r--r-- | tests/auto/cmake/test_widgets_app_deployment/main.cpp | 47 |
3 files changed, 126 insertions, 0 deletions
diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index 8073a47c16..54ce69f0be 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -284,3 +284,22 @@ _qt_internal_test_expect_pass(test_static_resources _qt_internal_test_expect_pass(test_generating_cpp_exports) _qt_internal_test_expect_pass(test_qt_extract_metatypes) + +set(deploy_args + test_widgets_app_deployment + BINARY "${CMAKE_CTEST_COMMAND}" + BINARY_ARGS "-V" + # Need to explicitly specify a writable install prefix. + BUILD_OPTIONS + -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test_widgets_app_deployment_installed +) + +# For now, the test should only pass on Windows and macOS shared and static builds and fail on +# other platforms, because there is no support for runtime dependency deployment +# on those platforms. +# With static builds the runtime dependencies are just skipped, but the test should still pass. +if((WIN32 OR (APPLE AND NOT IOS))) + _qt_internal_test_expect_pass(${deploy_args}) +else() + _qt_internal_test_expect_fail(${deploy_args}) +endif() diff --git a/tests/auto/cmake/test_widgets_app_deployment/CMakeLists.txt b/tests/auto/cmake/test_widgets_app_deployment/CMakeLists.txt new file mode 100644 index 0000000000..aa30954f45 --- /dev/null +++ b/tests/auto/cmake/test_widgets_app_deployment/CMakeLists.txt @@ -0,0 +1,60 @@ +cmake_minimum_required(VERSION 3.16) +project(deployment_api) +enable_testing() + +find_package(Qt6 COMPONENTS REQUIRED Widgets Test) + +qt6_standard_project_setup() + +function(create_test_executable target) + cmake_parse_arguments(arg "" "" "" ${ARGN}) + + qt_add_executable(${target} main.cpp) + set_target_properties(${target} PROPERTIES + # We explicitly don't set WIN32_EXECUTABLE to ensure we see errors from stderr when + # something fails and not having to use DebugView. + + MACOSX_BUNDLE TRUE + ) + target_link_libraries(${target} PRIVATE Qt::Widgets Qt::Test) + + install(TARGETS ${target} + BUNDLE DESTINATION . + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ) + + qt_generate_deploy_app_script( + TARGET ${target} + FILENAME_VARIABLE deploy_script + # Don't fail at configure time on unsupported platforms + NO_UNSUPPORTED_PLATFORM_ERROR + ) + install(SCRIPT ${deploy_script}) + + if(APPLE AND NOT IOS) + set(installed_app_location "${CMAKE_INSTALL_PREFIX}/${target}.app/Contents/MacOS/${target}") + elseif(WIN32) + set(installed_app_location "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/${target}.exe") + endif() + + # There's no nice way to get the location of an installed binary, so we need to construct + # the binary install path by hand, somewhat similar to how it's done in + # the implementation of qt_deploy_runtime_dependencies. + # On unsupported deployment platforms, either the install_ test will fail not finding + # the location of the app (because we do not set a installed_app_location value) + # or the run_deployed_ test will fail because we didn't deploy the runtime dependencies. + # When support for additional platforms is added, these locations will have to be augmented. + add_test(install_${target} "${CMAKE_COMMAND}" --install .) + set_tests_properties(install_${target} PROPERTIES FIXTURES_SETUP deploy_step) + add_test(NAME run_deployed_${target} + COMMAND "${installed_app_location}" + # Make sure that we don't use the default working directory which is + # CMAKE_CURRENT_BINARY_DIR because on Windows the loader might pick up dlls + # from the working directory instead of the installed app dir, if the dll is + # missing in the app dir. + WORKING_DIRECTORY "${CMAKE_INSTALL_PREFIX}") + set_tests_properties(run_deployed_${target} PROPERTIES FIXTURES_REQUIRED deploy_step) +endfunction() + +create_test_executable(App) + diff --git a/tests/auto/cmake/test_widgets_app_deployment/main.cpp b/tests/auto/cmake/test_widgets_app_deployment/main.cpp new file mode 100644 index 0000000000..40bcb0516c --- /dev/null +++ b/tests/auto/cmake/test_widgets_app_deployment/main.cpp @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: http://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$ +** +****************************************************************************/ +#include <QtTest> +#include <QMainWindow> + +class test_widgets_app_deployment : public QObject +{ + Q_OBJECT +private slots: + void canRun(); +}; + +void test_widgets_app_deployment::canRun() +{ + QMainWindow mw; + mw.show(); + QVERIFY(QTest::qWaitForWindowActive(&mw)); +} + +QTEST_MAIN(test_widgets_app_deployment) + +#include "main.moc" |