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 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=%d, Hi=0.\n",
96 test_name
, S(psize
).Lo
, S(psize
).Hi
, lo_size
);
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=%d, Hi=0.\n",
107 test_name
, S(psize
).Lo
, S(psize
).Hi
, lo_size
);
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 %d.\n",
117 test_name
, lf
.lfHeight
, hfont_height
);
123 static void test_QueryInterface(void)
130 hres
= pOleCreateFontIndirect(NULL
, &IID_IFont
, NULL
);
131 ok(hres
== E_POINTER
, "got 0x%08x\n", hres
);
133 hres
= pOleCreateFontIndirect(NULL
, &IID_IFont
, &pvObj
);
136 ok(hres
== S_OK
,"OCFI (NULL,..) does not return 0, but 0x%08x\n",hres
);
137 ok(font
!= NULL
,"OCFI (NULL,..) returns NULL, instead of !NULL\n");
140 hres
= IFont_QueryInterface( font
, &IID_IFont
, &pvObj
);
142 /* Test if QueryInterface increments ref counter for IFONTs */
143 ret
= IFont_AddRef(font
);
145 broken(ret
== 1), /* win95 */
146 "IFont_QI expected ref value 3 but instead got %d\n",ret
);
149 ok(hres
== S_OK
,"IFont_QI does not return S_OK, but 0x%08x\n", hres
);
150 ok(pvObj
!= NULL
,"IFont_QI does return NULL, instead of a ptr\n");
152 /* Original ref and QueryInterface ref both have to be released */
157 static void test_type_info(void)
161 IFontDisp
* fontdisp
= NULL
;
163 WCHAR name_Name
[] = {'N','a','m','e',0};
166 LCID en_us
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),
168 DISPPARAMS dispparams
;
171 pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, &pvObj
);
174 hres
= IFontDisp_GetTypeInfo(fontdisp
, 0, en_us
, &pTInfo
);
175 ok(hres
== S_OK
, "GTI returned 0x%08x instead of S_OK.\n", hres
);
176 ok(pTInfo
!= NULL
, "GTI returned NULL.\n");
178 hres
= ITypeInfo_GetNames(pTInfo
, DISPID_FONT_NAME
, names
, 3, &n
);
179 ok(hres
== S_OK
, "GetNames returned 0x%08x instead of S_OK.\n", hres
);
180 ok(n
== 1, "GetNames returned %d names instead of 1.\n", n
);
181 ok(!lstrcmpiW(names
[0],name_Name
), "DISPID_FONT_NAME doesn't get 'Names'.\n");
182 SysFreeString(names
[0]);
184 ITypeInfo_Release(pTInfo
);
186 dispparams
.cNamedArgs
= 0;
187 dispparams
.rgdispidNamedArgs
= NULL
;
188 dispparams
.cArgs
= 0;
189 dispparams
.rgvarg
= NULL
;
190 VariantInit(&varresult
);
191 hres
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_NAME
, &IID_NULL
,
192 LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
,
194 ok(hres
== S_OK
, "IFontDisp_Invoke return 0x%08x instead of S_OK.\n", hres
);
195 VariantClear(&varresult
);
197 IFontDisp_Release(fontdisp
);
200 static HRESULT WINAPI
FontEventsDisp_QueryInterface(
201 IFontEventsDisp
*iface
,
202 /* [in] */ REFIID riid
,
203 /* [iid_is][out] */ void __RPC_FAR
*__RPC_FAR
*ppvObject
)
205 if (IsEqualIID(riid
, &IID_IFontEventsDisp
) || IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDispatch
))
207 IUnknown_AddRef(iface
);
214 return E_NOINTERFACE
;
218 static ULONG WINAPI
FontEventsDisp_AddRef(
219 IFontEventsDisp
*iface
)
224 static ULONG WINAPI
FontEventsDisp_Release(
225 IFontEventsDisp
*iface
)
230 static int fonteventsdisp_invoke_called
= 0;
232 static HRESULT WINAPI
FontEventsDisp_Invoke(
233 IFontEventsDisp __RPC_FAR
* iface
,
234 /* [in] */ DISPID dispIdMember
,
235 /* [in] */ REFIID riid
,
236 /* [in] */ LCID lcid
,
237 /* [in] */ WORD wFlags
,
238 /* [out][in] */ DISPPARAMS __RPC_FAR
*pDispParams
,
239 /* [out] */ VARIANT __RPC_FAR
*pVarResult
,
240 /* [out] */ EXCEPINFO __RPC_FAR
*pExcepInfo
,
241 /* [out] */ UINT __RPC_FAR
*puArgErr
)
243 static const WCHAR wszBold
[] = {'B','o','l','d',0};
244 ok(wFlags
== INVOKE_FUNC
, "invoke flags should have been INVOKE_FUNC instead of 0x%x\n", wFlags
);
245 ok(dispIdMember
== DISPID_FONT_CHANGED
, "dispIdMember should have been DISPID_FONT_CHANGED instead of 0x%x\n", dispIdMember
);
246 ok(pDispParams
->cArgs
== 1, "pDispParams->cArgs should have been 1 instead of %d\n", pDispParams
->cArgs
);
247 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]));
248 ok(!lstrcmpW(V_BSTR(&pDispParams
->rgvarg
[0]), wszBold
), "String in first param should have been \"Bold\"\n");
250 fonteventsdisp_invoke_called
++;
254 static IFontEventsDispVtbl FontEventsDisp_Vtbl
=
256 FontEventsDisp_QueryInterface
,
257 FontEventsDisp_AddRef
,
258 FontEventsDisp_Release
,
262 FontEventsDisp_Invoke
265 static IFontEventsDisp FontEventsDisp
= { &FontEventsDisp_Vtbl
};
267 static void test_font_events_disp(void)
271 IConnectionPointContainer
*pCPC
;
272 IConnectionPoint
*pCP
;
276 IFontDisp
*pFontDisp
;
277 DISPPARAMS dispparams
;
280 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
);
281 fontdesc
.lpstrName
= MSSansSerif_font
;
282 fontdesc
.cySize
.int64
= 12 * 10000; /* 12 pt */
283 fontdesc
.sWeight
= FW_NORMAL
;
284 fontdesc
.sCharset
= 0;
285 fontdesc
.fItalic
= FALSE
;
286 fontdesc
.fUnderline
= FALSE
;
287 fontdesc
.fStrikethrough
= FALSE
;
289 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&pFont
);
290 ok_ole_success(hr
, "OleCreateFontIndirect");
292 hr
= IFont_QueryInterface(pFont
, &IID_IConnectionPointContainer
, (void **)&pCPC
);
293 ok_ole_success(hr
, "IFont_QueryInterface");
295 hr
= IConnectionPointContainer_FindConnectionPoint(pCPC
, &IID_IFontEventsDisp
, &pCP
);
296 ok_ole_success(hr
, "IConnectionPointContainer_FindConnectionPoint");
297 IConnectionPointContainer_Release(pCPC
);
299 hr
= IConnectionPoint_Advise(pCP
, (IUnknown
*)&FontEventsDisp
, &dwCookie
);
300 ok_ole_success(hr
, "IConnectionPoint_Advise");
301 IConnectionPoint_Release(pCP
);
303 hr
= IFont_put_Bold(pFont
, TRUE
);
304 ok_ole_success(hr
, "IFont_put_Bold");
306 ok(fonteventsdisp_invoke_called
== 1, "IFontEventDisp::Invoke wasn't called once\n");
308 hr
= IFont_QueryInterface(pFont
, &IID_IFontDisp
, (void **)&pFontDisp
);
309 ok_ole_success(hr
, "IFont_QueryInterface");
311 V_VT(&vararg
) = VT_BOOL
;
312 V_BOOL(&vararg
) = VARIANT_FALSE
;
313 dispparams
.cNamedArgs
= 0;
314 dispparams
.rgdispidNamedArgs
= NULL
;
315 dispparams
.cArgs
= 1;
316 dispparams
.rgvarg
= &vararg
;
317 hr
= IFontDisp_Invoke(pFontDisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYPUT
, &dispparams
, NULL
, NULL
, NULL
);
319 IFontDisp_Release(pFontDisp
);
321 ok(fonteventsdisp_invoke_called
== 2, "IFontEventDisp::Invoke was called %d times instead of twice\n",
322 fonteventsdisp_invoke_called
);
324 hr
= IFont_Clone(pFont
, &pFont2
);
325 ok_ole_success(hr
, "IFont_Clone");
326 IFont_Release(pFont
);
328 hr
= IFont_put_Bold(pFont2
, FALSE
);
329 ok_ole_success(hr
, "IFont_put_Bold");
331 /* this test shows that the notification routine isn't called again */
332 ok(fonteventsdisp_invoke_called
== 2, "IFontEventDisp::Invoke was called %d times instead of twice\n",
333 fonteventsdisp_invoke_called
);
335 IFont_Release(pFont2
);
338 static void test_names_ids(WCHAR
* w_name_1
, const char* a_name_1
,
339 WCHAR
* w_name_2
, const char* a_name_2
,
340 LCID lcid
, DISPID id_1
, DISPID id_2
,
341 HRESULT hres_expect
, int numnames
)
344 IFontDisp
*fontdisp
= NULL
;
346 DISPID rgDispId
[2] = {0xdeadbeef, 0xdeadbeef};
347 LPOLESTR names
[2] = {w_name_1
, w_name_2
};
349 pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, &pvObj
);
352 hres
= IFontDisp_GetIDsOfNames(fontdisp
, &IID_NULL
, names
, numnames
,
356 ok(hres
== hres_expect
,
357 "GetIDsOfNames: \"%s\", \"%s\" returns 0x%08x, expected 0x%08x.\n",
358 a_name_1
, a_name_2
, hres
, hres_expect
);
360 /* test first DISPID */
361 ok(rgDispId
[0]==id_1
,
362 "GetIDsOfNames: \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
363 a_name_1
, rgDispId
[0], id_1
);
365 /* test second DISPID is present */
368 ok(rgDispId
[1]==id_2
,
369 "GetIDsOfNames: ..., \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
370 a_name_2
, rgDispId
[1], id_2
);
373 IFontDisp_Release(fontdisp
);
376 static void test_GetIDsOfNames(void)
378 WCHAR name_Name
[] = {'N','a','m','e',0};
379 WCHAR name_Italic
[] = {'I','t','a','l','i','c',0};
380 WCHAR name_Size
[] = {'S','i','z','e',0};
381 WCHAR name_Bold
[] = {'B','o','l','d',0};
382 WCHAR name_Underline
[] = {'U','n','d','e','r','l','i','n','e',0};
383 WCHAR name_Strikethrough
[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
384 WCHAR name_Weight
[] = {'W','e','i','g','h','t',0};
385 WCHAR name_Charset
[] = {'C','h','a','r','s','e','t',0};
386 WCHAR name_Foo
[] = {'F','o','o',0};
387 WCHAR name_nAmE
[] = {'n','A','m','E',0};
388 WCHAR name_Nom
[] = {'N','o','m',0};
390 LCID en_us
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),
392 LCID fr_fr
= MAKELCID(MAKELANGID(LANG_FRENCH
,SUBLANG_FRENCH
),
395 /* Test DISPID_FONTs for the various properties. */
396 test_names_ids(name_Name
, "Name", NULL
, "", en_us
,
397 DISPID_FONT_NAME
, 0, S_OK
,1);
398 test_names_ids(name_Size
, "Size", NULL
, "", en_us
,
399 DISPID_FONT_SIZE
, 0, S_OK
,1);
400 test_names_ids(name_Bold
, "Bold", NULL
, "", en_us
,
401 DISPID_FONT_BOLD
, 0, S_OK
,1);
402 test_names_ids(name_Italic
, "Italic", NULL
, "", en_us
,
403 DISPID_FONT_ITALIC
, 0, S_OK
,1);
404 test_names_ids(name_Underline
, "Underline", NULL
, "", en_us
,
405 DISPID_FONT_UNDER
, 0, S_OK
,1);
406 test_names_ids(name_Strikethrough
, "Strikethrough", NULL
, "", en_us
,
407 DISPID_FONT_STRIKE
, 0, S_OK
,1);
408 test_names_ids(name_Weight
, "Weight", NULL
, "", en_us
,
409 DISPID_FONT_WEIGHT
, 0, S_OK
,1);
410 test_names_ids(name_Charset
, "Charset", NULL
, "", en_us
,
411 DISPID_FONT_CHARSET
, 0, S_OK
,1);
413 /* Capitalization doesn't matter. */
414 test_names_ids(name_nAmE
, "nAmE", NULL
, "", en_us
,
415 DISPID_FONT_NAME
, 0, S_OK
,1);
418 test_names_ids(name_Foo
, "Foo", NULL
, "", en_us
,
419 DISPID_UNKNOWN
, 0, DISP_E_UNKNOWNNAME
,1);
421 /* Pass several names: first is processed, */
422 /* second gets DISPID_UNKNOWN and doesn't affect retval. */
423 test_names_ids(name_Italic
, "Italic", name_Name
, "Name", en_us
,
424 DISPID_FONT_ITALIC
, DISPID_UNKNOWN
, S_OK
,2);
425 test_names_ids(name_Italic
, "Italic", name_Foo
, "Foo", en_us
,
426 DISPID_FONT_ITALIC
, DISPID_UNKNOWN
, S_OK
,2);
428 /* Locale ID has no effect. */
429 test_names_ids(name_Name
, "Name", NULL
, "", fr_fr
,
430 DISPID_FONT_NAME
, 0, S_OK
,1);
431 test_names_ids(name_Nom
, "This is not a font", NULL
, "", fr_fr
,
432 DISPID_UNKNOWN
, 0, DISP_E_UNKNOWNNAME
,1);
434 /* One of the arguments are invalid */
435 test_names_ids(name_Name
, "Name", NULL
, "", en_us
,
436 0xdeadbeef, 0xdeadbeef, E_INVALIDARG
,0);
437 test_names_ids(name_Italic
, "Italic", NULL
, "", en_us
,
438 0xdeadbeef, 0xdeadbeef, E_INVALIDARG
,0);
439 test_names_ids(name_Foo
, "Foo", NULL
, "", en_us
,
440 0xdeadbeef, 0xdeadbeef, E_INVALIDARG
,0);
442 /* Crazy locale ID? */
443 test_names_ids(name_Name
, "Name", NULL
, "", -1,
444 DISPID_FONT_NAME
, 0, S_OK
,1);
447 static void test_Invoke(void)
452 DISPPARAMS dispparams
;
455 hr
= pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, (void **)&fontdisp
);
456 ok_ole_success(hr
, "OleCreateFontIndirect");
458 V_VT(&vararg
) = VT_BOOL
;
459 V_BOOL(&vararg
) = VARIANT_FALSE
;
460 dispparams
.cNamedArgs
= 0;
461 dispparams
.rgdispidNamedArgs
= NULL
;
462 dispparams
.cArgs
= 1;
463 dispparams
.rgvarg
= &vararg
;
464 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_IFontDisp
, 0, DISPATCH_PROPERTYPUT
, &dispparams
, NULL
, NULL
, NULL
);
465 ok(hr
== DISP_E_UNKNOWNINTERFACE
, "IFontDisp_Invoke should have returned DISP_E_UNKNOWNINTERFACE instead of 0x%08x\n", hr
);
467 dispparams
.cArgs
= 0;
468 dispparams
.rgvarg
= NULL
;
469 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYPUT
, &dispparams
, NULL
, NULL
, NULL
);
470 ok(hr
== DISP_E_BADPARAMCOUNT
, "IFontDisp_Invoke should have returned DISP_E_BADPARAMCOUNT instead of 0x%08x\n", hr
);
472 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYPUT
, 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
, NULL
, NULL
, NULL
);
476 ok(hr
== DISP_E_PARAMNOTOPTIONAL
, "IFontDisp_Invoke should have returned DISP_E_PARAMNOTOPTIONAL instead of 0x%08x\n", hr
);
478 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, NULL
, &varresult
, NULL
, NULL
);
479 ok_ole_success(hr
, "IFontDisp_Invoke");
481 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_METHOD
, 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 hr
= IFontDisp_Invoke(fontdisp
, 0xdeadbeef, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, NULL
, &varresult
, NULL
, NULL
);
485 ok(hr
== DISP_E_MEMBERNOTFOUND
, "IFontDisp_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr
);
487 dispparams
.cArgs
= 1;
488 dispparams
.rgvarg
= &vararg
;
489 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, NULL
, NULL
);
490 ok_ole_success(hr
, "IFontDisp_Invoke");
492 IFontDisp_Release(fontdisp
);
495 static void test_IsEqual(void)
502 /* Basic font description */
503 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
504 fd
.lpstrName
= system_font
;
505 S(fd
.cySize
).Lo
= 100;
506 S(fd
.cySize
).Hi
= 100;
511 fd
.fStrikethrough
= 0;
514 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt
);
516 /* Test equal fonts */
517 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
518 hres
= IFont_IsEqual(ifnt
,ifnt2
);
520 "IFont_IsEqual: (EQUAL) Expected S_OK but got 0x%08x\n",hres
);
521 IFont_Release(ifnt2
);
523 /* Check for bad pointer */
524 hres
= IFont_IsEqual(ifnt
,NULL
);
525 ok(hres
== E_POINTER
,
526 "IFont_IsEqual: (NULL) Expected 0x80004003 but got 0x%08x\n",hres
);
529 fd
.lpstrName
= arial_font
;
530 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
531 hres
= IFont_IsEqual(ifnt
,ifnt2
);
533 "IFont_IsEqual: (strName) Expected S_FALSE but got 0x%08x\n",hres
);
534 fd
.lpstrName
= system_font
;
535 IFont_Release(ifnt2
);
537 /* Test lo font size */
538 S(fd
.cySize
).Lo
= 10000;
539 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
540 hres
= IFont_IsEqual(ifnt
,ifnt2
);
542 "IFont_IsEqual: (Lo font size) Expected S_FALSE but got 0x%08x\n",hres
);
543 S(fd
.cySize
).Lo
= 100;
544 IFont_Release(ifnt2
);
546 /* Test hi font size */
547 S(fd
.cySize
).Hi
= 10000;
548 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
549 hres
= IFont_IsEqual(ifnt
,ifnt2
);
551 "IFont_IsEqual: (Hi font size) Expected S_FALSE but got 0x%08x\n",hres
);
552 S(fd
.cySize
).Hi
= 100;
553 IFont_Release(ifnt2
);
555 /* Test font weight */
557 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
558 hres
= IFont_IsEqual(ifnt
,ifnt2
);
560 "IFont_IsEqual: (Weight) Expected S_FALSE but got 0x%08x\n",hres
);
562 IFont_Release(ifnt2
);
566 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
567 hres
= IFont_IsEqual(ifnt
,ifnt2
);
569 "IFont_IsEqual: (Charset) Expected S_FALSE but got 0x%08x\n",hres
);
571 IFont_Release(ifnt2
);
573 /* Test italic setting */
575 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
576 hres
= IFont_IsEqual(ifnt
,ifnt2
);
578 "IFont_IsEqual: (Italic) Expected S_FALSE but got 0x%08x\n",hres
);
580 IFont_Release(ifnt2
);
582 /* Test underline setting */
584 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
585 hres
= IFont_IsEqual(ifnt
,ifnt2
);
587 "IFont_IsEqual: (Underline) Expected S_FALSE but got 0x%08x\n",hres
);
589 IFont_Release(ifnt2
);
591 /* Test strikethrough setting */
592 fd
.fStrikethrough
= 1;
593 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
594 hres
= IFont_IsEqual(ifnt
,ifnt2
);
596 "IFont_IsEqual: (Strikethrough) Expected S_FALSE but got 0x%08x\n",hres
);
597 fd
.fStrikethrough
= 0;
598 IFont_Release(ifnt2
);
604 static void test_ReleaseHfont(void)
607 LPVOID pvObj1
= NULL
;
608 LPVOID pvObj2
= NULL
;
615 /* Basic font description */
616 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
617 fd
.lpstrName
= system_font
;
618 S(fd
.cySize
).Lo
= 100;
619 S(fd
.cySize
).Hi
= 100;
624 fd
.fStrikethrough
= 0;
626 /* Create HFONTs and IFONTs */
627 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj1
);
629 IFont_get_hFont(ifnt1
,&hfnt1
);
630 fd
.lpstrName
= arial_font
;
631 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
633 IFont_get_hFont(ifnt2
,&hfnt2
);
635 /* Try invalid HFONT */
636 hres
= IFont_ReleaseHfont(ifnt1
,NULL
);
637 ok(hres
== E_INVALIDARG
,
638 "IFont_ReleaseHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
641 /* Try to add a bad HFONT */
642 hres
= IFont_ReleaseHfont(ifnt1
,(HFONT
)32);
644 "IFont_ReleaseHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
647 /* Release all refs */
648 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
650 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
653 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
655 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
658 /* Check that both lists are empty */
659 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
661 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
664 /* The list should be empty */
665 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
667 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
670 IFont_Release(ifnt1
);
671 IFont_Release(ifnt2
);
674 static void test_AddRefHfont(void)
685 /* Basic font description */
686 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
687 fd
.lpstrName
= system_font
;
688 S(fd
.cySize
).Lo
= 100;
689 S(fd
.cySize
).Hi
= 100;
694 fd
.fStrikethrough
= 0;
696 /* Create HFONTs and IFONTs */
697 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt1
);
698 IFont_get_hFont(ifnt1
,&hfnt1
);
699 fd
.lpstrName
= arial_font
;
700 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
701 IFont_get_hFont(ifnt2
,&hfnt2
);
703 /* Try invalid HFONT */
704 hres
= IFont_AddRefHfont(ifnt1
,NULL
);
705 ok(hres
== E_INVALIDARG
,
706 "IFont_AddRefHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
709 /* Try to add a bad HFONT */
710 hres
= IFont_AddRefHfont(ifnt1
,(HFONT
)32);
712 "IFont_AddRefHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
715 /* Add simple IFONT HFONT pair */
716 hres
= IFont_AddRefHfont(ifnt1
,hfnt1
);
718 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
721 /* IFONT and HFONT do not have to be the same (always looks at HFONT) */
722 hres
= IFont_AddRefHfont(ifnt2
,hfnt1
);
724 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
727 /* Release all hfnt1 refs */
728 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
730 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
733 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
735 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
738 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
740 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
743 /* Check if hfnt1 is empty */
744 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
746 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
749 /* Release all hfnt2 refs */
750 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
752 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
755 /* Check if hfnt2 is empty */
756 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
758 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
761 /* Show that releasing an IFONT does not always release it from the HFONT cache. */
763 IFont_Release(ifnt1
);
765 /* Add a reference for destroyed hfnt1 */
766 hres
= IFont_AddRefHfont(ifnt2
,hfnt1
);
768 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
771 /* Decrement reference for destroyed hfnt1 */
772 hres
= IFont_ReleaseHfont(ifnt2
,hfnt1
);
774 hres
== S_FALSE
, /* <= win2k */
775 "IFont_AddRefHfont: (Release ref) Expected S_OK or S_FALSE but got 0x%08x\n",
778 /* Shows that releasing all IFONT's does clear the HFONT cache. */
780 IFont_Release(ifnt2
);
782 /* Need to make a new IFONT for testing */
784 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt3
);
785 IFont_get_hFont(ifnt3
,&hfnt3
);
787 /* Add a reference for destroyed hfnt1 */
788 hres
= IFont_AddRefHfont(ifnt3
,hfnt1
);
790 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
793 /* Decrement reference for destroyed hfnt1 */
794 hres
= IFont_ReleaseHfont(ifnt3
,hfnt1
);
796 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
799 IFont_Release(ifnt3
);
802 static void test_returns(void)
808 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
);
809 fontdesc
.lpstrName
= MSSansSerif_font
;
810 fontdesc
.cySize
.int64
= 12 * 10000; /* 12 pt */
811 fontdesc
.sWeight
= FW_NORMAL
;
812 fontdesc
.sCharset
= 0;
813 fontdesc
.fItalic
= FALSE
;
814 fontdesc
.fUnderline
= FALSE
;
815 fontdesc
.fStrikethrough
= FALSE
;
817 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&pFont
);
818 ok_ole_success(hr
, "OleCreateFontIndirect");
820 hr
= IFont_put_Name(pFont
, NULL
);
821 ok(hr
== CTL_E_INVALIDPROPERTYVALUE
,
822 "IFont::put_Name: Expected CTL_E_INVALIDPROPERTYVALUE got 0x%08x\n",
825 hr
= IFont_get_Name(pFont
, NULL
);
827 "IFont::get_Name: Expected E_POINTER got 0x%08x\n",
830 hr
= IFont_get_Size(pFont
, NULL
);
832 "IFont::get_Size: Expected E_POINTER got 0x%08x\n",
835 hr
= IFont_get_Bold(pFont
, NULL
);
837 "IFont::get_Bold: Expected E_POINTER got 0x%08x\n",
840 IFont_Release(pFont
);
843 static void test_hfont_lifetime(void)
848 HFONT hfont
, first_hfont
= NULL
;
853 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
);
854 fontdesc
.lpstrName
= arial_font
;
855 fontdesc
.cySize
.int64
= 12 * 10000; /* 12 pt */
856 fontdesc
.sWeight
= FW_NORMAL
;
857 fontdesc
.sCharset
= ANSI_CHARSET
;
858 fontdesc
.fItalic
= FALSE
;
859 fontdesc
.fUnderline
= FALSE
;
860 fontdesc
.fStrikethrough
= FALSE
;
862 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
863 ok_ole_success(hr
, "OleCreateFontIndirect");
865 hr
= IFont_get_hFont(font
, &hfont
);
866 ok_ole_success(hr
, "get_hFont");
868 /* show that if the font is updated the old hfont is deleted when the
869 new font is realized */
870 for(i
= 0; i
< 100; i
++)
872 HFONT last_hfont
= hfont
;
874 size
.int64
= (i
+ 10) * 20000;
876 obj_type
= GetObjectType(hfont
);
877 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
879 hr
= IFont_put_Size(font
, size
);
880 ok_ole_success(hr
, "put_Size");
882 /* put_Size doesn't cause the new font to be realized */
883 obj_type
= GetObjectType(last_hfont
);
884 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
886 hr
= IFont_get_hFont(font
, &hfont
);
887 ok_ole_success(hr
, "get_hFont");
889 obj_type
= GetObjectType(last_hfont
);
890 ok(obj_type
== 0, "%d: got obj type %d\n", i
, obj_type
);
893 /* now show that if we take a reference on the hfont, it persists
894 until the font object is released */
895 for(i
= 0; i
< 100; i
++)
898 size
.int64
= (i
+ 10) * 20000;
900 obj_type
= GetObjectType(hfont
);
901 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
903 hr
= IFont_put_Size(font
, size
);
904 ok_ole_success(hr
, "put_Size");
906 hr
= IFont_get_hFont(font
, &hfont
);
907 ok_ole_success(hr
, "get_hFont");
909 hr
= IFont_AddRefHfont(font
, hfont
);
910 ok_ole_success(hr
, "AddRefHfont");
912 if(i
== 0) first_hfont
= hfont
;
913 obj_type
= GetObjectType(first_hfont
);
914 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
919 obj_type
= GetObjectType(first_hfont
);
920 ok(obj_type
== 0, "got obj type %d\n", obj_type
);
922 /* An AddRefHfont followed by a ReleaseHfont means the font doesn't not persist
923 through re-realization */
925 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
926 ok_ole_success(hr
, "OleCreateFontIndirect");
928 hr
= IFont_get_hFont(font
, &hfont
);
929 ok_ole_success(hr
, "get_hFont");
931 for(i
= 0; i
< 100; i
++)
933 HFONT last_hfont
= hfont
;
935 size
.int64
= (i
+ 10) * 20000;
937 obj_type
= GetObjectType(hfont
);
938 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
940 hr
= IFont_put_Size(font
, size
);
941 ok_ole_success(hr
, "put_Size");
943 /* put_Size doesn't cause the new font to be realized */
944 obj_type
= GetObjectType(last_hfont
);
945 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
947 hr
= IFont_get_hFont(font
, &hfont
);
948 ok_ole_success(hr
, "get_hFont");
950 hr
= IFont_AddRefHfont(font
, hfont
);
951 ok_ole_success(hr
, "AddRefHfont");
953 hr
= IFont_ReleaseHfont(font
, hfont
);
954 ok_ole_success(hr
, "ReleaseHfont");
956 obj_type
= GetObjectType(last_hfont
);
957 ok(obj_type
== 0, "%d: got obj type %d\n", i
, obj_type
);
960 /* Interestingly if we release a nonexistent reference on the hfont,
961 * it persists until the font object is released
963 for(i
= 0; i
< 100; i
++)
965 size
.int64
= (i
+ 10) * 20000;
967 obj_type
= GetObjectType(hfont
);
968 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
970 hr
= IFont_put_Size(font
, size
);
971 ok_ole_success(hr
, "put_Size");
973 hr
= IFont_get_hFont(font
, &hfont
);
974 ok_ole_success(hr
, "get_hFont");
976 hr
= IFont_ReleaseHfont(font
, hfont
);
977 ok_ole_success(hr
, "ReleaseHfont");
979 if(i
== 0) first_hfont
= hfont
;
980 obj_type
= GetObjectType(first_hfont
);
981 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
986 obj_type
= GetObjectType(first_hfont
);
987 ok(obj_type
== 0, "got obj type %d\n", obj_type
);
989 /* If we take two internal references on a hfont then we can release
990 it twice. So it looks like there's a total reference count
991 that includes internal and external references */
993 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
994 ok_ole_success(hr
, "OleCreateFontIndirect");
995 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font2
);
996 ok_ole_success(hr
, "OleCreateFontIndirect");
998 hr
= IFont_get_hFont(font
, &hfont
);
999 ok_ole_success(hr
, "get_hFont");
1000 hr
= IFont_get_hFont(font2
, &first_hfont
);
1001 ok_ole_success(hr
, "get_hFont");
1003 ok(hfont
== first_hfont
, "fonts differ\n");
1004 hr
= IFont_ReleaseHfont(font
, hfont
);
1005 ok(hr
== S_OK
, "got %08x\n", hr
);
1006 hr
= IFont_ReleaseHfont(font
, hfont
);
1008 ok(hr
== S_OK
, "got %08x\n", hr
);
1009 hr
= IFont_ReleaseHfont(font
, hfont
);
1010 ok(hr
== S_FALSE
, "got %08x\n", hr
);
1012 obj_type
= GetObjectType(hfont
);
1013 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1015 IFont_Release(font
);
1017 obj_type
= GetObjectType(hfont
);
1018 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1020 IFont_Release(font2
);
1022 obj_type
= GetObjectType(hfont
);
1023 ok(obj_type
== 0, "got obj type %d\n", obj_type
);
1026 static void test_realization(void)
1034 /* Try to create a symbol only font (marlett) with charset
1035 set to ANSI. This will result in another, ANSI, font
1037 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
);
1038 fontdesc
.lpstrName
= marlett_font
;
1039 fontdesc
.cySize
.int64
= 12 * 10000; /* 12 pt */
1040 fontdesc
.sWeight
= FW_NORMAL
;
1041 fontdesc
.sCharset
= ANSI_CHARSET
;
1042 fontdesc
.fItalic
= FALSE
;
1043 fontdesc
.fUnderline
= FALSE
;
1044 fontdesc
.fStrikethrough
= FALSE
;
1046 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
1047 ok_ole_success(hr
, "OleCreateFontIndirect");
1049 hr
= IFont_get_Charset(font
, &cs
);
1050 ok_ole_success(hr
, "get_Charset");
1051 ok(cs
== ANSI_CHARSET
, "got charset %d\n", cs
);
1053 IFont_Release(font
);
1055 /* Now create an ANSI font and change the name to marlett */
1057 fontdesc
.lpstrName
= arial_font
;
1059 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
1060 ok_ole_success(hr
, "OleCreateFontIndirect");
1062 hr
= IFont_get_Charset(font
, &cs
);
1063 ok_ole_success(hr
, "get_Charset");
1064 ok(cs
== ANSI_CHARSET
, "got charset %d\n", cs
);
1066 name
= SysAllocString(marlett_font
);
1067 hr
= IFont_put_Name(font
, name
);
1068 ok_ole_success(hr
, "put_Name");
1069 SysFreeString(name
);
1071 hr
= IFont_get_Name(font
, &name
);
1072 ok_ole_success(hr
, "get_Name");
1073 ok(!lstrcmpiW(name
, marlett_font
), "got name %s\n", wine_dbgstr_w(name
));
1074 SysFreeString(name
);
1076 hr
= IFont_get_Charset(font
, &cs
);
1077 ok_ole_success(hr
, "get_Charset");
1078 ok(cs
== SYMBOL_CHARSET
, "got charset %d\n", cs
);
1080 IFont_Release(font
);
1085 hOleaut32
= GetModuleHandleA("oleaut32.dll");
1086 pOleCreateFontIndirect
= (void*)GetProcAddress(hOleaut32
, "OleCreateFontIndirect");
1087 if (!pOleCreateFontIndirect
)
1089 win_skip("OleCreateFontIndirect not available\n");
1093 test_QueryInterface();
1096 /* Test various size operations and conversions. */
1097 /* Add more as needed. */
1098 if (0) /* FIXME: failing tests */
1100 test_ifont_sizes(180000, 0, 72, 2540, -18, "default");
1101 test_ifont_sizes(180000, 0, 144, 2540, -36, "ratio1"); /* change ratio */
1102 test_ifont_sizes(180000, 0, 72, 1270, -36, "ratio2"); /* 2nd part of ratio */
1104 /* These depend on details of how IFont rounds sizes internally. */
1105 test_ifont_sizes(0, 0, 72, 2540, 0, "zero size"); /* zero size */
1106 test_ifont_sizes(186000, 0, 72, 2540, -19, "rounding"); /* test rounding */
1109 test_font_events_disp();
1110 test_GetIDsOfNames();
1113 test_ReleaseHfont();
1116 test_hfont_lifetime();