YongHao Hu : msvcp110: Add tr2_sys__Equivalent implementation and test.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Jun 15 08:49:09 CDT 2015


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

Author: YongHao Hu <christopherwuy at gmail.com>
Date:   Sat Jun 13 00:29:18 2015 +0800

msvcp110: Add tr2_sys__Equivalent implementation and test.

---

 dlls/msvcp110/msvcp110.spec         |  4 +--
 dlls/msvcp120/msvcp120.spec         |  4 +--
 dlls/msvcp120/tests/msvcp120.c      | 58 +++++++++++++++++++++++++++++++++++++
 dlls/msvcp120_app/msvcp120_app.spec |  4 +--
 dlls/msvcp90/ios.c                  | 36 +++++++++++++++++++++++
 5 files changed, 100 insertions(+), 6 deletions(-)

diff --git a/dlls/msvcp110/msvcp110.spec b/dlls/msvcp110/msvcp110.spec
index 5c48c76..c388eaf 100644
--- a/dlls/msvcp110/msvcp110.spec
+++ b/dlls/msvcp110/msvcp110.spec
@@ -1196,8 +1196,8 @@
 @ cdecl -arch=arm ?_Empty@?$_Yarn at _W@std@@QBA_NXZ(ptr) _Yarn_wchar__Empty
 @ thiscall -arch=i386 ?_Empty@?$_Yarn at _W@std@@QBE_NXZ(ptr) _Yarn_wchar__Empty
 @ cdecl -arch=win64 ?_Empty@?$_Yarn at _W@std@@QEBA_NXZ(ptr) _Yarn_wchar__Empty
-@ stub -arch=win32 ?_Equivalent at sys@tr2 at std@@YAHPBD0 at Z
-@ stub -arch=win64 ?_Equivalent at sys@tr2 at std@@YAHPEBD0 at Z
+@ cdecl -arch=win32 ?_Equivalent at sys@tr2 at std@@YAHPBD0 at Z(str str) tr2_sys__Equivalent
+@ cdecl -arch=win64 ?_Equivalent at sys@tr2 at std@@YAHPEBD0 at Z(str str) tr2_sys__Equivalent
 @ stub -arch=win32 ?_Equivalent at sys@tr2 at std@@YAHPB_W0 at Z
 @ stub -arch=win64 ?_Equivalent at sys@tr2 at std@@YAHPEB_W0 at Z
 @ cdecl -arch=win32 ?_Ffmt@?$num_put at DV?$ostreambuf_iterator at DU?$char_traits at D@std@@@std@@@std@@ABAPADPADDH at Z(ptr ptr long long) num_put_char__Ffmt
diff --git a/dlls/msvcp120/msvcp120.spec b/dlls/msvcp120/msvcp120.spec
index a6e60b1..c74e6ca 100644
--- a/dlls/msvcp120/msvcp120.spec
+++ b/dlls/msvcp120/msvcp120.spec
@@ -1161,8 +1161,8 @@
 @ cdecl -arch=arm ?_Empty@?$_Yarn at _W@std@@QBA_NXZ(ptr) _Yarn_wchar__Empty
 @ thiscall -arch=i386 ?_Empty@?$_Yarn at _W@std@@QBE_NXZ(ptr) _Yarn_wchar__Empty
 @ cdecl -arch=win64 ?_Empty@?$_Yarn at _W@std@@QEBA_NXZ(ptr) _Yarn_wchar__Empty
-@ stub -arch=win32 ?_Equivalent at sys@tr2 at std@@YAHPBD0 at Z
-@ stub -arch=win64 ?_Equivalent at sys@tr2 at std@@YAHPEBD0 at Z
+@ cdecl -arch=win32 ?_Equivalent at sys@tr2 at std@@YAHPBD0 at Z(str str) tr2_sys__Equivalent
+@ cdecl -arch=win64 ?_Equivalent at sys@tr2 at std@@YAHPEBD0 at Z(str str) tr2_sys__Equivalent
 @ stub -arch=win32 ?_Equivalent at sys@tr2 at std@@YAHPB_W0 at Z
 @ stub -arch=win64 ?_Equivalent at sys@tr2 at std@@YAHPEB_W0 at Z
 @ cdecl -arch=win32 ?_Ffmt@?$num_put at DV?$ostreambuf_iterator at DU?$char_traits at D@std@@@std@@@std@@ABAPADPADDH at Z(ptr ptr long long) num_put_char__Ffmt
