mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-07 01:35:25 +08:00
qt 6.5.1 original
This commit is contained in:
14
tests/auto/other/qprocess_and_guieventloop/CMakeLists.txt
Normal file
14
tests/auto/other/qprocess_and_guieventloop/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## tst_qprocess_and_guieventloop Test:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_test(tst_qprocess_and_guieventloop
|
||||
SOURCES
|
||||
tst_qprocess_and_guieventloop.cpp
|
||||
LIBRARIES
|
||||
Qt::Gui
|
||||
)
|
||||
add_subdirectory(write-read-write)
|
@ -0,0 +1,58 @@
|
||||
// Copyright (C) 2021 The Qt Company Ltd.
|
||||
// Copyright (C) 2016 Intel Corporation.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QtGui/QGuiApplication>
|
||||
#include <QTest>
|
||||
#include <QSignalSpy>
|
||||
#include <QtCore/QProcess>
|
||||
|
||||
class tst_QProcess_and_GuiEventLoop : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void waitForAndEventLoop();
|
||||
};
|
||||
|
||||
|
||||
void tst_QProcess_and_GuiEventLoop::waitForAndEventLoop()
|
||||
{
|
||||
#ifdef Q_OS_ANDROID
|
||||
QSKIP("Not supported on Android");
|
||||
#else
|
||||
|
||||
// based on testcase provided in QTBUG-39488
|
||||
QByteArray msg = "Hello World";
|
||||
|
||||
QProcess process;
|
||||
process.start("write-read-write/write-read-write", QStringList() << msg);
|
||||
QVERIFY(process.waitForStarted(5000));
|
||||
QVERIFY(process.waitForReadyRead(5000));
|
||||
QCOMPARE(process.readAll().trimmed(), msg);
|
||||
|
||||
// run the GUI event dispatcher once
|
||||
QSignalSpy spy(&process, SIGNAL(readyRead()));
|
||||
qApp->processEvents(QEventLoop::AllEvents, 100);
|
||||
|
||||
// we mustn't have read anything in the event loop
|
||||
QCOMPARE(spy.size(), 0);
|
||||
|
||||
// ensure the process hasn't died
|
||||
QVERIFY(!process.waitForFinished(250));
|
||||
|
||||
// we mustn't have read anything during waitForFinished either
|
||||
QCOMPARE(spy.size(), 0);
|
||||
|
||||
// release the child for the second write
|
||||
process.write("\n");
|
||||
QVERIFY(process.waitForFinished(5000));
|
||||
QCOMPARE(int(process.exitStatus()), int(QProcess::NormalExit));
|
||||
QCOMPARE(process.exitCode(), 0);
|
||||
QCOMPARE(spy.size(), 1);
|
||||
QCOMPARE(process.readAll().trimmed(), msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QProcess_and_GuiEventLoop)
|
||||
|
||||
#include "tst_qprocess_and_guieventloop.moc"
|
@ -0,0 +1,12 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## write-read-write Binary:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_executable(write-read-write
|
||||
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/"
|
||||
SOURCES
|
||||
main.cpp
|
||||
)
|
@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2016 Intel Corporation.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int, char **argv)
|
||||
{
|
||||
const char *msg = argv[1];
|
||||
char buf[2];
|
||||
|
||||
puts(msg);
|
||||
fflush(stdout);
|
||||
|
||||
// wait for a newline
|
||||
const char *result = fgets(buf, sizeof buf, stdin);
|
||||
if (result != buf)
|
||||
return -1;
|
||||
|
||||
puts(msg);
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user