Author: phater
Date: Thu Nov 10 15:13:19 2016
New Revision: 73195
URL:
http://svn.reactos.org/svn/reactos?rev=73195&view=rev
Log:
[WS2_32_APITESTS] Add nonblocking tests
Added:
trunk/rostests/apitests/ws2_32/nonblocking.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] Thu Nov 10 15:13:19 2016
@@ -6,6 +6,7 @@
getservbyport.c
helpers.c
ioctlsocket.c
+ nonblocking.c
nostartup.c
recv.c
send.c
Added: trunk/rostests/apitests/ws2_32/nonblocking.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ws2_32/nonblocki…
==============================================================================
--- trunk/rostests/apitests/ws2_32/nonblocking.c (added)
+++ trunk/rostests/apitests/ws2_32/nonblocking.c [iso-8859-1] Thu Nov 10 15:13:19 2016
@@ -0,0 +1,135 @@
+/*
+* PROJECT: ReactOS api tests
+* LICENSE: GPL - See COPYING in the top level directory
+* PURPOSE: Test for nonblocking sockets
+* PROGRAMMERS: Peter Hater
+*/
+
+#include <apitest.h>
+
+#include <stdio.h>
+#include <windows.h>
+#include <winsock2.h>
+
+#define SVR_PORT 5000
+#define WAIT_TIMEOUT_ 10000
+#define EXIT_FLAGS (FD_ACCEPT|FD_CONNECT)
+
+START_TEST(nonblocking)
+{
+ WSADATA WsaData;
+ SOCKET ServerSocket = INVALID_SOCKET,
+ ClientSocket = INVALID_SOCKET;
+ struct sockaddr_in server_addr_in;
+ struct sockaddr_in addr_remote;
+ struct sockaddr_in addr_con_loc;
+ int nConRes, err;
+ int addrsize;
+ SOCKET sockaccept;
+ ULONG ulValue = 1;
+ DWORD dwFlags = 0, dwLen, dwAddrLen;
+ fd_set readfds, writefds, exceptfds;
+ struct timeval tval = { 0 };
+ char address[100];
+
+ if (WSAStartup(MAKEWORD(2, 2), &WsaData) != 0)
+ {
+ skip("WSAStartup failed\n");
+ return;
+ }
+
+ ServerSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ ClientSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+
+ if (ServerSocket == INVALID_SOCKET)
+ {
+ skip("ERROR: Server socket creation failed\n");
+ return;
+ }
+ if (ClientSocket == INVALID_SOCKET)
+ {
+ skip("ERROR: Client socket creation failed\n");
+ closesocket(ServerSocket);
+ return;
+ }
+ server_addr_in.sin_family = AF_INET;
+ server_addr_in.sin_addr.s_addr = INADDR_ANY;
+ server_addr_in.sin_port = htons(SVR_PORT);
+
+ // server inialialization
+ trace("Initializing server and client connections ...\n");
+ err = bind(ServerSocket, (struct sockaddr*)&server_addr_in,
sizeof(server_addr_in));
+ ok(err == 0, "ERROR: server bind failed\n");
+ err = ioctlsocket(ServerSocket, FIONBIO, &ulValue);
+ ok(err == 0, "ERROR: server ioctlsocket FIONBIO failed\n");
+
+ // client inialialization
+ err = ioctlsocket(ClientSocket, FIONBIO, &ulValue);
+ ok(err == 0, "ERROR: client ioctlsocket FIONBIO failed\n");
+
+ // listen
+ trace("Starting server listening mode ...\n");
+ err = listen(ServerSocket, 2);
+ ok(err == 0, "ERROR: cannot initialize server listen\n");
+
+ trace("Starting client to server connection ...\n");
+ // connect
+ server_addr_in.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ server_addr_in.sin_port = htons(SVR_PORT);
+ nConRes = connect(ClientSocket, (struct sockaddr*)&server_addr_in,
sizeof(server_addr_in));
+ ok(nConRes == SOCKET_ERROR, "ERROR: client connect() result is not
SOCKET_ERROR\n");
+ ok(WSAGetLastError() == WSAEWOULDBLOCK, "ERROR: client connect() last error is
not WSAEWOULDBLOCK\n");
+ FD_ZERO(&readfds);
+ FD_ZERO(&writefds);
+ FD_ZERO(&exceptfds);
+ FD_SET(ServerSocket, &readfds);
+
+ while (dwFlags != EXIT_FLAGS)
+ {
+ addrsize = sizeof(addr_con_loc);
+ err = getsockname(ClientSocket, (struct sockaddr*)&addr_con_loc,
&addrsize);
+ if (err == 0)
+ {// client connected
+ dwLen = sizeof(addr_con_loc);
+ dwAddrLen = sizeof(address);
+ err = WSAAddressToStringA((PSOCKADDR)&addr_con_loc, dwLen, NULL, address,
&dwAddrLen);
+ if (err == 0)
+ {
+ trace("Event FD_CONNECT...\n");
+ dwFlags |= FD_CONNECT;
+ err = recv(ClientSocket, address, dwAddrLen, 0);
+ ok(err == -1, "ERROR: error reading data from connected socket,
error %d\n", WSAGetLastError());
+ ok(WSAGetLastError() == WSAEWOULDBLOCK, "ERROR: client connect()
last error is not WSAEWOULDBLOCK\n");
+ err = send(ClientSocket, address, dwAddrLen, 0);
+ ok(err == dwAddrLen, "ERROR: error writing data to connected socket,
error %d %d\n", err, WSAGetLastError());
+ }
+ else
+ {
+ trace("WSAAddressToStringA failed %d\n", WSAGetLastError());
+ }
+ }
+
+ err = select(1, &readfds, &writefds, &exceptfds, &tval);
+ if (err == 1 && FD_ISSET(ServerSocket, &readfds))
+ {// connection ready to be accepted
+ trace("Event FD_ACCEPT...\n");
+ addrsize = sizeof(addr_remote);
+ sockaccept = accept(ServerSocket, (struct sockaddr*)&addr_remote,
&addrsize);
+ ok(sockaccept != INVALID_SOCKET, "ERROR: Connection accept function
failed, error %d\n", WSAGetLastError());
+ dwFlags |= FD_ACCEPT;
+ dwLen = sizeof(addr_remote);
+ dwAddrLen = sizeof(address);
+ err = WSAAddressToStringA((PSOCKADDR)&addr_remote, dwLen, NULL, address,
&dwAddrLen);
+ ok(err == 0, "WSAAddressToStringA, error %d\n",
WSAGetLastError());
+ ok(dwAddrLen > 7, "len <= 7\n");
+ err = send(sockaccept, address, dwAddrLen, 0);
+ ok(err == dwAddrLen, "ERROR: error sending data on accepted socket,
error %d\n", WSAGetLastError());
+ }
+ }
+
+ closesocket(sockaccept);
+ closesocket(ServerSocket);
+ closesocket(ClientSocket);
+
+ WSACleanup();
+}
Propchange: trunk/rostests/apitests/ws2_32/nonblocking.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] Thu Nov 10 15:13:19 2016
@@ -8,6 +8,7 @@
extern void func_getservbyname(void);
extern void func_getservbyport(void);
extern void func_ioctlsocket(void);
+extern void func_nonblocking(void);
extern void func_nostartup(void);
extern void func_recv(void);
extern void func_send(void);
@@ -23,6 +24,7 @@
{ "getservbyname", func_getservbyname },
{ "getservbyport", func_getservbyport },
{ "ioctlsocket", func_ioctlsocket },
+ { "nonblocking", func_nonblocking },
{ "nostartup", func_nostartup },
{ "recv", func_recv },
{ "send", func_send },