forked from qt-creator/qt-creator
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:
@@ -1 +1,2 @@
|
||||
add_subdirectory(qprocesstask)
|
||||
add_subdirectory(tasking)
|
||||
|
7
tests/auto/solutions/qprocesstask/CMakeLists.txt
Normal file
7
tests/auto/solutions/qprocesstask/CMakeLists.txt
Normal 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
|
||||
)
|
25
tests/auto/solutions/qprocesstask/qprocesstask.qbs
Normal file
25
tests/auto/solutions/qprocesstask/qprocesstask.qbs
Normal 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"
|
||||
}
|
@@ -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}"
|
||||
)
|
12
tests/auto/solutions/qprocesstask/testsleep/main.cpp
Normal file
12
tests/auto/solutions/qprocesstask/testsleep/main.cpp
Normal 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;
|
||||
}
|
12
tests/auto/solutions/qprocesstask/testsleep/testsleep.qbs
Normal file
12
tests/auto/solutions/qprocesstask/testsleep/testsleep.qbs
Normal file
@@ -0,0 +1,12 @@
|
||||
import qbs.FileInfo
|
||||
|
||||
QtApplication {
|
||||
name: "testsleep"
|
||||
|
||||
consoleApplication: true
|
||||
|
||||
install: false
|
||||
files: [
|
||||
"main.cpp",
|
||||
]
|
||||
}
|
40
tests/auto/solutions/qprocesstask/tst_qprocesstask.cpp
Normal file
40
tests/auto/solutions/qprocesstask/tst_qprocesstask.cpp
Normal 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"
|
@@ -3,6 +3,7 @@ import qbs
|
||||
Project {
|
||||
name: "Solutions autotests"
|
||||
references: [
|
||||
"qprocesstask/qprocesstask.qbs",
|
||||
"tasking/tasking.qbs",
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user