https://git.reactos.org/?p=reactos.git;a=commitdiff;h=ec605e913847bfc228712…
commit ec605e913847bfc228712c637bac3997d96923e3
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Tue Nov 27 21:25:23 2018 +0100
Commit: Pierre Schweitzer <pierre(a)reactos.org>
CommitDate: Tue Nov 27 21:36:48 2018 +0100
[IPHLPAPI_APITEST] Add tests for AllocateAndGetTcpExTable2FromStack()
---
.../iphlpapi/AllocateAndGetTcpExTable2FromStack.c | 351 +++++++++++++++++++++
modules/rostests/apitests/iphlpapi/CMakeLists.txt | 3 +-
modules/rostests/apitests/iphlpapi/testlist.c | 10 +-
3 files changed, 359 insertions(+), 5 deletions(-)
diff --git a/modules/rostests/apitests/iphlpapi/AllocateAndGetTcpExTable2FromStack.c
b/modules/rostests/apitests/iphlpapi/AllocateAndGetTcpExTable2FromStack.c
new file mode 100644
index 0000000000..002d7d1909
--- /dev/null
+++ b/modules/rostests/apitests/iphlpapi/AllocateAndGetTcpExTable2FromStack.c
@@ -0,0 +1,351 @@
+/*
+ * PROJECT: ReactOS API Tests
+ * LICENSE: GPL-2.0+ (
https://spdx.org/licenses/GPL-2.0+)
+ * PURPOSE: Tests for TCP connections enumeration functions
+ * COPYRIGHT: Copyright 2018 Pierre Schweitzer
+ */
+
+#include <apitest.h>
+
+#define WIN32_NO_STATUS
+#include <iphlpapi.h>
+#include <winsock2.h>
+
+static DWORD (WINAPI *
pAllocateAndGetTcpExTable2FromStack)(PVOID*,BOOL,HANDLE,DWORD,DWORD,TCP_TABLE_CLASS);
+
+START_TEST(AllocateAndGetTcpExTable2FromStack)
+{
+ WSADATA wsaData;
+ SOCKET sock;
+ SOCKADDR_IN server;
+ PMIB_TCPTABLE TcpTable;
+ PMIB_TCPTABLE_OWNER_PID TcpTableOwner;
+ PMIB_TCPTABLE_OWNER_MODULE TcpTableOwnerMod;
+ DWORD i;
+ BOOLEAN Found;
+ HINSTANCE hIpHlpApi;
+ SYSTEMTIME Creation;
+ DWORD Pid = GetCurrentProcessId();
+
+ hIpHlpApi = GetModuleHandleW(L"iphlpapi.dll");
+ if (!hIpHlpApi)
+ {
+ skip("Failed to load iphlpapi.dll\n");
+ return;
+ }
+
+ pAllocateAndGetTcpExTable2FromStack = (void *)GetProcAddress(hIpHlpApi,
"AllocateAndGetTcpExTable2FromStack");
+ if (pAllocateAndGetTcpExTable2FromStack == NULL)
+ {
+ skip("AllocateAndGetTcpExTable2FromStack not found\n");
+ return;
+ }
+
+ if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
+ {
+ skip("Failed to init WS2\n");
+ return;
+ }
+
+ GetSystemTime(&Creation);
+
+ sock = socket(AF_INET, SOCK_STREAM, 0);
+ if (sock == INVALID_SOCKET)
+ {
+ skip("Cannot create socket\n");
+ goto quit;
+ }
+
+ ZeroMemory(&server, sizeof(SOCKADDR_IN));
+ server.sin_family = AF_INET;
+ server.sin_addr.s_addr = htonl(INADDR_ANY);
+ server.sin_port = htons(9876);
+
+ if (bind(sock, (SOCKADDR*)&server, sizeof(SOCKADDR_IN)) == SOCKET_ERROR)
+ {
+ skip("Cannot bind socket\n");
+ goto quit2;
+ }
+
+ if (listen(sock, SOMAXCONN) == SOCKET_ERROR)
+ {
+ skip("Cannot listen on socket\n");
+ goto quit2;
+ }
+
+ if (pAllocateAndGetTcpExTable2FromStack((PVOID *)&TcpTable, TRUE,
GetProcessHeap(), 0, AF_INET, TCP_TABLE_BASIC_ALL) == ERROR_SUCCESS)
+ {
+ ok(TcpTable->dwNumEntries > 0, "No TCP connections?!\n");
+
+ Found = FALSE;
+ for (i = 0; i < TcpTable->dwNumEntries; ++i)
+ {
+ if (TcpTable->table[i].dwState == MIB_TCP_STATE_LISTEN &&
+ TcpTable->table[i].dwLocalAddr == 0 &&
+ TcpTable->table[i].dwLocalPort == htons(9876) &&
+ TcpTable->table[i].dwRemoteAddr == 0)
+ {
+ Found = TRUE;
+ break;
+ }
+ }
+ ok(Found, "Our socket wasn't found!\n");
+
+ HeapFree(GetProcessHeap(), 0, TcpTable);
+ }
+ else
+ {
+ skip("AllocateAndGetTcpExTable2FromStack failure\n");
+ }
+
+ if (pAllocateAndGetTcpExTable2FromStack((PVOID *)&TcpTable, TRUE,
GetProcessHeap(), 0, AF_INET, TCP_TABLE_BASIC_CONNECTIONS) == ERROR_SUCCESS)
+ {
+ Found = FALSE;
+ for (i = 0; i < TcpTable->dwNumEntries; ++i)
+ {
+ if (TcpTable->table[i].dwState == MIB_TCP_STATE_LISTEN &&
+ TcpTable->table[i].dwLocalAddr == 0 &&
+ TcpTable->table[i].dwLocalPort == htons(9876) &&
+ TcpTable->table[i].dwRemoteAddr == 0)
+ {
+ Found = TRUE;
+ break;
+ }
+ }
+ ok(Found == FALSE, "Our socket was found!\n");
+
+ HeapFree(GetProcessHeap(), 0, TcpTable);
+ }
+ else
+ {
+ skip("AllocateAndGetTcpExTable2FromStack failure\n");
+ }
+
+ if (pAllocateAndGetTcpExTable2FromStack((PVOID *)&TcpTable, TRUE,
GetProcessHeap(), 0, AF_INET, TCP_TABLE_BASIC_LISTENER) == ERROR_SUCCESS)
+ {
+ ok(TcpTable->dwNumEntries > 0, "No TCP connections?!\n");
+
+ Found = FALSE;
+ for (i = 0; i < TcpTable->dwNumEntries; ++i)
+ {
+ if (TcpTable->table[i].dwState == MIB_TCP_STATE_LISTEN &&
+ TcpTable->table[i].dwLocalAddr == 0 &&
+ TcpTable->table[i].dwLocalPort == htons(9876) &&
+ TcpTable->table[i].dwRemoteAddr == 0)
+ {
+ Found = TRUE;
+ break;
+ }
+ }
+ ok(Found, "Our socket wasn't found!\n");
+
+ HeapFree(GetProcessHeap(), 0, TcpTable);
+ }
+ else
+ {
+ skip("AllocateAndGetTcpExTable2FromStack failure\n");
+ }
+
+ if (pAllocateAndGetTcpExTable2FromStack((PVOID *)&TcpTableOwner, TRUE,
GetProcessHeap(), 0, AF_INET, TCP_TABLE_OWNER_PID_ALL) == ERROR_SUCCESS)
+ {
+ ok(TcpTableOwner->dwNumEntries > 0, "No TCP connections?!\n");
+
+ Found = FALSE;
+ for (i = 0; i < TcpTableOwner->dwNumEntries; ++i)
+ {
+ if (TcpTableOwner->table[i].dwState == MIB_TCP_STATE_LISTEN &&
+ TcpTableOwner->table[i].dwLocalAddr == 0 &&
+ TcpTableOwner->table[i].dwLocalPort == htons(9876) &&
+ TcpTableOwner->table[i].dwRemoteAddr == 0)
+ {
+ Found = TRUE;
+ break;
+ }
+ }
+
+ if (!Found)
+ {
+ skip("Our socket wasn't found!\n");
+ }
+ else
+ {
+ ok(TcpTableOwner->table[i].dwOwningPid == Pid, "Invalid
owner\n");
+ }
+
+ HeapFree(GetProcessHeap(), 0, TcpTableOwner);
+ }
+ else
+ {
+ skip("AllocateAndGetTcpExTable2FromStack failure\n");
+ }
+
+ if (pAllocateAndGetTcpExTable2FromStack((PVOID *)&TcpTableOwner, TRUE,
GetProcessHeap(), 0, AF_INET, TCP_TABLE_OWNER_PID_CONNECTIONS) == ERROR_SUCCESS)
+ {
+ Found = FALSE;
+ for (i = 0; i < TcpTableOwner->dwNumEntries; ++i)
+ {
+ if (TcpTableOwner->table[i].dwState == MIB_TCP_STATE_LISTEN &&
+ TcpTableOwner->table[i].dwLocalAddr == 0 &&
+ TcpTableOwner->table[i].dwLocalPort == htons(9876) &&
+ TcpTableOwner->table[i].dwRemoteAddr == 0)
+ {
+ Found = TRUE;
+ break;
+ }
+ }
+ ok(Found == FALSE, "Our socket was found!\n");
+
+ HeapFree(GetProcessHeap(), 0, TcpTableOwner);
+ }
+ else
+ {
+ skip("AllocateAndGetTcpExTable2FromStack failure\n");
+ }
+
+ if (pAllocateAndGetTcpExTable2FromStack((PVOID *)&TcpTableOwner, TRUE,
GetProcessHeap(), 0, AF_INET, TCP_TABLE_OWNER_PID_LISTENER) == ERROR_SUCCESS)
+ {
+ ok(TcpTableOwner->dwNumEntries > 0, "No TCP connections?!\n");
+
+ Found = FALSE;
+ for (i = 0; i < TcpTableOwner->dwNumEntries; ++i)
+ {
+ if (TcpTableOwner->table[i].dwState == MIB_TCP_STATE_LISTEN &&
+ TcpTableOwner->table[i].dwLocalAddr == 0 &&
+ TcpTableOwner->table[i].dwLocalPort == htons(9876) &&
+ TcpTableOwner->table[i].dwRemoteAddr == 0)
+ {
+ Found = TRUE;
+ break;
+ }
+ }
+
+ if (!Found)
+ {
+ skip("Our socket wasn't found!\n");
+ }
+ else
+ {
+ ok(TcpTableOwner->table[i].dwOwningPid == Pid, "Invalid
owner\n");
+ }
+
+ HeapFree(GetProcessHeap(), 0, TcpTableOwner);
+ }
+ else
+ {
+ skip("AllocateAndGetTcpExTable2FromStack failure\n");
+ }
+
+ if (pAllocateAndGetTcpExTable2FromStack((PVOID *)&TcpTableOwnerMod, TRUE,
GetProcessHeap(), 0, AF_INET, TCP_TABLE_OWNER_MODULE_ALL) == ERROR_SUCCESS)
+ {
+ ok(TcpTableOwnerMod->dwNumEntries > 0, "No TCP
connections?!\n");
+
+ Found = FALSE;
+ for (i = 0; i < TcpTableOwnerMod->dwNumEntries; ++i)
+ {
+ if (TcpTableOwnerMod->table[i].dwState == MIB_TCP_STATE_LISTEN &&
+ TcpTableOwnerMod->table[i].dwLocalAddr == 0 &&
+ TcpTableOwnerMod->table[i].dwLocalPort == htons(9876) &&
+ TcpTableOwnerMod->table[i].dwRemoteAddr == 0)
+ {
+ Found = TRUE;
+ break;
+ }
+ }
+
+ if (!Found)
+ {
+ skip("Our socket wasn't found!\n");
+ }
+ else
+ {
+ SYSTEMTIME SockTime;
+
+ ok(TcpTableOwnerMod->table[i].dwOwningPid == Pid, "Invalid
owner\n");
+
+ CopyMemory(&SockTime,
&TcpTableOwnerMod->table[i].liCreateTimestamp, sizeof(SYSTEMTIME));
+ ok(Creation.wYear == SockTime.wYear, "Invalid year\n");
+ ok(Creation.wMonth == SockTime.wMonth, "Invalid month\n");
+ ok(Creation.wDayOfWeek == SockTime.wDayOfWeek, "Invalid day of
week\n");
+ ok(Creation.wDay == SockTime.wDay, "Invalid day\n");
+ ok(Creation.wHour == SockTime.wHour, "Invalid hour\n");
+ ok(Creation.wMinute == SockTime.wMinute, "Invalid minute\n");
+ }
+
+ HeapFree(GetProcessHeap(), 0, TcpTableOwnerMod);
+ }
+ else
+ {
+ skip("AllocateAndGetTcpExTable2FromStack failure\n");
+ }
+
+ if (pAllocateAndGetTcpExTable2FromStack((PVOID *)&TcpTableOwnerMod, TRUE,
GetProcessHeap(), 0, AF_INET, TCP_TABLE_OWNER_MODULE_CONNECTIONS) == ERROR_SUCCESS)
+ {
+ Found = FALSE;
+ for (i = 0; i < TcpTableOwnerMod->dwNumEntries; ++i)
+ {
+ if (TcpTableOwnerMod->table[i].dwState == MIB_TCP_STATE_LISTEN &&
+ TcpTableOwnerMod->table[i].dwLocalAddr == 0 &&
+ TcpTableOwnerMod->table[i].dwLocalPort == htons(9876) &&
+ TcpTableOwnerMod->table[i].dwRemoteAddr == 0)
+ {
+ Found = TRUE;
+ break;
+ }
+ }
+ ok(Found == FALSE, "Our socket was found!\n");
+
+ HeapFree(GetProcessHeap(), 0, TcpTableOwnerMod);
+ }
+ else
+ {
+ skip("AllocateAndGetTcpExTable2FromStack failure\n");
+ }
+
+ if (pAllocateAndGetTcpExTable2FromStack((PVOID *)&TcpTableOwnerMod, TRUE,
GetProcessHeap(), 0, AF_INET, TCP_TABLE_OWNER_MODULE_LISTENER) == ERROR_SUCCESS)
+ {
+ ok(TcpTableOwnerMod->dwNumEntries > 0, "No TCP
connections?!\n");
+
+ Found = FALSE;
+ for (i = 0; i < TcpTableOwnerMod->dwNumEntries; ++i)
+ {
+ if (TcpTableOwnerMod->table[i].dwState == MIB_TCP_STATE_LISTEN &&
+ TcpTableOwnerMod->table[i].dwLocalAddr == 0 &&
+ TcpTableOwnerMod->table[i].dwLocalPort == htons(9876) &&
+ TcpTableOwnerMod->table[i].dwRemoteAddr == 0)
+ {
+ Found = TRUE;
+ break;
+ }
+ }
+
+ if (!Found)
+ {
+ skip("Our socket wasn't found!\n");
+ }
+ else
+ {
+ SYSTEMTIME SockTime;
+
+ ok(TcpTableOwnerMod->table[i].dwOwningPid == Pid, "Invalid
owner\n");
+
+ CopyMemory(&SockTime,
&TcpTableOwnerMod->table[i].liCreateTimestamp, sizeof(SYSTEMTIME));
+ ok(Creation.wYear == SockTime.wYear, "Invalid year\n");
+ ok(Creation.wMonth == SockTime.wMonth, "Invalid month\n");
+ ok(Creation.wDayOfWeek == SockTime.wDayOfWeek, "Invalid day of
week\n");
+ ok(Creation.wDay == SockTime.wDay, "Invalid day\n");
+ ok(Creation.wHour == SockTime.wHour, "Invalid hour\n");
+ ok(Creation.wMinute == SockTime.wMinute, "Invalid minute\n");
+ }
+
+ HeapFree(GetProcessHeap(), 0, TcpTableOwnerMod);
+ }
+ else
+ {
+ skip("AllocateAndGetTcpExTable2FromStack failure\n");
+ }
+
+quit2:
+ closesocket(sock);
+quit:
+ WSACleanup();
+}
diff --git a/modules/rostests/apitests/iphlpapi/CMakeLists.txt
b/modules/rostests/apitests/iphlpapi/CMakeLists.txt
index 2a5a3ad754..8e59d25643 100644
--- a/modules/rostests/apitests/iphlpapi/CMakeLists.txt
+++ b/modules/rostests/apitests/iphlpapi/CMakeLists.txt
@@ -1,5 +1,6 @@
list(APPEND SOURCE
+ AllocateAndGetTcpExTable2FromStack.c
GetInterfaceName.c
GetNetworkParams.c
icmp.c
@@ -9,5 +10,5 @@ list(APPEND SOURCE
add_executable(iphlpapi_apitest ${SOURCE})
target_link_libraries(iphlpapi_apitest wine ${PSEH_LIB})
set_module_type(iphlpapi_apitest win32cui)
-add_importlibs(iphlpapi_apitest iphlpapi advapi32 msvcrt kernel32 ntdll)
+add_importlibs(iphlpapi_apitest iphlpapi ws2_32 advapi32 msvcrt kernel32 ntdll)
add_rostests_file(TARGET iphlpapi_apitest)
diff --git a/modules/rostests/apitests/iphlpapi/testlist.c
b/modules/rostests/apitests/iphlpapi/testlist.c
index 942004df68..78843f5b5e 100644
--- a/modules/rostests/apitests/iphlpapi/testlist.c
+++ b/modules/rostests/apitests/iphlpapi/testlist.c
@@ -3,6 +3,7 @@
#define STANDALONE
#include <apitest.h>
+extern void func_AllocateAndGetTcpExTable2FromStack(void);
extern void func_GetInterfaceName(void);
extern void func_GetNetworkParams(void);
extern void func_icmp(void);
@@ -10,10 +11,11 @@ extern void func_SendARP(void);
const struct test winetest_testlist[] =
{
- { "GetInterfaceName", func_GetInterfaceName },
- { "GetNetworkParams", func_GetNetworkParams },
- { "icmp", func_icmp },
- { "SendARP", func_SendARP },
+ { "AllocateAndGetTcpExTable2FromStack",
func_AllocateAndGetTcpExTable2FromStack },
+ { "GetInterfaceName", func_GetInterfaceName },
+ { "GetNetworkParams", func_GetNetworkParams },
+ { "icmp", func_icmp },
+ { "SendARP", func_SendARP },
{ 0, 0 }
};