You've already forked wine-staging
mirror of
https://gitlab.winehq.org/wine/wine-staging.git
synced 2025-04-13 14:42:51 -07:00
Added patch for tests of RtlIpv6StringToAddress, RtlIpv{4,6}StringToAddressEx (by Mark Jansen).
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,333 @@
|
||||
From 61f51c445a223aaceb0b404f4c13eda296133f25 Mon Sep 17 00:00:00 2001
|
||||
From: Mark Jansen <learn0more+wine@gmail.com>
|
||||
Date: Sun, 8 Mar 2015 18:24:50 +0100
|
||||
Subject: ntdll/tests: Tests for RtlIpv6StringToAddressEx (try 6)
|
||||
|
||||
Changes from try5:
|
||||
-Reformat ipv6 table to be less wide
|
||||
-Remove _s6_un from memcmp calls
|
||||
|
||||
Changes from try4 (all suggestions from stefand in #winehackers):
|
||||
-Use RtlMultiByteToUnicodeN for A->W conversion
|
||||
-Fix warning
|
||||
-Clarify comment / move init_ip6 inside if branch
|
||||
|
||||
Changes from try3:
|
||||
-Also test the W version against the A version
|
||||
-Test the ip against the non-ex version as suggested by stefand
|
||||
-Add more testcases
|
||||
---
|
||||
dlls/ntdll/tests/rtl.c | 269 ++++++++++++++++++++++++++++++++++++++++++++++++-
|
||||
1 file changed, 268 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/dlls/ntdll/tests/rtl.c b/dlls/ntdll/tests/rtl.c
|
||||
index 8030c86..5d789d1 100644
|
||||
--- a/dlls/ntdll/tests/rtl.c
|
||||
+++ b/dlls/ntdll/tests/rtl.c
|
||||
@@ -92,6 +92,8 @@ static NTSTATUS (WINAPI *pRtlIpv4AddressToStringExA)(const IN_ADDR *, USHORT, L
|
||||
static NTSTATUS (WINAPI *pRtlIpv4StringToAddressA)(PCSTR, BOOLEAN, PCSTR *, IN_ADDR *);
|
||||
static NTSTATUS (WINAPI *pRtlIpv6StringToAddressA)(PCSTR, PCSTR *, struct in6_addr *);
|
||||
static NTSTATUS (WINAPI *pRtlIpv6StringToAddressW)(PCWSTR, PCWSTR *, struct in6_addr *);
|
||||
+static NTSTATUS (WINAPI *pRtlIpv6StringToAddressExA)(PCSTR, struct in6_addr *, PULONG, PUSHORT);
|
||||
+static NTSTATUS (WINAPI *pRtlIpv6StringToAddressExW)(PCWSTR, 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);
|
||||
@@ -142,6 +144,8 @@ static void InitFunctionPtrs(void)
|
||||
pRtlIpv4StringToAddressA = (void *)GetProcAddress(hntdll, "RtlIpv4StringToAddressA");
|
||||
pRtlIpv6StringToAddressA = (void *)GetProcAddress(hntdll, "RtlIpv6StringToAddressA");
|
||||
pRtlIpv6StringToAddressW = (void *)GetProcAddress(hntdll, "RtlIpv6StringToAddressW");
|
||||
+ pRtlIpv6StringToAddressExA = (void *)GetProcAddress(hntdll, "RtlIpv6StringToAddressExA");
|
||||
+ pRtlIpv6StringToAddressExW = (void *)GetProcAddress(hntdll, "RtlIpv6StringToAddressExW");
|
||||
pLdrAddRefDll = (void *)GetProcAddress(hntdll, "LdrAddRefDll");
|
||||
pLdrLockLoaderLock = (void *)GetProcAddress(hntdll, "LdrLockLoaderLock");
|
||||
pLdrUnlockLoaderLock = (void *)GetProcAddress(hntdll, "LdrUnlockLoaderLock");
|
||||
@@ -1775,7 +1779,6 @@ static const struct
|
||||
};
|
||||
const unsigned int ipv6_testcount = sizeof(ipv6_tests) / sizeof(ipv6_tests[0]);
|
||||
|
||||
-
|
||||
static void init_ip6(IN6_ADDR* addr, const int src[8])
|
||||
{
|
||||
unsigned int j;
|
||||
@@ -1921,6 +1924,269 @@ static void test_RtlIpv6StringToAddress(void)
|
||||
}
|
||||
}
|
||||
|
||||
+static void compare_RtlIpv6StringToAddressExW(PCSTR name_a, const struct in6_addr *addr_a, HRESULT res_a, ULONG scope_a, USHORT port_a)
|
||||
+{
|
||||
+ WCHAR name[512];
|
||||
+ NTSTATUS res;
|
||||
+ IN6_ADDR ip;
|
||||
+ ULONG scope = 0xbadf00d;
|
||||
+ USHORT port = 0xbeef;
|
||||
+
|
||||
+ if (!pRtlIpv6StringToAddressExW)
|
||||
+ return;
|
||||
+
|
||||
+ pRtlMultiByteToUnicodeN(name, sizeof(name), NULL, name_a, strlen(name_a) + 1);
|
||||
+
|
||||
+ init_ip6(&ip, NULL);
|
||||
+ res = pRtlIpv6StringToAddressExW(name, &ip, &scope, &port);
|
||||
+
|
||||
+ ok(res == res_a, "[W:%s] res = 0x%08x, expected 0x%08x\n", name_a, res, res_a);
|
||||
+ ok(scope == scope_a, "[W:%s] scope = 0x%08x, expected 0x%08x\n", name_a, scope, scope_a);
|
||||
+ ok(port == port_a, "[W:%s] port = 0x%08x, expected 0x%08x\n", name_a, port, port_a);
|
||||
+
|
||||
+ ok(!memcmp(&ip, addr_a, sizeof(ip)),
|
||||
+ "[W:%s] ip = %x:%x:%x:%x:%x:%x:%x:%x, expected %x:%x:%x:%x:%x:%x:%x:%x\n",
|
||||
+ name_a,
|
||||
+ 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],
|
||||
+ addr_a->s6_words[0], addr_a->s6_words[1], addr_a->s6_words[2], addr_a->s6_words[3],
|
||||
+ addr_a->s6_words[4], addr_a->s6_words[5], addr_a->s6_words[6], addr_a->s6_words[7]);
|
||||
+}
|
||||
+
|
||||
+static void test_RtlIpv6StringToAddressEx(void)
|
||||
+{
|
||||
+ NTSTATUS res;
|
||||
+ IN6_ADDR ip, expected_ip;
|
||||
+ ULONG scope;
|
||||
+ USHORT port;
|
||||
+ static const struct
|
||||
+ {
|
||||
+ PCSTR address;
|
||||
+ NTSTATUS res;
|
||||
+ ULONG scope;
|
||||
+ USHORT port;
|
||||
+ int ip[8];
|
||||
+ } ipv6_ex_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 } },
|
||||
+ { "[::1]:0x80", STATUS_SUCCESS, 0, 0x8000,
|
||||
+ { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
|
||||
+ { "[::1]:0X80", STATUS_SUCCESS, 0, 0x8000,
|
||||
+ { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
|
||||
+ { "[::1]:080", STATUS_INVALID_PARAMETER, 0xbadf00d, 0xbeef,
|
||||
+ { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
|
||||
+ { "[::1]:800000000080", STATUS_INVALID_PARAMETER, 0xbadf00d, 0xbeef,
|
||||
+ { 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 } },
|
||||
+ { "[::FFFF:129.144.52.38]:-80", STATUS_INVALID_PARAMETER, 0xbadf00d, 0xbeef,
|
||||
+ { 0, 0, 0, 0, 0, 0xffff, 0x9081, 0x2634 } },
|
||||
+ { "[::FFFF:129.144.52.38]:999999999999", STATUS_INVALID_PARAMETER, 0xbadf00d, 0xbeef,
|
||||
+ { 0, 0, 0, 0, 0, 0xffff, 0x9081, 0x2634 } },
|
||||
+ { "[::FFFF:129.144.52.38%-8]:80", STATUS_INVALID_PARAMETER, 0xbadf00d, 0xbeef,
|
||||
+ { 0, 0, 0, 0, 0, 0xffff, 0x9081, 0x2634 } },
|
||||
+ { "[::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, 0xffffffff, 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%1", STATUS_INVALID_PARAMETER, 0xbadf00d, 0xbeef,
|
||||
+ { 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 unsigned int ipv6_ex_testcount = sizeof(ipv6_ex_tests) / sizeof(ipv6_ex_tests[0]);
|
||||
+ const char *simple_ip = "::";
|
||||
+ unsigned int i;
|
||||
+
|
||||
+ if (!pRtlIpv6StringToAddressExW)
|
||||
+ {
|
||||
+ skip("RtlIpv6StringToAddressExW not available\n");
|
||||
+ /* we can continue, just not test W */
|
||||
+ }
|
||||
+
|
||||
+ if (!pRtlIpv6StringToAddressExA)
|
||||
+ {
|
||||
+ skip("RtlIpv6StringToAddressExA not available\n");
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ res = pRtlIpv6StringToAddressExA(simple_ip, &ip, &scope, &port);
|
||||
+ ok(res == STATUS_SUCCESS, "[validate] res = 0x%08x, expected STATUS_SUCCESS\n", res);
|
||||
+
|
||||
+ init_ip6(&ip, NULL);
|
||||
+ init_ip6(&expected_ip, NULL);
|
||||
+ scope = 0xbadf00d;
|
||||
+ port = 0xbeef;
|
||||
+ res = pRtlIpv6StringToAddressExA(NULL, &ip, &scope, &port);
|
||||
+ ok(res == STATUS_INVALID_PARAMETER,
|
||||
+ "[null string] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res);
|
||||
+ ok(scope == 0xbadf00d, "[null string] scope = 0x%08x, expected 0xbadf00d\n", scope);
|
||||
+ ok(port == 0xbeef, "[null string] port = 0x%08x, expected 0xbeef\n", port);
|
||||
+ ok(!memcmp(&ip, &expected_ip, sizeof(ip)),
|
||||
+ "[null string] ip is changed, expected it not to change\n");
|
||||
+
|
||||
+
|
||||
+ init_ip6(&ip, NULL);
|
||||
+ scope = 0xbadf00d;
|
||||
+ port = 0xbeef;
|
||||
+ res = pRtlIpv6StringToAddressExA(simple_ip, NULL, &scope, &port);
|
||||
+ ok(res == STATUS_INVALID_PARAMETER,
|
||||
+ "[null result] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res);
|
||||
+ ok(scope == 0xbadf00d, "[null result] scope = 0x%08x, expected 0xbadf00d\n", scope);
|
||||
+ ok(port == 0xbeef, "[null result] port = 0x%08x, expected 0xbeef\n", port);
|
||||
+ ok(!memcmp(&ip, &expected_ip, sizeof(ip)),
|
||||
+ "[null result] ip is changed, expected it not to change\n");
|
||||
+
|
||||
+ init_ip6(&ip, NULL);
|
||||
+ scope = 0xbadf00d;
|
||||
+ port = 0xbeef;
|
||||
+ res = pRtlIpv6StringToAddressExA(simple_ip, &ip, NULL, &port);
|
||||
+ ok(res == STATUS_INVALID_PARAMETER,
|
||||
+ "[null scope] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res);
|
||||
+ ok(scope == 0xbadf00d, "[null scope] scope = 0x%08x, expected 0xbadf00d\n", scope);
|
||||
+ ok(port == 0xbeef, "[null scope] port = 0x%08x, expected 0xbeef\n", port);
|
||||
+ ok(!memcmp(&ip, &expected_ip, sizeof(ip)),
|
||||
+ "[null scope] ip is changed, expected it not to change\n");
|
||||
+
|
||||
+ init_ip6(&ip, NULL);
|
||||
+ scope = 0xbadf00d;
|
||||
+ port = 0xbeef;
|
||||
+ res = pRtlIpv6StringToAddressExA(simple_ip, &ip, &scope, NULL);
|
||||
+ ok(res == STATUS_INVALID_PARAMETER,
|
||||
+ "[null port] res = 0x%08x, expected STATUS_INVALID_PARAMETER\n", res);
|
||||
+ ok(scope == 0xbadf00d, "[null port] scope = 0x%08x, expected 0xbadf00d\n", scope);
|
||||
+ ok(port == 0xbeef, "[null port] port = 0x%08x, expected 0xbeef\n", port);
|
||||
+ ok(!memcmp(&ip, &expected_ip, sizeof(ip)),
|
||||
+ "[null port] ip is changed, expected it not to change\n");
|
||||
+
|
||||
+ /* sanity check */
|
||||
+ ok(sizeof(ip) == sizeof(USHORT)* 8, "sizeof(ip)\n");
|
||||
+
|
||||
+ /* first we run all ip related tests, to make sure someone didnt accidentally reimplement instead of re-use. */
|
||||
+ for (i = 0; i < ipv6_testcount; i++)
|
||||
+ {
|
||||
+ ULONG scope = 0xbadf00d;
|
||||
+ USHORT port = 0xbeef;
|
||||
+ NTSTATUS expect_ret = (ipv6_tests[i].flags & ex_fail_6) ? STATUS_INVALID_PARAMETER : ipv6_tests[i].res;
|
||||
+
|
||||
+ if (ipv6_tests[i].flags & ex_skip_6)
|
||||
+ continue;
|
||||
+
|
||||
+ init_ip6(&ip, NULL);
|
||||
+ res = pRtlIpv6StringToAddressExA(ipv6_tests[i].address, &ip, &scope, &port);
|
||||
+ compare_RtlIpv6StringToAddressExW(ipv6_tests[i].address, &ip, res, scope, port);
|
||||
+
|
||||
+ /* make sure nothing was changed if this function fails. */
|
||||
+ if (res == STATUS_INVALID_PARAMETER)
|
||||
+ {
|
||||
+ ok(scope == 0xbadf00d, "[%s] scope = 0x%08x, expected 0xbadf00d\n",
|
||||
+ ipv6_tests[i].address, scope);
|
||||
+ ok(port == 0xbeef, "[%s] port = 0x%08x, expected 0xbeef\n",
|
||||
+ ipv6_tests[i].address, port);
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ ok(scope != 0xbadf00d, "[%s] scope = 0x%08x, not expected 0xbadf00d\n",
|
||||
+ ipv6_tests[i].address, scope);
|
||||
+ ok(port != 0xbeef, "[%s] port = 0x%08x, not expected 0xbeef\n",
|
||||
+ ipv6_tests[i].address, port);
|
||||
+ }
|
||||
+
|
||||
+ if (ipv6_tests[i].flags & win_broken_6)
|
||||
+ {
|
||||
+ ok(res == expect_ret || broken(res == STATUS_INVALID_PARAMETER),
|
||||
+ "[%s] res = 0x%08x, expected 0x%08x\n", ipv6_tests[i].address, res, expect_ret);
|
||||
+
|
||||
+ if (res == STATUS_INVALID_PARAMETER)
|
||||
+ continue;
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ ok(res == expect_ret, "[%s] res = 0x%08x, expected 0x%08x\n",
|
||||
+ ipv6_tests[i].address, res, expect_ret);
|
||||
+ }
|
||||
+
|
||||
+ /* If ex fails but non-ex does not we cannot check if the part that is converted
|
||||
+ before it failed was correct, since there is no data for it in the table. */
|
||||
+ if (res == expect_ret)
|
||||
+ {
|
||||
+ init_ip6(&expected_ip, ipv6_tests[i].ip);
|
||||
+ ok(!memcmp(&ip, &expected_ip, sizeof(ip)),
|
||||
+ "[%s] ip = %x:%x:%x:%x:%x:%x:%x:%x, expected %x:%x:%x:%x:%x:%x:%x:%x\n",
|
||||
+ ipv6_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]);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ /* now we run scope / port related tests */
|
||||
+ for (i = 0; i < ipv6_ex_testcount; i++)
|
||||
+ {
|
||||
+ scope = 0xbadf00d;
|
||||
+ port = 0xbeef;
|
||||
+ init_ip6(&ip, NULL);
|
||||
+ res = pRtlIpv6StringToAddressExA(ipv6_ex_tests[i].address, &ip, &scope, &port);
|
||||
+ compare_RtlIpv6StringToAddressExW(ipv6_ex_tests[i].address, &ip, res, scope, port);
|
||||
+
|
||||
+ ok(res == ipv6_ex_tests[i].res, "[%s] res = 0x%08x, expected 0x%08x\n",
|
||||
+ ipv6_ex_tests[i].address, res, ipv6_ex_tests[i].res);
|
||||
+ ok(scope == ipv6_ex_tests[i].scope, "[%s] scope = 0x%08x, expected 0x%08x\n",
|
||||
+ ipv6_ex_tests[i].address, scope, ipv6_ex_tests[i].scope);
|
||||
+ ok(port == ipv6_ex_tests[i].port, "[%s] port = 0x%08x, expected 0x%08x\n",
|
||||
+ ipv6_ex_tests[i].address, port, ipv6_ex_tests[i].port);
|
||||
+
|
||||
+ init_ip6(&expected_ip, ipv6_ex_tests[i].ip);
|
||||
+ ok(!memcmp(&ip, &expected_ip, sizeof(ip)),
|
||||
+ "[%s] ip = %x:%x:%x:%x:%x:%x:%x:%x, expected %x:%x:%x:%x:%x:%x:%x:%x\n",
|
||||
+ ipv6_ex_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;
|
||||
@@ -2053,6 +2319,7 @@ START_TEST(rtl)
|
||||
test_RtlIpv4AddressToStringEx();
|
||||
test_RtlIpv4StringToAddress();
|
||||
test_RtlIpv6StringToAddress();
|
||||
+ test_RtlIpv6StringToAddressEx();
|
||||
test_LdrAddRefDll();
|
||||
test_LdrLockLoaderLock();
|
||||
}
|
||||
--
|
||||
2.3.1
|
||||
|
@@ -0,0 +1,456 @@
|
||||
From a2f2703bd49023e395090c6ed8b7b6d2e7722680 Mon Sep 17 00:00:00 2001
|
||||
From: Mark Jansen <learn0more+wine@gmail.com>
|
||||
Date: Sun, 8 Mar 2015 18:24:48 +0100
|
||||
Subject: ntdll/tests: Tests for RtlIpv4StringToAddressEx (try 5, resend)
|
||||
|
||||
Changes from try4:
|
||||
-Remove leftover comments
|
||||
|
||||
Changes from try3:
|
||||
-Test the ip against the non-ex version as suggested by stefand
|
||||
-Change strict_is_different to a flag
|
||||
-Add ipv4 init function to avoid code duplication
|
||||
---
|
||||
dlls/ntdll/tests/rtl.c | 371 ++++++++++++++++++++++++++++++++-----------------
|
||||
1 file changed, 247 insertions(+), 124 deletions(-)
|
||||
|
||||
diff --git a/dlls/ntdll/tests/rtl.c b/dlls/ntdll/tests/rtl.c
|
||||
index 5d789d1..79c4974 100644
|
||||
--- a/dlls/ntdll/tests/rtl.c
|
||||
+++ b/dlls/ntdll/tests/rtl.c
|
||||
@@ -90,6 +90,7 @@ 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 *pRtlIpv6StringToAddressW)(PCWSTR, PCWSTR *, struct in6_addr *);
|
||||
static NTSTATUS (WINAPI *pRtlIpv6StringToAddressExA)(PCSTR, struct in6_addr *, PULONG, PUSHORT);
|
||||
@@ -142,6 +143,7 @@ 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");
|
||||
pRtlIpv6StringToAddressW = (void *)GetProcAddress(hntdll, "RtlIpv6StringToAddressW");
|
||||
pRtlIpv6StringToAddressExA = (void *)GetProcAddress(hntdll, "RtlIpv6StringToAddressExA");
|
||||
@@ -1331,98 +1333,109 @@ static void test_RtlIpv4AddressToStringEx(void)
|
||||
res, size, buffer);
|
||||
}
|
||||
|
||||
+static struct
|
||||
+{
|
||||
+ PCSTR address;
|
||||
+ NTSTATUS res;
|
||||
+ int terminator_offset;
|
||||
+ int ip[4];
|
||||
+ enum { normal_4, strict_diff_4 = 1, ex_fail_4 = 2 } flags;
|
||||
+ NTSTATUS res_strict;
|
||||
+ int terminator_offset_strict;
|
||||
+ int ip_strict[4];
|
||||
+} ipv4_tests[] =
|
||||
+{
|
||||
+ { "", STATUS_INVALID_PARAMETER, 0, { -1 } },
|
||||
+ { " ", STATUS_INVALID_PARAMETER, 0, { -1 } },
|
||||
+ { "1.1.1.1", STATUS_SUCCESS, 7, { 1, 1, 1, 1 } },
|
||||
+ { "0.0.0.0", STATUS_SUCCESS, 7, { 0, 0, 0, 0 } },
|
||||
+ { "255.255.255.255", STATUS_SUCCESS, 15, { 255, 255, 255, 255 } },
|
||||
+ { "255.255.255.255:123", STATUS_SUCCESS, 15, { 255, 255, 255, 255 } },
|
||||
+ { "255.255.255.256", STATUS_INVALID_PARAMETER, 15, { -1 } },
|
||||
+ { "255.255.255.4294967295", STATUS_INVALID_PARAMETER, 22, { -1 } },
|
||||
+ { "255.255.255.4294967296", STATUS_INVALID_PARAMETER, 21, { -1 } },
|
||||
+ { "255.255.255.4294967297", STATUS_INVALID_PARAMETER, 21, { -1 } },
|
||||
+ { "a", STATUS_INVALID_PARAMETER, 0, { -1 } },
|
||||
+ { "1.1.1.0xaA", STATUS_SUCCESS, 10, { 1, 1, 1, 170 }, strict_diff_4,
|
||||
+ STATUS_INVALID_PARAMETER, 8, { -1 } },
|
||||
+ { "1.1.1.0XaA", STATUS_SUCCESS, 10, { 1, 1, 1, 170 }, strict_diff_4,
|
||||
+ STATUS_INVALID_PARAMETER, 8, { -1 } },
|
||||
+ { "1.1.1.0x", STATUS_INVALID_PARAMETER, 8, { -1 } },
|
||||
+ { "1.1.1.0xff", STATUS_SUCCESS, 10, { 1, 1, 1, 255 }, strict_diff_4,
|
||||
+ STATUS_INVALID_PARAMETER, 8, { -1 } },
|
||||
+ { "1.1.1.0x100", STATUS_INVALID_PARAMETER, 11, { -1 }, strict_diff_4,
|
||||
+ STATUS_INVALID_PARAMETER, 8, { -1 } },
|
||||
+ { "1.1.1.0xffffffff", STATUS_INVALID_PARAMETER, 16, { -1 }, strict_diff_4,
|
||||
+ STATUS_INVALID_PARAMETER, 8, { -1 } },
|
||||
+ { "1.1.1.0x100000000", STATUS_INVALID_PARAMETER, 16, { -1, 0, 0, 0 }, strict_diff_4,
|
||||
+ STATUS_INVALID_PARAMETER, 8, { -1 } },
|
||||
+ { "1.1.1.010", STATUS_SUCCESS, 9, { 1, 1, 1, 8 }, strict_diff_4,
|
||||
+ STATUS_INVALID_PARAMETER, 7, { -1 } },
|
||||
+ { "1.1.1.00", STATUS_SUCCESS, 8, { 1, 1, 1, 0 }, strict_diff_4,
|
||||
+ STATUS_INVALID_PARAMETER, 7, { -1 } },
|
||||
+ { "1.1.1.007", STATUS_SUCCESS, 9, { 1, 1, 1, 7 }, strict_diff_4,
|
||||
+ STATUS_INVALID_PARAMETER, 7, { -1 } },
|
||||
+ { "1.1.1.08", STATUS_INVALID_PARAMETER, 7, { -1 } },
|
||||
+ { "1.1.1.008", STATUS_SUCCESS, 8, { 1, 1, 1, 0 }, strict_diff_4 | ex_fail_4,
|
||||
+ STATUS_INVALID_PARAMETER, 7, { -1 } },
|
||||
+ { "1.1.1.0a", STATUS_SUCCESS, 7, { 1, 1, 1, 0 }, ex_fail_4 },
|
||||
+ { "1.1.1.0o10", STATUS_SUCCESS, 7, { 1, 1, 1, 0 }, ex_fail_4 },
|
||||
+ { "1.1.1.0b10", STATUS_SUCCESS, 7, { 1, 1, 1, 0 }, ex_fail_4 },
|
||||
+ { "1.1.1.-2", STATUS_INVALID_PARAMETER, 6, { -1 } },
|
||||
+ { "1", STATUS_SUCCESS, 1, { 0, 0, 0, 1 }, strict_diff_4,
|
||||
+ STATUS_INVALID_PARAMETER, 1, { -1 } },
|
||||
+ { "-1", STATUS_INVALID_PARAMETER, 0, { -1 } },
|
||||
+ { "203569230", STATUS_SUCCESS, 9, { 12, 34, 56, 78 }, strict_diff_4,
|
||||
+ STATUS_INVALID_PARAMETER, 9, { -1 } },
|
||||
+ { "1.223756", STATUS_SUCCESS, 8, { 1, 3, 106, 12 }, strict_diff_4,
|
||||
+ STATUS_INVALID_PARAMETER, 8, { -1 } },
|
||||
+ { "3.4.756", STATUS_SUCCESS, 7, { 3, 4, 2, 244 }, strict_diff_4,
|
||||
+ STATUS_INVALID_PARAMETER, 7, { -1 } },
|
||||
+ { "3.4.756.1", STATUS_INVALID_PARAMETER, 9, { -1 } },
|
||||
+ { "3.4.65536", STATUS_INVALID_PARAMETER, 9, { -1 } },
|
||||
+ { "3.4.5.6.7", STATUS_INVALID_PARAMETER, 7, { -1 } },
|
||||
+ { "3.4.5.+6", STATUS_INVALID_PARAMETER, 6, { -1 } },
|
||||
+ { " 3.4.5.6", STATUS_INVALID_PARAMETER, 0, { -1 } },
|
||||
+ { "\t3.4.5.6", STATUS_INVALID_PARAMETER, 0, { -1 } },
|
||||
+ { "3.4.5.6 ", STATUS_SUCCESS, 7, { 3, 4, 5, 6 }, ex_fail_4 },
|
||||
+ { "3. 4.5.6", STATUS_INVALID_PARAMETER, 2, { -1 } },
|
||||
+ { ".", STATUS_INVALID_PARAMETER, 1, { -1 } },
|
||||
+ { "..", STATUS_INVALID_PARAMETER, 1, { -1 } },
|
||||
+ { "1.", STATUS_INVALID_PARAMETER, 2, { -1 } },
|
||||
+ { "1..", STATUS_INVALID_PARAMETER, 3, { -1 } },
|
||||
+ { ".1", STATUS_INVALID_PARAMETER, 1, { -1 } },
|
||||
+ { ".1.", STATUS_INVALID_PARAMETER, 1, { -1 } },
|
||||
+ { ".1.2.3", STATUS_INVALID_PARAMETER, 1, { -1 } },
|
||||
+ { "0.1.2.3", STATUS_SUCCESS, 7, { 0, 1, 2, 3 } },
|
||||
+ { "0.1.2.3.", STATUS_INVALID_PARAMETER, 7, { -1 } },
|
||||
+ { "[0.1.2.3]", STATUS_INVALID_PARAMETER, 0, { -1 } },
|
||||
+ { "::1", STATUS_INVALID_PARAMETER, 0, { -1 } },
|
||||
+ { ":1", STATUS_INVALID_PARAMETER, 0, { -1 } },
|
||||
+};
|
||||
+const unsigned int ipv4_testcount = sizeof(ipv4_tests) / sizeof(ipv4_tests[0]);
|
||||
+
|
||||
+static void init_ip4(IN_ADDR* addr, const int src[4])
|
||||
+{
|
||||
+ if (!src || src[0] == -1)
|
||||
+ {
|
||||
+ addr->S_un.S_addr = 0xabababab;
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ addr->S_un.S_un_b.s_b1 = src[0];
|
||||
+ addr->S_un.S_un_b.s_b2 = src[1];
|
||||
+ addr->S_un.S_un_b.s_b3 = src[2];
|
||||
+ addr->S_un.S_un_b.s_b4 = src[3];
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
static void test_RtlIpv4StringToAddress(void)
|
||||
{
|
||||
NTSTATUS res;
|
||||
IN_ADDR ip, expected_ip;
|
||||
PCSTR terminator;
|
||||
CHAR dummy;
|
||||
- struct
|
||||
- {
|
||||
- PCSTR address;
|
||||
- NTSTATUS res;
|
||||
- int terminator_offset;
|
||||
- int ip[4];
|
||||
- BOOL strict_is_different;
|
||||
- NTSTATUS res_strict;
|
||||
- int terminator_offset_strict;
|
||||
- int ip_strict[4];
|
||||
- } tests[] =
|
||||
- {
|
||||
- { "", STATUS_INVALID_PARAMETER, 0, { -1 } },
|
||||
- { " ", STATUS_INVALID_PARAMETER, 0, { -1 } },
|
||||
- { "1.1.1.1", STATUS_SUCCESS, 7, { 1, 1, 1, 1 } },
|
||||
- { "0.0.0.0", STATUS_SUCCESS, 7, { 0, 0, 0, 0 } },
|
||||
- { "255.255.255.255", STATUS_SUCCESS, 15, { 255, 255, 255, 255 } },
|
||||
- { "255.255.255.255:123",
|
||||
- STATUS_SUCCESS, 15, { 255, 255, 255, 255 } },
|
||||
- { "255.255.255.256", STATUS_INVALID_PARAMETER, 15, { -1 } },
|
||||
- { "255.255.255.4294967295",
|
||||
- STATUS_INVALID_PARAMETER, 22, { -1 } },
|
||||
- { "255.255.255.4294967296",
|
||||
- STATUS_INVALID_PARAMETER, 21, { -1 } },
|
||||
- { "255.255.255.4294967297",
|
||||
- STATUS_INVALID_PARAMETER, 21, { -1 } },
|
||||
- { "a", STATUS_INVALID_PARAMETER, 0, { -1 } },
|
||||
- { "1.1.1.0xaA", STATUS_SUCCESS, 10, { 1, 1, 1, 170 },
|
||||
- TRUE, STATUS_INVALID_PARAMETER, 8, { -1 } },
|
||||
- { "1.1.1.0XaA", STATUS_SUCCESS, 10, { 1, 1, 1, 170 },
|
||||
- TRUE, STATUS_INVALID_PARAMETER, 8, { -1 } },
|
||||
- { "1.1.1.0x", STATUS_INVALID_PARAMETER, 8, { -1 } },
|
||||
- { "1.1.1.0xff", STATUS_SUCCESS, 10, { 1, 1, 1, 255 },
|
||||
- TRUE, STATUS_INVALID_PARAMETER, 8, { -1 } },
|
||||
- { "1.1.1.0x100", STATUS_INVALID_PARAMETER, 11, { -1 },
|
||||
- TRUE, STATUS_INVALID_PARAMETER, 8, { -1 } },
|
||||
- { "1.1.1.0xffffffff",STATUS_INVALID_PARAMETER, 16, { -1 },
|
||||
- TRUE, STATUS_INVALID_PARAMETER, 8, { -1 } },
|
||||
- { "1.1.1.0x100000000",
|
||||
- STATUS_INVALID_PARAMETER, 16, { -1, 0, 0, 0 },
|
||||
- TRUE, STATUS_INVALID_PARAMETER, 8, { -1 } },
|
||||
- { "1.1.1.010", STATUS_SUCCESS, 9, { 1, 1, 1, 8 },
|
||||
- TRUE, STATUS_INVALID_PARAMETER, 7, { -1 } },
|
||||
- { "1.1.1.00", STATUS_SUCCESS, 8, { 1, 1, 1, 0 },
|
||||
- TRUE, STATUS_INVALID_PARAMETER, 7, { -1 } },
|
||||
- { "1.1.1.007", STATUS_SUCCESS, 9, { 1, 1, 1, 7 },
|
||||
- TRUE, STATUS_INVALID_PARAMETER, 7, { -1 } },
|
||||
- { "1.1.1.08", STATUS_INVALID_PARAMETER, 7, { -1 } },
|
||||
- { "1.1.1.008", STATUS_SUCCESS, 8, { 1, 1, 1, 0 },
|
||||
- TRUE, STATUS_INVALID_PARAMETER, 7, { -1 } },
|
||||
- { "1.1.1.0a", STATUS_SUCCESS, 7, { 1, 1, 1, 0 } },
|
||||
- { "1.1.1.0o10", STATUS_SUCCESS, 7, { 1, 1, 1, 0 } },
|
||||
- { "1.1.1.0b10", STATUS_SUCCESS, 7, { 1, 1, 1, 0 } },
|
||||
- { "1.1.1.-2", STATUS_INVALID_PARAMETER, 6, { -1 } },
|
||||
- { "1", STATUS_SUCCESS, 1, { 0, 0, 0, 1 },
|
||||
- TRUE, STATUS_INVALID_PARAMETER, 1, { -1 } },
|
||||
- { "-1", STATUS_INVALID_PARAMETER, 0, { -1 } },
|
||||
- { "203569230", STATUS_SUCCESS, 9, { 12, 34, 56, 78 },
|
||||
- TRUE, STATUS_INVALID_PARAMETER, 9, { -1 } },
|
||||
- { "1.223756", STATUS_SUCCESS, 8, { 1, 3, 106, 12 },
|
||||
- TRUE, STATUS_INVALID_PARAMETER, 8, { -1 } },
|
||||
- { "3.4.756", STATUS_SUCCESS, 7, { 3, 4, 2, 244 },
|
||||
- TRUE, STATUS_INVALID_PARAMETER, 7, { -1 } },
|
||||
- { "3.4.756.1", STATUS_INVALID_PARAMETER, 9, { -1 } },
|
||||
- { "3.4.65536", STATUS_INVALID_PARAMETER, 9, { -1 } },
|
||||
- { "3.4.5.6.7", STATUS_INVALID_PARAMETER, 7, { -1 } },
|
||||
- { "3.4.5.+6", STATUS_INVALID_PARAMETER, 6, { -1 } },
|
||||
- { " 3.4.5.6", STATUS_INVALID_PARAMETER, 0, { -1 } },
|
||||
- { "\t3.4.5.6", STATUS_INVALID_PARAMETER, 0, { -1 } },
|
||||
- { "3.4.5.6 ", STATUS_SUCCESS, 7, { 3, 4, 5, 6 } },
|
||||
- { "3. 4.5.6", STATUS_INVALID_PARAMETER, 2, { -1 } },
|
||||
- { ".", STATUS_INVALID_PARAMETER, 1, { -1 } },
|
||||
- { "..", STATUS_INVALID_PARAMETER, 1, { -1 } },
|
||||
- { "1.", STATUS_INVALID_PARAMETER, 2, { -1 } },
|
||||
- { "1..", STATUS_INVALID_PARAMETER, 3, { -1 } },
|
||||
- { ".1", STATUS_INVALID_PARAMETER, 1, { -1 } },
|
||||
- { ".1.", STATUS_INVALID_PARAMETER, 1, { -1 } },
|
||||
- { ".1.2.3", STATUS_INVALID_PARAMETER, 1, { -1 } },
|
||||
- { "0.1.2.3", STATUS_SUCCESS, 7, { 0, 1, 2, 3 } },
|
||||
- { "0.1.2.3.", STATUS_INVALID_PARAMETER, 7, { -1 } },
|
||||
- { "[0.1.2.3]", STATUS_INVALID_PARAMETER, 0, { -1 } },
|
||||
- { "::1", STATUS_INVALID_PARAMETER, 0, { -1 } },
|
||||
- { ":1", STATUS_INVALID_PARAMETER, 0, { -1 } },
|
||||
- };
|
||||
- const int testcount = sizeof(tests) / sizeof(tests[0]);
|
||||
- int i;
|
||||
+ unsigned int i;
|
||||
|
||||
if (!pRtlIpv4StringToAddressA)
|
||||
{
|
||||
@@ -1444,65 +1457,174 @@ static void test_RtlIpv4StringToAddress(void)
|
||||
*/
|
||||
}
|
||||
|
||||
- for (i = 0; i < testcount; i++)
|
||||
+ for (i = 0; i < ipv4_testcount; i++)
|
||||
{
|
||||
/* non-strict */
|
||||
terminator = &dummy;
|
||||
ip.S_un.S_addr = 0xabababab;
|
||||
- res = pRtlIpv4StringToAddressA(tests[i].address, FALSE, &terminator, &ip);
|
||||
- ok(res == tests[i].res,
|
||||
+ res = pRtlIpv4StringToAddressA(ipv4_tests[i].address, FALSE, &terminator, &ip);
|
||||
+ ok(res == ipv4_tests[i].res,
|
||||
"[%s] res = 0x%08x, expected 0x%08x\n",
|
||||
- tests[i].address, res, tests[i].res);
|
||||
- ok(terminator == tests[i].address + tests[i].terminator_offset,
|
||||
+ ipv4_tests[i].address, res, ipv4_tests[i].res);
|
||||
+ ok(terminator == ipv4_tests[i].address + ipv4_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)
|
||||
- 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];
|
||||
- }
|
||||
+ ipv4_tests[i].address, terminator, ipv4_tests[i].address + ipv4_tests[i].terminator_offset);
|
||||
+
|
||||
+ init_ip4(&expected_ip, ipv4_tests[i].ip);
|
||||
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);
|
||||
+ ipv4_tests[i].address, ip.S_un.S_addr, expected_ip.S_un.S_addr);
|
||||
|
||||
- if (!tests[i].strict_is_different)
|
||||
+ if (!(ipv4_tests[i].flags & strict_diff_4))
|
||||
{
|
||||
- tests[i].res_strict = tests[i].res;
|
||||
- tests[i].terminator_offset_strict = tests[i].terminator_offset;
|
||||
- tests[i].ip_strict[0] = tests[i].ip[0];
|
||||
- tests[i].ip_strict[1] = tests[i].ip[1];
|
||||
- tests[i].ip_strict[2] = tests[i].ip[2];
|
||||
- tests[i].ip_strict[3] = tests[i].ip[3];
|
||||
+ ipv4_tests[i].res_strict = ipv4_tests[i].res;
|
||||
+ ipv4_tests[i].terminator_offset_strict = ipv4_tests[i].terminator_offset;
|
||||
+ ipv4_tests[i].ip_strict[0] = ipv4_tests[i].ip[0];
|
||||
+ ipv4_tests[i].ip_strict[1] = ipv4_tests[i].ip[1];
|
||||
+ ipv4_tests[i].ip_strict[2] = ipv4_tests[i].ip[2];
|
||||
+ ipv4_tests[i].ip_strict[3] = ipv4_tests[i].ip[3];
|
||||
}
|
||||
/* strict */
|
||||
terminator = &dummy;
|
||||
ip.S_un.S_addr = 0xabababab;
|
||||
- res = pRtlIpv4StringToAddressA(tests[i].address, TRUE, &terminator, &ip);
|
||||
- ok(res == tests[i].res_strict,
|
||||
+ res = pRtlIpv4StringToAddressA(ipv4_tests[i].address, TRUE, &terminator, &ip);
|
||||
+ ok(res == ipv4_tests[i].res_strict,
|
||||
"[%s] res = 0x%08x, expected 0x%08x\n",
|
||||
- tests[i].address, res, tests[i].res_strict);
|
||||
- ok(terminator == tests[i].address + tests[i].terminator_offset_strict,
|
||||
+ ipv4_tests[i].address, res, ipv4_tests[i].res_strict);
|
||||
+ ok(terminator == ipv4_tests[i].address + ipv4_tests[i].terminator_offset_strict,
|
||||
"[%s] terminator = %p, expected %p\n",
|
||||
- tests[i].address, terminator, tests[i].address + tests[i].terminator_offset_strict);
|
||||
- if (tests[i].ip_strict[0] == -1)
|
||||
- expected_ip.S_un.S_addr = 0xabababab;
|
||||
- else
|
||||
- {
|
||||
- expected_ip.S_un.S_un_b.s_b1 = tests[i].ip_strict[0];
|
||||
- expected_ip.S_un.S_un_b.s_b2 = tests[i].ip_strict[1];
|
||||
- expected_ip.S_un.S_un_b.s_b3 = tests[i].ip_strict[2];
|
||||
- expected_ip.S_un.S_un_b.s_b4 = tests[i].ip_strict[3];
|
||||
- }
|
||||
+ ipv4_tests[i].address, terminator, ipv4_tests[i].address + ipv4_tests[i].terminator_offset_strict);
|
||||
+
|
||||
+ init_ip4(&expected_ip, ipv4_tests[i].ip_strict);
|
||||
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);
|
||||
+ ipv4_tests[i].address, ip.S_un.S_addr, expected_ip.S_un.S_addr);
|
||||
}
|
||||
}
|
||||
|
||||
+static void test_RtlIpv4StringToAddressEx(void)
|
||||
+{
|
||||
+ NTSTATUS res;
|
||||
+ IN_ADDR ip, expected_ip;
|
||||
+ USHORT port;
|
||||
+ static const struct
|
||||
+ {
|
||||
+ PCSTR address;
|
||||
+ NTSTATUS res;
|
||||
+ int ip[4];
|
||||
+ USHORT port;
|
||||
+ } ipv4_ex_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 },
|
||||
+ { "256.1.1.1:1", STATUS_INVALID_PARAMETER, { -1 }, 0xdead },
|
||||
+ { "-1.1.1.1:1", STATUS_INVALID_PARAMETER, { -1 }, 0xdead },
|
||||
+ { "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 unsigned int ipv4_ex_testcount = sizeof(ipv4_ex_tests) / sizeof(ipv4_ex_tests[0]);
|
||||
+ unsigned int i;
|
||||
+ BOOLEAN 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);
|
||||
+
|
||||
+ /* first we run the non-ex testcases on the ex function */
|
||||
+ for (i = 0; i < ipv4_testcount; i++)
|
||||
+ {
|
||||
+ NTSTATUS expect_res = (ipv4_tests[i].flags & ex_fail_4) ? STATUS_INVALID_PARAMETER : ipv4_tests[i].res;
|
||||
+
|
||||
+ /* non-strict */
|
||||
+ port = 0xdead;
|
||||
+ ip.S_un.S_addr = 0xabababab;
|
||||
+ res = pRtlIpv4StringToAddressExA(ipv4_tests[i].address, FALSE, &ip, &port);
|
||||
+ ok(res == expect_res, "[%s] res = 0x%08x, expected 0x%08x\n",
|
||||
+ ipv4_tests[i].address, res, expect_res);
|
||||
+
|
||||
+ init_ip4(&expected_ip, ipv4_tests[i].ip);
|
||||
+ ok(ip.S_un.S_addr == expected_ip.S_un.S_addr, "[%s] ip = %08x, expected %08x\n",
|
||||
+ ipv4_tests[i].address, ip.S_un.S_addr, expected_ip.S_un.S_addr);
|
||||
+
|
||||
+ if (!(ipv4_tests[i].flags & strict_diff_4))
|
||||
+ {
|
||||
+ ipv4_tests[i].res_strict = ipv4_tests[i].res;
|
||||
+ ipv4_tests[i].terminator_offset_strict = ipv4_tests[i].terminator_offset;
|
||||
+ ipv4_tests[i].ip_strict[0] = ipv4_tests[i].ip[0];
|
||||
+ ipv4_tests[i].ip_strict[1] = ipv4_tests[i].ip[1];
|
||||
+ ipv4_tests[i].ip_strict[2] = ipv4_tests[i].ip[2];
|
||||
+ ipv4_tests[i].ip_strict[3] = ipv4_tests[i].ip[3];
|
||||
+ }
|
||||
+ /* strict */
|
||||
+ expect_res = (ipv4_tests[i].flags & ex_fail_4) ? STATUS_INVALID_PARAMETER : ipv4_tests[i].res_strict;
|
||||
+ port = 0xdead;
|
||||
+ ip.S_un.S_addr = 0xabababab;
|
||||
+ res = pRtlIpv4StringToAddressExA(ipv4_tests[i].address, TRUE, &ip, &port);
|
||||
+ ok(res == expect_res, "[%s] res = 0x%08x, expected 0x%08x\n",
|
||||
+ ipv4_tests[i].address, res, expect_res);
|
||||
+
|
||||
+ init_ip4(&expected_ip, ipv4_tests[i].ip_strict);
|
||||
+ ok(ip.S_un.S_addr == expected_ip.S_un.S_addr, "[%s] ip = %08x, expected %08x\n",
|
||||
+ ipv4_tests[i].address, ip.S_un.S_addr, expected_ip.S_un.S_addr);
|
||||
+ }
|
||||
+
|
||||
+
|
||||
+ for (i = 0; i < ipv4_ex_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(ipv4_ex_tests[i].address, strict, &ip, &port);
|
||||
+ ok(res == ipv4_ex_tests[i].res, "[%s] res = 0x%08x, expected 0x%08x\n",
|
||||
+ ipv4_ex_tests[i].address, res, ipv4_ex_tests[i].res);
|
||||
+
|
||||
+ init_ip4(&expected_ip, ipv4_ex_tests[i].ip);
|
||||
+ ok(ip.S_un.S_addr == expected_ip.S_un.S_addr, "[%s] ip = %08x, expected %08x\n",
|
||||
+ ipv4_ex_tests[i].address, ip.S_un.S_addr, expected_ip.S_un.S_addr);
|
||||
+ ok(port == ipv4_ex_tests[i].port, "[%s] port = %u, expected %u\n",
|
||||
+ ipv4_ex_tests[i].address, port, ipv4_ex_tests[i].port);
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
|
||||
/* ipv6 addresses based on the set from https://github.com/beaugunderson/javascript-ipv6/tree/master/test/data */
|
||||
static const struct
|
||||
@@ -2318,6 +2440,7 @@ START_TEST(rtl)
|
||||
test_RtlIpv4AddressToString();
|
||||
test_RtlIpv4AddressToStringEx();
|
||||
test_RtlIpv4StringToAddress();
|
||||
+ test_RtlIpv4StringToAddressEx();
|
||||
test_RtlIpv6StringToAddress();
|
||||
test_RtlIpv6StringToAddressEx();
|
||||
test_LdrAddRefDll();
|
||||
--
|
||||
2.3.1
|
||||
|
Reference in New Issue
Block a user