https://git.reactos.org/?p=reactos.git;a=commitdiff;h=3bf53491725d081ef38566...
commit 3bf53491725d081ef385660c00fb327dcef1492d Author: Mark Jansen mark.jansen@reactos.org AuthorDate: Mon Mar 19 22:34:45 2018 +0100 Commit: Mark Jansen mark.jansen@reactos.org CommitDate: Mon Mar 19 22:35:21 2018 +0100
[WS2_32_APITEST] Add a test showing that GetFileType / _open_osfhandle should succeed. CORE-13067 --- modules/rostests/apitests/ws2_32/CMakeLists.txt | 1 + modules/rostests/apitests/ws2_32/open_osfhandle.c | 49 +++++++++++++++++++++++ modules/rostests/apitests/ws2_32/testlist.c | 2 + 3 files changed, 52 insertions(+)
diff --git a/modules/rostests/apitests/ws2_32/CMakeLists.txt b/modules/rostests/apitests/ws2_32/CMakeLists.txt index cd63545a38..cae491a2fb 100644 --- a/modules/rostests/apitests/ws2_32/CMakeLists.txt +++ b/modules/rostests/apitests/ws2_32/CMakeLists.txt @@ -10,6 +10,7 @@ list(APPEND SOURCE ioctlsocket.c nonblocking.c nostartup.c + open_osfhandle.c recv.c send.c WSAAsync.c diff --git a/modules/rostests/apitests/ws2_32/open_osfhandle.c b/modules/rostests/apitests/ws2_32/open_osfhandle.c new file mode 100644 index 0000000000..821b4f3fe7 --- /dev/null +++ b/modules/rostests/apitests/ws2_32/open_osfhandle.c @@ -0,0 +1,49 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) + * PURPOSE: Test for open_osfhandle on WSASocket + * COPYRIGHT: Copyright 2018 Mark Jansen (mark.jansen@reactos.org) + */ + +#include "ws2_32.h" +#include <io.h> +#include <fcntl.h> + + +static void run_open_osfhandle(void) +{ + DWORD type; + int handle, err; + SOCKET fd = WSASocketA(AF_INET, SOCK_STREAM, 0, NULL, 0, 0); + ok (fd != INVALID_SOCKET, "Invalid socket\n"); + if (fd == INVALID_SOCKET) + return; + + type = GetFileType((HANDLE)fd); + ok(type == FILE_TYPE_PIPE, "Expected type FILE_TYPE_PIPE, was: %lu\n", type); + + handle = _open_osfhandle(fd, _O_BINARY | _O_RDWR); + err = *_errno(); + + ok(handle != -1, "Expected a valid handle (%i)\n", err); + if (handle != -1) + { + /* To close a file opened with _open_osfhandle, call _close. The underlying handle is also closed by + a call to _close, so it is not necessary to call the Win32 function CloseHandle on the original handle. */ + _close(handle); + } + else + { + closesocket(fd); + } +} + +START_TEST(open_osfhandle) +{ + WSADATA wdata; + int iResult = WSAStartup(MAKEWORD(2, 2), &wdata); + ok(iResult == 0, "WSAStartup failed, iResult == %d\n", iResult); + run_open_osfhandle(); + WSACleanup(); +} + diff --git a/modules/rostests/apitests/ws2_32/testlist.c b/modules/rostests/apitests/ws2_32/testlist.c index a8e6f2f7c6..8e33e8daa3 100644 --- a/modules/rostests/apitests/ws2_32/testlist.c +++ b/modules/rostests/apitests/ws2_32/testlist.c @@ -12,6 +12,7 @@ extern void func_getservbyport(void); extern void func_ioctlsocket(void); extern void func_nonblocking(void); extern void func_nostartup(void); +extern void func_open_osfhandle(void); extern void func_recv(void); extern void func_send(void); extern void func_WSAAsync(void); @@ -30,6 +31,7 @@ const struct test winetest_testlist[] = { "ioctlsocket", func_ioctlsocket }, { "nonblocking", func_nonblocking }, { "nostartup", func_nostartup }, + { "open_osfhandle", func_open_osfhandle }, { "recv", func_recv }, { "send", func_send }, { "WSAAsync", func_WSAAsync },