2005-06-20 12:33:17 +02:00
|
|
|
/*
|
|
|
|
* Component Object Tests
|
|
|
|
*
|
|
|
|
* Copyright 2005 Robert Shearman
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-06-20 12:33:17 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
2006-09-29 12:45:44 +02:00
|
|
|
#define CONST_VTABLE
|
2005-06-20 12:33:17 +02:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "objbase.h"
|
2006-02-20 11:16:08 +01:00
|
|
|
#include "shlguid.h"
|
2007-04-04 19:56:14 +02:00
|
|
|
#include "urlmon.h" /* for CLSID_FileProtocol */
|
2005-06-20 12:33:17 +02:00
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2006-07-14 18:13:58 +02:00
|
|
|
/* functions that are not present on all versions of Windows */
|
|
|
|
HRESULT (WINAPI * pCoInitializeEx)(LPVOID lpReserved, DWORD dwCoInit);
|
2007-11-01 14:26:56 +01:00
|
|
|
HRESULT (WINAPI * pCoGetObjectContext)(REFIID riid, LPVOID *ppv);
|
2006-07-14 18:13:58 +02:00
|
|
|
|
2006-10-14 04:54:46 +02:00
|
|
|
#define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
|
2007-01-09 18:17:15 +01:00
|
|
|
#define ok_more_than_one_lock() ok(cLocks > 0, "Number of locks should be > 0, but actually is %d\n", cLocks)
|
|
|
|
#define ok_no_locks() ok(cLocks == 0, "Number of locks should be 0, but actually is %d\n", cLocks)
|
2005-06-20 12:33:17 +02:00
|
|
|
|
2006-01-20 19:41:56 +01:00
|
|
|
static const CLSID CLSID_non_existent = { 0x12345678, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
|
2005-06-20 12:33:17 +02:00
|
|
|
static const CLSID CLSID_CDeviceMoniker = { 0x4315d437, 0x5b8c, 0x11d0, { 0xbd, 0x3b, 0x00, 0xa0, 0xc9, 0x11, 0xce, 0x86 } };
|
2007-01-23 14:40:20 +01:00
|
|
|
static WCHAR devicedotone[] = {'d','e','v','i','c','e','.','1',0};
|
2006-09-07 20:01:50 +02:00
|
|
|
static const WCHAR wszNonExistent[] = {'N','o','n','E','x','i','s','t','e','n','t',0};
|
2007-01-23 14:40:20 +01:00
|
|
|
static WCHAR wszCLSID_CDeviceMoniker[] =
|
2006-01-09 18:40:27 +01:00
|
|
|
{
|
|
|
|
'{',
|
|
|
|
'4','3','1','5','d','4','3','7','-',
|
|
|
|
'5','b','8','c','-',
|
|
|
|
'1','1','d','0','-',
|
|
|
|
'b','d','3','b','-',
|
|
|
|
'0','0','a','0','c','9','1','1','c','e','8','6',
|
|
|
|
'}',0
|
|
|
|
};
|
2005-06-20 12:33:17 +02:00
|
|
|
|
2006-07-20 20:30:21 +02:00
|
|
|
static const IID IID_IWineTest =
|
|
|
|
{
|
|
|
|
0x5201163f,
|
|
|
|
0x8164,
|
|
|
|
0x4fd0,
|
|
|
|
{0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd}
|
|
|
|
}; /* 5201163f-8164-4fd0-a1a2-5d5a3654d3bd */
|
2007-05-08 00:58:12 +02:00
|
|
|
static const CLSID CLSID_WineOOPTest = {
|
|
|
|
0x5201163f,
|
|
|
|
0x8164,
|
|
|
|
0x4fd0,
|
|
|
|
{0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd}
|
|
|
|
}; /* 5201163f-8164-4fd0-a1a2-5d5a3654d3bd */
|
2006-07-20 20:30:21 +02:00
|
|
|
|
2007-01-09 18:17:15 +01:00
|
|
|
static LONG cLocks;
|
|
|
|
|
|
|
|
static void LockModule(void)
|
|
|
|
{
|
|
|
|
InterlockedIncrement(&cLocks);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UnlockModule(void)
|
|
|
|
{
|
|
|
|
InterlockedDecrement(&cLocks);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Test_IClassFactory_QueryInterface(
|
|
|
|
LPCLASSFACTORY iface,
|
|
|
|
REFIID riid,
|
|
|
|
LPVOID *ppvObj)
|
|
|
|
{
|
|
|
|
if (ppvObj == NULL) return E_POINTER;
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualGUID(riid, &IID_IClassFactory))
|
|
|
|
{
|
|
|
|
*ppvObj = (LPVOID)iface;
|
|
|
|
IClassFactory_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppvObj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI Test_IClassFactory_AddRef(LPCLASSFACTORY iface)
|
|
|
|
{
|
|
|
|
LockModule();
|
|
|
|
return 2; /* non-heap-based object */
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI Test_IClassFactory_Release(LPCLASSFACTORY iface)
|
|
|
|
{
|
|
|
|
UnlockModule();
|
|
|
|
return 1; /* non-heap-based object */
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Test_IClassFactory_CreateInstance(
|
|
|
|
LPCLASSFACTORY iface,
|
|
|
|
LPUNKNOWN pUnkOuter,
|
|
|
|
REFIID riid,
|
|
|
|
LPVOID *ppvObj)
|
|
|
|
{
|
|
|
|
*ppvObj = NULL;
|
|
|
|
if (pUnkOuter) return CLASS_E_NOAGGREGATION;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Test_IClassFactory_LockServer(
|
|
|
|
LPCLASSFACTORY iface,
|
|
|
|
BOOL fLock)
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IClassFactoryVtbl TestClassFactory_Vtbl =
|
|
|
|
{
|
|
|
|
Test_IClassFactory_QueryInterface,
|
|
|
|
Test_IClassFactory_AddRef,
|
|
|
|
Test_IClassFactory_Release,
|
|
|
|
Test_IClassFactory_CreateInstance,
|
|
|
|
Test_IClassFactory_LockServer
|
|
|
|
};
|
|
|
|
|
|
|
|
static IClassFactory Test_ClassFactory = { &TestClassFactory_Vtbl };
|
2006-07-20 20:30:21 +02:00
|
|
|
|
2005-06-20 12:33:17 +02:00
|
|
|
static void test_ProgIDFromCLSID(void)
|
|
|
|
{
|
|
|
|
LPWSTR progid;
|
|
|
|
HRESULT hr = ProgIDFromCLSID(&CLSID_CDeviceMoniker, &progid);
|
2006-10-14 04:54:46 +02:00
|
|
|
ok(hr == S_OK, "ProgIDFromCLSID failed with error 0x%08x\n", hr);
|
2005-06-20 12:33:17 +02:00
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
ok(!lstrcmpiW(progid, devicedotone), "Didn't get expected prog ID\n");
|
|
|
|
CoTaskMemFree(progid);
|
|
|
|
}
|
2006-01-20 19:41:56 +01:00
|
|
|
|
|
|
|
progid = (LPWSTR)0xdeadbeef;
|
|
|
|
hr = ProgIDFromCLSID(&CLSID_non_existent, &progid);
|
2006-10-14 04:54:46 +02:00
|
|
|
ok(hr == REGDB_E_CLASSNOTREG, "ProgIDFromCLSID returned %08x\n", hr);
|
2006-01-20 19:41:56 +01:00
|
|
|
ok(progid == NULL, "ProgIDFromCLSID returns with progid %p\n", progid);
|
2006-08-16 13:29:17 +02:00
|
|
|
|
|
|
|
hr = ProgIDFromCLSID(&CLSID_CDeviceMoniker, NULL);
|
2006-10-14 04:54:46 +02:00
|
|
|
ok(hr == E_INVALIDARG, "ProgIDFromCLSID should return E_INVALIDARG instead of 0x%08x\n", hr);
|
2005-06-20 12:33:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_CLSIDFromProgID(void)
|
|
|
|
{
|
|
|
|
CLSID clsid;
|
|
|
|
HRESULT hr = CLSIDFromProgID(devicedotone, &clsid);
|
2006-10-14 04:54:46 +02:00
|
|
|
ok(hr == S_OK, "CLSIDFromProgID failed with error 0x%08x\n", hr);
|
2005-06-20 12:33:17 +02:00
|
|
|
ok(IsEqualCLSID(&clsid, &CLSID_CDeviceMoniker), "clsid wasn't equal to CLSID_CDeviceMoniker\n");
|
2006-01-09 18:40:27 +01:00
|
|
|
|
2007-01-23 14:40:20 +01:00
|
|
|
hr = CLSIDFromString(devicedotone, &clsid);
|
2006-01-09 18:40:27 +01:00
|
|
|
ok_ole_success(hr, "CLSIDFromString");
|
|
|
|
ok(IsEqualCLSID(&clsid, &CLSID_CDeviceMoniker), "clsid wasn't equal to CLSID_CDeviceMoniker\n");
|
2006-08-16 13:29:07 +02:00
|
|
|
|
|
|
|
/* test some failure cases */
|
|
|
|
|
2006-09-07 20:01:50 +02:00
|
|
|
hr = CLSIDFromProgID(wszNonExistent, NULL);
|
2006-10-14 04:54:46 +02:00
|
|
|
ok(hr == E_INVALIDARG, "CLSIDFromProgID should have returned E_INVALIDARG instead of 0x%08x\n", hr);
|
2006-08-16 13:29:07 +02:00
|
|
|
|
|
|
|
hr = CLSIDFromProgID(NULL, &clsid);
|
2006-10-14 04:54:46 +02:00
|
|
|
ok(hr == E_INVALIDARG, "CLSIDFromProgID should have returned E_INVALIDARG instead of 0x%08x\n", hr);
|
2006-08-16 13:29:07 +02:00
|
|
|
|
|
|
|
memset(&clsid, 0xcc, sizeof(clsid));
|
2006-09-07 20:01:50 +02:00
|
|
|
hr = CLSIDFromProgID(wszNonExistent, &clsid);
|
2006-10-14 04:54:46 +02:00
|
|
|
ok(hr == CO_E_CLASSSTRING, "CLSIDFromProgID on nonexistent ProgID should have returned CO_E_CLASSSTRING instead of 0x%08x\n", hr);
|
2006-08-16 13:29:07 +02:00
|
|
|
ok(IsEqualCLSID(&clsid, &CLSID_NULL), "CLSIDFromProgID should have set clsid to all-zeros on failure\n");
|
2006-01-09 18:40:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_CLSIDFromString(void)
|
|
|
|
{
|
|
|
|
CLSID clsid;
|
2007-01-23 14:40:20 +01:00
|
|
|
HRESULT hr = CLSIDFromString(wszCLSID_CDeviceMoniker, &clsid);
|
2006-01-09 18:40:27 +01:00
|
|
|
ok_ole_success(hr, "CLSIDFromString");
|
|
|
|
ok(IsEqualCLSID(&clsid, &CLSID_CDeviceMoniker), "clsid wasn't equal to CLSID_CDeviceMoniker\n");
|
2006-08-16 13:29:17 +02:00
|
|
|
|
|
|
|
hr = CLSIDFromString(NULL, &clsid);
|
|
|
|
ok_ole_success(hr, "CLSIDFromString");
|
|
|
|
ok(IsEqualCLSID(&clsid, &CLSID_NULL), "clsid wasn't equal to CLSID_NULL\n");
|
2005-06-20 12:33:17 +02:00
|
|
|
}
|
|
|
|
|
2006-02-20 11:16:08 +01:00
|
|
|
static void test_CoCreateInstance(void)
|
|
|
|
{
|
|
|
|
REFCLSID rclsid = &CLSID_MyComputer;
|
|
|
|
IUnknown *pUnk = (IUnknown *)0xdeadbeef;
|
|
|
|
HRESULT hr = CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&pUnk);
|
2006-10-14 04:54:46 +02:00
|
|
|
ok(hr == CO_E_NOTINITIALIZED, "CoCreateInstance should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr);
|
2006-02-20 11:16:08 +01:00
|
|
|
ok(pUnk == NULL, "CoCreateInstance should have changed the passed in pointer to NULL, instead of %p\n", pUnk);
|
|
|
|
|
|
|
|
OleInitialize(NULL);
|
|
|
|
hr = CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&pUnk);
|
|
|
|
ok_ole_success(hr, "CoCreateInstance");
|
|
|
|
IUnknown_Release(pUnk);
|
|
|
|
OleUninitialize();
|
|
|
|
|
|
|
|
hr = CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&pUnk);
|
2006-10-14 04:54:46 +02:00
|
|
|
ok(hr == CO_E_NOTINITIALIZED, "CoCreateInstance should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr);
|
2006-02-20 11:16:08 +01:00
|
|
|
}
|
|
|
|
|
2006-07-14 01:02:24 +02:00
|
|
|
static void test_CoGetClassObject(void)
|
|
|
|
{
|
|
|
|
IUnknown *pUnk = (IUnknown *)0xdeadbeef;
|
|
|
|
HRESULT hr = CoGetClassObject(&CLSID_MyComputer, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void **)&pUnk);
|
2006-10-14 04:54:46 +02:00
|
|
|
ok(hr == CO_E_NOTINITIALIZED, "CoGetClassObject should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr);
|
2006-07-14 01:02:24 +02:00
|
|
|
ok(pUnk == NULL, "CoGetClassObject should have changed the passed in pointer to NULL, instead of %p\n", pUnk);
|
|
|
|
|
|
|
|
hr = CoGetClassObject(&CLSID_MyComputer, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, NULL);
|
2006-10-14 04:54:46 +02:00
|
|
|
ok(hr == E_INVALIDARG, "CoGetClassObject should have returned E_INVALIDARG instead of 0x%08x\n", hr);
|
2006-07-14 01:02:24 +02:00
|
|
|
}
|
|
|
|
|
2006-06-14 14:20:01 +02:00
|
|
|
static ATOM register_dummy_class(void)
|
|
|
|
{
|
|
|
|
WNDCLASS wc =
|
|
|
|
{
|
|
|
|
0,
|
|
|
|
DefWindowProc,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
GetModuleHandle(NULL),
|
|
|
|
NULL,
|
|
|
|
LoadCursor(NULL, IDC_ARROW),
|
|
|
|
(HBRUSH)(COLOR_BTNFACE+1),
|
|
|
|
NULL,
|
|
|
|
TEXT("WineOleTestClass"),
|
|
|
|
};
|
2007-01-09 18:17:15 +01:00
|
|
|
|
2006-06-14 14:20:01 +02:00
|
|
|
return RegisterClass(&wc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_ole_menu(void)
|
|
|
|
{
|
|
|
|
HWND hwndFrame;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hwndFrame = CreateWindow(MAKEINTATOM(register_dummy_class()), "Test", 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, NULL, NULL);
|
|
|
|
hr = OleSetMenuDescriptor(NULL, hwndFrame, NULL, NULL, NULL);
|
|
|
|
todo_wine ok_ole_success(hr, "OleSetMenuDescriptor");
|
|
|
|
|
|
|
|
DestroyWindow(hwndFrame);
|
|
|
|
}
|
|
|
|
|
2006-07-14 18:13:58 +02:00
|
|
|
|
|
|
|
static HRESULT WINAPI MessageFilter_QueryInterface(IMessageFilter *iface, REFIID riid, void ** ppvObj)
|
|
|
|
{
|
|
|
|
if (ppvObj == NULL) return E_POINTER;
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualGUID(riid, &IID_IClassFactory))
|
|
|
|
{
|
|
|
|
*ppvObj = (LPVOID)iface;
|
|
|
|
IMessageFilter_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MessageFilter_AddRef(IMessageFilter *iface)
|
|
|
|
{
|
|
|
|
return 2; /* non-heap object */
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MessageFilter_Release(IMessageFilter *iface)
|
|
|
|
{
|
|
|
|
return 1; /* non-heap object */
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI MessageFilter_HandleInComingCall(
|
|
|
|
IMessageFilter *iface,
|
|
|
|
DWORD dwCallType,
|
|
|
|
HTASK threadIDCaller,
|
|
|
|
DWORD dwTickCount,
|
|
|
|
LPINTERFACEINFO lpInterfaceInfo)
|
|
|
|
{
|
|
|
|
trace("HandleInComingCall\n");
|
|
|
|
return SERVERCALL_ISHANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI MessageFilter_RetryRejectedCall(
|
|
|
|
IMessageFilter *iface,
|
|
|
|
HTASK threadIDCallee,
|
|
|
|
DWORD dwTickCount,
|
|
|
|
DWORD dwRejectType)
|
|
|
|
{
|
|
|
|
trace("RetryRejectedCall\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI MessageFilter_MessagePending(
|
|
|
|
IMessageFilter *iface,
|
|
|
|
HTASK threadIDCallee,
|
|
|
|
DWORD dwTickCount,
|
|
|
|
DWORD dwPendingType)
|
|
|
|
{
|
|
|
|
trace("MessagePending\n");
|
|
|
|
return PENDINGMSG_WAITNOPROCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMessageFilterVtbl MessageFilter_Vtbl =
|
|
|
|
{
|
|
|
|
MessageFilter_QueryInterface,
|
|
|
|
MessageFilter_AddRef,
|
|
|
|
MessageFilter_Release,
|
|
|
|
MessageFilter_HandleInComingCall,
|
|
|
|
MessageFilter_RetryRejectedCall,
|
|
|
|
MessageFilter_MessagePending
|
|
|
|
};
|
|
|
|
|
|
|
|
static IMessageFilter MessageFilter = { &MessageFilter_Vtbl };
|
|
|
|
|
|
|
|
static void test_CoRegisterMessageFilter(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IMessageFilter *prev_filter;
|
|
|
|
|
|
|
|
hr = CoRegisterMessageFilter(&MessageFilter, &prev_filter);
|
2006-11-16 18:49:31 +01:00
|
|
|
ok(hr == CO_E_NOT_SUPPORTED,
|
|
|
|
"CoRegisterMessageFilter should have failed with CO_E_NOT_SUPPORTED instead of 0x%08x\n",
|
|
|
|
hr);
|
2006-07-14 18:13:58 +02:00
|
|
|
|
|
|
|
pCoInitializeEx(NULL, COINIT_MULTITHREADED);
|
|
|
|
prev_filter = (IMessageFilter *)0xdeadbeef;
|
|
|
|
hr = CoRegisterMessageFilter(&MessageFilter, &prev_filter);
|
|
|
|
ok(hr == CO_E_NOT_SUPPORTED,
|
2006-10-14 04:54:46 +02:00
|
|
|
"CoRegisterMessageFilter should have failed with CO_E_NOT_SUPPORTED instead of 0x%08x\n",
|
2006-07-14 18:13:58 +02:00
|
|
|
hr);
|
|
|
|
ok(prev_filter == (IMessageFilter *)0xdeadbeef,
|
|
|
|
"prev_filter should have been set to %p\n", prev_filter);
|
|
|
|
CoUninitialize();
|
|
|
|
|
|
|
|
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
|
|
|
|
hr = CoRegisterMessageFilter(NULL, NULL);
|
|
|
|
ok_ole_success(hr, "CoRegisterMessageFilter");
|
|
|
|
|
|
|
|
prev_filter = (IMessageFilter *)0xdeadbeef;
|
|
|
|
hr = CoRegisterMessageFilter(NULL, &prev_filter);
|
|
|
|
ok_ole_success(hr, "CoRegisterMessageFilter");
|
|
|
|
ok(prev_filter == NULL, "prev_filter should have been set to NULL instead of %p\n", prev_filter);
|
|
|
|
|
|
|
|
hr = CoRegisterMessageFilter(&MessageFilter, &prev_filter);
|
|
|
|
ok_ole_success(hr, "CoRegisterMessageFilter");
|
|
|
|
ok(prev_filter == NULL, "prev_filter should have been set to NULL instead of %p\n", prev_filter);
|
|
|
|
|
|
|
|
hr = CoRegisterMessageFilter(NULL, NULL);
|
|
|
|
ok_ole_success(hr, "CoRegisterMessageFilter");
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|
|
|
|
|
2006-07-20 20:30:21 +02:00
|
|
|
static HRESULT WINAPI Test_IUnknown_QueryInterface(
|
|
|
|
LPUNKNOWN iface,
|
|
|
|
REFIID riid,
|
|
|
|
LPVOID *ppvObj)
|
|
|
|
{
|
|
|
|
if (ppvObj == NULL) return E_POINTER;
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IWineTest))
|
|
|
|
{
|
|
|
|
*ppvObj = (LPVOID)iface;
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppvObj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI Test_IUnknown_AddRef(LPUNKNOWN iface)
|
|
|
|
{
|
|
|
|
return 2; /* non-heap-based object */
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI Test_IUnknown_Release(LPUNKNOWN iface)
|
|
|
|
{
|
|
|
|
return 1; /* non-heap-based object */
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IUnknownVtbl TestUnknown_Vtbl =
|
|
|
|
{
|
|
|
|
Test_IUnknown_QueryInterface,
|
|
|
|
Test_IUnknown_AddRef,
|
|
|
|
Test_IUnknown_Release,
|
|
|
|
};
|
|
|
|
|
|
|
|
static IUnknown Test_Unknown = { &TestUnknown_Vtbl };
|
|
|
|
|
|
|
|
static HRESULT WINAPI PSFactoryBuffer_QueryInterface(
|
|
|
|
IPSFactoryBuffer * This,
|
|
|
|
/* [in] */ REFIID riid,
|
|
|
|
/* [iid_is][out] */ void **ppvObject)
|
|
|
|
{
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IPSFactoryBuffer))
|
|
|
|
{
|
|
|
|
*ppvObject = This;
|
|
|
|
IPSFactoryBuffer_AddRef(This);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
2007-01-09 18:17:15 +01:00
|
|
|
|
2006-07-20 20:30:21 +02:00
|
|
|
static ULONG WINAPI PSFactoryBuffer_AddRef(
|
|
|
|
IPSFactoryBuffer * This)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI PSFactoryBuffer_Release(
|
|
|
|
IPSFactoryBuffer * This)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PSFactoryBuffer_CreateProxy(
|
|
|
|
IPSFactoryBuffer * This,
|
|
|
|
/* [in] */ IUnknown *pUnkOuter,
|
|
|
|
/* [in] */ REFIID riid,
|
|
|
|
/* [out] */ IRpcProxyBuffer **ppProxy,
|
|
|
|
/* [out] */ void **ppv)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2007-01-09 18:17:15 +01:00
|
|
|
|
2006-07-20 20:30:21 +02:00
|
|
|
static HRESULT WINAPI PSFactoryBuffer_CreateStub(
|
|
|
|
IPSFactoryBuffer * This,
|
|
|
|
/* [in] */ REFIID riid,
|
|
|
|
/* [unique][in] */ IUnknown *pUnkServer,
|
|
|
|
/* [out] */ IRpcStubBuffer **ppStub)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static IPSFactoryBufferVtbl PSFactoryBufferVtbl =
|
|
|
|
{
|
|
|
|
PSFactoryBuffer_QueryInterface,
|
|
|
|
PSFactoryBuffer_AddRef,
|
|
|
|
PSFactoryBuffer_Release,
|
|
|
|
PSFactoryBuffer_CreateProxy,
|
|
|
|
PSFactoryBuffer_CreateStub
|
|
|
|
};
|
|
|
|
|
|
|
|
static IPSFactoryBuffer PSFactoryBuffer = { &PSFactoryBufferVtbl };
|
|
|
|
|
|
|
|
static const CLSID CLSID_WineTestPSFactoryBuffer =
|
|
|
|
{
|
|
|
|
0x52011640,
|
|
|
|
0x8164,
|
|
|
|
0x4fd0,
|
|
|
|
{0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd}
|
|
|
|
}; /* 52011640-8164-4fd0-a1a2-5d5a3654d3bd */
|
|
|
|
|
|
|
|
static void test_CoRegisterPSClsid(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
DWORD dwRegistrationKey;
|
|
|
|
IStream *stream;
|
|
|
|
CLSID clsid;
|
|
|
|
|
|
|
|
hr = CoRegisterPSClsid(&IID_IWineTest, &CLSID_WineTestPSFactoryBuffer);
|
2006-10-14 04:54:46 +02:00
|
|
|
ok(hr == CO_E_NOTINITIALIZED, "CoRegisterPSClsid should have returened CO_E_NOTINITIALIZED instead of 0x%08x\n", hr);
|
2006-07-20 20:30:21 +02:00
|
|
|
|
|
|
|
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
|
|
|
|
hr = CoRegisterClassObject(&CLSID_WineTestPSFactoryBuffer, (IUnknown *)&PSFactoryBuffer,
|
|
|
|
CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &dwRegistrationKey);
|
|
|
|
ok_ole_success(hr, "CoRegisterClassObject");
|
|
|
|
|
|
|
|
hr = CoRegisterPSClsid(&IID_IWineTest, &CLSID_WineTestPSFactoryBuffer);
|
|
|
|
ok_ole_success(hr, "CoRegisterPSClsid");
|
|
|
|
|
|
|
|
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
|
|
|
|
ok_ole_success(hr, "CreateStreamOnHGlobal");
|
|
|
|
|
|
|
|
hr = CoMarshalInterface(stream, &IID_IWineTest, (IUnknown *)&Test_Unknown, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL);
|
2006-10-14 04:54:46 +02:00
|
|
|
ok(hr == E_NOTIMPL, "CoMarshalInterface should have returned E_NOTIMPL instead of 0x%08x\n", hr);
|
2006-07-20 20:30:21 +02:00
|
|
|
IStream_Release(stream);
|
|
|
|
|
|
|
|
hr = CoRevokeClassObject(dwRegistrationKey);
|
|
|
|
ok_ole_success(hr, "CoRevokeClassObject");
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
|
|
|
|
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
|
|
|
|
hr = CoGetPSClsid(&IID_IWineTest, &clsid);
|
2006-10-14 04:54:46 +02:00
|
|
|
ok(hr == REGDB_E_IIDNOTREG, "CoGetPSClsid should have returned REGDB_E_IIDNOTREG instead of 0x%08x\n", hr);
|
2006-07-20 20:30:21 +02:00
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|
|
|
|
|
2006-08-16 13:29:17 +02:00
|
|
|
static void test_CoGetPSClsid(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
CLSID clsid;
|
|
|
|
|
|
|
|
hr = CoGetPSClsid(&IID_IClassFactory, &clsid);
|
|
|
|
ok(hr == CO_E_NOTINITIALIZED,
|
2006-10-14 04:54:46 +02:00
|
|
|
"CoGetPSClsid should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n",
|
2006-08-16 13:29:17 +02:00
|
|
|
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,
|
2006-10-14 04:54:46 +02:00
|
|
|
"CoGetPSClsid for random IID returned 0x%08x instead of REGDB_E_IIDNOTREG\n",
|
2006-08-16 13:29:17 +02:00
|
|
|
hr);
|
|
|
|
|
|
|
|
hr = CoGetPSClsid(&IID_IClassFactory, NULL);
|
|
|
|
ok(hr == E_INVALIDARG,
|
2006-10-14 04:54:46 +02:00
|
|
|
"CoGetPSClsid for null clsid returned 0x%08x instead of E_INVALIDARG\n",
|
2006-08-16 13:29:17 +02:00
|
|
|
hr);
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|
|
|
|
|
2007-01-09 18:17:34 +01:00
|
|
|
/* basic test, mainly for invalid arguments. see marshal.c for more */
|
|
|
|
static void test_CoUnmarshalInterface(void)
|
|
|
|
{
|
|
|
|
IUnknown *pProxy;
|
|
|
|
IStream *pStream;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = CoUnmarshalInterface(NULL, &IID_IUnknown, (void **)&pProxy);
|
|
|
|
ok(hr == E_INVALIDARG, "CoUnmarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
|
|
|
|
ok_ole_success(hr, "CreateStreamOnHGlobal");
|
|
|
|
|
2007-03-06 18:58:21 +01:00
|
|
|
hr = CoUnmarshalInterface(pStream, &IID_IUnknown, (void **)&pProxy);
|
|
|
|
todo_wine
|
|
|
|
ok(hr == CO_E_NOTINITIALIZED, "CoUnmarshalInterface should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr);
|
|
|
|
|
|
|
|
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
|
2007-01-09 18:17:34 +01:00
|
|
|
hr = CoUnmarshalInterface(pStream, &IID_IUnknown, (void **)&pProxy);
|
|
|
|
ok(hr == STG_E_READFAULT, "CoUnmarshalInterface should have returned STG_E_READFAULT instead of 0x%08x\n", hr);
|
|
|
|
|
2007-03-06 18:58:21 +01:00
|
|
|
CoUninitialize();
|
|
|
|
|
2007-01-09 18:17:34 +01:00
|
|
|
hr = CoUnmarshalInterface(pStream, &IID_IUnknown, NULL);
|
|
|
|
ok(hr == E_INVALIDARG, "CoUnmarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr);
|
|
|
|
|
|
|
|
IStream_Release(pStream);
|
|
|
|
}
|
|
|
|
|
2007-01-09 18:15:02 +01:00
|
|
|
static void test_CoGetInterfaceAndReleaseStream(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IUnknown *pUnk;
|
|
|
|
|
|
|
|
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
|
|
|
|
hr = CoGetInterfaceAndReleaseStream(NULL, &IID_IUnknown, (void**)&pUnk);
|
|
|
|
ok(hr == E_INVALIDARG, "hr %08x\n", hr);
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|
2006-08-16 13:29:17 +02:00
|
|
|
|
2007-01-09 18:17:34 +01:00
|
|
|
/* basic test, mainly for invalid arguments. see marshal.c for more */
|
2007-01-09 18:17:15 +01:00
|
|
|
static void test_CoMarshalInterface(void)
|
|
|
|
{
|
|
|
|
IStream *pStream;
|
|
|
|
HRESULT hr;
|
|
|
|
static const LARGE_INTEGER llZero;
|
|
|
|
|
|
|
|
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
|
|
|
|
hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
|
|
|
|
ok_ole_success(hr, "CreateStreamOnHGlobal");
|
|
|
|
|
|
|
|
hr = CoMarshalInterface(pStream, &IID_IUnknown, NULL, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL);
|
|
|
|
ok(hr == E_INVALIDARG, "CoMarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = CoMarshalInterface(NULL, &IID_IUnknown, (IUnknown *)&Test_ClassFactory, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL);
|
|
|
|
ok(hr == E_INVALIDARG, "CoMarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = CoMarshalInterface(pStream, &IID_IUnknown, (IUnknown *)&Test_ClassFactory, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL);
|
|
|
|
ok_ole_success(hr, "CoMarshalInterface");
|
|
|
|
|
|
|
|
/* stream not rewound */
|
|
|
|
hr = CoReleaseMarshalData(pStream);
|
|
|
|
ok(hr == STG_E_READFAULT, "CoReleaseMarshalData should have returned STG_E_READFAULT instead of 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IStream_Seek(pStream, llZero, STREAM_SEEK_SET, NULL);
|
|
|
|
ok_ole_success(hr, "IStream_Seek");
|
|
|
|
|
|
|
|
hr = CoReleaseMarshalData(pStream);
|
|
|
|
ok_ole_success(hr, "CoReleaseMarshalData");
|
|
|
|
|
|
|
|
IStream_Release(pStream);
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_CoMarshalInterThreadInterfaceInStream(void)
|
|
|
|
{
|
|
|
|
IStream *pStream;
|
|
|
|
HRESULT hr;
|
|
|
|
IClassFactory *pProxy;
|
|
|
|
|
|
|
|
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
|
|
|
|
cLocks = 0;
|
|
|
|
|
|
|
|
hr = CoMarshalInterThreadInterfaceInStream(&IID_IUnknown, (IUnknown *)&Test_ClassFactory, NULL);
|
|
|
|
ok(hr == E_INVALIDARG, "CoMarshalInterThreadInterfaceInStream should have returned E_INVALIDARG instead of 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = CoMarshalInterThreadInterfaceInStream(&IID_IUnknown, NULL, &pStream);
|
|
|
|
ok(hr == E_INVALIDARG, "CoMarshalInterThreadInterfaceInStream should have returned E_INVALIDARG instead of 0x%08x\n", hr);
|
|
|
|
|
|
|
|
ok_no_locks();
|
|
|
|
|
|
|
|
hr = CoMarshalInterThreadInterfaceInStream(&IID_IUnknown, (IUnknown *)&Test_ClassFactory, &pStream);
|
|
|
|
ok_ole_success(hr, "CoMarshalInterThreadInterfaceInStream");
|
|
|
|
|
|
|
|
ok_more_than_one_lock();
|
|
|
|
|
|
|
|
hr = CoUnmarshalInterface(pStream, &IID_IClassFactory, (void **)&pProxy);
|
|
|
|
ok_ole_success(hr, "CoUnmarshalInterface");
|
|
|
|
|
|
|
|
IClassFactory_Release(pProxy);
|
2007-11-10 14:55:06 +01:00
|
|
|
IStream_Release(pStream);
|
2007-01-09 18:17:15 +01:00
|
|
|
|
|
|
|
ok_no_locks();
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|
|
|
|
|
2007-03-09 18:49:05 +01:00
|
|
|
static void test_CoRegisterClassObject(void)
|
|
|
|
{
|
|
|
|
DWORD cookie;
|
|
|
|
HRESULT hr;
|
2007-05-08 00:56:43 +02:00
|
|
|
IClassFactory *pcf;
|
2007-03-09 18:49:05 +01:00
|
|
|
|
|
|
|
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
|
|
|
|
/* CLSCTX_INPROC_SERVER */
|
|
|
|
hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory,
|
|
|
|
CLSCTX_INPROC_SERVER, REGCLS_SINGLEUSE, &cookie);
|
|
|
|
ok_ole_success(hr, "CoRegisterClassObject");
|
|
|
|
hr = CoRevokeClassObject(cookie);
|
|
|
|
ok_ole_success(hr, "CoRevokeClassObject");
|
|
|
|
|
|
|
|
hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory,
|
|
|
|
CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &cookie);
|
|
|
|
ok_ole_success(hr, "CoRegisterClassObject");
|
|
|
|
hr = CoRevokeClassObject(cookie);
|
|
|
|
ok_ole_success(hr, "CoRevokeClassObject");
|
|
|
|
|
|
|
|
hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory,
|
|
|
|
CLSCTX_INPROC_SERVER, REGCLS_MULTI_SEPARATE, &cookie);
|
|
|
|
ok_ole_success(hr, "CoRegisterClassObject");
|
|
|
|
hr = CoRevokeClassObject(cookie);
|
|
|
|
ok_ole_success(hr, "CoRevokeClassObject");
|
|
|
|
|
|
|
|
/* CLSCTX_LOCAL_SERVER */
|
|
|
|
hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory,
|
|
|
|
CLSCTX_LOCAL_SERVER, REGCLS_SINGLEUSE, &cookie);
|
|
|
|
ok_ole_success(hr, "CoRegisterClassObject");
|
|
|
|
hr = CoRevokeClassObject(cookie);
|
|
|
|
ok_ole_success(hr, "CoRevokeClassObject");
|
|
|
|
|
|
|
|
hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory,
|
|
|
|
CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, &cookie);
|
|
|
|
ok_ole_success(hr, "CoRegisterClassObject");
|
|
|
|
hr = CoRevokeClassObject(cookie);
|
|
|
|
ok_ole_success(hr, "CoRevokeClassObject");
|
|
|
|
|
|
|
|
hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory,
|
|
|
|
CLSCTX_LOCAL_SERVER, REGCLS_MULTI_SEPARATE, &cookie);
|
|
|
|
ok_ole_success(hr, "CoRegisterClassObject");
|
|
|
|
hr = CoRevokeClassObject(cookie);
|
|
|
|
ok_ole_success(hr, "CoRevokeClassObject");
|
|
|
|
|
|
|
|
/* CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER */
|
|
|
|
hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory,
|
|
|
|
CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER, REGCLS_SINGLEUSE, &cookie);
|
|
|
|
ok_ole_success(hr, "CoRegisterClassObject");
|
|
|
|
hr = CoRevokeClassObject(cookie);
|
|
|
|
ok_ole_success(hr, "CoRevokeClassObject");
|
|
|
|
|
2007-05-08 00:56:43 +02:00
|
|
|
/* test whether registered class becomes invalid when apartment is destroyed */
|
|
|
|
hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory,
|
|
|
|
CLSCTX_INPROC_SERVER, REGCLS_SINGLEUSE, &cookie);
|
|
|
|
ok_ole_success(hr, "CoRegisterClassObject");
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
|
|
|
|
hr = CoGetClassObject(&CLSID_WineOOPTest, CLSCTX_INPROC_SERVER, NULL,
|
|
|
|
&IID_IClassFactory, (void **)&pcf);
|
|
|
|
ok(hr == REGDB_E_CLASSNOTREG, "object registered in an apartment shouldn't accessible after it is destroyed\n");
|
|
|
|
|
|
|
|
/* crashes with at least win9x DCOM! */
|
|
|
|
if (0)
|
|
|
|
hr = CoRevokeClassObject(cookie);
|
|
|
|
|
2007-03-09 18:49:05 +01:00
|
|
|
CoUninitialize();
|
|
|
|
}
|
|
|
|
|
2007-05-08 00:58:12 +02:00
|
|
|
static HRESULT get_class_object(CLSCTX clsctx)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IClassFactory *pcf;
|
|
|
|
|
|
|
|
hr = CoGetClassObject(&CLSID_WineOOPTest, clsctx, NULL, &IID_IClassFactory,
|
|
|
|
(void **)&pcf);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
IClassFactory_Release(pcf);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD CALLBACK get_class_object_thread(LPVOID pv)
|
|
|
|
{
|
|
|
|
CLSCTX clsctx = (CLSCTX)(DWORD_PTR)pv;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
|
|
|
|
hr = get_class_object(clsctx);
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2007-05-08 01:03:18 +02:00
|
|
|
static DWORD CALLBACK get_class_object_proxy_thread(LPVOID pv)
|
|
|
|
{
|
|
|
|
CLSCTX clsctx = (CLSCTX)(DWORD_PTR)pv;
|
|
|
|
HRESULT hr;
|
|
|
|
IClassFactory *pcf;
|
|
|
|
IMultiQI *pMQI;
|
|
|
|
|
|
|
|
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
|
|
|
|
hr = CoGetClassObject(&CLSID_WineOOPTest, clsctx, NULL, &IID_IClassFactory,
|
|
|
|
(void **)&pcf);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IClassFactory_QueryInterface(pcf, &IID_IMultiQI, (void **)&pMQI);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
IMultiQI_Release(pMQI);
|
|
|
|
IClassFactory_Release(pcf);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2007-05-08 00:58:12 +02:00
|
|
|
static DWORD CALLBACK register_class_object_thread(LPVOID pv)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
DWORD cookie;
|
|
|
|
|
|
|
|
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
|
|
|
|
hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory,
|
|
|
|
CLSCTX_INPROC_SERVER, REGCLS_SINGLEUSE, &cookie);
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD CALLBACK revoke_class_object_thread(LPVOID pv)
|
|
|
|
{
|
|
|
|
DWORD cookie = (DWORD_PTR)pv;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
|
|
|
|
hr = CoRevokeClassObject(cookie);
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_registered_object_thread_affinity(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
DWORD cookie;
|
|
|
|
HANDLE thread;
|
|
|
|
DWORD tid;
|
|
|
|
DWORD exitcode;
|
|
|
|
|
|
|
|
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
|
|
|
|
/* CLSCTX_INPROC_SERVER */
|
|
|
|
|
|
|
|
hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory,
|
|
|
|
CLSCTX_INPROC_SERVER, REGCLS_SINGLEUSE, &cookie);
|
|
|
|
ok_ole_success(hr, "CoRegisterClassObject");
|
|
|
|
|
|
|
|
thread = CreateThread(NULL, 0, get_class_object_thread, (LPVOID)CLSCTX_INPROC_SERVER, 0, &tid);
|
|
|
|
ok(thread != NULL, "CreateThread failed with error %d\n", GetLastError());
|
|
|
|
WaitForSingleObject(thread, INFINITE);
|
|
|
|
GetExitCodeThread(thread, &exitcode);
|
|
|
|
hr = exitcode;
|
|
|
|
ok(hr == REGDB_E_CLASSNOTREG, "CoGetClassObject on inproc object "
|
|
|
|
"registered in different thread should return REGDB_E_CLASSNOTREG "
|
|
|
|
"instead of 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = get_class_object(CLSCTX_INPROC_SERVER);
|
|
|
|
ok(hr == S_OK, "CoGetClassObject on inproc object registered in same "
|
|
|
|
"thread should return S_OK instead of 0x%08x\n", hr);
|
|
|
|
|
|
|
|
thread = CreateThread(NULL, 0, register_class_object_thread, NULL, 0, &tid);
|
|
|
|
ok(thread != NULL, "CreateThread failed with error %d\n", GetLastError());
|
|
|
|
WaitForSingleObject(thread, INFINITE);
|
|
|
|
GetExitCodeThread(thread, &exitcode);
|
|
|
|
hr = exitcode;
|
|
|
|
ok(hr == S_OK, "CoRegisterClassObject with same CLSID but in different thread should return S_OK instead of 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = CoRevokeClassObject(cookie);
|
|
|
|
ok_ole_success(hr, "CoRevokeClassObject");
|
|
|
|
|
|
|
|
/* CLSCTX_LOCAL_SERVER */
|
|
|
|
|
|
|
|
hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory,
|
|
|
|
CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, &cookie);
|
|
|
|
ok_ole_success(hr, "CoRegisterClassObject");
|
|
|
|
|
2007-05-08 01:03:18 +02:00
|
|
|
thread = CreateThread(NULL, 0, get_class_object_proxy_thread, (LPVOID)CLSCTX_LOCAL_SERVER, 0, &tid);
|
2007-05-08 00:58:12 +02:00
|
|
|
ok(thread != NULL, "CreateThread failed with error %d\n", GetLastError());
|
|
|
|
while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_ALLINPUT) == WAIT_OBJECT_0 + 1)
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessageA(&msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GetExitCodeThread(thread, &exitcode);
|
|
|
|
hr = exitcode;
|
|
|
|
ok(hr == S_OK, "CoGetClassObject on local server object "
|
|
|
|
"registered in different thread should return S_OK "
|
|
|
|
"instead of 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = get_class_object(CLSCTX_LOCAL_SERVER);
|
|
|
|
ok(hr == S_OK, "CoGetClassObject on local server object registered in same "
|
|
|
|
"thread should return S_OK instead of 0x%08x\n", hr);
|
|
|
|
|
|
|
|
thread = CreateThread(NULL, 0, revoke_class_object_thread, (LPVOID)cookie, 0, &tid);
|
|
|
|
ok(thread != NULL, "CreateThread failed with error %d\n", GetLastError());
|
|
|
|
WaitForSingleObject(thread, INFINITE);
|
|
|
|
GetExitCodeThread(thread, &exitcode);
|
|
|
|
hr = exitcode;
|
|
|
|
ok(hr == RPC_E_WRONG_THREAD, "CoRevokeClassObject called from different "
|
|
|
|
"thread to where registered should return RPC_E_WRONG_THREAD instead of 0x%08x\n", hr);
|
|
|
|
|
|
|
|
thread = CreateThread(NULL, 0, register_class_object_thread, NULL, 0, &tid);
|
|
|
|
ok(thread != NULL, "CreateThread failed with error %d\n", GetLastError());
|
|
|
|
WaitForSingleObject(thread, INFINITE);
|
|
|
|
GetExitCodeThread(thread, &exitcode);
|
|
|
|
hr = exitcode;
|
|
|
|
ok(hr == S_OK, "CoRegisterClassObject with same CLSID but in different "
|
|
|
|
"thread should return S_OK instead of 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = CoRevokeClassObject(cookie);
|
|
|
|
ok_ole_success(hr, "CoRevokeClassObject");
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|
|
|
|
|
2007-04-04 19:56:14 +02:00
|
|
|
static DWORD CALLBACK free_libraries_thread(LPVOID p)
|
|
|
|
{
|
|
|
|
CoFreeUnusedLibraries();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline BOOL is_module_loaded(const char *module)
|
|
|
|
{
|
|
|
|
return GetModuleHandle(module) ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_CoFreeUnusedLibraries(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IUnknown *pUnk;
|
|
|
|
DWORD tid;
|
|
|
|
HANDLE thread;
|
|
|
|
|
|
|
|
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
|
|
|
|
ok(!is_module_loaded("urlmon.dll"), "urlmon.dll shouldn't be loaded\n");
|
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&pUnk);
|
|
|
|
if (hr == REGDB_E_CLASSNOTREG)
|
|
|
|
{
|
|
|
|
trace("IE not installed so can't run CoFreeUnusedLibraries test\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok_ole_success(hr, "CoCreateInstance");
|
|
|
|
|
|
|
|
ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
|
|
|
|
|
|
|
|
IUnknown_Release(pUnk);
|
|
|
|
|
|
|
|
ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
|
|
|
|
|
|
|
|
thread = CreateThread(NULL, 0, free_libraries_thread, NULL, 0, &tid);
|
|
|
|
WaitForSingleObject(thread, INFINITE);
|
|
|
|
CloseHandle(thread);
|
|
|
|
|
|
|
|
ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
|
|
|
|
|
|
|
|
CoFreeUnusedLibraries();
|
|
|
|
|
|
|
|
ok(!is_module_loaded("urlmon.dll"), "urlmon.dll shouldn't be loaded\n");
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|
|
|
|
|
2007-11-01 14:26:56 +01:00
|
|
|
static void test_CoGetObjectContext(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
ULONG refs;
|
|
|
|
IComThreadingInfo *pComThreadingInfo;
|
|
|
|
APTTYPE apttype;
|
|
|
|
THDTYPE thdtype;
|
|
|
|
|
|
|
|
if (!pCoGetObjectContext)
|
|
|
|
{
|
|
|
|
skip("CoGetObjectContext not present\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = pCoGetObjectContext(&IID_IComThreadingInfo, (void **)&pComThreadingInfo);
|
|
|
|
ok(hr == CO_E_NOTINITIALIZED, "CoGetObjectContext should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr);
|
|
|
|
ok(pComThreadingInfo == NULL, "pComThreadingInfo should have been set to NULL\n");
|
|
|
|
|
|
|
|
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
|
|
|
|
hr = pCoGetObjectContext(&IID_IComThreadingInfo, (void **)&pComThreadingInfo);
|
|
|
|
ok_ole_success(hr, "CoGetObjectContext");
|
|
|
|
|
|
|
|
hr = IComThreadingInfo_GetCurrentApartmentType(pComThreadingInfo, &apttype);
|
|
|
|
ok_ole_success(hr, "IComThreadingInfo_GetCurrentApartmentType");
|
|
|
|
ok(apttype == APTTYPE_MAINSTA, "apartment type should be APTTYPE_MAINSTA instead of %d\n", apttype);
|
|
|
|
|
|
|
|
hr = IComThreadingInfo_GetCurrentThreadType(pComThreadingInfo, &thdtype);
|
|
|
|
ok_ole_success(hr, "IComThreadingInfo_GetCurrentThreadType");
|
|
|
|
ok(thdtype == THDTYPE_PROCESSMESSAGES, "thread type should be THDTYPE_PROCESSMESSAGES instead of %d\n", thdtype);
|
|
|
|
|
|
|
|
refs = IComThreadingInfo_Release(pComThreadingInfo);
|
|
|
|
ok(refs == 0, "pComThreadingInfo should have 0 refs instead of %d refs\n", refs);
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
|
|
|
|
pCoInitializeEx(NULL, COINIT_MULTITHREADED);
|
|
|
|
|
|
|
|
hr = pCoGetObjectContext(&IID_IComThreadingInfo, (void **)&pComThreadingInfo);
|
|
|
|
ok_ole_success(hr, "CoGetObjectContext");
|
|
|
|
|
|
|
|
hr = IComThreadingInfo_GetCurrentApartmentType(pComThreadingInfo, &apttype);
|
|
|
|
ok_ole_success(hr, "IComThreadingInfo_GetCurrentApartmentType");
|
|
|
|
ok(apttype == APTTYPE_MTA, "apartment type should be APTTYPE_MTA instead of %d\n", apttype);
|
|
|
|
|
|
|
|
hr = IComThreadingInfo_GetCurrentThreadType(pComThreadingInfo, &thdtype);
|
|
|
|
ok_ole_success(hr, "IComThreadingInfo_GetCurrentThreadType");
|
|
|
|
ok(thdtype == THDTYPE_BLOCKMESSAGES, "thread type should be THDTYPE_BLOCKMESSAGES instead of %d\n", thdtype);
|
|
|
|
|
|
|
|
refs = IComThreadingInfo_Release(pComThreadingInfo);
|
|
|
|
ok(refs == 0, "pComThreadingInfo should have 0 refs instead of %d refs\n", refs);
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|
2007-04-04 19:56:14 +02:00
|
|
|
|
2005-06-20 12:33:17 +02:00
|
|
|
START_TEST(compobj)
|
|
|
|
{
|
2006-07-14 18:13:58 +02:00
|
|
|
HMODULE hOle32 = GetModuleHandle("ole32");
|
2007-11-01 14:26:56 +01:00
|
|
|
pCoGetObjectContext = (void*)GetProcAddress(hOle32, "CoGetObjectContext");
|
2006-07-14 18:13:58 +02:00
|
|
|
if (!(pCoInitializeEx = (void*)GetProcAddress(hOle32, "CoInitializeEx")))
|
|
|
|
{
|
|
|
|
trace("You need DCOM95 installed to run this test\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-06-20 12:33:17 +02:00
|
|
|
test_ProgIDFromCLSID();
|
|
|
|
test_CLSIDFromProgID();
|
2006-01-09 18:40:27 +01:00
|
|
|
test_CLSIDFromString();
|
2006-02-20 11:16:08 +01:00
|
|
|
test_CoCreateInstance();
|
2006-06-14 14:20:01 +02:00
|
|
|
test_ole_menu();
|
2006-07-14 01:02:24 +02:00
|
|
|
test_CoGetClassObject();
|
2006-07-14 18:13:58 +02:00
|
|
|
test_CoRegisterMessageFilter();
|
2006-07-20 20:30:21 +02:00
|
|
|
test_CoRegisterPSClsid();
|
2006-08-16 13:29:17 +02:00
|
|
|
test_CoGetPSClsid();
|
2007-01-09 18:17:34 +01:00
|
|
|
test_CoUnmarshalInterface();
|
2007-01-09 18:15:02 +01:00
|
|
|
test_CoGetInterfaceAndReleaseStream();
|
2007-01-09 18:17:15 +01:00
|
|
|
test_CoMarshalInterface();
|
|
|
|
test_CoMarshalInterThreadInterfaceInStream();
|
2007-03-09 18:49:05 +01:00
|
|
|
test_CoRegisterClassObject();
|
2007-05-08 00:58:12 +02:00
|
|
|
test_registered_object_thread_affinity();
|
2007-04-04 19:56:14 +02:00
|
|
|
test_CoFreeUnusedLibraries();
|
2007-11-01 14:26:56 +01:00
|
|
|
test_CoGetObjectContext();
|
2005-06-20 12:33:17 +02:00
|
|
|
}
|