From 1e9fb35fbc0dc50c99b36816e40154875f822809 Mon Sep 17 00:00:00 2001 From: Pierre Schweitzer Date: Thu, 29 Nov 2018 08:42:13 +0100 Subject: [PATCH] [IPHLPAPI_APITEST] Test GetExtendedTcpTable rather than AllocateAndGetTcpExTable2FromStack --- .../rostests/apitests/iphlpapi/CMakeLists.txt | 2 +- ...able2FromStack.c => GetExtendedTcpTable.c} | 80 +++++++++++-------- modules/rostests/apitests/iphlpapi/testlist.c | 12 +-- 3 files changed, 52 insertions(+), 42 deletions(-) rename modules/rostests/apitests/iphlpapi/{AllocateAndGetTcpExTable2FromStack.c => GetExtendedTcpTable.c} (76%) diff --git a/modules/rostests/apitests/iphlpapi/CMakeLists.txt b/modules/rostests/apitests/iphlpapi/CMakeLists.txt index 8e59d256436..23b82189725 100644 --- a/modules/rostests/apitests/iphlpapi/CMakeLists.txt +++ b/modules/rostests/apitests/iphlpapi/CMakeLists.txt @@ -1,6 +1,6 @@ list(APPEND SOURCE - AllocateAndGetTcpExTable2FromStack.c + GetExtendedTcpTable.c GetInterfaceName.c GetNetworkParams.c icmp.c diff --git a/modules/rostests/apitests/iphlpapi/AllocateAndGetTcpExTable2FromStack.c b/modules/rostests/apitests/iphlpapi/GetExtendedTcpTable.c similarity index 76% rename from modules/rostests/apitests/iphlpapi/AllocateAndGetTcpExTable2FromStack.c rename to modules/rostests/apitests/iphlpapi/GetExtendedTcpTable.c index 1f49664fc1d..3beda7e8fdb 100644 --- a/modules/rostests/apitests/iphlpapi/AllocateAndGetTcpExTable2FromStack.c +++ b/modules/rostests/apitests/iphlpapi/GetExtendedTcpTable.c @@ -11,9 +11,34 @@ #include #include -static DWORD (WINAPI * pAllocateAndGetTcpExTable2FromStack)(PVOID*,BOOL,HANDLE,DWORD,DWORD,TCP_TABLE_CLASS); +DWORD GetExtendedTcpTableWithAlloc(PVOID *TcpTable, BOOL Order, DWORD Family, TCP_TABLE_CLASS Class) +{ + DWORD ret; + DWORD Size = 0; -START_TEST(AllocateAndGetTcpExTable2FromStack) + *TcpTable = NULL; + + ret = GetExtendedTcpTable(*TcpTable, &Size, Order, Family, Class, 0); + if (ret == ERROR_INSUFFICIENT_BUFFER) + { + *TcpTable = HeapAlloc(GetProcessHeap(), 0, Size); + if (*TcpTable == NULL) + { + return ERROR_OUTOFMEMORY; + } + + ret = GetExtendedTcpTable(*TcpTable, &Size, Order, Family, Class, 0); + if (ret != NO_ERROR) + { + HeapFree(GetProcessHeap(), 0, *TcpTable); + *TcpTable = NULL; + } + } + + return ret; +} + +START_TEST(GetExtendedTcpTable) { WSADATA wsaData; SOCKET sock; @@ -23,25 +48,10 @@ START_TEST(AllocateAndGetTcpExTable2FromStack) PMIB_TCPTABLE_OWNER_MODULE TcpTableOwnerMod; DWORD i; BOOLEAN Found; - HINSTANCE hIpHlpApi; FILETIME Creation; LARGE_INTEGER CreationTime; 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"); @@ -76,7 +86,7 @@ START_TEST(AllocateAndGetTcpExTable2FromStack) goto quit2; } - if (pAllocateAndGetTcpExTable2FromStack((PVOID *)&TcpTable, TRUE, GetProcessHeap(), 0, AF_INET, TCP_TABLE_BASIC_ALL) == ERROR_SUCCESS) + if (GetExtendedTcpTableWithAlloc((PVOID *)&TcpTable, TRUE, AF_INET, TCP_TABLE_BASIC_ALL) == ERROR_SUCCESS) { ok(TcpTable->dwNumEntries > 0, "No TCP connections?!\n"); @@ -98,10 +108,10 @@ START_TEST(AllocateAndGetTcpExTable2FromStack) } else { - skip("AllocateAndGetTcpExTable2FromStack failure\n"); + skip("GetExtendedTcpTableWithAlloc failure\n"); } - if (pAllocateAndGetTcpExTable2FromStack((PVOID *)&TcpTable, TRUE, GetProcessHeap(), 0, AF_INET, TCP_TABLE_BASIC_CONNECTIONS) == ERROR_SUCCESS) + if (GetExtendedTcpTableWithAlloc((PVOID *)&TcpTable, TRUE, AF_INET, TCP_TABLE_BASIC_CONNECTIONS) == ERROR_SUCCESS) { Found = FALSE; for (i = 0; i < TcpTable->dwNumEntries; ++i) @@ -121,10 +131,10 @@ START_TEST(AllocateAndGetTcpExTable2FromStack) } else { - skip("AllocateAndGetTcpExTable2FromStack failure\n"); + skip("GetExtendedTcpTableWithAlloc failure\n"); } - if (pAllocateAndGetTcpExTable2FromStack((PVOID *)&TcpTable, TRUE, GetProcessHeap(), 0, AF_INET, TCP_TABLE_BASIC_LISTENER) == ERROR_SUCCESS) + if (GetExtendedTcpTableWithAlloc((PVOID *)&TcpTable, TRUE, AF_INET, TCP_TABLE_BASIC_LISTENER) == ERROR_SUCCESS) { ok(TcpTable->dwNumEntries > 0, "No TCP connections?!\n"); @@ -146,10 +156,10 @@ START_TEST(AllocateAndGetTcpExTable2FromStack) } else { - skip("AllocateAndGetTcpExTable2FromStack failure\n"); + skip("GetExtendedTcpTableWithAlloc failure\n"); } - if (pAllocateAndGetTcpExTable2FromStack((PVOID *)&TcpTableOwner, TRUE, GetProcessHeap(), 0, AF_INET, TCP_TABLE_OWNER_PID_ALL) == ERROR_SUCCESS) + if (GetExtendedTcpTableWithAlloc((PVOID *)&TcpTableOwner, TRUE, AF_INET, TCP_TABLE_OWNER_PID_ALL) == ERROR_SUCCESS) { ok(TcpTableOwner->dwNumEntries > 0, "No TCP connections?!\n"); @@ -179,10 +189,10 @@ START_TEST(AllocateAndGetTcpExTable2FromStack) } else { - skip("AllocateAndGetTcpExTable2FromStack failure\n"); + skip("GetExtendedTcpTableWithAlloc failure\n"); } - if (pAllocateAndGetTcpExTable2FromStack((PVOID *)&TcpTableOwner, TRUE, GetProcessHeap(), 0, AF_INET, TCP_TABLE_OWNER_PID_CONNECTIONS) == ERROR_SUCCESS) + if (GetExtendedTcpTableWithAlloc((PVOID *)&TcpTableOwner, TRUE, AF_INET, TCP_TABLE_OWNER_PID_CONNECTIONS) == ERROR_SUCCESS) { Found = FALSE; for (i = 0; i < TcpTableOwner->dwNumEntries; ++i) @@ -202,10 +212,10 @@ START_TEST(AllocateAndGetTcpExTable2FromStack) } else { - skip("AllocateAndGetTcpExTable2FromStack failure\n"); + skip("GetExtendedTcpTableWithAlloc failure\n"); } - if (pAllocateAndGetTcpExTable2FromStack((PVOID *)&TcpTableOwner, TRUE, GetProcessHeap(), 0, AF_INET, TCP_TABLE_OWNER_PID_LISTENER) == ERROR_SUCCESS) + if (GetExtendedTcpTableWithAlloc((PVOID *)&TcpTableOwner, TRUE, AF_INET, TCP_TABLE_OWNER_PID_LISTENER) == ERROR_SUCCESS) { ok(TcpTableOwner->dwNumEntries > 0, "No TCP connections?!\n"); @@ -235,10 +245,10 @@ START_TEST(AllocateAndGetTcpExTable2FromStack) } else { - skip("AllocateAndGetTcpExTable2FromStack failure\n"); + skip("GetExtendedTcpTableWithAlloc failure\n"); } - if (pAllocateAndGetTcpExTable2FromStack((PVOID *)&TcpTableOwnerMod, TRUE, GetProcessHeap(), 0, AF_INET, TCP_TABLE_OWNER_MODULE_ALL) == ERROR_SUCCESS) + if (GetExtendedTcpTableWithAlloc((PVOID *)&TcpTableOwnerMod, TRUE, AF_INET, TCP_TABLE_OWNER_MODULE_ALL) == ERROR_SUCCESS) { ok(TcpTableOwnerMod->dwNumEntries > 0, "No TCP connections?!\n"); @@ -271,10 +281,10 @@ START_TEST(AllocateAndGetTcpExTable2FromStack) } else { - skip("AllocateAndGetTcpExTable2FromStack failure\n"); + skip("GetExtendedTcpTableWithAlloc failure\n"); } - if (pAllocateAndGetTcpExTable2FromStack((PVOID *)&TcpTableOwnerMod, TRUE, GetProcessHeap(), 0, AF_INET, TCP_TABLE_OWNER_MODULE_CONNECTIONS) == ERROR_SUCCESS) + if (GetExtendedTcpTableWithAlloc((PVOID *)&TcpTableOwnerMod, TRUE, AF_INET, TCP_TABLE_OWNER_MODULE_CONNECTIONS) == ERROR_SUCCESS) { Found = FALSE; for (i = 0; i < TcpTableOwnerMod->dwNumEntries; ++i) @@ -294,10 +304,10 @@ START_TEST(AllocateAndGetTcpExTable2FromStack) } else { - skip("AllocateAndGetTcpExTable2FromStack failure\n"); + skip("GetExtendedTcpTableWithAlloc failure\n"); } - if (pAllocateAndGetTcpExTable2FromStack((PVOID *)&TcpTableOwnerMod, TRUE, GetProcessHeap(), 0, AF_INET, TCP_TABLE_OWNER_MODULE_LISTENER) == ERROR_SUCCESS) + if (GetExtendedTcpTableWithAlloc((PVOID *)&TcpTableOwnerMod, TRUE, AF_INET, TCP_TABLE_OWNER_MODULE_LISTENER) == ERROR_SUCCESS) { ok(TcpTableOwnerMod->dwNumEntries > 0, "No TCP connections?!\n"); @@ -330,7 +340,7 @@ START_TEST(AllocateAndGetTcpExTable2FromStack) } else { - skip("AllocateAndGetTcpExTable2FromStack failure\n"); + skip("GetExtendedTcpTableWithAlloc failure\n"); } quit2: diff --git a/modules/rostests/apitests/iphlpapi/testlist.c b/modules/rostests/apitests/iphlpapi/testlist.c index 78843f5b5eb..fb2e999445c 100644 --- a/modules/rostests/apitests/iphlpapi/testlist.c +++ b/modules/rostests/apitests/iphlpapi/testlist.c @@ -3,7 +3,7 @@ #define STANDALONE #include -extern void func_AllocateAndGetTcpExTable2FromStack(void); +extern void func_GetExtendedTcpTable(void); extern void func_GetInterfaceName(void); extern void func_GetNetworkParams(void); extern void func_icmp(void); @@ -11,11 +11,11 @@ extern void func_SendARP(void); const struct test winetest_testlist[] = { - { "AllocateAndGetTcpExTable2FromStack", func_AllocateAndGetTcpExTable2FromStack }, - { "GetInterfaceName", func_GetInterfaceName }, - { "GetNetworkParams", func_GetNetworkParams }, - { "icmp", func_icmp }, - { "SendARP", func_SendARP }, + { "GetExtendedTcpTable", func_GetExtendedTcpTable }, + { "GetInterfaceName", func_GetInterfaceName }, + { "GetNetworkParams", func_GetNetworkParams }, + { "icmp", func_icmp }, + { "SendARP", func_SendARP }, { 0, 0 } };