[SCRRUN_WINETEST]
authorAmine Khaldi <amine.khaldi@reactos.org>
Wed, 8 Oct 2014 18:04:21 +0000 (18:04 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Wed, 8 Oct 2014 18:04:21 +0000 (18:04 +0000)
* Sync with Wine 1.7.27.
CORE-8540

svn path=/trunk/; revision=64602

rostests/winetests/scrrun/filesystem.c

index c258a0f..bf159b6 100644 (file)
@@ -41,10 +41,20 @@ static inline ULONG get_refcount(IUnknown *iface)
 }
 
 static const WCHAR crlfW[] = {'\r','\n',0};
+static const char utf16bom[] = {0xff,0xfe,0};
 
 #define GET_REFCOUNT(iface) \
     get_refcount((IUnknown*)iface)
 
+static inline void get_temp_path(const WCHAR *prefix, WCHAR *path)
+{
+    WCHAR buffW[MAX_PATH];
+
+    GetTempPathW(MAX_PATH, buffW);
+    GetTempFileNameW(buffW, prefix, 0, path);
+    DeleteFileW(path);
+}
+
 static void test_interfaces(void)
 {
     static const WCHAR nonexistent_dirW[] = {
@@ -129,15 +139,13 @@ static void test_interfaces(void)
 
 static void test_createfolder(void)
 {
-    WCHAR pathW[MAX_PATH], buffW[MAX_PATH];
+    WCHAR buffW[MAX_PATH];
     HRESULT hr;
     BSTR path;
     IFolder *folder;
     BOOL ret;
 
-    GetTempPathW(MAX_PATH, pathW);
-    GetTempFileNameW(pathW, NULL, 0, buffW);
-    DeleteFileW(buffW);
+    get_temp_path(NULL, buffW);
     ret = CreateDirectoryW(buffW, NULL);
     ok(ret, "got %d, %d\n", ret, GetLastError());
 
@@ -528,33 +536,31 @@ static void test_GetAbsolutePathName(void)
 
 static void test_GetFile(void)
 {
-    static const WCHAR get_file[] = {'g','e','t','_','f','i','l','e','.','t','s','t',0};
-
-    BSTR path = SysAllocString(get_file);
+    static const WCHAR slW[] = {'\\',0};
+    BSTR path;
+    WCHAR pathW[MAX_PATH];
     FileAttribute fa;
     VARIANT size;
     DWORD gfa;
     IFile *file;
     HRESULT hr;
     HANDLE hf;
+    BOOL ret;
 
+    get_temp_path(NULL, pathW);
+
+    path = SysAllocString(pathW);
     hr = IFileSystem3_GetFile(fs3, path, NULL);
     ok(hr == E_POINTER, "GetFile returned %x, expected E_POINTER\n", hr);
     hr = IFileSystem3_GetFile(fs3, NULL, &file);
     ok(hr == E_INVALIDARG, "GetFile returned %x, expected E_INVALIDARG\n", hr);
 
-    if(GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES) {
-        skip("File already exists, skipping GetFile tests\n");
-        SysFreeString(path);
-        return;
-    }
-
     file = (IFile*)0xdeadbeef;
     hr = IFileSystem3_GetFile(fs3, path, &file);
     ok(!file, "file != NULL\n");
     ok(hr == CTL_E_FILENOTFOUND, "GetFile returned %x, expected CTL_E_FILENOTFOUND\n", hr);
 
-    hf = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_READONLY, NULL);
+    hf = CreateFileW(pathW, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_READONLY, NULL);
     if(hf == INVALID_HANDLE_VALUE) {
         skip("Can't create temporary file\n");
         SysFreeString(path);
@@ -566,7 +572,7 @@ static void test_GetFile(void)
     ok(hr == S_OK, "GetFile returned %x, expected S_OK\n", hr);
 
     hr = IFile_get_Attributes(file, &fa);
-    gfa = GetFileAttributesW(get_file) & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN |
+    gfa = GetFileAttributesW(pathW) & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN |
             FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_ARCHIVE |
             FILE_ATTRIBUTE_REPARSE_POINT | FILE_ATTRIBUTE_COMPRESSED);
     ok(hr == S_OK, "get_Attributes returned %x, expected S_OK\n", hr);
@@ -589,6 +595,18 @@ static void test_GetFile(void)
     ok(hr == CTL_E_FILENOTFOUND, "DeleteFile returned %x, expected CTL_E_FILENOTFOUND\n", hr);
 
     SysFreeString(path);
+
+    /* try with directory */
+    lstrcatW(pathW, slW);
+    ret = CreateDirectoryW(pathW, NULL);
+    ok(ret, "got %d, error %d\n", ret, GetLastError());
+
+    path = SysAllocString(pathW);
+    hr = IFileSystem3_GetFile(fs3, path, &file);
+    ok(hr == CTL_E_FILENOTFOUND, "GetFile returned %x, expected S_OK\n", hr);
+    SysFreeString(path);
+
+    RemoveDirectoryW(pathW);
 }
 
 static inline BOOL create_file(const WCHAR *name)
@@ -858,9 +876,7 @@ static void test_FolderCollection(void)
     BSTR str;
     int found_a = 0, found_b = 0, found_c = 0;
 
-    GetTempPathW(MAX_PATH, pathW);
-    GetTempFileNameW(pathW, fooW, 0, buffW);
-    DeleteFileW(buffW);
+    get_temp_path(fooW, buffW);
     CreateDirectoryW(buffW, NULL);
 
     str = SysAllocString(buffW);
@@ -1042,9 +1058,7 @@ static void test_FileCollection(void)
     HANDLE file_a, file_b, file_c;
     int found_a = 0, found_b = 0, found_c = 0;
 
-    GetTempPathW(MAX_PATH, pathW);
-    GetTempFileNameW(pathW, fooW, 0, buffW);
-    DeleteFileW(buffW);
+    get_temp_path(fooW, buffW);
     CreateDirectoryW(buffW, NULL);
 
     str = SysAllocString(buffW);
@@ -1070,9 +1084,7 @@ static void test_FileCollection(void)
 
     count = 0;
     hr = IFileCollection_get_Count(files, &count);
-todo_wine
     ok(hr == S_OK, "got 0x%08x\n", hr);
-todo_wine
     ok(count == 2, "got %d\n", count);
 
     lstrcpyW(pathW, buffW);
@@ -1083,9 +1095,7 @@ todo_wine
     /* every time property is requested it scans directory */
     count = 0;
     hr = IFileCollection_get_Count(files, &count);
-todo_wine
     ok(hr == S_OK, "got 0x%08x\n", hr);
-todo_wine
     ok(count == 3, "got %d\n", count);
 
     hr = IFileCollection_get__NewEnum(files, NULL);
@@ -1278,20 +1288,29 @@ static void test_DriveCollection(void)
             V_VT(&size) = VT_EMPTY;
             hr = IDrive_get_TotalSize(drive, &size);
             ok(hr == S_OK, "got 0x%08x\n", hr);
-            ok(V_VT(&size) == VT_R8, "got %d\n", V_VT(&size));
-            ok(V_R8(&size) > 0, "got %f\n", V_R8(&size));
+            ok(V_VT(&size) == VT_R8 || V_VT(&size) == VT_I4, "got %d\n", V_VT(&size));
+            if (V_VT(&size) == VT_R8)
+                ok(V_R8(&size) > 0, "got %f\n", V_R8(&size));
+            else
+                ok(V_I4(&size) > 0, "got %d\n", V_I4(&size));
 
             V_VT(&size) = VT_EMPTY;
             hr = IDrive_get_AvailableSpace(drive, &size);
             ok(hr == S_OK, "got 0x%08x\n", hr);
-            ok(V_VT(&size) == VT_R8, "got %d\n", V_VT(&size));
-            ok(V_R8(&size) > 0, "got %f\n", V_R8(&size));
+            ok(V_VT(&size) == VT_R8 || V_VT(&size) == VT_I4, "got %d\n", V_VT(&size));
+            if (V_VT(&size) == VT_R8)
+                ok(V_R8(&size) > (double)INT_MAX, "got %f\n", V_R8(&size));
+            else
+                ok(V_I4(&size) > 0, "got %d\n", V_I4(&size));
 
             V_VT(&size) = VT_EMPTY;
             hr = IDrive_get_FreeSpace(drive, &size);
             ok(hr == S_OK, "got 0x%08x\n", hr);
-            ok(V_VT(&size) == VT_R8, "got %d\n", V_VT(&size));
-            ok(V_R8(&size) > 0, "got %f\n", V_R8(&size));
+            ok(V_VT(&size) == VT_R8 || V_VT(&size) == VT_I4, "got %d\n", V_VT(&size));
+            if (V_VT(&size) == VT_R8)
+                ok(V_R8(&size) > 0, "got %f\n", V_R8(&size));
+            else
+                ok(V_I4(&size) > 0, "got %d\n", V_I4(&size));
         }
         VariantClear(&var);
     }
