4 * Copyright 2003 Marcus Meissner
5 * Copyright 2006 (Google) Benjamin Arai
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.
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.
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
30 #include <wine/test.h>
43 DEFINE_GUID(GUID_NULL
,0,0,0,0,0,0,0,0,0,0,0);
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 };
50 static HMODULE hOleaut32
;
52 static HRESULT (WINAPI
*pOleCreateFontIndirect
)(LPFONTDESC
,REFIID
,LPVOID
*);
54 #define EXPECT_HR(hr,hr_exp) \
55 ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
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
)
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
;
81 fd
.fUnderline
= FALSE
;
82 fd
.fStrikethrough
= FALSE
;
84 /* Create font, test that it worked. */
85 hres
= pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj
);
87 ok(hres
== S_OK
,"%s: OCFI returns 0x%08x instead of S_OK.\n",
89 ok(pvObj
!= NULL
,"%s: OCFI returns NULL.\n", test_name
);
91 /* Change the scaling ratio */
92 hres
= IFont_SetRatio(ifnt
, ratio_logical
, ratio_himetric
);
93 ok((ratio_logical
&& ratio_himetric
) ? hres
== S_OK
: hres
== E_FAIL
,
94 "%s: IFont_SetRatio unexpectedly returned 0x%08x.\n", test_name
, hres
);
97 hres
= IFont_get_Size(ifnt
, &psize
);
98 ok(hres
== S_OK
,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
101 /* Check returned size - allow for errors due to rounding & font realization. */
102 ok((abs(S(psize
).Lo
- lo_size
) < 10000) && S(psize
).Hi
== hi_size
,
103 "%s: IFont_get_Size: Lo=%d, Hi=%d; expected Lo=%d, Hi=%d.\n",
104 test_name
, S(psize
).Lo
, S(psize
).Hi
, lo_size
, hi_size
);
106 /* Check hFont size. */
107 hres
= IFont_get_hFont (ifnt
, &hfont
);
108 ok(hres
== S_OK
, "%s: IFont_get_hFont returns 0x%08x instead of S_OK.\n",
110 rtnval
= GetObjectA(hfont
, sizeof(LOGFONTA
), &lf
);
111 ok(rtnval
> 0, "GetObject(hfont) failed\n");
113 /* Since font scaling may encounter rounding errors, allow 1 pixel deviation. */
114 ok(abs(lf
.lfHeight
- hfont_height
) <= 1,
115 "%s: hFont has lf.lfHeight=%d, expected %d.\n",
116 test_name
, lf
.lfHeight
, hfont_height
);
122 static void test_ifont_sizes(void)
124 /* Test various size operations and conversions. */
125 /* Add more as needed. */
127 /* Results of first 2 tests depend on display resolution. */
129 LONG dpi
= GetDeviceCaps(hdc
, LOGPIXELSY
); /* expected results depend on display DPI */
131 if(dpi
== 96) /* normal resolution display */
133 test_ifont_size(180000, 0, 0, 0, -24, "default"); /* normal font */
134 test_ifont_size(186000, 0, 0, 0, -25, "rounding"); /* test rounding */
135 } else if(dpi
== 72) /* low resolution display */
137 test_ifont_size(180000, 0, 0, 0, -18, "default"); /* normal font */
138 test_ifont_size(186000, 0, 0, 0, -19, "rounding"); /* test rounding */
139 } else if(dpi
== 120) /* high resolution display */
141 test_ifont_size(180000, 0, 0, 0, -30, "default"); /* normal font */
142 test_ifont_size(186000, 0, 0, 0, -31, "rounding"); /* test rounding */
144 skip("Skipping resolution dependent font size tests - display resolution is %d\n", dpi
);
146 /* Next 4 tests specify a scaling ratio, so display resolution is not a factor. */
147 test_ifont_size(180000, 0, 72, 2540, -18, "ratio1"); /* change ratio */
148 test_ifont_size(180000, 0, 144, 2540, -36, "ratio2"); /* another ratio */
149 test_ifont_size(180000, 0, 72, 1270, -36, "ratio3"); /* yet another ratio */
150 test_ifont_size(186000, 0, 72, 2540, -19, "rounding+ratio"); /* test rounding with ratio */
152 /* test various combinations of logical == himetric */
153 test_ifont_size(180000, 0, 10, 10, -635, "identical ratio 1");
154 test_ifont_size(240000, 0, 10, 10, -848, "identical ratio 2");
155 test_ifont_size(300000, 0, 10, 10, -1058, "identical ratio 3");
157 /* test various combinations of logical and himetric both set to 1 */
158 test_ifont_size(180000, 0, 1, 1, -24, "1:1 ratio 1");
159 test_ifont_size(240000, 0, 1, 1, -32, "1:1 ratio 2");
160 test_ifont_size(300000, 0, 1, 1, -40, "1:1 ratio 3");
162 /* test various combinations of logical set to 1 */
163 test_ifont_size(180000, 0, 1, 0, -24, "1:0 ratio 1");
164 test_ifont_size(240000, 0, 1, 0, -32, "1:0 ratio 2");
165 test_ifont_size(300000, 0, 1, 0, -40, "1:0 ratio 3");
167 /* test various combinations of himetric set to 1 */
168 test_ifont_size(180000, 0, 0, 1, -24, "0:1 ratio 1");
169 test_ifont_size(240000, 0, 0, 1, -32, "0:1 ratio 2");
170 test_ifont_size(300000, 0, 0, 1, -40, "0:1 ratio 3");
172 /* test various combinations of 2:1 logical:himetric */
173 test_ifont_size(180000, 0, 2, 1, -1270, "2:1 ratio 1");
174 test_ifont_size(240000, 0, 2, 1, -1694, "2:1 ratio 2");
175 test_ifont_size(300000, 0, 2, 1, -2117, "2:1 ratio 3");
177 /* test various combinations of 1:2 logical:himetric */
178 test_ifont_size(180000, 0, 1, 2, -318, "1:2 ratio 1");
179 test_ifont_size(240000, 0, 1, 2, -424, "1:2 ratio 2");
180 test_ifont_size(300000, 0, 1, 2, -529, "1:2 ratio 3");
182 /* test various combinations of logical and himetric both set to 2 */
183 test_ifont_size(180000, 0, 2, 2, -635, "2:2 ratio 1");
184 test_ifont_size(240000, 0, 2, 2, -848, "2:2 ratio 2");
185 test_ifont_size(300000, 0, 2, 2, -1058, "2:2 ratio 3");
188 static void test_QueryInterface(void)
195 hr
= pOleCreateFontIndirect(NULL
, &IID_IFont
, NULL
);
196 EXPECT_HR(hr
, E_POINTER
);
198 hr
= pOleCreateFontIndirect(NULL
, &IID_IFont
, &pvObj
);
202 ok(font
!= NULL
,"OCFI (NULL,..) returns NULL, instead of !NULL\n");
205 hr
= IFont_QueryInterface( font
, &IID_IFont
, &pvObj
);
208 /* Test if QueryInterface increments ref counter for IFONTs */
209 ref
= IFont_AddRef(font
);
211 broken(ref
== 1), /* win95 */
212 "IFont_QI expected ref value 3 but instead got %d\n", ref
);
215 ok(pvObj
!= NULL
,"IFont_QI does return NULL, instead of a ptr\n");
221 static void test_type_info(void)
225 IFontDisp
* fontdisp
= NULL
;
227 WCHAR name_Name
[] = {'N','a','m','e',0};
230 LCID en_us
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),
232 DISPPARAMS dispparams
;
235 pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, &pvObj
);
238 hres
= IFontDisp_GetTypeInfo(fontdisp
, 0, en_us
, &pTInfo
);
239 ok(hres
== S_OK
, "GTI returned 0x%08x instead of S_OK.\n", hres
);
240 ok(pTInfo
!= NULL
, "GTI returned NULL.\n");
242 hres
= ITypeInfo_GetNames(pTInfo
, DISPID_FONT_NAME
, names
, 3, &n
);
243 ok(hres
== S_OK
, "GetNames returned 0x%08x instead of S_OK.\n", hres
);
244 ok(n
== 1, "GetNames returned %d names instead of 1.\n", n
);
245 ok(!lstrcmpiW(names
[0],name_Name
), "DISPID_FONT_NAME doesn't get 'Names'.\n");
246 SysFreeString(names
[0]);
248 ITypeInfo_Release(pTInfo
);
250 dispparams
.cNamedArgs
= 0;
251 dispparams
.rgdispidNamedArgs
= NULL
;
252 dispparams
.cArgs
= 0;
253 dispparams
.rgvarg
= NULL
;
254 VariantInit(&varresult
);
255 hres
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_NAME
, &IID_NULL
,
256 LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
,
258 ok(hres
== S_OK
, "IFontDisp_Invoke return 0x%08x instead of S_OK.\n", hres
);
259 VariantClear(&varresult
);
261 IFontDisp_Release(fontdisp
);
264 static HRESULT WINAPI
FontEventsDisp_QueryInterface(IFontEventsDisp
*iface
, REFIID riid
, void **ppvObject
)
266 if (IsEqualIID(riid
, &IID_IFontEventsDisp
) || IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDispatch
))
268 IFontEventsDisp_AddRef(iface
);
275 return E_NOINTERFACE
;
279 static ULONG WINAPI
FontEventsDisp_AddRef(
280 IFontEventsDisp
*iface
)
285 static ULONG WINAPI
FontEventsDisp_Release(
286 IFontEventsDisp
*iface
)
291 static HRESULT WINAPI
FontEventsDisp_GetTypeInfoCount(IFontEventsDisp
*iface
, UINT
*pctinfo
)
293 ok(0, "unexpected call\n");
297 static HRESULT WINAPI
FontEventsDisp_GetTypeInfo(IFontEventsDisp
*iface
, UINT itinfo
, LCID lcid
, ITypeInfo
**pptinfo
)
299 ok(0, "unexpected call\n");
303 static HRESULT WINAPI
FontEventsDisp_GetIDsOfNames(IFontEventsDisp
*iface
, REFIID riid
, LPOLESTR
*names
, UINT cNames
, LCID lcid
,
306 ok(0, "unexpected call\n");
310 static int fonteventsdisp_invoke_called
;
311 static BSTR fonteventsdisp_invoke_arg0
;
313 static HRESULT WINAPI
FontEventsDisp_Invoke(
314 IFontEventsDisp
*iface
,
319 DISPPARAMS
*pDispParams
,
321 EXCEPINFO
*pExcepInfo
,
324 VARIANTARG
*arg0
= &pDispParams
->rgvarg
[0];
326 ok(dispid
== DISPID_FONT_CHANGED
, "expected DISPID_FONT_CHANGED instead of 0x%x\n", dispid
);
327 ok(IsEqualGUID(riid
, &GUID_NULL
), "got riid %s\n", wine_dbgstr_guid(riid
));
328 ok(wFlags
== INVOKE_FUNC
, "expected INVOKE_FUNC instead of 0x%x\n", wFlags
);
329 ok(pDispParams
->cArgs
== 1, "expected arg count 1, got %d\n", pDispParams
->cArgs
);
330 ok(V_VT(arg0
) == VT_BSTR
, "expected VT_BSTR, got %d\n", V_VT(arg0
));
332 fonteventsdisp_invoke_arg0
= SysAllocString(V_BSTR(arg0
));
333 fonteventsdisp_invoke_called
++;
337 static IFontEventsDispVtbl FontEventsDisp_Vtbl
=
339 FontEventsDisp_QueryInterface
,
340 FontEventsDisp_AddRef
,
341 FontEventsDisp_Release
,
342 FontEventsDisp_GetTypeInfoCount
,
343 FontEventsDisp_GetTypeInfo
,
344 FontEventsDisp_GetIDsOfNames
,
345 FontEventsDisp_Invoke
348 static IFontEventsDisp FontEventsDisp
= { &FontEventsDisp_Vtbl
};
356 static void test_font_events_disp(void)
358 static const WCHAR nameW
[] = {'N','a','m','e',0};
359 static const WCHAR sizeW
[] = {'S','i','z','e',0};
360 static const WCHAR boldW
[] = {'B','o','l','d',0};
361 static const WCHAR italicW
[] = {'I','t','a','l','i','c',0};
362 static const WCHAR underlineW
[] = {'U','n','d','e','r','l','i','n','e',0};
363 static const WCHAR strikeW
[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
364 static const WCHAR weightW
[] = {'W','e','i','g','h','t',0};
365 static const WCHAR charsetW
[] = {'C','h','a','r','s','e','t',0};
367 static const struct font_dispid font_dispids
[] =
369 { DISPID_FONT_NAME
, nameW
},
370 { DISPID_FONT_SIZE
, sizeW
},
371 { DISPID_FONT_BOLD
, boldW
},
372 { DISPID_FONT_ITALIC
, italicW
},
373 { DISPID_FONT_UNDER
, underlineW
},
374 { DISPID_FONT_STRIKE
, strikeW
},
375 { DISPID_FONT_WEIGHT
, weightW
},
376 { DISPID_FONT_CHARSET
, charsetW
}
381 IConnectionPointContainer
*pCPC
;
382 IConnectionPoint
*pCP
;
386 IFontDisp
*pFontDisp
;
387 DISPPARAMS dispparams
;
391 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
);
392 fontdesc
.lpstrName
= MSSansSerif_font
;
393 fontdesc
.cySize
.int64
= 12 * 10000; /* 12 pt */
394 fontdesc
.sWeight
= FW_NORMAL
;
395 fontdesc
.sCharset
= 0;
396 fontdesc
.fItalic
= FALSE
;
397 fontdesc
.fUnderline
= FALSE
;
398 fontdesc
.fStrikethrough
= FALSE
;
400 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&pFont
);
403 hr
= IFont_QueryInterface(pFont
, &IID_IConnectionPointContainer
, (void **)&pCPC
);
406 hr
= IConnectionPointContainer_FindConnectionPoint(pCPC
, &IID_IFontEventsDisp
, &pCP
);
408 IConnectionPointContainer_Release(pCPC
);
410 hr
= IConnectionPoint_Advise(pCP
, (IUnknown
*)&FontEventsDisp
, &dwCookie
);
412 IConnectionPoint_Release(pCP
);
414 fonteventsdisp_invoke_called
= 0;
415 fonteventsdisp_invoke_arg0
= NULL
;
416 hr
= IFont_put_Bold(pFont
, TRUE
);
419 ok(fonteventsdisp_invoke_called
== 1, "IFontEventDisp::Invoke wasn't called once\n");
420 SysFreeString(fonteventsdisp_invoke_arg0
);
422 hr
= IFont_QueryInterface(pFont
, &IID_IFontDisp
, (void **)&pFontDisp
);
425 for (i
= 0; i
< sizeof(font_dispids
)/sizeof(font_dispids
[0]); i
++)
427 switch (font_dispids
[i
].dispid
)
429 case DISPID_FONT_NAME
:
431 static const WCHAR arialW
[] = {'A','r','i','a','l',0};
432 V_VT(&vararg
) = VT_BSTR
;
433 V_BSTR(&vararg
) = SysAllocString(arialW
);
436 case DISPID_FONT_SIZE
:
437 V_VT(&vararg
) = VT_CY
;
438 S(V_CY(&vararg
)).Lo
= 25;
439 S(V_CY(&vararg
)).Hi
= 0;
441 case DISPID_FONT_BOLD
:
442 V_VT(&vararg
) = VT_BOOL
;
443 V_BOOL(&vararg
) = VARIANT_FALSE
;
445 case DISPID_FONT_ITALIC
:
446 case DISPID_FONT_UNDER
:
447 case DISPID_FONT_STRIKE
:
448 V_VT(&vararg
) = VT_BOOL
;
449 V_BOOL(&vararg
) = VARIANT_TRUE
;
451 case DISPID_FONT_WEIGHT
:
452 V_VT(&vararg
) = VT_I2
;
453 V_I2(&vararg
) = FW_BLACK
;
455 case DISPID_FONT_CHARSET
:
456 V_VT(&vararg
) = VT_I2
;
463 dispparams
.cNamedArgs
= 0;
464 dispparams
.rgdispidNamedArgs
= NULL
;
465 dispparams
.cArgs
= 1;
466 dispparams
.rgvarg
= &vararg
;
467 fonteventsdisp_invoke_called
= 0;
468 hr
= IFontDisp_Invoke(pFontDisp
, font_dispids
[i
].dispid
, &IID_NULL
, 0, DISPATCH_PROPERTYPUT
, &dispparams
, NULL
, NULL
, NULL
);
469 ok(hr
== S_OK
, "dispid=%d, got 0x%08x\n", font_dispids
[i
].dispid
, hr
);
470 ok(fonteventsdisp_invoke_called
== 1, "dispid=%d, DISPID_FONT_CHANGED not called, got %d\n", font_dispids
[i
].dispid
,
471 fonteventsdisp_invoke_called
);
474 ok(!lstrcmpW(font_dispids
[i
].name
, fonteventsdisp_invoke_arg0
), "dispid=%d, got %s, expected %s\n",
475 font_dispids
[i
].dispid
, wine_dbgstr_w(fonteventsdisp_invoke_arg0
), wine_dbgstr_w(font_dispids
[i
].name
));
476 SysFreeString(fonteventsdisp_invoke_arg0
);
478 VariantClear(&vararg
);
481 IFontDisp_Release(pFontDisp
);
483 hr
= IFont_Clone(pFont
, &pFont2
);
485 IFont_Release(pFont
);
487 /* this test shows that the notification routine isn't called again */
488 fonteventsdisp_invoke_called
= 0;
489 hr
= IFont_put_Bold(pFont2
, FALSE
);
491 ok(fonteventsdisp_invoke_called
== 0, "got %d\n", fonteventsdisp_invoke_called
);
493 IFont_Release(pFont2
);
496 static void test_names_ids(WCHAR
* w_name_1
, const char* a_name_1
,
497 WCHAR
* w_name_2
, const char* a_name_2
,
498 LCID lcid
, DISPID id_1
, DISPID id_2
,
499 HRESULT hres_expect
, int numnames
)
502 IFontDisp
*fontdisp
= NULL
;
504 DISPID rgDispId
[2] = {0xdeadbeef, 0xdeadbeef};
505 LPOLESTR names
[2] = {w_name_1
, w_name_2
};
507 pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, &pvObj
);
510 hres
= IFontDisp_GetIDsOfNames(fontdisp
, &IID_NULL
, names
, numnames
,
514 ok(hres
== hres_expect
,
515 "GetIDsOfNames: \"%s\", \"%s\" returns 0x%08x, expected 0x%08x.\n",
516 a_name_1
, a_name_2
, hres
, hres_expect
);
518 /* test first DISPID */
519 ok(rgDispId
[0]==id_1
,
520 "GetIDsOfNames: \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
521 a_name_1
, rgDispId
[0], id_1
);
523 /* test second DISPID is present */
526 ok(rgDispId
[1]==id_2
,
527 "GetIDsOfNames: ..., \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
528 a_name_2
, rgDispId
[1], id_2
);
531 IFontDisp_Release(fontdisp
);
534 static void test_GetIDsOfNames(void)
536 WCHAR name_Name
[] = {'N','a','m','e',0};
537 WCHAR name_Italic
[] = {'I','t','a','l','i','c',0};
538 WCHAR name_Size
[] = {'S','i','z','e',0};
539 WCHAR name_Bold
[] = {'B','o','l','d',0};
540 WCHAR name_Underline
[] = {'U','n','d','e','r','l','i','n','e',0};
541 WCHAR name_Strikethrough
[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
542 WCHAR name_Weight
[] = {'W','e','i','g','h','t',0};
543 WCHAR name_Charset
[] = {'C','h','a','r','s','e','t',0};
544 WCHAR name_Foo
[] = {'F','o','o',0};
545 WCHAR name_nAmE
[] = {'n','A','m','E',0};
546 WCHAR name_Nom
[] = {'N','o','m',0};
548 LCID en_us
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),
550 LCID fr_fr
= MAKELCID(MAKELANGID(LANG_FRENCH
,SUBLANG_FRENCH
),
553 /* Test DISPID_FONTs for the various properties. */
554 test_names_ids(name_Name
, "Name", NULL
, "", en_us
,
555 DISPID_FONT_NAME
, 0, S_OK
,1);
556 test_names_ids(name_Size
, "Size", NULL
, "", en_us
,
557 DISPID_FONT_SIZE
, 0, S_OK
,1);
558 test_names_ids(name_Bold
, "Bold", NULL
, "", en_us
,
559 DISPID_FONT_BOLD
, 0, S_OK
,1);
560 test_names_ids(name_Italic
, "Italic", NULL
, "", en_us
,
561 DISPID_FONT_ITALIC
, 0, S_OK
,1);
562 test_names_ids(name_Underline
, "Underline", NULL
, "", en_us
,
563 DISPID_FONT_UNDER
, 0, S_OK
,1);
564 test_names_ids(name_Strikethrough
, "Strikethrough", NULL
, "", en_us
,
565 DISPID_FONT_STRIKE
, 0, S_OK
,1);
566 test_names_ids(name_Weight
, "Weight", NULL
, "", en_us
,
567 DISPID_FONT_WEIGHT
, 0, S_OK
,1);
568 test_names_ids(name_Charset
, "Charset", NULL
, "", en_us
,
569 DISPID_FONT_CHARSET
, 0, S_OK
,1);
571 /* Capitalization doesn't matter. */
572 test_names_ids(name_nAmE
, "nAmE", NULL
, "", en_us
,
573 DISPID_FONT_NAME
, 0, S_OK
,1);
576 test_names_ids(name_Foo
, "Foo", NULL
, "", en_us
,
577 DISPID_UNKNOWN
, 0, DISP_E_UNKNOWNNAME
,1);
579 /* Pass several names: first is processed, */
580 /* second gets DISPID_UNKNOWN and doesn't affect retval. */
581 test_names_ids(name_Italic
, "Italic", name_Name
, "Name", en_us
,
582 DISPID_FONT_ITALIC
, DISPID_UNKNOWN
, S_OK
,2);
583 test_names_ids(name_Italic
, "Italic", name_Foo
, "Foo", en_us
,
584 DISPID_FONT_ITALIC
, DISPID_UNKNOWN
, S_OK
,2);
586 /* Locale ID has no effect. */
587 test_names_ids(name_Name
, "Name", NULL
, "", fr_fr
,
588 DISPID_FONT_NAME
, 0, S_OK
,1);
589 test_names_ids(name_Nom
, "This is not a font", NULL
, "", fr_fr
,
590 DISPID_UNKNOWN
, 0, DISP_E_UNKNOWNNAME
,1);
592 /* One of the arguments are invalid */
593 test_names_ids(name_Name
, "Name", NULL
, "", en_us
,
594 0xdeadbeef, 0xdeadbeef, E_INVALIDARG
,0);
595 test_names_ids(name_Italic
, "Italic", NULL
, "", en_us
,
596 0xdeadbeef, 0xdeadbeef, E_INVALIDARG
,0);
597 test_names_ids(name_Foo
, "Foo", NULL
, "", en_us
,
598 0xdeadbeef, 0xdeadbeef, E_INVALIDARG
,0);
600 /* Crazy locale ID? */
601 test_names_ids(name_Name
, "Name", NULL
, "", -1,
602 DISPID_FONT_NAME
, 0, S_OK
,1);
605 static void test_Invoke(void)
610 DISPPARAMS dispparams
;
613 hr
= pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, (void **)&fontdisp
);
616 V_VT(&vararg
) = VT_BOOL
;
617 V_BOOL(&vararg
) = VARIANT_FALSE
;
618 dispparams
.cNamedArgs
= 0;
619 dispparams
.rgdispidNamedArgs
= NULL
;
620 dispparams
.cArgs
= 1;
621 dispparams
.rgvarg
= &vararg
;
622 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_IFontDisp
, 0, DISPATCH_PROPERTYPUT
, &dispparams
, NULL
, NULL
, NULL
);
623 EXPECT_HR(hr
, DISP_E_UNKNOWNINTERFACE
);
625 dispparams
.cArgs
= 0;
626 dispparams
.rgvarg
= NULL
;
627 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYPUT
, &dispparams
, NULL
, NULL
, NULL
);
628 EXPECT_HR(hr
, DISP_E_BADPARAMCOUNT
);
630 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYPUT
, NULL
, NULL
, NULL
, NULL
);
631 EXPECT_HR(hr
, DISP_E_PARAMNOTOPTIONAL
);
633 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, NULL
, NULL
, NULL
, NULL
);
634 EXPECT_HR(hr
, DISP_E_PARAMNOTOPTIONAL
);
636 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, NULL
, &varresult
, NULL
, NULL
);
639 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_METHOD
, NULL
, &varresult
, NULL
, NULL
);
640 EXPECT_HR(hr
, DISP_E_MEMBERNOTFOUND
);
642 hr
= IFontDisp_Invoke(fontdisp
, 0xdeadbeef, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, NULL
, &varresult
, NULL
, NULL
);
643 EXPECT_HR(hr
, DISP_E_MEMBERNOTFOUND
);
645 dispparams
.cArgs
= 1;
646 dispparams
.rgvarg
= &vararg
;
647 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, NULL
, NULL
);
650 IFontDisp_Release(fontdisp
);
653 static void test_IsEqual(void)
660 /* Basic font description */
661 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
662 fd
.lpstrName
= system_font
;
663 S(fd
.cySize
).Lo
= 100;
664 S(fd
.cySize
).Hi
= 100;
668 fd
.fUnderline
= FALSE
;
669 fd
.fStrikethrough
= FALSE
;
672 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt
);
674 /* Test equal fonts */
675 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
676 hres
= IFont_IsEqual(ifnt
,ifnt2
);
678 "IFont_IsEqual: (EQUAL) Expected S_OK but got 0x%08x\n",hres
);
679 IFont_Release(ifnt2
);
681 /* Check for bad pointer */
682 hres
= IFont_IsEqual(ifnt
,NULL
);
683 ok(hres
== E_POINTER
,
684 "IFont_IsEqual: (NULL) Expected 0x80004003 but got 0x%08x\n",hres
);
687 fd
.lpstrName
= arial_font
;
688 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
689 hres
= IFont_IsEqual(ifnt
,ifnt2
);
691 "IFont_IsEqual: (strName) Expected S_FALSE but got 0x%08x\n",hres
);
692 fd
.lpstrName
= system_font
;
693 IFont_Release(ifnt2
);
695 /* Test lo font size */
696 S(fd
.cySize
).Lo
= 10000;
697 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
698 hres
= IFont_IsEqual(ifnt
,ifnt2
);
700 "IFont_IsEqual: (Lo font size) Expected S_FALSE but got 0x%08x\n",hres
);
701 S(fd
.cySize
).Lo
= 100;
702 IFont_Release(ifnt2
);
704 /* Test hi font size */
705 S(fd
.cySize
).Hi
= 10000;
706 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
707 hres
= IFont_IsEqual(ifnt
,ifnt2
);
709 "IFont_IsEqual: (Hi font size) Expected S_FALSE but got 0x%08x\n",hres
);
710 S(fd
.cySize
).Hi
= 100;
711 IFont_Release(ifnt2
);
713 /* Test font weight */
715 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
716 hres
= IFont_IsEqual(ifnt
,ifnt2
);
718 "IFont_IsEqual: (Weight) Expected S_FALSE but got 0x%08x\n",hres
);
720 IFont_Release(ifnt2
);
724 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
725 hres
= IFont_IsEqual(ifnt
,ifnt2
);
727 "IFont_IsEqual: (Charset) Expected S_FALSE but got 0x%08x\n",hres
);
729 IFont_Release(ifnt2
);
731 /* Test italic setting */
733 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
734 hres
= IFont_IsEqual(ifnt
,ifnt2
);
736 "IFont_IsEqual: (Italic) Expected S_FALSE but got 0x%08x\n",hres
);
738 IFont_Release(ifnt2
);
740 /* Test underline setting */
741 fd
.fUnderline
= TRUE
;
742 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
743 hres
= IFont_IsEqual(ifnt
,ifnt2
);
745 "IFont_IsEqual: (Underline) Expected S_FALSE but got 0x%08x\n",hres
);
746 fd
.fUnderline
= FALSE
;
747 IFont_Release(ifnt2
);
749 /* Test strikethrough setting */
750 fd
.fStrikethrough
= TRUE
;
751 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
752 hres
= IFont_IsEqual(ifnt
,ifnt2
);
754 "IFont_IsEqual: (Strikethrough) Expected S_FALSE but got 0x%08x\n",hres
);
755 fd
.fStrikethrough
= FALSE
;
756 IFont_Release(ifnt2
);
762 static void test_ReleaseHfont(void)
765 LPVOID pvObj1
= NULL
;
766 LPVOID pvObj2
= NULL
;
773 /* Basic font description */
774 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
775 fd
.lpstrName
= system_font
;
776 S(fd
.cySize
).Lo
= 100;
777 S(fd
.cySize
).Hi
= 100;
781 fd
.fUnderline
= FALSE
;
782 fd
.fStrikethrough
= FALSE
;
784 /* Create HFONTs and IFONTs */
785 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj1
);
787 IFont_get_hFont(ifnt1
,&hfnt1
);
788 fd
.lpstrName
= arial_font
;
789 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
791 IFont_get_hFont(ifnt2
,&hfnt2
);
793 /* Try invalid HFONT */
794 hres
= IFont_ReleaseHfont(ifnt1
,NULL
);
795 ok(hres
== E_INVALIDARG
,
796 "IFont_ReleaseHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
799 /* Try to add a bad HFONT */
800 hres
= IFont_ReleaseHfont(ifnt1
,(HFONT
)32);
802 "IFont_ReleaseHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
805 /* Release all refs */
806 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
808 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
811 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
813 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
816 /* Check that both lists are empty */
817 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
819 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
822 /* The list should be empty */
823 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
825 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
828 IFont_Release(ifnt1
);
829 IFont_Release(ifnt2
);
832 static void test_AddRefHfont(void)
843 /* Basic font description */
844 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
845 fd
.lpstrName
= system_font
;
846 S(fd
.cySize
).Lo
= 100;
847 S(fd
.cySize
).Hi
= 100;
851 fd
.fUnderline
= FALSE
;
852 fd
.fStrikethrough
= FALSE
;
854 /* Create HFONTs and IFONTs */
855 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt1
);
856 IFont_get_hFont(ifnt1
,&hfnt1
);
857 fd
.lpstrName
= arial_font
;
858 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
859 IFont_get_hFont(ifnt2
,&hfnt2
);
861 /* Try invalid HFONT */
862 hres
= IFont_AddRefHfont(ifnt1
,NULL
);
863 ok(hres
== E_INVALIDARG
,
864 "IFont_AddRefHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
867 /* Try to add a bad HFONT */
868 hres
= IFont_AddRefHfont(ifnt1
,(HFONT
)32);
870 "IFont_AddRefHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
873 /* Add simple IFONT HFONT pair */
874 hres
= IFont_AddRefHfont(ifnt1
,hfnt1
);
876 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
879 /* IFONT and HFONT do not have to be the same (always looks at HFONT) */
880 hres
= IFont_AddRefHfont(ifnt2
,hfnt1
);
882 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
885 /* Release all hfnt1 refs */
886 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
888 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
891 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
893 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
896 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
898 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
901 /* Check if hfnt1 is empty */
902 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
904 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
907 /* Release all hfnt2 refs */
908 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
910 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
913 /* Check if hfnt2 is empty */
914 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
916 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
919 /* Show that releasing an IFONT does not always release it from the HFONT cache. */
921 IFont_Release(ifnt1
);
923 /* Add a reference for destroyed hfnt1 */
924 hres
= IFont_AddRefHfont(ifnt2
,hfnt1
);
926 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
929 /* Decrement reference for destroyed hfnt1 */
930 hres
= IFont_ReleaseHfont(ifnt2
,hfnt1
);
932 hres
== S_FALSE
, /* <= win2k */
933 "IFont_AddRefHfont: (Release ref) Expected S_OK or S_FALSE but got 0x%08x\n",
936 /* Shows that releasing all IFONT's does clear the HFONT cache. */
938 IFont_Release(ifnt2
);
940 /* Need to make a new IFONT for testing */
941 fd
.fUnderline
= TRUE
;
942 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt3
);
943 IFont_get_hFont(ifnt3
,&hfnt3
);
945 /* Add a reference for destroyed hfnt1 */
946 hres
= IFont_AddRefHfont(ifnt3
,hfnt1
);
948 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
951 /* Decrement reference for destroyed hfnt1 */
952 hres
= IFont_ReleaseHfont(ifnt3
,hfnt1
);
954 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
957 IFont_Release(ifnt3
);
960 static void test_returns(void)
966 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
);
967 fontdesc
.lpstrName
= MSSansSerif_font
;
968 fontdesc
.cySize
.int64
= 12 * 10000; /* 12 pt */
969 fontdesc
.sWeight
= FW_NORMAL
;
970 fontdesc
.sCharset
= 0;
971 fontdesc
.fItalic
= FALSE
;
972 fontdesc
.fUnderline
= FALSE
;
973 fontdesc
.fStrikethrough
= FALSE
;
975 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&pFont
);
978 hr
= IFont_put_Name(pFont
, NULL
);
979 EXPECT_HR(hr
, CTL_E_INVALIDPROPERTYVALUE
);
981 hr
= IFont_get_Name(pFont
, NULL
);
982 EXPECT_HR(hr
, E_POINTER
);
984 hr
= IFont_get_Size(pFont
, NULL
);
985 EXPECT_HR(hr
, E_POINTER
);
987 hr
= IFont_get_Bold(pFont
, NULL
);
988 EXPECT_HR(hr
, E_POINTER
);
990 IFont_Release(pFont
);
993 static void test_hfont_lifetime(void)
998 HFONT hfont
, first_hfont
= NULL
;
1003 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
);
1004 fontdesc
.lpstrName
= arial_font
;
1005 fontdesc
.cySize
.int64
= 12 * 10000; /* 12 pt */
1006 fontdesc
.sWeight
= FW_NORMAL
;
1007 fontdesc
.sCharset
= ANSI_CHARSET
;
1008 fontdesc
.fItalic
= FALSE
;
1009 fontdesc
.fUnderline
= FALSE
;
1010 fontdesc
.fStrikethrough
= FALSE
;
1012 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
1013 EXPECT_HR(hr
, S_OK
);
1015 hr
= IFont_get_hFont(font
, &hfont
);
1016 EXPECT_HR(hr
, S_OK
);
1018 /* show that if the font is updated the old hfont is deleted when the
1019 new font is realized */
1020 for(i
= 0; i
< 100; i
++)
1022 HFONT last_hfont
= hfont
;
1024 size
.int64
= (i
+ 10) * 20000;
1026 obj_type
= GetObjectType(hfont
);
1027 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1029 hr
= IFont_put_Size(font
, size
);
1030 EXPECT_HR(hr
, S_OK
);
1032 /* put_Size doesn't cause the new font to be realized */
1033 obj_type
= GetObjectType(last_hfont
);
1034 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1036 hr
= IFont_get_hFont(font
, &hfont
);
1037 EXPECT_HR(hr
, S_OK
);
1039 obj_type
= GetObjectType(last_hfont
);
1040 ok(obj_type
== 0, "%d: got obj type %d\n", i
, obj_type
);
1043 /* now show that if we take a reference on the hfont, it persists
1044 until the font object is released */
1045 for(i
= 0; i
< 100; i
++)
1047 size
.int64
= (i
+ 10) * 20000;
1049 obj_type
= GetObjectType(hfont
);
1050 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1052 hr
= IFont_put_Size(font
, size
);
1053 EXPECT_HR(hr
, S_OK
);
1055 hr
= IFont_get_hFont(font
, &hfont
);
1056 EXPECT_HR(hr
, S_OK
);
1058 hr
= IFont_AddRefHfont(font
, hfont
);
1059 EXPECT_HR(hr
, S_OK
);
1061 if(i
== 0) first_hfont
= hfont
;
1062 obj_type
= GetObjectType(first_hfont
);
1063 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1066 IFont_Release(font
);
1068 obj_type
= GetObjectType(first_hfont
);
1069 ok(obj_type
== 0, "got obj type %d\n", obj_type
);
1071 /* An AddRefHfont followed by a ReleaseHfont means the font doesn't not persist
1072 through re-realization */
1074 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
1075 EXPECT_HR(hr
, S_OK
);
1077 hr
= IFont_get_hFont(font
, &hfont
);
1078 EXPECT_HR(hr
, S_OK
);
1080 for(i
= 0; i
< 100; i
++)
1082 HFONT last_hfont
= hfont
;
1084 size
.int64
= (i
+ 10) * 20000;
1086 obj_type
= GetObjectType(hfont
);
1087 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1089 hr
= IFont_put_Size(font
, size
);
1090 EXPECT_HR(hr
, S_OK
);
1092 /* put_Size doesn't cause the new font to be realized */
1093 obj_type
= GetObjectType(last_hfont
);
1094 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1096 hr
= IFont_get_hFont(font
, &hfont
);
1097 EXPECT_HR(hr
, S_OK
);
1099 hr
= IFont_AddRefHfont(font
, hfont
);
1100 EXPECT_HR(hr
, S_OK
);
1102 hr
= IFont_ReleaseHfont(font
, hfont
);
1103 EXPECT_HR(hr
, S_OK
);
1105 obj_type
= GetObjectType(last_hfont
);
1106 ok(obj_type
== 0, "%d: got obj type %d\n", i
, obj_type
);
1109 /* Interestingly if we release a nonexistent reference on the hfont,
1110 * it persists until the font object is released
1112 for(i
= 0; i
< 100; i
++)
1114 size
.int64
= (i
+ 10) * 20000;
1116 obj_type
= GetObjectType(hfont
);
1117 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1119 hr
= IFont_put_Size(font
, size
);
1120 EXPECT_HR(hr
, S_OK
);
1122 hr
= IFont_get_hFont(font
, &hfont
);
1123 EXPECT_HR(hr
, S_OK
);
1125 hr
= IFont_ReleaseHfont(font
, hfont
);
1126 EXPECT_HR(hr
, S_OK
);
1128 if(i
== 0) first_hfont
= hfont
;
1129 obj_type
= GetObjectType(first_hfont
);
1130 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1133 IFont_Release(font
);
1135 obj_type
= GetObjectType(first_hfont
);
1136 ok(obj_type
== 0, "got obj type %d\n", obj_type
);
1138 /* If we take two internal references on a hfont then we can release
1139 it twice. So it looks like there's a total reference count
1140 that includes internal and external references */
1142 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
1143 EXPECT_HR(hr
, S_OK
);
1144 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font2
);
1145 EXPECT_HR(hr
, S_OK
);
1147 hr
= IFont_get_hFont(font
, &hfont
);
1148 EXPECT_HR(hr
, S_OK
);
1149 hr
= IFont_get_hFont(font2
, &first_hfont
);
1150 EXPECT_HR(hr
, S_OK
);
1152 ok(hfont
== first_hfont
, "fonts differ\n");
1153 hr
= IFont_ReleaseHfont(font
, hfont
);
1154 EXPECT_HR(hr
, S_OK
);
1155 hr
= IFont_ReleaseHfont(font
, hfont
);
1157 EXPECT_HR(hr
, S_OK
);
1158 hr
= IFont_ReleaseHfont(font
, hfont
);
1159 EXPECT_HR(hr
, S_FALSE
);
1161 obj_type
= GetObjectType(hfont
);
1162 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1164 IFont_Release(font
);
1166 obj_type
= GetObjectType(hfont
);
1167 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1169 IFont_Release(font2
);
1171 obj_type
= GetObjectType(hfont
);
1172 ok(obj_type
== 0, "got obj type %d\n", obj_type
);
1175 static void test_realization(void)
1183 /* Try to create a symbol only font (marlett) with charset
1184 set to ANSI. This will result in another, ANSI, font
1186 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
);
1187 fontdesc
.lpstrName
= marlett_font
;
1188 fontdesc
.cySize
.int64
= 12 * 10000; /* 12 pt */
1189 fontdesc
.sWeight
= FW_NORMAL
;
1190 fontdesc
.sCharset
= ANSI_CHARSET
;
1191 fontdesc
.fItalic
= FALSE
;
1192 fontdesc
.fUnderline
= FALSE
;
1193 fontdesc
.fStrikethrough
= FALSE
;
1195 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
1196 EXPECT_HR(hr
, S_OK
);
1198 hr
= IFont_get_Charset(font
, &cs
);
1199 EXPECT_HR(hr
, S_OK
);
1200 ok(cs
== ANSI_CHARSET
, "got charset %d\n", cs
);
1202 IFont_Release(font
);
1204 /* Now create an ANSI font and change the name to marlett */
1206 fontdesc
.lpstrName
= arial_font
;
1208 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
1209 EXPECT_HR(hr
, S_OK
);
1211 hr
= IFont_get_Charset(font
, &cs
);
1212 EXPECT_HR(hr
, S_OK
);
1213 ok(cs
== ANSI_CHARSET
, "got charset %d\n", cs
);
1215 name
= SysAllocString(marlett_font
);
1216 hr
= IFont_put_Name(font
, name
);
1217 EXPECT_HR(hr
, S_OK
);
1218 SysFreeString(name
);
1220 hr
= IFont_get_Name(font
, &name
);
1221 EXPECT_HR(hr
, S_OK
);
1222 ok(!lstrcmpiW(name
, marlett_font
), "got name %s\n", wine_dbgstr_w(name
));
1223 SysFreeString(name
);
1225 hr
= IFont_get_Charset(font
, &cs
);
1226 EXPECT_HR(hr
, S_OK
);
1227 ok(cs
== SYMBOL_CHARSET
, "got charset %d\n", cs
);
1229 IFont_Release(font
);
1232 static void test_OleCreateFontIndirect(void)
1238 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
);
1239 fontdesc
.lpstrName
= arial_font
;
1240 fontdesc
.cySize
.int64
= 12 * 10000; /* 12 pt */
1241 fontdesc
.sWeight
= FW_NORMAL
;
1242 fontdesc
.sCharset
= ANSI_CHARSET
;
1243 fontdesc
.fItalic
= FALSE
;
1244 fontdesc
.fUnderline
= FALSE
;
1245 fontdesc
.fStrikethrough
= FALSE
;
1247 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void**)&font
);
1248 EXPECT_HR(hr
, S_OK
);
1249 IFont_Release(font
);
1251 /* play with cbSizeofstruct value */
1252 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
)-1;
1253 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void**)&font
);
1254 EXPECT_HR(hr
, S_OK
);
1255 IFont_Release(font
);
1257 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
)+1;
1258 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void**)&font
);
1259 EXPECT_HR(hr
, S_OK
);
1260 IFont_Release(font
);
1262 fontdesc
.cbSizeofstruct
= 0;
1263 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void**)&font
);
1264 EXPECT_HR(hr
, S_OK
);
1265 IFont_Release(font
);
1270 hOleaut32
= GetModuleHandleA("oleaut32.dll");
1271 pOleCreateFontIndirect
= (void*)GetProcAddress(hOleaut32
, "OleCreateFontIndirect");
1272 if (!pOleCreateFontIndirect
)
1274 win_skip("OleCreateFontIndirect not available\n");
1278 test_QueryInterface();
1281 test_font_events_disp();
1282 test_GetIDsOfNames();
1285 test_ReleaseHfont();
1288 test_hfont_lifetime();
1290 test_OleCreateFontIndirect();