summaryrefslogtreecommitdiff
path: root/tests/manual/ssh/shell
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2022-05-06 02:26:52 +0200
committerJarek Kobus <jaroslaw.kobus@qt.io>2022-05-09 07:42:13 +0000
commit2856091c757c61aeff1ec6e3981d4ed9c8b0a6b6 (patch)
tree7249ac4733dd53db0d8707859eec23cff5d1c839 /tests/manual/ssh/shell
parentd8ee25ec3db039368ac0440af647fd7afd80079b (diff)
downloadqt-creator-2856091c757c61aeff1ec6e3981d4ed9c8b0a6b6.tar.gz
Get rid of SshRemoteProcess
It's being replaced by QtcProcess with path on device. Change-Id: I29eb038d1b17151683f86855eb547e47f7f7dea5 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'tests/manual/ssh/shell')
-rw-r--r--tests/manual/ssh/shell/CMakeLists.txt13
-rw-r--r--tests/manual/ssh/shell/argumentscollector.cpp135
-rw-r--r--tests/manual/ssh/shell/argumentscollector.h50
-rw-r--r--tests/manual/ssh/shell/main.cpp56
-rw-r--r--tests/manual/ssh/shell/shell.cpp111
-rw-r--r--tests/manual/ssh/shell/shell.h60
-rw-r--r--tests/manual/ssh/shell/shell.pro6
-rw-r--r--tests/manual/ssh/shell/shell.qbs27
8 files changed, 0 insertions, 458 deletions
diff --git a/tests/manual/ssh/shell/CMakeLists.txt b/tests/manual/ssh/shell/CMakeLists.txt
deleted file mode 100644
index f7748f2e96..0000000000
--- a/tests/manual/ssh/shell/CMakeLists.txt
+++ /dev/null
@@ -1,13 +0,0 @@
-file(RELATIVE_PATH RELATIVE_TEST_PATH "${PROJECT_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}")
-file(RELATIVE_PATH TEST_RELATIVE_LIBEXEC_PATH "/${RELATIVE_TEST_PATH}" "/${IDE_LIBEXEC_PATH}")
-
-add_qtc_test(tst_manual_shell
- MANUALTEST
- CONDITION UNIX
- DEPENDS Utils QtcSsh Qt5::Network
- DEFINES "TEST_RELATIVE_LIBEXEC_PATH=\"${TEST_RELATIVE_LIBEXEC_PATH}\""
- SOURCES
- argumentscollector.cpp argumentscollector.h
- main.cpp
- shell.cpp shell.h
-)
diff --git a/tests/manual/ssh/shell/argumentscollector.cpp b/tests/manual/ssh/shell/argumentscollector.cpp
deleted file mode 100644
index e9e7e61888..0000000000
--- a/tests/manual/ssh/shell/argumentscollector.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of Qt Creator.
-**
-** 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 https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** 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.
-**
-****************************************************************************/
-
-#include "argumentscollector.h"
-
-#include <QDir>
-#include <QProcessEnvironment>
-
-#include <iostream>
-
-using namespace QSsh;
-
-using namespace std;
-
-ArgumentsCollector::ArgumentsCollector(const QStringList &args)
- : m_arguments(args)
-{
-}
-
-SshConnectionParameters ArgumentsCollector::collect(bool &success) const
-{
- SshConnectionParameters parameters;
- try {
- bool authTypeGiven = false;
- bool portGiven = false;
- bool timeoutGiven = false;
- int pos;
- int port = 22;
-
- for (pos = 1; pos < m_arguments.count() - 1; ++pos) {
- QString str;
- if (checkAndSetStringArg(pos, str, "-h")) {
- parameters.setHost(str);
- } else if (checkAndSetStringArg(pos, str, "-u")) {
- parameters.setUserName(str);
- } else if (checkAndSetIntArg(pos, port, portGiven, "-p")
- || checkAndSetIntArg(pos, parameters.timeout, timeoutGiven, "-t")) {
- continue;
- } else if (checkAndSetStringArg(pos, str, "-k")) {
- parameters.privateKeyFile = Utils::FilePath::fromString(str);
- parameters.authenticationType
- = SshConnectionParameters::AuthenticationTypeSpecificKey;
- authTypeGiven = true;
- }
- }
-
- Q_ASSERT(pos <= m_arguments.count());
-
- if (!authTypeGiven)
- parameters.authenticationType = SshConnectionParameters::AuthenticationTypeAll;
-
- if (parameters.userName().isEmpty())
- parameters.setUserName(QProcessEnvironment::systemEnvironment().value("USER"));
- if (parameters.userName().isEmpty())
- throw ArgumentErrorException(QLatin1String("No user name given."));
-
- if (parameters.host().isEmpty())
- throw ArgumentErrorException(QLatin1String("No host given."));
-
- parameters.setPort(portGiven ? port : 22);
- if (!timeoutGiven)
- parameters.timeout = 30;
- success = true;
- } catch (ArgumentErrorException &ex) {
- cerr << "Error: " << qPrintable(ex.error) << endl;
- printUsage();
- success = false;
- }
- return parameters;
-}
-
-void ArgumentsCollector::printUsage() const
-{
- cerr << "Usage: " << qPrintable(m_arguments.first())
- << " -h <host> [ -u <user> ] "
- << "[ -k <private key file> ] [ -p <port> ] "
- << "[ -t <timeout> ] [ -no-proxy ]" << endl;
-}
-
-bool ArgumentsCollector::checkAndSetStringArg(int &pos, QString &arg, const char *opt) const
-{
- if (m_arguments.at(pos) == QLatin1String(opt)) {
- if (!arg.isEmpty()) {
- throw ArgumentErrorException(QLatin1String("option ") + QLatin1String(opt)
- + QLatin1String(" was given twice."));
- }
- arg = m_arguments.at(++pos);
- if (arg.isEmpty() && QLatin1String(opt) != QLatin1String("-pwd"))
- throw ArgumentErrorException(QLatin1String("empty argument not allowed here."));
- return true;
- }
- return false;
-}
-
-bool ArgumentsCollector::checkAndSetIntArg(int &pos, int &val,
- bool &alreadyGiven, const char *opt) const
-{
- if (m_arguments.at(pos) == QLatin1String(opt)) {
- if (alreadyGiven) {
- throw ArgumentErrorException(QLatin1String("option ") + QLatin1String(opt)
- + QLatin1String(" was given twice."));
- }
- bool isNumber;
- val = m_arguments.at(++pos).toInt(&isNumber);
- if (!isNumber) {
- throw ArgumentErrorException(QLatin1String("option ") + QLatin1String(opt)
- + QLatin1String(" needs integer argument"));
- }
- alreadyGiven = true;
- return true;
- }
- return false;
-}
diff --git a/tests/manual/ssh/shell/argumentscollector.h b/tests/manual/ssh/shell/argumentscollector.h
deleted file mode 100644
index 4d36ca1802..0000000000
--- a/tests/manual/ssh/shell/argumentscollector.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of Qt Creator.
-**
-** 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 https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** 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.
-**
-****************************************************************************/
-
-#pragma once
-
-#include <ssh/sshconnection.h>
-
-#include <QStringList>
-
-class ArgumentsCollector
-{
-public:
- ArgumentsCollector(const QStringList &args);
- QSsh::SshConnectionParameters collect(bool &success) const;
-private:
- struct ArgumentErrorException
- {
- ArgumentErrorException(const QString &error) : error(error) {}
- const QString error;
- };
-
- void printUsage() const;
- bool checkAndSetStringArg(int &pos, QString &arg, const char *opt) const;
- bool checkAndSetIntArg(int &pos, int &val, bool &alreadyGiven,
- const char *opt) const;
-
- const QStringList m_arguments;
-};
diff --git a/tests/manual/ssh/shell/main.cpp b/tests/manual/ssh/shell/main.cpp
deleted file mode 100644
index c47471ae7d..0000000000
--- a/tests/manual/ssh/shell/main.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of Qt Creator.
-**
-** 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 https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** 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.
-**
-****************************************************************************/
-
-#include "argumentscollector.h"
-#include "shell.h"
-
-#include <ssh/sshconnection.h>
-#include <utils/launcherinterface.h>
-#include <utils/temporarydirectory.h>
-
-#include <QCoreApplication>
-#include <QDir>
-#include <QObject>
-#include <QStringList>
-
-#include <cstdlib>
-#include <iostream>
-
-int main(int argc, char *argv[])
-{
- QCoreApplication app(argc, argv);
- Utils::LauncherInterface::setPathToLauncher(qApp->applicationDirPath() + '/'
- + QLatin1String(TEST_RELATIVE_LIBEXEC_PATH));
- bool parseSuccess;
- const QSsh::SshConnectionParameters &parameters
- = ArgumentsCollector(app.arguments()).collect(parseSuccess);
- if (!parseSuccess)
- return EXIT_FAILURE;
- Utils::TemporaryDirectory::setMasterTemporaryDirectory(QDir::tempPath()
- + "/qtc-ssh-shelltest-XXXXXX");
- Shell shell(parameters);
- shell.run();
- return app.exec();
-}
diff --git a/tests/manual/ssh/shell/shell.cpp b/tests/manual/ssh/shell/shell.cpp
deleted file mode 100644
index b85e61b970..0000000000
--- a/tests/manual/ssh/shell/shell.cpp
+++ /dev/null
@@ -1,111 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of Qt Creator.
-**
-** 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 https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** 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.
-**
-****************************************************************************/
-
-#include "shell.h"
-
-#include <ssh/sshremoteprocess.h>
-
-#include <utils/qtcprocess.h>
-
-#include <QCoreApplication>
-#include <QFile>
-#include <QSocketNotifier>
-
-#include <cstdlib>
-#include <iostream>
-
-using namespace QSsh;
-using namespace Utils;
-
-Shell::Shell(const SshConnectionParameters &parameters, QObject *parent)
- : QObject(parent),
- m_connection(new SshConnection(parameters)),
- m_stdin(new QFile(this))
-{
- connect(m_connection, &SshConnection::connected, this, &Shell::handleConnected);
- connect(m_connection, &SshConnection::errorOccurred, this, &Shell::handleConnectionError);
-}
-
-Shell::~Shell()
-{
- delete m_connection;
-}
-
-void Shell::run()
-{
- if (!m_stdin->open(stdin, QIODevice::ReadOnly | QIODevice::Unbuffered)) {
- std::cerr << "Error: Cannot read from standard input." << std::endl;
- QCoreApplication::exit(EXIT_FAILURE);
- return;
- }
-
- m_connection->connectToHost();
-}
-
-void Shell::handleConnectionError()
-{
- std::cerr << "SSH connection error: " << qPrintable(m_connection->errorString()) << std::endl;
- QCoreApplication::exit(EXIT_FAILURE);
-}
-
-void Shell::handleConnected()
-{
- m_shell = m_connection->createRemoteShell();
- connect(m_shell.get(), &QtcProcess::started, this, &Shell::handleShellStarted);
- connect(m_shell.get(), &QtcProcess::readyReadStandardOutput,
- this, &Shell::handleRemoteStdout);
- connect(m_shell.get(), &QtcProcess::readyReadStandardError,
- this, &Shell::handleRemoteStderr);
- connect(m_shell.get(), &QtcProcess::done, this, &Shell::handleChannelClosed);
- m_shell->start();
-}
-
-void Shell::handleShellStarted()
-{
- QSocketNotifier * const notifier = new QSocketNotifier(0, QSocketNotifier::Read, this);
- connect(notifier, &QSocketNotifier::activated, this, &Shell::handleStdin);
-}
-
-void Shell::handleRemoteStdout()
-{
- std::cout << m_shell->readAllStandardOutput().data() << std::flush;
-}
-
-void Shell::handleRemoteStderr()
-{
- std::cerr << m_shell->readAllStandardError().data() << std::flush;
-}
-
-void Shell::handleChannelClosed()
-{
- std::cerr << "Shell closed. Exit code was " << m_shell->exitCode() << "." << std::endl;
- QCoreApplication::exit(m_shell->errorString().isEmpty() && m_shell->exitCode() == 0
- ? EXIT_SUCCESS : EXIT_FAILURE);
-}
-
-void Shell::handleStdin()
-{
- m_shell->write(m_stdin->readLine());
-}
diff --git a/tests/manual/ssh/shell/shell.h b/tests/manual/ssh/shell/shell.h
deleted file mode 100644
index db8bcce9ca..0000000000
--- a/tests/manual/ssh/shell/shell.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of Qt Creator.
-**
-** 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 https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** 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.
-**
-****************************************************************************/
-
-#pragma once
-
-#include <ssh/sshconnection.h>
-
-#include <QObject>
-
-QT_BEGIN_NAMESPACE
-class QByteArray;
-class QFile;
-class QString;
-QT_END_NAMESPACE
-
-class Shell : public QObject
-{
- Q_OBJECT
-public:
- Shell(const QSsh::SshConnectionParameters &parameters, QObject *parent = 0);
- ~Shell();
-
- void run();
-
-private:
- void handleConnected();
- void handleConnectionError();
- void handleRemoteStdout();
- void handleRemoteStderr();
- void handleShellMessage(const QString &message);
- void handleChannelClosed();
- void handleShellStarted();
- void handleStdin();
-
- QSsh::SshConnection *m_connection;
- QSsh::SshRemoteProcessPtr m_shell;
- QFile * const m_stdin;
-};
diff --git a/tests/manual/ssh/shell/shell.pro b/tests/manual/ssh/shell/shell.pro
deleted file mode 100644
index f7d0b174f0..0000000000
--- a/tests/manual/ssh/shell/shell.pro
+++ /dev/null
@@ -1,6 +0,0 @@
-include(../ssh.pri)
-QT += network
-
-TARGET=shell
-SOURCES=main.cpp shell.cpp argumentscollector.cpp
-HEADERS=shell.h argumentscollector.h
diff --git a/tests/manual/ssh/shell/shell.qbs b/tests/manual/ssh/shell/shell.qbs
deleted file mode 100644
index f8cc41a022..0000000000
--- a/tests/manual/ssh/shell/shell.qbs
+++ /dev/null
@@ -1,27 +0,0 @@
-import qbs
-import qbs.FileInfo
-
-QtcManualtest {
- name: "Manual ssh shell test"
- condition: qbs.targetOS.contains("unix")
- Depends { name: "Utils" }
- Depends { name: "QtcSsh" }
- Depends { name: "Qt.network" }
-
- cpp.defines: {
- var defines = base;
- var absLibExecPath = FileInfo.joinPaths(qbs.installRoot, qbs.installPrefix,
- qtc.ide_libexec_path);
- var relLibExecPath = FileInfo.relativePath(destinationDirectory, absLibExecPath);
- defines.push('TEST_RELATIVE_LIBEXEC_PATH="' + relLibExecPath + '"');
- return defines;
- }
-
- files: [
- "argumentscollector.cpp",
- "argumentscollector.h",
- "main.cpp",
- "shell.cpp",
- "shell.h",
- ]
-}