Commit 088b7c58 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

ws2_32/tests: Add more tests for WSASocket() parameters.

parent c2b089aa
...@@ -2471,107 +2471,78 @@ static void test_WSASocket(void) ...@@ -2471,107 +2471,78 @@ static void test_WSASocket(void)
int items, err, size, socktype, i, j; int items, err, size, socktype, i, j;
UINT pi_size; UINT pi_size;
SetLastError(0xdeadbeef); static const struct
ok(WSASocketA(0, 0, 0, NULL, 0, 0) == INVALID_SOCKET, {
"WSASocketA should have failed\n"); int family, type, protocol;
err = WSAGetLastError(); DWORD error;
ok(err == WSAEINVAL, "Expected 10022, received %d\n", err); int ret_family, ret_type, ret_protocol;
}
sock = WSASocketA(AF_INET, 0, 0, NULL, 0, 0); tests[] =
ok(sock != INVALID_SOCKET, "WSASocketA should have succeeded\n"); {
closesocket(sock); /* 0 */
{0xdead, SOCK_STREAM, IPPROTO_TCP, WSAEAFNOSUPPORT},
sock = WSASocketA(AF_INET, SOCK_STREAM, 0, NULL, 0, 0); {-1, SOCK_STREAM, IPPROTO_TCP, WSAEAFNOSUPPORT},
ok(sock != INVALID_SOCKET, "WSASocketA should have succeeded\n"); {AF_INET, 0xdead, IPPROTO_TCP, WSAESOCKTNOSUPPORT},
closesocket(sock); {AF_INET, -1, IPPROTO_TCP, WSAESOCKTNOSUPPORT},
{AF_INET, SOCK_STREAM, 0xdead, WSAEPROTONOSUPPORT},
SetLastError(0xdeadbeef); {AF_INET, SOCK_STREAM, -1, WSAEPROTONOSUPPORT},
ok(WSASocketA(0, SOCK_STREAM, -1, NULL, 0, 0) == INVALID_SOCKET, {0xdead, 0xdead, IPPROTO_TCP, WSAESOCKTNOSUPPORT},
"WSASocketA should have failed\n"); {0xdead, SOCK_STREAM, 0xdead, WSAEAFNOSUPPORT},
err = WSAGetLastError(); {AF_INET, 0xdead, 0xdead, WSAESOCKTNOSUPPORT},
ok(err == WSAEPROTONOSUPPORT, "Expected 10043, received %d\n", err); {0xdead, SOCK_STREAM, IPPROTO_UDP, WSAEAFNOSUPPORT},
SetLastError(0xdeadbeef); /* 10 */
ok(WSASocketA(0, -1, IPPROTO_UDP, NULL, 0, 0) == INVALID_SOCKET, {AF_INET, SOCK_STREAM, 0, 0, AF_INET, SOCK_STREAM, IPPROTO_TCP},
"WSASocketA should have failed\n"); {AF_INET, SOCK_DGRAM, 0, 0, AF_INET, SOCK_DGRAM, IPPROTO_UDP},
err = WSAGetLastError(); {AF_INET, 0xdead, 0, WSAESOCKTNOSUPPORT},
ok(err == WSAESOCKTNOSUPPORT, "Expected 10044, received %d\n", err); {AF_INET, 0, IPPROTO_TCP, 0, AF_INET, SOCK_STREAM, IPPROTO_TCP},
{AF_INET, 0, IPPROTO_UDP, 0, AF_INET, SOCK_DGRAM, IPPROTO_UDP},
SetLastError(0xdeadbeef); {AF_INET, 0, 0xdead, WSAEPROTONOSUPPORT},
ok(WSASocketA(0, -1, 0, NULL, 0, 0) == INVALID_SOCKET, {AF_INET, 0, 0, 0, AF_INET, SOCK_STREAM, IPPROTO_TCP},
"WSASocketA should have failed\n"); {AF_INET, SOCK_STREAM, IPPROTO_UDP, WSAEPROTONOSUPPORT},
err = WSAGetLastError(); {AF_INET, SOCK_DGRAM, IPPROTO_TCP, WSAEPROTONOSUPPORT},
ok(err == WSAEINVAL, "Expected 10022, received %d\n", err);
/* 19 */
SetLastError(0xdeadbeef); {AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP, 0, AF_INET, SOCK_STREAM, IPPROTO_TCP},
ok(WSASocketA(AF_INET, -1, 0, NULL, 0, 0) == INVALID_SOCKET, {AF_UNSPEC, SOCK_STREAM, 0xdead, WSAEPROTONOSUPPORT},
"WSASocketA should have failed\n"); {AF_UNSPEC, 0xdead, IPPROTO_UDP, WSAESOCKTNOSUPPORT},
err = WSAGetLastError(); {AF_UNSPEC, SOCK_STREAM, 0, WSAEINVAL},
ok(err == WSAESOCKTNOSUPPORT, "Expected 10044, received %d\n", err); {AF_UNSPEC, SOCK_DGRAM, 0, WSAEINVAL},
{AF_UNSPEC, 0xdead, 0, WSAEINVAL},
SetLastError(0xdeadbeef); {AF_UNSPEC, 0, IPPROTO_TCP, 0, AF_INET, SOCK_STREAM, IPPROTO_TCP},
ok(WSASocketA(AF_INET, 0, -1, NULL, 0, 0) == INVALID_SOCKET, {AF_UNSPEC, 0, IPPROTO_UDP, 0, AF_INET, SOCK_DGRAM, IPPROTO_UDP},
"WSASocketA should have failed\n"); {AF_UNSPEC, 0, 0xdead, WSAEPROTONOSUPPORT},
err = WSAGetLastError(); {AF_UNSPEC, 0, 0, WSAEINVAL},
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); for (i = 0; i < ARRAY_SIZE(tests); ++i)
ok(WSASocketA(0, 0xdead, 0, NULL, 0, 0) == INVALID_SOCKET, {
"WSASocketA should have failed\n"); SetLastError( 0xdeadbeef );
err = WSAGetLastError(); sock = WSASocketA( tests[i].family, tests[i].type, tests[i].protocol, NULL, 0, 0 );
ok(err == WSAEINVAL, "Expected 10022, received %d\n", err); 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;
sock = WSASocketA(0, 0, IPPROTO_TCP, NULL, 0, 0); todo_wine_if (i == 19) ok(sock != INVALID_SOCKET, "Text %u: expected success\n", i);
ok(sock != INVALID_SOCKET, "WSASocketA should have succeeded\n"); if (sock == INVALID_SOCKET) continue;
closesocket(sock);
/* SOCK_STREAM does not support IPPROTO_UDP */ size = sizeof(info);
SetLastError(0xdeadbeef); err = getsockopt( sock, SOL_SOCKET, SO_PROTOCOL_INFOA, (char *)&info, &size );
ok(WSASocketA(AF_INET, SOCK_STREAM, IPPROTO_UDP, NULL, 0, 0) == INVALID_SOCKET, ok(!err, "Test %u: getsockopt failed, error %u\n", i, WSAGetLastError());
"WSASocketA should have failed\n"); ok(info.iAddressFamily == tests[i].ret_family, "Test %u: got wrong family %d\n", i, info.iAddressFamily);
err = WSAGetLastError(); ok(info.iSocketType == tests[i].ret_type, "Test %u: got wrong type %d\n", i, info.iSocketType);
ok(err == WSAEPROTONOSUPPORT, "Expected 10043, received %d\n", err); 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);
/* SOCK_DGRAM does not support IPPROTO_TCP */ closesocket( sock );
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);
/* Set pi_size explicitly to a value below 2*sizeof(WSAPROTOCOL_INFOA) /* Set pi_size explicitly to a value below 2*sizeof(WSAPROTOCOL_INFOA)
* to avoid a crash on win98. * to avoid a crash on win98.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment