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>
43 static HMODULE hOleaut32
;
45 static HRESULT (WINAPI
*pOleCreateFontIndirect
)(LPFONTDESC
,REFIID
,LPVOID
*);
47 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
49 /* Create a font with cySize given by lo_size, hi_size, */
50 /* SetRatio to ratio_logical, ratio_himetric, */
51 /* check that resulting hfont has height hfont_height. */
52 /* Various checks along the way. */
54 static void test_ifont_sizes(long lo_size
, long hi_size
,
55 long ratio_logical
, long ratio_himetric
,
56 long hfont_height
, const char * test_name
)
59 static const WCHAR fname
[] = { 'S','y','s','t','e','m',0 };
67 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
68 fd
.lpstrName
= (WCHAR
*)fname
;
69 S(fd
.cySize
).Lo
= lo_size
;
70 S(fd
.cySize
).Hi
= hi_size
;
75 fd
.fStrikethrough
= 0;
77 /* Create font, test that it worked. */
78 hres
= pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj
);
80 ok(hres
== S_OK
,"%s: OCFI returns 0x%08x instead of S_OK.\n",
82 ok(pvObj
!= NULL
,"%s: OCFI returns NULL.\n", test_name
);
84 /* Read back size. Hi part was ignored. */
85 hres
= IFont_get_Size(ifnt
, &psize
);
86 ok(hres
== S_OK
,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
88 ok(S(psize
).Lo
== lo_size
&& S(psize
).Hi
== 0,
89 "%s: get_Size: Lo=%d, Hi=%d; expected Lo=%ld, Hi=%ld.\n",
90 test_name
, S(psize
).Lo
, S(psize
).Hi
, lo_size
, 0L);
92 /* Change ratio, check size unchanged. Standard is 72, 2540. */
93 hres
= IFont_SetRatio(ifnt
, ratio_logical
, ratio_himetric
);
94 ok(hres
== S_OK
,"%s: IFont_SR returns 0x%08x instead of S_OK.\n",
96 hres
= IFont_get_Size(ifnt
, &psize
);
97 ok(hres
== S_OK
,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
99 ok(S(psize
).Lo
== lo_size
&& S(psize
).Hi
== 0,
100 "%s: gS after SR: Lo=%d, Hi=%d; expected Lo=%ld, Hi=%ld.\n",
101 test_name
, S(psize
).Lo
, S(psize
).Hi
, lo_size
, 0L);
103 /* Check hFont size with this ratio. This tests an important */
104 /* conversion for which MSDN is very wrong. */
105 hres
= IFont_get_hFont (ifnt
, &hfont
);
106 ok(hres
== S_OK
, "%s: IFont_get_hFont returns 0x%08x instead of S_OK.\n",
108 hres
= GetObject (hfont
, sizeof(LOGFONT
), &lf
);
109 ok(lf
.lfHeight
== hfont_height
,
110 "%s: hFont has lf.lfHeight=%d, expected %ld.\n",
111 test_name
, lf
.lfHeight
, hfont_height
);
117 static void test_QueryInterface(void)
124 hres
= pOleCreateFontIndirect(NULL
, &IID_IFont
, &pvObj
);
127 ok(hres
== S_OK
,"OCFI (NULL,..) does not return 0, but 0x%08x\n",hres
);
128 ok(font
!= NULL
,"OCFI (NULL,..) returns NULL, instead of !NULL\n");
131 hres
= IFont_QueryInterface( font
, &IID_IFont
, &pvObj
);
133 /* Test if QueryInterface increments ref counter for IFONTs */
134 ret
= IFont_AddRef(font
);
135 ok(ret
== 3, "IFont_QI expected ref value 3 but instead got %12u\n",ret
);
138 ok(hres
== S_OK
,"IFont_QI does not return S_OK, but 0x%08x\n", hres
);
139 ok(pvObj
!= NULL
,"IFont_QI does return NULL, instead of a ptr\n");
141 /* Orignial ref and QueryInterface ref both have to be released */
146 static void test_type_info(void)
150 IFontDisp
* fontdisp
= NULL
;
152 WCHAR name_Name
[] = {'N','a','m','e',0};
155 LCID en_us
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),
157 DISPPARAMS dispparams
;
160 pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, &pvObj
);
163 hres
= IFontDisp_GetTypeInfo(fontdisp
, 0, en_us
, &pTInfo
);
164 ok(hres
== S_OK
, "GTI returned 0x%08x instead of S_OK.\n", hres
);
165 ok(pTInfo
!= NULL
, "GTI returned NULL.\n");
167 hres
= ITypeInfo_GetNames(pTInfo
, DISPID_FONT_NAME
, names
, 3, &n
);
168 ok(hres
== S_OK
, "GetNames returned 0x%08x instead of S_OK.\n", hres
);
169 ok(n
== 1, "GetNames returned %d names instead of 1.\n", n
);
170 ok(!lstrcmpiW(names
[0],name_Name
), "DISPID_FONT_NAME doesn't get 'Names'.\n");
172 ITypeInfo_Release(pTInfo
);
174 dispparams
.cNamedArgs
= 0;
175 dispparams
.rgdispidNamedArgs
= NULL
;
176 dispparams
.cArgs
= 0;
177 dispparams
.rgvarg
= NULL
;
178 VariantInit(&varresult
);
179 hres
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_NAME
, &IID_NULL
,
180 LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
,
182 ok(hres
== S_OK
, "IFontDisp_Invoke return 0x%08x instead of S_OK.\n", hres
);
183 VariantClear(&varresult
);
185 IFontDisp_Release(fontdisp
);
188 static HRESULT WINAPI
FontEventsDisp_QueryInterface(
189 IFontEventsDisp
*iface
,
190 /* [in] */ REFIID riid
,
191 /* [iid_is][out] */ void __RPC_FAR
*__RPC_FAR
*ppvObject
)
193 if (IsEqualIID(riid
, &IID_IFontEventsDisp
) || IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDispatch
))
195 IUnknown_AddRef(iface
);
202 return E_NOINTERFACE
;
206 static ULONG WINAPI
FontEventsDisp_AddRef(
207 IFontEventsDisp
*iface
)
212 static ULONG WINAPI
FontEventsDisp_Release(
213 IFontEventsDisp
*iface
)
218 static int fonteventsdisp_invoke_called
= 0;
220 static HRESULT WINAPI
FontEventsDisp_Invoke(
221 IFontEventsDisp __RPC_FAR
* iface
,
222 /* [in] */ DISPID dispIdMember
,
223 /* [in] */ REFIID riid
,
224 /* [in] */ LCID lcid
,
225 /* [in] */ WORD wFlags
,
226 /* [out][in] */ DISPPARAMS __RPC_FAR
*pDispParams
,
227 /* [out] */ VARIANT __RPC_FAR
*pVarResult
,
228 /* [out] */ EXCEPINFO __RPC_FAR
*pExcepInfo
,
229 /* [out] */ UINT __RPC_FAR
*puArgErr
)
231 static const WCHAR wszBold
[] = {'B','o','l','d',0};
232 ok(wFlags
== INVOKE_FUNC
, "invoke flags should have been INVOKE_FUNC instead of 0x%x\n", wFlags
);
233 ok(dispIdMember
== DISPID_FONT_CHANGED
, "dispIdMember should have been DISPID_FONT_CHANGED instead of 0x%x\n", dispIdMember
);
234 ok(pDispParams
->cArgs
== 1, "pDispParams->cArgs should have been 1 instead of %d\n", pDispParams
->cArgs
);
235 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]));
236 ok(!lstrcmpW(V_BSTR(&pDispParams
->rgvarg
[0]), wszBold
), "String in first param should have been \"Bold\"\n");
238 fonteventsdisp_invoke_called
++;
242 static IFontEventsDispVtbl FontEventsDisp_Vtbl
=
244 FontEventsDisp_QueryInterface
,
245 FontEventsDisp_AddRef
,
246 FontEventsDisp_Release
,
250 FontEventsDisp_Invoke
253 static IFontEventsDisp FontEventsDisp
= { &FontEventsDisp_Vtbl
};
255 static void test_font_events_disp(void)
259 IConnectionPointContainer
*pCPC
;
260 IConnectionPoint
*pCP
;
264 IFontDisp
*pFontDisp
;
265 static const WCHAR wszMSSansSerif
[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0};
266 DISPPARAMS dispparams
;
269 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
);
270 fontdesc
.lpstrName
= (LPOLESTR
)wszMSSansSerif
;
271 fontdesc
.cySize
.int64
= 12 * 10000; /* 12 pt */
272 fontdesc
.sWeight
= FW_NORMAL
;
273 fontdesc
.sCharset
= 0;
274 fontdesc
.fItalic
= FALSE
;
275 fontdesc
.fUnderline
= FALSE
;
276 fontdesc
.fStrikethrough
= FALSE
;
278 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&pFont
);
279 ok_ole_success(hr
, "OleCreateFontIndirect");
281 hr
= IFont_QueryInterface(pFont
, &IID_IConnectionPointContainer
, (void **)&pCPC
);
282 ok_ole_success(hr
, "IFont_QueryInterface");
284 hr
= IConnectionPointContainer_FindConnectionPoint(pCPC
, &IID_IFontEventsDisp
, &pCP
);
285 ok_ole_success(hr
, "IConnectionPointContainer_FindConnectionPoint");
286 IConnectionPointContainer_Release(pCPC
);
288 hr
= IConnectionPoint_Advise(pCP
, (IUnknown
*)&FontEventsDisp
, &dwCookie
);
289 ok_ole_success(hr
, "IConnectionPoint_Advise");
290 IConnectionPoint_Release(pCP
);
292 hr
= IFont_put_Bold(pFont
, TRUE
);
293 ok_ole_success(hr
, "IFont_put_Bold");
295 ok(fonteventsdisp_invoke_called
== 1, "IFontEventDisp::Invoke wasn't called once\n");
297 hr
= IFont_QueryInterface(pFont
, &IID_IFontDisp
, (void **)&pFontDisp
);
298 ok_ole_success(hr
, "IFont_QueryInterface");
300 V_VT(&vararg
) = VT_BOOL
;
301 V_BOOL(&vararg
) = VARIANT_FALSE
;
302 dispparams
.cNamedArgs
= 0;
303 dispparams
.rgdispidNamedArgs
= NULL
;
304 dispparams
.cArgs
= 1;
305 dispparams
.rgvarg
= &vararg
;
306 hr
= IFontDisp_Invoke(pFontDisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYPUT
, &dispparams
, NULL
, NULL
, NULL
);
308 IFontDisp_Release(pFontDisp
);
310 ok(fonteventsdisp_invoke_called
== 2, "IFontEventDisp::Invoke was called %d times instead of twice\n",
311 fonteventsdisp_invoke_called
);
313 hr
= IFont_Clone(pFont
, &pFont2
);
314 ok_ole_success(hr
, "IFont_Clone");
315 IFont_Release(pFont
);
317 hr
= IFont_put_Bold(pFont2
, FALSE
);
318 ok_ole_success(hr
, "IFont_put_Bold");
320 /* this test shows that the notification routine isn't called again */
321 ok(fonteventsdisp_invoke_called
== 2, "IFontEventDisp::Invoke was called %d times instead of twice\n",
322 fonteventsdisp_invoke_called
);
324 IFont_Release(pFont2
);
327 static void test_names_ids(WCHAR
* w_name_1
, const char* a_name_1
,
328 WCHAR
* w_name_2
, const char* a_name_2
,
329 LCID lcid
, DISPID id_1
, DISPID id_2
,
330 HRESULT hres_expect
, int numnames
)
333 IFontDisp
*fontdisp
= NULL
;
335 DISPID rgDispId
[2] = {0xdeadbeef, 0xdeadbeef};
336 LPOLESTR names
[2] = {w_name_1
, w_name_2
};
338 pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, &pvObj
);
341 hres
= IFontDisp_GetIDsOfNames(fontdisp
, &IID_NULL
, names
, numnames
,
345 ok(hres
== hres_expect
,
346 "GetIDsOfNames: \"%s\", \"%s\" returns 0x%08x, expected 0x%08x.\n",
347 a_name_1
, a_name_2
, hres
, hres_expect
);
349 /* test first DISPID */
350 ok(rgDispId
[0]==id_1
,
351 "GetIDsOfNames: \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
352 a_name_1
, rgDispId
[0], id_1
);
354 /* test second DISPID is present */
357 ok(rgDispId
[1]==id_2
,
358 "GetIDsOfNames: ..., \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
359 a_name_2
, rgDispId
[1], id_2
);
362 IFontDisp_Release(fontdisp
);
365 static void test_GetIDsOfNames(void)
367 WCHAR name_Name
[] = {'N','a','m','e',0};
368 WCHAR name_Italic
[] = {'I','t','a','l','i','c',0};
369 WCHAR name_Size
[] = {'S','i','z','e',0};
370 WCHAR name_Bold
[] = {'B','o','l','d',0};
371 WCHAR name_Underline
[] = {'U','n','d','e','r','l','i','n','e',0};
372 WCHAR name_Strikethrough
[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
373 WCHAR name_Weight
[] = {'W','e','i','g','h','t',0};
374 WCHAR name_Charset
[] = {'C','h','a','r','s','e','t',0};
375 WCHAR name_Foo
[] = {'F','o','o',0};
376 WCHAR name_nAmE
[] = {'n','A','m','E',0};
377 WCHAR name_Nom
[] = {'N','o','m',0};
379 LCID en_us
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),
381 LCID fr_fr
= MAKELCID(MAKELANGID(LANG_FRENCH
,SUBLANG_FRENCH
),
384 /* Test DISPID_FONTs for the various properties. */
385 test_names_ids(name_Name
, "Name", NULL
, "", en_us
,
386 DISPID_FONT_NAME
, 0, S_OK
,1);
387 test_names_ids(name_Size
, "Size", NULL
, "", en_us
,
388 DISPID_FONT_SIZE
, 0, S_OK
,1);
389 test_names_ids(name_Bold
, "Bold", NULL
, "", en_us
,
390 DISPID_FONT_BOLD
, 0, S_OK
,1);
391 test_names_ids(name_Italic
, "Italic", NULL
, "", en_us
,
392 DISPID_FONT_ITALIC
, 0, S_OK
,1);
393 test_names_ids(name_Underline
, "Underline", NULL
, "", en_us
,
394 DISPID_FONT_UNDER
, 0, S_OK
,1);
395 test_names_ids(name_Strikethrough
, "Strikethrough", NULL
, "", en_us
,
396 DISPID_FONT_STRIKE
, 0, S_OK
,1);
397 test_names_ids(name_Weight
, "Weight", NULL
, "", en_us
,
398 DISPID_FONT_WEIGHT
, 0, S_OK
,1);
399 test_names_ids(name_Charset
, "Charset", NULL
, "", en_us
,
400 DISPID_FONT_CHARSET
, 0, S_OK
,1);
402 /* Capitalization doesn't matter. */
403 test_names_ids(name_nAmE
, "nAmE", NULL
, "", en_us
,
404 DISPID_FONT_NAME
, 0, S_OK
,1);
407 test_names_ids(name_Foo
, "Foo", NULL
, "", en_us
,
408 DISPID_UNKNOWN
, 0, DISP_E_UNKNOWNNAME
,1);
410 /* Pass several names: first is processed, */
411 /* second gets DISPID_UNKNOWN and doesn't affect retval. */
412 test_names_ids(name_Italic
, "Italic", name_Name
, "Name", en_us
,
413 DISPID_FONT_ITALIC
, DISPID_UNKNOWN
, S_OK
,2);
414 test_names_ids(name_Italic
, "Italic", name_Foo
, "Foo", en_us
,
415 DISPID_FONT_ITALIC
, DISPID_UNKNOWN
, S_OK
,2);
417 /* Locale ID has no effect. */
418 test_names_ids(name_Name
, "Name", NULL
, "", fr_fr
,
419 DISPID_FONT_NAME
, 0, S_OK
,1);
420 test_names_ids(name_Nom
, "This is not a font", NULL
, "", fr_fr
,
421 DISPID_UNKNOWN
, 0, DISP_E_UNKNOWNNAME
,1);
423 /* One of the arguments are invalid */
424 test_names_ids(name_Name
, "Name", NULL
, "", en_us
,
425 0xdeadbeef, 0xdeadbeef, E_INVALIDARG
,0);
426 test_names_ids(name_Italic
, "Italic", NULL
, "", en_us
,
427 0xdeadbeef, 0xdeadbeef, E_INVALIDARG
,0);
428 test_names_ids(name_Foo
, "Foo", NULL
, "", en_us
,
429 0xdeadbeef, 0xdeadbeef, E_INVALIDARG
,0);
431 /* Crazy locale ID? */
432 test_names_ids(name_Name
, "Name", NULL
, "", -1,
433 DISPID_FONT_NAME
, 0, S_OK
,1);
436 static void test_Invoke(void)
441 DISPPARAMS dispparams
;
444 hr
= pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, (void **)&fontdisp
);
445 ok_ole_success(hr
, "OleCreateFontIndirect");
447 V_VT(&vararg
) = VT_BOOL
;
448 V_BOOL(&vararg
) = VARIANT_FALSE
;
449 dispparams
.cNamedArgs
= 0;
450 dispparams
.rgdispidNamedArgs
= NULL
;
451 dispparams
.cArgs
= 1;
452 dispparams
.rgvarg
= &vararg
;
453 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_IFontDisp
, 0, DISPATCH_PROPERTYPUT
, &dispparams
, NULL
, NULL
, NULL
);
454 ok(hr
== DISP_E_UNKNOWNINTERFACE
, "IFontDisp_Invoke should have returned DISP_E_UNKNOWNINTERFACE instead of 0x%08x\n", hr
);
456 dispparams
.cArgs
= 0;
457 dispparams
.rgvarg
= NULL
;
458 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYPUT
, &dispparams
, NULL
, NULL
, NULL
);
459 ok(hr
== DISP_E_BADPARAMCOUNT
, "IFontDisp_Invoke should have returned DISP_E_BADPARAMCOUNT instead of 0x%08x\n", hr
);
461 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYPUT
, NULL
, NULL
, NULL
, NULL
);
462 ok(hr
== DISP_E_PARAMNOTOPTIONAL
, "IFontDisp_Invoke should have returned DISP_E_PARAMNOTOPTIONAL instead of 0x%08x\n", hr
);
464 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, NULL
, NULL
, NULL
, NULL
);
465 ok(hr
== DISP_E_PARAMNOTOPTIONAL
, "IFontDisp_Invoke should have returned DISP_E_PARAMNOTOPTIONAL instead of 0x%08x\n", hr
);
467 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, NULL
, &varresult
, NULL
, NULL
);
468 ok_ole_success(hr
, "IFontDisp_Invoke");
470 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_METHOD
, NULL
, &varresult
, NULL
, NULL
);
471 ok(hr
== DISP_E_MEMBERNOTFOUND
, "IFontDisp_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr
);
473 hr
= IFontDisp_Invoke(fontdisp
, 0xdeadbeef, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, NULL
, &varresult
, NULL
, NULL
);
474 ok(hr
== DISP_E_MEMBERNOTFOUND
, "IFontDisp_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr
);
476 dispparams
.cArgs
= 1;
477 dispparams
.rgvarg
= &vararg
;
478 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, NULL
, NULL
);
479 ok_ole_success(hr
, "IFontDisp_Invoke");
481 IFontDisp_Release(fontdisp
);
484 static void test_IsEqual()
487 static const WCHAR system_font
[] = { 'S','y','s','t','e','m',0 };
488 static const WCHAR arial_font
[] = { 'A','r','i','a','l',0 };
490 LPVOID pvObj2
= NULL
;
495 /* Basic font description */
496 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
497 fd
.lpstrName
= (WCHAR
*)system_font
;
498 S(fd
.cySize
).Lo
= 100;
499 S(fd
.cySize
).Hi
= 100;
504 fd
.fStrikethrough
= 0;
507 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj
);
510 /* Test equal fonts */
511 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
513 hres
= IFont_IsEqual(ifnt
,ifnt2
);
515 "IFont_IsEqual: (EQUAL) Expected S_OK but got 0x%08x\n",hres
);
516 IFont_Release(ifnt2
);
518 /* Check for bad pointer */
519 hres
= IFont_IsEqual(ifnt
,NULL
);
520 ok(hres
== E_POINTER
,
521 "IFont_IsEqual: (NULL) Expected 0x80004003 but got 0x%08x\n",hres
);
524 fd
.lpstrName
= (WCHAR
*)arial_font
;
525 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
526 hres
= IFont_IsEqual(ifnt
,ifnt2
);
528 "IFont_IsEqual: (strName) Expected S_FALSE but got 0x%08x\n",hres
);
529 fd
.lpstrName
= (WCHAR
*)system_font
;
530 IFont_Release(ifnt2
);
532 /* Test lo font size */
533 S(fd
.cySize
).Lo
= 10000;
534 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
536 hres
= IFont_IsEqual(ifnt
,ifnt2
);
538 "IFont_IsEqual: (Lo font size) Expected S_FALSE but got 0x%08x\n",hres
);
539 S(fd
.cySize
).Lo
= 100;
540 IFont_Release(ifnt2
);
542 /* Test hi font size */
543 S(fd
.cySize
).Hi
= 10000;
544 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
546 hres
= IFont_IsEqual(ifnt
,ifnt2
);
548 "IFont_IsEqual: (Hi font size) Expected S_FALSE but got 0x%08x\n",hres
);
549 S(fd
.cySize
).Hi
= 100;
550 IFont_Release(ifnt2
);
552 /* Test font weight */
554 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
556 hres
= IFont_IsEqual(ifnt
,ifnt2
);
558 "IFont_IsEqual: (Weight) Expected S_FALSE but got 0x%08x\n",hres
);
560 IFont_Release(ifnt2
);
564 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
565 hres
= IFont_IsEqual(ifnt
,ifnt2
);
567 "IFont_IsEqual: (Charset) Expected S_FALSE but got 0x%08x\n",hres
);
569 IFont_Release(ifnt2
);
571 /* Test italic setting */
573 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
574 hres
= IFont_IsEqual(ifnt
,ifnt2
);
576 "IFont_IsEqual: (Italic) Expected S_FALSE but got 0x%08x\n",hres
);
578 IFont_Release(ifnt2
);
580 /* Test underline setting */
582 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
583 hres
= IFont_IsEqual(ifnt
,ifnt2
);
585 "IFont_IsEqual: (Underline) Expected S_FALSE but got 0x%08x\n",hres
);
587 IFont_Release(ifnt2
);
589 /* Test strikethrough setting */
590 fd
.fStrikethrough
= 1;
591 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
592 hres
= IFont_IsEqual(ifnt
,ifnt2
);
594 "IFont_IsEqual: (Strikethrough) Expected S_FALSE but got 0x%08x\n",hres
);
595 fd
.fStrikethrough
= 0;
596 IFont_Release(ifnt2
);
602 static void test_ReleaseHfont(void)
605 static const WCHAR system_font
[] = { 'S','y','s','t','e','m',0 };
606 static const WCHAR arial_font
[] = { 'A','r','i','a','l',0 };
607 LPVOID pvObj1
= NULL
;
608 LPVOID pvObj2
= NULL
;
615 /* Basic font description */
616 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
617 fd
.lpstrName
= (WCHAR
*)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
= (WCHAR
*)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);
643 todo_wine
{ok(hres
== S_FALSE
,
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
);
660 todo_wine
{ok(hres
== S_FALSE
,
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
);
666 todo_wine
{ok(hres
== S_FALSE
,
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)
677 static const WCHAR system_font
[] = { 'S','y','s','t','e','m',0 };
678 static const WCHAR arial_font
[] = { 'A','r','i','a','l',0 };
679 LPVOID pvObj1
= NULL
;
680 LPVOID pvObj2
= NULL
;
681 LPVOID pvObj3
= NULL
;
690 /* Basic font description */
691 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
692 fd
.lpstrName
= (WCHAR
*)system_font
;
693 S(fd
.cySize
).Lo
= 100;
694 S(fd
.cySize
).Hi
= 100;
699 fd
.fStrikethrough
= 0;
701 /* Create HFONTs and IFONTs */
702 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj1
);
704 IFont_get_hFont(ifnt1
,&hfnt1
);
705 fd
.lpstrName
= (WCHAR
*)arial_font
;
706 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
708 IFont_get_hFont(ifnt2
,&hfnt2
);
710 /* Try invalid HFONT */
711 hres
= IFont_AddRefHfont(ifnt1
,NULL
);
712 ok(hres
== E_INVALIDARG
,
713 "IFont_AddRefHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
716 /* Try to add a bad HFONT */
717 hres
= IFont_AddRefHfont(ifnt1
,(HFONT
)32);
718 todo_wine
{ ok(hres
== S_FALSE
,
719 "IFont_AddRefHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
722 /* Add simple IFONT HFONT pair */
723 hres
= IFont_AddRefHfont(ifnt1
,hfnt1
);
725 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
728 /* IFONT and HFONT do not have to be the same (always looks at HFONT) */
729 hres
= IFont_AddRefHfont(ifnt2
,hfnt1
);
730 todo_wine
{ok(hres
== S_OK
,
731 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
734 /* Release all hfnt1 refs */
735 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
737 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
740 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
741 todo_wine
{ok(hres
== S_OK
,
742 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
745 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
746 todo_wine
{ok(hres
== S_OK
,
747 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
750 /* Check if hfnt1 is empty */
751 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
752 todo_wine
{ok(hres
== S_FALSE
,
753 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
756 /* Release all hfnt2 refs */
757 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
759 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
762 /* Check if hfnt2 is empty */
763 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
764 todo_wine
{ok(hres
== S_FALSE
,
765 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
768 /* Show that releasing an IFONT does not always release it from the HFONT cache. */
770 IFont_Release(ifnt1
);
772 /* Add a reference for destroyed hfnt1 */
773 hres
= IFont_AddRefHfont(ifnt2
,hfnt1
);
774 todo_wine
{ok(hres
== S_OK
,
775 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
778 /* Decrement reference for destroyed hfnt1 */
779 hres
= IFont_ReleaseHfont(ifnt2
,hfnt1
);
780 todo_wine
{ok(hres
== S_OK
,
781 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
784 /* Shows that releasing all IFONT's does clear the HFONT cache. */
786 IFont_Release(ifnt2
);
788 /* Need to make a new IFONT for testing */
790 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj3
);
792 IFont_get_hFont(ifnt3
,&hfnt3
);
794 /* Add a reference for destroyed hfnt1 */
795 hres
= IFont_AddRefHfont(ifnt3
,hfnt1
);
796 todo_wine
{ok(hres
== S_FALSE
,
797 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
800 /* Decrement reference for destroyed hfnt1 */
801 hres
= IFont_ReleaseHfont(ifnt3
,hfnt1
);
802 todo_wine
{ok(hres
== S_FALSE
,
803 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
806 hres
= IFont_Release(ifnt3
);
811 hOleaut32
= LoadLibraryA("oleaut32.dll");
812 pOleCreateFontIndirect
= (void*)GetProcAddress(hOleaut32
, "OleCreateFontIndirect");
813 if (!pOleCreateFontIndirect
)
816 test_QueryInterface();
819 /* Test various size operations and conversions. */
820 /* Add more as needed. */
821 test_ifont_sizes(180000, 0, 72, 2540, -18, "default");
822 test_ifont_sizes(180000, 0, 144, 2540, -36, "ratio1"); /* change ratio */
823 test_ifont_sizes(180000, 0, 72, 1270, -36, "ratio2"); /* 2nd part of ratio */
825 /* These depend on details of how IFont rounds sizes internally. */
826 test_ifont_sizes(0, 0, 72, 2540, 0, "zero size"); /* zero size */
827 test_ifont_sizes(186000, 0, 72, 2540, -19, "rounding"); /* test rounding */
829 test_font_events_disp();
830 test_GetIDsOfNames();