Module: wine Branch: master Commit: 31726e3823f822ec107f899003729287930dcbdf URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=31726e3823f822ec107f8990...
Author: Robert Shearman rob@codeweavers.com Date: Wed Aug 16 12:29:07 2006 +0100
ole32: Add tests for the failure cases of CLSIDFromProgID and fix the function to conform to these.
---
dlls/ole32/compobj.c | 18 ++++++++++++++---- dlls/ole32/tests/compobj.c | 14 ++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/dlls/ole32/compobj.c b/dlls/ole32/compobj.c index 8857fcc..0537b2c 100644 --- a/dlls/ole32/compobj.c +++ b/dlls/ole32/compobj.c @@ -1102,20 +1102,30 @@ HRESULT WINAPI ProgIDFromCLSID(REFCLSID * * PARAMS * progid [I] Unicode program ID, as found in registry. - * riid [O] Associated CLSID. + * clsid [O] Associated CLSID. * * RETURNS * Success: S_OK * Failure: CO_E_CLASSSTRING - the given ProgID cannot be found. */ -HRESULT WINAPI CLSIDFromProgID(LPCOLESTR progid, LPCLSID riid) +HRESULT WINAPI CLSIDFromProgID(LPCOLESTR progid, LPCLSID clsid) { static const WCHAR clsidW[] = { '\','C','L','S','I','D',0 }; WCHAR buf2[CHARS_IN_GUID]; LONG buf2len = sizeof(buf2); HKEY xhkey; + WCHAR *buf;
- WCHAR *buf = HeapAlloc( GetProcessHeap(),0,(strlenW(progid)+8) * sizeof(WCHAR) ); + if (!progid || !clsid) + { + ERR("neither progid (%p) nor clsid (%p) are optional\n", progid, clsid); + return E_INVALIDARG; + } + + /* initialise clsid in case of failure */ + memset(clsid, 0, sizeof(*clsid)); + + buf = HeapAlloc( GetProcessHeap(),0,(strlenW(progid)+8) * sizeof(WCHAR) ); strcpyW( buf, progid ); strcatW( buf, clsidW ); if (RegOpenKeyW(HKEY_CLASSES_ROOT,buf,&xhkey)) @@ -1131,7 +1141,7 @@ HRESULT WINAPI CLSIDFromProgID(LPCOLESTR return CO_E_CLASSSTRING; } RegCloseKey(xhkey); - return CLSIDFromString(buf2,riid); + return CLSIDFromString(buf2,clsid); }
diff --git a/dlls/ole32/tests/compobj.c b/dlls/ole32/tests/compobj.c index bcce10a..6f2247d 100644 --- a/dlls/ole32/tests/compobj.c +++ b/dlls/ole32/tests/compobj.c @@ -37,6 +37,7 @@ #define ok_ole_success(hr, func) ok(hr = static const CLSID CLSID_non_existent = { 0x12345678, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } }; static const CLSID CLSID_CDeviceMoniker = { 0x4315d437, 0x5b8c, 0x11d0, { 0xbd, 0x3b, 0x00, 0xa0, 0xc9, 0x11, 0xce, 0x86 } }; static const WCHAR devicedotone[] = {'d','e','v','i','c','e','.','1',0}; +static const WCHAR wszNonExistant[] = {'N','o','n','E','x','i','s','t','a','n','t',0}; static const WCHAR wszCLSID_CDeviceMoniker[] = { '{', @@ -84,6 +85,19 @@ static void test_CLSIDFromProgID(void) hr = CLSIDFromString((LPOLESTR)devicedotone, &clsid); ok_ole_success(hr, "CLSIDFromString"); ok(IsEqualCLSID(&clsid, &CLSID_CDeviceMoniker), "clsid wasn't equal to CLSID_CDeviceMoniker\n"); + + /* test some failure cases */ + + hr = CLSIDFromProgID(wszNonExistant, NULL); + ok(hr == E_INVALIDARG, "CLSIDFromProgID should have returned E_INVALIDARG instead of 0x%08lx\n", hr); + + hr = CLSIDFromProgID(NULL, &clsid); + ok(hr == E_INVALIDARG, "CLSIDFromProgID should have returned E_INVALIDARG instead of 0x%08lx\n", hr); + + memset(&clsid, 0xcc, sizeof(clsid)); + hr = CLSIDFromProgID(wszNonExistant, &clsid); + ok(hr == CO_E_CLASSSTRING, "CLSIDFromProgID on non-existant ProgID should have returned CO_E_CLASSSTRING instead of 0x%08lx\n", hr); + ok(IsEqualCLSID(&clsid, &CLSID_NULL), "CLSIDFromProgID should have set clsid to all-zeros on failure\n"); }
static void test_CLSIDFromString(void)