Commit ce0e3158 authored by Bruno Jesus's avatar Bruno Jesus Committed by Alexandre Julliard

ws2_32/tests: Add and update WSASocketA() tests.

parent c0faf86f
......@@ -1701,6 +1701,22 @@ todo_wine
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();
todo_wine
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();
todo_wine
ok(err == WSAEPROTONOSUPPORT, "Expected 10043, received %d\n", err);
/* Set pi_size explicitly to a value below 2*sizeof(WSAPROTOCOL_INFOA)
* to avoid a crash on win98.
*/
......@@ -1739,6 +1755,18 @@ todo_wine
pi[0].iProtocol = IPPROTO_UDP;
pi[0].iSocketType = SOCK_DGRAM;
pi[0].iAddressFamily = AF_INET;
sock = WSASocketA(0, 0, 0, &pi[0], 0, 0);
todo_wine {
ok(sock != INVALID_SOCKET, "Failed to create socket: %d\n",
WSAGetLastError());
size = sizeof(socktype);
socktype = 0xdead;
err = getsockopt(sock, SOL_SOCKET, SO_TYPE, (char *) &socktype, &size);
ok(!err,"getsockopt failed with %d\n", WSAGetLastError());
ok(socktype == SOCK_DGRAM, "Wrong socket type, expected %d received %d\n",
SOCK_DGRAM, socktype);
closesocket(sock);
}
sock = WSASocketA(AF_INET, SOCK_STREAM, IPPROTO_TCP, &pi[0], 0, 0);
ok(sock != INVALID_SOCKET, "Failed to create socket: %d\n",
WSAGetLastError());
......@@ -1771,7 +1799,9 @@ todo_wine
ok(items != SOCKET_ERROR, "WSAEnumProtocolsA failed, last error is %d\n",
WSAGetLastError());
/* when no protocol is specified the first socket type from WSAEnumProtocols is returned */
/* when no protocol and socket type are specified the first entry
* from WSAEnumProtocols that has the flag PFL_MATCHES_PROTOCOL_ZERO
* is returned */
sock = WSASocketA(AF_INET, 0, 0, NULL, 0, 0);
todo_wine
ok(sock != INVALID_SOCKET, "Failed to create socket: %d\n",
......@@ -1782,12 +1812,21 @@ todo_wine {
socktype = 0xdead;
err = getsockopt(sock, SOL_SOCKET, SO_TYPE, (char *) &socktype, &size);
ok(!err, "getsockopt failed with %d\n", WSAGetLastError());
ok(socktype == pi[0].iSocketType, "Wrong socket type, expected %d received %d\n",
pi[0].iSocketType, socktype);
for(i = 0; i < items; i++)
{
if(pi[i].dwProviderFlags & PFL_MATCHES_PROTOCOL_ZERO)
{
ok(socktype == pi[i].iSocketType, "Wrong socket type, expected %d received %d\n",
pi[i].iSocketType, socktype);
break;
}
}
ok(i != items, "Creating a socket without protocol and socket type didn't work\n");
}
closesocket(sock);
/* when the protocol is specified the first socket type that matches the protocol is returned */
/* when no socket type is specified the first entry from WSAEnumProtocols
* that matches the protocol is returned */
for (i = 0; i < sizeof(autoprotocols) / sizeof(autoprotocols[0]); i++)
{
sock = WSASocketA(0, 0, autoprotocols[i], NULL, 0, 0);
......@@ -1801,18 +1840,21 @@ todo_wine
todo_wine
ok(!err, "getsockopt failed with %d\n", WSAGetLastError());
for (j = 0; j < items; j++)
for (err = 1, j = 0; j < items; j++)
{
if (pi[j].iProtocol == autoprotocols[i])
{
if (socktype == pi[j].iSocketType)
err = 0;
else
todo_wine
ok(socktype == pi[j].iSocketType, "Wrong socket type, expected %d received %d\n",
pi[j].iSocketType, socktype);
ok(0, "Wrong socket type, expected %d received %d\n",
pi[j].iSocketType, socktype);
break;
}
}
todo_wine
ok(socktype != 0xdead, "Protocol %d not found in WSAEnumProtocols\n", autoprotocols[i]);
ok(!err, "Protocol %d not found in WSAEnumProtocols\n", autoprotocols[i]);
closesocket(sock);
}
......
......@@ -213,6 +213,12 @@ typedef struct _WSAPROTOCOLCHAIN
DWORD ChainEntries[MAX_PROTOCOL_CHAIN]; /* a list of dwCatalogEntryIds */
} WSAPROTOCOLCHAIN, * LPWSAPROTOCOLCHAIN;
/* constants used in dwProviderFlags from struct WSAPROTOCOL_INFO */
#define PFL_MULTIPLE_PROTO_ENTRIES 0x00000001
#define PFL_RECOMMENDED_PROTO_ENTRY 0x00000002
#define PFL_HIDDEN 0x00000004
#define PFL_MATCHES_PROTOCOL_ZERO 0x00000008
#define XP1_CONNECTIONLESS 0x00000001
#define XP1_GUARANTEED_DELIVERY 0x00000002
#define XP1_GUARANTEED_ORDER 0x00000004
......
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