ReactOS 0.4.16-dev-122-g325d74c
WSAStartup.c File Reference
#include "ws2_32.h"
#include <apitest_guard.h>
Include dependency graph for WSAStartup.c:

Go to the source code of this file.

Functions

static BOOLEAN CheckStringBuffer (PCSTR Buffer, SIZE_T MaximumLength, PCSTR Expected, UCHAR Fill)
 
static BOOLEAN IsWinsockInitialized (VOID)
 
static BOOLEAN AreLegacyFunctionsSupported (VOID)
 
 START_TEST (WSAStartup)
 

Function Documentation

◆ AreLegacyFunctionsSupported()

static BOOLEAN AreLegacyFunctionsSupported ( VOID  )
static

Definition at line 68 of file WSAStartup.c.

69{
70 int Error;
71
73 ok(Error == SOCKET_ERROR, "Error = %d\n", Error);
75 WSAGetLastError() == WSAEINVAL, "WSAGetLastError = %d\n", WSAGetLastError());
76
78}
#define ok(value,...)
Definition: atltest.h:57
BOOL Error
Definition: chkdsk.c:66
#define WSAEOPNOTSUPP
Definition: winerror.h:1958
#define WSAEINVAL
Definition: winerror.h:1946
int PASCAL FAR WSAGetLastError(void)
Definition: dllmain.c:112
int PASCAL FAR WSACancelBlockingCall(void)
Definition: bhook.c:23
#define SOCKET_ERROR
Definition: winsock.h:333

Referenced by START_TEST().

◆ CheckStringBuffer()

static BOOLEAN CheckStringBuffer ( PCSTR  Buffer,
SIZE_T  MaximumLength,
PCSTR  Expected,
UCHAR  Fill 
)
static

Definition at line 13 of file WSAStartup.c.

18{
20 SIZE_T EqualLength;
22 SIZE_T i;
23
24 EqualLength = RtlCompareMemory(Buffer, Expected, Length);
25 if (EqualLength != Length)
26 {
27 ok(0, "String is '%.*s', expected '%s'\n", (int)MaximumLength, Buffer, Expected);
28 Result = FALSE;
29 }
30
31 if (Buffer[Length] != ANSI_NULL)
32 {
33 ok(0, "Not null terminated\n");
34 Result = FALSE;
35 }
36
37 /* The function nulls the rest of the buffer! */
38 for (i = Length + 1; i < MaximumLength; i++)
39 {
40 UCHAR Char = ((PUCHAR)Buffer)[i];
41 if (Char != Fill)
42 {
43 ok(0, "Found 0x%x at offset %lu, expected 0x%x\n", Char, (ULONG)i, Fill);
44 /* Don't count this as a failure unless the string was actually wrong */
45 //Result = FALSE;
46 /* Don't flood the log */
47 break;
48 }
49 }
50
51 return Result;
52}
BOOLEAN Expected
unsigned char BOOLEAN
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
Definition: bufpool.h:45
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
void Fill(HDC hdc, LONG x, LONG y, COLORREF color)
Definition: drawing.cpp:107
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ANSI_NULL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
ULONG_PTR SIZE_T
Definition: typedefs.h:80
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFDMATRANSACTION _In_ size_t MaximumLength
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by START_TEST().

◆ IsWinsockInitialized()

static BOOLEAN IsWinsockInitialized ( VOID  )
static

Definition at line 56 of file WSAStartup.c.

57{
58 struct hostent *Hostent;
59
60 Hostent = gethostbyname("localhost");
61 if (!Hostent)
63 return Hostent != NULL;
64}
#define ok_dec(expression, result)
Definition: atltest.h:101
#define NULL
Definition: types.h:112
PHOSTENT WSAAPI gethostbyname(IN const char FAR *name)
Definition: getxbyxx.c:221
#define WSANOTINITIALISED
Definition: winerror.h:1987

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( WSAStartup  )

Definition at line 80 of file WSAStartup.c.

