Hi Dan,

On 12/26/09 5:16 PM, Dan Kegel wrote:
OK, cmd/tests it is.
I've updated http://kegel.com/wine/sweng/2010/#tests accordingly.

A rough prototype is at
http://kegel.com/wine/cmd/tests/
(I'm doing this all on a tiny netbook which
doesn't have a wine development system,
so I can't produce a patch yet.)

I've been following cmd.exe topic and I was concerned about the fact, that these tests are out of Wine tree, so I wanted to help and implemented a simple framework. I almost didn't test it so I didn't send it before. It caused a code duplication, I'm sorry about that. I'm attaching the patch (it requires running tools/make_makefiles) and I will leave it for others.

To-do list:
- fix http://bugs.winehq.org/show_bug.cgi?id=21144 so
we can more easily compare output of wine's cmd with
output of windows' cmd
- integrate into wine's build system

It is in done in my patch. It came out that it just worked as with dlls tests.

- bundle the test scripts with resource calls instead of escaped arrays

Done.

- better messages on test failures?

Messages probably need improvements. There is no info at all ATM.

- alternately, move to one test script per bug?

Perhaps not one per bug, but one per command/feature would be good.

- coax winetest into including this binary,
   and make sure they work well together

It doesn't work ATM, but it shouldn't be hard to fix.

Also, your tests are very risky in terms of non-English locales. I think we shouldn't test error messages strings. A problem with directory in prompt may be fixed by special escape in expected result file that would be replaced by the right directory in runtime.


Thanks,
    Jacek
commit 1bb49dc70c42702a2f41c566e008c2ad3d120acc
Author: Jacek Caban <ja...@codeweavers.com>
Date:   Sat Dec 26 19:49:00 2009 +0100

    cmd.exe: Added test framework.

diff --git a/programs/cmd/tests/Makefile.in b/programs/cmd/tests/Makefile.in
new file mode 100644
index 0000000..b96d8f8
--- /dev/null
+++ b/programs/cmd/tests/Makefile.in
@@ -0,0 +1,15 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../../..
+SRCDIR    = @srcdir@
+VPATH     = @srcdir@
+TESTDLL   = cmd.exe
+IMPORTS   = kernel32
+
+CTESTS = \
+       cmd.c
+
+RC_SRCS = rsrc.rc
+
+...@make_test_rules@
+
+...@dependencies@  # everything below this line is overwritten by make depend
diff --git a/programs/cmd/tests/cmd.c b/programs/cmd/tests/cmd.c
new file mode 100644
index 0000000..ec47122
--- /dev/null
+++ b/programs/cmd/tests/cmd.c
@@ -0,0 +1,142 @@
+/*
+ * Copyright 2009 Jacek Caban for CodeWeavers
+ *
+ * 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 <stdio.h>
+
+#include "wine/test.h"
+
+static const char *success_tests[] = {"test_echo"};
+static const char *todo_tests[] = {};
+
+static const char *load_res(const char *res_name, DWORD *size)
+{
+    const char *res;
+    HRSRC src;
+
+    src = FindResourceA(NULL, res_name, (LPCSTR)40);
+    ok(src != NULL, "Could not find resource %s\n", res_name);
+    if(!src)
+        return NULL;
+
+    res = LoadResource(NULL, src);
+    *size = strstr(res, "<wine_eof")-res;
+    return res;
+}
+
+static BOOL run_cmd(const char *test_name)
+{
+    SECURITY_ATTRIBUTES sa = {sizeof(sa), 0, TRUE};
+    char command[] = "test.cmd";
+    STARTUPINFOA si = {sizeof(si)};
+    PROCESS_INFORMATION pi;
+    HANDLE file;
+    char buf[64];
+    const char *res;
+    DWORD size;
+    BOOL bres = FALSE;
+
+    sprintf(buf, "%s.cmd", test_name);
+    res = load_res(buf, &size);
+    if(!res)
+        return FALSE;
+
+    file = CreateFileA("test.cmd", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
+            FILE_ATTRIBUTE_NORMAL, NULL);
+    ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
+    if(file == INVALID_HANDLE_VALUE)
+        return FALSE;
+
+    WriteFile(file, res, size, &size, NULL);
+    CloseHandle(file);
+
+    file = CreateFileA("test.out", GENERIC_WRITE, 0, &sa, CREATE_ALWAYS,
+            FILE_ATTRIBUTE_NORMAL, NULL);
+    ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
+    if(file == INVALID_HANDLE_VALUE)
+        return FALSE;
+
+    si.dwFlags = STARTF_USESTDHANDLES;
+    si.hStdOutput = file;
+    bres = CreateProcessA(NULL, command, NULL, NULL, 0, 0, NULL, NULL, &si, 
&pi);
+    ok(bres, "CreateProcess failed: %u\n", GetLastError());
+    CloseHandle(file);
+    if(!bres)
+        return FALSE;
+
+    WaitForSingleObject(pi.hProcess, INFINITE);
+    CloseHandle(pi.hThread);
+    CloseHandle(pi.hProcess);
+    return TRUE;
+}
+
+static void result_cmp(const char *test_name, BOOL expect_success)
+{
+    DWORD exp_size, out_size;
+    const char *exp, *out;
+    HANDLE file, map;
+    char buf[64];
+
+    sprintf(buf, "%s.out", test_name);
+    exp = load_res(buf, &exp_size);
+    if(!exp)
+        return;
+
+    file = CreateFileA("test.out", GENERIC_READ, 0, NULL, OPEN_EXISTING, 
FILE_ATTRIBUTE_READONLY, NULL);
+    ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %08x\n", 
GetLastError());
+    if(file == INVALID_HANDLE_VALUE)
+        return;
+
+    out_size = GetFileSize(file, NULL);
+
+    map = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL);
+    CloseHandle(file);
+    ok(map != NULL, "CreateFileMapping failed: %u\n", GetLastError());
+    if(map == INVALID_HANDLE_VALUE)
+        return;
+
+    out = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
+    ok(out != NULL, "MapViewOfFile failed: %u\n", GetLastError());
+    CloseHandle(map);
+    if(!out)
+        return;
+
+    if(expect_success)
+        ok(exp_size == out_size && !memcmp(exp, out, exp_size), "Wrong output 
for %s\n", test_name);
+    else todo_wine
+        ok(exp_size == out_size && !memcmp(exp, out, exp_size), "Wrong output 
for %s\n", test_name);
+
+    UnmapViewOfFile(out);
+}
+
+static void run_tests(const char **tests, unsigned test_cnt, BOOL 
expect_success)
+{
+    unsigned i;
+
+    for(i=0; i < test_cnt; i++) {
+        if(run_cmd(tests[i]))
+            result_cmp(tests[i], expect_success);
+        //DeleteFileA("test.cmd");
+        //DeleteFileA("test.out");
+    }
+}
+
+START_TEST(cmd)
+{
+    run_tests(success_tests, sizeof(success_tests)/sizeof(*success_tests), 
TRUE);
+    run_tests(todo_tests, sizeof(todo_tests)/sizeof(*todo_tests), FALSE);
+}
diff --git a/programs/cmd/tests/rsrc.rc b/programs/cmd/tests/rsrc.rc
new file mode 100644
index 0000000..baa9d8a
--- /dev/null
+++ b/programs/cmd/tests/rsrc.rc
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2009 Jacek Caban for CodeWeavers
+ *
+ * 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
+ */
+
+/* @makedep: test_echo.cmd */
+test_echo.cmd 40 "test_echo.cmd"
+
+/* @makedep: test_echo.out */
+test_echo.out 40 "test_echo.out"
diff --git a/programs/cmd/tests/test_echo.cmd b/programs/cmd/tests/test_echo.cmd
new file mode 100644
index 0000000..b7ef1bf
--- /dev/null
+++ b/programs/cmd/tests/test_echo.cmd
@@ -0,0 +1,3 @@
+...@echo off
+echo test
+<wine_eof>
\ No newline at end of file
diff --git a/programs/cmd/tests/test_echo.out b/programs/cmd/tests/test_echo.out
new file mode 100644
index 0000000..93fdd83
--- /dev/null
+++ b/programs/cmd/tests/test_echo.out
@@ -0,0 +1,2 @@
+test
+<wine_eof>
\ No newline at end of file


Reply via email to