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 * FtpSetCurrentDirectory
41 #include "wine/test.h"
44 static BOOL (WINAPI *pFtpCommandA)(HINTERNET,BOOL,DWORD,LPCSTR,DWORD_PTR,HINTERNET*);
45 static INTERNET_STATUS_CALLBACK (WINAPI *pInternetSetStatusCallbackA)(HINTERNET,INTERNET_STATUS_CALLBACK);
48 static void test_getfile_no_open(void)
52 /* Invalid internet handle, the others are valid parameters */
53 SetLastError(0xdeadbeef);
54 bRet = FtpGetFileA(NULL, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
55 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
56 ok ( GetLastError() == ERROR_INTERNET_NOT_INITIALIZED ||
57 GetLastError() == ERROR_INVALID_HANDLE,
58 "Expected ERROR_INTERNET_NOT_INITIALIZED or ERROR_INVALID_HANDLE (win98), got %d\n", GetLastError());
61 static void test_connect(HINTERNET hInternet)
65 /* Try a few username/password combinations:
73 SetLastError(0xdeadbeef);
74 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", NULL, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
75 if (hFtp) /* some servers accept an empty password */
77 ok ( GetLastError() == ERROR_SUCCESS, "ERROR_SUCCESS, got %d\n", GetLastError());
78 InternetCloseHandle(hFtp);
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, INTERNET_FLAG_PASSIVE, 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 SetLastError(0xdeadbeef);
91 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "", "IEUser@",
92 INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
93 ok(!hFtp, "Expected InternetConnect to fail\n");
94 ok(GetLastError() == ERROR_INVALID_PARAMETER,
95 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
97 /* Using a NULL username and password will be interpreted as anonymous ftp. The username will be 'anonymous' the password
98 * is created via some simple heuristics (see dlls/wininet/ftp.c).
99 * On Wine this registry key is not set by default so (NULL, NULL) will result in anonymous ftp with an (most likely) not
100 * accepted password (the username).
101 * If the first call fails because we get an ERROR_INTERNET_LOGIN_FAILURE, we try again with a (more) correct password.
104 SetLastError(0xdeadbeef);
105 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, NULL, NULL, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
106 if (!hFtp && (GetLastError() == ERROR_INTERNET_LOGIN_FAILURE))
108 /* We are most likely running on a clean Wine install or a Windows install where the registry key is removed */
109 SetLastError(0xdeadbeef);
110 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
112 ok ( hFtp != NULL, "InternetConnect failed : %d\n", GetLastError());
113 ok ( GetLastError() == ERROR_SUCCESS,
114 "ERROR_SUCCESS, got %d\n", GetLastError());
116 SetLastError(0xdeadbeef);
117 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "", NULL,
118 INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
121 ok(GetLastError() == ERROR_INTERNET_LOGIN_FAILURE,
122 "Expected ERROR_INTERNET_LOGIN_FAILURE, got %d\n", GetLastError());
126 ok(GetLastError() == ERROR_SUCCESS,
127 "Expected ERROR_SUCCESS, got %d\n", GetLastError());
131 static void test_createdir(HINTERNET hFtp, HINTERNET hConnect)
135 /* Invalid internet handle, the other is a valid parameter */
136 SetLastError(0xdeadbeef);
137 bRet = FtpCreateDirectoryA(NULL, "new_directory_deadbeef");
138 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
139 ok ( GetLastError() == ERROR_INVALID_HANDLE,
140 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
142 /* No directory-name */
143 SetLastError(0xdeadbeef);
144 bRet = FtpCreateDirectoryA(hFtp, NULL);
145 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
146 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
147 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
149 /* Parameters are OK, but we shouldn't be allowed to create the directory */
150 SetLastError(0xdeadbeef);
151 bRet = FtpCreateDirectoryA(hFtp, "new_directory_deadbeef");
152 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
153 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
154 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
156 /* One small test to show that handle type is checked before parameters */
157 SetLastError(0xdeadbeef);
158 bRet = FtpCreateDirectoryA(hConnect, NULL);
159 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
160 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
161 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
163 SetLastError(0xdeadbeef);
164 bRet = FtpCreateDirectoryA(hConnect, "new_directory_deadbeef");
165 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
166 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
167 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
170 static void test_deletefile(HINTERNET hFtp, HINTERNET hConnect)
174 /* Invalid internet handle, the other is a valid parameter */
175 SetLastError(0xdeadbeef);
176 bRet = FtpDeleteFileA(NULL, "non_existent_file_deadbeef");
177 ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
178 ok ( GetLastError() == ERROR_INVALID_HANDLE,
179 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
182 SetLastError(0xdeadbeef);
183 bRet = FtpDeleteFileA(hFtp, NULL);
184 ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
185 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
186 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
188 /* Parameters are OK but remote file should not be there */
189 SetLastError(0xdeadbeef);
190 bRet = FtpDeleteFileA(hFtp, "non_existent_file_deadbeef");
191 ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
192 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
193 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
195 /* One small test to show that handle type is checked before parameters */
196 SetLastError(0xdeadbeef);
197 bRet = FtpDeleteFileA(hConnect, NULL);
198 ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
199 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
200 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
202 SetLastError(0xdeadbeef);
203 bRet = FtpDeleteFileA(hConnect, "non_existent_file_deadbeef");
204 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
205 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
206 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
209 static void test_getfile(HINTERNET hFtp, HINTERNET hConnect)
214 /* The order of checking is:
216 * All parameters except 'session handle' and 'condition flags'
218 * Session handle type
222 /* Test to show the parameter checking order depends on the Windows version */
223 SetLastError(0xdeadbeef);
224 bRet = FtpGetFileA(NULL, NULL, "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
225 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
226 ok ( GetLastError() == ERROR_INVALID_HANDLE ||
227 GetLastError() == ERROR_INVALID_PARAMETER,
228 "Expected ERROR_INVALID_HANDLE (win98) or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
230 /* Test to show session handle is checked before 'condition flags' */
231 SetLastError(0xdeadbeef);
232 bRet = FtpGetFileA(NULL, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, 5, 0);
233 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
234 ok ( GetLastError() == ERROR_INVALID_HANDLE,
235 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
237 /* Make sure we start clean */
239 DeleteFileA("should_be_non_existing_deadbeef");
240 DeleteFileA("should_also_be_non_existing_deadbeef");
243 SetLastError(0xdeadbeef);
244 bRet = FtpGetFileA(hFtp, NULL, "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
245 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
246 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
247 "Expected ERROR_INVALID_PARAMETER, 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");
253 SetLastError(0xdeadbeef);
254 bRet = FtpGetFileA(hFtp, "welcome.msg", NULL, FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
255 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
256 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
257 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
259 /* Zero attributes */
260 SetLastError(0xdeadbeef);
261 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_existing_non_deadbeef", FALSE, 0, FTP_TRANSFER_TYPE_UNKNOWN, 0);
262 ok ( bRet == TRUE, "Expected FtpGetFileA to succeed\n");
263 ok (GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
264 ok (GetFileAttributesA("should_be_existing_non_deadbeef") != INVALID_FILE_ATTRIBUTES,
265 "Local file should have been created\n");
266 DeleteFileA("should_be_existing_non_deadbeef");
268 /* Illegal condition flags */
269 SetLastError(0xdeadbeef);
270 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, 0xffffffff, 0);
271 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
272 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR || GetLastError() == ERROR_INVALID_PARAMETER,
273 "Expected ERROR_INTERNET_EXTENDED_ERROR or ERROR_INVALID_PARAMETER (win98), got %d\n", GetLastError());
274 ok (GetFileAttributesA("should_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
275 "Local file should not have been created\n");
276 DeleteFileA("should_be_non_existing_deadbeef");
278 /* Remote file doesn't exist (and local doesn't exist as well) */
279 SetLastError(0xdeadbeef);
280 bRet = FtpGetFileA(hFtp, "should_be_non_existing_deadbeef", "should_also_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_INTERNET_EXTENDED_ERROR,
283 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
284 /* Currently Wine always creates the local file (even on failure) which is not correct, hence the test */
285 ok (GetFileAttributesA("should_also_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
286 "Local file should not have been created\n");
288 DeleteFileA("should_also_be_non_existing_deadbeef");
290 /* Same call as the previous but now the local file does exists. Windows just removes the file if the call fails
291 * even if the local existed before!
294 /* Create a temporary local file */
295 SetLastError(0xdeadbeef);
296 hFile = CreateFileA("should_also_be_non_existing_deadbeef", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
297 ok ( hFile != NULL, "Error creating a local file : %d\n", GetLastError());
299 SetLastError(0xdeadbeef);
300 bRet = FtpGetFileA(hFtp, "should_be_non_existing_deadbeef", "should_also_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
301 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
302 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
303 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
304 /* Currently Wine always creates the local file (even on failure) which is not correct, hence the test */
305 ok (GetFileAttributesA("should_also_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
306 "Local file should not have been created\n");
308 DeleteFileA("should_also_be_non_existing_deadbeef");
310 /* This one should succeed */
311 SetLastError(0xdeadbeef);
312 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_existing_non_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
313 ok ( bRet == TRUE, "Expected FtpGetFileA to fail\n");
314 ok ( GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
316 if (GetFileAttributesA("should_be_existing_non_deadbeef") != INVALID_FILE_ATTRIBUTES)
318 /* Should succeed as fFailIfExists is set to FALSE (meaning don't fail if local file exists) */
319 SetLastError(0xdeadbeef);
320 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
321 ok ( bRet == TRUE, "Expected FtpGetFileA to succeed\n");
322 ok ( GetLastError() == ERROR_SUCCESS,
323 "Expected ERROR_SUCCESS, got %d\n", GetLastError());
325 /* Should fail as fFailIfExists is set to TRUE */
326 SetLastError(0xdeadbeef);
327 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", TRUE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
328 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
329 ok ( GetLastError() == ERROR_FILE_EXISTS,
330 "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
332 /* Prove that the existence of the local file is checked first (or at least reported last) */
333 SetLastError(0xdeadbeef);
334 bRet = FtpGetFileA(hFtp, "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_FILE_EXISTS,
337 "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
339 DeleteFileA("should_be_existing_non_deadbeef");
342 /* Test to show the parameter checking order depends on the Windows version */
343 SetLastError(0xdeadbeef);
344 bRet = FtpGetFileA(hConnect, NULL, "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
345 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
346 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE ||
347 GetLastError() == ERROR_INVALID_PARAMETER,
348 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE (win98) or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
350 /* Test to show that 'session handle type' is checked before 'condition flags' */
351 SetLastError(0xdeadbeef);
352 bRet = FtpGetFileA(hConnect, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, 5, 0);
353 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
354 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
355 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
357 SetLastError(0xdeadbeef);
358 bRet = FtpGetFileA(hConnect, "should_be_non_existing_deadbeef", "should_be_non_existing_deadbeef", TRUE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
359 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
360 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
361 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
364 static void trace_extended_error(DWORD error)
366 DWORD code, buflen = 0;
368 if (error != ERROR_INTERNET_EXTENDED_ERROR) return;
369 if (!InternetGetLastResponseInfoA(&code, NULL, &buflen) && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
371 char *text = HeapAlloc(GetProcessHeap(), 0, ++buflen);
372 InternetGetLastResponseInfoA(&code, text, &buflen);
373 trace("%u %s\n", code, text);
374 HeapFree(GetProcessHeap(), 0, text);
378 static void test_openfile(HINTERNET hFtp, HINTERNET hConnect)
382 /* Invalid internet handle, the rest are valid parameters */
383 SetLastError(0xdeadbeef);
384 hOpenFile = FtpOpenFileA(NULL, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
385 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
386 ok ( GetLastError() == ERROR_INVALID_HANDLE,
387 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
388 InternetCloseHandle(hOpenFile); /* Just in case */
391 SetLastError(0xdeadbeef);
392 hOpenFile = FtpOpenFileA(hFtp, NULL, GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
393 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
394 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
395 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
396 InternetCloseHandle(hOpenFile); /* Just in case */
398 /* Illegal access flags */
399 SetLastError(0xdeadbeef);
400 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", 0, FTP_TRANSFER_TYPE_ASCII, 0);
401 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
402 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
403 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
404 InternetCloseHandle(hOpenFile); /* Just in case */
406 /* Illegal combination of access flags */
407 SetLastError(0xdeadbeef);
408 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ|GENERIC_WRITE, FTP_TRANSFER_TYPE_ASCII, 0);
409 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
410 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
411 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
412 InternetCloseHandle(hOpenFile); /* Just in case */
414 /* Illegal condition flags */
415 SetLastError(0xdeadbeef);
416 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, 0xffffffff, 0);
417 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
418 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR || GetLastError() == ERROR_INVALID_PARAMETER,
419 "Expected ERROR_INTERNET_EXTENDED_ERROR or ERROR_INVALID_PARAMETER (win98), got %d\n", GetLastError());
420 InternetCloseHandle(hOpenFile); /* Just in case */
422 SetLastError(0xdeadbeef);
423 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
424 ok ( hOpenFile != NULL, "Expected FtpOpenFileA to succeed\n");
425 ok ( GetLastError() == ERROR_SUCCESS ||
426 broken(GetLastError() == ERROR_FILE_NOT_FOUND), /* Win98 */
427 "Expected ERROR_SUCCESS, got %u\n", GetLastError());
433 HINTERNET hOpenFile2;
436 /* We have a handle so all ftp calls should fail (TODO: Put all ftp-calls in here) */
437 SetLastError(0xdeadbeef);
438 bRet = FtpCreateDirectoryA(hFtp, "new_directory_deadbeef");
439 error = GetLastError();
440 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
441 ok ( error == ERROR_FTP_TRANSFER_IN_PROGRESS || broken(error == ERROR_INTERNET_EXTENDED_ERROR),
442 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error);
443 trace_extended_error(error);
445 SetLastError(0xdeadbeef);
446 bRet = FtpDeleteFileA(hFtp, "non_existent_file_deadbeef");
447 error = GetLastError();
448 ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
449 ok ( error == ERROR_FTP_TRANSFER_IN_PROGRESS || broken(error == ERROR_INTERNET_EXTENDED_ERROR),
450 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error);
451 trace_extended_error(error);
453 SetLastError(0xdeadbeef);
454 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
455 error = GetLastError();
456 ok ( bRet == FALSE || broken(bRet == TRUE), "Expected FtpGetFileA to fail\n");
457 ok ( error == ERROR_FTP_TRANSFER_IN_PROGRESS || broken(error == ERROR_SUCCESS),
458 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error);
459 DeleteFileA("should_be_non_existing_deadbeef"); /* Just in case */
461 SetLastError(0xdeadbeef);
462 hOpenFile2 = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
463 error = GetLastError();
464 ok ( bRet == FALSE || broken(bRet == TRUE), "Expected FtpOpenFileA to fail\n");
465 ok ( error == ERROR_FTP_TRANSFER_IN_PROGRESS || broken(error == ERROR_SUCCESS),
466 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error);
467 InternetCloseHandle(hOpenFile2); /* Just in case */
469 /* Create a temporary local file */
470 SetLastError(0xdeadbeef);
471 hFile = CreateFileA("now_existing_local", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
472 ok ( hFile != NULL, "Error creating a local file : %d\n", GetLastError());
474 SetLastError(0xdeadbeef);
475 bRet = FtpPutFileA(hFtp, "now_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
476 error = GetLastError();
477 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
478 ok ( error == ERROR_FTP_TRANSFER_IN_PROGRESS || broken(error == ERROR_INTERNET_EXTENDED_ERROR),
479 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error);
480 DeleteFileA("now_existing_local");
482 SetLastError(0xdeadbeef);
483 bRet = FtpRemoveDirectoryA(hFtp, "should_be_non_existing_deadbeef_dir");
484 error = GetLastError();
485 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
486 ok ( error == ERROR_FTP_TRANSFER_IN_PROGRESS || broken(error == ERROR_INTERNET_EXTENDED_ERROR),
487 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error);
489 SetLastError(0xdeadbeef);
490 bRet = FtpRenameFileA(hFtp , "should_be_non_existing_deadbeef", "new");
491 error = GetLastError();
492 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
493 ok ( error == ERROR_FTP_TRANSFER_IN_PROGRESS || broken(error == ERROR_INTERNET_EXTENDED_ERROR),
494 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error);
497 InternetCloseHandle(hOpenFile);
499 /* One small test to show that handle type is checked before parameters */
500 SetLastError(0xdeadbeef);
501 hOpenFile = FtpOpenFileA(hConnect, "welcome.msg", GENERIC_READ, 5, 0);
502 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
503 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
504 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
505 InternetCloseHandle(hOpenFile); /* Just in case */
507 SetLastError(0xdeadbeef);
508 hOpenFile = FtpOpenFileA(hConnect, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
509 ok ( hOpenFile == NULL, "Expected FtpOpenFileA to fail\n");
510 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
511 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
513 InternetCloseHandle(hOpenFile); /* Just in case */
516 static void test_putfile(HINTERNET hFtp, HINTERNET hConnect)
521 /* The order of checking is:
523 * All parameters except 'session handle' and 'condition flags'
525 * Session handle type
529 /* Test to show the parameter checking order depends on the Windows version */
530 SetLastError(0xdeadbeef);
531 bRet = FtpPutFileA(NULL, NULL, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
532 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
533 ok ( GetLastError() == ERROR_INVALID_HANDLE ||
534 GetLastError() == ERROR_INVALID_PARAMETER,
535 "Expected ERROR_INVALID_HANDLE (win98) or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
537 /* Test to show session handle is checked before 'condition flags' */
538 SetLastError(0xdeadbeef);
539 bRet = FtpPutFileA(NULL, "non_existing_local", "non_existing_remote", 5, 0);
540 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
541 ok ( GetLastError() == ERROR_INVALID_HANDLE,
542 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
545 DeleteFileA("non_existing_local");
547 /* No local file given */
548 SetLastError(0xdeadbeef);
549 bRet = FtpPutFileA(hFtp, NULL, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
550 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
551 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
552 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
554 /* No remote file given */
555 SetLastError(0xdeadbeef);
556 bRet = FtpPutFileA(hFtp, "non_existing_local", NULL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
557 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
558 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
559 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
561 /* Illegal condition flags */
562 SetLastError(0xdeadbeef);
563 bRet = FtpPutFileA(hFtp, "non_existing_local", "non_existing_remote", 5, 0);
564 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
565 ok ( GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_INVALID_PARAMETER,
566 "Expected ERROR_FILE_NOT_FOUND or ERROR_INVALID_PARAMETER (win98), got %d\n", GetLastError());
568 /* Parameters are OK but local file doesn't exist */
569 SetLastError(0xdeadbeef);
570 bRet = FtpPutFileA(hFtp, "non_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
571 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
572 ok ( GetLastError() == ERROR_FILE_NOT_FOUND,
573 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
575 /* Create a temporary local file */
576 SetLastError(0xdeadbeef);
577 hFile = CreateFileA("now_existing_local", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
578 ok ( hFile != NULL, "Error creating a local file : %d\n", GetLastError());
581 /* Local file exists but we shouldn't be allowed to 'put' the file */
582 SetLastError(0xdeadbeef);
583 bRet = FtpPutFileA(hFtp, "now_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
584 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
585 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
586 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
588 DeleteFileA("now_existing_local");
590 /* Test to show the parameter checking order depends on the Windows version */
591 SetLastError(0xdeadbeef);
592 bRet = FtpPutFileA(hConnect, NULL, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
593 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
594 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE ||
595 GetLastError() == ERROR_INVALID_PARAMETER,
596 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE (win98) or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
598 /* Test to show that 'session handle type' is checked before 'condition flags' */
599 SetLastError(0xdeadbeef);
600 bRet = FtpPutFileA(hConnect, "non_existing_local", "non_existing_remote", 5, 0);
601 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
602 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
603 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
605 SetLastError(0xdeadbeef);
606 bRet = FtpPutFileA(hConnect, "non_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
607 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
608 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
609 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
612 static void test_removedir(HINTERNET hFtp, HINTERNET hConnect)
616 /* Invalid internet handle, the other is a valid parameter */
617 SetLastError(0xdeadbeef);
618 bRet = FtpRemoveDirectoryA(NULL, "should_be_non_existing_deadbeef_dir");
619 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
620 ok ( GetLastError() == ERROR_INVALID_HANDLE,
621 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
623 /* No remote directory given */
624 SetLastError(0xdeadbeef);
625 bRet = FtpRemoveDirectoryA(hFtp, NULL);
626 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
627 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
628 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
630 /* Remote directory doesn't exist */
631 SetLastError(0xdeadbeef);
632 bRet = FtpRemoveDirectoryA(hFtp, "should_be_non_existing_deadbeef_dir");
633 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
634 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
635 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
637 /* We shouldn't be allowed to remove that directory */
638 SetLastError(0xdeadbeef);
639 bRet = FtpRemoveDirectoryA(hFtp, "pub");
640 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
641 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
642 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
644 /* One small test to show that handle type is checked before parameters */
645 SetLastError(0xdeadbeef);
646 bRet = FtpRemoveDirectoryA(hConnect, NULL);
647 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
648 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
649 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
651 SetLastError(0xdeadbeef);
652 bRet = FtpRemoveDirectoryA(hConnect, "should_be_non_existing_deadbeef_dir");
653 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
654 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
655 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
658 static void test_renamefile(HINTERNET hFtp, HINTERNET hConnect)
662 /* Invalid internet handle, the rest are valid parameters */
663 SetLastError(0xdeadbeef);
664 bRet = FtpRenameFileA(NULL , "should_be_non_existing_deadbeef", "new");
665 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
666 ok ( GetLastError() == ERROR_INVALID_HANDLE,
667 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
669 /* No 'existing' file */
670 SetLastError(0xdeadbeef);
671 bRet = FtpRenameFileA(hFtp , NULL, "new");
672 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
673 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
674 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
677 SetLastError(0xdeadbeef);
678 bRet = FtpRenameFileA(hFtp , "should_be_non_existing_deadbeef", NULL);
679 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
680 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
681 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
683 /* Existing file shouldn't be there */
684 SetLastError(0xdeadbeef);
685 bRet = FtpRenameFileA(hFtp , "should_be_non_existing_deadbeef", "new");
686 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
687 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
688 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
690 /* One small test to show that handle type is checked before parameters */
691 SetLastError(0xdeadbeef);
692 bRet = FtpRenameFileA(hConnect , "should_be_non_existing_deadbeef", NULL);
693 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
694 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
695 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
697 SetLastError(0xdeadbeef);
698 bRet = FtpRenameFileA(hConnect , "should_be_non_existing_deadbeef", "new");
699 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
700 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
701 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
704 static void test_command(HINTERNET hFtp, HINTERNET hConnect)
717 { FALSE, ERROR_INVALID_PARAMETER, NULL },
718 { FALSE, ERROR_INVALID_PARAMETER, "" },
719 { FALSE, ERROR_INTERNET_EXTENDED_ERROR, "HELO" },
720 { FALSE, ERROR_INTERNET_EXTENDED_ERROR, "SIZE " },
721 { FALSE, ERROR_INTERNET_EXTENDED_ERROR, " SIZE" },
722 { FALSE, ERROR_INTERNET_EXTENDED_ERROR, "SIZE " },
723 { FALSE, ERROR_INTERNET_EXTENDED_ERROR, "SIZE /welcome.msg /welcome.msg" },
724 { FALSE, ERROR_INTERNET_EXTENDED_ERROR, "SIZE /welcome.msg" },
725 { FALSE, ERROR_INTERNET_EXTENDED_ERROR, "SIZE /welcome.msg " },
726 { TRUE, ERROR_SUCCESS, "SIZE\t/welcome.msg" },
727 { TRUE, ERROR_SUCCESS, "SIZE /welcome.msg" },
728 { FALSE, ERROR_INTERNET_EXTENDED_ERROR, "PWD /welcome.msg" },
729 { TRUE, ERROR_SUCCESS, "PWD" },
730 { TRUE, ERROR_SUCCESS, "PWD\r\n" }
735 win_skip("FtpCommandA() is not available. Skipping the Ftp command tests\n");
739 for (i = 0; i < sizeof(command_test) / sizeof(command_test[0]); i++)
741 SetLastError(0xdeadbeef);
742 ret = pFtpCommandA(hFtp, FALSE, FTP_TRANSFER_TYPE_ASCII, command_test[i].cmd, 0, NULL);
743 error = GetLastError();
745 ok(ret == command_test[i].ret, "%d: expected FtpCommandA to %s\n", i, command_test[i].ret ? "succeed" : "fail");
746 ok(error == command_test[i].error, "%d: expected error %u, got %u\n", i, command_test[i].error, error);
750 static void test_find_first_file(HINTERNET hFtp, HINTERNET hConnect)
752 WIN32_FIND_DATA findData;
758 /* NULL as the search file ought to return the first file in the directory */
759 SetLastError(0xdeadbeef);
760 hSearch = FtpFindFirstFileA(hFtp, NULL, &findData, 0, 0);
761 ok ( hSearch != NULL, "Expected FtpFindFirstFileA to pass\n" );
763 /* This should fail as the previous handle wasn't closed */
764 SetLastError(0xdeadbeef);
765 hSearch2 = FtpFindFirstFileA(hFtp, "welcome.msg", &findData, 0, 0);
766 todo_wine ok ( hSearch2 == NULL, "Expected FtpFindFirstFileA to fail\n" );
767 todo_wine ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS,
768 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError() );
769 InternetCloseHandle(hSearch2); /* Just in case */
771 InternetCloseHandle(hSearch);
773 /* Try a valid filename in a subdirectory search */
774 SetLastError(0xdeadbeef);
775 hSearch = FtpFindFirstFileA(hFtp, "pub/wine", &findData, 0, 0);
776 todo_wine ok ( hSearch != NULL, "Expected FtpFindFirstFileA to pass\n" );
777 InternetCloseHandle(hSearch);
779 /* Try a valid filename in a subdirectory wildcard search */
780 SetLastError(0xdeadbeef);
781 hSearch = FtpFindFirstFileA(hFtp, "pub/w*", &findData, 0, 0);
782 todo_wine ok ( hSearch != NULL, "Expected FtpFindFirstFileA to pass\n" );
783 InternetCloseHandle(hSearch);
785 /* Try an invalid wildcard search */
786 SetLastError(0xdeadbeef);
787 hSearch = FtpFindFirstFileA(hFtp, "*/w*", &findData, 0, 0);
788 ok ( hSearch == NULL, "Expected FtpFindFirstFileA to fail\n" );
789 InternetCloseHandle(hSearch); /* Just in case */
791 /* Try FindFirstFile between FtpOpenFile and InternetCloseHandle */
792 SetLastError(0xdeadbeef);
793 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
794 ok ( hOpenFile != NULL, "Expected FtpOpenFileA to succeed\n" );
795 ok ( GetLastError() == ERROR_SUCCESS ||
796 broken(GetLastError() == ERROR_FILE_NOT_FOUND), /* Win98 */
797 "Expected ERROR_SUCCESS, got %u\n", GetLastError() );
799 /* This should fail as the OpenFile handle wasn't closed */
800 SetLastError(0xdeadbeef);
801 hSearch = FtpFindFirstFileA(hFtp, "welcome.msg", &findData, 0, 0);
802 error = GetLastError();
803 ok ( hSearch == NULL || broken(hSearch != NULL), /* win2k */
804 "Expected FtpFindFirstFileA to fail\n" );
806 ok ( error == ERROR_FTP_TRANSFER_IN_PROGRESS || broken(error == ERROR_INTERNET_EXTENDED_ERROR),
807 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error );
810 ok( error == ERROR_SUCCESS, "wrong error %u on success\n", GetLastError() );
811 InternetCloseHandle(hSearch);
814 InternetCloseHandle(hOpenFile);
816 /* Test using a nonexistent filename */
817 SetLastError(0xdeadbeef);
818 hSearch = FtpFindFirstFileA(hFtp, "this_file_should_not_exist", &findData, 0, 0);
819 ok ( hSearch == NULL, "Expected FtpFindFirstFileA to fail\n" );
820 todo_wine ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
821 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError() );
822 InternetCloseHandle(hSearch); /* Just in case */
824 /* Test using a nonexistent filename and a wildcard */
825 SetLastError(0xdeadbeef);
826 hSearch = FtpFindFirstFileA(hFtp, "this_file_should_not_exist*", &findData, 0, 0);
827 ok ( hSearch == NULL, "Expected FtpFindFirstFileA to fail\n" );
828 todo_wine ok ( GetLastError() == ERROR_NO_MORE_FILES,
829 "Expected ERROR_NO_MORE_FILES, got %d\n", GetLastError() );
830 InternetCloseHandle(hSearch); /* Just in case */
832 /* Test using an invalid handle type */
833 SetLastError(0xdeadbeef);
834 hSearch = FtpFindFirstFileA(hConnect, "welcome.msg", &findData, 0, 0);
835 ok ( hSearch == NULL, "Expected FtpFindFirstFileA to fail\n" );
836 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
837 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError() );
838 InternetCloseHandle(hSearch); /* Just in case */
841 static void test_get_current_dir(HINTERNET hFtp, HINTERNET hConnect)
844 DWORD dwCurrentDirectoryLen = MAX_PATH;
845 CHAR lpszCurrentDirectory[MAX_PATH];
849 win_skip("FtpCommandA() is not available. Skipping the Ftp get_current_dir tests\n");
853 /* change directories to get a more interesting pwd */
854 bRet = pFtpCommandA(hFtp, FALSE, FTP_TRANSFER_TYPE_ASCII, "CWD pub/", 0, NULL);
857 skip("Failed to change directories in test_get_current_dir(HINTERNET hFtp).\n");
861 /* test with all NULL arguments */
862 SetLastError(0xdeadbeef);
863 bRet = FtpGetCurrentDirectoryA( NULL, NULL, 0 );
864 ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" );
865 ok ( GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got: %d\n", GetLastError());
867 /* test with NULL parameters instead of expected LPSTR/LPDWORD */
868 SetLastError(0xdeadbeef);
869 bRet = FtpGetCurrentDirectoryA( hFtp, NULL, 0 );
870 ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" );
871 ok ( GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got: %d\n", GetLastError());
873 /* test with no valid handle and valid parameters */
874 SetLastError(0xdeadbeef);
875 bRet = FtpGetCurrentDirectoryA( NULL, lpszCurrentDirectory, &dwCurrentDirectoryLen );
876 ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" );
877 ok ( GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got: %d\n", GetLastError());
879 /* test with invalid dwCurrentDirectory and all other parameters correct */
880 SetLastError(0xdeadbeef);
881 bRet = FtpGetCurrentDirectoryA( hFtp, lpszCurrentDirectory, 0 );
882 ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" );
883 ok ( GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got: %d\n", GetLastError());
885 /* test with invalid lpszCurrentDirectory and all other parameters correct */
886 SetLastError(0xdeadbeef);
887 bRet = FtpGetCurrentDirectoryA( hFtp, NULL, &dwCurrentDirectoryLen );
888 ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" );
889 ok ( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INSUFFICIENT_BUFFER, got: %d\n", GetLastError());
891 /* test to show it checks the handle type */
892 SetLastError(0xdeadbeef);
893 bRet = FtpGetCurrentDirectoryA( hConnect, lpszCurrentDirectory, &dwCurrentDirectoryLen );
894 ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" );
895 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
896 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got: %d\n", GetLastError());
898 /* test for the current directory with legitimate values */
899 SetLastError(0xdeadbeef);
900 bRet = FtpGetCurrentDirectoryA( hFtp, lpszCurrentDirectory, &dwCurrentDirectoryLen );
901 ok ( bRet == TRUE, "Expected FtpGetCurrentDirectoryA to pass\n" );
902 ok ( !strcmp(lpszCurrentDirectory, "/pub"), "Expected returned value \"%s\" to match \"/pub\"\n", lpszCurrentDirectory);
903 ok ( GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got: %d\n", GetLastError());
905 /* test for the current directory with a size only large enough to
906 * fit the string and not the null terminating character */
907 SetLastError(0xdeadbeef);
908 dwCurrentDirectoryLen = 4;
909 lpszCurrentDirectory[4] = 'a'; /* set position 4 of the array to something else to make sure a leftover \0 isn't fooling the test */
910 bRet = FtpGetCurrentDirectoryA( hFtp, lpszCurrentDirectory, &dwCurrentDirectoryLen );
911 ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n");
912 ok ( strcmp(lpszCurrentDirectory, "/pub"), "Expected returned value \"%s\" to not match \"/pub\"\n", lpszCurrentDirectory);
913 ok ( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INSUFFICIENT_BUFFER, got: %d\n", GetLastError());
915 /* test for the current directory with a size large enough to store
916 * the expected string as well as the null terminating character */
917 SetLastError(0xdeadbeef);
918 dwCurrentDirectoryLen = 5;
919 bRet = FtpGetCurrentDirectoryA( hFtp, lpszCurrentDirectory, &dwCurrentDirectoryLen );
920 ok ( bRet == TRUE, "Expected FtpGetCurrentDirectoryA to pass\n");
921 ok ( !strcmp(lpszCurrentDirectory, "/pub"), "Expected returned value \"%s\" to match \"/pub\"\n", lpszCurrentDirectory);
922 ok ( GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got: %d\n", GetLastError());
925 static void WINAPI status_callback(HINTERNET handle, DWORD_PTR ctx, DWORD status, LPVOID info, DWORD info_len)
929 case INTERNET_STATUS_RESOLVING_NAME:
930 case INTERNET_STATUS_NAME_RESOLVED:
931 case INTERNET_STATUS_CONNECTING_TO_SERVER:
932 case INTERNET_STATUS_CONNECTED_TO_SERVER:
933 trace("%p %lx %u %s %u\n", handle, ctx, status, (char *)info, info_len);
940 static void test_status_callbacks(HINTERNET hInternet)
942 INTERNET_STATUS_CALLBACK cb;
946 cb = pInternetSetStatusCallbackA(hInternet, status_callback);
947 ok(cb == NULL, "expected NULL got %p\n", cb);
949 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", NULL,
950 INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 1);
953 skip("No ftp connection could be made to ftp.winehq.org %u\n", GetLastError());
957 ret = InternetCloseHandle(hFtp);
958 ok(ret, "InternetCloseHandle failed %u\n", GetLastError());
960 cb = pInternetSetStatusCallbackA(hInternet, NULL);
961 ok(cb == status_callback, "expected check_status got %p\n", cb);
967 HANDLE hInternet, hFtp, hHttp;
969 hWininet = GetModuleHandleA("wininet.dll");
971 if(!GetProcAddress(hWininet, "InternetGetCookieExW")) {
972 win_skip("Too old IE (older than 6.0)\n");
976 pFtpCommandA = (void*)GetProcAddress(hWininet, "FtpCommandA");
977 pInternetSetStatusCallbackA = (void*)GetProcAddress(hWininet, "InternetSetStatusCallbackA");
979 SetLastError(0xdeadbeef);
980 hInternet = InternetOpen("winetest", 0, NULL, NULL, 0);
981 ok(hInternet != NULL, "InternetOpen failed: %u\n", GetLastError());
983 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", NULL, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
986 InternetCloseHandle(hInternet);
987 skip("No ftp connection could be made to ftp.winehq.org\n");
990 hHttp = InternetConnect(hInternet, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
993 InternetCloseHandle(hFtp);
994 InternetCloseHandle(hInternet);
995 skip("No http connection could be made to www.winehq.org\n");
999 /* The first call should always be a proper InternetOpen, if not
1000 * several calls will return ERROR_INTERNET_NOT_INITIALIZED when
1001 * all parameters are correct but no session handle is given. Whereas
1002 * the same call will return ERROR_INVALID_HANDLE if an InternetOpen
1004 * The following test will show that behaviour, where the tests inside
1005 * the other sub-tests will show the other situation.
1007 test_getfile_no_open();
1008 test_connect(hInternet);
1009 test_createdir(hFtp, hHttp);
1010 test_deletefile(hFtp, hHttp);
1011 test_getfile(hFtp, hHttp);
1012 test_openfile(hFtp, hHttp);
1013 test_putfile(hFtp, hHttp);
1014 test_removedir(hFtp, hHttp);
1015 test_renamefile(hFtp, hHttp);
1016 test_command(hFtp, hHttp);
1017 test_find_first_file(hFtp, hHttp);
1018 test_get_current_dir(hFtp, hHttp);
1019 test_status_callbacks(hInternet);
1021 InternetCloseHandle(hHttp);
1022 InternetCloseHandle(hFtp);
1023 InternetCloseHandle(hInternet);