2 * Component Object Tests
4 * Copyright 2005 Robert Shearman
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/test.h"
32 /* functions that are not present on all versions of Windows */
33 HRESULT (WINAPI * pCoInitializeEx)(LPVOID lpReserved, DWORD dwCoInit);
35 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08lx\n", hr)
37 static const CLSID CLSID_non_existent = { 0x12345678, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
38 static const CLSID CLSID_CDeviceMoniker = { 0x4315d437, 0x5b8c, 0x11d0, { 0xbd, 0x3b, 0x00, 0xa0, 0xc9, 0x11, 0xce, 0x86 } };
39 static const WCHAR devicedotone[] = {'d','e','v','i','c','e','.','1',0};
40 static const WCHAR wszCLSID_CDeviceMoniker[] =
43 '4','3','1','5','d','4','3','7','-',
47 '0','0','a','0','c','9','1','1','c','e','8','6',
51 static void test_ProgIDFromCLSID(void)
54 HRESULT hr = ProgIDFromCLSID(&CLSID_CDeviceMoniker, &progid);
55 ok(hr == S_OK, "ProgIDFromCLSID failed with error 0x%08lx\n", hr);
58 ok(!lstrcmpiW(progid, devicedotone), "Didn't get expected prog ID\n");
59 CoTaskMemFree(progid);
62 progid = (LPWSTR)0xdeadbeef;
63 hr = ProgIDFromCLSID(&CLSID_non_existent, &progid);
64 ok(hr == REGDB_E_CLASSNOTREG, "ProgIDFromCLSID returned %08lx\n", hr);
65 ok(progid == NULL, "ProgIDFromCLSID returns with progid %p\n", progid);
68 static void test_CLSIDFromProgID(void)
71 HRESULT hr = CLSIDFromProgID(devicedotone, &clsid);
72 ok(hr == S_OK, "CLSIDFromProgID failed with error 0x%08lx\n", hr);
73 ok(IsEqualCLSID(&clsid, &CLSID_CDeviceMoniker), "clsid wasn't equal to CLSID_CDeviceMoniker\n");
75 hr = CLSIDFromString((LPOLESTR)devicedotone, &clsid);
76 ok_ole_success(hr, "CLSIDFromString");
77 ok(IsEqualCLSID(&clsid, &CLSID_CDeviceMoniker), "clsid wasn't equal to CLSID_CDeviceMoniker\n");
80 static void test_CLSIDFromString(void)
83 HRESULT hr = CLSIDFromString((LPOLESTR)wszCLSID_CDeviceMoniker, &clsid);
84 ok_ole_success(hr, "CLSIDFromString");
85 ok(IsEqualCLSID(&clsid, &CLSID_CDeviceMoniker), "clsid wasn't equal to CLSID_CDeviceMoniker\n");
88 static void test_CoCreateInstance(void)
90 REFCLSID rclsid = &CLSID_MyComputer;
91 IUnknown *pUnk = (IUnknown *)0xdeadbeef;
92 HRESULT hr = CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&pUnk);
93 ok(hr == CO_E_NOTINITIALIZED, "CoCreateInstance should have returned CO_E_NOTINITIALIZED instead of 0x%08lx\n", hr);
94 ok(pUnk == NULL, "CoCreateInstance should have changed the passed in pointer to NULL, instead of %p\n", pUnk);
97 hr = CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&pUnk);
98 ok_ole_success(hr, "CoCreateInstance");
99 IUnknown_Release(pUnk);
102 hr = CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&pUnk);
103 ok(hr == CO_E_NOTINITIALIZED, "CoCreateInstance should have returned CO_E_NOTINITIALIZED instead of 0x%08lx\n", hr);
106 static void test_CoGetClassObject(void)
108 IUnknown *pUnk = (IUnknown *)0xdeadbeef;
109 HRESULT hr = CoGetClassObject(&CLSID_MyComputer, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void **)&pUnk);
110 ok(hr == CO_E_NOTINITIALIZED, "CoGetClassObject should have returned CO_E_NOTINITIALIZED instead of 0x%08lx\n", hr);
111 ok(pUnk == NULL, "CoGetClassObject should have changed the passed in pointer to NULL, instead of %p\n", pUnk);
113 hr = CoGetClassObject(&CLSID_MyComputer, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, NULL);
114 ok(hr == E_INVALIDARG, "CoGetClassObject should have returned E_INVALIDARG instead of 0x%08lx\n", hr);
117 static ATOM register_dummy_class(void)
125 GetModuleHandle(NULL),
127 LoadCursor(NULL, IDC_ARROW),
128 (HBRUSH)(COLOR_BTNFACE+1),
130 TEXT("WineOleTestClass"),
133 return RegisterClass(&wc);
136 static void test_ole_menu(void)
141 hwndFrame = CreateWindow(MAKEINTATOM(register_dummy_class()), "Test", 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, NULL, NULL);
142 hr = OleSetMenuDescriptor(NULL, hwndFrame, NULL, NULL, NULL);
143 todo_wine ok_ole_success(hr, "OleSetMenuDescriptor");
145 DestroyWindow(hwndFrame);
149 static HRESULT WINAPI MessageFilter_QueryInterface(IMessageFilter *iface, REFIID riid, void ** ppvObj)
151 if (ppvObj == NULL) return E_POINTER;
153 if (IsEqualGUID(riid, &IID_IUnknown) ||
154 IsEqualGUID(riid, &IID_IClassFactory))
156 *ppvObj = (LPVOID)iface;
157 IMessageFilter_AddRef(iface);
161 return E_NOINTERFACE;
164 static ULONG WINAPI MessageFilter_AddRef(IMessageFilter *iface)
166 return 2; /* non-heap object */
169 static ULONG WINAPI MessageFilter_Release(IMessageFilter *iface)
171 return 1; /* non-heap object */
174 static DWORD WINAPI MessageFilter_HandleInComingCall(
175 IMessageFilter *iface,
177 HTASK threadIDCaller,
179 LPINTERFACEINFO lpInterfaceInfo)
181 trace("HandleInComingCall\n");
182 return SERVERCALL_ISHANDLED;
185 static DWORD WINAPI MessageFilter_RetryRejectedCall(
186 IMessageFilter *iface,
187 HTASK threadIDCallee,
191 trace("RetryRejectedCall\n");
195 static DWORD WINAPI MessageFilter_MessagePending(
196 IMessageFilter *iface,
197 HTASK threadIDCallee,
201 trace("MessagePending\n");
202 return PENDINGMSG_WAITNOPROCESS;
205 static const IMessageFilterVtbl MessageFilter_Vtbl =
207 MessageFilter_QueryInterface,
208 MessageFilter_AddRef,
209 MessageFilter_Release,
210 MessageFilter_HandleInComingCall,
211 MessageFilter_RetryRejectedCall,
212 MessageFilter_MessagePending
215 static IMessageFilter MessageFilter = { &MessageFilter_Vtbl };
217 static void test_CoRegisterMessageFilter(void)
220 IMessageFilter *prev_filter;
222 #if 0 /* crashes without an apartment! */
223 hr = CoRegisterMessageFilter(&MessageFilter, &prev_filter);
226 pCoInitializeEx(NULL, COINIT_MULTITHREADED);
227 prev_filter = (IMessageFilter *)0xdeadbeef;
228 hr = CoRegisterMessageFilter(&MessageFilter, &prev_filter);
229 ok(hr == CO_E_NOT_SUPPORTED,
230 "CoRegisterMessageFilter should have failed with CO_E_NOT_SUPPORTED instead of 0x%08lx\n",
232 ok(prev_filter == (IMessageFilter *)0xdeadbeef,
233 "prev_filter should have been set to %p\n", prev_filter);
236 pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
238 hr = CoRegisterMessageFilter(NULL, NULL);
239 ok_ole_success(hr, "CoRegisterMessageFilter");
241 prev_filter = (IMessageFilter *)0xdeadbeef;
242 hr = CoRegisterMessageFilter(NULL, &prev_filter);
243 ok_ole_success(hr, "CoRegisterMessageFilter");
244 ok(prev_filter == NULL, "prev_filter should have been set to NULL instead of %p\n", prev_filter);
246 hr = CoRegisterMessageFilter(&MessageFilter, &prev_filter);
247 ok_ole_success(hr, "CoRegisterMessageFilter");
248 ok(prev_filter == NULL, "prev_filter should have been set to NULL instead of %p\n", prev_filter);
250 hr = CoRegisterMessageFilter(NULL, NULL);
251 ok_ole_success(hr, "CoRegisterMessageFilter");
258 HMODULE hOle32 = GetModuleHandle("ole32");
259 if (!(pCoInitializeEx = (void*)GetProcAddress(hOle32, "CoInitializeEx")))
261 trace("You need DCOM95 installed to run this test\n");
265 test_ProgIDFromCLSID();
266 test_CLSIDFromProgID();
267 test_CLSIDFromString();
268 test_CoCreateInstance();
270 test_CoGetClassObject();
271 test_CoRegisterMessageFilter();