https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f42a6c16f2565e2c73ab5…
commit f42a6c16f2565e2c73ab5c8e3c4ade20098c92c8
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Fri Dec 21 19:05:07 2018 +0100
Commit: Pierre Schweitzer <pierre(a)reactos.org>
CommitDate: Fri Dec 21 19:17:11 2018 +0100
[IPHLPAPI_APITEST] Add tests for GetExtendedUdpTable
---
modules/rostests/apitests/iphlpapi/CMakeLists.txt | 1 +
.../apitests/iphlpapi/GetExtendedUdpTable.c | 175 +++++++++++++++++++++
modules/rostests/apitests/iphlpapi/testlist.c | 2 +
3 files changed, 178 insertions(+)
diff --git a/modules/rostests/apitests/iphlpapi/CMakeLists.txt
b/modules/rostests/apitests/iphlpapi/CMakeLists.txt
index 81ca68cae9..69b44b8efd 100644
--- a/modules/rostests/apitests/iphlpapi/CMakeLists.txt
+++ b/modules/rostests/apitests/iphlpapi/CMakeLists.txt
@@ -1,6 +1,7 @@
list(APPEND SOURCE
GetExtendedTcpTable.c
+ GetExtendedUdpTable.c
GetInterfaceName.c
GetNetworkParams.c
GetOwnerModuleFromTcpEntry.c
diff --git a/modules/rostests/apitests/iphlpapi/GetExtendedUdpTable.c
b/modules/rostests/apitests/iphlpapi/GetExtendedUdpTable.c
new file mode 100644
index 0000000000..ea1c0cb27e
--- /dev/null
+++ b/modules/rostests/apitests/iphlpapi/GetExtendedUdpTable.c
@@ -0,0 +1,175 @@
+/*
+ * PROJECT: ReactOS API Tests
+ * LICENSE: GPL-2.0+ (
https://spdx.org/licenses/GPL-2.0+)
+ * PURPOSE: Tests for UDP connections enumeration functions
+ * COPYRIGHT: Copyright 2018 Pierre Schweitzer
+ */
+
+#include <apitest.h>
+
+#define WIN32_NO_STATUS
+#include <iphlpapi.h>
+#include <winsock2.h>
+
+static DWORD GetExtendedUdpTableWithAlloc(PVOID *UdpTable, BOOL Order, DWORD Family,
UDP_TABLE_CLASS Class)
+{
+ DWORD ret;
+ DWORD Size = 0;
+
+ *UdpTable = NULL;
+
+ ret = GetExtendedUdpTable(*UdpTable, &Size, Order, Family, Class, 0);
+ if (ret == ERROR_INSUFFICIENT_BUFFER)
+ {
+ *UdpTable = HeapAlloc(GetProcessHeap(), 0, Size);
+ if (*UdpTable == NULL)
+ {
+ return ERROR_OUTOFMEMORY;
+ }
+
+ ret = GetExtendedUdpTable(*UdpTable, &Size, Order, Family, Class, 0);
+ if (ret != NO_ERROR)
+ {
+ HeapFree(GetProcessHeap(), 0, *UdpTable);
+ *UdpTable = NULL;
+ }
+ }
+
+ return ret;
+}
+
+START_TEST(GetExtendedUdpTable)
+{
+ WSADATA wsaData;
+ SOCKET sock;
+ SOCKADDR_IN server;
+ PMIB_UDPTABLE UdpTable;
+ PMIB_UDPTABLE_OWNER_PID UdpTableOwner;
+ PMIB_UDPTABLE_OWNER_MODULE UdpTableOwnerMod;
+ DWORD i;
+ BOOLEAN Found;
+ FILETIME Creation;
+ LARGE_INTEGER CreationTime;
+ DWORD Pid = GetCurrentProcessId();
+
+ if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
+ {
+ skip("Failed to init WS2\n");
+ return;
+ }
+
+ GetSystemTimeAsFileTime(&Creation);
+ CreationTime.LowPart = Creation.dwLowDateTime;
+ CreationTime.HighPart = Creation.dwHighDateTime;
+
+ sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ 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 (GetExtendedUdpTableWithAlloc((PVOID *)&UdpTable, TRUE, AF_INET,
UDP_TABLE_BASIC) == ERROR_SUCCESS)
+ {
+ ok(UdpTable->dwNumEntries > 0, "No UDP connections?!\n");
+
+ Found = FALSE;
+ for (i = 0; i < UdpTable->dwNumEntries; ++i)
+ {
+ if (UdpTable->table[i].dwLocalAddr == 0 &&
+ UdpTable->table[i].dwLocalPort == htons(9876))
+ {
+ Found = TRUE;
+ break;
+ }
+ }
+ ok(Found, "Our socket wasn't found!\n");
+
+ HeapFree(GetProcessHeap(), 0, UdpTable);
+ }
+ else
+ {
+ skip("GetExtendedUdpTableWithAlloc failure\n");
+ }
+
+ if (GetExtendedUdpTableWithAlloc((PVOID *)&UdpTableOwner, TRUE, AF_INET,
UDP_TABLE_OWNER_PID) == ERROR_SUCCESS)
+ {
+ ok(UdpTableOwner->dwNumEntries > 0, "No UDP connections?!\n");
+
+ Found = FALSE;
+ for (i = 0; i < UdpTableOwner->dwNumEntries; ++i)
+ {
+ if (UdpTableOwner->table[i].dwLocalAddr == 0 &&
+ UdpTableOwner->table[i].dwLocalPort == htons(9876))
+ {
+ Found = TRUE;
+ break;
+ }
+ }
+
+ if (!Found)
+ {
+ skip("Our socket wasn't found!\n");
+ }
+ else
+ {
+ ok(UdpTableOwner->table[i].dwOwningPid == Pid, "Invalid
owner\n");
+ }
+
+ HeapFree(GetProcessHeap(), 0, UdpTableOwner);
+ }
+ else
+ {
+ skip("GetExtendedUdpTableWithAlloc failure\n");
+ }
+
+ if (GetExtendedUdpTableWithAlloc((PVOID *)&UdpTableOwnerMod, TRUE, AF_INET,
UDP_TABLE_OWNER_MODULE) == ERROR_SUCCESS)
+ {
+ ok(UdpTableOwnerMod->dwNumEntries > 0, "No TCP
connections?!\n");
+
+ Found = FALSE;
+ for (i = 0; i < UdpTableOwnerMod->dwNumEntries; ++i)
+ {
+ if (UdpTableOwnerMod->table[i].dwLocalAddr == 0 &&
+ UdpTableOwnerMod->table[i].dwLocalPort == htons(9876))
+ {
+ Found = TRUE;
+ break;
+ }
+ }
+
+ if (!Found)
+ {
+ skip("Our socket wasn't found!\n");
+ }
+ else
+ {
+ ok(UdpTableOwnerMod->table[i].dwOwningPid == Pid, "Invalid
owner\n");
+
+ ok(UdpTableOwnerMod->table[i].liCreateTimestamp.QuadPart >=
CreationTime.QuadPart, "Invalid time\n");
+ ok(UdpTableOwnerMod->table[i].liCreateTimestamp.QuadPart <=
CreationTime.QuadPart + 60000000000LL, "Invalid time\n");
+ }
+
+ HeapFree(GetProcessHeap(), 0, UdpTableOwnerMod);
+ }
+ else
+ {
+ skip("GetExtendedUdpTableWithAlloc failure\n");
+ }
+
+quit2:
+ closesocket(sock);
+quit:
+ WSACleanup();
+}
diff --git a/modules/rostests/apitests/iphlpapi/testlist.c
b/modules/rostests/apitests/iphlpapi/testlist.c
index 4f56d9da55..6690e3d260 100644
--- a/modules/rostests/apitests/iphlpapi/testlist.c
+++ b/modules/rostests/apitests/iphlpapi/testlist.c
@@ -4,6 +4,7 @@
#include <apitest.h>
extern void func_GetExtendedTcpTable(void);
+extern void func_GetExtendedUdpTable(void);
extern void func_GetInterfaceName(void);
extern void func_GetNetworkParams(void);
extern void func_GetOwnerModuleFromTcpEntry(void);
@@ -13,6 +14,7 @@ extern void func_SendARP(void);
const struct test winetest_testlist[] =
{
{ "GetExtendedTcpTable", func_GetExtendedTcpTable },
+ { "GetExtendedUdpTable", func_GetExtendedUdpTable },
{ "GetInterfaceName", func_GetInterfaceName },
{ "GetNetworkParams", func_GetNetworkParams },
{ "GetOwnerModuleFromTcpEntry", func_GetOwnerModuleFromTcpEntry },