From fad8b1f545e948c6ff538f487658b4bde1477e29 Mon Sep 17 00:00:00 2001 From: Stanislav Motylkov Date: Wed, 24 Jan 2018 16:32:51 +0300 Subject: [PATCH] [IPHLPAPI_APITEST] Add tests for IcmpSendEcho --- modules/rostests/apitests/iphlpapi/icmp.c | 45 +++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/modules/rostests/apitests/iphlpapi/icmp.c b/modules/rostests/apitests/iphlpapi/icmp.c index bf6e9d55f57..0d853ffa575 100644 --- a/modules/rostests/apitests/iphlpapi/icmp.c +++ b/modules/rostests/apitests/iphlpapi/icmp.c @@ -82,9 +82,54 @@ test_IcmpCloseHandle(void) ok_err(ERROR_INVALID_HANDLE); } +static +void +test_IcmpSendEcho(void) +{ + HANDLE hIcmp; + unsigned long ipaddr = INADDR_NONE; + DWORD bRet = 0, error = 0; + char SendData[32] = "Data Buffer"; + PVOID ReplyBuffer = NULL; + DWORD ReplySize = 0; + + SetLastError(0xDEADBEEF); + hIcmp = IcmpCreateFile(); + if (hIcmp == INVALID_HANDLE_VALUE) + { + skip("IcmpCreateFile failed unexpectedly: %lu\n", GetLastError()); + return; + } + + ipaddr = 0x08080808; // 8.8.8.8 + + ReplySize = sizeof(ICMP_ECHO_REPLY); + ReplyBuffer = malloc(ReplySize); + SetLastError(0xDEADBEEF); + bRet = IcmpSendEcho(hIcmp, ipaddr, SendData, sizeof(SendData), + NULL, ReplyBuffer, ReplySize, 5000); + + ok(!bRet, "IcmpSendEcho succeeded unexpectedly\n"); + error = GetLastError(); + ok(error == IP_GENERAL_FAILURE, "IcmpSendEcho returned unexpected error: %lu\n", error); + free(ReplyBuffer); + + ReplySize = sizeof(ICMP_ECHO_REPLY) + sizeof(SendData); + ReplyBuffer = malloc(ReplySize); + SetLastError(0xDEADBEEF); + bRet = IcmpSendEcho(hIcmp, ipaddr, SendData, sizeof(SendData), + NULL, ReplyBuffer, ReplySize, 5000); + + ok(bRet, "IcmpSendEcho failed unexpectedly: %lu\n", GetLastError()); + free(ReplyBuffer); + + IcmpCloseHandle(hIcmp); +} + START_TEST(icmp) { test_IcmpCreateFile(); test_Icmp6CreateFile(); test_IcmpCloseHandle(); + test_IcmpSendEcho(); }