diff --git a/tests/auto/solutions/CMakeLists.txt b/tests/auto/solutions/CMakeLists.txt index 694d940195d..848b48eca9a 100644 --- a/tests/auto/solutions/CMakeLists.txt +++ b/tests/auto/solutions/CMakeLists.txt @@ -1 +1,2 @@ +add_subdirectory(qprocesstask) add_subdirectory(tasking) diff --git a/tests/auto/solutions/qprocesstask/CMakeLists.txt b/tests/auto/solutions/qprocesstask/CMakeLists.txt new file mode 100644 index 00000000000..dab250943cf --- /dev/null +++ b/tests/auto/solutions/qprocesstask/CMakeLists.txt @@ -0,0 +1,7 @@ +add_subdirectory(testsleep) + +add_qtc_test(tst_qprocesstask + DEFINES "PROCESS_TESTAPP=\"${CMAKE_CURRENT_BINARY_DIR}/testsleep\"" + DEPENDS Tasking Qt::Network + SOURCES tst_qprocesstask.cpp +) diff --git a/tests/auto/solutions/qprocesstask/qprocesstask.qbs b/tests/auto/solutions/qprocesstask/qprocesstask.qbs new file mode 100644 index 00000000000..c1bc1ce889d --- /dev/null +++ b/tests/auto/solutions/qprocesstask/qprocesstask.qbs @@ -0,0 +1,25 @@ +import qbs.FileInfo + +Project { + QtcAutotest { + name: "QProcessTask autotest" + + Depends { name: "Qt"; submodules: ["network"] } + Depends { name: "Tasking" } + + files: [ + "tst_qprocesstask.cpp", + ] + cpp.defines: { + var defines = base; + if (qbs.targetOS === "windows") + defines.push("_CRT_SECURE_NO_WARNINGS"); + defines.push('PROCESS_TESTAPP="' + + FileInfo.joinPaths(destinationDirectory, "testsleep") + '"'); + return defines; + } + destinationDirectory: project.buildDirectory + '/' + + FileInfo.relativePath(project.ide_source_tree, sourceDirectory) + } + references: "testsleep/testsleep.qbs" +} diff --git a/tests/auto/solutions/qprocesstask/testsleep/CMakeLists.txt b/tests/auto/solutions/qprocesstask/testsleep/CMakeLists.txt new file mode 100644 index 00000000000..b1e6ceffe4e --- /dev/null +++ b/tests/auto/solutions/qprocesstask/testsleep/CMakeLists.txt @@ -0,0 +1,9 @@ +add_qtc_executable(testsleep + SOURCES main.cpp + SKIP_INSTALL + INTERNAL_ONLY +) + +set_target_properties(testsleep PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" +) diff --git a/tests/auto/solutions/qprocesstask/testsleep/main.cpp b/tests/auto/solutions/qprocesstask/testsleep/main.cpp new file mode 100644 index 00000000000..cfe8752e02a --- /dev/null +++ b/tests/auto/solutions/qprocesstask/testsleep/main.cpp @@ -0,0 +1,12 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include + +using namespace std; + +int main() +{ + this_thread::sleep_for(10s); + return 0; +} diff --git a/tests/auto/solutions/qprocesstask/testsleep/testsleep.qbs b/tests/auto/solutions/qprocesstask/testsleep/testsleep.qbs new file mode 100644 index 00000000000..ae9bbd9431d --- /dev/null +++ b/tests/auto/solutions/qprocesstask/testsleep/testsleep.qbs @@ -0,0 +1,12 @@ +import qbs.FileInfo + +QtApplication { + name: "testsleep" + + consoleApplication: true + + install: false + files: [ + "main.cpp", + ] +} diff --git a/tests/auto/solutions/qprocesstask/tst_qprocesstask.cpp b/tests/auto/solutions/qprocesstask/tst_qprocesstask.cpp new file mode 100644 index 00000000000..f4bff2e0981 --- /dev/null +++ b/tests/auto/solutions/qprocesstask/tst_qprocesstask.cpp @@ -0,0 +1,40 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include + +#include + +using namespace Tasking; + +class tst_QProcessTask : public QObject +{ + Q_OBJECT + +private slots: + void qProcessTask(); +}; + +#ifdef Q_OS_WIN +static const char s_processName[] = "testsleep.exe"; +#else +static const char s_processName[] = "testsleep"; +#endif + +void tst_QProcessTask::qProcessTask() +{ + const auto setupProcess = [](QProcess &process) { + process.setProgram(QLatin1String(PROCESS_TESTAPP) + '/' + s_processName); + }; + + { + TaskTree taskTree({QProcessTask(setupProcess)}); + taskTree.start(); + QTRY_VERIFY(taskTree.isRunning()); + } + QProcessDeleter::deleteAll(); +} + +QTEST_GUILESS_MAIN(tst_QProcessTask) + +#include "tst_qprocesstask.moc" diff --git a/tests/auto/solutions/solutions.qbs b/tests/auto/solutions/solutions.qbs index cc445753cc2..b96095f3dbe 100644 --- a/tests/auto/solutions/solutions.qbs +++ b/tests/auto/solutions/solutions.qbs @@ -3,6 +3,7 @@ import qbs Project { name: "Solutions autotests" references: [ + "qprocesstask/qprocesstask.qbs", "tasking/tasking.qbs", ] }