[COM_APITEST]
[reactos.git] / rostests / apitests / com / com_apitest.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: COM interface test
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6 */
7
8 #include "com_apitest.h"
9
10 #define NDEBUG
11 #include <debug.h>
12
13 #define myskip(c, ...) ((c) ? 0 : (skip(__VA_ARGS__), 1))
14 #define mytrace(...) do { \
15 int debug = winetest_debug; \
16 winetest_debug = 1; \
17 trace(__VA_ARGS__); \
18 winetest_debug = debug; \
19 } while (0)
20
21 typedef struct _KNOWN_INTERFACE
22 {
23 const IID *iid;
24 PCSTR name;
25 PCWSTR wname;
26 BOOLEAN noreg;
27 } KNOWN_INTERFACE;
28 typedef const KNOWN_INTERFACE *PCKNOWN_INTERFACE;
29
30 #undef ID_NAME
31 #define ID_NAME(c) &c, #c, L ## #c
32 static KNOWN_INTERFACE KnownInterfaces[] =
33 {
34 { ID_NAME(IID_IACList), TRUE },
35 { ID_NAME(IID_IACList2), TRUE },
36 { ID_NAME(IID_IADesktopP2), TRUE },
37 { ID_NAME(IID_IAccIdentity) },
38 { ID_NAME(IID_IAccPropServer) },
39 { ID_NAME(IID_IAccPropServices) },
40 { ID_NAME(IID_IAccessible) },
41 { ID_NAME(IID_IAccessibleHandler) },
42 { ID_NAME(IID_IAccessControl), TRUE },
43 { ID_NAME(IID_IAccessor) },
44 { ID_NAME(IID_IActiveDesktop), TRUE },
45 { ID_NAME(IID_IActiveDesktopP), TRUE },
46 { ID_NAME(IID_IActionProgress) },
47 { ID_NAME(IID_IActionProgressDialog) },
48 { ID_NAME(IID_IAddressBarParser), TRUE },
49 { ID_NAME(IID_IAddressBand), TRUE },
50 { ID_NAME(IID_IAddressEditBox), TRUE },
51 { ID_NAME(IID_IAugmentedShellFolder), TRUE },
52 { ID_NAME(IID_IAugmentedShellFolder2), TRUE },
53 { ID_NAME(IID_IAutoComplete), TRUE },
54 { ID_NAME(IID_IAutoComplete2), TRUE },
55 { ID_NAME(IID_IAutoCompleteDropDown) },
56 { ID_NAME(IID_IBandHost) },
57 { ID_NAME(IID_IBandNavigate), },
58 { ID_NAME(IID_IBandProxy), TRUE },
59 { ID_NAME(IID_IBandSite) },
60 { ID_NAME(IID_IBandSiteHelper), TRUE },
61 { ID_NAME(IID_IBanneredBar), TRUE },
62 { ID_NAME(IID_IBindCtx) },
63 { ID_NAME(IID_IBindEventHandler) },
64 { ID_NAME(IID_IBindHost) },
65 { ID_NAME(IID_IBinding) },
66 { ID_NAME(IID_IBindProtocol), TRUE },
67 { ID_NAME(IID_IBindResource) },
68 { ID_NAME(IID_IBindStatusCallback) },
69 { ID_NAME(IID_IBrowserFrameOptions), TRUE },
70 { ID_NAME(IID_IBrowserService) },
71 { ID_NAME(IID_IBrowserService2), TRUE },
72 { ID_NAME(IID_IBrowserService3), TRUE },
73 { ID_NAME(IID_IBrowserService4), TRUE },
74 { ID_NAME(IID_ICDBurn) },
75 { ID_NAME(IID_ICDBurnExt) },
76 { ID_NAME(IID_IClassFactory) },
77 { ID_NAME(IID_IClassFactory2) },
78 { ID_NAME(IID_IClassFactory3), TRUE },
79 { ID_NAME(IID_IClientSecurity), TRUE },
80 { ID_NAME(IID_ICommDlgBrowser) },
81 { ID_NAME(IID_ICommDlgBrowser2) },
82 { ID_NAME(IID_ICommDlgBrowser3) },
83 { ID_NAME(IID_IComputerInfoChangeNotify), },
84 { ID_NAME(IID_IComThreadingInfo), TRUE },
85 { ID_NAME(IID_IContext), TRUE },
86 { ID_NAME(IID_IContextMenu), TRUE },
87 { ID_NAME(IID_IContextMenu2), TRUE },
88 { ID_NAME(IID_IContextMenu3), TRUE },
89 { ID_NAME(IID_IContextMenuCB), TRUE },
90 { ID_NAME(IID_IContextMenuSite) },
91 { ID_NAME(IID_IContinue) },
92 { ID_NAME(IID_ICopyHookA), TRUE },
93 { ID_NAME(IID_ICopyHookW), TRUE },
94 { ID_NAME(IID_IDVGetEnum), TRUE },
95 { ID_NAME(IID_IDataObject) },
96 //{ ID_NAME(IID_IDefViewID) }, == DefViewFrame3
97 { ID_NAME(IID_IDefViewFrame), TRUE },
98 { ID_NAME(IID_IDefViewFrame3) },
99 { ID_NAME(IID_IDefViewFrameGroup) },
100 { ID_NAME(IID_IDefViewSafety), },
101 { ID_NAME(IID_IDefViewScript), TRUE },
102 { ID_NAME(IID_IDelayedRelease), TRUE },
103 { ID_NAME(IID_IDeskBand) },
104 { ID_NAME(IID_IDeskBandEx) },
105 { ID_NAME(IID_IDeskBar), TRUE },
106 { ID_NAME(IID_IDeskBarClient), TRUE },
107 { ID_NAME(IID_IDeskMovr), TRUE },
108 { ID_NAME(IID_IDispatch) },
109 { ID_NAME(IID_IDockingWindow) },
110 { ID_NAME(IID_IDockingWindowFrame), TRUE },
111 { ID_NAME(IID_IDockingWindowSite), TRUE },
112 { ID_NAME(IID_IDocViewSite), TRUE },
113 { ID_NAME(IID_IDragSourceHelper), TRUE },
114 { ID_NAME(IID_IDropSource) },
115 { ID_NAME(IID_IDropTarget) },
116 { ID_NAME(IID_IDropTargetHelper), TRUE },
117 { ID_NAME(IID_IEnumExtraSearch) },
118 { ID_NAME(IID_IEnumGUID) },
119 { ID_NAME(IID_IEnumIDList) },
120 { ID_NAME(IID_IEnumMoniker) },
121 //{ ID_NAME(IID_IEnumNetCfgBindingInterface) },
122 //{ ID_NAME(IID_IEnumNetCfgBindingPath) },
123 { ID_NAME(IID_IEnumNetCfgComponent), TRUE },
124 { ID_NAME(IID_IEnumNetConnection) },
125 { ID_NAME(IID_IEnumShellItems) },
126 { ID_NAME(IID_IEnumSTATSTG) },
127 { ID_NAME(IID_IEnumString) },
128 { ID_NAME(IID_IEnumUnknown) },
129 { ID_NAME(IID_IEnumVARIANT) },
130 { ID_NAME(IID_IErrorLog) },
131 { ID_NAME(IID_IExplorerBrowser) },
132 { ID_NAME(IID_IExplorerToolbar), TRUE },
133 { ID_NAME(IID_IExtractIconA), TRUE },
134 { ID_NAME(IID_IExtractIconW), TRUE },
135 { ID_NAME(IID_IExtractImage) },
136 { ID_NAME(IID_IExtractImage2) },
137 { ID_NAME(IID_IFileDialog) },
138 { ID_NAME(IID_IFileDialog2), TRUE },
139 { ID_NAME(IID_IFileOpenDialog) },
140 { ID_NAME(IID_IFileSaveDialog) },
141 { ID_NAME(IID_IFileSearchBand) },
142 { ID_NAME(IID_IFileViewerA), TRUE },
143 { ID_NAME(IID_IFileViewerSite), TRUE },
144 { ID_NAME(IID_IFileViewerW), TRUE },
145 { ID_NAME(IID_IFolderBandPriv) },
146 { ID_NAME(IID_IFolderFilter) },
147 { ID_NAME(IID_IFolderFilterSite) },
148 { ID_NAME(IID_IFolderView) },
149 { ID_NAME(IID_IFolderView2) },
150 { ID_NAME(IID_IFolderViewHost), TRUE },
151 { ID_NAME(IID_IFolderViewOC) },
152 { ID_NAME(IID_IFolderViewSettings) },
153 { ID_NAME(IID_IGetNameSpaceExtensionPointer),TRUE},
154 { ID_NAME(IID_IGlobalFolderSettings), TRUE },
155 { ID_NAME(IID_IHWEventHandler) },
156 { ID_NAME(IID_IHWEventHandler2) },
157 { ID_NAME(IID_IImageList), TRUE },
158 { ID_NAME(IID_IImageList2), TRUE },
159 { ID_NAME(IID_IInitializeObject), TRUE },
160 { ID_NAME(IID_IInputObject) },
161 { ID_NAME(IID_IInputObjectSite) },
162 { ID_NAME(IID_IInternalUnknown), TRUE },
163 { ID_NAME(IID_IMarshal) },
164 { ID_NAME(IID_IMarshal2), TRUE },
165 { ID_NAME(IID_IMenuBand), TRUE },
166 { ID_NAME(IID_IMenuPopup), TRUE },
167 { ID_NAME(IID_IModalWindow) },
168 { ID_NAME(IID_IMoniker) },
169 { ID_NAME(IID_IMultiMonitorDockingSite), TRUE },
170 { ID_NAME(IID_IMultiQI), TRUE },
171 { ID_NAME(IID_INamespaceProxy), TRUE },
172 { ID_NAME(IID_INameSpaceTreeControl), TRUE },
173 { ID_NAME(IID_INamespaceWalk) },
174 { ID_NAME(IID_INamespaceWalkCB) },
175 { ID_NAME(IID_INamespaceWalkCB2) },
176 { ID_NAME(IID_INetCfg), TRUE },
177 //{ ID_NAME(IID_INetCfgBindingInterface) },
178 //{ ID_NAME(IID_INetCfgBindingPath) },
179 { ID_NAME(IID_INetCfgComponent), TRUE },
180 { ID_NAME(IID_INetCfgComponentBindings), TRUE },
181 { ID_NAME(IID_INetCfgComponentControl), TRUE },
182 { ID_NAME(IID_INetCfgComponentPropertyUi), TRUE },
183 { ID_NAME(IID_INetCfgLock), TRUE },
184 { ID_NAME(IID_INetCfgPnpReconfigCallback), TRUE },
185 { ID_NAME(IID_INetConnectionConnectUi), TRUE },
186 { ID_NAME(IID_INetConnectionPropertyUi), TRUE },
187 { ID_NAME(IID_INetConnectionPropertyUi2), TRUE },
188 { ID_NAME(IID_INetConnectionManager) },
189 { ID_NAME(IID_INetLanConnectionUiInfo), TRUE },
190 { ID_NAME(IID_INewShortcutHookA), TRUE },
191 { ID_NAME(IID_INewShortcutHookW), TRUE },
192 { ID_NAME(IID_INewWindowManager) },
193 { ID_NAME(IID_INSCTree), TRUE },
194 { ID_NAME(IID_INSCTree2), TRUE },
195 { ID_NAME(IID_IObjMgr), TRUE },
196 { ID_NAME(IID_IObjectSafety) },
197 { ID_NAME(IID_IObjectWithSite) },
198 { ID_NAME(IID_IOleCommandTarget) },
199 { ID_NAME(IID_IOleInPlaceActiveObject) },
200 { ID_NAME(IID_IOleInPlaceFrame) },
201 { ID_NAME(IID_IOleInPlaceObject) },
202 { ID_NAME(IID_IOleInPlaceObjectWindowless), TRUE },
203 { ID_NAME(IID_IOleInPlaceSite) },
204 { ID_NAME(IID_IOleInPlaceSiteEx) },
205 { ID_NAME(IID_IOleInPlaceSiteWindowless), TRUE },
206 { ID_NAME(IID_IOleInPlaceUIWindow) },
207 { ID_NAME(IID_IOleObject) },
208 { ID_NAME(IID_IOleWindow) },
209 { ID_NAME(IID_IPersist) },
210 { ID_NAME(IID_IPersistFile) },
211 { ID_NAME(IID_IPersistFolder) },
212 { ID_NAME(IID_IPersistFolder2) },
213 { ID_NAME(IID_IPersistFolder3) },
214 { ID_NAME(IID_IPersistFreeThreadedObject), TRUE },
215 { ID_NAME(IID_IPersistHistory) },
216 { ID_NAME(IID_IPersistIDList) },
217 { ID_NAME(IID_IPersistMemory) },
218 { ID_NAME(IID_IPersistPropertyBag) },
219 { ID_NAME(IID_IPersistPropertyBag2) },
220 { ID_NAME(IID_IPersistStorage) },
221 { ID_NAME(IID_IPersistStream) },
222 { ID_NAME(IID_IPersistStreamInit) },
223 { ID_NAME(IID_IPreviewHandler) },
224 { ID_NAME(IID_IPreviewHandlerFrame) },
225 { ID_NAME(IID_IPreviewHandlerVisuals) },
226 { ID_NAME(IID_IProgressDialog), TRUE },
227 { ID_NAME(IID_IPropertyBag) },
228 { ID_NAME(IID_IPropertyBag2) },
229 { ID_NAME(IID_IPropSheetPage), TRUE },
230 { ID_NAME(IID_IQueryAssociations), TRUE },
231 { ID_NAME(IID_IQueryInfo), TRUE },
232 { ID_NAME(IID_IRegTreeOptions), TRUE },
233 { ID_NAME(IID_IRemoteComputer) },
234 { ID_NAME(IID_IResolveShellLink) },
235 { ID_NAME(IID_IRunnableObject) },
236 { ID_NAME(IID_IScriptErrorList) },
237 { ID_NAME(IID_ISearch) },
238 { ID_NAME(IID_ISearchAssistantOC) },
239 { ID_NAME(IID_ISearchAssistantOC2) },
240 { ID_NAME(IID_ISearchAssistantOC3) },
241 { ID_NAME(IID_ISearches) },
242 { ID_NAME(IID_IServerSecurity), TRUE },
243 { ID_NAME(IID_IServiceProvider) },
244 { ID_NAME(IID_IShellApp), TRUE },
245 { ID_NAME(IID_IShellBrowser) },
246 { ID_NAME(IID_IShellBrowserService), TRUE },
247 { ID_NAME(IID_IShellChangeNotify), TRUE },
248 { ID_NAME(IID_IShellCopyHookA), TRUE },
249 { ID_NAME(IID_IShellCopyHookW), TRUE },
250 { ID_NAME(IID_IShellDesktopTray), TRUE },
251 { ID_NAME(IID_IShellDetails), TRUE },
252 { ID_NAME(IID_IShellDispatch) },
253 { ID_NAME(IID_IShellDispatch2) },
254 { ID_NAME(IID_IShellDispatch3) },
255 { ID_NAME(IID_IShellDispatch4) },
256 { ID_NAME(IID_IShellDispatch5), TRUE },
257 { ID_NAME(IID_IShellDispatch6), TRUE },
258 { ID_NAME(IID_IShellExecuteHookA), TRUE },
259 { ID_NAME(IID_IShellExecuteHookW), TRUE },
260 { ID_NAME(IID_IShellExtInit), TRUE },
261 { ID_NAME(IID_IShellFavoritesNameSpace) },
262 { ID_NAME(IID_IShellFolder) },
263 { ID_NAME(IID_IShellFolder2) },
264 { ID_NAME(IID_IShellFolderBand), TRUE },
265 { ID_NAME(IID_IShellFolderSearchable), TRUE },
266 { ID_NAME(IID_IShellFolderSearchableCallback), TRUE },
267 { ID_NAME(IID_IShellFolderView), TRUE },
268 { ID_NAME(IID_IShellFolderViewCB), TRUE },
269 { ID_NAME(IID_IShellFolderViewDual) },
270 { ID_NAME(IID_IShellFolderViewDual2) },
271 { ID_NAME(IID_IShellFolderViewDual3), TRUE },
272 { ID_NAME(IID_IShellFolderViewType), TRUE },
273 { ID_NAME(IID_IShellIcon) },
274 { ID_NAME(IID_IShellIconOverlay), TRUE },
275 { ID_NAME(IID_IShellIconOverlayIdentifier), TRUE },
276 { ID_NAME(IID_IShellImageData), TRUE },
277 { ID_NAME(IID_IShellImageDataAbort), TRUE },
278 { ID_NAME(IID_IShellImageDataFactory), TRUE },
279 { ID_NAME(IID_IShellItem) },
280 { ID_NAME(IID_IShellItem2) },
281 { ID_NAME(IID_IShellItemArray) },
282 { ID_NAME(IID_IShellItemFilter) },
283 { ID_NAME(IID_IShellLinkA) },
284 { ID_NAME(IID_IShellLinkDataList), TRUE },
285 { ID_NAME(IID_IShellLinkDual) },
286 { ID_NAME(IID_IShellLinkDual2) },
287 { ID_NAME(IID_IShellLinkW) },
288 { ID_NAME(IID_IShellMenu), TRUE },
289 { ID_NAME(IID_IShellMenu2), TRUE },
290 { ID_NAME(IID_IShellMenuAcc), TRUE },
291 { ID_NAME(IID_IShellMenuCallback), TRUE },
292 { ID_NAME(IID_IShellNameSpace) },
293 { ID_NAME(IID_IShellPropSheetExt), TRUE },
294 { ID_NAME(IID_IShellService), TRUE },
295 { ID_NAME(IID_IShellTaskScheduler), TRUE },
296 { ID_NAME(IID_IShellUIHelper) },
297 { ID_NAME(IID_IShellUIHelper2), TRUE },
298 { ID_NAME(IID_IShellView) },
299 { ID_NAME(IID_IShellView2) },
300 { ID_NAME(IID_IShellView3) },
301 { ID_NAME(IID_IShellWindows) },
302 { ID_NAME(IID_IStorage) },
303 { ID_NAME(IID_IStream) },
304 { ID_NAME(IID_ISurrogate) },
305 { ID_NAME(IID_ISynchronize) },
306 { ID_NAME(IID_ISynchronizeContainer), TRUE },
307 { ID_NAME(IID_ISynchronizeEvent), TRUE },
308 { ID_NAME(IID_ISynchronizeHandle), TRUE },
309 { ID_NAME(IID_ITaskbarList) },
310 { ID_NAME(IID_ITaskbarList2) },
311 { ID_NAME(IID_ITrackShellMenu), TRUE },
312 { ID_NAME(IID_ITranslateShellChangeNotify), TRUE },
313 { ID_NAME(IID_ITrayPriv), TRUE },
314 { ID_NAME(IID_ITrayPriv2), TRUE },
315 { ID_NAME(IID_IUnknown) },
316 { ID_NAME(IID_IURLSearchHook), TRUE },
317 { ID_NAME(IID_IURLSearchHook2), TRUE },
318 { ID_NAME(IID_IViewObject) },
319 { ID_NAME(IID_IViewObject2) },
320 { ID_NAME(IID_IViewObjectEx), TRUE },
321 { ID_NAME(IID_IWebBrowser) },
322 { ID_NAME(IID_IWebBrowser2) },
323 { ID_NAME(IID_IWebBrowserApp) },
324 { ID_NAME(IID_IWinEventHandler), TRUE },
325
326 { ID_NAME(IID_DFConstraint), TRUE },
327 { ID_NAME(DIID__SearchAssistantEvents) },
328 { ID_NAME(DIID_DShellFolderViewEvents) },
329 { ID_NAME(DIID_DShellNameSpaceEvents) },
330 { ID_NAME(DIID_DShellWindowsEvents) },
331 { ID_NAME(DIID_DWebBrowserEvents) },
332 { ID_NAME(DIID_DWebBrowserEvents2) },
333 { ID_NAME(DIID_XMLDOMDocumentEvents ) },
334
335 { ID_NAME(IID_CDefView), TRUE },
336 { ID_NAME(IID_Folder) },
337 { ID_NAME(IID_Folder2) },
338 { ID_NAME(IID_Folder3) },
339 { ID_NAME(IID_FolderItem) },
340 { ID_NAME(IID_FolderItem2) },
341 { ID_NAME(IID_FolderItems) },
342 { ID_NAME(IID_FolderItems2) },
343 { ID_NAME(IID_FolderItems3) },
344 { ID_NAME(IID_FolderItemVerb) },
345 { ID_NAME(IID_FolderItemVerbs) },
346
347 { ID_NAME(CLSID_ShellDesktop), TRUE }
348 };
349 static const INT KnownInterfaceCount = RTL_NUMBER_OF(KnownInterfaces);
350
351 static
352 PCKNOWN_INTERFACE
353 FindInterface(
354 _In_ const IID *iid)
355 {
356 INT i;
357
358 for (i = 0; i < KnownInterfaceCount; i++)
359 if (IsEqualIID(KnownInterfaces[i].iid, iid))
360 return &KnownInterfaces[i];
361 ASSERT(i != KnownInterfaceCount);
362 return NULL;
363 }
364
365 static
366 BOOLEAN
367 IsInterfaceExpected(
368 _In_ PCCLASS_AND_INTERFACES class,
369 _In_ const IID *iid)
370 {
371 INT i;
372
373 for (i = 0; class->ifaces[i].iid; i++)
374 if (IsEqualIID(class->ifaces[i].iid, iid))
375 return TRUE;
376 return FALSE;
377 }
378
379 #define INTF_NOT_EXPOSED LONG_MAX
380 static
381 LONG
382 GetInterfaceOffset(
383 _In_ PUNKNOWN pUnk,
384 _In_ const IID *iid)
385 {
386 HRESULT hr;
387 PVOID pObj;
388 PUNKNOWN pUnk2;
389 LONG offset;
390
391 hr = IUnknown_QueryInterface(pUnk, iid, &pObj);
392 ok(hr == S_OK || hr == E_NOINTERFACE, "IUnknown::QueryInterface returned 0x%lx\n", hr);
393 if (FAILED(hr))
394 return INTF_NOT_EXPOSED;
395
396 pUnk2 = pObj;
397 offset = (LONG_PTR)pObj - (LONG_PTR)pUnk;
398 IUnknown_Release(pUnk2);
399 return offset;
400 }
401
402 static
403 VOID
404 TestModuleInterfaces(
405 _In_ PCCLASS_AND_INTERFACES ExpectedInterfaces,
406 _In_ INT ExpectedInterfaceCount)
407 {
408 HRESULT hr;
409 PVOID pObj;
410 PUNKNOWN pUnk;
411 INT iClass, iIntf;
412 PCCLASS_AND_INTERFACES class;
413
414 for (iClass = 0; iClass < ExpectedInterfaceCount; iClass++)
415 {
416 class = &ExpectedInterfaces[iClass];
417 hr = CoCreateInstance(class->clsid,
418 NULL,
419 CLSCTX_INPROC_SERVER,
420 &IID_IUnknown,
421 &pObj);
422 ok(hr == S_OK, "CoCreateInstance failed. hr=0x%lx\n", hr);
423 if (FAILED(hr))
424 {
425 skip("Failed to instantiate %s.\n", class->name);
426 continue;
427 }
428
429 pUnk = pObj;
430
431 /* Check that all expected interfaces are present and have the right offset */
432 for (iIntf = 0; class->ifaces[iIntf].iid; iIntf++)
433 {
434 PCKNOWN_INTERFACE iface = FindInterface(class->ifaces[iIntf].iid);
435 LONG offset = GetInterfaceOffset(pUnk, iface->iid);
436 if (offset == INTF_NOT_EXPOSED)
437 ok(0, "%s is missing %s (offset %ld)\n", class->name, iface->name, class->ifaces[iIntf].offset);
438 else if (class->ifaces[iIntf].offset != FARAWY)
439 {
440 #ifdef FAIL_WRONG_OFFSET
441 ok(offset == class->ifaces[iIntf].offset, "%s, %s offset is %ld, expected %ld\n", class->name, iface->name, offset, class->ifaces[iIntf].offset);
442 #else
443 if (offset != class->ifaces[iIntf].offset)
444 mytrace("%s, %s offset is %ld, expected %ld\n", class->name, iface->name, offset, class->ifaces[iIntf].offset);
445 #endif
446 }
447 }
448
449 /* Check that none other than the expected interfaces are present */
450 for (iIntf = 0; iIntf < KnownInterfaceCount; iIntf++)
451 {
452 PCKNOWN_INTERFACE iface = &KnownInterfaces[iIntf];
453 LONG offset;
454 if (IsInterfaceExpected(class, iface->iid))
455 continue;
456 offset = GetInterfaceOffset(pUnk, iface->iid);
457 #ifdef GENERATE_TABLE_ENTRIES
458 ok(offset == INTF_NOT_EXPOSED, "%s: { %s0x%x, &%s },\n", class->name, offset < 0 ? "-" : "", offset < 0 ? -offset : offset, iface->name);
459 #else
460 ok(offset == INTF_NOT_EXPOSED, "%s exposes %s (offset %ld), but shouldn't\n", class->name, iface->name, offset);
461 #endif
462 }
463
464 // TODO: do some aggregation
465
466 IUnknown_Release(pUnk);
467 }
468 }
469
470 static
471 VOID
472 TestModuleRegistry(
473 _In_ PCWSTR ModuleName,
474 _In_ PCCLASS_AND_INTERFACES ExpectedInterfaces,
475 _In_ INT ExpectedInterfaceCount)
476 {
477 INT iClass;
478 PCCLASS_AND_INTERFACES class;
479 HKEY hKeyClasses;
480 LONG result;
481
482 result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Classes\\CLSID", 0, KEY_ENUMERATE_SUB_KEYS, &hKeyClasses);
483 ok(result == NO_ERROR, "Failed to open classes key, error %lu\n", result);
484 if (!myskip(result == NO_ERROR, "No classes key\n"))
485 {
486 for (iClass = 0; iClass < ExpectedInterfaceCount; iClass++)
487 {
488 HKEY hKey;
489 HKEY hKeyServer;
490 NTSTATUS status;
491 UNICODE_STRING clsid;
492 DWORD type;
493 WCHAR data[100];
494 DWORD dataSize;
495 PCWSTR expectedThreadingModel;
496
497 class = &ExpectedInterfaces[iClass];
498 status = RtlStringFromGUID(class->clsid, &clsid);
499 ok(status == STATUS_SUCCESS, "Failed to convert guid to string for %s, status %lx\n", class->name, status);
500 if (myskip(NT_SUCCESS(status), "No guid string\n"))
501 continue;
502
503 result = RegOpenKeyExW(hKeyClasses, clsid.Buffer, 0, KEY_ENUMERATE_SUB_KEYS, &hKey);
504 ok(result == NO_ERROR, "Failed to open key for %s, error %lu\n", class->name, result);
505 RtlFreeUnicodeString(&clsid);
506 if (myskip(result == NO_ERROR, "No key\n"))
507 continue;
508
509 result = RegOpenKeyExW(hKey, L"InProcServer32", 0, KEY_QUERY_VALUE, &hKeyServer);
510 ok(result == NO_ERROR, "Failed to open key for %s, error %lu\n", class->name, result);
511 RegCloseKey(hKey);
512 if (myskip(result == NO_ERROR, "No key\n"))
513 continue;
514
515 dataSize = sizeof(data);
516 result = RegQueryValueExW(hKeyServer, NULL, NULL, &type, (PBYTE)data, &dataSize);
517 ok(result == NO_ERROR, "Failed to query value for %s, error %lu\n", class->name, result);
518 if (!myskip(result == NO_ERROR, "No module name\n"))
519 {
520 ok(type == REG_SZ || type == REG_EXPAND_SZ, "type %lu for %s\n", type, class->name);
521 ok(dataSize % sizeof(WCHAR) == 0, "size %lu for %s\n", dataSize, class->name);
522 ok(dataSize <= sizeof(data), "size %lu for %s\n", dataSize, class->name);
523 ok(data[dataSize / sizeof(WCHAR) - 1] == UNICODE_NULL, "Not null terminated for %s\n", class->name);
524 // TODO: Use SearchPath (or assume everything's in system32) and do a proper full path compare
525 PathStripPathW(data);
526 PathRemoveExtensionW(data);
527 ok(!wcsicmp(data, ModuleName), "Server is %ls, expected %ls for %s\n", data, ModuleName, class->name);
528 }
529
530 dataSize = sizeof(data);
531 result = RegQueryValueExW(hKeyServer, L"ThreadingModel", NULL, &type, (PBYTE)data, &dataSize);
532 ok(result == NO_ERROR, "Failed to query value for %s, error %lu\n", class->name, result);
533 if (!myskip(result == NO_ERROR, "No ThreadingModel\n"))
534 {
535 ok(type == REG_SZ || type == REG_EXPAND_SZ, "type %lu for %s\n", type, class->name);
536 ok(dataSize % sizeof(WCHAR) == 0, "size %lu for %s\n", dataSize, class->name);
537 ok(dataSize <= sizeof(data), "size %lu for %s\n", dataSize, class->name);
538 ok(data[dataSize / sizeof(WCHAR) - 1] == UNICODE_NULL, "Not null terminated for %s\n", class->name);
539 expectedThreadingModel = class->ThreadingModel;
540 if (!expectedThreadingModel)
541 expectedThreadingModel = L"Apartment";
542 ok(!wcsicmp(data, expectedThreadingModel), "Server is %ls, expected %ls for %s\n", data, expectedThreadingModel, class->name);
543 }
544
545 RegCloseKey(hKeyServer);
546 }
547 RegCloseKey(hKeyClasses);
548 }
549 }
550
551 static
552 VOID
553 TestManualInstantiation(
554 _In_ PCWSTR ModuleName,
555 _In_ PCCLASS_AND_INTERFACES ExpectedInterfaces,
556 _In_ INT ExpectedInterfaceCount)
557 {
558 INT iClass;
559 PCCLASS_AND_INTERFACES class;
560 HRESULT (__stdcall *DllGetClassObject)(REFCLSID, REFIID, PVOID *);
561
562 DllGetClassObject = (PVOID)GetProcAddress(GetModuleHandleW(ModuleName), "DllGetClassObject");
563 ok(DllGetClassObject != NULL, "DllGetClassObject not found in %ls, error %lu\n", ModuleName, GetLastError());
564 if (myskip(DllGetClassObject != NULL, "No DllGetClassObject\n"))
565 return;
566
567 for (iClass = 0; iClass < ExpectedInterfaceCount; iClass++)
568 {
569 PVOID pv;
570 HRESULT hr;
571 class = &ExpectedInterfaces[iClass];
572 hr = DllGetClassObject(class->clsid, &IID_IClassFactory, &pv);
573 ok(hr == S_OK, "DllGetClassObject failed for %s, hr = 0x%lx\n", class->name, hr);
574 if (!myskip(SUCCEEDED(hr), "No class factory\n"))
575 {
576 IClassFactory *pCF = pv;
577 hr = IClassFactory_CreateInstance(pCF, NULL, &IID_IUnknown, &pv);
578 ok(hr == S_OK, "IClassFactory::CreateInstance failed for %s, hr = 0x%lx\n", class->name, hr);
579 if (!myskip(SUCCEEDED(hr), "No instance\n"))
580 {
581 IUnknown *pUnk = pv;
582 IUnknown_Release(pUnk);
583 }
584 IClassFactory_Release(pCF);
585 }
586 }
587 }
588
589 VOID
590 TestClasses(
591 _In_ PCWSTR ModuleName,
592 _In_ PCCLASS_AND_INTERFACES ExpectedInterfaces,
593 _In_ INT ExpectedInterfaceCount)
594 {
595 HRESULT hr;
596
597 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
598 ok(hr == S_OK, "CoInitializeEx failed. hr=0x%lx\n", hr);
599 if (myskip(SUCCEEDED(hr), "Failed to initialize COM. Cannot perform tests\n"))
600 return;
601
602 TestModuleInterfaces(ExpectedInterfaces, ExpectedInterfaceCount);
603 TestModuleRegistry(ModuleName, ExpectedInterfaces, ExpectedInterfaceCount);
604 TestManualInstantiation(ModuleName, ExpectedInterfaces, ExpectedInterfaceCount);
605
606 CoUninitialize();
607 }
608
609 static
610 VOID
611 TestInterfaceRegistry(
612 _In_ PCKNOWN_INTERFACE Interfaces,
613 _In_ INT InterfaceCount)
614 {
615 INT i;
616 HKEY hKeyInterface;
617 LONG result;
618
619 result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Classes\\Interface", 0, KEY_ENUMERATE_SUB_KEYS, &hKeyInterface);
620 ok(result == NO_ERROR, "Failed to open interface key, error %lu\n", result);
621 if (!myskip(result == NO_ERROR, "No interface key\n"))
622 {
623 for (i = 0; i < InterfaceCount; i++)
624 {
625 HKEY hKey;
626 NTSTATUS status;
627 UNICODE_STRING iid;
628 DWORD type;
629 WCHAR data[100];
630 DWORD dataSize;
631 PCKNOWN_INTERFACE iface;
632 PCWSTR expectedName;
633
634 iface = &Interfaces[i];
635 status = RtlStringFromGUID(iface->iid, &iid);
636 ok(status == STATUS_SUCCESS, "Failed to convert guid to string for %s, status %lx\n", iface->name, status);
637 if (myskip(NT_SUCCESS(status), "No guid string\n"))
638 continue;
639
640 result = RegOpenKeyExW(hKeyInterface, iid.Buffer, 0, KEY_QUERY_VALUE, &hKey);
641 if (iface->noreg)
642 {
643 ok(result == ERROR_FILE_NOT_FOUND, "RegOpenKeyEx returned %lu for %s\n", result, iface->name);
644 }
645 else
646 {
647 ok(result == NO_ERROR, "Failed to open key for %s, error %lu\n", iface->name, result);
648 (void)myskip(result == NO_ERROR, "No key\n");
649 }
650 RtlFreeUnicodeString(&iid);
651 if (result != NO_ERROR)
652 continue;
653
654 dataSize = sizeof(data);
655 result = RegQueryValueExW(hKey, NULL, NULL, &type, (PBYTE)data, &dataSize);
656 ok(result == NO_ERROR, "Failed to query value for %s, error %lu\n", iface->name, result);
657 if (!myskip(result == NO_ERROR, "No module name\n"))
658 {
659 ok(type == REG_SZ, "type %lu for %s\n", type, iface->name);
660 ok(dataSize % sizeof(WCHAR) == 0, "size %lu for %s\n", dataSize, iface->name);
661 ok(dataSize <= sizeof(data), "size %lu for %s\n", dataSize, iface->name);
662 ok(data[dataSize / sizeof(WCHAR) - 1] == UNICODE_NULL, "Not null terminated for %s\n", iface->name);
663 expectedName = wcschr(iface->wname, L'_');
664 if (expectedName)
665 expectedName++;
666 else
667 expectedName = iface->wname;
668 ok(!wcsicmp(data, expectedName), "Name is %ls, expected %ls\n", data, expectedName);
669 }
670
671 RegCloseKey(hKey);
672 }
673 RegCloseKey(hKeyInterface);
674 }
675 }
676
677 START_TEST(interfaces)
678 {
679 TestInterfaceRegistry(KnownInterfaces, KnownInterfaceCount);
680 }