diff --git a/dlls/msvcp120/tests/msvcp120.c b/dlls/msvcp120/tests/msvcp120.c
index 41e4c56..defa934 100644
--- a/dlls/msvcp120/tests/msvcp120.c
+++ b/dlls/msvcp120/tests/msvcp120.c
@@ -60,6 +60,7 @@ static void (CDECL *p__Do_call)(void *this);
 
 /* filesystem */
 static ULONGLONG(__cdecl *p_tr2_sys__File_size)(char const*);
+static int (__cdecl *p_tr2_sys__Equivalent)(char const*, char const*);
 
 static HMODULE msvcp;
 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
@@ -90,9 +91,13 @@ static BOOL init(void)
     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 {
         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");
     }
 
     msvcr = GetModuleHandleA("msvcr120.dll");
@@ -338,6 +343,58 @@ static void test_tr2_sys__File_size(void)
     ok(RemoveDirectoryA("tr2_test_dir"), "Expected tr2_test_dir to exist\n");
 }
 
+static void test_tr2_sys__Equivalent(void)
+{
+    int val, i;
+    HANDLE file;
+    char temp_path[MAX_PATH], current_path[MAX_PATH];
+    struct {
+        char const *path1;
+        char const *path2;
+        int equivalent;
+    } tests[] = {
+        { NULL, NULL, -1 },
+        { NULL, "f1", -1 },
+        { "f1", NULL, -1 },
+        { "f1", "tr2_test_dir", -1 },
+        { "tr2_test_dir", "f1", -1 },
+        { "tr2_test_dir", "tr2_test_dir", -1 },
+        { "tr2_test_dir/./f1", "tr2_test_dir/f2", 0 },
+        { "tr2_test_dir/f1"  , "tr2_test_dir/f1", 1 },
+        { "not_exists_file"  , "tr2_test_dir/f1", 0 },
+        { "tr2_test_dir\\f1" , "tr2_test_dir/./f1", 1 },
+        { "not_exists_file"  , "not_exists_file",  -1 },
+        { "tr2_test_dir/f1"  , "not_exists_file",   0 },
+        { "tr2_test_dir/../tr2_test_dir/f1", "tr2_test_dir/f1", 1 }
+    };
+
+    memset(current_path, 0, MAX_PATH);
+    GetCurrentDirectoryA(MAX_PATH, current_path);
+    memset(temp_path, 0, MAX_PATH);
+    GetTempPathA(MAX_PATH, temp_path);
+    ok(SetCurrentDirectoryA(temp_path), "SetCurrentDirectoryA to temp_path failed\n");
+    CreateDirectoryA("tr2_test_dir", NULL);
+
+    file = CreateFileA("tr2_test_dir/f1", 0, 0, NULL, CREATE_ALWAYS, 0, NULL);
+    ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
+    CloseHandle(file);
+    file = CreateFileA("tr2_test_dir/f2", 0, 0, NULL, CREATE_ALWAYS, 0, NULL);
+    ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
+    CloseHandle(file);
+
+    for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
+        errno = 0xdeadbeef;
+        val = p_tr2_sys__Equivalent(tests[i].path1, tests[i].path2);
+        ok(tests[i].equivalent == val, "tr2_sys__Equivalent(): test %d expect: %d, got %d\n", i+1, tests[i].equivalent, val);
+        ok(errno == 0xdeadbeef, "errno = %d\n", errno);
+    }
+
+    ok(DeleteFileA("tr2_test_dir/f1"), "Expected tr2_test_dir/f1 to exist\n");
+    ok(DeleteFileA("tr2_test_dir/f2"), "Expected tr2_test_dir/f2 to exist\n");
+    ok(RemoveDirectoryA("tr2_test_dir"), "Expected tr2_test_dir to exist\n");
+    ok(SetCurrentDirectoryA(current_path), "SetCurrentDirectoryA failed\n");
+}
+
 START_TEST(msvcp120)
 {
     if(!init()) return;
@@ -348,5 +405,6 @@ START_TEST(msvcp120)
     test__Do_call();
 
     test_tr2_sys__File_size();
+    test_tr2_sys__Equivalent();
     FreeLibrary(msvcp);
 }
