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