Alexandre Julliard : winetest: Store the test name as the resource name instead of in a separate string table .

Alexandre Julliard julliard at wine.codeweavers.com
Mon Sep 11 11:22:11 CDT 2006


Module: wine
Branch: master
Commit: 5e0a81571f4a2bf1236d806d3cbdf0808832d7e3
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=5e0a81571f4a2bf1236d806d3cbdf0808832d7e3

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Mon Sep 11 14:23:07 2006 +0200

winetest: Store the test name as the resource name instead of in a separate string table.

---

 programs/winetest/main.c     |   57 ++++++++++++++++++++++++------------------
 programs/winetest/maketest   |   11 +-------
 programs/winetest/util.c     |    7 +++++
 programs/winetest/winetest.h |    1 +
 4 files changed, 42 insertions(+), 34 deletions(-)

diff --git a/programs/winetest/main.c b/programs/winetest/main.c
index 20c25f4..796d542 100644
--- a/programs/winetest/main.c
+++ b/programs/winetest/main.c
@@ -57,6 +57,7 @@ struct rev_info
 
 char *tag = NULL;
 static struct wine_test *wine_tests;
+static int nr_of_files, nr_of_tests;
 static struct rev_info *rev_infos = NULL;
 static const char whitespace[] = " \t\r\n";
 
@@ -220,13 +221,13 @@ static void extract_rev_infos (void)
     }
 }
 
