4 * Copyright 2007 Paul Vriens
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * Use InternetGetLastResponseInfo when the last error is set to ERROR_INTERNET_EXTENDED_ERROR.
25 * Add W-function tests.
26 * Add missing function tests:
29 * FtpGetCurrentDirectory
31 * FtpSetCurrentDirectory
43 #include "wine/test.h"
45 static void test_getfile_no_open(void)
49 /* Invalid internet handle, the others are valid parameters */
50 SetLastError(0xdeadbeef);
51 bRet
= FtpGetFileA(NULL
, "welcome.msg", "should_be_non_existing_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
52 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
54 ok ( GetLastError() == ERROR_INTERNET_NOT_INITIALIZED
,
55 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
58 static void test_connect(void)
60 HINTERNET hInternet
, hFtp
;
62 SetLastError(0xdeadbeef);
63 hInternet
= InternetOpen(NULL
, 0, NULL
, NULL
, 0);
64 ok(hInternet
!= NULL
, "InternetOpen failed : %d\n", GetLastError());
68 skip("No internet connection could be made\n");
72 /* Try a few username/password combinations:
78 SetLastError(0xdeadbeef);
79 hFtp
= InternetConnect(hInternet
, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT
, "anonymous", NULL
, INTERNET_SERVICE_FTP
, 0, 0);
80 ok ( hFtp
== NULL
, "Expected InternetConnect to fail\n");
81 ok ( GetLastError() == ERROR_INTERNET_LOGIN_FAILURE
,
82 "Expected ERROR_INTERNET_LOGIN_FAILURE, got %d\n", GetLastError());
84 SetLastError(0xdeadbeef);
85 hFtp
= InternetConnect(hInternet
, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT
, NULL
, "IEUser@", INTERNET_SERVICE_FTP
, 0, 0);
86 ok ( hFtp
== NULL
, "Expected InternetConnect to fail\n");
87 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
88 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
90 /* Using a NULL username and password will be interpreted as anonymous ftp. The username will be 'anonymous' the password
91 * is created via some simple heuristics (see dlls/wininet/ftp.c).
92 * On Wine this registry key is not set by default so (NULL, NULL) will result in anonymous ftp with an (most likely) not
93 * accepted password (the username).
94 * If the first call fails because we get an ERROR_INTERNET_LOGIN_FAILURE, we try again with a (more) correct password.
97 SetLastError(0xdeadbeef);
98 hFtp
= InternetConnect(hInternet
, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_FTP
, 0, 0);
99 if (!hFtp
&& (GetLastError() == ERROR_INTERNET_LOGIN_FAILURE
))
101 /* We are most likely running on a clean Wine install or a Windows install where the registry key is removed */
102 SetLastError(0xdeadbeef);
103 hFtp
= InternetConnect(hInternet
, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT
, "anonymous", "IEUser@", INTERNET_SERVICE_FTP
, 0, 0);
105 ok ( hFtp
!= NULL
, "InternetConnect failed : %d\n", GetLastError());
106 ok ( GetLastError() == ERROR_SUCCESS
,
107 "ERROR_SUCCESS, got %d\n", GetLastError());
109 InternetCloseHandle(hFtp
);
110 InternetCloseHandle(hInternet
);
113 static void test_createdir(void)
116 HINTERNET hInternet
, hFtp
, hConnect
;
118 /* Invalid internet handle, the other is a valid parameter */
119 SetLastError(0xdeadbeef);
120 bRet
= FtpCreateDirectoryA(NULL
, "new_directory_deadbeef");
121 ok ( bRet
== FALSE
, "Expected FtpCreateDirectoryA to fail\n");
122 ok ( GetLastError() == ERROR_INVALID_HANDLE
,
123 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
125 hInternet
= InternetOpen(NULL
, 0, NULL
, NULL
, 0);
126 hFtp
= InternetConnect(hInternet
, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT
, "anonymous", "IEUser@", INTERNET_SERVICE_FTP
, 0, 0);
129 skip("No ftp connection could be made to ftp.winehq.org\n");
130 InternetCloseHandle(hInternet
);
134 /* We should have a ftp-connection (valid ftp session handle), try some creating */
136 /* No directory-name */
137 SetLastError(0xdeadbeef);
138 bRet
= FtpCreateDirectoryA(hFtp
, NULL
);
139 ok ( bRet
== FALSE
, "Expected FtpCreateDirectoryA to fail\n");
140 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
141 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
143 /* Parameters are OK, but we shouldn't be allowed to create the directory */
144 SetLastError(0xdeadbeef);
145 bRet
= FtpCreateDirectoryA(hFtp
, "new_directory_deadbeef");
146 ok ( bRet
== FALSE
, "Expected FtpCreateDirectoryA to fail\n");
148 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR
,
149 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
151 InternetCloseHandle(hFtp
);
153 /* Http handle-type for ftp connection */
155 hConnect
= InternetConnect(hInternet
, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
157 /* One small test to show that handle type is checked before parameters */
158 SetLastError(0xdeadbeef);
159 bRet
= FtpCreateDirectoryA(hConnect
, NULL
);
160 ok ( bRet
== FALSE
, "Expected FtpCreateDirectoryA to fail\n");
161 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
162 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
164 SetLastError(0xdeadbeef);
165 bRet
= FtpCreateDirectoryA(hConnect
, "new_directory_deadbeef");
166 ok ( bRet
== FALSE
, "Expected FtpCreateDirectoryA to fail\n");
167 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
168 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
170 InternetCloseHandle(hConnect
);
171 InternetCloseHandle(hInternet
);
174 static void test_deletefile(void)
177 HINTERNET hInternet
, hFtp
, hConnect
;
179 /* Invalid internet handle, the other is a valid parameter */
180 SetLastError(0xdeadbeef);
181 bRet
= FtpDeleteFileA(NULL
, "non_existent_file_deadbeef");
182 ok ( bRet
== FALSE
, "Expected FtpDeleteFileA to fail\n");
183 ok ( GetLastError() == ERROR_INVALID_HANDLE
,
184 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
186 hInternet
= InternetOpen(NULL
, 0, NULL
, NULL
, 0);
187 hFtp
= InternetConnect(hInternet
, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT
, "anonymous", "IEUser@", INTERNET_SERVICE_FTP
, 0, 0);
190 skip("No ftp connection could be made to ftp.winehq.org\n");
191 InternetCloseHandle(hInternet
);
195 /* We should have a ftp-connection, try some deleting */
198 SetLastError(0xdeadbeef);
199 bRet
= FtpDeleteFileA(hFtp
, NULL
);
200 ok ( bRet
== FALSE
, "Expected FtpDeleteFileA to fail\n");
201 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
202 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
204 /* Parameters are OK but remote file should not be there */
205 SetLastError(0xdeadbeef);
206 bRet
= FtpDeleteFileA(hFtp
, "non_existent_file_deadbeef");
207 ok ( bRet
== FALSE
, "Expected FtpDeleteFileA to fail\n");
209 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR
,
210 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
212 InternetCloseHandle(hFtp
);
214 /* Http handle-type for ftp connection */
216 hConnect
= InternetConnect(hInternet
, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
218 /* One small test to show that handle type is checked before parameters */
219 SetLastError(0xdeadbeef);
220 bRet
= FtpDeleteFileA(hConnect
, NULL
);
221 ok ( bRet
== FALSE
, "Expected FtpDeleteFileA to fail\n");
222 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
223 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
225 SetLastError(0xdeadbeef);
226 bRet
= FtpDeleteFileA(hConnect
, "non_existent_file_deadbeef");
227 ok ( bRet
== FALSE
, "Expected FtpCreateDirectoryA to fail\n");
228 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
229 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
231 InternetCloseHandle(hConnect
);
232 InternetCloseHandle(hInternet
);
235 static void test_getfile(void)
238 HINTERNET hInternet
, hFtp
, hConnect
;
240 /* The order of checking is:
242 * All parameters except 'session handle' and 'condition flags'
244 * Session handle type
248 /* Test to show validity of 'local file' parameter is tested first (together with 'remote file') */
249 SetLastError(0xdeadbeef);
250 bRet
= FtpGetFileA(NULL
, NULL
, "should_be_non_existing_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
251 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
252 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
253 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
255 /* Test to show session handle is checked before 'condition flags' */
256 SetLastError(0xdeadbeef);
257 bRet
= FtpGetFileA(NULL
, "welcome.msg", "should_be_non_existing_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, 5, 0);
258 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
259 ok ( GetLastError() == ERROR_INVALID_HANDLE
,
260 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
262 hInternet
= InternetOpen(NULL
, 0, NULL
, NULL
, 0);
263 hFtp
= InternetConnect(hInternet
, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT
, "anonymous", "IEUser@", INTERNET_SERVICE_FTP
, 0, 0);
266 skip("No ftp connection could be made to ftp.winehq.org\n");
267 InternetCloseHandle(hInternet
);
271 /* Make sure we start clean */
273 DeleteFileA("should_be_non_existing_deadbeef");
274 DeleteFileA("should_also_be_non_existing_deadbeef");
276 /* We should have a ftp-connection, try some getting */
279 SetLastError(0xdeadbeef);
280 bRet
= FtpGetFileA(hFtp
, NULL
, "should_be_non_existing_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
281 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
282 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
283 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
284 ok (GetFileAttributesA("should_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES
,
285 "Local file should not have been created\n");
286 DeleteFileA("should_be_non_existing_deadbeef");
289 SetLastError(0xdeadbeef);
290 bRet
= FtpGetFileA(hFtp
, "welcome.msg", NULL
, FALSE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
291 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
292 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
293 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
295 /* Zero attributes, but call succeeds (as would CreateFile with zero attributes) */
296 SetLastError(0xdeadbeef);
297 bRet
= FtpGetFileA(hFtp
, "welcome.msg", "should_be_non_existing_deadbeef", FALSE
, 0, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
300 ok ( bRet
== TRUE
, "Expected FtpGetFileA to succeed\n");
301 ok ( GetLastError() == ERROR_SUCCESS
,
302 "Expected ERROR_SUCCESS, got %d\n", GetLastError());
304 /* Wine passes this test but for the wrong reason */
305 ok (GetFileAttributesA("should_be_non_existing_deadbeef") != INVALID_FILE_ATTRIBUTES
,
306 "Local file should have been created\n");
307 DeleteFileA("should_be_non_existing_deadbeef");
309 /* Illegal condition flags */
310 SetLastError(0xdeadbeef);
311 bRet
= FtpGetFileA(hFtp
, "welcome.msg", "should_be_non_existing_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, 5, 0);
312 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
313 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
314 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
315 ok (GetFileAttributesA("should_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES
,
316 "Local file should not have been created\n");
317 DeleteFileA("should_be_non_existing_deadbeef");
319 /* Remote file doesn't exist */
320 SetLastError(0xdeadbeef);
321 bRet
= FtpGetFileA(hFtp
, "should_be_non_existing_deadbeef", "should_also_be_non_existing_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
322 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
325 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR
,
326 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
327 /* Currently Wine always creates the local file (even on failure) which is not correct, hence the test */
328 ok (GetFileAttributesA("should_also_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES
,
329 "Local file should not have been created\n");
331 DeleteFileA("should_also_be_non_existing_deadbeef");
333 /* This one should succeed and give us a copy of the 'welcome.msg' file */
334 SetLastError(0xdeadbeef);
335 bRet
= FtpGetFileA(hFtp
, "welcome.msg", "should_be_non_existing_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
338 ok ( bRet
== TRUE
, "Expected FtpGetFileA to succeed\n");
339 ok ( GetLastError() == ERROR_SUCCESS
,
340 "Expected ERROR_SUCCESS, got %d\n", GetLastError());
343 if (GetFileAttributesA("should_be_non_existing_deadbeef") != INVALID_FILE_ATTRIBUTES
)
345 /* Should succeed as fFailIfExists is set to FALSE (meaning don't fail if local file exists) */
346 SetLastError(0xdeadbeef);
347 bRet
= FtpGetFileA(hFtp
, "welcome.msg", "should_be_non_existing_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
350 ok ( bRet
== TRUE
, "Expected FtpGetFileA to succeed\n");
351 ok ( GetLastError() == ERROR_SUCCESS
,
352 "Expected ERROR_SUCCESS, got %d\n", GetLastError());
355 /* Should fail as fFailIfExists is set to TRUE */
356 SetLastError(0xdeadbeef);
357 bRet
= FtpGetFileA(hFtp
, "welcome.msg", "should_be_non_existing_deadbeef", TRUE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
358 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
360 ok ( GetLastError() == ERROR_FILE_EXISTS
,
361 "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
363 /* Prove that the existence of the local file is checked first (or at least reported last) */
364 SetLastError(0xdeadbeef);
365 bRet
= FtpGetFileA(hFtp
, "should_be_non_existing_deadbeef", "should_be_non_existing_deadbeef", TRUE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
366 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
368 ok ( GetLastError() == ERROR_FILE_EXISTS
,
369 "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
371 DeleteFileA("should_be_non_existing_deadbeef");
374 InternetCloseHandle(hFtp
);
376 /* Http handle-type for ftp connection */
378 hConnect
= InternetConnect(hInternet
, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
380 /* Test to show existence of local file is tested before 'session handle type' */
381 SetLastError(0xdeadbeef);
382 bRet
= FtpGetFileA(hConnect
, NULL
, "should_be_non_existing_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
383 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
384 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
385 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
387 /* Test to show that 'session handle type' is checked before 'condition flags' */
388 SetLastError(0xdeadbeef);
389 bRet
= FtpGetFileA(hConnect
, "welcome.msg", "should_be_non_existing_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, 5, 0);
390 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
391 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
392 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
394 SetLastError(0xdeadbeef);
395 bRet
= FtpGetFileA(hConnect
, "should_be_non_existing_deadbeef", "should_be_non_existing_deadbeef", TRUE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
396 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
397 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
398 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
400 InternetCloseHandle(hConnect
);
401 InternetCloseHandle(hInternet
);
404 static void test_openfile(void)
406 HINTERNET hOpenFile
, hInternet
, hFtp
, hConnect
;
408 /* Invalid internet handle, the rest are valid parameters */
409 SetLastError(0xdeadbeef);
410 hOpenFile
= FtpOpenFileA(NULL
, "welcome.msg", GENERIC_READ
, FTP_TRANSFER_TYPE_ASCII
, 0);
411 ok ( !hOpenFile
, "Expected FtpOpenFileA to fail\n");
412 ok ( GetLastError() == ERROR_INVALID_HANDLE
,
413 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
414 InternetCloseHandle(hOpenFile
); /* Just in case */
416 hInternet
= InternetOpen(NULL
, 0, NULL
, NULL
, 0);
417 hFtp
= InternetConnect(hInternet
, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT
, "anonymous", "IEUser@", INTERNET_SERVICE_FTP
, 0, 0);
420 skip("No ftp connection could be made to ftp.winehq.org\n");
421 InternetCloseHandle(hInternet
);
425 /* We should have a ftp-connection (valid ftp session handle), try some opening */
428 SetLastError(0xdeadbeef);
429 hOpenFile
= FtpOpenFileA(hFtp
, NULL
, GENERIC_READ
, FTP_TRANSFER_TYPE_ASCII
, 0);
430 ok ( !hOpenFile
, "Expected FtpOpenFileA to fail\n");
431 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
432 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
433 InternetCloseHandle(hOpenFile
); /* Just in case */
435 /* Illegal access flags */
436 SetLastError(0xdeadbeef);
437 hOpenFile
= FtpOpenFileA(hFtp
, "welcome.msg", 0, FTP_TRANSFER_TYPE_ASCII
, 0);
438 ok ( !hOpenFile
, "Expected FtpOpenFileA to fail\n");
439 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
440 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
441 InternetCloseHandle(hOpenFile
); /* Just in case */
443 /* Illegal combination of access flags */
444 SetLastError(0xdeadbeef);
445 hOpenFile
= FtpOpenFileA(hFtp
, "welcome.msg", GENERIC_READ
|GENERIC_WRITE
, FTP_TRANSFER_TYPE_ASCII
, 0);
446 ok ( !hOpenFile
, "Expected FtpOpenFileA to fail\n");
447 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
448 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
449 InternetCloseHandle(hOpenFile
); /* Just in case */
451 /* Illegal condition flags */
452 SetLastError(0xdeadbeef);
453 hOpenFile
= FtpOpenFileA(hFtp
, "welcome.msg", GENERIC_READ
, 5, 0);
454 ok ( !hOpenFile
, "Expected FtpOpenFileA to fail\n");
455 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
456 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
457 InternetCloseHandle(hOpenFile
); /* Just in case */
460 SetLastError(0xdeadbeef);
461 hOpenFile
= FtpOpenFileA(hFtp
, "welcome.msg", GENERIC_READ
, FTP_TRANSFER_TYPE_ASCII
, 0);
462 ok ( hOpenFile
!= NULL
, "Expected FtpOpenFileA to succeed\n");
463 /* For some strange/unknown reason, win98 returns ERROR_FILE_NOT_FOUND */
464 ok ( GetLastError() == ERROR_SUCCESS
|| GetLastError() == ERROR_FILE_NOT_FOUND
,
465 "Expected ERROR_SUCCESS or ERROR_FILE_NOT_FOUND (win98), got %d\n", GetLastError());
470 HINTERNET hOpenFile2
;
472 /* We have a handle so all ftp calls should fail (TODO: Put more ftp-calls in here) */
473 SetLastError(0xdeadbeef);
474 bRet
= FtpGetFileA(hFtp
, "welcome.msg", "should_be_non_existing_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
475 ok ( bRet
== FALSE
, "Expected FtpDeleteFileA to fail\n");
476 ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS
,
477 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError());
478 DeleteFileA("should_be_non_existing_deadbeef"); /* Just in case */
480 SetLastError(0xdeadbeef);
481 hOpenFile2
= FtpOpenFileA(hFtp
, "welcome.msg", GENERIC_READ
, FTP_TRANSFER_TYPE_ASCII
, 0);
482 ok ( bRet
== FALSE
, "Expected FtpOpenFileA to fail\n");
483 ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS
,
484 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError());
485 InternetCloseHandle(hOpenFile
); /* Just in case */
488 InternetCloseHandle(hOpenFile
);
489 InternetCloseHandle(hFtp
);
491 /* Http handle-type for ftp connection */
493 hConnect
= InternetConnect(hInternet
, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
495 /* One small test to show that handle type is checked before parameters */
496 SetLastError(0xdeadbeef);
497 hOpenFile
= FtpOpenFileA(hConnect
, "welcome.msg", GENERIC_READ
, 5, 0);
498 ok ( !hOpenFile
, "Expected FtpOpenFileA to fail\n");
499 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
500 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
501 InternetCloseHandle(hOpenFile
); /* Just in case */
503 SetLastError(0xdeadbeef);
504 hOpenFile
= FtpOpenFileA(hConnect
, "welcome.msg", GENERIC_READ
, FTP_TRANSFER_TYPE_ASCII
, 0);
505 ok ( hOpenFile
== NULL
, "Expected FtpOpenFileA to fail\n");
506 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
507 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
509 InternetCloseHandle(hOpenFile
); /* Just in case */
510 InternetCloseHandle(hConnect
);
511 InternetCloseHandle(hInternet
);
514 static void test_putfile(void)
517 HINTERNET hInternet
, hFtp
, hConnect
;
520 /* The order of checking is:
522 * All parameters except 'session handle' and 'condition flags'
524 * Session handle type
528 /* Test to show validity of 'local file' parameter is tested first (together with 'remote file') */
529 SetLastError(0xdeadbeef);
530 bRet
= FtpPutFileA(NULL
, NULL
, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN
, 0);
531 ok ( bRet
== FALSE
, "Expected FtpPutFileA to fail\n");
532 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
533 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
535 /* Test to show session handle is checked before 'condition flags' */
536 SetLastError(0xdeadbeef);
537 bRet
= FtpPutFileA(NULL
, "non_existing_local", "non_existing_remote", 5, 0);
538 ok ( bRet
== FALSE
, "Expected FtpPutFileA to fail\n");
539 ok ( GetLastError() == ERROR_INVALID_HANDLE
,
540 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
542 hInternet
= InternetOpen(NULL
, 0, NULL
, NULL
, 0);
543 hFtp
= InternetConnect(hInternet
, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT
, "anonymous", "IEUser@", INTERNET_SERVICE_FTP
, 0, 0);
546 skip("No ftp connection could be made to ftp.winehq.org\n");
547 InternetCloseHandle(hInternet
);
551 /* We should have a ftp-connection, try some puts */
553 /* No local file given */
554 SetLastError(0xdeadbeef);
555 bRet
= FtpPutFileA(hFtp
, NULL
, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN
, 0);
556 ok ( bRet
== FALSE
, "Expected FtpPutFileA to fail\n");
557 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
558 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
560 /* No remote file given */
561 SetLastError(0xdeadbeef);
562 bRet
= FtpPutFileA(hFtp
, "non_existing_local", NULL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
563 ok ( bRet
== FALSE
, "Expected FtpPutFileA to fail\n");
564 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
565 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
567 /* Illegal condition flags */
568 SetLastError(0xdeadbeef);
569 bRet
= FtpPutFileA(hFtp
, "non_existing_local", "non_existing_remote", 5, 0);
570 ok ( bRet
== FALSE
, "Expected FtpPutFileA to fail\n");
571 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
572 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
574 /* Parameters are OK but local file doesn't exist */
575 SetLastError(0xdeadbeef);
576 bRet
= FtpPutFileA(hFtp
, "non_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN
, 0);
577 ok ( bRet
== FALSE
, "Expected FtpPutFileA to fail\n");
578 ok ( GetLastError() == ERROR_FILE_NOT_FOUND
,
579 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
581 /* Create a temporary local file */
582 SetLastError(0xdeadbeef);
583 hFile
= CreateFileA("now_existing_local", GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
584 ok ( hFile
!= NULL
, "Error creating a local file : %d\n", GetLastError());
587 /* Local file exists but we shouldn't be allowed to 'put' the file */
588 SetLastError(0xdeadbeef);
589 bRet
= FtpPutFileA(hFtp
, "now_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN
, 0);
590 ok ( bRet
== FALSE
, "Expected FtpPutFileA to fail\n");
592 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR
,
593 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
595 DeleteFileA("now_existing_local");
597 InternetCloseHandle(hFtp
);
599 /* Http handle-type for ftp connection */
601 hConnect
= InternetConnect(hInternet
, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
603 /* Test to show validity of 'local file' parameter is tested a before 'session handle type' */
604 SetLastError(0xdeadbeef);
605 bRet
= FtpPutFileA(hConnect
, NULL
, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN
, 0);
606 ok ( bRet
== FALSE
, "Expected FtpPutFileA to fail\n");
607 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
608 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
610 /* Test to show that 'session handle type' is checked before 'condition flags' */
611 SetLastError(0xdeadbeef);
612 bRet
= FtpPutFileA(hConnect
, "non_existing_local", "non_existing_remote", 5, 0);
613 ok ( bRet
== FALSE
, "Expected FtpPutFileA to fail\n");
614 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
615 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
617 SetLastError(0xdeadbeef);
618 bRet
= FtpPutFileA(hConnect
, "non_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN
, 0);
619 ok ( bRet
== FALSE
, "Expected FtpPutFileA to fail\n");
620 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
621 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
623 InternetCloseHandle(hConnect
);
624 InternetCloseHandle(hInternet
);
627 static void test_removedir(void)
630 HINTERNET hInternet
, hFtp
, hConnect
;
632 /* Invalid internet handle, the other is a valid parameter */
633 SetLastError(0xdeadbeef);
634 bRet
= FtpRemoveDirectoryA(NULL
, "should_be_non_existing_deadbeef_dir");
635 ok ( bRet
== FALSE
, "Expected FtpRemoveDirectoryA to fail\n");
636 ok ( GetLastError() == ERROR_INVALID_HANDLE
,
637 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
639 hInternet
= InternetOpen(NULL
, 0, NULL
, NULL
, 0);
640 hFtp
= InternetConnect(hInternet
, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT
, "anonymous", "IEUser@", INTERNET_SERVICE_FTP
, 0, 0);
643 skip("No ftp connection could be made to ftp.winehq.org\n");
644 InternetCloseHandle(hInternet
);
648 /* We should have a ftp-connection, try some removing */
650 /* No remote directory given */
651 SetLastError(0xdeadbeef);
652 bRet
= FtpRemoveDirectoryA(hFtp
, NULL
);
653 ok ( bRet
== FALSE
, "Expected FtpRemoveDirectoryA to fail\n");
654 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
655 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
657 /* Remote directory doesn't exist */
658 SetLastError(0xdeadbeef);
659 bRet
= FtpRemoveDirectoryA(hFtp
, "should_be_non_existing_deadbeef_dir");
660 ok ( bRet
== FALSE
, "Expected FtpRemoveDirectoryA to fail\n");
662 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR
,
663 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
665 /* We shouldn't be allowed to remove that directory */
666 SetLastError(0xdeadbeef);
667 bRet
= FtpRemoveDirectoryA(hFtp
, "pub");
668 ok ( bRet
== FALSE
, "Expected FtpRemoveDirectoryA to fail\n");
670 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR
,
671 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
673 InternetCloseHandle(hFtp
);
675 /* Http handle-type for ftp connection */
677 hConnect
= InternetConnect(hInternet
, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
679 /* One small test to show that handle type is checked before parameters */
680 SetLastError(0xdeadbeef);
681 bRet
= FtpRemoveDirectoryA(hConnect
, NULL
);
682 ok ( bRet
== FALSE
, "Expected FtpRemoveDirectoryA to fail\n");
683 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
684 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
686 SetLastError(0xdeadbeef);
687 bRet
= FtpRemoveDirectoryA(hConnect
, "should_be_non_existing_deadbeef_dir");
688 ok ( bRet
== FALSE
, "Expected FtpRemoveDirectoryA to fail\n");
689 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
690 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
692 InternetCloseHandle(hConnect
);
693 InternetCloseHandle(hInternet
);
696 static void test_renamefile(void)
699 HINTERNET hInternet
, hFtp
, hConnect
;
701 /* Invalid internet handle, the rest are valid parameters */
702 SetLastError(0xdeadbeef);
703 bRet
= FtpRenameFileA(NULL
, "should_be_non_existing_deadbeef", "new");
704 ok ( bRet
== FALSE
, "Expected FtpRenameFileA to fail\n");
705 ok ( GetLastError() == ERROR_INVALID_HANDLE
,
706 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
708 hInternet
= InternetOpen(NULL
, 0, NULL
, NULL
, 0);
709 hFtp
= InternetConnect(hInternet
, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT
, "anonymous", "IEUser@", INTERNET_SERVICE_FTP
, 0, 0);
712 skip("No ftp connection could be made to ftp.winehq.org\n");
713 InternetCloseHandle(hInternet
);
717 /* We should have a ftp-connection, try some renaming */
719 /* No 'existing' file */
720 SetLastError(0xdeadbeef);
721 bRet
= FtpRenameFileA(hFtp
, NULL
, "new");
722 ok ( bRet
== FALSE
, "Expected FtpRenameFileA to fail\n");
723 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
724 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
727 SetLastError(0xdeadbeef);
728 bRet
= FtpRenameFileA(hFtp
, "should_be_non_existing_deadbeef", NULL
);
729 ok ( bRet
== FALSE
, "Expected FtpRenameFileA to fail\n");
730 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
731 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
733 /* Existing file shouldn't be there */
734 SetLastError(0xdeadbeef);
735 bRet
= FtpRenameFileA(hFtp
, "should_be_non_existing_deadbeef", "new");
736 ok ( bRet
== FALSE
, "Expected FtpRenameFileA to fail\n");
738 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR
,
739 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
741 InternetCloseHandle(hFtp
);
743 /* Http handle-type for ftp connection */
745 hConnect
= InternetConnect(hInternet
, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
747 /* One small test to show that handle type is checked before parameters */
748 SetLastError(0xdeadbeef);
749 bRet
= FtpRenameFileA(hConnect
, "should_be_non_existing_deadbeef", NULL
);
750 ok ( bRet
== FALSE
, "Expected FtpRenameFileA to fail\n");
751 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
752 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
754 SetLastError(0xdeadbeef);
755 bRet
= FtpRenameFileA(hConnect
, "should_be_non_existing_deadbeef", "new");
756 ok ( bRet
== FALSE
, "Expected FtpRenameFileA to fail\n");
757 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
758 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
760 InternetCloseHandle(hConnect
);
761 InternetCloseHandle(hInternet
);
766 /* The first call should always be a proper InternetOpen, if not
767 * several calls will return ERROR_INTERNET_NOT_INITIALIZED when
768 * all parameters are correct but no session handle is given. Whereas
769 * the same call will return ERROR_INVALID_HANDLE if an InternetOpen
771 * The following test will show that behaviour, where the tests inside
772 * the other sub-tests will show the other situation.
774 test_getfile_no_open();