1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
36 #include "parameters.h"
38 #include <utils/ssh/sftpchannel.h>
39 #include <utils/ssh/sshconnection.h>
41 #include <QtCore/QElapsedTimer>
42 #include <QtCore/QHash>
43 #include <QtCore/QList>
44 #include <QtCore/QObject>
45 #include <QtCore/QSharedPointer>
47 QT_FORWARD_DECLARE_CLASS(QFile);
49 class SftpTest : public QObject
53 SftpTest(const Parameters ¶ms);
58 void handleConnected();
60 void handleDisconnected();
61 void handleChannelInitialized();
62 void handleChannelInitializationFailure(const QString &reason);
63 void handleJobFinished(Utils::SftpJobId job, const QString &error);
64 void handleChannelClosed();
67 typedef QHash<Utils::SftpJobId, QString> JobMap;
68 typedef QSharedPointer<QFile> FilePtr;
69 enum State { Inactive, Connecting, InitializingChannel, UploadingSmall,
70 DownloadingSmall, RemovingSmall, UploadingBig, DownloadingBig,
71 RemovingBig, ChannelClosing, Disconnecting
74 void removeFile(const FilePtr &filePtr, bool remoteToo);
75 void removeFiles(bool remoteToo);
76 QString cmpFileName(const QString &localFileName) const;
77 QString remoteFilePath(const QString &localFileName) const;
78 void earlyDisconnectFromHost();
79 bool handleJobFinished(Utils::SftpJobId job, JobMap &jobMap,
80 const QString &error, const char *activity);
81 bool handleBigJobFinished(Utils::SftpJobId job, Utils::SftpJobId expectedJob,
82 const QString &error, const char *activity);
83 bool compareFiles(QFile *orig, QFile *copy);
85 const Parameters m_parameters;
88 Utils::SshConnection::Ptr m_connection;
89 Utils::SftpChannel::Ptr m_channel;
90 QList<FilePtr> m_localSmallFiles;
91 JobMap m_smallFilesUploadJobs;
92 JobMap m_smallFilesDownloadJobs;
93 JobMap m_smallFilesRemovalJobs;
94 FilePtr m_localBigFile;
95 Utils::SftpJobId m_bigFileUploadJob;
96 Utils::SftpJobId m_bigFileDownloadJob;
97 Utils::SftpJobId m_bigFileRemovalJob;
98 QElapsedTimer m_bigJobTimer;