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
23 #define NONAMELESSUNION
24 #define NONAMELESSSTRUCT
26 #include <wine/test.h>
35 #define ok_ole_success(hr, func) ok(hr == S_OK, #func " failed with error 0x%08x\n", hr)
37 static const WCHAR wszStdOle2
[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
39 static void ref_count_test(LPCWSTR type_lib
)
42 ITypeInfo
*iti1
, *iti2
;
46 trace("Loading type library\n");
47 hRes
= LoadTypeLib(type_lib
, &iface
);
48 ok(hRes
== S_OK
, "Could not load type library\n");
52 hRes
= ITypeLib_GetTypeInfo(iface
, 1, &iti1
);
53 ok(hRes
== S_OK
, "ITypeLib_GetTypeInfo failed on index = 1\n");
54 ok(ref_count
=ITypeLib_Release(iface
) > 0, "ITypeLib destroyed while ITypeInfo has back pointer\n");
58 hRes
= ITypeLib_GetTypeInfo(iface
, 1, &iti2
);
59 ok(hRes
== S_OK
, "ITypeLib_GetTypeInfo failed on index = 1\n");
60 ok(iti1
== iti2
, "ITypeLib_GetTypeInfo returned different pointers for same indexes\n");
62 ITypeLib_AddRef(iface
);
63 ITypeInfo_Release(iti2
);
64 ITypeInfo_Release(iti1
);
65 ok(ITypeLib_Release(iface
) == 0, "ITypeLib should be destroyed here.\n");
68 static void test_TypeComp(void)
77 ITypeInfo
*pFontTypeInfo
;
78 static WCHAR wszStdFunctions
[] = {'S','t','d','F','u','n','c','t','i','o','n','s',0};
79 static WCHAR wszSavePicture
[] = {'S','a','v','e','P','i','c','t','u','r','e',0};
80 static WCHAR wszOLE_TRISTATE
[] = {'O','L','E','_','T','R','I','S','T','A','T','E',0};
81 static WCHAR wszUnchecked
[] = {'U','n','c','h','e','c','k','e','d',0};
82 static WCHAR wszIUnknown
[] = {'I','U','n','k','n','o','w','n',0};
83 static WCHAR wszFont
[] = {'F','o','n','t',0};
84 static WCHAR wszGUID
[] = {'G','U','I','D',0};
85 static WCHAR wszStdPicture
[] = {'S','t','d','P','i','c','t','u','r','e',0};
86 static WCHAR wszOLE_COLOR
[] = {'O','L','E','_','C','O','L','O','R',0};
87 static WCHAR wszClone
[] = {'C','l','o','n','e',0};
88 static WCHAR wszclone
[] = {'c','l','o','n','e',0};
90 hr
= LoadTypeLib(wszStdOle2
, &pTypeLib
);
91 ok_ole_success(hr
, LoadTypeLib
);
93 hr
= ITypeLib_GetTypeComp(pTypeLib
, &pTypeComp
);
94 ok_ole_success(hr
, ITypeLib_GetTypeComp
);
96 /* test getting a TKIND_MODULE */
97 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszStdFunctions
);
98 hr
= ITypeComp_Bind(pTypeComp
, wszStdFunctions
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
99 ok_ole_success(hr
, ITypeComp_Bind
);
101 ok(desckind
== DESCKIND_TYPECOMP
,
102 "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
104 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
106 ITypeComp_Release(bindptr
.lptcomp
);
108 /* test getting a TKIND_MODULE with INVOKE_PROPERTYGET */
109 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszStdFunctions
);
110 hr
= ITypeComp_Bind(pTypeComp
, wszStdFunctions
, ulHash
, INVOKE_PROPERTYGET
, &pTypeInfo
, &desckind
, &bindptr
);
111 ok_ole_success(hr
, ITypeComp_Bind
);
113 ok(desckind
== DESCKIND_TYPECOMP
,
114 "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
116 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
118 /* test getting a function within a TKIND_MODULE */
119 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszSavePicture
);
120 hr
= ITypeComp_Bind(pTypeComp
, wszSavePicture
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
121 ok_ole_success(hr
, ITypeComp_Bind
);
123 ok(desckind
== DESCKIND_FUNCDESC
,
124 "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
126 ok(bindptr
.lpfuncdesc
!= NULL
, "bindptr.lpfuncdesc should not have been set to NULL\n");
127 ITypeInfo_ReleaseFuncDesc(pTypeInfo
, bindptr
.lpfuncdesc
);
128 ITypeInfo_Release(pTypeInfo
);
130 /* test getting a function within a TKIND_MODULE with INVOKE_PROPERTYGET */
131 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszSavePicture
);
132 hr
= ITypeComp_Bind(pTypeComp
, wszSavePicture
, ulHash
, INVOKE_PROPERTYGET
, &pTypeInfo
, &desckind
, &bindptr
);
133 todo_wine
ok(hr
== TYPE_E_TYPEMISMATCH
,
134 "ITypeComp_Bind should have failed with TYPE_E_TYPEMISMATCH instead of 0x%08x\n",
137 ok(desckind
== DESCKIND_NONE
,
138 "desckind should have been DESCKIND_NONE instead of %d\n",
140 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
141 ok(!bindptr
.lptcomp
, "bindptr should have been set to NULL\n");
143 /* test getting a TKIND_ENUM */
144 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszOLE_TRISTATE
);
145 hr
= ITypeComp_Bind(pTypeComp
, wszOLE_TRISTATE
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
146 ok_ole_success(hr
, ITypeComp_Bind
);
148 ok(desckind
== DESCKIND_TYPECOMP
,
149 "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
151 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
153 ITypeComp_Release(bindptr
.lptcomp
);
155 /* test getting a value within a TKIND_ENUM */
156 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszUnchecked
);
157 hr
= ITypeComp_Bind(pTypeComp
, wszUnchecked
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
158 ok_ole_success(hr
, ITypeComp_Bind
);
160 ok(desckind
== DESCKIND_VARDESC
,
161 "desckind should have been DESCKIND_VARDESC instead of %d\n",
163 ITypeInfo_ReleaseVarDesc(pTypeInfo
, bindptr
.lpvardesc
);
164 ITypeInfo_Release(pTypeInfo
);
166 /* test getting a TKIND_INTERFACE */
167 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszIUnknown
);
168 hr
= ITypeComp_Bind(pTypeComp
, wszIUnknown
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
169 ok_ole_success(hr
, ITypeComp_Bind
);
171 ok(desckind
== DESCKIND_NONE
,
172 "desckind should have been DESCKIND_NONE instead of %d\n",
174 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
175 ok(!bindptr
.lptcomp
, "bindptr should have been set to NULL\n");
177 /* test getting a TKIND_DISPATCH */
178 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszFont
);
179 hr
= ITypeComp_Bind(pTypeComp
, wszFont
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
180 ok_ole_success(hr
, ITypeComp_Bind
);
182 ok(desckind
== DESCKIND_NONE
,
183 "desckind should have been DESCKIND_NONE instead of %d\n",
185 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
186 ok(!bindptr
.lptcomp
, "bindptr should have been set to NULL\n");
188 /* test getting a TKIND_RECORD/TKIND_ALIAS */
189 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszGUID
);
190 hr
= ITypeComp_Bind(pTypeComp
, wszGUID
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
191 ok_ole_success(hr
, ITypeComp_Bind
);
193 ok(desckind
== DESCKIND_NONE
,
194 "desckind should have been DESCKIND_NONE instead of %d\n",
196 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
197 ok(!bindptr
.lptcomp
, "bindptr should have been set to NULL\n");
199 /* test getting a TKIND_ALIAS */
200 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszOLE_COLOR
);
201 hr
= ITypeComp_Bind(pTypeComp
, wszOLE_COLOR
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
202 ok_ole_success(hr
, ITypeComp_Bind
);
204 ok(desckind
== DESCKIND_NONE
,
205 "desckind should have been DESCKIND_NONE instead of %d\n",
207 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
208 ok(!bindptr
.lptcomp
, "bindptr should have been set to NULL\n");
210 /* test getting a TKIND_COCLASS */
211 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszStdPicture
);
212 hr
= ITypeComp_Bind(pTypeComp
, wszStdPicture
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
213 ok_ole_success(hr
, ITypeComp_Bind
);
215 ok(desckind
== DESCKIND_NONE
,
216 "desckind should have been DESCKIND_NONE instead of %d\n",
218 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
219 ok(!bindptr
.lptcomp
, "bindptr should have been set to NULL\n");
221 ITypeComp_Release(pTypeComp
);
223 /* tests for ITypeComp on an interface */
224 hr
= ITypeLib_GetTypeInfoOfGuid(pTypeLib
, &IID_IFont
, &pFontTypeInfo
);
225 ok_ole_success(hr
, ITypeLib_GetTypeInfoOfGuid
);
227 hr
= ITypeInfo_GetTypeComp(pFontTypeInfo
, &pTypeComp
);
228 ok_ole_success(hr
, ITypeLib_GetTypeComp
);
230 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszClone
);
231 hr
= ITypeComp_Bind(pTypeComp
, wszClone
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
232 ok_ole_success(hr
, ITypeComp_Bind
);
234 ok(desckind
== DESCKIND_FUNCDESC
,
235 "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
237 ok(bindptr
.lpfuncdesc
!= NULL
, "bindptr.lpfuncdesc should not have been set to NULL\n");
238 ITypeInfo_ReleaseFuncDesc(pTypeInfo
, bindptr
.lpfuncdesc
);
239 ITypeInfo_Release(pTypeInfo
);
241 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszClone
);
242 hr
= ITypeComp_Bind(pTypeComp
, wszClone
, ulHash
, INVOKE_PROPERTYGET
, &pTypeInfo
, &desckind
, &bindptr
);
243 ok(hr
== TYPE_E_TYPEMISMATCH
, "ITypeComp_Bind should have failed with TYPE_E_TYPEMISMATCH instead of 0x%08x\n", hr
);
245 ok(desckind
== DESCKIND_NONE
,
246 "desckind should have been DESCKIND_NONE instead of %d\n",
248 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
249 ok(!bindptr
.lptcomp
, "bindptr should have been set to NULL\n");
251 /* tests that the compare is case-insensitive */
252 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszclone
);
253 hr
= ITypeComp_Bind(pTypeComp
, wszclone
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
254 ok_ole_success(hr
, ITypeComp_Bind
);
256 ok(desckind
== DESCKIND_FUNCDESC
,
257 "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
259 ok(bindptr
.lpfuncdesc
!= NULL
, "bindptr.lpfuncdesc should not have been set to NULL\n");
260 ITypeInfo_ReleaseFuncDesc(pTypeInfo
, bindptr
.lpfuncdesc
);
261 ITypeInfo_Release(pTypeInfo
);
263 ITypeComp_Release(pTypeComp
);
264 ITypeInfo_Release(pFontTypeInfo
);
265 ITypeLib_Release(pTypeLib
);
268 static void test_CreateDispTypeInfo(void)
270 ITypeInfo
*pTypeInfo
, *pTI2
;
272 INTERFACEDATA ifdata
;
273 METHODDATA methdata
[4];
281 static const WCHAR func1
[] = {'f','u','n','c','1',0};
282 static const WCHAR func2
[] = {'f','u','n','c','2',0};
283 static const WCHAR func3
[] = {'f','u','n','c','3',0};
284 static const WCHAR parm1
[] = {'p','a','r','m','1',0};
285 static const WCHAR parm2
[] = {'p','a','r','m','2',0};
286 OLECHAR
*name
= (OLECHAR
*)func1
;
288 ifdata
.pmethdata
= methdata
;
289 ifdata
.cMembers
= sizeof(methdata
) / sizeof(methdata
[0]);
291 methdata
[0].szName
= SysAllocString(func1
);
292 methdata
[0].ppdata
= parms1
;
293 methdata
[0].dispid
= 0x123;
294 methdata
[0].iMeth
= 0;
295 methdata
[0].cc
= CC_STDCALL
;
296 methdata
[0].cArgs
= 2;
297 methdata
[0].wFlags
= DISPATCH_METHOD
;
298 methdata
[0].vtReturn
= VT_HRESULT
;
299 parms1
[0].szName
= SysAllocString(parm1
);
300 parms1
[0].vt
= VT_I4
;
301 parms1
[1].szName
= SysAllocString(parm2
);
302 parms1
[1].vt
= VT_BSTR
;
304 methdata
[1].szName
= SysAllocString(func2
);
305 methdata
[1].ppdata
= NULL
;
306 methdata
[1].dispid
= 0x124;
307 methdata
[1].iMeth
= 1;
308 methdata
[1].cc
= CC_STDCALL
;
309 methdata
[1].cArgs
= 0;
310 methdata
[1].wFlags
= DISPATCH_PROPERTYGET
;
311 methdata
[1].vtReturn
= VT_I4
;
313 methdata
[2].szName
= SysAllocString(func3
);
314 methdata
[2].ppdata
= parms3
;
315 methdata
[2].dispid
= 0x125;
316 methdata
[2].iMeth
= 3;
317 methdata
[2].cc
= CC_STDCALL
;
318 methdata
[2].cArgs
= 1;
319 methdata
[2].wFlags
= DISPATCH_PROPERTYPUT
;
320 methdata
[2].vtReturn
= VT_HRESULT
;
321 parms3
[0].szName
= SysAllocString(parm1
);
322 parms3
[0].vt
= VT_I4
;
324 methdata
[3].szName
= SysAllocString(func3
);
325 methdata
[3].ppdata
= NULL
;
326 methdata
[3].dispid
= 0x125;
327 methdata
[3].iMeth
= 4;
328 methdata
[3].cc
= CC_STDCALL
;
329 methdata
[3].cArgs
= 0;
330 methdata
[3].wFlags
= DISPATCH_PROPERTYGET
;
331 methdata
[3].vtReturn
= VT_I4
;
333 hr
= CreateDispTypeInfo(&ifdata
, LOCALE_NEUTRAL
, &pTypeInfo
);
334 ok(hr
== S_OK
, "hr %08x\n", hr
);
336 hr
= ITypeInfo_GetTypeAttr(pTypeInfo
, &pTypeAttr
);
337 ok(hr
== S_OK
, "hr %08x\n", hr
);
339 ok(pTypeAttr
->typekind
== TKIND_COCLASS
, "typekind %0x\n", pTypeAttr
->typekind
);
340 ok(pTypeAttr
->cImplTypes
== 1, "cImplTypes %d\n", pTypeAttr
->cImplTypes
);
341 ok(pTypeAttr
->cFuncs
== 0, "cFuncs %d\n", pTypeAttr
->cFuncs
);
342 ok(pTypeAttr
->wTypeFlags
== 0, "wTypeFlags %04x\n", pTypeAttr
->cFuncs
);
343 ITypeInfo_ReleaseTypeAttr(pTypeInfo
, pTypeAttr
);
345 hr
= ITypeInfo_GetRefTypeOfImplType(pTypeInfo
, 0, &href
);
346 ok(hr
== S_OK
, "hr %08x\n", hr
);
348 ok(href
== 0, "href = 0x%x\n", href
);
350 hr
= ITypeInfo_GetRefTypeInfo(pTypeInfo
, href
, &pTI2
);
351 ok(hr
== S_OK
, "hr %08x\n", hr
);
352 hr
= ITypeInfo_GetTypeAttr(pTI2
, &pTypeAttr
);
353 ok(hr
== S_OK
, "hr %08x\n", hr
);
354 ok(pTypeAttr
->typekind
== TKIND_INTERFACE
, "typekind %0x\n", pTypeAttr
->typekind
);
355 ITypeInfo_ReleaseTypeAttr(pTI2
, pTypeAttr
);
357 hr
= ITypeInfo_GetFuncDesc(pTI2
, 0, &pFuncDesc
);
358 ok(hr
== S_OK
, "hr %08x\n", hr
);
359 ok(pFuncDesc
->funckind
== FUNC_VIRTUAL
, "funckind %d\n", pFuncDesc
->funckind
);
360 ok(pFuncDesc
->invkind
== methdata
[0].wFlags
, "invkind %d\n", pFuncDesc
->invkind
);
361 ok(pFuncDesc
->callconv
== methdata
[0].cc
, "callconv %d\n", pFuncDesc
->callconv
);
362 ok(pFuncDesc
->cParams
== methdata
[0].cArgs
, "cParams %d\n", pFuncDesc
->cParams
);
363 ok(pFuncDesc
->oVft
== 0, "oVft %d\n", pFuncDesc
->oVft
);
364 ok(pFuncDesc
->wFuncFlags
== 0, "oVft %d\n", pFuncDesc
->wFuncFlags
);
365 ok(pFuncDesc
->elemdescFunc
.tdesc
.vt
== VT_HRESULT
, "ret vt %x\n", pFuncDesc
->elemdescFunc
.tdesc
.vt
);
366 ok(pFuncDesc
->lprgelemdescParam
[0].tdesc
.vt
== VT_I4
, "parm 0 vt %x\n", pFuncDesc
->lprgelemdescParam
[0].tdesc
.vt
);
367 ok(pFuncDesc
->lprgelemdescParam
[0].u
.paramdesc
.wParamFlags
== PARAMFLAG_NONE
, "parm 0 flags %x\n", pFuncDesc
->lprgelemdescParam
[0].u
.paramdesc
.wParamFlags
);
369 ok(pFuncDesc
->lprgelemdescParam
[1].tdesc
.vt
== VT_BSTR
, "parm 1 vt %x\n", pFuncDesc
->lprgelemdescParam
[1].tdesc
.vt
);
370 ok(pFuncDesc
->lprgelemdescParam
[1].u
.paramdesc
.wParamFlags
== PARAMFLAG_NONE
, "parm 1 flags %x\n", pFuncDesc
->lprgelemdescParam
[1].u
.paramdesc
.wParamFlags
);
371 ITypeInfo_ReleaseFuncDesc(pTI2
, pFuncDesc
);
373 hr
= ITypeInfo_GetFuncDesc(pTI2
, 1, &pFuncDesc
);
374 ok(hr
== S_OK
, "hr %08x\n", hr
);
375 ok(pFuncDesc
->funckind
== FUNC_VIRTUAL
, "funckind %d\n", pFuncDesc
->funckind
);
376 ok(pFuncDesc
->invkind
== methdata
[1].wFlags
, "invkind %d\n", pFuncDesc
->invkind
);
377 ok(pFuncDesc
->callconv
== methdata
[1].cc
, "callconv %d\n", pFuncDesc
->callconv
);
378 ok(pFuncDesc
->cParams
== methdata
[1].cArgs
, "cParams %d\n", pFuncDesc
->cParams
);
379 ok(pFuncDesc
->oVft
== 4, "oVft %d\n", pFuncDesc
->oVft
);
380 ok(pFuncDesc
->wFuncFlags
== 0, "oVft %d\n", pFuncDesc
->wFuncFlags
);
381 ok(pFuncDesc
->elemdescFunc
.tdesc
.vt
== VT_I4
, "ret vt %x\n", pFuncDesc
->elemdescFunc
.tdesc
.vt
);
382 ITypeInfo_ReleaseFuncDesc(pTI2
, pFuncDesc
);
384 hr
= ITypeInfo_GetFuncDesc(pTI2
, 2, &pFuncDesc
);
385 ok(hr
== S_OK
, "hr %08x\n", hr
);
386 ok(pFuncDesc
->funckind
== FUNC_VIRTUAL
, "funckind %d\n", pFuncDesc
->funckind
);
387 ok(pFuncDesc
->invkind
== methdata
[2].wFlags
, "invkind %d\n", pFuncDesc
->invkind
);
388 ok(pFuncDesc
->callconv
== methdata
[2].cc
, "callconv %d\n", pFuncDesc
->callconv
);
389 ok(pFuncDesc
->cParams
== methdata
[2].cArgs
, "cParams %d\n", pFuncDesc
->cParams
);
390 ok(pFuncDesc
->oVft
== 12, "oVft %d\n", pFuncDesc
->oVft
);
391 ok(pFuncDesc
->wFuncFlags
== 0, "oVft %d\n", pFuncDesc
->wFuncFlags
);
392 ok(pFuncDesc
->elemdescFunc
.tdesc
.vt
== VT_HRESULT
, "ret vt %x\n", pFuncDesc
->elemdescFunc
.tdesc
.vt
);
393 ok(pFuncDesc
->lprgelemdescParam
[0].tdesc
.vt
== VT_I4
, "parm 0 vt %x\n", pFuncDesc
->lprgelemdescParam
[0].tdesc
.vt
);
394 ok(pFuncDesc
->lprgelemdescParam
[0].u
.paramdesc
.wParamFlags
== PARAMFLAG_NONE
, "parm 0 flags %x\n", pFuncDesc
->lprgelemdescParam
[0].u
.paramdesc
.wParamFlags
);
395 ITypeInfo_ReleaseFuncDesc(pTI2
, pFuncDesc
);
397 hr
= ITypeInfo_GetFuncDesc(pTI2
, 3, &pFuncDesc
);
398 ok(hr
== S_OK
, "hr %08x\n", hr
);
399 ok(pFuncDesc
->funckind
== FUNC_VIRTUAL
, "funckind %d\n", pFuncDesc
->funckind
);
400 ok(pFuncDesc
->invkind
== methdata
[3].wFlags
, "invkind %d\n", pFuncDesc
->invkind
);
401 ok(pFuncDesc
->callconv
== methdata
[3].cc
, "callconv %d\n", pFuncDesc
->callconv
);
402 ok(pFuncDesc
->cParams
== methdata
[3].cArgs
, "cParams %d\n", pFuncDesc
->cParams
);
403 ok(pFuncDesc
->oVft
== 16, "oVft %d\n", pFuncDesc
->oVft
);
404 ok(pFuncDesc
->wFuncFlags
== 0, "oVft %d\n", pFuncDesc
->wFuncFlags
);
405 ok(pFuncDesc
->elemdescFunc
.tdesc
.vt
== VT_I4
, "ret vt %x\n", pFuncDesc
->elemdescFunc
.tdesc
.vt
);
406 ITypeInfo_ReleaseFuncDesc(pTI2
, pFuncDesc
);
408 /* test GetIDsOfNames on a coclass to see if it searches its interfaces */
409 hr
= ITypeInfo_GetIDsOfNames(pTypeInfo
, &name
, 1, &memid
);
410 ok(hr
== S_OK
, "hr 0x%08x\n", hr
);
411 ok(memid
== 0x123, "memid 0x%08x\n", memid
);
413 ITypeInfo_Release(pTI2
);
414 ITypeInfo_Release(pTypeInfo
);
416 SysFreeString(parms1
[0].szName
);
417 SysFreeString(parms1
[1].szName
);
418 SysFreeString(parms3
[0].szName
);
419 SysFreeString(methdata
[0].szName
);
420 SysFreeString(methdata
[1].szName
);
421 SysFreeString(methdata
[2].szName
);
422 SysFreeString(methdata
[3].szName
);
425 static void test_TypeInfo(void)
428 ITypeInfo
*pTypeInfo
;
430 static WCHAR wszBogus
[] = { 'b','o','g','u','s',0 };
431 static WCHAR wszGetTypeInfo
[] = { 'G','e','t','T','y','p','e','I','n','f','o',0 };
432 static WCHAR wszClone
[] = {'C','l','o','n','e',0};
433 OLECHAR
* bogus
= wszBogus
;
434 OLECHAR
* pwszGetTypeInfo
= wszGetTypeInfo
;
435 OLECHAR
* pwszClone
= wszClone
;
437 DISPPARAMS dispparams
;
439 hr
= LoadTypeLib(wszStdOle2
, &pTypeLib
);
440 ok_ole_success(hr
, LoadTypeLib
);
442 hr
= ITypeLib_GetTypeInfoOfGuid(pTypeLib
, &IID_IFont
, &pTypeInfo
);
443 ok_ole_success(hr
, ITypeLib_GetTypeInfoOfGuid
);
445 /* test nonexistent method name */
446 hr
= ITypeInfo_GetIDsOfNames(pTypeInfo
, &bogus
, 1, &dispidMember
);
447 ok(hr
== DISP_E_UNKNOWNNAME
,
448 "ITypeInfo_GetIDsOfNames should have returned DISP_E_UNKNOWNNAME instead of 0x%08x\n",
451 /* test invalid memberid */
452 dispparams
.cNamedArgs
= 0;
453 dispparams
.cArgs
= 0;
454 dispparams
.rgdispidNamedArgs
= NULL
;
455 dispparams
.rgvarg
= NULL
;
456 hr
= ITypeInfo_Invoke(pTypeInfo
, (void *)0xdeadbeef, 0xdeadbeef, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
457 ok(hr
== DISP_E_MEMBERNOTFOUND
, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr
);
459 hr
= ITypeInfo_GetIDsOfNames(pTypeInfo
, &pwszClone
, 1, &dispidMember
);
460 ok_ole_success(hr
, ITypeInfo_GetIDsOfNames
);
462 /* test correct memberid, but wrong flags */
463 hr
= ITypeInfo_Invoke(pTypeInfo
, (void *)0xdeadbeef, dispidMember
, DISPATCH_PROPERTYGET
, &dispparams
, NULL
, NULL
, NULL
);
464 ok(hr
== DISP_E_MEMBERNOTFOUND
, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr
);
466 /* test NULL dispparams */
467 hr
= ITypeInfo_Invoke(pTypeInfo
, (void *)0xdeadbeef, dispidMember
, DISPATCH_METHOD
, NULL
, NULL
, NULL
, NULL
);
468 ok(hr
== E_INVALIDARG
, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
470 /* test dispparams->cNamedArgs being bigger than dispparams->cArgs */
471 dispparams
.cNamedArgs
= 1;
472 hr
= ITypeInfo_Invoke(pTypeInfo
, (void *)0xdeadbeef, dispidMember
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
473 ok(hr
== E_INVALIDARG
, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
475 ITypeInfo_Release(pTypeInfo
);
477 hr
= ITypeLib_GetTypeInfoOfGuid(pTypeLib
, &IID_IDispatch
, &pTypeInfo
);
478 ok_ole_success(hr
, ITypeLib_GetTypeInfoOfGuid
);
480 hr
= ITypeInfo_GetIDsOfNames(pTypeInfo
, &pwszGetTypeInfo
, 1, &dispidMember
);
481 ok_ole_success(hr
, ITypeInfo_GetIDsOfNames
);
483 /* test invoking a method with a [restricted] keyword */
484 hr
= ITypeInfo_Invoke(pTypeInfo
, NULL
, dispidMember
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
486 ok(hr
== DISP_E_MEMBERNOTFOUND
, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr
);
489 ITypeInfo_Release(pTypeInfo
);
490 ITypeLib_Release(pTypeLib
);
493 static BOOL
do_typelib_reg_key(GUID
*uid
, WORD maj
, WORD min
, LPCWSTR base
, BOOL remove
)
495 static const WCHAR typelibW
[] = {'T','y','p','e','l','i','b','\\',0};
496 static const WCHAR formatW
[] = {'\\','%','u','.','%','u','\\','0','\\','w','i','n','3','2',0};
497 static const WCHAR format2W
[] = {'%','s','_','%','u','_','%','u','.','d','l','l',0};
502 memcpy(buf
, typelibW
, sizeof(typelibW
));
503 StringFromGUID2(uid
, buf
+ lstrlenW(buf
), 40);
508 ok(SHDeleteKeyW(HKEY_CLASSES_ROOT
, buf
) == ERROR_SUCCESS
, "SHDeleteKey failed\n");
513 wsprintfW(buf
+ lstrlenW(buf
), formatW
, maj
, min
);
515 if (RegCreateKeyExW(HKEY_CLASSES_ROOT
, buf
, 0, NULL
, 0,
516 KEY_WRITE
, NULL
, &hkey
, NULL
) != ERROR_SUCCESS
)
518 trace("RegCreateKeyExW failed\n");
522 wsprintfW(buf
, format2W
, base
, maj
, min
);
523 if (RegSetValueExW(hkey
, NULL
, 0, REG_SZ
,
524 (BYTE
*)buf
, (lstrlenW(buf
) + 1) * sizeof(WCHAR
)) != ERROR_SUCCESS
)
526 trace("RegSetValueExW failed\n");
533 static void test_QueryPathOfRegTypeLib(void)
535 static const struct test_data
539 const WCHAR path
[16];
541 { 1, 0, TYPE_E_LIBNOTREGISTERED
, { 0 } },
542 { 3, 0, S_OK
, {'f','a','k','e','_','3','_','0','.','d','l','l',0 } },
543 { 3, 1, S_OK
, {'f','a','k','e','_','3','_','1','.','d','l','l',0 } },
544 #if 0 /* todo: enable once properly implemented */
545 { 3, 22, S_OK
, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
547 { 3, 37, S_OK
, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
548 #if 0 /* todo: enable once properly implemented */
549 { 3, 40, S_OK
, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
551 { 4, 0, TYPE_E_LIBNOTREGISTERED
, { 0 } }
553 static const WCHAR base
[] = {'f','a','k','e',0};
561 status
= UuidCreate(&uid
);
562 ok(!status
, "UuidCreate error %08lx\n", status
);
564 StringFromGUID2(&uid
, uid_str
, 40);
565 /*trace("GUID: %s\n", wine_dbgstr_w(uid_str));*/
567 if (!do_typelib_reg_key(&uid
, 3, 0, base
, 0)) return;
568 if (!do_typelib_reg_key(&uid
, 3, 1, base
, 0)) return;
569 if (!do_typelib_reg_key(&uid
, 3, 37, base
, 0)) return;
571 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++)
573 ret
= QueryPathOfRegTypeLib(&uid
, td
[i
].maj
, td
[i
].min
, 0, &path
);
574 ok(ret
== td
[i
].ret
, "QueryPathOfRegTypeLib(%u.%u) returned %08x\n", td
[i
].maj
, td
[i
].min
, ret
);
577 ok(!lstrcmpW(td
[i
].path
, path
), "typelib %u.%u path doesn't match\n", td
[i
].maj
, td
[i
].min
);
582 do_typelib_reg_key(&uid
, 0, 0, NULL
, 1);
587 ref_count_test(wszStdOle2
);
589 test_CreateDispTypeInfo();
591 test_QueryPathOfRegTypeLib();