ntdll/tests: Add tests for RtlIpv[4/6]StringToAddress[Ex]

Mark Jansen learn0more+wine at gmail.com
Fri Feb 13 13:32:20 CST 2015


This patch adds tests for:
RtlIpv4StringToAddressExA, RtlIpv6StringToAddressA,
RtlIpv6StringToAddressExA

Tested on all vm's.

---
 dlls/ntdll/tests/rtl.c | 401
+++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 401 insertions(+)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20150213/e1bd2a70/attachment-0001.html>
-------------- next part --------------
From 20281b0b58f2e29add27d40dcaa8d9d830ed987f Mon Sep 17 00:00:00 2001
From: learn_more <learn0more+wine at gmail.com>
Date: Fri, 13 Feb 2015 12:27:49 +0100
Subject: Add tests for RtlIpv4StringToAddressExA, RtlIpv6StringToAddressA,
 RtlIpv6StringToAddressExA

---
 dlls/ntdll/tests/rtl.c | 401 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 401 insertions(+)

diff --git a/dlls/ntdll/tests/rtl.c b/dlls/ntdll/tests/rtl.c
index e8eb04a..09937ba 100644
--- a/dlls/ntdll/tests/rtl.c
+++ b/dlls/ntdll/tests/rtl.c
@@ -25,6 +25,7 @@
 
 #include "ntdll_test.h"
 #include "inaddr.h"
+#include "in6addr.h"
 
 #ifndef __WINE_WINTERNL_H
 
@@ -89,6 +90,9 @@ static IMAGE_BASE_RELOCATION *(WINAPI *pLdrProcessRelocationBlock)(void*,UINT,US
 static CHAR *    (WINAPI *pRtlIpv4AddressToStringA)(const IN_ADDR *, LPSTR);
 static NTSTATUS  (WINAPI *pRtlIpv4AddressToStringExA)(const IN_ADDR *, USHORT, LPSTR, PULONG);
 static NTSTATUS  (WINAPI *pRtlIpv4StringToAddressA)(PCSTR, BOOLEAN, PCSTR *, IN_ADDR *);
+static NTSTATUS  (WINAPI *pRtlIpv4StringToAddressExA)(PCSTR, BOOLEAN, IN_ADDR *, PUSHORT);
+static NTSTATUS  (WINAPI *pRtlIpv6StringToAddressA)(PCSTR, PCSTR *, struct in6_addr *);
+static NTSTATUS  (WINAPI *pRtlIpv6StringToAddressExA)(PCSTR AddressString, struct in6_addr *, PULONG, PUSHORT);
 static NTSTATUS  (WINAPI *pLdrAddRefDll)(ULONG, HMODULE);
 static NTSTATUS  (WINAPI *pLdrLockLoaderLock)(ULONG, ULONG*, ULONG_PTR*);
 static NTSTATUS  (WINAPI *pLdrUnlockLoaderLock)(ULONG, ULONG_PTR);
@@ -136,6 +140,9 @@ static void InitFunctionPtrs(void)
         pRtlIpv4AddressToStringA = (void *)GetProcAddress(hntdll, "RtlIpv4AddressToStringA");
         pRtlIpv4AddressToStringExA = (void *)GetProcAddress(hntdll, "RtlIpv4AddressToStringExA");
         pRtlIpv4StringToAddressA = (void *)GetProcAddress(hntdll, "RtlIpv4StringToAddressA");
+        pRtlIpv4StringToAddressExA = (void *)GetProcAddress(hntdll, "RtlIpv4StringToAddressExA");
+        pRtlIpv6StringToAddressA = (void *)GetProcAddress(hntdll, "RtlIpv6StringToAddressA");
+        pRtlIpv6StringToAddressExA = (void *)GetProcAddress(hntdll, "RtlIpv6StringToAddressExA");
         pLdrAddRefDll = (void *)GetProcAddress(hntdll, "LdrAddRefDll");
         pLdrLockLoaderLock = (void *)GetProcAddress(hntdll, "LdrLockLoaderLock");
         pLdrUnlockLoaderLock = (void *)GetProcAddress(hntdll, "LdrUnlockLoaderLock");
@@ -1492,6 +1499,397 @@ static void test_RtlIpv4StringToAddress(void)
     }
 }
 
