Author: cfinck
Date: Sun Jun 1 17:08:45 2008
New Revision: 33824
URL:
http://svn.reactos.org/svn/reactos?rev=33824&view=rev
Log:
- Add a test suite for ws2_32.dll
It currently tests the features I needed to adjust/implement when fixing the wininet
problem.
ReactOS currently passes all tests, but fails one if you launch the test app for the
second time quickly after the first time (timing problem in the network code?).
- Fix the behaviour on an ioctlsocket FIONREAD call: The output buffer is not touched,
when we have no socket, but when we have no connection, it is set to 0.
- Forward the socket call to WSASocketW instead of WSASocketA, minimal performance
improvement
Added:
trunk/rostests/apitests/ws2_32/ (with props)
trunk/rostests/apitests/ws2_32/helpers.c (with props)
trunk/rostests/apitests/ws2_32/testlist.c (with props)
trunk/rostests/apitests/ws2_32/tests/
trunk/rostests/apitests/ws2_32/tests/ioctlsocket.c (with props)
trunk/rostests/apitests/ws2_32/tests/recv.c (with props)
trunk/rostests/apitests/ws2_32/ws2_32.c (with props)
trunk/rostests/apitests/ws2_32/ws2_32.h (with props)
trunk/rostests/apitests/ws2_32/ws2_32.rbuild (with props)
Modified:
trunk/reactos/dll/win32/ws2_32/misc/dllmain.c
trunk/reactos/drivers/network/afd/afd/info.c
trunk/rostests/apitests/directory.rbuild
Modified: trunk/reactos/dll/win32/ws2_32/misc/dllmain.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/misc/dllm…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/misc/dllmain.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/misc/dllmain.c [iso-8859-1] Sun Jun 1 17:08:45 2008
@@ -166,7 +166,7 @@
IN INT type,
IN INT protocol)
{
- return WSASocketA(af,
+ return WSASocketW(af,
type,
protocol,
NULL,
Modified: trunk/reactos/drivers/network/afd/afd/info.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/afd/afd/in…
==============================================================================
--- trunk/reactos/drivers/network/afd/afd/info.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/afd/afd/info.c [iso-8859-1] Sun Jun 1 17:08:45 2008
@@ -49,9 +49,9 @@
break;
case AFD_INFO_RECEIVE_CONTENT_SIZE:
- /* Only touch InfoReq if we actually have a valid connection.
+ /* Only touch InfoReq if a socket has been set up.
Behaviour was verified under WinXP SP2. */
- if(FCB->Connection.Handle)
+ if(FCB->AddressFile.Object)
InfoReq->Information.Ulong = FCB->Recv.Content -
FCB->Recv.BytesUsed;
break;
Modified: trunk/rostests/apitests/directory.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/directory.rbuild…
==============================================================================
--- trunk/rostests/apitests/directory.rbuild [iso-8859-1] (original)
+++ trunk/rostests/apitests/directory.rbuild [iso-8859-1] Sun Jun 1 17:08:45 2008
@@ -23,4 +23,8 @@
<directory name="w32knapi">
<xi:include href="w32knapi/w32knapi.rbuild" />
</directory>
+
+ <directory name="ws2_32">
+ <xi:include href="ws2_32/ws2_32.rbuild" />
+ </directory>
</group>
Propchange: trunk/rostests/apitests/ws2_32/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Jun 1 17:08:45 2008
@@ -1,0 +1,7 @@
+GNUmakefile
+*.vcproj
+*.user
+*.cbp
+*.ncb
+*.suo
+*.sln
Added: trunk/rostests/apitests/ws2_32/helpers.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ws2_32/helpers.c…
==============================================================================
--- trunk/rostests/apitests/ws2_32/helpers.c (added)
+++ trunk/rostests/apitests/ws2_32/helpers.c [iso-8859-1] Sun Jun 1 17:08:45 2008
@@ -1,0 +1,65 @@
+/*
+ * PROJECT: ws2_32.dll API tests
+ * LICENSE: GPLv2 or any later version
+ * FILE: apitests/ws2_32/helpers.c
+ * PURPOSE: Helper functions for the socket tests
+ * COPYRIGHT: Copyright 2008 Colin Finck <mail(a)colinfinck.de>
+ */
+
+#include "ws2_32.h"
+
+int CreateSocket(PTESTINFO pti, SOCKET* psck)
+{
+ /* Create the socket */
+ *psck = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ TEST(*psck != INVALID_SOCKET);
+
+ if(*psck == INVALID_SOCKET)
+ {
+ printf("Winsock error code is %u\n", WSAGetLastError());
+ WSACleanup();
+ return APISTATUS_ASSERTION_FAILED;
+ }
+
+ return APISTATUS_NORMAL;
+}
+
+int ConnectToReactOSWebsite(PTESTINFO pti, SOCKET sck)
+{
+ int iResult;
+ struct hostent* host;
+ struct sockaddr_in sa;
+
+ /* Connect to "www.reactos.org" */
+ host = gethostbyname("www.reactos.org");
+
+ sa.sin_family = AF_INET;
+ sa.sin_addr.s_addr = *(u_long*)host->h_addr_list[0];
+ sa.sin_port = htons(80);
+
+ SCKTEST(connect(sck, (struct sockaddr *)&sa, sizeof(sa)));
+
+ return APISTATUS_NORMAL;
+}
+
+int GetRequestAndWait(PTESTINFO pti, SOCKET sck)
+{
+ const char szGetRequest[] = "GET / HTTP/1.0\r\n\r\n";
+ int iResult;
+ struct fd_set readable;
+
+ /* Send the GET request */
+ SCKTEST(send(sck, szGetRequest, strlen(szGetRequest), 0));
+ TEST(iResult == strlen(szGetRequest));
+
+ /* Shutdown the SEND connection */
+ SCKTEST(shutdown(sck, SD_SEND));
+
+ /* Wait until we're ready to read */
+ FD_ZERO(&readable);
+ FD_SET(sck, &readable);
+
+ SCKTEST(select(0, &readable, NULL, NULL, NULL));
+
+ return APISTATUS_NORMAL;
+}
Propchange: trunk/rostests/apitests/ws2_32/helpers.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: 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 (added)
+++ trunk/rostests/apitests/ws2_32/testlist.c [iso-8859-1] Sun Jun 1 17:08:45 2008
@@ -1,0 +1,33 @@
+/*
+ * PROJECT: ws2_32.dll API tests
+ * LICENSE: GPLv2 or any later version
+ * FILE: apitests/ws2_32/testlist.c
+ * PURPOSE: Test list file
+ * COPYRIGHT: Copyright 2008 Colin Finck <mail(a)colinfinck.de>
+ */
+
+#ifndef _WS2_32_TESTLIST_H
+#define _WS2_32_TESTLIST_H
+
+#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
+
+#include "ws2_32.h"
+
+/* include the tests */
+#include "tests/ioctlsocket.c"
+#include "tests/recv.c"
+
+/* The List of tests */
+TESTENTRY TestList[] =
+{
+ { L"ioctlsocket", Test_ioctlsocket },
+ { L"recv", Test_recv }
+};
+
+/* The function that gives us the number of tests */
+INT NumTests(void)
+{
+ return ARRAY_SIZE(TestList);
+}
+
+#endif
Propchange: trunk/rostests/apitests/ws2_32/testlist.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/rostests/apitests/ws2_32/tests/ioctlsocket.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ws2_32/tests/ioc…
==============================================================================
--- trunk/rostests/apitests/ws2_32/tests/ioctlsocket.c (added)
+++ trunk/rostests/apitests/ws2_32/tests/ioctlsocket.c [iso-8859-1] Sun Jun 1 17:08:45
2008
@@ -1,0 +1,83 @@
+/*
+ * PROJECT: ws2_32.dll API tests
+ * LICENSE: GPLv2 or any later version
+ * FILE: apitests/ws2_32/tests/ioctlsocket.c
+ * PURPOSE: Tests for the ioctlsocket function
+ * COPYRIGHT: Copyright 2008 Colin Finck <mail(a)colinfinck.de>
+ */
+
+#include "../ws2_32.h"
+
+/* For valid test results, the ReactOS Website needs to return at least 2 bytes on a
"GET / HTTP/1.0" request. */
+INT
+Test_ioctlsocket(PTESTINFO pti)
+{
+ LPSTR pszBuf;
+ int iResult;
+ SOCKET sck;
+ ULONG BytesAvailable;
+ ULONG BytesToRead;
+ WSADATA wdata;
+
+ /* Start up Winsock */
+ TEST(WSAStartup(MAKEWORD(2, 2), &wdata) == 0);
+
+ /* If we call ioctlsocket without a socket, it should return with an error and do
nothing. */
+ BytesAvailable = 0xdeadbeef;
+ TEST(ioctlsocket(0, FIONREAD, &BytesAvailable) == SOCKET_ERROR);
+ TEST(BytesAvailable == 0xdeadbeef);
+
+ /* Create the socket */
+ iResult = CreateSocket(pti, &sck);
+ if(iResult != APISTATUS_NORMAL)
+ return iResult;
+
+ /* Now we can pass at least a socket, but we have no connection yet. The function
should return 0. */
+ BytesAvailable = 0xdeadbeef;
+ TEST(ioctlsocket(sck, FIONREAD, &BytesAvailable) == 0);
+ TEST(BytesAvailable == 0);
+
+ /* Connect to "www.reactos.org" */
+ iResult = ConnectToReactOSWebsite(pti, sck);
+ if(iResult != APISTATUS_NORMAL)
+ return iResult;
+
+ /* Even with a connection, there shouldn't be any bytes available. */
+ TEST(ioctlsocket(sck, FIONREAD, &BytesAvailable) == 0);
+ TEST(BytesAvailable == 0);
+
+ /* Send the GET request */
+ iResult = GetRequestAndWait(pti, sck);
+ if(iResult != APISTATUS_NORMAL)
+ return iResult;
+
+ /* Try ioctlsocket with FIONREAD. There should be bytes available now. */
+ SCKTEST(ioctlsocket(sck, FIONREAD, &BytesAvailable));
+ TEST(BytesAvailable != 0);
+
+ /* Get half of the data */
+ BytesToRead = BytesAvailable / 2;
+ pszBuf = (LPSTR) HeapAlloc(g_hHeap, 0, BytesToRead);
+ SCKTEST(recv(sck, pszBuf, BytesToRead, 0));
+ HeapFree(g_hHeap, 0, pszBuf);
+
+ BytesToRead = BytesAvailable - BytesToRead;
+
+ /* Now try ioctlsocket again. BytesAvailable should be at the value saved in
BytesToRead now. */
+ SCKTEST(ioctlsocket(sck, FIONREAD, &BytesAvailable));
+ TEST(BytesAvailable == BytesToRead);
+
+ /* Read those bytes */
+ pszBuf = (LPSTR) HeapAlloc(g_hHeap, 0, BytesToRead);
+ SCKTEST(recv(sck, pszBuf, BytesToRead, 0));
+ HeapFree(g_hHeap, 0, pszBuf);
+
+ /* Try it for the last time. BytesAvailable should be at 0 now. */
+ SCKTEST(ioctlsocket(sck, FIONREAD, &BytesAvailable));
+ TEST(BytesAvailable == 0);
+
+ closesocket(sck);
+ WSACleanup();
+
+ return APISTATUS_NORMAL;
+}
Propchange: trunk/rostests/apitests/ws2_32/tests/ioctlsocket.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/rostests/apitests/ws2_32/tests/recv.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ws2_32/tests/rec…
==============================================================================
--- trunk/rostests/apitests/ws2_32/tests/recv.c (added)
+++ trunk/rostests/apitests/ws2_32/tests/recv.c [iso-8859-1] Sun Jun 1 17:08:45 2008
@@ -1,0 +1,69 @@
+/*
+ * PROJECT: ws2_32.dll API tests
+ * LICENSE: GPLv2 or any later version
+ * FILE: apitests/ws2_32/tests/recv.c
+ * PURPOSE: Tests for the recv function
+ * COPYRIGHT: Copyright 2008 Colin Finck <mail(a)colinfinck.de>
+ */
+
+#include "../ws2_32.h"
+
+#define RECV_BUF 4
+
+/* For valid test results, the ReactOS Website needs to return at least 8 bytes on a
"GET / HTTP/1.0" request.
+ Also the first 4 bytes and the last 4 bytes need to be different.
+ Both factors usually apply on standard HTTP responses. */
+INT
+Test_recv(PTESTINFO pti)
+{
+ const char szDummyBytes[RECV_BUF] = {0xFF, 0x00, 0xFF, 0x00};
+
+ char szBuf1[RECV_BUF];
+ char szBuf2[RECV_BUF];
+ int iResult;
+ SOCKET sck;
+ WSADATA wdata;
+
+ /* Start up Winsock */
+ TEST(WSAStartup(MAKEWORD(2, 2), &wdata) == 0);
+
+ /* If we call recv without a socket, it should return with an error and do nothing.
*/
+ memcpy(szBuf1, szDummyBytes, RECV_BUF);
+ TEST(recv(0, szBuf1, RECV_BUF, 0) == SOCKET_ERROR);
+ TEST(!memcmp(szBuf1, szDummyBytes, RECV_BUF));
+
+ /* Create the socket */
+ iResult = CreateSocket(pti, &sck);
+ if(iResult != APISTATUS_NORMAL)
+ return iResult;
+
+ /* Now we can pass at least a socket, but we have no connection yet. Should return
with an error and do nothing. */
+ memcpy(szBuf1, szDummyBytes, RECV_BUF);
+ TEST(recv(sck, szBuf1, RECV_BUF, 0) == SOCKET_ERROR);
+ TEST(!memcmp(szBuf1, szDummyBytes, RECV_BUF));
+
+ /* Connect to "www.reactos.org" */
+ iResult = ConnectToReactOSWebsite(pti, sck);
+ if(iResult != APISTATUS_NORMAL)
+ return iResult;
+
+ /* Send the GET request */
+ iResult = GetRequestAndWait(pti, sck);
+ if(iResult != APISTATUS_NORMAL)
+ return iResult;
+
+ /* Receive the data.
+ MSG_PEEK will not change the internal number of bytes read, so that a subsequent
request should return the same bytes again. */
+ SCKTEST(recv(sck, szBuf1, RECV_BUF, MSG_PEEK));
+ SCKTEST(recv(sck, szBuf2, RECV_BUF, 0));
+ TEST(!memcmp(szBuf1, szBuf2, RECV_BUF));
+
+ /* The last recv() call moved the internal file pointer, so that the next request
should return different data. */
+ SCKTEST(recv(sck, szBuf1, RECV_BUF, 0));
+ TEST(memcmp(szBuf1, szBuf2, RECV_BUF));
+
+ closesocket(sck);
+ WSACleanup();
+
+ return APISTATUS_NORMAL;
+}
Propchange: trunk/rostests/apitests/ws2_32/tests/recv.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/rostests/apitests/ws2_32/ws2_32.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ws2_32/ws2_32.c?…
==============================================================================
--- trunk/rostests/apitests/ws2_32/ws2_32.c (added)
+++ trunk/rostests/apitests/ws2_32/ws2_32.c [iso-8859-1] Sun Jun 1 17:08:45 2008
@@ -1,0 +1,24 @@
+/*
+ * PROJECT: ws2_32.dll API tests
+ * LICENSE: GPLv2 or any later version
+ * FILE: apitests/ws2_32/ws2_32.c
+ * PURPOSE: Program entry point
+ * COPYRIGHT: Copyright 2008 Colin Finck <mail(a)colinfinck.de>
+ */
+
+#include "ws2_32.h"
+
+HANDLE g_hHeap;
+
+BOOL
+IsFunctionPresent(LPWSTR lpszFunction)
+{
+ return TRUE;
+}
+
+int wmain()
+{
+ g_hHeap = GetProcessHeap();
+
+ return TestMain(L"ws2_32_apitests", L"ws2_32.dll");
+}
Propchange: trunk/rostests/apitests/ws2_32/ws2_32.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/rostests/apitests/ws2_32/ws2_32.h
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ws2_32/ws2_32.h?…
==============================================================================
--- trunk/rostests/apitests/ws2_32/ws2_32.h (added)
+++ trunk/rostests/apitests/ws2_32/ws2_32.h [iso-8859-1] Sun Jun 1 17:08:45 2008
@@ -1,0 +1,36 @@
+/*
+ * PROJECT: ws2_32.dll API tests
+ * LICENSE: GPLv2 or any later version
+ * FILE: apitests/ws2_32/ws2_32.h
+ * PURPOSE: Main header file
+ * COPYRIGHT: Copyright 2008 Colin Finck <mail(a)colinfinck.de>
+ */
+
+#ifndef _WS2_32_APITESTS_H
+#define _WS2_32_APITESTS_H
+
+#include <winsock2.h>
+
+#include "../apitest.h"
+
+/* Simple macro for executing a socket command and doing cleanup operations in case of a
failure */
+#define SCKTEST(_cmd_) \
+ iResult = _cmd_; \
+ TEST(iResult != SOCKET_ERROR); \
+ if(iResult == SOCKET_ERROR) \
+ { \
+ printf("Winsock error code is %u\n", WSAGetLastError()); \
+ closesocket(sck); \
+ WSACleanup(); \
+ return APISTATUS_ASSERTION_FAILED; \
+ }
+
+/* helpers.c */
+int CreateSocket(PTESTINFO pti, SOCKET* sck);
+int ConnectToReactOSWebsite(PTESTINFO pti, SOCKET sck);
+int GetRequestAndWait(PTESTINFO pti, SOCKET sck);
+
+/* ws2_32.c */
+extern HANDLE g_hHeap;
+
+#endif
Propchange: trunk/rostests/apitests/ws2_32/ws2_32.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/rostests/apitests/ws2_32/ws2_32.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ws2_32/ws2_32.rb…
==============================================================================
--- trunk/rostests/apitests/ws2_32/ws2_32.rbuild (added)
+++ trunk/rostests/apitests/ws2_32/ws2_32.rbuild [iso-8859-1] Sun Jun 1 17:08:45 2008
@@ -1,0 +1,11 @@
+<module name="ws2_32_apitests" type="win32cui"
unicode="yes">
+ <define name="_WIN32_WINNT">0x0501</define>
+ <library>apitest</library>
+ <library>kernel32</library>
+ <library>user32</library>
+ <library>shell32</library>
+ <library>ws2_32</library>
+ <file>helpers.c</file>
+ <file>testlist.c</file>
+ <file>ws2_32.c</file>
+</module>
Propchange: trunk/rostests/apitests/ws2_32/ws2_32.rbuild
------------------------------------------------------------------------------
svn:eol-style = native