[WS2_32_APITEST] Add tests for getnameinfo. By Peter Hater. CORE-8549

svn path=/trunk/; revision=72908
This commit is contained in:
Amine Khaldi 2016-10-05 09:33:03 +00:00
parent 9c1da77024
commit c3b215936d
3 changed files with 102 additions and 0 deletions

View file

@ -1,6 +1,7 @@
list(APPEND SOURCE
getaddrinfo.c
getnameinfo.c
getservbyname.c
getservbyport.c
helpers.c

View file

@ -0,0 +1,99 @@
/*
* PROJECT: ReactOS api tests
* LICENSE: GPLv2+ - See COPYING in the top level directory
* PURPOSE: Test for getaddrinfo
* PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
*/
#include <apitest.h>
#define WIN32_NO_STATUS
#define _INC_WINDOWS
#define COM_NO_WINDOWS_H
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <ws2tcpip.h>
#include <ndk/umtypes.h>
START_TEST(getnameinfo)
{
WSADATA WsaData;
int Error, MinSize;
PCHAR NodeBuffer, ServiceBuffer;
CHAR TestBuf[NI_MAXHOST];
WCHAR TestBufW[NI_MAXHOST];
SOCKADDR_IN LocalAddr;
/* not yet initialized */
StartSeh()
Error = getnameinfo(NULL, 0, NULL, 0, NULL, 0, 0);
ok_dec(Error, WSANOTINITIALISED);
EndSeh(STATUS_SUCCESS);
StartSeh()
NodeBuffer = InvalidPointer;
ServiceBuffer = InvalidPointer;
Error = getnameinfo(NULL, 0, NodeBuffer, 0, ServiceBuffer, 0, 0);
ok_dec(Error, WSANOTINITIALISED);
ok_ptr(NodeBuffer, InvalidPointer);
ok_ptr(ServiceBuffer, InvalidPointer);
EndSeh(STATUS_SUCCESS);
LocalAddr.sin_family = AF_INET;
LocalAddr.sin_port = 80;
LocalAddr.sin_addr.S_un.S_addr = ntohl(INADDR_LOOPBACK);
Error = getnameinfo((PSOCKADDR)&LocalAddr, sizeof(LocalAddr), TestBuf, sizeof(TestBuf), NULL, 0, 0);
ok_dec(Error, WSANOTINITIALISED);
Error = WSAStartup(MAKEWORD(2, 2), &WsaData);
ok_dec(Error, 0);
StartSeh()
Error = getnameinfo(NULL, 0, NULL, 0, NULL, 0, 0);
ok_dec(Error, WSAEFAULT);
EndSeh(STATUS_SUCCESS);
StartSeh()
NodeBuffer = InvalidPointer;
ServiceBuffer = InvalidPointer;
Error = getnameinfo(NULL, 0, NodeBuffer, 0, ServiceBuffer, 0, 0);
ok_dec(Error, WSAEFAULT);
ok_ptr(NodeBuffer, InvalidPointer);
ok_ptr(ServiceBuffer, InvalidPointer);
EndSeh(STATUS_SUCCESS);
/* initialize LocalAddress for tests */
Error = getnameinfo((PSOCKADDR)&LocalAddr, sizeof(LocalAddr), TestBuf, sizeof(TestBuf), NULL, 0, 0);
ok_dec(Error, 0);
ok_dec(WSAGetLastError(), 0);
/* test minimal size */
MinSize = sizeof(LocalAddr);
Error = getnameinfo((PSOCKADDR)&LocalAddr, MinSize, TestBuf, sizeof(TestBuf), NULL, 0, 0);
ok_dec(Error, 0);
ok_dec(WSAGetLastError(), 0);
Error = GetNameInfoA((PSOCKADDR)&LocalAddr, MinSize, TestBuf, sizeof(TestBuf), NULL, 0, 0);
ok_dec(Error, 0);
ok_dec(WSAGetLastError(), 0);
Error = GetNameInfoW((PSOCKADDR)&LocalAddr, MinSize, TestBufW, sizeof(TestBufW), NULL, 0, 0);
ok_dec(Error, 0);
ok_dec(WSAGetLastError(), 0);
MinSize--;
Error = getnameinfo((PSOCKADDR)&LocalAddr, MinSize, TestBuf, sizeof(TestBuf), NULL, 0, 0);
ok_dec(Error, WSAEFAULT);
Error = GetNameInfoA((PSOCKADDR)&LocalAddr, MinSize, TestBuf, sizeof(TestBuf), NULL, 0, 0);
ok_dec(Error, WSAEFAULT);
Error = GetNameInfoW((PSOCKADDR)&LocalAddr, MinSize, TestBufW, sizeof(TestBufW), NULL, 0, 0);
ok_dec(Error, WSAEFAULT);
Error = WSACleanup();
ok_dec(Error, 0);
/* not initialized anymore */
Error = getnameinfo((PSOCKADDR)&LocalAddr, sizeof(LocalAddr), NodeBuffer, 0, ServiceBuffer, 0, 0);
ok_dec(Error, WSANOTINITIALISED);
}

View file

@ -4,6 +4,7 @@
#include <apitest.h>
extern void func_getaddrinfo(void);
extern void func_getnameinfo(void);
extern void func_getservbyname(void);
extern void func_getservbyport(void);
extern void func_ioctlsocket(void);
@ -15,6 +16,7 @@ extern void func_nostartup(void);
const struct test winetest_testlist[] =
{
{ "getaddrinfo", func_getaddrinfo },
{ "getnameinfo", func_getnameinfo },
{ "getservbyname", func_getservbyname },
{ "getservbyport", func_getservbyport },
{ "ioctlsocket", func_ioctlsocket },