[IPHLPAPI_APITEST] Test GetExtendedTcpTable rather than AllocateAndGetTcpExTable2From...
authorPierre Schweitzer <pierre@reactos.org>
Thu, 29 Nov 2018 07:42:13 +0000 (08:42 +0100)
committerPierre Schweitzer <pierre@reactos.org>
Thu, 29 Nov 2018 19:30:22 +0000 (20:30 +0100)
modules/rostests/apitests/iphlpapi/CMakeLists.txt
modules/rostests/apitests/iphlpapi/GetExtendedTcpTable.c [moved from modules/rostests/apitests/iphlpapi/AllocateAndGetTcpExTable2FromStack.c with 76% similarity]
modules/rostests/apitests/iphlpapi/testlist.c

index 8e59d25..23b8218 100644 (file)
@@ -1,6 +1,6 @@
 
 list(APPEND SOURCE
-    AllocateAndGetTcpExTable2FromStack.c
+    GetExtendedTcpTable.c
     GetInterfaceName.c
     GetNetworkParams.c
     icmp.c
 #include <iphlpapi.h>
 #include <winsock2.h>
 
-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;
+
+    *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;
+        }
+    }
 
-START_TEST(AllocateAndGetTcpExTable2FromStack)
+    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:
index 78843f5..fb2e999 100644 (file)
@@ -3,7 +3,7 @@
 #define STANDALONE
 #include <apitest.h>
 
-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 }
 };