@@ -1304,8 +1323,7 @@ static void test_CreateTextFile(void)
 {
     static const WCHAR scrrunW[] = {'s','c','r','r','u','n','\\',0};
     static const WCHAR testfileW[] = {'t','e','s','t','.','t','x','t',0};
-    static const WCHAR bomAW[] = {0xff,0xfe,0};
-    WCHAR pathW[MAX_PATH], dirW[MAX_PATH];
+    WCHAR pathW[MAX_PATH], dirW[MAX_PATH], buffW[10];
     ITextStream *stream;
     BSTR nameW, str;
     HANDLE file;
@@ -1352,11 +1370,16 @@ static void test_CreateTextFile(void)
     ok(hr == S_OK, "got 0x%08x\n", hr);
     ITextStream_Release(stream);
 
+    /* File was created in Unicode mode, it contains 0xfffe BOM. Opening it in non-Unicode mode
+       treats BOM like a valuable data with appropriate CP_ACP -> WCHAR conversion. */
+    buffW[0] = 0;
+    MultiByteToWideChar(CP_ACP, 0, utf16bom, -1, buffW, sizeof(buffW)/sizeof(WCHAR));
+
     hr = IFileSystem3_OpenTextFile(fs3, nameW, ForReading, VARIANT_FALSE, TristateFalse, &stream);
     ok(hr == S_OK, "got 0x%08x\n", hr);
     hr = ITextStream_ReadAll(stream, &str);
     ok(hr == S_FALSE || broken(hr == S_OK) /* win2k */, "got 0x%08x\n", hr);
-    ok(!lstrcmpW(str, bomAW), "got %s\n", wine_dbgstr_w(str));
+    ok(!lstrcmpW(str, buffW), "got %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(buffW));
     SysFreeString(str);
     ITextStream_Release(stream);
 
@@ -1493,7 +1516,9 @@ static void test_ReadAll(void)
     str = NULL;
     hr = ITextStream_ReadAll(stream, &str);
     ok(hr == S_FALSE || broken(hr == S_OK) /* win2k */, "got 0x%08x\n", hr);
-    ok(str[0] == 0x00ff && str[1] == 0x00fe, "got %s, %d\n", wine_dbgstr_w(str), SysStringLen(str));
+    buffW[0] = 0;
+    MultiByteToWideChar(CP_ACP, 0, utf16bom, -1, buffW, sizeof(buffW)/sizeof(WCHAR));
+    ok(str[0] == buffW[0] && str[1] == buffW[1], "got %s, %d\n", wine_dbgstr_w(str), SysStringLen(str));
     SysFreeString(str);
     ITextStream_Release(stream);
 
@@ -1640,7 +1665,11 @@ static void test_Read(void)
     str = NULL;
     hr = ITextStream_Read(stream, 2, &str);
     ok(hr == S_OK, "got 0x%08x\n", hr);
-    ok(str[0] == 0x00ff && str[1] == 0x00fe, "got %s, %d\n", wine_dbgstr_w(str), SysStringLen(str));
+
+    buffW[0] = 0;
+    MultiByteToWideChar(CP_ACP, 0, utf16bom, -1, buffW, sizeof(buffW)/sizeof(WCHAR));
+
+    ok(!lstrcmpW(str, buffW), "got %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(buffW));
     ok(SysStringLen(str) == 2, "got %d\n", SysStringLen(str));
     SysFreeString(str);
     ITextStream_Release(stream);
@@ -1718,6 +1747,121 @@ todo_wine
     SysFreeString(nameW);
 }
 
+struct getdrivename_test {
+    const WCHAR path[10];
+    const WCHAR drive[5];
+};
+
+static const struct getdrivename_test getdrivenametestdata[] = {
+    { {'C',':','\\','1','.','t','s','t',0}, {'C',':',0} },
+    { {'O',':','\\','1','.','t','s','t',0}, {'O',':',0} },
+    { {'O',':',0}, {'O',':',0} },
+    { {'o',':',0}, {'o',':',0} },
+    { {'O','O',':',0} },
+    { {':',0} },
+    { {'O',0} },
+    { { 0 } }
+};
+
+static void test_GetDriveName(void)
+{
+    const struct getdrivename_test *ptr = getdrivenametestdata;
+    HRESULT hr;
+    BSTR name;
+
+    hr = IFileSystem3_GetDriveName(fs3, NULL, NULL);
+    ok(hr == E_POINTER, "got 0x%08x\n", hr);
+
+    name = (void*)0xdeadbeef;
+    hr = IFileSystem3_GetDriveName(fs3, NULL, &name);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    ok(name == NULL, "got %p\n", name);
+
+    while (*ptr->path) {
+        BSTR path = SysAllocString(ptr->path);
+        name = (void*)0xdeadbeef;
+        hr = IFileSystem3_GetDriveName(fs3, path, &name);
+        ok(hr == S_OK, "got 0x%08x\n", hr);
+        if (name)
+            ok(!lstrcmpW(ptr->drive, name), "got %s, expected %s\n", wine_dbgstr_w(name), wine_dbgstr_w(ptr->drive));
+        else
+            ok(!*ptr->drive, "got %s, expected %s\n", wine_dbgstr_w(name), wine_dbgstr_w(ptr->drive));
+        SysFreeString(path);
+        SysFreeString(name);
+        ptr++;
+    }
+}
+
+static void test_SerialNumber(void)
+{
+    IDriveCollection *drives;
+    IEnumVARIANT *iter;
+    IDrive *drive;
+    LONG serial;
+    HRESULT hr;
+    BSTR name;
+
+    hr = IFileSystem3_get_Drives(fs3, &drives);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+
+    hr = IDriveCollection_get__NewEnum(drives, (IUnknown**)&iter);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    IDriveCollection_Release(drives);
+
+    while (1) {
+        DriveTypeConst type;
+        VARIANT var;
+
+        hr = IEnumVARIANT_Next(iter, 1, &var, NULL);
+        if (hr == S_FALSE) {
+            skip("No fixed drive found, skipping test.\n");
+            IEnumVARIANT_Release(iter);
+            return;
+        }
+        ok(hr == S_OK, "got 0x%08x\n", hr);
+
+        hr = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IDrive, (void**)&drive);
+        ok(hr == S_OK, "got 0x%08x\n", hr);
+        VariantClear(&var);
+
+        hr = IDrive_get_DriveType(drive, &type);
+        ok(hr == S_OK, "got 0x%08x\n", hr);
+        if (type == Fixed)
+            break;
+
+        IDrive_Release(drive);
+    }
+
+    hr = IDrive_get_SerialNumber(drive, NULL);
+    ok(hr == E_POINTER, "got 0x%08x\n", hr);
+
+    serial = 0xdeadbeef;
+    hr = IDrive_get_SerialNumber(drive, &serial);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    ok(serial != 0xdeadbeef, "got %x\n", serial);
+
+    hr = IDrive_get_FileSystem(drive, NULL);
+    ok(hr == E_POINTER, "got 0x%08x\n", hr);
+
+    name = NULL;
+    hr = IDrive_get_FileSystem(drive, &name);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    ok(name != NULL, "got %p\n", name);
+    SysFreeString(name);
+
+    hr = IDrive_get_VolumeName(drive, NULL);
+    ok(hr == E_POINTER, "got 0x%08x\n", hr);
+
+    name = NULL;
+    hr = IDrive_get_VolumeName(drive, &name);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    ok(name != NULL, "got %p\n", name);
+    SysFreeString(name);
+
+    IDrive_Release(drive);
+    IEnumVARIANT_Release(iter);
+}
+
 START_TEST(filesystem)
 {
     HRESULT hr;
@@ -1750,6 +1894,8 @@ START_TEST(filesystem)
     test_WriteLine();
     test_ReadAll();
     test_Read();
+    test_GetDriveName();
+    test_SerialNumber();
 
     IFileSystem3_Release(fs3);