Author: tfaber
Date: Sat Jun 13 12:29:07 2015
New Revision: 68120
URL:
http://svn.reactos.org/svn/reactos?rev=68120&view=rev
Log:
[WS2_32_APITEST]
- Add a test for send/sendto with a read-only buffer
CORE-9807
Added:
trunk/rostests/apitests/ws2_32/send.c (with props)
Modified:
trunk/rostests/apitests/ws2_32/CMakeLists.txt
trunk/rostests/apitests/ws2_32/testlist.c
Modified: trunk/rostests/apitests/ws2_32/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ws2_32/CMakeList…
==============================================================================
--- trunk/rostests/apitests/ws2_32/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/rostests/apitests/ws2_32/CMakeLists.txt [iso-8859-1] Sat Jun 13 12:29:07 2015
@@ -5,6 +5,7 @@
ioctlsocket.c
nostartup.c
recv.c
+ send.c
WSAStartup.c
testlist.c)
Added: trunk/rostests/apitests/ws2_32/send.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ws2_32/send.c?re…
==============================================================================
--- trunk/rostests/apitests/ws2_32/send.c (added)
+++ trunk/rostests/apitests/ws2_32/send.c [iso-8859-1] Sat Jun 13 12:29:07 2015
@@ -0,0 +1,185 @@
+/*
+ * PROJECT: ReactOS api tests
+ * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
+ * PURPOSE: Test for send/sendto
+ * PROGRAMMER: Thomas Faber <thomas.faber(a)reactos.org>
+ */
+
+#include <apitest.h>
+#include <winsock2.h>
+
+#define WIN32_NO_STATUS
+#include <ndk/mmfuncs.h>
+#include <ndk/rtlfuncs.h>
+
+static
+PVOID
+AllocateReadOnly(
+ _In_ SIZE_T SizeRequested)
+{
+ NTSTATUS Status;
+ SIZE_T Size = PAGE_ROUND_UP(SizeRequested);
+ PVOID VirtualMemory = NULL;
+
+ Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0,
&Size, MEM_COMMIT, PAGE_READONLY);
+ if (!NT_SUCCESS(Status))
+ return NULL;
+
+ return VirtualMemory;
+}
+
+static
+VOID
+FreeReadOnly(
+ _In_ PVOID VirtualMemory)
+{
+ NTSTATUS Status;
+ SIZE_T Size = 0;
+
+ Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size,
MEM_RELEASE);
+ ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
+}
+
+static
+VOID
+test_send(void)
+{
+ SOCKET sock;
+ int ret;
+ int error;
+ PVOID buffer;
+ ULONG bufferSize;
+ struct sockaddr_in addr;
+
+ bufferSize = 32;
+ buffer = AllocateReadOnly(bufferSize);
+ ok(buffer != NULL, "AllocateReadOnly failed\n");
+ if (!buffer)
+ {
+ skip("No memory\n");
+ return;
+ }
+
+ ret = send(0, NULL, 0, 0);
+ error = WSAGetLastError();
+ ok(ret == SOCKET_ERROR, "send returned %d\n", ret);
+ ok(error == WSAENOTSOCK, "error = %d\n", error);
+
+ ret = send(0, buffer, bufferSize, 0);
+ error = WSAGetLastError();
+ ok(ret == SOCKET_ERROR, "send returned %d\n", ret);
+ ok(error == WSAENOTSOCK, "error = %d\n", error);
+
+ sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ ok(sock != INVALID_SOCKET, "socket failed\n");
+ if (sock == INVALID_SOCKET)
+ {
+ skip("No socket\n");
+ FreeReadOnly(buffer);
+ return;
+ }
+
+ ret = send(sock, NULL, 0, 0);
+ error = WSAGetLastError();
+ ok(ret == SOCKET_ERROR, "send returned %d\n", ret);
+ ok(error == WSAENOTCONN, "error = %d\n", error);
+
+ ret = send(sock, buffer, bufferSize, 0);
+ error = WSAGetLastError();
+ ok(ret == SOCKET_ERROR, "send returned %d\n", ret);
+ ok(error == WSAENOTCONN, "error = %d\n", error);
+
+ memset(&addr, 0, sizeof(addr));
+ addr.sin_family = AF_INET;
+ addr.sin_addr.s_addr = inet_addr("8.8.8.8");
+ addr.sin_port = htons(53);
+ ret = connect(sock, (const struct sockaddr *)&addr, sizeof(addr));
+ error = WSAGetLastError();
+ ok(ret == 0, "connect returned %d\n", ret);
+ ok(error == 0, "error = %d\n", error);
+
+ ret = send(sock, NULL, 0, 0);
+ error = WSAGetLastError();
+ ok(ret == 0, "send returned %d\n", ret);
+ ok(error == 0, "error = %d\n", error);
+
+ ret = send(sock, buffer, bufferSize, 0);
+ error = WSAGetLastError();
+ ok(ret == bufferSize, "send returned %d\n", ret);
+ ok(error == 0, "error = %d\n", error);
+
+ closesocket(sock);
+
+ FreeReadOnly(buffer);
+}
+
+static
+VOID
+test_sendto(void)
+{
+ SOCKET sock;
+ int ret;
+ int error;
+ PVOID buffer;
+ ULONG bufferSize;
+ struct sockaddr_in addr;
+
+ bufferSize = 32;
+ buffer = AllocateReadOnly(bufferSize);
+ ok(buffer != NULL, "AllocateReadOnly failed\n");
+ if (!buffer)
+ {
+ skip("No memory\n");
+ return;
+ }
+
+ memset(&addr, 0, sizeof(addr));
+ addr.sin_family = AF_INET;
+ addr.sin_addr.s_addr = inet_addr("8.8.8.8");
+ addr.sin_port = htons(53);
+
+ ret = sendto(0, NULL, 0, 0, (const struct sockaddr *)&addr, sizeof(addr));
+ error = WSAGetLastError();
+ ok(ret == SOCKET_ERROR, "sendto returned %d\n", ret);
+ ok(error == WSAENOTSOCK, "error = %d\n", error);
+
+ ret = sendto(0, buffer, bufferSize, 0, (const struct sockaddr *)&addr,
sizeof(addr));
+ error = WSAGetLastError();
+ ok(ret == SOCKET_ERROR, "sendto returned %d\n", ret);
+ ok(error == WSAENOTSOCK, "error = %d\n", error);
+
+ sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ ok(sock != INVALID_SOCKET, "socket failed\n");
+ if (sock == INVALID_SOCKET)
+ {
+ skip("No socket\n");
+ FreeReadOnly(buffer);
+ return;
+ }
+
+ ret = sendto(sock, NULL, 0, 0, (const struct sockaddr *)&addr, sizeof(addr));
+ error = WSAGetLastError();
+ ok(ret == 0, "sendto returned %d\n", ret);
+ ok(error == 0, "error = %d\n", error);
+
+ ret = sendto(sock, buffer, bufferSize, 0, (const struct sockaddr *)&addr,
sizeof(addr));
+ error = WSAGetLastError();
+ ok(ret == bufferSize, "sendto returned %d\n", ret);
+ ok(error == 0, "error = %d\n", error);
+
+ closesocket(sock);
+
+ FreeReadOnly(buffer);
+}
+
+START_TEST(send)
+{
+ int ret;
+ WSADATA wsad;
+
+ ret = WSAStartup(MAKEWORD(2, 2), &wsad);
+ ok(ret == 0, "WSAStartup failed with %d\n", ret);
+ test_send();
+ test_sendto();
+ WSACleanup();
+}
Propchange: trunk/rostests/apitests/ws2_32/send.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/rostests/apitests/ws2_32/testlist.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ws2_32/testlist.…
==============================================================================
--- trunk/rostests/apitests/ws2_32/testlist.c [iso-8859-1] (original)
+++ trunk/rostests/apitests/ws2_32/testlist.c [iso-8859-1] Sat Jun 13 12:29:07 2015
@@ -6,6 +6,7 @@
extern void func_getaddrinfo(void);
extern void func_ioctlsocket(void);
extern void func_recv(void);
+extern void func_send(void);
extern void func_WSAStartup(void);
extern void func_nostartup(void);
@@ -15,6 +16,7 @@
{ "ioctlsocket", func_ioctlsocket },
{ "nostartup", func_nostartup },
{ "recv", func_recv },
+ { "send", func_send },
{ "WSAStartup", func_WSAStartup },
{ 0, 0 }
};