Release 1.4.1.
[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
28 #define COBJMACROS
29
30 #include <wine/test.h>
31 #include <windef.h>
32 #include <winbase.h>
33 #include <winuser.h>
34 #include <wingdi.h>
35 #include <winnls.h>
36 #include <winerror.h>
37 #include <winnt.h>
38 #include <initguid.h>
39 #include <wtypes.h>
40 #include <olectl.h>
41 #include <ocidl.h>
42
43 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
44
45 static WCHAR MSSansSerif_font[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0};
46 static WCHAR system_font[] = { 'S','y','s','t','e','m',0 };
47 static WCHAR arial_font[] = { 'A','r','i','a','l',0 };
48 static WCHAR marlett_font[] = { 'M','a','r','l','e','t','t',0 };
49
50 static HMODULE hOleaut32;
51
52 static HRESULT (WINAPI *pOleCreateFontIndirect)(LPFONTDESC,REFIID,LPVOID*);
53
54 #define EXPECT_HR(hr,hr_exp) \
55     ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
56
57 /* Create a font with cySize given by lo_size, hi_size,  */
58 /* SetRatio to ratio_logical, ratio_himetric,            */
59 /* check that resulting hfont has height hfont_height.   */
60 /* Various checks along the way.                         */
61 static void test_ifont_size(LONG lo_size, LONG hi_size,
62         LONG ratio_logical, LONG ratio_himetric,
63         LONG hfont_height, const char * test_name)
64 {
65         FONTDESC fd;
66         LPVOID pvObj = NULL;
67         IFont* ifnt = NULL;
68         HFONT hfont;
69         LOGFONT lf;
70         CY psize;
71         HRESULT hres;
72         DWORD rtnval;
73
74         fd.cbSizeofstruct = sizeof(FONTDESC);
75         fd.lpstrName      = arial_font; /* using scalable instead of bitmap font reduces errors due to font realization */
76         S(fd.cySize).Lo   = lo_size;
77         S(fd.cySize).Hi   = hi_size;
78         fd.sWeight        = 0;
79         fd.sCharset       = 0;
80         fd.fItalic        = 0;
81         fd.fUnderline     = 0;
82         fd.fStrikethrough = 0;
83
84         /* Create font, test that it worked. */
85         hres = pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj);
86         ifnt = pvObj;
87         ok(hres == S_OK,"%s: OCFI returns 0x%08x instead of S_OK.\n",
88                 test_name, hres);
89         ok(pvObj != NULL,"%s: OCFI returns NULL.\n", test_name);
90
91         /* If scaling ration specified, change ratio. */
92         if(ratio_logical && ratio_himetric)
93         {
94           hres = IFont_SetRatio(ifnt, ratio_logical, ratio_himetric);
95           ok(hres == S_OK,"%s: IFont_SetRatio returns 0x%08x instead of S_OK.\n",
96             test_name, hres);
97         }
98
99         /* Read back size. */
100         hres = IFont_get_Size(ifnt, &psize);
101         ok(hres == S_OK,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
102                 test_name, hres);
103
104         /* Check returned size - allow for errors due to rounding & font realization. */
105         ok((abs(S(psize).Lo - lo_size) < 10000) && S(psize).Hi == hi_size,
106                 "%s: IFont_get_Size: Lo=%d, Hi=%d; expected Lo=%d, Hi=%d.\n",
107                 test_name, S(psize).Lo, S(psize).Hi, lo_size, hi_size);
108
109         /* Check hFont size. */
110         hres = IFont_get_hFont (ifnt, &hfont);
111         ok(hres == S_OK, "%s: IFont_get_hFont returns 0x%08x instead of S_OK.\n",
112                 test_name, hres);
113         rtnval = GetObject (hfont, sizeof(LOGFONT), &lf);
114         ok(rtnval > 0, "GetObject(hfont) failed\n");
115
116         /* Since font scaling may encounter rounding errors, allow 1 pixel deviation. */
117         ok(abs(lf.lfHeight - hfont_height) <= 1,
118                 "%s: hFont has lf.lfHeight=%d, expected %d.\n",
119                 test_name, lf.lfHeight, hfont_height);
120
121         /* Free IFont. */
122         IFont_Release(ifnt);
123 }
124
125 static void test_ifont_sizes(void)
126 {
127   /* Test various size operations and conversions. */
128   /* Add more as needed. */
129
130   /* Results of first 2 tests depend on display resolution. */
131   HDC hdc = GetDC(0);
132   LONG dpi = GetDeviceCaps(hdc, LOGPIXELSY); /* expected results depend on display DPI */
133   ReleaseDC(0, hdc);
134   if(dpi == 96) /* normal resolution display */
135   {
136     test_ifont_size(180000, 0, 0, 0, -24, "default");     /* normal font */
137     test_ifont_size(186000, 0, 0, 0, -25, "rounding");    /* test rounding */
138   } else if(dpi == 72) /* low resolution display */
139   {
140     test_ifont_size(180000, 0, 0, 0, -18, "default");     /* normal font */
141     test_ifont_size(186000, 0, 0, 0, -19, "rounding");    /* test rounding */
142   } else if(dpi == 120) /* high resolution display */
143   {
144     test_ifont_size(180000, 0, 0, 0, -30, "default");     /* normal font */
145     test_ifont_size(186000, 0, 0, 0, -31, "rounding");    /* test rounding */
146   } else
147     skip("Skipping resolution dependent font size tests - display resolution is %d\n", dpi);
148
149   /* Next 4 tests specify a scaling ratio, so display resolution is not a factor. */
150     test_ifont_size(180000, 0, 72,  2540, -18, "ratio1");  /* change ratio */
151     test_ifont_size(180000, 0, 144, 2540, -36, "ratio2");  /* another ratio */
152     test_ifont_size(180000, 0, 72,  1270, -36, "ratio3");  /* yet another ratio */
153     test_ifont_size(186000, 0, 72,  2540, -19, "rounding+ratio"); /* test rounding with ratio */
154 }
155
156 static void test_QueryInterface(void)
157 {
158     LPVOID pvObj = NULL;
159     HRESULT hr;
160     IFont*  font = NULL;
161     LONG ref;
162
163     hr = pOleCreateFontIndirect(NULL, &IID_IFont, NULL);
164     EXPECT_HR(hr, E_POINTER);
165
166     hr = pOleCreateFontIndirect(NULL, &IID_IFont, &pvObj);
167     font = pvObj;
168
169     EXPECT_HR(hr, S_OK);
170     ok(font != NULL,"OCFI (NULL,..) returns NULL, instead of !NULL\n");
171
172     pvObj = NULL;
173     hr = IFont_QueryInterface( font, &IID_IFont, &pvObj);
174     EXPECT_HR(hr, S_OK);
175
176     /* Test if QueryInterface increments ref counter for IFONTs */
177     ref = IFont_AddRef(font);
178     ok(ref == 3 ||
179        broken(ref == 1), /* win95 */
180            "IFont_QI expected ref value 3 but instead got %d\n", ref);
181     IFont_Release(font);
182
183     ok(pvObj != NULL,"IFont_QI does return NULL, instead of a ptr\n");
184
185     IFont_Release(font);
186     IFont_Release(font);
187 }
188
189 static void test_type_info(void)
190 {
191         LPVOID pvObj = NULL;
192         HRESULT hres;
193         IFontDisp*  fontdisp = NULL;
194         ITypeInfo* pTInfo;
195         WCHAR name_Name[] = {'N','a','m','e',0};
196         BSTR names[3];
197         UINT n;
198         LCID en_us = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),
199                 SORT_DEFAULT);
200         DISPPARAMS dispparams;
201         VARIANT varresult;
202
203         pOleCreateFontIndirect(NULL, &IID_IFontDisp, &pvObj);
204         fontdisp = pvObj;
205
206         hres = IFontDisp_GetTypeInfo(fontdisp, 0, en_us, &pTInfo);
207         ok(hres == S_OK, "GTI returned 0x%08x instead of S_OK.\n", hres);
208         ok(pTInfo != NULL, "GTI returned NULL.\n");
209
210         hres = ITypeInfo_GetNames(pTInfo, DISPID_FONT_NAME, names, 3, &n);
211         ok(hres == S_OK, "GetNames returned 0x%08x instead of S_OK.\n", hres);
212         ok(n == 1, "GetNames returned %d names instead of 1.\n", n);
213         ok(!lstrcmpiW(names[0],name_Name), "DISPID_FONT_NAME doesn't get 'Names'.\n");
214         SysFreeString(names[0]);
215
216         ITypeInfo_Release(pTInfo);
217
218         dispparams.cNamedArgs = 0;
219         dispparams.rgdispidNamedArgs = NULL;
220         dispparams.cArgs = 0;
221         dispparams.rgvarg = NULL;
222         VariantInit(&varresult);
223         hres = IFontDisp_Invoke(fontdisp, DISPID_FONT_NAME, &IID_NULL,
224             LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult,
225             NULL, NULL);
226         ok(hres == S_OK, "IFontDisp_Invoke return 0x%08x instead of S_OK.\n", hres);
227         VariantClear(&varresult);
228
229         IFontDisp_Release(fontdisp);
230 }
231
232 static HRESULT WINAPI FontEventsDisp_QueryInterface(
233         IFontEventsDisp *iface,
234     /* [in] */ REFIID riid,
235     /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
236 {
237     if (IsEqualIID(riid, &IID_IFontEventsDisp) || IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDispatch))
238     {
239         IUnknown_AddRef(iface);
240         *ppvObject = iface;
241         return S_OK;
242     }
243     else
244     {
245         *ppvObject = NULL;
246         return E_NOINTERFACE;
247     }
248 }
249
250 static ULONG WINAPI FontEventsDisp_AddRef(
251     IFontEventsDisp *iface)
252 {
253     return 2;
254 }
255
256 static ULONG WINAPI FontEventsDisp_Release(
257         IFontEventsDisp *iface)
258 {
259     return 1;
260 }
261
262 static int fonteventsdisp_invoke_called = 0;
263
264 static HRESULT WINAPI FontEventsDisp_Invoke(
265         IFontEventsDisp __RPC_FAR * iface,
266     /* [in] */ DISPID dispIdMember,
267     /* [in] */ REFIID riid,
268     /* [in] */ LCID lcid,
269     /* [in] */ WORD wFlags,
270     /* [out][in] */ DISPPARAMS __RPC_FAR *pDispParams,
271     /* [out] */ VARIANT __RPC_FAR *pVarResult,
272     /* [out] */ EXCEPINFO __RPC_FAR *pExcepInfo,
273     /* [out] */ UINT __RPC_FAR *puArgErr)
274 {
275     static const WCHAR wszBold[] = {'B','o','l','d',0};
276     ok(wFlags == INVOKE_FUNC, "invoke flags should have been INVOKE_FUNC instead of 0x%x\n", wFlags);
277     ok(dispIdMember == DISPID_FONT_CHANGED, "dispIdMember should have been DISPID_FONT_CHANGED instead of 0x%x\n", dispIdMember);
278     ok(pDispParams->cArgs == 1, "pDispParams->cArgs should have been 1 instead of %d\n", pDispParams->cArgs);
279     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]));
280     ok(!lstrcmpW(V_BSTR(&pDispParams->rgvarg[0]), wszBold), "String in first param should have been \"Bold\"\n");
281
282     fonteventsdisp_invoke_called++;
283     return S_OK;
284 }
285
286 static IFontEventsDispVtbl FontEventsDisp_Vtbl =
287 {
288     FontEventsDisp_QueryInterface,
289     FontEventsDisp_AddRef,
290     FontEventsDisp_Release,
291     NULL,
292     NULL,
293     NULL,
294     FontEventsDisp_Invoke
295 };
296
297 static IFontEventsDisp FontEventsDisp = { &FontEventsDisp_Vtbl };
298
299 static void test_font_events_disp(void)
300 {
301     IFont *pFont;
302     IFont *pFont2;
303     IConnectionPointContainer *pCPC;
304     IConnectionPoint *pCP;
305     FONTDESC fontdesc;
306     HRESULT hr;
307     DWORD dwCookie;
308     IFontDisp *pFontDisp;
309     DISPPARAMS dispparams;
310     VARIANTARG vararg;
311
312     fontdesc.cbSizeofstruct = sizeof(fontdesc);
313     fontdesc.lpstrName = MSSansSerif_font;
314     fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
315     fontdesc.sWeight = FW_NORMAL;
316     fontdesc.sCharset = 0;
317     fontdesc.fItalic = FALSE;
318     fontdesc.fUnderline = FALSE;
319     fontdesc.fStrikethrough = FALSE;
320
321     hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&pFont);
322     EXPECT_HR(hr, S_OK);
323
324     hr = IFont_QueryInterface(pFont, &IID_IConnectionPointContainer, (void **)&pCPC);
325     EXPECT_HR(hr, S_OK);
326
327     hr = IConnectionPointContainer_FindConnectionPoint(pCPC, &IID_IFontEventsDisp, &pCP);
328     EXPECT_HR(hr, S_OK);
329     IConnectionPointContainer_Release(pCPC);
330
331     hr = IConnectionPoint_Advise(pCP, (IUnknown *)&FontEventsDisp, &dwCookie);
332     EXPECT_HR(hr, S_OK);
333     IConnectionPoint_Release(pCP);
334
335     hr = IFont_put_Bold(pFont, TRUE);
336     EXPECT_HR(hr, S_OK);
337
338     ok(fonteventsdisp_invoke_called == 1, "IFontEventDisp::Invoke wasn't called once\n");
339
340     hr = IFont_QueryInterface(pFont, &IID_IFontDisp, (void **)&pFontDisp);
341     EXPECT_HR(hr, S_OK);
342
343     V_VT(&vararg) = VT_BOOL;
344     V_BOOL(&vararg) = VARIANT_FALSE;
345     dispparams.cNamedArgs = 0;
346     dispparams.rgdispidNamedArgs = NULL;
347     dispparams.cArgs = 1;
348     dispparams.rgvarg = &vararg;
349     hr = IFontDisp_Invoke(pFontDisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
350     EXPECT_HR(hr, S_OK);
351
352     IFontDisp_Release(pFontDisp);
353
354     ok(fonteventsdisp_invoke_called == 2, "IFontEventDisp::Invoke was called %d times instead of twice\n",
355         fonteventsdisp_invoke_called);
356
357     hr = IFont_Clone(pFont, &pFont2);
358     EXPECT_HR(hr, S_OK);
359     IFont_Release(pFont);
360
361     hr = IFont_put_Bold(pFont2, FALSE);
362     EXPECT_HR(hr, S_OK);
363
364     /* this test shows that the notification routine isn't called again */
365     ok(fonteventsdisp_invoke_called == 2, "IFontEventDisp::Invoke was called %d times instead of twice\n",
366         fonteventsdisp_invoke_called);
367
368     IFont_Release(pFont2);
369 }
370
371 static void test_names_ids(WCHAR* w_name_1, const char* a_name_1,
372                     WCHAR* w_name_2, const char* a_name_2,
373                     LCID lcid, DISPID id_1, DISPID id_2,
374                     HRESULT hres_expect, int numnames)
375 {
376     LPVOID pvObj = NULL;
377     IFontDisp *fontdisp = NULL;
378     HRESULT hres;
379     DISPID rgDispId[2] = {0xdeadbeef, 0xdeadbeef};
380     LPOLESTR names[2] = {w_name_1, w_name_2};
381
382     pOleCreateFontIndirect(NULL, &IID_IFontDisp, &pvObj);
383     fontdisp = pvObj;
384
385     hres = IFontDisp_GetIDsOfNames(fontdisp, &IID_NULL, names, numnames,
386                                    lcid, rgDispId);
387
388     /* test hres */
389     ok(hres == hres_expect,
390         "GetIDsOfNames: \"%s\", \"%s\" returns 0x%08x, expected 0x%08x.\n",
391         a_name_1, a_name_2, hres, hres_expect);
392
393     /* test first DISPID */
394     ok(rgDispId[0]==id_1,
395         "GetIDsOfNames: \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
396         a_name_1, rgDispId[0], id_1);
397
398     /* test second DISPID is present */
399     if (numnames == 2)
400     {
401         ok(rgDispId[1]==id_2,
402             "GetIDsOfNames: ..., \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
403             a_name_2, rgDispId[1], id_2);
404     }
405
406    IFontDisp_Release(fontdisp);
407 }
408
409 static void test_GetIDsOfNames(void)
410 {
411     WCHAR name_Name[] = {'N','a','m','e',0};
412     WCHAR name_Italic[] = {'I','t','a','l','i','c',0};
413     WCHAR name_Size[] = {'S','i','z','e',0};
414     WCHAR name_Bold[] = {'B','o','l','d',0};
415     WCHAR name_Underline[] = {'U','n','d','e','r','l','i','n','e',0};
416     WCHAR name_Strikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
417     WCHAR name_Weight[] = {'W','e','i','g','h','t',0};
418     WCHAR name_Charset[] = {'C','h','a','r','s','e','t',0};
419     WCHAR name_Foo[] = {'F','o','o',0};
420     WCHAR name_nAmE[] = {'n','A','m','E',0};
421     WCHAR name_Nom[] = {'N','o','m',0};
422
423     LCID en_us = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),
424                           SORT_DEFAULT);
425     LCID fr_fr = MAKELCID(MAKELANGID(LANG_FRENCH,SUBLANG_FRENCH),
426                           SORT_DEFAULT);
427
428     /* Test DISPID_FONTs for the various properties. */
429     test_names_ids(name_Name, "Name", NULL, "", en_us,
430                    DISPID_FONT_NAME, 0, S_OK,1);
431     test_names_ids(name_Size, "Size", NULL, "", en_us,
432                    DISPID_FONT_SIZE, 0, S_OK,1);
433     test_names_ids(name_Bold, "Bold", NULL, "", en_us,
434                    DISPID_FONT_BOLD, 0, S_OK,1);
435     test_names_ids(name_Italic, "Italic", NULL, "", en_us,
436                    DISPID_FONT_ITALIC, 0, S_OK,1);
437     test_names_ids(name_Underline, "Underline", NULL, "", en_us,
438                    DISPID_FONT_UNDER, 0, S_OK,1);
439     test_names_ids(name_Strikethrough, "Strikethrough", NULL, "", en_us,
440                    DISPID_FONT_STRIKE, 0, S_OK,1);
441     test_names_ids(name_Weight, "Weight", NULL, "", en_us,
442                    DISPID_FONT_WEIGHT, 0, S_OK,1);
443     test_names_ids(name_Charset, "Charset", NULL, "", en_us,
444                    DISPID_FONT_CHARSET, 0, S_OK,1);
445
446     /* Capitalization doesn't matter. */
447     test_names_ids(name_nAmE, "nAmE", NULL, "", en_us,
448                    DISPID_FONT_NAME, 0, S_OK,1);
449
450     /* Unknown name. */
451     test_names_ids(name_Foo, "Foo", NULL, "", en_us,
452                    DISPID_UNKNOWN, 0, DISP_E_UNKNOWNNAME,1);
453
454     /* Pass several names: first is processed,                */
455     /* second gets DISPID_UNKNOWN and doesn't affect retval.  */
456     test_names_ids(name_Italic, "Italic", name_Name, "Name", en_us,
457                    DISPID_FONT_ITALIC, DISPID_UNKNOWN, S_OK,2);
458     test_names_ids(name_Italic, "Italic", name_Foo, "Foo", en_us,
459                    DISPID_FONT_ITALIC, DISPID_UNKNOWN, S_OK,2);
460
461     /* Locale ID has no effect. */
462     test_names_ids(name_Name, "Name", NULL, "", fr_fr,
463                    DISPID_FONT_NAME, 0, S_OK,1);
464     test_names_ids(name_Nom, "This is not a font", NULL, "", fr_fr,
465                    DISPID_UNKNOWN, 0, DISP_E_UNKNOWNNAME,1);
466
467     /* One of the arguments are invalid */
468     test_names_ids(name_Name, "Name", NULL, "", en_us,
469                    0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
470     test_names_ids(name_Italic, "Italic", NULL, "", en_us,
471                    0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
472     test_names_ids(name_Foo, "Foo", NULL, "", en_us,
473                    0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
474
475     /* Crazy locale ID? */
476     test_names_ids(name_Name, "Name", NULL, "", -1,
477                    DISPID_FONT_NAME, 0, S_OK,1);
478 }
479
480 static void test_Invoke(void)
481 {
482     IFontDisp *fontdisp;
483     HRESULT hr;
484     VARIANTARG vararg;
485     DISPPARAMS dispparams;
486     VARIANT varresult;
487
488     hr = pOleCreateFontIndirect(NULL, &IID_IFontDisp, (void **)&fontdisp);
489     EXPECT_HR(hr, S_OK);
490
491     V_VT(&vararg) = VT_BOOL;
492     V_BOOL(&vararg) = VARIANT_FALSE;
493     dispparams.cNamedArgs = 0;
494     dispparams.rgdispidNamedArgs = NULL;
495     dispparams.cArgs = 1;
496     dispparams.rgvarg = &vararg;
497     hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_IFontDisp, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
498     EXPECT_HR(hr, DISP_E_UNKNOWNINTERFACE);
499
500     dispparams.cArgs = 0;
501     dispparams.rgvarg = NULL;
502     hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
503     EXPECT_HR(hr, DISP_E_BADPARAMCOUNT);
504
505     hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, NULL, NULL, NULL, NULL);
506     EXPECT_HR(hr, DISP_E_PARAMNOTOPTIONAL);
507
508     hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, NULL, NULL, NULL);
509     EXPECT_HR(hr, DISP_E_PARAMNOTOPTIONAL);
510
511     hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, &varresult, NULL, NULL);
512     EXPECT_HR(hr, S_OK);
513
514     hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_METHOD, NULL, &varresult, NULL, NULL);
515     EXPECT_HR(hr, DISP_E_MEMBERNOTFOUND);
516
517     hr = IFontDisp_Invoke(fontdisp, 0xdeadbeef, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, &varresult, NULL, NULL);
518     EXPECT_HR(hr, DISP_E_MEMBERNOTFOUND);
519
520     dispparams.cArgs = 1;
521     dispparams.rgvarg = &vararg;
522     hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, &dispparams, &varresult, NULL, NULL);
523     EXPECT_HR(hr, S_OK);
524
525     IFontDisp_Release(fontdisp);
526 }
527
528 static void test_IsEqual(void)
529 {
530     FONTDESC fd;
531     IFont* ifnt = NULL;
532     IFont* ifnt2 = NULL;
533     HRESULT hres;
534
535     /* Basic font description */
536     fd.cbSizeofstruct = sizeof(FONTDESC);
537     fd.lpstrName      = system_font;
538     S(fd.cySize).Lo   = 100;
539     S(fd.cySize).Hi   = 100;
540     fd.sWeight        = 0;
541     fd.sCharset       = 0;
542     fd.fItalic        = 0;
543     fd.fUnderline     = 0;
544     fd.fStrikethrough = 0;
545
546     /* Create font */
547     pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt);
548
549     /* Test equal fonts */
550     pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
551     hres = IFont_IsEqual(ifnt,ifnt2);
552     ok(hres == S_OK,
553         "IFont_IsEqual: (EQUAL) Expected S_OK but got 0x%08x\n",hres);
554     IFont_Release(ifnt2);
555
556     /* Check for bad pointer */
557     hres = IFont_IsEqual(ifnt,NULL);
558     ok(hres == E_POINTER,
559         "IFont_IsEqual: (NULL) Expected 0x80004003 but got 0x%08x\n",hres);
560
561     /* Test strName */
562     fd.lpstrName = arial_font;
563     pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
564     hres = IFont_IsEqual(ifnt,ifnt2);
565     ok(hres == S_FALSE,
566         "IFont_IsEqual: (strName) Expected S_FALSE but got 0x%08x\n",hres);
567     fd.lpstrName = system_font;
568     IFont_Release(ifnt2);
569
570     /* Test lo font size */
571     S(fd.cySize).Lo = 10000;
572     pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
573     hres = IFont_IsEqual(ifnt,ifnt2);
574     ok(hres == S_FALSE,
575         "IFont_IsEqual: (Lo font size) Expected S_FALSE but got 0x%08x\n",hres);
576     S(fd.cySize).Lo = 100;
577     IFont_Release(ifnt2);
578
579     /* Test hi font size */
580     S(fd.cySize).Hi = 10000;
581     pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
582     hres = IFont_IsEqual(ifnt,ifnt2);
583     ok(hres == S_FALSE,
584         "IFont_IsEqual: (Hi font size) Expected S_FALSE but got 0x%08x\n",hres);
585     S(fd.cySize).Hi = 100;
586     IFont_Release(ifnt2);
587
588     /* Test font weight  */
589     fd.sWeight = 100;
590     pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
591     hres = IFont_IsEqual(ifnt,ifnt2);
592     ok(hres == S_FALSE,
593         "IFont_IsEqual: (Weight) Expected S_FALSE but got 0x%08x\n",hres);
594     fd.sWeight = 0;
595     IFont_Release(ifnt2);
596
597     /* Test charset */
598     fd.sCharset = 1;
599     pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
600     hres = IFont_IsEqual(ifnt,ifnt2);
601     ok(hres == S_FALSE,
602         "IFont_IsEqual: (Charset) Expected S_FALSE but got 0x%08x\n",hres);
603     fd.sCharset = 0;
604     IFont_Release(ifnt2);
605
606     /* Test italic setting */
607     fd.fItalic = 1;
608     pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
609     hres = IFont_IsEqual(ifnt,ifnt2);
610     ok(hres == S_FALSE,
611         "IFont_IsEqual: (Italic) Expected S_FALSE but got 0x%08x\n",hres);
612     fd.fItalic = 0;
613     IFont_Release(ifnt2);
614
615     /* Test underline setting */
616     fd.fUnderline = 1;
617     pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
618     hres = IFont_IsEqual(ifnt,ifnt2);
619     ok(hres == S_FALSE,
620         "IFont_IsEqual: (Underline) Expected S_FALSE but got 0x%08x\n",hres);
621     fd.fUnderline = 0;
622     IFont_Release(ifnt2);
623
624     /* Test strikethrough setting */
625     fd.fStrikethrough = 1;
626     pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
627     hres = IFont_IsEqual(ifnt,ifnt2);
628     ok(hres == S_FALSE,
629         "IFont_IsEqual: (Strikethrough) Expected S_FALSE but got 0x%08x\n",hres);
630     fd.fStrikethrough = 0;
631     IFont_Release(ifnt2);
632
633     /* Free IFont. */
634     IFont_Release(ifnt);
635 }
636
637 static void test_ReleaseHfont(void)
638 {
639     FONTDESC fd;
640     LPVOID pvObj1 = NULL;
641     LPVOID pvObj2 = NULL;
642     IFont* ifnt1 = NULL;
643     IFont* ifnt2 = NULL;
644     HFONT hfnt1 = 0;
645     HFONT hfnt2 = 0;
646     HRESULT hres;
647
648     /* Basic font description */
649     fd.cbSizeofstruct = sizeof(FONTDESC);
650     fd.lpstrName      = system_font;
651     S(fd.cySize).Lo   = 100;
652     S(fd.cySize).Hi   = 100;
653     fd.sWeight        = 0;
654     fd.sCharset       = 0;
655     fd.fItalic        = 0;
656     fd.fUnderline     = 0;
657     fd.fStrikethrough = 0;
658
659     /* Create HFONTs and IFONTs */
660     pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj1);
661     ifnt1 = pvObj1;
662     IFont_get_hFont(ifnt1,&hfnt1);
663     fd.lpstrName = arial_font;
664     pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
665     ifnt2 = pvObj2;
666     IFont_get_hFont(ifnt2,&hfnt2);
667
668     /* Try invalid HFONT */
669     hres = IFont_ReleaseHfont(ifnt1,NULL);
670     ok(hres == E_INVALIDARG,
671         "IFont_ReleaseHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
672         hres);
673
674     /* Try to add a bad HFONT */
675     hres = IFont_ReleaseHfont(ifnt1,(HFONT)32);
676     ok(hres == S_FALSE,
677         "IFont_ReleaseHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
678         hres);
679
680     /* Release all refs */
681     hres = IFont_ReleaseHfont(ifnt1,hfnt1);
682     ok(hres == S_OK,
683         "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
684         hres);
685
686     hres = IFont_ReleaseHfont(ifnt2,hfnt2);
687     ok(hres == S_OK,
688         "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
689         hres);
690
691     /* Check that both lists are empty */
692     hres = IFont_ReleaseHfont(ifnt1,hfnt1);
693     ok(hres == S_FALSE,
694         "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
695         hres);
696
697     /* The list should be empty */
698     hres = IFont_ReleaseHfont(ifnt2,hfnt2);
699     ok(hres == S_FALSE,
700         "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
701         hres);
702
703     IFont_Release(ifnt1);
704     IFont_Release(ifnt2);
705 }
706
707 static void test_AddRefHfont(void)
708 {
709     FONTDESC fd;
710     IFont* ifnt1 = NULL;
711     IFont* ifnt2 = NULL;
712     IFont* ifnt3 = NULL;
713     HFONT hfnt1 = 0;
714     HFONT hfnt2 = 0;
715     HFONT hfnt3 = 0;
716     HRESULT hres;
717
718     /* Basic font description */
719     fd.cbSizeofstruct = sizeof(FONTDESC);
720     fd.lpstrName      = system_font;
721     S(fd.cySize).Lo   = 100;
722     S(fd.cySize).Hi   = 100;
723     fd.sWeight        = 0;
724     fd.sCharset       = 0;
725     fd.fItalic        = 0;
726     fd.fUnderline     = 0;
727     fd.fStrikethrough = 0;
728
729     /* Create HFONTs and IFONTs */
730     pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt1);
731     IFont_get_hFont(ifnt1,&hfnt1);
732     fd.lpstrName = arial_font;
733     pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
734     IFont_get_hFont(ifnt2,&hfnt2);
735
736     /* Try invalid HFONT */
737     hres = IFont_AddRefHfont(ifnt1,NULL);
738     ok(hres == E_INVALIDARG,
739         "IFont_AddRefHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
740         hres);
741
742     /* Try to add a bad HFONT */
743     hres = IFont_AddRefHfont(ifnt1,(HFONT)32);
744     ok(hres == S_FALSE,
745         "IFont_AddRefHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
746         hres);
747
748     /* Add simple IFONT HFONT pair */
749     hres = IFont_AddRefHfont(ifnt1,hfnt1);
750     ok(hres == S_OK,
751         "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
752         hres);
753
754     /* IFONT and HFONT do not have to be the same (always looks at HFONT) */
755     hres = IFont_AddRefHfont(ifnt2,hfnt1);
756     ok(hres == S_OK,
757         "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
758         hres);
759
760     /* Release all hfnt1 refs */
761     hres = IFont_ReleaseHfont(ifnt1,hfnt1);
762     ok(hres == S_OK,
763         "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
764         hres);
765
766     hres = IFont_ReleaseHfont(ifnt1,hfnt1);
767     ok(hres == S_OK,
768         "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
769         hres);
770
771     hres = IFont_ReleaseHfont(ifnt1,hfnt1);
772     ok(hres == S_OK,
773         "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
774         hres);
775
776     /* Check if hfnt1 is empty */
777     hres = IFont_ReleaseHfont(ifnt1,hfnt1);
778     ok(hres == S_FALSE,
779         "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
780         hres);
781
782     /* Release all hfnt2 refs */
783     hres = IFont_ReleaseHfont(ifnt2,hfnt2);
784     ok(hres == S_OK,
785         "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
786         hres);
787
788     /* Check if hfnt2 is empty */
789     hres = IFont_ReleaseHfont(ifnt2,hfnt2);
790     ok(hres == S_FALSE,
791         "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
792         hres);
793
794     /* Show that releasing an IFONT does not always release it from the HFONT cache. */
795
796     IFont_Release(ifnt1);
797
798     /* Add a reference for destroyed hfnt1 */
799     hres = IFont_AddRefHfont(ifnt2,hfnt1);
800     ok(hres == S_OK,
801         "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
802         hres);
803
804     /* Decrement reference for destroyed hfnt1 */
805     hres = IFont_ReleaseHfont(ifnt2,hfnt1);
806     ok(hres == S_OK ||
807        hres == S_FALSE, /* <= win2k */
808         "IFont_AddRefHfont: (Release ref) Expected S_OK or S_FALSE but got 0x%08x\n",
809         hres);
810
811     /* Shows that releasing all IFONT's does clear the HFONT cache. */
812
813     IFont_Release(ifnt2);
814
815     /* Need to make a new IFONT for testing */
816     fd.fUnderline = 1;
817     pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt3);
818     IFont_get_hFont(ifnt3,&hfnt3);
819
820     /* Add a reference for destroyed hfnt1 */
821     hres = IFont_AddRefHfont(ifnt3,hfnt1);
822     ok(hres == S_FALSE,
823         "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
824         hres);
825
826     /* Decrement reference for destroyed hfnt1 */
827     hres = IFont_ReleaseHfont(ifnt3,hfnt1);
828     ok(hres == S_FALSE,
829         "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
830         hres);
831
832     IFont_Release(ifnt3);
833 }
834
835 static void test_returns(void)
836 {
837     IFont *pFont;
838     FONTDESC fontdesc;
839     HRESULT hr;
840
841     fontdesc.cbSizeofstruct = sizeof(fontdesc);
842     fontdesc.lpstrName = MSSansSerif_font;
843     fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
844     fontdesc.sWeight = FW_NORMAL;
845     fontdesc.sCharset = 0;
846     fontdesc.fItalic = FALSE;
847     fontdesc.fUnderline = FALSE;
848     fontdesc.fStrikethrough = FALSE;
849
850     hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&pFont);
851     EXPECT_HR(hr, S_OK);
852
853     hr = IFont_put_Name(pFont, NULL);
854     EXPECT_HR(hr, CTL_E_INVALIDPROPERTYVALUE);
855
856     hr = IFont_get_Name(pFont, NULL);
857     EXPECT_HR(hr, E_POINTER);
858
859     hr = IFont_get_Size(pFont, NULL);
860     EXPECT_HR(hr, E_POINTER);
861
862     hr = IFont_get_Bold(pFont, NULL);
863     EXPECT_HR(hr, E_POINTER);
864
865     IFont_Release(pFont);
866 }
867
868 static void test_hfont_lifetime(void)
869 {
870     IFont *font, *font2;
871     FONTDESC fontdesc;
872     HRESULT hr;
873     HFONT hfont, first_hfont = NULL;
874     CY size;
875     DWORD obj_type;
876     int i;
877
878     fontdesc.cbSizeofstruct = sizeof(fontdesc);
879     fontdesc.lpstrName = arial_font;
880     fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
881     fontdesc.sWeight = FW_NORMAL;
882     fontdesc.sCharset = ANSI_CHARSET;
883     fontdesc.fItalic = FALSE;
884     fontdesc.fUnderline = FALSE;
885     fontdesc.fStrikethrough = FALSE;
886
887     hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
888     EXPECT_HR(hr, S_OK);
889
890     hr = IFont_get_hFont(font, &hfont);
891     EXPECT_HR(hr, S_OK);
892
893     /* show that if the font is updated the old hfont is deleted when the
894        new font is realized */
895     for(i = 0; i < 100; i++)
896     {
897         HFONT last_hfont = hfont;
898
899         size.int64 = (i + 10) * 20000;
900
901         obj_type = GetObjectType(hfont);
902         ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
903
904         hr = IFont_put_Size(font, size);
905         EXPECT_HR(hr, S_OK);
906
907         /* put_Size doesn't cause the new font to be realized */
908         obj_type = GetObjectType(last_hfont);
909         ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
910
911         hr = IFont_get_hFont(font, &hfont);
912         EXPECT_HR(hr, S_OK);
913
914         obj_type = GetObjectType(last_hfont);
915         ok(obj_type == 0, "%d: got obj type %d\n", i, obj_type);
916     }
917
918     /* now show that if we take a reference on the hfont, it persists
919        until the font object is released */
920     for(i = 0; i < 100; i++)
921     {
922         size.int64 = (i + 10) * 20000;
923
924         obj_type = GetObjectType(hfont);
925         ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
926
927         hr = IFont_put_Size(font, size);
928         EXPECT_HR(hr, S_OK);
929
930         hr = IFont_get_hFont(font, &hfont);
931         EXPECT_HR(hr, S_OK);
932
933         hr = IFont_AddRefHfont(font, hfont);
934         EXPECT_HR(hr, S_OK);
935
936         if(i == 0) first_hfont = hfont;
937         obj_type = GetObjectType(first_hfont);
938         ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
939     }
940
941     IFont_Release(font);
942
943     obj_type = GetObjectType(first_hfont);
944     ok(obj_type == 0, "got obj type %d\n", obj_type);
945
946     /* An AddRefHfont followed by a ReleaseHfont means the font doesn't not persist
947        through re-realization */
948
949     hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
950     EXPECT_HR(hr, S_OK);
951
952     hr = IFont_get_hFont(font, &hfont);
953     EXPECT_HR(hr, S_OK);
954
955     for(i = 0; i < 100; i++)
956     {
957         HFONT last_hfont = hfont;
958
959         size.int64 = (i + 10) * 20000;
960
961         obj_type = GetObjectType(hfont);
962         ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
963
964         hr = IFont_put_Size(font, size);
965         EXPECT_HR(hr, S_OK);
966
967         /* put_Size doesn't cause the new font to be realized */
968         obj_type = GetObjectType(last_hfont);
969         ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
970
971         hr = IFont_get_hFont(font, &hfont);
972         EXPECT_HR(hr, S_OK);
973
974         hr = IFont_AddRefHfont(font, hfont);
975         EXPECT_HR(hr, S_OK);
976
977         hr = IFont_ReleaseHfont(font, hfont);
978         EXPECT_HR(hr, S_OK);
979
980         obj_type = GetObjectType(last_hfont);
981         ok(obj_type == 0, "%d: got obj type %d\n", i, obj_type);
982     }
983
984     /* Interestingly if we release a nonexistent reference on the hfont,
985      * it persists until the font object is released
986      */
987     for(i = 0; i < 100; i++)
988     {
989         size.int64 = (i + 10) * 20000;
990
991         obj_type = GetObjectType(hfont);
992         ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
993
994         hr = IFont_put_Size(font, size);
995         EXPECT_HR(hr, S_OK);
996
997         hr = IFont_get_hFont(font, &hfont);
998         EXPECT_HR(hr, S_OK);
999
1000         hr = IFont_ReleaseHfont(font, hfont);
1001         EXPECT_HR(hr, S_OK);
1002
1003         if(i == 0) first_hfont = hfont;
1004         obj_type = GetObjectType(first_hfont);
1005         ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
1006     }
1007
1008     IFont_Release(font);
1009
1010     obj_type = GetObjectType(first_hfont);
1011     ok(obj_type == 0, "got obj type %d\n", obj_type);
1012
1013     /* If we take two internal references on a hfont then we can release
1014        it twice.  So it looks like there's a total reference count
1015        that includes internal and external references */
1016
1017     hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
1018     EXPECT_HR(hr, S_OK);
1019     hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font2);
1020     EXPECT_HR(hr, S_OK);
1021
1022     hr = IFont_get_hFont(font, &hfont);
1023     EXPECT_HR(hr, S_OK);
1024     hr = IFont_get_hFont(font2, &first_hfont);
1025     EXPECT_HR(hr, S_OK);
1026 todo_wine
1027     ok(hfont == first_hfont, "fonts differ\n");
1028     hr = IFont_ReleaseHfont(font, hfont);
1029     EXPECT_HR(hr, S_OK);
1030     hr = IFont_ReleaseHfont(font, hfont);
1031 todo_wine
1032     EXPECT_HR(hr, S_OK);
1033     hr = IFont_ReleaseHfont(font, hfont);
1034     EXPECT_HR(hr, S_FALSE);
1035
1036     obj_type = GetObjectType(hfont);
1037     ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
1038
1039     IFont_Release(font);
1040
1041     obj_type = GetObjectType(hfont);
1042     ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
1043
1044     IFont_Release(font2);
1045
1046     obj_type = GetObjectType(hfont);
1047     ok(obj_type == 0, "got obj type %d\n", obj_type);
1048 }
1049
1050 static void test_realization(void)
1051 {
1052     IFont *font;
1053     FONTDESC fontdesc;
1054     HRESULT hr;
1055     BSTR name;
1056     SHORT cs;
1057
1058     /* Try to create a symbol only font (marlett) with charset
1059        set to ANSI.  This will result in another, ANSI, font
1060        being selected */
1061     fontdesc.cbSizeofstruct = sizeof(fontdesc);
1062     fontdesc.lpstrName = marlett_font;
1063     fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
1064     fontdesc.sWeight = FW_NORMAL;
1065     fontdesc.sCharset = ANSI_CHARSET;
1066     fontdesc.fItalic = FALSE;
1067     fontdesc.fUnderline = FALSE;
1068     fontdesc.fStrikethrough = FALSE;
1069
1070     hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
1071     EXPECT_HR(hr, S_OK);
1072
1073     hr = IFont_get_Charset(font, &cs);
1074     EXPECT_HR(hr, S_OK);
1075     ok(cs == ANSI_CHARSET, "got charset %d\n", cs);
1076
1077     IFont_Release(font);
1078
1079     /* Now create an ANSI font and change the name to marlett */
1080
1081     fontdesc.lpstrName = arial_font;
1082
1083     hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
1084     EXPECT_HR(hr, S_OK);
1085
1086     hr = IFont_get_Charset(font, &cs);
1087     EXPECT_HR(hr, S_OK);
1088     ok(cs == ANSI_CHARSET, "got charset %d\n", cs);
1089
1090     name = SysAllocString(marlett_font);
1091     hr = IFont_put_Name(font, name);
1092     EXPECT_HR(hr, S_OK);
1093     SysFreeString(name);
1094
1095     hr = IFont_get_Name(font, &name);
1096     EXPECT_HR(hr, S_OK);
1097     ok(!lstrcmpiW(name, marlett_font), "got name %s\n", wine_dbgstr_w(name));
1098     SysFreeString(name);
1099
1100     hr = IFont_get_Charset(font, &cs);
1101     EXPECT_HR(hr, S_OK);
1102     ok(cs == SYMBOL_CHARSET, "got charset %d\n", cs);
1103
1104     IFont_Release(font);
1105 }
1106
1107 static void test_OleCreateFontIndirect(void)
1108 {
1109     FONTDESC fontdesc;
1110     IFont *font;
1111     HRESULT hr;
1112
1113     fontdesc.cbSizeofstruct = sizeof(fontdesc);
1114     fontdesc.lpstrName = arial_font;
1115     fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
1116     fontdesc.sWeight = FW_NORMAL;
1117     fontdesc.sCharset = ANSI_CHARSET;
1118     fontdesc.fItalic = FALSE;
1119     fontdesc.fUnderline = FALSE;
1120     fontdesc.fStrikethrough = FALSE;
1121
1122     hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
1123     EXPECT_HR(hr, S_OK);
1124     IFont_Release(font);
1125
1126     /* play with cbSizeofstruct value */
1127     fontdesc.cbSizeofstruct = sizeof(fontdesc)-1;
1128     hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
1129     EXPECT_HR(hr, S_OK);
1130     IFont_Release(font);
1131
1132     fontdesc.cbSizeofstruct = sizeof(fontdesc)+1;
1133     hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
1134     EXPECT_HR(hr, S_OK);
1135     IFont_Release(font);
1136
1137     fontdesc.cbSizeofstruct = 0;
1138     hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
1139     EXPECT_HR(hr, S_OK);
1140     IFont_Release(font);
1141 }
1142
1143 START_TEST(olefont)
1144 {
1145     hOleaut32 = GetModuleHandleA("oleaut32.dll");
1146     pOleCreateFontIndirect = (void*)GetProcAddress(hOleaut32, "OleCreateFontIndirect");
1147     if (!pOleCreateFontIndirect)
1148     {
1149         win_skip("OleCreateFontIndirect not available\n");
1150         return;
1151     }
1152
1153     test_QueryInterface();
1154     test_type_info();
1155     test_ifont_sizes();
1156     test_font_events_disp();
1157     test_GetIDsOfNames();
1158     test_Invoke();
1159     test_IsEqual();
1160     test_ReleaseHfont();
1161     test_AddRefHfont();
1162     test_returns();
1163     test_hfont_lifetime();
1164     test_realization();
1165     test_OleCreateFontIndirect();
1166 }