ReactOS  0.4.14-dev-815-ge410a12
getnameinfo.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: GPLv2+ - See COPYING in the top level directory
4  * PURPOSE: Test for getaddrinfo
5  * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6  */
7 
8 #include "ws2_32.h"
9 
11 {
12  WSADATA WsaData;
13  int Error, MinSize;
14  PCHAR NodeBuffer, ServiceBuffer;
15  CHAR TestBuf[NI_MAXHOST];
16  WCHAR TestBufW[NI_MAXHOST];
17  SOCKADDR_IN LocalAddr;
18 
19  /* not yet initialized */
20  StartSeh()
21  Error = getnameinfo(NULL, 0, NULL, 0, NULL, 0, 0);
24  StartSeh()
25  NodeBuffer = InvalidPointer;
26  ServiceBuffer = InvalidPointer;
27  Error = getnameinfo(NULL, 0, NodeBuffer, 0, ServiceBuffer, 0, 0);
29  ok_ptr(NodeBuffer, InvalidPointer);
30  ok_ptr(ServiceBuffer, InvalidPointer);
32 
33  LocalAddr.sin_family = AF_INET;
34  LocalAddr.sin_port = 80;
35  LocalAddr.sin_addr.S_un.S_addr = ntohl(INADDR_LOOPBACK);
36  Error = getnameinfo((PSOCKADDR)&LocalAddr, sizeof(LocalAddr), TestBuf, sizeof(TestBuf), NULL, 0, 0);
38 
39  Error = WSAStartup(MAKEWORD(2, 2), &WsaData);
40  ok_dec(Error, 0);
41 
42  StartSeh()
43  Error = getnameinfo(NULL, 0, NULL, 0, NULL, 0, 0);
46  StartSeh()
47  NodeBuffer = InvalidPointer;
48  ServiceBuffer = InvalidPointer;
49  Error = getnameinfo(NULL, 0, NodeBuffer, 0, ServiceBuffer, 0, 0);
51  ok_ptr(NodeBuffer, InvalidPointer);
52  ok_ptr(ServiceBuffer, InvalidPointer);
54 
55  /* initialize LocalAddress for tests */
56  Error = getnameinfo((PSOCKADDR)&LocalAddr, sizeof(LocalAddr), TestBuf, sizeof(TestBuf), NULL, 0, 0);
57  ok_dec(Error, 0);
58  ok_dec(WSAGetLastError(), 0);
59 
60  /* test minimal size */
61  MinSize = sizeof(LocalAddr);
62  Error = getnameinfo((PSOCKADDR)&LocalAddr, MinSize, TestBuf, sizeof(TestBuf), NULL, 0, 0);
63  ok_dec(Error, 0);
64  ok_dec(WSAGetLastError(), 0);
65 
66  Error = GetNameInfoA((PSOCKADDR)&LocalAddr, MinSize, TestBuf, sizeof(TestBuf), NULL, 0, 0);
67  ok_dec(Error, 0);
68  ok_dec(WSAGetLastError(), 0);
69 
70  Error = GetNameInfoW((PSOCKADDR)&LocalAddr, MinSize, TestBufW, sizeof(TestBufW), NULL, 0, 0);
71  ok_dec(Error, 0);
72  ok_dec(WSAGetLastError(), 0);
73 
74  MinSize--;
75  Error = getnameinfo((PSOCKADDR)&LocalAddr, MinSize, TestBuf, sizeof(TestBuf), NULL, 0, 0);
77 
78  Error = GetNameInfoA((PSOCKADDR)&LocalAddr, MinSize, TestBuf, sizeof(TestBuf), NULL, 0, 0);
80 
81  Error = GetNameInfoW((PSOCKADDR)&LocalAddr, MinSize, TestBufW, sizeof(TestBufW), NULL, 0, 0);
83 
84  Error = WSACleanup();
85  ok_dec(Error, 0);
86 
87  /* not initialized anymore */
88  Error = getnameinfo((PSOCKADDR)&LocalAddr, sizeof(LocalAddr), NodeBuffer, 0, ServiceBuffer, 0, 0);
90 }
signed char * PCHAR
Definition: retypes.h:7
#define WSAEFAULT
Definition: winerror.h:1945
u_short sin_port
Definition: winsock.h:511
#define MAKEWORD(a, b)
Definition: typedefs.h:247
char CHAR
Definition: xmlstorage.h:175
START_TEST(getnameinfo)
Definition: getnameinfo.c:10
INT WSAAPI WSACleanup(VOID)
Definition: startup.c:60
#define ok_ptr(expression, result)
Definition: atltest.h:108
#define StartSeh()
Definition: _sntprintf.h:16
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
smooth NULL
Definition: ftsmooth.c:416
#define InvalidPointer
#define WSANOTINITIALISED
Definition: winerror.h:1987
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL Error
Definition: chkdsk.c:66
#define NI_MAXHOST
Definition: ws2def.h:359
INT WSAAPI GetNameInfoW(IN CONST SOCKADDR *pSockaddr, IN socklen_t SockaddrLength, OUT PWCHAR pNodeBuffer, IN DWORD NodeBufferSize, OUT PWCHAR pServiceBuffer, IN DWORD ServiceBufferSize, IN INT Flags)
Definition: addrinfo.c:873
struct in_addr sin_addr
Definition: winsock.h:512
#define getnameinfo
Definition: wspiapi.h:45
#define GetNameInfoA
Definition: ws2tcpip.h:392
#define AF_INET
Definition: tcpip.h:117
#define INADDR_LOOPBACK
Definition: winsock.h:312
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define ok_dec(expression, result)
Definition: atltest.h:101
short sin_family
Definition: winsock.h:510
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17
#define ntohl(x)
Definition: module.h:203