QProcess.tests: adding test for channel forwarding
This tests QProcess::setProcessChannelMode(). The tests verifies if testForwarding really forwards the output of testProcessEcho (spawned by testForwarding). Change-Id: Ifc4164569256aeaeab0edef42116986272362c01 Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
This commit is contained in:
parent
a5e3e9eaf1
commit
ad41111167
@ -16,5 +16,7 @@ SUBPROGRAMS = \
|
||||
testSetWorkingDirectory \
|
||||
testSoftExit
|
||||
|
||||
!contains(QMAKE_PLATFORM, wince): SUBPROGRAMS += testForwarding
|
||||
|
||||
contains(QT_CONFIG, no-widgets): SUBPROGRAMS -= \
|
||||
testGuiProcess
|
||||
|
67
tests/auto/corelib/io/qprocess/testForwarding/main.cpp
Normal file
67
tests/auto/corelib/io/qprocess/testForwarding/main.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the test suite of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** 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 Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/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 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt 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.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtCore/QProcess>
|
||||
|
||||
int main()
|
||||
{
|
||||
QProcess process;
|
||||
process.setProcessChannelMode(QProcess::ForwardedChannels);
|
||||
if (process.processChannelMode() != QProcess::ForwardedChannels)
|
||||
return -1;
|
||||
|
||||
process.start("testProcessEcho/testProcessEcho");
|
||||
|
||||
if (!process.waitForStarted(5000))
|
||||
return -1;
|
||||
|
||||
if (process.write("forwarded\n") != 10)
|
||||
return -1;
|
||||
|
||||
process.waitForReadyRead(250);
|
||||
if (process.bytesAvailable() != 0)
|
||||
return -1;
|
||||
|
||||
process.closeWriteChannel();
|
||||
process.waitForFinished(5000);
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
SOURCES = main.cpp
|
||||
CONFIG -= app_bundle
|
||||
CONFIG += console
|
||||
DESTDIR = ./
|
@ -110,6 +110,7 @@ private slots:
|
||||
void softExitInSlots();
|
||||
void mergedChannels();
|
||||
void forwardedChannels();
|
||||
void forwardedChannelsOutput();
|
||||
void atEnd();
|
||||
void atEnd2();
|
||||
void processInAThread();
|
||||
@ -1128,6 +1129,21 @@ void tst_QProcess::forwardedChannels()
|
||||
QVERIFY(process.waitForFinished(5000));
|
||||
}
|
||||
|
||||
void tst_QProcess::forwardedChannelsOutput()
|
||||
{
|
||||
#ifdef Q_OS_WINCE
|
||||
QSKIP("Reading and writing to a process is not supported on Qt/CE");
|
||||
#endif
|
||||
|
||||
QProcess process;
|
||||
process.start("testForwarding/testForwarding");
|
||||
QVERIFY(process.waitForStarted(5000));
|
||||
QVERIFY(process.waitForFinished(5000));
|
||||
QVERIFY(!process.exitCode());
|
||||
QByteArray data = process.readAll();
|
||||
QVERIFY(!data.isEmpty());
|
||||
QVERIFY(data.contains("forwarded"));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void tst_QProcess::atEnd()
|
||||
|
Loading…
Reference in New Issue
Block a user