From: Kaipeng Zeng Subject: [PATCH] findstr: Added test for findstr. (try 2) Message-Id: <5510FC5C.5040002@gmail.com> Date: Tue, 24 Mar 2015 13:55:40 +0800 Thanks Stefan! Superseded patch 110143 . ChangeLog: - Exclude change to configure - Return exit code of findstr in runcmd() From 5b5d02a05f3f7607c307501426f3be77905ccbd3 Mon Sep 17 00:00:00 2001 From: Kaipeng Zeng Date: Tue, 24 Mar 2015 12:51:51 +0800 Subject: [PATCH] findstr: Added test for findstr. --- configure.ac | 1 + programs/findstr/tests/Makefile.in | 5 ++ programs/findstr/tests/findstr.c | 96 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 programs/findstr/tests/Makefile.in create mode 100644 programs/findstr/tests/findstr.c diff --git a/configure.ac b/configure.ac index d23227a..822affe 100644 --- a/configure.ac +++ b/configure.ac @@ -3432,6 +3432,7 @@ WINE_CONFIG_PROGRAM(expand,,[install]) WINE_CONFIG_PROGRAM(explorer,,[install,po]) WINE_CONFIG_PROGRAM(extrac32,,[install]) WINE_CONFIG_PROGRAM(findstr,,[install]) +WINE_CONFIG_TEST(programs/findstr/tests) WINE_CONFIG_PROGRAM(hh,,[install]) WINE_CONFIG_PROGRAM(hostname,,[install,po]) WINE_CONFIG_PROGRAM(icinfo,,[install]) diff --git a/programs/findstr/tests/Makefile.in b/programs/findstr/tests/Makefile.in new file mode 100644 index 0000000..b5195d0 --- /dev/null +++ b/programs/findstr/tests/Makefile.in @@ -0,0 +1,5 @@ +TESTDLL = findstr.exe + +C_SRCS = \ + findstr.c + diff --git a/programs/findstr/tests/findstr.c b/programs/findstr/tests/findstr.c new file mode 100644 index 0000000..22539e8 --- /dev/null +++ b/programs/findstr/tests/findstr.c @@ -0,0 +1,96 @@ +/* + * Copyright 2015 Kaipeng Zeng + * + * 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 "wine/test.h" + + +static DWORD runcmd(const char *cmd, char *output) +{ + char *wcmd; + SECURITY_ATTRIBUTES sa; + HANDLE hRead, hWrite; + STARTUPINFOA si; + PROCESS_INFORMATION pi; + DWORD bytesRead; + DWORD result; + + wcmd = HeapAlloc(GetProcessHeap(), 0, strlen(cmd) + 1); + strcpy(wcmd, cmd); + + sa.nLength = sizeof(SECURITY_ATTRIBUTES); + sa.lpSecurityDescriptor = NULL; + sa.bInheritHandle = TRUE; + if (!CreatePipe(&hRead, &hWrite, &sa, 0)) + return 260; + + si.cb = sizeof(STARTUPINFOA); + GetStartupInfoA(&si); + si.hStdError = hWrite; + si.hStdOutput = hWrite; + si.wShowWindow = SW_HIDE; + si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; + if (!CreateProcessA(NULL, wcmd, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) + { + HeapFree(GetProcessHeap(), 0, wcmd); + CloseHandle(hWrite); + CloseHandle(hRead); + return 260; + } + CloseHandle(hWrite); + HeapFree(GetProcessHeap(), 0, wcmd); + while (ReadFile(hRead, output, GetFileSize(hRead, NULL), &bytesRead, NULL)) + ; + + CloseHandle(hRead); + GetExitCodeProcess(pi.hProcess, &result); + + return result; +} + +void init_env(void) +{ + char text_for_test[] = "Wine Is Not an Emulator.\n" + "Wine will always be free software.\n" + "Wine is heavily reliant on its user community too."; + HANDLE file; + DWORD dwBytesToWrite = (DWORD)strlen(text_for_test); + DWORD dwBytesWritten = 0; + + file = CreateFileA("test.txt", GENERIC_READ|GENERIC_WRITE, 0, NULL, + CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + WriteFile(file, text_for_test, dwBytesToWrite, &dwBytesWritten, NULL); + CloseHandle(file); +} + +void test_without_arg(void) +{ + char buffer[2048] = {0}; + + init_env(); + todo_wine ok(!runcmd("findstr free test.txt", buffer), "'findstr free test.txt' fails\n"); + todo_wine ok(!strcmp(buffer, "Wine will always be free software.\n"), + "Return wrong string.\n"); + DeleteFileA("test.txt"); +} + +START_TEST(findstr) +{ + test_without_arg(); +} -- 2.1.0