ws2_32/tests: Add tests for WSAStartup().

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2022-02-01 00:20:46 -06:00 committed by Alexandre Julliard
parent 7e2cbad2eb
commit 155449c5d1
1 changed files with 95 additions and 4 deletions

View File

@ -2815,10 +2815,86 @@ static void test_WSCGetProviderPath(void)
ok(len == 256, "Got unexpected len %d.\n", len);
}
static void test_startup(void)
{
unsigned int i;
WSADATA data;
int ret;
static const struct
{
WORD version;
WORD ret_version;
}
tests[] =
{
{MAKEWORD(0, 0), MAKEWORD(2, 2)},
{MAKEWORD(0, 1), MAKEWORD(2, 2)},
{MAKEWORD(1, 0), MAKEWORD(1, 0)},
{MAKEWORD(1, 1), MAKEWORD(1, 1)},
{MAKEWORD(1, 2), MAKEWORD(1, 1)},
{MAKEWORD(1, 0xff), MAKEWORD(1, 1)},
{MAKEWORD(2, 0), MAKEWORD(2, 0)},
{MAKEWORD(2, 1), MAKEWORD(2, 1)},
{MAKEWORD(2, 2), MAKEWORD(2, 2)},
{MAKEWORD(2, 3), MAKEWORD(2, 2)},
{MAKEWORD(2, 0xff), MAKEWORD(2, 2)},
{MAKEWORD(3, 0), MAKEWORD(2, 2)},
{MAKEWORD(0xff, 0), MAKEWORD(2, 2)},
};
for (i = 0; i < ARRAY_SIZE(tests); ++i)
{
winetest_push_context("Version %#x", tests[i].version);
memset(&data, 0xcc, sizeof(data));
data.lpVendorInfo = (void *)0xdeadbeef;
ret = WSAStartup(tests[i].version, &data);
ok(ret == (LOBYTE(tests[i].version) ? 0 : WSAVERNOTSUPPORTED), "got %d\n", ret);
todo_wine_if (tests[i].version != tests[i].ret_version)
ok(data.wVersion == tests[i].ret_version, "got version %#x\n", data.wVersion);
if (!ret)
{
ret = WSAStartup(tests[i].version, &data);
ok(!ret, "got %d\n", ret);
WSASetLastError(0xdeadbeef);
ret = WSACleanup();
ok(!ret, "got %d\n", ret);
todo_wine ok(!WSAGetLastError(), "got error %u\n", WSAGetLastError());
WSASetLastError(0xdeadbeef);
ret = WSACleanup();
ok(!ret, "got %d\n", ret);
todo_wine ok(!WSAGetLastError(), "got error %u\n", WSAGetLastError());
}
ok(data.lpVendorInfo == (void *)0xdeadbeef, "got vendor info %p\n", data.lpVendorInfo);
todo_wine_if (ret)
{
ok(data.wHighVersion == 0x202, "got maximum version %#x\n", data.wHighVersion);
ok(!strcmp(data.szDescription, "WinSock 2.0"), "got description %s\n", debugstr_a(data.szDescription));
ok(!strcmp(data.szSystemStatus, "Running"), "got status %s\n", debugstr_a(data.szSystemStatus));
}
todo_wine ok(data.iMaxSockets == (LOBYTE(tests[i].version) == 1 ? 32767 : 0), "got maximum sockets %u\n", data.iMaxSockets);
todo_wine ok(data.iMaxUdpDg == (LOBYTE(tests[i].version) == 1 ? 65467 : 0), "got maximum datagram size %u\n", data.iMaxUdpDg);
WSASetLastError(0xdeadbeef);
ret = WSACleanup();
ok(ret == -1, "got %d\n", ret);
ok(WSAGetLastError() == WSANOTINITIALISED, "got error %u\n", WSAGetLastError());
ret = WSAStartup(tests[i].version, NULL);
todo_wine_if (LOBYTE(tests[i].version))
ok(ret == (LOBYTE(tests[i].version) ? WSAEFAULT : WSAVERNOTSUPPORTED), "got %d\n", ret);
winetest_pop_context();
}
}
START_TEST( protocol )
{
WSADATA data;
WORD version = MAKEWORD( 2, 2 );
int ret;
pFreeAddrInfoExW = (void *)GetProcAddress(GetModuleHandleA("ws2_32"), "FreeAddrInfoExW");
pGetAddrInfoExOverlappedResult = (void *)GetProcAddress(GetModuleHandleA("ws2_32"), "GetAddrInfoExOverlappedResult");
@ -2830,7 +2906,8 @@ START_TEST( protocol )
pInetPtonW = (void *)GetProcAddress(GetModuleHandleA("ws2_32"), "InetPtonW");
pWSCGetProviderInfo = (void *)GetProcAddress(GetModuleHandleA("ws2_32"), "WSCGetProviderInfo");
if (WSAStartup( version, &data )) return;
ret = WSAStartup(0x202, &data);
ok(!ret, "got %d\n", ret);
test_WSAEnumProtocolsA();
test_WSAEnumProtocolsW();
@ -2839,8 +2916,6 @@ START_TEST( protocol )
test_getservbyname();
test_WSALookupService();
test_WSAAsyncGetServByPort();
test_WSAAsyncGetServByName();
test_inet_ntoa();
test_inet_pton();
@ -2862,4 +2937,20 @@ START_TEST( protocol )
test_WSAEnumNameSpaceProvidersW();
test_WSCGetProviderInfo();
test_WSCGetProviderPath();
WSACleanup();
/* These tests are finnicky. If WSAStartup() is ever called with a
* version below 2.2, it causes getaddrinfo() to behave differently. */
test_startup();
/* And if WSAAsyncGetServBy*() is ever called, it somehow causes
* WSAStartup() to succeed with 0.1 instead of failing. */
ret = WSAStartup(0x202, &data);
ok(!ret, "got %d\n", ret);
test_WSAAsyncGetServByPort();
test_WSAAsyncGetServByName();
}