2 * ITypeLib and ITypeInfo test
4 * Copyright 2004 Jacek Caban
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <wine/test.h>
30 #define ok_ole_success(hr, func) ok(hr == S_OK, #func " failed with error 0x%08lx\n", hr)
32 static void ref_count_test(LPCWSTR type_lib)
35 ITypeInfo *iti1, *iti2;
39 trace("Loading type library\n");
40 hRes = LoadTypeLib(type_lib, &iface);
41 ok(hRes == S_OK, "Could not load type library\n");
45 hRes = ITypeLib_GetTypeInfo(iface, 1, &iti1);
46 ok(hRes == S_OK, "ITypeLib_GetTypeInfo failed on index = 1\n");
47 ok(ref_count=ITypeLib_Release(iface) > 0, "ITypeLib destroyed while ITypeInfo has back pointer\n");
51 hRes = ITypeLib_GetTypeInfo(iface, 1, &iti2);
52 ok(hRes == S_OK, "ITypeLib_GetTypeInfo failed on index = 1\n");
53 ok(iti1 == iti2, "ITypeLib_GetTypeInfo returned different pointers for same indexes\n");
55 ITypeLib_AddRef(iface);
56 ITypeInfo_Release(iti2);
57 ITypeInfo_Release(iti1);
58 ok(ITypeLib_Release(iface) == 0, "ITypeLib should be destroyed here.\n");
61 static void test_TypeComp(void)
70 static const WCHAR wszStdOle2[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
71 static WCHAR wszStdFunctions[] = {'S','t','d','F','u','n','c','t','i','o','n','s',0};
72 static WCHAR wszSavePicture[] = {'S','a','v','e','P','i','c','t','u','r','e',0};
73 static WCHAR wszOLE_TRISTATE[] = {'O','L','E','_','T','R','I','S','T','A','T','E',0};
74 static WCHAR wszUnchecked[] = {'U','n','c','h','e','c','k','e','d',0};
75 static WCHAR wszIUnknown[] = {'I','U','n','k','n','o','w','n',0};
76 static WCHAR wszFont[] = {'F','o','n','t',0};
77 static WCHAR wszGUID[] = {'G','U','I','D',0};
78 static WCHAR wszStdPicture[] = {'S','t','d','P','i','c','t','u','r','e',0};
79 static WCHAR wszOLE_COLOR[] = {'O','L','E','_','C','O','L','O','R',0};
81 hr = LoadTypeLib(wszStdOle2, &pTypeLib);
82 ok_ole_success(hr, LoadTypeLib);
84 hr = ITypeLib_GetTypeComp(pTypeLib, &pTypeComp);
85 ok_ole_success(hr, ITypeLib_GetTypeComp);
87 /* test getting a TKIND_MODULE */
88 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszStdFunctions);
89 hr = ITypeComp_Bind(pTypeComp, wszStdFunctions, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
90 ok_ole_success(hr, ITypeComp_Bind);
92 ok(desckind == DESCKIND_TYPECOMP,
93 "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
95 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
97 ITypeComp_Release(bindptr.lptcomp);
99 /* test getting a TKIND_MODULE with INVOKE_PROPERTYGET */
100 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszStdFunctions);
101 hr = ITypeComp_Bind(pTypeComp, wszStdFunctions, ulHash, INVOKE_PROPERTYGET, &pTypeInfo, &desckind, &bindptr);
102 ok_ole_success(hr, ITypeComp_Bind);
104 ok(desckind == DESCKIND_TYPECOMP,
105 "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
107 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
109 /* test getting a function within a TKIND_MODULE */
110 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszSavePicture);
111 hr = ITypeComp_Bind(pTypeComp, wszSavePicture, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
112 ok_ole_success(hr, ITypeComp_Bind);
114 ok(desckind == DESCKIND_FUNCDESC,
115 "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
117 ok(bindptr.lpfuncdesc != NULL, "bindptr.lpfuncdesc should not have been set to NULL\n");
118 ITypeInfo_ReleaseFuncDesc(pTypeInfo, bindptr.lpfuncdesc);
119 ITypeInfo_Release(pTypeInfo);
121 /* test getting a function within a TKIND_MODULE with INVOKE_PROPERTYGET */
122 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszSavePicture);
123 hr = ITypeComp_Bind(pTypeComp, wszSavePicture, ulHash, INVOKE_PROPERTYGET, &pTypeInfo, &desckind, &bindptr);
124 todo_wine ok(hr == TYPE_E_TYPEMISMATCH,
125 "ITypeComp_Bind should have failed with TYPE_E_TYPEMISMATCH instead of 0x%08lx\n",
128 ok(desckind == DESCKIND_NONE,
129 "desckind should have been DESCKIND_NONE instead of %d\n",
131 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
132 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
134 /* test getting a TKIND_ENUM */
135 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszOLE_TRISTATE);
136 hr = ITypeComp_Bind(pTypeComp, wszOLE_TRISTATE, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
137 ok_ole_success(hr, ITypeComp_Bind);
139 ok(desckind == DESCKIND_TYPECOMP,
140 "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
142 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
144 ITypeComp_Release(bindptr.lptcomp);
146 /* test getting a value within a TKIND_ENUM */
147 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszUnchecked);
148 hr = ITypeComp_Bind(pTypeComp, wszUnchecked, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
149 ok_ole_success(hr, ITypeComp_Bind);
151 ok(desckind == DESCKIND_VARDESC,
152 "desckind should have been DESCKIND_VARDESC instead of %d\n",
154 ITypeInfo_ReleaseVarDesc(pTypeInfo, bindptr.lpvardesc);
155 ITypeInfo_Release(pTypeInfo);
157 /* test getting a TKIND_INTERFACE */
158 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszIUnknown);
159 hr = ITypeComp_Bind(pTypeComp, wszIUnknown, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
160 ok_ole_success(hr, ITypeComp_Bind);
162 ok(desckind == DESCKIND_NONE,
163 "desckind should have been DESCKIND_NONE instead of %d\n",
165 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
166 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
168 /* test getting a TKIND_DISPATCH */
169 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszFont);
170 hr = ITypeComp_Bind(pTypeComp, wszFont, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
171 ok_ole_success(hr, ITypeComp_Bind);
173 ok(desckind == DESCKIND_NONE,
174 "desckind should have been DESCKIND_NONE instead of %d\n",
176 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
177 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
179 /* test getting a TKIND_RECORD/TKIND_ALIAS */
180 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszGUID);
181 hr = ITypeComp_Bind(pTypeComp, wszGUID, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
182 ok_ole_success(hr, ITypeComp_Bind);
184 ok(desckind == DESCKIND_NONE,
185 "desckind should have been DESCKIND_NONE instead of %d\n",
187 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
188 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
190 /* test getting a TKIND_ALIAS */
191 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszOLE_COLOR);
192 hr = ITypeComp_Bind(pTypeComp, wszOLE_COLOR, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
193 ok_ole_success(hr, ITypeComp_Bind);
195 ok(desckind == DESCKIND_NONE,
196 "desckind should have been DESCKIND_NONE instead of %d\n",
198 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
199 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
201 /* test getting a TKIND_COCLASS */
202 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszStdPicture);
203 hr = ITypeComp_Bind(pTypeComp, wszStdPicture, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
204 ok_ole_success(hr, ITypeComp_Bind);
206 ok(desckind == DESCKIND_NONE,
207 "desckind should have been DESCKIND_NONE instead of %d\n",
209 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
210 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
212 ITypeComp_Release(pTypeComp);
213 ITypeLib_Release(pTypeLib);
218 static const WCHAR type_lib_stdole32[] = {'s','t','d','o','l','e','3','2','.','t','l','b',0};
219 ref_count_test(type_lib_stdole32);