diff --git a/dlls/msvcp120_app/msvcp120_app.spec b/dlls/msvcp120_app/msvcp120_app.spec
index e317987..fdbda65 100644
--- a/dlls/msvcp120_app/msvcp120_app.spec
+++ b/dlls/msvcp120_app/msvcp120_app.spec
@@ -1161,8 +1161,8 @@
 @ cdecl -arch=arm ?_Empty@?$_Yarn at _W@std@@QBA_NXZ(ptr) msvcp120.?_Empty@?$_Yarn at _W@std@@QBA_NXZ
 @ thiscall -arch=i386 ?_Empty@?$_Yarn at _W@std@@QBE_NXZ(ptr) msvcp120.?_Empty@?$_Yarn at _W@std@@QBE_NXZ
 @ cdecl -arch=win64 ?_Empty@?$_Yarn at _W@std@@QEBA_NXZ(ptr) msvcp120.?_Empty@?$_Yarn at _W@std@@QEBA_NXZ
-@ stub -arch=win32 ?_Equivalent at sys@tr2 at std@@YAHPBD0 at Z
-@ stub -arch=win64 ?_Equivalent at sys@tr2 at std@@YAHPEBD0 at Z
+@ cdecl -arch=win32 ?_Equivalent at sys@tr2 at std@@YAHPBD0 at Z(str str) msvcp120.?_Equivalent at sys@tr2 at std@@YAHPBD0 at Z
+@ cdecl -arch=win64 ?_Equivalent at sys@tr2 at std@@YAHPEBD0 at Z(str str) msvcp120.?_Equivalent at sys@tr2 at std@@YAHPEBD0 at Z
 @ stub -arch=win32 ?_Equivalent at sys@tr2 at std@@YAHPB_W0 at Z
 @ stub -arch=win64 ?_Equivalent at sys@tr2 at std@@YAHPEB_W0 at Z
 @ cdecl -arch=win32 ?_Ffmt@?$num_put at DV?$ostreambuf_iterator at DU?$char_traits at D@std@@@std@@@std@@ABAPADPADDH at Z(ptr ptr long long) msvcp120.?_Ffmt@?$num_put at DV?$ostreambuf_iterator at DU?$char_traits at D@std@@@std@@@std@@ABAPADPADDH at Z
diff --git a/dlls/msvcp90/ios.c b/dlls/msvcp90/ios.c
index 7b8e226..d68e26a 100644
--- a/dlls/msvcp90/ios.c
+++ b/dlls/msvcp90/ios.c
@@ -14205,6 +14205,42 @@ ULONGLONG __cdecl tr2_sys__File_size(const char* path)
     return ((ULONGLONG)(fad.nFileSizeHigh) << 32) + fad.nFileSizeLow;
 }
 
+/* ?_Equivalent at sys@tr2 at std@@YAHPBD0 at Z  */
+/* ?_Equivalent at sys@tr2 at std@@YAHPEBD0 at Z */
+int __cdecl tr2_sys__Equivalent(char const* path1, char const* path2)
+{
+    HANDLE h1, h2;
+    int ret;
+    BY_HANDLE_FILE_INFORMATION info1, info2;
+    TRACE("(%p %p)\n", path1, path2);
+
+    h1 = CreateFileA(path1, 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
+            NULL, OPEN_EXISTING, 0, 0);
+    h2 = CreateFileA(path2, 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
+            NULL, OPEN_EXISTING, 0, 0);
+    if(h1 == INVALID_HANDLE_VALUE) {
+        if(h2 == INVALID_HANDLE_VALUE) {
+            return -1;
+        }else {
+            CloseHandle(h2);
+            return 0;
+        }
+    }else if(h2 == INVALID_HANDLE_VALUE) {
+        CloseHandle(h1);
+        return 0;
+    }
+
+    ret = GetFileInformationByHandle(h1, &info1) && GetFileInformationByHandle(h2, &info2);
+    CloseHandle(h1);
+    CloseHandle(h2);
+    if(!ret)
+        return -1;
+    return (info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber
+            && info1.nFileIndexHigh == info2.nFileIndexHigh
+            && info1.nFileIndexLow == info2.nFileIndexLow
+            );
+}
+
 /* ??0strstream at std@@QAE at PADHH@Z */
 /* ??0strstream at std@@QEAA at PEAD_JH@Z */
 #if STREAMSIZE_BITS == 64




More information about the wine-cvs mailing list