ws2_32/tests: Load GetHostNameW() dynamically.

It is not available on Windows 7 and lower.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Francois Gouget 2021-04-21 20:15:52 +02:00 committed by Alexandre Julliard
parent 2f2cdc8bb1
commit 6ccd501503
1 changed files with 11 additions and 4 deletions

View File

@ -71,6 +71,7 @@ static int (WINAPI *pGetAddrInfoExW)(const WCHAR *name, const WCHAR *servname,
struct timeval *timeout, OVERLAPPED *overlapped,
LPLOOKUPSERVICE_COMPLETION_ROUTINE completion_routine, HANDLE *handle);
static int (WINAPI *pGetAddrInfoExOverlappedResult)(OVERLAPPED *overlapped);
static int (WINAPI *pGetHostNameW)(WCHAR *, int);
static PCSTR (WINAPI *pInetNtop)(INT,LPVOID,LPSTR,ULONG);
static PCWSTR(WINAPI *pInetNtopW)(INT,LPVOID,LPWSTR,ULONG);
static int (WINAPI *pInetPtonA)(INT,LPCSTR,LPVOID);
@ -1203,6 +1204,7 @@ static void Init (void)
pFreeAddrInfoExW = (void *)GetProcAddress(hws2_32, "FreeAddrInfoExW");
pGetAddrInfoExW = (void *)GetProcAddress(hws2_32, "GetAddrInfoExW");
pGetAddrInfoExOverlappedResult = (void *)GetProcAddress(hws2_32, "GetAddrInfoExOverlappedResult");
pGetHostNameW = (void *)GetProcAddress(hws2_32, "GetHostNameW");
pInetNtop = (void *)GetProcAddress(hws2_32, "inet_ntop");
pInetNtopW = (void *)GetProcAddress(hws2_32, "InetNtopW");
pInetPtonA = (void *)GetProcAddress(hws2_32, "inet_pton");
@ -4328,26 +4330,31 @@ static void test_GetHostNameW(void)
WCHAR name[256];
int ret, len;
if (!pGetHostNameW)
{
win_skip("GetHostNameW() not present\n");
return;
}
WSASetLastError(0xdeadbeef);
ret = GetHostNameW(NULL, 256);
ret = pGetHostNameW(NULL, 256);
ok(ret == -1, "GetHostNameW() returned %d\n", ret);
ok(WSAGetLastError() == WSAEFAULT, "GetHostNameW with null buffer "
"failed with %d, expected %d\n", WSAGetLastError(), WSAEFAULT);
ret = GetHostNameW(name, sizeof(name));
ret = pGetHostNameW(name, sizeof(name));
ok(ret == 0, "GetHostNameW() call failed: %d\n", WSAGetLastError());
len = wcslen(name);
WSASetLastError(0xdeadbeef);
wcscpy(name, L"deadbeef");
ret = GetHostNameW(name, len);
ret = pGetHostNameW(name, len);
ok(ret == -1, "GetHostNameW() returned %d\n", ret);
ok(!wcscmp(name, L"deadbeef"), "name changed unexpected!\n");
ok(WSAGetLastError() == WSAEFAULT, "GetHostNameW with insufficient length "
"failed with %d, expected %d\n", WSAGetLastError(), WSAEFAULT);
len++;
ret = GetHostNameW(name, len);
ret = pGetHostNameW(name, len);
ok(ret == 0, "GetHostNameW() call failed: %d\n", WSAGetLastError());
}