ReactOS  0.4.14-dev-583-g2a1ba2c
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 989 of file ftp.c.

990 {
991  HMODULE hWininet;
992  HANDLE hInternet, hFtp, hHttp;
993 
994  hWininet = GetModuleHandleA("wininet.dll");
995 
996  if(!GetProcAddress(hWininet, "InternetGetCookieExW")) {
997  win_skip("Too old IE (older than 6.0)\n");
998  return;
999  }
1000 
1001  pFtpCommandA = (void*)GetProcAddress(hWininet, "FtpCommandA");
1002  pInternetSetStatusCallbackA = (void*)GetProcAddress(hWininet, "InternetSetStatusCallbackA");
1003 
1004  SetLastError(0xdeadbeef);
1005  hInternet = InternetOpenA("winetest", 0, NULL, NULL, 0);
1006  ok(hInternet != NULL, "InternetOpen failed: %u\n", GetLastError());
1007 
1008  hFtp = InternetConnectA(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
1009  if (!hFtp)
1010  {
1011  InternetCloseHandle(hInternet);
1012  skip("No ftp connection could be made to ftp.winehq.org\n");
1013  return;
1014  }
1015  hHttp = InternetConnectA(hInternet, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1016  if (!hHttp)
1017  {
1018  InternetCloseHandle(hFtp);
1019  InternetCloseHandle(hInternet);
1020  skip("No http connection could be made to www.winehq.org\n");
1021  return;
1022  }
1023 
1024  /* The first call should always be a proper InternetOpen, if not
1025  * several calls will return ERROR_INTERNET_NOT_INITIALIZED when
1026  * all parameters are correct but no session handle is given. Whereas
1027  * the same call will return ERROR_INVALID_HANDLE if an InternetOpen
1028  * is done before.
1029  * The following test will show that behaviour, where the tests inside
1030  * the other sub-tests will show the other situation.
1031  */
1033  test_connect(hInternet);
1034  test_createdir(hFtp, hHttp);
1035  test_deletefile(hFtp, hHttp);
1036  test_getfile(hFtp, hHttp);
1037  test_openfile(hFtp, hHttp);
1038  test_putfile(hFtp, hHttp);
1039  test_removedir(hFtp, hHttp);
1040  test_renamefile(hFtp, hHttp);
1041  test_command(hFtp);
1042  test_find_first_file(hFtp, hHttp);
1043  test_get_current_dir(hFtp, hHttp);
1044  test_status_callbacks(hInternet);
1045 
1046  InternetCloseHandle(hHttp);
1047  InternetCloseHandle(hFtp);
1048  InternetCloseHandle(hInternet);
1049 }
static void test_getfile(HINTERNET hFtp, HINTERNET hConnect)
Definition: ftp.c:217
HINTERNET WINAPI InternetConnectA(HINTERNET hInternet, LPCSTR lpszServerName, INTERNET_PORT nServerPort, LPCSTR lpszUserName, LPCSTR lpszPassword, DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
Definition: internet.c:1343
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static void test_getfile_no_open(void)
Definition: ftp.c:48
static void test_deletefile(HINTERNET hFtp, HINTERNET hConnect)
Definition: ftp.c:178
BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
Definition: internet.c:1436
#define INTERNET_DEFAULT_HTTP_PORT
Definition: winhttp.h:36
HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType, LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
Definition: internet.c:1079
static void test_status_callbacks(HINTERNET hInternet)
Definition: ftp.c:965
static void test_createdir(HINTERNET hFtp, HINTERNET hConnect)
Definition: ftp.c:139
smooth NULL
Definition: ftsmooth.c:416
static void test_openfile(HINTERNET hFtp, HINTERNET hConnect)
Definition: ftp.c:384
static void test_find_first_file(HINTERNET hFtp, HINTERNET hConnect)
Definition: ftp.c:756
#define SetLastError(x)
Definition: compat.h:417
#define INTERNET_DEFAULT_FTP_PORT
Definition: wininet.h:38
#define INTERNET_SERVICE_FTP
Definition: wininet.h:560
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:821
static void test_get_current_dir(HINTERNET hFtp, HINTERNET hConnect)
Definition: ftp.c:866
#define INTERNET_FLAG_PASSIVE
Definition: wininet.h:65
static void test_renamefile(HINTERNET hFtp, HINTERNET hConnect)
Definition: ftp.c:664
static void test_connect(HINTERNET hInternet)
Definition: ftp.c:61
static void test_removedir(HINTERNET hFtp, HINTERNET hConnect)
Definition: ftp.c:618
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define GetProcAddress(x, y)
Definition: compat.h:418
#define win_skip
Definition: test.h:150
static void test_putfile(HINTERNET hFtp, HINTERNET hConnect)
Definition: ftp.c:522
#define INTERNET_SERVICE_HTTP
Definition: wininet.h:562
static void test_command(HINTERNET hFtp)
Definition: ftp.c:710

◆ status_callback()

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

Definition at line 950 of file ftp.c.

951 {
952  switch (status)
953  {
958  trace("%p %lx %u %s %u\n", handle, ctx, status, (char *)info, info_len);
959  break;
960  default:
961  break;
962  }
963 }
#define INTERNET_STATUS_CONNECTING_TO_SERVER
Definition: wininet.h:885
#define INTERNET_STATUS_NAME_RESOLVED
Definition: wininet.h:884
#define trace
Definition: atltest.h:70
#define INTERNET_STATUS_RESOLVING_NAME
Definition: wininet.h:883
#define INTERNET_STATUS_CONNECTED_TO_SERVER
Definition: wininet.h:886
Definition: ps.c:97

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 710 of file ftp.c.

711 {
712  BOOL ret;
713  DWORD error;
714  unsigned int i;
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" },
728  { FALSE, ERROR_INTERNET_EXTENDED_ERROR, "size " },
729  { FALSE, ERROR_INTERNET_EXTENDED_ERROR, " size" },
730  { FALSE, ERROR_INTERNET_EXTENDED_ERROR, "size " },
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  SetLastError(0xdeadbeef);
748  ret = pFtpCommandA(hFtp, FALSE, FTP_TRANSFER_TYPE_ASCII, command_test[i].cmd, 0, NULL);
749  error = GetLastError();
750 
751  ok(ret == command_test[i].ret, "%d: expected FtpCommandA to %s\n", i, command_test[i].ret ? "succeed" : "fail");
752  ok(error == command_test[i].error, "%d: expected error %u, got %u\n", i, command_test[i].error, error);
753  }
754 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define error(str)
Definition: mkdosfs.c:1605
#define ERROR_INTERNET_EXTENDED_ERROR
Definition: wininet.h:1992
Definition: ftp_var.h:139
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
char * cmd
Definition: vfdcmd.c:85
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
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
int ret
#define ARRAY_SIZE(a)
Definition: main.h:24
#define ok(value,...)
Definition: atltest.h:57
#define FTP_TRANSFER_TYPE_ASCII
Definition: wininet.h:918
#define win_skip
Definition: test.h:150

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 : NULL
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) /* some servers accept an empty password */
76  {
78  ok ( GetLastError() == ERROR_SUCCESS, "ERROR_SUCCESS, got %d\n", GetLastError());
79  InternetCloseHandle(hFtp);
80  }
81  else
84  "Expected ERROR_INTERNET_LOGIN_FAILURE, got %d\n", GetLastError());
85 
86  SetLastError(0xdeadbeef);
87  hFtp = InternetConnectA(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, NULL, "IEUser@", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
88  ok ( hFtp == NULL, "Expected InternetConnect to fail\n");
90  "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
91 
92  SetLastError(0xdeadbeef);
93  hFtp = InternetConnectA(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "", "IEUser@",
95  ok(!hFtp, "Expected InternetConnect to fail\n");
97  "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
98 
99  /* Using a NULL username and password will be interpreted as anonymous ftp. The username will be 'anonymous' the password
100  * is created via some simple heuristics (see dlls/wininet/ftp.c).
101  * On Wine this registry key is not set by default so (NULL, NULL) will result in anonymous ftp with an (most likely) not
102  * accepted password (the username).
103  * If the first call fails because we get an ERROR_INTERNET_LOGIN_FAILURE, we try again with a (more) correct password.
104  */
105 
106  SetLastError(0xdeadbeef);
108  if (!hFtp && (GetLastError() == ERROR_INTERNET_LOGIN_FAILURE))
109  {
110  /* We are most likely running on a clean Wine install or a Windows install where the registry key is removed */
111  SetLastError(0xdeadbeef);
112  hFtp = InternetConnectA(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
113  }
115  ok ( hFtp != NULL, "InternetConnect failed : %d\n", GetLastError());
118  "ERROR_SUCCESS, got %d\n", GetLastError());
119  InternetCloseHandle(hFtp);
120 
121  SetLastError(0xdeadbeef);
122  hFtp = InternetConnectA(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "", NULL,
124  if (!hFtp)
125  {
128  "Expected ERROR_INTERNET_LOGIN_FAILURE, got %d\n", GetLastError());
129  }
130  else
131  {
134  "Expected ERROR_SUCCESS, got %d\n", GetLastError());
135  InternetCloseHandle(hFtp);
136  }
137 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define ERROR_SUCCESS
Definition: deptool.c:10
HINTERNET WINAPI InternetConnectA(HINTERNET hInternet, LPCSTR lpszServerName, INTERNET_PORT nServerPort, LPCSTR lpszUserName, LPCSTR lpszPassword, DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
Definition: internet.c:1343
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
Definition: internet.c:1436
smooth NULL
Definition: ftsmooth.c:416
#define SetLastError(x)
Definition: compat.h:417
#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 ERROR_INTERNET_LOGIN_FAILURE
Definition: wininet.h:2004
#define ros_skip_flaky
Definition: test.h:167
#define ok(value,...)
Definition: atltest.h:57

Referenced by START_TEST().

◆ test_createdir()

static void test_createdir ( HINTERNET  hFtp,
HINTERNET  hConnect 
)
static

Definition at line 139 of file ftp.c.

140 {
141  BOOL bRet;
142 
143  /* Invalid internet handle, the other is a valid parameter */
144  SetLastError(0xdeadbeef);
145  bRet = FtpCreateDirectoryA(NULL, "new_directory_deadbeef");
146  ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
148  "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
149 
150  /* No directory-name */
151  SetLastError(0xdeadbeef);
152  bRet = FtpCreateDirectoryA(hFtp, NULL);
153  ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
155  "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
156 
157  /* Parameters are OK, but we shouldn't be allowed to create the directory */
158  SetLastError(0xdeadbeef);
159  bRet = FtpCreateDirectoryA(hFtp, "new_directory_deadbeef");
160  ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
162  "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
163 
164  /* One small test to show that handle type is checked before parameters */
165  SetLastError(0xdeadbeef);
166  bRet = FtpCreateDirectoryA(hConnect, NULL);
167  ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
169  "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
170 
171  SetLastError(0xdeadbeef);
172  bRet = FtpCreateDirectoryA(hConnect, "new_directory_deadbeef");
173  ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
175  "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
176 }
#define ERROR_INTERNET_INCORRECT_HANDLE_TYPE
Definition: wininet.h:2007
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
BOOL WINAPI FtpCreateDirectoryA(HINTERNET hConnect, LPCSTR lpszDirectory)
Definition: ftp.c:563
#define ERROR_INTERNET_EXTENDED_ERROR
Definition: wininet.h:1992
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define SetLastError(x)
Definition: compat.h:417
#define ok(value,...)
Definition: atltest.h:57

Referenced by START_TEST().

◆ test_deletefile()

static void test_deletefile ( HINTERNET  hFtp,
HINTERNET  hConnect 
)
static

Definition at line 178 of file ftp.c.

179 {
180  BOOL bRet;
181 
182  /* Invalid internet handle, the other is a valid parameter */
183  SetLastError(0xdeadbeef);
184  bRet = FtpDeleteFileA(NULL, "non_existent_file_deadbeef");
185  ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
187  "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
188 
189  /* No filename */
190  SetLastError(0xdeadbeef);
191  bRet = FtpDeleteFileA(hFtp, NULL);
192  ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
194  "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
195 
196  /* Parameters are OK but remote file should not be there */
197  SetLastError(0xdeadbeef);
198  bRet = FtpDeleteFileA(hFtp, "non_existent_file_deadbeef");
199  ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
201  "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
202 
203  /* One small test to show that handle type is checked before parameters */
204  SetLastError(0xdeadbeef);
205  bRet = FtpDeleteFileA(hConnect, NULL);
206  ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
208  "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
209 
210  SetLastError(0xdeadbeef);
211  bRet = FtpDeleteFileA(hConnect, "non_existent_file_deadbeef");
212  ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
214  "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
215 }
#define ERROR_INTERNET_INCORRECT_HANDLE_TYPE
Definition: wininet.h:2007
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define ERROR_INTERNET_EXTENDED_ERROR
Definition: wininet.h:1992
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define SetLastError(x)
Definition: compat.h:417
#define ok(value,...)
Definition: atltest.h:57
BOOL WINAPI FtpDeleteFileA(HINTERNET hFtpSession, LPCSTR lpszFileName)
Definition: ftp.c:1774

Referenced by START_TEST().

◆ test_find_first_file()

static void test_find_first_file ( HINTERNET  hFtp,
HINTERNET  hConnect 
)
static

Definition at line 756 of file ftp.c.

757 {
758  WIN32_FIND_DATAA findData;
759  HINTERNET hSearch;
760  HINTERNET hSearch2;
761  HINTERNET hOpenFile;
762  DWORD error;
763  BOOL success;
764 
765  /* NULL as the search file ought to return the first file in the directory */
766  SetLastError(0xdeadbeef);
767  hSearch = FtpFindFirstFileA(hFtp, NULL, &findData, 0, 0);
768  ok ( hSearch != NULL, "Expected FtpFindFirstFileA to pass\n" );
769 
770  /* This should fail as the previous handle wasn't closed */
771  SetLastError(0xdeadbeef);
772  hSearch2 = FtpFindFirstFileA(hFtp, "welcome.msg", &findData, 0, 0);
773  todo_wine ok ( hSearch2 == NULL, "Expected FtpFindFirstFileA to fail\n" );
775  "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError() );
776  InternetCloseHandle(hSearch2); /* Just in case */
777 
778  InternetCloseHandle(hSearch);
779 
780  /* Try a valid filename in a subdirectory search */
781  SetLastError(0xdeadbeef);
782  hSearch = FtpFindFirstFileA(hFtp, "pub/wine", &findData, 0, 0);
783  ok( hSearch != NULL, "Expected FtpFindFirstFileA to pass\n" );
784  InternetCloseHandle(hSearch);
785 
786  /* Try a valid filename in a subdirectory wildcard search */
787  SetLastError(0xdeadbeef);
788  hSearch = FtpFindFirstFileA(hFtp, "pub/w*", &findData, 0, 0);
789  ok( hSearch != NULL, "Expected FtpFindFirstFileA to pass\n" );
790  InternetCloseHandle(hSearch);
791 
792  /* Try an invalid wildcard search */
793  SetLastError(0xdeadbeef);
794  hSearch = FtpFindFirstFileA(hFtp, "*/w*", &findData, 0, 0);
795  ok ( hSearch == NULL, "Expected FtpFindFirstFileA to fail\n" );
796  InternetCloseHandle(hSearch); /* Just in case */
797 
798  /* change current directory, and repeat those tests - this shows
799  * that the search string is interpreted as relative directory. */
800  success = FtpSetCurrentDirectoryA(hFtp, "pub");
801  ok( success, "Expected FtpSetCurrentDirectory to succeed\n" );
802 
803  SetLastError(0xdeadbeef);
804  hSearch = FtpFindFirstFileA(hFtp, "wine", &findData, 0, 0);
805  ok( hSearch != NULL, "Expected FtpFindFirstFileA to pass\n" );
806  InternetCloseHandle(hSearch);
807 
808  SetLastError(0xdeadbeef);
809  hSearch = FtpFindFirstFileA(hFtp, "w*", &findData, 0, 0);
810  ok( hSearch != NULL, "Expected FtpFindFirstFileA to pass\n" );
811  InternetCloseHandle(hSearch);
812 
813  success = FtpSetCurrentDirectoryA(hFtp, "..");
814  ok( success, "Expected FtpSetCurrentDirectory to succeed\n" );
815 
816  /* Try FindFirstFile between FtpOpenFile and InternetCloseHandle */
817  SetLastError(0xdeadbeef);
818  hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
819  ok ( hOpenFile != NULL, "Expected FtpOpenFileA to succeed\n" );
820  ok ( GetLastError() == ERROR_SUCCESS ||
821  broken(GetLastError() == ERROR_FILE_NOT_FOUND), /* Win98 */
822  "Expected ERROR_SUCCESS, got %u\n", GetLastError() );
823 
824  /* This should fail as the OpenFile handle wasn't closed */
825  SetLastError(0xdeadbeef);
826  hSearch = FtpFindFirstFileA(hFtp, "welcome.msg", &findData, 0, 0);
827  error = GetLastError();
828  ok ( hSearch == NULL || broken(hSearch != NULL), /* win2k */
829  "Expected FtpFindFirstFileA to fail\n" );
830  if (!hSearch)
832  "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error );
833  else
834  {
835  ok( error == ERROR_SUCCESS, "wrong error %u on success\n", GetLastError() );
836  InternetCloseHandle(hSearch);
837  }
838 
839  InternetCloseHandle(hOpenFile);
840 
841  /* Test using a nonexistent filename */
842  SetLastError(0xdeadbeef);
843  hSearch = FtpFindFirstFileA(hFtp, "this_file_should_not_exist", &findData, 0, 0);
844  ok ( hSearch == NULL, "Expected FtpFindFirstFileA to fail\n" );
846  "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError() );
847  InternetCloseHandle(hSearch); /* Just in case */
848 
849  /* Test using a nonexistent filename and a wildcard */
850  SetLastError(0xdeadbeef);
851  hSearch = FtpFindFirstFileA(hFtp, "this_file_should_not_exist*", &findData, 0, 0);
852  ok ( hSearch == NULL, "Expected FtpFindFirstFileA to fail\n" );
854  "Expected ERROR_NO_MORE_FILES, got %d\n", GetLastError() );
855  InternetCloseHandle(hSearch); /* Just in case */
856 
857  /* Test using an invalid handle type */
858  SetLastError(0xdeadbeef);
859  hSearch = FtpFindFirstFileA(hConnect, "welcome.msg", &findData, 0, 0);
860  ok ( hSearch == NULL, "Expected FtpFindFirstFileA to fail\n" );
862  "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError() );
863  InternetCloseHandle(hSearch); /* Just in case */
864 }
#define ERROR_INTERNET_INCORRECT_HANDLE_TYPE
Definition: wininet.h:2007
#define ERROR_SUCCESS
Definition: deptool.c:10
#define error(str)
Definition: mkdosfs.c:1605
#define ERROR_INTERNET_EXTENDED_ERROR
Definition: wininet.h:1992
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
HINTERNET WINAPI FtpFindFirstFileA(HINTERNET hConnect, LPCSTR lpszSearchFile, LPWIN32_FIND_DATAA lpFindFileData, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:706
BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
Definition: internet.c:1436
HINTERNET WINAPI FtpOpenFileA(HINTERNET hFtpSession, LPCSTR lpszFileName, DWORD fdwAccess, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:1440
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define ERROR_NO_MORE_FILES
Definition: winerror.h:121
BOOL WINAPI FtpSetCurrentDirectoryA(HINTERNET hConnect, LPCSTR lpszDirectory)
Definition: ftp.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
#define success(from, fromstr, to, tostr)
#define SetLastError(x)
Definition: compat.h:417
#define ERROR_FTP_TRANSFER_IN_PROGRESS
Definition: wininet.h:2046
#define todo_wine
Definition: test.h:163
#define GENERIC_READ
Definition: compat.h:124
#define broken(x)
Definition: _sntprintf.h:21
#define ok(value,...)
Definition: atltest.h:57
#define FTP_TRANSFER_TYPE_ASCII
Definition: wininet.h:918

Referenced by START_TEST().

◆ test_get_current_dir()

static void test_get_current_dir ( HINTERNET  hFtp,
HINTERNET  hConnect 
)
static

Definition at line 866 of file ftp.c.

867 {
868  BOOL bRet;
869  DWORD dwCurrentDirectoryLen = MAX_PATH;
870  CHAR lpszCurrentDirectory[MAX_PATH];
871 
872  if (!pFtpCommandA)
873  {
874  win_skip("FtpCommandA() is not available. Skipping the Ftp get_current_dir tests\n");
875  return;
876  }
877 
878  /* change directories to get a more interesting pwd */
879  bRet = pFtpCommandA(hFtp, FALSE, FTP_TRANSFER_TYPE_ASCII, "CWD pub/", 0, NULL);
880  if(bRet == FALSE)
881  {
882  skip("Failed to change directories in test_get_current_dir(HINTERNET hFtp).\n");
883  return;
884  }
885 
886  /* test with all NULL arguments */
887  SetLastError(0xdeadbeef);
888  bRet = FtpGetCurrentDirectoryA( NULL, NULL, 0 );
889  ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" );
890  ok ( GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got: %d\n", GetLastError());
891 
892  /* test with NULL parameters instead of expected LPSTR/LPDWORD */
893  SetLastError(0xdeadbeef);
894  bRet = FtpGetCurrentDirectoryA( hFtp, NULL, 0 );
895  ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" );
896  ok ( GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got: %d\n", GetLastError());
897 
898  /* test with no valid handle and valid parameters */
899  SetLastError(0xdeadbeef);
900  bRet = FtpGetCurrentDirectoryA( NULL, lpszCurrentDirectory, &dwCurrentDirectoryLen );
901  ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" );
902  ok ( GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got: %d\n", GetLastError());
903 
904  /* test with invalid dwCurrentDirectory and all other parameters correct */
905  SetLastError(0xdeadbeef);
906  bRet = FtpGetCurrentDirectoryA( hFtp, lpszCurrentDirectory, 0 );
907  ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" );
908  ok ( GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got: %d\n", GetLastError());
909 
910  /* test with invalid lpszCurrentDirectory and all other parameters correct */
911  SetLastError(0xdeadbeef);
912  bRet = FtpGetCurrentDirectoryA( hFtp, NULL, &dwCurrentDirectoryLen );
913  ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" );
914  ok ( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INSUFFICIENT_BUFFER, got: %d\n", GetLastError());
915 
916  /* test to show it checks the handle type */
917  SetLastError(0xdeadbeef);
918  bRet = FtpGetCurrentDirectoryA( hConnect, lpszCurrentDirectory, &dwCurrentDirectoryLen );
919  ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" );
921  "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got: %d\n", GetLastError());
922 
923  /* test for the current directory with legitimate values */
924  SetLastError(0xdeadbeef);
925  bRet = FtpGetCurrentDirectoryA( hFtp, lpszCurrentDirectory, &dwCurrentDirectoryLen );
926  ok ( bRet == TRUE, "Expected FtpGetCurrentDirectoryA to pass\n" );
927  ok ( !strcmp(lpszCurrentDirectory, "/pub"), "Expected returned value \"%s\" to match \"/pub\"\n", lpszCurrentDirectory);
928  ok ( GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got: %d\n", GetLastError());
929 
930  /* test for the current directory with a size only large enough to
931  * fit the string and not the null terminating character */
932  SetLastError(0xdeadbeef);
933  dwCurrentDirectoryLen = 4;
934  lpszCurrentDirectory[4] = 'a'; /* set position 4 of the array to something else to make sure a leftover \0 isn't fooling the test */
935  bRet = FtpGetCurrentDirectoryA( hFtp, lpszCurrentDirectory, &dwCurrentDirectoryLen );
936  ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n");
937  ok ( strcmp(lpszCurrentDirectory, "/pub"), "Expected returned value \"%s\" to not match \"/pub\"\n", lpszCurrentDirectory);
938  ok ( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INSUFFICIENT_BUFFER, got: %d\n", GetLastError());
939 
940  /* test for the current directory with a size large enough to store
941  * the expected string as well as the null terminating character */
942  SetLastError(0xdeadbeef);
943  dwCurrentDirectoryLen = 5;
944  bRet = FtpGetCurrentDirectoryA( hFtp, lpszCurrentDirectory, &dwCurrentDirectoryLen );
945  ok ( bRet == TRUE, "Expected FtpGetCurrentDirectoryA to pass\n");
946  ok ( !strcmp(lpszCurrentDirectory, "/pub"), "Expected returned value \"%s\" to match \"/pub\"\n", lpszCurrentDirectory);
947  ok ( GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got: %d\n", GetLastError());
948 }
#define ERROR_INTERNET_INCORRECT_HANDLE_TYPE
Definition: wininet.h:2007
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
char CHAR
Definition: xmlstorage.h:175
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI FtpGetCurrentDirectoryA(HINTERNET hFtpSession, LPSTR lpszCurrentDirectory, LPDWORD lpdwCurrentDirectory)
Definition: ftp.c:913
smooth NULL
Definition: ftsmooth.c:416
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define FTP_TRANSFER_TYPE_ASCII
Definition: wininet.h:918
#define win_skip
Definition: test.h:150
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by START_TEST().

◆ test_getfile()

static void test_getfile ( HINTERNET  hFtp,
HINTERNET  hConnect 
)
static

Definition at line 217 of file ftp.c.

218 {
219  BOOL bRet;
220  HANDLE hFile;
221 
222  /* The order of checking is:
223  *
224  * All parameters except 'session handle' and 'condition flags'
225  * Session handle
226  * Session handle type
227  * Condition flags
228  */
229 
230  /* Test to show the parameter checking order depends on the Windows version */
231  SetLastError(0xdeadbeef);
232  bRet = FtpGetFileA(NULL, NULL, "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
233  ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
236  "Expected ERROR_INVALID_HANDLE (win98) or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
237 
238  /* Test to show session handle is checked before 'condition flags' */
239  SetLastError(0xdeadbeef);
240  bRet = FtpGetFileA(NULL, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, 5, 0);
241  ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
243  "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
244 
245  /* Make sure we start clean */
246 
247  DeleteFileA("should_be_non_existing_deadbeef");
248  DeleteFileA("should_also_be_non_existing_deadbeef");
249 
250  /* No remote file */
251  SetLastError(0xdeadbeef);
252  bRet = FtpGetFileA(hFtp, NULL, "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
253  ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
255  "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
256  ok (GetFileAttributesA("should_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
257  "Local file should not have been created\n");
258  DeleteFileA("should_be_non_existing_deadbeef");
259 
260  /* No local file */
261  SetLastError(0xdeadbeef);
262  bRet = FtpGetFileA(hFtp, "welcome.msg", NULL, FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
263  ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
265  "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
266 
267  /* Zero attributes */
268  bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_existing_non_deadbeef", FALSE, 0, FTP_TRANSFER_TYPE_UNKNOWN, 0);
269  ok ( bRet == TRUE, "Expected FtpGetFileA to succeed\n");
270  ok (GetFileAttributesA("should_be_existing_non_deadbeef") != INVALID_FILE_ATTRIBUTES,
271  "Local file should have been created\n");
272  DeleteFileA("should_be_existing_non_deadbeef");
273 
274  /* Illegal condition flags */
275  SetLastError(0xdeadbeef);
276  bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, 0xffffffff, 0);
277  ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
279  "Expected ERROR_INTERNET_EXTENDED_ERROR or ERROR_INVALID_PARAMETER (win98), got %d\n", GetLastError());
280  ok (GetFileAttributesA("should_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
281  "Local file should not have been created\n");
282  DeleteFileA("should_be_non_existing_deadbeef");
283 
284  /* Remote file doesn't exist (and local doesn't exist as well) */
285  SetLastError(0xdeadbeef);
286  bRet = FtpGetFileA(hFtp, "should_be_non_existing_deadbeef", "should_also_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
287  ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
289  "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
290  /* Currently Wine always creates the local file (even on failure) which is not correct, hence the test */
291  ok (GetFileAttributesA("should_also_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
292  "Local file should not have been created\n");
293 
294  DeleteFileA("should_also_be_non_existing_deadbeef");
295 
296  /* Same call as the previous but now the local file does exists. Windows just removes the file if the call fails
297  * even if the local existed before!
298  */
299 
300  /* Create a temporary local file */
301  SetLastError(0xdeadbeef);
302  hFile = CreateFileA("should_also_be_non_existing_deadbeef", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
303  ok ( hFile != NULL, "Error creating a local file : %d\n", GetLastError());
305  SetLastError(0xdeadbeef);
306  bRet = FtpGetFileA(hFtp, "should_be_non_existing_deadbeef", "should_also_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
307  ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
309  "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
310  /* Currently Wine always creates the local file (even on failure) which is not correct, hence the test */
311  ok (GetFileAttributesA("should_also_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
312  "Local file should not have been created\n");
313 
314  DeleteFileA("should_also_be_non_existing_deadbeef");
315 
316  /* This one should succeed */
317  SetLastError(0xdeadbeef);
318  bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_existing_non_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
319  ok ( bRet == TRUE, "Expected FtpGetFileA to fail\n");
320  ok ( GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
321 
322  if (GetFileAttributesA("should_be_existing_non_deadbeef") != INVALID_FILE_ATTRIBUTES)
323  {
324  /* Should succeed as fFailIfExists is set to FALSE (meaning don't fail if local file exists) */
325  SetLastError(0xdeadbeef);
326  bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
327  ok ( bRet == TRUE, "Expected FtpGetFileA to succeed\n");
329  "Expected ERROR_SUCCESS, got %d\n", GetLastError());
330 
331  /* Should fail as fFailIfExists is set to TRUE */
332  SetLastError(0xdeadbeef);
333  bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", TRUE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
334  ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
336  "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
337 
338  /* Prove that the existence of the local file is checked first (or at least reported last) */
339  SetLastError(0xdeadbeef);
340  bRet = FtpGetFileA(hFtp, "should_be_non_existing_deadbeef", "should_be_non_existing_deadbeef", TRUE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
341  ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
343  "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
344 
345  DeleteFileA("should_be_existing_non_deadbeef");
346  }
347 
348  /* Test to show the parameter checking order depends on the Windows version */
349  SetLastError(0xdeadbeef);
350  bRet = FtpGetFileA(hConnect, NULL, "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
351  ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
354  "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE (win98) or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
355 
356  /* Test to show that 'session handle type' is checked before 'condition flags' */
357  SetLastError(0xdeadbeef);
358  bRet = FtpGetFileA(hConnect, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, 5, 0);
359  ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
361  "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
362 
363  SetLastError(0xdeadbeef);
364  bRet = FtpGetFileA(hConnect, "should_be_non_existing_deadbeef", "should_be_non_existing_deadbeef", TRUE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
365  ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
367  "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
368 }
#define ERROR_INTERNET_INCORRECT_HANDLE_TYPE
Definition: wininet.h:2007
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define ERROR_FILE_EXISTS
Definition: winerror.h:165
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
BOOL WINAPI FtpGetFileA(HINTERNET hInternet, LPCSTR lpszRemoteFile, LPCSTR lpszNewFile, BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags, DWORD_PTR dwContext)
Definition: ftp.c:1556
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_INTERNET_EXTENDED_ERROR
Definition: wininet.h:1992
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD WINAPI GetFileAttributesA(LPCSTR lpFileName)
Definition: fileinfo.c:786
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define SetLastError(x)
Definition: compat.h:417
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
_In_ HANDLE hFile
Definition: mswsock.h:90
#define CREATE_ALWAYS
Definition: disk.h:72
#define ok(value,...)
Definition: atltest.h:57
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:407
#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 %d\n", GetLastError());
59 }
BOOL WINAPI FtpGetFileA(HINTERNET hInternet, LPCSTR lpszRemoteFile, LPCSTR lpszNewFile, BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags, DWORD_PTR dwContext)
Definition: ftp.c:1556
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define SetLastError(x)
Definition: compat.h:417
#define ERROR_INTERNET_NOT_INITIALIZED
Definition: wininet.h:2080
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define ok(value,...)
Definition: atltest.h:57
#define FTP_TRANSFER_TYPE_UNKNOWN
Definition: wininet.h:917

Referenced by START_TEST().

◆ test_openfile()

static void test_openfile ( HINTERNET  hFtp,
HINTERNET  hConnect 
)
static

Definition at line 384 of file ftp.c.

385 {
386  HINTERNET hOpenFile;
387 
388  /* Invalid internet handle, the rest are valid parameters */
389  SetLastError(0xdeadbeef);
390  hOpenFile = FtpOpenFileA(NULL, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
391  ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
393  "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
394  InternetCloseHandle(hOpenFile); /* Just in case */
395 
396  /* No filename */
397  SetLastError(0xdeadbeef);
398  hOpenFile = FtpOpenFileA(hFtp, NULL, GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
399  ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
401  "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
402  InternetCloseHandle(hOpenFile); /* Just in case */
403 
404  /* Illegal access flags */
405  SetLastError(0xdeadbeef);
406  hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", 0, FTP_TRANSFER_TYPE_ASCII, 0);
407  ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
409  "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
410  InternetCloseHandle(hOpenFile); /* Just in case */
411 
412  /* Illegal combination of access flags */
413  SetLastError(0xdeadbeef);
414  hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ|GENERIC_WRITE, FTP_TRANSFER_TYPE_ASCII, 0);
415  ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
417  "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
418  InternetCloseHandle(hOpenFile); /* Just in case */
419 
420  /* Illegal condition flags */
421  SetLastError(0xdeadbeef);
422  hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, 0xffffffff, 0);
423  ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
425  "Expected ERROR_INTERNET_EXTENDED_ERROR or ERROR_INVALID_PARAMETER (win98), got %d\n", GetLastError());
426  InternetCloseHandle(hOpenFile); /* Just in case */
427 
428  SetLastError(0xdeadbeef);
429  hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
430  ok ( hOpenFile != NULL, "Expected FtpOpenFileA to succeed\n");
431  ok ( GetLastError() == ERROR_SUCCESS ||
432  broken(GetLastError() == ERROR_FILE_NOT_FOUND), /* Win98 */
433  "Expected ERROR_SUCCESS, got %u\n", GetLastError());
434 
435  if (hOpenFile)
436  {
437  BOOL bRet;
438  DWORD error;
439  HINTERNET hOpenFile2;
440  HANDLE hFile;
441 
442  /* We have a handle so all ftp calls should fail (TODO: Put all ftp-calls in here) */
443  SetLastError(0xdeadbeef);
444  bRet = FtpCreateDirectoryA(hFtp, "new_directory_deadbeef");
445  error = GetLastError();
446  ok ( bRet == FALSE, "Expected FtpCreateDirectoryA to fail\n");
448  "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error);
450 
451  SetLastError(0xdeadbeef);
452  bRet = FtpDeleteFileA(hFtp, "non_existent_file_deadbeef");
453  error = GetLastError();
454  ok ( bRet == FALSE, "Expected FtpDeleteFileA to fail\n");
456  "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error);
458 
459  SetLastError(0xdeadbeef);
460  bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
461  error = GetLastError();
462  ok ( bRet == FALSE || broken(bRet == TRUE), "Expected FtpGetFileA to fail\n");
464  "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error);
465  DeleteFileA("should_be_non_existing_deadbeef"); /* Just in case */
466 
467  SetLastError(0xdeadbeef);
468  hOpenFile2 = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
469  error = GetLastError();
470  ok ( bRet == FALSE || broken(bRet == TRUE), "Expected FtpOpenFileA to fail\n");
472  "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error);
473  InternetCloseHandle(hOpenFile2); /* Just in case */
474 
475  /* Create a temporary local file */
476  SetLastError(0xdeadbeef);
477  hFile = CreateFileA("now_existing_local", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
478  ok ( hFile != NULL, "Error creating a local file : %d\n", GetLastError());
480  SetLastError(0xdeadbeef);
481  bRet = FtpPutFileA(hFtp, "now_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
482  error = GetLastError();
483  ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
485  "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error);
486  DeleteFileA("now_existing_local");
487 
488  SetLastError(0xdeadbeef);
489  bRet = FtpRemoveDirectoryA(hFtp, "should_be_non_existing_deadbeef_dir");
490  error = GetLastError();
491  ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
493  "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error);
494 
495  SetLastError(0xdeadbeef);
496  bRet = FtpRenameFileA(hFtp , "should_be_non_existing_deadbeef", "new");
497  error = GetLastError();
498  ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
500  "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", error);
501  }
502 
503  InternetCloseHandle(hOpenFile);
504 
505  /* One small test to show that handle type is checked before parameters */
506  SetLastError(0xdeadbeef);
507  hOpenFile = FtpOpenFileA(hConnect, "welcome.msg", GENERIC_READ, 5, 0);
508  ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
510  "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
511  InternetCloseHandle(hOpenFile); /* Just in case */
512 
513  SetLastError(0xdeadbeef);
514  hOpenFile = FtpOpenFileA(hConnect, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
515  ok ( hOpenFile == NULL, "Expected FtpOpenFileA to fail\n");
517  "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
518 
519  InternetCloseHandle(hOpenFile); /* Just in case */
520 }
#define ERROR_INTERNET_INCORRECT_HANDLE_TYPE
Definition: wininet.h:2007
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
BOOL WINAPI FtpCreateDirectoryA(HINTERNET hConnect, LPCSTR lpszDirectory)
Definition: ftp.c:563
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
BOOL WINAPI FtpGetFileA(HINTERNET hInternet, LPCSTR lpszRemoteFile, LPCSTR lpszNewFile, BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags, DWORD_PTR dwContext)
Definition: ftp.c:1556
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOL WINAPI FtpRenameFileA(HINTERNET hFtpSession, LPCSTR lpszSrc, LPCSTR lpszDest)
Definition: ftp.c:2064
#define error(str)
Definition: mkdosfs.c:1605
#define ERROR_INTERNET_EXTENDED_ERROR
Definition: wininet.h:1992
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
Definition: internet.c:1436
HINTERNET WINAPI FtpOpenFileA(HINTERNET hFtpSession, LPCSTR lpszFileName, DWORD fdwAccess, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:1440
BOOL WINAPI FtpRemoveDirectoryA(HINTERNET hFtpSession, LPCSTR lpszDirectory)
Definition: ftp.c:1921
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
BOOL WINAPI FtpPutFileA(HINTERNET hConnect, LPCSTR lpszLocalFile, LPCSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:221
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
#define ERROR_FTP_TRANSFER_IN_PROGRESS
Definition: wininet.h:2046
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define GENERIC_READ
Definition: compat.h:124
_In_ HANDLE hFile
Definition: mswsock.h:90
#define broken(x)
Definition: _sntprintf.h:21
#define CREATE_ALWAYS
Definition: disk.h:72
#define ok(value,...)
Definition: atltest.h:57
#define FTP_TRANSFER_TYPE_ASCII
Definition: wininet.h:918
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:407
static void trace_extended_error(DWORD error)
Definition: ftp.c:370
BOOL WINAPI FtpDeleteFileA(HINTERNET hFtpSession, LPCSTR lpszFileName)
Definition: ftp.c:1774
#define FTP_TRANSFER_TYPE_UNKNOWN
Definition: wininet.h:917

Referenced by START_TEST().

◆ test_putfile()

static void test_putfile ( HINTERNET  hFtp,
HINTERNET  hConnect 
)
static

Definition at line 522 of file ftp.c.

523 {
524  BOOL bRet;
525  HANDLE hFile;
526 
527  /* The order of checking is:
528  *
529  * All parameters except 'session handle' and 'condition flags'
530  * Session handle
531  * Session handle type
532  * Condition flags
533  */
534 
535  /* Test to show the parameter checking order depends on the Windows version */
536  SetLastError(0xdeadbeef);
537  bRet = FtpPutFileA(NULL, NULL, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
538  ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
541  "Expected ERROR_INVALID_HANDLE (win98) or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
542 
543  /* Test to show session handle is checked before 'condition flags' */
544  SetLastError(0xdeadbeef);
545  bRet = FtpPutFileA(NULL, "non_existing_local", "non_existing_remote", 5, 0);
546  ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
548  "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
549 
550  /* Start clean */
551  DeleteFileA("non_existing_local");
552 
553  /* No local file given */
554  SetLastError(0xdeadbeef);
555  bRet = FtpPutFileA(hFtp, NULL, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
556  ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
558  "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
559 
560  /* No remote file given */
561  SetLastError(0xdeadbeef);
562  bRet = FtpPutFileA(hFtp, "non_existing_local", NULL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
563  ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
565  "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
566 
567  /* Illegal condition flags */
568  SetLastError(0xdeadbeef);
569  bRet = FtpPutFileA(hFtp, "non_existing_local", "non_existing_remote", 5, 0);
570  ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
572  "Expected ERROR_FILE_NOT_FOUND or ERROR_INVALID_PARAMETER (win98), got %d\n", GetLastError());
573 
574  /* Parameters are OK but local file doesn't exist */
575  SetLastError(0xdeadbeef);
576  bRet = FtpPutFileA(hFtp, "non_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
577  ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
579  "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
580 
581  /* Create a temporary local file */
582  SetLastError(0xdeadbeef);
583  hFile = CreateFileA("now_existing_local", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
584  ok ( hFile != NULL, "Error creating a local file : %d\n", GetLastError());
586 
587  /* Local file exists but we shouldn't be allowed to 'put' the file */
588  SetLastError(0xdeadbeef);
589  bRet = FtpPutFileA(hFtp, "now_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
590  ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
592  "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
593 
594  DeleteFileA("now_existing_local");
595 
596  /* Test to show the parameter checking order depends on the Windows version */
597  SetLastError(0xdeadbeef);
598  bRet = FtpPutFileA(hConnect, NULL, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
599  ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
602  "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE (win98) or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
603 
604  /* Test to show that 'session handle type' is checked before 'condition flags' */
605  SetLastError(0xdeadbeef);
606  bRet = FtpPutFileA(hConnect, "non_existing_local", "non_existing_remote", 5, 0);
607  ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
609  "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
610 
611  SetLastError(0xdeadbeef);
612  bRet = FtpPutFileA(hConnect, "non_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
613  ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
615  "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
616 }
#define ERROR_INTERNET_INCORRECT_HANDLE_TYPE
Definition: wininet.h:2007
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define CloseHandle
Definition: compat.h:406
#define ERROR_INTERNET_EXTENDED_ERROR
Definition: wininet.h:1992
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
BOOL WINAPI FtpPutFileA(HINTERNET hConnect, LPCSTR lpszLocalFile, LPCSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:221
#define SetLastError(x)
Definition: compat.h:417
_In_ HANDLE hFile
Definition: mswsock.h:90
#define CREATE_ALWAYS
Definition: disk.h:72
#define ok(value,...)
Definition: atltest.h:57
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:407
#define FTP_TRANSFER_TYPE_UNKNOWN
Definition: wininet.h:917

Referenced by START_TEST().

◆ test_removedir()

static void test_removedir ( HINTERNET  hFtp,
HINTERNET  hConnect 
)
static

Definition at line 618 of file ftp.c.

619 {
620  BOOL bRet;
621 
622  /* Invalid internet handle, the other is a valid parameter */
623  SetLastError(0xdeadbeef);
624  bRet = FtpRemoveDirectoryA(NULL, "should_be_non_existing_deadbeef_dir");
625  ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
627  "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
628 
629  /* No remote directory given */
630  SetLastError(0xdeadbeef);
631  bRet = FtpRemoveDirectoryA(hFtp, NULL);
632  ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
634  "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
635 
636  /* Remote directory doesn't exist */
637  SetLastError(0xdeadbeef);
638  bRet = FtpRemoveDirectoryA(hFtp, "should_be_non_existing_deadbeef_dir");
639  ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
641  "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
642 
643  /* We shouldn't be allowed to remove that directory */
644  SetLastError(0xdeadbeef);
645  bRet = FtpRemoveDirectoryA(hFtp, "pub");
646  ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
648  "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
649 
650  /* One small test to show that handle type is checked before parameters */
651  SetLastError(0xdeadbeef);
652  bRet = FtpRemoveDirectoryA(hConnect, NULL);
653  ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
655  "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
656 
657  SetLastError(0xdeadbeef);
658  bRet = FtpRemoveDirectoryA(hConnect, "should_be_non_existing_deadbeef_dir");
659  ok ( bRet == FALSE, "Expected FtpRemoveDirectoryA to fail\n");
661  "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
662 }
#define ERROR_INTERNET_INCORRECT_HANDLE_TYPE
Definition: wininet.h:2007
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define ERROR_INTERNET_EXTENDED_ERROR
Definition: wininet.h:1992
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI FtpRemoveDirectoryA(HINTERNET hFtpSession, LPCSTR lpszDirectory)
Definition: ftp.c:1921
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define SetLastError(x)
Definition: compat.h:417
#define ok(value,...)
Definition: atltest.h:57

Referenced by START_TEST().

◆ test_renamefile()

static void test_renamefile ( HINTERNET  hFtp,
HINTERNET  hConnect 
)
static

Definition at line 664 of file ftp.c.

665 {
666  BOOL bRet;
667 
668  /* Invalid internet handle, the rest are valid parameters */
669  SetLastError(0xdeadbeef);
670  bRet = FtpRenameFileA(NULL , "should_be_non_existing_deadbeef", "new");
671  ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
673  "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
674 
675  /* No 'existing' file */
676  SetLastError(0xdeadbeef);
677  bRet = FtpRenameFileA(hFtp , NULL, "new");
678  ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
680  "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
681 
682  /* No new file */
683  SetLastError(0xdeadbeef);
684  bRet = FtpRenameFileA(hFtp , "should_be_non_existing_deadbeef", NULL);
685  ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
687  "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
688 
689  /* Existing file shouldn't be there */
690  SetLastError(0xdeadbeef);
691  bRet = FtpRenameFileA(hFtp , "should_be_non_existing_deadbeef", "new");
692  ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
694  "Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
695 
696  /* One small test to show that handle type is checked before parameters */
697  SetLastError(0xdeadbeef);
698  bRet = FtpRenameFileA(hConnect , "should_be_non_existing_deadbeef", NULL);
699  ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
701  "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
702 
703  SetLastError(0xdeadbeef);
704  bRet = FtpRenameFileA(hConnect , "should_be_non_existing_deadbeef", "new");
705  ok ( bRet == FALSE, "Expected FtpRenameFileA to fail\n");
707  "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError());
708 }
#define ERROR_INTERNET_INCORRECT_HANDLE_TYPE
Definition: wininet.h:2007
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
BOOL WINAPI FtpRenameFileA(HINTERNET hFtpSession, LPCSTR lpszSrc, LPCSTR lpszDest)
Definition: ftp.c:2064
#define ERROR_INTERNET_EXTENDED_ERROR
Definition: wininet.h:1992
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define SetLastError(x)
Definition: compat.h:417
#define ok(value,...)
Definition: atltest.h:57

Referenced by START_TEST().

◆ test_status_callbacks()

static void test_status_callbacks ( HINTERNET  hInternet)
static

Definition at line 965 of file ftp.c.

966 {
968  HINTERNET hFtp;
969  BOOL ret;
970 
971  cb = pInternetSetStatusCallbackA(hInternet, status_callback);
972  ok(cb == NULL, "expected NULL got %p\n", cb);
973 
974  hFtp = InternetConnectA(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@",
976  if (!hFtp)
977  {
978  skip("No ftp connection could be made to ftp.winehq.org %u\n", GetLastError());
979  return;
980  }
981 
982  ret = InternetCloseHandle(hFtp);
983  ok(ret, "InternetCloseHandle failed %u\n", GetLastError());
984 
985  cb = pInternetSetStatusCallbackA(hInternet, NULL);
986  ok(cb == status_callback, "expected check_status got %p\n", cb);
987 }
HINTERNET WINAPI InternetConnectA(HINTERNET hInternet, LPCSTR lpszServerName, INTERNET_PORT nServerPort, LPCSTR lpszUserName, LPCSTR lpszPassword, DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
Definition: internet.c:1343
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
Definition: internet.c:1436
static void WINAPI status_callback(HINTERNET handle, DWORD_PTR ctx, DWORD status, LPVOID info, DWORD info_len)
Definition: ftp.c:950
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define INTERNET_DEFAULT_FTP_PORT
Definition: wininet.h:38
int ret
#define INTERNET_SERVICE_FTP
Definition: wininet.h:560
#define INTERNET_FLAG_PASSIVE
Definition: wininet.h:65
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
static HMODULE MODULEINFO DWORD cb
Definition: module.c:32
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 370 of file ftp.c.

371 {
372  DWORD code, buflen = 0;
373 
374  if (error != ERROR_INTERNET_EXTENDED_ERROR) return;
376  {
377  char *text = HeapAlloc(GetProcessHeap(), 0, ++buflen);
379  trace("%u %s\n", code, text);
381  }
382 }
#define error(str)
Definition: mkdosfs.c:1605
#define ERROR_INTERNET_EXTENDED_ERROR
Definition: wininet.h:1992
const WCHAR * text
Definition: package.c:1827
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:403
#define trace
Definition: atltest.h:70
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
int code
Definition: i386-dis.c:3591
BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError, LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
Definition: internet.c:1110
#define HeapFree(x, y, z)
Definition: compat.h:402
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by test_openfile().

Variable Documentation

◆ BOOL

Definition at line 44 of file ftp.c.

◆ DWORD

◆ DWORD_PTR

◆ INTERNET_STATUS_CALLBACK

HINTERNET* static INTERNET_STATUS_CALLBACK

Definition at line 45 of file ftp.c.

Referenced by test_status_callbacks().

◆ LPCSTR

Definition at line 44 of file ftp.c.