+static void test_RtlIpv4StringToAddressEx(void)
+{
+    NTSTATUS res;
+    IN_ADDR ip, expected_ip;
+    USHORT port;
+    struct
+    {
+        PCSTR address;
+        NTSTATUS res;
+        int ip[4];
+        USHORT port;
+    } tests[] =
+    {
+        { "",               STATUS_INVALID_PARAMETER,   { -1 },         0xdead },
+        { " ",              STATUS_INVALID_PARAMETER,   { -1 },         0xdead },
+        { "1.1.1.1:",       STATUS_INVALID_PARAMETER,   { 1, 1, 1, 1 }, 0xdead },
+        { "1.1.1.1+",       STATUS_INVALID_PARAMETER,   { 1, 1, 1, 1 }, 0xdead },
+        { "1.1.1.1:1",      STATUS_SUCCESS,             { 1, 1, 1, 1 }, 0x100 },
+        { "0.0.0.0:0",      STATUS_INVALID_PARAMETER,   { 0, 0, 0, 0 }, 0xdead },
+        { "0.0.0.0:1",      STATUS_SUCCESS,             { 0, 0, 0, 0 }, 0x100 },
+        { "1.2.3.4:65535",  STATUS_SUCCESS,             { 1, 2, 3, 4 }, 65535 },
+        { "1.2.3.4:65536",  STATUS_INVALID_PARAMETER,   { 1, 2, 3, 4 }, 0xdead },
+        { "1.2.3.4:0xffff", STATUS_SUCCESS,             { 1, 2, 3, 4 }, 65535 },
+        { "1.2.3.4:0XfFfF", STATUS_SUCCESS,             { 1, 2, 3, 4 }, 65535 },
+        { "1.2.3.4:011064", STATUS_SUCCESS,             { 1, 2, 3, 4 }, 0x3412 },
+        { "1.2.3.4:1234a",  STATUS_INVALID_PARAMETER,   { 1, 2, 3, 4 }, 0xdead },
+        { "1.2.3.4:1234+",  STATUS_INVALID_PARAMETER,   { 1, 2, 3, 4 }, 0xdead },
+        { "1.2.3.4: 1234",  STATUS_INVALID_PARAMETER,   { 1, 2, 3, 4 }, 0xdead },
+        { "1.2.3.4:\t1234", STATUS_INVALID_PARAMETER,   { 1, 2, 3, 4 }, 0xdead },
+    };
+    const int testcount = sizeof(tests) / sizeof(tests[0]);
+    int i, Strict;
+
+    if (!pRtlIpv4StringToAddressExA)
+    {
+        skip("RtlIpv4StringToAddressEx not available\n");
+        return;
+    }
+
+    /* do not crash, and do not touch the ip / port. */
+    ip.S_un.S_addr = 0xabababab;
+    port = 0xdead;
+    res = pRtlIpv4StringToAddressExA(NULL, FALSE, &ip, &port);
+    ok(res == STATUS_INVALID_PARAMETER,
+           "[null address] res = 0x%08x, expected 0x%08x\n",
+           res, STATUS_INVALID_PARAMETER);
+    ok(ip.S_un.S_addr == 0xabababab, "RtlIpv4StringToAddressExA should not touch the ip!, ip == %x\n", ip.S_un.S_addr);
+    ok(port == 0xdead, "RtlIpv4StringToAddressExA should not touch the port!, port == %x\n", port);
+
+    port = 0xdead;
+    res = pRtlIpv4StringToAddressExA("1.1.1.1", FALSE, NULL, &port);
+    ok(res == STATUS_INVALID_PARAMETER,
+           "[null ip] res = 0x%08x, expected 0x%08x\n",
+           res, STATUS_INVALID_PARAMETER);
+    ok(port == 0xdead, "RtlIpv4StringToAddressExA should not touch the port!, port == %x\n", port);
+
+    ip.S_un.S_addr = 0xabababab;
+    port = 0xdead;
+    res = pRtlIpv4StringToAddressExA("1.1.1.1", FALSE, &ip, NULL);
+    ok(res == STATUS_INVALID_PARAMETER,
+           "[null port] res = 0x%08x, expected 0x%08x\n",
+           res, STATUS_INVALID_PARAMETER);
+    ok(ip.S_un.S_addr == 0xabababab, "RtlIpv4StringToAddressExA should not touch the ip!, ip == %x\n", ip.S_un.S_addr);
+    ok(port == 0xdead, "RtlIpv4StringToAddressExA should not touch the port!, port == %x\n", port);
+
+    for (i = 0; i < testcount; i++)
+    {
+        /* Strict is only relevant for the ip address, so make sure that it does not influence the port */
+        for (Strict = 0; Strict < 2; Strict++)
+        {
+            ip.S_un.S_addr = 0xabababab;
+            port = 0xdead;
+            res = pRtlIpv4StringToAddressExA(tests[i].address, Strict, &ip, &port);
+            ok(res == tests[i].res,
+               "[%s] res = 0x%08x, expected 0x%08x\n",
+               tests[i].address, res, tests[i].res);
+            if (tests[i].ip[0] == -1)
+            {
+                expected_ip.S_un.S_addr = 0xabababab;
+            }
+            else
+            {
+                expected_ip.S_un.S_un_b.s_b1 = tests[i].ip[0];
+                expected_ip.S_un.S_un_b.s_b2 = tests[i].ip[1];
+                expected_ip.S_un.S_un_b.s_b3 = tests[i].ip[2];
+                expected_ip.S_un.S_un_b.s_b4 = tests[i].ip[3];
+            }
+            ok(ip.S_un.S_addr == expected_ip.S_un.S_addr,
+               "[%s] ip = %08x, expected %08x\n",
+               tests[i].address, ip.S_un.S_addr, expected_ip.S_un.S_addr);
+            ok(port == tests[i].port,
+               "[%s] port = %u, expected %u\n",
+               tests[i].address, port, tests[i].port);
+        }
+    }
+}
+
+/* ipv6 addresses from https://github.com/beaugunderson/javascript-ipv6/tree/master/test/data */
+static void test_RtlIpv6StringToAddress(void)
+{
+    NTSTATUS res;
+    IN6_ADDR ip, expected_ip;
+    PCSTR terminator;
+    CHAR dummy;
+    struct
+    {
+        PCSTR address;
+        NTSTATUS res;
+        int terminator_offset;
+        int ip[8];
+    } tests[] =
+    {
+        /* according to the github, all these should succeed */
+        { "0000:0000:0000:0000:0000:0000:0000:0000",        STATUS_SUCCESS,             39, { 0, 0, 0, 0, 0, 0, 0, 0 } },
+        { "0000:0000:0000:0000:0000:0000:0000:0001",        STATUS_SUCCESS,             39, { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
+        { "0:0:0:0:0:0:0:0",                                STATUS_SUCCESS,             15, { 0, 0, 0, 0, 0, 0, 0, 0 } },
+        { "0:0:0:0:0:0:0:1",                                STATUS_SUCCESS,             15, { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
+        /* This test fails on Win7 + 8 x86
+        { "0:0:0:0:0:0:0::",                                STATUS_INVALID_PARAMETER,   13, { 0, 0, 0, 0, 0, 0, 0xabab, 0xabab } },*/
+        { "0:0:0:0:0:0:13.1.68.3",                          STATUS_SUCCESS,             21, { 0, 0, 0, 0, 0, 0, 0x10d, 0x344 } },
+        { "0:0:0:0:0:0::",                                  STATUS_SUCCESS,             13, { 0, 0, 0, 0, 0, 0, 0, 0 } },
+        { "0:0:0:0:0::",                                    STATUS_SUCCESS,             11, { 0, 0, 0, 0, 0, 0, 0, 0 } },
+        { "0:0:0:0:0:FFFF:129.144.52.38",                   STATUS_SUCCESS,             28, { 0, 0, 0, 0, 0, 0xffff, 0x9081, 0x2634 } },
+        { "0::",                                            STATUS_SUCCESS,             3,  { 0, 0, 0, 0, 0, 0, 0, 0 } },
+        { "0:1:2:3:4:5:6:7",                                STATUS_SUCCESS,             15, { 0, 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x700 } },
+        { "1080:0:0:0:8:800:200c:417a",                     STATUS_SUCCESS,             26, { 0x8010, 0, 0, 0, 0x800, 0x8, 0x0c20, 0x7a41 } },
+        /* This test fails on Win7 + 8 x86
+        { "0:a:b:c:d:e:f::",                                STATUS_INVALID_PARAMETER,   13, { 0, 0xa00, 0xb00, 0xc00, 0xd00, 0xe00, 0xabab, 0xabab } },*/
+        { "1111:2222:3333:4444:5555:6666:123.123.123.123",  STATUS_SUCCESS,             45, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
+        { "1111:2222:3333:4444:5555:6666:7777:8888",        STATUS_SUCCESS,             39, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } },
+        /* This test fails on Win7 + 8 x86
+        { "1111:2222:3333:4444:5555:6666:7777::",           STATUS_INVALID_PARAMETER,   34, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0xabab, 0xabab } },*/
+        { "1111:2222:3333:4444:5555:6666::",                STATUS_SUCCESS,             31, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0, 0 } },
+        { "1111:2222:3333:4444:5555:6666::8888",            STATUS_SUCCESS,             35, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0, 0x8888 } },
+        { "1111:2222:3333:4444:5555::",                     STATUS_SUCCESS,             26, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0 } },
+        { "1111:2222:3333:4444:5555::123.123.123.123",      STATUS_SUCCESS,             41, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0x7b7b, 0x7b7b } },
+        { "1111:2222:3333:4444:5555::7777:8888",            STATUS_SUCCESS,             35, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0x7777, 0x8888 } },
+        { "1111:2222:3333:4444:5555::8888",                 STATUS_SUCCESS,             30, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x8888 } },
+        { "1111::",                                         STATUS_SUCCESS,             6,  { 0x1111, 0, 0, 0, 0, 0, 0, 0 } },
+        { "1111::123.123.123.123",                          STATUS_SUCCESS,             21, { 0x1111, 0, 0, 0, 0, 0, 0x7b7b, 0x7b7b } },
+        { "1111::3333:4444:5555:6666:123.123.123.123",      STATUS_SUCCESS,             41, { 0x1111, 0, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
+        { "1111::3333:4444:5555:6666:7777:8888",            STATUS_SUCCESS,             35, { 0x1111, 0, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } },
+        { "1111::4444:5555:6666:123.123.123.123",           STATUS_SUCCESS,             36, { 0x1111, 0, 0, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
+        { "1111::4444:5555:6666:7777:8888",                 STATUS_SUCCESS,             30, { 0x1111, 0, 0, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } },
+        { "1111::5555:6666:123.123.123.123",                STATUS_SUCCESS,             31, { 0x1111, 0, 0, 0, 0x5555, 0x6666, 0x7b7b, 0x7b7b } },
+        { "1111::5555:6666:7777:8888",                      STATUS_SUCCESS,             25, { 0x1111, 0, 0, 0, 0x5555, 0x6666, 0x7777, 0x8888 } },
+        { "1111::6666:123.123.123.123",                     STATUS_SUCCESS,             26, { 0x1111, 0, 0, 0, 0, 0x6666, 0x7b7b, 0x7b7b } },
+        { "1111::6666:7777:8888",                           STATUS_SUCCESS,             20, { 0x1111, 0, 0, 0, 0, 0x6666, 0x7777, 0x8888 } },
+        { "1111::7777:8888",                                STATUS_SUCCESS,             15, { 0x1111, 0, 0, 0, 0, 0, 0x7777, 0x8888 } },
+        { "1111::8888",                                     STATUS_SUCCESS,             10, { 0x1111, 0, 0, 0, 0, 0, 0, 0x8888 } },
+        { "1:2:3:4:5:6:1.2.3.4",                            STATUS_SUCCESS,             19, { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x201, 0x403 } },
+        { "1:2:3:4:5:6:7:8",                                STATUS_SUCCESS,             15, { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x700, 0x800 } },
+        { "1:2:3:4:5:6::",                                  STATUS_SUCCESS,             13, { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0, 0 } },
+        { "1:2:3:4:5:6::8",                                 STATUS_SUCCESS,             14, { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0, 0x800 } },
+        { "2001:0000:1234:0000:0000:C1C0:ABCD:0876",        STATUS_SUCCESS,             39, { 0x120, 0, 0x3412, 0, 0, 0xc0c1, 0xcdab, 0x7608 } },
+        { "2001:0000:4136:e378:8000:63bf:3fff:fdd2",        STATUS_SUCCESS,             39, { 0x120, 0, 0x3641, 0x78e3, 0x80, 0xbf63, 0xff3f, 0xd2fd } },
+        { "2001:0db8:0:0:0:0:1428:57ab",                    STATUS_SUCCESS,             27, { 0x120, 0xb80d, 0, 0, 0, 0, 0x2814, 0xab57 } },
+        { "2001:0db8:1234:ffff:ffff:ffff:ffff:ffff",        STATUS_SUCCESS,             39, { 0x120, 0xb80d, 0x3412, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff } },
+        { "2001::CE49:7601:2CAD:DFFF:7C94:FFFE",            STATUS_SUCCESS,             35, { 0x120, 0, 0x49ce, 0x176, 0xad2c, 0xffdf, 0x947c, 0xfeff } },
+        { "2001:db8:85a3::8a2e:370:7334",                   STATUS_SUCCESS,             28, { 0x120, 0xb80d, 0xa385, 0, 0, 0x2e8a, 0x7003, 0x3473 } },
+        { "3ffe:0b00:0000:0000:0001:0000:0000:000a",        STATUS_SUCCESS,             39, { 0xfe3f, 0xb, 0, 0, 0x100, 0, 0, 0xa00 } },
+        { "::",                                             STATUS_SUCCESS,             2,  { 0, 0, 0, 0, 0, 0, 0, 0 } },
+        { "::%16",                                          STATUS_SUCCESS,             2,  { 0, 0, 0, 0, 0, 0, 0, 0 } },
+        { "::/16",                                          STATUS_SUCCESS,             2,  { 0, 0, 0, 0, 0, 0, 0, 0 } },
+        { "::0",                                            STATUS_SUCCESS,             3,  { 0, 0, 0, 0, 0, 0, 0, 0 } },
+        { "::0:0",                                          STATUS_SUCCESS,             5,  { 0, 0, 0, 0, 0, 0, 0, 0 } },
+        { "::0:0:0",                                        STATUS_SUCCESS,             7,  { 0, 0, 0, 0, 0, 0, 0, 0 } },
+        { "::0:0:0:0",                                      STATUS_SUCCESS,             9,  { 0, 0, 0, 0, 0, 0, 0, 0 } },
+        { "::0:0:0:0:0",                                    STATUS_SUCCESS,             11, { 0, 0, 0, 0, 0, 0, 0, 0 } },
+        { "::0:0:0:0:0:0",                                  STATUS_SUCCESS,             13, { 0, 0, 0, 0, 0, 0, 0, 0 } },
+        { "::0:0:0:0:0:0:0",                                STATUS_SUCCESS,             13, { 0, 0, 0, 0, 0, 0, 0, 0 } },
+        { "::0:a:b:c:d:e:f",                                STATUS_SUCCESS,             13, { 0, 0, 0, 0xa00, 0xb00, 0xc00, 0xd00, 0xe00 } },
+        { "::123.123.123.123",                              STATUS_SUCCESS,             17, { 0, 0, 0, 0, 0, 0, 0x7b7b, 0x7b7b } },
+        { "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",        STATUS_SUCCESS,             39, { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff } },
+
+        /* and all these should fail */
+        { "':10.0.0.1",                                     STATUS_INVALID_PARAMETER,   0,  { -1 } },
+        { "-1",                                             STATUS_INVALID_PARAMETER,   0,  { -1 } },
+        { "02001:0000:1234:0000:0000:C1C0:ABCD:0876",       STATUS_INVALID_PARAMETER,   -1, { -1 } },
+        { "1.2.3.4",                                        STATUS_INVALID_PARAMETER,   7,  { 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
+        { "1.2.3.4:1111::5555",                             STATUS_INVALID_PARAMETER,   7,  { 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
+        { "1.2.3.4::5555",                                  STATUS_INVALID_PARAMETER,   7,  { 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
+        { "11112222:3333:4444:5555:6666:1.2.3.4",           STATUS_INVALID_PARAMETER,   -1, { -1 } },
+        { "11112222:3333:4444:5555:6666:7777:8888",         STATUS_INVALID_PARAMETER,   -1, { -1 } },
+        { "1111",                                           STATUS_INVALID_PARAMETER,   4,  { -1 } },
+        { "1111:22223333:4444:5555:6666:1.2.3.4",           STATUS_INVALID_PARAMETER,   -1, { 0x1111, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
+        { "1111:22223333:4444:5555:6666:7777:8888",         STATUS_INVALID_PARAMETER,   -1, { 0x1111, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
+        { "1111:2222:",                                     STATUS_INVALID_PARAMETER,   10, { 0x1111, 0x2222, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
+        { "1111:2222:1.2.3.4",                              STATUS_INVALID_PARAMETER,   17, { 0x1111, 0x2222, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab } },
+        { "1111:2222:3333",                                 STATUS_INVALID_PARAMETER,   14, { 0x1111, 0x2222, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
+        { "1111:2222:3333:4444:5555:6666:7777:1.2.3.4",     STATUS_SUCCESS,             36, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x100 } },
+        { "1111:2222:3333:4444:5555:6666:7777:8888:",       STATUS_SUCCESS,             39, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } },
+        { "1111:2222:3333:4444:5555:6666:7777:8888:1.2.3.4",STATUS_SUCCESS,             39, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } },
+        { "1111:2222:3333:4444:5555:6666:7777:8888:9999",   STATUS_SUCCESS,             39, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } },
+        { "1111:2222:::",                                   STATUS_SUCCESS,             11, { 0x1111, 0x2222, 0, 0, 0, 0, 0, 0 } },
+        { "1111::5555:",                                    STATUS_INVALID_PARAMETER,   11, { 0x1111, 0x5555, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
+        { "1111::3333:4444:5555:6666:7777::",               STATUS_SUCCESS,             30, { 0x1111, 0, 0, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777 } },
+        { "1111:2222:::4444:5555:6666:1.2.3.4",             STATUS_SUCCESS,             11, { 0x1111, 0x2222, 0, 0, 0, 0, 0, 0 } },
+        { "1111::3333::5555:6666:1.2.3.4",                  STATUS_SUCCESS,             10, { 0x1111, 0, 0, 0, 0, 0, 0, 0x3333 } },
+        { "12345::6:7:8",                                   STATUS_INVALID_PARAMETER,   -1, { -1 } },
+        { "1::1.2.256.4",                                   STATUS_INVALID_PARAMETER,   -1, { 0x100, 0x201, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
+        { "1::1.2.3.256",                                   STATUS_INVALID_PARAMETER,   12, { 0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
+        { "1::1.2.3.300",                                   STATUS_INVALID_PARAMETER,   12, { 0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
+        { "1::1.2.3.900",                                   STATUS_INVALID_PARAMETER,   12, { 0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
+        { "1::1.2.300.4",                                   STATUS_INVALID_PARAMETER,   -1, { 0x100, 0x201, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
+        { "1::1.256.3.4",                                   STATUS_INVALID_PARAMETER,   -1, { 0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
+        { "1::256.2.3.4",                                   STATUS_INVALID_PARAMETER,   -1, { 0x100, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
+        { "1::2::3",                                        STATUS_SUCCESS,             4,  { 0x100, 0, 0, 0, 0, 0, 0, 0x200 } },
+        { "2001:0000:1234: 0000:0000:C1C0:ABCD:0876",       STATUS_INVALID_PARAMETER,   15, { 0x120, 0, 0x3412, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } },
+        { "2001:0000:1234:0000:0000:C1C0:ABCD:0876  0",     STATUS_SUCCESS,             39, { 0x120, 0, 0x3412, 0, 0, 0xc0c1, 0xcdab, 0x7608 } },
+        { "2001:1:1:1:1:1:255Z255X255Y255",                 STATUS_INVALID_PARAMETER,   18, { 0x120, 0x100, 0x100, 0x100, 0x100, 0x100, 0xabab, 0xabab } },
+        { "2001::FFD3::57ab",                               STATUS_SUCCESS,             10, { 0x120, 0, 0, 0, 0, 0, 0, 0xd3ff } },
+        { ":",                                              STATUS_INVALID_PARAMETER,   0,  { -1 } },
+        { ":1111:2222:3333:4444:5555:6666:1.2.3.4",         STATUS_INVALID_PARAMETER,   0,  { -1 } },
+        { ":1111:2222:3333:4444:5555:6666:7777:8888",       STATUS_INVALID_PARAMETER,   0,  { -1 } },
+        { ":1111::",                                        STATUS_INVALID_PARAMETER,   0,  { -1 } },
+        { "::-1",                                           STATUS_SUCCESS,             2,  { 0, 0, 0, 0, 0, 0, 0, 0 } },
+        { "::.",                                            STATUS_SUCCESS,             2,  { 0, 0, 0, 0, 0, 0, 0, 0 } },
+        { "::..",                                           STATUS_SUCCESS,             2,  { 0, 0, 0, 0, 0, 0, 0, 0 } },
+        { "::...",                                          STATUS_SUCCESS,             2,  { 0, 0, 0, 0, 0, 0, 0, 0 } },
+        { "XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:1.2.3.4",          STATUS_INVALID_PARAMETER,   0,  { -1 } },
+        { "[::]",                                           STATUS_INVALID_PARAMETER,   0,  { -1 } },
+
+        /* windows disagrees with that...
+           it also seems to directly operate on the ipv6 struct, and sometimes forgets to update the terminator. */
+    };
+    const int testcount = sizeof(tests) / sizeof(tests[0]);
+    int i, j;
+
+    if (!pRtlIpv6StringToAddressA)
+    {
+        skip("RtlIpv6StringToAddress not available\n");
+        return;
+    }
+
+    res = pRtlIpv6StringToAddressA("::", &terminator, &ip);
+    ok(res == STATUS_SUCCESS, "[validate] res = 0x%08x, expected STATUS_SUCCESS\n", res);
+    if (0) {
+        /* any of these crash */
+        res = pRtlIpv6StringToAddressA(NULL, &terminator, &ip);
+        ok(res == STATUS_INVALID_PARAMETER, "[null string] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res);
+        res = pRtlIpv6StringToAddressA("::", NULL, &ip);
+        ok(res == STATUS_INVALID_PARAMETER, "[null terminator] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res);
+        res = pRtlIpv6StringToAddressA("::", &terminator, NULL);
+        ok(res == STATUS_INVALID_PARAMETER, "[null result] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res);
+    }
+
+
+    /* sanity check */
+    ok(sizeof(ip._S6_un) == (sizeof(USHORT)* 8), "sizeof(ip._S6_un)\n");
+
+    for (i = 0; i < testcount; i++)
+    {
+        terminator = &dummy;
+        for (j = 0; j < 8; ++j)
+            ip.s6_words[j] = 0xabab;
+        res = pRtlIpv6StringToAddressA(tests[i].address, &terminator, &ip);
+        ok(res == tests[i].res,
+            "[%s] res = 0x%08x, expected 0x%08x\n",
+            tests[i].address, res, tests[i].res);
+        if (tests[i].terminator_offset < 0)
+        {
+            ok(terminator == &dummy,
+                "[%s] terminator = %p, expected it not to change\n",
+                tests[i].address, terminator);
+        }
+        else
+        {
+            ok(terminator == tests[i].address + tests[i].terminator_offset,
+                "[%s] terminator = %p, expected %p\n",
+                tests[i].address, terminator, tests[i].address + tests[i].terminator_offset);
+        }
+        if (tests[i].ip[0] == -1)
+        {
+            for (j = 0; j < 8; ++j)
+                expected_ip.s6_words[j] = 0xabab;
+        }
+        else
+        {
+            for (j = 0; j < 8; ++j)
+                expected_ip.s6_words[j] = tests[i].ip[j];
+        }
+        ok(!memcmp(ip.s6_addr, expected_ip.s6_addr, sizeof(ip._S6_un)),
+            "[%s] ip = %x:%x:%x:%x:%x:%x:%x:%x, expected %x:%x:%x:%x:%x:%x:%x:%x\n",
+            tests[i].address,
+            ip.s6_words[0], ip.s6_words[1], ip.s6_words[2], ip.s6_words[3],
+            ip.s6_words[4], ip.s6_words[5], ip.s6_words[6], ip.s6_words[7],
+            expected_ip.s6_words[0], expected_ip.s6_words[1], expected_ip.s6_words[2], expected_ip.s6_words[3],
+            expected_ip.s6_words[4], expected_ip.s6_words[5], expected_ip.s6_words[6], expected_ip.s6_words[7]);
+    }
+}
+
+static void test_RtlIpv6StringToAddressEx(void)
+{
+    NTSTATUS res;
+    IN6_ADDR ip, expected_ip;
+    ULONG scope;
+    USHORT port;
+    struct
+    {
+        PCSTR address;
+        NTSTATUS res;
+        ULONG scope;
+        USHORT port;
+        int ip[8];
+    } tests[] =
+    {
+        { "[::]",                                           STATUS_SUCCESS,             0,          0, { 0, 0, 0, 0, 0, 0, 0, 0 } },
+        { "[::1]:8080",                                     STATUS_SUCCESS,             0,          0x901f, { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
+        { "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80",   STATUS_SUCCESS,             0,          0x5000, { 0xdcfe, 0x98ba, 0x5476, 0x1032, 0xdcfe, 0x98ba, 0x5476, 0x1032 } },
+        { "[1080:0:0:0:8:800:200C:417A]:1234",              STATUS_SUCCESS,             0,          0xd204, { 0x8010, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
+        { "[3ffe:2a00:100:7031::1]:8080",                   STATUS_SUCCESS,             0,          0x901f, { 0xfe3f, 0x2a, 1, 0x3170, 0, 0, 0, 0x100 } },
+        { "[ 3ffe:2a00:100:7031::1]:8080",                  STATUS_INVALID_PARAMETER,   0xbadf00d,  0xbeef, { -1 } },
+        { "[3ffe:2a00:100:7031::1 ]:8080",                  STATUS_INVALID_PARAMETER,   0xbadf00d,  0xbeef, { 0xfe3f, 0x2a, 1, 0x3170, 0, 0, 0, 0x100 } },
+        { "[3ffe:2a00:100:7031::1].8080",                   STATUS_INVALID_PARAMETER,   0xbadf00d,  0xbeef, { 0xfe3f, 0x2a, 1, 0x3170, 0, 0, 0, 0x100 } },
+        { "[1080::8:800:200C:417A]:8080",                   STATUS_SUCCESS,             0,          0x901f, { 0x8010, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
+        { "[1080::8:800:200C:417A]!8080",                   STATUS_INVALID_PARAMETER,   0xbadf00d,  0xbeef, { 0x8010, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
+        { "[::FFFF:129.144.52.38]:80",                      STATUS_SUCCESS,             0,          0x5000, { 0, 0, 0, 0, 0, 0xffff, 0x9081, 0x2634 } },
+        { "[12345::6:7:8]:80",                              STATUS_INVALID_PARAMETER,   0xbadf00d,  0xbeef, { -1 } },
+        { "[ff01::8:800:200C:417A%16]:8080",                STATUS_SUCCESS,             16,         0x901f, { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
+        { "[ff01::8:800:200C:417A%100]:8080",               STATUS_SUCCESS,             100,        0x901f, { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
+        { "[ff01::8:800:200C:417A%1000]:8080",              STATUS_SUCCESS,             1000,       0x901f, { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
+        { "[ff01::8:800:200C:417A%10000]:8080",             STATUS_SUCCESS,             10000,      0x901f, { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
+        { "[ff01::8:800:200C:417A%1000000]:8080",           STATUS_SUCCESS,             1000000,    0x901f, { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
+        { "[ff01::8:800:200C:417A%4294967295]:8080",        STATUS_SUCCESS,             4294967295, 0x901f, { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
+        { "[ff01::8:800:200C:417A%4294967296]:8080",        STATUS_INVALID_PARAMETER,   0xbadf00d,  0xbeef, { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
+        { "[ff01::8:800:200C:417A%-1]:8080",                STATUS_INVALID_PARAMETER,   0xbadf00d,  0xbeef, { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
+        { "[ff01::8:800:200C:417A%0]:8080",                 STATUS_SUCCESS,             0,          0x901f, { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
+        { "[ff01::8:800:200C:417A%0x1000]:8080",            STATUS_INVALID_PARAMETER,   0xbadf00d,  0xbeef, { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
+        { "[ff01::8:800:200C:417A/16]:8080",                STATUS_INVALID_PARAMETER,   0xbadf00d,  0xbeef, { 0x1ff, 0, 0, 0, 0x800, 8, 0xc20, 0x7a41 } },
+    };
+    const int testcount = sizeof(tests) / sizeof(tests[0]);
+    int i, j;
+
+    if (!pRtlIpv6StringToAddressExA)
+    {
+        skip("RtlIpv6StringToAddressEx not available\n");
+        return;
+    }
+
+    res = pRtlIpv6StringToAddressExA("::", &ip, &scope, &port);
+    ok(res == STATUS_SUCCESS, "[validate] res = 0x%08x, expected STATUS_SUCCESS\n", res);
+    res = pRtlIpv6StringToAddressExA(NULL, &ip, &scope, &port);
+    ok(res == STATUS_INVALID_PARAMETER, "[null string] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res);
+    res = pRtlIpv6StringToAddressExA("::", NULL, &scope, &port);
+    ok(res == STATUS_INVALID_PARAMETER, "[null result] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res);
+    res = pRtlIpv6StringToAddressExA("::", &ip, NULL, &port);
+    ok(res == STATUS_INVALID_PARAMETER, "[null scope] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res);
+    res = pRtlIpv6StringToAddressExA("::", &ip, &scope, NULL);
+    ok(res == STATUS_INVALID_PARAMETER, "[null port] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res);
+
+    /* sanity check */
+    ok(sizeof(ip._S6_un) == (sizeof(USHORT)* 8), "sizeof(ip._S6_un)\n");
+
+    for (i = 0; i < testcount; i++)
+    {
+        scope = 0xbadf00d;
+        port = 0xbeef;
+        for (j = 0; j < 8; ++j)
+            ip.s6_words[j] = 0xabab;
+        res = pRtlIpv6StringToAddressExA(tests[i].address, &ip, &scope, &port);
+        ok(res == tests[i].res,
+            "[%s] res = 0x%08x, expected 0x%08x\n",
+            tests[i].address, res, tests[i].res);
+        ok(scope == tests[i].scope,
+            "[%s] scope = 0x%08x, expected 0x%08x\n",
+            tests[i].address, scope, tests[i].scope);
+        ok(port == tests[i].port,
+            "[%s] port = 0x%08x, expected 0x%08x\n",
+            tests[i].address, port, tests[i].port);
+
+        if (tests[i].ip[0] == -1)
+        {
+            for (j = 0; j < 8; ++j)
+                expected_ip.s6_words[j] = 0xabab;
+        }
+        else
+        {
+            for (j = 0; j < 8; ++j)
+                expected_ip.s6_words[j] = tests[i].ip[j];
+        }
+        ok(!memcmp(ip.s6_addr, expected_ip.s6_addr, sizeof(ip._S6_un)),
+            "[%s] ip = %x:%x:%x:%x:%x:%x:%x:%x, expected %x:%x:%x:%x:%x:%x:%x:%x\n",
+            tests[i].address,
+            ip.s6_words[0], ip.s6_words[1], ip.s6_words[2], ip.s6_words[3],
+            ip.s6_words[4], ip.s6_words[5], ip.s6_words[6], ip.s6_words[7],
+            expected_ip.s6_words[0], expected_ip.s6_words[1], expected_ip.s6_words[2], expected_ip.s6_words[3],
+            expected_ip.s6_words[4], expected_ip.s6_words[5], expected_ip.s6_words[6], expected_ip.s6_words[7]);
+    }
+}
+
 static void test_LdrAddRefDll(void)
 {
     HMODULE mod, mod2;
@@ -1623,6 +2021,9 @@ START_TEST(rtl)
     test_RtlIpv4AddressToString();
     test_RtlIpv4AddressToStringEx();
     test_RtlIpv4StringToAddress();
+    test_RtlIpv4StringToAddressEx();
+    test_RtlIpv6StringToAddress();
+    test_RtlIpv6StringToAddressEx();
     test_LdrAddRefDll();
     test_LdrLockLoaderLock();
 }
-- 
1.9.1



More information about the wine-patches mailing list