kernel32: FindFirstChangeNotification needs a static IO_STATUS_BLOCK.
[wine] / dlls / oleaut32 / tests / typelib.c
1 /*
2  * ITypeLib and ITypeInfo test
3  *
4  * Copyright 2004 Jacek Caban
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #define COBJMACROS
22
23 #include <wine/test.h>
24 #include <stdarg.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "oleauto.h"
29
30 #define ok_ole_success(hr, func) ok(hr == S_OK, #func " failed with error 0x%08lx\n", hr)
31
32 static void ref_count_test(LPCWSTR type_lib)
33 {
34     ITypeLib *iface;
35     ITypeInfo *iti1, *iti2;
36     HRESULT hRes;
37     int ref_count;
38
39     trace("Loading type library\n");
40     hRes = LoadTypeLib(type_lib, &iface);
41     ok(hRes == S_OK, "Could not load type library\n");
42     if(hRes != S_OK)
43         return;
44
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");
48     if(!ref_count)
49         return;
50
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");
54
55     ITypeLib_AddRef(iface);
56     ITypeInfo_Release(iti2);
57     ITypeInfo_Release(iti1);
58     ok(ITypeLib_Release(iface) == 0, "ITypeLib should be destroyed here.\n");
59 }
60
61 static void test_TypeComp(void)
62 {
63     ITypeLib *pTypeLib;
64     ITypeComp *pTypeComp;
65     HRESULT hr;
66     ULONG ulHash;
67     DESCKIND desckind;
68     BINDPTR bindptr;
69     ITypeInfo *pTypeInfo;
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};
80
81     hr = LoadTypeLib(wszStdOle2, &pTypeLib);
82     ok_ole_success(hr, LoadTypeLib);
83
84     hr = ITypeLib_GetTypeComp(pTypeLib, &pTypeComp);
85     ok_ole_success(hr, ITypeLib_GetTypeComp);
86
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);
91
92     ok(desckind == DESCKIND_TYPECOMP,
93         "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
94         desckind);
95     ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
96
97     ITypeComp_Release(bindptr.lptcomp);
98
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);
103
104     ok(desckind == DESCKIND_TYPECOMP,
105         "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
106         desckind);
107     ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
108
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);
113
114     ok(desckind == DESCKIND_FUNCDESC,
115         "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
116         desckind);
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);
120
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",
126         hr);
127
128     ok(desckind == DESCKIND_NONE,
129         "desckind should have been DESCKIND_NONE instead of %d\n",
130         desckind);
131     ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
132     ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
133
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);
138
139     ok(desckind == DESCKIND_TYPECOMP,
140         "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
141         desckind);
142     ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
143
144     ITypeComp_Release(bindptr.lptcomp);
145
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);
150
151     ok(desckind == DESCKIND_VARDESC,
152         "desckind should have been DESCKIND_VARDESC instead of %d\n",
153         desckind);
154     ITypeInfo_ReleaseVarDesc(pTypeInfo, bindptr.lpvardesc);
155     ITypeInfo_Release(pTypeInfo);
156
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);
161
162     ok(desckind == DESCKIND_NONE,
163         "desckind should have been DESCKIND_NONE instead of %d\n",
164         desckind);
165     ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
166     ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
167
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);
172
173     ok(desckind == DESCKIND_NONE,
174         "desckind should have been DESCKIND_NONE instead of %d\n",
175         desckind);
176     ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
177     ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
178
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);
183
184     ok(desckind == DESCKIND_NONE,
185         "desckind should have been DESCKIND_NONE instead of %d\n",
186         desckind);
187     ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
188     ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
189
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);
194
195     ok(desckind == DESCKIND_NONE,
196         "desckind should have been DESCKIND_NONE instead of %d\n",
197         desckind);
198     ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
199     ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
200
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);
205
206     ok(desckind == DESCKIND_NONE,
207         "desckind should have been DESCKIND_NONE instead of %d\n",
208         desckind);
209     ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
210     ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
211
212     ITypeComp_Release(pTypeComp);
213     ITypeLib_Release(pTypeLib);
214 }
215
216 START_TEST(typelib)
217 {
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);
220     test_TypeComp();
221 }