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
= InternetConnectA(hInternet
, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT
, "anonymous", "IEUser@", INTERNET_SERVICE_FTP
, INTERNET_FLAG_PASSIVE
, 0);
77 skip("No ftp connection could be made to ftp.winehq.org %u\n", GetLastError());
80 ok(GetLastError() == ERROR_SUCCESS
,
81 "Expected ERROR_SUCCESS, got %d\n", GetLastError());
82 InternetCloseHandle(hFtp
);
84 SetLastError(0xdeadbeef);
85 hFtp
= InternetConnectA(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
= InternetConnectA(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
= InternetConnectA(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
= InternetConnectA(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());
115 InternetCloseHandle(hFtp
);
117 SetLastError(0xdeadbeef);
118 hFtp
= InternetConnectA(hInternet
, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT
, "", NULL
,
119 INTERNET_SERVICE_FTP
, INTERNET_FLAG_PASSIVE
, 0);
122 ok(GetLastError() == ERROR_INTERNET_LOGIN_FAILURE
,
123 "Expected ERROR_INTERNET_LOGIN_FAILURE, got %d\n", GetLastError());
127 ok(GetLastError() == ERROR_SUCCESS
,
128 "Expected ERROR_SUCCESS, got %d\n", GetLastError());
129 InternetCloseHandle(hFtp
);
133 static void test_createdir(HINTERNET hFtp
, HINTERNET hConnect
)
137 /* Invalid internet handle, the other is a valid parameter */
138 SetLastError(0xdeadbeef);
139 bRet
= FtpCreateDirectoryA(NULL
, "new_directory_deadbeef");
140 ok ( bRet
== FALSE
, "Expected FtpCreateDirectoryA to fail\n");
141 ok ( GetLastError() == ERROR_INVALID_HANDLE
,
142 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
144 /* No directory-name */
145 SetLastError(0xdeadbeef);
146 bRet
= FtpCreateDirectoryA(hFtp
, NULL
);
147 ok ( bRet
== FALSE
, "Expected FtpCreateDirectoryA to fail\n");
148 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
149 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
151 /* Parameters are OK, but we shouldn't be allowed to create the directory */
152 SetLastError(0xdeadbeef);
153 bRet
= FtpCreateDirectoryA(hFtp
, "new_directory_deadbeef");
154 ok ( bRet
== FALSE
, "Expected FtpCreateDirectoryA to fail\n");
155 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR
,
156 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
158 /* One small test to show that handle type is checked before parameters */
159 SetLastError(0xdeadbeef);
160 bRet
= FtpCreateDirectoryA(hConnect
, NULL
);
161 ok ( bRet
== FALSE
, "Expected FtpCreateDirectoryA to fail\n");
162 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
163 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
165 SetLastError(0xdeadbeef);
166 bRet
= FtpCreateDirectoryA(hConnect
, "new_directory_deadbeef");
167 ok ( bRet
== FALSE
, "Expected FtpCreateDirectoryA to fail\n");
168 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
169 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
172 static void test_deletefile(HINTERNET hFtp
, HINTERNET hConnect
)
176 /* Invalid internet handle, the other is a valid parameter */
177 SetLastError(0xdeadbeef);
178 bRet
= FtpDeleteFileA(NULL
, "non_existent_file_deadbeef");
179 ok ( bRet
== FALSE
, "Expected FtpDeleteFileA to fail\n");
180 ok ( GetLastError() == ERROR_INVALID_HANDLE
,
181 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
184 SetLastError(0xdeadbeef);
185 bRet
= FtpDeleteFileA(hFtp
, NULL
);
186 ok ( bRet
== FALSE
, "Expected FtpDeleteFileA to fail\n");
187 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
188 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
190 /* Parameters are OK but remote file should not be there */
191 SetLastError(0xdeadbeef);
192 bRet
= FtpDeleteFileA(hFtp
, "non_existent_file_deadbeef");
193 ok ( bRet
== FALSE
, "Expected FtpDeleteFileA to fail\n");
194 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR
,
195 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
197 /* One small test to show that handle type is checked before parameters */
198 SetLastError(0xdeadbeef);
199 bRet
= FtpDeleteFileA(hConnect
, NULL
);
200 ok ( bRet
== FALSE
, "Expected FtpDeleteFileA to fail\n");
201 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
202 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
204 SetLastError(0xdeadbeef);
205 bRet
= FtpDeleteFileA(hConnect
, "non_existent_file_deadbeef");
206 ok ( bRet
== FALSE
, "Expected FtpCreateDirectoryA to fail\n");
207 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
208 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
211 static void test_getfile(HINTERNET hFtp
, HINTERNET hConnect
)
216 /* The order of checking is:
218 * All parameters except 'session handle' and 'condition flags'
220 * Session handle type
224 /* Test to show the parameter checking order depends on the Windows version */
225 SetLastError(0xdeadbeef);
226 bRet
= FtpGetFileA(NULL
, NULL
, "should_be_non_existing_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
227 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
228 ok ( GetLastError() == ERROR_INVALID_HANDLE
||
229 GetLastError() == ERROR_INVALID_PARAMETER
,
230 "Expected ERROR_INVALID_HANDLE (win98) or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
232 /* Test to show session handle is checked before 'condition flags' */
233 SetLastError(0xdeadbeef);
234 bRet
= FtpGetFileA(NULL
, "welcome.msg", "should_be_non_existing_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, 5, 0);
235 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
236 ok ( GetLastError() == ERROR_INVALID_HANDLE
,
237 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
239 /* Make sure we start clean */
241 DeleteFileA("should_be_non_existing_deadbeef");
242 DeleteFileA("should_also_be_non_existing_deadbeef");
245 SetLastError(0xdeadbeef);
246 bRet
= FtpGetFileA(hFtp
, NULL
, "should_be_non_existing_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
247 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
248 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
249 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
250 ok (GetFileAttributesA("should_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES
,
251 "Local file should not have been created\n");
252 DeleteFileA("should_be_non_existing_deadbeef");
255 SetLastError(0xdeadbeef);
256 bRet
= FtpGetFileA(hFtp
, "welcome.msg", NULL
, FALSE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
257 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
258 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
259 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
261 /* Zero attributes */
262 bRet
= FtpGetFileA(hFtp
, "welcome.msg", "should_be_existing_non_deadbeef", FALSE
, 0, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
263 ok ( bRet
== TRUE
, "Expected FtpGetFileA to succeed\n");
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
)
709 BOOL had_error_zero
= FALSE
;
710 BOOL had_error_zero_size_positive
= FALSE
;
719 { FALSE
, ERROR_INVALID_PARAMETER
, NULL
},
720 { FALSE
, ERROR_INVALID_PARAMETER
, "" },
721 { FALSE
, ERROR_INTERNET_EXTENDED_ERROR
, "invalid" },
722 { FALSE
, ERROR_INTERNET_EXTENDED_ERROR
, "size" },
723 { TRUE
, ERROR_SUCCESS
, "type i" },
724 { FALSE
, ERROR_INTERNET_EXTENDED_ERROR
, "size " },
725 { FALSE
, ERROR_INTERNET_EXTENDED_ERROR
, " size" },
726 { FALSE
, ERROR_INTERNET_EXTENDED_ERROR
, "size " },
727 { FALSE
, ERROR_INTERNET_EXTENDED_ERROR
, "size welcome.msg welcome.msg" },
728 { FALSE
, ERROR_INTERNET_EXTENDED_ERROR
, "size welcome.msg" },
729 { FALSE
, ERROR_INTERNET_EXTENDED_ERROR
, "size welcome.msg " },
730 { TRUE
, ERROR_SUCCESS
, "size welcome.msg" },
731 { FALSE
, ERROR_INTERNET_EXTENDED_ERROR
, "pwd welcome.msg" },
732 { TRUE
, ERROR_SUCCESS
, "pwd" }
737 win_skip("FtpCommandA() is not available. Skipping the Ftp command tests\n");
741 for (i
= 0; i
< ARRAY_SIZE(command_test
); i
++)
743 DWORD size
, orig_size
;
746 SetLastError(0xdeadbeef);
747 ret
= pFtpCommandA(hFtp
, FALSE
, FTP_TRANSFER_TYPE_ASCII
, command_test
[i
].cmd
, 0, NULL
);
748 error
= GetLastError();
750 ok(ret
== command_test
[i
].ret
, "%d: expected FtpCommandA to %s\n", i
, command_test
[i
].ret
? "succeed" : "fail");
751 ok(error
== command_test
[i
].error
, "%d: expected error %u, got %u\n", i
, command_test
[i
].error
, error
);
754 ret
= InternetGetLastResponseInfoA(&error
, NULL
, NULL
);
755 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
, "%d: ret %d, lasterr %d\n", i
, ret
, GetLastError());
756 ret
= InternetGetLastResponseInfoA(NULL
, NULL
, &size
);
757 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
, "%d: ret %d, lasterr %d\n", i
, ret
, GetLastError());
760 ret
= InternetGetLastResponseInfoA(&error
, NULL
, &size
);
761 ok((ret
&& size
== 0) || (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
), "%d: got ret %d, size %d, lasterr %d\n", i
, ret
, size
, GetLastError());
762 /* Positive size, NULL buffer */
764 ret
= InternetGetLastResponseInfoA(&error
, NULL
, &size
);
765 ok((ret
&& size
== 0) || (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
), "%d: got ret %d, size %u, lasterr %d\n", i
, ret
, size
, GetLastError());
766 /* When buffer is 1 char too short, it succeeds but trims the string: */
768 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
769 ok(buffer
!= NULL
, "%d: no memory\n", i
);
770 ret
= InternetGetLastResponseInfoA(&error
, buffer
, &size
);
771 ok(ret
, "%d: got ret %d\n", i
, ret
);
772 ok(orig_size
== 0 ? size
== 0 : size
== orig_size
- 1, "%d: got orig_size %d, size %d\n", i
, orig_size
, size
);
773 ok(size
== 0 || strlen(buffer
) == size
, "%d: size %d, buffer size %d\n", i
, size
, size
? strlen(buffer
) : 0);
774 HeapFree(GetProcessHeap(), 0, buffer
);
775 /* Long enough buffer */
776 buffer
= HeapAlloc(GetProcessHeap(), 0, ++size
);
777 ok(buffer
!= NULL
, "%d: no memory\n", i
);
778 ret
= InternetGetLastResponseInfoA(&error
, buffer
, &size
);
779 ok(ret
, "%d: got ret %d\n", i
, ret
);
780 ok(size
== 0 || strlen(buffer
) == size
, "%d: size %d, buffer size %d\n", i
, size
, size
? strlen(buffer
) : 0);
781 had_error_zero
|= (error
== 0);
782 had_error_zero_size_positive
|= (error
== 0 && size
> 0);
783 HeapFree(GetProcessHeap(), 0, buffer
);
786 ok(!had_error_zero
|| had_error_zero_size_positive
, "never observed error 0 with positive size\n");
789 static void test_find_first_file(HINTERNET hFtp
, HINTERNET hConnect
)
791 WIN32_FIND_DATAA findData
;
798 /* NULL as the search file ought to return the first file in the directory */
799 SetLastError(0xdeadbeef);
800 hSearch
= FtpFindFirstFileA(hFtp
, NULL
, &findData
, 0, 0);
801 ok ( hSearch
!= NULL
, "Expected FtpFindFirstFileA to pass\n" );
803 /* This should fail as the previous handle wasn't closed */
804 SetLastError(0xdeadbeef);
805 hSearch2
= FtpFindFirstFileA(hFtp
, "welcome.msg", &findData
, 0, 0);
806 todo_wine
ok ( hSearch2
== NULL
, "Expected FtpFindFirstFileA to fail\n" );
807 todo_wine
ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS
,
808 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError() );
809 InternetCloseHandle(hSearch2
); /* Just in case */
811 InternetCloseHandle(hSearch
);
813 /* Try a valid filename in a subdirectory search */
814 SetLastError(0xdeadbeef);
815 hSearch
= FtpFindFirstFileA(hFtp
, "pub/wine", &findData
, 0, 0);
816 ok( hSearch
!= NULL
, "Expected FtpFindFirstFileA to pass\n" );
817 InternetCloseHandle(hSearch
);
819 /* Try a valid filename in a subdirectory wildcard search */
820 SetLastError(0xdeadbeef);
821 hSearch
= FtpFindFirstFileA(hFtp
, "pub/w*", &findData
, 0, 0);
822 ok( hSearch
!= NULL
, "Expected FtpFindFirstFileA to pass\n" );
823 InternetCloseHandle(hSearch
);
825 /* Try an invalid wildcard search */
826 SetLastError(0xdeadbeef);
827 hSearch
= FtpFindFirstFileA(hFtp
, "*/w*", &findData
, 0, 0);
828 ok ( hSearch
== NULL
, "Expected FtpFindFirstFileA to fail\n" );
829 InternetCloseHandle(hSearch
); /* Just in case */
831 /* change current directory, and repeat those tests - this shows
832 * that the search string is interpreted as relative directory. */
833 success
= FtpSetCurrentDirectoryA(hFtp
, "pub");
834 ok( success
, "Expected FtpSetCurrentDirectory to succeed\n" );
836 SetLastError(0xdeadbeef);
837 hSearch
= FtpFindFirstFileA(hFtp
, "wine", &findData
, 0, 0);
838 ok( hSearch
!= NULL
, "Expected FtpFindFirstFileA to pass\n" );
839 InternetCloseHandle(hSearch
);
841 SetLastError(0xdeadbeef);
842 hSearch
= FtpFindFirstFileA(hFtp
, "w*", &findData
, 0, 0);
843 ok( hSearch
!= NULL
, "Expected FtpFindFirstFileA to pass\n" );
844 InternetCloseHandle(hSearch
);
846 success
= FtpSetCurrentDirectoryA(hFtp
, "..");
847 ok( success
, "Expected FtpSetCurrentDirectory to succeed\n" );
849 /* Try FindFirstFile between FtpOpenFile and InternetCloseHandle */
850 SetLastError(0xdeadbeef);
851 hOpenFile
= FtpOpenFileA(hFtp
, "welcome.msg", GENERIC_READ
, FTP_TRANSFER_TYPE_ASCII
, 0);
852 ok ( hOpenFile
!= NULL
, "Expected FtpOpenFileA to succeed\n" );
853 ok ( GetLastError() == ERROR_SUCCESS
||
854 broken(GetLastError() == ERROR_FILE_NOT_FOUND
), /* Win98 */
855 "Expected ERROR_SUCCESS, got %u\n", GetLastError() );
857 /* This should fail as the OpenFile handle wasn't closed */
858 SetLastError(0xdeadbeef);
859 hSearch
= FtpFindFirstFileA(hFtp
, "welcome.msg", &findData
, 0, 0);
860 error
= GetLastError();
861 ok ( hSearch
== NULL
|| broken(hSearch
!= NULL
), /* win2k */
862 "Expected FtpFindFirstFileA to fail\n" );
864 ok ( error
== ERROR_FTP_TRANSFER_IN_PROGRESS
|| broken(error
== ERROR_INTERNET_EXTENDED_ERROR
),
865 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error
);
868 ok( error
== ERROR_SUCCESS
, "wrong error %u on success\n", GetLastError() );
869 InternetCloseHandle(hSearch
);
872 InternetCloseHandle(hOpenFile
);
874 /* Test using a nonexistent filename */
875 SetLastError(0xdeadbeef);
876 hSearch
= FtpFindFirstFileA(hFtp
, "this_file_should_not_exist", &findData
, 0, 0);
877 ok ( hSearch
== NULL
, "Expected FtpFindFirstFileA to fail\n" );
878 todo_wine
ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR
,
879 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError() );
880 InternetCloseHandle(hSearch
); /* Just in case */
882 /* Test using a nonexistent filename and a wildcard */
883 SetLastError(0xdeadbeef);
884 hSearch
= FtpFindFirstFileA(hFtp
, "this_file_should_not_exist*", &findData
, 0, 0);
885 ok ( hSearch
== NULL
, "Expected FtpFindFirstFileA to fail\n" );
886 todo_wine
ok ( GetLastError() == ERROR_NO_MORE_FILES
,
887 "Expected ERROR_NO_MORE_FILES, got %d\n", GetLastError() );
888 InternetCloseHandle(hSearch
); /* Just in case */
890 /* Test using an invalid handle type */
891 SetLastError(0xdeadbeef);
892 hSearch
= FtpFindFirstFileA(hConnect
, "welcome.msg", &findData
, 0, 0);
893 ok ( hSearch
== NULL
, "Expected FtpFindFirstFileA to fail\n" );
894 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
895 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError() );
896 InternetCloseHandle(hSearch
); /* Just in case */
899 static void test_get_current_dir(HINTERNET hFtp
, HINTERNET hConnect
)
902 DWORD dwCurrentDirectoryLen
= MAX_PATH
;
903 CHAR lpszCurrentDirectory
[MAX_PATH
];
907 win_skip("FtpCommandA() is not available. Skipping the Ftp get_current_dir tests\n");
911 /* change directories to get a more interesting pwd */
912 bRet
= pFtpCommandA(hFtp
, FALSE
, FTP_TRANSFER_TYPE_ASCII
, "CWD pub/", 0, NULL
);
915 skip("Failed to change directories in test_get_current_dir(HINTERNET hFtp).\n");
919 /* test with all NULL arguments */
920 SetLastError(0xdeadbeef);
921 bRet
= FtpGetCurrentDirectoryA( NULL
, NULL
, 0 );
922 ok ( bRet
== FALSE
, "Expected FtpGetCurrentDirectoryA to fail\n" );
923 ok ( GetLastError() == ERROR_INVALID_HANDLE
, "Expected ERROR_INVALID_HANDLE, got: %d\n", GetLastError());
925 /* test with NULL parameters instead of expected LPSTR/LPDWORD */
926 SetLastError(0xdeadbeef);
927 bRet
= FtpGetCurrentDirectoryA( hFtp
, NULL
, 0 );
928 ok ( bRet
== FALSE
, "Expected FtpGetCurrentDirectoryA to fail\n" );
929 ok ( GetLastError() == ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got: %d\n", GetLastError());
931 /* test with no valid handle and valid parameters */
932 SetLastError(0xdeadbeef);
933 bRet
= FtpGetCurrentDirectoryA( NULL
, lpszCurrentDirectory
, &dwCurrentDirectoryLen
);
934 ok ( bRet
== FALSE
, "Expected FtpGetCurrentDirectoryA to fail\n" );
935 ok ( GetLastError() == ERROR_INVALID_HANDLE
, "Expected ERROR_INVALID_HANDLE, got: %d\n", GetLastError());
937 /* test with invalid dwCurrentDirectory and all other parameters correct */
938 SetLastError(0xdeadbeef);
939 bRet
= FtpGetCurrentDirectoryA( hFtp
, lpszCurrentDirectory
, 0 );
940 ok ( bRet
== FALSE
, "Expected FtpGetCurrentDirectoryA to fail\n" );
941 ok ( GetLastError() == ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got: %d\n", GetLastError());
943 /* test with invalid lpszCurrentDirectory and all other parameters correct */
944 SetLastError(0xdeadbeef);
945 bRet
= FtpGetCurrentDirectoryA( hFtp
, NULL
, &dwCurrentDirectoryLen
);
946 ok ( bRet
== FALSE
, "Expected FtpGetCurrentDirectoryA to fail\n" );
947 ok ( GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Expected ERROR_INSUFFICIENT_BUFFER, got: %d\n", GetLastError());
949 /* test to show it checks the handle type */
950 SetLastError(0xdeadbeef);
951 bRet
= FtpGetCurrentDirectoryA( hConnect
, lpszCurrentDirectory
, &dwCurrentDirectoryLen
);
952 ok ( bRet
== FALSE
, "Expected FtpGetCurrentDirectoryA to fail\n" );
953 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
954 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got: %d\n", GetLastError());
956 /* test for the current directory with legitimate values */
957 SetLastError(0xdeadbeef);
958 bRet
= FtpGetCurrentDirectoryA( hFtp
, lpszCurrentDirectory
, &dwCurrentDirectoryLen
);
959 ok ( bRet
== TRUE
, "Expected FtpGetCurrentDirectoryA to pass\n" );
960 ok ( !strcmp(lpszCurrentDirectory
, "/pub"), "Expected returned value \"%s\" to match \"/pub\"\n", lpszCurrentDirectory
);
961 ok ( GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got: %d\n", GetLastError());
963 /* test for the current directory with a size only large enough to
964 * fit the string and not the null terminating character */
965 SetLastError(0xdeadbeef);
966 dwCurrentDirectoryLen
= 4;
967 lpszCurrentDirectory
[4] = 'a'; /* set position 4 of the array to something else to make sure a leftover \0 isn't fooling the test */
968 bRet
= FtpGetCurrentDirectoryA( hFtp
, lpszCurrentDirectory
, &dwCurrentDirectoryLen
);
969 ok ( bRet
== FALSE
, "Expected FtpGetCurrentDirectoryA to fail\n");
970 ok ( strcmp(lpszCurrentDirectory
, "/pub"), "Expected returned value \"%s\" to not match \"/pub\"\n", lpszCurrentDirectory
);
971 ok ( GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Expected ERROR_INSUFFICIENT_BUFFER, got: %d\n", GetLastError());
973 /* test for the current directory with a size large enough to store
974 * the expected string as well as the null terminating character */
975 SetLastError(0xdeadbeef);
976 dwCurrentDirectoryLen
= 5;
977 bRet
= FtpGetCurrentDirectoryA( hFtp
, lpszCurrentDirectory
, &dwCurrentDirectoryLen
);
978 ok ( bRet
== TRUE
, "Expected FtpGetCurrentDirectoryA to pass\n");
979 ok ( !strcmp(lpszCurrentDirectory
, "/pub"), "Expected returned value \"%s\" to match \"/pub\"\n", lpszCurrentDirectory
);
980 ok ( GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got: %d\n", GetLastError());
983 static void WINAPI
status_callback(HINTERNET handle
, DWORD_PTR ctx
, DWORD status
, LPVOID info
, DWORD info_len
)
987 case INTERNET_STATUS_RESOLVING_NAME
:
988 case INTERNET_STATUS_NAME_RESOLVED
:
989 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
990 case INTERNET_STATUS_CONNECTED_TO_SERVER
:
991 trace("%p %lx %u %s %u\n", handle
, ctx
, status
, (char *)info
, info_len
);
998 static void test_status_callbacks(HINTERNET hInternet
)
1000 INTERNET_STATUS_CALLBACK cb
;
1004 cb
= pInternetSetStatusCallbackA(hInternet
, status_callback
);
1005 ok(cb
== NULL
, "expected NULL got %p\n", cb
);
1007 hFtp
= InternetConnectA(hInternet
, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT
, "anonymous", "IEUser@",
1008 INTERNET_SERVICE_FTP
, INTERNET_FLAG_PASSIVE
, 1);
1011 skip("No ftp connection could be made to ftp.winehq.org %u\n", GetLastError());
1015 ret
= InternetCloseHandle(hFtp
);
1016 ok(ret
, "InternetCloseHandle failed %u\n", GetLastError());
1018 cb
= pInternetSetStatusCallbackA(hInternet
, NULL
);
1019 ok(cb
== status_callback
, "expected check_status got %p\n", cb
);
1025 HANDLE hInternet
, hFtp
, hHttp
;
1027 hWininet
= GetModuleHandleA("wininet.dll");
1029 if(!GetProcAddress(hWininet
, "InternetGetCookieExW")) {
1030 win_skip("Too old IE (older than 6.0)\n");
1034 pFtpCommandA
= (void*)GetProcAddress(hWininet
, "FtpCommandA");
1035 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hWininet
, "InternetSetStatusCallbackA");
1037 SetLastError(0xdeadbeef);
1038 hInternet
= InternetOpenA("winetest", 0, NULL
, NULL
, 0);
1039 ok(hInternet
!= NULL
, "InternetOpen failed: %u\n", GetLastError());
1041 hFtp
= InternetConnectA(hInternet
, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT
, "anonymous", "IEUser@", INTERNET_SERVICE_FTP
, INTERNET_FLAG_PASSIVE
, 0);
1044 InternetCloseHandle(hInternet
);
1045 skip("No ftp connection could be made to ftp.winehq.org\n");
1048 hHttp
= InternetConnectA(hInternet
, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1051 InternetCloseHandle(hFtp
);
1052 InternetCloseHandle(hInternet
);
1053 skip("No http connection could be made to www.winehq.org\n");
1057 /* The first call should always be a proper InternetOpen, if not
1058 * several calls will return ERROR_INTERNET_NOT_INITIALIZED when
1059 * all parameters are correct but no session handle is given. Whereas
1060 * the same call will return ERROR_INVALID_HANDLE if an InternetOpen
1062 * The following test will show that behaviour, where the tests inside
1063 * the other sub-tests will show the other situation.
1065 test_getfile_no_open();
1066 test_connect(hInternet
);
1067 test_createdir(hFtp
, hHttp
);
1068 test_deletefile(hFtp
, hHttp
);
1069 test_getfile(hFtp
, hHttp
);
1070 test_openfile(hFtp
, hHttp
);
1071 test_putfile(hFtp
, hHttp
);
1072 test_removedir(hFtp
, hHttp
);
1073 test_renamefile(hFtp
, hHttp
);
1075 test_find_first_file(hFtp
, hHttp
);
1076 test_get_current_dir(hFtp
, hHttp
);
1077 test_status_callbacks(hInternet
);
1079 InternetCloseHandle(hHttp
);
1080 InternetCloseHandle(hFtp
);
1081 InternetCloseHandle(hInternet
);