[1/3] scrrun: Implement filesys_DriveExists. (try 2)

Joachim Priesner joachim.priesner at web.de
Thu Oct 15 16:36:16 CDT 2015


v2 - Return false for DRIVE_UNKNOWN drive type

Signed-off-by: Joachim Priesner <joachim.priesner at web.de>
---
 dlls/scrrun/filesystem.c       | 16 ++++++++--
 dlls/scrrun/tests/filesystem.c | 67 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+), 2 deletions(-)

diff --git a/dlls/scrrun/filesystem.c b/dlls/scrrun/filesystem.c
index 3de38d2..cff7725 100644
--- a/dlls/scrrun/filesystem.c
+++ b/dlls/scrrun/filesystem.c
@@ -3221,9 +3221,21 @@ static HRESULT WINAPI filesys_GetTempName(IFileSystem3 *iface, BSTR *pbstrResult
 static HRESULT WINAPI filesys_DriveExists(IFileSystem3 *iface, BSTR DriveSpec,
                                             VARIANT_BOOL *pfExists)
 {
-    FIXME("%p %s %p\n", iface, debugstr_w(DriveSpec), pfExists);
+    UINT len;
+    TRACE("%p %s %p\n", iface, debugstr_w(DriveSpec), pfExists);
 
-    return E_NOTIMPL;
+    if (!pfExists) return E_POINTER;
+    *pfExists = VARIANT_FALSE;
+    len = SysStringLen(DriveSpec);
+    if (len >= 1 && DriveSpec[0] >= 'A' && DriveSpec[0] <= 'Z'
+            && (len < 2 || DriveSpec[1] == ':')
+            && (len < 3 || DriveSpec[2] == '\\')) {
+        const WCHAR root[] = {toupperW(DriveSpec[0]), ':', '\\', 0};
+        UINT drivetype = GetDriveTypeW(root);
+        *pfExists = drivetype != DRIVE_NO_ROOT_DIR && drivetype != DRIVE_UNKNOWN ? VARIANT_TRUE : VARIANT_FALSE;
+    }
+
+    return S_OK;
 }
 
 static HRESULT WINAPI filesys_FileExists(IFileSystem3 *iface, BSTR path, VARIANT_BOOL *ret)
diff --git a/dlls/scrrun/tests/filesystem.c b/dlls/scrrun/tests/filesystem.c
index 28242ce..5270726 100644
--- a/dlls/scrrun/tests/filesystem.c
+++ b/dlls/scrrun/tests/filesystem.c
@@ -1790,6 +1790,72 @@ todo_wine
     SysFreeString(nameW);
 }
 
+struct driveexists_test {
+    const WCHAR drivespec[10];
+    const INT drivetype;
+    const VARIANT_BOOL expected_ret;
+};
+
+/* The first character of 'drivespec' will be replaced with the drive letter
+ * of a drive of type 'drivetype'. If such a drive does not exist, the test
+ * will be skipped. */
+static const struct driveexists_test driveexiststestdata[] = {
+    { {'N',':','\\',0}, DRIVE_NO_ROOT_DIR, VARIANT_FALSE },
+    { {'R',':','\\',0}, DRIVE_REMOVABLE, VARIANT_TRUE },
+    { {'F',':','\\',0}, DRIVE_FIXED, VARIANT_TRUE },
+    { {'F',':',0}, DRIVE_FIXED, VARIANT_TRUE },
+    { {'F','?',0}, DRIVE_FIXED, VARIANT_FALSE },
+    { {'F',0}, DRIVE_FIXED, VARIANT_TRUE },
+    { {'?',0}, -1, VARIANT_FALSE },
+    { { 0 } }
+};
+
+static void test_DriveExists(void)
+{
+    const struct driveexists_test *ptr = driveexiststestdata;
+    HRESULT hr;
+    VARIANT_BOOL ret;
+    BSTR drivespec;
+    WCHAR root[] = {'?',':','\\',0};
+
+    hr = IFileSystem3_DriveExists(fs3, NULL, NULL);
+    ok(hr == E_POINTER, "got 0x%08x\n", hr);
+
+    ret = VARIANT_TRUE;
+    hr = IFileSystem3_DriveExists(fs3, NULL, &ret);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    ok(ret == VARIANT_FALSE, "wrong result of DriveExists\n");
+
+    drivespec = SysAllocString(root);
+    hr = IFileSystem3_DriveExists(fs3, drivespec, NULL);
+    ok(hr == E_POINTER, "got 0x%08x\n", hr);
+    SysFreeString(drivespec);
+
+    for (; *ptr->drivespec; ptr++) {
+        drivespec = SysAllocString(ptr->drivespec);
+        if (ptr->drivetype != -1) {
+            for (root[0] = 'A'; root[0] <= 'Z'; root[0]++)
+                if (GetDriveTypeW(root) == ptr->drivetype)
+                    break;
+            if (root[0] > 'Z') {
+                skip("No drive with type 0x%x found, skipping test %s.\n",
+                        ptr->drivetype, wine_dbgstr_w(ptr->drivespec));
+                SysFreeString(drivespec);
+                continue;
+            }
+            drivespec[0] = root[0];
+        }
+
+        ret = ptr->expected_ret == VARIANT_TRUE ? VARIANT_FALSE : VARIANT_TRUE;
+        hr = IFileSystem3_DriveExists(fs3, drivespec, &ret);
+        ok(hr == S_OK, "got 0x%08x for drive spec %s (%s)\n",
+                hr, wine_dbgstr_w(drivespec), wine_dbgstr_w(ptr->drivespec));
+        ok(ret == ptr->expected_ret, "got %d, expected %d for drive spec %s (%s)\n",
+                ret, ptr->expected_ret, wine_dbgstr_w(drivespec), wine_dbgstr_w(ptr->drivespec));
+        SysFreeString(drivespec);
+    }
+}
+
 struct getdrivename_test {
     const WCHAR path[10];
     const WCHAR drive[5];
@@ -2019,6 +2085,7 @@ START_TEST(filesystem)
     test_WriteLine();
     test_ReadAll();
     test_Read();
+    test_DriveExists();
     test_GetDriveName();
     test_SerialNumber();
     test_GetExtensionName();
-- 
2.1.4




More information about the wine-patches mailing list