TaskTree: Add a test for QProcessTask

Change-Id: If49ec3dded8ce92a2a78b55ce95b56e8683de1f5
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2023-10-27 10:50:30 +02:00
parent 65341d7e5f
commit 63bfeba87f
8 changed files with 107 additions and 0 deletions

View File

@@ -1 +1,2 @@
add_subdirectory(qprocesstask)
add_subdirectory(tasking) add_subdirectory(tasking)

View File

@@ -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
)

View File

@@ -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"
}

View File

@@ -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}"
)

View File

@@ -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 <thread>
using namespace std;
int main()
{
this_thread::sleep_for(10s);
return 0;
}

View File

@@ -0,0 +1,12 @@
import qbs.FileInfo
QtApplication {
name: "testsleep"
consoleApplication: true
install: false
files: [
"main.cpp",
]
}

View File

@@ -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 <tasking/qprocesstask.h>
#include <QtTest>
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"

View File

@@ -3,6 +3,7 @@ import qbs
Project { Project {
name: "Solutions autotests" name: "Solutions autotests"
references: [ references: [
"qprocesstask/qprocesstask.qbs",
"tasking/tasking.qbs", "tasking/tasking.qbs",
] ]
} }