summaryrefslogtreecommitdiff
path: root/tests/manual
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@nokia.com>2011-11-29 10:18:10 +0100
committerhjk <qthjk@ovi.com>2011-11-29 14:00:39 +0100
commit57c0979012c43f329e61547c638d7935a1444439 (patch)
tree9117913c39029c9a2602ccc58656d1ba4ed68bda /tests/manual
parent59359905bf7820c91ae5b61aeeb46e9e5da52679 (diff)
downloadqt-creator-57c0979012c43f329e61547c638d7935a1444439.tar.gz
SSH: Support different read channels in SshRemoteProcess.
This is part of the effort to support more QProcess concepts. Change-Id: Idb888e733570a58d3810f371409b657b30bbd929 Reviewed-by: hjk <qthjk@ovi.com>
Diffstat (limited to 'tests/manual')
-rw-r--r--tests/manual/ssh/remoteprocess/remoteprocesstest.cpp80
-rw-r--r--tests/manual/ssh/remoteprocess/remoteprocesstest.h7
2 files changed, 74 insertions, 13 deletions
diff --git a/tests/manual/ssh/remoteprocess/remoteprocesstest.cpp b/tests/manual/ssh/remoteprocess/remoteprocesstest.cpp
index dd8cfafdef..7f5fcd63cd 100644
--- a/tests/manual/ssh/remoteprocess/remoteprocesstest.cpp
+++ b/tests/manual/ssh/remoteprocess/remoteprocesstest.cpp
@@ -42,6 +42,8 @@
using namespace Utils;
+const QByteArray StderrOutput("ChannelTest");
+
RemoteProcessTest::RemoteProcessTest(const SshConnectionParameters &params)
: m_sshParams(params),
m_timeoutTimer(new QTimer(this)),
@@ -76,7 +78,7 @@ void RemoteProcessTest::run()
void RemoteProcessTest::handleConnectionError()
{
- const QString error = m_state == TestingIoDevice
+ const QString error = m_state == TestingIoDevice || m_state == TestingProcessChannels
? m_sshConnection->errorString() : m_remoteRunner->lastConnectionErrorString();
std::cerr << "Error: Connection failure (" << qPrintable(error) << ")." << std::endl;
@@ -212,9 +214,29 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus)
connect(m_sshConnection.data(), SIGNAL(error(Utils::SshError)),
SLOT(handleConnectionError()));
m_sshConnection->connectToHost();
+ m_timeoutTimer->start();
break;
}
case TestingIoDevice:
+ std::cerr << "Error: Successful exit from process that was supposed to crash."
+ << std::endl;
+ qApp->exit(EXIT_FAILURE);
+ break;
+ case TestingProcessChannels:
+ if (m_remoteStderr.isEmpty()) {
+ std::cerr << "Error: Did not receive readyReadStderr()." << std::endl;
+ qApp->exit(EXIT_FAILURE);
+ return;
+ }
+ if (m_remoteData != StderrOutput) {
+ std::cerr << "Error: Expected output '" << StderrOutput.data() << "', received '"
+ << m_remoteData.data() << "'." << std::endl;
+ qApp->exit(EXIT_FAILURE);
+ return;
+ }
+ std::cout << "Ok.\nAll tests succeeded." << std::endl;
+ qApp->quit();
+ break;
case Inactive:
Q_ASSERT(false);
}
@@ -238,8 +260,19 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus)
m_remoteRunner->runInTerminal("top -n 1", SshPseudoTerminal(), m_sshParams);
break;
case TestingIoDevice:
- std::cout << "Ok.\nAll tests succeeded." << std::endl;
- qApp->quit();
+ std::cout << "Ok\nTesting process channels... " << std::flush;
+ m_state = TestingProcessChannels;
+ m_started = false;
+ m_remoteStderr.clear();
+ m_echoProcess = m_sshConnection->createRemoteProcess("printf " + StderrOutput + " >&2");
+ m_echoProcess->setReadChannel(QProcess::StandardError);
+ connect(m_echoProcess.data(), SIGNAL(started()), SLOT(handleProcessStarted()));
+ connect(m_echoProcess.data(), SIGNAL(closed(int)), SLOT(handleProcessClosed(int)));
+ connect(m_echoProcess.data(), SIGNAL(readyRead()), SLOT(handleReadyRead()));
+ connect(m_echoProcess.data(), SIGNAL(readyReadStandardError()),
+ SLOT(handleReadyReadStderr()));
+ m_echoProcess->start();
+ m_timeoutTimer->start();
break;
default:
std::cerr << "Error: Unexpected crash." << std::endl;
@@ -274,15 +307,38 @@ QString RemoteProcessTest::testString() const
void RemoteProcessTest::handleReadyRead()
{
- Q_ASSERT(m_state == TestingIoDevice);
-
- const QString &data = QString::fromUtf8(m_catProcess->readAll());
- if (data != testString()) {
- std::cerr << "Testing of QIODevice functionality failed: Expected '"
- << qPrintable(testString()) << "', got '" << qPrintable(data) << "'." << std::endl;
- qApp->exit(1);
+ switch (m_state) {
+ case TestingIoDevice: {
+ const QString &data = QString::fromUtf8(m_catProcess->readAll());
+ if (data != testString()) {
+ std::cerr << "Testing of QIODevice functionality failed: Expected '"
+ << qPrintable(testString()) << "', got '" << qPrintable(data) << "'." << std::endl;
+ qApp->exit(1);
+ }
+ Utils::SshRemoteProcessRunner * const killer = new Utils::SshRemoteProcessRunner(this);
+ killer->run("pkill -9 cat", m_sshParams);
+ break;
}
+ case TestingProcessChannels:
+ m_remoteData += m_echoProcess->readAll();
+ break;
+ default:
+ qFatal("%s: Unexpected state %d.", Q_FUNC_INFO, m_state);
+ }
+
+}
+
+void RemoteProcessTest::handleReadyReadStdout()
+{
+ Q_ASSERT(m_state == TestingProcessChannels);
+
+ std::cerr << "Error: Received unexpected stdout data." << std::endl;
+ qApp->exit(EXIT_FAILURE);
+}
+
+void RemoteProcessTest::handleReadyReadStderr()
+{
+ Q_ASSERT(m_state == TestingProcessChannels);
- Utils::SshRemoteProcessRunner * const killer = new Utils::SshRemoteProcessRunner(this);
- killer->run("pkill -9 cat", m_sshParams);
+ m_remoteStderr = "dummy";
}
diff --git a/tests/manual/ssh/remoteprocess/remoteprocesstest.h b/tests/manual/ssh/remoteprocess/remoteprocesstest.h
index bc1a381999..9a90f6a4b9 100644
--- a/tests/manual/ssh/remoteprocess/remoteprocesstest.h
+++ b/tests/manual/ssh/remoteprocess/remoteprocesstest.h
@@ -56,11 +56,14 @@ private slots:
void handleProcessClosed(int exitStatus);
void handleTimeout();
void handleReadyRead();
+ void handleReadyReadStdout();
+ void handleReadyReadStderr();
void handleConnected();
private:
enum State {
- Inactive, TestingSuccess, TestingFailure, TestingCrash, TestingTerminal, TestingIoDevice
+ Inactive, TestingSuccess, TestingFailure, TestingCrash, TestingTerminal, TestingIoDevice,
+ TestingProcessChannels
};
QString testString() const;
@@ -70,9 +73,11 @@ private:
QTextStream *m_textStream;
Utils::SshRemoteProcessRunner * const m_remoteRunner;
Utils::SshRemoteProcess::Ptr m_catProcess;
+ Utils::SshRemoteProcess::Ptr m_echoProcess;
Utils::SshConnection::Ptr m_sshConnection;
QByteArray m_remoteStdout;
QByteArray m_remoteStderr;
+ QByteArray m_remoteData;
State m_state;
bool m_started;
};