wininet/ftp.c: Fix some returned error codes.
[wine.git] / dlls / wininet / tests / ftp.c
blobd5a4a6f2c1d3bbaa25a97d07c79c0ac8ac4c8ba8
1 /*
2 * Wininet - ftp tests
4 * Copyright 2007 Paul Vriens
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * FIXME:
23 * Use InternetGetLastResponseInfo when the last error is set to ERROR_INTERNET_EXTENDED_ERROR.
24 * TODO:
25 * Add W-function tests.
26 * Add missing function tests:
27 * FtpCommand
28 * FtpFindFirstFile
29 * FtpGetCurrentDirectory
30 * FtpGetFileSize
31 * FtpSetCurrentDirectory
34 #include <stdarg.h>
35 #include <stdio.h>
36 #include <stdlib.h>
38 #include "windef.h"
39 #include "winbase.h"
40 #include "wininet.h"
41 #include "winsock.h"
43 #include "wine/test.h"
45 static void test_connect(void)
47 HINTERNET hInternet, hFtp;
49 SetLastError(0xdeadbeef);
50 hInternet = InternetOpen(NULL, 0, NULL, NULL, 0);
51 ok(hInternet != NULL, "InternetOpen failed : %d\n", GetLastError());
53 if(!hInternet)
55 skip("No internet connection could be made\n");
56 return;
59 /* Try a few username/password combinations:
60 * anonymous : NULL
61 * NULL : IEUser@
62 * NULL : NULL
65 SetLastError(0xdeadbeef);
66 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", NULL, INTERNET_SERVICE_FTP, 0, 0);
67 ok ( hFtp == NULL, "Expected InternetConnect to fail\n");
68 ok ( GetLastError() == ERROR_INTERNET_LOGIN_FAILURE,
69 "Expected ERROR_INTERNET_LOGIN_FAILURE, got %d\n", GetLastError());
71 SetLastError(0xdeadbeef);
72 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, NULL, "IEUser@", INTERNET_SERVICE_FTP, 0, 0);
73 ok ( hFtp == NULL, "Expected InternetConnect to fail\n");
74 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
75 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
77 /* Using a NULL username and password will be interpreted as anonymous ftp. The username will be 'anonymous' the password
78 * is created via some simple heuristics (see dlls/wininet/ftp.c).
79 * On Wine this registry key is not set by default so (NULL, NULL) will result in anonymous ftp with an (most likely) not
80 * accepted password (the username).
81 * If the first call fails because we get an ERROR_INTERNET_LOGIN_FAILURE, we try again with a (more) correct password.
84 SetLastError(0xdeadbeef);
85 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
86 if (!hFtp && (GetLastError() == ERROR_INTERNET_LOGIN_FAILURE))
88 /* We are most likely running on a clean Wine install or a Windows install where the registry key is removed */
89 SetLastError(0xdeadbeef);
90 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0);
92 ok ( hFtp != NULL, "InternetConnect failed : %d\n", GetLastError());
93 ok ( GetLastError() == ERROR_SUCCESS,
94 "ERROR_SUCCESS, got %d\n", GetLastError());
96 InternetCloseHandle(hFtp);
97 InternetCloseHandle(hInternet);
100 static void test_createdir(void)
102 BOOL bRet;
103 HINTERNET hInternet, hFtp, hConnect;
105 /* Invalid internet handle, the other is a valid parameter */
106 SetLastError(0xdeadbeef);
107 bRet = FtpCreateDirectoryA(NULL, "new_directory_deadbeef");
108 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
109 ok ( GetLastError() == ERROR_INVALID_HANDLE,
110 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
112 hInternet = InternetOpen(NULL, 0, NULL, NULL, 0);
113 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0);
114 if(!hFtp)
116 skip("No ftp connection could be made\n");
117 InternetCloseHandle(hInternet);
118 return;
121 /* We should have a ftp-connection (valid ftp session handle), try some creating */
123 /* No directory-name */
124 SetLastError(0xdeadbeef);
125 bRet = FtpCreateDirectoryA(hFtp, NULL);
126 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
127 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
128 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
130 /* Parameters are OK, but we shouldn't be allowed to create the directory */
131 SetLastError(0xdeadbeef);
132 bRet = FtpCreateDirectoryA(hFtp, "new_directory_deadbeef");
133 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
134 todo_wine
135 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
136 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
138 InternetCloseHandle(hFtp);
140 /* Http handle-type for ftp connection */
142 hConnect = InternetConnect(hInternet, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
144 /* One small test to show that handle type is checked before parameters */
145 SetLastError(0xdeadbeef);
146 bRet = FtpCreateDirectoryA(hConnect, NULL);
147 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
148 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
149 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
151 SetLastError(0xdeadbeef);
152 bRet = FtpCreateDirectoryA(hConnect, "new_directory_deadbeef");
153 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
154 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
155 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
157 InternetCloseHandle(hConnect);
158 InternetCloseHandle(hInternet);
161 static void test_deletefile(void)
163 BOOL bRet;
164 HINTERNET hInternet, hFtp, hConnect;
166 /* Invalid internet handle, the other is a valid parameter */
167 SetLastError(0xdeadbeef);
168 bRet = FtpDeleteFileA(NULL, "non_existent_file_deadbeef");
169 ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
170 todo_wine
171 ok ( GetLastError() == ERROR_INVALID_HANDLE,
172 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
174 hInternet = InternetOpen(NULL, 0, NULL, NULL, 0);
175 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0);
176 if(!hFtp)
178 skip("No ftp connection could be made\n");
179 InternetCloseHandle(hInternet);
180 return;
183 /* We should have a ftp-connection, try some deleting */
185 /* No filename */
186 SetLastError(0xdeadbeef);
187 bRet = FtpDeleteFileA(hFtp, NULL);
188 ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
189 todo_wine
190 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
191 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
193 /* Parameters are OK but remote file should not be there */
194 SetLastError(0xdeadbeef);
195 bRet = FtpDeleteFileA(hFtp, "non_existent_file_deadbeef");
196 ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
197 todo_wine
198 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
199 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
201 InternetCloseHandle(hFtp);
203 /* Http handle-type for ftp connection */
205 hConnect = InternetConnect(hInternet, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
207 /* One small test to show that handle type is checked before parameters */
208 SetLastError(0xdeadbeef);
209 bRet = FtpDeleteFileA(hConnect, NULL);
210 ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
211 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
212 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
214 SetLastError(0xdeadbeef);
215 bRet = FtpDeleteFileA(hConnect, "non_existent_file_deadbeef");
216 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
217 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
218 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
220 InternetCloseHandle(hConnect);
221 InternetCloseHandle(hInternet);
224 static void test_getfile(void)
226 BOOL bRet;
227 HINTERNET hInternet, hFtp, hConnect;
229 /* Invalid internet handle, the other is a valid parameter */
230 SetLastError(0xdeadbeef);
231 bRet = FtpGetFileA(NULL, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
232 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
233 todo_wine
234 ok ( GetLastError() == ERROR_INVALID_HANDLE,
235 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
237 /* Test to show that FtpGetFileA checks the parameters before the handle */
238 SetLastError(0xdeadbeef);
239 bRet = FtpGetFileA(NULL, NULL, NULL, FALSE, 0, 5, 0);
240 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
241 todo_wine
242 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
243 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
245 hInternet = InternetOpen(NULL, 0, NULL, NULL, 0);
246 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0);
247 if(!hFtp)
249 skip("No ftp connection could be made\n");
250 InternetCloseHandle(hInternet);
251 return;
254 /* Make sure we start clean */
256 DeleteFileA("should_be_non_existing_deadbeef");
257 DeleteFileA("should_also_be_non_existing_deadbeef");
259 /* We should have a ftp-connection, try some getting */
261 /* No remote file */
262 SetLastError(0xdeadbeef);
263 bRet = FtpGetFileA(hFtp, NULL, "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
264 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
265 todo_wine
267 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
268 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
269 /* Currently Wine always creates the local file (even on failure) which is not correct, hence the test */
270 ok (GetFileAttributesA("should_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
271 "Local file should not have been created\n");
273 DeleteFileA("should_be_non_existing_deadbeef");
275 /* No local file */
276 SetLastError(0xdeadbeef);
277 bRet = FtpGetFileA(hFtp, "welcome.msg", NULL, FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
278 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
279 todo_wine
280 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
281 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
283 /* Zero attributes, but call succeeds (as would CreateFile with zero attributes) */
284 SetLastError(0xdeadbeef);
285 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, 0, FTP_TRANSFER_TYPE_UNKNOWN, 0);
286 todo_wine
288 ok ( bRet == TRUE, "Expected FtpGetFileA to succeed\n");
289 ok ( GetLastError() == ERROR_SUCCESS,
290 "Expected ERROR_SUCCESS, got %d\n", GetLastError());
292 /* Wine passes this test but for the wrong reason */
293 ok (GetFileAttributesA("should_be_non_existing_deadbeef") != INVALID_FILE_ATTRIBUTES,
294 "Local file should have been created\n");
295 DeleteFileA("should_be_non_existing_deadbeef");
297 /* Illegal condition flags */
298 SetLastError(0xdeadbeef);
299 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, 5, 0);
300 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
301 todo_wine
303 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
304 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
305 ok (GetFileAttributesA("should_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
306 "Local file should not have been created\n");
308 DeleteFileA("should_be_non_existing_deadbeef");
310 /* Remote file doesn't exist */
311 SetLastError(0xdeadbeef);
312 bRet = FtpGetFileA(hFtp, "should_be_non_existing_deadbeef", "should_also_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
313 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
314 todo_wine
316 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
317 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
318 ok (GetFileAttributesA("should_also_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
319 "Local file should not have been created\n");
321 DeleteFileA("should_also_be_non_existing_deadbeef");
323 /* This one should succeed and give us a copy of the 'welcome.msg' file */
324 SetLastError(0xdeadbeef);
325 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
326 todo_wine
328 ok ( bRet == TRUE, "Expected FtpGetFileA to succeed\n");
329 ok ( GetLastError() == ERROR_SUCCESS,
330 "Expected ERROR_SUCCESS, got %d\n", GetLastError());
333 if (GetFileAttributesA("should_be_non_existing_deadbeef") != INVALID_FILE_ATTRIBUTES)
335 /* Should succeed as fFailIfExists is set to FALSE (meaning don't fail if local file exists) */
336 SetLastError(0xdeadbeef);
337 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
338 todo_wine
340 ok ( bRet == TRUE, "Expected FtpGetFileA to succeed\n");
341 ok ( GetLastError() == ERROR_SUCCESS,
342 "Expected ERROR_SUCCESS, got %d\n", GetLastError());
345 /* Should fail as fFailIfExists is set to TRUE */
346 SetLastError(0xdeadbeef);
347 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", TRUE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
348 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
349 todo_wine
350 ok ( GetLastError() == ERROR_FILE_EXISTS,
351 "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
353 /* Prove that the existence of the local file is checked first (or at least reported last) */
354 SetLastError(0xdeadbeef);
355 bRet = FtpGetFileA(hFtp, "should_be_non_existing_deadbeef", "should_be_non_existing_deadbeef", TRUE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
356 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
357 todo_wine
358 ok ( GetLastError() == ERROR_FILE_EXISTS,
359 "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
361 DeleteFileA("should_be_non_existing_deadbeef");
364 InternetCloseHandle(hFtp);
366 /* Http handle-type for ftp connection */
368 hConnect = InternetConnect(hInternet, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
370 /* One small test to show that handle type is checked before parameters */
371 SetLastError(0xdeadbeef);
372 bRet = FtpGetFileA(hConnect, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, 5, 0);
373 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
374 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
375 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
377 SetLastError(0xdeadbeef);
378 bRet = FtpGetFileA(hConnect, "should_be_non_existing_deadbeef", "should_be_non_existing_deadbeef", TRUE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
379 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
380 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
381 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
383 InternetCloseHandle(hConnect);
384 InternetCloseHandle(hInternet);
387 static void test_openfile(void)
389 HINTERNET hOpenFile, hInternet, hFtp, hConnect;
391 /* Invalid internet handle, the rest are valid parameters */
392 SetLastError(0xdeadbeef);
393 hOpenFile = FtpOpenFileA(NULL, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
394 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
395 todo_wine
396 ok ( GetLastError() == ERROR_INVALID_HANDLE,
397 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
398 InternetCloseHandle(hOpenFile); /* Just in case */
400 hInternet = InternetOpen(NULL, 0, NULL, NULL, 0);
401 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0);
402 if(!hFtp)
404 skip("No ftp connection could be made\n");
405 InternetCloseHandle(hInternet);
406 return;
409 /* We should have a ftp-connection (valid ftp session handle), try some opening */
411 /* No filename */
412 SetLastError(0xdeadbeef);
413 hOpenFile = FtpOpenFileA(hFtp, NULL, GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
414 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
415 todo_wine
416 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
417 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
418 InternetCloseHandle(hOpenFile); /* Just in case */
420 /* Illegal access flags */
421 SetLastError(0xdeadbeef);
422 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", 0, FTP_TRANSFER_TYPE_ASCII, 0);
423 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
424 todo_wine
425 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
426 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
427 InternetCloseHandle(hOpenFile); /* Just in case */
429 /* Illegal combination of access flags */
430 SetLastError(0xdeadbeef);
431 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ|GENERIC_WRITE, FTP_TRANSFER_TYPE_ASCII, 0);
432 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
433 todo_wine
434 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
435 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
436 InternetCloseHandle(hOpenFile); /* Just in case */
438 /* Illegal condition flags */
439 SetLastError(0xdeadbeef);
440 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, 5, 0);
441 todo_wine
443 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
444 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
445 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
447 InternetCloseHandle(hOpenFile); /* Just in case */
449 /* All OK */
450 SetLastError(0xdeadbeef);
451 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
452 todo_wine
454 ok ( hOpenFile != NULL, "Expected FtpOpenFileA to succeed\n");
455 /* For some strange/unknown reason, win98 returns ERROR_FILE_NOT_FOUND */
456 ok ( GetLastError() == ERROR_SUCCESS || GetLastError() == ERROR_FILE_NOT_FOUND,
457 "Expected ERROR_SUCCESS or ERROR_FILE_NOT_FOUND (win98), got %d\n", GetLastError());
460 if (hOpenFile)
462 BOOL bRet;
464 /* We have a handle so all ftp calls should fail (TODO: Put more ftp-calls in here) */
465 SetLastError(0xdeadbeef);
466 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
467 ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
468 ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS,
469 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError());
470 DeleteFileA("should_be_non_existing_deadbeef"); /* Just in case */
473 InternetCloseHandle(hOpenFile);
474 InternetCloseHandle(hFtp);
476 /* Http handle-type for ftp connection */
478 hConnect = InternetConnect(hInternet, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
480 /* One small test to show that handle type is checked before parameters */
481 SetLastError(0xdeadbeef);
482 hOpenFile = FtpOpenFileA(hConnect, "welcome.msg", GENERIC_READ, 5, 0);
483 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
484 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
485 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
486 InternetCloseHandle(hOpenFile); /* Just in case */
488 SetLastError(0xdeadbeef);
489 hOpenFile = FtpOpenFileA(hConnect, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
490 ok ( hOpenFile == NULL, "Expected FtpOpenFileA to fail\n");
491 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
492 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
494 InternetCloseHandle(hOpenFile); /* Just in case */
495 InternetCloseHandle(hConnect);
496 InternetCloseHandle(hInternet);
499 static void test_putfile(void)
501 BOOL bRet;
502 HINTERNET hInternet, hFtp, hConnect;
503 HANDLE hFile;
505 /* Invalid internet handle, the rest are valid parameters */
506 SetLastError(0xdeadbeef);
507 bRet = FtpPutFileA(NULL, "non_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
508 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
509 todo_wine
510 ok ( GetLastError() == ERROR_INVALID_HANDLE,
511 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
513 hInternet = InternetOpen(NULL, 0, NULL, NULL, 0);
514 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0);
515 if(!hFtp)
517 skip("No ftp connection could be made\n");
518 InternetCloseHandle(hInternet);
519 return;
522 /* We should have a ftp-connection, try some puts */
524 /* No local file given */
525 SetLastError(0xdeadbeef);
526 bRet = FtpPutFileA(hFtp, NULL, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
527 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
528 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
529 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
531 /* No remote file given */
532 SetLastError(0xdeadbeef);
533 bRet = FtpPutFileA(hFtp, "non_existing_local", NULL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
534 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
535 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
536 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
538 /* Illegal condition flags */
539 SetLastError(0xdeadbeef);
540 bRet = FtpPutFileA(hFtp, "non_existing_local", "non_existing_remote", 5, 0);
541 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
542 todo_wine
543 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
544 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
546 /* Parameters are OK but local file doesn't exist */
547 SetLastError(0xdeadbeef);
548 bRet = FtpPutFileA(hFtp, "non_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
549 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
550 todo_wine
551 ok ( GetLastError() == ERROR_FILE_NOT_FOUND,
552 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
554 /* Create a temporary local file */
555 SetLastError(0xdeadbeef);
556 hFile = CreateFileA("now_existing_local", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
557 ok ( hFile != NULL, "Error creating a local file : %d\n", GetLastError());
558 CloseHandle(hFile);
560 /* Local file exists but we shouldn't be allowed to 'put' the file */
561 SetLastError(0xdeadbeef);
562 bRet = FtpPutFileA(hFtp, "now_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
563 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
564 todo_wine
565 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
566 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
568 DeleteFileA("now_existing_local");
570 InternetCloseHandle(hFtp);
572 /* Http handle-type for ftp connection */
574 hConnect = InternetConnect(hInternet, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
576 /* One small test to show that handle type is checked before parameters */
577 SetLastError(0xdeadbeef);
578 bRet = FtpPutFileA(hConnect, "non_existing_local", "non_existing_remote", 5, 0);
579 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
580 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
581 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
583 SetLastError(0xdeadbeef);
584 bRet = FtpPutFileA(hConnect, "non_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
585 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
586 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
587 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
589 InternetCloseHandle(hConnect);
590 InternetCloseHandle(hInternet);
593 static void test_removedir(void)
595 BOOL bRet;
596 HINTERNET hInternet, hFtp, hConnect;
598 /* Invalid internet handle, the other is a valid parameter */
599 SetLastError(0xdeadbeef);
600 bRet = FtpRemoveDirectoryA(NULL, "should_be_non_existing_deadbeef_dir");
601 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
602 todo_wine
603 ok ( GetLastError() == ERROR_INVALID_HANDLE,
604 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
606 hInternet = InternetOpen(NULL, 0, NULL, NULL, 0);
607 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0);
608 if(!hFtp)
610 skip("No ftp connection could be made\n");
611 InternetCloseHandle(hInternet);
612 return;
615 /* We should have a ftp-connection, try some removing */
617 /* No remote directory given */
618 SetLastError(0xdeadbeef);
619 bRet = FtpRemoveDirectoryA(hFtp, NULL);
620 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
621 todo_wine
622 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
623 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
625 /* Remote directory doesn't exist */
626 SetLastError(0xdeadbeef);
627 bRet = FtpRemoveDirectoryA(hFtp, "should_be_non_existing_deadbeef_dir");
628 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
629 todo_wine
630 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
631 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
633 /* We shouldn't be allowed to remove that directory */
634 SetLastError(0xdeadbeef);
635 bRet = FtpRemoveDirectoryA(hFtp, "pub");
636 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
637 todo_wine
638 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
639 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
641 InternetCloseHandle(hFtp);
643 /* Http handle-type for ftp connection */
645 hConnect = InternetConnect(hInternet, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
647 /* One small test to show that handle type is checked before parameters */
648 SetLastError(0xdeadbeef);
649 bRet = FtpRemoveDirectoryA(hConnect, NULL);
650 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
651 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
652 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
654 SetLastError(0xdeadbeef);
655 bRet = FtpRemoveDirectoryA(hConnect, "should_be_non_existing_deadbeef_dir");
656 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
657 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
658 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
660 InternetCloseHandle(hConnect);
661 InternetCloseHandle(hInternet);
664 static void test_renamefile(void)
666 BOOL bRet;
667 HINTERNET hInternet, hFtp, hConnect;
669 /* Invalid internet handle, the rest are valid parameters */
670 SetLastError(0xdeadbeef);
671 bRet = FtpRenameFileA(NULL , "should_be_non_existing_deadbeef", "new");
672 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
673 todo_wine
674 ok ( GetLastError() == ERROR_INVALID_HANDLE,
675 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
677 hInternet = InternetOpen(NULL, 0, NULL, NULL, 0);
678 hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0);
679 if(!hFtp)
681 skip("No ftp connection could be made\n");
682 InternetCloseHandle(hInternet);
683 return;
686 /* We should have a ftp-connection, try some renaming */
688 /* No 'existing' file */
689 SetLastError(0xdeadbeef);
690 bRet = FtpRenameFileA(hFtp , NULL, "new");
691 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
692 todo_wine
693 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
694 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
696 /* No new file */
697 SetLastError(0xdeadbeef);
698 bRet = FtpRenameFileA(hFtp , "should_be_non_existing_deadbeef", NULL);
699 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
700 todo_wine
701 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
702 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
704 /* Existing file shouldn't be there */
705 SetLastError(0xdeadbeef);
706 bRet = FtpRenameFileA(hFtp , "should_be_non_existing_deadbeef", "new");
707 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
708 todo_wine
709 ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
710 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
712 InternetCloseHandle(hFtp);
714 /* Http handle-type for ftp connection */
716 hConnect = InternetConnect(hInternet, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
718 /* One small test to show that handle type is checked before parameters */
719 SetLastError(0xdeadbeef);
720 bRet = FtpRenameFileA(hConnect , "should_be_non_existing_deadbeef", NULL);
721 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
722 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
723 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
725 SetLastError(0xdeadbeef);
726 bRet = FtpRenameFileA(hConnect , "should_be_non_existing_deadbeef", "new");
727 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
728 ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE,
729 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
731 InternetCloseHandle(hConnect);
732 InternetCloseHandle(hInternet);
735 START_TEST(ftp)
737 test_connect();
738 test_createdir();
739 test_deletefile();
740 test_getfile();
741 test_openfile();
742 test_putfile();
743 test_removedir();
744 test_renamefile();