Release 0.9.61.
[wine/gsoc-2012-control.git] / dlls / oleaut32 / tests / typelib.c
blob74a7812f988b13c6dc26d0f4d10496801f414467
1 /*
2 * ITypeLib and ITypeInfo test
4 * Copyright 2004 Jacek Caban
5 * Copyright 2006 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define COBJMACROS
24 #include <wine/test.h>
25 #include <stdarg.h>
26 #include <stdio.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "oleauto.h"
31 #include "ocidl.h"
32 #include "shlwapi.h"
33 #include "tmarshal.h"
35 #define expect_eq(expr, value, type, format) { type _ret = (expr); ok((value) == _ret, #expr " expected " format " got " format "\n", value, _ret); }
36 #define expect_int(expr, value) expect_eq(expr, (int)value, int, "%d")
37 #define expect_hex(expr, value) expect_eq(expr, (int)value, int, "0x%x")
38 #define expect_null(expr) expect_eq(expr, NULL, const void *, "%p")
40 #define expect_wstr_utf8val(expr, value) \
41 { \
42 CHAR buf[260]; \
43 expect_eq(!WideCharToMultiByte(CP_UTF8, 0, (expr), -1, buf, 260, NULL, NULL), 0, int, "%d"); \
44 ok(lstrcmp(value, buf) == 0, #expr " expected \"%s\" got \"%s\"\n", value, buf); \
47 #define ole_expect(expr, expect) { \
48 HRESULT r = expr; \
49 ok(r == (expect), #expr " returned %x, expected %s (%x)\n", r, #expect, expect); \
52 #define ole_check(expr) ole_expect(expr, S_OK);
54 #define ok_ole_success(hr, func) ok(hr == S_OK, #func " failed with error 0x%08x\n", hr)
56 static const WCHAR wszStdOle2[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
58 static void ref_count_test(LPCWSTR type_lib)
60 ITypeLib *iface;
61 ITypeInfo *iti1, *iti2;
62 HRESULT hRes;
63 int ref_count;
65 trace("Loading type library\n");
66 hRes = LoadTypeLib(type_lib, &iface);
67 ok(hRes == S_OK, "Could not load type library\n");
68 if(hRes != S_OK)
69 return;
71 hRes = ITypeLib_GetTypeInfo(iface, 1, &iti1);
72 ok(hRes == S_OK, "ITypeLib_GetTypeInfo failed on index = 1\n");
73 ok(ref_count=ITypeLib_Release(iface) > 0, "ITypeLib destroyed while ITypeInfo has back pointer\n");
74 if(!ref_count)
75 return;
77 hRes = ITypeLib_GetTypeInfo(iface, 1, &iti2);
78 ok(hRes == S_OK, "ITypeLib_GetTypeInfo failed on index = 1\n");
79 ok(iti1 == iti2, "ITypeLib_GetTypeInfo returned different pointers for same indexes\n");
81 ITypeLib_AddRef(iface);
82 ITypeInfo_Release(iti2);
83 ITypeInfo_Release(iti1);
84 ok(ITypeLib_Release(iface) == 0, "ITypeLib should be destroyed here.\n");
87 static void test_TypeComp(void)
89 ITypeLib *pTypeLib;
90 ITypeComp *pTypeComp;
91 HRESULT hr;
92 ULONG ulHash;
93 DESCKIND desckind;
94 BINDPTR bindptr;
95 ITypeInfo *pTypeInfo;
96 ITypeInfo *pFontTypeInfo;
97 static WCHAR wszStdFunctions[] = {'S','t','d','F','u','n','c','t','i','o','n','s',0};
98 static WCHAR wszSavePicture[] = {'S','a','v','e','P','i','c','t','u','r','e',0};
99 static WCHAR wszOLE_TRISTATE[] = {'O','L','E','_','T','R','I','S','T','A','T','E',0};
100 static WCHAR wszUnchecked[] = {'U','n','c','h','e','c','k','e','d',0};
101 static WCHAR wszIUnknown[] = {'I','U','n','k','n','o','w','n',0};
102 static WCHAR wszFont[] = {'F','o','n','t',0};
103 static WCHAR wszGUID[] = {'G','U','I','D',0};
104 static WCHAR wszStdPicture[] = {'S','t','d','P','i','c','t','u','r','e',0};
105 static WCHAR wszOLE_COLOR[] = {'O','L','E','_','C','O','L','O','R',0};
106 static WCHAR wszClone[] = {'C','l','o','n','e',0};
107 static WCHAR wszclone[] = {'c','l','o','n','e',0};
109 hr = LoadTypeLib(wszStdOle2, &pTypeLib);
110 ok_ole_success(hr, LoadTypeLib);
112 hr = ITypeLib_GetTypeComp(pTypeLib, &pTypeComp);
113 ok_ole_success(hr, ITypeLib_GetTypeComp);
115 /* test getting a TKIND_MODULE */
116 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszStdFunctions);
117 hr = ITypeComp_Bind(pTypeComp, wszStdFunctions, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
118 ok_ole_success(hr, ITypeComp_Bind);
120 ok(desckind == DESCKIND_TYPECOMP,
121 "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
122 desckind);
123 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
125 ITypeComp_Release(bindptr.lptcomp);
127 /* test getting a TKIND_MODULE with INVOKE_PROPERTYGET */
128 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszStdFunctions);
129 hr = ITypeComp_Bind(pTypeComp, wszStdFunctions, ulHash, INVOKE_PROPERTYGET, &pTypeInfo, &desckind, &bindptr);
130 ok_ole_success(hr, ITypeComp_Bind);
132 ok(desckind == DESCKIND_TYPECOMP,
133 "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
134 desckind);
135 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
136 ITypeComp_Release(bindptr.lptcomp);
138 /* test getting a function within a TKIND_MODULE */
139 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszSavePicture);
140 hr = ITypeComp_Bind(pTypeComp, wszSavePicture, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
141 ok_ole_success(hr, ITypeComp_Bind);
143 ok(desckind == DESCKIND_FUNCDESC,
144 "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
145 desckind);
146 ok(bindptr.lpfuncdesc != NULL, "bindptr.lpfuncdesc should not have been set to NULL\n");
147 ITypeInfo_ReleaseFuncDesc(pTypeInfo, bindptr.lpfuncdesc);
148 ITypeInfo_Release(pTypeInfo);
150 /* test getting a function within a TKIND_MODULE with INVOKE_PROPERTYGET */
151 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszSavePicture);
152 hr = ITypeComp_Bind(pTypeComp, wszSavePicture, ulHash, INVOKE_PROPERTYGET, &pTypeInfo, &desckind, &bindptr);
153 todo_wine ok(hr == TYPE_E_TYPEMISMATCH,
154 "ITypeComp_Bind should have failed with TYPE_E_TYPEMISMATCH instead of 0x%08x\n",
155 hr);
157 ok(desckind == DESCKIND_NONE,
158 "desckind should have been DESCKIND_NONE instead of %d\n",
159 desckind);
160 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
161 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
163 /* test getting a TKIND_ENUM */
164 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszOLE_TRISTATE);
165 hr = ITypeComp_Bind(pTypeComp, wszOLE_TRISTATE, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
166 ok_ole_success(hr, ITypeComp_Bind);
168 ok(desckind == DESCKIND_TYPECOMP,
169 "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
170 desckind);
171 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
173 ITypeComp_Release(bindptr.lptcomp);
175 /* test getting a value within a TKIND_ENUM */
176 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszUnchecked);
177 hr = ITypeComp_Bind(pTypeComp, wszUnchecked, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
178 ok_ole_success(hr, ITypeComp_Bind);
180 ok(desckind == DESCKIND_VARDESC,
181 "desckind should have been DESCKIND_VARDESC instead of %d\n",
182 desckind);
183 ITypeInfo_ReleaseVarDesc(pTypeInfo, bindptr.lpvardesc);
184 ITypeInfo_Release(pTypeInfo);
186 /* test getting a TKIND_INTERFACE */
187 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszIUnknown);
188 hr = ITypeComp_Bind(pTypeComp, wszIUnknown, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
189 ok_ole_success(hr, ITypeComp_Bind);
191 ok(desckind == DESCKIND_NONE,
192 "desckind should have been DESCKIND_NONE instead of %d\n",
193 desckind);
194 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
195 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
197 /* test getting a TKIND_DISPATCH */
198 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszFont);
199 hr = ITypeComp_Bind(pTypeComp, wszFont, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
200 ok_ole_success(hr, ITypeComp_Bind);
202 ok(desckind == DESCKIND_NONE,
203 "desckind should have been DESCKIND_NONE instead of %d\n",
204 desckind);
205 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
206 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
208 /* test getting a TKIND_RECORD/TKIND_ALIAS */
209 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszGUID);
210 hr = ITypeComp_Bind(pTypeComp, wszGUID, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
211 ok_ole_success(hr, ITypeComp_Bind);
213 ok(desckind == DESCKIND_NONE,
214 "desckind should have been DESCKIND_NONE instead of %d\n",
215 desckind);
216 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
217 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
219 /* test getting a TKIND_ALIAS */
220 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszOLE_COLOR);
221 hr = ITypeComp_Bind(pTypeComp, wszOLE_COLOR, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
222 ok_ole_success(hr, ITypeComp_Bind);
224 ok(desckind == DESCKIND_NONE,
225 "desckind should have been DESCKIND_NONE instead of %d\n",
226 desckind);
227 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
228 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
230 /* test getting a TKIND_COCLASS */
231 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszStdPicture);
232 hr = ITypeComp_Bind(pTypeComp, wszStdPicture, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
233 ok_ole_success(hr, ITypeComp_Bind);
235 ok(desckind == DESCKIND_NONE,
236 "desckind should have been DESCKIND_NONE instead of %d\n",
237 desckind);
238 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
239 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
241 ITypeComp_Release(pTypeComp);
243 /* tests for ITypeComp on an interface */
244 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_IFont, &pFontTypeInfo);
245 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
247 hr = ITypeInfo_GetTypeComp(pFontTypeInfo, &pTypeComp);
248 ok_ole_success(hr, ITypeLib_GetTypeComp);
250 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszClone);
251 hr = ITypeComp_Bind(pTypeComp, wszClone, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
252 ok_ole_success(hr, ITypeComp_Bind);
254 ok(desckind == DESCKIND_FUNCDESC,
255 "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
256 desckind);
257 ok(bindptr.lpfuncdesc != NULL, "bindptr.lpfuncdesc should not have been set to NULL\n");
258 ITypeInfo_ReleaseFuncDesc(pTypeInfo, bindptr.lpfuncdesc);
259 ITypeInfo_Release(pTypeInfo);
261 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszClone);
262 hr = ITypeComp_Bind(pTypeComp, wszClone, ulHash, INVOKE_PROPERTYGET, &pTypeInfo, &desckind, &bindptr);
263 ok(hr == TYPE_E_TYPEMISMATCH, "ITypeComp_Bind should have failed with TYPE_E_TYPEMISMATCH instead of 0x%08x\n", hr);
265 ok(desckind == DESCKIND_NONE,
266 "desckind should have been DESCKIND_NONE instead of %d\n",
267 desckind);
268 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
269 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
271 /* tests that the compare is case-insensitive */
272 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszclone);
273 hr = ITypeComp_Bind(pTypeComp, wszclone, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
274 ok_ole_success(hr, ITypeComp_Bind);
276 ok(desckind == DESCKIND_FUNCDESC,
277 "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
278 desckind);
279 ok(bindptr.lpfuncdesc != NULL, "bindptr.lpfuncdesc should not have been set to NULL\n");
280 ITypeInfo_ReleaseFuncDesc(pTypeInfo, bindptr.lpfuncdesc);
281 ITypeInfo_Release(pTypeInfo);
283 ITypeComp_Release(pTypeComp);
284 ITypeInfo_Release(pFontTypeInfo);
285 ITypeLib_Release(pTypeLib);
288 static void test_CreateDispTypeInfo(void)
290 ITypeInfo *pTypeInfo, *pTI2;
291 HRESULT hr;
292 INTERFACEDATA ifdata;
293 METHODDATA methdata[4];
294 PARAMDATA parms1[2];
295 PARAMDATA parms3[1];
296 TYPEATTR *pTypeAttr;
297 HREFTYPE href;
298 FUNCDESC *pFuncDesc;
299 MEMBERID memid;
301 static WCHAR func1[] = {'f','u','n','c','1',0};
302 static const WCHAR func2[] = {'f','u','n','c','2',0};
303 static const WCHAR func3[] = {'f','u','n','c','3',0};
304 static const WCHAR parm1[] = {'p','a','r','m','1',0};
305 static const WCHAR parm2[] = {'p','a','r','m','2',0};
306 OLECHAR *name = func1;
308 ifdata.pmethdata = methdata;
309 ifdata.cMembers = sizeof(methdata) / sizeof(methdata[0]);
311 methdata[0].szName = SysAllocString(func1);
312 methdata[0].ppdata = parms1;
313 methdata[0].dispid = 0x123;
314 methdata[0].iMeth = 0;
315 methdata[0].cc = CC_STDCALL;
316 methdata[0].cArgs = 2;
317 methdata[0].wFlags = DISPATCH_METHOD;
318 methdata[0].vtReturn = VT_HRESULT;
319 parms1[0].szName = SysAllocString(parm1);
320 parms1[0].vt = VT_I4;
321 parms1[1].szName = SysAllocString(parm2);
322 parms1[1].vt = VT_BSTR;
324 methdata[1].szName = SysAllocString(func2);
325 methdata[1].ppdata = NULL;
326 methdata[1].dispid = 0x124;
327 methdata[1].iMeth = 1;
328 methdata[1].cc = CC_STDCALL;
329 methdata[1].cArgs = 0;
330 methdata[1].wFlags = DISPATCH_PROPERTYGET;
331 methdata[1].vtReturn = VT_I4;
333 methdata[2].szName = SysAllocString(func3);
334 methdata[2].ppdata = parms3;
335 methdata[2].dispid = 0x125;
336 methdata[2].iMeth = 3;
337 methdata[2].cc = CC_STDCALL;
338 methdata[2].cArgs = 1;
339 methdata[2].wFlags = DISPATCH_PROPERTYPUT;
340 methdata[2].vtReturn = VT_HRESULT;
341 parms3[0].szName = SysAllocString(parm1);
342 parms3[0].vt = VT_I4;
344 methdata[3].szName = SysAllocString(func3);
345 methdata[3].ppdata = NULL;
346 methdata[3].dispid = 0x125;
347 methdata[3].iMeth = 4;
348 methdata[3].cc = CC_STDCALL;
349 methdata[3].cArgs = 0;
350 methdata[3].wFlags = DISPATCH_PROPERTYGET;
351 methdata[3].vtReturn = VT_I4;
353 hr = CreateDispTypeInfo(&ifdata, LOCALE_NEUTRAL, &pTypeInfo);
354 ok(hr == S_OK, "hr %08x\n", hr);
356 hr = ITypeInfo_GetTypeAttr(pTypeInfo, &pTypeAttr);
357 ok(hr == S_OK, "hr %08x\n", hr);
359 ok(pTypeAttr->typekind == TKIND_COCLASS, "typekind %0x\n", pTypeAttr->typekind);
360 ok(pTypeAttr->cImplTypes == 1, "cImplTypes %d\n", pTypeAttr->cImplTypes);
361 ok(pTypeAttr->cFuncs == 0, "cFuncs %d\n", pTypeAttr->cFuncs);
362 ok(pTypeAttr->wTypeFlags == 0, "wTypeFlags %04x\n", pTypeAttr->cFuncs);
363 ITypeInfo_ReleaseTypeAttr(pTypeInfo, pTypeAttr);
365 hr = ITypeInfo_GetRefTypeOfImplType(pTypeInfo, 0, &href);
366 ok(hr == S_OK, "hr %08x\n", hr);
367 ok(href == 0, "href = 0x%x\n", href);
368 hr = ITypeInfo_GetRefTypeInfo(pTypeInfo, href, &pTI2);
369 ok(hr == S_OK, "hr %08x\n", hr);
370 hr = ITypeInfo_GetTypeAttr(pTI2, &pTypeAttr);
371 ok(hr == S_OK, "hr %08x\n", hr);
372 ok(pTypeAttr->typekind == TKIND_INTERFACE, "typekind %0x\n", pTypeAttr->typekind);
373 ok(pTypeAttr->cFuncs == 4, "cFuncs %d\n", pTypeAttr->cFuncs);
374 ok(IsEqualGUID(&pTypeAttr->guid, &GUID_NULL), "guid {%08x-...}\n", pTypeAttr->guid.Data1);
375 ok(pTypeAttr->wTypeFlags == 0, "typeflags %08x\n", pTypeAttr->wTypeFlags);
377 ITypeInfo_ReleaseTypeAttr(pTI2, pTypeAttr);
379 hr = ITypeInfo_GetFuncDesc(pTI2, 0, &pFuncDesc);
380 ok(hr == S_OK, "hr %08x\n", hr);
381 ok(pFuncDesc->memid == 0x123, "memid %x\n", pFuncDesc->memid);
382 ok(pFuncDesc->funckind == FUNC_VIRTUAL, "funckind %d\n", pFuncDesc->funckind);
383 ok(pFuncDesc->invkind == methdata[0].wFlags, "invkind %d\n", pFuncDesc->invkind);
384 ok(pFuncDesc->callconv == methdata[0].cc, "callconv %d\n", pFuncDesc->callconv);
385 ok(pFuncDesc->cParams == methdata[0].cArgs, "cParams %d\n", pFuncDesc->cParams);
386 ok(pFuncDesc->oVft == 0, "oVft %d\n", pFuncDesc->oVft);
387 ok(pFuncDesc->wFuncFlags == 0, "oVft %d\n", pFuncDesc->wFuncFlags);
388 ok(pFuncDesc->elemdescFunc.tdesc.vt == VT_HRESULT, "ret vt %x\n", pFuncDesc->elemdescFunc.tdesc.vt);
389 ok(pFuncDesc->lprgelemdescParam[0].tdesc.vt == VT_I4, "parm 0 vt %x\n", pFuncDesc->lprgelemdescParam[0].tdesc.vt);
390 ok(U(pFuncDesc->lprgelemdescParam[0]).paramdesc.wParamFlags == PARAMFLAG_NONE, "parm 0 flags %x\n", U(pFuncDesc->lprgelemdescParam[0]).paramdesc.wParamFlags);
392 ok(pFuncDesc->lprgelemdescParam[1].tdesc.vt == VT_BSTR, "parm 1 vt %x\n", pFuncDesc->lprgelemdescParam[1].tdesc.vt);
393 ok(U(pFuncDesc->lprgelemdescParam[1]).paramdesc.wParamFlags == PARAMFLAG_NONE, "parm 1 flags %x\n", U(pFuncDesc->lprgelemdescParam[1]).paramdesc.wParamFlags);
394 ITypeInfo_ReleaseFuncDesc(pTI2, pFuncDesc);
396 hr = ITypeInfo_GetFuncDesc(pTI2, 1, &pFuncDesc);
397 ok(hr == S_OK, "hr %08x\n", hr);
398 ok(pFuncDesc->funckind == FUNC_VIRTUAL, "funckind %d\n", pFuncDesc->funckind);
399 ok(pFuncDesc->invkind == methdata[1].wFlags, "invkind %d\n", pFuncDesc->invkind);
400 ok(pFuncDesc->callconv == methdata[1].cc, "callconv %d\n", pFuncDesc->callconv);
401 ok(pFuncDesc->cParams == methdata[1].cArgs, "cParams %d\n", pFuncDesc->cParams);
402 ok(pFuncDesc->oVft == 4, "oVft %d\n", pFuncDesc->oVft);
403 ok(pFuncDesc->wFuncFlags == 0, "oVft %d\n", pFuncDesc->wFuncFlags);
404 ok(pFuncDesc->elemdescFunc.tdesc.vt == VT_I4, "ret vt %x\n", pFuncDesc->elemdescFunc.tdesc.vt);
405 ITypeInfo_ReleaseFuncDesc(pTI2, pFuncDesc);
407 hr = ITypeInfo_GetFuncDesc(pTI2, 2, &pFuncDesc);
408 ok(hr == S_OK, "hr %08x\n", hr);
409 ok(pFuncDesc->funckind == FUNC_VIRTUAL, "funckind %d\n", pFuncDesc->funckind);
410 ok(pFuncDesc->invkind == methdata[2].wFlags, "invkind %d\n", pFuncDesc->invkind);
411 ok(pFuncDesc->callconv == methdata[2].cc, "callconv %d\n", pFuncDesc->callconv);
412 ok(pFuncDesc->cParams == methdata[2].cArgs, "cParams %d\n", pFuncDesc->cParams);
413 ok(pFuncDesc->oVft == 12, "oVft %d\n", pFuncDesc->oVft);
414 ok(pFuncDesc->wFuncFlags == 0, "oVft %d\n", pFuncDesc->wFuncFlags);
415 ok(pFuncDesc->elemdescFunc.tdesc.vt == VT_HRESULT, "ret vt %x\n", pFuncDesc->elemdescFunc.tdesc.vt);
416 ok(pFuncDesc->lprgelemdescParam[0].tdesc.vt == VT_I4, "parm 0 vt %x\n", pFuncDesc->lprgelemdescParam[0].tdesc.vt);
417 ok(U(pFuncDesc->lprgelemdescParam[0]).paramdesc.wParamFlags == PARAMFLAG_NONE, "parm 0 flags %x\n", U(pFuncDesc->lprgelemdescParam[0]).paramdesc.wParamFlags);
418 ITypeInfo_ReleaseFuncDesc(pTI2, pFuncDesc);
420 hr = ITypeInfo_GetFuncDesc(pTI2, 3, &pFuncDesc);
421 ok(hr == S_OK, "hr %08x\n", hr);
422 ok(pFuncDesc->funckind == FUNC_VIRTUAL, "funckind %d\n", pFuncDesc->funckind);
423 ok(pFuncDesc->invkind == methdata[3].wFlags, "invkind %d\n", pFuncDesc->invkind);
424 ok(pFuncDesc->callconv == methdata[3].cc, "callconv %d\n", pFuncDesc->callconv);
425 ok(pFuncDesc->cParams == methdata[3].cArgs, "cParams %d\n", pFuncDesc->cParams);
426 ok(pFuncDesc->oVft == 16, "oVft %d\n", pFuncDesc->oVft);
427 ok(pFuncDesc->wFuncFlags == 0, "oVft %d\n", pFuncDesc->wFuncFlags);
428 ok(pFuncDesc->elemdescFunc.tdesc.vt == VT_I4, "ret vt %x\n", pFuncDesc->elemdescFunc.tdesc.vt);
429 ITypeInfo_ReleaseFuncDesc(pTI2, pFuncDesc);
431 /* test GetIDsOfNames on a coclass to see if it searches its interfaces */
432 hr = ITypeInfo_GetIDsOfNames(pTypeInfo, &name, 1, &memid);
433 ok(hr == S_OK, "hr 0x%08x\n", hr);
434 ok(memid == 0x123, "memid 0x%08x\n", memid);
436 ITypeInfo_Release(pTI2);
437 ITypeInfo_Release(pTypeInfo);
439 SysFreeString(parms1[0].szName);
440 SysFreeString(parms1[1].szName);
441 SysFreeString(parms3[0].szName);
442 SysFreeString(methdata[0].szName);
443 SysFreeString(methdata[1].szName);
444 SysFreeString(methdata[2].szName);
445 SysFreeString(methdata[3].szName);
448 static void test_TypeInfo(void)
450 ITypeLib *pTypeLib;
451 ITypeInfo *pTypeInfo;
452 HRESULT hr;
453 static WCHAR wszBogus[] = { 'b','o','g','u','s',0 };
454 static WCHAR wszGetTypeInfo[] = { 'G','e','t','T','y','p','e','I','n','f','o',0 };
455 static WCHAR wszClone[] = {'C','l','o','n','e',0};
456 OLECHAR* bogus = wszBogus;
457 OLECHAR* pwszGetTypeInfo = wszGetTypeInfo;
458 OLECHAR* pwszClone = wszClone;
459 DISPID dispidMember;
460 DISPPARAMS dispparams;
462 hr = LoadTypeLib(wszStdOle2, &pTypeLib);
463 ok_ole_success(hr, LoadTypeLib);
465 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_IFont, &pTypeInfo);
466 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
468 /* test nonexistent method name */
469 hr = ITypeInfo_GetIDsOfNames(pTypeInfo, &bogus, 1, &dispidMember);
470 ok(hr == DISP_E_UNKNOWNNAME,
471 "ITypeInfo_GetIDsOfNames should have returned DISP_E_UNKNOWNNAME instead of 0x%08x\n",
472 hr);
474 /* test invalid memberid */
475 dispparams.cNamedArgs = 0;
476 dispparams.cArgs = 0;
477 dispparams.rgdispidNamedArgs = NULL;
478 dispparams.rgvarg = NULL;
479 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, 0xdeadbeef, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
480 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
482 hr = ITypeInfo_GetIDsOfNames(pTypeInfo, &pwszClone, 1, &dispidMember);
483 ok_ole_success(hr, ITypeInfo_GetIDsOfNames);
485 /* test correct memberid, but wrong flags */
486 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_PROPERTYGET, &dispparams, NULL, NULL, NULL);
487 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
489 /* test NULL dispparams */
490 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_METHOD, NULL, NULL, NULL, NULL);
491 ok(hr == E_INVALIDARG, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr);
493 /* test dispparams->cNamedArgs being bigger than dispparams->cArgs */
494 dispparams.cNamedArgs = 1;
495 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
496 ok(hr == E_INVALIDARG, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr);
498 ITypeInfo_Release(pTypeInfo);
500 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_IDispatch, &pTypeInfo);
501 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
503 hr = ITypeInfo_GetIDsOfNames(pTypeInfo, &pwszGetTypeInfo, 1, &dispidMember);
504 ok_ole_success(hr, ITypeInfo_GetIDsOfNames);
506 /* test invoking a method with a [restricted] keyword */
507 hr = ITypeInfo_Invoke(pTypeInfo, NULL, dispidMember, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
508 todo_wine {
509 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
512 ITypeInfo_Release(pTypeInfo);
513 ITypeLib_Release(pTypeLib);
516 /* RegDeleteTreeW from dlls/advapi32/registry.c */
517 static LSTATUS myRegDeleteTreeW(HKEY hKey, LPCWSTR lpszSubKey)
519 LONG ret;
520 DWORD dwMaxSubkeyLen, dwMaxValueLen;
521 DWORD dwMaxLen, dwSize;
522 WCHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
523 HKEY hSubKey = hKey;
525 if(lpszSubKey)
527 ret = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
528 if (ret) return ret;
531 ret = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, NULL,
532 &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
533 if (ret) goto cleanup;
535 dwMaxSubkeyLen++;
536 dwMaxValueLen++;
537 dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
538 if (dwMaxLen > sizeof(szNameBuf)/sizeof(WCHAR))
540 /* Name too big: alloc a buffer for it */
541 if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(WCHAR))))
543 ret = ERROR_NOT_ENOUGH_MEMORY;
544 goto cleanup;
548 /* Recursively delete all the subkeys */
549 while (TRUE)
551 dwSize = dwMaxLen;
552 if (RegEnumKeyExW(hSubKey, 0, lpszName, &dwSize, NULL,
553 NULL, NULL, NULL)) break;
555 ret = myRegDeleteTreeW(hSubKey, lpszName);
556 if (ret) goto cleanup;
559 if (lpszSubKey)
560 ret = RegDeleteKeyW(hKey, lpszSubKey);
561 else
562 while (TRUE)
564 dwSize = dwMaxLen;
565 if (RegEnumValueW(hKey, 0, lpszName, &dwSize,
566 NULL, NULL, NULL, NULL)) break;
568 ret = RegDeleteValueW(hKey, lpszName);
569 if (ret) goto cleanup;
572 cleanup:
573 if (lpszName != szNameBuf)
574 HeapFree(GetProcessHeap(), 0, lpszName);
575 if(lpszSubKey)
576 RegCloseKey(hSubKey);
577 return ret;
580 static BOOL do_typelib_reg_key(GUID *uid, WORD maj, WORD min, LPCWSTR base, BOOL remove)
582 static const WCHAR typelibW[] = {'T','y','p','e','l','i','b','\\',0};
583 static const WCHAR formatW[] = {'\\','%','u','.','%','u','\\','0','\\','w','i','n','3','2',0};
584 static const WCHAR format2W[] = {'%','s','_','%','u','_','%','u','.','d','l','l',0};
585 WCHAR buf[128];
586 HKEY hkey;
587 BOOL ret = TRUE;
589 memcpy(buf, typelibW, sizeof(typelibW));
590 StringFromGUID2(uid, buf + lstrlenW(buf), 40);
592 if (remove)
594 ok(myRegDeleteTreeW(HKEY_CLASSES_ROOT, buf) == ERROR_SUCCESS, "SHDeleteKey failed\n");
595 return TRUE;
598 wsprintfW(buf + lstrlenW(buf), formatW, maj, min );
600 if (RegCreateKeyExW(HKEY_CLASSES_ROOT, buf, 0, NULL, 0,
601 KEY_WRITE, NULL, &hkey, NULL) != ERROR_SUCCESS)
603 trace("RegCreateKeyExW failed\n");
604 return FALSE;
607 wsprintfW(buf, format2W, base, maj, min);
608 if (RegSetValueExW(hkey, NULL, 0, REG_SZ,
609 (BYTE *)buf, (lstrlenW(buf) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
611 trace("RegSetValueExW failed\n");
612 ret = FALSE;
614 RegCloseKey(hkey);
615 return ret;
618 static void test_QueryPathOfRegTypeLib(void)
620 static const struct test_data
622 WORD maj, min;
623 HRESULT ret;
624 const WCHAR path[16];
625 } td[] = {
626 { 1, 0, TYPE_E_LIBNOTREGISTERED, { 0 } },
627 { 3, 0, S_OK, {'f','a','k','e','_','3','_','0','.','d','l','l',0 } },
628 { 3, 1, S_OK, {'f','a','k','e','_','3','_','1','.','d','l','l',0 } },
629 { 3, 22, S_OK, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
630 { 3, 37, S_OK, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
631 { 3, 40, S_OK, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
632 { 4, 0, TYPE_E_LIBNOTREGISTERED, { 0 } }
634 static const WCHAR base[] = {'f','a','k','e',0};
635 UINT i;
636 RPC_STATUS status;
637 GUID uid;
638 WCHAR uid_str[40];
639 HRESULT ret;
640 BSTR path;
642 status = UuidCreate(&uid);
643 ok(!status, "UuidCreate error %08lx\n", status);
645 StringFromGUID2(&uid, uid_str, 40);
646 /*trace("GUID: %s\n", wine_dbgstr_w(uid_str));*/
648 if (!do_typelib_reg_key(&uid, 3, 0, base, 0)) return;
649 if (!do_typelib_reg_key(&uid, 3, 1, base, 0)) return;
650 if (!do_typelib_reg_key(&uid, 3, 37, base, 0)) return;
652 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
654 ret = QueryPathOfRegTypeLib(&uid, td[i].maj, td[i].min, 0, &path);
655 ok(ret == td[i].ret, "QueryPathOfRegTypeLib(%u.%u) returned %08x\n", td[i].maj, td[i].min, ret);
656 if (ret == S_OK)
658 ok(!lstrcmpW(td[i].path, path), "typelib %u.%u path doesn't match\n", td[i].maj, td[i].min);
659 SysFreeString(path);
663 do_typelib_reg_key(&uid, 0, 0, NULL, 1);
666 static void test_inheritance(void)
668 HRESULT hr;
669 ITypeLib *pTL;
670 ITypeInfo *pTI, *pTI_p;
671 TYPEATTR *pTA;
672 HREFTYPE href;
673 FUNCDESC *pFD;
674 WCHAR path[MAX_PATH];
675 static const WCHAR tl_path[] = {'.','\\','m','i','d','l','_','t','m','a','r','s','h','a','l','.','t','l','b',0};
677 BOOL use_midl_tlb = 0;
679 GetModuleFileNameW(NULL, path, MAX_PATH);
681 if(use_midl_tlb)
682 memcpy(path, tl_path, sizeof(tl_path));
684 hr = LoadTypeLib(path, &pTL);
685 if(FAILED(hr)) return;
688 /* ItestIF3 is a syntax 2 dispinterface */
689 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &DIID_ItestIF3, &pTI);
690 ok(hr == S_OK, "hr %08x\n", hr);
692 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
693 ok(hr == S_OK, "hr %08x\n", hr);
694 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
695 ok(pTA->cbSizeVft == 28, "sizevft %d\n", pTA->cbSizeVft);
696 ok(pTA->wTypeFlags == TYPEFLAG_FDISPATCHABLE, "typeflags %x\n", pTA->wTypeFlags);
697 if(use_midl_tlb) {
698 ok(pTA->cFuncs == 6, "cfuncs %d\n", pTA->cFuncs);
699 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
700 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
702 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
703 ok(hr == S_OK, "hr %08x\n", hr);
704 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
705 ok(hr == S_OK, "hr %08x\n", hr);
706 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
707 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
708 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
709 ITypeInfo_Release(pTI_p);
711 /* Should have six methods */
712 hr = ITypeInfo_GetFuncDesc(pTI, 6, &pFD);
713 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
714 hr = ITypeInfo_GetFuncDesc(pTI, 5, &pFD);
715 ok(hr == S_OK, "hr %08x\n", hr);
716 ok(pFD->memid == 0x60020000, "memid %08x\n", pFD->memid);
717 ok(pFD->oVft == 20, "oVft %d\n", pFD->oVft);
718 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
720 ITypeInfo_Release(pTI);
723 /* ItestIF4 is a syntax 1 dispinterface */
724 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &DIID_ItestIF4, &pTI);
725 ok(hr == S_OK, "hr %08x\n", hr);
727 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
728 ok(hr == S_OK, "hr %08x\n", hr);
729 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
730 ok(pTA->cbSizeVft == 28, "sizevft %d\n", pTA->cbSizeVft);
731 ok(pTA->wTypeFlags == TYPEFLAG_FDISPATCHABLE, "typeflags %x\n", pTA->wTypeFlags);
732 ok(pTA->cFuncs == 1, "cfuncs %d\n", pTA->cFuncs);
733 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
734 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
736 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
737 ok(hr == S_OK, "hr %08x\n", hr);
738 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
739 ok(hr == S_OK, "hr %08x\n", hr);
740 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
741 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
742 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
743 ITypeInfo_Release(pTI_p);
744 hr = ITypeInfo_GetFuncDesc(pTI, 1, &pFD);
745 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
746 hr = ITypeInfo_GetFuncDesc(pTI, 0, &pFD);
747 ok(hr == S_OK, "hr %08x\n", hr);
748 ok(pFD->memid == 0x1c, "memid %08x\n", pFD->memid);
749 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
750 ITypeInfo_Release(pTI);
753 /* ItestIF5 is dual with inherited ifaces which derive from IUnknown but not IDispatch */
754 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &IID_ItestIF5, &pTI);
755 ok(hr == S_OK, "hr %08x\n", hr);
757 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
758 ok(hr == S_OK, "hr %08x\n", hr);
759 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
760 ok(pTA->cbSizeVft == 28, "sizevft %d\n", pTA->cbSizeVft);
761 if(use_midl_tlb) {
762 ok(pTA->wTypeFlags == TYPEFLAG_FDUAL, "typeflags %x\n", pTA->wTypeFlags);
764 ok(pTA->cFuncs == 8, "cfuncs %d\n", pTA->cFuncs);
765 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
766 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
768 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
769 ok(hr == S_OK, "hr %08x\n", hr);
770 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
771 ok(hr == S_OK, "hr %08x\n", hr);
772 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
773 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
774 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
775 ITypeInfo_Release(pTI_p);
776 if(use_midl_tlb) {
777 hr = ITypeInfo_GetFuncDesc(pTI, 6, &pFD);
778 ok(hr == S_OK, "hr %08x\n", hr);
779 ok(pFD->memid == 0x1234, "memid %08x\n", pFD->memid);
780 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
782 ITypeInfo_Release(pTI);
784 /* ItestIF7 is dual with inherited ifaces which derive from Dispatch */
785 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &IID_ItestIF7, &pTI);
786 ok(hr == S_OK, "hr %08x\n", hr);
788 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
789 ok(hr == S_OK, "hr %08x\n", hr);
790 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
791 ok(pTA->cbSizeVft == 28, "sizevft %d\n", pTA->cbSizeVft);
792 ok(pTA->wTypeFlags == (TYPEFLAG_FDISPATCHABLE|TYPEFLAG_FDUAL), "typeflags %x\n", pTA->wTypeFlags);
793 ok(pTA->cFuncs == 10, "cfuncs %d\n", pTA->cFuncs);
794 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
795 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
797 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
798 ok(hr == S_OK, "hr %08x\n", hr);
799 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
800 ok(hr == S_OK, "hr %08x\n", hr);
801 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
802 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
803 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
804 ITypeInfo_Release(pTI_p);
806 hr = ITypeInfo_GetFuncDesc(pTI, 9, &pFD);
807 ok(hr == S_OK, "hr %08x\n", hr);
808 ok(pFD->memid == 0x1236, "memid %08x\n", pFD->memid);
809 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
810 ITypeInfo_Release(pTI);
812 /* ItestIF10 is a syntax 2 dispinterface which doesn't derive from IUnknown */
813 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &DIID_ItestIF10, &pTI);
814 ok(hr == S_OK, "hr %08x\n", hr);
816 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
817 ok(hr == S_OK, "hr %08x\n", hr);
818 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
819 ok(pTA->cbSizeVft == 28, "sizevft %d\n", pTA->cbSizeVft);
820 ok(pTA->wTypeFlags == TYPEFLAG_FDISPATCHABLE, "typeflags %x\n", pTA->wTypeFlags);
821 if(use_midl_tlb) {
822 ok(pTA->cFuncs == 3, "cfuncs %d\n", pTA->cFuncs);
823 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
824 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
826 hr = ITypeInfo_GetRefTypeOfImplType(pTI, -1, &href);
827 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
828 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
829 ok(hr == S_OK, "hr %08x\n", hr);
830 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
831 ok(hr == S_OK, "hr %08x\n", hr);
832 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
833 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
834 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
835 ITypeInfo_Release(pTI_p);
837 /* Should have three methods */
838 hr = ITypeInfo_GetFuncDesc(pTI, 3, &pFD);
839 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
840 hr = ITypeInfo_GetFuncDesc(pTI, 2, &pFD);
841 ok(hr == S_OK, "hr %08x\n", hr);
842 ok(pFD->memid == 0x60010000, "memid %08x\n", pFD->memid);
843 ok(pFD->oVft == 8, "oVft %d\n", pFD->oVft);
844 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
846 ITypeInfo_Release(pTI);
848 /* ItestIF11 is a syntax 2 dispinterface which derives from IDispatch */
849 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &DIID_ItestIF11, &pTI);
850 ok(hr == S_OK, "hr %08x\n", hr);
852 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
853 ok(hr == S_OK, "hr %08x\n", hr);
854 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
855 ok(pTA->cbSizeVft == 28, "sizevft %d\n", pTA->cbSizeVft);
856 ok(pTA->wTypeFlags == TYPEFLAG_FDISPATCHABLE, "typeflags %x\n", pTA->wTypeFlags);
857 if(use_midl_tlb) {
858 ok(pTA->cFuncs == 10, "cfuncs %d\n", pTA->cFuncs);
859 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
860 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
862 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
863 ok(hr == S_OK, "hr %08x\n", hr);
864 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
865 ok(hr == S_OK, "hr %08x\n", hr);
866 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
867 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
868 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
869 ITypeInfo_Release(pTI_p);
871 /* Should have ten methods */
872 hr = ITypeInfo_GetFuncDesc(pTI, 10, &pFD);
873 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
874 hr = ITypeInfo_GetFuncDesc(pTI, 9, &pFD);
875 ok(hr == S_OK, "hr %08x\n", hr);
876 ok(pFD->memid == 0x1236, "memid %08x\n", pFD->memid);
877 ok(pFD->oVft == 36, "oVft %d\n", pFD->oVft);
878 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
880 ITypeInfo_Release(pTI);
883 /* ItestIF2 is an interface which derives from IUnknown */
884 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &IID_ItestIF2, &pTI);
885 ok(hr == S_OK, "hr %08x\n", hr);
887 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
888 ok(hr == S_OK, "hr %08x\n", hr);
889 ok(pTA->typekind == TKIND_INTERFACE, "kind %04x\n", pTA->typekind);
890 ok(pTA->cbSizeVft == 24, "sizevft %d\n", pTA->cbSizeVft);
891 ok(pTA->wTypeFlags == 0, "typeflags %x\n", pTA->wTypeFlags);
892 if(use_midl_tlb) {
893 ok(pTA->cFuncs == 1, "cfuncs %d\n", pTA->cFuncs);
894 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
895 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
897 /* Should have one method */
898 hr = ITypeInfo_GetFuncDesc(pTI, 1, &pFD);
899 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
900 hr = ITypeInfo_GetFuncDesc(pTI, 0, &pFD);
901 ok(hr == S_OK, "hr %08x\n", hr);
902 ok(pFD->memid == 0x60020000, "memid %08x\n", pFD->memid);
903 ok(pFD->oVft == 20, "oVft %d\n", pFD->oVft);
904 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
906 ITypeInfo_Release(pTI);
908 ITypeLib_Release(pTL);
910 return;
913 #if 0 /* use this to generate more tests */
915 #define OLE_CHECK(x) { HRESULT hr = x; if (FAILED(hr)) { printf(#x "failed - %x\n", hr); return; } }
917 static char *dump_string(LPWSTR wstr)
919 int size = lstrlenW(wstr)+3;
920 char *out = CoTaskMemAlloc(size);
921 WideCharToMultiByte(20127, 0, wstr, -1, out+1, size, NULL, NULL);
922 out[0] = '\"';
923 strcat(out, "\"");
924 return out;
927 struct map_entry
929 DWORD value;
930 const char *name;
933 #define MAP_ENTRY(x) { x, #x }
934 static const struct map_entry tkind_map[] = {
935 MAP_ENTRY(TKIND_ENUM),
936 MAP_ENTRY(TKIND_RECORD),
937 MAP_ENTRY(TKIND_MODULE),
938 MAP_ENTRY(TKIND_INTERFACE),
939 MAP_ENTRY(TKIND_DISPATCH),
940 MAP_ENTRY(TKIND_COCLASS),
941 MAP_ENTRY(TKIND_ALIAS),
942 MAP_ENTRY(TKIND_UNION),
943 MAP_ENTRY(TKIND_MAX),
944 {0, NULL}
947 static const struct map_entry funckind_map[] = {
948 MAP_ENTRY(FUNC_VIRTUAL),
949 MAP_ENTRY(FUNC_PUREVIRTUAL),
950 MAP_ENTRY(FUNC_NONVIRTUAL),
951 MAP_ENTRY(FUNC_STATIC),
952 MAP_ENTRY(FUNC_DISPATCH),
953 {0, NULL}
956 static const struct map_entry invkind_map[] = {
957 MAP_ENTRY(INVOKE_FUNC),
958 MAP_ENTRY(INVOKE_PROPERTYGET),
959 MAP_ENTRY(INVOKE_PROPERTYPUT),
960 MAP_ENTRY(INVOKE_PROPERTYPUTREF),
961 {0, NULL}
964 #undef MAP_ENTRY
966 static const char *map_value(DWORD val, const struct map_entry *map)
968 static int map_id;
969 static char bufs[16][256];
970 char *buf;
972 while (map->name)
974 if (map->value == val)
975 return map->name;
976 map++;
979 buf = bufs[(map_id++)%16];
980 sprintf(buf, "0x%x", val);
981 return buf;
984 static void test_dump_typelib(const char *name)
986 WCHAR wszString[260];
987 ITypeInfo *info;
988 ITypeLib *lib;
989 int count;
990 int i;
992 MultiByteToWideChar(CP_ACP, 0, name, -1, wszString, 260);
993 OLE_CHECK(LoadTypeLib(wszString, &lib));
994 count = ITypeLib_GetTypeInfoCount(lib);
995 printf("/* interfaces count: %d */\n", count);
996 for (i = 0; i < count; i++)
998 TYPEATTR *attr;
999 BSTR name;
1000 int f = 0;
1002 OLE_CHECK(ITypeLib_GetDocumentation(lib, i, &name, NULL, NULL, NULL));
1003 printf("{\n"
1004 " %s,\n", dump_string(name));
1005 SysFreeString(name);
1007 OLE_CHECK(ITypeLib_GetTypeInfo(lib, i, &info));
1008 ITypeInfo_GetTypeAttr(info, &attr);
1009 printf(" /*kind*/ %s, /*flags*/ 0x%x, /*align*/ %d, /*size*/ %d,\n"
1010 " /*#vtbl*/ %d, /*#func*/ %d,\n"
1011 " {\n",
1012 map_value(attr->typekind, tkind_map), attr->wTypeFlags, attr->cbAlignment, attr->cbSizeInstance, attr->cbSizeVft,
1013 attr->cFuncs);
1014 ITypeInfo_ReleaseTypeAttr(info, attr);
1015 while (1)
1017 FUNCDESC *desc;
1018 BSTR tab[256];
1019 UINT cNames;
1020 int p;
1022 if (FAILED(ITypeInfo_GetFuncDesc(info, f, &desc)))
1023 break;
1024 printf(" {\n"
1025 " 0x%x, /*func*/ %s, /*inv*/ %s, /*call*/ 0x%x,\n",
1026 desc->memid, map_value(desc->funckind, funckind_map), map_value(desc->invkind, invkind_map),
1027 desc->callconv);
1028 printf(" /*#param*/ %d, /*#opt*/ %d, /*vtbl*/ %d, /*#scodes*/ %d, /*flags*/ 0x%x,\n",
1029 desc->cParams, desc->cParamsOpt, desc->oVft, desc->cScodes, desc->wFuncFlags);
1030 printf(" {%d, %x}, /* ret */\n", desc->elemdescFunc.tdesc.vt, desc->elemdescFunc.paramdesc.wParamFlags);
1031 printf(" { /* params */\n");
1032 for (p = 0; p < desc->cParams; p++)
1034 ELEMDESC e = desc->lprgelemdescParam[p];
1035 printf(" {%d, %x},\n", e.tdesc.vt, e.paramdesc.wParamFlags);
1037 printf(" {-1, -1}\n");
1038 printf(" },\n");
1039 printf(" { /* names */\n");
1040 OLE_CHECK(ITypeInfo_GetNames(info, desc->memid, tab, 256, &cNames));
1041 for (p = 0; p < cNames; p++)
1043 printf(" %s,\n", dump_string(tab[p]));
1044 SysFreeString(tab[p]);
1046 printf(" NULL,\n");
1047 printf(" },\n");
1048 printf(" },\n");
1049 ITypeInfo_ReleaseFuncDesc(info, desc);
1050 f++;
1052 printf(" }\n");
1053 printf("},\n");
1054 ITypeInfo_Release(info);
1056 ITypeLib_Release(lib);
1059 #else
1061 typedef struct _element_info
1063 VARTYPE vt;
1064 USHORT wParamFlags;
1065 } element_info;
1067 typedef struct _function_info
1069 MEMBERID memid;
1070 FUNCKIND funckind;
1071 INVOKEKIND invkind;
1072 CALLCONV callconv;
1073 short cParams;
1074 short cParamsOpt;
1075 short oVft;
1076 short cScodes;
1077 WORD wFuncFlags;
1078 element_info ret_type;
1079 element_info params[15];
1080 LPCSTR names[15];
1081 } function_info;
1083 typedef struct _interface_info
1085 LPCSTR name;
1086 TYPEKIND type;
1087 WORD wTypeFlags;
1088 USHORT cbAlignment;
1089 USHORT cbSizeInstance;
1090 USHORT cbSizeVft;
1091 USHORT cFuncs;
1092 function_info funcs[20];
1093 } interface_info;
1095 static const interface_info info[] = {
1096 /* interfaces count: 2 */
1098 "IDualIface",
1099 /*kind*/ TKIND_DISPATCH, /*flags*/ 0x1040, /*align*/ 4, /*size*/ 4,
1100 /*#vtbl*/ 28, /*#func*/ 8,
1103 0x60000000, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1104 /*#param*/ 2, /*#opt*/ 0, /*vtbl*/ 0, /*#scodes*/ 0, /*flags*/ 0x1,
1105 {24, 0}, /* ret */
1106 { /* params */
1107 {26, 1},
1108 {26, 2},
1109 {-1, -1}
1111 { /* names */
1112 "QueryInterface",
1113 "riid",
1114 "ppvObj",
1115 NULL,
1119 0x60000001, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1120 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 4, /*#scodes*/ 0, /*flags*/ 0x1,
1121 {19, 0}, /* ret */
1122 { /* params */
1123 {-1, -1}
1125 { /* names */
1126 "AddRef",
1127 NULL,
1131 0x60000002, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1132 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 8, /*#scodes*/ 0, /*flags*/ 0x1,
1133 {19, 0}, /* ret */
1134 { /* params */
1135 {-1, -1}
1137 { /* names */
1138 "Release",
1139 NULL,
1143 0x60010000, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1144 /*#param*/ 1, /*#opt*/ 0, /*vtbl*/ 12, /*#scodes*/ 0, /*flags*/ 0x1,
1145 {24, 0}, /* ret */
1146 { /* params */
1147 {26, 2},
1148 {-1, -1}
1150 { /* names */
1151 "GetTypeInfoCount",
1152 "pctinfo",
1153 NULL,
1157 0x60010001, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1158 /*#param*/ 3, /*#opt*/ 0, /*vtbl*/ 16, /*#scodes*/ 0, /*flags*/ 0x1,
1159 {24, 0}, /* ret */
1160 { /* params */
1161 {23, 1},
1162 {19, 1},
1163 {26, 2},
1164 {-1, -1}
1166 { /* names */
1167 "GetTypeInfo",
1168 "itinfo",
1169 "lcid",
1170 "pptinfo",
1171 NULL,
1175 0x60010002, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1176 /*#param*/ 5, /*#opt*/ 0, /*vtbl*/ 20, /*#scodes*/ 0, /*flags*/ 0x1,
1177 {24, 0}, /* ret */
1178 { /* params */
1179 {26, 1},
1180 {26, 1},
1181 {23, 1},
1182 {19, 1},
1183 {26, 2},
1184 {-1, -1}
1186 { /* names */
1187 "GetIDsOfNames",
1188 "riid",
1189 "rgszNames",
1190 "cNames",
1191 "lcid",
1192 "rgdispid",
1193 NULL,
1197 0x60010003, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1198 /*#param*/ 8, /*#opt*/ 0, /*vtbl*/ 24, /*#scodes*/ 0, /*flags*/ 0x1,
1199 {24, 0}, /* ret */
1200 { /* params */
1201 {3, 1},
1202 {26, 1},
1203 {19, 1},
1204 {18, 1},
1205 {26, 1},
1206 {26, 2},
1207 {26, 2},
1208 {26, 2},
1209 {-1, -1}
1211 { /* names */
1212 "Invoke",
1213 "dispidMember",
1214 "riid",
1215 "lcid",
1216 "wFlags",
1217 "pdispparams",
1218 "pvarResult",
1219 "pexcepinfo",
1220 "puArgErr",
1221 NULL,
1225 0x60020000, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1226 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 28, /*#scodes*/ 0, /*flags*/ 0x0,
1227 {24, 0}, /* ret */
1228 { /* params */
1229 {-1, -1}
1231 { /* names */
1232 "Test",
1233 NULL,
1239 "ISimpleIface",
1240 /*kind*/ TKIND_INTERFACE, /*flags*/ 0x1000, /*align*/ 4, /*size*/ 4,
1241 /*#vtbl*/ 32, /*#func*/ 1,
1244 0x60020000, /*func*/ FUNC_PUREVIRTUAL, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1245 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 28, /*#scodes*/ 0, /*flags*/ 0x0,
1246 {25, 0}, /* ret */
1247 { /* params */
1248 {-1, -1}
1250 { /* names */
1251 "Test",
1252 NULL,
1259 #define check_type(elem, info) { \
1260 expect_int((elem)->tdesc.vt, (info)->vt); \
1261 expect_hex(U(*(elem)).paramdesc.wParamFlags, (info)->wParamFlags); \
1264 static void test_dump_typelib(const char *name)
1266 WCHAR wszName[MAX_PATH];
1267 ITypeLib *typelib;
1268 int ifcount = sizeof(info)/sizeof(info[0]);
1269 int iface, func;
1271 MultiByteToWideChar(CP_UTF8, 0, name, -1, wszName, MAX_PATH);
1272 ole_check(LoadTypeLibEx(wszName, REGKIND_NONE, &typelib));
1273 expect_eq(ITypeLib_GetTypeInfoCount(typelib), ifcount, UINT, "%d");
1274 for (iface = 0; iface < ifcount; iface++)
1276 const interface_info *if_info = &info[iface];
1277 ITypeInfo *typeinfo;
1278 TYPEATTR *typeattr;
1279 BSTR bstrIfName;
1281 trace("Interface %s\n", if_info->name);
1282 ole_check(ITypeLib_GetTypeInfo(typelib, iface, &typeinfo));
1283 ole_check(ITypeLib_GetDocumentation(typelib, iface, &bstrIfName, NULL, NULL, NULL));
1284 expect_wstr_utf8val(bstrIfName, if_info->name);
1285 SysFreeString(bstrIfName);
1287 ole_check(ITypeInfo_GetTypeAttr(typeinfo, &typeattr));
1288 expect_int(typeattr->typekind, if_info->type);
1289 expect_hex(typeattr->wTypeFlags, if_info->wTypeFlags);
1290 expect_int(typeattr->cbAlignment, if_info->cbAlignment);
1291 expect_int(typeattr->cbSizeInstance, if_info->cbSizeInstance);
1292 expect_int(typeattr->cbSizeVft, if_info->cbSizeVft);
1293 expect_int(typeattr->cFuncs, if_info->cFuncs);
1295 for (func = 0; func < typeattr->cFuncs; func++)
1297 function_info *fn_info = (function_info *)&if_info->funcs[func];
1298 FUNCDESC *desc;
1299 BSTR namesTab[256];
1300 UINT cNames;
1301 int i;
1303 trace("Function %s\n", fn_info->names[0]);
1304 ole_check(ITypeInfo_GetFuncDesc(typeinfo, func, &desc));
1305 expect_int(desc->memid, fn_info->memid);
1306 expect_int(desc->funckind, fn_info->funckind);
1307 expect_int(desc->invkind, fn_info->invkind);
1308 expect_int(desc->callconv, fn_info->callconv);
1309 expect_int(desc->cParams, fn_info->cParams);
1310 expect_int(desc->cParamsOpt, fn_info->cParamsOpt);
1311 expect_int(desc->oVft, fn_info->oVft);
1312 expect_int(desc->cScodes, fn_info->cScodes);
1313 expect_int(desc->wFuncFlags, fn_info->wFuncFlags);
1314 ole_check(ITypeInfo_GetNames(typeinfo, desc->memid, namesTab, 256, &cNames));
1315 for (i = 0; i < cNames; i++)
1317 expect_wstr_utf8val(namesTab[i], fn_info->names[i]);
1318 SysFreeString(namesTab[i]);
1320 expect_null(fn_info->names[cNames]);
1322 check_type(&desc->elemdescFunc, &fn_info->ret_type);
1323 for (i = 0 ; i < desc->cParams; i++)
1325 check_type(&desc->lprgelemdescParam[i], &fn_info->params[i]);
1327 expect_int(fn_info->params[desc->cParams].vt, (VARTYPE)-1);
1329 ITypeInfo_ReleaseFuncDesc(typeinfo, desc);
1332 ITypeInfo_ReleaseTypeAttr(typeinfo, typeattr);
1333 ITypeInfo_Release(typeinfo);
1335 ITypeLib_Release(typelib);
1338 #endif
1340 static const char *create_test_typelib(void)
1342 static char filename[MAX_PATH];
1343 HANDLE file;
1344 HRSRC res;
1345 void *ptr;
1346 DWORD written;
1348 GetTempFileNameA( ".", "tlb", 0, filename );
1349 file = CreateFile( filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 );
1350 ok( file != INVALID_HANDLE_VALUE, "file creation failed\n" );
1351 if (file == INVALID_HANDLE_VALUE) return NULL;
1352 res = FindResource( GetModuleHandle(0), MAKEINTRESOURCE(2), "TYPELIB" );
1353 ok( res != 0, "couldn't find resource\n" );
1354 ptr = LockResource( LoadResource( GetModuleHandle(0), res ));
1355 WriteFile( file, ptr, SizeofResource( GetModuleHandle(0), res ), &written, NULL );
1356 ok( written == SizeofResource( GetModuleHandle(0), res ), "couldn't write resource\n" );
1357 CloseHandle( file );
1358 return filename;
1361 START_TEST(typelib)
1363 const char *filename;
1365 ref_count_test(wszStdOle2);
1366 test_TypeComp();
1367 test_CreateDispTypeInfo();
1368 test_TypeInfo();
1369 test_QueryPathOfRegTypeLib();
1370 test_inheritance();
1372 if ((filename = create_test_typelib()))
1374 test_dump_typelib( filename );
1375 DeleteFile( filename );