Piotr Caban : scrrun: Add IFileSystem3::GetBaseName implementation.
Alexandre Julliard
julliard at winehq.org
Wed Jul 24 14:55:27 CDT 2013
Module: wine
Branch: master
Commit: dd64952040b64293103f44f068026455c972fa42
URL: http://source.winehq.org/git/wine.git/?a=commit;h=dd64952040b64293103f44f068026455c972fa42
Author: Piotr Caban <piotr at codeweavers.com>
Date: Tue Jul 23 18:51:05 2013 +0200
scrrun: Add IFileSystem3::GetBaseName implementation.
---
dlls/scrrun/filesystem.c | 34 +++++++++++++++++++++++++++-
dlls/scrrun/tests/filesystem.c | 47 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 79 insertions(+), 2 deletions(-)
diff --git a/dlls/scrrun/filesystem.c b/dlls/scrrun/filesystem.c
index 9099951..62bc676 100644
--- a/dlls/scrrun/filesystem.c
+++ b/dlls/scrrun/filesystem.c
@@ -815,9 +815,39 @@ static HRESULT WINAPI filesys_GetFileName(IFileSystem3 *iface, BSTR Path,
static HRESULT WINAPI filesys_GetBaseName(IFileSystem3 *iface, BSTR Path,
BSTR *pbstrResult)
{
- FIXME("%p %s %p\n", iface, debugstr_w(Path), pbstrResult);
+ int i, end;
- return E_NOTIMPL;
+ TRACE("%p %s %p\n", iface, debugstr_w(Path), pbstrResult);
+
+ if(!pbstrResult)
+ return E_POINTER;
+
+ if(!Path) {
+ *pbstrResult = NULL;
+ return S_OK;
+ }
+
+ for(end=strlenW(Path)-1; end>=0; end--)
+ if(Path[end]!='/' && Path[end]!='\\')
+ break;
+
+ for(i=end; i>=0; i--) {
+ if(Path[i]=='.' && Path[end+1]!='.')
+ end = i-1;
+ if(Path[i]=='/' || Path[i]=='\\')
+ break;
+ }
+ i++;
+
+ if((i>end && Path[end+1]!='.') || (i==0 && end==1 && Path[1]==':')) {
+ *pbstrResult = NULL;
+ return S_OK;
+ }
+
+ *pbstrResult = SysAllocStringLen(Path+i, end-i+1);
+ if(!*pbstrResult)
+ return E_OUTOFMEMORY;
+ return S_OK;
}
static HRESULT WINAPI filesys_GetExtensionName(IFileSystem3 *iface, BSTR Path,
diff --git a/dlls/scrrun/tests/filesystem.c b/dlls/scrrun/tests/filesystem.c
index 940356f..4cd4e2d 100644
--- a/dlls/scrrun/tests/filesystem.c
+++ b/dlls/scrrun/tests/filesystem.c
@@ -345,6 +345,52 @@ static void test_GetFileName(void)
}
}
+static void test_GetBaseName(void)
+{
+ static const WCHAR path1[] = {'a',0};
+ static const WCHAR path2[] = {'a','/','a','.','b','.','c',0};
+ static const WCHAR path3[] = {'a','.','b','\\',0};
+ static const WCHAR path4[] = {'c',':',0};
+ static const WCHAR path5[] = {'/','\\',0};
+ static const WCHAR path6[] = {'.','a',0};
+ static const WCHAR result1[] = {'a',0};
+ static const WCHAR result2[] = {'a','.','b',0};
+ static const WCHAR result6[] = {0};
+
+ static const struct {
+ const WCHAR *path;
+ const WCHAR *result;
+ } tests[] = {
+ {NULL, NULL},
+ {path1, result1},
+ {path2, result2},
+ {path3, result1},
+ {path4, NULL},
+ {path5, NULL},
+ {path6, result6}
+ };
+
+ BSTR path, result;
+ HRESULT hr;
+ int i;
+
+ hr = IFileSystem3_GetBaseName(fs3, NULL, NULL);
+ ok(hr == E_POINTER, "GetBaseName 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_GetBaseName(fs3, path, &result);
+ ok(hr == S_OK, "%d) GetBaseName 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;
@@ -364,6 +410,7 @@ START_TEST(filesystem)
test_GetFileVersion();
test_GetParentFolderName();
test_GetFileName();
+ test_GetBaseName();
IFileSystem3_Release(fs3);
More information about the wine-cvs
mailing list