ws2_32/tests: Add tests for Inet_Ntop and inet_ntoa.

This commit is contained in:
Jeff Latimer 2009-04-25 00:30:06 +10:00 committed by Alexandre Julliard
parent 82744c93e0
commit 0cdd0d80ee

View file

@ -55,6 +55,9 @@
ok ( cond tmp, msg, GetCurrentThreadId(), err); \
} while (0);
/* Function pointers */
static HMODULE hws2_32 = 0;
static PCSTR (WINAPI *pInetNtop)(INT,LPVOID,LPSTR,ULONG) = 0;
/**************** Structs and typedefs ***************/
@ -1996,6 +1999,67 @@ static void test_inet_addr(void)
ok(addr == INADDR_NONE, "inet_addr succeeded unexpectedly\n");
}
static void test_addr_to_print(void)
{
char dst[16];
char dst6[64];
const char * pdst;
struct in_addr in;
struct in6_addr in6;
u_long addr0_Num = 0x00000000;
PCSTR addr0_Str = "0.0.0.0";
u_long addr1_Num = 0x20201015;
PCSTR addr1_Str = "21.16.32.32";
u_char addr2_Num[16] = {0,0,0,0,0,0,0,0,0,0,0xff,0xfe,0xcC,0x98,0xbd,0x74};
PCSTR addr2_Str = "::fffe:cc98:bd74";
u_char addr3_Num[16] = {0x20,0x30,0xa4,0xb1};
PCSTR addr3_Str = "2030:a4b1::";
hws2_32 = GetModuleHandle("ws2_32.dll");
pInetNtop = (void *)GetProcAddress(hws2_32, "inet_ntop");
in.s_addr = addr0_Num;
pdst = inet_ntoa(*((struct in_addr*)&in.s_addr));
ok(pdst != NULL, "inet_ntoa failed %s\n", dst);
ok(!strcmp(pdst, addr0_Str),"Address %s != %s\n", pdst, addr0_Str);
/* Test that inet_ntoa and inet_ntop return the same value */
in.S_un.S_addr = addr1_Num;
pdst = inet_ntoa(*((struct in_addr*)&in.s_addr));
ok(pdst != NULL, "inet_ntoa failed %s\n", dst);
ok(!strcmp(pdst, addr1_Str),"Address %s != %s\n", pdst, addr1_Str);
/* InetNtop became available in Vista and Win2008 */
if (!pInetNtop)
{
win_skip("InetNtop not present, not executing tests\n");
return;
}
pdst = pInetNtop(AF_INET,(void*)&in.s_addr, dst, sizeof(dst));
ok(pdst != NULL, "InetNtop failed %s\n", dst);
todo_wine ok(!strcmp(pdst, addr1_Str),"Address %s != %s\n", pdst, addr1_Str);
/* Test invalid parm conditions */
pdst = pInetNtop(1, (void*)&in.s_addr, dst, sizeof(dst));
ok(pdst == NULL, "The pointer should not be returned (%p)\n", pdst);
ok(WSAGetLastError() == WSAEAFNOSUPPORT, "Should be WSAEAFNOSUPPORT\n");
/* Test an zero prefixed IPV6 address */
memcpy(in6.u.Byte, addr2_Num, sizeof(addr2_Num));
pdst = pInetNtop(AF_INET6,(void*)&in6.s6_addr, dst6, sizeof(dst6));
ok(pdst != NULL, "InetNtop failed %s\n", dst6);
todo_wine ok(!strcmp(pdst, addr2_Str),"Address %s != %s\n", pdst, addr2_Str);
/* Test an zero suffixed IPV6 address */
memcpy(in6.s6_addr, addr3_Num, sizeof(addr3_Num));
pdst = pInetNtop(AF_INET6,(void*)&in6.s6_addr, dst6, sizeof(dst6));
ok(pdst != NULL, "InetNtop failed %s\n", dst6);
todo_wine ok(!strcmp(pdst, addr3_Str),"Address %s != %s\n", pdst, addr3_Str);
}
static void test_ioctlsocket(void)
{
SOCKET sock;
@ -2369,6 +2433,7 @@ START_TEST( sock )
test_accept();
test_getsockname();
test_inet_addr();
test_addr_to_print();
test_ioctlsocket();
test_dns();
test_gethostbyname_hack();