Commit 35a887ac authored by Bruno Jesus's avatar Bruno Jesus Committed by Alexandre Julliard

ws2_32/tests: Show that send/recv functions set last error to zero on success.

parent ed281c74
...@@ -1769,8 +1769,10 @@ static void test_ip_pktinfo(void) ...@@ -1769,8 +1769,10 @@ static void test_ip_pktinfo(void)
* Send a packet from the client to the server and test for specifying * Send a packet from the client to the server and test for specifying
* a short control header. * a short control header.
*/ */
SetLastError(0xdeadbeef);
rc=sendto(s2, msg, sizeof(msg), 0, (struct sockaddr*)&s2addr, sizeof(s2addr)); rc=sendto(s2, msg, sizeof(msg), 0, (struct sockaddr*)&s2addr, sizeof(s2addr));
ok(rc == sizeof(msg), "sendto() failed error: %d\n", WSAGetLastError()); ok(rc == sizeof(msg), "sendto() failed error: %d\n", WSAGetLastError());
ok(GetLastError() == ERROR_SUCCESS, "Expected 0, got %d\n", GetLastError());
hdr.Control.len = 1; hdr.Control.len = 1;
rc=pWSARecvMsg(s1, &hdr, &dwSize, NULL, NULL); rc=pWSARecvMsg(s1, &hdr, &dwSize, NULL, NULL);
err=WSAGetLastError(); err=WSAGetLastError();
...@@ -1783,8 +1785,10 @@ static void test_ip_pktinfo(void) ...@@ -1783,8 +1785,10 @@ static void test_ip_pktinfo(void)
rc=pWSARecvMsg(s1, &hdr, NULL, &ov, NULL); rc=pWSARecvMsg(s1, &hdr, NULL, &ov, NULL);
err=WSAGetLastError(); err=WSAGetLastError();
ok(rc != 0 && err == WSA_IO_PENDING, "WSARecvMsg() failed error: %d\n", err); ok(rc != 0 && err == WSA_IO_PENDING, "WSARecvMsg() failed error: %d\n", err);
SetLastError(0xdeadbeef);
rc=sendto(s2, msg, sizeof(msg), 0, (struct sockaddr*)&s2addr, sizeof(s2addr)); rc=sendto(s2, msg, sizeof(msg), 0, (struct sockaddr*)&s2addr, sizeof(s2addr));
ok(rc == sizeof(msg), "sendto() failed error: %d\n", WSAGetLastError()); ok(rc == sizeof(msg), "sendto() failed error: %d\n", WSAGetLastError());
ok(GetLastError() == ERROR_SUCCESS, "Expected 0, got %d\n", GetLastError());
if (WaitForSingleObject(ov.hEvent, 100) != WAIT_OBJECT_0) if (WaitForSingleObject(ov.hEvent, 100) != WAIT_OBJECT_0)
{ {
skip("Server side did not receive packet, some tests skipped.\n"); skip("Server side did not receive packet, some tests skipped.\n");
...@@ -5123,16 +5127,24 @@ static void test_events(int useMessages) ...@@ -5123,16 +5127,24 @@ static void test_events(int useMessages)
/* broken on all windows - FD_CONNECT error is garbage */ /* broken on all windows - FD_CONNECT error is garbage */
/* Test simple send/recv */ /* Test simple send/recv */
SetLastError(0xdeadbeef);
ret = send(dst, buffer, 100, 0); ret = send(dst, buffer, 100, 0);
ok(ret == 100, "Failed to send buffer %d err %d\n", ret, GetLastError()); ok(ret == 100, "Failed to send buffer %d err %d\n", ret, GetLastError());
ok(GetLastError() == ERROR_SUCCESS, "Expected 0, got %d\n", GetLastError());
ok_event_seq(src, hEvent, read_seq, NULL, 0); ok_event_seq(src, hEvent, read_seq, NULL, 0);
SetLastError(0xdeadbeef);
ret = recv(src, buffer, 1, MSG_PEEK); ret = recv(src, buffer, 1, MSG_PEEK);
ok(ret == 1, "Failed to peek at recv buffer %d err %d\n", ret, GetLastError()); ok(ret == 1, "Failed to peek at recv buffer %d err %d\n", ret, GetLastError());
todo_wine
ok(GetLastError() == ERROR_SUCCESS, "Expected 0, got %d\n", GetLastError());
ok_event_seq(src, hEvent, read_seq, NULL, 0); ok_event_seq(src, hEvent, read_seq, NULL, 0);
SetLastError(0xdeadbeef);
ret = recv(src, buffer, 50, 0); ret = recv(src, buffer, 50, 0);
ok(ret == 50, "Failed to recv buffer %d err %d\n", ret, GetLastError()); ok(ret == 50, "Failed to recv buffer %d err %d\n", ret, GetLastError());
todo_wine
ok(GetLastError() == ERROR_SUCCESS, "Expected 0, got %d\n", GetLastError());
ok_event_seq(src, hEvent, read_seq, NULL, 0); ok_event_seq(src, hEvent, read_seq, NULL, 0);
ret = recv(src, buffer, 50, 0); ret = recv(src, buffer, 50, 0);
...@@ -5156,8 +5168,11 @@ static void test_events(int useMessages) ...@@ -5156,8 +5168,11 @@ static void test_events(int useMessages)
else else
ok_event_seq(src, hEvent, empty_seq, NULL, 0); ok_event_seq(src, hEvent, empty_seq, NULL, 0);
SetLastError(0xdeadbeef);
ret = recv(src, buffer, 1, 0); ret = recv(src, buffer, 1, 0);
ok(ret == 1, "Failed to recv buffer %d err %d\n", ret, GetLastError()); ok(ret == 1, "Failed to recv buffer %d err %d\n", ret, GetLastError());
todo_wine
ok(GetLastError() == ERROR_SUCCESS, "Expected 0, got %d\n", GetLastError());
ok_event_seq(src, hEvent, empty_seq, NULL, 0); ok_event_seq(src, hEvent, empty_seq, NULL, 0);
/* Interaction with overlapped */ /* Interaction with overlapped */
...@@ -5199,8 +5214,10 @@ static void test_events(int useMessages) ...@@ -5199,8 +5214,10 @@ static void test_events(int useMessages)
ok(buffer[1] == '2', "Got %c instead of 2\n", buffer[1]); ok(buffer[1] == '2', "Got %c instead of 2\n", buffer[1]);
} }
SetLastError(0xdeadbeef);
ret = send(dst, "1", 1, 0); ret = send(dst, "1", 1, 0);
ok(ret == 1, "Failed to send buffer %d err %d\n", ret, GetLastError()); ok(ret == 1, "Failed to send buffer %d err %d\n", ret, GetLastError());
ok(GetLastError() == ERROR_SUCCESS, "Expected 0, got %d\n", GetLastError());
ok_event_seq(src, hEvent, read_seq, NULL, 0); ok_event_seq(src, hEvent, read_seq, NULL, 0);
ret = recv(src, buffer, 1, 0); ret = recv(src, buffer, 1, 0);
...@@ -5571,17 +5588,23 @@ static void test_WSASendMsg(void) ...@@ -5571,17 +5588,23 @@ static void test_WSASendMsg(void)
set_blocking(sock, TRUE); set_blocking(sock, TRUE);
bytesSent = 0; bytesSent = 0;
SetLastError(0xdeadbeef);
ret = pWSASendMsg(sock, &msg, 0, &bytesSent, NULL, NULL); ret = pWSASendMsg(sock, &msg, 0, &bytesSent, NULL, NULL);
ok(!ret, "WSASendMsg should have worked\n"); ok(!ret, "WSASendMsg should have worked\n");
ok(GetLastError() == 0 || broken(GetLastError() == 0xdeadbeef) /* Win <= 2008 */,
"Expected 0, got %d\n", GetLastError());
ok(bytesSent == iovec[0].len, "incorret bytes sent, expected %d, sent %d\n", ok(bytesSent == iovec[0].len, "incorret bytes sent, expected %d, sent %d\n",
iovec[0].len, bytesSent); iovec[0].len, bytesSent);
/* receive data */ /* receive data */
addrlen = sizeof(sockaddr); addrlen = sizeof(sockaddr);
memset(buffer, 0, sizeof(buffer)); memset(buffer, 0, sizeof(buffer));
SetLastError(0xdeadbeef);
ret = recvfrom(dst, buffer, sizeof(buffer), 0, (struct sockaddr *) &sockaddr, &addrlen); ret = recvfrom(dst, buffer, sizeof(buffer), 0, (struct sockaddr *) &sockaddr, &addrlen);
ok(ret == bytesSent, "got %d, expected %d\n", ok(ret == bytesSent, "got %d, expected %d\n",
ret, bytesSent); ret, bytesSent);
todo_wine
ok(GetLastError() == ERROR_SUCCESS, "Expected 0, got %d\n", GetLastError());
/* A successful call to WSASendMsg must have bound the socket */ /* A successful call to WSASendMsg must have bound the socket */
addrlen = sizeof(sockaddr); addrlen = sizeof(sockaddr);
...@@ -5596,17 +5619,23 @@ static void test_WSASendMsg(void) ...@@ -5596,17 +5619,23 @@ static void test_WSASendMsg(void)
msg.dwBufferCount = 2; /* send both buffers */ msg.dwBufferCount = 2; /* send both buffers */
bytesSent = 0; bytesSent = 0;
SetLastError(0xdeadbeef);
ret = pWSASendMsg(sock, &msg, 0, &bytesSent, NULL, NULL); ret = pWSASendMsg(sock, &msg, 0, &bytesSent, NULL, NULL);
ok(!ret, "WSASendMsg should have worked\n"); ok(!ret, "WSASendMsg should have worked\n");
ok(bytesSent == iovec[0].len + iovec[1].len, "incorret bytes sent, expected %d, sent %d\n", ok(bytesSent == iovec[0].len + iovec[1].len, "incorret bytes sent, expected %d, sent %d\n",
iovec[0].len + iovec[1].len, bytesSent); iovec[0].len + iovec[1].len, bytesSent);
ok(GetLastError() == 0 || broken(GetLastError() == 0xdeadbeef) /* Win <= 2008 */,
"Expected 0, got %d\n", GetLastError());
/* receive data */ /* receive data */
addrlen = sizeof(sockaddr); addrlen = sizeof(sockaddr);
memset(buffer, 0, sizeof(buffer)); memset(buffer, 0, sizeof(buffer));
SetLastError(0xdeadbeef);
ret = recvfrom(dst, buffer, sizeof(buffer), 0, (struct sockaddr *) &sockaddr, &addrlen); ret = recvfrom(dst, buffer, sizeof(buffer), 0, (struct sockaddr *) &sockaddr, &addrlen);
ok(ret == bytesSent, "got %d, expected %d\n", ok(ret == bytesSent, "got %d, expected %d\n",
ret, bytesSent); ret, bytesSent);
todo_wine
ok(GetLastError() == ERROR_SUCCESS, "Expected 0, got %d\n", GetLastError());
closesocket(sock); closesocket(sock);
closesocket(dst); closesocket(dst);
...@@ -5719,8 +5748,6 @@ static void test_WSARecv(void) ...@@ -5719,8 +5748,6 @@ static void test_WSARecv(void)
BOOL bret; BOOL bret;
HANDLE thread; HANDLE thread;
memset(&ov, 0, sizeof(ov));
tcp_socketpair(&src, &dest); tcp_socketpair(&src, &dest);
if (src == INVALID_SOCKET || dest == INVALID_SOCKET) if (src == INVALID_SOCKET || dest == INVALID_SOCKET)
{ {
...@@ -5728,9 +5755,45 @@ static void test_WSARecv(void) ...@@ -5728,9 +5755,45 @@ static void test_WSARecv(void)
goto end; goto end;
} }
bufs.len = sizeof(buf); memset(&ov, 0, sizeof(ov));
bufs.buf = buf;
flags = 0; flags = 0;
bufs.len = 2;
bufs.buf = buf;
/* Send 4 bytes and receive in two calls of 2 */
SetLastError(0xdeadbeef);
iret = send(src, "test", 4, 0);
ok(iret == 4, "Expected 4, got %d\n", iret);
ok(GetLastError() == ERROR_SUCCESS, "Expected 0, got %d\n", GetLastError());
SetLastError(0xdeadbeef);
bytesReturned = 0xdeadbeef;
iret = WSARecv(dest, &bufs, 1, &bytesReturned, &flags, NULL, NULL);
ok(!iret, "Expected 0, got %d\n", iret);
ok(bytesReturned, "Expected 2, got %d\n", bytesReturned);
todo_wine
ok(GetLastError() == ERROR_SUCCESS, "Expected 0, got %d\n", GetLastError());
SetLastError(0xdeadbeef);
bytesReturned = 0xdeadbeef;
iret = WSARecv(dest, &bufs, 1, &bytesReturned, &flags, NULL, NULL);
ok(!iret, "Expected 0, got %d\n", iret);
ok(bytesReturned, "Expected 2, got %d\n", bytesReturned);
todo_wine
ok(GetLastError() == ERROR_SUCCESS, "Expected 0, got %d\n", GetLastError());
bufs.len = 4;
SetLastError(0xdeadbeef);
iret = send(src, "test", 4, 0);
ok(iret == 4, "Expected 4, got %d\n", iret);
ok(GetLastError() == ERROR_SUCCESS, "Expected 0, got %d\n", GetLastError());
SetLastError(0xdeadbeef);
bytesReturned = 0xdeadbeef;
iret = WSARecv(dest, &bufs, 1, &bytesReturned, &flags, NULL, NULL);
ok(!iret, "Expected 0, got %d\n", iret);
ok(bytesReturned, "Expected 4, got %d\n", bytesReturned);
todo_wine
ok(GetLastError() == ERROR_SUCCESS, "Expected 0, got %d\n", GetLastError());
bufs.len = sizeof(buf);
ov.hEvent = CreateEventA(NULL, FALSE, FALSE, NULL); ov.hEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
ok(ov.hEvent != NULL, "could not create event object, errno = %d\n", GetLastError()); ok(ov.hEvent != NULL, "could not create event object, errno = %d\n", GetLastError());
......
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