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
;
82 fd
.fStrikethrough
= 0;
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 /* If scaling ration specified, change ratio. */
92 if(ratio_logical
&& ratio_himetric
)
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",
100 hres
= IFont_get_Size(ifnt
, &psize
);
101 ok(hres
== S_OK
,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
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
);
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",
113 rtnval
= GetObject (hfont
, sizeof(LOGFONT
), &lf
);
114 ok(rtnval
> 0, "GetObject(hfont) failed\n");
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
);
125 static void test_ifont_sizes(void)
127 /* Test various size operations and conversions. */
128 /* Add more as needed. */
130 /* Results of first 2 tests depend on display resolution. */
132 LONG dpi
= GetDeviceCaps(hdc
, LOGPIXELSY
); /* expected results depend on display DPI */
134 if(dpi
== 96) /* normal resolution display */
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 */
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 */
144 test_ifont_size(180000, 0, 0, 0, -30, "default"); /* normal font */
145 test_ifont_size(186000, 0, 0, 0, -31, "rounding"); /* test rounding */
147 skip("Skipping resolution dependent font size tests - display resolution is %d\n", dpi
);
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 */
156 static void test_QueryInterface(void)
163 hr
= pOleCreateFontIndirect(NULL
, &IID_IFont
, NULL
);
164 EXPECT_HR(hr
, E_POINTER
);
166 hr
= pOleCreateFontIndirect(NULL
, &IID_IFont
, &pvObj
);
170 ok(font
!= NULL
,"OCFI (NULL,..) returns NULL, instead of !NULL\n");
173 hr
= IFont_QueryInterface( font
, &IID_IFont
, &pvObj
);
176 /* Test if QueryInterface increments ref counter for IFONTs */
177 ref
= IFont_AddRef(font
);
179 broken(ref
== 1), /* win95 */
180 "IFont_QI expected ref value 3 but instead got %d\n", ref
);
183 ok(pvObj
!= NULL
,"IFont_QI does return NULL, instead of a ptr\n");
189 static void test_type_info(void)
193 IFontDisp
* fontdisp
= NULL
;
195 WCHAR name_Name
[] = {'N','a','m','e',0};
198 LCID en_us
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),
200 DISPPARAMS dispparams
;
203 pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, &pvObj
);
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");
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]);
216 ITypeInfo_Release(pTInfo
);
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
,
226 ok(hres
== S_OK
, "IFontDisp_Invoke return 0x%08x instead of S_OK.\n", hres
);
227 VariantClear(&varresult
);
229 IFontDisp_Release(fontdisp
);
232 static HRESULT WINAPI
FontEventsDisp_QueryInterface(
233 IFontEventsDisp
*iface
,
234 /* [in] */ REFIID riid
,
235 /* [iid_is][out] */ void __RPC_FAR
*__RPC_FAR
*ppvObject
)
237 if (IsEqualIID(riid
, &IID_IFontEventsDisp
) || IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDispatch
))
239 IUnknown_AddRef(iface
);
246 return E_NOINTERFACE
;
250 static ULONG WINAPI
FontEventsDisp_AddRef(
251 IFontEventsDisp
*iface
)
256 static ULONG WINAPI
FontEventsDisp_Release(
257 IFontEventsDisp
*iface
)
262 static int fonteventsdisp_invoke_called
= 0;
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
)
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");
282 fonteventsdisp_invoke_called
++;
286 static IFontEventsDispVtbl FontEventsDisp_Vtbl
=
288 FontEventsDisp_QueryInterface
,
289 FontEventsDisp_AddRef
,
290 FontEventsDisp_Release
,
294 FontEventsDisp_Invoke
297 static IFontEventsDisp FontEventsDisp
= { &FontEventsDisp_Vtbl
};
299 static void test_font_events_disp(void)
303 IConnectionPointContainer
*pCPC
;
304 IConnectionPoint
*pCP
;
308 IFontDisp
*pFontDisp
;
309 DISPPARAMS dispparams
;
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
;
321 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&pFont
);
324 hr
= IFont_QueryInterface(pFont
, &IID_IConnectionPointContainer
, (void **)&pCPC
);
327 hr
= IConnectionPointContainer_FindConnectionPoint(pCPC
, &IID_IFontEventsDisp
, &pCP
);
329 IConnectionPointContainer_Release(pCPC
);
331 hr
= IConnectionPoint_Advise(pCP
, (IUnknown
*)&FontEventsDisp
, &dwCookie
);
333 IConnectionPoint_Release(pCP
);
335 hr
= IFont_put_Bold(pFont
, TRUE
);
338 ok(fonteventsdisp_invoke_called
== 1, "IFontEventDisp::Invoke wasn't called once\n");
340 hr
= IFont_QueryInterface(pFont
, &IID_IFontDisp
, (void **)&pFontDisp
);
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
);
352 IFontDisp_Release(pFontDisp
);
354 ok(fonteventsdisp_invoke_called
== 2, "IFontEventDisp::Invoke was called %d times instead of twice\n",
355 fonteventsdisp_invoke_called
);
357 hr
= IFont_Clone(pFont
, &pFont2
);
359 IFont_Release(pFont
);
361 hr
= IFont_put_Bold(pFont2
, FALSE
);
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
);
368 IFont_Release(pFont2
);
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
)
377 IFontDisp
*fontdisp
= NULL
;
379 DISPID rgDispId
[2] = {0xdeadbeef, 0xdeadbeef};
380 LPOLESTR names
[2] = {w_name_1
, w_name_2
};
382 pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, &pvObj
);
385 hres
= IFontDisp_GetIDsOfNames(fontdisp
, &IID_NULL
, names
, numnames
,
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
);
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
);
398 /* test second DISPID is present */
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
);
406 IFontDisp_Release(fontdisp
);
409 static void test_GetIDsOfNames(void)
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};
423 LCID en_us
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),
425 LCID fr_fr
= MAKELCID(MAKELANGID(LANG_FRENCH
,SUBLANG_FRENCH
),
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);
446 /* Capitalization doesn't matter. */
447 test_names_ids(name_nAmE
, "nAmE", NULL
, "", en_us
,
448 DISPID_FONT_NAME
, 0, S_OK
,1);
451 test_names_ids(name_Foo
, "Foo", NULL
, "", en_us
,
452 DISPID_UNKNOWN
, 0, DISP_E_UNKNOWNNAME
,1);
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);
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);
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);
475 /* Crazy locale ID? */
476 test_names_ids(name_Name
, "Name", NULL
, "", -1,
477 DISPID_FONT_NAME
, 0, S_OK
,1);
480 static void test_Invoke(void)
485 DISPPARAMS dispparams
;
488 hr
= pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, (void **)&fontdisp
);
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
);
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
);
505 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYPUT
, NULL
, NULL
, NULL
, NULL
);
506 EXPECT_HR(hr
, DISP_E_PARAMNOTOPTIONAL
);
508 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, NULL
, NULL
, NULL
, NULL
);
509 EXPECT_HR(hr
, DISP_E_PARAMNOTOPTIONAL
);
511 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, NULL
, &varresult
, NULL
, NULL
);
514 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_METHOD
, NULL
, &varresult
, NULL
, NULL
);
515 EXPECT_HR(hr
, DISP_E_MEMBERNOTFOUND
);
517 hr
= IFontDisp_Invoke(fontdisp
, 0xdeadbeef, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, NULL
, &varresult
, NULL
, NULL
);
518 EXPECT_HR(hr
, DISP_E_MEMBERNOTFOUND
);
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
);
525 IFontDisp_Release(fontdisp
);
528 static void test_IsEqual(void)
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;
544 fd
.fStrikethrough
= 0;
547 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt
);
549 /* Test equal fonts */
550 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
551 hres
= IFont_IsEqual(ifnt
,ifnt2
);
553 "IFont_IsEqual: (EQUAL) Expected S_OK but got 0x%08x\n",hres
);
554 IFont_Release(ifnt2
);
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
);
562 fd
.lpstrName
= arial_font
;
563 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
564 hres
= IFont_IsEqual(ifnt
,ifnt2
);
566 "IFont_IsEqual: (strName) Expected S_FALSE but got 0x%08x\n",hres
);
567 fd
.lpstrName
= system_font
;
568 IFont_Release(ifnt2
);
570 /* Test lo font size */
571 S(fd
.cySize
).Lo
= 10000;
572 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
573 hres
= IFont_IsEqual(ifnt
,ifnt2
);
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
);
579 /* Test hi font size */
580 S(fd
.cySize
).Hi
= 10000;
581 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
582 hres
= IFont_IsEqual(ifnt
,ifnt2
);
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
);
588 /* Test font weight */
590 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
591 hres
= IFont_IsEqual(ifnt
,ifnt2
);
593 "IFont_IsEqual: (Weight) Expected S_FALSE but got 0x%08x\n",hres
);
595 IFont_Release(ifnt2
);
599 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
600 hres
= IFont_IsEqual(ifnt
,ifnt2
);
602 "IFont_IsEqual: (Charset) Expected S_FALSE but got 0x%08x\n",hres
);
604 IFont_Release(ifnt2
);
606 /* Test italic setting */
608 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
609 hres
= IFont_IsEqual(ifnt
,ifnt2
);
611 "IFont_IsEqual: (Italic) Expected S_FALSE but got 0x%08x\n",hres
);
613 IFont_Release(ifnt2
);
615 /* Test underline setting */
617 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
618 hres
= IFont_IsEqual(ifnt
,ifnt2
);
620 "IFont_IsEqual: (Underline) Expected S_FALSE but got 0x%08x\n",hres
);
622 IFont_Release(ifnt2
);
624 /* Test strikethrough setting */
625 fd
.fStrikethrough
= 1;
626 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
627 hres
= IFont_IsEqual(ifnt
,ifnt2
);
629 "IFont_IsEqual: (Strikethrough) Expected S_FALSE but got 0x%08x\n",hres
);
630 fd
.fStrikethrough
= 0;
631 IFont_Release(ifnt2
);
637 static void test_ReleaseHfont(void)
640 LPVOID pvObj1
= NULL
;
641 LPVOID pvObj2
= NULL
;
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;
657 fd
.fStrikethrough
= 0;
659 /* Create HFONTs and IFONTs */
660 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj1
);
662 IFont_get_hFont(ifnt1
,&hfnt1
);
663 fd
.lpstrName
= arial_font
;
664 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
666 IFont_get_hFont(ifnt2
,&hfnt2
);
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",
674 /* Try to add a bad HFONT */
675 hres
= IFont_ReleaseHfont(ifnt1
,(HFONT
)32);
677 "IFont_ReleaseHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
680 /* Release all refs */
681 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
683 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
686 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
688 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
691 /* Check that both lists are empty */
692 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
694 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
697 /* The list should be empty */
698 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
700 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
703 IFont_Release(ifnt1
);
704 IFont_Release(ifnt2
);
707 static void test_AddRefHfont(void)
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;
727 fd
.fStrikethrough
= 0;
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
);
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",
742 /* Try to add a bad HFONT */
743 hres
= IFont_AddRefHfont(ifnt1
,(HFONT
)32);
745 "IFont_AddRefHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
748 /* Add simple IFONT HFONT pair */
749 hres
= IFont_AddRefHfont(ifnt1
,hfnt1
);
751 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
754 /* IFONT and HFONT do not have to be the same (always looks at HFONT) */
755 hres
= IFont_AddRefHfont(ifnt2
,hfnt1
);
757 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
760 /* Release all hfnt1 refs */
761 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
763 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
766 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
768 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
771 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
773 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
776 /* Check if hfnt1 is empty */
777 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
779 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
782 /* Release all hfnt2 refs */
783 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
785 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
788 /* Check if hfnt2 is empty */
789 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
791 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
794 /* Show that releasing an IFONT does not always release it from the HFONT cache. */
796 IFont_Release(ifnt1
);
798 /* Add a reference for destroyed hfnt1 */
799 hres
= IFont_AddRefHfont(ifnt2
,hfnt1
);
801 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
804 /* Decrement reference for destroyed hfnt1 */
805 hres
= IFont_ReleaseHfont(ifnt2
,hfnt1
);
807 hres
== S_FALSE
, /* <= win2k */
808 "IFont_AddRefHfont: (Release ref) Expected S_OK or S_FALSE but got 0x%08x\n",
811 /* Shows that releasing all IFONT's does clear the HFONT cache. */
813 IFont_Release(ifnt2
);
815 /* Need to make a new IFONT for testing */
817 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt3
);
818 IFont_get_hFont(ifnt3
,&hfnt3
);
820 /* Add a reference for destroyed hfnt1 */
821 hres
= IFont_AddRefHfont(ifnt3
,hfnt1
);
823 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
826 /* Decrement reference for destroyed hfnt1 */
827 hres
= IFont_ReleaseHfont(ifnt3
,hfnt1
);
829 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
832 IFont_Release(ifnt3
);
835 static void test_returns(void)
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
;
850 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&pFont
);
853 hr
= IFont_put_Name(pFont
, NULL
);
854 EXPECT_HR(hr
, CTL_E_INVALIDPROPERTYVALUE
);
856 hr
= IFont_get_Name(pFont
, NULL
);
857 EXPECT_HR(hr
, E_POINTER
);
859 hr
= IFont_get_Size(pFont
, NULL
);
860 EXPECT_HR(hr
, E_POINTER
);
862 hr
= IFont_get_Bold(pFont
, NULL
);
863 EXPECT_HR(hr
, E_POINTER
);
865 IFont_Release(pFont
);
868 static void test_hfont_lifetime(void)
873 HFONT hfont
, first_hfont
= NULL
;
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
;
887 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
890 hr
= IFont_get_hFont(font
, &hfont
);
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
++)
897 HFONT last_hfont
= hfont
;
899 size
.int64
= (i
+ 10) * 20000;
901 obj_type
= GetObjectType(hfont
);
902 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
904 hr
= IFont_put_Size(font
, size
);
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
);
911 hr
= IFont_get_hFont(font
, &hfont
);
914 obj_type
= GetObjectType(last_hfont
);
915 ok(obj_type
== 0, "%d: got obj type %d\n", i
, obj_type
);
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
++)
922 size
.int64
= (i
+ 10) * 20000;
924 obj_type
= GetObjectType(hfont
);
925 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
927 hr
= IFont_put_Size(font
, size
);
930 hr
= IFont_get_hFont(font
, &hfont
);
933 hr
= IFont_AddRefHfont(font
, hfont
);
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
);
943 obj_type
= GetObjectType(first_hfont
);
944 ok(obj_type
== 0, "got obj type %d\n", obj_type
);
946 /* An AddRefHfont followed by a ReleaseHfont means the font doesn't not persist
947 through re-realization */
949 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
952 hr
= IFont_get_hFont(font
, &hfont
);
955 for(i
= 0; i
< 100; i
++)
957 HFONT last_hfont
= hfont
;
959 size
.int64
= (i
+ 10) * 20000;
961 obj_type
= GetObjectType(hfont
);
962 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
964 hr
= IFont_put_Size(font
, size
);
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
);
971 hr
= IFont_get_hFont(font
, &hfont
);
974 hr
= IFont_AddRefHfont(font
, hfont
);
977 hr
= IFont_ReleaseHfont(font
, hfont
);
980 obj_type
= GetObjectType(last_hfont
);
981 ok(obj_type
== 0, "%d: got obj type %d\n", i
, obj_type
);
984 /* Interestingly if we release a nonexistent reference on the hfont,
985 * it persists until the font object is released
987 for(i
= 0; i
< 100; i
++)
989 size
.int64
= (i
+ 10) * 20000;
991 obj_type
= GetObjectType(hfont
);
992 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
994 hr
= IFont_put_Size(font
, size
);
997 hr
= IFont_get_hFont(font
, &hfont
);
1000 hr
= IFont_ReleaseHfont(font
, hfont
);
1001 EXPECT_HR(hr
, S_OK
);
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
);
1008 IFont_Release(font
);
1010 obj_type
= GetObjectType(first_hfont
);
1011 ok(obj_type
== 0, "got obj type %d\n", obj_type
);
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 */
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
);
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
);
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
);
1032 EXPECT_HR(hr
, S_OK
);
1033 hr
= IFont_ReleaseHfont(font
, hfont
);
1034 EXPECT_HR(hr
, S_FALSE
);
1036 obj_type
= GetObjectType(hfont
);
1037 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1039 IFont_Release(font
);
1041 obj_type
= GetObjectType(hfont
);
1042 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1044 IFont_Release(font2
);
1046 obj_type
= GetObjectType(hfont
);
1047 ok(obj_type
== 0, "got obj type %d\n", obj_type
);
1050 static void test_realization(void)
1058 /* Try to create a symbol only font (marlett) with charset
1059 set to ANSI. This will result in another, ANSI, font
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
;
1070 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
1071 EXPECT_HR(hr
, S_OK
);
1073 hr
= IFont_get_Charset(font
, &cs
);
1074 EXPECT_HR(hr
, S_OK
);
1075 ok(cs
== ANSI_CHARSET
, "got charset %d\n", cs
);
1077 IFont_Release(font
);
1079 /* Now create an ANSI font and change the name to marlett */
1081 fontdesc
.lpstrName
= arial_font
;
1083 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
1084 EXPECT_HR(hr
, S_OK
);
1086 hr
= IFont_get_Charset(font
, &cs
);
1087 EXPECT_HR(hr
, S_OK
);
1088 ok(cs
== ANSI_CHARSET
, "got charset %d\n", cs
);
1090 name
= SysAllocString(marlett_font
);
1091 hr
= IFont_put_Name(font
, name
);
1092 EXPECT_HR(hr
, S_OK
);
1093 SysFreeString(name
);
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
);
1100 hr
= IFont_get_Charset(font
, &cs
);
1101 EXPECT_HR(hr
, S_OK
);
1102 ok(cs
== SYMBOL_CHARSET
, "got charset %d\n", cs
);
1104 IFont_Release(font
);
1107 static void test_OleCreateFontIndirect(void)
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
;
1122 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void**)&font
);
1123 EXPECT_HR(hr
, S_OK
);
1124 IFont_Release(font
);
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
);
1132 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
)+1;
1133 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void**)&font
);
1134 EXPECT_HR(hr
, S_OK
);
1135 IFont_Release(font
);
1137 fontdesc
.cbSizeofstruct
= 0;
1138 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void**)&font
);
1139 EXPECT_HR(hr
, S_OK
);
1140 IFont_Release(font
);
1145 hOleaut32
= GetModuleHandleA("oleaut32.dll");
1146 pOleCreateFontIndirect
= (void*)GetProcAddress(hOleaut32
, "OleCreateFontIndirect");
1147 if (!pOleCreateFontIndirect
)
1149 win_skip("OleCreateFontIndirect not available\n");
1153 test_QueryInterface();
1156 test_font_events_disp();
1157 test_GetIDsOfNames();
1160 test_ReleaseHfont();
1163 test_hfont_lifetime();
1165 test_OleCreateFontIndirect();