author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 20:15:53 +0300 | |
branch | RCL_3 |
changeset 13 | c0432d11811c |
parent 7 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
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 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
||
45 |
#include <qcoreapplication.h> |
|
46 |
#include <qfile.h> |
|
47 |
#include <qbuffer.h> |
|
48 |
#include "qftp.h" |
|
49 |
#include <qmap.h> |
|
50 |
#include <time.h> |
|
51 |
#include <stdlib.h> |
|
52 |
#include <QNetworkProxy> |
|
53 |
||
54 |
#include "../network-settings.h" |
|
55 |
||
56 |
//TESTED_CLASS= |
|
57 |
//TESTED_FILES= |
|
58 |
||
59 |
#ifdef Q_OS_SYMBIAN |
|
60 |
// In Symbian OS test data is located in applications private dir |
|
61 |
// Application private dir is default serach path for files, so SRCDIR can be set to empty |
|
62 |
#define SRCDIR "" |
|
63 |
#endif |
|
64 |
||
65 |
||
66 |
||
67 |
class tst_QFtp : public QObject |
|
68 |
{ |
|
69 |
Q_OBJECT |
|
70 |
||
71 |
public: |
|
72 |
tst_QFtp(); |
|
73 |
virtual ~tst_QFtp(); |
|
74 |
||
75 |
||
76 |
public slots: |
|
77 |
void initTestCase_data(); |
|
78 |
void initTestCase(); |
|
79 |
void cleanupTestCase(); |
|
80 |
void init(); |
|
81 |
void cleanup(); |
|
82 |
private slots: |
|
83 |
void connectToHost_data(); |
|
84 |
void connectToHost(); |
|
85 |
void connectToUnresponsiveHost(); |
|
86 |
void login_data(); |
|
87 |
void login(); |
|
88 |
void close_data(); |
|
89 |
void close(); |
|
90 |
||
91 |
void list_data(); |
|
92 |
void list(); |
|
93 |
void cd_data(); |
|
94 |
void cd(); |
|
95 |
void get_data(); |
|
96 |
void get(); |
|
97 |
void put_data(); |
|
98 |
void put(); |
|
99 |
void remove(); |
|
100 |
void mkdir_data(); |
|
101 |
void mkdir(); |
|
102 |
void mkdir2(); |
|
103 |
void rmdir(); |
|
104 |
void rename_data(); |
|
105 |
void rename(); |
|
106 |
||
107 |
void commandSequence_data(); |
|
108 |
void commandSequence(); |
|
109 |
||
110 |
void abort_data(); |
|
111 |
void abort(); |
|
112 |
||
113 |
void bytesAvailable_data(); |
|
114 |
void bytesAvailable(); |
|
115 |
||
116 |
void activeMode(); |
|
117 |
||
118 |
void proxy_data(); |
|
119 |
void proxy(); |
|
120 |
||
121 |
void binaryAscii(); |
|
122 |
||
123 |
void doneSignal(); |
|
124 |
void queueMoreCommandsInDoneSlot(); |
|
125 |
||
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
126 |
void qtbug7359Crash(); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
127 |
|
0 | 128 |
protected slots: |
129 |
void stateChanged( int ); |
|
130 |
void listInfo( const QUrlInfo & ); |
|
131 |
void readyRead(); |
|
132 |
void dataTransferProgress(qint64, qint64); |
|
133 |
||
134 |
void commandStarted( int ); |
|
135 |
void commandFinished( int, bool ); |
|
136 |
void done( bool ); |
|
137 |
void activeModeDone( bool ); |
|
138 |
void mkdir2Slot(int id, bool error); |
|
139 |
void cdUpSlot(bool); |
|
140 |
||
141 |
private: |
|
142 |
QFtp *newFtp(); |
|
143 |
void addCommand( QFtp::Command, int ); |
|
144 |
bool fileExists( const QString &host, quint16 port, const QString &user, const QString &password, const QString &file, const QString &cdDir = QString::null ); |
|
145 |
bool dirExists( const QString &host, quint16 port, const QString &user, const QString &password, const QString &cdDir, const QString &dirToCreate ); |
|
146 |
||
147 |
void renameInit( const QString &host, const QString &user, const QString &password, const QString &createFile ); |
|
148 |
void renameCleanup( const QString &host, const QString &user, const QString &password, const QString &fileToDelete ); |
|
149 |
||
150 |
QFtp *ftp; |
|
151 |
||
152 |
QList<int> ids; // helper to make sure that all expected signals are emitted |
|
153 |
int current_id; |
|
154 |
||
155 |
int connectToHost_state; |
|
156 |
int close_state; |
|
157 |
int login_state; |
|
158 |
int cur_state; |
|
159 |
struct CommandResult |
|
160 |
{ |
|
161 |
int id; |
|
162 |
int success; |
|
163 |
}; |
|
164 |
QMap< QFtp::Command, CommandResult > resultMap; |
|
165 |
typedef QMap<QFtp::Command,CommandResult>::Iterator ResMapIt; |
|
166 |
||
167 |
int done_success; |
|
168 |
int commandSequence_success; |
|
169 |
||
170 |
qlonglong bytesAvailable_finishedGet; |
|
171 |
qlonglong bytesAvailable_finished; |
|
172 |
qlonglong bytesAvailable_done; |
|
173 |
||
174 |
QList<QUrlInfo> listInfo_i; |
|
175 |
QByteArray newData_ba; |
|
176 |
qlonglong bytesTotal; |
|
177 |
qlonglong bytesDone; |
|
178 |
||
179 |
bool inFileDirExistsFunction; |
|
180 |
||
181 |
QString uniqueExtension; |
|
182 |
}; |
|
183 |
||
184 |
//#define DUMP_SIGNALS |
|
185 |
||
186 |
const int bytesTotal_init = -10; |
|
187 |
const int bytesDone_init = -10; |
|
188 |
||
189 |
tst_QFtp::tst_QFtp() |
|
190 |
{ |
|
191 |
Q_SET_DEFAULT_IAP |
|
192 |
} |
|
193 |
||
194 |
tst_QFtp::~tst_QFtp() |
|
195 |
{ |
|
196 |
} |
|
197 |
||
198 |
void tst_QFtp::initTestCase_data() |
|
199 |
{ |
|
200 |
QTest::addColumn<bool>("setProxy"); |
|
201 |
QTest::addColumn<int>("proxyType"); |
|
202 |
||
203 |
QTest::newRow("WithoutProxy") << false << 0; |
|
204 |
QTest::newRow("WithSocks5Proxy") << true << int(QNetworkProxy::Socks5Proxy); |
|
205 |
//### doesn't work well yet. |
|
206 |
//QTest::newRow("WithHttpProxy") << true << int(QNetworkProxy::HttpProxy); |
|
207 |
} |
|
208 |
||
209 |
void tst_QFtp::initTestCase() |
|
210 |
{ |
|
211 |
} |
|
212 |
||
213 |
void tst_QFtp::cleanupTestCase() |
|
214 |
{ |
|
215 |
} |
|
216 |
||
217 |
void tst_QFtp::init() |
|
218 |
{ |
|
219 |
QFETCH_GLOBAL(bool, setProxy); |
|
220 |
if (setProxy) { |
|
221 |
QFETCH_GLOBAL(int, proxyType); |
|
222 |
if (proxyType == QNetworkProxy::Socks5Proxy) { |
|
223 |
QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::Socks5Proxy, QtNetworkSettings::serverName(), 1080)); |
|
224 |
} else if (proxyType == QNetworkProxy::HttpProxy) { |
|
225 |
QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::HttpProxy, QtNetworkSettings::serverName(), 3128)); |
|
226 |
} |
|
227 |
} |
|
228 |
||
229 |
ftp = 0; |
|
230 |
||
231 |
ids.clear(); |
|
232 |
current_id = 0; |
|
233 |
||
234 |
resultMap.clear(); |
|
235 |
connectToHost_state = -1; |
|
236 |
close_state = -1; |
|
237 |
login_state = -1; |
|
238 |
cur_state = QFtp::Unconnected; |
|
239 |
||
240 |
listInfo_i.clear(); |
|
241 |
newData_ba = QByteArray(); |
|
242 |
bytesTotal = bytesTotal_init; |
|
243 |
bytesDone = bytesDone_init; |
|
244 |
||
245 |
done_success = -1; |
|
246 |
commandSequence_success = -1; |
|
247 |
||
248 |
bytesAvailable_finishedGet = 1234567890; |
|
249 |
bytesAvailable_finished = 1234567890; |
|
250 |
bytesAvailable_done = 1234567890; |
|
251 |
||
252 |
inFileDirExistsFunction = FALSE; |
|
253 |
||
254 |
#if !defined(Q_OS_WINCE) |
|
255 |
srand(time(0)); |
|
256 |
uniqueExtension = QString("%1%2%3").arg((qulonglong)this).arg(rand()).arg((qulonglong)time(0)); |
|
257 |
#else |
|
258 |
srand(0); |
|
259 |
uniqueExtension = QString("%1%2%3").arg((qulonglong)this).arg(rand()).arg((qulonglong)(0)); |
|
260 |
#endif |
|
261 |
} |
|
262 |
||
263 |
void tst_QFtp::cleanup() |
|
264 |
{ |
|
265 |
QFETCH_GLOBAL(bool, setProxy); |
|
266 |
if (setProxy) { |
|
267 |
QNetworkProxy::setApplicationProxy(QNetworkProxy::DefaultProxy); |
|
268 |
} |
|
269 |
} |
|
270 |
||
271 |
void tst_QFtp::connectToHost_data() |
|
272 |
{ |
|
273 |
QTest::addColumn<QString>("host"); |
|
274 |
QTest::addColumn<uint>("port"); |
|
275 |
QTest::addColumn<int>("state"); |
|
276 |
||
277 |
QTest::newRow( "ok01" ) << QtNetworkSettings::serverName() << (uint)21 << (int)QFtp::Connected; |
|
278 |
QTest::newRow( "error01" ) << QtNetworkSettings::serverName() << (uint)2222 << (int)QFtp::Unconnected; |
|
279 |
QTest::newRow( "error02" ) << QString("foo.bar") << (uint)21 << (int)QFtp::Unconnected; |
|
280 |
} |
|
281 |
||
282 |
void tst_QFtp::connectToHost() |
|
283 |
{ |
|
284 |
QFETCH( QString, host ); |
|
285 |
QFETCH( uint, port ); |
|
286 |
||
287 |
ftp = newFtp(); |
|
288 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host, port ) ); |
|
289 |
||
290 |
QTestEventLoop::instance().enterLoop( 61 ); |
|
291 |
delete ftp; |
|
292 |
if ( QTestEventLoop::instance().timeout() ) |
|
293 |
QFAIL( "Network operation timed out" ); |
|
294 |
||
295 |
QTEST( connectToHost_state, "state" ); |
|
296 |
||
297 |
ResMapIt it = resultMap.find( QFtp::ConnectToHost ); |
|
298 |
QVERIFY( it != resultMap.end() ); |
|
299 |
QFETCH( int, state ); |
|
300 |
if ( state == QFtp::Connected ) { |
|
301 |
QVERIFY( it.value().success == 1 ); |
|
302 |
} else { |
|
303 |
QVERIFY( it.value().success == 0 ); |
|
304 |
} |
|
305 |
} |
|
306 |
||
307 |
void tst_QFtp::connectToUnresponsiveHost() |
|
308 |
{ |
|
309 |
QFETCH_GLOBAL(bool, setProxy); |
|
310 |
if (setProxy) |
|
311 |
QSKIP( "This test takes too long if we test with proxies too", SkipSingle ); |
|
312 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
313 |
QString host = "192.0.2.42"; // IP out of TEST-NET, should be unreachable |
0 | 314 |
uint port = 21; |
315 |
||
316 |
ftp = newFtp(); |
|
317 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host, port ) ); |
|
318 |
||
319 |
qDebug( "About to connect to host that won't reply (this test takes 60 seconds)" ); |
|
320 |
QTestEventLoop::instance().enterLoop( 61 ); |
|
321 |
#ifdef Q_OS_WIN |
|
322 |
/* On Windows, we do not get a timeout, because Winsock is behaving in a strange way: |
|
323 |
We issue two "WSAConnect()" calls, after the first, as a result we get WSAEWOULDBLOCK, |
|
324 |
after the second, we get WSAEISCONN, which means that the socket is connected, which cannot be. |
|
325 |
However, after some seconds we get a socket error saying that the remote host closed the connection, |
|
326 |
which can neither be. For this test, that would actually enable us to finish before timout, but handling that case |
|
327 |
(in void QFtpPI::error(QAbstractSocket::SocketError e)) breaks |
|
328 |
a lot of other stuff in QFtp, so we just expect this test to fail on Windows. |
|
329 |
*/ |
|
330 |
QEXPECT_FAIL("", "timeout not working due to strange Windows socket behaviour (see source file of this test for explanation)", Abort); |
|
331 |
#endif |
|
332 |
QVERIFY2(! QTestEventLoop::instance().timeout(), "Network timeout longer than expected (should have been 60 seconds)"); |
|
333 |
||
334 |
QVERIFY( ftp->state() == QFtp::Unconnected); |
|
335 |
ResMapIt it = resultMap.find( QFtp::ConnectToHost ); |
|
336 |
QVERIFY( it != resultMap.end() ); |
|
337 |
QVERIFY( it.value().success == 0 ); |
|
338 |
||
339 |
delete ftp; |
|
340 |
} |
|
341 |
||
342 |
void tst_QFtp::login_data() |
|
343 |
{ |
|
344 |
QTest::addColumn<QString>("host"); |
|
345 |
QTest::addColumn<uint>("port"); |
|
346 |
QTest::addColumn<QString>("user"); |
|
347 |
QTest::addColumn<QString>("password"); |
|
348 |
QTest::addColumn<int>("success"); |
|
349 |
||
350 |
QTest::newRow( "ok01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << 1; |
|
351 |
QTest::newRow( "ok02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftp") << QString() << 1; |
|
352 |
QTest::newRow( "ok03" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftp") << QString("foo") << 1; |
|
353 |
QTest::newRow( "ok04" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") << 1; |
|
354 |
||
355 |
QTest::newRow( "error01" ) << QtNetworkSettings::serverName() << (uint)21 << QString("foo") << QString() << 0; |
|
356 |
QTest::newRow( "error02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("foo") << QString("bar") << 0; |
|
357 |
} |
|
358 |
||
359 |
void tst_QFtp::login() |
|
360 |
{ |
|
361 |
QFETCH( QString, host ); |
|
362 |
QFETCH( uint, port ); |
|
363 |
QFETCH( QString, user ); |
|
364 |
QFETCH( QString, password ); |
|
365 |
||
366 |
ftp = newFtp(); |
|
367 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host, port ) ); |
|
368 |
addCommand( QFtp::Login, ftp->login( user, password ) ); |
|
369 |
||
370 |
QTestEventLoop::instance().enterLoop( 30 ); |
|
371 |
delete ftp; |
|
372 |
if ( QTestEventLoop::instance().timeout() ) |
|
373 |
QFAIL( "Network operation timed out" ); |
|
374 |
||
375 |
ResMapIt it = resultMap.find( QFtp::Login ); |
|
376 |
QVERIFY( it != resultMap.end() ); |
|
377 |
QTEST( it.value().success, "success" ); |
|
378 |
||
379 |
if ( it.value().success ) { |
|
380 |
QVERIFY( login_state == QFtp::LoggedIn ); |
|
381 |
} else { |
|
382 |
QVERIFY( login_state != QFtp::LoggedIn ); |
|
383 |
} |
|
384 |
} |
|
385 |
||
386 |
void tst_QFtp::close_data() |
|
387 |
{ |
|
388 |
QTest::addColumn<QString>("host"); |
|
389 |
QTest::addColumn<uint>("port"); |
|
390 |
QTest::addColumn<QString>("user"); |
|
391 |
QTest::addColumn<QString>("password"); |
|
392 |
QTest::addColumn<bool>("login"); |
|
393 |
||
394 |
QTest::newRow( "login01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << (bool)TRUE; |
|
395 |
QTest::newRow( "login02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftp") << QString() << (bool)TRUE; |
|
396 |
QTest::newRow( "login03" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftp") << QString("foo") << (bool)TRUE; |
|
397 |
QTest::newRow( "login04" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") << (bool)TRUE; |
|
398 |
||
399 |
QTest::newRow( "no-login01" ) << QtNetworkSettings::serverName() << (uint)21 << QString("") << QString("") << (bool)FALSE; |
|
400 |
} |
|
401 |
||
402 |
void tst_QFtp::close() |
|
403 |
{ |
|
404 |
QFETCH( QString, host ); |
|
405 |
QFETCH( uint, port ); |
|
406 |
QFETCH( QString, user ); |
|
407 |
QFETCH( QString, password ); |
|
408 |
QFETCH( bool, login ); |
|
409 |
||
410 |
ftp = newFtp(); |
|
411 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host, port ) ); |
|
412 |
if ( login ) |
|
413 |
addCommand( QFtp::Login, ftp->login( user, password ) ); |
|
414 |
addCommand( QFtp::Close, ftp->close() ); |
|
415 |
||
416 |
QTestEventLoop::instance().enterLoop( 30 ); |
|
417 |
delete ftp; |
|
418 |
if ( QTestEventLoop::instance().timeout() ) |
|
419 |
QFAIL( "Network operation timed out" ); |
|
420 |
||
421 |
QCOMPARE( close_state, (int)QFtp::Unconnected ); |
|
422 |
||
423 |
ResMapIt it = resultMap.find( QFtp::Close ); |
|
424 |
QVERIFY( it != resultMap.end() ); |
|
425 |
QVERIFY( it.value().success == 1 ); |
|
426 |
} |
|
427 |
||
428 |
void tst_QFtp::list_data() |
|
429 |
{ |
|
430 |
QTest::addColumn<QString>("host"); |
|
431 |
QTest::addColumn<uint>("port"); |
|
432 |
QTest::addColumn<QString>("user"); |
|
433 |
QTest::addColumn<QString>("password"); |
|
434 |
QTest::addColumn<QString>("dir"); |
|
435 |
QTest::addColumn<int>("success"); |
|
436 |
QTest::addColumn<QStringList>("entryNames"); // ### we should rather use a QList<QUrlInfo> here |
|
437 |
||
438 |
QStringList flukeRoot; |
|
439 |
flukeRoot << "pub"; |
|
440 |
flukeRoot << "qtest"; |
|
441 |
QStringList flukeQtest; |
|
442 |
flukeQtest << "bigfile"; |
|
443 |
flukeQtest << "nonASCII"; |
|
444 |
flukeQtest << "rfc3252"; |
|
445 |
flukeQtest << "rfc3252.txt"; |
|
446 |
flukeQtest << "upload"; |
|
447 |
||
448 |
QTest::newRow( "workDir01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString() << 1 << flukeRoot; |
|
449 |
QTest::newRow( "workDir02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") << QString() << 1 << flukeRoot; |
|
450 |
||
451 |
QTest::newRow( "relPath01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("qtest") << 1 << flukeQtest; |
|
452 |
QTest::newRow( "relPath02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") << QString("qtest") << 1 << flukeQtest; |
|
453 |
||
454 |
QTest::newRow( "absPath01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("/qtest") << 1 << flukeQtest; |
|
455 |
QTest::newRow( "absPath02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") << QString("/var/ftp/qtest") << 1 << flukeQtest; |
|
456 |
||
457 |
QTest::newRow( "nonExist01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("foo") << 1 << QStringList(); |
|
458 |
QTest::newRow( "nonExist02" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("/foo") << 1 << QStringList(); |
|
459 |
// ### The microsoft server does not seem to work properly at the moment -- |
|
460 |
// I am also not able to open a data connection with other, non-Qt FTP |
|
461 |
// clients to it. |
|
462 |
// QTest::newRow( "nonExist03" ) << "ftp.microsoft.com" << (uint)21 << QString() << QString() << QString("/foo") << 0 << QStringList(); |
|
463 |
||
464 |
QStringList susePub; |
|
465 |
susePub << "README.mirror-policy" << "axp" << "i386" << "ia64" << "install" << "noarch" << "pubring.gpg-build.suse.de" << "update" << "x86_64"; |
|
466 |
QTest::newRow( "epsvNotSupported" ) << QString("ftp.funet.fi") << (uint)21 << QString::fromLatin1("ftp") << QString::fromLatin1("root@") << QString("/pub/Linux/suse/suse") << 1 << susePub; |
|
467 |
} |
|
468 |
||
469 |
void tst_QFtp::list() |
|
470 |
{ |
|
471 |
QFETCH( QString, host ); |
|
472 |
QFETCH( uint, port ); |
|
473 |
QFETCH( QString, user ); |
|
474 |
QFETCH( QString, password ); |
|
475 |
QFETCH( QString, dir ); |
|
476 |
||
477 |
ftp = newFtp(); |
|
478 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host, port ) ); |
|
479 |
addCommand( QFtp::Login, ftp->login( user, password ) ); |
|
480 |
addCommand( QFtp::List, ftp->list( dir ) ); |
|
481 |
addCommand( QFtp::Close, ftp->close() ); |
|
482 |
||
483 |
QTestEventLoop::instance().enterLoop( 30 ); |
|
484 |
delete ftp; |
|
485 |
if ( QTestEventLoop::instance().timeout() ) |
|
486 |
QFAIL( "Network operation timed out" ); |
|
487 |
||
488 |
ResMapIt it = resultMap.find( QFtp::List ); |
|
489 |
QVERIFY( it != resultMap.end() ); |
|
490 |
QTEST( it.value().success, "success" ); |
|
491 |
QFETCH( QStringList, entryNames ); |
|
492 |
QCOMPARE( listInfo_i.count(), entryNames.count() ); |
|
493 |
for ( uint i=0; i < (uint) entryNames.count(); i++ ) { |
|
494 |
QCOMPARE( listInfo_i[i].name(), entryNames[i] ); |
|
495 |
} |
|
496 |
} |
|
497 |
||
498 |
void tst_QFtp::cd_data() |
|
499 |
{ |
|
500 |
QTest::addColumn<QString>("host"); |
|
501 |
QTest::addColumn<uint>("port"); |
|
502 |
QTest::addColumn<QString>("user"); |
|
503 |
QTest::addColumn<QString>("password"); |
|
504 |
QTest::addColumn<QString>("dir"); |
|
505 |
QTest::addColumn<int>("success"); |
|
506 |
QTest::addColumn<QStringList>("entryNames"); // ### we should rather use a QList<QUrlInfo> here |
|
507 |
||
508 |
QStringList flukeRoot; |
|
509 |
flukeRoot << "qtest"; |
|
510 |
QStringList flukeQtest; |
|
511 |
flukeQtest << "bigfile"; |
|
512 |
flukeQtest << "nonASCII"; |
|
513 |
flukeQtest << "rfc3252"; |
|
514 |
flukeQtest << "rfc3252.txt"; |
|
515 |
flukeQtest << "upload"; |
|
516 |
||
517 |
QTest::newRow( "relPath01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("qtest") << 1 << flukeQtest; |
|
518 |
QTest::newRow( "relPath02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") << QString("qtest") << 1 << flukeQtest; |
|
519 |
||
520 |
QTest::newRow( "absPath01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("/qtest") << 1 << flukeQtest; |
|
521 |
QTest::newRow( "absPath02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") << QString("/var/ftp/qtest") << 1 << flukeQtest; |
|
522 |
||
523 |
QTest::newRow( "nonExist01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("foo") << 0 << QStringList(); |
|
524 |
QTest::newRow( "nonExist03" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("/foo") << 0 << QStringList(); |
|
525 |
} |
|
526 |
||
527 |
void tst_QFtp::cd() |
|
528 |
{ |
|
529 |
QFETCH( QString, host ); |
|
530 |
QFETCH( uint, port ); |
|
531 |
QFETCH( QString, user ); |
|
532 |
QFETCH( QString, password ); |
|
533 |
QFETCH( QString, dir ); |
|
534 |
||
535 |
ftp = newFtp(); |
|
536 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host, port ) ); |
|
537 |
addCommand( QFtp::Login, ftp->login( user, password ) ); |
|
538 |
addCommand( QFtp::Cd, ftp->cd( dir ) ); |
|
539 |
addCommand( QFtp::List, ftp->list() ); |
|
540 |
addCommand( QFtp::Close, ftp->close() ); |
|
541 |
||
542 |
QTestEventLoop::instance().enterLoop( 30 ); |
|
543 |
||
544 |
delete ftp; |
|
545 |
if ( QTestEventLoop::instance().timeout() ) { |
|
546 |
QFAIL( "Network operation timed out" ); |
|
547 |
} |
|
548 |
||
549 |
ResMapIt it = resultMap.find( QFtp::Cd ); |
|
550 |
QVERIFY( it != resultMap.end() ); |
|
551 |
QTEST( it.value().success, "success" ); |
|
552 |
QFETCH( QStringList, entryNames ); |
|
553 |
QCOMPARE( listInfo_i.count(), entryNames.count() ); |
|
554 |
for ( uint i=0; i < (uint) entryNames.count(); i++ ) { |
|
555 |
QCOMPARE( listInfo_i[i].name(), entryNames[i] ); |
|
556 |
} |
|
557 |
} |
|
558 |
||
559 |
void tst_QFtp::get_data() |
|
560 |
{ |
|
561 |
QTest::addColumn<QString>("host"); |
|
562 |
QTest::addColumn<uint>("port"); |
|
563 |
QTest::addColumn<QString>("user"); |
|
564 |
QTest::addColumn<QString>("password"); |
|
565 |
QTest::addColumn<QString>("file"); |
|
566 |
QTest::addColumn<int>("success"); |
|
567 |
QTest::addColumn<QByteArray>("res"); |
|
568 |
QTest::addColumn<bool>("useIODevice"); |
|
569 |
||
570 |
// ### move this into external testdata |
|
571 |
QFile file( SRCDIR "rfc3252.txt" ); |
|
572 |
QVERIFY( file.open( QIODevice::ReadOnly ) ); |
|
573 |
QByteArray rfc3252 = file.readAll(); |
|
574 |
||
575 |
// test the two get() overloads in one routine |
|
576 |
for ( int i=0; i<2; i++ ) { |
|
577 |
QTest::newRow( QString("relPath01_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() |
|
578 |
<< "qtest/rfc3252" << 1 << rfc3252 << (bool)(i==1); |
|
579 |
QTest::newRow( QString("relPath02_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") |
|
580 |
<< "qtest/rfc3252" << 1 << rfc3252 << (bool)(i==1); |
|
581 |
||
582 |
QTest::newRow( QString("absPath01_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() |
|
583 |
<< "/qtest/rfc3252" << 1 << rfc3252 << (bool)(i==1); |
|
584 |
QTest::newRow( QString("absPath02_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") |
|
585 |
<< "/var/ftp/qtest/rfc3252" << 1 << rfc3252 << (bool)(i==1); |
|
586 |
||
587 |
QTest::newRow( QString("nonExist01_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() |
|
588 |
<< QString("foo") << 0 << QByteArray() << (bool)(i==1); |
|
589 |
QTest::newRow( QString("nonExist02_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() |
|
590 |
<< QString("/foo") << 0 << QByteArray() << (bool)(i==1); |
|
591 |
} |
|
592 |
} |
|
593 |
||
594 |
void tst_QFtp::get() |
|
595 |
{ |
|
596 |
// for the overload that takes a QIODevice |
|
597 |
QByteArray buf_ba; |
|
598 |
QBuffer buf( &buf_ba ); |
|
599 |
||
600 |
QFETCH( QString, host ); |
|
601 |
QFETCH( uint, port ); |
|
602 |
QFETCH( QString, user ); |
|
603 |
QFETCH( QString, password ); |
|
604 |
QFETCH( QString, file ); |
|
605 |
QFETCH( bool, useIODevice ); |
|
606 |
||
607 |
ftp = newFtp(); |
|
608 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host, port ) ); |
|
609 |
addCommand( QFtp::Login, ftp->login( user, password ) ); |
|
610 |
if ( useIODevice ) { |
|
611 |
buf.open( QIODevice::WriteOnly ); |
|
612 |
addCommand( QFtp::Get, ftp->get( file, &buf ) ); |
|
613 |
} else { |
|
614 |
addCommand( QFtp::Get, ftp->get( file ) ); |
|
615 |
} |
|
616 |
addCommand( QFtp::Close, ftp->close() ); |
|
617 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
618 |
QTestEventLoop::instance().enterLoop( 50 ); |
0 | 619 |
delete ftp; |
620 |
if ( QTestEventLoop::instance().timeout() ) |
|
621 |
QFAIL( "Network operation timed out" ); |
|
622 |
||
623 |
ResMapIt it = resultMap.find( QFtp::Get ); |
|
624 |
QVERIFY( it != resultMap.end() ); |
|
625 |
QTEST( it.value().success, "success" ); |
|
626 |
if ( useIODevice ) { |
|
627 |
QTEST( buf_ba, "res" ); |
|
628 |
} else { |
|
629 |
QTEST( newData_ba, "res" ); |
|
630 |
} |
|
631 |
QVERIFY( bytesTotal != bytesTotal_init ); |
|
632 |
if ( bytesTotal != -1 ) { |
|
633 |
QVERIFY( bytesDone == bytesTotal ); |
|
634 |
} |
|
635 |
if ( useIODevice ) { |
|
636 |
if ( bytesDone != bytesDone_init ) { |
|
637 |
QVERIFY( (int)buf_ba.size() == bytesDone ); |
|
638 |
} |
|
639 |
} else { |
|
640 |
if ( bytesDone != bytesDone_init ) { |
|
641 |
QVERIFY( (int)newData_ba.size() == bytesDone ); |
|
642 |
} |
|
643 |
} |
|
644 |
} |
|
645 |
||
646 |
void tst_QFtp::put_data() |
|
647 |
{ |
|
648 |
QTest::addColumn<QString>("host"); |
|
649 |
QTest::addColumn<uint>("port"); |
|
650 |
QTest::addColumn<QString>("user"); |
|
651 |
QTest::addColumn<QString>("password"); |
|
652 |
QTest::addColumn<QString>("file"); |
|
653 |
QTest::addColumn<QByteArray>("fileData"); |
|
654 |
QTest::addColumn<bool>("useIODevice"); |
|
655 |
QTest::addColumn<int>("success"); |
|
656 |
||
657 |
// ### move this into external testdata |
|
658 |
QFile file( SRCDIR "rfc3252.txt" ); |
|
659 |
QVERIFY( file.open( QIODevice::ReadOnly ) ); |
|
660 |
QByteArray rfc3252 = file.readAll(); |
|
661 |
||
662 |
QByteArray bigData( 10*1024*1024, 0 ); |
|
663 |
bigData.fill( 'A' ); |
|
664 |
||
665 |
// test the two put() overloads in one routine |
|
666 |
for ( int i=0; i<2; i++ ) { |
|
667 |
QTest::newRow( QString("relPath01_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() |
|
668 |
<< QString("qtest/upload/rel01_%1") << rfc3252 |
|
669 |
<< (bool)(i==1) << 1; |
|
670 |
/* |
|
671 |
QTest::newRow( QString("relPath02_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") |
|
672 |
<< QString("qtest/upload/rel02_%1") << rfc3252 |
|
673 |
<< (bool)(i==1) << 1; |
|
674 |
QTest::newRow( QString("relPath03_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") |
|
675 |
<< QString("qtest/upload/rel03_%1") << QByteArray() |
|
676 |
<< (bool)(i==1) << 1; |
|
677 |
QTest::newRow( QString("relPath04_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") |
|
678 |
<< QString("qtest/upload/rel04_%1") << bigData |
|
679 |
<< (bool)(i==1) << 1; |
|
680 |
||
681 |
QTest::newRow( QString("absPath01_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() |
|
682 |
<< QString("/qtest/upload/abs01_%1") << rfc3252 |
|
683 |
<< (bool)(i==1) << 1; |
|
684 |
QTest::newRow( QString("absPath02_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") |
|
685 |
<< QString("/srv/ftp/qtest/upload/abs02_%1") << rfc3252 |
|
686 |
<< (bool)(i==1) << 1; |
|
687 |
||
688 |
QTest::newRow( QString("nonExist01_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() |
|
689 |
<< QString("foo") << QByteArray() |
|
690 |
<< (bool)(i==1) << 0; |
|
691 |
QTest::newRow( QString("nonExist02_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() |
|
692 |
<< QString("/foo") << QByteArray() |
|
693 |
<< (bool)(i==1) << 0; |
|
694 |
*/ |
|
695 |
} |
|
696 |
} |
|
697 |
||
698 |
void tst_QFtp::put() |
|
699 |
{ |
|
700 |
QFETCH( QString, host ); |
|
701 |
QFETCH( uint, port ); |
|
702 |
QFETCH( QString, user ); |
|
703 |
QFETCH( QString, password ); |
|
704 |
QFETCH( QString, file ); |
|
705 |
QFETCH( QByteArray, fileData ); |
|
706 |
QFETCH( bool, useIODevice ); |
|
707 |
||
708 |
#ifdef Q_OS_WIN |
|
709 |
QFETCH_GLOBAL(bool, setProxy); |
|
710 |
if (setProxy) { |
|
711 |
QFETCH_GLOBAL(int, proxyType); |
|
712 |
if (proxyType == QNetworkProxy::Socks5Proxy) { |
|
713 |
QSKIP("With socks5 the put() test takes too long time on Windows.", SkipAll); |
|
714 |
} |
|
715 |
} |
|
716 |
#endif |
|
717 |
||
718 |
const int timestep = 50; |
|
719 |
||
720 |
if(file.contains('%')) |
|
721 |
file = file.arg(uniqueExtension); |
|
722 |
||
723 |
// for the overload that takes a QIODevice |
|
724 |
QBuffer buf_fileData( &fileData ); |
|
725 |
buf_fileData.open( QIODevice::ReadOnly ); |
|
726 |
||
727 |
ResMapIt it; |
|
728 |
////////////////////////////////////////////////////////////////// |
|
729 |
// upload the file |
|
730 |
init(); |
|
731 |
ftp = newFtp(); |
|
732 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host, port ) ); |
|
733 |
addCommand( QFtp::Login, ftp->login( user, password ) ); |
|
734 |
if ( useIODevice ) |
|
735 |
addCommand( QFtp::Put, ftp->put( &buf_fileData, file ) ); |
|
736 |
else |
|
737 |
addCommand( QFtp::Put, ftp->put( fileData, file ) ); |
|
738 |
addCommand( QFtp::Close, ftp->close() ); |
|
739 |
||
740 |
for(int time = 0; time <= fileData.length() / 20000; time += timestep) { |
|
741 |
QTestEventLoop::instance().enterLoop( timestep ); |
|
742 |
if(ftp->currentCommand() == QFtp::None) |
|
743 |
break; |
|
744 |
} |
|
745 |
delete ftp; |
|
746 |
if ( QTestEventLoop::instance().timeout() ) |
|
747 |
QFAIL( "Network operation timed out" ); |
|
748 |
||
749 |
it = resultMap.find( QFtp::Put ); |
|
750 |
QVERIFY( it != resultMap.end() ); |
|
751 |
QTEST( it.value().success, "success" ); |
|
752 |
if ( !it.value().success ) { |
|
753 |
QVERIFY( !fileExists( host, port, user, password, file ) ); |
|
754 |
return; // the following tests are only meaningful if the file could be put |
|
755 |
} |
|
756 |
QVERIFY( bytesTotal == (int)fileData.size() ); |
|
757 |
QVERIFY( bytesDone == bytesTotal ); |
|
758 |
||
759 |
QVERIFY( fileExists( host, port, user, password, file ) ); |
|
760 |
||
761 |
////////////////////////////////////////////////////////////////// |
|
762 |
// fetch file to make sure that it is equal to the uploaded file |
|
763 |
init(); |
|
764 |
ftp = newFtp(); |
|
765 |
QBuffer buf; |
|
766 |
buf.open( QIODevice::WriteOnly ); |
|
767 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host, port ) ); |
|
768 |
addCommand( QFtp::Login, ftp->login( user, password ) ); |
|
769 |
addCommand( QFtp::Get, ftp->get( file, &buf ) ); |
|
770 |
addCommand( QFtp::Close, ftp->close() ); |
|
771 |
||
772 |
for(int time = 0; time <= fileData.length() / 20000; time += timestep) { |
|
773 |
QTestEventLoop::instance().enterLoop( timestep ); |
|
774 |
if(ftp->currentCommand() == QFtp::None) |
|
775 |
break; |
|
776 |
} |
|
777 |
delete ftp; |
|
778 |
if ( QTestEventLoop::instance().timeout() ) |
|
779 |
QFAIL( "Network operation timed out" ); |
|
780 |
||
781 |
QVERIFY( done_success == 1 ); |
|
782 |
QTEST( buf.buffer(), "fileData" ); |
|
783 |
||
784 |
////////////////////////////////////////////////////////////////// |
|
785 |
// cleanup (i.e. remove the file) -- this also tests the remove command |
|
786 |
init(); |
|
787 |
ftp = newFtp(); |
|
788 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host, port ) ); |
|
789 |
addCommand( QFtp::Login, ftp->login( user, password ) ); |
|
790 |
addCommand( QFtp::Remove, ftp->remove( file ) ); |
|
791 |
addCommand( QFtp::Close, ftp->close() ); |
|
792 |
||
793 |
QTestEventLoop::instance().enterLoop( timestep ); |
|
794 |
delete ftp; |
|
795 |
if ( QTestEventLoop::instance().timeout() ) |
|
796 |
QFAIL( "Network operation timed out" ); |
|
797 |
||
798 |
it = resultMap.find( QFtp::Remove ); |
|
799 |
QVERIFY( it != resultMap.end() ); |
|
800 |
QCOMPARE( it.value().success, 1 ); |
|
801 |
||
802 |
QVERIFY( !fileExists( host, port, user, password, file ) ); |
|
803 |
} |
|
804 |
||
805 |
void tst_QFtp::remove() |
|
806 |
{ |
|
807 |
DEPENDS_ON( "put" ); |
|
808 |
} |
|
809 |
||
810 |
void tst_QFtp::mkdir_data() |
|
811 |
{ |
|
812 |
QTest::addColumn<QString>("host"); |
|
813 |
QTest::addColumn<uint>("port"); |
|
814 |
QTest::addColumn<QString>("user"); |
|
815 |
QTest::addColumn<QString>("password"); |
|
816 |
QTest::addColumn<QString>("cdDir"); |
|
817 |
QTest::addColumn<QString>("dirToCreate"); |
|
818 |
QTest::addColumn<int>("success"); |
|
819 |
||
820 |
QTest::newRow( "relPath01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() |
|
821 |
<< "qtest/upload" << QString("rel01_%1") << 1; |
|
822 |
QTest::newRow( "relPath02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") |
|
823 |
<< "qtest/upload" << QString("rel02_%1") << 1; |
|
824 |
QTest::newRow( "relPath03" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") |
|
825 |
<< "qtest/upload" << QString("rel03_%1") << 1; |
|
826 |
||
827 |
QTest::newRow( "absPath01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() |
|
828 |
<< "." << QString("/qtest/upload/abs01_%1") << 1; |
|
829 |
QTest::newRow( "absPath02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") |
|
830 |
<< "." << QString("/var/ftp/qtest/upload/abs02_%1") << 1; |
|
831 |
||
832 |
// QTest::newRow( "nonExist01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("foo") << 0; |
|
833 |
QTest::newRow( "nonExist01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() |
|
834 |
<< "." << QString("foo") << 0; |
|
835 |
QTest::newRow( "nonExist02" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() |
|
836 |
<< "." << QString("/foo") << 0; |
|
837 |
} |
|
838 |
||
839 |
void tst_QFtp::mkdir() |
|
840 |
{ |
|
841 |
QFETCH( QString, host ); |
|
842 |
QFETCH( uint, port ); |
|
843 |
QFETCH( QString, user ); |
|
844 |
QFETCH( QString, password ); |
|
845 |
QFETCH( QString, cdDir ); |
|
846 |
QFETCH( QString, dirToCreate ); |
|
847 |
||
848 |
if(dirToCreate.contains('%')) |
|
849 |
dirToCreate = dirToCreate.arg(uniqueExtension); |
|
850 |
||
851 |
////////////////////////////////////////////////////////////////// |
|
852 |
// create the directory |
|
853 |
init(); |
|
854 |
ftp = newFtp(); |
|
855 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host, port ) ); |
|
856 |
addCommand( QFtp::Login, ftp->login( user, password ) ); |
|
857 |
addCommand( QFtp::Cd, ftp->cd( cdDir ) ); |
|
858 |
addCommand( QFtp::Mkdir, ftp->mkdir( dirToCreate ) ); |
|
859 |
addCommand( QFtp::Close, ftp->close() ); |
|
860 |
||
861 |
QTestEventLoop::instance().enterLoop( 30 ); |
|
862 |
delete ftp; |
|
863 |
if ( QTestEventLoop::instance().timeout() ) |
|
864 |
QFAIL( "Network operation timed out" ); |
|
865 |
||
866 |
ResMapIt it = resultMap.find( QFtp::Mkdir ); |
|
867 |
QVERIFY( it != resultMap.end() ); |
|
868 |
QTEST( it.value().success, "success" ); |
|
869 |
if ( !it.value().success ) { |
|
870 |
QVERIFY( !dirExists( host, port, user, password, cdDir, dirToCreate ) ); |
|
871 |
return; // the following tests are only meaningful if the dir could be created |
|
872 |
} |
|
873 |
QVERIFY( dirExists( host, port, user, password, cdDir, dirToCreate ) ); |
|
874 |
||
875 |
////////////////////////////////////////////////////////////////// |
|
876 |
// create the directory again (should always fail!) |
|
877 |
init(); |
|
878 |
ftp = newFtp(); |
|
879 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host, port ) ); |
|
880 |
addCommand( QFtp::Login, ftp->login( user, password ) ); |
|
881 |
addCommand( QFtp::Cd, ftp->cd( cdDir ) ); |
|
882 |
addCommand( QFtp::Mkdir, ftp->mkdir( dirToCreate ) ); |
|
883 |
addCommand( QFtp::Close, ftp->close() ); |
|
884 |
||
885 |
QTestEventLoop::instance().enterLoop( 30 ); |
|
886 |
delete ftp; |
|
887 |
if ( QTestEventLoop::instance().timeout() ) |
|
888 |
QFAIL( "Network operation timed out" ); |
|
889 |
||
890 |
it = resultMap.find( QFtp::Mkdir ); |
|
891 |
QVERIFY( it != resultMap.end() ); |
|
892 |
QCOMPARE( it.value().success, 0 ); |
|
893 |
||
894 |
////////////////////////////////////////////////////////////////// |
|
895 |
// remove the directory |
|
896 |
init(); |
|
897 |
ftp = newFtp(); |
|
898 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host, port ) ); |
|
899 |
addCommand( QFtp::Login, ftp->login( user, password ) ); |
|
900 |
addCommand( QFtp::Cd, ftp->cd( cdDir ) ); |
|
901 |
addCommand( QFtp::Rmdir, ftp->rmdir( dirToCreate ) ); |
|
902 |
addCommand( QFtp::Close, ftp->close() ); |
|
903 |
||
904 |
QTestEventLoop::instance().enterLoop( 30 ); |
|
905 |
delete ftp; |
|
906 |
if ( QTestEventLoop::instance().timeout() ) |
|
907 |
QFAIL( "Network operation timed out" ); |
|
908 |
||
909 |
it = resultMap.find( QFtp::Rmdir ); |
|
910 |
QVERIFY( it != resultMap.end() ); |
|
911 |
QCOMPARE( it.value().success, 1 ); |
|
912 |
||
913 |
QVERIFY( !dirExists( host, port, user, password, cdDir, dirToCreate ) ); |
|
914 |
} |
|
915 |
||
916 |
void tst_QFtp::mkdir2() |
|
917 |
{ |
|
918 |
ftp = new QFtp; |
|
919 |
ftp->connectToHost(QtNetworkSettings::serverName()); |
|
920 |
ftp->login(); |
|
921 |
current_id = ftp->cd("kake/test"); |
|
922 |
||
923 |
QEventLoop loop; |
|
924 |
connect(ftp, SIGNAL(done(bool)), &loop, SLOT(quit())); |
|
925 |
connect(ftp, SIGNAL(commandFinished(int, bool)), this, SLOT(mkdir2Slot(int, bool))); |
|
926 |
QTimer::singleShot(5000, &loop, SLOT(quit())); |
|
927 |
||
928 |
QSignalSpy commandStartedSpy(ftp, SIGNAL(commandStarted(int))); |
|
929 |
QSignalSpy commandFinishedSpy(ftp, SIGNAL(commandFinished(int, bool))); |
|
930 |
||
931 |
loop.exec(); |
|
932 |
||
933 |
QCOMPARE(commandStartedSpy.count(), 4); // connect, login, cd, mkdir |
|
934 |
QCOMPARE(commandFinishedSpy.count(), 4); |
|
935 |
||
936 |
for (int i = 0; i < 4; ++i) |
|
937 |
QCOMPARE(commandFinishedSpy.at(i).at(0), commandStartedSpy.at(i).at(0)); |
|
938 |
||
939 |
QVERIFY(!commandFinishedSpy.at(0).at(1).toBool()); |
|
940 |
QVERIFY(!commandFinishedSpy.at(1).at(1).toBool()); |
|
941 |
QVERIFY(commandFinishedSpy.at(2).at(1).toBool()); |
|
942 |
QVERIFY(commandFinishedSpy.at(3).at(1).toBool()); |
|
943 |
||
944 |
delete ftp; |
|
945 |
} |
|
946 |
||
947 |
void tst_QFtp::mkdir2Slot(int id, bool) |
|
948 |
{ |
|
949 |
if (id == current_id) |
|
950 |
ftp->mkdir("kake/test"); |
|
951 |
} |
|
952 |
||
953 |
void tst_QFtp::rmdir() |
|
954 |
{ |
|
955 |
DEPENDS_ON( "mkdir" ); |
|
956 |
} |
|
957 |
||
958 |
void tst_QFtp::rename_data() |
|
959 |
{ |
|
960 |
QTest::addColumn<QString>("host"); |
|
961 |
QTest::addColumn<QString>("user"); |
|
962 |
QTest::addColumn<QString>("password"); |
|
963 |
QTest::addColumn<QString>("cdDir"); |
|
964 |
QTest::addColumn<QString>("oldfile"); |
|
965 |
QTest::addColumn<QString>("newfile"); |
|
966 |
QTest::addColumn<QString>("createFile"); |
|
967 |
QTest::addColumn<QString>("renamedFile"); |
|
968 |
QTest::addColumn<int>("success"); |
|
969 |
||
970 |
QTest::newRow("relPath01") << QtNetworkSettings::serverName() << QString() << QString() |
|
971 |
<< "qtest/upload" |
|
972 |
<< QString("rel_old01_%1") << QString("rel_new01_%1") |
|
973 |
<< QString("qtest/upload/rel_old01_%1") << QString("qtest/upload/rel_new01_%1") |
|
974 |
<< 1; |
|
975 |
QTest::newRow("relPath02") << QtNetworkSettings::serverName() << QString("ftptest") << "password" |
|
976 |
<< "qtest/upload" |
|
977 |
<< QString("rel_old02_%1") << QString("rel_new02_%1") |
|
978 |
<< QString("qtest/upload/rel_old02_%1") << QString("qtest/upload/rel_new02_%1") |
|
979 |
<< 1; |
|
980 |
QTest::newRow("relPath03") << QtNetworkSettings::serverName() << QString("ftptest") << "password" |
|
981 |
<< "qtest/upload" |
|
982 |
<< QString("rel_old03_%1")<< QString("rel_new03_%1") |
|
983 |
<< QString("qtest/upload/rel_old03_%1") << QString("qtest/upload/rel_new03_%1") |
|
984 |
<< 1; |
|
985 |
||
986 |
QTest::newRow("absPath01") << QtNetworkSettings::serverName() << QString() << QString() |
|
987 |
<< QString() |
|
988 |
<< QString("/qtest/upload/abs_old01_%1") << QString("/qtest/upload/abs_new01_%1") |
|
989 |
<< QString("/qtest/upload/abs_old01_%1") << QString("/qtest/upload/abs_new01_%1") |
|
990 |
<< 1; |
|
991 |
QTest::newRow("absPath02") << QtNetworkSettings::serverName() << QString("ftptest") << "password" |
|
992 |
<< QString() |
|
993 |
<< QString("/var/ftp/qtest/upload/abs_old02_%1") << QString("/var/ftp/qtest/upload/abs_new02_%1") |
|
994 |
<< QString("/var/ftp/qtest/upload/abs_old02_%1") << QString("/var/ftp/qtest/upload/abs_new02_%1") |
|
995 |
<< 1; |
|
996 |
||
997 |
QTest::newRow("nonExist01") << QtNetworkSettings::serverName() << QString() << QString() |
|
998 |
<< QString() |
|
999 |
<< QString("foo") << "new_foo" |
|
1000 |
<< QString() << QString() |
|
1001 |
<< 0; |
|
1002 |
QTest::newRow("nonExist02") << QtNetworkSettings::serverName() << QString() << QString() |
|
1003 |
<< QString() |
|
1004 |
<< QString("/foo") << QString("/new_foo") |
|
1005 |
<< QString() << QString() |
|
1006 |
<< 0; |
|
1007 |
} |
|
1008 |
||
1009 |
void tst_QFtp::renameInit( const QString &host, const QString &user, const QString &password, const QString &createFile ) |
|
1010 |
{ |
|
1011 |
if ( !createFile.isNull() ) { |
|
1012 |
// upload the file |
|
1013 |
init(); |
|
1014 |
ftp = newFtp(); |
|
1015 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host ) ); |
|
1016 |
addCommand( QFtp::Login, ftp->login( user, password ) ); |
|
1017 |
addCommand( QFtp::Put, ftp->put( QByteArray(), createFile ) ); |
|
1018 |
addCommand( QFtp::Close, ftp->close() ); |
|
1019 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1020 |
QTestEventLoop::instance().enterLoop( 50 ); |
0 | 1021 |
delete ftp; |
1022 |
if ( QTestEventLoop::instance().timeout() ) |
|
1023 |
QFAIL( "Network operation timed out" ); |
|
1024 |
||
1025 |
ResMapIt it = resultMap.find( QFtp::Put ); |
|
1026 |
QVERIFY( it != resultMap.end() ); |
|
1027 |
QVERIFY( it.value().success == 1 ); |
|
1028 |
||
1029 |
QVERIFY( fileExists( host, 21, user, password, createFile ) ); |
|
1030 |
} |
|
1031 |
} |
|
1032 |
||
1033 |
void tst_QFtp::renameCleanup( const QString &host, const QString &user, const QString &password, const QString &fileToDelete ) |
|
1034 |
{ |
|
1035 |
if ( !fileToDelete.isNull() ) { |
|
1036 |
// cleanup (i.e. remove the file) |
|
1037 |
init(); |
|
1038 |
ftp = newFtp(); |
|
1039 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host ) ); |
|
1040 |
addCommand( QFtp::Login, ftp->login( user, password ) ); |
|
1041 |
addCommand( QFtp::Remove, ftp->remove( fileToDelete ) ); |
|
1042 |
addCommand( QFtp::Close, ftp->close() ); |
|
1043 |
||
1044 |
QTestEventLoop::instance().enterLoop( 30 ); |
|
1045 |
delete ftp; |
|
1046 |
if ( QTestEventLoop::instance().timeout() ) |
|
1047 |
QFAIL( "Network operation timed out" ); |
|
1048 |
||
1049 |
ResMapIt it = resultMap.find( QFtp::Remove ); |
|
1050 |
QVERIFY( it != resultMap.end() ); |
|
1051 |
QVERIFY( it.value().success == 1 ); |
|
1052 |
||
1053 |
QVERIFY( !fileExists( host, 21, user, password, fileToDelete ) ); |
|
1054 |
} |
|
1055 |
} |
|
1056 |
||
1057 |
void tst_QFtp::rename() |
|
1058 |
{ |
|
1059 |
QFETCH( QString, host ); |
|
1060 |
QFETCH( QString, user ); |
|
1061 |
QFETCH( QString, password ); |
|
1062 |
QFETCH( QString, cdDir ); |
|
1063 |
QFETCH( QString, oldfile ); |
|
1064 |
QFETCH( QString, newfile ); |
|
1065 |
QFETCH( QString, createFile ); |
|
1066 |
QFETCH( QString, renamedFile ); |
|
1067 |
||
1068 |
if(oldfile.contains('%')) |
|
1069 |
oldfile = oldfile.arg(uniqueExtension); |
|
1070 |
if(newfile.contains('%')) |
|
1071 |
newfile = newfile.arg(uniqueExtension); |
|
1072 |
if(createFile.contains('%')) |
|
1073 |
createFile = createFile.arg(uniqueExtension); |
|
1074 |
if(renamedFile.contains('%')) |
|
1075 |
renamedFile = renamedFile.arg(uniqueExtension); |
|
1076 |
||
1077 |
renameInit( host, user, password, createFile ); |
|
1078 |
||
1079 |
init(); |
|
1080 |
ftp = newFtp(); |
|
1081 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host ) ); |
|
1082 |
addCommand( QFtp::Login, ftp->login( user, password ) ); |
|
1083 |
if ( !cdDir.isNull() ) |
|
1084 |
addCommand( QFtp::Cd, ftp->cd( cdDir ) ); |
|
1085 |
addCommand( QFtp::Rename, ftp->rename( oldfile, newfile ) ); |
|
1086 |
addCommand( QFtp::Close, ftp->close() ); |
|
1087 |
||
1088 |
QTestEventLoop::instance().enterLoop( 30 ); |
|
1089 |
delete ftp; |
|
1090 |
if ( QTestEventLoop::instance().timeout() ) |
|
1091 |
QFAIL( "Network operation timed out" ); |
|
1092 |
||
1093 |
ResMapIt it = resultMap.find( QFtp::Rename ); |
|
1094 |
QVERIFY( it != resultMap.end() ); |
|
1095 |
QTEST( it.value().success, "success" ); |
|
1096 |
||
1097 |
if ( it.value().success ) { |
|
1098 |
QVERIFY( !fileExists( host, 21, user, password, oldfile, cdDir ) ); |
|
1099 |
QVERIFY( fileExists( host, 21, user, password, newfile, cdDir ) ); |
|
1100 |
QVERIFY( fileExists( host, 21, user, password, renamedFile ) ); |
|
1101 |
} else { |
|
1102 |
QVERIFY( !fileExists( host, 21, user, password, newfile, cdDir ) ); |
|
1103 |
QVERIFY( !fileExists( host, 21, user, password, renamedFile ) ); |
|
1104 |
} |
|
1105 |
||
1106 |
renameCleanup( host, user, password, renamedFile ); |
|
1107 |
} |
|
1108 |
||
1109 |
/* |
|
1110 |
The commandSequence() test does not test any particular function. It rather |
|
1111 |
tests a sequence of arbitrary commands specified in the test data. |
|
1112 |
*/ |
|
1113 |
class FtpCommand |
|
1114 |
{ |
|
1115 |
public: |
|
1116 |
FtpCommand() : |
|
1117 |
cmd(QFtp::None) |
|
1118 |
{ } |
|
1119 |
||
1120 |
FtpCommand( QFtp::Command command ) : |
|
1121 |
cmd(command) |
|
1122 |
{ } |
|
1123 |
||
1124 |
FtpCommand( QFtp::Command command, const QStringList &arguments ) : |
|
1125 |
cmd(command), args(arguments) |
|
1126 |
{ } |
|
1127 |
||
1128 |
FtpCommand( const FtpCommand &c ) |
|
1129 |
{ *this = c; } |
|
1130 |
||
1131 |
FtpCommand &operator=( const FtpCommand &c ) |
|
1132 |
{ |
|
1133 |
this->cmd = c.cmd; |
|
1134 |
this->args = c.args; |
|
1135 |
return *this; |
|
1136 |
} |
|
1137 |
||
1138 |
QFtp::Command cmd; |
|
1139 |
QStringList args; |
|
1140 |
}; |
|
1141 |
QDataStream &operator<<( QDataStream &s, const FtpCommand &command ) |
|
1142 |
{ |
|
1143 |
s << (int)command.cmd; |
|
1144 |
s << command.args; |
|
1145 |
return s; |
|
1146 |
} |
|
1147 |
QDataStream &operator>>( QDataStream &s, FtpCommand &command ) |
|
1148 |
{ |
|
1149 |
int tmp; |
|
1150 |
s >> tmp; |
|
1151 |
command.cmd = (QFtp::Command)tmp; |
|
1152 |
s >> command.args; |
|
1153 |
return s; |
|
1154 |
} |
|
1155 |
Q_DECLARE_METATYPE(QList<FtpCommand>) |
|
1156 |
||
1157 |
void tst_QFtp::commandSequence_data() |
|
1158 |
{ |
|
1159 |
// some "constants" |
|
1160 |
QStringList argConnectToHost01; |
|
1161 |
argConnectToHost01 << QtNetworkSettings::serverName() << "21"; |
|
1162 |
||
1163 |
QStringList argLogin01, argLogin02, argLogin03, argLogin04; |
|
1164 |
argLogin01 << QString() << QString(); |
|
1165 |
argLogin02 << "ftp" << QString(); |
|
1166 |
argLogin03 << "ftp" << "foo"; |
|
1167 |
argLogin04 << QString("ftptest") << "password"; |
|
1168 |
||
1169 |
FtpCommand connectToHost01( QFtp::ConnectToHost, argConnectToHost01 ); |
|
1170 |
FtpCommand login01( QFtp::Login, argLogin01 ); |
|
1171 |
FtpCommand login02( QFtp::Login, argLogin01 ); |
|
1172 |
FtpCommand login03( QFtp::Login, argLogin01 ); |
|
1173 |
FtpCommand login04( QFtp::Login, argLogin01 ); |
|
1174 |
FtpCommand close01( QFtp::Close ); |
|
1175 |
||
1176 |
QTest::addColumn<QList<FtpCommand> >("cmds"); |
|
1177 |
QTest::addColumn<int>("success"); |
|
1178 |
||
1179 |
// success data |
|
1180 |
{ |
|
1181 |
QList<FtpCommand> cmds; |
|
1182 |
cmds << connectToHost01; |
|
1183 |
QTest::newRow( "simple_ok01" ) << cmds << 1; |
|
1184 |
} |
|
1185 |
{ |
|
1186 |
QList<FtpCommand> cmds; |
|
1187 |
cmds << connectToHost01; |
|
1188 |
cmds << login01; |
|
1189 |
QTest::newRow( "simple_ok02" ) << cmds << 1; |
|
1190 |
} |
|
1191 |
{ |
|
1192 |
QList<FtpCommand> cmds; |
|
1193 |
cmds << connectToHost01; |
|
1194 |
cmds << login01; |
|
1195 |
cmds << close01; |
|
1196 |
QTest::newRow( "simple_ok03" ) << cmds << 1; |
|
1197 |
} |
|
1198 |
{ |
|
1199 |
QList<FtpCommand> cmds; |
|
1200 |
cmds << connectToHost01; |
|
1201 |
cmds << close01; |
|
1202 |
QTest::newRow( "simple_ok04" ) << cmds << 1; |
|
1203 |
} |
|
1204 |
{ |
|
1205 |
QList<FtpCommand> cmds; |
|
1206 |
cmds << connectToHost01; |
|
1207 |
cmds << login01; |
|
1208 |
cmds << close01; |
|
1209 |
cmds << connectToHost01; |
|
1210 |
cmds << login02; |
|
1211 |
cmds << close01; |
|
1212 |
QTest::newRow( "connect_twice" ) << cmds << 1; |
|
1213 |
} |
|
1214 |
||
1215 |
// error data |
|
1216 |
{ |
|
1217 |
QList<FtpCommand> cmds; |
|
1218 |
cmds << close01; |
|
1219 |
QTest::newRow( "error01" ) << cmds << 0; |
|
1220 |
} |
|
1221 |
{ |
|
1222 |
QList<FtpCommand> cmds; |
|
1223 |
cmds << login01; |
|
1224 |
QTest::newRow( "error02" ) << cmds << 0; |
|
1225 |
} |
|
1226 |
{ |
|
1227 |
QList<FtpCommand> cmds; |
|
1228 |
cmds << login01; |
|
1229 |
cmds << close01; |
|
1230 |
QTest::newRow( "error03" ) << cmds << 0; |
|
1231 |
} |
|
1232 |
{ |
|
1233 |
QList<FtpCommand> cmds; |
|
1234 |
cmds << connectToHost01; |
|
1235 |
cmds << login01; |
|
1236 |
cmds << close01; |
|
1237 |
cmds << login01; |
|
1238 |
QTest::newRow( "error04" ) << cmds << 0; |
|
1239 |
} |
|
1240 |
} |
|
1241 |
||
1242 |
void tst_QFtp::commandSequence() |
|
1243 |
{ |
|
1244 |
QFETCH( QList<FtpCommand>, cmds ); |
|
1245 |
||
1246 |
ftp = newFtp(); |
|
1247 |
QList<FtpCommand>::iterator it; |
|
1248 |
for ( it = cmds.begin(); it != cmds.end(); ++it ) { |
|
1249 |
switch ( (*it).cmd ) { |
|
1250 |
case QFtp::ConnectToHost: |
|
1251 |
{ |
|
1252 |
QVERIFY( (*it).args.count() == 2 ); |
|
1253 |
uint port; |
|
1254 |
bool portOk; |
|
1255 |
port = (*it).args[1].toUInt( &portOk ); |
|
1256 |
QVERIFY( portOk ); |
|
1257 |
ids << ftp->connectToHost( (*it).args[0], port ); |
|
1258 |
} |
|
1259 |
break; |
|
1260 |
case QFtp::Login: |
|
1261 |
QVERIFY( (*it).args.count() == 2 ); |
|
1262 |
ids << ftp->login( (*it).args[0], (*it).args[1] ); |
|
1263 |
break; |
|
1264 |
case QFtp::Close: |
|
1265 |
QVERIFY( (*it).args.count() == 0 ); |
|
1266 |
ids << ftp->close(); |
|
1267 |
break; |
|
1268 |
default: |
|
1269 |
QFAIL( "Error in test: unexpected enum value" ); |
|
1270 |
break; |
|
1271 |
} |
|
1272 |
} |
|
1273 |
||
1274 |
QTestEventLoop::instance().enterLoop( 30 ); |
|
1275 |
delete ftp; |
|
1276 |
if ( QTestEventLoop::instance().timeout() ) |
|
1277 |
QFAIL( "Network operation timed out" ); |
|
1278 |
||
1279 |
QTEST( commandSequence_success, "success" ); |
|
1280 |
} |
|
1281 |
||
1282 |
void tst_QFtp::abort_data() |
|
1283 |
{ |
|
1284 |
QTest::addColumn<QString>("host"); |
|
1285 |
QTest::addColumn<uint>("port"); |
|
1286 |
QTest::addColumn<QString>("file"); |
|
1287 |
QTest::addColumn<QByteArray>("uploadData"); |
|
1288 |
||
1289 |
QTest::newRow( "get_fluke01" ) << QtNetworkSettings::serverName() << (uint)21 << QString("qtest/bigfile") << QByteArray(); |
|
1290 |
QTest::newRow( "get_fluke02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("qtest/rfc3252") << QByteArray(); |
|
1291 |
||
1292 |
// Qt/CE and Symbian test environment has to less memory for this test |
|
1293 |
#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) |
|
1294 |
QByteArray bigData( 10*1024*1024, 0 ); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1295 |
#else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1296 |
QByteArray bigData( 1*1024*1024, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1297 |
#endif |
0 | 1298 |
bigData.fill( 'B' ); |
1299 |
QTest::newRow( "put_fluke01" ) << QtNetworkSettings::serverName() << (uint)21 << QString("qtest/upload/abort_put") << bigData; |
|
1300 |
} |
|
1301 |
||
1302 |
void tst_QFtp::abort() |
|
1303 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1304 |
// In case you wonder where the abort() actually happens, look into |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1305 |
// tst_QFtp::dataTransferProgress |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1306 |
// |
0 | 1307 |
QFETCH( QString, host ); |
1308 |
QFETCH( uint, port ); |
|
1309 |
QFETCH( QString, file ); |
|
1310 |
QFETCH( QByteArray, uploadData ); |
|
1311 |
||
1312 |
QFtp::Command cmd; |
|
1313 |
if ( uploadData.size() == 0 ) |
|
1314 |
cmd = QFtp::Get; |
|
1315 |
else |
|
1316 |
cmd = QFtp::Put; |
|
1317 |
||
1318 |
ftp = newFtp(); |
|
1319 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host, port ) ); |
|
1320 |
addCommand( QFtp::Login, ftp->login() ); |
|
1321 |
if ( cmd == QFtp::Get ) |
|
1322 |
addCommand( cmd, ftp->get( file ) ); |
|
1323 |
else |
|
1324 |
addCommand( cmd, ftp->put( uploadData, file ) ); |
|
1325 |
addCommand( QFtp::Close, ftp->close() ); |
|
1326 |
||
1327 |
for(int time = 0; time <= uploadData.length() / 30000; time += 30) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1328 |
QTestEventLoop::instance().enterLoop( 50 ); |
0 | 1329 |
if(ftp->currentCommand() == QFtp::None) |
1330 |
break; |
|
1331 |
} |
|
1332 |
delete ftp; |
|
1333 |
if ( QTestEventLoop::instance().timeout() ) |
|
1334 |
QFAIL( "Network operation timed out" ); |
|
1335 |
||
1336 |
ResMapIt it = resultMap.find( cmd ); |
|
1337 |
QVERIFY( it != resultMap.end() ); |
|
1338 |
// ### how to test the abort? |
|
1339 |
if ( it.value().success ) { |
|
1340 |
// The FTP server on fluke is sadly returning a success, even when |
|
1341 |
// the operation was aborted. So we have to use some heuristics. |
|
1342 |
if ( host == QtNetworkSettings::serverName() ) { |
|
1343 |
if ( cmd == QFtp::Get ) { |
|
1344 |
QVERIFY(bytesDone <= bytesTotal); |
|
1345 |
} else { |
|
1346 |
// put commands should always be aborted, since we use really |
|
1347 |
// big data |
|
1348 |
QVERIFY( bytesDone != bytesTotal ); |
|
1349 |
} |
|
1350 |
} else { |
|
1351 |
// this could be tested by verifying that no more progress signals are emited |
|
1352 |
QVERIFY(bytesDone <= bytesTotal); |
|
1353 |
} |
|
1354 |
} else { |
|
1355 |
QVERIFY( bytesDone != bytesTotal ); |
|
1356 |
} |
|
1357 |
||
1358 |
if ( cmd == QFtp::Put ) { |
|
1359 |
////////////////////////////////////// |
|
1360 |
// cleanup (i.e. remove the file) |
|
1361 |
init(); |
|
1362 |
ftp = newFtp(); |
|
1363 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host, port ) ); |
|
1364 |
addCommand( QFtp::Login, ftp->login() ); |
|
1365 |
addCommand( QFtp::Remove, ftp->remove( file ) ); |
|
1366 |
addCommand( QFtp::Close, ftp->close() ); |
|
1367 |
||
1368 |
QTestEventLoop::instance().enterLoop( 30 ); |
|
1369 |
delete ftp; |
|
1370 |
if ( QTestEventLoop::instance().timeout() ) |
|
1371 |
QFAIL( "Network operation timed out" ); |
|
1372 |
||
1373 |
it = resultMap.find( QFtp::Remove ); |
|
1374 |
QVERIFY( it != resultMap.end() ); |
|
1375 |
QVERIFY( it.value().success == 1 ); |
|
1376 |
} |
|
1377 |
} |
|
1378 |
||
1379 |
void tst_QFtp::bytesAvailable_data() |
|
1380 |
{ |
|
1381 |
QTest::addColumn<QString>("host"); |
|
1382 |
QTest::addColumn<QString>("file"); |
|
1383 |
QTest::addColumn<int>("type"); |
|
1384 |
QTest::addColumn<qlonglong>("bytesAvailFinishedGet"); |
|
1385 |
QTest::addColumn<qlonglong>("bytesAvailFinished"); |
|
1386 |
QTest::addColumn<qlonglong>("bytesAvailDone"); |
|
1387 |
||
1388 |
QTest::newRow( "fluke01" ) << QtNetworkSettings::serverName() << QString("qtest/bigfile") << 0 << (qlonglong)519240 << (qlonglong)519240 << (qlonglong)519240; |
|
1389 |
QTest::newRow( "fluke02" ) << QtNetworkSettings::serverName() << QString("qtest/rfc3252") << 0 << (qlonglong)25962 << (qlonglong)25962 << (qlonglong)25962; |
|
1390 |
||
1391 |
QTest::newRow( "fluke03" ) << QtNetworkSettings::serverName() << QString("qtest/bigfile") << 1 << (qlonglong)519240 << (qlonglong)0 << (qlonglong)0; |
|
1392 |
QTest::newRow( "fluke04" ) << QtNetworkSettings::serverName() << QString("qtest/rfc3252") << 1 << (qlonglong)25962 << (qlonglong)0 << (qlonglong)0; |
|
1393 |
} |
|
1394 |
||
1395 |
void tst_QFtp::bytesAvailable() |
|
1396 |
{ |
|
1397 |
QFETCH( QString, host ); |
|
1398 |
QFETCH( QString, file ); |
|
1399 |
QFETCH( int, type ); |
|
1400 |
||
1401 |
ftp = newFtp(); |
|
1402 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host ) ); |
|
1403 |
addCommand( QFtp::Login, ftp->login() ); |
|
1404 |
addCommand( QFtp::Get, ftp->get( file ) ); |
|
1405 |
if ( type != 0 ) |
|
1406 |
addCommand( QFtp::Close, ftp->close() ); |
|
1407 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1408 |
QTestEventLoop::instance().enterLoop( 40 ); |
0 | 1409 |
if ( QTestEventLoop::instance().timeout() ) |
1410 |
QFAIL( "Network operation timed out" ); |
|
1411 |
||
1412 |
ResMapIt it = resultMap.find( QFtp::Get ); |
|
1413 |
QVERIFY( it != resultMap.end() ); |
|
1414 |
QVERIFY( it.value().success ); |
|
1415 |
||
1416 |
QFETCH(qlonglong, bytesAvailFinishedGet); |
|
1417 |
QCOMPARE(bytesAvailable_finishedGet, bytesAvailFinishedGet); |
|
1418 |
||
1419 |
QFETCH(qlonglong, bytesAvailFinished); |
|
1420 |
QCOMPARE(bytesAvailable_finished, bytesAvailFinished); |
|
1421 |
||
1422 |
QFETCH(qlonglong, bytesAvailDone); |
|
1423 |
QCOMPARE(bytesAvailable_done, bytesAvailDone); |
|
1424 |
||
1425 |
ftp->readAll(); |
|
1426 |
QVERIFY( ftp->bytesAvailable() == 0 ); |
|
1427 |
delete ftp; |
|
1428 |
} |
|
1429 |
||
1430 |
void tst_QFtp::activeMode() |
|
1431 |
{ |
|
1432 |
QFile file("tst_QFtp_activeMode_inittab"); |
|
1433 |
file.open(QIODevice::ReadWrite); |
|
1434 |
QFtp ftp; |
|
1435 |
ftp.setTransferMode(QFtp::Active); |
|
1436 |
ftp.connectToHost(QtNetworkSettings::serverName(), 21); |
|
1437 |
ftp.login(); |
|
1438 |
ftp.list(); |
|
1439 |
ftp.get("/qtest/rfc3252.txt", &file); |
|
1440 |
connect(&ftp, SIGNAL(done(bool)), SLOT(activeModeDone(bool))); |
|
1441 |
QTestEventLoop::instance().enterLoop(900); |
|
1442 |
QFile::remove("tst_QFtp_activeMode_inittab"); |
|
1443 |
QVERIFY(done_success == 1); |
|
1444 |
||
1445 |
} |
|
1446 |
||
1447 |
void tst_QFtp::activeModeDone(bool error) |
|
1448 |
{ |
|
1449 |
done_success = error ? -1 : 1; |
|
1450 |
QTestEventLoop::instance().exitLoop(); |
|
1451 |
} |
|
1452 |
||
1453 |
void tst_QFtp::proxy_data() |
|
1454 |
{ |
|
1455 |
QTest::addColumn<QString>("host"); |
|
1456 |
QTest::addColumn<uint>("port"); |
|
1457 |
QTest::addColumn<QString>("user"); |
|
1458 |
QTest::addColumn<QString>("password"); |
|
1459 |
QTest::addColumn<QString>("dir"); |
|
1460 |
QTest::addColumn<int>("success"); |
|
1461 |
QTest::addColumn<QStringList>("entryNames"); // ### we should rather use a QList<QUrlInfo> here |
|
1462 |
||
1463 |
QStringList flukeRoot; |
|
1464 |
flukeRoot << "qtest"; |
|
1465 |
QStringList flukeQtest; |
|
1466 |
flukeQtest << "bigfile"; |
|
1467 |
flukeQtest << "nonASCII"; |
|
1468 |
flukeQtest << "rfc3252"; |
|
1469 |
flukeQtest << "rfc3252.txt"; |
|
1470 |
flukeQtest << "upload"; |
|
1471 |
||
1472 |
QTest::newRow( "proxy_relPath01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("qtest") << 1 << flukeQtest; |
|
1473 |
QTest::newRow( "proxy_relPath02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") << QString("qtest") << 1 << flukeQtest; |
|
1474 |
||
1475 |
QTest::newRow( "proxy_absPath01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("/qtest") << 1 << flukeQtest; |
|
1476 |
QTest::newRow( "proxy_absPath02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") << QString("/var/ftp/qtest") << 1 << flukeQtest; |
|
1477 |
||
1478 |
QTest::newRow( "proxy_nonExist01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("foo") << 0 << QStringList(); |
|
1479 |
QTest::newRow( "proxy_nonExist03" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("/foo") << 0 << QStringList(); |
|
1480 |
} |
|
1481 |
||
1482 |
void tst_QFtp::proxy() |
|
1483 |
{ |
|
1484 |
QFETCH( QString, host ); |
|
1485 |
QFETCH( uint, port ); |
|
1486 |
QFETCH( QString, user ); |
|
1487 |
QFETCH( QString, password ); |
|
1488 |
QFETCH( QString, dir ); |
|
1489 |
||
1490 |
ftp = newFtp(); |
|
1491 |
addCommand( QFtp::SetProxy, ftp->setProxy( QtNetworkSettings::serverName(), 2121 ) ); |
|
1492 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host, port ) ); |
|
1493 |
addCommand( QFtp::Login, ftp->login( user, password ) ); |
|
1494 |
addCommand( QFtp::Cd, ftp->cd( dir ) ); |
|
1495 |
addCommand( QFtp::List, ftp->list() ); |
|
1496 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1497 |
QTestEventLoop::instance().enterLoop( 50 ); |
0 | 1498 |
|
1499 |
delete ftp; |
|
1500 |
if ( QTestEventLoop::instance().timeout() ) { |
|
1501 |
QFAIL( "Network operation timed out" ); |
|
1502 |
} |
|
1503 |
||
1504 |
ResMapIt it = resultMap.find( QFtp::Cd ); |
|
1505 |
QVERIFY( it != resultMap.end() ); |
|
1506 |
QFETCH( int, success ); |
|
1507 |
QCOMPARE( it.value().success, success ); |
|
1508 |
QFETCH( QStringList, entryNames ); |
|
1509 |
QCOMPARE( listInfo_i.count(), entryNames.count() ); |
|
1510 |
for ( uint i=0; i < (uint) entryNames.count(); i++ ) { |
|
1511 |
QCOMPARE( listInfo_i[i].name(), entryNames[i] ); |
|
1512 |
} |
|
1513 |
} |
|
1514 |
||
1515 |
||
1516 |
void tst_QFtp::binaryAscii() |
|
1517 |
{ |
|
1518 |
QString file = "asciifile%1.txt"; |
|
1519 |
||
1520 |
if(file.contains('%')) |
|
1521 |
file = file.arg(uniqueExtension); |
|
1522 |
||
1523 |
QByteArray putData = "a line of text\r\n"; |
|
1524 |
||
1525 |
init(); |
|
1526 |
ftp = newFtp(); |
|
1527 |
addCommand(QFtp::ConnectToHost, ftp->connectToHost(QtNetworkSettings::serverName(), 21)); |
|
1528 |
addCommand(QFtp::Login, ftp->login("ftptest", "password")); |
|
1529 |
addCommand(QFtp::Cd, ftp->cd("qtest/upload")); |
|
1530 |
addCommand(QFtp::Put, ftp->put(putData, file, QFtp::Ascii)); |
|
1531 |
addCommand(QFtp::Close, ftp->close()); |
|
1532 |
||
1533 |
QTestEventLoop::instance().enterLoop( 30 ); |
|
1534 |
if ( QTestEventLoop::instance().timeout() ) |
|
1535 |
QFAIL( "Network operation timed out" ); |
|
1536 |
||
1537 |
ResMapIt it = resultMap.find(QFtp::Put); |
|
1538 |
QVERIFY(it != resultMap.end()); |
|
1539 |
QVERIFY(it.value().success); |
|
1540 |
||
1541 |
QByteArray getData; |
|
1542 |
QBuffer getBuf(&getData); |
|
1543 |
getBuf.open(QBuffer::WriteOnly); |
|
1544 |
||
1545 |
init(); |
|
1546 |
ftp = newFtp(); |
|
1547 |
addCommand(QFtp::ConnectToHost, ftp->connectToHost(QtNetworkSettings::serverName(), 21)); |
|
1548 |
addCommand(QFtp::Login, ftp->login("ftptest", "password")); |
|
1549 |
addCommand(QFtp::Cd, ftp->cd("qtest/upload")); |
|
1550 |
addCommand(QFtp::Get, ftp->get(file, &getBuf, QFtp::Binary)); |
|
1551 |
addCommand(QFtp::Close, ftp->close()); |
|
1552 |
||
1553 |
QTestEventLoop::instance().enterLoop( 30 ); |
|
1554 |
if ( QTestEventLoop::instance().timeout() ) |
|
1555 |
QFAIL( "Network operation timed out" ); |
|
1556 |
||
1557 |
ResMapIt it2 = resultMap.find(QFtp::Get); |
|
1558 |
QVERIFY(it2 != resultMap.end()); |
|
1559 |
QVERIFY(it2.value().success); |
|
1560 |
// most modern ftp servers leave the file as it is by default |
|
1561 |
// (and do not remove the windows line ending), the -1 below could be |
|
1562 |
// deleted in the future |
|
1563 |
QVERIFY(getData.size() == putData.size()-1); |
|
1564 |
////////////////////////////////////////////////////////////////// |
|
1565 |
// cleanup (i.e. remove the file) -- this also tests the remove command |
|
1566 |
init(); |
|
1567 |
ftp = newFtp(); |
|
1568 |
addCommand(QFtp::ConnectToHost, ftp->connectToHost(QtNetworkSettings::serverName(), 21)); |
|
1569 |
addCommand(QFtp::Login, ftp->login("ftptest", "password")); |
|
1570 |
addCommand(QFtp::Cd, ftp->cd("qtest/upload")); |
|
1571 |
addCommand(QFtp::Remove, ftp->remove(file)); |
|
1572 |
addCommand(QFtp::Close, ftp->close()); |
|
1573 |
||
1574 |
QTestEventLoop::instance().enterLoop( 30 ); |
|
1575 |
delete ftp; |
|
1576 |
if ( QTestEventLoop::instance().timeout() ) |
|
1577 |
QFAIL( "Network operation timed out" ); |
|
1578 |
||
1579 |
it = resultMap.find( QFtp::Remove ); |
|
1580 |
QVERIFY( it != resultMap.end() ); |
|
1581 |
QCOMPARE( it.value().success, 1 ); |
|
1582 |
||
1583 |
QVERIFY(!fileExists(QtNetworkSettings::serverName(), 21, "ftptest", "password", file)); |
|
1584 |
} |
|
1585 |
||
1586 |
||
1587 |
// test QFtp::currentId() and QFtp::currentCommand() |
|
1588 |
#define CURRENTCOMMAND_TEST \ |
|
1589 |
{ \ |
|
1590 |
ResMapIt it; \ |
|
1591 |
for ( it = resultMap.begin(); it != resultMap.end(); ++it ) { \ |
|
1592 |
if ( it.value().id == ftp->currentId() ) { \ |
|
1593 |
QVERIFY( it.key() == ftp->currentCommand() ); \ |
|
1594 |
} \ |
|
1595 |
} \ |
|
1596 |
} |
|
1597 |
||
1598 |
void tst_QFtp::commandStarted( int id ) |
|
1599 |
{ |
|
1600 |
#if defined( DUMP_SIGNALS ) |
|
1601 |
qDebug( "%d:commandStarted( %d )", ftp->currentId(), id ); |
|
1602 |
#endif |
|
1603 |
// make sure that the commandStarted and commandFinished are nested correctly |
|
1604 |
QVERIFY( current_id == 0 ); |
|
1605 |
current_id = id; |
|
1606 |
||
1607 |
QVERIFY( !ids.isEmpty() ); |
|
1608 |
QVERIFY( ids.first() == id ); |
|
1609 |
if ( ids.count() > 1 ) { |
|
1610 |
QVERIFY( ftp->hasPendingCommands() ); |
|
1611 |
} else { |
|
1612 |
QVERIFY( !ftp->hasPendingCommands() ); |
|
1613 |
} |
|
1614 |
||
1615 |
QVERIFY( ftp->currentId() == id ); |
|
1616 |
QVERIFY( cur_state == ftp->state() ); |
|
1617 |
CURRENTCOMMAND_TEST; |
|
1618 |
||
1619 |
QVERIFY( ftp->error() == QFtp::NoError ); |
|
1620 |
} |
|
1621 |
||
1622 |
void tst_QFtp::commandFinished( int id, bool error ) |
|
1623 |
{ |
|
1624 |
#if defined( DUMP_SIGNALS ) |
|
1625 |
qDebug( "%d:commandFinished( %d, %d ) -- errorString: '%s'", |
|
1626 |
ftp->currentId(), id, (int)error, ftp->errorString().toLatin1().constData() ); |
|
1627 |
#endif |
|
1628 |
if ( ftp->currentCommand() == QFtp::Get ) { |
|
1629 |
bytesAvailable_finishedGet = ftp->bytesAvailable(); |
|
1630 |
} |
|
1631 |
bytesAvailable_finished = ftp->bytesAvailable(); |
|
1632 |
||
1633 |
// make sure that the commandStarted and commandFinished are nested correctly |
|
1634 |
QVERIFY( current_id == id ); |
|
1635 |
current_id = 0; |
|
1636 |
||
1637 |
QVERIFY( !ids.isEmpty() ); |
|
1638 |
QVERIFY( ids.first() == id ); |
|
1639 |
if ( !error && ids.count() > 1) { |
|
1640 |
QVERIFY( ftp->hasPendingCommands() ); |
|
1641 |
} else { |
|
1642 |
QVERIFY( !ftp->hasPendingCommands() ); |
|
1643 |
} |
|
1644 |
if ( error ) { |
|
1645 |
QVERIFY( ftp->error() != QFtp::NoError ); |
|
1646 |
ids.clear(); |
|
1647 |
} else { |
|
1648 |
QVERIFY( ftp->error() == QFtp::NoError ); |
|
1649 |
ids.pop_front(); |
|
1650 |
} |
|
1651 |
||
1652 |
QVERIFY( ftp->currentId() == id ); |
|
1653 |
QVERIFY( cur_state == ftp->state() ); |
|
1654 |
CURRENTCOMMAND_TEST; |
|
1655 |
||
1656 |
if ( QTest::currentTestFunction() != QLatin1String("commandSequence") ) { |
|
1657 |
ResMapIt it = resultMap.find( ftp->currentCommand() ); |
|
1658 |
QVERIFY( it != resultMap.end() ); |
|
1659 |
QVERIFY( it.value().success == -1 ); |
|
1660 |
if ( error ) |
|
1661 |
it.value().success = 0; |
|
1662 |
else |
|
1663 |
it.value().success = 1; |
|
1664 |
} |
|
1665 |
} |
|
1666 |
||
1667 |
void tst_QFtp::done( bool error ) |
|
1668 |
{ |
|
1669 |
#if defined( DUMP_SIGNALS ) |
|
1670 |
qDebug( "%d:done( %d )", ftp->currentId(), (int)error ); |
|
1671 |
#endif |
|
1672 |
bytesAvailable_done = ftp->bytesAvailable(); |
|
1673 |
||
1674 |
QVERIFY( ftp->currentId() == 0 ); |
|
1675 |
QVERIFY( current_id == 0 ); |
|
1676 |
QVERIFY( ids.isEmpty() ); |
|
1677 |
QVERIFY( cur_state == ftp->state() ); |
|
1678 |
QVERIFY( !ftp->hasPendingCommands() ); |
|
1679 |
||
1680 |
if ( QTest::currentTestFunction() == QLatin1String("commandSequence") ) { |
|
1681 |
QVERIFY( commandSequence_success == -1 ); |
|
1682 |
if ( error ) |
|
1683 |
commandSequence_success = 0; |
|
1684 |
else |
|
1685 |
commandSequence_success = 1; |
|
1686 |
} |
|
1687 |
QVERIFY( done_success == -1 ); |
|
1688 |
if ( error ) { |
|
1689 |
QVERIFY( ftp->error() != QFtp::NoError ); |
|
1690 |
done_success = 0; |
|
1691 |
} else { |
|
1692 |
QVERIFY( ftp->error() == QFtp::NoError ); |
|
1693 |
done_success = 1; |
|
1694 |
} |
|
1695 |
QTestEventLoop::instance().exitLoop(); |
|
1696 |
} |
|
1697 |
||
1698 |
void tst_QFtp::stateChanged( int state ) |
|
1699 |
{ |
|
1700 |
#if defined( DUMP_SIGNALS ) |
|
1701 |
qDebug( "%d: stateChanged( %d )", ftp->currentId(), state ); |
|
1702 |
#endif |
|
1703 |
QCOMPARE( ftp->currentId(), current_id ); |
|
1704 |
CURRENTCOMMAND_TEST; |
|
1705 |
||
1706 |
QVERIFY( state != cur_state ); |
|
1707 |
QCOMPARE( state, (int)ftp->state() ); |
|
1708 |
if ( state != QFtp::Unconnected ) { |
|
1709 |
// make sure that the states are always emitted in the right order (for |
|
1710 |
// this, we assume an ordering on the enum values, which they have at |
|
1711 |
// the moment) |
|
1712 |
QVERIFY( cur_state < state ); |
|
1713 |
||
1714 |
// make sure that state changes are only emitted in response to certain |
|
1715 |
// commands |
|
1716 |
switch ( state ) { |
|
1717 |
case QFtp::HostLookup: |
|
1718 |
case QFtp::Connecting: |
|
1719 |
case QFtp::Connected: |
|
1720 |
QCOMPARE( (int)ftp->currentCommand(), (int)QFtp::ConnectToHost ); |
|
1721 |
break; |
|
1722 |
case QFtp::LoggedIn: |
|
1723 |
QCOMPARE( (int)ftp->currentCommand(), (int)QFtp::Login ); |
|
1724 |
break; |
|
1725 |
case QFtp::Closing: |
|
1726 |
QCOMPARE( (int)ftp->currentCommand(), (int)QFtp::Close ); |
|
1727 |
break; |
|
1728 |
default: |
|
1729 |
QWARN( QString("Unexpected state '%1'").arg(state).toLatin1().constData() ); |
|
1730 |
break; |
|
1731 |
} |
|
1732 |
} |
|
1733 |
cur_state = state; |
|
1734 |
||
1735 |
if ( QTest::currentTestFunction() == QLatin1String("connectToHost") ) { |
|
1736 |
switch ( state ) { |
|
1737 |
case QFtp::HostLookup: |
|
1738 |
case QFtp::Connecting: |
|
1739 |
case QFtp::LoggedIn: |
|
1740 |
case QFtp::Closing: |
|
1741 |
// ignore |
|
1742 |
break; |
|
1743 |
case QFtp::Connected: |
|
1744 |
case QFtp::Unconnected: |
|
1745 |
QVERIFY( connectToHost_state == -1 ); |
|
1746 |
connectToHost_state = state; |
|
1747 |
break; |
|
1748 |
default: |
|
1749 |
QWARN( QString("Unknown state '%1'").arg(state).toLatin1().constData() ); |
|
1750 |
break; |
|
1751 |
} |
|
1752 |
} else if ( QTest::currentTestFunction() == QLatin1String("close") ) { |
|
1753 |
ResMapIt it = resultMap.find( QFtp::Close ); |
|
1754 |
if ( it!=resultMap.end() && ftp->currentId()==it.value().id ) { |
|
1755 |
if ( state == QFtp::Closing ) { |
|
1756 |
QVERIFY( close_state == -1 ); |
|
1757 |
close_state = state; |
|
1758 |
} else if ( state == QFtp::Unconnected ) { |
|
1759 |
QVERIFY( close_state == QFtp::Closing ); |
|
1760 |
close_state = state; |
|
1761 |
} |
|
1762 |
} |
|
1763 |
} else if ( QTest::currentTestFunction() == QLatin1String("login") ) { |
|
1764 |
ResMapIt it = resultMap.find( QFtp::Login ); |
|
1765 |
if ( it!=resultMap.end() && ftp->currentId()==it.value().id ) { |
|
1766 |
if ( state == QFtp::LoggedIn ) { |
|
1767 |
QVERIFY( login_state == -1 ); |
|
1768 |
login_state = state; |
|
1769 |
} |
|
1770 |
} |
|
1771 |
} |
|
1772 |
} |
|
1773 |
||
1774 |
void tst_QFtp::listInfo( const QUrlInfo &i ) |
|
1775 |
{ |
|
1776 |
#if defined( DUMP_SIGNALS ) |
|
1777 |
qDebug( "%d: listInfo( %s )", ftp->currentId(), i.name().toLatin1().constData() ); |
|
1778 |
#endif |
|
1779 |
QCOMPARE( ftp->currentId(), current_id ); |
|
1780 |
if ( ids.count() > 1 ) { |
|
1781 |
QVERIFY( ftp->hasPendingCommands() ); |
|
1782 |
} else { |
|
1783 |
QVERIFY( !ftp->hasPendingCommands() ); |
|
1784 |
} |
|
1785 |
QVERIFY( cur_state == ftp->state() ); |
|
1786 |
CURRENTCOMMAND_TEST; |
|
1787 |
||
1788 |
if ( QTest::currentTestFunction()==QLatin1String("list") || QTest::currentTestFunction()==QLatin1String("cd") || QTest::currentTestFunction()==QLatin1String("proxy") || inFileDirExistsFunction ) { |
|
1789 |
ResMapIt it = resultMap.find( QFtp::List ); |
|
1790 |
QVERIFY( it != resultMap.end() ); |
|
1791 |
QVERIFY( ftp->currentId() == it.value().id ); |
|
1792 |
listInfo_i << i; |
|
1793 |
} |
|
1794 |
} |
|
1795 |
||
1796 |
void tst_QFtp::readyRead() |
|
1797 |
{ |
|
1798 |
#if defined( DUMP_SIGNALS ) |
|
1799 |
qDebug( "%d: readyRead(), bytesAvailable == %lu", ftp->currentId(), ftp->bytesAvailable() ); |
|
1800 |
#endif |
|
1801 |
QCOMPARE( ftp->currentId(), current_id ); |
|
1802 |
if ( ids.count() > 1 ) { |
|
1803 |
QVERIFY( ftp->hasPendingCommands() ); |
|
1804 |
} else { |
|
1805 |
QVERIFY( !ftp->hasPendingCommands() ); |
|
1806 |
} |
|
1807 |
QVERIFY( cur_state == ftp->state() ); |
|
1808 |
CURRENTCOMMAND_TEST; |
|
1809 |
||
1810 |
if ( QTest::currentTestFunction() != QLatin1String("bytesAvailable") ) { |
|
1811 |
int oldSize = newData_ba.size(); |
|
1812 |
qlonglong bytesAvail = ftp->bytesAvailable(); |
|
1813 |
QByteArray ba = ftp->readAll(); |
|
1814 |
QVERIFY( ba.size() == (int) bytesAvail ); |
|
1815 |
newData_ba.resize( oldSize + ba.size() ); |
|
1816 |
memcpy( newData_ba.data()+oldSize, ba.data(), ba.size() ); |
|
1817 |
||
1818 |
if ( bytesTotal != -1 ) { |
|
1819 |
QVERIFY( (int)newData_ba.size() <= bytesTotal ); |
|
1820 |
} |
|
1821 |
QVERIFY( (int)newData_ba.size() == bytesDone ); |
|
1822 |
} |
|
1823 |
} |
|
1824 |
||
1825 |
void tst_QFtp::dataTransferProgress( qint64 done, qint64 total ) |
|
1826 |
{ |
|
1827 |
#if defined( DUMP_SIGNALS ) |
|
1828 |
qDebug( "%d: dataTransferProgress( %lli, %lli )", ftp->currentId(), done, total ); |
|
1829 |
#endif |
|
1830 |
QCOMPARE( ftp->currentId(), current_id ); |
|
1831 |
if ( ids.count() > 1 ) { |
|
1832 |
QVERIFY( ftp->hasPendingCommands() ); |
|
1833 |
} else { |
|
1834 |
QVERIFY( !ftp->hasPendingCommands() ); |
|
1835 |
} |
|
1836 |
QVERIFY( cur_state == ftp->state() ); |
|
1837 |
CURRENTCOMMAND_TEST; |
|
1838 |
||
1839 |
if ( bytesTotal == bytesTotal_init ) { |
|
1840 |
bytesTotal = total; |
|
1841 |
} else { |
|
1842 |
QVERIFY( bytesTotal == total ); |
|
1843 |
} |
|
1844 |
||
1845 |
QVERIFY( bytesTotal != bytesTotal_init ); |
|
1846 |
QVERIFY( bytesDone <= done ); |
|
1847 |
bytesDone = done; |
|
1848 |
if ( bytesTotal != -1 ) { |
|
1849 |
QVERIFY( bytesDone <= bytesTotal ); |
|
1850 |
} |
|
1851 |
||
1852 |
if ( QTest::currentTestFunction() == QLatin1String("abort") ) { |
|
1853 |
// ### it would be nice if we could specify in our testdata when to do |
|
1854 |
// the abort |
|
1855 |
if ( done >= total/100000 ) { |
|
1856 |
if ( ids.count() != 1 ) { |
|
1857 |
// do abort only once |
|
1858 |
int tmpId = ids.first(); |
|
1859 |
ids.clear(); |
|
1860 |
ids << tmpId; |
|
1861 |
ftp->abort(); |
|
1862 |
} |
|
1863 |
} |
|
1864 |
} |
|
1865 |
} |
|
1866 |
||
1867 |
||
1868 |
QFtp *tst_QFtp::newFtp() |
|
1869 |
{ |
|
1870 |
QFtp *nFtp = new QFtp( this ); |
|
1871 |
connect( nFtp, SIGNAL(commandStarted(int)), |
|
1872 |
SLOT(commandStarted(int)) ); |
|
1873 |
connect( nFtp, SIGNAL(commandFinished(int,bool)), |
|
1874 |
SLOT(commandFinished(int,bool)) ); |
|
1875 |
connect( nFtp, SIGNAL(done(bool)), |
|
1876 |
SLOT(done(bool)) ); |
|
1877 |
connect( nFtp, SIGNAL(stateChanged(int)), |
|
1878 |
SLOT(stateChanged(int)) ); |
|
1879 |
connect( nFtp, SIGNAL(listInfo(const QUrlInfo&)), |
|
1880 |
SLOT(listInfo(const QUrlInfo&)) ); |
|
1881 |
connect( nFtp, SIGNAL(readyRead()), |
|
1882 |
SLOT(readyRead()) ); |
|
1883 |
connect( nFtp, SIGNAL(dataTransferProgress(qint64, qint64)), |
|
1884 |
SLOT(dataTransferProgress(qint64, qint64)) ); |
|
1885 |
||
1886 |
return nFtp; |
|
1887 |
} |
|
1888 |
||
1889 |
void tst_QFtp::addCommand( QFtp::Command cmd, int id ) |
|
1890 |
{ |
|
1891 |
ids << id; |
|
1892 |
CommandResult res; |
|
1893 |
res.id = id; |
|
1894 |
res.success = -1; |
|
1895 |
resultMap[ cmd ] = res; |
|
1896 |
} |
|
1897 |
||
1898 |
bool tst_QFtp::fileExists( const QString &host, quint16 port, const QString &user, const QString &password, const QString &file, const QString &cdDir ) |
|
1899 |
{ |
|
1900 |
init(); |
|
1901 |
ftp = newFtp(); |
|
1902 |
// ### make these tests work |
|
1903 |
if (ftp->currentId() != 0) { |
|
1904 |
qWarning("ftp->currentId() != 0"); |
|
1905 |
return FALSE; |
|
1906 |
} |
|
1907 |
||
1908 |
if (ftp->state() != QFtp::Unconnected) { |
|
1909 |
qWarning("ftp->state() != QFtp::Unconnected"); |
|
1910 |
return FALSE; |
|
1911 |
} |
|
1912 |
||
1913 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host, port ) ); |
|
1914 |
addCommand( QFtp::Login, ftp->login( user, password ) ); |
|
1915 |
if ( !cdDir.isNull() ) |
|
1916 |
addCommand( QFtp::Cd, ftp->cd( cdDir ) ); |
|
1917 |
addCommand( QFtp::List, ftp->list( file ) ); |
|
1918 |
addCommand( QFtp::Close, ftp->close() ); |
|
1919 |
||
1920 |
inFileDirExistsFunction = TRUE; |
|
1921 |
QTestEventLoop::instance().enterLoop( 30 ); |
|
1922 |
delete ftp; |
|
1923 |
if ( QTestEventLoop::instance().timeout() ) { |
|
1924 |
// ### make this test work |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1925 |
qWarning("tst_QFtp::fileExists: Network operation timed out"); |
0 | 1926 |
return FALSE; |
1927 |
} |
|
1928 |
inFileDirExistsFunction = FALSE; |
|
1929 |
||
1930 |
ResMapIt it = resultMap.find( QFtp::ConnectToHost ); |
|
1931 |
// ### make these tests work |
|
1932 |
if (it == resultMap.end()) { |
|
1933 |
qWarning("it != resultMap.end()"); |
|
1934 |
return FALSE; |
|
1935 |
} |
|
1936 |
||
1937 |
if (it.value().success == -1) { |
|
1938 |
qWarning("it.value().success != -1"); |
|
1939 |
return FALSE; |
|
1940 |
} |
|
1941 |
||
1942 |
if ( it.value().success == 1 ) { |
|
1943 |
for ( uint i=0; i < (uint) listInfo_i.count(); i++ ) { |
|
1944 |
if ( QFileInfo(listInfo_i[i].name()).fileName() == QFileInfo(file).fileName() ) |
|
1945 |
return TRUE; |
|
1946 |
} |
|
1947 |
} |
|
1948 |
||
1949 |
//this is not a good warning considering sometime this function is used to test that a file does not exist |
|
1950 |
//qWarning("file doesn't exist"); |
|
1951 |
return FALSE; |
|
1952 |
} |
|
1953 |
||
1954 |
bool tst_QFtp::dirExists( const QString &host, quint16 port, const QString &user, const QString &password, const QString &cdDir, const QString &dirToCreate ) |
|
1955 |
{ |
|
1956 |
init(); |
|
1957 |
ftp = newFtp(); |
|
1958 |
// ### make these tests work |
|
1959 |
// QCOMPARE( ftp->currentId(), 0 ); |
|
1960 |
// QCOMPARE( (int)ftp->state(), (int)QFtp::Unconnected ); |
|
1961 |
||
1962 |
addCommand( QFtp::ConnectToHost, ftp->connectToHost( host, port ) ); |
|
1963 |
addCommand( QFtp::Login, ftp->login( user, password ) ); |
|
1964 |
if ( dirToCreate.startsWith( "/" ) ) |
|
1965 |
addCommand( QFtp::Cd, ftp->cd( dirToCreate ) ); |
|
1966 |
else |
|
1967 |
addCommand( QFtp::Cd, ftp->cd( cdDir + "/" + dirToCreate ) ); |
|
1968 |
addCommand( QFtp::Close, ftp->close() ); |
|
1969 |
||
1970 |
inFileDirExistsFunction = TRUE; |
|
1971 |
QTestEventLoop::instance().enterLoop( 30 ); |
|
1972 |
delete ftp; |
|
1973 |
if ( QTestEventLoop::instance().timeout() ) { |
|
1974 |
// ### make this test work |
|
1975 |
// QFAIL( "Network operation timed out" ); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1976 |
qWarning("tst_QFtp::dirExists: Network operation timed out"); |
0 | 1977 |
return FALSE; |
1978 |
} |
|
1979 |
inFileDirExistsFunction = FALSE; |
|
1980 |
||
1981 |
ResMapIt it = resultMap.find( QFtp::Cd ); |
|
1982 |
// ### make these tests work |
|
1983 |
// QVERIFY( it != resultMap.end() ); |
|
1984 |
// QVERIFY( it.value().success != -1 ); |
|
1985 |
return it.value().success == 1; |
|
1986 |
} |
|
1987 |
||
1988 |
void tst_QFtp::doneSignal() |
|
1989 |
{ |
|
1990 |
QFtp ftp; |
|
1991 |
QSignalSpy spy(&ftp, SIGNAL(done(bool))); |
|
1992 |
||
1993 |
ftp.connectToHost(QtNetworkSettings::serverName()); |
|
1994 |
ftp.login("anonymous"); |
|
1995 |
ftp.list(); |
|
1996 |
ftp.close(); |
|
1997 |
||
1998 |
done_success = 0; |
|
1999 |
while ( ftp.hasPendingCommands() ) |
|
2000 |
QCoreApplication::instance()->processEvents(); |
|
2001 |
QTest::qWait(200); |
|
2002 |
||
2003 |
QCOMPARE(spy.count(), 1); |
|
2004 |
QCOMPARE(spy.first().first().toBool(), false); |
|
2005 |
} |
|
2006 |
||
2007 |
void tst_QFtp::queueMoreCommandsInDoneSlot() |
|
2008 |
{ |
|
2009 |
QSKIP("Task 127050 && 113966", SkipSingle); |
|
2010 |
||
2011 |
QFtp ftp; |
|
2012 |
QSignalSpy doneSpy(&ftp, SIGNAL(done(bool))); |
|
2013 |
QSignalSpy commandFinishedSpy(&ftp, SIGNAL(commandFinished(int, bool))); |
|
2014 |
||
2015 |
this->ftp = &ftp; |
|
2016 |
connect(&ftp, SIGNAL(done(bool)), this, SLOT(cdUpSlot(bool))); |
|
2017 |
||
2018 |
ftp.connectToHost("ftp.qt.nokia.com"); |
|
2019 |
ftp.login(); |
|
2020 |
ftp.cd("qt"); |
|
2021 |
ftp.rmdir("qtest-removedir-noexist"); |
|
2022 |
||
2023 |
while ( ftp.hasPendingCommands() || ftp.currentCommand() != QFtp::None ) { |
|
2024 |
QCoreApplication::instance()->processEvents(QEventLoop::AllEvents |
|
2025 |
| QEventLoop::WaitForMoreEvents); |
|
2026 |
} |
|
2027 |
||
2028 |
QCOMPARE(doneSpy.count(), 2); |
|
2029 |
QCOMPARE(doneSpy.first().first().toBool(), true); |
|
2030 |
QCOMPARE(doneSpy.last().first().toBool(), false); |
|
2031 |
||
2032 |
QCOMPARE(commandFinishedSpy.count(), 6); |
|
2033 |
int firstId = commandFinishedSpy.at(0).at(0).toInt(); |
|
2034 |
QCOMPARE(commandFinishedSpy.at(0).at(1).toBool(), false); |
|
2035 |
QCOMPARE(commandFinishedSpy.at(1).at(0).toInt(), firstId + 1); |
|
2036 |
QCOMPARE(commandFinishedSpy.at(1).at(1).toBool(), false); |
|
2037 |
QCOMPARE(commandFinishedSpy.at(2).at(0).toInt(), firstId + 2); |
|
2038 |
QCOMPARE(commandFinishedSpy.at(2).at(1).toBool(), false); |
|
2039 |
QCOMPARE(commandFinishedSpy.at(3).at(0).toInt(), firstId + 3); |
|
2040 |
QCOMPARE(commandFinishedSpy.at(3).at(1).toBool(), true); |
|
2041 |
QCOMPARE(commandFinishedSpy.at(4).at(0).toInt(), firstId + 4); |
|
2042 |
QCOMPARE(commandFinishedSpy.at(4).at(1).toBool(), false); |
|
2043 |
QCOMPARE(commandFinishedSpy.at(5).at(0).toInt(), firstId + 5); |
|
2044 |
QCOMPARE(commandFinishedSpy.at(5).at(1).toBool(), false); |
|
2045 |
||
2046 |
this->ftp = 0; |
|
2047 |
} |
|
2048 |
||
2049 |
void tst_QFtp::cdUpSlot(bool error) |
|
2050 |
{ |
|
2051 |
if (error) { |
|
2052 |
ftp->cd(".."); |
|
2053 |
ftp->cd("qt"); |
|
2054 |
} |
|
2055 |
} |
|
2056 |
||
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2057 |
void tst_QFtp::qtbug7359Crash() |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2058 |
{ |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2059 |
QFtp ftp; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2060 |
ftp.connectToHost("127.0.0.1"); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2061 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2062 |
QTime t; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2063 |
int elapsed; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2064 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2065 |
t.start(); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2066 |
while ((elapsed = t.elapsed()) < 200) |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2067 |
QCoreApplication::processEvents(QEventLoop::AllEvents, 200 - elapsed); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2068 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2069 |
ftp.close(); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2070 |
t.restart(); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2071 |
while ((elapsed = t.elapsed()) < 1000) |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2072 |
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000 - elapsed); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2073 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2074 |
ftp.connectToHost("127.0.0.1"); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2075 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2076 |
t.restart(); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2077 |
while ((elapsed = t.elapsed()) < 2000) |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2078 |
QCoreApplication::processEvents(QEventLoop::AllEvents, 2000 - elapsed); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2079 |
} |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2080 |
|
0 | 2081 |
QTEST_MAIN(tst_QFtp) |
2082 |
||
2083 |
#include "tst_qftp.moc" |