ReactOS 0.4.17-dev-1190-g4c812f4
ftp.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "windef.h"
#include "winbase.h"
#include "wininet.h"
#include "winsock2.h"
#include "wine/test.h"
Include dependency graph for ftp.c:

Go to the source code of this file.

Functions

static BOOL (WINAPI *pFtpCommandA)(HINTERNET
 
static HINTERNET *static INTERNET_STATUS_CALLBACK (WINAPI *pInternetSetStatusCallbackA)(HINTERNET
 
static void test_getfile_no_open (void)
 
static void test_connect (HINTERNET hInternet)
 
static void test_createdir (HINTERNET hFtp, HINTERNET hConnect)
 
static void test_deletefile (HINTERNET hFtp, HINTERNET hConnect)
 
static void test_getfile (HINTERNET hFtp, HINTERNET hConnect)
 
static void trace_extended_error (DWORD error)
 
static void test_openfile (HINTERNET hFtp, HINTERNET hConnect)
 
static void test_putfile (HINTERNET hFtp, HINTERNET hConnect)
 
static void test_removedir (HINTERNET hFtp, HINTERNET hConnect)
 
static void test_renamefile (HINTERNET hFtp, HINTERNET hConnect)
 
static void test_command (HINTERNET hFtp)
 
static void test_find_first_file (HINTERNET hFtp, HINTERNET hConnect)
 
static void test_get_current_dir (HINTERNET hFtp, HINTERNET hConnect)
 
static void WINAPI status_callback (HINTERNET handle, DWORD_PTR ctx, DWORD status, LPVOID info, DWORD info_len)
 
static void test_status_callbacks (HINTERNET hInternet)
 
 START_TEST (ftp)
 

Variables

static BOOL
 
static DWORD
 
static LPCSTR
 
static DWORD_PTR
 
static HINTERNET *static INTERNET_STATUS_CALLBACK
 

Function Documentation

◆ BOOL()

static BOOL ( WINAPI *  pFtpCommandA)
static

◆ INTERNET_STATUS_CALLBACK()

static HINTERNET *static INTERNET_STATUS_CALLBACK ( WINAPI *  pInternetSetStatusCallbackA)
static

◆ START_TEST()

START_TEST ( ftp  )

Definition at line 1026 of file ftp.c.

1027{
1028 HMODULE hWininet;
1029 HANDLE hInternet, hFtp, hHttp;
1030
1031 hWininet = GetModuleHandleA("wininet.dll");
1032
1033 if(!GetProcAddress(hWininet, "InternetGetCookieExW")) {
1034 win_skip("Too old IE (older than 6.0)\n");
1035 return;
1036 }
1037
1038 pFtpCommandA = (void*)GetProcAddress(hWininet, "FtpCommandA");
1039 pInternetSetStatusCallbackA = (void*)GetProcAddress(hWininet, "InternetSetStatusCallbackA");
1040
1041 SetLastError(0xdeadbeef);
1042 hInternet = InternetOpenA("winetest", 0, NULL, NULL, 0);
1043 ok(hInternet != NULL, "InternetOpen failed: %lu\n", GetLastError());
1044
1045 hFtp = InternetConnectA(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
1046 if (!hFtp)
1047 {
1048 InternetCloseHandle(hInternet);
1049 skip("No ftp connection could be made to ftp.winehq.org\n");
1050 return;
1051 }
1052 hHttp = InternetConnectA(hInternet, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1053 if (!hHttp)
1054 {
1055 InternetCloseHandle(hFtp);
1056 InternetCloseHandle(hInternet);
1057 skip("No http connection could be made to www.winehq.org\n");
1058 return;
1059 }
1060
1061 /* The first call should always be a proper InternetOpen, if not
1062 * several calls will return ERROR_INTERNET_NOT_INITIALIZED when
1063 * all parameters are correct but no session handle is given. Whereas
1064 * the same call will return ERROR_INVALID_HANDLE if an InternetOpen
1065 * is done before.
1066 * The following test will show that behaviour, where the tests inside
1067 * the other sub-tests will show the other situation.
1068 */
1070 test_connect(hInternet);
1071 test_createdir(hFtp, hHttp);
1072 test_deletefile(hFtp, hHttp);
1073 test_getfile(hFtp, hHttp);
1074 test_openfile(hFtp, hHttp);
1075 test_putfile(hFtp, hHttp);
1076 test_removedir(hFtp, hHttp);
1077 test_renamefile(hFtp, hHttp);
1078 test_command(hFtp);
1079 test_find_first_file(hFtp, hHttp);
1080 test_get_current_dir(hFtp, hHttp);
1081 test_status_callbacks(hInternet);
1082
1083 InternetCloseHandle(hHttp);
1084 InternetCloseHandle(hFtp);
1085 InternetCloseHandle(hInternet);
1086}
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define NULL
Definition: types.h:112
#define SetLastError(x)
Definition: compat.h:752
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType, LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
Definition: internet.c:1411
BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
Definition: internet.c:1841
HINTERNET WINAPI InternetConnectA(HINTERNET hInternet, LPCSTR lpszServerName, INTERNET_PORT nServerPort, LPCSTR lpszUserName, LPCSTR lpszPassword, DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
Definition: internet.c:1748
#define win_skip
Definition: minitest.h:67
static void test_openfile(HINTERNET hFtp, HINTERNET hConnect)
Definition: ftp.c:382
static void test_getfile(HINTERNET hFtp, HINTERNET hConnect)
Definition: ftp.c:215
static void test_renamefile(HINTERNET hFtp, HINTERNET hConnect)
Definition: ftp.c:662
static void test_createdir(HINTERNET hFtp, HINTERNET hConnect)
Definition: ftp.c:137
static void test_deletefile(HINTERNET hFtp, HINTERNET hConnect)
Definition: ftp.c:176
static void test_connect(HINTERNET hInternet)
Definition: ftp.c:61
static void test_getfile_no_open(void)
Definition: ftp.c:48
static void test_find_first_file(HINTERNET hFtp, HINTERNET hConnect)
Definition: ftp.c:793
static void test_removedir(HINTERNET hFtp, HINTERNET hConnect)
Definition: ftp.c:616
static void test_putfile(HINTERNET hFtp, HINTERNET hConnect)
Definition: ftp.c:520
static void test_status_callbacks(HINTERNET hInternet)
Definition: ftp.c:1002
static void test_get_current_dir(HINTERNET hFtp, HINTERNET hConnect)
Definition: ftp.c:903
static void test_command(HINTERNET hFtp)
Definition: ftp.c:708
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define INTERNET_DEFAULT_HTTP_PORT
Definition: winhttp.h:41
#define INTERNET_DEFAULT_FTP_PORT
Definition: wininet.h:38
#define INTERNET_SERVICE_FTP
Definition: wininet.h:560
#define INTERNET_FLAG_PASSIVE
Definition: wininet.h:65
#define INTERNET_SERVICE_HTTP
Definition: wininet.h:562

◆ status_callback()

static void WINAPI status_callback ( HINTERNET  handle,
DWORD_PTR  ctx,
DWORD  status,
LPVOID  info,
DWORD  info_len 
)
static

Definition at line 987 of file ftp.c.

988{
989 switch (status)
990 {
995 trace("%p %Ix %lu %s %lu\n", handle, ctx, status, (char *)info, info_len);
996 break;
997 default:
998 break;
999 }
1000}
#define trace
Definition: atltest.h:70
Definition: ps.c:97
#define INTERNET_STATUS_RESOLVING_NAME
Definition: wininet.h:883
#define INTERNET_STATUS_CONNECTING_TO_SERVER
Definition: wininet.h:885
#define INTERNET_STATUS_CONNECTED_TO_SERVER
Definition: wininet.h:886
#define INTERNET_STATUS_NAME_RESOLVED
Definition: wininet.h:884

Referenced by add_data_block(), add_data_to_folder(), add_file_data(), copy_data_blocks(), test_status_callbacks(), write_cabinet(), write_data_blocks(), and write_files().

◆ test_command()

static void test_command ( HINTERNET  hFtp)
static

Definition at line 708 of file ftp.c.

709{
710 BOOL ret;
711 DWORD error;
712 unsigned int i;
713 BOOL had_error_zero = FALSE;
714 BOOL had_error_zero_size_positive = FALSE;
715 static const struct
716 {
717 BOOL ret;
718 DWORD error;
719 const char *cmd;
720 }
721 command_test[] =
722 {
725 { FALSE, ERROR_INTERNET_EXTENDED_ERROR, "invalid" },
727 { TRUE, ERROR_SUCCESS, "type i" },
731 { FALSE, ERROR_INTERNET_EXTENDED_ERROR, "size welcome.msg welcome.msg" },
732 { FALSE, ERROR_INTERNET_EXTENDED_ERROR, "size welcome.msg" },
733 { FALSE, ERROR_INTERNET_EXTENDED_ERROR, "size welcome.msg " },
734 { TRUE, ERROR_SUCCESS, "size welcome.msg" },
735 { FALSE, ERROR_INTERNET_EXTENDED_ERROR, "pwd welcome.msg" },
736 { TRUE, ERROR_SUCCESS, "pwd" }
737 };
738
739 if (!pFtpCommandA)
740 {
741 win_skip("FtpCommandA() is not available. Skipping the Ftp command tests\n");
742 return;
743 }
744
745 for (i = 0; i < ARRAY_SIZE(command_test); i++)
746 {
747 DWORD size, orig_size;
748 char *buffer;
749
750 SetLastError(0xdeadbeef);
751 ret = pFtpCommandA(hFtp, FALSE, FTP_TRANSFER_TYPE_ASCII, command_test[i].cmd, 0, NULL);
753
754 ok(ret == command_test[i].ret, "%d: expected FtpCommandA to %s\n", i, command_test[i].ret ? "succeed" : "fail");
755 ok(error == command_test[i].error, "%d: expected error %lu, got %lu\n", i, command_test[i].error, error);
756
757 size = 0;
759 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "%d: ret %d, lasterr %ld\n", i, ret, GetLastError());
761 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "%d: ret %d, lasterr %ld\n", i, ret, GetLastError());
762 /* Zero size */
763 size = 0;
765 ok((ret && size == 0) || (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER), "%d: got ret %d, size %ld, lasterr %ld\n", i, ret, size, GetLastError());
766 /* Positive size, NULL buffer */
767 size++;
769 ok((ret && size == 0) || (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER), "%d: got ret %d, size %lu, lasterr %ld\n", i, ret, size, GetLastError());
770 /* When buffer is 1 char too short, it succeeds but trims the string: */
771 orig_size = size;
773 ok(buffer != NULL, "%d: no memory\n", i);
775 ok(ret, "%d: got ret %d\n", i, ret);
776 ok(orig_size == 0 ? size == 0 : size == orig_size - 1, "%d: got orig_size %ld, size %ld\n", i, orig_size, size);
777 ok(size == 0 || strlen(buffer) == size, "%d: size %ld, buffer size %Id\n", i, size, size ? strlen(buffer) : 0);
779 /* Long enough buffer */
781 ok(buffer != NULL, "%d: no memory\n", i);
783 ok(ret, "%d: got ret %d\n", i, ret);
784 ok(size == 0 || strlen(buffer) == size, "%d: size %ld, buffer size %Id\n", i, size, size ? strlen(buffer) : 0);
785 had_error_zero |= (error == 0);
786 had_error_zero_size_positive |= (error == 0 && size > 0);
788 }
789
790 ok(!had_error_zero || had_error_zero_size_positive, "never observed error 0 with positive size\n");
791}
#define ARRAY_SIZE(A)
Definition: main.h:20
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError, LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
Definition: internet.c:1442
return ret
Definition: mutex.c:147
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint buffer
Definition: glext.h:5915
GLsizeiptr size
Definition: glext.h:5919
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define error(str)
Definition: mkdosfs.c:1605
Definition: ftp_var.h:139
#define ERROR_INTERNET_EXTENDED_ERROR
Definition: wininet.h:1992
#define FTP_TRANSFER_TYPE_ASCII
Definition: wininet.h:918

Referenced by START_TEST().

◆ test_connect()

static void test_connect ( HINTERNET  hInternet)
static

Definition at line 61 of file ftp.c.

62{
63 HINTERNET hFtp;
64
65 /* Try a few username/password combinations:
66 * anonymous : IEUser@
67 * NULL : IEUser@
68 * NULL : NULL
69 * "" : IEUser@
70 * "" : NULL
71 */
72
73 SetLastError(0xdeadbeef);
74 hFtp = InternetConnectA(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
75 if (!hFtp)
76 {
77 skip("No ftp connection could be made to ftp.winehq.org %lu\n", GetLastError());
78 return;
79 }
81 "Expected ERROR_SUCCESS, got %ld\n", GetLastError());
83
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");
88 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
89
90 SetLastError(0xdeadbeef);
91 hFtp = InternetConnectA(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "", "IEUser@",
93 ok(!hFtp, "Expected InternetConnect to fail\n");
95 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
96
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.
102 */
103
104 SetLastError(0xdeadbeef);
106 if (!hFtp && (GetLastError() == ERROR_INTERNET_LOGIN_FAILURE))
107 {
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);
111 }
113 ok ( hFtp != NULL, "InternetConnect failed : %ld\n", GetLastError());
116 "ERROR_SUCCESS, got %ld\n", GetLastError());
118
119 SetLastError(0xdeadbeef);
120 hFtp = InternetConnectA(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "", NULL,
122 if (!hFtp)
123 {
126 "Expected ERROR_INTERNET_LOGIN_FAILURE, got %ld\n", GetLastError());
127 }
128 else
129 {
132 "Expected ERROR_SUCCESS, got %ld\n", GetLastError());
134 }
135}
#define ros_skip_flaky
Definition: minitest.h:84
#define ERROR_INTERNET_LOGIN_FAILURE
Definition: wininet.h:2004

Referenced by START_TEST().

◆ test_createdir()

static void test_createdir ( HINTERNET  hFtp,
HINTERNET  hConnect 
)
static

Definition at line 137 of file ftp.c.

138{
139 BOOL bRet;
140
141 /* Invalid internet handle, the other is a valid parameter */
142 SetLastError(0xdeadbeef);
143 bRet = FtpCreateDirectoryA(NULL, "new_directory_deadbeef");
144 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
146 "Expected ERROR_INVALID_HANDLE, got %ld\n", GetLastError());
147
148 /* No directory-name */
149 SetLastError(0xdeadbeef);
150 bRet = FtpCreateDirectoryA(hFtp, NULL);
151 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
153 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
154
155 /* Parameters are OK, but we shouldn't be allowed to create the directory */
156 SetLastError(0xdeadbeef);
157 bRet = FtpCreateDirectoryA(hFtp, "new_directory_deadbeef");
158 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
160 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %ld\n", GetLastError());
161
162 /* One small test to show that handle type is checked before parameters */
163 SetLastError(0xdeadbeef);
164 bRet = FtpCreateDirectoryA(hConnect, NULL);
165 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
167 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %ld\n", GetLastError());
168
169 SetLastError(0xdeadbeef);
170 bRet = FtpCreateDirectoryA(hConnect, "new_directory_deadbeef");
171 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
173 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %ld\n", GetLastError());
174}
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
BOOL WINAPI FtpCreateDirectoryA(HINTERNET hConnect, LPCSTR lpszDirectory)
Definition: ftp.c:566
#define ERROR_INTERNET_INCORRECT_HANDLE_TYPE
Definition: wininet.h:2007

