4 * Copyright 2007 Paul Vriens
5 * Copyright 2007 Hans Leidekker
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * Use InternetGetLastResponseInfo when the last error is set to ERROR_INTERNET_EXTENDED_ERROR.
26 * Add W-function tests.
27 * 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(HINTERNET hInternet)
62 /* Try a few username/password combinations:
68 SetLastError(0xdeadbeef);
69 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", NULL, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
70 if (hFtp) /* some servers accept an empty password */
72 ok ( GetLastError() == ERROR_SUCCESS, "ERROR_SUCCESS, got %d\n", GetLastError());
73 InternetCloseHandle(hFtp);
76 ok ( GetLastError() == ERROR_INTERNET_LOGIN_FAILURE,
77 "Expected ERROR_INTERNET_LOGIN_FAILURE, got %d\n", GetLastError());
79 SetLastError(0xdeadbeef);
80 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, NULL, "IEUser@", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
81 ok ( hFtp == NULL, "Expected InternetConnect to fail\n");
82 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
83 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
85 /* Using a NULL username and password will be interpreted as anonymous ftp. The username will be 'anonymous' the password
86 * is created via some simple heuristics (see dlls/wininet/ftp.c).
87 * On Wine this registry key is not set by default so (NULL, NULL) will result in anonymous ftp with an (most likely) not
88 * accepted password (the username).
89 * If the first call fails because we get an ERROR_INTERNET_LOGIN_FAILURE, we try again with a (more) correct password.
92 SetLastError(0xdeadbeef);
93 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, NULL, NULL, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
94 if (!hFtp && (GetLastError() == ERROR_INTERNET_LOGIN_FAILURE))
96 /* We are most likely running on a clean Wine install or a Windows install where the registry key is removed */
97 SetLastError(0xdeadbeef);
98 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
100 ok ( hFtp != NULL, "InternetConnect failed : %d\n", GetLastError());
101 ok ( GetLastError() == ERROR_SUCCESS,
102 "ERROR_SUCCESS, got %d\n", GetLastError());
105 static void test_createdir(HINTERNET hFtp, HINTERNET hConnect)
109 /* Invalid internet handle, the other is a valid parameter */
110 SetLastError(0xdeadbeef);
111 bRet = FtpCreateDirectoryA(NULL, "new_directory_deadbeef");
112 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
113 ok ( GetLastError() == ERROR_INVALID_HANDLE,
114 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
116 /* No directory-name */
117 SetLastError(0xdeadbeef);
118 bRet = FtpCreateDirectoryA(hFtp, NULL);
119 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
120 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
121 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
123 /* Parameters are OK, but we shouldn't be allowed to create the directory */
124 SetLastError(0xdeadbeef);
125 bRet = FtpCreateDirectoryA(hFtp, "new_directory_deadbeef");
126 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
127 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
128 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
130 /* One small test to show that handle type is checked before parameters */
131 SetLastError(0xdeadbeef);
132 bRet = FtpCreateDirectoryA(hConnect, NULL);
133 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
134 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
135 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
137 SetLastError(0xdeadbeef);
138 bRet = FtpCreateDirectoryA(hConnect, "new_directory_deadbeef");
139 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
140 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
141 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
144 static void test_deletefile(HINTERNET hFtp, HINTERNET hConnect)
148 /* Invalid internet handle, the other is a valid parameter */
149 SetLastError(0xdeadbeef);
150 bRet = FtpDeleteFileA(NULL, "non_existent_file_deadbeef");
151 ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
152 ok ( GetLastError() == ERROR_INVALID_HANDLE,
153 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
156 SetLastError(0xdeadbeef);
157 bRet = FtpDeleteFileA(hFtp, NULL);
158 ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
159 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
160 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
162 /* Parameters are OK but remote file should not be there */
163 SetLastError(0xdeadbeef);
164 bRet = FtpDeleteFileA(hFtp, "non_existent_file_deadbeef");
165 ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
166 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
167 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
169 /* One small test to show that handle type is checked before parameters */
170 SetLastError(0xdeadbeef);
171 bRet = FtpDeleteFileA(hConnect, NULL);
172 ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
173 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
174 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
176 SetLastError(0xdeadbeef);
177 bRet = FtpDeleteFileA(hConnect, "non_existent_file_deadbeef");
178 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
179 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
180 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
183 static void test_getfile(HINTERNET hFtp, HINTERNET hConnect)
188 /* The order of checking is:
190 * All parameters except 'session handle' and 'condition flags'
192 * Session handle type
196 /* Test to show the parameter checking order depends on the Windows version */
197 SetLastError(0xdeadbeef);
198 bRet = FtpGetFileA(NULL, NULL, "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
199 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
200 ok ( GetLastError() == ERROR_INVALID_HANDLE ||
201 GetLastError() == ERROR_INVALID_PARAMETER,
202 "Expected ERROR_INVALID_HANDLE (win98) or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
204 /* Test to show session handle is checked before 'condition flags' */
205 SetLastError(0xdeadbeef);
206 bRet = FtpGetFileA(NULL, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, 5, 0);
207 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
208 ok ( GetLastError() == ERROR_INVALID_HANDLE,
209 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
211 /* Make sure we start clean */
213 DeleteFileA("should_be_non_existing_deadbeef");
214 DeleteFileA("should_also_be_non_existing_deadbeef");
217 SetLastError(0xdeadbeef);
218 bRet = FtpGetFileA(hFtp, NULL, "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
219 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
220 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
221 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
222 ok (GetFileAttributesA("should_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
223 "Local file should not have been created\n");
224 DeleteFileA("should_be_non_existing_deadbeef");
227 SetLastError(0xdeadbeef);
228 bRet = FtpGetFileA(hFtp, "welcome.msg", NULL, FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
229 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
230 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
231 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
233 /* Zero attributes */
234 SetLastError(0xdeadbeef);
235 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_existing_non_deadbeef", FALSE, 0, FTP_TRANSFER_TYPE_UNKNOWN, 0);
236 ok ( bRet == TRUE, "Expected FtpGetFileA to succeed\n");
237 ok (GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
238 ok (GetFileAttributesA("should_be_existing_non_deadbeef") != INVALID_FILE_ATTRIBUTES,
239 "Local file should have been created\n");
240 DeleteFileA("should_be_existing_non_deadbeef");
242 /* Illegal condition flags */
243 SetLastError(0xdeadbeef);
244 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, 0xffffffff, 0);
245 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
246 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR || GetLastError() == ERROR_INVALID_PARAMETER,
247 "Expected ERROR_INTERNET_EXTENDED_ERROR or ERROR_INVALID_PARAMETER (win98), got %d\n", GetLastError());
248 ok (GetFileAttributesA("should_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
249 "Local file should not have been created\n");
250 DeleteFileA("should_be_non_existing_deadbeef");
252 /* Remote file doesn't exist (and local doesn't exist as well) */
253 SetLastError(0xdeadbeef);
254 bRet = FtpGetFileA(hFtp, "should_be_non_existing_deadbeef", "should_also_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
255 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
256 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
257 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
258 /* Currently Wine always creates the local file (even on failure) which is not correct, hence the test */
260 ok (GetFileAttributesA("should_also_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
261 "Local file should not have been created\n");
263 DeleteFileA("should_also_be_non_existing_deadbeef");
265 /* Same call as the previous but now the local file does exists. Windows just removes the file if the call fails
266 * even if the local existed before!
269 /* Create a temporary local file */
270 SetLastError(0xdeadbeef);
271 hFile = CreateFileA("should_also_be_non_existing_deadbeef", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
272 ok ( hFile != NULL, "Error creating a local file : %d\n", GetLastError());
274 SetLastError(0xdeadbeef);
275 bRet = FtpGetFileA(hFtp, "should_be_non_existing_deadbeef", "should_also_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
276 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
277 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
278 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
279 /* Currently Wine always creates the local file (even on failure) which is not correct, hence the test */
281 ok (GetFileAttributesA("should_also_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
282 "Local file should not have been created\n");
284 DeleteFileA("should_also_be_non_existing_deadbeef");
286 /* This one should succeed */
287 SetLastError(0xdeadbeef);
288 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_existing_non_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
289 ok ( bRet == TRUE, "Expected FtpGetFileA to fail\n");
290 ok ( GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
292 if (GetFileAttributesA("should_be_existing_non_deadbeef") != INVALID_FILE_ATTRIBUTES)
294 /* Should succeed as fFailIfExists is set to FALSE (meaning don't fail if local file exists) */
295 SetLastError(0xdeadbeef);
296 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
297 ok ( bRet == TRUE, "Expected FtpGetFileA to succeed\n");
298 ok ( GetLastError() == ERROR_SUCCESS,
299 "Expected ERROR_SUCCESS, got %d\n", GetLastError());
301 /* Should fail as fFailIfExists is set to TRUE */
302 SetLastError(0xdeadbeef);
303 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", TRUE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
304 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
305 ok ( GetLastError() == ERROR_FILE_EXISTS,
306 "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
308 /* Prove that the existence of the local file is checked first (or at least reported last) */
309 SetLastError(0xdeadbeef);
310 bRet = FtpGetFileA(hFtp, "should_be_non_existing_deadbeef", "should_be_non_existing_deadbeef", TRUE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
311 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
312 ok ( GetLastError() == ERROR_FILE_EXISTS,
313 "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
315 DeleteFileA("should_be_existing_non_deadbeef");
318 /* Test to show the parameter checking order depends on the Windows version */
319 SetLastError(0xdeadbeef);
320 bRet = FtpGetFileA(hConnect, NULL, "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
321 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
322 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE ||
323 GetLastError() == ERROR_INVALID_PARAMETER,
324 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE (win98) or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
326 /* Test to show that 'session handle type' is checked before 'condition flags' */
327 SetLastError(0xdeadbeef);
328 bRet = FtpGetFileA(hConnect, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, 5, 0);
329 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
330 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
331 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
333 SetLastError(0xdeadbeef);
334 bRet = FtpGetFileA(hConnect, "should_be_non_existing_deadbeef", "should_be_non_existing_deadbeef", TRUE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
335 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
336 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
337 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
340 static void test_openfile(HINTERNET hFtp, HINTERNET hConnect)
344 /* Invalid internet handle, the rest are valid parameters */
345 SetLastError(0xdeadbeef);
346 hOpenFile = FtpOpenFileA(NULL, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
347 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
348 ok ( GetLastError() == ERROR_INVALID_HANDLE,
349 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
350 InternetCloseHandle(hOpenFile); /* Just in case */
353 SetLastError(0xdeadbeef);
354 hOpenFile = FtpOpenFileA(hFtp, NULL, GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
355 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
356 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
357 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
358 InternetCloseHandle(hOpenFile); /* Just in case */
360 /* Illegal access flags */
361 SetLastError(0xdeadbeef);
362 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", 0, FTP_TRANSFER_TYPE_ASCII, 0);
363 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
364 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
365 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
366 InternetCloseHandle(hOpenFile); /* Just in case */
368 /* Illegal combination of access flags */
369 SetLastError(0xdeadbeef);
370 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ|GENERIC_WRITE, FTP_TRANSFER_TYPE_ASCII, 0);
371 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
372 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
373 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
374 InternetCloseHandle(hOpenFile); /* Just in case */
376 /* Illegal condition flags */
377 SetLastError(0xdeadbeef);
378 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, 0xffffffff, 0);
379 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
380 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR || GetLastError() == ERROR_INVALID_PARAMETER,
381 "Expected ERROR_INTERNET_EXTENDED_ERROR or ERROR_INVALID_PARAMETER (win98), got %d\n", GetLastError());
382 InternetCloseHandle(hOpenFile); /* Just in case */
384 SetLastError(0xdeadbeef);
385 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
386 ok ( hOpenFile != NULL, "Expected FtpOpenFileA to succeed\n");
387 ok ( GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", GetLastError());
392 HINTERNET hOpenFile2;
395 /* We have a handle so all ftp calls should fail (TODO: Put all ftp-calls in here) */
396 SetLastError(0xdeadbeef);
397 bRet = FtpCreateDirectoryA(hFtp, "new_directory_deadbeef");
398 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
399 ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS,
400 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError());
402 SetLastError(0xdeadbeef);
403 bRet = FtpDeleteFileA(hFtp, "non_existent_file_deadbeef");
404 ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
405 ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS,
406 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError());
408 SetLastError(0xdeadbeef);
409 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
410 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
411 ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS,
412 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError());
413 DeleteFileA("should_be_non_existing_deadbeef"); /* Just in case */
415 SetLastError(0xdeadbeef);
416 hOpenFile2 = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
417 ok ( bRet == FALSE, "Expected FtpOpenFileA to fail\n");
418 ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS,
419 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError());
420 InternetCloseHandle(hOpenFile2); /* Just in case */
422 /* Create a temporary local file */
423 SetLastError(0xdeadbeef);
424 hFile = CreateFileA("now_existing_local", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
425 ok ( hFile != NULL, "Error creating a local file : %d\n", GetLastError());
427 SetLastError(0xdeadbeef);
428 bRet = FtpPutFileA(hFtp, "now_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
429 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
430 ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS,
431 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError());
432 DeleteFileA("now_existing_local");
434 SetLastError(0xdeadbeef);
435 bRet = FtpRemoveDirectoryA(hFtp, "should_be_non_existing_deadbeef_dir");
436 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
437 ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS,
438 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError());
440 SetLastError(0xdeadbeef);
441 bRet = FtpRenameFileA(hFtp , "should_be_non_existing_deadbeef", "new");
442 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
443 ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS,
444 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError());
447 InternetCloseHandle(hOpenFile);
449 /* One small test to show that handle type is checked before parameters */
450 SetLastError(0xdeadbeef);
451 hOpenFile = FtpOpenFileA(hConnect, "welcome.msg", GENERIC_READ, 5, 0);
452 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
453 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
454 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
455 InternetCloseHandle(hOpenFile); /* Just in case */
457 SetLastError(0xdeadbeef);
458 hOpenFile = FtpOpenFileA(hConnect, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
459 ok ( hOpenFile == NULL, "Expected FtpOpenFileA to fail\n");
460 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
461 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
463 InternetCloseHandle(hOpenFile); /* Just in case */
466 static void test_putfile(HINTERNET hFtp, HINTERNET hConnect)
471 /* The order of checking is:
473 * All parameters except 'session handle' and 'condition flags'
475 * Session handle type
479 /* Test to show the parameter checking order depends on the Windows version */
480 SetLastError(0xdeadbeef);
481 bRet = FtpPutFileA(NULL, NULL, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
482 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
483 ok ( GetLastError() == ERROR_INVALID_HANDLE ||
484 GetLastError() == ERROR_INVALID_PARAMETER,
485 "Expected ERROR_INVALID_HANDLE (win98) or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
487 /* Test to show session handle is checked before 'condition flags' */
488 SetLastError(0xdeadbeef);
489 bRet = FtpPutFileA(NULL, "non_existing_local", "non_existing_remote", 5, 0);
490 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
491 ok ( GetLastError() == ERROR_INVALID_HANDLE,
492 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
495 DeleteFileA("non_existing_local");
497 /* No local file given */
498 SetLastError(0xdeadbeef);
499 bRet = FtpPutFileA(hFtp, NULL, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
500 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
501 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
502 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
504 /* No remote file given */
505 SetLastError(0xdeadbeef);
506 bRet = FtpPutFileA(hFtp, "non_existing_local", NULL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
507 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
508 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
509 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
511 /* Illegal condition flags */
512 SetLastError(0xdeadbeef);
513 bRet = FtpPutFileA(hFtp, "non_existing_local", "non_existing_remote", 5, 0);
514 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
515 ok ( GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_INVALID_PARAMETER,
516 "Expected ERROR_FILE_NOT_FOUND or ERROR_INVALID_PARAMETER (win98), got %d\n", GetLastError());
518 /* Parameters are OK but local file doesn't exist */
519 SetLastError(0xdeadbeef);
520 bRet = FtpPutFileA(hFtp, "non_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
521 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
522 ok ( GetLastError() == ERROR_FILE_NOT_FOUND,
523 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
525 /* Create a temporary local file */
526 SetLastError(0xdeadbeef);
527 hFile = CreateFileA("now_existing_local", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
528 ok ( hFile != NULL, "Error creating a local file : %d\n", GetLastError());
531 /* Local file exists but we shouldn't be allowed to 'put' the file */
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");
535 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
536 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
538 DeleteFileA("now_existing_local");
540 /* Test to show the parameter checking order depends on the Windows version */
541 SetLastError(0xdeadbeef);
542 bRet = FtpPutFileA(hConnect, NULL, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
543 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
544 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE ||
545 GetLastError() == ERROR_INVALID_PARAMETER,
546 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE (win98) or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
548 /* Test to show that 'session handle type' is checked before 'condition flags' */
549 SetLastError(0xdeadbeef);
550 bRet = FtpPutFileA(hConnect, "non_existing_local", "non_existing_remote", 5, 0);
551 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
552 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
553 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
555 SetLastError(0xdeadbeef);
556 bRet = FtpPutFileA(hConnect, "non_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
557 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
558 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
559 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
562 static void test_removedir(HINTERNET hFtp, HINTERNET hConnect)
566 /* Invalid internet handle, the other is a valid parameter */
567 SetLastError(0xdeadbeef);
568 bRet = FtpRemoveDirectoryA(NULL, "should_be_non_existing_deadbeef_dir");
569 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
570 ok ( GetLastError() == ERROR_INVALID_HANDLE,
571 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
573 /* No remote directory given */
574 SetLastError(0xdeadbeef);
575 bRet = FtpRemoveDirectoryA(hFtp, NULL);
576 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
577 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
578 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
580 /* Remote directory doesn't exist */
581 SetLastError(0xdeadbeef);
582 bRet = FtpRemoveDirectoryA(hFtp, "should_be_non_existing_deadbeef_dir");
583 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
584 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
585 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
587 /* We shouldn't be allowed to remove that directory */
588 SetLastError(0xdeadbeef);
589 bRet = FtpRemoveDirectoryA(hFtp, "pub");
590 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
591 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
592 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
594 /* One small test to show that handle type is checked before parameters */
595 SetLastError(0xdeadbeef);
596 bRet = FtpRemoveDirectoryA(hConnect, NULL);
597 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
598 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
599 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
601 SetLastError(0xdeadbeef);
602 bRet = FtpRemoveDirectoryA(hConnect, "should_be_non_existing_deadbeef_dir");
603 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
604 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
605 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
608 static void test_renamefile(HINTERNET hFtp, HINTERNET hConnect)
612 /* Invalid internet handle, the rest are valid parameters */
613 SetLastError(0xdeadbeef);
614 bRet = FtpRenameFileA(NULL , "should_be_non_existing_deadbeef", "new");
615 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
616 ok ( GetLastError() == ERROR_INVALID_HANDLE,
617 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
619 /* No 'existing' file */
620 SetLastError(0xdeadbeef);
621 bRet = FtpRenameFileA(hFtp , NULL, "new");
622 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
623 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
624 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
627 SetLastError(0xdeadbeef);
628 bRet = FtpRenameFileA(hFtp , "should_be_non_existing_deadbeef", NULL);
629 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
630 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
631 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
633 /* Existing file shouldn't be there */
634 SetLastError(0xdeadbeef);
635 bRet = FtpRenameFileA(hFtp , "should_be_non_existing_deadbeef", "new");
636 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
637 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
638 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
640 /* One small test to show that handle type is checked before parameters */
641 SetLastError(0xdeadbeef);
642 bRet = FtpRenameFileA(hConnect , "should_be_non_existing_deadbeef", NULL);
643 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
644 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
645 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
647 SetLastError(0xdeadbeef);
648 bRet = FtpRenameFileA(hConnect , "should_be_non_existing_deadbeef", "new");
649 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
650 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
651 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
654 static void test_command(HINTERNET hFtp, HINTERNET hConnect)
667 { FALSE, ERROR_INVALID_PARAMETER, NULL },
668 { FALSE, ERROR_INVALID_PARAMETER, "" },
669 { FALSE, ERROR_INTERNET_EXTENDED_ERROR, "HELO" },
670 { FALSE, ERROR_INTERNET_EXTENDED_ERROR, "SIZE " },
671 { FALSE, ERROR_INTERNET_EXTENDED_ERROR, " SIZE" },
672 { FALSE, ERROR_INTERNET_EXTENDED_ERROR, "SIZE " },
673 { FALSE, ERROR_INTERNET_EXTENDED_ERROR, "SIZE /welcome.msg /welcome.msg" },
674 { FALSE, ERROR_INTERNET_EXTENDED_ERROR, "SIZE /welcome.msg" },
675 { FALSE, ERROR_INTERNET_EXTENDED_ERROR, "SIZE /welcome.msg " },
676 { TRUE, ERROR_SUCCESS, "SIZE\t/welcome.msg" },
677 { TRUE, ERROR_SUCCESS, "SIZE /welcome.msg" },
678 { FALSE, ERROR_INTERNET_EXTENDED_ERROR, "PWD /welcome.msg" },
679 { TRUE, ERROR_SUCCESS, "PWD" },
680 { TRUE, ERROR_SUCCESS, "PWD\r\n" }
683 for (i = 0; i < sizeof(command_test) / sizeof(command_test[0]); i++)
685 SetLastError(0xdeadbeef);
686 ret = FtpCommandA(hFtp, FALSE, FTP_TRANSFER_TYPE_ASCII, command_test[i].cmd, 0, NULL);
687 error = GetLastError();
689 ok(ret == command_test[i].ret, "%d: expected FtpCommandA to %s\n", i, command_test[i].ret ? "succeed" : "fail");
690 ok(error == command_test[i].error, "%d: expected error %u, got %u\n", i, command_test[i].error, error);
696 HANDLE hInternet, hFtp, hHttp;
698 SetLastError(0xdeadbeef);
699 hInternet = InternetOpen("winetest", 0, NULL, NULL, 0);
700 ok(hInternet != NULL, "InternetOpen failed: %u\n", GetLastError());
702 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", NULL, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
705 InternetCloseHandle(hInternet);
706 skip("No ftp connection could be made to ftp.winehq.org\n");
709 hHttp = InternetConnect(hInternet, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
712 InternetCloseHandle(hFtp);
713 InternetCloseHandle(hInternet);
714 skip("No http connection could be made to www.winehq.org\n");
718 /* The first call should always be a proper InternetOpen, if not
719 * several calls will return ERROR_INTERNET_NOT_INITIALIZED when
720 * all parameters are correct but no session handle is given. Whereas
721 * the same call will return ERROR_INVALID_HANDLE if an InternetOpen
723 * The following test will show that behaviour, where the tests inside
724 * the other sub-tests will show the other situation.
726 test_getfile_no_open();
727 test_connect(hInternet);
728 test_createdir(hFtp, hHttp);
729 test_deletefile(hFtp, hHttp);
730 test_getfile(hFtp, hHttp);
731 test_openfile(hFtp, hHttp);
732 test_putfile(hFtp, hHttp);
733 test_removedir(hFtp, hHttp);
734 test_renamefile(hFtp, hHttp);
735 test_command(hFtp, hHttp);
737 InternetCloseHandle(hHttp);
738 InternetCloseHandle(hFtp);
739 InternetCloseHandle(hInternet);