-static void* extract_rcdata (int id, int type, DWORD* size)
+static void* extract_rcdata (LPTSTR name, int type, DWORD* size)
 {
     HRSRC rsrc;
     HGLOBAL hdl;
     LPVOID addr;
     
-    if (!(rsrc = FindResource (NULL, (LPTSTR)id, MAKEINTRESOURCE(type))) ||
+    if (!(rsrc = FindResource (NULL, name, MAKEINTRESOURCE(type))) ||
         !(*size = SizeofResource (0, rsrc)) ||
         !(hdl = LoadResource (0, rsrc)) ||
         !(addr = LockResource (hdl)))
@@ -236,24 +237,18 @@ static void* extract_rcdata (int id, int
 
 /* Fills in the name and exename fields */
 static void
-extract_test (struct wine_test *test, const char *dir, int id)
+extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
 {
     BYTE* code;
     DWORD size;
     FILE* fout;
-    int strlen, bufflen = 128;
     char *exepos;
 
-    code = extract_rcdata (id, TESTRES, &size);
-    if (!code) report (R_FATAL, "Can't find test resource %d: %d",
-                       id, GetLastError ());
-    test->name = xmalloc (bufflen);
-    while ((strlen = LoadStringA (NULL, id, test->name, bufflen))
-           == bufflen - 1) {
-        bufflen *= 2;
-        test->name = xrealloc (test->name, bufflen);
-    }
-    if (!strlen) report (R_FATAL, "Can't read name of test %d.", id);
+    code = extract_rcdata (res_name, TESTRES, &size);
+    if (!code) report (R_FATAL, "Can't find test resource %s: %d",
+                       res_name, GetLastError ());
+    test->name = xstrdup( res_name );
+    CharLowerA( test->name );
     test->exename = strmake (NULL, "%s/%s", dir, test->name);
     exepos = strstr (test->name, "_test.exe");
     if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
@@ -351,7 +346,7 @@ run_ex (char *cmd, const char *out, DWOR
 }
 
 static void
-get_subtests (const char *tempdir, struct wine_test *test, int id)
+get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
 {
     char *subname, *cmd;
     FILE *subfile;
@@ -365,7 +360,7 @@ get_subtests (const char *tempdir, struc
     subname = tempnam (0, "sub");
     if (!subname) report (R_FATAL, "Can't name subtests file.");
 
-    extract_test (test, tempdir, id);
+    extract_test (test, tempdir, res_name);
     cmd = strmake (NULL, "%s --list", test->exename);
     run_ex (cmd, subname, 5000);
     free (cmd);
@@ -437,10 +432,21 @@ EnumTestFileProc (HMODULE hModule, LPCTS
     return TRUE;
 }
 
+static BOOL CALLBACK
+extract_test_proc (HMODULE hModule, LPCTSTR lpszType,
+                   LPTSTR lpszName, LONG_PTR lParam)
+{
+    const char *tempdir = (const char *)lParam;
+    get_subtests( tempdir, &wine_tests[nr_of_files], lpszName );
+    nr_of_tests += wine_tests[nr_of_files].subtest_count;
+    nr_of_files++;
+    return TRUE;
+}
+
 static char *
 run_tests (char *logname)
 {
-    int nr_of_files = 0, nr_of_tests = 0, i;
+    int i;
     char *tempdir, *shorttempdir;
     int logfile;
     char *strres, *eol, *nextline;
@@ -481,17 +487,17 @@ run_tests (char *logname)
     report (R_DIR, tempdir);
 
     xprintf ("Version 3\n");
-    strres = extract_rcdata (WINE_BUILD, STRINGRES, &strsize);
+    strres = extract_rcdata (MAKEINTRESOURCE(WINE_BUILD), STRINGRES, &strsize);
     xprintf ("Tests from build ");
     if (strres) xprintf ("%.*s", strsize, strres);
     else xprintf ("-\n");
-    strres = extract_rcdata (TESTS_URL, STRINGRES, &strsize);
+    strres = extract_rcdata (MAKEINTRESOURCE(TESTS_URL), STRINGRES, &strsize);
     xprintf ("Archive: ");
     if (strres) xprintf ("%.*s", strsize, strres);
     else xprintf ("-\n");
     xprintf ("Tag: %s\n", tag);
     xprintf ("Build info:\n");
-    strres = extract_rcdata (BUILD_INFO, STRINGRES, &strsize);
+    strres = extract_rcdata (MAKEINTRESOURCE(BUILD_INFO), STRINGRES, &strsize);
     while (strres) {
         eol = memchr (strres, '\n', strsize);
         if (!eol) {
@@ -518,10 +524,13 @@ run_tests (char *logname)
 
     report (R_STATUS, "Extracting tests");
     report (R_PROGRESS, 0, nr_of_files);
-    for (i = 0; i < nr_of_files; i++) {
-        get_subtests (tempdir, wine_tests+i, i);
-        nr_of_tests += wine_tests[i].subtest_count;
-    }
+    nr_of_files = 0;
+    nr_of_tests = 0;
+    if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
+                            extract_test_proc, (LPARAM)tempdir))
+        report (R_FATAL, "Can't enumerate test files: %d",
+                GetLastError ());
+
     report (R_DELTA, 0, "Extracting: Done");
 
     report (R_STATUS, "Running tests");
diff --git a/programs/winetest/maketest b/programs/winetest/maketest
index 527a3b4..0f907d9 100755
--- a/programs/winetest/maketest
+++ b/programs/winetest/maketest
@@ -8,13 +8,6 @@ echo "#include \"resource.h\""
 echo "STRINGTABLE {"
 
 i=0
-for test
-do
-    echo "$i \"$test\""
-    i=`expr $i + 1`
-done
-
-i=0
 cd $TOPSRCDIR
 if [ -d .git ]
 then
@@ -32,9 +25,7 @@ done
 
 echo "}"
 
-i=0
 for test
 do
-    echo "$i TESTRES \"$test\""
-    i=`expr $i + 1`
+    echo "$test TESTRES \"$test\""
 done
diff --git a/programs/winetest/util.c b/programs/winetest/util.c
index 741245d..12c6073 100644
--- a/programs/winetest/util.c
+++ b/programs/winetest/util.c
@@ -40,6 +40,13 @@ void *xrealloc (void *op, size_t len)
     return p;
 }
 
+char *xstrdup( const char *str )
+{
+    char *res = strdup( str );
+    if (!res) report (R_FATAL, "Out of memory.");
+    return res;
+}
+
 static char *vstrfmtmake (size_t *lenp, const char *fmt, va_list ap)
 {
     size_t size = 1000;
diff --git a/programs/winetest/winetest.h b/programs/winetest/winetest.h
index 168fc71..043e5ed 100644
--- a/programs/winetest/winetest.h
+++ b/programs/winetest/winetest.h
@@ -30,6 +30,7 @@ void fatal (const char* msg);
 void warning (const char* msg);
 void *xmalloc (size_t len);
 void *xrealloc (void *op, size_t len);
+char *xstrdup( const char *str );
 void xprintf (const char *fmt, ...);
 char *vstrmake (size_t *lenp, va_list ap);
 char *strmake (size_t *lenp, ...);




More information about the wine-cvs mailing list