[WS2_32_APITEST] Add tests for getnameinfo. By Peter Hater. CORE-8549
[reactos.git] / rostests / apitests / ws2_32 / getnameinfo.c
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 <apitest.h>
9
10 #define WIN32_NO_STATUS
11 #define _INC_WINDOWS
12 #define COM_NO_WINDOWS_H
13 #include <stdarg.h>
14 #include <windef.h>
15 #include <winbase.h>
16 #include <ws2tcpip.h>
17 #include <ndk/umtypes.h>
18
19 START_TEST(getnameinfo)
20 {
21 WSADATA WsaData;
22 int Error, MinSize;
23 PCHAR NodeBuffer, ServiceBuffer;
24 CHAR TestBuf[NI_MAXHOST];
25 WCHAR TestBufW[NI_MAXHOST];
26 SOCKADDR_IN LocalAddr;
27
28 /* not yet initialized */
29 StartSeh()
30 Error = getnameinfo(NULL, 0, NULL, 0, NULL, 0, 0);
31 ok_dec(Error, WSANOTINITIALISED);
32 EndSeh(STATUS_SUCCESS);
33 StartSeh()
34 NodeBuffer = InvalidPointer;
35 ServiceBuffer = InvalidPointer;
36 Error = getnameinfo(NULL, 0, NodeBuffer, 0, ServiceBuffer, 0, 0);
37 ok_dec(Error, WSANOTINITIALISED);
38 ok_ptr(NodeBuffer, InvalidPointer);
39 ok_ptr(ServiceBuffer, InvalidPointer);
40 EndSeh(STATUS_SUCCESS);
41
42 LocalAddr.sin_family = AF_INET;
43 LocalAddr.sin_port = 80;
44 LocalAddr.sin_addr.S_un.S_addr = ntohl(INADDR_LOOPBACK);
45 Error = getnameinfo((PSOCKADDR)&LocalAddr, sizeof(LocalAddr), TestBuf, sizeof(TestBuf), NULL, 0, 0);
46 ok_dec(Error, WSANOTINITIALISED);
47
48 Error = WSAStartup(MAKEWORD(2, 2), &WsaData);
49 ok_dec(Error, 0);
50
51 StartSeh()
52 Error = getnameinfo(NULL, 0, NULL, 0, NULL, 0, 0);
53 ok_dec(Error, WSAEFAULT);
54 EndSeh(STATUS_SUCCESS);
55 StartSeh()
56 NodeBuffer = InvalidPointer;
57 ServiceBuffer = InvalidPointer;
58 Error = getnameinfo(NULL, 0, NodeBuffer, 0, ServiceBuffer, 0, 0);
59 ok_dec(Error, WSAEFAULT);
60 ok_ptr(NodeBuffer, InvalidPointer);
61 ok_ptr(ServiceBuffer, InvalidPointer);
62 EndSeh(STATUS_SUCCESS);
63
64 /* initialize LocalAddress for tests */
65 Error = getnameinfo((PSOCKADDR)&LocalAddr, sizeof(LocalAddr), TestBuf, sizeof(TestBuf), NULL, 0, 0);
66 ok_dec(Error, 0);
67 ok_dec(WSAGetLastError(), 0);
68
69 /* test minimal size */
70 MinSize = sizeof(LocalAddr);
71 Error = getnameinfo((PSOCKADDR)&LocalAddr, MinSize, TestBuf, sizeof(TestBuf), NULL, 0, 0);
72 ok_dec(Error, 0);
73 ok_dec(WSAGetLastError(), 0);
74
75 Error = GetNameInfoA((PSOCKADDR)&LocalAddr, MinSize, TestBuf, sizeof(TestBuf), NULL, 0, 0);
76 ok_dec(Error, 0);
77 ok_dec(WSAGetLastError(), 0);
78
79 Error = GetNameInfoW((PSOCKADDR)&LocalAddr, MinSize, TestBufW, sizeof(TestBufW), NULL, 0, 0);
80 ok_dec(Error, 0);
81 ok_dec(WSAGetLastError(), 0);
82
83 MinSize--;
84 Error = getnameinfo((PSOCKADDR)&LocalAddr, MinSize, TestBuf, sizeof(TestBuf), NULL, 0, 0);
85 ok_dec(Error, WSAEFAULT);
86
87 Error = GetNameInfoA((PSOCKADDR)&LocalAddr, MinSize, TestBuf, sizeof(TestBuf), NULL, 0, 0);
88 ok_dec(Error, WSAEFAULT);
89
90 Error = GetNameInfoW((PSOCKADDR)&LocalAddr, MinSize, TestBufW, sizeof(TestBufW), NULL, 0, 0);
91 ok_dec(Error, WSAEFAULT);
92
93 Error = WSACleanup();
94 ok_dec(Error, 0);
95
96 /* not initialized anymore */
97 Error = getnameinfo((PSOCKADDR)&LocalAddr, sizeof(LocalAddr), NodeBuffer, 0, ServiceBuffer, 0, 0);
98 ok_dec(Error, WSANOTINITIALISED);
99 }