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", 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
= 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());
116 SetLastError(0xdeadbeef);
117 hFtp
= InternetConnectA(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 bRet
= FtpGetFileA(hFtp
, "welcome.msg", "should_be_existing_non_deadbeef", FALSE
, 0, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
261 ok ( bRet
== TRUE
, "Expected FtpGetFileA to succeed\n");
262 ok (GetFileAttributesA("should_be_existing_non_deadbeef") != INVALID_FILE_ATTRIBUTES
,
263 "Local file should have been created\n");
264 DeleteFileA("should_be_existing_non_deadbeef");
266 /* Illegal condition flags */
267 SetLastError(0xdeadbeef);
268 bRet
= FtpGetFileA(hFtp
, "welcome.msg", "should_be_non_existing_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, 0xffffffff, 0);
269 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
270 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR
|| GetLastError() == ERROR_INVALID_PARAMETER
,
271 "Expected ERROR_INTERNET_EXTENDED_ERROR or ERROR_INVALID_PARAMETER (win98), got %d\n", GetLastError());
272 ok (GetFileAttributesA("should_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES
,
273 "Local file should not have been created\n");
274 DeleteFileA("should_be_non_existing_deadbeef");
276 /* Remote file doesn't exist (and local doesn't exist as well) */
277 SetLastError(0xdeadbeef);
278 bRet
= FtpGetFileA(hFtp
, "should_be_non_existing_deadbeef", "should_also_be_non_existing_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
279 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
280 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR
,
281 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
282 /* Currently Wine always creates the local file (even on failure) which is not correct, hence the test */
283 ok (GetFileAttributesA("should_also_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES
,
284 "Local file should not have been created\n");
286 DeleteFileA("should_also_be_non_existing_deadbeef");
288 /* Same call as the previous but now the local file does exists. Windows just removes the file if the call fails
289 * even if the local existed before!
292 /* Create a temporary local file */
293 SetLastError(0xdeadbeef);
294 hFile
= CreateFileA("should_also_be_non_existing_deadbeef", GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
295 ok ( hFile
!= NULL
, "Error creating a local file : %d\n", GetLastError());
297 SetLastError(0xdeadbeef);
298 bRet
= FtpGetFileA(hFtp
, "should_be_non_existing_deadbeef", "should_also_be_non_existing_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
299 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
300 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR
,
301 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
302 /* Currently Wine always creates the local file (even on failure) which is not correct, hence the test */
303 ok (GetFileAttributesA("should_also_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES
,
304 "Local file should not have been created\n");
306 DeleteFileA("should_also_be_non_existing_deadbeef");
308 /* This one should succeed */
309 SetLastError(0xdeadbeef);
310 bRet
= FtpGetFileA(hFtp
, "welcome.msg", "should_be_existing_non_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
311 ok ( bRet
== TRUE
, "Expected FtpGetFileA to fail\n");
312 ok ( GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
314 if (GetFileAttributesA("should_be_existing_non_deadbeef") != INVALID_FILE_ATTRIBUTES
)
316 /* Should succeed as fFailIfExists is set to FALSE (meaning don't fail if local file exists) */
317 SetLastError(0xdeadbeef);
318 bRet
= FtpGetFileA(hFtp
, "welcome.msg", "should_be_non_existing_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
319 ok ( bRet
== TRUE
, "Expected FtpGetFileA to succeed\n");
320 ok ( GetLastError() == ERROR_SUCCESS
,
321 "Expected ERROR_SUCCESS, got %d\n", GetLastError());
323 /* Should fail as fFailIfExists is set to TRUE */
324 SetLastError(0xdeadbeef);
325 bRet
= FtpGetFileA(hFtp
, "welcome.msg", "should_be_non_existing_deadbeef", TRUE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
326 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
327 ok ( GetLastError() == ERROR_FILE_EXISTS
,
328 "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
330 /* Prove that the existence of the local file is checked first (or at least reported last) */
331 SetLastError(0xdeadbeef);
332 bRet
= FtpGetFileA(hFtp
, "should_be_non_existing_deadbeef", "should_be_non_existing_deadbeef", TRUE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
333 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
334 ok ( GetLastError() == ERROR_FILE_EXISTS
,
335 "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
337 DeleteFileA("should_be_existing_non_deadbeef");
340 /* Test to show the parameter checking order depends on the Windows version */
341 SetLastError(0xdeadbeef);
342 bRet
= FtpGetFileA(hConnect
, NULL
, "should_be_non_existing_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
343 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
344 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
||
345 GetLastError() == ERROR_INVALID_PARAMETER
,
346 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE (win98) or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
348 /* Test to show that 'session handle type' is checked before 'condition flags' */
349 SetLastError(0xdeadbeef);
350 bRet
= FtpGetFileA(hConnect
, "welcome.msg", "should_be_non_existing_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, 5, 0);
351 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
352 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
353 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
355 SetLastError(0xdeadbeef);
356 bRet
= FtpGetFileA(hConnect
, "should_be_non_existing_deadbeef", "should_be_non_existing_deadbeef", TRUE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
357 ok ( bRet
== FALSE
, "Expected FtpGetFileA to fail\n");
358 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
359 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
362 static void trace_extended_error(DWORD error
)
364 DWORD code
, buflen
= 0;
366 if (error
!= ERROR_INTERNET_EXTENDED_ERROR
) return;
367 if (!InternetGetLastResponseInfoA(&code
, NULL
, &buflen
) && GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
369 char *text
= HeapAlloc(GetProcessHeap(), 0, ++buflen
);
370 InternetGetLastResponseInfoA(&code
, text
, &buflen
);
371 trace("%u %s\n", code
, text
);
372 HeapFree(GetProcessHeap(), 0, text
);
376 static void test_openfile(HINTERNET hFtp
, HINTERNET hConnect
)
380 /* Invalid internet handle, the rest are valid parameters */
381 SetLastError(0xdeadbeef);
382 hOpenFile
= FtpOpenFileA(NULL
, "welcome.msg", GENERIC_READ
, FTP_TRANSFER_TYPE_ASCII
, 0);
383 ok ( !hOpenFile
, "Expected FtpOpenFileA to fail\n");
384 ok ( GetLastError() == ERROR_INVALID_HANDLE
,
385 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
386 InternetCloseHandle(hOpenFile
); /* Just in case */
389 SetLastError(0xdeadbeef);
390 hOpenFile
= FtpOpenFileA(hFtp
, NULL
, GENERIC_READ
, FTP_TRANSFER_TYPE_ASCII
, 0);
391 ok ( !hOpenFile
, "Expected FtpOpenFileA to fail\n");
392 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
393 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
394 InternetCloseHandle(hOpenFile
); /* Just in case */
396 /* Illegal access flags */
397 SetLastError(0xdeadbeef);
398 hOpenFile
= FtpOpenFileA(hFtp
, "welcome.msg", 0, FTP_TRANSFER_TYPE_ASCII
, 0);
399 ok ( !hOpenFile
, "Expected FtpOpenFileA to fail\n");
400 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
401 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
402 InternetCloseHandle(hOpenFile
); /* Just in case */
404 /* Illegal combination of access flags */
405 SetLastError(0xdeadbeef);
406 hOpenFile
= FtpOpenFileA(hFtp
, "welcome.msg", GENERIC_READ
|GENERIC_WRITE
, FTP_TRANSFER_TYPE_ASCII
, 0);
407 ok ( !hOpenFile
, "Expected FtpOpenFileA to fail\n");
408 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
409 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
410 InternetCloseHandle(hOpenFile
); /* Just in case */
412 /* Illegal condition flags */
413 SetLastError(0xdeadbeef);
414 hOpenFile
= FtpOpenFileA(hFtp
, "welcome.msg", GENERIC_READ
, 0xffffffff, 0);
415 ok ( !hOpenFile
, "Expected FtpOpenFileA to fail\n");
416 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR
|| GetLastError() == ERROR_INVALID_PARAMETER
,
417 "Expected ERROR_INTERNET_EXTENDED_ERROR or ERROR_INVALID_PARAMETER (win98), got %d\n", GetLastError());
418 InternetCloseHandle(hOpenFile
); /* Just in case */
420 SetLastError(0xdeadbeef);
421 hOpenFile
= FtpOpenFileA(hFtp
, "welcome.msg", GENERIC_READ
, FTP_TRANSFER_TYPE_ASCII
, 0);
422 ok ( hOpenFile
!= NULL
, "Expected FtpOpenFileA to succeed\n");
423 ok ( GetLastError() == ERROR_SUCCESS
||
424 broken(GetLastError() == ERROR_FILE_NOT_FOUND
), /* Win98 */
425 "Expected ERROR_SUCCESS, got %u\n", GetLastError());
431 HINTERNET hOpenFile2
;
434 /* We have a handle so all ftp calls should fail (TODO: Put all ftp-calls in here) */
435 SetLastError(0xdeadbeef);
436 bRet
= FtpCreateDirectoryA(hFtp
, "new_directory_deadbeef");
437 error
= GetLastError();
438 ok ( bRet
== FALSE
, "Expected FtpCreateDirectoryA to fail\n");
439 ok ( error
== ERROR_FTP_TRANSFER_IN_PROGRESS
|| broken(error
== ERROR_INTERNET_EXTENDED_ERROR
),
440 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error
);
441 trace_extended_error(error
);
443 SetLastError(0xdeadbeef);
444 bRet
= FtpDeleteFileA(hFtp
, "non_existent_file_deadbeef");
445 error
= GetLastError();
446 ok ( bRet
== FALSE
, "Expected FtpDeleteFileA to fail\n");
447 ok ( error
== ERROR_FTP_TRANSFER_IN_PROGRESS
|| broken(error
== ERROR_INTERNET_EXTENDED_ERROR
),
448 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error
);
449 trace_extended_error(error
);
451 SetLastError(0xdeadbeef);
452 bRet
= FtpGetFileA(hFtp
, "welcome.msg", "should_be_non_existing_deadbeef", FALSE
, FILE_ATTRIBUTE_NORMAL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
453 error
= GetLastError();
454 ok ( bRet
== FALSE
|| broken(bRet
== TRUE
), "Expected FtpGetFileA to fail\n");
455 ok ( error
== ERROR_FTP_TRANSFER_IN_PROGRESS
|| broken(error
== ERROR_SUCCESS
),
456 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error
);
457 DeleteFileA("should_be_non_existing_deadbeef"); /* Just in case */
459 SetLastError(0xdeadbeef);
460 hOpenFile2
= FtpOpenFileA(hFtp
, "welcome.msg", GENERIC_READ
, FTP_TRANSFER_TYPE_ASCII
, 0);
461 error
= GetLastError();
462 ok ( bRet
== FALSE
|| broken(bRet
== TRUE
), "Expected FtpOpenFileA to fail\n");
463 ok ( error
== ERROR_FTP_TRANSFER_IN_PROGRESS
|| broken(error
== ERROR_SUCCESS
),
464 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error
);
465 InternetCloseHandle(hOpenFile2
); /* Just in case */
467 /* Create a temporary local file */
468 SetLastError(0xdeadbeef);
469 hFile
= CreateFileA("now_existing_local", GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
470 ok ( hFile
!= NULL
, "Error creating a local file : %d\n", GetLastError());
472 SetLastError(0xdeadbeef);
473 bRet
= FtpPutFileA(hFtp
, "now_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN
, 0);
474 error
= GetLastError();
475 ok ( bRet
== FALSE
, "Expected FtpPutFileA to fail\n");
476 ok ( error
== ERROR_FTP_TRANSFER_IN_PROGRESS
|| broken(error
== ERROR_INTERNET_EXTENDED_ERROR
),
477 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error
);
478 DeleteFileA("now_existing_local");
480 SetLastError(0xdeadbeef);
481 bRet
= FtpRemoveDirectoryA(hFtp
, "should_be_non_existing_deadbeef_dir");
482 error
= GetLastError();
483 ok ( bRet
== FALSE
, "Expected FtpRemoveDirectoryA to fail\n");
484 ok ( error
== ERROR_FTP_TRANSFER_IN_PROGRESS
|| broken(error
== ERROR_INTERNET_EXTENDED_ERROR
),
485 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error
);
487 SetLastError(0xdeadbeef);
488 bRet
= FtpRenameFileA(hFtp
, "should_be_non_existing_deadbeef", "new");
489 error
= GetLastError();
490 ok ( bRet
== FALSE
, "Expected FtpRenameFileA to fail\n");
491 ok ( error
== ERROR_FTP_TRANSFER_IN_PROGRESS
|| broken(error
== ERROR_INTERNET_EXTENDED_ERROR
),
492 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error
);
495 InternetCloseHandle(hOpenFile
);
497 /* One small test to show that handle type is checked before parameters */
498 SetLastError(0xdeadbeef);
499 hOpenFile
= FtpOpenFileA(hConnect
, "welcome.msg", GENERIC_READ
, 5, 0);
500 ok ( !hOpenFile
, "Expected FtpOpenFileA to fail\n");
501 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
502 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
503 InternetCloseHandle(hOpenFile
); /* Just in case */
505 SetLastError(0xdeadbeef);
506 hOpenFile
= FtpOpenFileA(hConnect
, "welcome.msg", GENERIC_READ
, FTP_TRANSFER_TYPE_ASCII
, 0);
507 ok ( hOpenFile
== NULL
, "Expected FtpOpenFileA to fail\n");
508 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
509 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
511 InternetCloseHandle(hOpenFile
); /* Just in case */
514 static void test_putfile(HINTERNET hFtp
, HINTERNET hConnect
)
519 /* The order of checking is:
521 * All parameters except 'session handle' and 'condition flags'
523 * Session handle type
527 /* Test to show the parameter checking order depends on the Windows version */
528 SetLastError(0xdeadbeef);
529 bRet
= FtpPutFileA(NULL
, NULL
, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN
, 0);
530 ok ( bRet
== FALSE
, "Expected FtpPutFileA to fail\n");
531 ok ( GetLastError() == ERROR_INVALID_HANDLE
||
532 GetLastError() == ERROR_INVALID_PARAMETER
,
533 "Expected ERROR_INVALID_HANDLE (win98) or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
535 /* Test to show session handle is checked before 'condition flags' */
536 SetLastError(0xdeadbeef);
537 bRet
= FtpPutFileA(NULL
, "non_existing_local", "non_existing_remote", 5, 0);
538 ok ( bRet
== FALSE
, "Expected FtpPutFileA to fail\n");
539 ok ( GetLastError() == ERROR_INVALID_HANDLE
,
540 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
543 DeleteFileA("non_existing_local");
545 /* No local file given */
546 SetLastError(0xdeadbeef);
547 bRet
= FtpPutFileA(hFtp
, NULL
, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN
, 0);
548 ok ( bRet
== FALSE
, "Expected FtpPutFileA to fail\n");
549 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
550 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
552 /* No remote file given */
553 SetLastError(0xdeadbeef);
554 bRet
= FtpPutFileA(hFtp
, "non_existing_local", NULL
, FTP_TRANSFER_TYPE_UNKNOWN
, 0);
555 ok ( bRet
== FALSE
, "Expected FtpPutFileA to fail\n");
556 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
557 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
559 /* Illegal condition flags */
560 SetLastError(0xdeadbeef);
561 bRet
= FtpPutFileA(hFtp
, "non_existing_local", "non_existing_remote", 5, 0);
562 ok ( bRet
== FALSE
, "Expected FtpPutFileA to fail\n");
563 ok ( GetLastError() == ERROR_FILE_NOT_FOUND
|| GetLastError() == ERROR_INVALID_PARAMETER
,
564 "Expected ERROR_FILE_NOT_FOUND or ERROR_INVALID_PARAMETER (win98), got %d\n", GetLastError());
566 /* Parameters are OK but local file doesn't exist */
567 SetLastError(0xdeadbeef);
568 bRet
= FtpPutFileA(hFtp
, "non_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN
, 0);
569 ok ( bRet
== FALSE
, "Expected FtpPutFileA to fail\n");
570 ok ( GetLastError() == ERROR_FILE_NOT_FOUND
,
571 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
573 /* Create a temporary local file */
574 SetLastError(0xdeadbeef);
575 hFile
= CreateFileA("now_existing_local", GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
576 ok ( hFile
!= NULL
, "Error creating a local file : %d\n", GetLastError());
579 /* Local file exists but we shouldn't be allowed to 'put' the file */
580 SetLastError(0xdeadbeef);
581 bRet
= FtpPutFileA(hFtp
, "now_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN
, 0);
582 ok ( bRet
== FALSE
, "Expected FtpPutFileA to fail\n");
583 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR
,
584 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
586 DeleteFileA("now_existing_local");
588 /* Test to show the parameter checking order depends on the Windows version */
589 SetLastError(0xdeadbeef);
590 bRet
= FtpPutFileA(hConnect
, NULL
, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN
, 0);
591 ok ( bRet
== FALSE
, "Expected FtpPutFileA to fail\n");
592 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
||
593 GetLastError() == ERROR_INVALID_PARAMETER
,
594 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE (win98) or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
596 /* Test to show that 'session handle type' is checked before 'condition flags' */
597 SetLastError(0xdeadbeef);
598 bRet
= FtpPutFileA(hConnect
, "non_existing_local", "non_existing_remote", 5, 0);
599 ok ( bRet
== FALSE
, "Expected FtpPutFileA to fail\n");
600 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
601 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
603 SetLastError(0xdeadbeef);
604 bRet
= FtpPutFileA(hConnect
, "non_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN
, 0);
605 ok ( bRet
== FALSE
, "Expected FtpPutFileA to fail\n");
606 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
607 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
610 static void test_removedir(HINTERNET hFtp
, HINTERNET hConnect
)
614 /* Invalid internet handle, the other is a valid parameter */
615 SetLastError(0xdeadbeef);
616 bRet
= FtpRemoveDirectoryA(NULL
, "should_be_non_existing_deadbeef_dir");
617 ok ( bRet
== FALSE
, "Expected FtpRemoveDirectoryA to fail\n");
618 ok ( GetLastError() == ERROR_INVALID_HANDLE
,
619 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
621 /* No remote directory given */
622 SetLastError(0xdeadbeef);
623 bRet
= FtpRemoveDirectoryA(hFtp
, NULL
);
624 ok ( bRet
== FALSE
, "Expected FtpRemoveDirectoryA to fail\n");
625 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
626 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
628 /* Remote directory doesn't exist */
629 SetLastError(0xdeadbeef);
630 bRet
= FtpRemoveDirectoryA(hFtp
, "should_be_non_existing_deadbeef_dir");
631 ok ( bRet
== FALSE
, "Expected FtpRemoveDirectoryA to fail\n");
632 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR
,
633 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
635 /* We shouldn't be allowed to remove that directory */
636 SetLastError(0xdeadbeef);
637 bRet
= FtpRemoveDirectoryA(hFtp
, "pub");
638 ok ( bRet
== FALSE
, "Expected FtpRemoveDirectoryA to fail\n");
639 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR
,
640 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
642 /* One small test to show that handle type is checked before parameters */
643 SetLastError(0xdeadbeef);
644 bRet
= FtpRemoveDirectoryA(hConnect
, NULL
);
645 ok ( bRet
== FALSE
, "Expected FtpRemoveDirectoryA to fail\n");
646 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
647 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
649 SetLastError(0xdeadbeef);
650 bRet
= FtpRemoveDirectoryA(hConnect
, "should_be_non_existing_deadbeef_dir");
651 ok ( bRet
== FALSE
, "Expected FtpRemoveDirectoryA to fail\n");
652 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
653 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
656 static void test_renamefile(HINTERNET hFtp
, HINTERNET hConnect
)
660 /* Invalid internet handle, the rest are valid parameters */
661 SetLastError(0xdeadbeef);
662 bRet
= FtpRenameFileA(NULL
, "should_be_non_existing_deadbeef", "new");
663 ok ( bRet
== FALSE
, "Expected FtpRenameFileA to fail\n");
664 ok ( GetLastError() == ERROR_INVALID_HANDLE
,
665 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
667 /* No 'existing' file */
668 SetLastError(0xdeadbeef);
669 bRet
= FtpRenameFileA(hFtp
, NULL
, "new");
670 ok ( bRet
== FALSE
, "Expected FtpRenameFileA to fail\n");
671 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
672 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
675 SetLastError(0xdeadbeef);
676 bRet
= FtpRenameFileA(hFtp
, "should_be_non_existing_deadbeef", NULL
);
677 ok ( bRet
== FALSE
, "Expected FtpRenameFileA to fail\n");
678 ok ( GetLastError() == ERROR_INVALID_PARAMETER
,
679 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
681 /* Existing file shouldn't be there */
682 SetLastError(0xdeadbeef);
683 bRet
= FtpRenameFileA(hFtp
, "should_be_non_existing_deadbeef", "new");
684 ok ( bRet
== FALSE
, "Expected FtpRenameFileA to fail\n");
685 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR
,
686 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
688 /* One small test to show that handle type is checked before parameters */
689 SetLastError(0xdeadbeef);
690 bRet
= FtpRenameFileA(hConnect
, "should_be_non_existing_deadbeef", NULL
);
691 ok ( bRet
== FALSE
, "Expected FtpRenameFileA to fail\n");
692 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
693 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
695 SetLastError(0xdeadbeef);
696 bRet
= FtpRenameFileA(hConnect
, "should_be_non_existing_deadbeef", "new");
697 ok ( bRet
== FALSE
, "Expected FtpRenameFileA to fail\n");
698 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
699 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
702 static void test_command(HINTERNET hFtp
, HINTERNET hConnect
)
715 { FALSE
, ERROR_INVALID_PARAMETER
, NULL
},
716 { FALSE
, ERROR_INVALID_PARAMETER
, "" },
717 { FALSE
, ERROR_INTERNET_EXTENDED_ERROR
, "HELO" },
718 { FALSE
, ERROR_INTERNET_EXTENDED_ERROR
, "SIZE " },
719 { FALSE
, ERROR_INTERNET_EXTENDED_ERROR
, " SIZE" },
720 { FALSE
, ERROR_INTERNET_EXTENDED_ERROR
, "SIZE " },
721 { FALSE
, ERROR_INTERNET_EXTENDED_ERROR
, "SIZE /welcome.msg /welcome.msg" },
722 { FALSE
, ERROR_INTERNET_EXTENDED_ERROR
, "SIZE /welcome.msg" },
723 { FALSE
, ERROR_INTERNET_EXTENDED_ERROR
, "SIZE /welcome.msg " },
724 { TRUE
, ERROR_SUCCESS
, "SIZE\t/welcome.msg" },
725 { TRUE
, ERROR_SUCCESS
, "SIZE /welcome.msg" },
726 { FALSE
, ERROR_INTERNET_EXTENDED_ERROR
, "PWD /welcome.msg" },
727 { TRUE
, ERROR_SUCCESS
, "PWD" }
732 win_skip("FtpCommandA() is not available. Skipping the Ftp command tests\n");
736 for (i
= 0; i
< sizeof(command_test
) / sizeof(command_test
[0]); i
++)
738 SetLastError(0xdeadbeef);
739 ret
= pFtpCommandA(hFtp
, FALSE
, FTP_TRANSFER_TYPE_ASCII
, command_test
[i
].cmd
, 0, NULL
);
740 error
= GetLastError();
742 ok(ret
== command_test
[i
].ret
, "%d: expected FtpCommandA to %s\n", i
, command_test
[i
].ret
? "succeed" : "fail");
743 ok(error
== command_test
[i
].error
, "%d: expected error %u, got %u\n", i
, command_test
[i
].error
, error
);
747 static void test_find_first_file(HINTERNET hFtp
, HINTERNET hConnect
)
749 WIN32_FIND_DATAA findData
;
755 /* NULL as the search file ought to return the first file in the directory */
756 SetLastError(0xdeadbeef);
757 hSearch
= FtpFindFirstFileA(hFtp
, NULL
, &findData
, 0, 0);
758 ok ( hSearch
!= NULL
, "Expected FtpFindFirstFileA to pass\n" );
760 /* This should fail as the previous handle wasn't closed */
761 SetLastError(0xdeadbeef);
762 hSearch2
= FtpFindFirstFileA(hFtp
, "welcome.msg", &findData
, 0, 0);
763 todo_wine
ok ( hSearch2
== NULL
, "Expected FtpFindFirstFileA to fail\n" );
764 todo_wine
ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS
,
765 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError() );
766 InternetCloseHandle(hSearch2
); /* Just in case */
768 InternetCloseHandle(hSearch
);
770 /* Try a valid filename in a subdirectory search */
771 SetLastError(0xdeadbeef);
772 hSearch
= FtpFindFirstFileA(hFtp
, "pub/wine", &findData
, 0, 0);
773 todo_wine
ok ( hSearch
!= NULL
, "Expected FtpFindFirstFileA to pass\n" );
774 InternetCloseHandle(hSearch
);
776 /* Try a valid filename in a subdirectory wildcard search */
777 SetLastError(0xdeadbeef);
778 hSearch
= FtpFindFirstFileA(hFtp
, "pub/w*", &findData
, 0, 0);
779 todo_wine
ok ( hSearch
!= NULL
, "Expected FtpFindFirstFileA to pass\n" );
780 InternetCloseHandle(hSearch
);
782 /* Try an invalid wildcard search */
783 SetLastError(0xdeadbeef);
784 hSearch
= FtpFindFirstFileA(hFtp
, "*/w*", &findData
, 0, 0);
785 ok ( hSearch
== NULL
, "Expected FtpFindFirstFileA to fail\n" );
786 InternetCloseHandle(hSearch
); /* Just in case */
788 /* Try FindFirstFile between FtpOpenFile and InternetCloseHandle */
789 SetLastError(0xdeadbeef);
790 hOpenFile
= FtpOpenFileA(hFtp
, "welcome.msg", GENERIC_READ
, FTP_TRANSFER_TYPE_ASCII
, 0);
791 ok ( hOpenFile
!= NULL
, "Expected FtpOpenFileA to succeed\n" );
792 ok ( GetLastError() == ERROR_SUCCESS
||
793 broken(GetLastError() == ERROR_FILE_NOT_FOUND
), /* Win98 */
794 "Expected ERROR_SUCCESS, got %u\n", GetLastError() );
796 /* This should fail as the OpenFile handle wasn't closed */
797 SetLastError(0xdeadbeef);
798 hSearch
= FtpFindFirstFileA(hFtp
, "welcome.msg", &findData
, 0, 0);
799 error
= GetLastError();
800 ok ( hSearch
== NULL
|| broken(hSearch
!= NULL
), /* win2k */
801 "Expected FtpFindFirstFileA to fail\n" );
803 ok ( error
== ERROR_FTP_TRANSFER_IN_PROGRESS
|| broken(error
== ERROR_INTERNET_EXTENDED_ERROR
),
804 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error
);
807 ok( error
== ERROR_SUCCESS
, "wrong error %u on success\n", GetLastError() );
808 InternetCloseHandle(hSearch
);
811 InternetCloseHandle(hOpenFile
);
813 /* Test using a nonexistent filename */
814 SetLastError(0xdeadbeef);
815 hSearch
= FtpFindFirstFileA(hFtp
, "this_file_should_not_exist", &findData
, 0, 0);
816 ok ( hSearch
== NULL
, "Expected FtpFindFirstFileA to fail\n" );
817 todo_wine
ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR
,
818 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError() );
819 InternetCloseHandle(hSearch
); /* Just in case */
821 /* Test using a nonexistent filename and a wildcard */
822 SetLastError(0xdeadbeef);
823 hSearch
= FtpFindFirstFileA(hFtp
, "this_file_should_not_exist*", &findData
, 0, 0);
824 ok ( hSearch
== NULL
, "Expected FtpFindFirstFileA to fail\n" );
825 todo_wine
ok ( GetLastError() == ERROR_NO_MORE_FILES
,
826 "Expected ERROR_NO_MORE_FILES, got %d\n", GetLastError() );
827 InternetCloseHandle(hSearch
); /* Just in case */
829 /* Test using an invalid handle type */
830 SetLastError(0xdeadbeef);
831 hSearch
= FtpFindFirstFileA(hConnect
, "welcome.msg", &findData
, 0, 0);
832 ok ( hSearch
== NULL
, "Expected FtpFindFirstFileA to fail\n" );
833 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
834 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError() );
835 InternetCloseHandle(hSearch
); /* Just in case */
838 static void test_get_current_dir(HINTERNET hFtp
, HINTERNET hConnect
)
841 DWORD dwCurrentDirectoryLen
= MAX_PATH
;
842 CHAR lpszCurrentDirectory
[MAX_PATH
];
846 win_skip("FtpCommandA() is not available. Skipping the Ftp get_current_dir tests\n");
850 /* change directories to get a more interesting pwd */
851 bRet
= pFtpCommandA(hFtp
, FALSE
, FTP_TRANSFER_TYPE_ASCII
, "CWD pub/", 0, NULL
);
854 skip("Failed to change directories in test_get_current_dir(HINTERNET hFtp).\n");
858 /* test with all NULL arguments */
859 SetLastError(0xdeadbeef);
860 bRet
= FtpGetCurrentDirectoryA( NULL
, NULL
, 0 );
861 ok ( bRet
== FALSE
, "Expected FtpGetCurrentDirectoryA to fail\n" );
862 ok ( GetLastError() == ERROR_INVALID_HANDLE
, "Expected ERROR_INVALID_HANDLE, got: %d\n", GetLastError());
864 /* test with NULL parameters instead of expected LPSTR/LPDWORD */
865 SetLastError(0xdeadbeef);
866 bRet
= FtpGetCurrentDirectoryA( hFtp
, NULL
, 0 );
867 ok ( bRet
== FALSE
, "Expected FtpGetCurrentDirectoryA to fail\n" );
868 ok ( GetLastError() == ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got: %d\n", GetLastError());
870 /* test with no valid handle and valid parameters */
871 SetLastError(0xdeadbeef);
872 bRet
= FtpGetCurrentDirectoryA( NULL
, lpszCurrentDirectory
, &dwCurrentDirectoryLen
);
873 ok ( bRet
== FALSE
, "Expected FtpGetCurrentDirectoryA to fail\n" );
874 ok ( GetLastError() == ERROR_INVALID_HANDLE
, "Expected ERROR_INVALID_HANDLE, got: %d\n", GetLastError());
876 /* test with invalid dwCurrentDirectory and all other parameters correct */
877 SetLastError(0xdeadbeef);
878 bRet
= FtpGetCurrentDirectoryA( hFtp
, lpszCurrentDirectory
, 0 );
879 ok ( bRet
== FALSE
, "Expected FtpGetCurrentDirectoryA to fail\n" );
880 ok ( GetLastError() == ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got: %d\n", GetLastError());
882 /* test with invalid lpszCurrentDirectory and all other parameters correct */
883 SetLastError(0xdeadbeef);
884 bRet
= FtpGetCurrentDirectoryA( hFtp
, NULL
, &dwCurrentDirectoryLen
);
885 ok ( bRet
== FALSE
, "Expected FtpGetCurrentDirectoryA to fail\n" );
886 ok ( GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Expected ERROR_INSUFFICIENT_BUFFER, got: %d\n", GetLastError());
888 /* test to show it checks the handle type */
889 SetLastError(0xdeadbeef);
890 bRet
= FtpGetCurrentDirectoryA( hConnect
, lpszCurrentDirectory
, &dwCurrentDirectoryLen
);
891 ok ( bRet
== FALSE
, "Expected FtpGetCurrentDirectoryA to fail\n" );
892 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
,
893 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got: %d\n", GetLastError());
895 /* test for the current directory with legitimate values */
896 SetLastError(0xdeadbeef);
897 bRet
= FtpGetCurrentDirectoryA( hFtp
, lpszCurrentDirectory
, &dwCurrentDirectoryLen
);
898 ok ( bRet
== TRUE
, "Expected FtpGetCurrentDirectoryA to pass\n" );
899 ok ( !strcmp(lpszCurrentDirectory
, "/pub"), "Expected returned value \"%s\" to match \"/pub\"\n", lpszCurrentDirectory
);
900 ok ( GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got: %d\n", GetLastError());
902 /* test for the current directory with a size only large enough to
903 * fit the string and not the null terminating character */
904 SetLastError(0xdeadbeef);
905 dwCurrentDirectoryLen
= 4;
906 lpszCurrentDirectory
[4] = 'a'; /* set position 4 of the array to something else to make sure a leftover \0 isn't fooling the test */
907 bRet
= FtpGetCurrentDirectoryA( hFtp
, lpszCurrentDirectory
, &dwCurrentDirectoryLen
);
908 ok ( bRet
== FALSE
, "Expected FtpGetCurrentDirectoryA to fail\n");
909 ok ( strcmp(lpszCurrentDirectory
, "/pub"), "Expected returned value \"%s\" to not match \"/pub\"\n", lpszCurrentDirectory
);
910 ok ( GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Expected ERROR_INSUFFICIENT_BUFFER, got: %d\n", GetLastError());
912 /* test for the current directory with a size large enough to store
913 * the expected string as well as the null terminating character */
914 SetLastError(0xdeadbeef);
915 dwCurrentDirectoryLen
= 5;
916 bRet
= FtpGetCurrentDirectoryA( hFtp
, lpszCurrentDirectory
, &dwCurrentDirectoryLen
);
917 ok ( bRet
== TRUE
, "Expected FtpGetCurrentDirectoryA to pass\n");
918 ok ( !strcmp(lpszCurrentDirectory
, "/pub"), "Expected returned value \"%s\" to match \"/pub\"\n", lpszCurrentDirectory
);
919 ok ( GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got: %d\n", GetLastError());
922 static void WINAPI
status_callback(HINTERNET handle
, DWORD_PTR ctx
, DWORD status
, LPVOID info
, DWORD info_len
)
926 case INTERNET_STATUS_RESOLVING_NAME
:
927 case INTERNET_STATUS_NAME_RESOLVED
:
928 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
929 case INTERNET_STATUS_CONNECTED_TO_SERVER
:
930 trace("%p %lx %u %s %u\n", handle
, ctx
, status
, (char *)info
, info_len
);
937 static void test_status_callbacks(HINTERNET hInternet
)
939 INTERNET_STATUS_CALLBACK cb
;
943 cb
= pInternetSetStatusCallbackA(hInternet
, status_callback
);
944 ok(cb
== NULL
, "expected NULL got %p\n", cb
);
946 hFtp
= InternetConnectA(hInternet
, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT
, "anonymous", NULL
,
947 INTERNET_SERVICE_FTP
, INTERNET_FLAG_PASSIVE
, 1);
950 skip("No ftp connection could be made to ftp.winehq.org %u\n", GetLastError());
954 ret
= InternetCloseHandle(hFtp
);
955 ok(ret
, "InternetCloseHandle failed %u\n", GetLastError());
957 cb
= pInternetSetStatusCallbackA(hInternet
, NULL
);
958 ok(cb
== status_callback
, "expected check_status got %p\n", cb
);
964 HANDLE hInternet
, hFtp
, hHttp
;
966 hWininet
= GetModuleHandleA("wininet.dll");
968 if(!GetProcAddress(hWininet
, "InternetGetCookieExW")) {
969 win_skip("Too old IE (older than 6.0)\n");
973 pFtpCommandA
= (void*)GetProcAddress(hWininet
, "FtpCommandA");
974 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hWininet
, "InternetSetStatusCallbackA");
976 SetLastError(0xdeadbeef);
977 hInternet
= InternetOpenA("winetest", 0, NULL
, NULL
, 0);
978 ok(hInternet
!= NULL
, "InternetOpen failed: %u\n", GetLastError());
980 hFtp
= InternetConnectA(hInternet
, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT
, "anonymous", NULL
, INTERNET_SERVICE_FTP
, INTERNET_FLAG_PASSIVE
, 0);
983 InternetCloseHandle(hInternet
);
984 skip("No ftp connection could be made to ftp.winehq.org\n");
987 hHttp
= InternetConnectA(hInternet
, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
990 InternetCloseHandle(hFtp
);
991 InternetCloseHandle(hInternet
);
992 skip("No http connection could be made to www.winehq.org\n");
996 /* The first call should always be a proper InternetOpen, if not
997 * several calls will return ERROR_INTERNET_NOT_INITIALIZED when
998 * all parameters are correct but no session handle is given. Whereas
999 * the same call will return ERROR_INVALID_HANDLE if an InternetOpen
1001 * The following test will show that behaviour, where the tests inside
1002 * the other sub-tests will show the other situation.
1004 test_getfile_no_open();
1005 test_connect(hInternet
);
1006 test_createdir(hFtp
, hHttp
);
1007 test_deletefile(hFtp
, hHttp
);
1008 test_getfile(hFtp
, hHttp
);
1009 test_openfile(hFtp
, hHttp
);
1010 test_putfile(hFtp
, hHttp
);
1011 test_removedir(hFtp
, hHttp
);
1012 test_renamefile(hFtp
, hHttp
);
1013 test_command(hFtp
, hHttp
);
1014 test_find_first_file(hFtp
, hHttp
);
1015 test_get_current_dir(hFtp
, hHttp
);
1016 test_status_callbacks(hInternet
);
1018 InternetCloseHandle(hHttp
);
1019 InternetCloseHandle(hFtp
);
1020 InternetCloseHandle(hInternet
);