OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / tests / manual / ssh / sftp / sftptest.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef SFTPTEST_H
34 #define SFTPTEST_H
35
36 #include "parameters.h"
37
38 #include <utils/ssh/sftpchannel.h>
39 #include <utils/ssh/sshconnection.h>
40
41 #include <QtCore/QElapsedTimer>
42 #include <QtCore/QHash>
43 #include <QtCore/QList>
44 #include <QtCore/QObject>
45 #include <QtCore/QSharedPointer>
46
47 QT_FORWARD_DECLARE_CLASS(QFile);
48
49 class SftpTest : public QObject
50 {
51     Q_OBJECT
52 public:
53     SftpTest(const Parameters &params);
54     ~SftpTest();
55     void run();
56
57 private slots:
58     void handleConnected();
59     void handleError();
60     void handleDisconnected();
61     void handleChannelInitialized();
62     void handleChannelInitializationFailure(const QString &reason);
63     void handleJobFinished(Utils::SftpJobId job, const QString &error);
64     void handleChannelClosed();
65
66 private:
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
72     };
73
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);
84
85     const Parameters m_parameters;
86     State m_state;
87     bool m_error;
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;
99 };
100
101
102 #endif // SFTPTEST_H