ws2_32/tests: Add more tests for WSASocket() parameters.
Signed-off-by: Zebediah Figura <z.figura12@gmail.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
c2b089aae5
commit
088b7c5814
|
@ -2471,107 +2471,78 @@ static void test_WSASocket(void)
|
|||
int items, err, size, socktype, i, j;
|
||||
UINT pi_size;
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
ok(WSASocketA(0, 0, 0, NULL, 0, 0) == INVALID_SOCKET,
|
||||
"WSASocketA should have failed\n");
|
||||
err = WSAGetLastError();
|
||||
ok(err == WSAEINVAL, "Expected 10022, received %d\n", err);
|
||||
static const struct
|
||||
{
|
||||
int family, type, protocol;
|
||||
DWORD error;
|
||||
int ret_family, ret_type, ret_protocol;
|
||||
}
|
||||
tests[] =
|
||||
{
|
||||
/* 0 */
|
||||
{0xdead, SOCK_STREAM, IPPROTO_TCP, WSAEAFNOSUPPORT},
|
||||
{-1, SOCK_STREAM, IPPROTO_TCP, WSAEAFNOSUPPORT},
|
||||
{AF_INET, 0xdead, IPPROTO_TCP, WSAESOCKTNOSUPPORT},
|
||||
{AF_INET, -1, IPPROTO_TCP, WSAESOCKTNOSUPPORT},
|
||||
{AF_INET, SOCK_STREAM, 0xdead, WSAEPROTONOSUPPORT},
|
||||
{AF_INET, SOCK_STREAM, -1, WSAEPROTONOSUPPORT},
|
||||
{0xdead, 0xdead, IPPROTO_TCP, WSAESOCKTNOSUPPORT},
|
||||
{0xdead, SOCK_STREAM, 0xdead, WSAEAFNOSUPPORT},
|
||||
{AF_INET, 0xdead, 0xdead, WSAESOCKTNOSUPPORT},
|
||||
{0xdead, SOCK_STREAM, IPPROTO_UDP, WSAEAFNOSUPPORT},
|
||||
|
||||
sock = WSASocketA(AF_INET, 0, 0, NULL, 0, 0);
|
||||
ok(sock != INVALID_SOCKET, "WSASocketA should have succeeded\n");
|
||||
closesocket(sock);
|
||||
/* 10 */
|
||||
{AF_INET, SOCK_STREAM, 0, 0, AF_INET, SOCK_STREAM, IPPROTO_TCP},
|
||||
{AF_INET, SOCK_DGRAM, 0, 0, AF_INET, SOCK_DGRAM, IPPROTO_UDP},
|
||||
{AF_INET, 0xdead, 0, WSAESOCKTNOSUPPORT},
|
||||
{AF_INET, 0, IPPROTO_TCP, 0, AF_INET, SOCK_STREAM, IPPROTO_TCP},
|
||||
{AF_INET, 0, IPPROTO_UDP, 0, AF_INET, SOCK_DGRAM, IPPROTO_UDP},
|
||||
{AF_INET, 0, 0xdead, WSAEPROTONOSUPPORT},
|
||||
{AF_INET, 0, 0, 0, AF_INET, SOCK_STREAM, IPPROTO_TCP},
|
||||
{AF_INET, SOCK_STREAM, IPPROTO_UDP, WSAEPROTONOSUPPORT},
|
||||
{AF_INET, SOCK_DGRAM, IPPROTO_TCP, WSAEPROTONOSUPPORT},
|
||||
|
||||
sock = WSASocketA(AF_INET, SOCK_STREAM, 0, NULL, 0, 0);
|
||||
ok(sock != INVALID_SOCKET, "WSASocketA should have succeeded\n");
|
||||
closesocket(sock);
|
||||
/* 19 */
|
||||
{AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP, 0, AF_INET, SOCK_STREAM, IPPROTO_TCP},
|
||||
{AF_UNSPEC, SOCK_STREAM, 0xdead, WSAEPROTONOSUPPORT},
|
||||
{AF_UNSPEC, 0xdead, IPPROTO_UDP, WSAESOCKTNOSUPPORT},
|
||||
{AF_UNSPEC, SOCK_STREAM, 0, WSAEINVAL},
|
||||
{AF_UNSPEC, SOCK_DGRAM, 0, WSAEINVAL},
|
||||
{AF_UNSPEC, 0xdead, 0, WSAEINVAL},
|
||||
{AF_UNSPEC, 0, IPPROTO_TCP, 0, AF_INET, SOCK_STREAM, IPPROTO_TCP},
|
||||
{AF_UNSPEC, 0, IPPROTO_UDP, 0, AF_INET, SOCK_DGRAM, IPPROTO_UDP},
|
||||
{AF_UNSPEC, 0, 0xdead, WSAEPROTONOSUPPORT},
|
||||
{AF_UNSPEC, 0, 0, WSAEINVAL},
|
||||
};
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
ok(WSASocketA(0, SOCK_STREAM, -1, NULL, 0, 0) == INVALID_SOCKET,
|
||||
"WSASocketA should have failed\n");
|
||||
err = WSAGetLastError();
|
||||
ok(err == WSAEPROTONOSUPPORT, "Expected 10043, received %d\n", err);
|
||||
for (i = 0; i < ARRAY_SIZE(tests); ++i)
|
||||
{
|
||||
SetLastError( 0xdeadbeef );
|
||||
sock = WSASocketA( tests[i].family, tests[i].type, tests[i].protocol, NULL, 0, 0 );
|
||||
todo_wine_if (!tests[i].error || i == 7)
|
||||
ok(WSAGetLastError() == tests[i].error, "Test %u: got wrong error %u\n", i, WSAGetLastError());
|
||||
if (tests[i].error)
|
||||
{
|
||||
ok(sock == INVALID_SOCKET, "Test %u: expected failure\n", i);
|
||||
}
|
||||
else
|
||||
{
|
||||
WSAPROTOCOL_INFOA info;
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
ok(WSASocketA(0, -1, IPPROTO_UDP, NULL, 0, 0) == INVALID_SOCKET,
|
||||
"WSASocketA should have failed\n");
|
||||
err = WSAGetLastError();
|
||||
ok(err == WSAESOCKTNOSUPPORT, "Expected 10044, received %d\n", err);
|
||||
todo_wine_if (i == 19) ok(sock != INVALID_SOCKET, "Text %u: expected success\n", i);
|
||||
if (sock == INVALID_SOCKET) continue;
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
ok(WSASocketA(0, -1, 0, NULL, 0, 0) == INVALID_SOCKET,
|
||||
"WSASocketA should have failed\n");
|
||||
err = WSAGetLastError();
|
||||
ok(err == WSAEINVAL, "Expected 10022, received %d\n", err);
|
||||
size = sizeof(info);
|
||||
err = getsockopt( sock, SOL_SOCKET, SO_PROTOCOL_INFOA, (char *)&info, &size );
|
||||
ok(!err, "Test %u: getsockopt failed, error %u\n", i, WSAGetLastError());
|
||||
ok(info.iAddressFamily == tests[i].ret_family, "Test %u: got wrong family %d\n", i, info.iAddressFamily);
|
||||
ok(info.iSocketType == tests[i].ret_type, "Test %u: got wrong type %d\n", i, info.iSocketType);
|
||||
todo_wine_if (i == 10 || i == 11 || i == 16)
|
||||
ok(info.iProtocol == tests[i].ret_protocol, "Test %u: got wrong protocol %d\n", i, info.iProtocol);
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
ok(WSASocketA(AF_INET, -1, 0, NULL, 0, 0) == INVALID_SOCKET,
|
||||
"WSASocketA should have failed\n");
|
||||
err = WSAGetLastError();
|
||||
ok(err == WSAESOCKTNOSUPPORT, "Expected 10044, received %d\n", err);
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
ok(WSASocketA(AF_INET, 0, -1, NULL, 0, 0) == INVALID_SOCKET,
|
||||
"WSASocketA should have failed\n");
|
||||
err = WSAGetLastError();
|
||||
ok(err == WSAEPROTONOSUPPORT, "Expected 10043, received %d\n", err);
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
ok(WSASocketA(0, -1, -1, NULL, 0, 0) == INVALID_SOCKET,
|
||||
"WSASocketA should have failed\n");
|
||||
err = WSAGetLastError();
|
||||
ok(err == WSAESOCKTNOSUPPORT, "Expected 10044, received %d\n", err);
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
ok(WSASocketA(-1, SOCK_STREAM, IPPROTO_UDP, NULL, 0, 0) == INVALID_SOCKET,
|
||||
"WSASocketA should have failed\n");
|
||||
err = WSAGetLastError();
|
||||
ok(err == WSAEAFNOSUPPORT, "Expected 10047, received %d\n", err);
|
||||
|
||||
sock = WSASocketA(AF_INET, 0, IPPROTO_TCP, NULL, 0, 0);
|
||||
ok(sock != INVALID_SOCKET, "WSASocketA should have succeeded\n");
|
||||
closesocket(sock);
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
ok(WSASocketA(0, SOCK_STREAM, 0, NULL, 0, 0) == INVALID_SOCKET,
|
||||
"WSASocketA should have failed\n");
|
||||
err = WSAGetLastError();
|
||||
ok(err == WSAEINVAL, "Expected 10022, received %d\n", err);
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
ok(WSASocketA(0, 0, 0xdead, NULL, 0, 0) == INVALID_SOCKET,
|
||||
"WSASocketA should have failed\n");
|
||||
err = WSAGetLastError();
|
||||
ok(err == WSAEPROTONOSUPPORT, "Expected 10043, received %d\n", err);
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
ok(WSASocketA(AF_INET, 0xdead, 0, NULL, 0, 0) == INVALID_SOCKET,
|
||||
"WSASocketA should have failed\n");
|
||||
err = WSAGetLastError();
|
||||
ok(err == WSAESOCKTNOSUPPORT, "Expected 10044, received %d\n", err);
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
ok(WSASocketA(0, 0xdead, 0, NULL, 0, 0) == INVALID_SOCKET,
|
||||
"WSASocketA should have failed\n");
|
||||
err = WSAGetLastError();
|
||||
ok(err == WSAEINVAL, "Expected 10022, received %d\n", err);
|
||||
|
||||
sock = WSASocketA(0, 0, IPPROTO_TCP, NULL, 0, 0);
|
||||
ok(sock != INVALID_SOCKET, "WSASocketA should have succeeded\n");
|
||||
closesocket(sock);
|
||||
|
||||
/* SOCK_STREAM does not support IPPROTO_UDP */
|
||||
SetLastError(0xdeadbeef);
|
||||
ok(WSASocketA(AF_INET, SOCK_STREAM, IPPROTO_UDP, NULL, 0, 0) == INVALID_SOCKET,
|
||||
"WSASocketA should have failed\n");
|
||||
err = WSAGetLastError();
|
||||
ok(err == WSAEPROTONOSUPPORT, "Expected 10043, received %d\n", err);
|
||||
|
||||
/* SOCK_DGRAM does not support IPPROTO_TCP */
|
||||
SetLastError(0xdeadbeef);
|
||||
ok(WSASocketA(AF_INET, SOCK_DGRAM, IPPROTO_TCP, NULL, 0, 0) == INVALID_SOCKET,
|
||||
"WSASocketA should have failed\n");
|
||||
err = WSAGetLastError();
|
||||
ok(err == WSAEPROTONOSUPPORT, "Expected 10043, received %d\n", err);
|
||||
closesocket( sock );
|
||||
}
|
||||
}
|
||||
|
||||
/* Set pi_size explicitly to a value below 2*sizeof(WSAPROTOCOL_INFOA)
|
||||
* to avoid a crash on win98.
|
||||
|
|
Loading…
Reference in New Issue