summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/io/qprocess/tst_qprocess.cpp')
-rw-r--r--tests/auto/corelib/io/qprocess/tst_qprocess.cpp96
1 files changed, 62 insertions, 34 deletions
diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
index 7e1d5487ba..1f0ace0dd3 100644
--- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
+++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
@@ -1,32 +1,27 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Copyright (C) 2015 Intel Corporation.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2016 Intel Corporation.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** 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$
**
@@ -128,7 +123,8 @@ private slots:
void spaceArgsTest();
#if defined(Q_OS_WIN)
void nativeArguments();
-#endif
+ void createProcessArgumentsModifier();
+#endif // Q_OS_WIN
void exitCodeTest();
void systemEnvironment();
void lockupsInStartDetached();
@@ -492,9 +488,11 @@ void tst_QProcess::echoTest2()
QCOMPARE(process.error(), QProcess::Timedout);
process.write("Hello");
+ QSignalSpy spy0(&process, &QProcess::channelReadyRead);
QSignalSpy spy1(&process, &QProcess::readyReadStandardOutput);
QSignalSpy spy2(&process, &QProcess::readyReadStandardError);
+ QVERIFY(spy0.isValid());
QVERIFY(spy1.isValid());
QVERIFY(spy2.isValid());
@@ -513,6 +511,7 @@ void tst_QProcess::echoTest2()
break;
}
+ QVERIFY(spy0.count() > 0);
QVERIFY(spy1.count() > 0);
QVERIFY(spy2.count() > 0);
@@ -828,11 +827,11 @@ void tst_QProcess::openModes()
{
QProcess proc;
QVERIFY(!proc.isOpen());
- QVERIFY(proc.openMode() == QProcess::NotOpen);
+ QCOMPARE(proc.openMode(), QProcess::NotOpen);
proc.start("testProcessEcho3/testProcessEcho3");
QVERIFY(proc.waitForStarted(5000));
QVERIFY(proc.isOpen());
- QVERIFY(proc.openMode() == QProcess::ReadWrite);
+ QCOMPARE(proc.openMode(), QProcess::ReadWrite);
QVERIFY(proc.isReadable());
QVERIFY(proc.isWritable());
@@ -841,7 +840,7 @@ void tst_QProcess::openModes()
proc.closeWriteChannel();
QVERIFY(proc.isWritable());
- QVERIFY(proc.openMode() == QProcess::ReadWrite);
+ QCOMPARE(proc.openMode(), QProcess::ReadWrite);
while (proc.bytesAvailable() < 4 && proc.waitForReadyRead(5000))
{ }
@@ -850,12 +849,12 @@ void tst_QProcess::openModes()
proc.closeReadChannel(QProcess::StandardOutput);
- QVERIFY(proc.openMode() == QProcess::ReadWrite);
+ QCOMPARE(proc.openMode(), QProcess::ReadWrite);
QVERIFY(proc.isReadable());
proc.closeReadChannel(QProcess::StandardError);
- QVERIFY(proc.openMode() == QProcess::ReadWrite);
+ QCOMPARE(proc.openMode(), QProcess::ReadWrite);
QVERIFY(proc.isReadable());
proc.close();
@@ -982,6 +981,9 @@ public:
this, &SoftExitProcess::terminateSlot);
break;
case 4:
+ setReadChannelMode(QProcess::MergedChannels);
+ connect(this, SIGNAL(channelReadyRead(int)), this, SLOT(terminateSlot()));
+ break;
default:
connect(this, &QProcess::stateChanged,
this, &SoftExitProcess::terminateSlot);
@@ -1003,8 +1005,8 @@ public:
public slots:
void terminateSlot()
{
- writePendingData(); // In cases 3 and 4 we haven't written the data yet.
- if (killing || (n == 4 && state() != Running)) {
+ writePendingData(); // In cases 3 and 5 we haven't written the data yet.
+ if (killing || (n == 5 && state() != Running)) {
// Don't try to kill the process before it is running - that can
// be hazardous, as the actual child process might not be running
// yet. Also, don't kill it "recursively".
@@ -1047,14 +1049,14 @@ void tst_QProcess::softExitInSlots_data()
QByteArray dataTagPrefix("gui app ");
#ifndef QT_NO_WIDGETS
- for (int i = 0; i < 5; ++i) {
+ for (int i = 0; i < 6; ++i) {
QTest::newRow(dataTagPrefix + QByteArray::number(i))
<< "testGuiProcess/testGuiProcess" << i;
}
#endif
dataTagPrefix = "console app ";
- for (int i = 0; i < 5; ++i) {
+ for (int i = 0; i < 6; ++i) {
QTest::newRow(dataTagPrefix + QByteArray::number(i))
<< "testProcessEcho2/testProcessEcho2" << i;
}
@@ -1434,11 +1436,11 @@ void tst_QProcess::spaceArgsTest()
QCOMPARE(actual, args);
#endif
- if (program.contains(" "))
- program = "\"" + program + "\"";
+ if (program.contains(QLatin1Char(' ')))
+ program = QLatin1Char('"') + program + QLatin1Char('"');
if (!stringArgs.isEmpty())
- program += QString::fromLatin1(" ") + stringArgs;
+ program += QLatin1Char(' ') + stringArgs;
errorMessage.clear();
process.start(program);
@@ -1484,9 +1486,9 @@ void tst_QProcess::nativeArguments()
char buf[256];
fgets(buf, 256, file);
fclose(file);
- QStringList actual = QString::fromLatin1(buf).split("|");
+ QStringList actual = QString::fromLatin1(buf).split(QLatin1Char('|'));
#else
- QStringList actual = QString::fromLatin1(proc.readAll()).split("|");
+ QStringList actual = QString::fromLatin1(proc.readAll()).split(QLatin1Char('|'));
#endif
QVERIFY(!actual.isEmpty());
// not interested in the program name, it might be different.
@@ -1500,7 +1502,26 @@ void tst_QProcess::nativeArguments()
QCOMPARE(actual, expected);
}
-#endif
+void tst_QProcess::createProcessArgumentsModifier()
+{
+ int calls = 0;
+ const QString reversedCommand = "lamroNssecorPtset/lamroNssecorPtset";
+ QProcess process;
+ process.setCreateProcessArgumentsModifier([&calls] (QProcess::CreateProcessArguments *args)
+ {
+ calls++;
+ std::reverse(args->arguments, args->arguments + wcslen(args->arguments) - 1);
+ });
+ process.start(reversedCommand);
+ QVERIFY2(process.waitForStarted(), qUtf8Printable(process.errorString()));
+ QVERIFY(process.waitForFinished());
+ QCOMPARE(calls, 1);
+
+ process.setCreateProcessArgumentsModifier(QProcess::CreateProcessArgumentModifier());
+ QVERIFY(!process.waitForStarted());
+ QCOMPARE(calls, 1);
+}
+#endif // Q_OS_WIN
void tst_QProcess::exitCodeTest()
{
@@ -2268,6 +2289,13 @@ void tst_QProcess::setNonExistentWorkingDirectory()
process.start(QFileInfo("testSetWorkingDirectory/testSetWorkingDirectory").absoluteFilePath());
QVERIFY(!process.waitForFinished());
QCOMPARE(int(process.error()), int(QProcess::FailedToStart));
+
+#ifdef Q_OS_UNIX
+# ifdef QPROCESS_USE_SPAWN
+ QEXPECT_FAIL("", "QProcess cannot detect failure to start when using posix_spawn()", Continue);
+# endif
+ QVERIFY2(process.errorString().startsWith("chdir:"), process.errorString().toLocal8Bit());
+#endif
}
#endif