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
31 #include <wine/test.h>
44 DEFINE_GUID(GUID_NULL
,0,0,0,0,0,0,0,0,0,0,0);
46 static WCHAR MSSansSerif_font
[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0};
47 static WCHAR system_font
[] = { 'S','y','s','t','e','m',0 };
48 static WCHAR arial_font
[] = { 'A','r','i','a','l',0 };
50 static HMODULE hOleaut32
;
52 static HRESULT (WINAPI
*pOleCreateFontIndirect
)(LPFONTDESC
,REFIID
,LPVOID
*);
54 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
56 /* Create a font with cySize given by lo_size, hi_size, */
57 /* SetRatio to ratio_logical, ratio_himetric, */
58 /* check that resulting hfont has height hfont_height. */
59 /* Various checks along the way. */
61 static void test_ifont_sizes(long lo_size
, long hi_size
,
62 long ratio_logical
, long ratio_himetric
,
63 long hfont_height
, const char * test_name
)
73 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
74 fd
.lpstrName
= system_font
;
75 S(fd
.cySize
).Lo
= lo_size
;
76 S(fd
.cySize
).Hi
= hi_size
;
81 fd
.fStrikethrough
= 0;
83 /* Create font, test that it worked. */
84 hres
= pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj
);
86 ok(hres
== S_OK
,"%s: OCFI returns 0x%08x instead of S_OK.\n",
88 ok(pvObj
!= NULL
,"%s: OCFI returns NULL.\n", test_name
);
90 /* Read back size. Hi part was ignored. */
91 hres
= IFont_get_Size(ifnt
, &psize
);
92 ok(hres
== S_OK
,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
94 ok(S(psize
).Lo
== lo_size
&& S(psize
).Hi
== 0,
95 "%s: get_Size: Lo=%d, Hi=%d; expected Lo=%ld, Hi=%ld.\n",
96 test_name
, S(psize
).Lo
, S(psize
).Hi
, lo_size
, 0L);
98 /* Change ratio, check size unchanged. Standard is 72, 2540. */
99 hres
= IFont_SetRatio(ifnt
, ratio_logical
, ratio_himetric
);
100 ok(hres
== S_OK
,"%s: IFont_SR returns 0x%08x instead of S_OK.\n",
102 hres
= IFont_get_Size(ifnt
, &psize
);
103 ok(hres
== S_OK
,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
105 ok(S(psize
).Lo
== lo_size
&& S(psize
).Hi
== 0,
106 "%s: gS after SR: Lo=%d, Hi=%d; expected Lo=%ld, Hi=%ld.\n",
107 test_name
, S(psize
).Lo
, S(psize
).Hi
, lo_size
, 0L);
109 /* Check hFont size with this ratio. This tests an important */
110 /* conversion for which MSDN is very wrong. */
111 hres
= IFont_get_hFont (ifnt
, &hfont
);
112 ok(hres
== S_OK
, "%s: IFont_get_hFont returns 0x%08x instead of S_OK.\n",
114 hres
= GetObject (hfont
, sizeof(LOGFONT
), &lf
);
115 ok(lf
.lfHeight
== hfont_height
,
116 "%s: hFont has lf.lfHeight=%d, expected %ld.\n",
117 test_name
, lf
.lfHeight
, hfont_height
);
123 static void test_QueryInterface(void)
130 hres
= pOleCreateFontIndirect(NULL
, &IID_IFont
, &pvObj
);
133 ok(hres
== S_OK
,"OCFI (NULL,..) does not return 0, but 0x%08x\n",hres
);
134 ok(font
!= NULL
,"OCFI (NULL,..) returns NULL, instead of !NULL\n");
137 hres
= IFont_QueryInterface( font
, &IID_IFont
, &pvObj
);
139 /* Test if QueryInterface increments ref counter for IFONTs */
140 ret
= IFont_AddRef(font
);
142 broken(ret
== 1), /* win95 */
143 "IFont_QI expected ref value 3 but instead got %ld\n",ret
);
146 ok(hres
== S_OK
,"IFont_QI does not return S_OK, but 0x%08x\n", hres
);
147 ok(pvObj
!= NULL
,"IFont_QI does return NULL, instead of a ptr\n");
149 /* Original ref and QueryInterface ref both have to be released */
154 static void test_type_info(void)
158 IFontDisp
* fontdisp
= NULL
;
160 WCHAR name_Name
[] = {'N','a','m','e',0};
163 LCID en_us
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),
165 DISPPARAMS dispparams
;
168 pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, &pvObj
);
171 hres
= IFontDisp_GetTypeInfo(fontdisp
, 0, en_us
, &pTInfo
);
172 ok(hres
== S_OK
, "GTI returned 0x%08x instead of S_OK.\n", hres
);
173 ok(pTInfo
!= NULL
, "GTI returned NULL.\n");
175 hres
= ITypeInfo_GetNames(pTInfo
, DISPID_FONT_NAME
, names
, 3, &n
);
176 ok(hres
== S_OK
, "GetNames returned 0x%08x instead of S_OK.\n", hres
);
177 ok(n
== 1, "GetNames returned %d names instead of 1.\n", n
);
178 ok(!lstrcmpiW(names
[0],name_Name
), "DISPID_FONT_NAME doesn't get 'Names'.\n");
179 SysFreeString(names
[0]);
181 ITypeInfo_Release(pTInfo
);
183 dispparams
.cNamedArgs
= 0;
184 dispparams
.rgdispidNamedArgs
= NULL
;
185 dispparams
.cArgs
= 0;
186 dispparams
.rgvarg
= NULL
;
187 VariantInit(&varresult
);
188 hres
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_NAME
, &IID_NULL
,
189 LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
,
191 ok(hres
== S_OK
, "IFontDisp_Invoke return 0x%08x instead of S_OK.\n", hres
);
192 VariantClear(&varresult
);
194 IFontDisp_Release(fontdisp
);
197 static HRESULT WINAPI
FontEventsDisp_QueryInterface(
198 IFontEventsDisp
*iface
,
199 /* [in] */ REFIID riid
,
200 /* [iid_is][out] */ void __RPC_FAR
*__RPC_FAR
*ppvObject
)
202 if (IsEqualIID(riid
, &IID_IFontEventsDisp
) || IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDispatch
))
204 IUnknown_AddRef(iface
);
211 return E_NOINTERFACE
;
215 static ULONG WINAPI
FontEventsDisp_AddRef(
216 IFontEventsDisp
*iface
)
221 static ULONG WINAPI
FontEventsDisp_Release(
222 IFontEventsDisp
*iface
)
227 static int fonteventsdisp_invoke_called
= 0;
229 static HRESULT WINAPI
FontEventsDisp_Invoke(
230 IFontEventsDisp __RPC_FAR
* iface
,
231 /* [in] */ DISPID dispIdMember
,
232 /* [in] */ REFIID riid
,
233 /* [in] */ LCID lcid
,
234 /* [in] */ WORD wFlags
,
235 /* [out][in] */ DISPPARAMS __RPC_FAR
*pDispParams
,
236 /* [out] */ VARIANT __RPC_FAR
*pVarResult
,
237 /* [out] */ EXCEPINFO __RPC_FAR
*pExcepInfo
,
238 /* [out] */ UINT __RPC_FAR
*puArgErr
)
240 static const WCHAR wszBold
[] = {'B','o','l','d',0};
241 ok(wFlags
== INVOKE_FUNC
, "invoke flags should have been INVOKE_FUNC instead of 0x%x\n", wFlags
);
242 ok(dispIdMember
== DISPID_FONT_CHANGED
, "dispIdMember should have been DISPID_FONT_CHANGED instead of 0x%x\n", dispIdMember
);
243 ok(pDispParams
->cArgs
== 1, "pDispParams->cArgs should have been 1 instead of %d\n", pDispParams
->cArgs
);
244 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]));
245 ok(!lstrcmpW(V_BSTR(&pDispParams
->rgvarg
[0]), wszBold
), "String in first param should have been \"Bold\"\n");
247 fonteventsdisp_invoke_called
++;
251 static IFontEventsDispVtbl FontEventsDisp_Vtbl
=
253 FontEventsDisp_QueryInterface
,
254 FontEventsDisp_AddRef
,
255 FontEventsDisp_Release
,
259 FontEventsDisp_Invoke
262 static IFontEventsDisp FontEventsDisp
= { &FontEventsDisp_Vtbl
};
264 static void test_font_events_disp(void)
268 IConnectionPointContainer
*pCPC
;
269 IConnectionPoint
*pCP
;
273 IFontDisp
*pFontDisp
;
274 DISPPARAMS dispparams
;
277 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
);
278 fontdesc
.lpstrName
= MSSansSerif_font
;
279 fontdesc
.cySize
.int64
= 12 * 10000; /* 12 pt */
280 fontdesc
.sWeight
= FW_NORMAL
;
281 fontdesc
.sCharset
= 0;
282 fontdesc
.fItalic
= FALSE
;
283 fontdesc
.fUnderline
= FALSE
;
284 fontdesc
.fStrikethrough
= FALSE
;
286 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&pFont
);
287 ok_ole_success(hr
, "OleCreateFontIndirect");
289 hr
= IFont_QueryInterface(pFont
, &IID_IConnectionPointContainer
, (void **)&pCPC
);
290 ok_ole_success(hr
, "IFont_QueryInterface");
292 hr
= IConnectionPointContainer_FindConnectionPoint(pCPC
, &IID_IFontEventsDisp
, &pCP
);
293 ok_ole_success(hr
, "IConnectionPointContainer_FindConnectionPoint");
294 IConnectionPointContainer_Release(pCPC
);
296 hr
= IConnectionPoint_Advise(pCP
, (IUnknown
*)&FontEventsDisp
, &dwCookie
);
297 ok_ole_success(hr
, "IConnectionPoint_Advise");
298 IConnectionPoint_Release(pCP
);
300 hr
= IFont_put_Bold(pFont
, TRUE
);
301 ok_ole_success(hr
, "IFont_put_Bold");
303 ok(fonteventsdisp_invoke_called
== 1, "IFontEventDisp::Invoke wasn't called once\n");
305 hr
= IFont_QueryInterface(pFont
, &IID_IFontDisp
, (void **)&pFontDisp
);
306 ok_ole_success(hr
, "IFont_QueryInterface");
308 V_VT(&vararg
) = VT_BOOL
;
309 V_BOOL(&vararg
) = VARIANT_FALSE
;
310 dispparams
.cNamedArgs
= 0;
311 dispparams
.rgdispidNamedArgs
= NULL
;
312 dispparams
.cArgs
= 1;
313 dispparams
.rgvarg
= &vararg
;
314 hr
= IFontDisp_Invoke(pFontDisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYPUT
, &dispparams
, NULL
, NULL
, NULL
);
316 IFontDisp_Release(pFontDisp
);
318 ok(fonteventsdisp_invoke_called
== 2, "IFontEventDisp::Invoke was called %d times instead of twice\n",
319 fonteventsdisp_invoke_called
);
321 hr
= IFont_Clone(pFont
, &pFont2
);
322 ok_ole_success(hr
, "IFont_Clone");
323 IFont_Release(pFont
);
325 hr
= IFont_put_Bold(pFont2
, FALSE
);
326 ok_ole_success(hr
, "IFont_put_Bold");
328 /* this test shows that the notification routine isn't called again */
329 ok(fonteventsdisp_invoke_called
== 2, "IFontEventDisp::Invoke was called %d times instead of twice\n",
330 fonteventsdisp_invoke_called
);
332 IFont_Release(pFont2
);
335 static void test_names_ids(WCHAR
* w_name_1
, const char* a_name_1
,
336 WCHAR
* w_name_2
, const char* a_name_2
,
337 LCID lcid
, DISPID id_1
, DISPID id_2
,
338 HRESULT hres_expect
, int numnames
)
341 IFontDisp
*fontdisp
= NULL
;
343 DISPID rgDispId
[2] = {0xdeadbeef, 0xdeadbeef};
344 LPOLESTR names
[2] = {w_name_1
, w_name_2
};
346 pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, &pvObj
);
349 hres
= IFontDisp_GetIDsOfNames(fontdisp
, &IID_NULL
, names
, numnames
,
353 ok(hres
== hres_expect
,
354 "GetIDsOfNames: \"%s\", \"%s\" returns 0x%08x, expected 0x%08x.\n",
355 a_name_1
, a_name_2
, hres
, hres_expect
);
357 /* test first DISPID */
358 ok(rgDispId
[0]==id_1
,
359 "GetIDsOfNames: \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
360 a_name_1
, rgDispId
[0], id_1
);
362 /* test second DISPID is present */
365 ok(rgDispId
[1]==id_2
,
366 "GetIDsOfNames: ..., \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
367 a_name_2
, rgDispId
[1], id_2
);
370 IFontDisp_Release(fontdisp
);
373 static void test_GetIDsOfNames(void)
375 WCHAR name_Name
[] = {'N','a','m','e',0};
376 WCHAR name_Italic
[] = {'I','t','a','l','i','c',0};
377 WCHAR name_Size
[] = {'S','i','z','e',0};
378 WCHAR name_Bold
[] = {'B','o','l','d',0};
379 WCHAR name_Underline
[] = {'U','n','d','e','r','l','i','n','e',0};
380 WCHAR name_Strikethrough
[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
381 WCHAR name_Weight
[] = {'W','e','i','g','h','t',0};
382 WCHAR name_Charset
[] = {'C','h','a','r','s','e','t',0};
383 WCHAR name_Foo
[] = {'F','o','o',0};
384 WCHAR name_nAmE
[] = {'n','A','m','E',0};
385 WCHAR name_Nom
[] = {'N','o','m',0};
387 LCID en_us
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),
389 LCID fr_fr
= MAKELCID(MAKELANGID(LANG_FRENCH
,SUBLANG_FRENCH
),
392 /* Test DISPID_FONTs for the various properties. */
393 test_names_ids(name_Name
, "Name", NULL
, "", en_us
,
394 DISPID_FONT_NAME
, 0, S_OK
,1);
395 test_names_ids(name_Size
, "Size", NULL
, "", en_us
,
396 DISPID_FONT_SIZE
, 0, S_OK
,1);
397 test_names_ids(name_Bold
, "Bold", NULL
, "", en_us
,
398 DISPID_FONT_BOLD
, 0, S_OK
,1);
399 test_names_ids(name_Italic
, "Italic", NULL
, "", en_us
,
400 DISPID_FONT_ITALIC
, 0, S_OK
,1);
401 test_names_ids(name_Underline
, "Underline", NULL
, "", en_us
,
402 DISPID_FONT_UNDER
, 0, S_OK
,1);
403 test_names_ids(name_Strikethrough
, "Strikethrough", NULL
, "", en_us
,
404 DISPID_FONT_STRIKE
, 0, S_OK
,1);
405 test_names_ids(name_Weight
, "Weight", NULL
, "", en_us
,
406 DISPID_FONT_WEIGHT
, 0, S_OK
,1);
407 test_names_ids(name_Charset
, "Charset", NULL
, "", en_us
,
408 DISPID_FONT_CHARSET
, 0, S_OK
,1);
410 /* Capitalization doesn't matter. */
411 test_names_ids(name_nAmE
, "nAmE", NULL
, "", en_us
,
412 DISPID_FONT_NAME
, 0, S_OK
,1);
415 test_names_ids(name_Foo
, "Foo", NULL
, "", en_us
,
416 DISPID_UNKNOWN
, 0, DISP_E_UNKNOWNNAME
,1);
418 /* Pass several names: first is processed, */
419 /* second gets DISPID_UNKNOWN and doesn't affect retval. */
420 test_names_ids(name_Italic
, "Italic", name_Name
, "Name", en_us
,
421 DISPID_FONT_ITALIC
, DISPID_UNKNOWN
, S_OK
,2);
422 test_names_ids(name_Italic
, "Italic", name_Foo
, "Foo", en_us
,
423 DISPID_FONT_ITALIC
, DISPID_UNKNOWN
, S_OK
,2);
425 /* Locale ID has no effect. */
426 test_names_ids(name_Name
, "Name", NULL
, "", fr_fr
,
427 DISPID_FONT_NAME
, 0, S_OK
,1);
428 test_names_ids(name_Nom
, "This is not a font", NULL
, "", fr_fr
,
429 DISPID_UNKNOWN
, 0, DISP_E_UNKNOWNNAME
,1);
431 /* One of the arguments are invalid */
432 test_names_ids(name_Name
, "Name", NULL
, "", en_us
,
433 0xdeadbeef, 0xdeadbeef, E_INVALIDARG
,0);
434 test_names_ids(name_Italic
, "Italic", NULL
, "", en_us
,
435 0xdeadbeef, 0xdeadbeef, E_INVALIDARG
,0);
436 test_names_ids(name_Foo
, "Foo", NULL
, "", en_us
,
437 0xdeadbeef, 0xdeadbeef, E_INVALIDARG
,0);
439 /* Crazy locale ID? */
440 test_names_ids(name_Name
, "Name", NULL
, "", -1,
441 DISPID_FONT_NAME
, 0, S_OK
,1);
444 static void test_Invoke(void)
449 DISPPARAMS dispparams
;
452 hr
= pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, (void **)&fontdisp
);
453 ok_ole_success(hr
, "OleCreateFontIndirect");
455 V_VT(&vararg
) = VT_BOOL
;
456 V_BOOL(&vararg
) = VARIANT_FALSE
;
457 dispparams
.cNamedArgs
= 0;
458 dispparams
.rgdispidNamedArgs
= NULL
;
459 dispparams
.cArgs
= 1;
460 dispparams
.rgvarg
= &vararg
;
461 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_IFontDisp
, 0, DISPATCH_PROPERTYPUT
, &dispparams
, NULL
, NULL
, NULL
);
462 ok(hr
== DISP_E_UNKNOWNINTERFACE
, "IFontDisp_Invoke should have returned DISP_E_UNKNOWNINTERFACE instead of 0x%08x\n", hr
);
464 dispparams
.cArgs
= 0;
465 dispparams
.rgvarg
= NULL
;
466 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYPUT
, &dispparams
, NULL
, NULL
, NULL
);
467 ok(hr
== DISP_E_BADPARAMCOUNT
, "IFontDisp_Invoke should have returned DISP_E_BADPARAMCOUNT instead of 0x%08x\n", hr
);
469 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYPUT
, NULL
, NULL
, NULL
, NULL
);
470 ok(hr
== DISP_E_PARAMNOTOPTIONAL
, "IFontDisp_Invoke should have returned DISP_E_PARAMNOTOPTIONAL instead of 0x%08x\n", hr
);
472 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, NULL
, NULL
, NULL
, NULL
);
473 ok(hr
== DISP_E_PARAMNOTOPTIONAL
, "IFontDisp_Invoke should have returned DISP_E_PARAMNOTOPTIONAL instead of 0x%08x\n", hr
);
475 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, NULL
, &varresult
, NULL
, NULL
);
476 ok_ole_success(hr
, "IFontDisp_Invoke");
478 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_METHOD
, NULL
, &varresult
, NULL
, NULL
);
479 ok(hr
== DISP_E_MEMBERNOTFOUND
, "IFontDisp_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr
);
481 hr
= IFontDisp_Invoke(fontdisp
, 0xdeadbeef, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, NULL
, &varresult
, NULL
, NULL
);
482 ok(hr
== DISP_E_MEMBERNOTFOUND
, "IFontDisp_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr
);
484 dispparams
.cArgs
= 1;
485 dispparams
.rgvarg
= &vararg
;
486 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, NULL
, NULL
);
487 ok_ole_success(hr
, "IFontDisp_Invoke");
489 IFontDisp_Release(fontdisp
);
492 static void test_IsEqual(void)
496 LPVOID pvObj2
= NULL
;
501 /* Basic font description */
502 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
503 fd
.lpstrName
= system_font
;
504 S(fd
.cySize
).Lo
= 100;
505 S(fd
.cySize
).Hi
= 100;
510 fd
.fStrikethrough
= 0;
513 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj
);
516 /* Test equal fonts */
517 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
519 hres
= IFont_IsEqual(ifnt
,ifnt2
);
521 "IFont_IsEqual: (EQUAL) Expected S_OK but got 0x%08x\n",hres
);
522 IFont_Release(ifnt2
);
524 /* Check for bad pointer */
525 hres
= IFont_IsEqual(ifnt
,NULL
);
526 ok(hres
== E_POINTER
,
527 "IFont_IsEqual: (NULL) Expected 0x80004003 but got 0x%08x\n",hres
);
530 fd
.lpstrName
= arial_font
;
531 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
532 hres
= IFont_IsEqual(ifnt
,ifnt2
);
534 "IFont_IsEqual: (strName) Expected S_FALSE but got 0x%08x\n",hres
);
535 fd
.lpstrName
= system_font
;
536 IFont_Release(ifnt2
);
538 /* Test lo font size */
539 S(fd
.cySize
).Lo
= 10000;
540 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
542 hres
= IFont_IsEqual(ifnt
,ifnt2
);
544 "IFont_IsEqual: (Lo font size) Expected S_FALSE but got 0x%08x\n",hres
);
545 S(fd
.cySize
).Lo
= 100;
546 IFont_Release(ifnt2
);
548 /* Test hi font size */
549 S(fd
.cySize
).Hi
= 10000;
550 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
552 hres
= IFont_IsEqual(ifnt
,ifnt2
);
554 "IFont_IsEqual: (Hi font size) Expected S_FALSE but got 0x%08x\n",hres
);
555 S(fd
.cySize
).Hi
= 100;
556 IFont_Release(ifnt2
);
558 /* Test font weight */
560 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
562 hres
= IFont_IsEqual(ifnt
,ifnt2
);
564 "IFont_IsEqual: (Weight) Expected S_FALSE but got 0x%08x\n",hres
);
566 IFont_Release(ifnt2
);
570 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
571 hres
= IFont_IsEqual(ifnt
,ifnt2
);
573 "IFont_IsEqual: (Charset) Expected S_FALSE but got 0x%08x\n",hres
);
575 IFont_Release(ifnt2
);
577 /* Test italic setting */
579 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
580 hres
= IFont_IsEqual(ifnt
,ifnt2
);
582 "IFont_IsEqual: (Italic) Expected S_FALSE but got 0x%08x\n",hres
);
584 IFont_Release(ifnt2
);
586 /* Test underline setting */
588 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
589 hres
= IFont_IsEqual(ifnt
,ifnt2
);
591 "IFont_IsEqual: (Underline) Expected S_FALSE but got 0x%08x\n",hres
);
593 IFont_Release(ifnt2
);
595 /* Test strikethrough setting */
596 fd
.fStrikethrough
= 1;
597 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
598 hres
= IFont_IsEqual(ifnt
,ifnt2
);
600 "IFont_IsEqual: (Strikethrough) Expected S_FALSE but got 0x%08x\n",hres
);
601 fd
.fStrikethrough
= 0;
602 IFont_Release(ifnt2
);
608 static void test_ReleaseHfont(void)
611 LPVOID pvObj1
= NULL
;
612 LPVOID pvObj2
= NULL
;
619 /* Basic font description */
620 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
621 fd
.lpstrName
= system_font
;
622 S(fd
.cySize
).Lo
= 100;
623 S(fd
.cySize
).Hi
= 100;
628 fd
.fStrikethrough
= 0;
630 /* Create HFONTs and IFONTs */
631 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj1
);
633 IFont_get_hFont(ifnt1
,&hfnt1
);
634 fd
.lpstrName
= arial_font
;
635 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
637 IFont_get_hFont(ifnt2
,&hfnt2
);
639 /* Try invalid HFONT */
640 hres
= IFont_ReleaseHfont(ifnt1
,NULL
);
641 ok(hres
== E_INVALIDARG
,
642 "IFont_ReleaseHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
645 /* Try to add a bad HFONT */
646 hres
= IFont_ReleaseHfont(ifnt1
,(HFONT
)32);
648 "IFont_ReleaseHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
651 /* Release all refs */
652 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
654 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
657 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
659 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
662 /* Check that both lists are empty */
663 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
665 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
668 /* The list should be empty */
669 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
671 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
674 IFont_Release(ifnt1
);
675 IFont_Release(ifnt2
);
678 static void test_AddRefHfont(void)
689 /* Basic font description */
690 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
691 fd
.lpstrName
= system_font
;
692 S(fd
.cySize
).Lo
= 100;
693 S(fd
.cySize
).Hi
= 100;
698 fd
.fStrikethrough
= 0;
700 /* Create HFONTs and IFONTs */
701 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt1
);
702 IFont_get_hFont(ifnt1
,&hfnt1
);
703 fd
.lpstrName
= arial_font
;
704 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
705 IFont_get_hFont(ifnt2
,&hfnt2
);
707 /* Try invalid HFONT */
708 hres
= IFont_AddRefHfont(ifnt1
,NULL
);
709 ok(hres
== E_INVALIDARG
,
710 "IFont_AddRefHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
713 /* Try to add a bad HFONT */
714 hres
= IFont_AddRefHfont(ifnt1
,(HFONT
)32);
716 "IFont_AddRefHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
719 /* Add simple IFONT HFONT pair */
720 hres
= IFont_AddRefHfont(ifnt1
,hfnt1
);
722 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
725 /* IFONT and HFONT do not have to be the same (always looks at HFONT) */
726 hres
= IFont_AddRefHfont(ifnt2
,hfnt1
);
728 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
731 /* Release all hfnt1 refs */
732 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
734 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
737 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
739 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
742 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
744 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
747 /* Check if hfnt1 is empty */
748 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
750 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
753 /* Release all hfnt2 refs */
754 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
756 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
759 /* Check if hfnt2 is empty */
760 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
762 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
765 /* Show that releasing an IFONT does not always release it from the HFONT cache. */
767 IFont_Release(ifnt1
);
769 /* Add a reference for destroyed hfnt1 */
770 hres
= IFont_AddRefHfont(ifnt2
,hfnt1
);
772 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
775 /* Decrement reference for destroyed hfnt1 */
776 hres
= IFont_ReleaseHfont(ifnt2
,hfnt1
);
778 hres
== S_FALSE
, /* <= win2k */
779 "IFont_AddRefHfont: (Release ref) Expected S_OK or S_FALSE but got 0x%08x\n",
782 /* Shows that releasing all IFONT's does clear the HFONT cache. */
784 IFont_Release(ifnt2
);
786 /* Need to make a new IFONT for testing */
788 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt3
);
789 IFont_get_hFont(ifnt3
,&hfnt3
);
791 /* Add a reference for destroyed hfnt1 */
792 hres
= IFont_AddRefHfont(ifnt3
,hfnt1
);
794 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
797 /* Decrement reference for destroyed hfnt1 */
798 hres
= IFont_ReleaseHfont(ifnt3
,hfnt1
);
800 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
803 IFont_Release(ifnt3
);
808 hOleaut32
= GetModuleHandleA("oleaut32.dll");
809 pOleCreateFontIndirect
= (void*)GetProcAddress(hOleaut32
, "OleCreateFontIndirect");
810 if (!pOleCreateFontIndirect
)
812 skip("OleCreateFontIndirect not available\n");
816 test_QueryInterface();
819 /* Test various size operations and conversions. */
820 /* Add more as needed. */
821 if (0) /* FIXME: failing tests */
823 test_ifont_sizes(180000, 0, 72, 2540, -18, "default");
824 test_ifont_sizes(180000, 0, 144, 2540, -36, "ratio1"); /* change ratio */
825 test_ifont_sizes(180000, 0, 72, 1270, -36, "ratio2"); /* 2nd part of ratio */
827 /* These depend on details of how IFont rounds sizes internally. */
828 test_ifont_sizes(0, 0, 72, 2540, 0, "zero size"); /* zero size */
829 test_ifont_sizes(186000, 0, 72, 2540, -19, "rounding"); /* test rounding */
832 test_font_events_disp();
833 test_GetIDsOfNames();