Jeff Latimer : ws2_32/tests: Add tests for Inet_Ntop and inet_ntoa.

Alexandre Julliard julliard at winehq.org
Mon Apr 27 08:04:10 CDT 2009


Module: wine
Branch: master
Commit: 0cdd0d80eef747f7400568f6a16e89292bbaa531
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=0cdd0d80eef747f7400568f6a16e89292bbaa531

Author: Jeff Latimer <lats at yless4u.com.au>
Date:   Sat Apr 25 00:30:06 2009 +1000

ws2_32/tests: Add tests for Inet_Ntop and inet_ntoa.

---

 dlls/ws2_32/tests/sock.c |   65 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index dbd43d8..7bc3ee8 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -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();




More information about the wine-cvs mailing list