Commit 0e99d795 authored by Robert Shearman's avatar Robert Shearman Committed by Alexandre Julliard

ole32: Add some more tests for failure cases of Co* functions and make builtin ole32 pass them.

parent 31726e38
......@@ -915,6 +915,9 @@ HRESULT WINAPI CLSIDFromString(LPOLESTR idstr, CLSID *id )
{
HRESULT ret;
if (!id)
return E_INVALIDARG;
ret = __CLSIDFromString(idstr, id);
if(ret != S_OK) { /* It appears a ProgID is also valid */
ret = CLSIDFromProgID(idstr, id);
......@@ -1057,21 +1060,27 @@ HRESULT COM_OpenKeyForCLSID(REFCLSID clsid, LPCWSTR keyname, REGSAM access, HKEY
*
* PARAMS
* clsid [I] Class ID, as found in registry.
* lplpszProgID [O] Associated ProgID.
* ppszProgID [O] Associated ProgID.
*
* RETURNS
* S_OK
* E_OUTOFMEMORY
* REGDB_E_CLASSNOTREG if the given clsid has no associated ProgID
*/
HRESULT WINAPI ProgIDFromCLSID(REFCLSID clsid, LPOLESTR *lplpszProgID)
HRESULT WINAPI ProgIDFromCLSID(REFCLSID clsid, LPOLESTR *ppszProgID)
{
static const WCHAR wszProgID[] = {'P','r','o','g','I','D',0};
HKEY hkey;
HRESULT ret;
LONG progidlen = 0;
*lplpszProgID = NULL;
if (!ppszProgID)
{
ERR("ppszProgId isn't optional\n");
return E_INVALIDARG;
}
*ppszProgID = NULL;
ret = COM_OpenKeyForCLSID(clsid, wszProgID, KEY_READ, &hkey);
if (FAILED(ret))
return ret;
......@@ -1081,10 +1090,10 @@ HRESULT WINAPI ProgIDFromCLSID(REFCLSID clsid, LPOLESTR *lplpszProgID)
if (ret == S_OK)
{
*lplpszProgID = CoTaskMemAlloc(progidlen * sizeof(WCHAR));
if (*lplpszProgID)
*ppszProgID = CoTaskMemAlloc(progidlen * sizeof(WCHAR));
if (*ppszProgID)
{
if (RegQueryValueW(hkey, NULL, *lplpszProgID, &progidlen))
if (RegQueryValueW(hkey, NULL, *ppszProgID, &progidlen))
ret = REGDB_E_CLASSNOTREG;
}
else
......@@ -1200,6 +1209,12 @@ HRESULT WINAPI CoGetPSClsid(REFIID riid, CLSID *pclsid)
return CO_E_NOTINITIALIZED;
}
if (!pclsid)
{
ERR("pclsid isn't optional\n");
return E_INVALIDARG;
}
EnterCriticalSection(&apt->cs);
LIST_FOR_EACH_ENTRY(registered_psclsid, &apt->psclsids, struct registered_psclsid, entry)
......
......@@ -73,6 +73,9 @@ static void test_ProgIDFromCLSID(void)
hr = ProgIDFromCLSID(&CLSID_non_existent, &progid);
ok(hr == REGDB_E_CLASSNOTREG, "ProgIDFromCLSID returned %08lx\n", hr);
ok(progid == NULL, "ProgIDFromCLSID returns with progid %p\n", progid);
hr = ProgIDFromCLSID(&CLSID_CDeviceMoniker, NULL);
ok(hr == E_INVALIDARG, "ProgIDFromCLSID should return E_INVALIDARG instead of 0x%08lx\n", hr);
}
static void test_CLSIDFromProgID(void)
......@@ -106,6 +109,10 @@ static void test_CLSIDFromString(void)
HRESULT hr = CLSIDFromString((LPOLESTR)wszCLSID_CDeviceMoniker, &clsid);
ok_ole_success(hr, "CLSIDFromString");
ok(IsEqualCLSID(&clsid, &CLSID_CDeviceMoniker), "clsid wasn't equal to CLSID_CDeviceMoniker\n");
hr = CLSIDFromString(NULL, &clsid);
ok_ole_success(hr, "CLSIDFromString");
ok(IsEqualCLSID(&clsid, &CLSID_NULL), "clsid wasn't equal to CLSID_NULL\n");
}
static void test_CoCreateInstance(void)
......@@ -418,6 +425,35 @@ static void test_CoRegisterPSClsid(void)
CoUninitialize();
}
static void test_CoGetPSClsid(void)
{
HRESULT hr;
CLSID clsid;
hr = CoGetPSClsid(&IID_IClassFactory, &clsid);
ok(hr == CO_E_NOTINITIALIZED,
"CoGetPSClsid should have returned CO_E_NOTINITIALIZED instead of 0x%08lx\n",
hr);
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
hr = CoGetPSClsid(&IID_IClassFactory, &clsid);
ok_ole_success(hr, "CoGetPSClsid");
hr = CoGetPSClsid(&IID_IWineTest, &clsid);
ok(hr == REGDB_E_IIDNOTREG,
"CoGetPSClsid for random IID returned 0x%08lx instead of REGDB_E_IIDNOTREG\n",
hr);
hr = CoGetPSClsid(&IID_IClassFactory, NULL);
ok(hr == E_INVALIDARG,
"CoGetPSClsid for null clsid returned 0x%08lx instead of E_INVALIDARG\n",
hr);
CoUninitialize();
}
START_TEST(compobj)
{
HMODULE hOle32 = GetModuleHandle("ole32");
......@@ -435,4 +471,5 @@ START_TEST(compobj)
test_CoGetClassObject();
test_CoRegisterMessageFilter();
test_CoRegisterPSClsid();
test_CoGetPSClsid();
}
......@@ -46,20 +46,6 @@ static const IID IID_IWineTest =
{0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd}
}; /* 5201163f-8164-4fd0-a1a2-5d5a3654d3bd */
static void test_CoGetPSClsid(void)
{
HRESULT hr;
CLSID clsid;
hr = CoGetPSClsid(&IID_IClassFactory, &clsid);
ok_ole_success(hr, CoGetPSClsid);
hr = CoGetPSClsid(&IID_IWineTest, &clsid);
ok(hr == REGDB_E_IIDNOTREG,
"CoGetPSClsid for random IID returned 0x%08lx instead of REGDB_E_IIDNOTREG\n",
hr);
}
static void test_cocreateinstance_proxy(void)
{
IUnknown *pProxy;
......@@ -2281,9 +2267,6 @@ START_TEST(marshal)
/* FIXME: test CoCreateInstanceEx */
/* helper function tests */
test_CoGetPSClsid();
/* lifecycle management and marshaling tests */
test_no_marshaler();
test_normal_marshal_and_release();
......
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