Referenced by START_TEST().

◆ test_deletefile()

static void test_deletefile ( HINTERNET  hFtp,
HINTERNET  hConnect 
)
static

Definition at line 176 of file ftp.c.

177{
178 BOOL bRet;
179
180 /* Invalid internet handle, the other is a valid parameter */
181 SetLastError(0xdeadbeef);
182 bRet = FtpDeleteFileA(NULL, "non_existent_file_deadbeef");
183 ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
185 "Expected ERROR_INVALID_HANDLE, got %ld\n", GetLastError());
186
187 /* No filename */
188 SetLastError(0xdeadbeef);
189 bRet = FtpDeleteFileA(hFtp, NULL);
190 ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
192 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
193
194 /* Parameters are OK but remote file should not be there */
195 SetLastError(0xdeadbeef);
196 bRet = FtpDeleteFileA(hFtp, "non_existent_file_deadbeef");
197 ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
199 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %ld\n", GetLastError());
200
201 /* One small test to show that handle type is checked before parameters */
202 SetLastError(0xdeadbeef);
203 bRet = FtpDeleteFileA(hConnect, NULL);
204 ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
206 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %ld\n", GetLastError());
207
208 SetLastError(0xdeadbeef);
209 bRet = FtpDeleteFileA(hConnect, "non_existent_file_deadbeef");
210 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
212 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %ld\n", GetLastError());
213}
BOOL WINAPI FtpDeleteFileA(HINTERNET hFtpSession, LPCSTR lpszFileName)
Definition: ftp.c:1778

Referenced by START_TEST().

◆ test_find_first_file()

static void test_find_first_file ( HINTERNET  hFtp,
HINTERNET  hConnect 
)
static

Definition at line 793 of file ftp.c.

794{
795 WIN32_FIND_DATAA findData;
796 HINTERNET hSearch;
797 HINTERNET hSearch2;
798 HINTERNET hOpenFile;
799 DWORD error;
801
802 /* NULL as the search file ought to return the first file in the directory */
803 SetLastError(0xdeadbeef);
804 hSearch = FtpFindFirstFileA(hFtp, NULL, &findData, 0, 0);
805 ok ( hSearch != NULL, "Expected FtpFindFirstFileA to pass\n" );
806
807 /* This should fail as the previous handle wasn't closed */
808 SetLastError(0xdeadbeef);
809 hSearch2 = FtpFindFirstFileA(hFtp, "welcome.msg", &findData, 0, 0);
810 todo_wine ok ( hSearch2 == NULL, "Expected FtpFindFirstFileA to fail\n" );
812 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %ld\n", GetLastError() );
813 InternetCloseHandle(hSearch2); /* Just in case */
814
815 InternetCloseHandle(hSearch);
816
817 /* Try a valid filename in a subdirectory search */
818 SetLastError(0xdeadbeef);
819 hSearch = FtpFindFirstFileA(hFtp, "pub/wine", &findData, 0, 0);
820 ok( hSearch != NULL, "Expected FtpFindFirstFileA to pass\n" );
821 InternetCloseHandle(hSearch);
822
823 /* Try a valid filename in a subdirectory wildcard search */
824 SetLastError(0xdeadbeef);
825 hSearch = FtpFindFirstFileA(hFtp, "pub/w*", &findData, 0, 0);
826 ok( hSearch != NULL, "Expected FtpFindFirstFileA to pass\n" );
827 InternetCloseHandle(hSearch);
828
829 /* Try an invalid wildcard search */
830 SetLastError(0xdeadbeef);
831 hSearch = FtpFindFirstFileA(hFtp, "*/w*", &findData, 0, 0);
832 ok ( hSearch == NULL, "Expected FtpFindFirstFileA to fail\n" );
833 InternetCloseHandle(hSearch); /* Just in case */
834
835 /* change current directory, and repeat those tests - this shows
836 * that the search string is interpreted as relative directory. */
837 success = FtpSetCurrentDirectoryA(hFtp, "pub");
838 ok( success, "Expected FtpSetCurrentDirectory to succeed\n" );
839
840 SetLastError(0xdeadbeef);
841 hSearch = FtpFindFirstFileA(hFtp, "wine", &findData, 0, 0);
842 ok( hSearch != NULL, "Expected FtpFindFirstFileA to pass\n" );
843 InternetCloseHandle(hSearch);
844
845 SetLastError(0xdeadbeef);
846 hSearch = FtpFindFirstFileA(hFtp, "w*", &findData, 0, 0);
847 ok( hSearch != NULL, "Expected FtpFindFirstFileA to pass\n" );
848 InternetCloseHandle(hSearch);
849
850 success = FtpSetCurrentDirectoryA(hFtp, "..");
851 ok( success, "Expected FtpSetCurrentDirectory to succeed\n" );
852
853 /* Try FindFirstFile between FtpOpenFile and InternetCloseHandle */
854 SetLastError(0xdeadbeef);
855 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
856 ok ( hOpenFile != NULL, "Expected FtpOpenFileA to succeed\n" );
858 broken(GetLastError() == ERROR_FILE_NOT_FOUND), /* Win98 */
859 "Expected ERROR_SUCCESS, got %lu\n", GetLastError() );
860
861 /* This should fail as the OpenFile handle wasn't closed */
862 SetLastError(0xdeadbeef);
863 hSearch = FtpFindFirstFileA(hFtp, "welcome.msg", &findData, 0, 0);
865 ok ( hSearch == NULL || broken(hSearch != NULL), /* win2k */
866 "Expected FtpFindFirstFileA to fail\n" );
867 if (!hSearch)
869 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %ld\n", error );
870 else
871 {
872 ok( error == ERROR_SUCCESS, "wrong error %lu on success\n", GetLastError() );
873 InternetCloseHandle(hSearch);
874 }
875
876 InternetCloseHandle(hOpenFile);
877
878 /* Test using a nonexistent filename */
879 SetLastError(0xdeadbeef);
880 hSearch = FtpFindFirstFileA(hFtp, "this_file_should_not_exist", &findData, 0, 0);
881 ok ( hSearch == NULL, "Expected FtpFindFirstFileA to fail\n" );
883 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %ld\n", GetLastError() );
884 InternetCloseHandle(hSearch); /* Just in case */
885
886 /* Test using a nonexistent filename and a wildcard */
887 SetLastError(0xdeadbeef);
888 hSearch = FtpFindFirstFileA(hFtp, "this_file_should_not_exist*", &findData, 0, 0);
889 ok ( hSearch == NULL, "Expected FtpFindFirstFileA to fail\n" );
891 "Expected ERROR_NO_MORE_FILES, got %ld\n", GetLastError() );
892 InternetCloseHandle(hSearch); /* Just in case */
893
894 /* Test using an invalid handle type */
895 SetLastError(0xdeadbeef);
896 hSearch = FtpFindFirstFileA(hConnect, "welcome.msg", &findData, 0, 0);
897 ok ( hSearch == NULL, "Expected FtpFindFirstFileA to fail\n" );
899 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %ld\n", GetLastError() );
900 InternetCloseHandle(hSearch); /* Just in case */
901}
#define broken(x)
Definition: atltest.h:178
#define GENERIC_READ
Definition: compat.h:135
HINTERNET WINAPI FtpFindFirstFileA(HINTERNET hConnect, LPCSTR lpszSearchFile, LPWIN32_FIND_DATAA lpFindFileData, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:709
BOOL WINAPI FtpSetCurrentDirectoryA(HINTERNET hConnect, LPCSTR lpszDirectory)
Definition: ftp.c:419
HINTERNET WINAPI FtpOpenFileA(HINTERNET hFtpSession, LPCSTR lpszFileName, DWORD fdwAccess, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:1444
#define todo_wine
Definition: minitest.h:80
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define success(from, fromstr, to, tostr)
#define ERROR_NO_MORE_FILES
Definition: winerror.h:243
#define ERROR_FTP_TRANSFER_IN_PROGRESS
Definition: wininet.h:2046

Referenced by START_TEST().

◆ test_get_current_dir()

static void test_get_current_dir ( HINTERNET  hFtp,
HINTERNET  hConnect 
)
static

Definition at line 903 of file ftp.c.

904{
905 BOOL bRet;
906 DWORD dwCurrentDirectoryLen = MAX_PATH;
907 CHAR lpszCurrentDirectory[MAX_PATH];
908
909 if (!pFtpCommandA)
910 {
911 win_skip("FtpCommandA() is not available. Skipping the Ftp get_current_dir tests\n");
912 return;
913 }
914
915 /* change directories to get a more interesting pwd */
916 bRet = pFtpCommandA(hFtp, FALSE, FTP_TRANSFER_TYPE_ASCII, "CWD pub/", 0, NULL);
917 if(bRet == FALSE)
918 {
919 skip("Failed to change directories in test_get_current_dir(HINTERNET hFtp).\n");
920 return;
921 }
922
923 /* test with all NULL arguments */
924 SetLastError(0xdeadbeef);
925 bRet = FtpGetCurrentDirectoryA( NULL, NULL, 0 );
926 ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" );
927 ok ( GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got: %ld\n", GetLastError());
928
929 /* test with NULL parameters instead of expected LPSTR/LPDWORD */
930 SetLastError(0xdeadbeef);
931 bRet = FtpGetCurrentDirectoryA( hFtp, NULL, 0 );
932 ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" );
933 ok ( GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got: %ld\n", GetLastError());
934
935 /* test with no valid handle and valid parameters */
936 SetLastError(0xdeadbeef);
937 bRet = FtpGetCurrentDirectoryA( NULL, lpszCurrentDirectory, &dwCurrentDirectoryLen );
938 ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" );
939 ok ( GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got: %ld\n", GetLastError());
940
941 /* test with invalid dwCurrentDirectory and all other parameters correct */
942 SetLastError(0xdeadbeef);
943 bRet = FtpGetCurrentDirectoryA( hFtp, lpszCurrentDirectory, 0 );
944 ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" );
945 ok ( GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got: %ld\n", GetLastError());
946
947 /* test with invalid lpszCurrentDirectory and all other parameters correct */
948 SetLastError(0xdeadbeef);
949 bRet = FtpGetCurrentDirectoryA( hFtp, NULL, &dwCurrentDirectoryLen );
950 ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" );
951 ok ( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INSUFFICIENT_BUFFER, got: %ld\n", GetLastError());
952
953 /* test to show it checks the handle type */
954 SetLastError(0xdeadbeef);
955 bRet = FtpGetCurrentDirectoryA( hConnect, lpszCurrentDirectory, &dwCurrentDirectoryLen );
956 ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" );
958 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got: %ld\n", GetLastError());
959
960 /* test for the current directory with legitimate values */
961 SetLastError(0xdeadbeef);
962 bRet = FtpGetCurrentDirectoryA( hFtp, lpszCurrentDirectory, &dwCurrentDirectoryLen );
963 ok ( bRet == TRUE, "Expected FtpGetCurrentDirectoryA to pass\n" );
964 ok ( !strcmp(lpszCurrentDirectory, "/pub"), "Expected returned value \"%s\" to match \"/pub\"\n", lpszCurrentDirectory);
965 ok ( GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got: %ld\n", GetLastError());
966
967 /* test for the current directory with a size only large enough to
968 * fit the string and not the null terminating character */
969 SetLastError(0xdeadbeef);
970 dwCurrentDirectoryLen = 4;
971 lpszCurrentDirectory[4] = 'a'; /* set position 4 of the array to something else to make sure a leftover \0 isn't fooling the test */
972 bRet = FtpGetCurrentDirectoryA( hFtp, lpszCurrentDirectory, &dwCurrentDirectoryLen );
973 ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n");
974 ok ( strcmp(lpszCurrentDirectory, "/pub"), "Expected returned value \"%s\" to not match \"/pub\"\n", lpszCurrentDirectory);
975 ok ( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INSUFFICIENT_BUFFER, got: %ld\n", GetLastError());
976
977 /* test for the current directory with a size large enough to store
978 * the expected string as well as the null terminating character */
979 SetLastError(0xdeadbeef);
980 dwCurrentDirectoryLen = 5;
981 bRet = FtpGetCurrentDirectoryA( hFtp, lpszCurrentDirectory, &dwCurrentDirectoryLen );
982 ok ( bRet == TRUE, "Expected FtpGetCurrentDirectoryA to pass\n");
983 ok ( !strcmp(lpszCurrentDirectory, "/pub"), "Expected returned value \"%s\" to match \"/pub\"\n", lpszCurrentDirectory);
984 ok ( GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got: %ld\n", GetLastError());
985}
#define MAX_PATH
Definition: compat.h:34
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3324
BOOL WINAPI FtpGetCurrentDirectoryA(HINTERNET hFtpSession, LPSTR lpszCurrentDirectory, LPDWORD lpdwCurrentDirectory)
Definition: ftp.c:916
char CHAR
Definition: pedump.c:57

Referenced by START_TEST().

◆ test_getfile()

static void test_getfile ( HINTERNET  hFtp,
HINTERNET  hConnect 
)
static

Definition at line 215 of file ftp.c.

216{
217 BOOL bRet;
219
220 /* The order of checking is:
221 *
222 * All parameters except 'session handle' and 'condition flags'
223 * Session handle
224 * Session handle type
225 * Condition flags
226 */
227
228 /* Test to show the parameter checking order depends on the Windows version */
229 SetLastError(0xdeadbeef);
230 bRet = FtpGetFileA(NULL, NULL, "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
231 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
234 "Expected ERROR_INVALID_HANDLE (win98) or ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
235
236 /* Test to show session handle is checked before 'condition flags' */
237 SetLastError(0xdeadbeef);
238 bRet = FtpGetFileA(NULL, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, 5, 0);
239 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
241 "Expected ERROR_INVALID_HANDLE, got %ld\n", GetLastError());
242
243 /* Make sure we start clean */
244
245 DeleteFileA("should_be_non_existing_deadbeef");
246 DeleteFileA("should_also_be_non_existing_deadbeef");
247
248 /* No remote file */
249 SetLastError(0xdeadbeef);
250 bRet = FtpGetFileA(hFtp, NULL, "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
251 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
253 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
254 ok (GetFileAttributesA("should_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
255 "Local file should not have been created\n");
256 DeleteFileA("should_be_non_existing_deadbeef");
257
258 /* No local file */
259 SetLastError(0xdeadbeef);
260 bRet = FtpGetFileA(hFtp, "welcome.msg", NULL, FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
261 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
263 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
264
265 /* Zero attributes */
266 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_existing_non_deadbeef", FALSE, 0, FTP_TRANSFER_TYPE_UNKNOWN, 0);
267 ok ( bRet == TRUE, "Expected FtpGetFileA to succeed\n");
268 ok (GetFileAttributesA("should_be_existing_non_deadbeef") != INVALID_FILE_ATTRIBUTES,
269 "Local file should have been created\n");
270 DeleteFileA("should_be_existing_non_deadbeef");
271
272 /* Illegal condition flags */
273 SetLastError(0xdeadbeef);
274 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, 0xffffffff, 0);
275 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
277 "Expected ERROR_INTERNET_EXTENDED_ERROR or ERROR_INVALID_PARAMETER (win98), got %ld\n", GetLastError());
278 ok (GetFileAttributesA("should_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
279 "Local file should not have been created\n");
280 DeleteFileA("should_be_non_existing_deadbeef");
281
282 /* Remote file doesn't exist (and local doesn't exist as well) */
283 SetLastError(0xdeadbeef);
284 bRet = FtpGetFileA(hFtp, "should_be_non_existing_deadbeef", "should_also_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
285 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
287 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %ld\n", GetLastError());
288 /* Currently Wine always creates the local file (even on failure) which is not correct, hence the test */
289 ok (GetFileAttributesA("should_also_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
290 "Local file should not have been created\n");
291
292 DeleteFileA("should_also_be_non_existing_deadbeef");
293
294 /* Same call as the previous but now the local file does exists. Windows just removes the file if the call fails
295 * even if the local existed before!
296 */
297
298 /* Create a temporary local file */
299 SetLastError(0xdeadbeef);
300 hFile = CreateFileA("should_also_be_non_existing_deadbeef", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
301 ok ( hFile != NULL, "Error creating a local file : %ld\n", GetLastError());
303 SetLastError(0xdeadbeef);
304 bRet = FtpGetFileA(hFtp, "should_be_non_existing_deadbeef", "should_also_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
305 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
307 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %ld\n", GetLastError());
308 /* Currently Wine always creates the local file (even on failure) which is not correct, hence the test */
309 ok (GetFileAttributesA("should_also_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
310 "Local file should not have been created\n");
311
312 DeleteFileA("should_also_be_non_existing_deadbeef");
313
314 /* This one should succeed */
315 SetLastError(0xdeadbeef);
316 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_existing_non_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
317 ok ( bRet == TRUE, "Expected FtpGetFileA to fail\n");
318 ok ( GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", GetLastError());
319
320 if (GetFileAttributesA("should_be_existing_non_deadbeef") != INVALID_FILE_ATTRIBUTES)
321 {
322 /* Should succeed as fFailIfExists is set to FALSE (meaning don't fail if local file exists) */
323 SetLastError(0xdeadbeef);
324 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
325 ok ( bRet == TRUE, "Expected FtpGetFileA to succeed\n");
327 "Expected ERROR_SUCCESS, got %ld\n", GetLastError());
328
329 /* Should fail as fFailIfExists is set to TRUE */
330 SetLastError(0xdeadbeef);
331 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", TRUE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
332 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
334 "Expected ERROR_FILE_EXISTS, got %ld\n", GetLastError());
335
336 /* Prove that the existence of the local file is checked first (or at least reported last) */
337 SetLastError(0xdeadbeef);
338 bRet = FtpGetFileA(hFtp, "should_be_non_existing_deadbeef", "should_be_non_existing_deadbeef", TRUE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
339 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
341 "Expected ERROR_FILE_EXISTS, got %ld\n", GetLastError());
342
343 DeleteFileA("should_be_existing_non_deadbeef");
344 }
345
346 /* Test to show the parameter checking order depends on the Windows version */
347 SetLastError(0xdeadbeef);
348 bRet = FtpGetFileA(hConnect, NULL, "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
349 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
352 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE (win98) or ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
353
354 /* Test to show that 'session handle type' is checked before 'condition flags' */
355 SetLastError(0xdeadbeef);
356 bRet = FtpGetFileA(hConnect, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, 5, 0);
357 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
359 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %ld\n", GetLastError());
360
361 SetLastError(0xdeadbeef);
362 bRet = FtpGetFileA(hConnect, "should_be_non_existing_deadbeef", "should_be_non_existing_deadbeef", TRUE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
363 ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
365 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %ld\n", GetLastError());
366}
#define CloseHandle
Definition: compat.h:739
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
DWORD WINAPI GetFileAttributesA(LPCSTR lpFileName)
Definition: fileinfo.c:620
BOOL WINAPI FtpGetFileA(HINTERNET hInternet, LPCSTR lpszRemoteFile, LPCSTR lpszNewFile, BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags, DWORD_PTR dwContext)
Definition: ftp.c:1560
#define CREATE_ALWAYS
Definition: disk.h:72
_In_ HANDLE hFile
Definition: mswsock.h:90
#define GENERIC_WRITE
Definition: nt_native.h:90
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
#define ERROR_FILE_EXISTS
Definition: winerror.h:287
#define FTP_TRANSFER_TYPE_UNKNOWN
Definition: wininet.h:917

Referenced by START_TEST().

◆ test_getfile_no_open()

static void test_getfile_no_open ( void  )
static

Definition at line 48 of file ftp.c.

49{
50 BOOL bRet;
51
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");
58 "Expected ERROR_INTERNET_NOT_INITIALIZED or ERROR_INVALID_HANDLE (win98), got %ld\n", GetLastError());
59}
#define ERROR_INTERNET_NOT_INITIALIZED
Definition: wininet.h:2080

Referenced by START_TEST().

◆ test_openfile()

static void test_openfile ( HINTERNET  hFtp,
HINTERNET  hConnect 
)
static

Definition at line 382 of file ftp.c.

383{
384 HINTERNET hOpenFile;
385
386 /* Invalid internet handle, the rest are valid parameters */
387 SetLastError(0xdeadbeef);
388 hOpenFile = FtpOpenFileA(NULL, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
389 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
391 "Expected ERROR_INVALID_HANDLE, got %ld\n", GetLastError());
392 InternetCloseHandle(hOpenFile); /* Just in case */
393
394 /* No filename */
395 SetLastError(0xdeadbeef);
397 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
399 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
400 InternetCloseHandle(hOpenFile); /* Just in case */
401
402 /* Illegal access flags */
403 SetLastError(0xdeadbeef);
404 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", 0, FTP_TRANSFER_TYPE_ASCII, 0);
405 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
407 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
408 InternetCloseHandle(hOpenFile); /* Just in case */
409
410 /* Illegal combination of access flags */
411 SetLastError(0xdeadbeef);
412 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ|GENERIC_WRITE, FTP_TRANSFER_TYPE_ASCII, 0);
413 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
415 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
416 InternetCloseHandle(hOpenFile); /* Just in case */
417
418 /* Illegal condition flags */
419 SetLastError(0xdeadbeef);
420 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, 0xffffffff, 0);
421 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
423 "Expected ERROR_INTERNET_EXTENDED_ERROR or ERROR_INVALID_PARAMETER (win98), got %ld\n", GetLastError());
424 InternetCloseHandle(hOpenFile); /* Just in case */
425
426 SetLastError(0xdeadbeef);
427 hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
428 ok ( hOpenFile != NULL, "Expected FtpOpenFileA to succeed\n");
430 broken(GetLastError() == ERROR_FILE_NOT_FOUND), /* Win98 */
431 "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
432
433 if (hOpenFile)
434 {
435 BOOL bRet;
436 DWORD error;
437 HINTERNET hOpenFile2;
439
440 /* We have a handle so all ftp calls should fail (TODO: Put all ftp-calls in here) */
441 SetLastError(0xdeadbeef);
442 bRet = FtpCreateDirectoryA(hFtp, "new_directory_deadbeef");
444 ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
446 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %ld\n", error);
448
449 SetLastError(0xdeadbeef);
450 bRet = FtpDeleteFileA(hFtp, "non_existent_file_deadbeef");
452 ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
454 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %ld\n", error);
456
457 SetLastError(0xdeadbeef);
458 bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
460 ok ( bRet == FALSE || broken(bRet == TRUE), "Expected FtpGetFileA to fail\n");
462 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %ld\n", error);
463 DeleteFileA("should_be_non_existing_deadbeef"); /* Just in case */
464
465 SetLastError(0xdeadbeef);
466 hOpenFile2 = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
468 ok ( bRet == FALSE || broken(bRet == TRUE), "Expected FtpOpenFileA to fail\n");
470 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %ld\n", error);
471 InternetCloseHandle(hOpenFile2); /* Just in case */
472
473 /* Create a temporary local file */
474 SetLastError(0xdeadbeef);
475 hFile = CreateFileA("now_existing_local", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
476 ok ( hFile != NULL, "Error creating a local file : %ld\n", GetLastError());
478 SetLastError(0xdeadbeef);
479 bRet = FtpPutFileA(hFtp, "now_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
481 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
483 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %ld\n", error);
484 DeleteFileA("now_existing_local");
485
486 SetLastError(0xdeadbeef);
487 bRet = FtpRemoveDirectoryA(hFtp, "should_be_non_existing_deadbeef_dir");
489 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
491 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %ld\n", error);
492
493 SetLastError(0xdeadbeef);
494 bRet = FtpRenameFileA(hFtp , "should_be_non_existing_deadbeef", "new");
496 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
498 "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %ld\n", error);
499 }
500
501 InternetCloseHandle(hOpenFile);
502
503 /* One small test to show that handle type is checked before parameters */
504 SetLastError(0xdeadbeef);
505 hOpenFile = FtpOpenFileA(hConnect, "welcome.msg", GENERIC_READ, 5, 0);
506 ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
508 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %ld\n", GetLastError());
509 InternetCloseHandle(hOpenFile); /* Just in case */
510
511 SetLastError(0xdeadbeef);
512 hOpenFile = FtpOpenFileA(hConnect, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
513 ok ( hOpenFile == NULL, "Expected FtpOpenFileA to fail\n");
515 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %ld\n", GetLastError());
516
517 InternetCloseHandle(hOpenFile); /* Just in case */
518}
BOOL WINAPI FtpRenameFileA(HINTERNET hFtpSession, LPCSTR lpszSrc, LPCSTR lpszDest)
Definition: ftp.c:2068
BOOL WINAPI FtpPutFileA(HINTERNET hConnect, LPCSTR lpszLocalFile, LPCSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:224
BOOL WINAPI FtpRemoveDirectoryA(HINTERNET hFtpSession, LPCSTR lpszDirectory)
Definition: ftp.c:1925
static void trace_extended_error(DWORD error)
Definition: ftp.c:368

Referenced by START_TEST().

◆ test_putfile()

static void test_putfile ( HINTERNET  hFtp,
HINTERNET  hConnect 
)
static

Definition at line 520 of file ftp.c.

521{
522 BOOL bRet;
524
525 /* The order of checking is:
526 *
527 * All parameters except 'session handle' and 'condition flags'
528 * Session handle
529 * Session handle type
530 * Condition flags
531 */
532
533 /* Test to show the parameter checking order depends on the Windows version */
534 SetLastError(0xdeadbeef);
535 bRet = FtpPutFileA(NULL, NULL, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
536 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
539 "Expected ERROR_INVALID_HANDLE (win98) or ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
540
541 /* Test to show session handle is checked before 'condition flags' */
542 SetLastError(0xdeadbeef);
543 bRet = FtpPutFileA(NULL, "non_existing_local", "non_existing_remote", 5, 0);
544 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
546 "Expected ERROR_INVALID_HANDLE, got %ld\n", GetLastError());
547
548 /* Start clean */
549 DeleteFileA("non_existing_local");
550
551 /* No local file given */
552 SetLastError(0xdeadbeef);
553 bRet = FtpPutFileA(hFtp, NULL, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
554 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
556 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
557
558 /* No remote file given */
559 SetLastError(0xdeadbeef);
560 bRet = FtpPutFileA(hFtp, "non_existing_local", NULL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
561 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
563 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
564
565 /* Illegal condition flags */
566 SetLastError(0xdeadbeef);
567 bRet = FtpPutFileA(hFtp, "non_existing_local", "non_existing_remote", 5, 0);
568 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
570 "Expected ERROR_FILE_NOT_FOUND or ERROR_INVALID_PARAMETER (win98), got %ld\n", GetLastError());
571
572 /* Parameters are OK but local file doesn't exist */
573 SetLastError(0xdeadbeef);
574 bRet = FtpPutFileA(hFtp, "non_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
575 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
577 "Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
578
579 /* Create a temporary local file */
580 SetLastError(0xdeadbeef);
581 hFile = CreateFileA("now_existing_local", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
582 ok ( hFile != NULL, "Error creating a local file : %ld\n", GetLastError());
584
585 /* Local file exists but we shouldn't be allowed to 'put' the file */
586 SetLastError(0xdeadbeef);
587 bRet = FtpPutFileA(hFtp, "now_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
588 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
590 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %ld\n", GetLastError());
591
592 DeleteFileA("now_existing_local");
593
594 /* Test to show the parameter checking order depends on the Windows version */
595 SetLastError(0xdeadbeef);
596 bRet = FtpPutFileA(hConnect, NULL, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
597 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
600 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE (win98) or ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
601
602 /* Test to show that 'session handle type' is checked before 'condition flags' */
603 SetLastError(0xdeadbeef);
604 bRet = FtpPutFileA(hConnect, "non_existing_local", "non_existing_remote", 5, 0);
605 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
607 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %ld\n", GetLastError());
608
609 SetLastError(0xdeadbeef);
610 bRet = FtpPutFileA(hConnect, "non_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
611 ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
613 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %ld\n", GetLastError());
614}

Referenced by START_TEST().

◆ test_removedir()

static void test_removedir ( HINTERNET  hFtp,
HINTERNET  hConnect 
)
static

Definition at line 616 of file ftp.c.

617{
618 BOOL bRet;
619
620 /* Invalid internet handle, the other is a valid parameter */
621 SetLastError(0xdeadbeef);
622 bRet = FtpRemoveDirectoryA(NULL, "should_be_non_existing_deadbeef_dir");
623 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
625 "Expected ERROR_INVALID_HANDLE, got %ld\n", GetLastError());
626
627 /* No remote directory given */
628 SetLastError(0xdeadbeef);
629 bRet = FtpRemoveDirectoryA(hFtp, NULL);
630 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
632 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
633
634 /* Remote directory doesn't exist */
635 SetLastError(0xdeadbeef);
636 bRet = FtpRemoveDirectoryA(hFtp, "should_be_non_existing_deadbeef_dir");
637 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
639 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %ld\n", GetLastError());
640
641 /* We shouldn't be allowed to remove that directory */
642 SetLastError(0xdeadbeef);
643 bRet = FtpRemoveDirectoryA(hFtp, "pub");
644 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
646 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %ld\n", GetLastError());
647
648 /* One small test to show that handle type is checked before parameters */
649 SetLastError(0xdeadbeef);
650 bRet = FtpRemoveDirectoryA(hConnect, NULL);
651 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
653 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %ld\n", GetLastError());
654
655 SetLastError(0xdeadbeef);
656 bRet = FtpRemoveDirectoryA(hConnect, "should_be_non_existing_deadbeef_dir");
657 ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
659 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %ld\n", GetLastError());
660}

Referenced by START_TEST().

◆ test_renamefile()

static void test_renamefile ( HINTERNET  hFtp,
HINTERNET  hConnect 
)
static

Definition at line 662 of file ftp.c.

663{
664 BOOL bRet;
665
666 /* Invalid internet handle, the rest are valid parameters */
667 SetLastError(0xdeadbeef);
668 bRet = FtpRenameFileA(NULL , "should_be_non_existing_deadbeef", "new");
669 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
671 "Expected ERROR_INVALID_HANDLE, got %ld\n", GetLastError());
672
673 /* No 'existing' file */
674 SetLastError(0xdeadbeef);
675 bRet = FtpRenameFileA(hFtp , NULL, "new");
676 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
678 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
679
680 /* No new file */
681 SetLastError(0xdeadbeef);
682 bRet = FtpRenameFileA(hFtp , "should_be_non_existing_deadbeef", NULL);
683 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
685 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
686
687 /* Existing file shouldn't be there */
688 SetLastError(0xdeadbeef);
689 bRet = FtpRenameFileA(hFtp , "should_be_non_existing_deadbeef", "new");
690 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
692 "Expected ERROR_INTERNET_EXTENDED_ERROR, got %ld\n", GetLastError());
693
694 /* One small test to show that handle type is checked before parameters */
695 SetLastError(0xdeadbeef);
696 bRet = FtpRenameFileA(hConnect , "should_be_non_existing_deadbeef", NULL);
697 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
699 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %ld\n", GetLastError());
700
701 SetLastError(0xdeadbeef);
702 bRet = FtpRenameFileA(hConnect , "should_be_non_existing_deadbeef", "new");
703 ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
705 "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %ld\n", GetLastError());
706}

Referenced by START_TEST().

◆ test_status_callbacks()

static void test_status_callbacks ( HINTERNET  hInternet)
static

Definition at line 1002 of file ftp.c.

1003{
1005 HINTERNET hFtp;
1006 BOOL ret;
1007
1008 cb = pInternetSetStatusCallbackA(hInternet, status_callback);
1009 ok(cb == NULL, "expected NULL got %p\n", cb);
1010
1011 hFtp = InternetConnectA(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@",
1013 if (!hFtp)
1014 {
1015 skip("No ftp connection could be made to ftp.winehq.org %lu\n", GetLastError());
1016 return;
1017 }
1018
1019 ret = InternetCloseHandle(hFtp);
1020 ok(ret, "InternetCloseHandle failed %lu\n", GetLastError());
1021
1022 cb = pInternetSetStatusCallbackA(hInternet, NULL);
1023 ok(cb == status_callback, "expected check_status got %p\n", cb);
1024}
static MonoProfilerRuntimeShutdownBeginCallback cb
Definition: metahost.c:118
static void WINAPI status_callback(HINTERNET handle, DWORD_PTR ctx, DWORD status, LPVOID info, DWORD info_len)
Definition: ftp.c:987
static HINTERNET *static INTERNET_STATUS_CALLBACK
Definition: ftp.c:45

Referenced by START_TEST().

◆ trace_extended_error()

static void trace_extended_error ( DWORD  error)
static

Definition at line 368 of file ftp.c.

369{
370 DWORD code, buflen = 0;
371
374 {
375 char *text = HeapAlloc(GetProcessHeap(), 0, ++buflen);
377 trace("%lu %s\n", code, text);
379 }
380}
const WCHAR * text
Definition: package.c:1826
Definition: inflate.c:139

Referenced by test_openfile().

Variable Documentation

◆ BOOL

Definition at line 44 of file ftp.c.

◆ DWORD

Definition at line 44 of file ftp.c.

◆ DWORD_PTR

Definition at line 44 of file ftp.c.

◆ INTERNET_STATUS_CALLBACK

HINTERNET *static INTERNET_STATUS_CALLBACK

Definition at line 45 of file ftp.c.

◆ LPCSTR

Definition at line 44 of file ftp.c.