ReactOS 0.4.16-dev-136-g52192f1
send.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS api tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for send/sendto
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6 */
7
8#include "ws2_32.h"
9
10static
13 _In_ SIZE_T SizeRequested)
14{
16 SIZE_T Size = PAGE_ROUND_UP(SizeRequested);
17 PVOID VirtualMemory = NULL;
18
20 if (!NT_SUCCESS(Status))
21 return NULL;
22
23 return VirtualMemory;
24}
25
26static
27VOID
29 _In_ PVOID VirtualMemory)
30{
32 SIZE_T Size = 0;
33
35 ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
36}
37
38static
39VOID
41{
43 int ret;
44 int error;
47 struct sockaddr_in addr;
48
49 bufferSize = 32;
51 ok(buffer != NULL, "AllocateReadOnly failed\n");
52 if (!buffer)
53 {
54 skip("No memory\n");
55 return;
56 }
57
58 ret = send(0, NULL, 0, 0);
60 ok(ret == SOCKET_ERROR, "send returned %d\n", ret);
61 ok(error == WSAENOTSOCK, "error = %d\n", error);
62
63 ret = send(0, buffer, bufferSize, 0);
65 ok(ret == SOCKET_ERROR, "send returned %d\n", ret);
66 ok(error == WSAENOTSOCK, "error = %d\n", error);
67
69 ok(sock != INVALID_SOCKET, "socket failed\n");
70 if (sock == INVALID_SOCKET)
71 {
72 skip("No socket\n");
74 return;
75 }
76
77 ret = send(sock, NULL, 0, 0);
79 ok(ret == SOCKET_ERROR, "send returned %d\n", ret);
80 ok(error == WSAENOTCONN, "error = %d\n", error);
81
84 ok(ret == SOCKET_ERROR, "send returned %d\n", ret);
85 ok(error == WSAENOTCONN, "error = %d\n", error);
86
87 memset(&addr, 0, sizeof(addr));
88 addr.sin_family = AF_INET;
89 addr.sin_addr.s_addr = inet_addr("8.8.8.8");
90 addr.sin_port = htons(53);
91 ret = connect(sock, (const struct sockaddr *)&addr, sizeof(addr));
93 ok(ret == 0, "connect returned %d\n", ret);
94 ok(error == 0, "error = %d\n", error);
95
96 ret = send(sock, NULL, 0, 0);
98 ok(ret == 0, "send returned %d\n", ret);
99 ok(error == 0, "error = %d\n", error);
100
101 ret = send(sock, buffer, bufferSize, 0);
103 ok(ret == bufferSize, "send returned %d\n", ret);
104 ok(error == 0, "error = %d\n", error);
105
107
109}
110
111static
112VOID
114{
115 SOCKET sock;
116 int ret;
117 int error;
120 struct sockaddr_in addr;
121
122 bufferSize = 32;
124 ok(buffer != NULL, "AllocateReadOnly failed\n");
125 if (!buffer)
126 {
127 skip("No memory\n");
128 return;
129 }
130
131 memset(&addr, 0, sizeof(addr));
132 addr.sin_family = AF_INET;
133 addr.sin_addr.s_addr = inet_addr("8.8.8.8");
134 addr.sin_port = htons(53);
135
136 ret = sendto(0, NULL, 0, 0, (const struct sockaddr *)&addr, sizeof(addr));
138 ok(ret == SOCKET_ERROR, "sendto returned %d\n", ret);
139 ok(error == WSAENOTSOCK, "error = %d\n", error);
140
141 ret = sendto(0, buffer, bufferSize, 0, (const struct sockaddr *)&addr, sizeof(addr));
143 ok(ret == SOCKET_ERROR, "sendto returned %d\n", ret);
144 ok(error == WSAENOTSOCK, "error = %d\n", error);
145
147 ok(sock != INVALID_SOCKET, "socket failed\n");
148 if (sock == INVALID_SOCKET)
149 {
150 skip("No socket\n");
152 return;
153 }
154
155 ret = sendto(sock, NULL, 0, 0, (const struct sockaddr *)&addr, sizeof(addr));
157 ok(ret == 0, "sendto returned %d\n", ret);
158 ok(error == 0, "error = %d\n", error);
159
160 ret = sendto(sock, buffer, bufferSize, 0, (const struct sockaddr *)&addr, sizeof(addr));
162 ok(ret == bufferSize, "sendto returned %d\n", ret);
163 ok(error == 0, "error = %d\n", error);
164
166
168}
169
171{
172 int ret;
173 WSADATA wsad;
174
175 ret = WSAStartup(MAKEWORD(2, 2), &wsad);
176 ok(ret == 0, "WSAStartup failed with %d\n", ret);
177 test_send();
178 test_sendto();
179 WSACleanup();
180}
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define PAGE_READONLY
Definition: compat.h:138
INT WSAAPI sendto(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags, IN CONST struct sockaddr *to, IN INT tolen)
Definition: send.c:82
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
Definition: send.c:23
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
#define IPPROTO_TCP
Definition: ip.h:196
#define IPPROTO_UDP
Definition: ip.h:197
#define SOCK_STREAM
Definition: tcpip.h:118
#define AF_INET
Definition: tcpip.h:117
size_t bufferSize
Status
Definition: gdiplustypes.h:25
GLuint buffer
Definition: glext.h:5915
GLenum const GLvoid * addr
Definition: glext.h:9621
#define inet_addr(cp)
Definition: inet.h:98
#define error(str)
Definition: mkdosfs.c:1605
#define htons(x)
Definition: module.h:215
static VOID test_sendto(void)
Definition: send.c:113
static PVOID AllocateReadOnly(_In_ SIZE_T SizeRequested)
Definition: send.c:12
static VOID FreeReadOnly(_In_ PVOID VirtualMemory)
Definition: send.c:28
static VOID test_send(void)
Definition: send.c:40
#define _In_
Definition: ms_sal.h:308
#define closesocket
Definition: ncftp.h:477
#define PAGE_ROUND_UP(x)
Definition: mmtypes.h:38
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define MEM_RELEASE
Definition: nt_native.h:1316
#define MEM_COMMIT
Definition: nt_native.h:1313
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
Definition: virtual.c:5230
NTSTATUS NTAPI NtAllocateVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UBaseAddress, IN ULONG_PTR ZeroBits, IN OUT PSIZE_T URegionSize, IN ULONG AllocationType, IN ULONG Protect)
Definition: virtual.c:4492
#define memset(x, y, z)
Definition: compat.h:39
#define STATUS_SUCCESS
Definition: shellext.h:65
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
Definition: tcpcore.h:1455
#define MAKEWORD(a, b)
Definition: typedefs.h:248
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG
Definition: typedefs.h:59
int ret
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
#define WSAENOTSOCK
Definition: winerror.h:1951
#define WSAENOTCONN
Definition: winerror.h:1970
int PASCAL FAR WSAGetLastError(void)
Definition: dllmain.c:112
int PASCAL FAR WSACleanup(void)
Definition: startup.c:60
#define INVALID_SOCKET
Definition: winsock.h:332
#define SOCK_DGRAM
Definition: winsock.h:336
UINT_PTR SOCKET
Definition: winsock.h:47
#define SOCKET_ERROR
Definition: winsock.h:333