Author: tkreuzer Date: Wed Aug 25 08:48:55 2010 New Revision: 48619
URL: http://svn.reactos.org/svn/reactos?rev=48619&view=rev Log: [APITESTS] Convert dciman32api, user32api and wa2_32 into wine style tests
Added: trunk/rostests/apitests/ws2_32/ioctlsocket.c (with props) trunk/rostests/apitests/ws2_32/recv.c (with props) trunk/rostests/apitests/ws2_32/ws2_32_apitest.rbuild (with props) Removed: trunk/rostests/apitests/dciman32api/ trunk/rostests/apitests/user32api/ trunk/rostests/apitests/ws2_32/tests/ trunk/rostests/apitests/ws2_32/ws2_32.c trunk/rostests/apitests/ws2_32/ws2_32.rbuild Modified: trunk/rostests/apitests/directory.rbuild trunk/rostests/apitests/ws2_32/helpers.c trunk/rostests/apitests/ws2_32/testlist.c trunk/rostests/apitests/ws2_32/ws2_32.h
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] Wed Aug 25 08:48:55 2010 @@ -6,16 +6,16 @@ <file>apitest.c</file> </module>
- <directory name="dciman32api"> - <xi:include href="dciman32api/dciman32api.rbuild" /> + <directory name="dciman32"> + <xi:include href="dciman32/dciman32_apitest.rbuild" /> </directory>
<directory name="gdi32"> <xi:include href="gdi32/gdi32_apitest.rbuild" /> </directory>
- <directory name="user32api"> - <xi:include href="user32api/user32api.rbuild" /> + <directory name="user32"> + <xi:include href="user32/user32_apitest.rbuild" /> </directory>
<if property="ARCH" value="i386"> @@ -29,6 +29,6 @@ </if>
<directory name="ws2_32"> - <xi:include href="ws2_32/ws2_32.rbuild" /> + <xi:include href="ws2_32/ws2_32_apitest.rbuild" /> </directory> </group>
Modified: 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 [iso-8859-1] (original) +++ trunk/rostests/apitests/ws2_32/helpers.c [iso-8859-1] Wed Aug 25 08:48:55 2010 @@ -6,25 +6,27 @@ * COPYRIGHT: Copyright 2008 Colin Finck mail@colinfinck.de */
+#include <stdio.h> +#include <wine/test.h> #include "ws2_32.h"
-int CreateSocket(PTESTINFO pti, SOCKET* psck) +int CreateSocket(SOCKET* psck) { /* Create the socket */ *psck = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - TEST(*psck != INVALID_SOCKET); + ok(*psck != INVALID_SOCKET, "*psck = %d\n", *psck);
if(*psck == INVALID_SOCKET) { printf("Winsock error code is %u\n", WSAGetLastError()); WSACleanup(); - return APISTATUS_ASSERTION_FAILED; + return 0; }
- return APISTATUS_NORMAL; + return 1; }
-int ConnectToReactOSWebsite(PTESTINFO pti, SOCKET sck) +int ConnectToReactOSWebsite(SOCKET sck) { int iResult; struct hostent* host; @@ -38,11 +40,11 @@ sa.sin_port = htons(80);
SCKTEST(connect(sck, (struct sockaddr *)&sa, sizeof(sa))); - - return APISTATUS_NORMAL; + + return 1; }
-int GetRequestAndWait(PTESTINFO pti, SOCKET sck) +int GetRequestAndWait(SOCKET sck) { const char szGetRequest[] = "GET / HTTP/1.0\r\n\r\n"; int iResult; @@ -50,7 +52,7 @@
/* Send the GET request */ SCKTEST(send(sck, szGetRequest, strlen(szGetRequest), 0)); - TEST(iResult == strlen(szGetRequest)); + ok(iResult == strlen(szGetRequest), "iResult = %d\n", iResult);
/* Shutdown the SEND connection */ SCKTEST(shutdown(sck, SD_SEND)); @@ -60,6 +62,6 @@ FD_SET(sck, &readable);
SCKTEST(select(0, &readable, NULL, NULL, NULL)); - - return APISTATUS_NORMAL; + + return 1; }
Added: trunk/rostests/apitests/ws2_32/ioctlsocket.c URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ws2_32/ioctlsocke... ============================================================================== --- trunk/rostests/apitests/ws2_32/ioctlsocket.c (added) +++ trunk/rostests/apitests/ws2_32/ioctlsocket.c [iso-8859-1] Wed Aug 25 08:48:55 2010 @@ -1,0 +1,98 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GPL - See COPYING in the top level directory + * PURPOSE: Test for ioctlsocket + * PROGRAMMERS: Colin Finck + */ + +#include <stdio.h> +#include <wine/test.h> +#include <windows.h> +#include "ws2_32.h" + +int Test_ioctlsocket() +{ + LPSTR pszBuf; + int iResult; + SOCKET sck; + ULONG BytesAvailable; + ULONG BytesToRead; + WSADATA wdata; + + /* Start up Winsock */ + iResult = WSAStartup(MAKEWORD(2, 2), &wdata); + ok(iResult == 0, "WSAStartup failed. iResult = %d\n", iResult); + + /* If we call ioctlsocket without a socket, it should return with an error and do nothing. */ + BytesAvailable = 0xdeadbeef; + iResult = ioctlsocket(0, FIONREAD, &BytesAvailable); + ok(iResult == SOCKET_ERROR, "iResult = %d\n", iResult); + ok(BytesAvailable == 0xdeadbeef, "BytesAvailable = %ld\n", BytesAvailable); + + /* Create the socket */ + if (!CreateSocket(&sck)) + { + ok(0, "CreateSocket failed. Aborting test.\n"); + return 0; + } + + /* Now we can pass at least a socket, but we have no connection yet. The function should return 0. */ + BytesAvailable = 0xdeadbeef; + iResult = ioctlsocket(sck, FIONREAD, &BytesAvailable); + ok(iResult == 0, "iResult = %d\n", iResult); + ok(BytesAvailable == 0, "BytesAvailable = %ld\n", BytesAvailable); + + /* Connect to "www.reactos.org" */ + if (!ConnectToReactOSWebsite(sck)) + { + ok(0, "ConnectToReactOSWebsite failed. Aborting test.\n"); + return 0; + } + + /* Even with a connection, there shouldn't be any bytes available. */ + iResult = ioctlsocket(sck, FIONREAD, &BytesAvailable); + ok(iResult == 0, "iResult = %d\n", iResult); + ok(BytesAvailable == 0, "BytesAvailable = %ld\n", BytesAvailable); + + /* Send the GET request */ + if (!GetRequestAndWait(sck)) + { + ok(0, "GetRequestAndWait failed. Aborting test.\n"); + return 0; + } + + /* Try ioctlsocket with FIONREAD. There should be bytes available now. */ + SCKTEST(ioctlsocket(sck, FIONREAD, &BytesAvailable)); + ok(BytesAvailable != 0, "BytesAvailable = %ld\n", BytesAvailable); + + /* Get half of the data */ + BytesToRead = BytesAvailable / 2; + pszBuf = (LPSTR) HeapAlloc(GetProcessHeap(), 0, BytesToRead); + SCKTEST(recv(sck, pszBuf, BytesToRead, 0)); + HeapFree(GetProcessHeap(), 0, pszBuf); + + BytesToRead = BytesAvailable - BytesToRead; + + /* Now try ioctlsocket again. BytesAvailable should be at the value saved in BytesToRead now. */ + SCKTEST(ioctlsocket(sck, FIONREAD, &BytesAvailable)); + ok(BytesAvailable == BytesToRead, "BytesAvailable = %ld\n", BytesAvailable); + + /* Read those bytes */ + pszBuf = (LPSTR) HeapAlloc(GetProcessHeap(), 0, BytesToRead); + SCKTEST(recv(sck, pszBuf, BytesToRead, 0)); + HeapFree(GetProcessHeap(), 0, pszBuf); + + /* Try it for the last time. BytesAvailable should be at 0 now. */ + SCKTEST(ioctlsocket(sck, FIONREAD, &BytesAvailable)); + ok(BytesAvailable == 0, "BytesAvailable = %ld\n", BytesAvailable); + + closesocket(sck); + WSACleanup(); + return 1; +} + +START_TEST(ioctlsocket) +{ + Test_ioctlsocket(); +} +
Propchange: trunk/rostests/apitests/ws2_32/ioctlsocket.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/rostests/apitests/ws2_32/recv.c URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ws2_32/recv.c?rev... ============================================================================== --- trunk/rostests/apitests/ws2_32/recv.c (added) +++ trunk/rostests/apitests/ws2_32/recv.c [iso-8859-1] Wed Aug 25 08:48:55 2010 @@ -1,0 +1,85 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GPL - See COPYING in the top level directory + * PURPOSE: Test for recv + * PROGRAMMERS: Colin Finck + */ + +#include <stdio.h> +#include <wine/test.h> +#include <windows.h> +#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() +{ + 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 */ + iResult = WSAStartup(MAKEWORD(2, 2), &wdata); + ok(iResult == 0, "WSAStartup failed, iResult == %d\n", iResult); + + /* If we call recv without a socket, it should return with an error and do nothing. */ + memcpy(szBuf1, szDummyBytes, RECV_BUF); + iResult = recv(0, szBuf1, RECV_BUF, 0); + ok(iResult == SOCKET_ERROR, "iRseult = %d\n", iResult); + ok(!memcmp(szBuf1, szDummyBytes, RECV_BUF), "not equal\n"); + + /* Create the socket */ + if (!CreateSocket(&sck)) + { + ok(0, "CreateSocket failed. Aborting test.\n"); + return 0; + } + + /* 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); + iResult = recv(sck, szBuf1, RECV_BUF, 0); + ok(iResult == SOCKET_ERROR, "iResult = %d\n", iResult); + ok(!memcmp(szBuf1, szDummyBytes, RECV_BUF), "not equal\n"); + + /* Connect to "www.reactos.org" */ + if (!ConnectToReactOSWebsite(sck)) + { + ok(0, "ConnectToReactOSWebsite failed. Aborting test.\n"); + return 0; + } + + /* Send the GET request */ + if (!GetRequestAndWait(sck)) + { + ok(0, "GetRequestAndWait failed. Aborting test.\n"); + return 0; + } + + /* 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)); + ok(!memcmp(szBuf1, szBuf2, RECV_BUF), "not equal\n"); + + /* 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)); + ok(memcmp(szBuf1, szBuf2, RECV_BUF), "equal\n"); + + closesocket(sck); + WSACleanup(); + return 1; +} + +START_TEST(recv) +{ + Test_recv(); +} +
Propchange: trunk/rostests/apitests/ws2_32/recv.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.c... ============================================================================== --- trunk/rostests/apitests/ws2_32/testlist.c [iso-8859-1] (original) +++ trunk/rostests/apitests/ws2_32/testlist.c [iso-8859-1] Wed Aug 25 08:48:55 2010 @@ -1,33 +1,18 @@ -/* - * 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@colinfinck.de - */ +#define WIN32_LEAN_AND_MEAN +#define __ROS_LONG64__ +#include <windows.h>
-#ifndef _WS2_32_TESTLIST_H -#define _WS2_32_TESTLIST_H +#define STANDALONE +#include "wine/test.h"
-#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) +extern void func_ioctlsocket(void); +extern void func_recv(void);
-#include "ws2_32.h" +const struct test winetest_testlist[] = +{ + { "ioctlsocket", func_ioctlsocket }, + { "recv", func_recv },
-/* 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 } + { 0, 0 } };
-/* The function that gives us the number of tests */ -INT NumTests(void) -{ - return ARRAY_SIZE(TestList); -} - -#endif
Removed: trunk/rostests/apitests/ws2_32/ws2_32.c URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ws2_32/ws2_32.c?r... ============================================================================== --- trunk/rostests/apitests/ws2_32/ws2_32.c [iso-8859-1] (original) +++ trunk/rostests/apitests/ws2_32/ws2_32.c (removed) @@ -1,24 +1,0 @@ -/* - * 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@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"); -}
Modified: trunk/rostests/apitests/ws2_32/ws2_32.h URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ws2_32/ws2_32.h?r... ============================================================================== --- trunk/rostests/apitests/ws2_32/ws2_32.h [iso-8859-1] (original) +++ trunk/rostests/apitests/ws2_32/ws2_32.h [iso-8859-1] Wed Aug 25 08:48:55 2010 @@ -11,24 +11,22 @@
#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); \ + ok(iResult != SOCKET_ERROR, "iResult = %d\n", iResult); \ if(iResult == SOCKET_ERROR) \ { \ printf("Winsock error code is %u\n", WSAGetLastError()); \ closesocket(sck); \ WSACleanup(); \ - return APISTATUS_ASSERTION_FAILED; \ + return 0; \ }
/* helpers.c */ -int CreateSocket(PTESTINFO pti, SOCKET* sck); -int ConnectToReactOSWebsite(PTESTINFO pti, SOCKET sck); -int GetRequestAndWait(PTESTINFO pti, SOCKET sck); +int CreateSocket(SOCKET* sck); +int ConnectToReactOSWebsite(SOCKET sck); +int GetRequestAndWait(SOCKET sck);
/* ws2_32.c */ extern HANDLE g_hHeap;
Removed: trunk/rostests/apitests/ws2_32/ws2_32.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ws2_32/ws2_32.rbu... ============================================================================== --- trunk/rostests/apitests/ws2_32/ws2_32.rbuild [iso-8859-1] (original) +++ trunk/rostests/apitests/ws2_32/ws2_32.rbuild (removed) @@ -1,9 +1,0 @@ -<module name="ws2_32_apitests" type="win32cui" unicode="yes"> - <library>apitest</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>
Added: trunk/rostests/apitests/ws2_32/ws2_32_apitest.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ws2_32/ws2_32_api... ============================================================================== --- trunk/rostests/apitests/ws2_32/ws2_32_apitest.rbuild (added) +++ trunk/rostests/apitests/ws2_32/ws2_32_apitest.rbuild [iso-8859-1] Wed Aug 25 08:48:55 2010 @@ -1,0 +1,18 @@ +<?xml version="1.0"?> +<!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd"> +<group> +<module name="ws2_32_apitest" type="win32cui" installbase="bin" installname="ws2_32_apitest.exe"> + <include base="ws2_32_apitest">.</include> + <library>wine</library> + <library>gdi32</library> + <library>user32</library> + <library>pseh</library> + <library>ws2_32</library> + <file>testlist.c</file> + <file>helpers.c</file> + + <file>ioctlsocket.c</file> + <file>recv.c</file> + +</module> +</group>
Propchange: trunk/rostests/apitests/ws2_32/ws2_32_apitest.rbuild ------------------------------------------------------------------------------ svn:eol-style = native