81{
82 BOOLEAN Okay;
83 LPWSADATA WsaData;
84 int Error;
85 struct
86 {
88 BOOLEAN ExpectedSuccess;
89 WORD ExpectedVersion;
90 } Tests[] =
91 {
92 { MAKEWORD(0, 0), FALSE, MAKEWORD(2, 2) },
93 { MAKEWORD(0, 9), FALSE, MAKEWORD(2, 2) },
94 { MAKEWORD(1, 0), TRUE },
95 { MAKEWORD(1, 1), TRUE },
96 { MAKEWORD(1, 2), TRUE, MAKEWORD(1, 1) },
97 { MAKEWORD(1, 15), TRUE, MAKEWORD(1, 1) },
98 { MAKEWORD(1, 255), TRUE, MAKEWORD(1, 1) },
99 { MAKEWORD(2, 0), TRUE },
100 { MAKEWORD(2, 1), TRUE },
101 { MAKEWORD(2, 2), TRUE },
102 { MAKEWORD(2, 3), TRUE, MAKEWORD(2, 2) },
103 { MAKEWORD(2, 15), TRUE, MAKEWORD(2, 2) },
104 { MAKEWORD(2, 255), TRUE, MAKEWORD(2, 2) },
105 { MAKEWORD(3, 0), TRUE, MAKEWORD(2, 2) },
106 { MAKEWORD(3, 1), TRUE, MAKEWORD(2, 2) },
107 { MAKEWORD(3, 2), TRUE, MAKEWORD(2, 2) },
108 { MAKEWORD(3, 3), TRUE, MAKEWORD(2, 2) },
109 { MAKEWORD(3, 15), TRUE, MAKEWORD(2, 2) },
110 { MAKEWORD(3, 255), TRUE, MAKEWORD(2, 2) },
111 { MAKEWORD(15, 255), TRUE, MAKEWORD(2, 2) },
112 { MAKEWORD(255, 255), TRUE, MAKEWORD(2, 2) },
113 };
114 const INT TestCount = sizeof(Tests) / sizeof(Tests[0]);
115 INT i;
116
117 ok(!IsWinsockInitialized(), "Winsock unexpectedly initialized\n");
118
119 /* parameter checks */
120 StartSeh()
121 Error = WSAStartup(0, NULL);
125 StartSeh()
126 Error = WSAStartup(MAKEWORD(2, 2), NULL);
130 ok(!IsWinsockInitialized(), "Winsock unexpectedly initialized\n");
131
132 WsaData = AllocateGuarded(sizeof(*WsaData));
133 if (!WsaData)
134 {
135 skip("Out of memory\n");
136 return;
137 }
138
139 /* test different version */
140 for (i = 0; i < TestCount; i++)
141 {
142 trace("%d: version %d.%d\n",
144 FillMemory(WsaData, sizeof(*WsaData), 0x55);
146 StartSeh()
147 Error = WSAStartup(Tests[i].Version, WsaData);
149 if (Error)
150 {
151 ok(!Tests[i].ExpectedSuccess, "WSAStartup failed unexpectedly\n");
154 ok(!IsWinsockInitialized(), "Winsock unexpectedly initialized\n");
155 }
156 else
157 {
158 ok(Tests[i].ExpectedSuccess, "WSAStartup succeeded unexpectedly\n");
160 ok(IsWinsockInitialized(), "Winsock not initialized despite success\n");
161 if (LOBYTE(Tests[i].Version) < 2)
162 ok(AreLegacyFunctionsSupported(), "Legacy function failed\n");
163 else
164 ok(!AreLegacyFunctionsSupported(), "Legacy function succeeded\n");
165 WSACleanup();
166 ok(!IsWinsockInitialized(), "Winsock still initialized after cleanup\n");
167 }
168 if (Tests[i].ExpectedVersion)
169 ok_hex(WsaData->wVersion, Tests[i].ExpectedVersion);
170 else
171 ok_hex(WsaData->wVersion, Tests[i].Version);
172 ok_hex(WsaData->wHighVersion, MAKEWORD(2, 2));
173 Okay = CheckStringBuffer(WsaData->szDescription,
174 sizeof(WsaData->szDescription),
175 "WinSock 2.0",
176 0x55);
177 ok(Okay, "CheckStringBuffer failed\n");
178 Okay = CheckStringBuffer(WsaData->szSystemStatus,
179 sizeof(WsaData->szSystemStatus),
180 "Running",
181 0x55);
182 ok(Okay, "CheckStringBuffer failed\n");
183 if (LOBYTE(WsaData->wVersion) >= 2)
184 {
185 ok_dec(WsaData->iMaxSockets, 0);
186 ok_dec(WsaData->iMaxUdpDg, 0);
187 }
188 else
189 {
190 ok_dec(WsaData->iMaxSockets, 32767);
191 ok_dec(WsaData->iMaxUdpDg, 65467);
192 }
193 ok_ptr(WsaData->lpVendorInfo, (PVOID)0x5555555555555555ULL);
194 }
195
196 /* upgrade the version */
197 FillMemory(WsaData, sizeof(*WsaData), 0x55);
198 Error = WSAStartup(MAKEWORD(1, 1), WsaData);
199 ok_dec(Error, 0);
201 ok_hex(WsaData->wVersion, MAKEWORD(1, 1));
202 ok_hex(WsaData->wHighVersion, MAKEWORD(2, 2));
203 Okay = CheckStringBuffer(WsaData->szDescription,
204 sizeof(WsaData->szDescription),
205 "WinSock 2.0",
206 0x55);
207 ok(Okay, "CheckStringBuffer failed\n");
208 Okay = CheckStringBuffer(WsaData->szSystemStatus,
209 sizeof(WsaData->szSystemStatus),
210 "Running",
211 0x55);
212 ok(Okay, "CheckStringBuffer failed\n");
213 ok_dec(WsaData->iMaxSockets, 32767);
214 ok_dec(WsaData->iMaxUdpDg, 65467);
215 ok_ptr(WsaData->lpVendorInfo, (PVOID)0x5555555555555555ULL);
216 ok(IsWinsockInitialized(), "Winsock not initialized\n");
217 if (!Error)
218 {
219 ok(AreLegacyFunctionsSupported(), "Legacy function failed\n");
220 FillMemory(WsaData, sizeof(*WsaData), 0x55);
221 Error = WSAStartup(MAKEWORD(2, 2), WsaData);
222 ok_dec(Error, 0);
223 ok_hex(WsaData->wVersion, MAKEWORD(2, 2));
224 ok_hex(WsaData->wHighVersion, MAKEWORD(2, 2));
225 Okay = CheckStringBuffer(WsaData->szDescription,
226 sizeof(WsaData->szDescription),
227 "WinSock 2.0",
228 0x55);
229 ok(Okay, "CheckStringBuffer failed\n");
230 Okay = CheckStringBuffer(WsaData->szSystemStatus,
231 sizeof(WsaData->szSystemStatus),
232 "Running",
233 0x55);
234 ok(Okay, "CheckStringBuffer failed\n");
235 ok_dec(WsaData->iMaxSockets, 0);
236 ok_dec(WsaData->iMaxUdpDg, 0);
237 ok_ptr(WsaData->lpVendorInfo, (PVOID)0x5555555555555555ULL);
238 if (!Error)
239 {
240 ok(AreLegacyFunctionsSupported(), "Legacy function failed\n");
241 WSACleanup();
242 ok(IsWinsockInitialized(), "Winsock prematurely uninitialized\n");
243 }
244 WSACleanup();
245 ok(!IsWinsockInitialized(), "Winsock still initialized after cleanup\n");
246 }
247
248 /* downgrade the version */
249 FillMemory(WsaData, sizeof(*WsaData), 0x55);
250 Error = WSAStartup(MAKEWORD(2, 2), WsaData);
251 ok_dec(Error, 0);
253 ok_hex(WsaData->wVersion, MAKEWORD(2, 2));
254 ok_hex(WsaData->wHighVersion, MAKEWORD(2, 2));
255 Okay = CheckStringBuffer(WsaData->szDescription,
256 sizeof(WsaData->szDescription),
257 "WinSock 2.0",
258 0x55);
259 ok(Okay, "CheckStringBuffer failed\n");
260 Okay = CheckStringBuffer(WsaData->szSystemStatus,
261 sizeof(WsaData->szSystemStatus),
262 "Running",
263 0x55);
264 ok(Okay, "CheckStringBuffer failed\n");
265 ok_dec(WsaData->iMaxSockets, 0);
266 ok_dec(WsaData->iMaxUdpDg, 0);
267 ok_ptr(WsaData->lpVendorInfo, (PVOID)0x5555555555555555ULL);
268 ok(IsWinsockInitialized(), "Winsock not initialized\n");
269 if (!Error)
270 {
271 ok(!AreLegacyFunctionsSupported(), "Legacy function succeeded\n");
272 FillMemory(WsaData, sizeof(*WsaData), 0x55);
273 Error = WSAStartup(MAKEWORD(1, 1), WsaData);
274 ok_dec(Error, 0);
275 ok_hex(WsaData->wVersion, MAKEWORD(1, 1));
276 ok_hex(WsaData->wHighVersion, MAKEWORD(2, 2));
277 Okay = CheckStringBuffer(WsaData->szDescription,
278 sizeof(WsaData->szDescription),
279 "WinSock 2.0",
280 0x55);
281 ok(Okay, "CheckStringBuffer failed\n");
282 Okay = CheckStringBuffer(WsaData->szSystemStatus,
283 sizeof(WsaData->szSystemStatus),
284 "Running",
285 0x55);
286 ok(Okay, "CheckStringBuffer failed\n");
287 ok_dec(WsaData->iMaxSockets, 32767);
288 ok_dec(WsaData->iMaxUdpDg, 65467);
289 ok_ptr(WsaData->lpVendorInfo, (PVOID)0x5555555555555555ULL);
290 if (!Error)
291 {
292 ok(AreLegacyFunctionsSupported(), "Legacy function failed\n");
293 WSACleanup();
294 ok(IsWinsockInitialized(), "Winsock prematurely uninitialized\n");
295 }
296 WSACleanup();
297 ok(!IsWinsockInitialized(), "Winsock still initialized after cleanup\n");
298 }
299
300 FreeGuarded(WsaData);
301}
struct test_data Tests[]
static BOOLEAN AreLegacyFunctionsSupported(VOID)
Definition: WSAStartup.c:68
static BOOLEAN IsWinsockInitialized(VOID)
Definition: WSAStartup.c:56
static BOOLEAN CheckStringBuffer(PCSTR Buffer, SIZE_T MaximumLength, PCSTR Expected, UCHAR Fill)
Definition: WSAStartup.c:13
#define StartSeh()
Definition: _sntprintf.h:16
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17
static VOID FreeGuarded(_In_ PVOID Pointer)
Definition: apitest_guard.h:45
static PVOID AllocateGuarded(_In_ SIZE_T SizeRequested)
Definition: apitest_guard.h:10
#define ok_hex(expression, result)
Definition: atltest.h:94
#define trace
Definition: atltest.h:70
#define skip(...)
Definition: atltest.h:64
#define ok_ptr(expression, result)
Definition: atltest.h:108
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
#define FillMemory(BUF, SIZ, MASK)
Definition: strucsup.c:31
unsigned short WORD
Definition: ntddk_ex.h:93
GLdouble n
Definition: glext.h:7729
#define LOBYTE(W)
Definition: jmemdos.c:487
#define HIBYTE(W)
Definition: jmemdos.c:486
if(dx< 0)
Definition: linetemp.h:194
#define STATUS_SUCCESS
Definition: shellext.h:65
static BOOL initialized
Definition: syslog.c:39
#define MAKEWORD(a, b)
Definition: typedefs.h:248
int32_t INT
Definition: typedefs.h:58
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE _In_ USHORT _In_ USHORT Version
Definition: wdffdo.h:469
#define WSAVERNOTSUPPORTED
Definition: winerror.h:1986
#define WSAEFAULT
Definition: winerror.h:1945
#define WSANO_RECOVERY
Definition: winerror.h:2002
int PASCAL FAR WSACleanup(void)
Definition: startup.c:60
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList