[PATCH] findstr: Added test for findstr.

Kaipeng Zeng kaipeng94 at gmail.com
Sun Mar 22 22:14:52 CDT 2015


-------------- next part --------------
>From 43232be3be8558d3a7587ccdbb26aa5e0f73eb49 Mon Sep 17 00:00:00 2001
From: Kaipeng Zeng <kaipeng94 at gmail.com>
Date: Mon, 23 Mar 2015 10:20:02 +0800
Subject: [PATCH] findstr: Added test for findstr.

---
 configure                          |  1 +
 configure.ac                       |  1 +
 programs/findstr/tests/Makefile.in |  5 ++
 programs/findstr/tests/findstr.c   | 94 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 101 insertions(+)
 create mode 100644 programs/findstr/tests/Makefile.in
 create mode 100644 programs/findstr/tests/findstr.c

diff --git a/configure b/configure
index 5f5e9d5..f3056c7 100755
--- a/configure
+++ b/configure
@@ -17730,6 +17730,7 @@ wine_fn_config_program expand enable_expand install
 wine_fn_config_program explorer enable_explorer install,po
 wine_fn_config_program extrac32 enable_extrac32 install
 wine_fn_config_program findstr enable_findstr install
+wine_fn_config_test programs/findstr/tests findstr.exe_test
 wine_fn_config_program hh enable_hh install
 wine_fn_config_program hostname enable_hostname install,po
 wine_fn_config_program icinfo enable_icinfo install
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..93df09f
--- /dev/null
+++ b/programs/findstr/tests/findstr.c
@@ -0,0 +1,94 @@
+/*
+ * 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 <windows.h>
+
+#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;
+
+    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 FALSE;
+
+    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 FALSE;
+    }
+    CloseHandle(hWrite);
+    HeapFree(GetProcessHeap(), 0, wcmd);
+    while (ReadFile(hRead, output, GetFileSize(hRead, NULL), &bytesRead, NULL))
+        ;
+
+    CloseHandle(hRead);
+    return TRUE;
+}
+
+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();
+    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



More information about the wine-patches mailing list