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");
53 ok ( GetLastError() == ERROR_INTERNET_NOT_INITIALIZED ||
54 GetLastError() == ERROR_INVALID_HANDLE,
55 "Expected ERROR_INTERNET_NOT_INITIALIZED or ERROR_INVALID_HANDLE (win98), 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;
241 /* The order of checking is:
243 * All parameters except 'session handle' and 'condition flags'
245 * Session handle type
249 /* Test to show the parameter checking order depends on the Windows version */
250 SetLastError(0xdeadbeef);
251 bRet = FtpGetFileA(NULL, NULL, "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
252 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
253 ok ( GetLastError() == ERROR_INVALID_HANDLE ||
254 GetLastError() == ERROR_INVALID_PARAMETER,
255 "Expected ERROR_INVALID_HANDLE (win98) or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
257 /* Test to show session handle is checked before 'condition flags' */
258 SetLastError(0xdeadbeef);
259 bRet = FtpGetFileA(NULL, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, 5, 0);
260 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
261 ok ( GetLastError() == ERROR_INVALID_HANDLE,
262 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
264 hInternet = InternetOpen(NULL, 0, NULL, NULL, 0);
265 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0);
268 skip("No ftp connection could be made to ftp.winehq.org\n");
269 InternetCloseHandle(hInternet);
273 /* Make sure we start clean */
275 DeleteFileA("should_be_non_existing_deadbeef");
276 DeleteFileA("should_also_be_non_existing_deadbeef");
278 /* We should have a ftp-connection, try some getting */
281 SetLastError(0xdeadbeef);
282 bRet = FtpGetFileA(hFtp, NULL, "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
283 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
284 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
285 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
286 ok (GetFileAttributesA("should_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
287 "Local file should not have been created\n");
288 DeleteFileA("should_be_non_existing_deadbeef");
291 SetLastError(0xdeadbeef);
292 bRet = FtpGetFileA(hFtp, "welcome.msg", NULL, FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
293 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
294 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
295 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
297 /* Zero attributes, but call succeeds (as would CreateFile with zero attributes) */
298 SetLastError(0xdeadbeef);
299 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, 0, FTP_TRANSFER_TYPE_UNKNOWN, 0);
302 ok ( bRet == TRUE, "Expected FtpGetFileA to succeed\n");
303 ok ( GetLastError() == ERROR_SUCCESS,
304 "Expected ERROR_SUCCESS, got %d\n", GetLastError());
306 /* Wine passes this test but for the wrong reason */
307 ok (GetFileAttributesA("should_be_non_existing_deadbeef") != INVALID_FILE_ATTRIBUTES,
308 "Local file should have been created\n");
309 DeleteFileA("should_be_non_existing_deadbeef");
311 /* Illegal condition flags */
312 SetLastError(0xdeadbeef);
313 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, 5, 0);
314 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
315 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
316 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
317 ok (GetFileAttributesA("should_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
318 "Local file should not have been created\n");
319 DeleteFileA("should_be_non_existing_deadbeef");
321 /* Remote file doesn't exist (and local doesn't exist as well) */
322 SetLastError(0xdeadbeef);
323 bRet = FtpGetFileA(hFtp, "should_be_non_existing_deadbeef", "should_also_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
324 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
327 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
328 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
329 /* Currently Wine always creates the local file (even on failure) which is not correct, hence the test */
330 ok (GetFileAttributesA("should_also_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
331 "Local file should not have been created\n");
333 DeleteFileA("should_also_be_non_existing_deadbeef");
335 /* Same call as the previous but now the local file does exists. Windows just removes the file if the call fails
336 * even if the local existed before!
339 /* Create a temporary local file */
340 SetLastError(0xdeadbeef);
341 hFile = CreateFileA("should_also_be_non_existing_deadbeef", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
342 ok ( hFile != NULL, "Error creating a local file : %d\n", GetLastError());
344 SetLastError(0xdeadbeef);
345 bRet = FtpGetFileA(hFtp, "should_be_non_existing_deadbeef", "should_also_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
346 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
349 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
350 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
351 /* Currently Wine always creates the local file (even on failure) which is not correct, hence the test */
352 ok (GetFileAttributesA("should_also_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
353 "Local file should not have been created\n");
355 DeleteFileA("should_also_be_non_existing_deadbeef");
357 /* This one should succeed and give us a copy of the 'welcome.msg' file */
358 SetLastError(0xdeadbeef);
359 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
362 ok ( bRet == TRUE, "Expected FtpGetFileA to succeed\n");
363 ok ( GetLastError() == ERROR_SUCCESS,
364 "Expected ERROR_SUCCESS, got %d\n", GetLastError());
367 if (GetFileAttributesA("should_be_non_existing_deadbeef") != INVALID_FILE_ATTRIBUTES)
369 /* Should succeed as fFailIfExists is set to FALSE (meaning don't fail if local file exists) */
370 SetLastError(0xdeadbeef);
371 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
374 ok ( bRet == TRUE, "Expected FtpGetFileA to succeed\n");
375 ok ( GetLastError() == ERROR_SUCCESS,
376 "Expected ERROR_SUCCESS, got %d\n", GetLastError());
379 /* Should fail as fFailIfExists is set to TRUE */
380 SetLastError(0xdeadbeef);
381 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", TRUE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
382 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
384 ok ( GetLastError() == ERROR_FILE_EXISTS,
385 "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
387 /* Prove that the existence of the local file is checked first (or at least reported last) */
388 SetLastError(0xdeadbeef);
389 bRet = FtpGetFileA(hFtp, "should_be_non_existing_deadbeef", "should_be_non_existing_deadbeef", TRUE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
390 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
392 ok ( GetLastError() == ERROR_FILE_EXISTS,
393 "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
395 DeleteFileA("should_be_non_existing_deadbeef");
398 InternetCloseHandle(hFtp);
400 /* Http handle-type for ftp connection */
402 hConnect = InternetConnect(hInternet, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
404 /* Test to show the parameter checking order depends on the Windows version */
405 SetLastError(0xdeadbeef);
406 bRet = FtpGetFileA(hConnect, NULL, "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
407 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
408 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE ||
409 GetLastError() == ERROR_INVALID_PARAMETER,
410 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE (win98) or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
412 /* Test to show that 'session handle type' is checked before 'condition flags' */
413 SetLastError(0xdeadbeef);
414 bRet = FtpGetFileA(hConnect, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, 5, 0);
415 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
416 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
417 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
419 SetLastError(0xdeadbeef);
420 bRet = FtpGetFileA(hConnect, "should_be_non_existing_deadbeef", "should_be_non_existing_deadbeef", TRUE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
421 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
422 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
423 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
425 InternetCloseHandle(hConnect);
426 InternetCloseHandle(hInternet);
429 static void test_openfile(void)
431 HINTERNET hOpenFile, hInternet, hFtp, hConnect;
433 /* Invalid internet handle, the rest are valid parameters */
434 SetLastError(0xdeadbeef);
435 hOpenFile = FtpOpenFileA(NULL, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
436 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
437 ok ( GetLastError() == ERROR_INVALID_HANDLE,
438 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
439 InternetCloseHandle(hOpenFile); /* Just in case */
441 hInternet = InternetOpen(NULL, 0, NULL, NULL, 0);
442 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0);
445 skip("No ftp connection could be made to ftp.winehq.org\n");
446 InternetCloseHandle(hInternet);
450 /* We should have a ftp-connection (valid ftp session handle), try some opening */
453 SetLastError(0xdeadbeef);
454 hOpenFile = FtpOpenFileA(hFtp, NULL, GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
455 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
456 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
457 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
458 InternetCloseHandle(hOpenFile); /* Just in case */
460 /* Illegal access flags */
461 SetLastError(0xdeadbeef);
462 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", 0, FTP_TRANSFER_TYPE_ASCII, 0);
463 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
464 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
465 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
466 InternetCloseHandle(hOpenFile); /* Just in case */
468 /* Illegal combination of access flags */
469 SetLastError(0xdeadbeef);
470 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ|GENERIC_WRITE, FTP_TRANSFER_TYPE_ASCII, 0);
471 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
472 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
473 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
474 InternetCloseHandle(hOpenFile); /* Just in case */
476 /* Illegal condition flags */
477 SetLastError(0xdeadbeef);
478 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, 5, 0);
479 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
480 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
481 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
482 InternetCloseHandle(hOpenFile); /* Just in case */
485 SetLastError(0xdeadbeef);
486 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
487 ok ( hOpenFile != NULL, "Expected FtpOpenFileA to succeed\n");
488 /* For some strange/unknown reason, win98 returns ERROR_FILE_NOT_FOUND */
489 ok ( GetLastError() == ERROR_SUCCESS || GetLastError() == ERROR_FILE_NOT_FOUND,
490 "Expected ERROR_SUCCESS or ERROR_FILE_NOT_FOUND (win98), got %d\n", GetLastError());
495 HINTERNET hOpenFile2;
498 /* We have a handle so all ftp calls should fail (TODO: Put all ftp-calls in here) */
499 SetLastError(0xdeadbeef);
500 bRet = FtpCreateDirectoryA(hFtp, "new_directory_deadbeef");
501 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
503 ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS,
504 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError());
506 SetLastError(0xdeadbeef);
507 bRet = FtpDeleteFileA(hFtp, "non_existent_file_deadbeef");
508 ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
510 ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS,
511 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError());
513 SetLastError(0xdeadbeef);
514 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
515 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
516 ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS,
517 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError());
518 DeleteFileA("should_be_non_existing_deadbeef"); /* Just in case */
520 SetLastError(0xdeadbeef);
521 hOpenFile2 = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
522 ok ( bRet == FALSE, "Expected FtpOpenFileA to fail\n");
523 ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS,
524 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError());
525 InternetCloseHandle(hOpenFile2); /* Just in case */
527 /* Create a temporary local file */
528 SetLastError(0xdeadbeef);
529 hFile = CreateFileA("now_existing_local", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
530 ok ( hFile != NULL, "Error creating a local file : %d\n", GetLastError());
532 SetLastError(0xdeadbeef);
533 bRet = FtpPutFileA(hFtp, "now_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
534 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
536 ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS,
537 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError());
538 DeleteFileA("now_existing_local");
540 SetLastError(0xdeadbeef);
541 bRet = FtpRemoveDirectoryA(hFtp, "should_be_non_existing_deadbeef_dir");
542 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
544 ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS,
545 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError());
547 SetLastError(0xdeadbeef);
548 bRet = FtpRenameFileA(hFtp , "should_be_non_existing_deadbeef", "new");
549 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
551 ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS,
552 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError());
555 InternetCloseHandle(hOpenFile);
556 InternetCloseHandle(hFtp);
558 /* Http handle-type for ftp connection */
560 hConnect = InternetConnect(hInternet, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
562 /* One small test to show that handle type is checked before parameters */
563 SetLastError(0xdeadbeef);
564 hOpenFile = FtpOpenFileA(hConnect, "welcome.msg", GENERIC_READ, 5, 0);
565 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
566 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
567 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
568 InternetCloseHandle(hOpenFile); /* Just in case */
570 SetLastError(0xdeadbeef);
571 hOpenFile = FtpOpenFileA(hConnect, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
572 ok ( hOpenFile == NULL, "Expected FtpOpenFileA to fail\n");
573 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
574 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
576 InternetCloseHandle(hOpenFile); /* Just in case */
577 InternetCloseHandle(hConnect);
578 InternetCloseHandle(hInternet);
581 static void test_putfile(void)
584 HINTERNET hInternet, hFtp, hConnect;
587 /* The order of checking is:
589 * All parameters except 'session handle' and 'condition flags'
591 * Session handle type
595 /* Test to show the parameter checking order depends on the Windows version */
596 SetLastError(0xdeadbeef);
597 bRet = FtpPutFileA(NULL, NULL, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
598 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
599 ok ( GetLastError() == ERROR_INVALID_HANDLE ||
600 GetLastError() == ERROR_INVALID_PARAMETER,
601 "Expected ERROR_INVALID_HANDLE (win98) or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
603 /* Test to show session handle is checked before 'condition flags' */
604 SetLastError(0xdeadbeef);
605 bRet = FtpPutFileA(NULL, "non_existing_local", "non_existing_remote", 5, 0);
606 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
607 ok ( GetLastError() == ERROR_INVALID_HANDLE,
608 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
610 hInternet = InternetOpen(NULL, 0, NULL, NULL, 0);
611 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0);
614 skip("No ftp connection could be made to ftp.winehq.org\n");
615 InternetCloseHandle(hInternet);
620 DeleteFileA("non_existing_local");
622 /* We should have a ftp-connection, try some puts */
624 /* No local file given */
625 SetLastError(0xdeadbeef);
626 bRet = FtpPutFileA(hFtp, NULL, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
627 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
628 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
629 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
631 /* No remote file given */
632 SetLastError(0xdeadbeef);
633 bRet = FtpPutFileA(hFtp, "non_existing_local", NULL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
634 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
635 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
636 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
638 /* Illegal condition flags */
639 SetLastError(0xdeadbeef);
640 bRet = FtpPutFileA(hFtp, "non_existing_local", "non_existing_remote", 5, 0);
641 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
642 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
643 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
645 /* Parameters are OK but local file doesn't exist */
646 SetLastError(0xdeadbeef);
647 bRet = FtpPutFileA(hFtp, "non_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
648 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
649 ok ( GetLastError() == ERROR_FILE_NOT_FOUND,
650 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
652 /* Create a temporary local file */
653 SetLastError(0xdeadbeef);
654 hFile = CreateFileA("now_existing_local", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
655 ok ( hFile != NULL, "Error creating a local file : %d\n", GetLastError());
658 /* Local file exists but we shouldn't be allowed to 'put' the file */
659 SetLastError(0xdeadbeef);
660 bRet = FtpPutFileA(hFtp, "now_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
661 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
663 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
664 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
666 DeleteFileA("now_existing_local");
668 InternetCloseHandle(hFtp);
670 /* Http handle-type for ftp connection */
672 hConnect = InternetConnect(hInternet, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
674 /* Test to show the parameter checking order depends on the Windows version */
675 SetLastError(0xdeadbeef);
676 bRet = FtpPutFileA(hConnect, NULL, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
677 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
678 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE ||
679 GetLastError() == ERROR_INVALID_PARAMETER,
680 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE (win98) or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
682 /* Test to show that 'session handle type' is checked before 'condition flags' */
683 SetLastError(0xdeadbeef);
684 bRet = FtpPutFileA(hConnect, "non_existing_local", "non_existing_remote", 5, 0);
685 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
686 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
687 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
689 SetLastError(0xdeadbeef);
690 bRet = FtpPutFileA(hConnect, "non_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
691 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
692 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
693 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
695 InternetCloseHandle(hConnect);
696 InternetCloseHandle(hInternet);
699 static void test_removedir(void)
702 HINTERNET hInternet, hFtp, hConnect;
704 /* Invalid internet handle, the other is a valid parameter */
705 SetLastError(0xdeadbeef);
706 bRet = FtpRemoveDirectoryA(NULL, "should_be_non_existing_deadbeef_dir");
707 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
708 ok ( GetLastError() == ERROR_INVALID_HANDLE,
709 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
711 hInternet = InternetOpen(NULL, 0, NULL, NULL, 0);
712 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0);
715 skip("No ftp connection could be made to ftp.winehq.org\n");
716 InternetCloseHandle(hInternet);
720 /* We should have a ftp-connection, try some removing */
722 /* No remote directory given */
723 SetLastError(0xdeadbeef);
724 bRet = FtpRemoveDirectoryA(hFtp, NULL);
725 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
726 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
727 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
729 /* Remote directory doesn't exist */
730 SetLastError(0xdeadbeef);
731 bRet = FtpRemoveDirectoryA(hFtp, "should_be_non_existing_deadbeef_dir");
732 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
734 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
735 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
737 /* We shouldn't be allowed to remove that directory */
738 SetLastError(0xdeadbeef);
739 bRet = FtpRemoveDirectoryA(hFtp, "pub");
740 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
742 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
743 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
745 InternetCloseHandle(hFtp);
747 /* Http handle-type for ftp connection */
749 hConnect = InternetConnect(hInternet, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
751 /* One small test to show that handle type is checked before parameters */
752 SetLastError(0xdeadbeef);
753 bRet = FtpRemoveDirectoryA(hConnect, NULL);
754 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
755 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
756 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
758 SetLastError(0xdeadbeef);
759 bRet = FtpRemoveDirectoryA(hConnect, "should_be_non_existing_deadbeef_dir");
760 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
761 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
762 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
764 InternetCloseHandle(hConnect);
765 InternetCloseHandle(hInternet);
768 static void test_renamefile(void)
771 HINTERNET hInternet, hFtp, hConnect;
773 /* Invalid internet handle, the rest are valid parameters */
774 SetLastError(0xdeadbeef);
775 bRet = FtpRenameFileA(NULL , "should_be_non_existing_deadbeef", "new");
776 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
777 ok ( GetLastError() == ERROR_INVALID_HANDLE,
778 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
780 hInternet = InternetOpen(NULL, 0, NULL, NULL, 0);
781 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0);
784 skip("No ftp connection could be made to ftp.winehq.org\n");
785 InternetCloseHandle(hInternet);
789 /* We should have a ftp-connection, try some renaming */
791 /* No 'existing' file */
792 SetLastError(0xdeadbeef);
793 bRet = FtpRenameFileA(hFtp , NULL, "new");
794 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
795 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
796 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
799 SetLastError(0xdeadbeef);
800 bRet = FtpRenameFileA(hFtp , "should_be_non_existing_deadbeef", NULL);
801 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
802 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
803 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
805 /* Existing file shouldn't be there */
806 SetLastError(0xdeadbeef);
807 bRet = FtpRenameFileA(hFtp , "should_be_non_existing_deadbeef", "new");
808 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
810 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
811 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
813 InternetCloseHandle(hFtp);
815 /* Http handle-type for ftp connection */
817 hConnect = InternetConnect(hInternet, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
819 /* One small test to show that handle type is checked before parameters */
820 SetLastError(0xdeadbeef);
821 bRet = FtpRenameFileA(hConnect , "should_be_non_existing_deadbeef", NULL);
822 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
823 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
824 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
826 SetLastError(0xdeadbeef);
827 bRet = FtpRenameFileA(hConnect , "should_be_non_existing_deadbeef", "new");
828 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
829 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
830 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
832 InternetCloseHandle(hConnect);
833 InternetCloseHandle(hInternet);
838 /* The first call should always be a proper InternetOpen, if not
839 * several calls will return ERROR_INTERNET_NOT_INITIALIZED when
840 * all parameters are correct but no session handle is given. Whereas
841 * the same call will return ERROR_INVALID_HANDLE if an InternetOpen
843 * The following test will show that behaviour, where the tests inside
844 * the other sub-tests will show the other situation.
846 test_getfile_no_open();