made functions and variables static in some testcases.
[wine] / dlls / oleaut32 / tests / olefont.c
1 /*
2  * OLEFONT test program
3  *
4  * Copyright 2003 Marcus Meissner
5  * Copyright 2006 (Google) Benjamin Arai
6  *
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <math.h>
26 #include <float.h>
27 #include <time.h>
28
29 #define COBJMACROS
30
31 #include <wine/test.h>
32 #include <windef.h>
33 #include <winbase.h>
34 #include <winuser.h>
35 #include <wingdi.h>
36 #include <winnls.h>
37 #include <winerror.h>
38 #include <winnt.h>
39 #include <wtypes.h>
40 #include <olectl.h>
41 #include <ocidl.h>
42
43 static HMODULE hOleaut32;
44
45 static HRESULT (WINAPI *pOleCreateFontIndirect)(LPFONTDESC,REFIID,LPVOID*);
46
47 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
48
49 /* Create a font with cySize given by lo_size, hi_size,  */
50 /* SetRatio to ratio_logical, ratio_himetric,            */
51 /* check that resulting hfont has height hfont_height.   */
52 /* Various checks along the way.                         */
53
54 static void test_ifont_sizes(long lo_size, long hi_size, 
55         long ratio_logical, long ratio_himetric,
56         long hfont_height, const char * test_name)
57 {
58         FONTDESC fd;
59         static const WCHAR fname[] = { 'S','y','s','t','e','m',0 };
60         LPVOID pvObj = NULL;
61         IFont* ifnt = NULL;
62         HFONT hfont;
63         LOGFONT lf;
64         CY psize;
65         HRESULT hres;
66
67         fd.cbSizeofstruct = sizeof(FONTDESC);
68         fd.lpstrName      = (WCHAR*)fname;
69         S(fd.cySize).Lo   = lo_size;
70         S(fd.cySize).Hi   = hi_size;
71         fd.sWeight        = 0;
72         fd.sCharset       = 0;
73         fd.fItalic        = 0;
74         fd.fUnderline     = 0;
75         fd.fStrikethrough = 0;
76
77         /* Create font, test that it worked. */
78         hres = pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj);
79         ifnt = pvObj;
80         ok(hres == S_OK,"%s: OCFI returns 0x%08x instead of S_OK.\n",
81                 test_name, hres);
82         ok(pvObj != NULL,"%s: OCFI returns NULL.\n", test_name);
83
84         /* Read back size.  Hi part was ignored. */
85         hres = IFont_get_Size(ifnt, &psize);
86         ok(hres == S_OK,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
87                 test_name, hres);
88         ok(S(psize).Lo == lo_size && S(psize).Hi == 0,
89                 "%s: get_Size: Lo=%d, Hi=%d; expected Lo=%ld, Hi=%ld.\n",
90                 test_name, S(psize).Lo, S(psize).Hi, lo_size, 0L);
91
92         /* Change ratio, check size unchanged.  Standard is 72, 2540. */
93         hres = IFont_SetRatio(ifnt, ratio_logical, ratio_himetric);
94         ok(hres == S_OK,"%s: IFont_SR returns 0x%08x instead of S_OK.\n",
95                 test_name, hres);
96         hres = IFont_get_Size(ifnt, &psize);
97         ok(hres == S_OK,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
98                 test_name, hres);
99         ok(S(psize).Lo == lo_size && S(psize).Hi == 0,
100                 "%s: gS after SR: Lo=%d, Hi=%d; expected Lo=%ld, Hi=%ld.\n",
101                 test_name, S(psize).Lo, S(psize).Hi, lo_size, 0L);
102
103         /* Check hFont size with this ratio.  This tests an important   */
104         /* conversion for which MSDN is very wrong.                     */
105         hres = IFont_get_hFont (ifnt, &hfont);
106         ok(hres == S_OK, "%s: IFont_get_hFont returns 0x%08x instead of S_OK.\n",
107                 test_name, hres);
108         hres = GetObject (hfont, sizeof(LOGFONT), &lf);
109         ok(lf.lfHeight == hfont_height,
110                 "%s: hFont has lf.lfHeight=%d, expected %ld.\n",
111                 test_name, lf.lfHeight, hfont_height);
112
113         /* Free IFont. */
114         IFont_Release(ifnt);
115 }
116
117 static void test_QueryInterface(void)
118 {
119         LPVOID pvObj = NULL;
120         HRESULT hres;
121         IFont*  font = NULL;
122         LONG ret;
123
124         hres = pOleCreateFontIndirect(NULL, &IID_IFont, &pvObj);
125         font = pvObj;
126
127         ok(hres == S_OK,"OCFI (NULL,..) does not return 0, but 0x%08x\n",hres);
128         ok(font != NULL,"OCFI (NULL,..) returns NULL, instead of !NULL\n");
129
130         pvObj = NULL;
131         hres = IFont_QueryInterface( font, &IID_IFont, &pvObj);
132
133         /* Test if QueryInterface increments ref counter for IFONTs */
134         ret = IFont_AddRef(font);
135         ok(ret == 3, "IFont_QI expected ref value 3 but instead got %12u\n",ret);
136         IFont_Release(font);
137
138         ok(hres == S_OK,"IFont_QI does not return S_OK, but 0x%08x\n", hres);
139         ok(pvObj != NULL,"IFont_QI does return NULL, instead of a ptr\n");
140
141         /* Orignial ref and QueryInterface ref both have to be released */
142         IFont_Release(font);
143         IFont_Release(font);
144 }
145
146 static void test_type_info(void)
147 {
148         LPVOID pvObj = NULL;
149         HRESULT hres;
150         IFontDisp*  fontdisp = NULL;
151         ITypeInfo* pTInfo;
152         WCHAR name_Name[] = {'N','a','m','e',0};
153         BSTR names[3];
154         UINT n;
155         LCID en_us = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),
156                 SORT_DEFAULT);
157         DISPPARAMS dispparams;
158         VARIANT varresult;
159
160         pOleCreateFontIndirect(NULL, &IID_IFontDisp, &pvObj);
161         fontdisp = pvObj;
162
163         hres = IFontDisp_GetTypeInfo(fontdisp, 0, en_us, &pTInfo);
164         ok(hres == S_OK, "GTI returned 0x%08x instead of S_OK.\n", hres);
165         ok(pTInfo != NULL, "GTI returned NULL.\n");
166
167         hres = ITypeInfo_GetNames(pTInfo, DISPID_FONT_NAME, names, 3, &n);
168         ok(hres == S_OK, "GetNames returned 0x%08x instead of S_OK.\n", hres);
169         ok(n == 1, "GetNames returned %d names instead of 1.\n", n);
170         ok(!lstrcmpiW(names[0],name_Name), "DISPID_FONT_NAME doesn't get 'Names'.\n");
171
172         ITypeInfo_Release(pTInfo);
173
174         dispparams.cNamedArgs = 0;
175         dispparams.rgdispidNamedArgs = NULL;
176         dispparams.cArgs = 0;
177         dispparams.rgvarg = NULL;
178         VariantInit(&varresult);
179         hres = IFontDisp_Invoke(fontdisp, DISPID_FONT_NAME, &IID_NULL,
180             LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult,
181             NULL, NULL);
182         ok(hres == S_OK, "IFontDisp_Invoke return 0x%08x instead of S_OK.\n", hres);
183         VariantClear(&varresult);
184
185         IFontDisp_Release(fontdisp);
186 }
187
188 static HRESULT WINAPI FontEventsDisp_QueryInterface(
189         IFontEventsDisp *iface,
190     /* [in] */ REFIID riid,
191     /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
192 {
193     if (IsEqualIID(riid, &IID_IFontEventsDisp) || IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDispatch))
194     {
195         IUnknown_AddRef(iface);
196         *ppvObject = iface;
197         return S_OK;
198     }
199     else
200     {
201         *ppvObject = NULL;
202         return E_NOINTERFACE;
203     }
204 }
205
206 static ULONG WINAPI FontEventsDisp_AddRef(
207     IFontEventsDisp *iface)
208 {
209     return 2;
210 }
211
212 static ULONG WINAPI FontEventsDisp_Release(
213         IFontEventsDisp *iface)
214 {
215     return 1;
216 }
217
218 static int fonteventsdisp_invoke_called = 0;
219
220 static HRESULT WINAPI FontEventsDisp_Invoke(
221         IFontEventsDisp __RPC_FAR * iface,
222     /* [in] */ DISPID dispIdMember,
223     /* [in] */ REFIID riid,
224     /* [in] */ LCID lcid,
225     /* [in] */ WORD wFlags,
226     /* [out][in] */ DISPPARAMS __RPC_FAR *pDispParams,
227     /* [out] */ VARIANT __RPC_FAR *pVarResult,
228     /* [out] */ EXCEPINFO __RPC_FAR *pExcepInfo,
229     /* [out] */ UINT __RPC_FAR *puArgErr)
230 {
231     static const WCHAR wszBold[] = {'B','o','l','d',0};
232     ok(wFlags == INVOKE_FUNC, "invoke flags should have been INVOKE_FUNC instead of 0x%x\n", wFlags);
233     ok(dispIdMember == DISPID_FONT_CHANGED, "dispIdMember should have been DISPID_FONT_CHANGED instead of 0x%x\n", dispIdMember);
234     ok(pDispParams->cArgs == 1, "pDispParams->cArgs should have been 1 instead of %d\n", pDispParams->cArgs);
235     ok(V_VT(&pDispParams->rgvarg[0]) == VT_BSTR, "VT of first param should have been VT_BSTR instead of %d\n", V_VT(&pDispParams->rgvarg[0]));
236     ok(!lstrcmpW(V_BSTR(&pDispParams->rgvarg[0]), wszBold), "String in first param should have been \"Bold\"\n");
237
238     fonteventsdisp_invoke_called++;
239     return S_OK;
240 }
241
242 static IFontEventsDispVtbl FontEventsDisp_Vtbl =
243 {
244     FontEventsDisp_QueryInterface,
245     FontEventsDisp_AddRef,
246     FontEventsDisp_Release,
247     NULL,
248     NULL,
249     NULL,
250     FontEventsDisp_Invoke
251 };
252
253 static IFontEventsDisp FontEventsDisp = { &FontEventsDisp_Vtbl };
254
255 static void test_font_events_disp(void)
256 {
257     IFont *pFont;
258     IFont *pFont2;
259     IConnectionPointContainer *pCPC;
260     IConnectionPoint *pCP;
261     FONTDESC fontdesc;
262     HRESULT hr;
263     DWORD dwCookie;
264     IFontDisp *pFontDisp;
265     static const WCHAR wszMSSansSerif[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0};
266     DISPPARAMS dispparams;
267     VARIANTARG vararg;
268
269     fontdesc.cbSizeofstruct = sizeof(fontdesc);
270     fontdesc.lpstrName = (LPOLESTR)wszMSSansSerif;
271     fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
272     fontdesc.sWeight = FW_NORMAL;
273     fontdesc.sCharset = 0;
274     fontdesc.fItalic = FALSE;
275     fontdesc.fUnderline = FALSE;
276     fontdesc.fStrikethrough = FALSE;
277
278     hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&pFont);
279     ok_ole_success(hr, "OleCreateFontIndirect");
280
281     hr = IFont_QueryInterface(pFont, &IID_IConnectionPointContainer, (void **)&pCPC);
282     ok_ole_success(hr, "IFont_QueryInterface");
283
284     hr = IConnectionPointContainer_FindConnectionPoint(pCPC, &IID_IFontEventsDisp, &pCP);
285     ok_ole_success(hr, "IConnectionPointContainer_FindConnectionPoint");
286     IConnectionPointContainer_Release(pCPC);
287
288     hr = IConnectionPoint_Advise(pCP, (IUnknown *)&FontEventsDisp, &dwCookie);
289     ok_ole_success(hr, "IConnectionPoint_Advise");
290     IConnectionPoint_Release(pCP);
291
292     hr = IFont_put_Bold(pFont, TRUE);
293     ok_ole_success(hr, "IFont_put_Bold");
294
295     ok(fonteventsdisp_invoke_called == 1, "IFontEventDisp::Invoke wasn't called once\n");
296
297     hr = IFont_QueryInterface(pFont, &IID_IFontDisp, (void **)&pFontDisp);
298     ok_ole_success(hr, "IFont_QueryInterface");
299
300     V_VT(&vararg) = VT_BOOL;
301     V_BOOL(&vararg) = VARIANT_FALSE;
302     dispparams.cNamedArgs = 0;
303     dispparams.rgdispidNamedArgs = NULL;
304     dispparams.cArgs = 1;
305     dispparams.rgvarg = &vararg;
306     hr = IFontDisp_Invoke(pFontDisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
307
308     IFontDisp_Release(pFontDisp);
309
310     ok(fonteventsdisp_invoke_called == 2, "IFontEventDisp::Invoke was called %d times instead of twice\n",
311         fonteventsdisp_invoke_called);
312
313     hr = IFont_Clone(pFont, &pFont2);
314     ok_ole_success(hr, "IFont_Clone");
315     IFont_Release(pFont);
316
317     hr = IFont_put_Bold(pFont2, FALSE);
318     ok_ole_success(hr, "IFont_put_Bold");
319
320     /* this test shows that the notification routine isn't called again */
321     ok(fonteventsdisp_invoke_called == 2, "IFontEventDisp::Invoke was called %d times instead of twice\n",
322         fonteventsdisp_invoke_called);
323
324     IFont_Release(pFont2);
325 }
326
327 static void test_names_ids(WCHAR* w_name_1, const char* a_name_1,
328                     WCHAR* w_name_2, const char* a_name_2,
329                     LCID lcid, DISPID id_1, DISPID id_2,
330                     HRESULT hres_expect, int numnames)
331 {
332     LPVOID pvObj = NULL;
333     IFontDisp *fontdisp = NULL;
334     HRESULT hres;
335     DISPID rgDispId[2] = {0xdeadbeef, 0xdeadbeef};
336     LPOLESTR names[2] = {w_name_1, w_name_2};
337
338     pOleCreateFontIndirect(NULL, &IID_IFontDisp, &pvObj);
339     fontdisp = pvObj;
340
341     hres = IFontDisp_GetIDsOfNames(fontdisp, &IID_NULL, names, numnames,
342                                    lcid, rgDispId);
343
344     /* test hres */
345     ok(hres == hres_expect,
346         "GetIDsOfNames: \"%s\", \"%s\" returns 0x%08x, expected 0x%08x.\n",
347         a_name_1, a_name_2, hres, hres_expect);
348
349     /* test first DISPID */
350     ok(rgDispId[0]==id_1,
351         "GetIDsOfNames: \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
352         a_name_1, rgDispId[0], id_1);
353
354     /* test second DISPID is present */
355     if (numnames == 2)
356     {
357         ok(rgDispId[1]==id_2,
358             "GetIDsOfNames: ..., \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
359             a_name_2, rgDispId[1], id_2);
360     }
361
362    IFontDisp_Release(fontdisp);
363 }
364
365 static void test_GetIDsOfNames(void)
366 {
367     WCHAR name_Name[] = {'N','a','m','e',0};
368     WCHAR name_Italic[] = {'I','t','a','l','i','c',0};
369     WCHAR name_Size[] = {'S','i','z','e',0};
370     WCHAR name_Bold[] = {'B','o','l','d',0};
371     WCHAR name_Underline[] = {'U','n','d','e','r','l','i','n','e',0};
372     WCHAR name_Strikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
373     WCHAR name_Weight[] = {'W','e','i','g','h','t',0};
374     WCHAR name_Charset[] = {'C','h','a','r','s','e','t',0};
375     WCHAR name_Foo[] = {'F','o','o',0};
376     WCHAR name_nAmE[] = {'n','A','m','E',0};
377     WCHAR name_Nom[] = {'N','o','m',0};
378
379     LCID en_us = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),
380                           SORT_DEFAULT);
381     LCID fr_fr = MAKELCID(MAKELANGID(LANG_FRENCH,SUBLANG_FRENCH),
382                           SORT_DEFAULT);
383
384     /* Test DISPID_FONTs for the various properties. */
385     test_names_ids(name_Name, "Name", NULL, "", en_us,
386                    DISPID_FONT_NAME, 0, S_OK,1);
387     test_names_ids(name_Size, "Size", NULL, "", en_us,
388                    DISPID_FONT_SIZE, 0, S_OK,1);
389     test_names_ids(name_Bold, "Bold", NULL, "", en_us,
390                    DISPID_FONT_BOLD, 0, S_OK,1);
391     test_names_ids(name_Italic, "Italic", NULL, "", en_us,
392                    DISPID_FONT_ITALIC, 0, S_OK,1);
393     test_names_ids(name_Underline, "Underline", NULL, "", en_us,
394                    DISPID_FONT_UNDER, 0, S_OK,1);
395     test_names_ids(name_Strikethrough, "Strikethrough", NULL, "", en_us,
396                    DISPID_FONT_STRIKE, 0, S_OK,1);
397     test_names_ids(name_Weight, "Weight", NULL, "", en_us,
398                    DISPID_FONT_WEIGHT, 0, S_OK,1);
399     test_names_ids(name_Charset, "Charset", NULL, "", en_us,
400                    DISPID_FONT_CHARSET, 0, S_OK,1);
401
402     /* Capitalization doesn't matter. */
403     test_names_ids(name_nAmE, "nAmE", NULL, "", en_us,
404                    DISPID_FONT_NAME, 0, S_OK,1);
405
406     /* Unknown name. */
407     test_names_ids(name_Foo, "Foo", NULL, "", en_us,
408                    DISPID_UNKNOWN, 0, DISP_E_UNKNOWNNAME,1);
409
410     /* Pass several names: first is processed,                */
411     /* second gets DISPID_UNKNOWN and doesn't affect retval.  */
412     test_names_ids(name_Italic, "Italic", name_Name, "Name", en_us,
413                    DISPID_FONT_ITALIC, DISPID_UNKNOWN, S_OK,2);
414     test_names_ids(name_Italic, "Italic", name_Foo, "Foo", en_us,
415                    DISPID_FONT_ITALIC, DISPID_UNKNOWN, S_OK,2);
416
417     /* Locale ID has no effect. */
418     test_names_ids(name_Name, "Name", NULL, "", fr_fr,
419                    DISPID_FONT_NAME, 0, S_OK,1);
420     test_names_ids(name_Nom, "This is not a font", NULL, "", fr_fr,
421                    DISPID_UNKNOWN, 0, DISP_E_UNKNOWNNAME,1);
422
423     /* One of the arguments are invalid */
424     test_names_ids(name_Name, "Name", NULL, "", en_us,
425                    0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
426     test_names_ids(name_Italic, "Italic", NULL, "", en_us,
427                    0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
428     test_names_ids(name_Foo, "Foo", NULL, "", en_us,
429                    0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
430
431     /* Crazy locale ID? */
432     test_names_ids(name_Name, "Name", NULL, "", -1,
433                    DISPID_FONT_NAME, 0, S_OK,1);
434 }
435
436 static void test_Invoke(void)
437 {
438     IFontDisp *fontdisp;
439     HRESULT hr;
440     VARIANTARG vararg;
441     DISPPARAMS dispparams;
442     VARIANT varresult;
443
444     hr = pOleCreateFontIndirect(NULL, &IID_IFontDisp, (void **)&fontdisp);
445     ok_ole_success(hr, "OleCreateFontIndirect");
446
447     V_VT(&vararg) = VT_BOOL;
448     V_BOOL(&vararg) = VARIANT_FALSE;
449     dispparams.cNamedArgs = 0;
450     dispparams.rgdispidNamedArgs = NULL;
451     dispparams.cArgs = 1;
452     dispparams.rgvarg = &vararg;
453     hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_IFontDisp, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
454     ok(hr == DISP_E_UNKNOWNINTERFACE, "IFontDisp_Invoke should have returned DISP_E_UNKNOWNINTERFACE instead of 0x%08x\n", hr);
455
456     dispparams.cArgs = 0;
457     dispparams.rgvarg = NULL;
458     hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
459     ok(hr == DISP_E_BADPARAMCOUNT, "IFontDisp_Invoke should have returned DISP_E_BADPARAMCOUNT instead of 0x%08x\n", hr);
460
461     hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, NULL, NULL, NULL, NULL);
462     ok(hr == DISP_E_PARAMNOTOPTIONAL, "IFontDisp_Invoke should have returned DISP_E_PARAMNOTOPTIONAL instead of 0x%08x\n", hr);
463
464     hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, NULL, NULL, NULL);
465     ok(hr == DISP_E_PARAMNOTOPTIONAL, "IFontDisp_Invoke should have returned DISP_E_PARAMNOTOPTIONAL instead of 0x%08x\n", hr);
466
467     hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, &varresult, NULL, NULL);
468     ok_ole_success(hr, "IFontDisp_Invoke");
469
470     hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_METHOD, NULL, &varresult, NULL, NULL);
471     ok(hr == DISP_E_MEMBERNOTFOUND, "IFontDisp_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
472
473     hr = IFontDisp_Invoke(fontdisp, 0xdeadbeef, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, &varresult, NULL, NULL);
474     ok(hr == DISP_E_MEMBERNOTFOUND, "IFontDisp_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
475
476     dispparams.cArgs = 1;
477     dispparams.rgvarg = &vararg;
478     hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, &dispparams, &varresult, NULL, NULL);
479     ok_ole_success(hr, "IFontDisp_Invoke");
480
481     IFontDisp_Release(fontdisp);
482 }
483
484 static void test_IsEqual()
485 {
486     FONTDESC fd;
487     static const WCHAR system_font[] = { 'S','y','s','t','e','m',0 };
488     static const WCHAR arial_font[] = { 'A','r','i','a','l',0 };
489     LPVOID pvObj = NULL;
490     LPVOID pvObj2 = NULL;
491     IFont* ifnt = NULL;
492     IFont* ifnt2 = NULL;
493     HRESULT hres;
494
495     /* Basic font description */
496     fd.cbSizeofstruct = sizeof(FONTDESC);
497     fd.lpstrName      = (WCHAR*)system_font;
498     S(fd.cySize).Lo   = 100;
499     S(fd.cySize).Hi   = 100;
500     fd.sWeight        = 0;
501     fd.sCharset       = 0;
502     fd.fItalic        = 0;
503     fd.fUnderline     = 0;
504     fd.fStrikethrough = 0;
505
506     /* Create font */
507     pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj);
508     ifnt = pvObj;
509
510     /* Test equal fonts */
511     pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
512     ifnt2 = pvObj2;
513     hres = IFont_IsEqual(ifnt,ifnt2);
514     ok(hres == S_OK,
515         "IFont_IsEqual: (EQUAL) Expected S_OK but got 0x%08x\n",hres);
516     IFont_Release(ifnt2);
517
518     /* Check for bad pointer */
519     hres = IFont_IsEqual(ifnt,NULL);
520     ok(hres == E_POINTER,
521         "IFont_IsEqual: (NULL) Expected 0x80004003 but got 0x%08x\n",hres);
522
523     /* Test strName */
524     fd.lpstrName = (WCHAR*)arial_font;
525     pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
526     hres = IFont_IsEqual(ifnt,ifnt2);
527     ok(hres == S_FALSE,
528         "IFont_IsEqual: (strName) Expected S_FALSE but got 0x%08x\n",hres);
529     fd.lpstrName = (WCHAR*)system_font;
530     IFont_Release(ifnt2);
531
532     /* Test lo font size */
533     S(fd.cySize).Lo = 10000;
534     pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
535     ifnt2 = pvObj2;
536     hres = IFont_IsEqual(ifnt,ifnt2);
537     ok(hres == S_FALSE,
538         "IFont_IsEqual: (Lo font size) Expected S_FALSE but got 0x%08x\n",hres);
539     S(fd.cySize).Lo = 100;
540     IFont_Release(ifnt2);
541
542     /* Test hi font size */
543     S(fd.cySize).Hi = 10000;
544     pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
545     ifnt2 = pvObj2;
546     hres = IFont_IsEqual(ifnt,ifnt2);
547     ok(hres == S_FALSE,
548         "IFont_IsEqual: (Hi font size) Expected S_FALSE but got 0x%08x\n",hres);
549     S(fd.cySize).Hi = 100;
550     IFont_Release(ifnt2);
551
552     /* Test font weight  */
553     fd.sWeight = 100;
554     pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
555     ifnt2 = pvObj2;
556     hres = IFont_IsEqual(ifnt,ifnt2);
557     ok(hres == S_FALSE,
558         "IFont_IsEqual: (Weight) Expected S_FALSE but got 0x%08x\n",hres);
559     fd.sWeight = 0;
560     IFont_Release(ifnt2);
561
562     /* Test charset */
563     fd.sCharset = 1;
564     pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
565     hres = IFont_IsEqual(ifnt,ifnt2);
566     ok(hres == S_FALSE,
567         "IFont_IsEqual: (Charset) Expected S_FALSE but got 0x%08x\n",hres);
568     fd.sCharset = 0;
569     IFont_Release(ifnt2);
570
571     /* Test italic setting */
572     fd.fItalic = 1;
573     pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
574     hres = IFont_IsEqual(ifnt,ifnt2);
575     ok(hres == S_FALSE,
576         "IFont_IsEqual: (Italic) Expected S_FALSE but got 0x%08x\n",hres);
577     fd.fItalic = 0;
578     IFont_Release(ifnt2);
579
580     /* Test underline setting */
581     fd.fUnderline = 1;
582     pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
583     hres = IFont_IsEqual(ifnt,ifnt2);
584     ok(hres == S_FALSE,
585         "IFont_IsEqual: (Underline) Expected S_FALSE but got 0x%08x\n",hres);
586     fd.fUnderline = 0;
587     IFont_Release(ifnt2);
588
589     /* Test strikethrough setting */
590     fd.fStrikethrough = 1;
591     pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
592     hres = IFont_IsEqual(ifnt,ifnt2);
593     ok(hres == S_FALSE,
594         "IFont_IsEqual: (Strikethrough) Expected S_FALSE but got 0x%08x\n",hres);
595     fd.fStrikethrough = 0;
596     IFont_Release(ifnt2);
597
598     /* Free IFont. */
599     IFont_Release(ifnt);
600 }
601
602 static void test_ReleaseHfont(void)
603 {
604     FONTDESC fd;
605     static const WCHAR system_font[] = { 'S','y','s','t','e','m',0 };
606     static const WCHAR arial_font[] = { 'A','r','i','a','l',0 };
607     LPVOID pvObj1 = NULL;
608     LPVOID pvObj2 = NULL;
609     IFont* ifnt1 = NULL;
610     IFont* ifnt2 = NULL;
611     HFONT hfnt1 = 0;
612     HFONT hfnt2 = 0;
613     HRESULT hres;
614
615     /* Basic font description */
616     fd.cbSizeofstruct = sizeof(FONTDESC);
617     fd.lpstrName      = (WCHAR*)system_font;
618     S(fd.cySize).Lo   = 100;
619     S(fd.cySize).Hi   = 100;
620     fd.sWeight        = 0;
621     fd.sCharset       = 0;
622     fd.fItalic        = 0;
623     fd.fUnderline     = 0;
624     fd.fStrikethrough = 0;
625
626     /* Create HFONTs and IFONTs */
627     pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj1);
628     ifnt1 = pvObj1;
629     IFont_get_hFont(ifnt1,&hfnt1);
630     fd.lpstrName = (WCHAR*)arial_font;
631     pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
632     ifnt2 = pvObj2;
633     IFont_get_hFont(ifnt2,&hfnt2);
634
635     /* Try invalid HFONT */
636     hres = IFont_ReleaseHfont(ifnt1,NULL);
637     ok(hres == E_INVALIDARG,
638         "IFont_ReleaseHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
639         hres);
640
641     /* Try to add a bad HFONT */
642     hres = IFont_ReleaseHfont(ifnt1,(HFONT)32);
643     todo_wine {ok(hres == S_FALSE,
644         "IFont_ReleaseHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
645         hres);}
646
647     /* Release all refs */
648     hres = IFont_ReleaseHfont(ifnt1,hfnt1);
649     ok(hres == S_OK,
650         "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
651         hres);
652
653     hres = IFont_ReleaseHfont(ifnt2,hfnt2);
654     ok(hres == S_OK,
655         "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
656         hres);
657
658     /* Check that both lists are empty */
659     hres = IFont_ReleaseHfont(ifnt1,hfnt1);
660     todo_wine {ok(hres == S_FALSE,
661         "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
662         hres);}
663
664     /* The list should be empty */
665     hres = IFont_ReleaseHfont(ifnt2,hfnt2);
666     todo_wine {ok(hres == S_FALSE,
667         "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
668         hres);}
669
670     IFont_Release(ifnt1);
671     IFont_Release(ifnt2);
672 }
673
674 static void test_AddRefHfont(void)
675 {
676     FONTDESC fd;
677     static const WCHAR system_font[] = { 'S','y','s','t','e','m',0 };
678     static const WCHAR arial_font[] = { 'A','r','i','a','l',0 };
679     LPVOID pvObj1 = NULL;
680     LPVOID pvObj2 = NULL;
681     LPVOID pvObj3 = NULL;
682     IFont* ifnt1 = NULL;
683     IFont* ifnt2 = NULL;
684     IFont* ifnt3 = NULL;
685     HFONT hfnt1 = 0;
686     HFONT hfnt2 = 0;
687     HFONT hfnt3 = 0;
688     HRESULT hres;
689
690     /* Basic font description */
691     fd.cbSizeofstruct = sizeof(FONTDESC);
692     fd.lpstrName      = (WCHAR*)system_font;
693     S(fd.cySize).Lo   = 100;
694     S(fd.cySize).Hi   = 100;
695     fd.sWeight        = 0;
696     fd.sCharset       = 0;
697     fd.fItalic        = 0;
698     fd.fUnderline     = 0;
699     fd.fStrikethrough = 0;
700
701     /* Create HFONTs and IFONTs */
702     pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj1);
703     ifnt1 = pvObj1;
704     IFont_get_hFont(ifnt1,&hfnt1);
705     fd.lpstrName = (WCHAR*)arial_font;
706     pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
707     ifnt2 = pvObj2;
708     IFont_get_hFont(ifnt2,&hfnt2);
709
710     /* Try invalid HFONT */
711     hres = IFont_AddRefHfont(ifnt1,NULL);
712     ok(hres == E_INVALIDARG,
713         "IFont_AddRefHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
714         hres);
715
716     /* Try to add a bad HFONT */
717     hres = IFont_AddRefHfont(ifnt1,(HFONT)32);
718     todo_wine{ ok(hres == S_FALSE,
719         "IFont_AddRefHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
720         hres);}
721
722     /* Add simple IFONT HFONT pair */
723     hres = IFont_AddRefHfont(ifnt1,hfnt1);
724     ok(hres == S_OK,
725         "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
726         hres);
727
728     /* IFONT and HFONT do not have to be the same (always looks at HFONT) */
729     hres = IFont_AddRefHfont(ifnt2,hfnt1);
730     todo_wine {ok(hres == S_OK,
731         "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
732         hres);}
733
734     /* Release all hfnt1 refs */
735     hres = IFont_ReleaseHfont(ifnt1,hfnt1);
736     ok(hres == S_OK,
737         "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
738         hres);
739
740     hres = IFont_ReleaseHfont(ifnt1,hfnt1);
741     todo_wine {ok(hres == S_OK,
742         "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
743         hres);}
744
745     hres = IFont_ReleaseHfont(ifnt1,hfnt1);
746     todo_wine {ok(hres == S_OK,
747         "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
748         hres);}
749
750     /* Check if hfnt1 is empty */
751     hres = IFont_ReleaseHfont(ifnt1,hfnt1);
752     todo_wine {ok(hres == S_FALSE,
753         "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
754         hres);}
755
756     /* Release all hfnt2 refs */
757     hres = IFont_ReleaseHfont(ifnt2,hfnt2);
758     ok(hres == S_OK,
759         "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
760         hres);
761
762     /* Check if hfnt2 is empty */
763     hres = IFont_ReleaseHfont(ifnt2,hfnt2);
764     todo_wine {ok(hres == S_FALSE,
765         "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
766         hres);}
767
768     /* Show that releasing an IFONT does not always release it from the HFONT cache. */
769
770     IFont_Release(ifnt1);
771
772     /* Add a reference for destroyed hfnt1 */
773     hres = IFont_AddRefHfont(ifnt2,hfnt1);
774     todo_wine {ok(hres == S_OK,
775         "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
776         hres);}
777
778     /* Decrement reference for destroyed hfnt1 */
779     hres = IFont_ReleaseHfont(ifnt2,hfnt1);
780     todo_wine {ok(hres == S_OK,
781         "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
782         hres);}
783
784     /* Shows that releasing all IFONT's does clear the HFONT cache. */
785
786     IFont_Release(ifnt2);
787
788     /* Need to make a new IFONT for testing */
789     fd.fUnderline = 1;
790     pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj3);
791     ifnt3 = pvObj3;
792     IFont_get_hFont(ifnt3,&hfnt3);
793
794     /* Add a reference for destroyed hfnt1 */
795     hres = IFont_AddRefHfont(ifnt3,hfnt1);
796     todo_wine {ok(hres == S_FALSE,
797         "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
798         hres);}
799
800     /* Decrement reference for destroyed hfnt1 */
801     hres = IFont_ReleaseHfont(ifnt3,hfnt1);
802     todo_wine {ok(hres == S_FALSE,
803         "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
804         hres);}
805
806     hres = IFont_Release(ifnt3);
807 }
808
809 START_TEST(olefont)
810 {
811         hOleaut32 = LoadLibraryA("oleaut32.dll");    
812         pOleCreateFontIndirect = (void*)GetProcAddress(hOleaut32, "OleCreateFontIndirect");
813         if (!pOleCreateFontIndirect)
814             return;
815
816         test_QueryInterface();
817         test_type_info();
818
819         /* Test various size operations and conversions. */
820         /* Add more as needed. */
821         test_ifont_sizes(180000, 0, 72, 2540, -18, "default");
822         test_ifont_sizes(180000, 0, 144, 2540, -36, "ratio1");          /* change ratio */
823         test_ifont_sizes(180000, 0, 72, 1270, -36, "ratio2");           /* 2nd part of ratio */
824
825         /* These depend on details of how IFont rounds sizes internally. */
826         test_ifont_sizes(0, 0, 72, 2540, 0, "zero size");          /* zero size */
827         test_ifont_sizes(186000, 0, 72, 2540, -19, "rounding");   /* test rounding */
828
829         test_font_events_disp();
830         test_GetIDsOfNames();
831         test_Invoke();
832         test_IsEqual();
833         test_ReleaseHfont();
834         test_AddRefHfont();
835 }