ReactOS 0.4.15-dev-7942-gd23573b
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
16static 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);
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. */
56 }
57 else
58 {
60 }
61}
62
63START_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
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
NTSTATUS NTAPI RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: version.c:158
#define _O_RDWR
Definition: cabinet.h:39
#define _O_BINARY
Definition: cabinet.h:51
DWORD WINAPI GetFileType(HANDLE hFile)
Definition: fileinfo.c:269
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
#define SOCK_STREAM
Definition: tcpip.h:118
#define AF_INET
Definition: tcpip.h:117
unsigned long DWORD
Definition: ntddk_ex.h:95
@ FileFsDeviceInformation
Definition: from_kernel.h:222
Status
Definition: gdiplustypes.h:25
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define closesocket
Definition: ncftp.h:477
static void run_open_osfhandle(void)
#define WINVER_WIN8
#define FILE_DEVICE_NAMED_PIPE
Definition: winioctl.h:123
#define err(...)
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
_Check_return_opt_ _CRTIMP int __cdecl _close(_In_ int _FileHandle)
_CRTIMP int __cdecl _open_osfhandle(_In_ intptr_t _OSFileHandle, _In_ int _Flags)
static int fd
Definition: io.c:51
NTSTATUS NTAPI NtQueryVolumeInformationFile(HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FsInformation, ULONG Length, FS_INFORMATION_CLASS FsInformationClass)
#define STATUS_SUCCESS
Definition: shellext.h:65
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
ULONG dwMajorVersion
Definition: rtltypes.h:270
ULONG dwMinorVersion
Definition: rtltypes.h:271
#define MAKEWORD(a, b)
Definition: typedefs.h:248
uint32_t ULONG
Definition: typedefs.h:59
#define FILE_TYPE_PIPE
Definition: winbase.h:261
int PASCAL FAR WSACleanup(void)
Definition: startup.c:60
#define INVALID_SOCKET
Definition: winsock.h:332
UINT_PTR SOCKET
Definition: winsock.h:47