[PATCH 1/3] ntdll/tests: Add tests for RtlIpv4StringToAddressEx (try 3)
Mark Jansen
learn0more+wine at gmail.com
Thu Feb 19 16:37:37 CST 2015
---
dlls/ntdll/tests/rtl.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 103 insertions(+)
-------------- next part --------------
From 32b2b02580cf33c6903ac9a9f30664c4ed241128 Mon Sep 17 00:00:00 2001
From: Mark Jansen <learn0more+wine at gmail.com>
Date: Sun, 15 Feb 2015 16:16:03 +0100
Subject: [PATCH 1/3] Add test for RtlIpv4StringToAddressEx
---
dlls/ntdll/tests/rtl.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 103 insertions(+)
diff --git a/dlls/ntdll/tests/rtl.c b/dlls/ntdll/tests/rtl.c
index e8eb04a..8fdd80d 100644
--- a/dlls/ntdll/tests/rtl.c
+++ b/dlls/ntdll/tests/rtl.c
@@ -89,6 +89,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 *pLdrAddRefDll)(ULONG, HMODULE);
static NTSTATUS (WINAPI *pLdrLockLoaderLock)(ULONG, ULONG*, ULONG_PTR*);
static NTSTATUS (WINAPI *pLdrUnlockLoaderLock)(ULONG, ULONG_PTR);
@@ -136,6 +137,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");
pLdrAddRefDll = (void *)GetProcAddress(hntdll, "LdrAddRefDll");
pLdrLockLoaderLock = (void *)GetProcAddress(hntdll, "LdrLockLoaderLock");
pLdrUnlockLoaderLock = (void *)GetProcAddress(hntdll, "LdrUnlockLoaderLock");
@@ -1492,6 +1494,106 @@ static void test_RtlIpv4StringToAddress(void)
}
}
+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;
+ } 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 testcount = sizeof(tests) / sizeof(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);
+
+ 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);
+ }
+ }
+}
+
static void test_LdrAddRefDll(void)
{
HMODULE mod, mod2;
@@ -1623,6 +1725,7 @@ START_TEST(rtl)
test_RtlIpv4AddressToString();
test_RtlIpv4AddressToStringEx();
test_RtlIpv4StringToAddress();
+ test_RtlIpv4StringToAddressEx();
test_LdrAddRefDll();
test_LdrLockLoaderLock();
}
--
1.8.3.msysgit.0
More information about the wine-patches
mailing list