An issue with msvcp110 test's design

YongHao Hu christopherwuy at gmail.com
Sun Mar 15 03:50:07 CDT 2015


Hi, all
Thanks for Piotr's comment on my GSOC ideas.
In order to have a good knowledge of functions from tr2 namespace, I had 
made a test and written some functions' implementation.

However, I had an issue with msvcp test's design when I need to free 
library of msvcp90 and load msvcp110.
619 static HMODULE msvcr, msvcp;
  620 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
  621 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' 
not found\     n", y); } while(0)
In my patch, I use a hmodule variable named msvcp90 to save msvcp90 
hmodule and then reuse msvcp to save msvcp110.
As far as I am concerned, the name msvcp90 or msvcp90_saver is not good 
enough. Could you give it a good name?

And the other method I came up with is  undefining SETNOFAIL and SET and 
using msvcp110 to define it again, which I think is ugly.
By the way, my crosstest on all the testbots[1] show that msvcp110.dll 
or msvcrt110.dll not installed.
It seems testbot doesn't install msvcp110.

I will be grateful for any advice you can provide.

[1]: https://testbot.winehq.org/JobDetails.pl?Key=12146&log_110=1#k110
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-devel/attachments/20150315/15f53062/attachment.html>
-------------- next part --------------
diff --git a/dlls/msvcp90/tests/ios.c b/dlls/msvcp90/tests/ios.c
index ab6c3ab..1b99e25 100644
--- a/dlls/msvcp90/tests/ios.c
+++ b/dlls/msvcp90/tests/ios.c
@@ -17,6 +17,7 @@
  */
 
 #include <stdio.h>
+#include <direct.h>
 #include <locale.h>
 #include <sys/stat.h>
 
@@ -516,6 +517,10 @@ static basic_string_wchar* (__thiscall *p_basic_string_wchar_ctor_cstr)(basic_st
 static const wchar_t* (__thiscall *p_basic_string_wchar_cstr)(basic_string_wchar*);
 static void (__thiscall *p_basic_string_wchar_dtor)(basic_string_wchar*);
 
+/* filesystem */
+static unsigned long long (*__cdecl p_tr2_sys_file_size)(char const*);
+static int (*__cdecl p_tr2_sys_equivalent)(char const*, char const*);
+
 static int invalid_parameter = 0;
 static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
         const wchar_t *function, const wchar_t *file,
@@ -616,7 +621,7 @@ static void init_thiscall_thunk(void)
 
 #endif /* __i386__ */
 
-static HMODULE msvcr, msvcp;
+static HMODULE msvcr90, msvcp90, msvcr, msvcp;
 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
 static BOOL init(void)
@@ -1022,6 +1027,40 @@ static BOOL init(void)
 #endif
     }
 
+    msvcr90 = msvcr;
+    msvcp90 = msvcp;
+    msvcr = LoadLibraryA("msvcr110.dll");
+    msvcp = LoadLibraryA("msvcp110.dll");
+    if(!msvcr || !msvcp) {
+        win_skip("msvcp110.dll or msvcrt110.dll not installed\n");
+        return FALSE;
+    }
+    p_set_invalid_parameter_handler = (void*)GetProcAddress(msvcr, "_set_invalid_parameter_handler");
+    p_free = (void*)GetProcAddress(msvcr, "free");
+    if(!p_set_invalid_parameter_handler || !p_free) {
+        win_skip("Error setting tests environment\n");
+        return FALSE;
+    }
+
+    p_set_invalid_parameter_handler(test_invalid_parameter_handler);
+    if(sizeof(void*) == 8) { /* 64-bit initialization */
+        SET(p_tr2_sys_file_size,
+                "?_File_size at sys@tr2 at std@@YA_KPEBD at Z");
+        SET(p_tr2_sys_equivalent,
+                "?_Equivalent at sys@tr2 at std@@YAHPEBD0 at Z");
+    } else {
+#ifdef __arm__
+        SET(p_tr2_sys_file_size,
+                "?_File_size at sys@tr2 at std@@YA_KPBD at Z");
+        SET(p_tr2_sys_equivalent,
+                "?_Equivalent at sys@tr2 at std@@YAHPBD0 at Z");
+#else
+        SET(p_tr2_sys_file_size,
+                "?_File_size at sys@tr2 at std@@YA_KPBD at Z");
+        SET(p_tr2_sys_equivalent,
+                "?_Equivalent at sys@tr2 at std@@YAHPBD0 at Z");
+#endif
+    }
     init_thiscall_thunk();
     return TRUE;
 }
@@ -2180,6 +2219,78 @@ static void test_ostream_print_complex_ldouble(void)
     call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
 }
 
+/* create a directory tree that can be used by subsequent tests
+ * ├── dir
+ * │   ├── d1
+ * │   │   └── d1f1     an empty file
+ * │   ├── f0           an empty file
+ * │   └── f1           a file containing "file f1"
+ */
+static void create_tree(void)
+{
+    FILE *file;
+    mkdir("dir");
+    mkdir("dir/d1");
+    file = fopen("dir/d1/d1f1", "wt");
+    fprintf(file, "");
+    fclose(file);
+
+    file = fopen("dir/f0", "wt");
+    fprintf(file, "");
+    fclose(file);
+
+    file = fopen("dir/f1", "wt");
+    fprintf(file, "file f1");
+    fclose(file);
+}
+
+static void test_tr2_sys_file_size(void)
+{
+    unsigned long long val;
+    val = p_tr2_sys_file_size("dir/d1/d1f1");
+    ok(val==0, "test fail: file_size is %llu\n", val);
+
+    val = p_tr2_sys_file_size("dir/f0");
+    ok(val==0, "test fail: file_size is %llu\n", val);
+
+    val = p_tr2_sys_file_size("dir/f1");
+    ok(val==7, "test fail: file_size is %llu\n", val);
+}
+
+static void test_tr2_sys_equivalent(void)
+{
+    BOOL val;
+    int i;
+    struct _test_tr2_sys_files {
+        char const *file_path1;
+        char const *file_path2;
+        BOOL equivalent;
+    } tests[] = {
+        { "f1",  "dir", FALSE },
+        { "dir", "f1",  FALSE },
+        { "d1",  "d2",  FALSE },
+        { "dir", "d2",  FALSE },
+        { "dir",    "dir/d1/..", TRUE },
+        { "dir/d1", "dir/d1",    TRUE },
+        { "dir/f1", "dir/f1",    TRUE },
+        { "dir/d1/d1f1", "dir/d1/../d1/d1f1", TRUE },
+    };
+
+    for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
+        val = p_tr2_sys_equivalent(tests[i].file_path1, tests[i].file_path2);
+        ok(tests[i].equivalent==val, "test %d fail: file equivalent is %d\n", i+1, val);
+    }
+}
+
+static void remove_tree(void)
+{
+    unlink("dir/f0");
+    unlink("dir/f1");
+    unlink("dir/d1/d1f1");
+    rmdir("dir/d1");
+    rmdir("dir");
+}
+
 START_TEST(ios)
 {
     if(!init())
@@ -2205,8 +2316,15 @@ START_TEST(ios)
     test_ostream_print_complex_double();
     test_ostream_print_complex_ldouble();
 
+    create_tree();
+    test_tr2_sys_file_size();
+    test_tr2_sys_equivalent();
+    remove_tree();
+
     ok(!invalid_parameter, "invalid_parameter_handler was invoked too many times\n");
 
+    FreeLibrary(msvcp90);
+    FreeLibrary(msvcr90);
     FreeLibrary(msvcr);
     FreeLibrary(msvcp);
 }


More information about the wine-devel mailing list