Commit 31726e38 authored by Robert Shearman's avatar Robert Shearman Committed by Alexandre Julliard

ole32: Add tests for the failure cases of CLSIDFromProgID and fix the function to conform to these.

parent 4bbc3ca8
......@@ -1102,20 +1102,30 @@ HRESULT WINAPI ProgIDFromCLSID(REFCLSID clsid, LPOLESTR *lplpszProgID)
*
* 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 progid, LPCLSID riid)
return CO_E_CLASSSTRING;
}
RegCloseKey(xhkey);
return CLSIDFromString(buf2,riid);
return CLSIDFromString(buf2,clsid);
}
......
......@@ -37,6 +37,7 @@ HRESULT (WINAPI * pCoInitializeEx)(LPVOID lpReserved, DWORD dwCoInit);
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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment