Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/ws2_32/tests/protocol.c | 99 ++++++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 4 deletions(-)
diff --git a/dlls/ws2_32/tests/protocol.c b/dlls/ws2_32/tests/protocol.c index 5597e3df854..a23cf51a8bd 100644 --- a/dlls/ws2_32/tests/protocol.c +++ b/dlls/ws2_32/tests/protocol.c @@ -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(); }
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/ws2_32/socket.c | 33 ++++++++++++++++----------------- dlls/ws2_32/tests/protocol.c | 9 +++------ 2 files changed, 19 insertions(+), 23 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index fe7e4fb3464..23140529b24 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -572,29 +572,28 @@ BOOL WINAPI DllMain( HINSTANCE instance, DWORD reason, void *reserved ) /*********************************************************************** * WSAStartup (WS2_32.115) */ -int WINAPI WSAStartup(WORD wVersionRequested, LPWSADATA lpWSAData) +int WINAPI WSAStartup( WORD version, WSADATA *data ) { - TRACE("verReq=%x\n", wVersionRequested); + TRACE( "version %#x\n", version );
- if (LOBYTE(wVersionRequested) < 1) + if (data) + { + data->wVersion = version; + data->wHighVersion = MAKEWORD(2, 2); + strcpy( data->szDescription, "WinSock 2.0" ); + strcpy( data->szSystemStatus, "Running" ); + data->iMaxSockets = MAX_SOCKETS_PER_PROCESS; + data->iMaxUdpDg = MAX_UDP_DATAGRAM; + /* don't fill lpVendorInfo */ + } + + if (!LOBYTE(version)) return WSAVERNOTSUPPORTED;
- if (!lpWSAData) return WSAEINVAL; + if (!data) return WSAEINVAL;
num_startup++; - - /* that's the whole of the negotiation for now */ - lpWSAData->wVersion = wVersionRequested; - /* return winsock information */ - lpWSAData->wHighVersion = 0x0202; - strcpy(lpWSAData->szDescription, "WinSock 2.0" ); - strcpy(lpWSAData->szSystemStatus, "Running" ); - lpWSAData->iMaxSockets = MAX_SOCKETS_PER_PROCESS; - lpWSAData->iMaxUdpDg = MAX_UDP_DATAGRAM; - /* don't do anything with lpWSAData->lpVendorInfo */ - /* (some apps don't allocate the space for this field) */ - - TRACE("succeeded starts: %d\n", num_startup); + TRACE( "increasing startup count to %d\n", num_startup ); return 0; }
diff --git a/dlls/ws2_32/tests/protocol.c b/dlls/ws2_32/tests/protocol.c index a23cf51a8bd..f859ad40e30 100644 --- a/dlls/ws2_32/tests/protocol.c +++ b/dlls/ws2_32/tests/protocol.c @@ -2869,12 +2869,9 @@ static void test_startup(void) 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)); - } + 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);
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/ws2_32/socket.c | 8 +++++++- dlls/ws2_32/tests/protocol.c | 3 +-- 2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 23140529b24..565f1c89dc0 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -578,7 +578,13 @@ int WINAPI WSAStartup( WORD version, WSADATA *data )
if (data) { - data->wVersion = version; + if (!LOBYTE(version) || LOBYTE(version) > 2 + || (LOBYTE(version) == 2 && HIBYTE(version) > 2)) + data->wVersion = MAKEWORD(2, 2); + else if (LOBYTE(version) == 1 && HIBYTE(version) > 1) + data->wVersion = MAKEWORD(1, 1); + else + data->wVersion = version; data->wHighVersion = MAKEWORD(2, 2); strcpy( data->szDescription, "WinSock 2.0" ); strcpy( data->szSystemStatus, "Running" ); diff --git a/dlls/ws2_32/tests/protocol.c b/dlls/ws2_32/tests/protocol.c index f859ad40e30..db89febff2e 100644 --- a/dlls/ws2_32/tests/protocol.c +++ b/dlls/ws2_32/tests/protocol.c @@ -2851,8 +2851,7 @@ static void test_startup(void) 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); + ok(data.wVersion == tests[i].ret_version, "got version %#x\n", data.wVersion); if (!ret) { ret = WSAStartup(tests[i].version, &data);
Depending on reported winsock version.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50352 Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/ws2_32/socket.c | 3 +-- dlls/ws2_32/tests/protocol.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 565f1c89dc0..19a7d901414 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -419,7 +419,6 @@ static BOOL socket_list_remove( SOCKET socket ) return FALSE; }
-#define MAX_SOCKETS_PER_PROCESS 128 /* reasonable guess */ #define MAX_UDP_DATAGRAM 1024 static INT WINAPI WSA_DefaultBlockingHook( FARPROC x );
@@ -588,7 +587,7 @@ int WINAPI WSAStartup( WORD version, WSADATA *data ) data->wHighVersion = MAKEWORD(2, 2); strcpy( data->szDescription, "WinSock 2.0" ); strcpy( data->szSystemStatus, "Running" ); - data->iMaxSockets = MAX_SOCKETS_PER_PROCESS; + data->iMaxSockets = (LOBYTE(version) == 1 ? 32767 : 0); data->iMaxUdpDg = MAX_UDP_DATAGRAM; /* don't fill lpVendorInfo */ } diff --git a/dlls/ws2_32/tests/protocol.c b/dlls/ws2_32/tests/protocol.c index db89febff2e..a95b6e685af 100644 --- a/dlls/ws2_32/tests/protocol.c +++ b/dlls/ws2_32/tests/protocol.c @@ -2871,7 +2871,7 @@ static void test_startup(void) 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); + 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);
Depending on reported winsock version.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/ws2_32/socket.c | 3 +-- dlls/ws2_32/tests/protocol.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 19a7d901414..7a1483f140f 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -419,7 +419,6 @@ static BOOL socket_list_remove( SOCKET socket ) return FALSE; }
-#define MAX_UDP_DATAGRAM 1024 static INT WINAPI WSA_DefaultBlockingHook( FARPROC x );
int num_startup; @@ -588,7 +587,7 @@ int WINAPI WSAStartup( WORD version, WSADATA *data ) strcpy( data->szDescription, "WinSock 2.0" ); strcpy( data->szSystemStatus, "Running" ); data->iMaxSockets = (LOBYTE(version) == 1 ? 32767 : 0); - data->iMaxUdpDg = MAX_UDP_DATAGRAM; + data->iMaxUdpDg = (LOBYTE(version) == 1 ? 65467 : 0); /* don't fill lpVendorInfo */ }
diff --git a/dlls/ws2_32/tests/protocol.c b/dlls/ws2_32/tests/protocol.c index a95b6e685af..8b429e5c914 100644 --- a/dlls/ws2_32/tests/protocol.c +++ b/dlls/ws2_32/tests/protocol.c @@ -2872,7 +2872,7 @@ static void test_startup(void) 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)); 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); + ok(data.iMaxUdpDg == (LOBYTE(tests[i].version) == 1 ? 65467 : 0), "got maximum datagram size %u\n", data.iMaxUdpDg);
WSASetLastError(0xdeadbeef); ret = WSACleanup();
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/ws2_32/socket.c | 2 +- dlls/ws2_32/tests/protocol.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 7a1483f140f..a75aaee68be 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -594,7 +594,7 @@ int WINAPI WSAStartup( WORD version, WSADATA *data ) if (!LOBYTE(version)) return WSAVERNOTSUPPORTED;
- if (!data) return WSAEINVAL; + if (!data) return WSAEFAULT;
num_startup++; TRACE( "increasing startup count to %d\n", num_startup ); diff --git a/dlls/ws2_32/tests/protocol.c b/dlls/ws2_32/tests/protocol.c index 8b429e5c914..1ff335f7fe2 100644 --- a/dlls/ws2_32/tests/protocol.c +++ b/dlls/ws2_32/tests/protocol.c @@ -2880,8 +2880,7 @@ static void test_startup(void) 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); + ok(ret == (LOBYTE(tests[i].version) ? WSAEFAULT : WSAVERNOTSUPPORTED), "got %d\n", ret);
winetest_pop_context(); }
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=106667
Your paranoid android.
=== w8 (32 bit report) ===
ws2_32: protocol.c:2001: Test failed: result != NULL