Module: wine Branch: master Commit: d51a35c565ca4e39faa4eb2999d7c54878a43405 URL: http://source.winehq.org/git/wine.git/?a=commit;h=d51a35c565ca4e39faa4eb2999...
Author: Piotr Caban piotr@codeweavers.com Date: Tue Jul 23 18:50:46 2013 +0200
scrrun: Add IFileSystem3::GetParentFolderName implementation.
---
dlls/scrrun/filesystem.c | 45 +++++++++++++++++++++++++++++++++++- dlls/scrrun/tests/filesystem.c | 49 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 2 deletions(-)
diff --git a/dlls/scrrun/filesystem.c b/dlls/scrrun/filesystem.c index 4f0b163..6af8123 100644 --- a/dlls/scrrun/filesystem.c +++ b/dlls/scrrun/filesystem.c @@ -728,12 +728,53 @@ static HRESULT WINAPI filesys_GetDriveName(IFileSystem3 *iface, BSTR Path, return E_NOTIMPL; }
+static inline DWORD get_parent_folder_name(const WCHAR *path, DWORD len) +{ + int i; + + if(!path) + return 0; + + for(i=len-1; i>=0; i--) + if(path[i]!='/' && path[i]!='\') + break; + + for(; i>=0; i--) + if(path[i]=='/' || path[i]=='\') + break; + + for(; i>=0; i--) + if(path[i]!='/' && path[i]!='\') + break; + + if(i < 0) + return 0; + + if(path[i]==':' && i==1) + i++; + return i+1; +} + static HRESULT WINAPI filesys_GetParentFolderName(IFileSystem3 *iface, BSTR Path, BSTR *pbstrResult) { - FIXME("%p %s %p\n", iface, debugstr_w(Path), pbstrResult); + DWORD len;
- return E_NOTIMPL; + TRACE("%p %s %p\n", iface, debugstr_w(Path), pbstrResult); + + if(!pbstrResult) + return E_POINTER; + + len = get_parent_folder_name(Path, SysStringLen(Path)); + if(!len) { + *pbstrResult = NULL; + return S_OK; + } + + *pbstrResult = SysAllocStringLen(Path, len); + if(!*pbstrResult) + return E_OUTOFMEMORY; + return S_OK; }
static HRESULT WINAPI filesys_GetFileName(IFileSystem3 *iface, BSTR Path, diff --git a/dlls/scrrun/tests/filesystem.c b/dlls/scrrun/tests/filesystem.c index b93927c..3f0f959 100644 --- a/dlls/scrrun/tests/filesystem.c +++ b/dlls/scrrun/tests/filesystem.c @@ -254,6 +254,54 @@ static void test_GetFileVersion(void) SysFreeString(path); }
+static void test_GetParentFolderName(void) +{ + static const WCHAR path1[] = {'a',0}; + static const WCHAR path2[] = {'a','/','a','/','a',0}; + static const WCHAR path3[] = {'a','\','a','\','a',0}; + static const WCHAR path4[] = {'a','/','a','/','/','\','\',0}; + static const WCHAR path5[] = {'c',':','\','\','a',0}; + static const WCHAR path6[] = {'a','c',':','\','a',0}; + static const WCHAR result2[] = {'a','/','a',0}; + static const WCHAR result3[] = {'a','\','a',0}; + static const WCHAR result4[] = {'a',0}; + static const WCHAR result5[] = {'c',':','\',0}; + static const WCHAR result6[] = {'a','c',':',0}; + + static const struct { + const WCHAR *path; + const WCHAR *result; + } tests[] = { + {NULL, NULL}, + {path1, NULL}, + {path2, result2}, + {path3, result3}, + {path4, result4}, + {path5, result5}, + {path6, result6} + }; + + BSTR path, result; + HRESULT hr; + int i; + + hr = IFileSystem3_GetParentFolderName(fs3, NULL, NULL); + ok(hr == E_POINTER, "GetParentFolderName returned %x, expected E_POINTER\n", hr); + + for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) { + result = (BSTR)0xdeadbeef; + path = tests[i].path ? SysAllocString(tests[i].path) : NULL; + hr = IFileSystem3_GetParentFolderName(fs3, path, &result); + ok(hr == S_OK, "%d) GetParentFolderName returned %x, expected S_OK\n", i, hr); + if(!tests[i].result) + ok(!result, "%d) result = %s\n", i, wine_dbgstr_w(result)); + else + ok(!lstrcmpW(result, tests[i].result), "%d) result = %s\n", i, wine_dbgstr_w(result)); + SysFreeString(path); + SysFreeString(result); + } +} + START_TEST(filesystem) { HRESULT hr; @@ -271,6 +319,7 @@ START_TEST(filesystem) test_createfolder(); test_textstream(); test_GetFileVersion(); + test_GetParentFolderName();
IFileSystem3_Release(fs3);