From: Isira Seneviratne Subject: [PATCH v2] ping: Add tests. Message-Id: Date: Tue, 5 Feb 2019 21:30:43 +0530

From 6a2e03442db7d7a493acbffe73d41e66415dddcb Mon Sep 17 00:00:00 2001 From: Isira-Seneviratne Date: Fri, 25 Jan 2019 10:27:29 +0530 Subject: [PATCH v2] ping: Add tests. This is my first patch incorporating tests. I would welcome feedback on how to properly test ping and its various options. Signed-off-by: Isira-Seneviratne --- configure | 1 + programs/ping/tests/Makefile.in | 5 +++ programs/ping/tests/ping_main.c | 70 +++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 programs/ping/tests/Makefile.in create mode 100644 programs/ping/tests/ping_main.c diff --git a/configure b/configure index ec211a538b..bbed6ea3a0 100755 --- a/configure +++ b/configure @@ -20203,6 +20203,7 @@ wine_fn_config_makefile programs/ngen enable_ngen wine_fn_config_makefile programs/notepad enable_notepad wine_fn_config_makefile programs/oleview enable_oleview wine_fn_config_makefile programs/ping enable_ping +wine_fn_config_makefile programs/ping/tests enable_tests wine_fn_config_makefile programs/plugplay enable_plugplay wine_fn_config_makefile programs/powershell enable_powershell wine_fn_config_makefile programs/presentationfontcache enable_presentationfontcache diff --git a/programs/ping/tests/Makefile.in b/programs/ping/tests/Makefile.in new file mode 100644 index 0000000000..fe1dab4df4 --- /dev/null +++ b/programs/ping/tests/Makefile.in @@ -0,0 +1,5 @@ +TESTDLL = ping.exe +IMPORTS = advapi32 + +C_SRCS = \ + ping_main.c diff --git a/programs/ping/tests/ping_main.c b/programs/ping/tests/ping_main.c new file mode 100644 index 0000000000..b054383a70 --- /dev/null +++ b/programs/ping/tests/ping_main.c @@ -0,0 +1,70 @@ +/* + * Copyright 2019 Isira Seneviratne + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ +#include +#include + +#include "wine/test.h" + +HANDLE ping_output; + +static BOOL ping_available(const char *cmd, int timeout) +{ + STARTUPINFOA si; + PROCESS_INFORMATION pi; + DWORD ping; + char cmdline[256]; + + memset(&si, 0, sizeof(si)); + si.cb = sizeof(si); + si.dwFlags = STARTF_USESTDHANDLES; + si.hStdInput = INVALID_HANDLE_VALUE; + si.hStdOutput = ping_output; + si.hStdError = INVALID_HANDLE_VALUE; + + strcpy(cmdline, cmd); + + if (!CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) + return FALSE; + + ping = WaitForSingleObject(pi.hProcess, timeout); + if (ping == WAIT_TIMEOUT) + TerminateProcess(pi.hProcess, 1); + + CloseHandle(pi.hThread); + CloseHandle(pi.hProcess); + + return ping != WAIT_TIMEOUT; +} + +static void test_ping_n(void) +{ + ping_available("ping -n 3 www.google.lk", 10000); +} + +START_TEST(ping_main) +{ + ping_output = CreateEventA(NULL, FALSE, FALSE, NULL); + + if (!ping_available("ping", 5000)) + { + win_skip("ping not installed, skipping ping tests\n"); + return; + } + + test_ping_n(); +} -- 2.20.1