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 10 START_TEST(getnameinfo) 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); 22 ok_dec(Error, WSANOTINITIALISED); 23 EndSeh(STATUS_SUCCESS); 24 StartSeh() 25 NodeBuffer = InvalidPointer; 26 ServiceBuffer = InvalidPointer; 27 Error = getnameinfo(NULL, 0, NodeBuffer, 0, ServiceBuffer, 0, 0); 28 ok_dec(Error, WSANOTINITIALISED); 29 ok_ptr(NodeBuffer, InvalidPointer); 30 ok_ptr(ServiceBuffer, InvalidPointer); 31 EndSeh(STATUS_SUCCESS); 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); 37 ok_dec(Error, WSANOTINITIALISED); 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); 44 ok_dec(Error, WSAEFAULT); 45 EndSeh(STATUS_SUCCESS); 46 StartSeh() 47 NodeBuffer = InvalidPointer; 48 ServiceBuffer = InvalidPointer; 49 Error = getnameinfo(NULL, 0, NodeBuffer, 0, ServiceBuffer, 0, 0); 50 ok_dec(Error, WSAEFAULT); 51 ok_ptr(NodeBuffer, InvalidPointer); 52 ok_ptr(ServiceBuffer, InvalidPointer); 53 EndSeh(STATUS_SUCCESS); 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); 76 ok_dec(Error, WSAEFAULT); 77 78 Error = GetNameInfoA((PSOCKADDR)&LocalAddr, MinSize, TestBuf, sizeof(TestBuf), NULL, 0, 0); 79 ok_dec(Error, WSAEFAULT); 80 81 Error = GetNameInfoW((PSOCKADDR)&LocalAddr, MinSize, TestBufW, sizeof(TestBufW), NULL, 0, 0); 82 ok_dec(Error, WSAEFAULT); 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); 89 ok_dec(Error, WSANOTINITIALISED); 90 } 91