ReactOS  0.4.15-dev-1206-g731eddf
open_osfhandle.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: Test for open_osfhandle on WSASocket
5  * COPYRIGHT: Copyright 2018 Mark Jansen (mark.jansen@reactos.org)
6  */
7 
8 #include "ws2_32.h"
9 #include <ndk/iofuncs.h>
10 #include <ndk/obfuncs.h>
11 #include <io.h>
12 #include <fcntl.h>
13 
14 #define WINVER_WIN8 0x0602
15 
16 static void run_open_osfhandle(void)
17 {
18  DWORD type;
19  int handle, err;
21  IO_STATUS_BLOCK StatusBlock;
23 
25  ok (fd != INVALID_SOCKET, "Invalid socket\n");
26  if (fd == INVALID_SOCKET)
27  return;
28 
30  ok(type == FILE_TYPE_PIPE, "Expected type FILE_TYPE_PIPE, was: %lu\n", type);
31 
33  ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lx\n", Status);
34  if (Status == STATUS_SUCCESS)
35  {
36  RTL_OSVERSIONINFOEXW rtlinfo = { sizeof(rtlinfo), 0 };
37  ULONG Characteristics;
38  DWORD dwWinVersion;
39  ok(DeviceInfo.DeviceType == FILE_DEVICE_NAMED_PIPE, "Expected FILE_DEVICE_NAMED_PIPE, got: 0x%lx\n", DeviceInfo.DeviceType);
40 
42  dwWinVersion = (rtlinfo.dwMajorVersion << 8) | rtlinfo.dwMinorVersion;
43  Characteristics = dwWinVersion >= WINVER_WIN8 ? 0x20000 : 0;
44  ok(DeviceInfo.Characteristics == Characteristics, "Expected 0x%lx, got: 0x%lx\n", Characteristics, DeviceInfo.Characteristics);
45  }
46 
48  err = *_errno();
49 
50  ok(handle != -1, "Expected a valid handle (%i)\n", err);
51  if (handle != -1)
52  {
53  /* To close a file opened with _open_osfhandle, call _close. The underlying handle is also closed by
54  a call to _close, so it is not necessary to call the Win32 function CloseHandle on the original handle. */
55  _close(handle);
56  }
57  else
58  {
59  closesocket(fd);
60  }
61 }
62 
63 START_TEST(open_osfhandle)
64 {
65  WSADATA wdata;
66  int iResult = WSAStartup(MAKEWORD(2, 2), &wdata);
67  ok(iResult == 0, "WSAStartup failed, iResult == %d\n", iResult);
69  WSACleanup();
70 }
71 
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
NTSTATUS NTAPI RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: version.c:158
#define MAKEWORD(a, b)
Definition: typedefs.h:248
#define FILE_DEVICE_NAMED_PIPE
Definition: winioctl.h:122
LONG NTSTATUS
Definition: precomp.h:26
SOCKET WSAAPI WSASocketA(IN INT af, IN INT type, IN INT protocol, IN LPWSAPROTOCOL_INFOA lpProtocolInfo, IN GROUP g, IN DWORD dwFlags)
Definition: socklife.c:444
#define closesocket
Definition: precomp.h:57
INT WSAAPI WSACleanup(VOID)
Definition: startup.c:60
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
static int fd
Definition: io.c:51
DWORD WINAPI GetFileType(HANDLE hFile)
Definition: fileinfo.c:269
#define _O_RDWR
Definition: cabinet.h:39
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
smooth NULL
Definition: ftsmooth.c:416
_Check_return_opt_ _CRTIMP int __cdecl _close(_In_ int _FileHandle)
ULONG dwMajorVersion
Definition: rtltypes.h:247
#define INVALID_SOCKET
Definition: winsock.h:332
struct _DeviceInfo DeviceInfo
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WINVER_WIN8
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
#define _O_BINARY
Definition: cabinet.h:51
Status
Definition: gdiplustypes.h:24
#define err(...)
START_TEST(open_osfhandle)
NTSTATUS NTAPI NtQueryVolumeInformationFile(HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FsInformation, ULONG Length, FS_INFORMATION_CLASS FsInformationClass)
#define FILE_TYPE_PIPE
Definition: winbase.h:258
#define ok(value,...)
Definition: atltest.h:57
ULONG dwMinorVersion
Definition: rtltypes.h:248
unsigned int ULONG
Definition: retypes.h:1
#define AF_INET
Definition: tcpip.h:117
UINT_PTR SOCKET
Definition: winsock.h:47
_CRTIMP int __cdecl _open_osfhandle(_In_ intptr_t _OSFileHandle, _In_ int _Flags)
#define SOCK_STREAM
Definition: tcpip.h:118
return STATUS_SUCCESS
Definition: btrfs.c:3014
static void run_open_osfhandle(void)