/* * ITypeLib and ITypeInfo test * * Copyright 2004 Jacek Caban * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #define COBJMACROS #define NONAMELESSUNION #define NONAMELESSSTRUCT #include #include #include "windef.h" #include "winbase.h" #include "oleauto.h" #define ok_ole_success(hr, func) ok(hr == S_OK, #func " failed with error 0x%08lx\n", hr) static const WCHAR wszStdOle2[] = {'s','t','d','o','l','e','2','.','t','l','b',0}; static void ref_count_test(LPCWSTR type_lib) { ITypeLib *iface; ITypeInfo *iti1, *iti2; HRESULT hRes; int ref_count; trace("Loading type library\n"); hRes = LoadTypeLib(type_lib, &iface); ok(hRes == S_OK, "Could not load type library\n"); if(hRes != S_OK) return; hRes = ITypeLib_GetTypeInfo(iface, 1, &iti1); ok(hRes == S_OK, "ITypeLib_GetTypeInfo failed on index = 1\n"); ok(ref_count=ITypeLib_Release(iface) > 0, "ITypeLib destroyed while ITypeInfo has back pointer\n"); if(!ref_count) return; hRes = ITypeLib_GetTypeInfo(iface, 1, &iti2); ok(hRes == S_OK, "ITypeLib_GetTypeInfo failed on index = 1\n"); ok(iti1 == iti2, "ITypeLib_GetTypeInfo returned different pointers for same indexes\n"); ITypeLib_AddRef(iface); ITypeInfo_Release(iti2); ITypeInfo_Release(iti1); ok(ITypeLib_Release(iface) == 0, "ITypeLib should be destroyed here.\n"); } static void test_TypeComp(void) { ITypeLib *pTypeLib; ITypeComp *pTypeComp; HRESULT hr; ULONG ulHash; DESCKIND desckind; BINDPTR bindptr; ITypeInfo *pTypeInfo; static WCHAR wszStdFunctions[] = {'S','t','d','F','u','n','c','t','i','o','n','s',0}; static WCHAR wszSavePicture[] = {'S','a','v','e','P','i','c','t','u','r','e',0}; static WCHAR wszOLE_TRISTATE[] = {'O','L','E','_','T','R','I','S','T','A','T','E',0}; static WCHAR wszUnchecked[] = {'U','n','c','h','e','c','k','e','d',0}; static WCHAR wszIUnknown[] = {'I','U','n','k','n','o','w','n',0}; static WCHAR wszFont[] = {'F','o','n','t',0}; static WCHAR wszGUID[] = {'G','U','I','D',0}; static WCHAR wszStdPicture[] = {'S','t','d','P','i','c','t','u','r','e',0}; static WCHAR wszOLE_COLOR[] = {'O','L','E','_','C','O','L','O','R',0}; hr = LoadTypeLib(wszStdOle2, &pTypeLib); ok_ole_success(hr, LoadTypeLib); hr = ITypeLib_GetTypeComp(pTypeLib, &pTypeComp); ok_ole_success(hr, ITypeLib_GetTypeComp); /* test getting a TKIND_MODULE */ ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszStdFunctions); hr = ITypeComp_Bind(pTypeComp, wszStdFunctions, ulHash, 0, &pTypeInfo, &desckind, &bindptr); ok_ole_success(hr, ITypeComp_Bind); ok(desckind == DESCKIND_TYPECOMP, "desckind should have been DESCKIND_TYPECOMP instead of %d\n", desckind); ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n"); ITypeComp_Release(bindptr.lptcomp); /* test getting a TKIND_MODULE with INVOKE_PROPERTYGET */ ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszStdFunctions); hr = ITypeComp_Bind(pTypeComp, wszStdFunctions, ulHash, INVOKE_PROPERTYGET, &pTypeInfo, &desckind, &bindptr); ok_ole_success(hr, ITypeComp_Bind); ok(desckind == DESCKIND_TYPECOMP, "desckind should have been DESCKIND_TYPECOMP instead of %d\n", desckind); ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n"); /* test getting a function within a TKIND_MODULE */ ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszSavePicture); hr = ITypeComp_Bind(pTypeComp, wszSavePicture, ulHash, 0, &pTypeInfo, &desckind, &bindptr); ok_ole_success(hr, ITypeComp_Bind); ok(desckind == DESCKIND_FUNCDESC, "desckind should have been DESCKIND_FUNCDESC instead of %d\n", desckind); ok(bindptr.lpfuncdesc != NULL, "bindptr.lpfuncdesc should not have been set to NULL\n"); ITypeInfo_ReleaseFuncDesc(pTypeInfo, bindptr.lpfuncdesc); ITypeInfo_Release(pTypeInfo); /* test getting a function within a TKIND_MODULE with INVOKE_PROPERTYGET */ ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszSavePicture); hr = ITypeComp_Bind(pTypeComp, wszSavePicture, ulHash, INVOKE_PROPERTYGET, &pTypeInfo, &desckind, &bindptr); todo_wine ok(hr == TYPE_E_TYPEMISMATCH, "ITypeComp_Bind should have failed with TYPE_E_TYPEMISMATCH instead of 0x%08lx\n", hr); ok(desckind == DESCKIND_NONE, "desckind should have been DESCKIND_NONE instead of %d\n", desckind); ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n"); ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n"); /* test getting a TKIND_ENUM */ ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszOLE_TRISTATE); hr = ITypeComp_Bind(pTypeComp, wszOLE_TRISTATE, ulHash, 0, &pTypeInfo, &desckind, &bindptr); ok_ole_success(hr, ITypeComp_Bind); ok(desckind == DESCKIND_TYPECOMP, "desckind should have been DESCKIND_TYPECOMP instead of %d\n", desckind); ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n"); ITypeComp_Release(bindptr.lptcomp); /* test getting a value within a TKIND_ENUM */ ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszUnchecked); hr = ITypeComp_Bind(pTypeComp, wszUnchecked, ulHash, 0, &pTypeInfo, &desckind, &bindptr); ok_ole_success(hr, ITypeComp_Bind); ok(desckind == DESCKIND_VARDESC, "desckind should have been DESCKIND_VARDESC instead of %d\n", desckind); ITypeInfo_ReleaseVarDesc(pTypeInfo, bindptr.lpvardesc); ITypeInfo_Release(pTypeInfo); /* test getting a TKIND_INTERFACE */ ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszIUnknown); hr = ITypeComp_Bind(pTypeComp, wszIUnknown, ulHash, 0, &pTypeInfo, &desckind, &bindptr); ok_ole_success(hr, ITypeComp_Bind); ok(desckind == DESCKIND_NONE, "desckind should have been DESCKIND_NONE instead of %d\n", desckind); ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n"); ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n"); /* test getting a TKIND_DISPATCH */ ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszFont); hr = ITypeComp_Bind(pTypeComp, wszFont, ulHash, 0, &pTypeInfo, &desckind, &bindptr); ok_ole_success(hr, ITypeComp_Bind); ok(desckind == DESCKIND_NONE, "desckind should have been DESCKIND_NONE instead of %d\n", desckind); ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n"); ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n"); /* test getting a TKIND_RECORD/TKIND_ALIAS */ ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszGUID); hr = ITypeComp_Bind(pTypeComp, wszGUID, ulHash, 0, &pTypeInfo, &desckind, &bindptr); ok_ole_success(hr, ITypeComp_Bind); ok(desckind == DESCKIND_NONE, "desckind should have been DESCKIND_NONE instead of %d\n", desckind); ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n"); ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n"); /* test getting a TKIND_ALIAS */ ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszOLE_COLOR); hr = ITypeComp_Bind(pTypeComp, wszOLE_COLOR, ulHash, 0, &pTypeInfo, &desckind, &bindptr); ok_ole_success(hr, ITypeComp_Bind); ok(desckind == DESCKIND_NONE, "desckind should have been DESCKIND_NONE instead of %d\n", desckind); ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n"); ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n"); /* test getting a TKIND_COCLASS */ ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszStdPicture); hr = ITypeComp_Bind(pTypeComp, wszStdPicture, ulHash, 0, &pTypeInfo, &desckind, &bindptr); ok_ole_success(hr, ITypeComp_Bind); ok(desckind == DESCKIND_NONE, "desckind should have been DESCKIND_NONE instead of %d\n", desckind); ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n"); ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n"); ITypeComp_Release(pTypeComp); ITypeLib_Release(pTypeLib); } static void test_CreateDispTypeInfo(void) { ITypeInfo *pTypeInfo, *pTI2; HRESULT hr; INTERFACEDATA ifdata; METHODDATA methdata[4]; PARAMDATA parms1[2]; PARAMDATA parms3[1]; TYPEATTR *pTypeAttr; HREFTYPE href; FUNCDESC *pFuncDesc; MEMBERID memid; static const WCHAR func1[] = {'f','u','n','c','1',0}; static const WCHAR func2[] = {'f','u','n','c','2',0}; static const WCHAR func3[] = {'f','u','n','c','3',0}; static const WCHAR parm1[] = {'p','a','r','m','1',0}; static const WCHAR parm2[] = {'p','a','r','m','2',0}; OLECHAR *name = (OLECHAR *)func1; ifdata.pmethdata = methdata; ifdata.cMembers = sizeof(methdata) / sizeof(methdata[0]); methdata[0].szName = SysAllocString(func1); methdata[0].ppdata = parms1; methdata[0].dispid = 0x123; methdata[0].iMeth = 0; methdata[0].cc = CC_STDCALL; methdata[0].cArgs = 2; methdata[0].wFlags = DISPATCH_METHOD; methdata[0].vtReturn = VT_HRESULT; parms1[0].szName = SysAllocString(parm1); parms1[0].vt = VT_I4; parms1[1].szName = SysAllocString(parm2); parms1[1].vt = VT_BSTR; methdata[1].szName = SysAllocString(func2); methdata[1].ppdata = NULL; methdata[1].dispid = 0x124; methdata[1].iMeth = 1; methdata[1].cc = CC_STDCALL; methdata[1].cArgs = 0; methdata[1].wFlags = DISPATCH_PROPERTYGET; methdata[1].vtReturn = VT_I4; methdata[2].szName = SysAllocString(func3); methdata[2].ppdata = parms3; methdata[2].dispid = 0x125; methdata[2].iMeth = 3; methdata[2].cc = CC_STDCALL; methdata[2].cArgs = 1; methdata[2].wFlags = DISPATCH_PROPERTYPUT; methdata[2].vtReturn = VT_HRESULT; parms3[0].szName = SysAllocString(parm1); parms3[0].vt = VT_I4; methdata[3].szName = SysAllocString(func3); methdata[3].ppdata = NULL; methdata[3].dispid = 0x125; methdata[3].iMeth = 4; methdata[3].cc = CC_STDCALL; methdata[3].cArgs = 0; methdata[3].wFlags = DISPATCH_PROPERTYGET; methdata[3].vtReturn = VT_I4; hr = CreateDispTypeInfo(&ifdata, LOCALE_NEUTRAL, &pTypeInfo); ok(hr == S_OK, "hr %08lx\n", hr); hr = ITypeInfo_GetTypeAttr(pTypeInfo, &pTypeAttr); ok(hr == S_OK, "hr %08lx\n", hr); ok(pTypeAttr->typekind == TKIND_COCLASS, "typekind %0x\n", pTypeAttr->typekind); ok(pTypeAttr->cImplTypes == 1, "cImplTypes %d\n", pTypeAttr->cImplTypes); ok(pTypeAttr->cFuncs == 0, "cFuncs %d\n", pTypeAttr->cFuncs); ok(pTypeAttr->wTypeFlags == 0, "wTypeFlags %04x\n", pTypeAttr->cFuncs); ITypeInfo_ReleaseTypeAttr(pTypeInfo, pTypeAttr); hr = ITypeInfo_GetRefTypeOfImplType(pTypeInfo, 0, &href); ok(hr == S_OK, "hr %08lx\n", hr); todo_wine { ok(href == 0, "href = 0x%lx\n", href); } hr = ITypeInfo_GetRefTypeInfo(pTypeInfo, href, &pTI2); ok(hr == S_OK, "hr %08lx\n", hr); hr = ITypeInfo_GetTypeAttr(pTI2, &pTypeAttr); ok(hr == S_OK, "hr %08lx\n", hr); ok(pTypeAttr->typekind == TKIND_INTERFACE, "typekind %0x\n", pTypeAttr->typekind); ITypeInfo_ReleaseTypeAttr(pTI2, pTypeAttr); hr = ITypeInfo_GetFuncDesc(pTI2, 0, &pFuncDesc); ok(hr == S_OK, "hr %08lx\n", hr); ok(pFuncDesc->funckind == FUNC_VIRTUAL, "funckind %d\n", pFuncDesc->funckind); ok(pFuncDesc->invkind == methdata[0].wFlags, "invkind %d\n", pFuncDesc->invkind); ok(pFuncDesc->callconv == methdata[0].cc, "callconv %d\n", pFuncDesc->callconv); ok(pFuncDesc->cParams == methdata[0].cArgs, "cParams %d\n", pFuncDesc->cParams); ok(pFuncDesc->oVft == 0, "oVft %d\n", pFuncDesc->oVft); ok(pFuncDesc->wFuncFlags == 0, "oVft %d\n", pFuncDesc->wFuncFlags); ok(pFuncDesc->elemdescFunc.tdesc.vt == VT_HRESULT, "ret vt %x\n", pFuncDesc->elemdescFunc.tdesc.vt); ok(pFuncDesc->lprgelemdescParam[0].tdesc.vt == VT_I4, "parm 0 vt %x\n", pFuncDesc->lprgelemdescParam[0].tdesc.vt); ok(pFuncDesc->lprgelemdescParam[0].u.paramdesc.wParamFlags == PARAMFLAG_NONE, "parm 0 flags %x\n", pFuncDesc->lprgelemdescParam[0].u.paramdesc.wParamFlags); ok(pFuncDesc->lprgelemdescParam[1].tdesc.vt == VT_BSTR, "parm 1 vt %x\n", pFuncDesc->lprgelemdescParam[1].tdesc.vt); ok(pFuncDesc->lprgelemdescParam[1].u.paramdesc.wParamFlags == PARAMFLAG_NONE, "parm 1 flags %x\n", pFuncDesc->lprgelemdescParam[1].u.paramdesc.wParamFlags); ITypeInfo_ReleaseFuncDesc(pTI2, pFuncDesc); hr = ITypeInfo_GetFuncDesc(pTI2, 1, &pFuncDesc); ok(hr == S_OK, "hr %08lx\n", hr); ok(pFuncDesc->funckind == FUNC_VIRTUAL, "funckind %d\n", pFuncDesc->funckind); ok(pFuncDesc->invkind == methdata[1].wFlags, "invkind %d\n", pFuncDesc->invkind); ok(pFuncDesc->callconv == methdata[1].cc, "callconv %d\n", pFuncDesc->callconv); ok(pFuncDesc->cParams == methdata[1].cArgs, "cParams %d\n", pFuncDesc->cParams); ok(pFuncDesc->oVft == 4, "oVft %d\n", pFuncDesc->oVft); ok(pFuncDesc->wFuncFlags == 0, "oVft %d\n", pFuncDesc->wFuncFlags); ok(pFuncDesc->elemdescFunc.tdesc.vt == VT_I4, "ret vt %x\n", pFuncDesc->elemdescFunc.tdesc.vt); ITypeInfo_ReleaseFuncDesc(pTI2, pFuncDesc); hr = ITypeInfo_GetFuncDesc(pTI2, 2, &pFuncDesc); ok(hr == S_OK, "hr %08lx\n", hr); ok(pFuncDesc->funckind == FUNC_VIRTUAL, "funckind %d\n", pFuncDesc->funckind); ok(pFuncDesc->invkind == methdata[2].wFlags, "invkind %d\n", pFuncDesc->invkind); ok(pFuncDesc->callconv == methdata[2].cc, "callconv %d\n", pFuncDesc->callconv); ok(pFuncDesc->cParams == methdata[2].cArgs, "cParams %d\n", pFuncDesc->cParams); ok(pFuncDesc->oVft == 12, "oVft %d\n", pFuncDesc->oVft); ok(pFuncDesc->wFuncFlags == 0, "oVft %d\n", pFuncDesc->wFuncFlags); ok(pFuncDesc->elemdescFunc.tdesc.vt == VT_HRESULT, "ret vt %x\n", pFuncDesc->elemdescFunc.tdesc.vt); ok(pFuncDesc->lprgelemdescParam[0].tdesc.vt == VT_I4, "parm 0 vt %x\n", pFuncDesc->lprgelemdescParam[0].tdesc.vt); ok(pFuncDesc->lprgelemdescParam[0].u.paramdesc.wParamFlags == PARAMFLAG_NONE, "parm 0 flags %x\n", pFuncDesc->lprgelemdescParam[0].u.paramdesc.wParamFlags); ITypeInfo_ReleaseFuncDesc(pTI2, pFuncDesc); hr = ITypeInfo_GetFuncDesc(pTI2, 3, &pFuncDesc); ok(hr == S_OK, "hr %08lx\n", hr); ok(pFuncDesc->funckind == FUNC_VIRTUAL, "funckind %d\n", pFuncDesc->funckind); ok(pFuncDesc->invkind == methdata[3].wFlags, "invkind %d\n", pFuncDesc->invkind); ok(pFuncDesc->callconv == methdata[3].cc, "callconv %d\n", pFuncDesc->callconv); ok(pFuncDesc->cParams == methdata[3].cArgs, "cParams %d\n", pFuncDesc->cParams); ok(pFuncDesc->oVft == 16, "oVft %d\n", pFuncDesc->oVft); ok(pFuncDesc->wFuncFlags == 0, "oVft %d\n", pFuncDesc->wFuncFlags); ok(pFuncDesc->elemdescFunc.tdesc.vt == VT_I4, "ret vt %x\n", pFuncDesc->elemdescFunc.tdesc.vt); ITypeInfo_ReleaseFuncDesc(pTI2, pFuncDesc); /* test GetIDsOfNames on a coclass to see if it searches its interfaces */ hr = ITypeInfo_GetIDsOfNames(pTypeInfo, &name, 1, &memid); ok(hr == S_OK, "hr 0x%08lx\n", hr); ok(memid == 0x123, "memid 0x%08lx\n", memid); ITypeInfo_Release(pTI2); ITypeInfo_Release(pTypeInfo); SysFreeString(parms1[0].szName); SysFreeString(parms1[1].szName); SysFreeString(parms3[0].szName); SysFreeString(methdata[0].szName); SysFreeString(methdata[1].szName); SysFreeString(methdata[2].szName); SysFreeString(methdata[3].szName); } static void test_TypeInfo(void) { ITypeLib *pTypeLib; ITypeInfo *pTypeInfo; HRESULT hr; static WCHAR szBogus[] = { 'b','o','g','u','s',0 }; OLECHAR* bogus = szBogus; DISPID dispidMember; DISPPARAMS dispparams; hr = LoadTypeLib(wszStdOle2, &pTypeLib); ok_ole_success(hr, LoadTypeLib); hr = ITypeLib_GetTypeInfo(pTypeLib, 1, &pTypeInfo); ok_ole_success(hr, ITypeLib_GetTypeInfo); ITypeLib_Release(pTypeLib); /* test nonexistent method name */ hr = ITypeInfo_GetIDsOfNames(pTypeInfo, &bogus, 1, &dispidMember); ok(hr == DISP_E_UNKNOWNNAME, "ITypeInfo_GetIDsOfNames should have returned DISP_E_UNKNOWNNAME instead of 0x%08lx\n", hr); /* test invalid memberid */ dispparams.cNamedArgs = 0; dispparams.cArgs = 0; dispparams.rgdispidNamedArgs = NULL; dispparams.rgvarg = NULL; hr = ITypeInfo_Invoke(pTypeInfo, NULL, 0xdeadbeef, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL); ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08lx\n", hr); ITypeInfo_Release(pTypeInfo); } START_TEST(typelib) { ref_count_test(wszStdOle2); test_TypeComp(); test_CreateDispTypeInfo(); test_TypeInfo(); }