Sync to trunk (r44371)
[reactos.git] / rostests / winetests / oleaut32 / typelib.c
1 /*
2 * ITypeLib and ITypeInfo test
3 *
4 * Copyright 2004 Jacek Caban
5 * Copyright 2006 Dmitry Timoshkov
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #define COBJMACROS
23
24 #include <wine/test.h>
25 #include <stdarg.h>
26 #include <stdio.h>
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "oleauto.h"
31 #include "ocidl.h"
32 #include "shlwapi.h"
33 #include "tmarshal.h"
34
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")
39
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); \
45 }
46
47 #define ole_expect(expr, expect) { \
48 HRESULT r = expr; \
49 ok(r == (expect), #expr " returned %x, expected %s (%x)\n", r, #expect, expect); \
50 }
51
52 #define ole_check(expr) ole_expect(expr, S_OK);
53
54 #define ok_ole_success(hr, func) ok(hr == S_OK, #func " failed with error 0x%08x\n", hr)
55
56 static const WCHAR wszStdOle2[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
57
58 static void ref_count_test(LPCWSTR type_lib)
59 {
60 ITypeLib *iface;
61 ITypeInfo *iti1, *iti2;
62 HRESULT hRes;
63 int ref_count;
64
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;
70
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;
76
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");
80
81 ITypeLib_AddRef(iface);
82 ITypeInfo_Release(iti2);
83 ITypeInfo_Release(iti1);
84 ok(ITypeLib_Release(iface) == 0, "ITypeLib should be destroyed here.\n");
85 }
86
87 static void test_TypeComp(void)
88 {
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};
108
109 hr = LoadTypeLib(wszStdOle2, &pTypeLib);
110 ok_ole_success(hr, LoadTypeLib);
111
112 hr = ITypeLib_GetTypeComp(pTypeLib, &pTypeComp);
113 ok_ole_success(hr, ITypeLib_GetTypeComp);
114
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);
119
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");
124
125 ITypeComp_Release(bindptr.lptcomp);
126
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);
131
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);
137
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);
142
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);
149
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);
156
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");
162
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);
167
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");
172
173 ITypeComp_Release(bindptr.lptcomp);
174
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);
179
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);
185
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);
190
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");
196
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);
201
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");
207
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);
212
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");
218
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);
223
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");
229
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);
234
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");
240
241 ITypeComp_Release(pTypeComp);
242
243 /* tests for ITypeComp on an interface */
244 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_IFont, &pFontTypeInfo);
245 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
246
247 hr = ITypeInfo_GetTypeComp(pFontTypeInfo, &pTypeComp);
248 ok_ole_success(hr, ITypeLib_GetTypeComp);
249
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);
253
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);
260
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);
264
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");
270
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);
275
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);
282
283 ITypeComp_Release(pTypeComp);
284 ITypeInfo_Release(pFontTypeInfo);
285 ITypeLib_Release(pTypeLib);
286 }
287
288 static void test_CreateDispTypeInfo(void)
289 {
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;
300
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;
307
308 ifdata.pmethdata = methdata;
309 ifdata.cMembers = sizeof(methdata) / sizeof(methdata[0]);
310
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;
323
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;
332
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;
343
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;
352
353 hr = CreateDispTypeInfo(&ifdata, LOCALE_NEUTRAL, &pTypeInfo);
354 ok(hr == S_OK, "hr %08x\n", hr);
355
356 hr = ITypeInfo_GetTypeAttr(pTypeInfo, &pTypeAttr);
357 ok(hr == S_OK, "hr %08x\n", hr);
358
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);
364
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);
376
377 ITypeInfo_ReleaseTypeAttr(pTI2, pTypeAttr);
378
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);
391
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);
395
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);
406
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);
419
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);
430
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);
435
436 ITypeInfo_Release(pTI2);
437 ITypeInfo_Release(pTypeInfo);
438
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);
446 }
447
448 static void test_TypeInfo(void)
449 {
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;
461
462 hr = LoadTypeLib(wszStdOle2, &pTypeLib);
463 ok_ole_success(hr, LoadTypeLib);
464
465 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_IFont, &pTypeInfo);
466 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
467
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);
473
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);
481
482 hr = ITypeInfo_GetIDsOfNames(pTypeInfo, &pwszClone, 1, &dispidMember);
483 ok_ole_success(hr, ITypeInfo_GetIDsOfNames);
484
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);
488
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);
492
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);
497
498 ITypeInfo_Release(pTypeInfo);
499
500 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_IDispatch, &pTypeInfo);
501 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
502
503 hr = ITypeInfo_GetIDsOfNames(pTypeInfo, &pwszGetTypeInfo, 1, &dispidMember);
504 ok_ole_success(hr, ITypeInfo_GetIDsOfNames);
505
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);
510 }
511
512 ITypeInfo_Release(pTypeInfo);
513 ITypeLib_Release(pTypeLib);
514 }
515
516 static BOOL do_typelib_reg_key(GUID *uid, WORD maj, WORD min, LPCWSTR base, BOOL remove)
517 {
518 static const WCHAR typelibW[] = {'T','y','p','e','l','i','b','\\',0};
519 static const WCHAR formatW[] = {'\\','%','u','.','%','u','\\','0','\\','w','i','n','3','2',0};
520 static const WCHAR format2W[] = {'%','s','_','%','u','_','%','u','.','d','l','l',0};
521 WCHAR buf[128];
522 HKEY hkey;
523 BOOL ret = TRUE;
524
525 memcpy(buf, typelibW, sizeof(typelibW));
526 StringFromGUID2(uid, buf + lstrlenW(buf), 40);
527
528 if (remove)
529 {
530 ok(SHDeleteKeyW(HKEY_CLASSES_ROOT, buf) == ERROR_SUCCESS, "SHDeleteKey failed\n");
531 return TRUE;
532 }
533
534 wsprintfW(buf + lstrlenW(buf), formatW, maj, min );
535
536 if (RegCreateKeyExW(HKEY_CLASSES_ROOT, buf, 0, NULL, 0,
537 KEY_WRITE, NULL, &hkey, NULL) != ERROR_SUCCESS)
538 {
539 trace("RegCreateKeyExW failed\n");
540 return FALSE;
541 }
542
543 wsprintfW(buf, format2W, base, maj, min);
544 if (RegSetValueExW(hkey, NULL, 0, REG_SZ,
545 (BYTE *)buf, (lstrlenW(buf) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
546 {
547 trace("RegSetValueExW failed\n");
548 ret = FALSE;
549 }
550 RegCloseKey(hkey);
551 return ret;
552 }
553
554 static void test_QueryPathOfRegTypeLib(void)
555 {
556 static const struct test_data
557 {
558 WORD maj, min;
559 HRESULT ret;
560 const WCHAR path[16];
561 } td[] = {
562 { 1, 0, TYPE_E_LIBNOTREGISTERED, { 0 } },
563 { 3, 0, S_OK, {'f','a','k','e','_','3','_','0','.','d','l','l',0 } },
564 { 3, 1, S_OK, {'f','a','k','e','_','3','_','1','.','d','l','l',0 } },
565 { 3, 22, S_OK, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
566 { 3, 37, S_OK, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
567 { 3, 40, S_OK, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
568 { 4, 0, TYPE_E_LIBNOTREGISTERED, { 0 } }
569 };
570 static const WCHAR base[] = {'f','a','k','e',0};
571 UINT i;
572 RPC_STATUS status;
573 GUID uid;
574 WCHAR uid_str[40];
575 HRESULT ret;
576 BSTR path;
577
578 status = UuidCreate(&uid);
579 ok(!status, "UuidCreate error %08lx\n", status);
580
581 StringFromGUID2(&uid, uid_str, 40);
582 /*trace("GUID: %s\n", wine_dbgstr_w(uid_str));*/
583
584 if (!do_typelib_reg_key(&uid, 3, 0, base, 0)) return;
585 if (!do_typelib_reg_key(&uid, 3, 1, base, 0)) return;
586 if (!do_typelib_reg_key(&uid, 3, 37, base, 0)) return;
587
588 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
589 {
590 ret = QueryPathOfRegTypeLib(&uid, td[i].maj, td[i].min, 0, &path);
591 ok(ret == td[i].ret, "QueryPathOfRegTypeLib(%u.%u) returned %08x\n", td[i].maj, td[i].min, ret);
592 if (ret == S_OK)
593 {
594 ok(!lstrcmpW(td[i].path, path), "typelib %u.%u path doesn't match\n", td[i].maj, td[i].min);
595 SysFreeString(path);
596 }
597 }
598
599 do_typelib_reg_key(&uid, 0, 0, NULL, 1);
600 }
601
602 static void test_inheritance(void)
603 {
604 HRESULT hr;
605 ITypeLib *pTL;
606 ITypeInfo *pTI, *pTI_p;
607 TYPEATTR *pTA;
608 HREFTYPE href;
609 FUNCDESC *pFD;
610 WCHAR path[MAX_PATH];
611 static const WCHAR tl_path[] = {'.','\\','m','i','d','l','_','t','m','a','r','s','h','a','l','.','t','l','b',0};
612
613 BOOL use_midl_tlb = 0;
614
615 GetModuleFileNameW(NULL, path, MAX_PATH);
616
617 if(use_midl_tlb)
618 memcpy(path, tl_path, sizeof(tl_path));
619
620 hr = LoadTypeLib(path, &pTL);
621 if(FAILED(hr)) return;
622
623
624 /* ItestIF3 is a syntax 2 dispinterface */
625 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &DIID_ItestIF3, &pTI);
626 ok(hr == S_OK, "hr %08x\n", hr);
627
628 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
629 ok(hr == S_OK, "hr %08x\n", hr);
630 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
631 ok(pTA->cbSizeVft == 28, "sizevft %d\n", pTA->cbSizeVft);
632 ok(pTA->wTypeFlags == TYPEFLAG_FDISPATCHABLE, "typeflags %x\n", pTA->wTypeFlags);
633 if(use_midl_tlb) {
634 ok(pTA->cFuncs == 6, "cfuncs %d\n", pTA->cFuncs);
635 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
636 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
637
638 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
639 ok(hr == S_OK, "hr %08x\n", hr);
640 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
641 ok(hr == S_OK, "hr %08x\n", hr);
642 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
643 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
644 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
645 ITypeInfo_Release(pTI_p);
646
647 /* Should have six methods */
648 hr = ITypeInfo_GetFuncDesc(pTI, 6, &pFD);
649 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
650 hr = ITypeInfo_GetFuncDesc(pTI, 5, &pFD);
651 ok(hr == S_OK, "hr %08x\n", hr);
652 ok(pFD->memid == 0x60020000, "memid %08x\n", pFD->memid);
653 ok(pFD->oVft == 20, "oVft %d\n", pFD->oVft);
654 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
655 }
656 ITypeInfo_Release(pTI);
657
658
659 /* ItestIF4 is a syntax 1 dispinterface */
660 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &DIID_ItestIF4, &pTI);
661 ok(hr == S_OK, "hr %08x\n", hr);
662
663 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
664 ok(hr == S_OK, "hr %08x\n", hr);
665 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
666 ok(pTA->cbSizeVft == 28, "sizevft %d\n", pTA->cbSizeVft);
667 ok(pTA->wTypeFlags == TYPEFLAG_FDISPATCHABLE, "typeflags %x\n", pTA->wTypeFlags);
668 ok(pTA->cFuncs == 1, "cfuncs %d\n", pTA->cFuncs);
669 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
670 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
671
672 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
673 ok(hr == S_OK, "hr %08x\n", hr);
674 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
675 ok(hr == S_OK, "hr %08x\n", hr);
676 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
677 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
678 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
679 ITypeInfo_Release(pTI_p);
680 hr = ITypeInfo_GetFuncDesc(pTI, 1, &pFD);
681 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
682 hr = ITypeInfo_GetFuncDesc(pTI, 0, &pFD);
683 ok(hr == S_OK, "hr %08x\n", hr);
684 ok(pFD->memid == 0x1c, "memid %08x\n", pFD->memid);
685 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
686 ITypeInfo_Release(pTI);
687
688
689 /* ItestIF5 is dual with inherited ifaces which derive from IUnknown but not IDispatch */
690 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &IID_ItestIF5, &pTI);
691 ok(hr == S_OK, "hr %08x\n", hr);
692
693 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
694 ok(hr == S_OK, "hr %08x\n", hr);
695 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
696 ok(pTA->cbSizeVft == 28, "sizevft %d\n", pTA->cbSizeVft);
697 if(use_midl_tlb) {
698 ok(pTA->wTypeFlags == TYPEFLAG_FDUAL, "typeflags %x\n", pTA->wTypeFlags);
699 }
700 ok(pTA->cFuncs == 8, "cfuncs %d\n", pTA->cFuncs);
701 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
702 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
703
704 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
705 ok(hr == S_OK, "hr %08x\n", hr);
706 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
707 ok(hr == S_OK, "hr %08x\n", hr);
708 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
709 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
710 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
711 ITypeInfo_Release(pTI_p);
712 if(use_midl_tlb) {
713 hr = ITypeInfo_GetFuncDesc(pTI, 6, &pFD);
714 ok(hr == S_OK, "hr %08x\n", hr);
715 ok(pFD->memid == 0x1234, "memid %08x\n", pFD->memid);
716 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
717 }
718 ITypeInfo_Release(pTI);
719
720 /* ItestIF7 is dual with inherited ifaces which derive from Dispatch */
721 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &IID_ItestIF7, &pTI);
722 ok(hr == S_OK, "hr %08x\n", hr);
723
724 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
725 ok(hr == S_OK, "hr %08x\n", hr);
726 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
727 ok(pTA->cbSizeVft == 28, "sizevft %d\n", pTA->cbSizeVft);
728 ok(pTA->wTypeFlags == (TYPEFLAG_FDISPATCHABLE|TYPEFLAG_FDUAL), "typeflags %x\n", pTA->wTypeFlags);
729 ok(pTA->cFuncs == 10, "cfuncs %d\n", pTA->cFuncs);
730 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
731 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
732
733 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
734 ok(hr == S_OK, "hr %08x\n", hr);
735 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
736 ok(hr == S_OK, "hr %08x\n", hr);
737 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
738 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
739 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
740 ITypeInfo_Release(pTI_p);
741
742 hr = ITypeInfo_GetFuncDesc(pTI, 9, &pFD);
743 ok(hr == S_OK, "hr %08x\n", hr);
744 ok(pFD->memid == 0x1236, "memid %08x\n", pFD->memid);
745 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
746 ITypeInfo_Release(pTI);
747
748 /* ItestIF10 is a syntax 2 dispinterface which doesn't derive from IUnknown */
749 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &DIID_ItestIF10, &pTI);
750 ok(hr == S_OK, "hr %08x\n", hr);
751
752 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
753 ok(hr == S_OK, "hr %08x\n", hr);
754 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
755 ok(pTA->cbSizeVft == 28, "sizevft %d\n", pTA->cbSizeVft);
756 ok(pTA->wTypeFlags == TYPEFLAG_FDISPATCHABLE, "typeflags %x\n", pTA->wTypeFlags);
757 if(use_midl_tlb) {
758 ok(pTA->cFuncs == 3, "cfuncs %d\n", pTA->cFuncs);
759 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
760 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
761
762 hr = ITypeInfo_GetRefTypeOfImplType(pTI, -1, &href);
763 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
764 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
765 ok(hr == S_OK, "hr %08x\n", hr);
766 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
767 ok(hr == S_OK, "hr %08x\n", hr);
768 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
769 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
770 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
771 ITypeInfo_Release(pTI_p);
772
773 /* Should have three methods */
774 hr = ITypeInfo_GetFuncDesc(pTI, 3, &pFD);
775 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
776 hr = ITypeInfo_GetFuncDesc(pTI, 2, &pFD);
777 ok(hr == S_OK, "hr %08x\n", hr);
778 ok(pFD->memid == 0x60010000, "memid %08x\n", pFD->memid);
779 ok(pFD->oVft == 8, "oVft %d\n", pFD->oVft);
780 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
781 }
782 ITypeInfo_Release(pTI);
783
784 /* ItestIF11 is a syntax 2 dispinterface which derives from IDispatch */
785 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &DIID_ItestIF11, &pTI);
786 ok(hr == S_OK, "hr %08x\n", hr);
787
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, "typeflags %x\n", pTA->wTypeFlags);
793 if(use_midl_tlb) {
794 ok(pTA->cFuncs == 10, "cfuncs %d\n", pTA->cFuncs);
795 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
796 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
797
798 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
799 ok(hr == S_OK, "hr %08x\n", hr);
800 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
801 ok(hr == S_OK, "hr %08x\n", hr);
802 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
803 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
804 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
805 ITypeInfo_Release(pTI_p);
806
807 /* Should have ten methods */
808 hr = ITypeInfo_GetFuncDesc(pTI, 10, &pFD);
809 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
810 hr = ITypeInfo_GetFuncDesc(pTI, 9, &pFD);
811 ok(hr == S_OK, "hr %08x\n", hr);
812 ok(pFD->memid == 0x1236, "memid %08x\n", pFD->memid);
813 ok(pFD->oVft == 36, "oVft %d\n", pFD->oVft);
814 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
815 }
816 ITypeInfo_Release(pTI);
817
818
819 /* ItestIF2 is an interface which derives from IUnknown */
820 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &IID_ItestIF2, &pTI);
821 ok(hr == S_OK, "hr %08x\n", hr);
822
823 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
824 ok(hr == S_OK, "hr %08x\n", hr);
825 ok(pTA->typekind == TKIND_INTERFACE, "kind %04x\n", pTA->typekind);
826 ok(pTA->cbSizeVft == 24, "sizevft %d\n", pTA->cbSizeVft);
827 ok(pTA->wTypeFlags == 0, "typeflags %x\n", pTA->wTypeFlags);
828 if(use_midl_tlb) {
829 ok(pTA->cFuncs == 1, "cfuncs %d\n", pTA->cFuncs);
830 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
831 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
832
833 /* Should have one method */
834 hr = ITypeInfo_GetFuncDesc(pTI, 1, &pFD);
835 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
836 hr = ITypeInfo_GetFuncDesc(pTI, 0, &pFD);
837 ok(hr == S_OK, "hr %08x\n", hr);
838 ok(pFD->memid == 0x60020000, "memid %08x\n", pFD->memid);
839 ok(pFD->oVft == 20, "oVft %d\n", pFD->oVft);
840 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
841 }
842 ITypeInfo_Release(pTI);
843
844 ITypeLib_Release(pTL);
845
846 return;
847 }
848
849 #if 0 /* use this to generate more tests */
850
851 #define OLE_CHECK(x) { HRESULT hr = x; if (FAILED(hr)) { printf(#x "failed - %x\n", hr); return; } }
852
853 static char *dump_string(LPWSTR wstr)
854 {
855 int size = lstrlenW(wstr)+3;
856 char *out = CoTaskMemAlloc(size);
857 WideCharToMultiByte(20127, 0, wstr, -1, out+1, size, NULL, NULL);
858 out[0] = '\"';
859 strcat(out, "\"");
860 return out;
861 }
862
863 struct map_entry
864 {
865 DWORD value;
866 const char *name;
867 };
868
869 #define MAP_ENTRY(x) { x, #x }
870 static const struct map_entry tkind_map[] = {
871 MAP_ENTRY(TKIND_ENUM),
872 MAP_ENTRY(TKIND_RECORD),
873 MAP_ENTRY(TKIND_MODULE),
874 MAP_ENTRY(TKIND_INTERFACE),
875 MAP_ENTRY(TKIND_DISPATCH),
876 MAP_ENTRY(TKIND_COCLASS),
877 MAP_ENTRY(TKIND_ALIAS),
878 MAP_ENTRY(TKIND_UNION),
879 MAP_ENTRY(TKIND_MAX),
880 {0, NULL}
881 };
882
883 static const struct map_entry funckind_map[] = {
884 MAP_ENTRY(FUNC_VIRTUAL),
885 MAP_ENTRY(FUNC_PUREVIRTUAL),
886 MAP_ENTRY(FUNC_NONVIRTUAL),
887 MAP_ENTRY(FUNC_STATIC),
888 MAP_ENTRY(FUNC_DISPATCH),
889 {0, NULL}
890 };
891
892 static const struct map_entry invkind_map[] = {
893 MAP_ENTRY(INVOKE_FUNC),
894 MAP_ENTRY(INVOKE_PROPERTYGET),
895 MAP_ENTRY(INVOKE_PROPERTYPUT),
896 MAP_ENTRY(INVOKE_PROPERTYPUTREF),
897 {0, NULL}
898 };
899
900 #undef MAP_ENTRY
901
902 static const char *map_value(DWORD val, const struct map_entry *map)
903 {
904 static int map_id;
905 static char bufs[16][256];
906 char *buf;
907
908 while (map->name)
909 {
910 if (map->value == val)
911 return map->name;
912 map++;
913 }
914
915 buf = bufs[(map_id++)%16];
916 sprintf(buf, "0x%x", val);
917 return buf;
918 }
919
920 static void test_dump_typelib(const char *name)
921 {
922 WCHAR wszString[260];
923 ITypeInfo *info;
924 ITypeLib *lib;
925 int count;
926 int i;
927
928 MultiByteToWideChar(CP_ACP, 0, name, -1, wszString, 260);
929 OLE_CHECK(LoadTypeLib(wszString, &lib));
930 count = ITypeLib_GetTypeInfoCount(lib);
931 printf("/* interfaces count: %d */\n", count);
932 for (i = 0; i < count; i++)
933 {
934 TYPEATTR *attr;
935 BSTR name;
936 int f = 0;
937
938 OLE_CHECK(ITypeLib_GetDocumentation(lib, i, &name, NULL, NULL, NULL));
939 printf("{\n"
940 " %s,\n", dump_string(name));
941 SysFreeString(name);
942
943 OLE_CHECK(ITypeLib_GetTypeInfo(lib, i, &info));
944 ITypeInfo_GetTypeAttr(info, &attr);
945 printf(" /*kind*/ %s, /*flags*/ 0x%x, /*align*/ %d, /*size*/ %d,\n"
946 " /*#vtbl*/ %d, /*#func*/ %d,\n"
947 " {\n",
948 map_value(attr->typekind, tkind_map), attr->wTypeFlags, attr->cbAlignment, attr->cbSizeInstance, attr->cbSizeVft,
949 attr->cFuncs);
950 ITypeInfo_ReleaseTypeAttr(info, attr);
951 while (1)
952 {
953 FUNCDESC *desc;
954 BSTR tab[256];
955 UINT cNames;
956 int p;
957
958 if (FAILED(ITypeInfo_GetFuncDesc(info, f, &desc)))
959 break;
960 printf(" {\n"
961 " 0x%x, /*func*/ %s, /*inv*/ %s, /*call*/ 0x%x,\n",
962 desc->memid, map_value(desc->funckind, funckind_map), map_value(desc->invkind, invkind_map),
963 desc->callconv);
964 printf(" /*#param*/ %d, /*#opt*/ %d, /*vtbl*/ %d, /*#scodes*/ %d, /*flags*/ 0x%x,\n",
965 desc->cParams, desc->cParamsOpt, desc->oVft, desc->cScodes, desc->wFuncFlags);
966 printf(" {%d, %x}, /* ret */\n", desc->elemdescFunc.tdesc.vt, desc->elemdescFunc.paramdesc.wParamFlags);
967 printf(" { /* params */\n");
968 for (p = 0; p < desc->cParams; p++)
969 {
970 ELEMDESC e = desc->lprgelemdescParam[p];
971 printf(" {%d, %x},\n", e.tdesc.vt, e.paramdesc.wParamFlags);
972 }
973 printf(" {-1, -1}\n");
974 printf(" },\n");
975 printf(" { /* names */\n");
976 OLE_CHECK(ITypeInfo_GetNames(info, desc->memid, tab, 256, &cNames));
977 for (p = 0; p < cNames; p++)
978 {
979 printf(" %s,\n", dump_string(tab[p]));
980 SysFreeString(tab[p]);
981 }
982 printf(" NULL,\n");
983 printf(" },\n");
984 printf(" },\n");
985 ITypeInfo_ReleaseFuncDesc(info, desc);
986 f++;
987 }
988 printf(" }\n");
989 printf("},\n");
990 ITypeInfo_Release(info);
991 }
992 ITypeLib_Release(lib);
993 }
994
995 #else
996
997 typedef struct _element_info
998 {
999 VARTYPE vt;
1000 USHORT wParamFlags;
1001 } element_info;
1002
1003 typedef struct _function_info
1004 {
1005 MEMBERID memid;
1006 FUNCKIND funckind;
1007 INVOKEKIND invkind;
1008 CALLCONV callconv;
1009 short cParams;
1010 short cParamsOpt;
1011 short oVft;
1012 short cScodes;
1013 WORD wFuncFlags;
1014 element_info ret_type;
1015 element_info params[15];
1016 LPCSTR names[15];
1017 } function_info;
1018
1019 typedef struct _interface_info
1020 {
1021 LPCSTR name;
1022 TYPEKIND type;
1023 WORD wTypeFlags;
1024 USHORT cbAlignment;
1025 USHORT cbSizeInstance;
1026 USHORT cbSizeVft;
1027 USHORT cFuncs;
1028 function_info funcs[20];
1029 } interface_info;
1030
1031 static const interface_info info[] = {
1032 /* interfaces count: 2 */
1033 {
1034 "IDualIface",
1035 /*kind*/ TKIND_DISPATCH, /*flags*/ 0x1040, /*align*/ 4, /*size*/ 4,
1036 /*#vtbl*/ 28, /*#func*/ 8,
1037 {
1038 {
1039 0x60000000, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1040 /*#param*/ 2, /*#opt*/ 0, /*vtbl*/ 0, /*#scodes*/ 0, /*flags*/ 0x1,
1041 {24, 0}, /* ret */
1042 { /* params */
1043 {26, 1},
1044 {26, 2},
1045 {-1, -1}
1046 },
1047 { /* names */
1048 "QueryInterface",
1049 "riid",
1050 "ppvObj",
1051 NULL,
1052 },
1053 },
1054 {
1055 0x60000001, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1056 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 4, /*#scodes*/ 0, /*flags*/ 0x1,
1057 {19, 0}, /* ret */
1058 { /* params */
1059 {-1, -1}
1060 },
1061 { /* names */
1062 "AddRef",
1063 NULL,
1064 },
1065 },
1066 {
1067 0x60000002, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1068 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 8, /*#scodes*/ 0, /*flags*/ 0x1,
1069 {19, 0}, /* ret */
1070 { /* params */
1071 {-1, -1}
1072 },
1073 { /* names */
1074 "Release",
1075 NULL,
1076 },
1077 },
1078 {
1079 0x60010000, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1080 /*#param*/ 1, /*#opt*/ 0, /*vtbl*/ 12, /*#scodes*/ 0, /*flags*/ 0x1,
1081 {24, 0}, /* ret */
1082 { /* params */
1083 {26, 2},
1084 {-1, -1}
1085 },
1086 { /* names */
1087 "GetTypeInfoCount",
1088 "pctinfo",
1089 NULL,
1090 },
1091 },
1092 {
1093 0x60010001, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1094 /*#param*/ 3, /*#opt*/ 0, /*vtbl*/ 16, /*#scodes*/ 0, /*flags*/ 0x1,
1095 {24, 0}, /* ret */
1096 { /* params */
1097 {23, 1},
1098 {19, 1},
1099 {26, 2},
1100 {-1, -1}
1101 },
1102 { /* names */
1103 "GetTypeInfo",
1104 "itinfo",
1105 "lcid",
1106 "pptinfo",
1107 NULL,
1108 },
1109 },
1110 {
1111 0x60010002, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1112 /*#param*/ 5, /*#opt*/ 0, /*vtbl*/ 20, /*#scodes*/ 0, /*flags*/ 0x1,
1113 {24, 0}, /* ret */
1114 { /* params */
1115 {26, 1},
1116 {26, 1},
1117 {23, 1},
1118 {19, 1},
1119 {26, 2},
1120 {-1, -1}
1121 },
1122 { /* names */
1123 "GetIDsOfNames",
1124 "riid",
1125 "rgszNames",
1126 "cNames",
1127 "lcid",
1128 "rgdispid",
1129 NULL,
1130 },
1131 },
1132 {
1133 0x60010003, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1134 /*#param*/ 8, /*#opt*/ 0, /*vtbl*/ 24, /*#scodes*/ 0, /*flags*/ 0x1,
1135 {24, 0}, /* ret */
1136 { /* params */
1137 {3, 1},
1138 {26, 1},
1139 {19, 1},
1140 {18, 1},
1141 {26, 1},
1142 {26, 2},
1143 {26, 2},
1144 {26, 2},
1145 {-1, -1}
1146 },
1147 { /* names */
1148 "Invoke",
1149 "dispidMember",
1150 "riid",
1151 "lcid",
1152 "wFlags",
1153 "pdispparams",
1154 "pvarResult",
1155 "pexcepinfo",
1156 "puArgErr",
1157 NULL,
1158 },
1159 },
1160 {
1161 0x60020000, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1162 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 28, /*#scodes*/ 0, /*flags*/ 0x0,
1163 {24, 0}, /* ret */
1164 { /* params */
1165 {-1, -1}
1166 },
1167 { /* names */
1168 "Test",
1169 NULL,
1170 },
1171 },
1172 }
1173 },
1174 {
1175 "ISimpleIface",
1176 /*kind*/ TKIND_INTERFACE, /*flags*/ 0x1000, /*align*/ 4, /*size*/ 4,
1177 /*#vtbl*/ 32, /*#func*/ 1,
1178 {
1179 {
1180 0x60020000, /*func*/ FUNC_PUREVIRTUAL, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1181 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 28, /*#scodes*/ 0, /*flags*/ 0x0,
1182 {25, 0}, /* ret */
1183 { /* params */
1184 {-1, -1}
1185 },
1186 { /* names */
1187 "Test",
1188 NULL,
1189 },
1190 },
1191 }
1192 },
1193 };
1194
1195 #define check_type(elem, info) { \
1196 expect_int((elem)->tdesc.vt, (info)->vt); \
1197 expect_hex(U(*(elem)).paramdesc.wParamFlags, (info)->wParamFlags); \
1198 }
1199
1200 static void test_dump_typelib(const char *name)
1201 {
1202 WCHAR wszName[MAX_PATH];
1203 ITypeLib *typelib;
1204 int ifcount = sizeof(info)/sizeof(info[0]);
1205 int iface, func;
1206
1207 MultiByteToWideChar(CP_UTF8, 0, name, -1, wszName, MAX_PATH);
1208 ole_check(LoadTypeLibEx(wszName, REGKIND_NONE, &typelib));
1209 expect_eq(ITypeLib_GetTypeInfoCount(typelib), ifcount, UINT, "%d");
1210 for (iface = 0; iface < ifcount; iface++)
1211 {
1212 const interface_info *if_info = &info[iface];
1213 ITypeInfo *typeinfo;
1214 TYPEATTR *typeattr;
1215 BSTR bstrIfName;
1216
1217 trace("Interface %s\n", if_info->name);
1218 ole_check(ITypeLib_GetTypeInfo(typelib, iface, &typeinfo));
1219 ole_check(ITypeLib_GetDocumentation(typelib, iface, &bstrIfName, NULL, NULL, NULL));
1220 expect_wstr_utf8val(bstrIfName, if_info->name);
1221 SysFreeString(bstrIfName);
1222
1223 ole_check(ITypeInfo_GetTypeAttr(typeinfo, &typeattr));
1224 expect_int(typeattr->typekind, if_info->type);
1225 expect_hex(typeattr->wTypeFlags, if_info->wTypeFlags);
1226 expect_int(typeattr->cbAlignment, if_info->cbAlignment);
1227 expect_int(typeattr->cbSizeInstance, if_info->cbSizeInstance);
1228 expect_int(typeattr->cbSizeVft, if_info->cbSizeVft);
1229 expect_int(typeattr->cFuncs, if_info->cFuncs);
1230
1231 for (func = 0; func < typeattr->cFuncs; func++)
1232 {
1233 function_info *fn_info = (function_info *)&if_info->funcs[func];
1234 FUNCDESC *desc;
1235 BSTR namesTab[256];
1236 UINT cNames;
1237 int i;
1238
1239 trace("Function %s\n", fn_info->names[0]);
1240 ole_check(ITypeInfo_GetFuncDesc(typeinfo, func, &desc));
1241 expect_int(desc->memid, fn_info->memid);
1242 expect_int(desc->funckind, fn_info->funckind);
1243 expect_int(desc->invkind, fn_info->invkind);
1244 expect_int(desc->callconv, fn_info->callconv);
1245 expect_int(desc->cParams, fn_info->cParams);
1246 expect_int(desc->cParamsOpt, fn_info->cParamsOpt);
1247 expect_int(desc->oVft, fn_info->oVft);
1248 expect_int(desc->cScodes, fn_info->cScodes);
1249 expect_int(desc->wFuncFlags, fn_info->wFuncFlags);
1250 ole_check(ITypeInfo_GetNames(typeinfo, desc->memid, namesTab, 256, &cNames));
1251 for (i = 0; i < cNames; i++)
1252 {
1253 expect_wstr_utf8val(namesTab[i], fn_info->names[i]);
1254 SysFreeString(namesTab[i]);
1255 }
1256 expect_null(fn_info->names[cNames]);
1257
1258 check_type(&desc->elemdescFunc, &fn_info->ret_type);
1259 for (i = 0 ; i < desc->cParams; i++)
1260 {
1261 check_type(&desc->lprgelemdescParam[i], &fn_info->params[i]);
1262 }
1263 expect_int(fn_info->params[desc->cParams].vt, (VARTYPE)-1);
1264
1265 ITypeInfo_ReleaseFuncDesc(typeinfo, desc);
1266 }
1267
1268 ITypeInfo_ReleaseTypeAttr(typeinfo, typeattr);
1269 ITypeInfo_Release(typeinfo);
1270 }
1271 ITypeLib_Release(typelib);
1272 }
1273
1274 #endif
1275
1276 START_TEST(typelib)
1277 {
1278 ref_count_test(wszStdOle2);
1279 test_TypeComp();
1280 test_CreateDispTypeInfo();
1281 test_TypeInfo();
1282 test_QueryPathOfRegTypeLib();
1283 test_inheritance();
1284 test_dump_typelib("test_tlb.tlb");
1285 }