From e864854ce3c68f35183161f9d3e688d7de38988e Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Tue, 6 Mar 2018 10:58:23 -0600 Subject: [PATCH] shell32/tests: Clean up and expand tests for IShellFolder_ParseDisplayName(). Signed-off-by: Zebediah Figura Signed-off-by: Alexandre Julliard --- dlls/shell32/tests/shlfolder.c | 161 ++++++++++++++++----------------- 1 file changed, 79 insertions(+), 82 deletions(-) diff --git a/dlls/shell32/tests/shlfolder.c b/dlls/shell32/tests/shlfolder.c index bd4bba2236f..1b140c05013 100644 --- a/dlls/shell32/tests/shlfolder.c +++ b/dlls/shell32/tests/shlfolder.c @@ -44,6 +44,8 @@ DEFINE_GUID(IID_IParentAndItem, 0xB3A4B685, 0xB685, 0x4805, 0x99,0xD9, 0x5D,0xEA,0xD2,0x87,0x32,0x36); DEFINE_GUID(CLSID_ShellDocObjView, 0xe7e4bc40, 0xe76a, 0x11ce, 0xa9,0xbb, 0x00,0xaa,0x00,0x4a,0xe8,0x37); +#define ARRAY_SIZE(x) ( sizeof(x) / sizeof((x)[0]) ) + static IMalloc *ppM; static HRESULT (WINAPI *pSHCreateItemFromIDList)(PCIDLIST_ABSOLUTE pidl, REFIID riid, void **ppv); @@ -172,108 +174,103 @@ static LPWSTR myPathAddBackslashW( LPWSTR lpszPath ) return lpszPath; } +static struct +{ + WCHAR path[MAX_PATH]; + HRESULT hr; + int todo; +} parse_tests[] = { + {{'c',':','\\',0}, S_OK}, + {{'c',':','\\','\\',0}, E_INVALIDARG, 1}, + {{'c',':','\\','f','a','k','e',0}, 0x80070002}, /* ERROR_FILE_NOT_FOUND */ + {{'c',':','f','a','k','e',0}, E_INVALIDARG, 1}, + {{'c',':','/',0}, E_INVALIDARG, 1}, + {{'c',':','\\','w','i','n','d','o','w','s',0}, S_OK}, + {{'c',':','\\','w','i','n','d','o','w','s','\\',0}, S_OK}, + {{'c',':','\\','w','i','n','d','o','w','s','\\','.',0}, E_INVALIDARG, 1}, + {{'c',':','\\','w','i','n','d','o','w','s','\\','.','.',0}, E_INVALIDARG, 1}, + {{'.',0}, E_INVALIDARG, 1}, + {{'.','.',0}, E_INVALIDARG, 1}, + {{'t','e','s','t',0}, 0x80070002}, + {{'t','e','s','t','\\',0}, 0x80070002}, + {{'s','u','b','\\','d','i','r',0}, 0x80070002}, + {{'s','u','b','/','d','i','r',0}, E_INVALIDARG, 1}, + {{'h','t','t','p',':',0}, S_OK, 1}, + {{'h','t','t','p',':','t','e','s','t',0}, S_OK, 1}, + {{'h','t','t','p',':','\\','t','e','s','t',0}, S_OK, 1}, + {{'x','x',':',0}, S_OK, 1}, +}; + static void test_ParseDisplayName(void) { + static WCHAR testdirW[] = {'p','a','r','s','e','t','e','s','t',0}; + static WCHAR backslashW[] = {'\\',0}; + WCHAR buffer[MAX_PATH], buffer2[MAX_PATH]; + IShellFolder *desktop; + ITEMIDLIST *pidl; HRESULT hr; - IShellFolder *IDesktopFolder; - static const char *cNonExistDir1A = "c:\\nonexist_subdir"; - static const char *cNonExistDir2A = "c:\\\\nonexist_subdir"; - static const char *cInetTestA = "http:\\yyy"; - static const char *cInetTest2A = "xx:yyy"; - DWORD res; - WCHAR cTestDirW [MAX_PATH] = {0}; - ITEMIDLIST *newPIDL; BOOL bRes; + int i; - hr = SHGetDesktopFolder(&IDesktopFolder); + hr = SHGetDesktopFolder(&desktop); ok(hr == S_OK, "Expected SHGetDesktopFolder to return S_OK, got 0x%08x\n", hr); - if(hr != S_OK) return; - if (pSHCreateShellItem) + hr = IShellFolder_ParseDisplayName(desktop, NULL, NULL, NULL, NULL, &pidl, NULL); + ok(hr == E_INVALIDARG, "got %#x\n", hr); + + for (i = 0; i < ARRAY_SIZE(parse_tests); i++) { - if (0) - { - /* null name and pidl, crashes on Windows 8 */ - hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, - NULL, NULL, NULL, 0); - ok(hr == E_INVALIDARG, "returned %08x, expected E_INVALIDARG\n", hr); - } - - /* null name */ - newPIDL = (ITEMIDLIST*)0xdeadbeef; - hr = IShellFolder_ParseDisplayName(IDesktopFolder, - NULL, NULL, NULL, NULL, &newPIDL, 0); - ok(newPIDL == 0, "expected null, got %p\n", newPIDL); - ok(hr == E_INVALIDARG, "returned %08x, expected E_INVALIDARG\n", hr); + hr = IShellFolder_ParseDisplayName(desktop, NULL, NULL, parse_tests[i].path, NULL, &pidl, NULL); +todo_wine_if(parse_tests[i].todo) + ok(hr == parse_tests[i].hr, "%s: expected %#x, got %#x\n", + wine_dbgstr_w(parse_tests[i].path), parse_tests[i].hr, hr); + if (SUCCEEDED(hr)) + CoTaskMemFree(pidl); } - else - win_skip("SHCreateShellItem requires XP SP1 or later\n"); - - MultiByteToWideChar(CP_ACP, 0, cInetTestA, -1, cTestDirW, MAX_PATH); - hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0); - todo_wine ok(hr == S_OK, "ParseDisplayName returned %08x, expected SUCCESS\n", hr); - if (hr == S_OK) - { - ok(ILFindLastID(newPIDL)->mkid.abID[0] == 0x61, "Last pidl should be of type " - "PT_IESPECIAL1, but is: %02x\n", ILFindLastID(newPIDL)->mkid.abID[0]); - IMalloc_Free(ppM, newPIDL); - } - - MultiByteToWideChar(CP_ACP, 0, cInetTest2A, -1, cTestDirW, MAX_PATH); - hr = IShellFolder_ParseDisplayName(IDesktopFolder, - NULL, NULL, cTestDirW, NULL, &newPIDL, 0); - todo_wine ok(hr == S_OK, "ParseDisplayName returned %08x, expected SUCCESS\n", hr); - if (hr == S_OK) - { - ok(ILFindLastID(newPIDL)->mkid.abID[0] == 0x61, "Last pidl should be of type " - "PT_IESPECIAL1, but is: %02x\n", ILFindLastID(newPIDL)->mkid.abID[0]); - IMalloc_Free(ppM, newPIDL); - } - - res = GetFileAttributesA(cNonExistDir1A); - if(res != INVALID_FILE_ATTRIBUTES) - { - skip("Test directory unexpectedly exists\n"); - goto finished; - } - - MultiByteToWideChar(CP_ACP, 0, cNonExistDir1A, -1, cTestDirW, MAX_PATH); - hr = IShellFolder_ParseDisplayName(IDesktopFolder, - NULL, NULL, cTestDirW, NULL, &newPIDL, 0); - ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), - "ParseDisplayName returned %08x, expected 0x80070002\n", hr); - - res = GetFileAttributesA(cNonExistDir2A); - if(res != INVALID_FILE_ATTRIBUTES) - { - skip("Test directory unexpectedly exists\n"); - goto finished; - } - - MultiByteToWideChar(CP_ACP, 0, cNonExistDir2A, -1, cTestDirW, MAX_PATH); - hr = IShellFolder_ParseDisplayName(IDesktopFolder, - NULL, NULL, cTestDirW, NULL, &newPIDL, 0); - todo_wine ok(hr == E_INVALIDARG, "ParseDisplayName returned %08x, expected E_INVALIDARG\n", hr); /* I thought that perhaps the DesktopFolder's ParseDisplayName would recognize the * path corresponding to CSIDL_PERSONAL and return a CLSID_MyDocuments PIDL. Turns * out it doesn't. The magic seems to happen in the file dialogs, then. */ - bRes = SHGetSpecialFolderPathW(NULL, cTestDirW, CSIDL_PERSONAL, FALSE); + bRes = SHGetSpecialFolderPathW(NULL, buffer, CSIDL_PERSONAL, FALSE); ok(bRes, "SHGetSpecialFolderPath(CSIDL_PERSONAL) failed! %u\n", GetLastError()); - if (!bRes) goto finished; - hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0); + hr = IShellFolder_ParseDisplayName(desktop, NULL, NULL, buffer, NULL, &pidl, 0); ok(hr == S_OK, "DesktopFolder->ParseDisplayName failed. hr = %08x.\n", hr); - if (hr != S_OK) goto finished; - ok(ILFindLastID(newPIDL)->mkid.abID[0] == 0x31, + ok(ILFindLastID(pidl)->mkid.abID[0] == 0x31, "Last pidl should be of type PT_FOLDER, but is: %02x\n", - ILFindLastID(newPIDL)->mkid.abID[0]); - IMalloc_Free(ppM, newPIDL); + ILFindLastID(pidl)->mkid.abID[0]); + CoTaskMemFree(pidl); -finished: - IShellFolder_Release(IDesktopFolder); + /* Relative paths are interpreted relative to the desktop. */ + GetTempPathW(sizeof(buffer), buffer); + GetLongPathNameW(buffer, buffer, sizeof(buffer)); + SetCurrentDirectoryW(buffer); + CreateDirectoryW(testdirW, NULL); + + hr = IShellFolder_ParseDisplayName(desktop, NULL, NULL, testdirW, NULL, &pidl, NULL); + ok(hr == 0x80070002, "got %#x\n", hr); + + RemoveDirectoryW(testdirW); + + hr = SHGetSpecialFolderPathW(NULL, buffer, CSIDL_DESKTOP, FALSE); + ok(hr == S_FALSE, "got %#x\n", hr); + SetCurrentDirectoryW(buffer); + CreateDirectoryW(testdirW, NULL); + + hr = IShellFolder_ParseDisplayName(desktop, NULL, NULL, testdirW, NULL, &pidl, NULL); + ok(hr == S_OK, "got %#x\n", hr); + + ok(SHGetPathFromIDListW(pidl, buffer2), "SHGetPathFromIDList failed\n"); + lstrcatW(buffer, backslashW); + lstrcatW(buffer, testdirW); + ok(!lstrcmpW(buffer, buffer2), "expected %s, got %s\n", wine_dbgstr_w(buffer), wine_dbgstr_w(buffer2)); + + RemoveDirectoryW(testdirW); + CoTaskMemFree(pidl); + + IShellFolder_Release(desktop); } /* creates a file with the specified name for tests */