9f8c3b0ce61446c6a2e4a67fed445e36ddbd5a40
[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_ISFHelper), TRUE },
223 { ID_NAME(IID_IShellApp), TRUE },
224 { ID_NAME(IID_IShellBrowser) },
225 { ID_NAME(IID_IShellBrowserService), TRUE },
226 { ID_NAME(IID_IShellChangeNotify), TRUE },
227 { ID_NAME(IID_IShellCopyHookA), TRUE },
228 { ID_NAME(IID_IShellCopyHookW), TRUE },
229 { ID_NAME(IID_IShellDesktopTray), TRUE },
230 { ID_NAME(IID_IShellDetails), TRUE },
231 { ID_NAME(IID_IShellDispatch) },
232 { ID_NAME(IID_IShellDispatch2) },
233 { ID_NAME(IID_IShellDispatch3) },
234 { ID_NAME(IID_IShellDispatch4) },
235 { ID_NAME(IID_IShellDispatch5), TRUE },
236 { ID_NAME(IID_IShellExecuteHookA), TRUE },
237 { ID_NAME(IID_IShellExecuteHookW), TRUE },
238 { ID_NAME(IID_IShellExtInit), TRUE },
239 { ID_NAME(IID_IShellFolder) },
240 { ID_NAME(IID_IShellFolder2) },
241 { ID_NAME(IID_IShellFolderBand), TRUE },
242 { ID_NAME(IID_IShellFolderSearchable), TRUE },
243 { ID_NAME(IID_IShellFolderSearchableCallback), TRUE },
244 { ID_NAME(IID_IShellFolderView), TRUE },
245 { ID_NAME(IID_IShellFolderViewCB), TRUE },
246 { ID_NAME(IID_IShellFolderViewDual) },
247 { ID_NAME(IID_IShellFolderViewDual2) },
248 { ID_NAME(IID_IShellFolderViewType), TRUE },
249 { ID_NAME(IID_IShellIcon) },
250 { ID_NAME(IID_IShellIconOverlay), TRUE },
251 { ID_NAME(IID_IShellIconOverlayIdentifier), TRUE },
252 { ID_NAME(IID_IShellImageData), TRUE },
253 { ID_NAME(IID_IShellImageDataAbort), TRUE },
254 { ID_NAME(IID_IShellImageDataFactory), TRUE },
255 { ID_NAME(IID_IShellItem) },
256 { ID_NAME(IID_IShellItem2) },
257 { ID_NAME(IID_IShellItemArray) },
258 { ID_NAME(IID_IShellItemFilter) },
259 { ID_NAME(IID_IShellLinkA) },
260 { ID_NAME(IID_IShellLinkDataList), TRUE },
261 { ID_NAME(IID_IShellLinkDual) },
262 { ID_NAME(IID_IShellLinkDual2) },
263 { ID_NAME(IID_IShellLinkW) },
264 { ID_NAME(IID_IShellMenu), TRUE },
265 { ID_NAME(IID_IShellMenu2), TRUE },
266 { ID_NAME(IID_IShellMenuAcc), TRUE },
267 { ID_NAME(IID_IShellMenuCallback), TRUE },
268 { ID_NAME(IID_IShellNameSpace) },
269 { ID_NAME(IID_IShellPropSheetExt), TRUE },
270 { ID_NAME(IID_IShellService), TRUE },
271 { ID_NAME(IID_IShellTaskScheduler), TRUE },
272 { ID_NAME(IID_IShellView) },
273 { ID_NAME(IID_IShellView2) },
274 { ID_NAME(IID_IShellView3) },
275 { ID_NAME(IID_IShellWindows) },
276 { ID_NAME(IID_IStorage) },
277 { ID_NAME(IID_IStream) },
278 { ID_NAME(IID_ISurrogate) },
279 { ID_NAME(IID_ISynchronize) },
280 { ID_NAME(IID_ISynchronizeContainer), TRUE },
281 { ID_NAME(IID_ISynchronizeEvent), TRUE },
282 { ID_NAME(IID_ISynchronizeHandle), TRUE },
283 { ID_NAME(IID_ITaskbarList) },
284 { ID_NAME(IID_ITaskbarList2) },
285 { ID_NAME(IID_ITrackShellMenu), TRUE },
286 { ID_NAME(IID_ITranslateShellChangeNotify), TRUE },
287 { ID_NAME(IID_ITrayPriv), TRUE },
288 { ID_NAME(IID_ITrayPriv2), TRUE },
289 { ID_NAME(IID_IUnknown) },
290 { ID_NAME(IID_IURLSearchHook), TRUE },
291 { ID_NAME(IID_IURLSearchHook2), TRUE },
292 { ID_NAME(IID_IViewObject) },
293 { ID_NAME(IID_IViewObject2) },
294 { ID_NAME(IID_IViewObjectEx), TRUE },
295 { ID_NAME(IID_IWinEventHandler), TRUE },
296
297 { ID_NAME(IID_DFConstraint), TRUE },
298 { ID_NAME(DIID_DShellFolderViewEvents) },
299
300 { ID_NAME(IID_CDefView), TRUE },
301 { ID_NAME(IID_Folder) },
302 { ID_NAME(IID_Folder2) },
303 { ID_NAME(IID_Folder3) },
304 { ID_NAME(IID_FolderItem) },
305 { ID_NAME(IID_FolderItem2) },
306 { ID_NAME(IID_FolderItems) },
307 { ID_NAME(IID_FolderItems2) },
308 { ID_NAME(IID_FolderItems3) },
309 { ID_NAME(IID_FolderItemVerb) },
310 { ID_NAME(IID_FolderItemVerbs) },
311
312 { ID_NAME(CLSID_ShellDesktop), TRUE }
313 };
314 static const INT KnownInterfaceCount = RTL_NUMBER_OF(KnownInterfaces);
315
316 static
317 PCKNOWN_INTERFACE
318 FindInterface(
319 _In_ const IID *iid)
320 {
321 INT i;
322
323 for (i = 0; i < KnownInterfaceCount; i++)
324 if (IsEqualIID(KnownInterfaces[i].iid, iid))
325 return &KnownInterfaces[i];
326 ASSERT(i != KnownInterfaceCount);
327 return NULL;
328 }
329
330 static
331 BOOLEAN
332 IsInterfaceExpected(
333 _In_ PCCLASS_AND_INTERFACES class,
334 _In_ const IID *iid)
335 {
336 INT i;
337
338 for (i = 0; class->ifaces[i].iid; i++)
339 if (IsEqualIID(class->ifaces[i].iid, iid))
340 return TRUE;
341 return FALSE;
342 }
343
344 #define INTF_NOT_EXPOSED LONG_MAX
345 static
346 LONG
347 GetInterfaceOffset(
348 _In_ PUNKNOWN pUnk,
349 _In_ const IID *iid)
350 {
351 HRESULT hr;
352 PVOID pObj;
353 PUNKNOWN pUnk2;
354 LONG offset;
355
356 hr = IUnknown_QueryInterface(pUnk, iid, &pObj);
357 ok(hr == S_OK || hr == E_NOINTERFACE, "IUnknown::QueryInterface returned 0x%lx\n", hr);
358 if (FAILED(hr))
359 return INTF_NOT_EXPOSED;
360
361 pUnk2 = pObj;
362 offset = (LONG_PTR)pObj - (LONG_PTR)pUnk;
363 IUnknown_Release(pUnk2);
364 return offset;
365 }
366
367 static
368 VOID
369 TestModuleInterfaces(
370 _In_ PCCLASS_AND_INTERFACES ExpectedInterfaces,
371 _In_ INT ExpectedInterfaceCount)
372 {
373 HRESULT hr;
374 PVOID pObj;
375 PUNKNOWN pUnk;
376 INT iClass, iIntf;
377 PCCLASS_AND_INTERFACES class;
378
379 for (iClass = 0; iClass < ExpectedInterfaceCount; iClass++)
380 {
381 class = &ExpectedInterfaces[iClass];
382 hr = CoCreateInstance(class->clsid,
383 NULL,
384 CLSCTX_INPROC_SERVER,
385 &IID_IUnknown,
386 &pObj);
387 ok(hr == S_OK, "CoCreateInstance failed. hr=0x%lx\n", hr);
388 if (FAILED(hr))
389 {
390 skip("Failed to instantiate %s.\n", class->name);
391 continue;
392 }
393
394 pUnk = pObj;
395
396 /* Check that all expected interfaces are present and have the right offset */
397 for (iIntf = 0; class->ifaces[iIntf].iid; iIntf++)
398 {
399 PCKNOWN_INTERFACE iface = FindInterface(class->ifaces[iIntf].iid);
400 LONG offset = GetInterfaceOffset(pUnk, iface->iid);
401 if (offset == INTF_NOT_EXPOSED)
402 ok(0, "%s is missing %s (offset %ld)\n", class->name, iface->name, class->ifaces[iIntf].offset);
403 else if (class->ifaces[iIntf].offset != FARAWY)
404 {
405 #ifdef FAIL_WRONG_OFFSET
406 ok(offset == class->ifaces[iIntf].offset, "%s, %s offset is %ld, expected %ld\n", class->name, iface->name, offset, class->ifaces[iIntf].offset);
407 #else
408 if (offset != class->ifaces[iIntf].offset)
409 mytrace("%s, %s offset is %ld, expected %ld\n", class->name, iface->name, offset, class->ifaces[iIntf].offset);
410 #endif
411 }
412 }
413
414 /* Check that none other than the expected interfaces are present */
415 for (iIntf = 0; iIntf < KnownInterfaceCount; iIntf++)
416 {
417 PCKNOWN_INTERFACE iface = &KnownInterfaces[iIntf];
418 LONG offset;
419 if (IsInterfaceExpected(class, iface->iid))
420 continue;
421 offset = GetInterfaceOffset(pUnk, iface->iid);
422 #ifdef GENERATE_TABLE_ENTRIES
423 ok(offset == INTF_NOT_EXPOSED, "%s: { %s0x%x, &%s },\n", class->name, offset < 0 ? "-" : "", offset < 0 ? -offset : offset, iface->name);
424 #else
425 ok(offset == INTF_NOT_EXPOSED, "%s exposes %s (offset %ld), but shouldn't\n", class->name, iface->name, offset);
426 #endif
427 }
428
429 // TODO: do some aggregation
430
431 IUnknown_Release(pUnk);
432 }
433 }
434
435 static
436 VOID
437 TestModuleRegistry(
438 _In_ PCWSTR ModuleName,
439 _In_ PCCLASS_AND_INTERFACES ExpectedInterfaces,
440 _In_ INT ExpectedInterfaceCount)
441 {
442 INT iClass;
443 PCCLASS_AND_INTERFACES class;
444 HKEY hKeyClasses;
445 LONG result;
446
447 result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Classes\\CLSID", 0, KEY_ENUMERATE_SUB_KEYS, &hKeyClasses);
448 ok(result == NO_ERROR, "Failed to open classes key, error %lu\n", result);
449 if (!myskip(result == NO_ERROR, "No classes key\n"))
450 {
451 for (iClass = 0; iClass < ExpectedInterfaceCount; iClass++)
452 {
453 HKEY hKey;
454 HKEY hKeyServer;
455 NTSTATUS status;
456 UNICODE_STRING clsid;
457 DWORD type;
458 WCHAR data[100];
459 DWORD dataSize;
460 PCWSTR expectedThreadingModel;
461
462 class = &ExpectedInterfaces[iClass];
463 status = RtlStringFromGUID(class->clsid, &clsid);
464 ok(status == STATUS_SUCCESS, "Failed to convert guid to string for %s, status %lx\n", class->name, status);
465 if (myskip(NT_SUCCESS(status), "No guid string\n"))
466 continue;
467
468 result = RegOpenKeyEx(hKeyClasses, clsid.Buffer, 0, KEY_ENUMERATE_SUB_KEYS, &hKey);
469 ok(result == NO_ERROR, "Failed to open key for %s, error %lu\n", class->name, result);
470 RtlFreeUnicodeString(&clsid);
471 if (myskip(result == NO_ERROR, "No key\n"))
472 continue;
473
474 result = RegOpenKeyEx(hKey, L"InProcServer32", 0, KEY_QUERY_VALUE, &hKeyServer);
475 ok(result == NO_ERROR, "Failed to open key for %s, error %lu\n", class->name, result);
476 RegCloseKey(hKey);
477 if (myskip(result == NO_ERROR, "No key\n"))
478 continue;
479
480 dataSize = sizeof(data);
481 result = RegQueryValueEx(hKeyServer, NULL, NULL, &type, (PBYTE)data, &dataSize);
482 ok(result == NO_ERROR, "Failed to query value for %s, error %lu\n", class->name, result);
483 if (!myskip(result == NO_ERROR, "No module name\n"))
484 {
485 ok(type == REG_SZ || type == REG_EXPAND_SZ, "type %lu for %s\n", type, class->name);
486 ok(dataSize % sizeof(WCHAR) == 0, "size %lu for %s\n", dataSize, class->name);
487 ok(dataSize <= sizeof(data), "size %lu for %s\n", dataSize, class->name);
488 ok(data[dataSize / sizeof(WCHAR) - 1] == UNICODE_NULL, "Not null terminated for %s\n", class->name);
489 // TODO: Use SearchPath (or assume everything's in system32) and do a proper full path compare
490 PathStripPathW(data);
491 PathRemoveExtensionW(data);
492 ok(!wcsicmp(data, ModuleName), "Server is %ls, expected %ls for %s\n", data, ModuleName, class->name);
493 }
494
495 dataSize = sizeof(data);
496 result = RegQueryValueEx(hKeyServer, L"ThreadingModel", NULL, &type, (PBYTE)data, &dataSize);
497 ok(result == NO_ERROR, "Failed to query value for %s, error %lu\n", class->name, result);
498 if (!myskip(result == NO_ERROR, "No ThreadingModel\n"))
499 {
500 ok(type == REG_SZ || type == REG_EXPAND_SZ, "type %lu for %s\n", type, class->name);
501 ok(dataSize % sizeof(WCHAR) == 0, "size %lu for %s\n", dataSize, class->name);
502 ok(dataSize <= sizeof(data), "size %lu for %s\n", dataSize, class->name);
503 ok(data[dataSize / sizeof(WCHAR) - 1] == UNICODE_NULL, "Not null terminated for %s\n", class->name);
504 expectedThreadingModel = class->ThreadingModel;
505 if (!expectedThreadingModel)
506 expectedThreadingModel = L"Apartment";
507 ok(!wcsicmp(data, expectedThreadingModel), "Server is %ls, expected %ls for %s\n", data, expectedThreadingModel, class->name);
508 }
509
510 RegCloseKey(hKeyServer);
511 }
512 RegCloseKey(hKeyClasses);
513 }
514 }
515
516 static
517 VOID
518 TestManualInstantiation(
519 _In_ PCWSTR ModuleName,
520 _In_ PCCLASS_AND_INTERFACES ExpectedInterfaces,
521 _In_ INT ExpectedInterfaceCount)
522 {
523 INT iClass;
524 PCCLASS_AND_INTERFACES class;
525 HRESULT (__stdcall *DllGetClassObject)(REFCLSID, REFIID, PVOID *);
526
527 DllGetClassObject = (PVOID)GetProcAddress(GetModuleHandle(ModuleName), "DllGetClassObject");
528 ok(DllGetClassObject != NULL, "DllGetClassObject not found in %ls, error %lu\n", ModuleName, GetLastError());
529 if (myskip(DllGetClassObject != NULL, "No DllGetClassObject\n"))
530 return;
531
532 for (iClass = 0; iClass < ExpectedInterfaceCount; iClass++)
533 {
534 PVOID pv;
535 HRESULT hr;
536 class = &ExpectedInterfaces[iClass];
537 hr = DllGetClassObject(class->clsid, &IID_IClassFactory, &pv);
538 ok(hr == S_OK, "DllGetClassObject failed for %s, hr = 0x%lx\n", class->name, hr);
539 if (!myskip(SUCCEEDED(hr), "No class factory\n"))
540 {
541 IClassFactory *pCF = pv;
542 hr = IClassFactory_CreateInstance(pCF, NULL, &IID_IUnknown, &pv);
543 ok(hr == S_OK, "IClassFactory::CreateInstance failed for %s, hr = 0x%lx\n", class->name, hr);
544 if (!myskip(SUCCEEDED(hr), "No instance\n"))
545 {
546 IUnknown *pUnk = pv;
547 IUnknown_Release(pUnk);
548 }
549 IClassFactory_Release(pCF);
550 }
551 }
552 }
553
554 VOID
555 TestClasses(
556 _In_ PCWSTR ModuleName,
557 _In_ PCCLASS_AND_INTERFACES ExpectedInterfaces,
558 _In_ INT ExpectedInterfaceCount)
559 {
560 HRESULT hr;
561
562 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
563 ok(hr == S_OK, "CoInitializeEx failed. hr=0x%lx\n", hr);
564 if (myskip(SUCCEEDED(hr), "Failed to initialize COM. Cannot perform tests\n"))
565 return;
566
567 TestModuleInterfaces(ExpectedInterfaces, ExpectedInterfaceCount);
568 TestModuleRegistry(ModuleName, ExpectedInterfaces, ExpectedInterfaceCount);
569 TestManualInstantiation(ModuleName, ExpectedInterfaces, ExpectedInterfaceCount);
570
571 CoUninitialize();
572 }
573
574 static
575 VOID
576 TestInterfaceRegistry(
577 _In_ PCKNOWN_INTERFACE Interfaces,
578 _In_ INT InterfaceCount)
579 {
580 INT i;
581 HKEY hKeyInterface;
582 LONG result;
583
584 result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Classes\\Interface", 0, KEY_ENUMERATE_SUB_KEYS, &hKeyInterface);
585 ok(result == NO_ERROR, "Failed to open interface key, error %lu\n", result);
586 if (!myskip(result == NO_ERROR, "No interface key\n"))
587 {
588 for (i = 0; i < InterfaceCount; i++)
589 {
590 HKEY hKey;
591 NTSTATUS status;
592 UNICODE_STRING iid;
593 DWORD type;
594 WCHAR data[100];
595 DWORD dataSize;
596 PCKNOWN_INTERFACE iface;
597 PCWSTR expectedName;
598
599 iface = &Interfaces[i];
600 status = RtlStringFromGUID(iface->iid, &iid);
601 ok(status == STATUS_SUCCESS, "Failed to convert guid to string for %s, status %lx\n", iface->name, status);
602 if (myskip(NT_SUCCESS(status), "No guid string\n"))
603 continue;
604
605 result = RegOpenKeyEx(hKeyInterface, iid.Buffer, 0, KEY_QUERY_VALUE, &hKey);
606 if (iface->noreg)
607 {
608 ok(result == ERROR_FILE_NOT_FOUND, "RegOpenKeyEx returned %lu for %s\n", result, iface->name);
609 }
610 else
611 {
612 ok(result == NO_ERROR, "Failed to open key for %s, error %lu\n", iface->name, result);
613 (void)myskip(result == NO_ERROR, "No key\n");
614 }
615 RtlFreeUnicodeString(&iid);
616 if (result != NO_ERROR)
617 continue;
618
619 dataSize = sizeof(data);
620 result = RegQueryValueEx(hKey, NULL, NULL, &type, (PBYTE)data, &dataSize);
621 ok(result == NO_ERROR, "Failed to query value for %s, error %lu\n", iface->name, result);
622 if (!myskip(result == NO_ERROR, "No module name\n"))
623 {
624 ok(type == REG_SZ, "type %lu for %s\n", type, iface->name);
625 ok(dataSize % sizeof(WCHAR) == 0, "size %lu for %s\n", dataSize, iface->name);
626 ok(dataSize <= sizeof(data), "size %lu for %s\n", dataSize, iface->name);
627 ok(data[dataSize / sizeof(WCHAR) - 1] == UNICODE_NULL, "Not null terminated for %s\n", iface->name);
628 expectedName = wcschr(iface->wname, L'_');
629 if (expectedName)
630 expectedName++;
631 else
632 expectedName = iface->wname;
633 ok(!wcsicmp(data, expectedName), "Name is %ls, expected %ls\n", data, expectedName);
634 }
635
636 RegCloseKey(hKey);
637 }
638 RegCloseKey(hKeyInterface);
639 }
640 }
641
642 START_TEST(interfaces)
643 {
644 TestInterfaceRegistry(KnownInterfaces, KnownInterfaceCount);
645 }